Skip to content

refactor(daemon): stop importing the commands barrel through src/runtime.ts #2540

Description

@thymikee

Purpose

Five daemon files import src/runtime.ts, which imports the command barrel with a value import:

// src/runtime.ts
import { bindCommands, type BoundAgentDeviceCommands } from './commands/index.ts';

The value closure of src/runtime.ts is 122 files, 48 of them under src/commands/. The daemon's total value closure is 717 files and carries 121 src/commands/** files — roughly the entire commands zone (140 files, 21k LOC) — plus 17 root flat files. The daemon loads a command surface it does not dispatch through, and every change in commands is potentially a daemon-restart-cost event.

Umbrella: #2545. Chosen first because it is the only child that changes what the daemon actually loads, and because #2469 (eager-closure budget tolerance) is unblocked by cutting closure, not by adding budget.

Required behavior

  1. src/runtime.ts keeps its public shape: AgentDevice, createAgentDevice, createMemorySessionStore, localCommandPolicy, restrictedCommandPolicy, and the re-exported command types. No consumer-side API change is part of this issue.
  2. Daemon consumers of src/runtime.ts take the specific declarations they use through their owning module or contract, not through the runtime facade. Determine the used symbol set per importer before choosing the seam; do not invent an interface wider than the symbols in use.
  3. The barrel src/commands/index.ts either stops being the value entry for runtime binding, or the binding moves to the composition root that needs it. One construction path, no second registry.

Completion conditions

  • Value-only transitive closure from src/daemon/** contains zero files under src/commands/. Measured with a probe over scripts/layering/model.ts as described in the parent, and reported in the PR.
  • src/runtime.ts has no value edge into src/commands/**, or is no longer reachable from src/daemon/** at all.
  • No new eager work: the eager-import-closure budgets for the daemon entry surfaces do not rise.
  • R4 stays 0, R5 stays 0, R6 does not grow past the ratchet.

Out of scope

  • Repackaging src/commands as a workspace package. That decision needs the cli-schema orientation settled first (sibling child).
  • Any change to the command descriptor registry or the command-registry package.

Dependencies

  • None. Wave A, independent branch.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions