@martinloop/mcp 0.1.4 → 0.2.5

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 (74) hide show
  1. package/README.md +138 -135
  2. package/dist/discovery-metadata.d.ts +16 -0
  3. package/dist/discovery-metadata.js +62 -0
  4. package/dist/discovery-support.d.ts +62 -0
  5. package/dist/discovery-support.js +224 -0
  6. package/dist/package-version.d.ts +1 -0
  7. package/dist/package-version.js +3 -0
  8. package/dist/prompts.d.ts +13 -0
  9. package/dist/prompts.js +455 -0
  10. package/dist/resources.d.ts +29 -0
  11. package/dist/resources.js +575 -0
  12. package/dist/server-validation.d.ts +2 -3
  13. package/dist/server-validation.js +295 -87
  14. package/dist/server.d.ts +76 -7
  15. package/dist/server.js +1135 -247
  16. package/dist/tools/doctor.js +14 -6
  17. package/dist/tools/get-attempt.d.ts +15 -0
  18. package/dist/tools/get-attempt.js +15 -0
  19. package/dist/tools/get-run.d.ts +24 -0
  20. package/dist/tools/get-run.js +23 -0
  21. package/dist/tools/get-status.d.ts +11 -0
  22. package/dist/tools/get-status.js +12 -2
  23. package/dist/tools/get-verification-results.d.ts +14 -0
  24. package/dist/tools/get-verification-results.js +14 -0
  25. package/dist/tools/inspect-loop.d.ts +9 -0
  26. package/dist/tools/inspect-loop.js +11 -2
  27. package/dist/tools/list-runs.d.ts +29 -0
  28. package/dist/tools/list-runs.js +24 -0
  29. package/dist/tools/preflight.js +7 -2
  30. package/dist/tools/run-dossier.d.ts +41 -0
  31. package/dist/tools/run-dossier.js +41 -0
  32. package/dist/tools/run-loop.d.ts +19 -0
  33. package/dist/tools/run-loop.js +41 -3
  34. package/dist/tools/run-store.d.ts +57 -3
  35. package/dist/tools/run-store.js +404 -53
  36. package/dist/tools/tool-errors.d.ts +37 -0
  37. package/dist/tools/tool-errors.js +170 -0
  38. package/dist/tools/tool-response.d.ts +16 -0
  39. package/dist/tools/tool-response.js +34 -0
  40. package/dist/tools/tool-support.d.ts +92 -2
  41. package/dist/tools/tool-support.js +358 -63
  42. package/dist/tools/triage-runs.d.ts +33 -0
  43. package/dist/tools/triage-runs.js +138 -0
  44. package/dist/vendor/adapters/claude-cli.js +0 -1
  45. package/dist/vendor/adapters/cli-bridge.js +0 -1
  46. package/dist/vendor/adapters/direct-provider.js +0 -1
  47. package/dist/vendor/adapters/index.js +0 -1
  48. package/dist/vendor/adapters/runtime-support.js +0 -1
  49. package/dist/vendor/adapters/stub-agent-cli.js +0 -1
  50. package/dist/vendor/adapters/stub-direct-provider.js +0 -1
  51. package/dist/vendor/adapters/verifier-only.js +0 -1
  52. package/dist/vendor/contracts/governance.js +0 -1
  53. package/dist/vendor/contracts/index.d.ts +2 -0
  54. package/dist/vendor/contracts/index.js +1 -1
  55. package/dist/vendor/contracts/operator.d.ts +19 -0
  56. package/dist/vendor/contracts/operator.js +11 -0
  57. package/dist/vendor/core/compiler.js +0 -1
  58. package/dist/vendor/core/context-integrity.js +0 -1
  59. package/dist/vendor/core/grounding.js +0 -1
  60. package/dist/vendor/core/index.js +1 -2
  61. package/dist/vendor/core/leash.js +19 -12
  62. package/dist/vendor/core/persistence/compiler.js +0 -1
  63. package/dist/vendor/core/persistence/index.js +0 -1
  64. package/dist/vendor/core/persistence/ledger.js +0 -1
  65. package/dist/vendor/core/persistence/runs-reader.js +0 -1
  66. package/dist/vendor/core/persistence/store.js +0 -1
  67. package/dist/vendor/core/policy.js +0 -1
  68. package/dist/vendor/core/red-blue/red-phase.d.ts +64 -0
  69. package/dist/vendor/core/red-blue/red-phase.js +135 -0
  70. package/dist/vendor/core/red-blue/risk-tiers.d.ts +22 -0
  71. package/dist/vendor/core/red-blue/risk-tiers.js +32 -0
  72. package/dist/vendor/core/rollback.js +2 -3
  73. package/package.json +10 -3
  74. package/server.json +2 -2
package/README.md CHANGED
@@ -1,38 +1,79 @@
1
1
  # @martinloop/mcp
2
2
 
3
- Governed MCP server for AI coding agents that need hard spend limits, verifier gates, scoped file edits, and inspectable run records.
3
+ Governed execution cockpit for AI coding agents over MCP stdio.
4
4
 
5
- `@martinloop/mcp@0.1.4` exposes five stdio tools:
5
+ The standalone `@martinloop/mcp` release train is documented through `0.1.4`, `0.2.0`, and the later `0.2.5` stable cockpit line. It gives hosts one bounded execution entrypoint, rich read-only inspection tools, discoverable resources, run triage, and operator prompts on top of Martin Loop’s persisted run records.
6
+
7
+ This package stays local-first and stdio-first in public packaging today.
8
+
9
+ For host-facing guidance, see [MCP for AI Agents](https://github.com/Keesan12/martin-loop/blob/main/docs/oss/MCP-FOR-AI-AGENTS.md).
10
+
11
+ ## Public Release Train
12
+
13
+ - 0.1.4 operator foundation.
14
+ - 0.2.0 cockpit expansion. 0.2.0 adds resources, resource templates, prompts, and read-only cockpit inspection.
15
+ - 0.2.5 stable cockpit line with local triage and degraded run-store hardening.
16
+
17
+ ## What Ships
18
+
19
+ ### Tools
6
20
 
7
21
  - `martin_doctor`
8
22
  - `martin_preflight`
9
23
  - `martin_run`
10
24
  - `martin_inspect`
11
25
  - `martin_status`
26
+ - `martin_list_runs`
27
+ - `martin_triage_runs`
28
+ - `martin_get_run`
29
+ - `martin_get_attempt`
30
+ - `martin_get_verification_results`
31
+ - `martin_run_dossier`
32
+
33
+ ### Resources
34
+
35
+ - `martin://server/health`
36
+ - `martin://runs/recent`
37
+ - `martin://runs/triage`
38
+ - `martin://runs/latest/summary`
39
+ - `martin://runs/latest/proof-card`
40
+ - `martin://runs/latest/budget-status`
41
+ - `martin://runs/latest/verifier-evidence`
42
+ - `martin://runs/latest/rollback-evidence`
43
+ - `martin://agent/next-step`
44
+ - `martin://guides/mcp-usage`
45
+ - `martin://guides/publish-readiness`
46
+
47
+ ### Resource templates
48
+
49
+ - `martin://runs/{loopId}`
50
+ - `martin://runs/{loopId}/attempts/{attemptIndex}`
51
+ - `martin://runs/{loopId}/verification`
52
+
53
+ ### Prompts
54
+
55
+ - `martin_start`
56
+ - `martin_preflight`
57
+ - `martin_triage`
58
+ - `martin_resume`
59
+ - `martin_prove`
60
+ - `martin_release_check`
61
+ - `martin_governed_coding_kickoff`
62
+ - `martin_debug_failed_run`
63
+ - `martin_publish_readiness_review`
64
+ - `martin_triage_run_store`
12
65
 
13
- Recommended flow:
66
+ ## Recommended Flow
14
67
 
15
68
  1. `martin_doctor`
16
69
  2. `martin_preflight`
17
70
  3. `martin_run`
18
- 4. `martin_inspect` or `martin_status`
19
-
20
- ## What This Server Is For
71
+ 4. `martin_triage_runs`
72
+ 5. `martin://agent/next-step` or `martin://runs/latest/summary`
73
+ 6. `martin_run_dossier` or `martin_get_*` when compact evidence says the full record is needed
74
+ 7. `martin://runs/latest/proof-card` or `martin_prove` for a shareable receipt
21
75
 
22
- Use this MCP when a host already knows how to delegate coding work, but you want Martin Loop to bound that work with:
23
-
24
- - a hard budget ceiling (`maxUsd`)
25
- - an attempt ceiling (`maxIterations`)
26
- - a total token ceiling (`maxTokens`)
27
- - verifier commands (`verificationPlan`)
28
- - allowed and denied file globs
29
- - persisted run records you can inspect afterward
30
-
31
- It is a good fit for Claude Code, Codex-oriented hosts, and other MCP clients that want governed code-change execution instead of open-ended retry behavior.
32
-
33
- For host-facing integration guidance, see [MCP for AI Agents](https://github.com/Keesan12/martin-loop/blob/main/docs/oss/MCP-FOR-AI-AGENTS.md).
34
-
35
- ## Quickstart
76
+ ## Install
36
77
 
37
78
  Run the packaged server directly:
38
79
 
@@ -52,149 +93,102 @@ Add it to Claude Code:
52
93
  # macOS/Linux
53
94
  claude mcp add --transport stdio --scope user martin-loop -- npx -y @martinloop/mcp
54
95
 
55
- # Windows PowerShell/cmd
96
+ # Windows PowerShell or cmd.exe
56
97
  claude mcp add --transport stdio --scope user martin-loop -- cmd /c npx -y @martinloop/mcp
57
98
  ```
58
99
 
59
- Generic stdio configuration:
100
+ Generate host config from the CLI when you want minimal, diagnostic, or full-local profiles:
60
101
 
61
- ```json
62
- {
63
- "type": "stdio",
64
- "command": "npx",
65
- "args": ["-y", "@martinloop/mcp"]
66
- }
102
+ ```sh
103
+ martin mcp print-config --host codex --transport stdio --profile minimal
104
+ martin mcp print-config --host claude --transport stdio --profile diagnostic
105
+ martin mcp print-config --host gemini --transport stdio --profile full-local
67
106
  ```
68
107
 
69
- Codex host configuration in `~/.codex/config.toml`:
108
+ `martin mcp install` supports the same host set and only writes when the target file is absent or already contains a Martin Loop block.
109
+
110
+ Codex also supports `~/.codex/config.toml` and project-scoped `.codex/config.toml`:
70
111
 
71
112
  ```toml
72
- [mcp_servers.martin-loop]
113
+ [mcp_servers."martin-loop"]
73
114
  command = "npx"
74
115
  args = ["-y", "@martinloop/mcp"]
116
+ cwd = "C:\\path\\to\\repo"
117
+ startup_timeout_sec = 20
118
+ tool_timeout_sec = 180
119
+ enabled_tools = [
120
+ "martin_doctor",
121
+ "martin_preflight",
122
+ "martin_list_runs",
123
+ "martin_triage_runs",
124
+ "martin_run_dossier",
125
+ ]
126
+ env = { MARTIN_RUNS_DIR = "C:\\path\\to\\runs" }
75
127
  ```
76
128
 
77
- ## Requirements
129
+ If you use `martin mcp install`, it will only write a starter host config when the target file is absent, or when it detects an existing Martin Loop block and can remain idempotent. Otherwise it refuses to overwrite mixed host config so you can merge safely.
78
130
 
79
- - Node 20+
80
- - For live `martin_run` usage, either the `claude` CLI or the `codex` CLI must be available on `PATH`
81
- - For stub or smoke flows, set `MARTIN_LIVE=false`
131
+ When `CODEX_HOME` is set, Codex user-scope installs target `CODEX_HOME\\config.toml` instead of the default user path.
82
132
 
83
- Example stub launch:
133
+ Registry/server identifier: `io.github.Keesan12/martin-loop`
84
134
 
85
- ```sh
86
- MARTIN_LIVE=false npx -y @martinloop/mcp
87
- ```
135
+ ## Host coverage
88
136
 
89
- ## Tool Contract
90
-
91
- | Tool | Purpose | Required input | Important optional input | Notes |
92
- | --- | --- | --- | --- | --- |
93
- | `martin_doctor` | Inspect local readiness and run-store health | none | `workingDirectory`, `runsDir`, `engine` | Read-only setup lane before execution. |
94
- | `martin_preflight` | Normalize and validate a proposed run contract | `objective` | `workingDirectory`, `engine`, `model`, `maxUsd`, `maxIterations`, `maxTokens`, `verificationPlan`, `allowedPaths`, `deniedPaths`, `workspaceId`, `projectId` | Read-only contract check; does not execute work. |
95
- | `martin_run` | Run a governed coding loop | `objective` | `workingDirectory`, `engine`, `model`, `maxUsd`, `maxIterations`, `maxTokens`, `verificationPlan`, `allowedPaths`, `deniedPaths`, `workspaceId`, `projectId` | Unknown arguments are rejected. |
96
- | `martin_inspect` | Read a saved run record or run folder | none | `file`, `runsDir` | `file` may point to a `loop-record.json`, legacy `.jsonl`, or a run directory under the runs root. |
97
- | `martin_status` | Report budget pressure and stop conditions | exactly one of `loopJson`, `file`, `loopId`, or `latest` | `runsDir` | `latest` must be `true` when used. |
98
-
99
- ## Safe-Root Path Model
100
-
101
- This MCP does not let tool callers point at arbitrary filesystem locations. The server resolves tool paths against safe roots chosen when the server starts.
102
-
103
- - `workingDirectory`
104
- Defaults to `MARTIN_MCP_WORKSPACE_ROOT` or the server process current directory. If you pass a value, it must still resolve inside that workspace root. `.` and repo-relative subpaths are the safest choices.
105
- - `file`
106
- For `martin_inspect` and `martin_status`, `file` resolves under the runs root, not the whole machine. Direct file targets must end in `.json` or `.jsonl`; run directories are also accepted where the tool supports them.
107
- - `runsDir`
108
- Defaults to `MARTIN_RUNS_DIR` or `~/.martin/runs`. Passing `runsDir` only re-states or narrows that safe runs root; it does not grant access outside it.
109
- - `allowedPaths` and `deniedPaths`
110
- These are relative glob patterns only. Absolute paths, drive-qualified paths, and patterns containing `..` are rejected.
111
-
112
- Absolute paths can work only when they still resolve inside the corresponding safe root. Escapes above the workspace or runs root are rejected.
113
-
114
- ## Tool Examples
115
-
116
- ### `martin_run`
117
-
118
- ```json
119
- {
120
- "objective": "Fix the auth regression and prove it with tests",
121
- "engine": "codex",
122
- "maxUsd": 3,
123
- "maxIterations": 3,
124
- "maxTokens": 20000,
125
- "verificationPlan": ["pnpm test --filter auth"],
126
- "workingDirectory": ".",
127
- "allowedPaths": ["src/**", "tests/**"],
128
- "deniedPaths": [".env*", "secrets/**"]
129
- }
130
- ```
137
+ - `codex`: local stdio profiles
138
+ - `claude`: local, user, and project scopes
139
+ - `gemini`: local `settings.json` snippets with `includeTools`
140
+ - `generic`: JSON config for MCP-aware wrappers
131
141
 
132
- ### `martin_inspect`
142
+ Operating-system launcher behavior is explicit:
133
143
 
134
- Inspect the default runs root:
144
+ - Windows: `cmd /c npx -y @martinloop/mcp`
145
+ - macOS/Linux: `npx -y @martinloop/mcp`
135
146
 
136
- ```json
137
- {}
138
- ```
147
+ Claude `--scope local` remains CLI-managed. `martin mcp install --host claude --scope local` shells out to Claude Code directly instead of fabricating a repo config file for that scope.
139
148
 
140
- Inspect a specific saved loop record under the runs root:
149
+ ## Discovery metadata
141
150
 
142
- ```json
143
- {
144
- "file": "loop-123/loop-record.json"
145
- }
146
- ```
151
+ - JSON resources now carry `metadata.serverVersion` and `metadata.discoveryRevision`.
152
+ - Environment-specific path details stay in `martin://server/health` instead of low-context discovery metadata.
153
+ - Compact resources expose low-token latest-run summaries, proof cards, budget status, verifier evidence, rollback evidence, and a single recommended next step.
154
+ - Prompts stamp the current server version and discovery revision into their descriptions so hosts can confirm which surface they discovered.
155
+ - The server does **not** advertise `listChanged` yet. That is deliberate: the current discovery surface is stable and versioned, but it does not yet emit authoritative change notifications.
147
156
 
148
- Inspect a subdirectory under the configured runs root:
157
+ ## Runtime Model
149
158
 
150
- ```json
151
- {
152
- "runsDir": "team-a"
153
- }
154
- ```
159
+ - `martin_run` is the only execution entrypoint.
160
+ - All other Martin MCP tools are read-only.
161
+ - Live runs require `claude` or `codex` on `PATH`.
162
+ - Stub or smoke flows use `MARTIN_LIVE=false`.
163
+ - Paths stay bounded to the configured workspace root and runs root.
164
+ - Direct raw-model compatibility is not the target. Martin Loop supports hosts and wrappers that speak MCP; open-source model families such as Gemma or Nemotron should use the `generic` host path through an MCP-capable shell or runtime.
155
165
 
156
- ### `martin_status`
166
+ ## Operator Notes
157
167
 
158
- Status for the latest saved run:
168
+ - `martin_get_verification_results` only reports persisted verification evidence. If evidence is missing, it returns `unavailable` with warnings.
169
+ - `martin_triage_runs` is the fastest way to decide which persisted run deserves attention first.
170
+ - `martin://agent/next-step`, `martin://runs/latest/summary`, and `martin://runs/latest/proof-card` are the best default follow-ups for context-constrained agents.
171
+ - `martin_run_dossier` is the richest single-run inspection surface and is best when a compact receipt says deeper evidence is needed.
172
+ - Resources and prompts reuse the same run-store selectors as the tools; they are discovery surfaces, not a second data model.
173
+ - The recommended host default is the `minimal` profile: `martin_doctor`, `martin_preflight`, `martin_list_runs`, `martin_triage_runs`, and `martin_run_dossier`. Use `diagnostic` for read-only archaeology and `full-local` only when the host should execute runs.
159
174
 
160
- ```json
161
- {
162
- "latest": true
163
- }
164
- ```
175
+ ## Debugging
165
176
 
166
- Status for a specific persisted loop:
177
+ Use the live handshake inspector before you blame the host:
167
178
 
168
- ```json
169
- {
170
- "loopId": "loop-123"
171
- }
179
+ ```sh
180
+ pnpm --filter @martinloop/mcp inspect:live
172
181
  ```
173
182
 
174
- Status from inline JSON:
183
+ If you want the official MCP Inspector UI, point it at the same stdio launch command:
175
184
 
176
- ```json
177
- {
178
- "loopJson": "{\"loopId\":\"loop-123\",\"status\":\"completed\",\"lifecycleState\":\"completed\",\"attempts\":[],\"budget\":{\"maxUsd\":5,\"softLimitUsd\":3,\"maxIterations\":2,\"maxTokens\":1000},\"cost\":{\"actualUsd\":1.25,\"avoidedUsd\":0,\"tokensIn\":20,\"tokensOut\":10}}"
179
- }
185
+ ```sh
186
+ npx @modelcontextprotocol/inspector --command npx --args "-y,@martinloop/mcp"
180
187
  ```
181
188
 
182
- ## Registry Metadata
183
-
184
- The registry manifest artifact for this package is `server.json`. In this repository, that manifest is authored at `packages/mcp/server.json`.
189
+ The stdio server keeps protocol output on stdout and diagnostic logging on stderr. When a host integration goes sideways, confirm the live discovery surface first, then move on to the host config.
185
190
 
186
- Current metadata:
187
-
188
- - npm package: `@martinloop/mcp`
189
- - registry server name: `io.github.Keesan12/martin-loop`
190
- - manifest artifact name: `server.json`
191
-
192
- Official MCP Registry publication is separate from npm publication. After publishing the package to npm, run the publisher from `packages/mcp`:
193
-
194
- ```sh
195
- mcp-publisher login github
196
- mcp-publisher publish
197
- ```
191
+ For WSL or Linux validation, do a native install on that platform before you smoke the package. Reusing Windows-installed `node_modules` across WSL will fail on native dependencies such as `esbuild`, which looks like a transport failure but is really a cross-platform install mismatch.
198
192
 
199
193
  ## Verification
200
194
 
@@ -207,14 +201,23 @@ pnpm --filter @martinloop/mcp build
207
201
  pnpm --filter @martinloop/mcp smoke:pack
208
202
  pnpm --filter @martinloop/mcp smoke:published:pack
209
203
  pnpm --filter @martinloop/mcp verify:release
204
+ pnpm --filter @martin/cli verify:hosts:live
210
205
  pnpm --filter @martinloop/mcp smoke:published
206
+ pnpm --filter @martinloop/mcp inspect:live
211
207
  ```
212
208
 
213
- - `smoke:pack` verifies the packed tarball shape and a stdio MCP launch
214
- - `smoke:published:pack` verifies install-and-run behavior from a freshly packed local tarball before npm publish
215
- - `verify:release` checks metadata parity, release-note presence, and public MCP doc accuracy for the current package version
216
- - `smoke:published` verifies the npm-installed artifact through `npm install` plus live MCP tool calls
209
+ - `smoke:pack` verifies the packed tarball and stdio launch path.
210
+ - `smoke:published:pack` verifies install-and-run behavior from a freshly packed local tarball through the installed `mcp` bin before npm publish.
211
+ - `verify:release` checks metadata parity, release-note presence, install docs, and discovery-surface claims.
212
+ - `@martin/cli verify:hosts:live` proves the generated host config against the real Codex, Claude, and Gemini CLIs on this machine.
213
+ - `smoke:published` remains a post-publish npm gate.
214
+
215
+ ## Compatibility
216
+
217
+ `0.2.5` is the current integrated governed execution cockpit line:
217
218
 
218
- ## Version Notes
219
+ - `martin_run`, `martin_inspect`, `martin_status`, `martin_doctor`, and `martin_preflight` remain backward-compatible.
220
+ - New read-only surfaces are additive.
221
+ - No new write-capable MCP tools are introduced in `0.2.5`.
219
222
 
220
- The root `CHANGELOG.md` is repo-wide and includes non-MCP changes. For the `@martinloop/mcp` surface, prefer this README and `server.json`.
223
+ See `docs/release/MCP-COMPATIBILITY.md`, `docs/release/MCP-0.2.0-RELEASE-NOTES.md`, and `docs/release/MCP-0.2.5-RELEASE-NOTES.md` for the public release contract and delivery sequence.
@@ -0,0 +1,16 @@
1
+ export declare const MARTIN_TOOL_NAMES: readonly ["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"];
2
+ export declare const MARTIN_STARTER_TOOL_NAMES: readonly ["martin_doctor", "martin_preflight", "martin_run", "martin_triage_runs", "martin_run_dossier"];
3
+ export declare const MARTIN_RESOURCE_URIS: readonly ["martin://server/health", "martin://runs/recent", "martin://runs/triage", "martin://guides/mcp-usage", "martin://guides/publish-readiness"];
4
+ export declare const MARTIN_RESOURCE_TEMPLATE_URIS: readonly ["martin://runs/{loopId}", "martin://runs/{loopId}/attempts/{attemptIndex}", "martin://runs/{loopId}/verification"];
5
+ export declare const MARTIN_PROMPT_NAMES: readonly ["martin_governed_coding_kickoff", "martin_debug_failed_run", "martin_publish_readiness_review", "martin_triage_run_store"];
6
+ export interface MartinDiscoveryMetadata {
7
+ serverVersion: string;
8
+ discoveryRevision: string;
9
+ generatedAt: string;
10
+ toolCount: number;
11
+ resourceCount: number;
12
+ resourceTemplateCount: number;
13
+ promptCount: number;
14
+ starterTools: string[];
15
+ }
16
+ export declare function buildMartinDiscoveryMetadata(serverVersion: string): MartinDiscoveryMetadata;
@@ -0,0 +1,62 @@
1
+ import { createHash } from "node:crypto";
2
+ export const MARTIN_TOOL_NAMES = [
3
+ "martin_run",
4
+ "martin_inspect",
5
+ "martin_status",
6
+ "martin_doctor",
7
+ "martin_preflight",
8
+ "martin_list_runs",
9
+ "martin_triage_runs",
10
+ "martin_get_run",
11
+ "martin_get_attempt",
12
+ "martin_get_verification_results",
13
+ "martin_run_dossier"
14
+ ];
15
+ export const MARTIN_STARTER_TOOL_NAMES = [
16
+ "martin_doctor",
17
+ "martin_preflight",
18
+ "martin_run",
19
+ "martin_triage_runs",
20
+ "martin_run_dossier"
21
+ ];
22
+ export const MARTIN_RESOURCE_URIS = [
23
+ "martin://server/health",
24
+ "martin://runs/recent",
25
+ "martin://runs/triage",
26
+ "martin://guides/mcp-usage",
27
+ "martin://guides/publish-readiness"
28
+ ];
29
+ export const MARTIN_RESOURCE_TEMPLATE_URIS = [
30
+ "martin://runs/{loopId}",
31
+ "martin://runs/{loopId}/attempts/{attemptIndex}",
32
+ "martin://runs/{loopId}/verification"
33
+ ];
34
+ export const MARTIN_PROMPT_NAMES = [
35
+ "martin_governed_coding_kickoff",
36
+ "martin_debug_failed_run",
37
+ "martin_publish_readiness_review",
38
+ "martin_triage_run_store"
39
+ ];
40
+ export function buildMartinDiscoveryMetadata(serverVersion) {
41
+ const surface = {
42
+ tools: [...MARTIN_TOOL_NAMES],
43
+ resources: [...MARTIN_RESOURCE_URIS],
44
+ resourceTemplates: [...MARTIN_RESOURCE_TEMPLATE_URIS],
45
+ prompts: [...MARTIN_PROMPT_NAMES],
46
+ starterTools: [...MARTIN_STARTER_TOOL_NAMES]
47
+ };
48
+ const discoveryRevision = createHash("sha256")
49
+ .update(JSON.stringify({ serverVersion, surface }))
50
+ .digest("hex")
51
+ .slice(0, 12);
52
+ return {
53
+ serverVersion,
54
+ discoveryRevision,
55
+ generatedAt: new Date().toISOString(),
56
+ toolCount: surface.tools.length,
57
+ resourceCount: surface.resources.length,
58
+ resourceTemplateCount: surface.resourceTemplates.length,
59
+ promptCount: surface.prompts.length,
60
+ starterTools: [...surface.starterTools]
61
+ };
62
+ }
@@ -0,0 +1,62 @@
1
+ import { type LedgerEvent, type LoopAttemptRecord, type LoopRunRecord } from "./vendor/core/index.js";
2
+ import type { LoopArtifact, LoopAttempt, LoopEvent, LoopTask } from "./vendor/contracts/index.js";
3
+ import { type LoopPreview, type MartinEngine } from "./tools/tool-support.js";
4
+ type PersistedLoopTask = LoopRunRecord["task"] & Partial<Pick<LoopTask, "verificationPlan" | "verificationStack" | "repoRoot" | "allowedPaths" | "deniedPaths" | "acceptanceCriteria" | "mutationMode" | "executionProfile" | "allowedNetworkDomains" | "approvalPolicy">>;
5
+ export type PersistedLoopAttemptRecord = LoopAttemptRecord & Partial<Pick<LoopAttempt, "attemptId" | "summary">>;
6
+ export interface PersistedLoopRecord extends LoopRunRecord {
7
+ workspaceId?: string;
8
+ projectId?: string;
9
+ teamId?: string;
10
+ task: PersistedLoopTask;
11
+ attempts: PersistedLoopAttemptRecord[];
12
+ artifacts?: LoopArtifact[];
13
+ events?: LoopEvent[];
14
+ metadata?: Record<string, string>;
15
+ }
16
+ export interface MartinDiscoveryContext {
17
+ runsRoot: string;
18
+ workingDirectory: string;
19
+ engine?: MartinEngine;
20
+ }
21
+ export interface MartinVerificationSnapshot {
22
+ attemptId?: string;
23
+ attemptIndex?: number;
24
+ timestamp: string;
25
+ lifecycleState: string;
26
+ passed?: boolean;
27
+ summary?: string;
28
+ }
29
+ export interface MartinAttemptSnapshot {
30
+ loopId: string;
31
+ attemptIndex: number;
32
+ loop: LoopPreview;
33
+ attempt: PersistedLoopAttemptRecord;
34
+ verification?: MartinVerificationSnapshot;
35
+ warnings: string[];
36
+ }
37
+ export interface MartinVerificationHistorySnapshot {
38
+ loopId: string;
39
+ loop: LoopPreview;
40
+ verificationCount: number;
41
+ latestVerification?: MartinVerificationSnapshot;
42
+ verificationHistory: MartinVerificationSnapshot[];
43
+ warnings: string[];
44
+ }
45
+ export declare function resolveMartinDiscoveryContext(input?: {
46
+ runsDir?: string;
47
+ workingDirectory?: string;
48
+ engine?: MartinEngine;
49
+ }): MartinDiscoveryContext;
50
+ export declare function loadPersistedLoopRecord(input: {
51
+ loopId: string;
52
+ runsDir?: string;
53
+ }): Promise<{
54
+ source: string;
55
+ loop: PersistedLoopRecord;
56
+ }>;
57
+ export declare function buildAttemptSnapshot(loop: PersistedLoopRecord, requestedAttemptIndex?: number, ledgerEvents?: LedgerEvent[]): MartinAttemptSnapshot;
58
+ export declare function buildVerificationHistorySnapshot(loop: PersistedLoopRecord, ledgerEvents?: LedgerEvent[]): MartinVerificationHistorySnapshot;
59
+ export declare function buildPersistedLoopPreview(loop: PersistedLoopRecord): LoopPreview;
60
+ export declare function parseAttemptIndex(value: string): number;
61
+ export declare function toPrettyJson(value: unknown): string;
62
+ export {};