@martinloop/mcp 0.3.9 → 0.5.0

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.
Files changed (96) hide show
  1. package/README.md +82 -141
  2. package/dist/discovery-metadata.d.ts +1 -1
  3. package/dist/discovery-metadata.js +1 -1
  4. package/dist/resources.d.ts +1 -2
  5. package/dist/resources.js +47 -95
  6. package/dist/server-validation.d.ts +1 -1
  7. package/dist/server-validation.js +16 -11
  8. package/dist/server.d.ts +23 -0
  9. package/dist/server.js +152 -7
  10. package/dist/tools/preflight.d.ts +2 -0
  11. package/dist/tools/preflight.js +42 -2
  12. package/dist/tools/run-dossier.d.ts +3 -1
  13. package/dist/tools/run-dossier.js +40 -2
  14. package/dist/tools/run-loop.d.ts +1 -4
  15. package/dist/tools/run-loop.js +6 -15
  16. package/dist/tools/tool-support.d.ts +2 -1
  17. package/dist/tools/tool-support.js +1 -12
  18. package/dist/vendor/adapters/claude-cli.js +38 -35
  19. package/dist/vendor/adapters/cli-bridge.d.ts +9 -1
  20. package/dist/vendor/adapters/cli-bridge.js +54 -13
  21. package/dist/vendor/adapters/codex-launcher.d.ts +61 -1
  22. package/dist/vendor/adapters/codex-launcher.js +118 -19
  23. package/dist/vendor/adapters/index.d.ts +1 -3
  24. package/dist/vendor/adapters/index.js +1 -3
  25. package/dist/vendor/adapters/openai-compatible.js +51 -12
  26. package/dist/vendor/contracts/adapter-capabilities.d.ts +1 -1
  27. package/dist/vendor/contracts/context-handoff.d.ts +100 -0
  28. package/dist/vendor/contracts/context-handoff.js +11 -0
  29. package/dist/vendor/contracts/context-manifest.d.ts +195 -0
  30. package/dist/vendor/contracts/context-manifest.js +17 -0
  31. package/dist/vendor/contracts/context-shadow.d.ts +75 -0
  32. package/dist/vendor/contracts/context-shadow.js +8 -0
  33. package/dist/vendor/contracts/delivery.d.ts +47 -0
  34. package/dist/vendor/contracts/delivery.js +18 -0
  35. package/dist/vendor/contracts/exits.d.ts +126 -0
  36. package/dist/vendor/contracts/exits.js +32 -0
  37. package/dist/vendor/contracts/index.d.ts +41 -2
  38. package/dist/vendor/contracts/index.js +24 -0
  39. package/dist/vendor/contracts/mission.d.ts +102 -0
  40. package/dist/vendor/contracts/mission.js +64 -0
  41. package/dist/vendor/contracts/operator.d.ts +3 -1
  42. package/dist/vendor/contracts/operator.js +2 -1
  43. package/dist/vendor/contracts/verified-handoff.d.ts +100 -0
  44. package/dist/vendor/contracts/verified-handoff.js +35 -0
  45. package/dist/vendor/core/context-chain-gate.d.ts +89 -0
  46. package/dist/vendor/core/context-chain-gate.js +173 -0
  47. package/dist/vendor/core/context-compiler.d.ts +53 -0
  48. package/dist/vendor/core/context-compiler.js +261 -0
  49. package/dist/vendor/core/context-handoff.d.ts +42 -0
  50. package/dist/vendor/core/context-handoff.js +167 -0
  51. package/dist/vendor/core/context-shadow.d.ts +39 -0
  52. package/dist/vendor/core/context-shadow.js +200 -0
  53. package/dist/vendor/core/delivery/index.d.ts +6 -0
  54. package/dist/vendor/core/delivery/index.js +4 -0
  55. package/dist/vendor/core/delivery/message-client.d.ts +18 -0
  56. package/dist/vendor/core/delivery/message-client.js +38 -0
  57. package/dist/vendor/core/delivery/message-ledger.d.ts +35 -0
  58. package/dist/vendor/core/delivery/message-ledger.js +97 -0
  59. package/dist/vendor/core/delivery/message-schema.d.ts +16 -0
  60. package/dist/vendor/core/delivery/message-schema.js +111 -0
  61. package/dist/vendor/core/delivery/update-check.d.ts +19 -0
  62. package/dist/vendor/core/delivery/update-check.js +107 -0
  63. package/dist/vendor/core/exit-signal.d.ts +88 -0
  64. package/dist/vendor/core/exit-signal.js +339 -0
  65. package/dist/vendor/core/exits.d.ts +41 -0
  66. package/dist/vendor/core/exits.js +258 -0
  67. package/dist/vendor/core/index.d.ts +44 -1
  68. package/dist/vendor/core/index.js +1088 -662
  69. package/dist/vendor/core/mission/aggregate.d.ts +27 -0
  70. package/dist/vendor/core/mission/aggregate.js +42 -0
  71. package/dist/vendor/core/mission/index.d.ts +2 -0
  72. package/dist/vendor/core/mission/index.js +1 -0
  73. package/dist/vendor/core/persistence/compiler.d.ts +8 -0
  74. package/dist/vendor/core/persistence/compiler.js +156 -0
  75. package/dist/vendor/core/persistence/context-handoff-store.d.ts +68 -0
  76. package/dist/vendor/core/persistence/context-handoff-store.js +112 -0
  77. package/dist/vendor/core/persistence/index.d.ts +4 -0
  78. package/dist/vendor/core/persistence/index.js +2 -0
  79. package/dist/vendor/core/persistence/ledger.d.ts +1 -1
  80. package/dist/vendor/core/persistence/mission-store.d.ts +56 -0
  81. package/dist/vendor/core/persistence/mission-store.js +281 -0
  82. package/dist/vendor/core/policy.d.ts +2 -0
  83. package/dist/vendor/core/policy.js +5 -2
  84. package/dist/vendor/core/rollback.js +15 -1
  85. package/dist/vendor/core/savings.d.ts +13 -0
  86. package/dist/vendor/core/savings.js +22 -0
  87. package/dist/vendor/core/termination-store.d.ts +15 -0
  88. package/dist/vendor/core/termination-store.js +44 -0
  89. package/dist/vendor/core/verified-handoff.d.ts +67 -0
  90. package/dist/vendor/core/verified-handoff.js +210 -0
  91. package/package.json +3 -13
  92. package/server.json +3 -3
  93. package/dist/vendor/adapters/stub-agent-cli.d.ts +0 -8
  94. package/dist/vendor/adapters/stub-agent-cli.js +0 -40
  95. package/dist/vendor/adapters/verifier-only.d.ts +0 -9
  96. package/dist/vendor/adapters/verifier-only.js +0 -63
package/README.md CHANGED
@@ -1,196 +1,137 @@
1
- # MartinLoop MCP
1
+ # @martinloop/mcp
2
2
 
3
- <div align="center">
4
- <img src="https://raw.githubusercontent.com/Keesan12/martin-loop/main/docs/assets/martinloop-logo.png" alt="MartinLoop" width="240">
3
+ You give an AI agent a coding task. It runs. You get a bill.
5
4
 
6
- **Stop runaway loops, bad code, and token waste.**
5
+ But did it actually work? Did it pass your tests? How much did it spend? What files did it touch? Did it loop 47 times trying the same broken approach?
7
6
 
8
- The governed MCP runtime for Claude Code, Codex, Gemini CLI, Cursor, and autonomous coding agents.
7
+ You don't know. And that's the problem.
9
8
 
10
- [![npm version](https://img.shields.io/npm/v/@martinloop/mcp?style=flat-square&logo=npm&logoColor=white)](https://www.npmjs.com/package/@martinloop/mcp)
11
- [![npm downloads](https://img.shields.io/npm/dm/@martinloop/mcp?style=flat-square&label=downloads)](https://www.npmjs.com/package/@martinloop/mcp)
12
- [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square&logo=apache)](https://github.com/Keesan12/martin-loop/blob/main/LICENSE)
13
- [![Node](https://img.shields.io/badge/node-%3E%3D20-3c873a?style=flat-square&logo=nodedotjs&logoColor=white)](#requirements)
14
- [![Glama score](https://glama.ai/mcp/servers/Keesan12/martin-loop/badges/score.svg)](https://glama.ai/mcp/servers/Keesan12/martin-loop)
15
- </div>
9
+ ## What This Does
16
10
 
17
- AI coding agents can write code. MartinLoop decides whether they are allowed to keep spending, whether the result is actually verified, and what evidence must remain for review.
11
+ MartinLoop is a governed loop for AI coding agents. You tell it what to do, set a budget, and point it at your test suite. It runs the agent, checks your tests after every attempt, and stops when either the tests pass or the money runs out.
18
12
 
19
- It wraps agent execution with:
13
+ When it's done, you get a receipt — not a vague summary, but a structured record: dollars spent, attempts made, verification results, files changed, and whether you got what you asked for.
20
14
 
21
- - hard USD, token, iteration, time, command, and file-change limits
22
- - verifier gates that must pass before completion
23
- - allowed and denied path contracts
24
- - preflight checks before any execution or spend
25
- - durable pause, continue, and cancel receipts
26
- - failure triage, run dossiers, evaluations, and PR-review evidence
27
-
28
- ## Connect in one command
29
-
30
- | Host | Command |
31
- | --- | --- |
32
- | Claude Code | `claude mcp add martin-loop -- npx -y @martinloop/mcp` |
33
- | Codex | `codex mcp add martin-loop -- npx -y @martinloop/mcp` |
34
- | Gemini CLI | `gemini mcp add martin-loop -- npx -y @martinloop/mcp` |
35
- | Any stdio MCP host | `npx -y @martinloop/mcp` |
36
-
37
- Windows Claude Code:
15
+ **One line to connect it:**
38
16
 
39
17
  ```sh
40
- claude mcp add --transport stdio --scope user martin-loop -- cmd /c npx -y @martinloop/mcp
18
+ claude mcp add martin-loop -- npx -y @martinloop/mcp
41
19
  ```
42
20
 
43
- No API key is required to start and inspect the server. Live execution requires a supported coding-agent CLI and its normal authentication.
21
+ That's it. Your agent now runs governed.
44
22
 
45
- ## Why agents use MartinLoop
23
+ ## Real Numbers From Real Runs
46
24
 
47
- | Uncontrolled agent run | Governed MartinLoop run |
48
- | --- | --- |
49
- | The agent decides when it is done | Your verifier decides whether completion is valid |
50
- | Retries continue until the user notices | Hard budgets and stop conditions prevent open-ended spend |
51
- | Scope drifts across the repository | Allowed and denied paths constrain writes |
52
- | The final answer hides failed attempts | The dossier preserves attempts, costs, verification, and artifacts |
53
- | Process control is ephemeral | Pause, continue, and cancel actions leave durable receipts |
54
- | “Probably fixed” becomes accepted | Missing, failed, contradicted, or unknown verification stays incomplete |
25
+ We tested this against live repos with real API spend:
55
26
 
56
- MartinLoop is not another coding agent. It is the enforcement and evidence layer around the agents you already use.
27
+ | What happened | Without MartinLoop | With MartinLoop |
28
+ |---|---|---|
29
+ | Budget: $1.50 task | Agent spent **$28.42** | Agent stopped at **$1.20** |
30
+ | Failing verifier | Retried indefinitely | Stopped after 3 attempts with diagnosis |
31
+ | CLI not on PATH | "not available on PATH" (dead stop) | Auto-discovered in AppData, kept running |
32
+ | `bun run lint && bun run test` | Passed `&&` as a literal arg (always fails) | Routed through shell, worked |
57
33
 
58
- ## Agent operating contract
34
+ These aren't hypotheticals. The $28 overshoot happened in production testing. We fixed the circuit breaker in `0.3.8`.
59
35
 
60
- Use this sequence for governed coding work:
36
+ ## Install
61
37
 
62
- ```text
63
- martin_doctor
64
- → martin_estimate
65
- → martin_plan
66
- → martin_preflight
67
- → martin_run
68
- → martin_dossier
69
- → martin_eval
38
+ ### Claude Code
39
+ ```sh
40
+ claude mcp add martin-loop -- npx -y @martinloop/mcp
70
41
  ```
71
42
 
72
- ### Rules for agents
43
+ Windows:
44
+ ```sh
45
+ claude mcp add --transport stdio --scope user martin-loop -- cmd /c npx -y @martinloop/mcp
46
+ ```
73
47
 
74
- 1. Start with `martin_doctor` to inspect the environment and run store.
75
- 2. Call `martin_estimate` before spending.
76
- 3. Keep the same objective and compatible scope through estimate, plan, preflight, and run.
77
- 4. Prefer read-only tools until execution is explicitly authorized.
78
- 5. Treat failed, contradicted, missing, or unknown verification as incomplete.
79
- 6. Use `martin://agent/next-step` or `martin://guides/agent-start` when the next action is unclear.
80
- 7. Do not use `martin_create_pr` with `execute: true` unless the user has explicitly authorized a GitHub write.
48
+ ### Codex
49
+ ```sh
50
+ codex mcp add martin-loop -- npx -y @martinloop/mcp
51
+ ```
81
52
 
82
- `martin_run` intentionally hard-blocks until the required doctor, estimate, plan, and preflight receipts exist for the same task.
53
+ ### Gemini CLI
54
+ ```sh
55
+ gemini mcp add martin-loop -- npx -y @martinloop/mcp
56
+ ```
83
57
 
84
- ## What a governed run looks like
58
+ ### Any MCP Host
59
+ ```sh
60
+ npx -y @martinloop/mcp
61
+ ```
85
62
 
86
- ```text
87
- User objective:
88
- "Fix the auth regression. Budget: $3. Verify: npm test."
63
+ ## How a Governed Run Works
89
64
 
90
- doctor checks environment, CLI availability, and run storage
91
- estimate predicts route, spend, and pre-work burn without spending
92
- plan defines scope, verifier proposal, policy pack, and risk
93
- preflight validates the contract before execution
94
- run executes inside budget, scope, policy, and verifier gates
95
- dossier returns attempts, cost, verification, artifacts, and evidence paths
96
- eval grades completion, verifier health, risk, and reviewability
97
65
  ```
66
+ You: "Fix the auth bug. Budget $3. Verify: npm test"
98
67
 
99
- Every attempt is bounded by the run contract. A confident model answer does not override a failed verifier.
100
-
101
- ## Proof, not promises
68
+ martin_doctor → checks CLI, auth, environment
69
+ martin_plan → scopes the task, sets constraints
70
+ martin_preflight → validates before any spend
71
+ martin_run → agent works inside budget + verifier gates
72
+ martin_dossier → receipt: $1.40 spent, 2 attempts, tests pass
73
+ ```
102
74
 
103
- This real governed run spent `$0.51` against a `$3.00` budget. The verifier passed and the receipt integrity was signed. MartinLoop still kept the result at `EVIDENCE_BOUNDARY` because rollback evidence had not been recorded.
75
+ Every attempt runs your verifier. Every dollar is tracked. If the agent drifts off-task, the scope contract catches it. If it blows the budget, the circuit breaker kills the subprocess mid-stream — not after the bill arrives.
104
76
 
105
- <div align="center">
106
- <img src="https://raw.githubusercontent.com/Keesan12/martin-loop/main/docs/assets/proof-receipt-live-governed.png" alt="MartinLoop governed run receipt showing spend, budget, verifier result, integrity, and evidence boundary" width="720">
107
- </div>
77
+ ## What Your Agent Gets
108
78
 
109
- Inspect the example receipt:
79
+ ### 21 Tools
110
80
 
111
- - [Markdown receipt](https://github.com/Keesan12/martin-loop/blob/main/docs/examples/proof-receipts/live-governed-run-receipt.md)
112
- - [JSON receipt](https://github.com/Keesan12/martin-loop/blob/main/docs/examples/proof-receipts/live-governed-run-receipt.json)
81
+ **Run the loop:**
82
+ `martin_doctor` `martin_plan` `martin_preflight` `martin_run` `martin_pause` `martin_continue` `martin_cancel`
113
83
 
114
- ## Tool surface
84
+ **Inspect results:**
85
+ `martin_status` `martin_logs` `martin_dossier` `martin_eval` `martin_inspect` `martin_list_runs` `martin_get_run` `martin_get_attempt` `martin_get_verification_results` `martin_triage_runs`
115
86
 
116
- ### Governed workflow
87
+ **Ship the work:**
88
+ `martin_pr_summary` `martin_create_pr` `martin_review_pr`
117
89
 
118
- - `martin_doctor` — inspect environment readiness; expected first call
119
- - `martin_estimate` — estimate cost and route without spending
120
- - `martin_plan` — produce scoped plan, verifier proposal, policy pack, and risk
121
- - `martin_preflight` — validate readiness before execution
122
- - `martin_run` — execute a governed coding task
123
- - `martin_pause` — record a durable pause request
124
- - `martin_continue` — record a durable resume request
125
- - `martin_cancel` — record a durable cancellation request
90
+ ### 11 Read-Only Resources
126
91
 
127
- ### Inspection and review
92
+ Your agent can pull context without side effects:
128
93
 
129
- - `martin_status`, `martin_logs`, `martin_inspect`
130
- - `martin_list_runs`, `martin_triage_runs`
131
- - `martin_get_run`, `martin_get_attempt`, `martin_get_verification_results`
132
- - `martin_run_dossier`, `martin_dossier`, `martin_eval`
133
- - `martin_pr_summary`, `martin_create_pr`, `martin_review_pr`
94
+ `martin://runs/latest` · `martin://runs/latest/proof-card` · `martin://runs/latest/budget-status` · `martin://runs/latest/verifier-evidence` · `martin://runs/recent` · `martin://server/health` · `martin://policies/current` · `martin://agent/next-step` · `martin://guides/mcp-usage` · `martin://guides/agent-start` · `martin://repo/risk-map`
134
95
 
135
- ### Read-only resources
96
+ ### Configuration Profiles
136
97
 
137
- The server exposes run summaries, receipts, budget status, verifier evidence, policies, health, agent guidance, and repository-risk context through `martin://` resources, including:
98
+ Generate host config tuned to your workflow:
138
99
 
139
- ```text
140
- martin://runs/latest
141
- martin://runs/latest/summary
142
- martin://runs/latest/receipt
143
- martin://runs/latest/budget-status
144
- martin://runs/latest/verifier-evidence
145
- martin://runs/recent
146
- martin://server/health
147
- martin://policies/current
148
- martin://agent/next-step
149
- martin://guides/agent-start
150
- martin://repo/risk-map
100
+ ```sh
101
+ npx martin-loop mcp print-config --host claude --profile minimal # run + inspect
102
+ npx martin-loop mcp print-config --host claude --profile diagnostic # + doctor + triage
103
+ npx martin-loop mcp print-config --host claude --profile full-local # all local tools
104
+ npx martin-loop mcp print-config --host claude --profile github-review # + PR workflow
151
105
  ```
152
106
 
153
- Use resources when the agent needs context without side effects.
154
-
155
- ## Configuration profiles
156
-
157
- Generate host config tuned to the minimum surface needed:
107
+ ## What Happens When Things Go Wrong
158
108
 
159
- ```sh
160
- npx martin-loop mcp print-config --host claude --profile minimal
161
- npx martin-loop mcp print-config --host claude --profile diagnostic
162
- npx martin-loop mcp print-config --host claude --profile full-local
163
- npx martin-loop mcp print-config --host claude --profile github-review
164
- ```
109
+ MartinLoop doesn't just report failures — it tries to fix them:
165
110
 
166
- - `minimal` — core run and inspection path
167
- - `diagnostic` — adds doctor and triage surfaces
168
- - `full-local` — all local tools
169
- - `github-review` — adds PR evidence and review workflow
111
+ | Failure | Old behavior | Now |
112
+ |---|---|---|
113
+ | CLI not on PATH | Error message, dead stop | Searches npm global, homebrew, nvm, scoop — uses what it finds |
114
+ | Verifier says "command not found" | Generic "verification failed" | Tells the next attempt: "bun is missing, install with `npm i -g bun`" |
115
+ | `git restore` fails mid-rollback | Throws, leaves dirty state | Retries once, falls back to `git checkout`, cleans up |
116
+ | Invalid `--profile` flag | Crashes | Warns, falls back to `minimal`, keeps running |
170
117
 
171
- ## Trust boundaries
118
+ ## Who Uses This
172
119
 
173
- - Cost and token values include provenance: actual, estimated, or unavailable.
174
- - A verifier proves only the commands you configured, not every product requirement.
175
- - Receipt integrity must be verified before evidence is trusted externally.
176
- - Unknown or missing evidence never passes silently.
177
- - MartinLoop does not guarantee that an agent will produce correct code; it makes execution bounded, verification explicit, and failure reviewable.
120
+ - **Engineers running overnight agent loops** — you need a kill switch that actually works, and a receipt in the morning
121
+ - **Teams with shared API budgets** — you need per-task spend caps, not org-wide prayer
122
+ - **Anyone reviewing agent-generated PRs** — the dossier shows what the agent tried, what passed, and what didn't
178
123
 
179
124
  ## Requirements
180
125
 
181
126
  - Node.js 20+
182
- - One supported coding-agent CLI for live execution: Claude Code, Codex, Gemini CLI, or an OpenAI-compatible route
183
- - Git repository for rollback-aware and changed-file workflows
127
+ - One AI coding CLI: [Claude Code](https://docs.anthropic.com/claude-code), [Codex](https://github.com/openai/codex), or [Gemini CLI](https://github.com/google/gemini-cli)
184
128
 
185
129
  ## Links
186
130
 
187
- - [Glama server page](https://glama.ai/mcp/servers/Keesan12/martin-loop)
188
- - [npm: @martinloop/mcp](https://www.npmjs.com/package/@martinloop/mcp)
189
- - [GitHub source and issues](https://github.com/Keesan12/martin-loop)
190
- - [MCP setup guide](https://github.com/Keesan12/martin-loop/blob/main/docs/getting-started/mcp.md)
191
- - [MCP tool reference](https://github.com/Keesan12/martin-loop/blob/main/docs/reference/mcp-tools.md)
131
+ - [martin-loop](https://www.npmjs.com/package/martin-loop) — the standalone CLI
132
+ - [GitHub](https://github.com/Keesan12/martin-loop) — source and issues
192
133
  - [martinloop.com](https://martinloop.com)
193
134
 
194
135
  ## License
195
136
 
196
- Apache-2.0.
137
+ Apache-2.0
@@ -4,7 +4,7 @@ export declare const MARTIN_MINIMAL_TOOL_NAMES: readonly ["martin_doctor", "mart
4
4
  export declare const MARTIN_DIAGNOSTIC_TOOL_NAMES: readonly ["martin_doctor", "martin_plan", "martin_preflight", "martin_estimate", "martin_logs", "martin_list_runs", "martin_triage_runs", "martin_get_run", "martin_get_attempt", "martin_get_verification_results", "martin_dossier", "martin_eval"];
5
5
  export declare const MARTIN_GITHUB_REVIEW_TOOL_NAMES: readonly ["martin_doctor", "martin_plan", "martin_preflight", "martin_dossier", "martin_eval", "martin_pr_summary", "martin_create_pr", "martin_review_pr"];
6
6
  export declare const MARTIN_PAID_REMOTE_TOOL_NAMES: readonly ["martin_doctor", "martin_plan", "martin_preflight", "martin_estimate", "martin_run", "martin_list_runs", "martin_triage_runs", "martin_get_run", "martin_get_verification_results", "martin_dossier", "martin_eval"];
7
- export declare const MARTIN_RESOURCE_URIS: readonly ["martin://server/health", "martin://runs/recent", "martin://runs/triage", "martin://runs/latest", "martin://runs/latest/summary", "martin://runs/latest/receipt", "martin://runs/latest/proof-card", "martin://runs/latest/budget-status", "martin://runs/latest/verifier-evidence", "martin://runs/latest/rollback-evidence", "martin://policies/current", "martin://repo/risk-map", "martin://verifiers/results", "martin://agent/next-step", "martin://agent/governance-status", "martin://agent/memory-summary", "martin://guides/mcp-usage", "martin://guides/agent-start", "martin://guides/command-map", "martin://guides/ide-onboarding", "martin://guides/operating-rules", "martin://guides/publish-readiness"];
7
+ export declare const MARTIN_RESOURCE_URIS: readonly ["martin://server/health", "martin://runs/recent", "martin://runs/triage", "martin://runs/latest", "martin://runs/latest/summary", "martin://runs/latest/proof-card", "martin://runs/latest/budget-status", "martin://runs/latest/verifier-evidence", "martin://runs/latest/rollback-evidence", "martin://policies/current", "martin://repo/risk-map", "martin://verifiers/results", "martin://agent/next-step", "martin://agent/governance-status", "martin://agent/mode-status", "martin://agent/memory-summary", "martin://guides/mcp-usage", "martin://guides/agent-start", "martin://guides/command-map", "martin://guides/ide-onboarding", "martin://guides/operating-rules", "martin://guides/publish-readiness"];
8
8
  export declare const MARTIN_RESOURCE_TEMPLATE_URIS: readonly ["martin://runs/{loopId}", "martin://runs/{loopId}/dossier", "martin://runs/{loopId}/attempts/{attemptIndex}", "martin://runs/{loopId}/verification"];
9
9
  export declare const MARTIN_PROMPT_NAMES: readonly ["martin_start", "martin_preflight", "martin_triage", "martin_resume", "martin_prove", "martin_release_check", "martin_governed_coding_kickoff", "martin_debug_failed_run", "martin_publish_readiness_review", "martin_triage_run_store", "safe_bug_fix", "write_tests_first", "small_refactor", "security_review", "pr_review", "release_check"];
10
10
  export interface MartinDiscoveryMetadata {
@@ -84,7 +84,6 @@ export const MARTIN_RESOURCE_URIS = [
84
84
  "martin://runs/triage",
85
85
  "martin://runs/latest",
86
86
  "martin://runs/latest/summary",
87
- "martin://runs/latest/receipt",
88
87
  "martin://runs/latest/proof-card",
89
88
  "martin://runs/latest/budget-status",
90
89
  "martin://runs/latest/verifier-evidence",
@@ -94,6 +93,7 @@ export const MARTIN_RESOURCE_URIS = [
94
93
  "martin://verifiers/results",
95
94
  "martin://agent/next-step",
96
95
  "martin://agent/governance-status",
96
+ "martin://agent/mode-status",
97
97
  "martin://agent/memory-summary",
98
98
  "martin://guides/mcp-usage",
99
99
  "martin://guides/agent-start",
@@ -6,7 +6,6 @@ export declare const MARTIN_STATIC_RESOURCE_URIS: {
6
6
  readonly triage: "martin://runs/triage";
7
7
  readonly latestRun: "martin://runs/latest";
8
8
  readonly latestSummary: "martin://runs/latest/summary";
9
- readonly latestReceipt: "martin://runs/latest/receipt";
10
9
  readonly latestProofCard: "martin://runs/latest/proof-card";
11
10
  readonly latestBudgetStatus: "martin://runs/latest/budget-status";
12
11
  readonly latestVerifierEvidence: "martin://runs/latest/verifier-evidence";
@@ -22,8 +21,8 @@ export declare const MARTIN_STATIC_RESOURCE_URIS: {
22
21
  readonly operatingRulesGuide: "martin://guides/operating-rules";
23
22
  readonly publishReadinessGuide: "martin://guides/publish-readiness";
24
23
  readonly governanceStatus: "martin://agent/governance-status";
25
- readonly memorySummary: "martin://agent/memory-summary";
26
24
  readonly modeStatus: "martin://agent/mode-status";
25
+ readonly memorySummary: "martin://agent/memory-summary";
27
26
  };
28
27
  export declare const MARTIN_RESOURCE_TEMPLATES: ResourceTemplate[];
29
28
  export declare const MARTIN_STATIC_RESOURCES: Resource[];
package/dist/resources.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { readFile } from "node:fs/promises";
2
- import { join } from "node:path";
3
2
  import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
4
  import { buildMartinDiscoveryMetadata } from "./discovery-metadata.js";
5
5
  import { MARTIN_MCP_PACKAGE_VERSION } from "./package-version.js";
6
6
  import { inspectLoopTool } from "./tools/inspect-loop.js";
@@ -19,7 +19,6 @@ export const MARTIN_STATIC_RESOURCE_URIS = {
19
19
  triage: "martin://runs/triage",
20
20
  latestRun: "martin://runs/latest",
21
21
  latestSummary: "martin://runs/latest/summary",
22
- latestReceipt: "martin://runs/latest/receipt",
23
22
  latestProofCard: "martin://runs/latest/proof-card",
24
23
  latestBudgetStatus: "martin://runs/latest/budget-status",
25
24
  latestVerifierEvidence: "martin://runs/latest/verifier-evidence",
@@ -35,8 +34,8 @@ export const MARTIN_STATIC_RESOURCE_URIS = {
35
34
  operatingRulesGuide: "martin://guides/operating-rules",
36
35
  publishReadinessGuide: "martin://guides/publish-readiness",
37
36
  governanceStatus: "martin://agent/governance-status",
38
- memorySummary: "martin://agent/memory-summary",
39
- modeStatus: "martin://agent/mode-status"
37
+ modeStatus: "martin://agent/mode-status",
38
+ memorySummary: "martin://agent/memory-summary"
40
39
  };
41
40
  export const MARTIN_RESOURCE_TEMPLATES = [
42
41
  {
@@ -100,18 +99,11 @@ export const MARTIN_STATIC_RESOURCES = [
100
99
  description: "Compact latest-run summary for context-constrained agents.",
101
100
  mimeType: "application/json"
102
101
  },
103
- {
104
- uri: MARTIN_STATIC_RESOURCE_URIS.latestReceipt,
105
- name: "martin_latest_receipt",
106
- title: "Martin Latest Receipt",
107
- description: "Canonical structured receipt for the latest run; use this before optional proof-card views.",
108
- mimeType: "application/json"
109
- },
110
102
  {
111
103
  uri: MARTIN_STATIC_RESOURCE_URIS.latestProofCard,
112
104
  name: "martin_latest_proof_card",
113
105
  title: "Martin Latest Proof Card",
114
- description: "Optional Markdown proof view derived from the latest receipt.",
106
+ description: "Small Markdown receipt showing what happened, what Martin prevented, and the next safe action.",
115
107
  mimeType: "text/markdown"
116
108
  },
117
109
  {
@@ -212,19 +204,19 @@ export const MARTIN_STATIC_RESOURCES = [
212
204
  description: "Proactive governance status: whether work is governed, budget remaining, unreceipted runs, and recommended next action. Read this before starting agent work.",
213
205
  mimeType: "application/json"
214
206
  },
207
+ {
208
+ uri: MARTIN_STATIC_RESOURCE_URIS.modeStatus,
209
+ name: "martin_mode_status",
210
+ title: "Martin Mode Status",
211
+ description: "Current MartinLoop working mode, whether it is inherited or explicitly configured, and how to switch it.",
212
+ mimeType: "application/json"
213
+ },
215
214
  {
216
215
  uri: MARTIN_STATIC_RESOURCE_URIS.memorySummary,
217
216
  name: "martin_memory_summary",
218
217
  title: "Martin Memory Summary",
219
218
  description: "MartinLoop persistent memory: user preferences, consent signals, budget patterns, and behavioral observations aggregated over time. Read at session start to personalize recommendations.",
220
219
  mimeType: "application/json"
221
- },
222
- {
223
- uri: MARTIN_STATIC_RESOURCE_URIS.modeStatus,
224
- name: "martin_mode_status",
225
- title: "Martin Mode Status",
226
- description: "Current Martin working mode (auto, plan, or edits) and consent state. Read before starting agent work to confirm whether the user expects autonomous execution, plan approval, or per-edit review.",
227
- mimeType: "application/json"
228
220
  }
229
221
  ];
230
222
  export function listMartinResources() {
@@ -260,8 +252,6 @@ export async function readMartinResource(input) {
260
252
  return jsonResource(input.uri, withDiscoveryMetadata(await martinRunDossierTool({ latest: true, runsDir: context.runsRoot }), context.runsRoot));
261
253
  case MARTIN_STATIC_RESOURCE_URIS.latestSummary:
262
254
  return jsonResource(input.uri, withDiscoveryMetadata(await buildLatestSummaryResource(context.runsRoot), context.runsRoot));
263
- case MARTIN_STATIC_RESOURCE_URIS.latestReceipt:
264
- return jsonResource(input.uri, withDiscoveryMetadata(await buildLatestReceiptResource(context.runsRoot), context.runsRoot));
265
255
  case MARTIN_STATIC_RESOURCE_URIS.latestProofCard:
266
256
  return textResource(input.uri, "text/markdown", await buildLatestProofCardResource(context.runsRoot));
267
257
  case MARTIN_STATIC_RESOURCE_URIS.latestBudgetStatus:
@@ -284,7 +274,7 @@ export async function readMartinResource(input) {
284
274
  case MARTIN_STATIC_RESOURCE_URIS.governanceStatus:
285
275
  return jsonResource(input.uri, withDiscoveryMetadata(await buildGovernanceStatusResource(context.runsRoot, context.workingDirectory), context.runsRoot));
286
276
  case MARTIN_STATIC_RESOURCE_URIS.modeStatus:
287
- return jsonResource(input.uri, withDiscoveryMetadata(await buildModeStatusResource(), context.runsRoot));
277
+ return jsonResource(input.uri, withDiscoveryMetadata(await buildModeStatusResource(context.workingDirectory), context.runsRoot));
288
278
  case MARTIN_STATIC_RESOURCE_URIS.agentNextStep:
289
279
  return jsonResource(input.uri, withDiscoveryMetadata(await buildAgentNextStepResource(context.runsRoot), context.runsRoot));
290
280
  case MARTIN_STATIC_RESOURCE_URIS.mcpUsageGuide:
@@ -433,44 +423,6 @@ async function buildLatestSummaryResource(runsRoot) {
433
423
  warnings: [...latest.detail.warnings, ...verification.warnings]
434
424
  };
435
425
  }
436
- async function buildLatestReceiptResource(runsRoot) {
437
- const latest = await loadLatestRunForCompactResource(runsRoot);
438
- if (latest.empty || !latest.detail) {
439
- return compactEmptyState("latest-receipt", runsRoot, latest.warnings);
440
- }
441
- const ledgerEvents = await readLedgerEvents(latest.detail);
442
- const loop = latest.detail.loop;
443
- const verification = buildVerificationHistorySnapshot(loop, ledgerEvents);
444
- const preview = buildPersistedLoopPreview(loop);
445
- return {
446
- kind: "latest-receipt",
447
- loop: preview,
448
- task: {
449
- title: loop.task?.title,
450
- objective: loop.task?.objective,
451
- verificationPlan: loop.task?.verificationPlan ?? []
452
- },
453
- receiptIntegrity: latest.detail.loop.receiptIntegrity,
454
- verification: {
455
- status: verification.latestVerification?.passed === true
456
- ? "passed"
457
- : verification.latestVerification?.passed === false
458
- ? "failed"
459
- : "unavailable",
460
- summary: verification.latestVerification?.summary,
461
- latest: verification.latestVerification,
462
- count: verification.verificationCount
463
- },
464
- whatHappened: loop.attempts.at(-1)?.summary ?? verification.latestVerification?.summary ?? loop.task?.objective,
465
- whatMartinPrevented: describePrevention(loop),
466
- nextSafeAction: inferAgentNextStep(loop, verification),
467
- proofCard: {
468
- artifactGuaranteed: false,
469
- resource: MARTIN_STATIC_RESOURCE_URIS.latestProofCard
470
- },
471
- warnings: [...latest.detail.warnings, ...verification.warnings]
472
- };
473
- }
474
426
  async function buildLatestBudgetStatusResource(runsRoot) {
475
427
  const latest = await loadLatestRunForCompactResource(runsRoot);
476
428
  if (latest.empty || !latest.detail) {
@@ -601,7 +553,7 @@ async function buildLatestProofCardResource(runsRoot) {
601
553
  "",
602
554
  "What happened: Martin has not found a local run record in this runs root.",
603
555
  "What Martin prevented: unknown until a governed run executes.",
604
- "Next safe action: call `martin_doctor`, run `npx martin-loop demo`, then inspect `martin://runs/latest/receipt` or `martin://runs/latest/summary`.",
556
+ "Next safe action: call `martin_doctor`, run `npx martin-loop demo`, then inspect `martin://runs/latest/summary`.",
605
557
  "",
606
558
  "Estimate note: no cost or token savings are claimed without run evidence.",
607
559
  ""
@@ -708,6 +660,33 @@ async function buildGovernanceStatusResource(runsRoot, workingDirectory) {
708
660
  warning: governed ? undefined : "This session is NOT governed. Complete the required sequence before making changes."
709
661
  };
710
662
  }
663
+ async function buildModeStatusResource(workingDirectory) {
664
+ const configPath = join(homedir(), ".martin", "config.json");
665
+ let config = {};
666
+ try {
667
+ config = JSON.parse(await readFile(configPath, "utf8"));
668
+ }
669
+ catch {
670
+ // Fresh config means the implicit auto default is in effect.
671
+ }
672
+ const projectMode = config.projectOverrides?.[workingDirectory];
673
+ const defaultMode = config.defaultMode ?? "auto";
674
+ const effectiveMode = projectMode ?? defaultMode;
675
+ return {
676
+ kind: "mode-status",
677
+ effectiveMode,
678
+ defaultMode,
679
+ scope: projectMode ? "project" : config.defaultMode ? "global" : "implicit_default",
680
+ configured: Boolean(projectMode || config.defaultMode),
681
+ projectOverride: projectMode ?? null,
682
+ workingDirectory,
683
+ switchCommands: {
684
+ auto: "martin mode auto",
685
+ plan: "martin mode plan",
686
+ edits: "martin mode edits"
687
+ }
688
+ };
689
+ }
711
690
  function buildCurrentPoliciesResource(workingDirectory) {
712
691
  const signals = inspectRepoSignals(workingDirectory);
713
692
  const recommended = buildPolicyPackDefinition(undefined, signals);
@@ -751,14 +730,14 @@ function inferAgentNextStep(loop, verification) {
751
730
  return {
752
731
  action: "triage_before_retry",
753
732
  toolOrResource: "martin_triage_runs",
754
- instruction: "Call `martin_triage_runs` and inspect the latest receipt before spending another attempt."
733
+ instruction: "Call `martin_triage_runs` and inspect the proof card before spending another attempt."
755
734
  };
756
735
  }
757
736
  if (loop.status === "completed" && verification.latestVerification?.passed === true) {
758
737
  return {
759
738
  action: "prove_and_share",
760
- toolOrResource: MARTIN_STATIC_RESOURCE_URIS.latestReceipt,
761
- instruction: "Read the latest receipt and full dossier before sharing or promoting the result; generate a proof card only when a visual artifact is explicitly needed."
739
+ toolOrResource: MARTIN_STATIC_RESOURCE_URIS.latestProofCard,
740
+ instruction: "Read the proof card and full dossier before sharing or promoting the result."
762
741
  };
763
742
  }
764
743
  return {
@@ -783,14 +762,14 @@ Martin Loop exposes governed coding workflows over MCP. Use the server health an
783
762
  2. Use the \`martin_governed_coding_kickoff\` prompt to frame a governed coding request.
784
763
  3. Call \`martin_preflight\` before \`martin_run\` when the task or safety envelope is non-trivial.
785
764
  4. After execution, inspect \`${MARTIN_STATIC_RESOURCE_URIS.recentRuns}\`, \`martin://runs/{loopId}\`, and \`martin://runs/{loopId}/verification\`.
786
- 5. For low-context agents, read \`${MARTIN_STATIC_RESOURCE_URIS.agentNextStep}\`, \`${MARTIN_STATIC_RESOURCE_URIS.latestSummary}\`, or \`${MARTIN_STATIC_RESOURCE_URIS.latestReceipt}\` before asking for full JSON. Treat \`${MARTIN_STATIC_RESOURCE_URIS.latestProofCard}\` as an optional derived view.
765
+ 5. For low-context agents, read \`${MARTIN_STATIC_RESOURCE_URIS.agentNextStep}\`, \`${MARTIN_STATIC_RESOURCE_URIS.latestSummary}\`, or \`${MARTIN_STATIC_RESOURCE_URIS.latestProofCard}\` before asking for full JSON.
787
766
  6. Read \`${MARTIN_STATIC_RESOURCE_URIS.triage}\` or call \`martin_triage_runs\` to prioritize which run needs attention first.
788
767
  7. Use \`martin_debug_failed_run\` when a loop exits failed, budget-bound, or escalated.
789
768
 
790
769
  ## Current Martin MCP Surface
791
770
 
792
771
  - Tools: \`martin_run\`, \`martin_inspect\`, \`martin_status\`, \`martin_doctor\`, \`martin_preflight\`, \`martin_list_runs\`, \`martin_triage_runs\`, \`martin_get_run\`, \`martin_get_attempt\`, \`martin_get_verification_results\`, \`martin_run_dossier\`
793
- - Static resources: \`${MARTIN_STATIC_RESOURCE_URIS.serverHealth}\`, \`${MARTIN_STATIC_RESOURCE_URIS.recentRuns}\`, \`${MARTIN_STATIC_RESOURCE_URIS.triage}\`, \`${MARTIN_STATIC_RESOURCE_URIS.latestSummary}\`, \`${MARTIN_STATIC_RESOURCE_URIS.latestReceipt}\`, \`${MARTIN_STATIC_RESOURCE_URIS.latestProofCard}\`, \`${MARTIN_STATIC_RESOURCE_URIS.latestBudgetStatus}\`, \`${MARTIN_STATIC_RESOURCE_URIS.latestVerifierEvidence}\`, \`${MARTIN_STATIC_RESOURCE_URIS.latestRollbackEvidence}\`, \`${MARTIN_STATIC_RESOURCE_URIS.agentNextStep}\`, \`${MARTIN_STATIC_RESOURCE_URIS.mcpUsageGuide}\`, \`${MARTIN_STATIC_RESOURCE_URIS.agentStartGuide}\`, \`${MARTIN_STATIC_RESOURCE_URIS.publishReadinessGuide}\`
772
+ - Static resources: \`${MARTIN_STATIC_RESOURCE_URIS.serverHealth}\`, \`${MARTIN_STATIC_RESOURCE_URIS.recentRuns}\`, \`${MARTIN_STATIC_RESOURCE_URIS.triage}\`, \`${MARTIN_STATIC_RESOURCE_URIS.latestSummary}\`, \`${MARTIN_STATIC_RESOURCE_URIS.latestProofCard}\`, \`${MARTIN_STATIC_RESOURCE_URIS.latestBudgetStatus}\`, \`${MARTIN_STATIC_RESOURCE_URIS.latestVerifierEvidence}\`, \`${MARTIN_STATIC_RESOURCE_URIS.latestRollbackEvidence}\`, \`${MARTIN_STATIC_RESOURCE_URIS.agentNextStep}\`, \`${MARTIN_STATIC_RESOURCE_URIS.governanceStatus}\`, \`${MARTIN_STATIC_RESOURCE_URIS.modeStatus}\`, \`${MARTIN_STATIC_RESOURCE_URIS.memorySummary}\`, \`${MARTIN_STATIC_RESOURCE_URIS.mcpUsageGuide}\`, \`${MARTIN_STATIC_RESOURCE_URIS.agentStartGuide}\`, \`${MARTIN_STATIC_RESOURCE_URIS.publishReadinessGuide}\`
794
773
  - Resource templates: \`martin://runs/{loopId}\`, \`martin://runs/{loopId}/attempts/{attemptIndex}\`, \`martin://runs/{loopId}/verification\`
795
774
  - Prompts: \`martin_start\`, \`martin_preflight\`, \`martin_triage\`, \`martin_resume\`, \`martin_prove\`, \`martin_release_check\`, \`martin_governed_coding_kickoff\`, \`martin_debug_failed_run\`, \`martin_publish_readiness_review\`, \`martin_triage_run_store\`
796
775
 
@@ -817,7 +796,7 @@ Use Martin Loop as the local governor before you spend agent tokens or retry a f
817
796
  2. If no runs exist, call \`martin_doctor\`, then \`martin_preflight\`.
818
797
  3. If a run exists, read \`${MARTIN_STATIC_RESOURCE_URIS.latestSummary}\` before reading full run JSON.
819
798
  4. If the verifier failed, use prompt \`martin_debug_failed_run\` or \`martin_triage\`.
820
- 5. If you need a shareable receipt, read \`${MARTIN_STATIC_RESOURCE_URIS.latestReceipt}\` first. Generate or inspect \`${MARTIN_STATIC_RESOURCE_URIS.latestProofCard}\` only when a visual artifact is explicitly required.
799
+ 5. If you need a shareable receipt, read \`${MARTIN_STATIC_RESOURCE_URIS.latestProofCard}\`.
821
800
 
822
801
  ## Install Profiles
823
802
 
@@ -855,8 +834,7 @@ Use this guide when an IDE or agent needs to know which Martin surface to call n
855
834
 
856
835
  - Need the smallest next action: \`${MARTIN_STATIC_RESOURCE_URIS.agentNextStep}\`
857
836
  - Need a quick receipt: \`${MARTIN_STATIC_RESOURCE_URIS.latestSummary}\`
858
- - Need the structured receipt source of truth: \`${MARTIN_STATIC_RESOURCE_URIS.latestReceipt}\`
859
- - Need an optional visual proof object: \`${MARTIN_STATIC_RESOURCE_URIS.latestProofCard}\`
837
+ - Need a shareable proof object: \`${MARTIN_STATIC_RESOURCE_URIS.latestProofCard}\`
860
838
  - Need a full run review: \`martin_dossier\`
861
839
  - Need to decide whether to retry: \`martin_triage_runs\`
862
840
  - Need IDE setup guidance: \`${MARTIN_STATIC_RESOURCE_URIS.ideOnboardingGuide}\`
@@ -939,32 +917,6 @@ Use this guide when reviewing whether the public MCP package is ready to publish
939
917
  - If a discovery helper exists but is not yet wired into the server, report that as an integration gap instead of treating the capability as fully shipped.
940
918
  `;
941
919
  }
942
- async function buildModeStatusResource() {
943
- let currentMode = "auto";
944
- let modeConfigured = false;
945
- try {
946
- const config = JSON.parse(await readFile(join(homedir(), ".martin", "config.json"), "utf8"));
947
- if (config.defaultMode) {
948
- currentMode = config.defaultMode;
949
- modeConfigured = true;
950
- }
951
- }
952
- catch { /* fresh install — default to auto */ }
953
- return {
954
- kind: "mode-status",
955
- currentMode,
956
- modeConfigured,
957
- modes: {
958
- auto: "MartinLoop governs autonomously — estimate, preflight, run, receipt without per-step approval.",
959
- plan: "MartinLoop shows the proposed plan before executing. Agent waits for user approval.",
960
- edits: "MartinLoop shows each file change before writing. Maximum human control."
961
- },
962
- agentGuidance: modeConfigured
963
- ? `User has explicitly set mode to "${currentMode}". Respect this preference during the session.`
964
- : "Mode not explicitly configured. Defaulting to auto. Suggest running `martin mode auto|plan|edits` to set a preference.",
965
- changeCommand: "martin mode auto | plan | edits"
966
- };
967
- }
968
920
  function withDiscoveryMetadata(value, runsRoot) {
969
921
  return {
970
922
  metadata: {
@@ -1,4 +1,4 @@
1
- type ToolName = "martin_run" | "martin_inspect" | "martin_status" | "martin_doctor" | "martin_estimate" | "martin_plan" | "martin_preflight" | "martin_logs" | "martin_cancel" | "martin_pause" | "martin_continue" | "martin_list_runs" | "martin_triage_runs" | "martin_get_run" | "martin_get_attempt" | "martin_get_verification_results" | "martin_run_dossier" | "martin_dossier" | "martin_eval" | "martin_pr_summary" | "martin_create_pr" | "martin_review_pr";
1
+ type ToolName = "martin_run" | "martin_inspect" | "martin_status" | "martin_doctor" | "martin_plan" | "martin_preflight" | "martin_estimate" | "martin_logs" | "martin_cancel" | "martin_pause" | "martin_continue" | "martin_list_runs" | "martin_triage_runs" | "martin_get_run" | "martin_get_attempt" | "martin_get_verification_results" | "martin_run_dossier" | "martin_dossier" | "martin_eval" | "martin_pr_summary" | "martin_create_pr" | "martin_review_pr";
2
2
  export { sanitizeToolErrorMessage } from "./tools/tool-errors.js";
3
3
  export declare function validateToolInput(name: ToolName, args: unknown): unknown;
4
4
  export declare function resolveSafeRepoRoot(repoRoot?: string, workspaceRoot?: string): string;