@kya-os/cli 1.8.1 → 1.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/agent.d.ts +35 -0
- package/dist/commands/agent.d.ts.map +1 -0
- package/dist/commands/agent.js +321 -0
- package/dist/commands/agent.js.map +1 -0
- package/dist/commands/build.js +2 -2
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/check.js +3 -3
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/checkpoint-init.d.ts +1 -1
- package/dist/commands/checkpoint-init.d.ts.map +1 -1
- package/dist/commands/checkpoint-init.js +8 -41
- package/dist/commands/checkpoint-init.js.map +1 -1
- package/dist/commands/claim.js +2 -2
- package/dist/commands/claim.js.map +1 -1
- package/dist/commands/dco.d.ts +59 -0
- package/dist/commands/dco.d.ts.map +1 -1
- package/dist/commands/dco.js +280 -5
- package/dist/commands/dco.js.map +1 -1
- package/dist/commands/dev.js +1 -1
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +18 -24
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/env.js +6 -6
- package/dist/commands/env.js.map +1 -1
- package/dist/commands/identity.js +3 -3
- package/dist/commands/identity.js.map +1 -1
- package/dist/commands/init-stages.d.ts +141 -0
- package/dist/commands/init-stages.d.ts.map +1 -0
- package/dist/commands/init-stages.js +684 -0
- package/dist/commands/init-stages.js.map +1 -0
- package/dist/commands/init.d.ts +46 -16
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +229 -279
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/orchestrator.d.ts +18 -0
- package/dist/commands/orchestrator.d.ts.map +1 -0
- package/dist/commands/orchestrator.js +251 -0
- package/dist/commands/orchestrator.js.map +1 -0
- package/dist/commands/register.d.ts +1 -1
- package/dist/commands/register.d.ts.map +1 -1
- package/dist/commands/register.js +35 -7
- package/dist/commands/register.js.map +1 -1
- package/dist/commands/review.d.ts +48 -0
- package/dist/commands/review.d.ts.map +1 -0
- package/dist/commands/review.js +220 -0
- package/dist/commands/review.js.map +1 -0
- package/dist/commands/rotate.js +4 -4
- package/dist/commands/rotate.js.map +1 -1
- package/dist/commands/score.d.ts +15 -0
- package/dist/commands/score.d.ts.map +1 -0
- package/dist/commands/score.js +471 -0
- package/dist/commands/score.js.map +1 -0
- package/dist/commands/start.js +3 -3
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/status.js +1 -1
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/verify.js +6 -6
- package/dist/commands/verify.js.map +1 -1
- package/dist/dco.d.ts +4 -0
- package/dist/dco.d.ts.map +1 -0
- package/dist/dco.js +23 -0
- package/dist/dco.js.map +1 -0
- package/dist/index.js +52 -9
- package/dist/orchestrator/daemon.d.ts +137 -0
- package/dist/orchestrator/daemon.d.ts.map +1 -0
- package/dist/orchestrator/daemon.js +242 -0
- package/dist/orchestrator/daemon.js.map +1 -0
- package/dist/orchestrator/db/dispatches.d.ts +108 -0
- package/dist/orchestrator/db/dispatches.d.ts.map +1 -0
- package/dist/orchestrator/db/dispatches.js +122 -0
- package/dist/orchestrator/db/dispatches.js.map +1 -0
- package/dist/orchestrator/db/index.d.ts +50 -0
- package/dist/orchestrator/db/index.d.ts.map +1 -0
- package/dist/orchestrator/db/index.js +116 -0
- package/dist/orchestrator/db/index.js.map +1 -0
- package/dist/orchestrator/db/journal.d.ts +93 -0
- package/dist/orchestrator/db/journal.d.ts.map +1 -0
- package/dist/orchestrator/db/journal.js +91 -0
- package/dist/orchestrator/db/journal.js.map +1 -0
- package/dist/orchestrator/db/liveness.d.ts +97 -0
- package/dist/orchestrator/db/liveness.d.ts.map +1 -0
- package/dist/orchestrator/db/liveness.js +105 -0
- package/dist/orchestrator/db/liveness.js.map +1 -0
- package/dist/orchestrator/db/mission.d.ts +78 -0
- package/dist/orchestrator/db/mission.d.ts.map +1 -0
- package/dist/orchestrator/db/mission.js +99 -0
- package/dist/orchestrator/db/mission.js.map +1 -0
- package/dist/orchestrator/db/schema.d.ts +14 -0
- package/dist/orchestrator/db/schema.d.ts.map +1 -0
- package/dist/orchestrator/db/schema.js +169 -0
- package/dist/orchestrator/db/schema.js.map +1 -0
- package/dist/orchestrator/db/tickets.d.ts +147 -0
- package/dist/orchestrator/db/tickets.d.ts.map +1 -0
- package/dist/orchestrator/db/tickets.js +238 -0
- package/dist/orchestrator/db/tickets.js.map +1 -0
- package/dist/orchestrator/db/verdicts.d.ts +187 -0
- package/dist/orchestrator/db/verdicts.d.ts.map +1 -0
- package/dist/orchestrator/db/verdicts.js +197 -0
- package/dist/orchestrator/db/verdicts.js.map +1 -0
- package/dist/orchestrator/events.d.ts +69 -0
- package/dist/orchestrator/events.d.ts.map +1 -0
- package/dist/orchestrator/events.js +20 -0
- package/dist/orchestrator/events.js.map +1 -0
- package/dist/orchestrator/github-credential-anchor-sender.d.ts +159 -0
- package/dist/orchestrator/github-credential-anchor-sender.d.ts.map +1 -0
- package/dist/orchestrator/github-credential-anchor-sender.js +313 -0
- package/dist/orchestrator/github-credential-anchor-sender.js.map +1 -0
- package/dist/orchestrator/hub-dispatch.d.ts +120 -0
- package/dist/orchestrator/hub-dispatch.d.ts.map +1 -0
- package/dist/orchestrator/hub-dispatch.js +257 -0
- package/dist/orchestrator/hub-dispatch.js.map +1 -0
- package/dist/orchestrator/hub-observer.d.ts +201 -0
- package/dist/orchestrator/hub-observer.d.ts.map +1 -0
- package/dist/orchestrator/hub-observer.js +474 -0
- package/dist/orchestrator/hub-observer.js.map +1 -0
- package/dist/orchestrator/journal-writer.d.ts +80 -0
- package/dist/orchestrator/journal-writer.d.ts.map +1 -0
- package/dist/orchestrator/journal-writer.js +113 -0
- package/dist/orchestrator/journal-writer.js.map +1 -0
- package/dist/orchestrator/mcp/server.d.ts +136 -0
- package/dist/orchestrator/mcp/server.d.ts.map +1 -0
- package/dist/orchestrator/mcp/server.js +582 -0
- package/dist/orchestrator/mcp/server.js.map +1 -0
- package/dist/orchestrator/mcp/stdio.d.ts +22 -0
- package/dist/orchestrator/mcp/stdio.d.ts.map +1 -0
- package/dist/orchestrator/mcp/stdio.js +51 -0
- package/dist/orchestrator/mcp/stdio.js.map +1 -0
- package/dist/orchestrator/review.d.ts +131 -0
- package/dist/orchestrator/review.d.ts.map +1 -0
- package/dist/orchestrator/review.js +322 -0
- package/dist/orchestrator/review.js.map +1 -0
- package/dist/tui/app.d.ts +33 -0
- package/dist/tui/app.d.ts.map +1 -0
- package/dist/tui/app.js +71 -0
- package/dist/tui/app.js.map +1 -0
- package/dist/tui/components.d.ts +110 -0
- package/dist/tui/components.d.ts.map +1 -0
- package/dist/tui/components.js +118 -0
- package/dist/tui/components.js.map +1 -0
- package/dist/tui/index.d.ts +30 -0
- package/dist/tui/index.d.ts.map +1 -0
- package/dist/tui/index.js +95 -0
- package/dist/tui/index.js.map +1 -0
- package/dist/tui/keymap.d.ts +33 -0
- package/dist/tui/keymap.d.ts.map +1 -0
- package/dist/tui/keymap.js +49 -0
- package/dist/tui/keymap.js.map +1 -0
- package/dist/tui/nav.d.ts +29 -0
- package/dist/tui/nav.d.ts.map +1 -0
- package/dist/tui/nav.js +39 -0
- package/dist/tui/nav.js.map +1 -0
- package/dist/tui/sanitize.d.ts +25 -0
- package/dist/tui/sanitize.d.ts.map +1 -0
- package/dist/tui/sanitize.js +36 -0
- package/dist/tui/sanitize.js.map +1 -0
- package/dist/tui/theme.d.ts +32 -0
- package/dist/tui/theme.d.ts.map +1 -0
- package/dist/tui/theme.js +63 -0
- package/dist/tui/theme.js.map +1 -0
- package/dist/tui/views/agents.d.ts +67 -0
- package/dist/tui/views/agents.d.ts.map +1 -0
- package/dist/tui/views/agents.js +231 -0
- package/dist/tui/views/agents.js.map +1 -0
- package/dist/tui/views/index.d.ts +93 -0
- package/dist/tui/views/index.d.ts.map +1 -0
- package/dist/tui/views/index.js +150 -0
- package/dist/tui/views/index.js.map +1 -0
- package/dist/tui/views/registry.d.ts +22 -0
- package/dist/tui/views/registry.d.ts.map +1 -0
- package/dist/tui/views/registry.js +110 -0
- package/dist/tui/views/registry.js.map +1 -0
- package/dist/utils/agent/backoff.d.ts +31 -0
- package/dist/utils/agent/backoff.d.ts.map +1 -0
- package/dist/utils/agent/backoff.js +51 -0
- package/dist/utils/agent/backoff.js.map +1 -0
- package/dist/utils/agent/markers.d.ts +87 -0
- package/dist/utils/agent/markers.d.ts.map +1 -0
- package/dist/utils/agent/markers.js +147 -0
- package/dist/utils/agent/markers.js.map +1 -0
- package/dist/utils/agent/review.d.ts +67 -0
- package/dist/utils/agent/review.d.ts.map +1 -0
- package/dist/utils/agent/review.js +305 -0
- package/dist/utils/agent/review.js.map +1 -0
- package/dist/utils/agent/spawn-agent.d.ts +117 -0
- package/dist/utils/agent/spawn-agent.d.ts.map +1 -0
- package/dist/utils/agent/spawn-agent.js +177 -0
- package/dist/utils/agent/spawn-agent.js.map +1 -0
- package/dist/utils/agent/task.d.ts +101 -0
- package/dist/utils/agent/task.d.ts.map +1 -0
- package/dist/utils/agent/task.js +357 -0
- package/dist/utils/agent/task.js.map +1 -0
- package/dist/utils/agent/verify.d.ts +47 -0
- package/dist/utils/agent/verify.d.ts.map +1 -0
- package/dist/utils/agent/verify.js +144 -0
- package/dist/utils/agent/verify.js.map +1 -0
- package/dist/utils/agent-detector.d.ts +48 -0
- package/dist/utils/agent-detector.d.ts.map +1 -0
- package/dist/utils/agent-detector.js +74 -0
- package/dist/utils/agent-detector.js.map +1 -0
- package/dist/utils/agent-profile-stage.d.ts +70 -0
- package/dist/utils/agent-profile-stage.d.ts.map +1 -0
- package/dist/utils/agent-profile-stage.js +153 -0
- package/dist/utils/agent-profile-stage.js.map +1 -0
- package/dist/utils/agent-profiles.d.ts +27 -0
- package/dist/utils/agent-profiles.d.ts.map +1 -0
- package/dist/utils/agent-profiles.js +61 -0
- package/dist/utils/agent-profiles.js.map +1 -0
- package/dist/utils/checkpoint-api.d.ts +1 -1
- package/dist/utils/checkpoint-api.js +1 -1
- package/dist/utils/checkpoint-env.d.ts +1 -1
- package/dist/utils/checkpoint-env.js +2 -2
- package/dist/utils/checkpoint-env.js.map +1 -1
- package/dist/utils/checkpoint-scaffold.d.ts +1 -1
- package/dist/utils/checkpoint-scaffold.js +1 -1
- package/dist/utils/cli-kit/browser.d.ts +24 -0
- package/dist/utils/cli-kit/browser.d.ts.map +1 -0
- package/dist/utils/cli-kit/browser.js +58 -0
- package/dist/utils/cli-kit/browser.js.map +1 -0
- package/dist/utils/cli-kit/claim-polling.d.ts +18 -0
- package/dist/utils/cli-kit/claim-polling.d.ts.map +1 -0
- package/dist/utils/{claim-polling.js → cli-kit/claim-polling.js} +19 -26
- package/dist/utils/cli-kit/claim-polling.js.map +1 -0
- package/dist/utils/cli-kit/diagnostics.d.ts +9 -0
- package/dist/utils/cli-kit/diagnostics.d.ts.map +1 -0
- package/dist/utils/cli-kit/diagnostics.js +11 -0
- package/dist/utils/cli-kit/diagnostics.js.map +1 -0
- package/dist/utils/cli-kit/fs-safe.d.ts +14 -0
- package/dist/utils/cli-kit/fs-safe.d.ts.map +1 -0
- package/dist/utils/cli-kit/fs-safe.js +20 -0
- package/dist/utils/cli-kit/fs-safe.js.map +1 -0
- package/dist/utils/cli-kit/index.d.ts +15 -0
- package/dist/utils/cli-kit/index.d.ts.map +1 -0
- package/dist/utils/cli-kit/index.js +10 -0
- package/dist/utils/cli-kit/index.js.map +1 -0
- package/dist/utils/cli-kit/json-file.d.ts +21 -0
- package/dist/utils/cli-kit/json-file.d.ts.map +1 -0
- package/dist/utils/cli-kit/json-file.js +51 -0
- package/dist/utils/cli-kit/json-file.js.map +1 -0
- package/dist/utils/cli-kit/marker-block.d.ts +26 -0
- package/dist/utils/cli-kit/marker-block.d.ts.map +1 -0
- package/dist/utils/cli-kit/marker-block.js +61 -0
- package/dist/utils/cli-kit/marker-block.js.map +1 -0
- package/dist/utils/cli-kit/paths.d.ts +15 -0
- package/dist/utils/cli-kit/paths.d.ts.map +1 -0
- package/dist/utils/cli-kit/paths.js +21 -0
- package/dist/utils/cli-kit/paths.js.map +1 -0
- package/dist/utils/cli-kit/secure-storage.d.ts +14 -0
- package/dist/utils/cli-kit/secure-storage.d.ts.map +1 -0
- package/dist/utils/cli-kit/secure-storage.js +20 -0
- package/dist/utils/cli-kit/secure-storage.js.map +1 -0
- package/dist/utils/cli-kit/step-report.d.ts +16 -0
- package/dist/utils/cli-kit/step-report.d.ts.map +1 -0
- package/dist/utils/cli-kit/step-report.js +36 -0
- package/dist/utils/cli-kit/step-report.js.map +1 -0
- package/dist/utils/dco/agent-metadata.d.ts +1 -1
- package/dist/utils/dco/agent-metadata.js +1 -1
- package/dist/utils/dco/agent-metadata.js.map +1 -1
- package/dist/utils/dco/claude-config.d.ts +18 -14
- package/dist/utils/dco/claude-config.d.ts.map +1 -1
- package/dist/utils/dco/claude-config.js +31 -97
- package/dist/utils/dco/claude-config.js.map +1 -1
- package/dist/utils/dco/dispatch.d.ts +134 -0
- package/dist/utils/dco/dispatch.d.ts.map +1 -0
- package/dist/utils/dco/dispatch.js +399 -0
- package/dist/utils/dco/dispatch.js.map +1 -0
- package/dist/utils/dco/fix.d.ts +122 -0
- package/dist/utils/dco/fix.d.ts.map +1 -0
- package/dist/utils/dco/fix.js +560 -0
- package/dist/utils/dco/fix.js.map +1 -0
- package/dist/utils/dco/git-config.d.ts.map +1 -1
- package/dist/utils/dco/git-config.js +5 -3
- package/dist/utils/dco/git-config.js.map +1 -1
- package/dist/utils/dco/github.d.ts +101 -0
- package/dist/utils/dco/github.d.ts.map +1 -1
- package/dist/utils/dco/github.js +133 -0
- package/dist/utils/dco/github.js.map +1 -1
- package/dist/utils/dco/paths.d.ts +1 -8
- package/dist/utils/dco/paths.d.ts.map +1 -1
- package/dist/utils/dco/paths.js +3 -12
- package/dist/utils/dco/paths.js.map +1 -1
- package/dist/utils/dco/render.d.ts +1 -1
- package/dist/utils/dco/render.d.ts.map +1 -1
- package/dist/utils/dco/render.js +4 -21
- package/dist/utils/dco/render.js.map +1 -1
- package/dist/utils/dco/resolve-agent.d.ts +54 -0
- package/dist/utils/dco/resolve-agent.d.ts.map +1 -0
- package/dist/utils/dco/resolve-agent.js +164 -0
- package/dist/utils/dco/resolve-agent.js.map +1 -0
- package/dist/utils/dco/setup.d.ts +10 -7
- package/dist/utils/dco/setup.d.ts.map +1 -1
- package/dist/utils/dco/setup.js +264 -200
- package/dist/utils/dco/setup.js.map +1 -1
- package/dist/utils/dco/signing-key-writer.d.ts +40 -0
- package/dist/utils/dco/signing-key-writer.d.ts.map +1 -0
- package/dist/utils/dco/signing-key-writer.js +76 -0
- package/dist/utils/dco/signing-key-writer.js.map +1 -0
- package/dist/utils/dco/ssh-key.d.ts +50 -0
- package/dist/utils/dco/ssh-key.d.ts.map +1 -1
- package/dist/utils/dco/ssh-key.js +129 -8
- package/dist/utils/dco/ssh-key.js.map +1 -1
- package/dist/utils/dco/status.d.ts +1 -1
- package/dist/utils/dco/status.d.ts.map +1 -1
- package/dist/utils/dco/status.js +3 -3
- package/dist/utils/dco/status.js.map +1 -1
- package/dist/utils/dco/verify.d.ts +170 -0
- package/dist/utils/dco/verify.d.ts.map +1 -0
- package/dist/utils/dco/verify.js +550 -0
- package/dist/utils/dco/verify.js.map +1 -0
- package/dist/utils/dependency-installer.d.ts +37 -0
- package/dist/utils/dependency-installer.d.ts.map +1 -0
- package/dist/utils/dependency-installer.js +32 -0
- package/dist/utils/dependency-installer.js.map +1 -0
- package/dist/utils/github-credential-stage.d.ts +87 -0
- package/dist/utils/github-credential-stage.d.ts.map +1 -0
- package/dist/utils/github-credential-stage.js +168 -0
- package/dist/utils/github-credential-stage.js.map +1 -0
- package/dist/utils/github-credential.d.ts +160 -0
- package/dist/utils/github-credential.d.ts.map +1 -0
- package/dist/utils/github-credential.js +308 -0
- package/dist/utils/github-credential.js.map +1 -0
- package/dist/utils/gitignore.d.ts +17 -0
- package/dist/utils/gitignore.d.ts.map +1 -0
- package/dist/utils/gitignore.js +40 -0
- package/dist/utils/gitignore.js.map +1 -0
- package/dist/utils/hub-config.d.ts +21 -0
- package/dist/utils/hub-config.d.ts.map +1 -0
- package/dist/utils/hub-config.js +28 -0
- package/dist/utils/hub-config.js.map +1 -0
- package/dist/utils/identity-heal.d.ts +16 -0
- package/dist/utils/identity-heal.d.ts.map +1 -0
- package/dist/utils/identity-heal.js +37 -0
- package/dist/utils/identity-heal.js.map +1 -0
- package/dist/utils/init/pipeline.d.ts +74 -0
- package/dist/utils/init/pipeline.d.ts.map +1 -0
- package/dist/utils/init/pipeline.js +96 -0
- package/dist/utils/init/pipeline.js.map +1 -0
- package/dist/utils/poll.d.ts +15 -1
- package/dist/utils/poll.d.ts.map +1 -1
- package/dist/utils/poll.js +6 -3
- package/dist/utils/poll.js.map +1 -1
- package/dist/utils/register-agent-identity.d.ts +67 -0
- package/dist/utils/register-agent-identity.d.ts.map +1 -0
- package/dist/utils/register-agent-identity.js +34 -0
- package/dist/utils/register-agent-identity.js.map +1 -0
- package/dist/utils/review/did-web-key.d.ts +34 -0
- package/dist/utils/review/did-web-key.d.ts.map +1 -0
- package/dist/utils/review/did-web-key.js +104 -0
- package/dist/utils/review/did-web-key.js.map +1 -0
- package/dist/utils/review/load-registry.d.ts +33 -0
- package/dist/utils/review/load-registry.d.ts.map +1 -0
- package/dist/utils/review/load-registry.js +62 -0
- package/dist/utils/review/load-registry.js.map +1 -0
- package/dist/utils/review/verdict-verify.d.ts +43 -0
- package/dist/utils/review/verdict-verify.d.ts.map +1 -0
- package/dist/utils/review/verdict-verify.js +53 -0
- package/dist/utils/review/verdict-verify.js.map +1 -0
- package/dist/utils/review-registry-writer.d.ts +52 -0
- package/dist/utils/review-registry-writer.d.ts.map +1 -0
- package/dist/utils/review-registry-writer.js +79 -0
- package/dist/utils/review-registry-writer.js.map +1 -0
- package/dist/utils/should-install-dependency.d.ts +17 -0
- package/dist/utils/should-install-dependency.d.ts.map +1 -0
- package/dist/utils/should-install-dependency.js +25 -0
- package/dist/utils/should-install-dependency.js.map +1 -0
- package/dist/utils/tool-readiness.d.ts +57 -0
- package/dist/utils/tool-readiness.d.ts.map +1 -0
- package/dist/utils/tool-readiness.js +114 -0
- package/dist/utils/tool-readiness.js.map +1 -0
- package/dist/utils/which.d.ts +2 -0
- package/dist/utils/which.d.ts.map +1 -0
- package/dist/utils/which.js +22 -0
- package/dist/utils/which.js.map +1 -0
- package/dist/version.d.ts +15 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +29 -0
- package/dist/version.js.map +1 -0
- package/package.json +19 -6
- package/dist/utils/claim-polling.d.ts +0 -21
- package/dist/utils/claim-polling.d.ts.map +0 -1
- package/dist/utils/claim-polling.js.map +0 -1
- package/dist/utils/dco/fs-safe.d.ts +0 -14
- package/dist/utils/dco/fs-safe.d.ts.map +0 -1
- package/dist/utils/dco/fs-safe.js +0 -20
- package/dist/utils/dco/fs-safe.js.map +0 -1
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ledger MCP server.
|
|
3
|
+
*
|
|
4
|
+
* The orchestrator session's tool surface. This is the boundary that makes
|
|
5
|
+
* approach C work: the daemon owns anything whose correctness a test can
|
|
6
|
+
* check, and the session owns anything whose correctness requires an opinion.
|
|
7
|
+
* Every tool here enforces its invariant in SQL, so a model cannot reason its
|
|
8
|
+
* way past one.
|
|
9
|
+
*
|
|
10
|
+
* Two absences are load-bearing:
|
|
11
|
+
*
|
|
12
|
+
* - There is NO tool that creates a Linear issue, and none by which the
|
|
13
|
+
* SESSION can create a ticket. That is about the session specifically: the
|
|
14
|
+
* ledger does hold agent-native tickets (linear_id NULL), and the daemon
|
|
15
|
+
* writes those deterministically from protocol events. What must not exist
|
|
16
|
+
* is a path by which a model decides, on its own reading of a situation,
|
|
17
|
+
* that some new work exists. A finding it wants to raise goes in the
|
|
18
|
+
* journal, and a human promotes it. Without this absence that policy would
|
|
19
|
+
* be a sentence in a prompt instead of a property of the surface.
|
|
20
|
+
* - There is NO tool that sets the mission note. Reading it is the point;
|
|
21
|
+
* writing it is the operator's. A session that can rewrite its own standing
|
|
22
|
+
* objective is not following one, and would drift toward whatever it last
|
|
23
|
+
* found interesting.
|
|
24
|
+
* - There is NO delete tool, for the same reason the store has no delete
|
|
25
|
+
* path: a bad autonomous close and a clean backlog are indistinguishable
|
|
26
|
+
* once the row is gone.
|
|
27
|
+
*
|
|
28
|
+
* JSON-RPC 2.0 is hand-rolled rather than pulled from the MCP SDK, matching
|
|
29
|
+
* `fleet-mcp.ts` in @kya-os/compute. It keeps a dependency out of a published
|
|
30
|
+
* CLI for what amounts to a switch statement.
|
|
31
|
+
*
|
|
32
|
+
* @module cli/orchestrator/mcp/server
|
|
33
|
+
*/
|
|
34
|
+
import { randomUUID } from "node:crypto";
|
|
35
|
+
import { z } from "zod";
|
|
36
|
+
import { getTicket, claimNextTicket, closeTicket, setTicketStatus, listTickets, TicketStatusSchema, SettableTicketStatusSchema, SETTABLE_TICKET_STATUSES, } from "../db/tickets.js";
|
|
37
|
+
import { appendJournal, listJournal, listJournalForTicket } from "../db/journal.js";
|
|
38
|
+
import { listDispatches, getDispatch } from "../db/dispatches.js";
|
|
39
|
+
import { readLiveness, judgeLiveness } from "../db/liveness.js";
|
|
40
|
+
import { currentMissionNote } from "../db/mission.js";
|
|
41
|
+
/**
|
|
42
|
+
* The MCP revision this server speaks.
|
|
43
|
+
*
|
|
44
|
+
* Named rather than inlined in the handshake response, so the version this
|
|
45
|
+
* server actually implements is greppable and changes in one place. Deliberately
|
|
46
|
+
* NOT echoed back from the client's request: the handshake exists for the client
|
|
47
|
+
* to discover what the server supports, and reflecting whatever it asked for
|
|
48
|
+
* would claim support for revisions this code has never been tested against,
|
|
49
|
+
* turning the one honest signal in the exchange into a mirror.
|
|
50
|
+
*/
|
|
51
|
+
export const MCP_PROTOCOL_VERSION = "2025-03-26";
|
|
52
|
+
/**
|
|
53
|
+
* Row cap shared by every list tool.
|
|
54
|
+
*
|
|
55
|
+
* journal.list capped and the others did not, which contradicted this file's own
|
|
56
|
+
* reason for capping: a model must not be able to ask for the whole table. The
|
|
57
|
+
* cap is uniform so the reason applies uniformly.
|
|
58
|
+
*/
|
|
59
|
+
export const MAX_ROWS = 500;
|
|
60
|
+
/** Serialised size limit for a session-written journal payload. */
|
|
61
|
+
export const MAX_EVENT_DATA_BYTES = 8000;
|
|
62
|
+
/** Size limit for a session-written event type. */
|
|
63
|
+
export const MAX_EVENT_TYPE_BYTES = 120;
|
|
64
|
+
/**
|
|
65
|
+
* Length limit for a ticket id arriving from the session.
|
|
66
|
+
*
|
|
67
|
+
* Generous next to the ids this ledger mints (a UUID is 36 characters), because
|
|
68
|
+
* its job is to refuse the absurd, not to second-guess the id format.
|
|
69
|
+
*/
|
|
70
|
+
export const MAX_TICKET_ID_LENGTH = 200;
|
|
71
|
+
/**
|
|
72
|
+
* Force a session-authored event into its own namespace.
|
|
73
|
+
*
|
|
74
|
+
* Idempotent, so a caller that already prefixes does not end up with
|
|
75
|
+
* `session.session.x`.
|
|
76
|
+
*/
|
|
77
|
+
export function sessionEventType(raw) {
|
|
78
|
+
const bare = raw.startsWith(SESSION_EVENT_PREFIX) ? raw.slice(SESSION_EVENT_PREFIX.length) : raw;
|
|
79
|
+
return `${SESSION_EVENT_PREFIX}${bare}`;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The statuses this surface may SET.
|
|
83
|
+
*
|
|
84
|
+
* `claimed` and `closed` each have a dedicated tool that carries something a
|
|
85
|
+
* bare status write cannot: an atomic claim, and a recorded close reason.
|
|
86
|
+
*
|
|
87
|
+
* The definition itself now lives in the store, which is the layer that has to
|
|
88
|
+
* hold the line for callers that never pass through this file. Re-exported here
|
|
89
|
+
* so the advertised JSON Schema, the Zod enforcement and the store's own guard
|
|
90
|
+
* are provably the same list -- they used to be written twice, with Zod holding
|
|
91
|
+
* the real enum while the advertised schema said `{ type: "string" }`, so the
|
|
92
|
+
* model learned the actual constraint only by guessing and reading the error
|
|
93
|
+
* back.
|
|
94
|
+
*/
|
|
95
|
+
export { SettableTicketStatusSchema, SETTABLE_TICKET_STATUSES };
|
|
96
|
+
export const TICKET_STATUSES = TicketStatusSchema.options;
|
|
97
|
+
/** Namespace for anything the orchestrator session writes to the journal. */
|
|
98
|
+
export const SESSION_EVENT_PREFIX = "session.";
|
|
99
|
+
/**
|
|
100
|
+
* Record that the SESSION moved a ticket, in the caller's transaction.
|
|
101
|
+
*
|
|
102
|
+
* Journaled HERE and not inside the store, deliberately. The store is also the
|
|
103
|
+
* path the daemon's review reactor writes through, and that reactor already
|
|
104
|
+
* emits its own `ticket_status_changed` alongside the status write -- so a row
|
|
105
|
+
* added down in `setTicketStatus` would double-record every protocol-driven
|
|
106
|
+
* transition. The layer that is unique to a model acting on its own is this one,
|
|
107
|
+
* and "the session did this" is exactly the fact that was missing.
|
|
108
|
+
*
|
|
109
|
+
* The gap it closes: a model could call setStatus{open} on a ticket another
|
|
110
|
+
* worker held. The SQL guard clears `claimed_by`, so the row stays consistent,
|
|
111
|
+
* but the worker still walked away believing it held the ticket -- and nothing
|
|
112
|
+
* anywhere recorded when it stopped holding it or who decided that. A ledger
|
|
113
|
+
* whose whole purpose is auditable history had no answer.
|
|
114
|
+
*/
|
|
115
|
+
function journalSessionMutation(db, ticketId, type, data) {
|
|
116
|
+
const written = appendJournal(db, {
|
|
117
|
+
event: {
|
|
118
|
+
type: sessionEventType(type),
|
|
119
|
+
timestamp: Date.now(),
|
|
120
|
+
agentDid: "",
|
|
121
|
+
agentName: "orchestrator",
|
|
122
|
+
data: { ticketId, ...data },
|
|
123
|
+
},
|
|
124
|
+
ticketId,
|
|
125
|
+
// A fresh id per occurrence, NOT the content hash. Two identical
|
|
126
|
+
// transitions in the same millisecond are two acts, and the default
|
|
127
|
+
// content-addressed id -- right for replayed hub observations -- dropped
|
|
128
|
+
// the second on its OR IGNORE while the ticket write committed. Evidence
|
|
129
|
+
// that can be deduplicated away is exactly the hole this closes.
|
|
130
|
+
id: randomUUID(),
|
|
131
|
+
});
|
|
132
|
+
// Belt and braces on the invariant this function exists for: an id collision
|
|
133
|
+
// here would mean state moved with nothing recording it, and silence is the
|
|
134
|
+
// one outcome this must never produce.
|
|
135
|
+
if (!written) {
|
|
136
|
+
throw new Error(`orchestrator: failed to journal ${type} for ticket ${ticketId}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* What a transition released, if anything.
|
|
141
|
+
*
|
|
142
|
+
* Only `claimed` carries a holder, and this surface cannot set `claimed`, so any
|
|
143
|
+
* move out of it is a release. Naming the displaced worker in the row is the
|
|
144
|
+
* point: "status changed" alone would not tell whoever is debugging that someone
|
|
145
|
+
* lost a ticket they thought they had.
|
|
146
|
+
*/
|
|
147
|
+
function releasedClaim(before) {
|
|
148
|
+
return before?.status === "claimed" && before.claimed_by
|
|
149
|
+
? { releasedClaimOf: before.claimed_by }
|
|
150
|
+
: {};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* The payload a session-authored journal row actually stores.
|
|
154
|
+
*
|
|
155
|
+
* One definition, shared by the schema that bounds it and the handler that
|
|
156
|
+
* writes it. Two copies of this composition is precisely how the size limit
|
|
157
|
+
* came to guard a value that was not the one being written.
|
|
158
|
+
*/
|
|
159
|
+
export function sessionEventPayload(data, note) {
|
|
160
|
+
return note === undefined ? data : { ...data, note };
|
|
161
|
+
}
|
|
162
|
+
/** Arguments each tool accepts, validated before it touches the ledger. */
|
|
163
|
+
const ArgSchemas = {
|
|
164
|
+
"ledger.tickets.list": z.object({
|
|
165
|
+
status: TicketStatusSchema.optional(),
|
|
166
|
+
limit: z.number().int().positive().max(MAX_ROWS).default(MAX_ROWS),
|
|
167
|
+
}),
|
|
168
|
+
"ledger.tickets.get": z.object({ id: z.string().min(1) }),
|
|
169
|
+
"ledger.tickets.claim": z.object({ workerDid: z.string().min(1) }),
|
|
170
|
+
"ledger.tickets.close": z.object({
|
|
171
|
+
id: z.string().min(1),
|
|
172
|
+
reason: z.string().min(1),
|
|
173
|
+
supersededBy: z.string().min(1).optional(),
|
|
174
|
+
}),
|
|
175
|
+
"ledger.tickets.setStatus": z.object({
|
|
176
|
+
id: z.string().min(1),
|
|
177
|
+
// 'closed' and 'claimed' are deliberately excluded. Each has its own
|
|
178
|
+
// atomic, invariant-preserving path, and this generic setter is a plain
|
|
179
|
+
// `UPDATE ... WHERE id = ?` that would let a caller reach the same state
|
|
180
|
+
// while skipping it:
|
|
181
|
+
// - 'closed' -> ledger.tickets.close, which requires a reason. Reaching
|
|
182
|
+
// it here would leave a null closed_reason -- exactly the audit trail
|
|
183
|
+
// the no-delete rule exists to preserve.
|
|
184
|
+
// - 'claimed' -> ledger.tickets.claim, whose single atomic UPDATE marks
|
|
185
|
+
// claimed_by/claimed_at together with the status change, so two
|
|
186
|
+
// callers racing the same open ticket cannot both win. This setter
|
|
187
|
+
// touches neither column and has no `WHERE status = 'open'` guard, so
|
|
188
|
+
// allowing 'claimed' through here would let two callers both "claim"
|
|
189
|
+
// one ticket, or land it in 'claimed' with claimed_by/claimed_at
|
|
190
|
+
// still null -- permanently invisible to claimNextTicket's own query
|
|
191
|
+
// and orphaned for good.
|
|
192
|
+
status: SettableTicketStatusSchema,
|
|
193
|
+
}),
|
|
194
|
+
"ledger.journal.append": z.object({
|
|
195
|
+
// Bounded in BYTES like the payload below it, not in UTF-16 code units. A
|
|
196
|
+
// Zod `.max()` on a string counts code units, so `max(120)` admitted 120 CJK
|
|
197
|
+
// characters and stored 360 bytes -- the same measurement error the payload
|
|
198
|
+
// cap sheds, sitting one property away in the same object.
|
|
199
|
+
eventType: z
|
|
200
|
+
.string()
|
|
201
|
+
.min(1)
|
|
202
|
+
.refine((s) => Buffer.byteLength(s, "utf8") <= MAX_EVENT_TYPE_BYTES, {
|
|
203
|
+
message: `eventType must be at most ${MAX_EVENT_TYPE_BYTES} UTF-8 bytes`,
|
|
204
|
+
}),
|
|
205
|
+
data: z
|
|
206
|
+
.record(z.unknown())
|
|
207
|
+
.default({}),
|
|
208
|
+
// Bounded so the refusal comes from this schema rather than from
|
|
209
|
+
// `FOREIGN KEY constraint failed` -- which is to say, rather than from
|
|
210
|
+
// db.pragma("foreign_keys = ON"), a per-connection setting SQLite defaults
|
|
211
|
+
// to OFF. Any other opener of the ledger file that forgets the pragma would
|
|
212
|
+
// otherwise write a multi-megabyte id straight past the payload cap.
|
|
213
|
+
ticketId: z.string().min(1).max(MAX_TICKET_ID_LENGTH).optional(),
|
|
214
|
+
note: z.string().optional(),
|
|
215
|
+
})
|
|
216
|
+
// Bounded because the journal is append-only and a model that decides to
|
|
217
|
+
// paste a diff into a row writes something nothing can later trim.
|
|
218
|
+
//
|
|
219
|
+
// The check is on the payload that actually gets STORED, not on one of the
|
|
220
|
+
// arguments it is built from. It used to sit on `data` alone while the
|
|
221
|
+
// stored row was `data` merged with `note`, so a tiny data object plus a
|
|
222
|
+
// multi-megabyte note sailed straight past a limit named for exactly that.
|
|
223
|
+
// Bounding the composed value means a field added to the payload later is
|
|
224
|
+
// covered without anyone remembering to extend this.
|
|
225
|
+
//
|
|
226
|
+
// Measured in UTF-8 BYTES, which is both what the name says and what SQLite
|
|
227
|
+
// stores. `String#length` counts UTF-16 code units, so a CJK payload cost a
|
|
228
|
+
// third of its real size against the budget and most emoji a half: the limit
|
|
229
|
+
// that exists to bound an append-only table was letting non-ASCII text bank
|
|
230
|
+
// several times the advertised allowance.
|
|
231
|
+
.refine((a) => Buffer.byteLength(JSON.stringify(sessionEventPayload(a.data, a.note)), "utf8") <=
|
|
232
|
+
MAX_EVENT_DATA_BYTES, {
|
|
233
|
+
message: `data and note together must serialise to at most ${MAX_EVENT_DATA_BYTES} UTF-8 bytes`,
|
|
234
|
+
}),
|
|
235
|
+
"ledger.journal.list": z.object({
|
|
236
|
+
limit: z.number().int().positive().max(MAX_ROWS).default(50),
|
|
237
|
+
ticketId: z.string().min(1).optional(),
|
|
238
|
+
}),
|
|
239
|
+
"ledger.dispatches.list": z.object({
|
|
240
|
+
limit: z.number().int().positive().max(MAX_ROWS).default(MAX_ROWS),
|
|
241
|
+
}),
|
|
242
|
+
// Both read-only and single-valued, so neither needs a row cap.
|
|
243
|
+
"ledger.mission.get": z.object({}),
|
|
244
|
+
"ledger.daemon.liveness": z.object({}),
|
|
245
|
+
"ledger.dispatches.get": z.object({ taskId: z.string().min(1) }),
|
|
246
|
+
};
|
|
247
|
+
export const LEDGER_TOOLS = [
|
|
248
|
+
{
|
|
249
|
+
name: "ledger.tickets.list",
|
|
250
|
+
description: "List tickets, optionally filtered by status (open, claimed, in-progress, in-review, blocked, ready, closed).",
|
|
251
|
+
inputSchema: {
|
|
252
|
+
type: "object",
|
|
253
|
+
properties: {
|
|
254
|
+
status: {
|
|
255
|
+
type: "string",
|
|
256
|
+
enum: TICKET_STATUSES,
|
|
257
|
+
description: "Filter by status",
|
|
258
|
+
},
|
|
259
|
+
limit: {
|
|
260
|
+
type: "number",
|
|
261
|
+
minimum: 1,
|
|
262
|
+
maximum: MAX_ROWS,
|
|
263
|
+
description: `Maximum rows to return (1-${MAX_ROWS}, default ${MAX_ROWS}); returns the most recent`,
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
name: "ledger.tickets.get",
|
|
270
|
+
description: "Fetch one ticket by id.",
|
|
271
|
+
inputSchema: {
|
|
272
|
+
type: "object",
|
|
273
|
+
properties: { id: { type: "string" } },
|
|
274
|
+
required: ["id"],
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
name: "ledger.tickets.claim",
|
|
279
|
+
description: "Atomically claim the oldest open ticket for a worker. Returns null when nothing is claimable, which is an ordinary outcome. The claim is a single SQL statement, so two callers racing cannot both win.",
|
|
280
|
+
inputSchema: {
|
|
281
|
+
type: "object",
|
|
282
|
+
properties: { workerDid: { type: "string" } },
|
|
283
|
+
required: ["workerDid"],
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
name: "ledger.tickets.close",
|
|
288
|
+
description: "Close a ticket with a reason. The row stays selectable; nothing is ever deleted.",
|
|
289
|
+
inputSchema: {
|
|
290
|
+
type: "object",
|
|
291
|
+
properties: {
|
|
292
|
+
id: { type: "string" },
|
|
293
|
+
reason: { type: "string" },
|
|
294
|
+
supersededBy: { type: "string", description: "Ticket that replaces this one" },
|
|
295
|
+
},
|
|
296
|
+
required: ["id", "reason"],
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
name: "ledger.tickets.setStatus",
|
|
301
|
+
description: "Move a ticket to a new status. Use 'blocked' for work stalled on a human decision. " +
|
|
302
|
+
"Cannot set 'claimed' (use ledger.tickets.claim) or 'closed' (use ledger.tickets.close) -- " +
|
|
303
|
+
"both require their dedicated tool to keep the claim atomic and the close reason recorded.",
|
|
304
|
+
inputSchema: {
|
|
305
|
+
type: "object",
|
|
306
|
+
properties: {
|
|
307
|
+
id: { type: "string" },
|
|
308
|
+
status: { type: "string", enum: SETTABLE_TICKET_STATUSES },
|
|
309
|
+
},
|
|
310
|
+
required: ["id", "status"],
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
name: "ledger.journal.append",
|
|
315
|
+
description: "Record an observation. This is where a finding goes: the orchestrator has no way to file a ticket, so surfacing something for a human to triage means writing it here. eventType is stored under a `session.` prefix, so session-authored rows are always distinguishable from protocol events the daemon recorded.",
|
|
316
|
+
inputSchema: {
|
|
317
|
+
type: "object",
|
|
318
|
+
properties: {
|
|
319
|
+
eventType: {
|
|
320
|
+
type: "string",
|
|
321
|
+
description: `Stored under a \`session.\` prefix; at most ${MAX_EVENT_TYPE_BYTES} UTF-8 bytes`,
|
|
322
|
+
},
|
|
323
|
+
data: {
|
|
324
|
+
type: "object",
|
|
325
|
+
description: `Serialises, together with note, to at most ${MAX_EVENT_DATA_BYTES} UTF-8 bytes`,
|
|
326
|
+
},
|
|
327
|
+
ticketId: { type: "string" },
|
|
328
|
+
note: { type: "string" },
|
|
329
|
+
},
|
|
330
|
+
required: ["eventType"],
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
name: "ledger.journal.list",
|
|
335
|
+
description: "Recent observations, newest first. Optionally scoped to one ticket.",
|
|
336
|
+
inputSchema: {
|
|
337
|
+
type: "object",
|
|
338
|
+
properties: {
|
|
339
|
+
limit: {
|
|
340
|
+
type: "number",
|
|
341
|
+
minimum: 1,
|
|
342
|
+
maximum: MAX_ROWS,
|
|
343
|
+
description: `Maximum rows to return (1-${MAX_ROWS}, default 50)`,
|
|
344
|
+
},
|
|
345
|
+
ticketId: { type: "string" },
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
name: "ledger.mission.get",
|
|
351
|
+
description: "The operator's standing mission note: what this orchestrator is currently trying to achieve. Read this on waking. There is deliberately no setter -- a session that could rewrite its own objective is not following one.",
|
|
352
|
+
inputSchema: { type: "object", properties: {} },
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
name: "ledger.daemon.liveness",
|
|
356
|
+
description: "Whether the daemon writing this ledger is still alive. `stale: true` means the ledger is no longer being updated, so an empty result means nothing is happening rather than nothing exists.",
|
|
357
|
+
inputSchema: { type: "object", properties: {} },
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
name: "ledger.dispatches.list",
|
|
361
|
+
description: "Every task handed to a worker.",
|
|
362
|
+
inputSchema: {
|
|
363
|
+
type: "object",
|
|
364
|
+
properties: {
|
|
365
|
+
limit: {
|
|
366
|
+
type: "number",
|
|
367
|
+
minimum: 1,
|
|
368
|
+
maximum: MAX_ROWS,
|
|
369
|
+
description: `Maximum rows to return (1-${MAX_ROWS}, default ${MAX_ROWS})`,
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
},
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
name: "ledger.dispatches.get",
|
|
376
|
+
description: "One dispatch by task id.",
|
|
377
|
+
inputSchema: {
|
|
378
|
+
type: "object",
|
|
379
|
+
properties: { taskId: { type: "string" } },
|
|
380
|
+
required: ["taskId"],
|
|
381
|
+
},
|
|
382
|
+
},
|
|
383
|
+
];
|
|
384
|
+
/**
|
|
385
|
+
* Run one tool against the ledger.
|
|
386
|
+
*
|
|
387
|
+
* Exported separately from the RPC plumbing so tests exercise the tool
|
|
388
|
+
* semantics without speaking JSON-RPC, and so the invariants are testable in
|
|
389
|
+
* isolation from the transport.
|
|
390
|
+
*/
|
|
391
|
+
export function callLedgerTool(db, name, rawArgs) {
|
|
392
|
+
if (!(name in ArgSchemas)) {
|
|
393
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
394
|
+
}
|
|
395
|
+
const schema = ArgSchemas[name];
|
|
396
|
+
// Parse, never cast. These arguments come from a language model, which is
|
|
397
|
+
// the least trustworthy caller in the system: it will confidently pass a
|
|
398
|
+
// number where a string belongs and a status that does not exist.
|
|
399
|
+
const args = schema.parse(rawArgs ?? {});
|
|
400
|
+
switch (name) {
|
|
401
|
+
case "ledger.tickets.list": {
|
|
402
|
+
const a = args;
|
|
403
|
+
return listTickets(db, a.status, a.limit);
|
|
404
|
+
}
|
|
405
|
+
case "ledger.tickets.get":
|
|
406
|
+
return getTicket(db, args.id) ?? null;
|
|
407
|
+
// The three mutating cases each pair their write with its evidence in ONE
|
|
408
|
+
// transaction. A refused write throws, the transaction rolls back, and no
|
|
409
|
+
// row is left behind -- the journal must only ever hold transitions the
|
|
410
|
+
// table actually took, or it stops being evidence and becomes a second
|
|
411
|
+
// opinion.
|
|
412
|
+
case "ledger.tickets.claim": {
|
|
413
|
+
const workerDid = args.workerDid;
|
|
414
|
+
return db.transaction(() => {
|
|
415
|
+
const claimed = claimNextTicket(db, workerDid);
|
|
416
|
+
// null is an ordinary outcome (nothing claimable) and not an event.
|
|
417
|
+
if (claimed !== null) {
|
|
418
|
+
journalSessionMutation(db, claimed.id, "ticket_claimed", {
|
|
419
|
+
workerDid,
|
|
420
|
+
to: "claimed",
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
return claimed;
|
|
424
|
+
})();
|
|
425
|
+
}
|
|
426
|
+
case "ledger.tickets.close": {
|
|
427
|
+
const a = args;
|
|
428
|
+
return db.transaction(() => {
|
|
429
|
+
const before = getTicket(db, a.id);
|
|
430
|
+
const closed = closeTicket(db, a.id, a.reason, a.supersededBy);
|
|
431
|
+
journalSessionMutation(db, closed.id, "ticket_status_changed", {
|
|
432
|
+
from: before?.status ?? null,
|
|
433
|
+
to: "closed",
|
|
434
|
+
reason: a.reason,
|
|
435
|
+
...releasedClaim(before),
|
|
436
|
+
});
|
|
437
|
+
return closed;
|
|
438
|
+
})();
|
|
439
|
+
}
|
|
440
|
+
case "ledger.tickets.setStatus": {
|
|
441
|
+
const a = args;
|
|
442
|
+
return db.transaction(() => {
|
|
443
|
+
const before = getTicket(db, a.id);
|
|
444
|
+
const moved = setTicketStatus(db, a.id, a.status);
|
|
445
|
+
journalSessionMutation(db, moved.id, "ticket_status_changed", {
|
|
446
|
+
from: before?.status ?? null,
|
|
447
|
+
to: a.status,
|
|
448
|
+
...releasedClaim(before),
|
|
449
|
+
});
|
|
450
|
+
return moved;
|
|
451
|
+
})();
|
|
452
|
+
}
|
|
453
|
+
case "ledger.journal.append": {
|
|
454
|
+
const a = args;
|
|
455
|
+
const written = appendJournal(db, {
|
|
456
|
+
event: {
|
|
457
|
+
// NAMESPACED, not merely validated. An unconstrained eventType let a
|
|
458
|
+
// session write `task_completed` or `review_verdict` rows that were
|
|
459
|
+
// distinguishable from daemon-recorded protocol events by convention
|
|
460
|
+
// alone -- which breaks the premise the whole ledger rests on, that
|
|
461
|
+
// the journal is evidence of what the protocol did rather than what a
|
|
462
|
+
// model asserted. Prefixing here makes the separation structural: it
|
|
463
|
+
// holds whatever the model sends, instead of depending on it complying.
|
|
464
|
+
type: sessionEventType(a.eventType),
|
|
465
|
+
timestamp: Date.now(),
|
|
466
|
+
agentDid: "",
|
|
467
|
+
agentName: "orchestrator",
|
|
468
|
+
data: sessionEventPayload(a.data, a.note),
|
|
469
|
+
},
|
|
470
|
+
ticketId: a.ticketId ?? null,
|
|
471
|
+
});
|
|
472
|
+
return { recorded: written };
|
|
473
|
+
}
|
|
474
|
+
case "ledger.journal.list": {
|
|
475
|
+
const a = args;
|
|
476
|
+
return a.ticketId
|
|
477
|
+
? listJournalForTicket(db, a.ticketId, a.limit)
|
|
478
|
+
: listJournal(db, a.limit);
|
|
479
|
+
}
|
|
480
|
+
case "ledger.mission.get":
|
|
481
|
+
return currentMissionNote(db) ?? null;
|
|
482
|
+
case "ledger.daemon.liveness":
|
|
483
|
+
return judgeLiveness(readLiveness(db), Date.now());
|
|
484
|
+
case "ledger.dispatches.list":
|
|
485
|
+
// The cap goes to SQL rather than to a slice on the result: the table only
|
|
486
|
+
// grows, so trimming afterwards bounds the answer without bounding the
|
|
487
|
+
// work the answer cost.
|
|
488
|
+
return listDispatches(db, args.limit);
|
|
489
|
+
case "ledger.dispatches.get":
|
|
490
|
+
return getDispatch(db, args.taskId) ?? null;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Handle one JSON-RPC request.
|
|
495
|
+
*
|
|
496
|
+
* Errors become JSON-RPC errors rather than thrown exceptions, because a
|
|
497
|
+
* thrown error here kills the stdio loop and takes every subsequent tool call
|
|
498
|
+
* with it. A tool that fails should fail one call.
|
|
499
|
+
*/
|
|
500
|
+
export function handleLedgerRpc(db, req) {
|
|
501
|
+
// JSON.parse succeeds for null, arrays, numbers and strings, and reading
|
|
502
|
+
// .id/.method off those throws. A throw here is outside every try/catch
|
|
503
|
+
// below, so one malformed frame would end the stdio loop and take every
|
|
504
|
+
// later call with it.
|
|
505
|
+
if (typeof req !== "object" || req === null || Array.isArray(req)) {
|
|
506
|
+
return {
|
|
507
|
+
jsonrpc: "2.0",
|
|
508
|
+
id: null,
|
|
509
|
+
error: { code: -32600, message: "Invalid Request: expected a JSON-RPC object" },
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
const method = typeof req.method === "string" ? req.method : "";
|
|
513
|
+
if (!method) {
|
|
514
|
+
return {
|
|
515
|
+
jsonrpc: "2.0",
|
|
516
|
+
id: req.id ?? null,
|
|
517
|
+
error: { code: -32600, message: "Invalid Request: missing method" },
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
// A frame with no id is a NOTIFICATION and must never be answered, whatever
|
|
521
|
+
// its method. Answering one desynchronises the stream: the client may read
|
|
522
|
+
// the reply as the response to a different request. Only initialized was
|
|
523
|
+
// handled before, so notifications/cancelled and anything the client
|
|
524
|
+
// invented got a method-not-found frame back.
|
|
525
|
+
const isNotification = req.id === undefined || req.id === null;
|
|
526
|
+
if (isNotification)
|
|
527
|
+
return null;
|
|
528
|
+
const id = req.id;
|
|
529
|
+
switch (method) {
|
|
530
|
+
case "initialize":
|
|
531
|
+
return {
|
|
532
|
+
jsonrpc: "2.0",
|
|
533
|
+
id,
|
|
534
|
+
result: {
|
|
535
|
+
protocolVersion: MCP_PROTOCOL_VERSION,
|
|
536
|
+
capabilities: { tools: {} },
|
|
537
|
+
serverInfo: { name: "@kya-os/orchestrator-ledger", version: "0.1.0" },
|
|
538
|
+
},
|
|
539
|
+
};
|
|
540
|
+
case "tools/list":
|
|
541
|
+
return { jsonrpc: "2.0", id, result: { tools: LEDGER_TOOLS } };
|
|
542
|
+
case "tools/call": {
|
|
543
|
+
const name = req.params?.["name"] ?? "";
|
|
544
|
+
try {
|
|
545
|
+
const value = callLedgerTool(db, name, req.params?.["arguments"]);
|
|
546
|
+
return {
|
|
547
|
+
jsonrpc: "2.0",
|
|
548
|
+
id,
|
|
549
|
+
result: { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] },
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
catch (err) {
|
|
553
|
+
// A tool that RAN and failed is not a malformed request. Per the MCP
|
|
554
|
+
// spec an execution failure belongs in the result with isError, so the
|
|
555
|
+
// model can read what went wrong and react; a JSON-RPC error is a
|
|
556
|
+
// transport-level fault and many clients surface it as a broken server
|
|
557
|
+
// rather than as feedback. -32602 ("Invalid params") was doubly wrong
|
|
558
|
+
// for a domain refusal like "that ticket is already closed".
|
|
559
|
+
return {
|
|
560
|
+
jsonrpc: "2.0",
|
|
561
|
+
id,
|
|
562
|
+
result: {
|
|
563
|
+
content: [
|
|
564
|
+
{
|
|
565
|
+
type: "text",
|
|
566
|
+
text: err instanceof Error ? err.message : String(err),
|
|
567
|
+
},
|
|
568
|
+
],
|
|
569
|
+
isError: true,
|
|
570
|
+
},
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
default:
|
|
575
|
+
return {
|
|
576
|
+
jsonrpc: "2.0",
|
|
577
|
+
id,
|
|
578
|
+
error: { code: -32601, message: `Method not found: ${method}` },
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/orchestrator/mcp/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,SAAS,EACT,eAAe,EACf,WAAW,EACX,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,0BAA0B,EAC1B,wBAAwB,GAIzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,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ClB,MAAM,IAAI,GAAI,GAAG,CAAC,MAAM,EAAE,CAAC,MAAM,CAAwB,IAAI,EAAE,CAAC;YAChE,IAAI,CAAC;gBACH,MAAM,KAAK,GAAG,cAAc,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;gBAClE,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,EAAE;oBACF,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE;iBAC9E,CAAC;YACJ,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,qEAAqE;gBACrE,uEAAuE;gBACvE,kEAAkE;gBAClE,uEAAuE;gBACvE,sEAAsE;gBACtE,6DAA6D;gBAC7D,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,EAAE;oBACF,MAAM,EAAE;wBACN,OAAO,EAAE;4BACP;gCACE,IAAI,EAAE,MAAM;gCACZ,IAAI,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;6BACvD;yBACF;wBACD,OAAO,EAAE,IAAI;qBACd;iBACF,CAAC;YACJ,CAAC;QACH,CAAC;QACD;YACE,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,EAAE;gBACF,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,qBAAqB,MAAM,EAAE,EAAE;aAChE,CAAC;IACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* stdio transport for the ledger MCP server.
|
|
3
|
+
*
|
|
4
|
+
* Newline-delimited JSON-RPC on stdin/stdout, which is how a local MCP client
|
|
5
|
+
* (an orchestrator session) speaks to a server it spawned.
|
|
6
|
+
*
|
|
7
|
+
* @module cli/orchestrator/mcp/stdio
|
|
8
|
+
*/
|
|
9
|
+
import type { Ledger } from "../db/index.js";
|
|
10
|
+
export interface StdioOptions {
|
|
11
|
+
input?: NodeJS.ReadableStream;
|
|
12
|
+
output?: NodeJS.WritableStream;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Serve until stdin closes.
|
|
16
|
+
*
|
|
17
|
+
* Nothing here writes to stdout except protocol frames. A stray console.log
|
|
18
|
+
* would be parsed by the client as a malformed message and desynchronise the
|
|
19
|
+
* stream, so diagnostics go to stderr, always.
|
|
20
|
+
*/
|
|
21
|
+
export declare function serveLedgerStdio(db: Ledger, opts?: StdioOptions): Promise<void>;
|
|
22
|
+
//# sourceMappingURL=stdio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../../../src/orchestrator/mcp/stdio.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAG7C,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;CAChC;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkCnF"}
|