LT import v3 — Decision Ledger
Status: in effect (0.7.0). This design is implemented. This document is the source of truth for the import design. Related amendments have landed in
spec.md(§1, §6.1, §13, §15, §16) andgrammar.ebnf.package-manager.mdis the operational summary. Implementation of phases 0–5 has landed; seeCHANGELOG.md.
The change in one sentence: package identity moves from a global name to
(dependency, path), external dependencies move to the manifest, and the lock
becomes read-only during builds.
1. The problem addressed
The v2 design is sound for a single small project, but it has a ceiling:
- Package names are unique per build, so two dependencies that both have
package usercannot coexist. Aliases do not help because the loader rejects before the alias is read. - File paths are public API. Moving a file breaks every import.
- There is no manifest. A version is a raw URL on the import line; there is no dependency graph, per-dependency update, or frozen mode for CI.
lt buildandlt checkwritelt.locksilently.- Multi-package files share one import list, and importing one package still loads and emits every package in that file.
- Unused imports are never reported.
What is not changed because it is already right: mandatory qualifiers,
per-declaration export, rejection of dot/blank imports, rejection of import
cycles, and the mapping of one package to one host module.
2. Decisions
| # | Decision | Rationale |
|---|---|---|
| 2.1 | Package identity = (dependency root, file path). Package names are unique per dependency, not per build. | Removes the scaling wall; two libraries may use the same package name. |
| 2.2 | Two dependencies may both declare package user. If both are imported into the same file, both must be aliased differently; the error only occurs when bindings collide. | Aliases only become useful once global uniqueness is dropped. Same model as Go. |
| 2.3 | One file contains exactly one package. Multi-package per file is removed. | Imports become package-scoped, the loader loads only what is referenced, and package = file = output module. |
| 2.4 | File names are free; the package name is written in the import and verified against the target file. Output module name = directory + package name. | The playground and conformance use path casing different from package names; forcing stem = name would break that convention with no semantic benefit. |
| 2.5 | Specifiers without an extension. Local: ./wallet/money. External: acme/wallet/money, first segment = manifest key. | The unit of import is the package, not the file. Single resolution: <path>.lt. |
| 2.6 | External dependencies are declared only in lt.toml. Local imports stay relative and need no manifest. | A single place for versions, sources, and dependency edges. |
| 2.7 | Manifest v1 contains only [dependencies]. [package], workspaces, and publishing metadata are deferred. | Metadata nobody uses is better not invented. |
| 2.8 | v1 sources: git (https/ssh) and local paths. No registry. | Covers early ecosystem needs without building a server, auth, and publishing. |
| 2.9 | Versions are written as semver ranges, exact tags, or 40-hex commits. Branches are rejected. The lock always pins a commit. | Reproducibility without forcing every consumer to bump a version manually on a diamond dependency. |
| 2.10 | Resolution is transitive, one version per source per build: the highest version satisfying all ranges. Irreconcilable ranges = error. | A model that can be explained; multi-version splits type identity and output size. |
| 2.11 | lt build and lt check never write the lock. An unlocked dependency = an error telling you to run lt update. | A lock only means something if a build cannot change it silently. |
| 2.12 | lt.lock is a versioned-format resolution graph: canonical source, commit, root, sha256 per file, and requirement edges. Entry identity = (source, commit), not content. | Enough for per-dependency updates, conflict explanation, and transport integrity. |
| 2.13 | Path dependencies are not pinned to commits — always live — but their transitive dependencies still enter the lock. | Local sources are part of the project, not downloaded artifacts. |
| 2.14 | Unused imports = a compile error, with autofix. Definition: at least one binding from that import entry is referenced. | Dead imports are dependencies that should not be resolved. |
| 2.15 | Explicit per-name re-export: export import money { Price as P } "./wallet/money". The item list is mandatory; wildcards and list-less forms are rejected. The qualifier stays locally bound but is not re-exported. | A stable façade without resurrecting nested namespaces or from. |
| 2.16 | Re-export is a name alias, not a new type. facade.P and money.Price are the same nominal type. | Two identical types that are not assignable to each other are a design bug, not a feature. |
| 2.17 | Dependency output uses the _deps prefix: src/_deps/<key>/<path>.ts, gen/_deps/<key>/<path>/<package>.go. _deps is reserved at the source root. | A stable namespace with no collision with local packages. |
| 2.18 | Transport: git https/ssh, raw files over https, http:// only for localhost. Auth via git credentials / GITHUB_TOKEN. No custom signatures in v1. | Consistent with the reproducibility claim; signatures are a project of their own. |
| 2.19 | vendor/ is optional and may be committed. Source order: vendor → cache → fetch the locked commit. --offline forbids the network. Path dependencies are not vendored. | Offline-first without adding a new way to change versions. |
| 2.20 | v1 commands: lt add, lt remove, lt update <key>/--all, lt vendor, lt migrate. No lt install. | One explicit place that writes the lock. |
| 2.21 | lt build stays entry-based; unreachable local packages are not emitted. | Determinism and minimal output. |
| 2.22 | lt migrate handles mechanical changes and rejects ambiguous cases. Dry-run by default; --write applies. | Humans should see file changes before they are written. |
| 2.23 | Go constraints remain hard: one package per output directory, no import cycles, Go-valid package names. | Go is a first-class target; an import graph that cannot be emitted to Go must not pass. |
| 2.24 | Deferred: registry, publishing, multi-version per source, workspaces, signatures. | Keeps v1 shippable and testable. |
3. Syntax
// src/app.lt
// imports come before the package block
// local, no extension
import money { Price, format } "./wallet/money"
import money as cash { Price as P } "../shared/money"
// external: the first segment is a key in lt.toml
import post "acme/blog/post"
// groups are still allowed; one entry per line, no commas
import (
money { Price } "./wallet/money"
post "acme/blog/post"
)
// façade: only the items inside { … } enter this package's API
export import money { Price as P } "./wallet/money"
Syntax rules:
importalways comes at the top of the file, before thepackageblock.export importis valid only as a single entry, not inside a group.export importmust have a non-empty item list.- The qualifier (
money) stays bound after destructuring and afterexport import, but the qualifier is not re-exported. - Dot imports, blank imports, and
fromare still rejected with dedicated messages. - Empty item lists
{}and empty import groups()remain errors.
4. Semantics
4.1 Project root and resolution
- Project root = the nearest ancestor of the entry that has
lt.toml. Withoutlt.toml, the project may only use local imports. - A specifier starting with
./or../resolves relative to the importing file:<specifier>.lt. There are no directory imports and no index files. - Any other specifier is treated as
<key>/<path>:keymust exist in[dependencies]. Target file =<checkout>/<root>/<path>.lt. - Every loaded file must declare exactly one package. File names are free; the package name determines identity and the output module name.
- Package names must be unique within one dependency. Two different dependencies may use the same name.
- Import cycles are detected on the file/package graph, with a message showing the cycle chain.
4.2 Imports and aliases
import money "./wallet/money"binds the qualifiermoney.import money { Price, format } "./wallet/money"binds the qualifiermoneyand the namesPrice/formatwithout a qualifier.import money as cash { Price as P } "./wallet/money"bindscashandP.- An import name must not shadow a local declaration or another import name.
- If two packages with the same name from two dependencies are imported into the same file, both must use different aliases. The error only appears when bindings collide, not when the package declaration is read.
- Using a type/function from a package that is not imported remains a compile error; there is no implicit resolution.
4.3 Unused import
- An import entry counts as used if at least one of its bindings is referenced,
including in type positions, inside template strings, and in
export import. export importalways counts as used because it is part of the API.- An unused entry = compile error. Autofix removes that entry; if the entry is the only content of a group, the group is removed too.
- v1 does not check for unused destructured items as long as the import entry itself is used.
4.4 Re-export
export import money { Price as P } "./wallet/money"addsPto this package’s export table. A consumer can writeimport facade { P } "./facade"orimport facade "./facade"and thenfacade.P.- A re-exported name must be part of the origin package’s API: a declaration
with
exportor the result of an explicit re-export from that package. Private names = error. - Re-exports may be aliased; a conflict with a local declaration or with another re-export result = error.
- A re-export does not create a new type. Nominal identity stays with the origin package, and the emitter refers to the origin module, not the façade package.
- Re-exports are not implicitly transitive: package A only exposes the names it explicitly re-exports.
- Because import cycles are forbidden, the re-export graph cannot loop.
4.5 Versions and conflicts
- The manifest writes semver ranges, exact tags, or 40-hex commits. The tag
v1.2.0normalizes to1.2.0; non-semver tags are valid only as exact versions. - v1 range operators:
^,~,=/exact, and*. Other comparison operators are not supported yet and are rejected as an exact version/tag that is not found. - The resolver reads each dependency’s manifest, collects all requirements, then picks the highest version that satisfies all of them.
- If no version satisfies all ranges, the build fails and prints every parent with its range.
- One source has only one version per build. There is no side-by-side version selection in v1.
- The lock stores the chosen commit; a build never re-selects a version.
4.6 Read-only lock
lt build/lt checkverify that the lock satisfies the current manifest. A missing, incomplete, or non-satisfying lock = an error with the repair command (lt update <key>orlt update --all).lt update <key>re-resolves that key and its closure. If the change touches a shared dependency, other entries are updated too and reported.lt update --allre-resolves the whole graph.lt addwrites the manifest and the lock;lt removeremoves the manifest then prunes lock entries that are no longer reachable.
5. Manifest
# lt.toml
[dependencies]
acme = { git = "https://github.com/acme/lt-lib", version = "^1.2", root = "." }
utils = { path = "../utils" }
- Dependency keys follow
[a-z][a-z0-9_]*and become the first segment of external specifiers. git+version(required) orpath(required); the two must not appear together.rootis optional, default".": the subdirectory inside the checkout that becomes the dependency’s package root. That directory must contain the dependency’slt.toml.- No
[package], workspaces, or publishing fields in v1. - The manifest is written by hand or via
lt add;lt fmtdoes not touch it in v1.
6. Lock
Format sketch (not a final byte contract; the content is what is locked):
version = 1
[[root]]
key = "acme"
source = "git+https://github.com/acme/lt-lib"
[[package]]
source = "git+https://github.com/acme/lt-lib"
commit = "0123456789abcdef0123456789abcdef01234567"
root = "."
[[package.files]]
path = "wallet/money.lt"
sha256 = "…"
[[package.dependencies]]
key = "utils"
source = "git+https://github.com/acme/lt-utils"
commit = "89abcdef0123456789abcdef0123456789abcdef"
requirement = "^2.0"
sourceis the canonical normalized URL (host, path, no.git, no trailing slash). Thesshandhttpsforms of the same repo normalize to the same identity.commitis always 40-hex for git. Path dependencies still get an entry (withoutcommit, sourcepath+…relative to the project root) so that edges and prunes can still be tracked; their content is always live and not verified from the lock.filesrecords every file actually loaded, with the sha256 of its content.dependenciesrecords requirement edges, so conflicts can be explained and per-key updates know what changed.versionis the lock format version. An old lock withoutversion= an error telling you to runlt update --all.
7. Output
| Origin | TypeScript | Python | Go |
|---|---|---|---|
| Local | src/<dir>/<package>.ts | gen/<dir>/<package>.py | gen/<dir>/<package>/<package>.go |
| Dependency | src/_deps/<key>/<dir>/<package>.ts | gen/_deps/<key>/<dir>/<package>.py | gen/_deps/<key>/<dir>/<package>/<package>.go |
The paths above are relative to the target output directory (out/ts, out/py,
out/go), following the existing emitter convention.
_depsis reserved at the source root; a project must not have a directory named_depscontaining local sources.- Tests and usage are emitted only for packages owned by the root project, not for dependency packages.
- The runtime stays one file per output package; dependency modules import the runtime with a relative path computed by the emitter.
- Type identity stays nominal per module; the output path does not change identity.
- Source file names are free; the output module uses the file’s directory + the package name.
8. Commands
lt add acme --git https://github.com/acme/lt-lib --version "^1.2"
lt add utils --path ../utils
lt remove acme
lt update acme
lt update --all
lt vendor
lt build -t ts src/app.lt
lt check src/
lt migrate [--write]
build/check/test/vendoraccept--offline;build/checkare read-only with respect to the lock and manifest.vendorcopies the locked source tree from the cache (or fetches the locked commit) intovendor/;--offlineforbids the network.migrateis dry-run by default;--writeapplies.
9. Migration
lt migrate handles:
- Removing
.ltfrom every local specifier. - Moving URL imports into
[dependencies]entries. The key is derived from the repo name; the path inside the repo becomes part of the specifier. - Splitting multi-package files into one file per package, copying only the imports each package actually uses.
- Not renaming files: file names are free and package names are preserved.
It refuses and stops with a clear message when:
- There are two different URLs/refs for the same source (violating one version per source).
- A dependency key already used by another source = error; choose another key manually.
- A file name produced by the split is already used by another package.
- An import cannot be mapped to a path inside the repo (e.g. a non-git URL).
Dry-run prints the plan per file; --write then writes. After migration, the
user runs lt update --all to write a new lock.
This repo itself has ~8 import sites and zero multi-package files, so its migration is small. File names do not need to change because file names need not match package names.
10. Implementation plan
| Phase | Contents | Crate |
|---|---|---|
| 0 | This document, spec/grammar amendments, breaking-release notes | docs/ |
| 1 | One package per file, extension-less specifiers, export import, unused imports, per-dependency uniqueness | lt-syntax, lt-hir, lt-lsp |
| 2 | lt.toml, git/path resolver + semver + transitive, lock graph, read-only build/check | lt-pkg, lt-hir, lt-cli |
| 3 | _deps output, test/usage filtering, runtime paths | lt-ir, lt-emit-* |
| 4 | lt add/remove/update/vendor/migrate, error messages, manifest-aware LSP | lt-cli, lt-lsp |
| 5 | New conformance, examples, docs, CI | tests/, examples/, docs/ |
Phase 1 deliberately does not depend on the resolver: language changes can land
and be tested with local imports only, before lt-pkg is torn apart.
11. v1 non-goals
Registry and publishing, multi-version per source, workspaces, multi-package per
file, custom signatures, and [package] in the manifest. Accepted consequences:
large packages must be split into several packages or use a re-export façade, and
the resolver depends on the git binary (not a Git library).
12. Implementation notes
- The git resolver uses the
gitCLI in v1 (ls-remote, fetch, checkout); semver uses thesemvercrate. Both can be replaced without changing the manifest/lock. - The
ModuleIdtype stays per package; what changes is the loader key and the uniqueness validation. - The checker must extend the export table with re-export results before
validating import items, but
TypeName.modulestill points to the origin package. - The emitter computes relative paths from the output name; the
_depsprefix only needs to be added in one place (module name computation), not in every emitter. lt checkwith multiple entries is valid only if they are all under the same project root.