Relationships
#4838 Load serve's subcommands lazily through a serve route table
Opened by zack · 11/17/2026· Shipped 11/17/2026
Prerequisite for swamp-club#4835 (swamp serve host).
Problem
serve loads all its subcommands eagerly. src/cli/commands/serve.ts is about 11k lines and defines the serve action and its reload, check-config and daemon subcommands (reloadCommand, checkConfigCommand, daemonCommand) in that one module. It statically imports the vault and datastore type registries and everything a running serve needs. Any swamp serve <subcommand> loads all of it.
data, workflow, model, extension, vault, datastore and access load their subcommands lazily through a *_routes.ts table read by loadGroupRoutes in src/cli/command_routes.ts. serve has no such table.
This blocks swamp-club#4835. swamp serve host must load no extensions, no datastore and none of the model, vault or datastore registries. Hung off serveCommand as things are now, it would load all of serve.ts just to start.
Change
- Add
src/cli/commands/serve_routes.tswith aCommandRouterow for each serve subcommand. - Move
reload,check-configanddaemoninto their own modules so each row'sloadimports only that subcommand. - Build the
servegroup from the table throughloadGroupRoutes, asaccessdoes.swamp servewith no subcommand still runs the server, so the group keeps its own action and options. Only the subcommands become lazy. - Add
serveto the list of lazily routed groups in AGENTS.md.
There is no change to the CLI surface: the flags, help text and json output stay the same.
Done when
integration/command_routes_rules_test.tscoversserve: each row's module is the file itsloadimports, the full tree's serve children equal the table, and a subcommand path loads only that subcommand.- A route for a serve subcommand whose module does not import serve.ts loads without serve.ts, so
swamp serve hostcan be added as one more row in swamp-club#4835. - Existing
servetests (serve_test.ts,serve_daemon_test.ts) pass unchanged.
Shipped
Click a lifecycle step above to view its details.
Sign in to post a ripple.