Relationships
#4611 Lazy loading L5: one anchor for embedded resources
Opened by zack · 11/10/2026· Shipped 11/10/2026
First step of the bundling track in the lazy command loading plan. It is independent of the routing issues (#4591, #4592) and can land in parallel with them.
Context
The plan ships a bundled build later (deno bundle --code-splitting, then deno compile). Measured on a prototype, bundling together with argv routing takes swamp version from 384 to ~111 ms, data get from 416 to ~132 ms and workflow run from 498 to ~358 ms, and cuts peak RSS by 25–50%. This issue removes the one source-level blocker to bundling, with no behaviour change.
Why
A bundled module's import.meta.dirname is the chunk's directory, not the source file's. A bundled swamp init --tool claude fails reading /.claude/skills/swamp/SKILL.md. The fix works the same unbundled, so it can land first with no behaviour change.
Of the import.meta.url / import.meta.dirname uses in src/, four need to change:
| Site | What it finds |
|---|---|
src/infrastructure/assets/skill_assets.ts |
.claude/skills |
src/infrastructure/runtime/embedded_deno_runtime.ts |
resources/deno |
src/serve/dashboard_assets.ts |
packages/dashboard/dist |
src/infrastructure/persistence/unit_of_work_scope.ts |
The source root it strips from stack-frame paths |
The rest stay as they are:
- About 28 are
recordDefiningModule(command, import.meta.url)in command modules, some of them split across lines (model_lease.ts). They are read only byintegration/json_mode_conformance_test.ts, which runs on source. - 4 locate an entry module to run under
deno run(litestream_replicator.ts,process_bundle_prober.ts,telemetry_sender_process.ts,dispatch_handler.ts). A compiled binary re-executes itself and never takes that branch. src/infrastructure/testing/subprocess_harness.tsis test support.src/libswamp/extensions/extension_tree_index.tsmentionsimport.meta.urlonly in a comment.
Scope
- A single module (for example
src/infrastructure/runtime/resource_root.ts) that resolves the root once, on first use. It walks up from its ownimport.meta.dirnameto the first ancestor that holds.claude/skills. That directory is always embedded and always present in a checkout, so the lookup does not depend on how deep the module, or the chunk it was bundled into, sits. This works on Deno 2.9.8 from source, compiled, and bundled then compiled. Resolving on first use, not at import, also keeps it independent of module evaluation order, which #4592 changes. - Migrate the four sites.
- Fitness rule, in its own file (for example
integration/resource_anchor_rules_test.ts), not inintegration/ddd_layer_rules_test.ts: #4591 and #4592 both edit that file, and a third PR there only adds merge conflicts. - The rule is a pinned ratchet over
import.meta.url/import.meta.dirnamereads, so a new resource lookup has to go through the anchor. Write it so it does not trip on ordinary command work:- Allow
recordDefiningModule(<command>, import.meta.url)by pattern, wherever it appears. UsecallArgumentsfromintegration/arch_fitness_helpers.ts, so a call split across lines matches too. Do not pin the command files that make these calls: otherwise every new or split command module, including the group routing work that follows #4592, fails the rule. - Pin only the remaining uses: the anchor module itself, the four helper-entry sites and the test-support harness.
- Scan
src/only.integration/locates fixtures and Worker modules throughimport.meta.url(the route-table Worker test in #4592 is likely to), and those run on source. - Ignore comments.
- Allow
Acceptance
swamp init --tool claudeinstalls skills.- The embedded Deno runtime is found.
- The dashboard serves its assets.
- The unscoped-write diagnostic names the same caller file as before.
deno run dev(unbundled source) still works.- A unit test resolves the root from an injected start directory at two different depths.
- The fitness rule passes on the result, fails on a new
import.meta.dirnamelookup insrc/, and passes on a new command module that callsrecordDefiningModule(command, import.meta.url). - Tests pass on Linux, macOS and Windows; paths use
@std/path. - The parity script from #4590 passes against a binary built from the base commit.
Release impact
Four files change, one of them in the persistence layer, so the attestation will select most or all commands.
Risk
Low. Windows path handling is the usual trap.
Shipped
Click a lifecycle step above to view its details.
Sign in to post a ripple.