@martinloop/mcp 0.2.0 → 0.2.7
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/README.md +118 -182
- package/dist/discovery-metadata.d.ts +21 -0
- package/dist/discovery-metadata.js +152 -0
- package/dist/discovery-support.d.ts +62 -0
- package/dist/discovery-support.js +224 -0
- package/dist/package-version.d.ts +1 -0
- package/dist/package-version.js +3 -0
- package/dist/prompts.d.ts +13 -3
- package/dist/prompts.js +537 -74
- package/dist/resources.d.ts +35 -5
- package/dist/resources.js +788 -71
- package/dist/server-validation.d.ts +2 -3
- package/dist/server-validation.js +375 -119
- package/dist/server.d.ts +76 -7
- package/dist/server.js +1478 -394
- package/dist/tools/doctor.d.ts +2 -0
- package/dist/tools/doctor.js +18 -6
- package/dist/tools/eval.d.ts +24 -0
- package/dist/tools/eval.js +65 -0
- package/dist/tools/get-attempt.d.ts +13 -6
- package/dist/tools/get-attempt.js +14 -5
- package/dist/tools/get-run.d.ts +19 -12
- package/dist/tools/get-run.js +20 -11
- package/dist/tools/get-status.d.ts +19 -0
- package/dist/tools/get-status.js +30 -2
- package/dist/tools/get-verification-results.d.ts +10 -7
- package/dist/tools/get-verification-results.js +11 -6
- package/dist/tools/inspect-loop.d.ts +9 -0
- package/dist/tools/inspect-loop.js +11 -2
- package/dist/tools/list-runs.d.ts +25 -5
- package/dist/tools/list-runs.js +21 -4
- package/dist/tools/logs.d.ts +25 -0
- package/dist/tools/logs.js +49 -0
- package/dist/tools/plan.d.ts +20 -0
- package/dist/tools/plan.js +10 -0
- package/dist/tools/pr-tools.d.ts +31 -0
- package/dist/tools/pr-tools.js +111 -0
- package/dist/tools/preflight.d.ts +10 -0
- package/dist/tools/preflight.js +18 -4
- package/dist/tools/run-controls.d.ts +36 -0
- package/dist/tools/run-controls.js +88 -0
- package/dist/tools/run-dossier.d.ts +51 -4
- package/dist/tools/run-dossier.js +100 -5
- package/dist/tools/run-loop.d.ts +19 -0
- package/dist/tools/run-loop.js +61 -4
- package/dist/tools/run-store.d.ts +57 -3
- package/dist/tools/run-store.js +404 -53
- package/dist/tools/tool-errors.d.ts +37 -0
- package/dist/tools/tool-errors.js +170 -0
- package/dist/tools/tool-response.d.ts +16 -0
- package/dist/tools/tool-response.js +34 -0
- package/dist/tools/tool-support.d.ts +92 -2
- package/dist/tools/tool-support.js +385 -63
- package/dist/tools/triage-runs.d.ts +33 -0
- package/dist/tools/triage-runs.js +138 -0
- package/dist/tools/workflow-governance.d.ts +133 -0
- package/dist/tools/workflow-governance.js +581 -0
- package/dist/vendor/adapters/claude-cli.js +0 -1
- package/dist/vendor/adapters/cli-bridge.d.ts +5 -0
- package/dist/vendor/adapters/cli-bridge.js +16 -9
- package/dist/vendor/adapters/direct-provider.js +0 -1
- package/dist/vendor/adapters/index.d.ts +2 -1
- package/dist/vendor/adapters/index.js +2 -1
- package/dist/vendor/adapters/openai-compatible.d.ts +47 -0
- package/dist/vendor/adapters/openai-compatible.js +242 -0
- package/dist/vendor/adapters/runtime-support.js +0 -1
- package/dist/vendor/adapters/stub-agent-cli.js +0 -1
- package/dist/vendor/adapters/stub-direct-provider.js +0 -1
- package/dist/vendor/adapters/verifier-only.js +0 -1
- package/dist/vendor/contracts/governance.js +0 -1
- package/dist/vendor/contracts/index.d.ts +2 -0
- package/dist/vendor/contracts/index.js +1 -1
- package/dist/vendor/contracts/operator.d.ts +19 -0
- package/dist/vendor/contracts/operator.js +11 -0
- package/dist/vendor/core/compiler.js +0 -1
- package/dist/vendor/core/context-integrity.js +0 -1
- package/dist/vendor/core/grounding.js +0 -1
- package/dist/vendor/core/index.js +1 -2
- package/dist/vendor/core/leash.js +19 -12
- package/dist/vendor/core/persistence/compiler.js +0 -1
- package/dist/vendor/core/persistence/index.js +0 -1
- package/dist/vendor/core/persistence/ledger.js +0 -1
- package/dist/vendor/core/persistence/runs-reader.js +0 -1
- package/dist/vendor/core/persistence/store.js +0 -1
- package/dist/vendor/core/policy.js +0 -1
- package/dist/vendor/core/red-blue/red-phase.d.ts +64 -0
- package/dist/vendor/core/red-blue/red-phase.js +135 -0
- package/dist/vendor/core/red-blue/risk-tiers.d.ts +22 -0
- package/dist/vendor/core/red-blue/risk-tiers.js +32 -0
- package/dist/vendor/core/rollback.js +2 -3
- package/dist/workflow-state.d.ts +25 -0
- package/dist/workflow-state.js +102 -0
- package/package.json +12 -7
- package/server.json +2 -2
- package/dist/tools/cockpit-support.d.ts +0 -69
- package/dist/tools/cockpit-support.js +0 -108
package/dist/resources.js
CHANGED
|
@@ -1,89 +1,806 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { buildMartinDiscoveryMetadata } from "./discovery-metadata.js";
|
|
2
|
+
import { MARTIN_MCP_PACKAGE_VERSION } from "./package-version.js";
|
|
3
|
+
import { inspectLoopTool } from "./tools/inspect-loop.js";
|
|
4
|
+
import { martinDoctorTool } from "./tools/doctor.js";
|
|
5
|
+
import { martinTriageRunsTool } from "./tools/triage-runs.js";
|
|
6
|
+
import { martinRunDossierTool } from "./tools/run-dossier.js";
|
|
7
|
+
import { inspectRepoSignals, buildPolicyPackDefinition, buildRepoRiskMap } from "./tools/workflow-governance.js";
|
|
8
|
+
import { buildAttemptSnapshot, buildPersistedLoopPreview, buildVerificationHistorySnapshot, parseAttemptIndex, resolveMartinDiscoveryContext, toPrettyJson } from "./discovery-support.js";
|
|
9
|
+
import { loadDetailedLoopRecord, readLedgerEvents } from "./tools/run-store.js";
|
|
10
|
+
import { invalidArgumentsError, MartinToolError } from "./tools/tool-errors.js";
|
|
11
|
+
export const MARTIN_STATIC_RESOURCE_URIS = {
|
|
12
|
+
serverHealth: "martin://server/health",
|
|
13
|
+
recentRuns: "martin://runs/recent",
|
|
14
|
+
triage: "martin://runs/triage",
|
|
15
|
+
latestRun: "martin://runs/latest",
|
|
16
|
+
latestSummary: "martin://runs/latest/summary",
|
|
17
|
+
latestProofCard: "martin://runs/latest/proof-card",
|
|
18
|
+
latestBudgetStatus: "martin://runs/latest/budget-status",
|
|
19
|
+
latestVerifierEvidence: "martin://runs/latest/verifier-evidence",
|
|
20
|
+
latestRollbackEvidence: "martin://runs/latest/rollback-evidence",
|
|
21
|
+
currentPolicies: "martin://policies/current",
|
|
22
|
+
repoRiskMap: "martin://repo/risk-map",
|
|
23
|
+
verifierResults: "martin://verifiers/results",
|
|
24
|
+
agentNextStep: "martin://agent/next-step",
|
|
25
|
+
mcpUsageGuide: "martin://guides/mcp-usage",
|
|
26
|
+
agentStartGuide: "martin://guides/agent-start",
|
|
27
|
+
commandMapGuide: "martin://guides/command-map",
|
|
28
|
+
ideOnboardingGuide: "martin://guides/ide-onboarding",
|
|
29
|
+
operatingRulesGuide: "martin://guides/operating-rules",
|
|
30
|
+
publishReadinessGuide: "martin://guides/publish-readiness"
|
|
31
|
+
};
|
|
32
|
+
export const MARTIN_RESOURCE_TEMPLATES = [
|
|
33
|
+
{
|
|
34
|
+
name: "martin_run_record",
|
|
35
|
+
title: "Martin Run Record",
|
|
36
|
+
uriTemplate: "martin://runs/{loopId}",
|
|
37
|
+
description: "Read a canonical Martin loop record using the same selector path as martin_status."
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "martin_run_dossier_resource",
|
|
41
|
+
title: "Martin Run Dossier",
|
|
42
|
+
uriTemplate: "martin://runs/{loopId}/dossier",
|
|
43
|
+
description: "Read the dossier-shaped summary for a persisted Martin loop."
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "martin_run_attempt",
|
|
47
|
+
title: "Martin Run Attempt",
|
|
48
|
+
uriTemplate: "martin://runs/{loopId}/attempts/{attemptIndex}",
|
|
49
|
+
description: "Inspect a specific persisted Martin attempt and its linked verification event."
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: "martin_run_verification",
|
|
53
|
+
title: "Martin Run Verification History",
|
|
54
|
+
uriTemplate: "martin://runs/{loopId}/verification",
|
|
55
|
+
description: "Inspect verification.completed events for a persisted Martin loop."
|
|
56
|
+
}
|
|
57
|
+
];
|
|
58
|
+
export const MARTIN_STATIC_RESOURCES = [
|
|
59
|
+
{
|
|
60
|
+
uri: MARTIN_STATIC_RESOURCE_URIS.serverHealth,
|
|
61
|
+
name: "martin_server_health",
|
|
62
|
+
title: "Martin Server Health",
|
|
63
|
+
description: "Health and environment readiness for the Martin MCP server.",
|
|
64
|
+
mimeType: "application/json"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
uri: MARTIN_STATIC_RESOURCE_URIS.recentRuns,
|
|
68
|
+
name: "martin_recent_runs",
|
|
69
|
+
title: "Martin Recent Runs",
|
|
70
|
+
description: "Recent Martin loop previews derived from the current runs root.",
|
|
71
|
+
mimeType: "application/json"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
uri: MARTIN_STATIC_RESOURCE_URIS.triage,
|
|
75
|
+
name: "martin_run_triage",
|
|
76
|
+
title: "Martin Run Triage",
|
|
77
|
+
description: "Priority-ranked Martin runs that likely need attention.",
|
|
78
|
+
mimeType: "application/json"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
uri: MARTIN_STATIC_RESOURCE_URIS.latestRun,
|
|
82
|
+
name: "martin_latest_run",
|
|
83
|
+
title: "Martin Latest Run",
|
|
84
|
+
description: "Full latest-run dossier surface for agents that need more than the compact summary.",
|
|
85
|
+
mimeType: "application/json"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
uri: MARTIN_STATIC_RESOURCE_URIS.latestSummary,
|
|
89
|
+
name: "martin_latest_summary",
|
|
90
|
+
title: "Martin Latest Summary",
|
|
91
|
+
description: "Compact latest-run summary for context-constrained agents.",
|
|
92
|
+
mimeType: "application/json"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
uri: MARTIN_STATIC_RESOURCE_URIS.latestProofCard,
|
|
96
|
+
name: "martin_latest_proof_card",
|
|
97
|
+
title: "Martin Latest Proof Card",
|
|
98
|
+
description: "Small Markdown receipt showing what happened, what Martin prevented, and the next safe action.",
|
|
99
|
+
mimeType: "text/markdown"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
uri: MARTIN_STATIC_RESOURCE_URIS.latestBudgetStatus,
|
|
103
|
+
name: "martin_latest_budget_status",
|
|
104
|
+
title: "Martin Latest Budget Status",
|
|
105
|
+
description: "Compact budget, token, and stop-condition snapshot for the latest run.",
|
|
106
|
+
mimeType: "application/json"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
uri: MARTIN_STATIC_RESOURCE_URIS.latestVerifierEvidence,
|
|
110
|
+
name: "martin_latest_verifier_evidence",
|
|
111
|
+
title: "Martin Latest Verifier Evidence",
|
|
112
|
+
description: "Compact verifier evidence and warnings for the latest run.",
|
|
113
|
+
mimeType: "application/json"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
uri: MARTIN_STATIC_RESOURCE_URIS.latestRollbackEvidence,
|
|
117
|
+
name: "martin_latest_rollback_evidence",
|
|
118
|
+
title: "Martin Latest Rollback Evidence",
|
|
119
|
+
description: "Compact rollback and artifact evidence for the latest run.",
|
|
120
|
+
mimeType: "application/json"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
uri: MARTIN_STATIC_RESOURCE_URIS.currentPolicies,
|
|
124
|
+
name: "martin_current_policies",
|
|
125
|
+
title: "Martin Current Policies",
|
|
126
|
+
description: "Local policy-pack presets and the recommended default pack for the current repo.",
|
|
127
|
+
mimeType: "application/json"
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
uri: MARTIN_STATIC_RESOURCE_URIS.repoRiskMap,
|
|
131
|
+
name: "martin_repo_risk_map",
|
|
132
|
+
title: "Martin Repo Risk Map",
|
|
133
|
+
description: "Sensitive repo surfaces and the recommended policy pack for this workspace.",
|
|
134
|
+
mimeType: "application/json"
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
uri: MARTIN_STATIC_RESOURCE_URIS.verifierResults,
|
|
138
|
+
name: "martin_latest_verifier_results",
|
|
139
|
+
title: "Martin Latest Verifier Results",
|
|
140
|
+
description: "Latest verifier results alias for compact run evidence.",
|
|
141
|
+
mimeType: "application/json"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
uri: MARTIN_STATIC_RESOURCE_URIS.agentNextStep,
|
|
145
|
+
name: "martin_agent_next_step",
|
|
146
|
+
title: "Martin Agent Next Step",
|
|
147
|
+
description: "Single next recommended Martin tool, prompt, or resource for a context-constrained agent.",
|
|
148
|
+
mimeType: "application/json"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
uri: MARTIN_STATIC_RESOURCE_URIS.mcpUsageGuide,
|
|
152
|
+
name: "martin_mcp_usage_guide",
|
|
153
|
+
title: "Martin MCP Usage Guide",
|
|
154
|
+
description: "Recommended workflow for using Martin Loop over MCP.",
|
|
155
|
+
mimeType: "text/markdown"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
uri: MARTIN_STATIC_RESOURCE_URIS.agentStartGuide,
|
|
159
|
+
name: "martin_agent_start_guide",
|
|
160
|
+
title: "Martin Agent Start Guide",
|
|
161
|
+
description: "Short agent-facing guide for using Martin with minimal context and low tool bloat.",
|
|
162
|
+
mimeType: "text/markdown"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
uri: MARTIN_STATIC_RESOURCE_URIS.commandMapGuide,
|
|
166
|
+
name: "martin_command_map_guide",
|
|
167
|
+
title: "Martin Command Map Guide",
|
|
168
|
+
description: "Command-by-command guide for choosing the right Martin tool or surface.",
|
|
169
|
+
mimeType: "text/markdown"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
uri: MARTIN_STATIC_RESOURCE_URIS.ideOnboardingGuide,
|
|
173
|
+
name: "martin_ide_onboarding_guide",
|
|
174
|
+
title: "Martin IDE Onboarding Guide",
|
|
175
|
+
description: "IDE-facing setup guide for making MartinLoop part of the default MCP workflow.",
|
|
176
|
+
mimeType: "text/markdown"
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
uri: MARTIN_STATIC_RESOURCE_URIS.operatingRulesGuide,
|
|
180
|
+
name: "martin_operating_rules_guide",
|
|
181
|
+
title: "Martin Operating Rules",
|
|
182
|
+
description: "Built-in operating rules that tell agents when Martin commands must be used before work proceeds.",
|
|
183
|
+
mimeType: "text/markdown"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
uri: MARTIN_STATIC_RESOURCE_URIS.publishReadinessGuide,
|
|
187
|
+
name: "martin_publish_readiness_guide",
|
|
188
|
+
title: "Martin Publish Readiness Guide",
|
|
189
|
+
description: "Checklist-oriented guide for MCP publish readiness reviews.",
|
|
190
|
+
mimeType: "text/markdown"
|
|
191
|
+
}
|
|
192
|
+
];
|
|
3
193
|
export function listMartinResources() {
|
|
4
|
-
return
|
|
5
|
-
{
|
|
6
|
-
|
|
7
|
-
name: "Martin run summary",
|
|
8
|
-
description: "Read-only summary of recent governed Martin Loop runs.",
|
|
9
|
-
mimeType: "application/json"
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
uri: "martin://runs/latest",
|
|
13
|
-
name: "Latest Martin run",
|
|
14
|
-
description: "Read-only dossier for the newest run in the local run store.",
|
|
15
|
-
mimeType: "application/json"
|
|
16
|
-
}
|
|
17
|
-
];
|
|
194
|
+
return {
|
|
195
|
+
resources: MARTIN_STATIC_RESOURCES.map((resource) => ({ ...resource }))
|
|
196
|
+
};
|
|
18
197
|
}
|
|
19
198
|
export function listMartinResourceTemplates() {
|
|
20
|
-
return
|
|
21
|
-
{
|
|
22
|
-
|
|
23
|
-
name: "Martin run dossier",
|
|
24
|
-
description: "Read-only run dossier by loopId.",
|
|
25
|
-
mimeType: "application/json"
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
uriTemplate: "martin://runs/{loopId}/attempts/{attemptIndex}",
|
|
29
|
-
name: "Martin run attempt",
|
|
30
|
-
description: "Read-only attempt evidence for a run.",
|
|
31
|
-
mimeType: "application/json"
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
uriTemplate: "martin://runs/{loopId}/verification",
|
|
35
|
-
name: "Martin verification results",
|
|
36
|
-
description: "Verifier results extracted from a run ledger.",
|
|
37
|
-
mimeType: "application/json"
|
|
38
|
-
}
|
|
39
|
-
];
|
|
199
|
+
return {
|
|
200
|
+
resourceTemplates: MARTIN_RESOURCE_TEMPLATES.map((template) => ({ ...template }))
|
|
201
|
+
};
|
|
40
202
|
}
|
|
41
|
-
export async function readMartinResource(
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
203
|
+
export async function readMartinResource(input) {
|
|
204
|
+
const context = resolveMartinDiscoveryContext(input);
|
|
205
|
+
switch (input.uri) {
|
|
206
|
+
case MARTIN_STATIC_RESOURCE_URIS.serverHealth: {
|
|
207
|
+
const health = await martinDoctorTool({
|
|
208
|
+
runsDir: context.runsRoot,
|
|
209
|
+
workingDirectory: context.workingDirectory,
|
|
210
|
+
...(context.engine ? { engine: context.engine } : {})
|
|
211
|
+
});
|
|
212
|
+
return jsonResource(input.uri, withDiscoveryMetadata(health, context.runsRoot));
|
|
213
|
+
}
|
|
214
|
+
case MARTIN_STATIC_RESOURCE_URIS.recentRuns: {
|
|
215
|
+
const recentRuns = await inspectLoopTool({ runsDir: context.runsRoot });
|
|
216
|
+
return jsonResource(input.uri, withDiscoveryMetadata(recentRuns, context.runsRoot));
|
|
217
|
+
}
|
|
218
|
+
case MARTIN_STATIC_RESOURCE_URIS.triage: {
|
|
219
|
+
const triage = await martinTriageRunsTool({ runsDir: context.runsRoot });
|
|
220
|
+
return jsonResource(input.uri, withDiscoveryMetadata(triage, context.runsRoot));
|
|
221
|
+
}
|
|
222
|
+
case MARTIN_STATIC_RESOURCE_URIS.latestRun:
|
|
223
|
+
return jsonResource(input.uri, withDiscoveryMetadata(await martinRunDossierTool({ latest: true, runsDir: context.runsRoot }), context.runsRoot));
|
|
224
|
+
case MARTIN_STATIC_RESOURCE_URIS.latestSummary:
|
|
225
|
+
return jsonResource(input.uri, withDiscoveryMetadata(await buildLatestSummaryResource(context.runsRoot), context.runsRoot));
|
|
226
|
+
case MARTIN_STATIC_RESOURCE_URIS.latestProofCard:
|
|
227
|
+
return textResource(input.uri, "text/markdown", await buildLatestProofCardResource(context.runsRoot));
|
|
228
|
+
case MARTIN_STATIC_RESOURCE_URIS.latestBudgetStatus:
|
|
229
|
+
return jsonResource(input.uri, withDiscoveryMetadata(await buildLatestBudgetStatusResource(context.runsRoot), context.runsRoot));
|
|
230
|
+
case MARTIN_STATIC_RESOURCE_URIS.latestVerifierEvidence:
|
|
231
|
+
return jsonResource(input.uri, withDiscoveryMetadata(await buildLatestVerifierEvidenceResource(context.runsRoot), context.runsRoot));
|
|
232
|
+
case MARTIN_STATIC_RESOURCE_URIS.latestRollbackEvidence:
|
|
233
|
+
return jsonResource(input.uri, withDiscoveryMetadata(await buildLatestRollbackEvidenceResource(context.runsRoot), context.runsRoot));
|
|
234
|
+
case MARTIN_STATIC_RESOURCE_URIS.currentPolicies:
|
|
235
|
+
return jsonResource(input.uri, withDiscoveryMetadata(buildCurrentPoliciesResource(context.workingDirectory), context.runsRoot));
|
|
236
|
+
case MARTIN_STATIC_RESOURCE_URIS.repoRiskMap:
|
|
237
|
+
return jsonResource(input.uri, withDiscoveryMetadata(buildRepoRiskMap(inspectRepoSignals(context.workingDirectory)), context.runsRoot));
|
|
238
|
+
case MARTIN_STATIC_RESOURCE_URIS.verifierResults:
|
|
239
|
+
return jsonResource(input.uri, withDiscoveryMetadata(await buildLatestVerifierEvidenceResource(context.runsRoot), context.runsRoot));
|
|
240
|
+
case MARTIN_STATIC_RESOURCE_URIS.agentNextStep:
|
|
241
|
+
return jsonResource(input.uri, withDiscoveryMetadata(await buildAgentNextStepResource(context.runsRoot), context.runsRoot));
|
|
242
|
+
case MARTIN_STATIC_RESOURCE_URIS.mcpUsageGuide:
|
|
243
|
+
return textResource(input.uri, "text/markdown", buildMcpUsageGuide(context.runsRoot));
|
|
244
|
+
case MARTIN_STATIC_RESOURCE_URIS.agentStartGuide:
|
|
245
|
+
return textResource(input.uri, "text/markdown", buildAgentStartGuide(context.runsRoot));
|
|
246
|
+
case MARTIN_STATIC_RESOURCE_URIS.commandMapGuide:
|
|
247
|
+
return textResource(input.uri, "text/markdown", buildCommandMapGuide(context.runsRoot));
|
|
248
|
+
case MARTIN_STATIC_RESOURCE_URIS.ideOnboardingGuide:
|
|
249
|
+
return textResource(input.uri, "text/markdown", buildIdeOnboardingGuide(context.runsRoot));
|
|
250
|
+
case MARTIN_STATIC_RESOURCE_URIS.operatingRulesGuide:
|
|
251
|
+
return textResource(input.uri, "text/markdown", buildOperatingRulesGuide(context.runsRoot));
|
|
252
|
+
case MARTIN_STATIC_RESOURCE_URIS.publishReadinessGuide:
|
|
253
|
+
return textResource(input.uri, "text/markdown", buildPublishReadinessGuide(context.runsRoot));
|
|
254
|
+
default:
|
|
255
|
+
return readDynamicMartinResource({
|
|
256
|
+
uri: input.uri,
|
|
257
|
+
runsDir: context.runsRoot
|
|
258
|
+
});
|
|
45
259
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
260
|
+
}
|
|
261
|
+
function textResource(uri, mimeType, text) {
|
|
262
|
+
return {
|
|
263
|
+
contents: [
|
|
264
|
+
{
|
|
265
|
+
uri,
|
|
266
|
+
mimeType,
|
|
267
|
+
text
|
|
268
|
+
}
|
|
269
|
+
]
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function jsonResource(uri, value) {
|
|
273
|
+
return textResource(uri, "application/json", toPrettyJson(value));
|
|
274
|
+
}
|
|
275
|
+
async function readDynamicMartinResource(input) {
|
|
276
|
+
const runMatch = /^martin:\/\/runs\/([^/]+)$/u.exec(input.uri);
|
|
277
|
+
if (runMatch?.[1]) {
|
|
278
|
+
const loopId = decodeURIComponent(runMatch[1]);
|
|
279
|
+
const detail = await loadDetailedLoopRecord({ loopId, runsDir: input.runsDir });
|
|
280
|
+
const ledgerEvents = await readLedgerEvents(detail);
|
|
281
|
+
const loop = detail.loop;
|
|
282
|
+
const verification = buildVerificationHistorySnapshot(loop, ledgerEvents);
|
|
283
|
+
return jsonResource(input.uri, withDiscoveryMetadata({
|
|
284
|
+
source: detail.source,
|
|
285
|
+
loop: buildPersistedLoopPreview(loop),
|
|
286
|
+
task: loop.task,
|
|
287
|
+
budget: loop.budget,
|
|
288
|
+
cost: loop.cost,
|
|
289
|
+
attempts: loop.attempts,
|
|
290
|
+
verification,
|
|
291
|
+
warnings: [...detail.warnings, ...verification.warnings]
|
|
292
|
+
}, input.runsDir));
|
|
49
293
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
294
|
+
const dossierMatch = /^martin:\/\/runs\/([^/]+)\/dossier$/u.exec(input.uri);
|
|
295
|
+
if (dossierMatch?.[1]) {
|
|
296
|
+
const loopId = decodeURIComponent(dossierMatch[1]);
|
|
297
|
+
const dossier = await martinRunDossierTool({ loopId, runsDir: input.runsDir });
|
|
298
|
+
return jsonResource(input.uri, withDiscoveryMetadata(dossier, input.runsDir));
|
|
53
299
|
}
|
|
54
|
-
|
|
55
|
-
|
|
300
|
+
const attemptMatch = /^martin:\/\/runs\/([^/]+)\/attempts\/([^/]+)$/u.exec(input.uri);
|
|
301
|
+
if (attemptMatch?.[1] && attemptMatch[2]) {
|
|
302
|
+
const loopId = decodeURIComponent(attemptMatch[1]);
|
|
303
|
+
const attemptIndex = parseAttemptIndex(decodeURIComponent(attemptMatch[2]));
|
|
304
|
+
const detail = await loadDetailedLoopRecord({ loopId, runsDir: input.runsDir });
|
|
305
|
+
const ledgerEvents = await readLedgerEvents(detail);
|
|
306
|
+
const loop = detail.loop;
|
|
307
|
+
const attempt = buildAttemptSnapshot(loop, attemptIndex, ledgerEvents);
|
|
308
|
+
return jsonResource(input.uri, withDiscoveryMetadata({
|
|
309
|
+
...attempt,
|
|
310
|
+
warnings: [...detail.warnings, ...attempt.warnings]
|
|
311
|
+
}, input.runsDir));
|
|
56
312
|
}
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
59
|
-
|
|
313
|
+
const verificationMatch = /^martin:\/\/runs\/([^/]+)\/verification$/u.exec(input.uri);
|
|
314
|
+
if (verificationMatch?.[1]) {
|
|
315
|
+
const loopId = decodeURIComponent(verificationMatch[1]);
|
|
316
|
+
const detail = await loadDetailedLoopRecord({ loopId, runsDir: input.runsDir });
|
|
317
|
+
const ledgerEvents = await readLedgerEvents(detail);
|
|
318
|
+
const loop = detail.loop;
|
|
319
|
+
const verification = buildVerificationHistorySnapshot(loop, ledgerEvents);
|
|
320
|
+
return jsonResource(input.uri, withDiscoveryMetadata({
|
|
321
|
+
...verification,
|
|
322
|
+
warnings: [...detail.warnings, ...verification.warnings]
|
|
323
|
+
}, input.runsDir));
|
|
60
324
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
325
|
+
throw invalidArgumentsError(`Unknown resource URI '${input.uri}'.`, "Use resources/list or resources/templates/list to discover Martin resource URIs.");
|
|
326
|
+
}
|
|
327
|
+
async function loadLatestRunForCompactResource(runsRoot) {
|
|
328
|
+
try {
|
|
329
|
+
return {
|
|
330
|
+
empty: false,
|
|
331
|
+
detail: await loadDetailedLoopRecord({ latest: true, runsDir: runsRoot }),
|
|
332
|
+
warnings: []
|
|
333
|
+
};
|
|
64
334
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
335
|
+
catch (error) {
|
|
336
|
+
if (error instanceof MartinToolError && error.code === "no_loop_records") {
|
|
337
|
+
return {
|
|
338
|
+
empty: true,
|
|
339
|
+
warnings: [
|
|
340
|
+
"No Martin run records were found yet.",
|
|
341
|
+
"Run `npx martin-loop demo`, then run a governed task or set MARTIN_LIVE=false for a no-spend local proof run."
|
|
342
|
+
]
|
|
343
|
+
};
|
|
69
344
|
}
|
|
70
|
-
|
|
71
|
-
return asJsonResource(uri, getAttempt(loop, parsedAttempt));
|
|
345
|
+
throw error;
|
|
72
346
|
}
|
|
73
|
-
|
|
74
|
-
|
|
347
|
+
}
|
|
348
|
+
async function buildLatestSummaryResource(runsRoot) {
|
|
349
|
+
const latest = await loadLatestRunForCompactResource(runsRoot);
|
|
350
|
+
if (latest.empty || !latest.detail) {
|
|
351
|
+
return compactEmptyState("latest-summary", runsRoot, latest.warnings);
|
|
75
352
|
}
|
|
76
|
-
|
|
353
|
+
const ledgerEvents = await readLedgerEvents(latest.detail);
|
|
354
|
+
const loop = latest.detail.loop;
|
|
355
|
+
const verification = buildVerificationHistorySnapshot(loop, ledgerEvents);
|
|
356
|
+
const preview = buildPersistedLoopPreview(loop);
|
|
357
|
+
const nextStep = inferAgentNextStep(loop, verification);
|
|
358
|
+
return {
|
|
359
|
+
kind: "latest-summary",
|
|
360
|
+
loop: preview,
|
|
361
|
+
task: {
|
|
362
|
+
title: loop.task?.title,
|
|
363
|
+
objective: loop.task?.objective,
|
|
364
|
+
verificationPlan: loop.task?.verificationPlan ?? []
|
|
365
|
+
},
|
|
366
|
+
budget: loop.budget,
|
|
367
|
+
cost: {
|
|
368
|
+
actualUsd: loop.cost.actualUsd,
|
|
369
|
+
avoidedUsdEstimate: loop.cost.avoidedUsd ?? 0,
|
|
370
|
+
tokensIn: loop.cost.tokensIn,
|
|
371
|
+
tokensOut: loop.cost.tokensOut,
|
|
372
|
+
estimateLabel: "Cost and avoided-spend fields are local run estimates unless your adapter reported authoritative usage."
|
|
373
|
+
},
|
|
374
|
+
verification: {
|
|
375
|
+
status: verification.latestVerification?.passed === true
|
|
376
|
+
? "passed"
|
|
377
|
+
: verification.latestVerification?.passed === false
|
|
378
|
+
? "failed"
|
|
379
|
+
: "unavailable",
|
|
380
|
+
latest: verification.latestVerification,
|
|
381
|
+
count: verification.verificationCount
|
|
382
|
+
},
|
|
383
|
+
whatMartinPrevented: describePrevention(loop),
|
|
384
|
+
nextStep,
|
|
385
|
+
warnings: [...latest.detail.warnings, ...verification.warnings]
|
|
386
|
+
};
|
|
77
387
|
}
|
|
78
|
-
function
|
|
388
|
+
async function buildLatestBudgetStatusResource(runsRoot) {
|
|
389
|
+
const latest = await loadLatestRunForCompactResource(runsRoot);
|
|
390
|
+
if (latest.empty || !latest.detail) {
|
|
391
|
+
return compactEmptyState("budget-status", runsRoot, latest.warnings);
|
|
392
|
+
}
|
|
393
|
+
const loop = latest.detail.loop;
|
|
394
|
+
const preview = buildPersistedLoopPreview(loop);
|
|
79
395
|
return {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
396
|
+
kind: "budget-status",
|
|
397
|
+
loopId: loop.loopId,
|
|
398
|
+
lifecycleState: loop.lifecycleState,
|
|
399
|
+
shouldStop: preview.shouldStop,
|
|
400
|
+
pressure: preview.pressure,
|
|
401
|
+
budget: loop.budget,
|
|
402
|
+
cost: {
|
|
403
|
+
actualUsd: loop.cost.actualUsd,
|
|
404
|
+
avoidedUsdEstimate: loop.cost.avoidedUsd ?? 0,
|
|
405
|
+
tokensIn: loop.cost.tokensIn,
|
|
406
|
+
tokensOut: loop.cost.tokensOut,
|
|
407
|
+
estimateLabel: "Avoided USD and token fields are estimates unless backed by adapter usage receipts."
|
|
408
|
+
},
|
|
409
|
+
remaining: {
|
|
410
|
+
budgetUsd: preview.remainingBudgetUsd,
|
|
411
|
+
iterations: preview.remainingIterations,
|
|
412
|
+
tokens: preview.remainingTokens
|
|
413
|
+
},
|
|
414
|
+
whatStoppedOrWillStopNext: preview.shouldStop
|
|
415
|
+
? `Martin is at a stop condition: ${loop.lifecycleState}.`
|
|
416
|
+
: "Martin still has budget/iteration/token room, but preflight should run before another attempt."
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
async function buildLatestVerifierEvidenceResource(runsRoot) {
|
|
420
|
+
const latest = await loadLatestRunForCompactResource(runsRoot);
|
|
421
|
+
if (latest.empty || !latest.detail) {
|
|
422
|
+
return compactEmptyState("verifier-evidence", runsRoot, latest.warnings);
|
|
423
|
+
}
|
|
424
|
+
const ledgerEvents = await readLedgerEvents(latest.detail);
|
|
425
|
+
const loop = latest.detail.loop;
|
|
426
|
+
const verification = buildVerificationHistorySnapshot(loop, ledgerEvents);
|
|
427
|
+
return {
|
|
428
|
+
kind: "verifier-evidence",
|
|
429
|
+
loopId: loop.loopId,
|
|
430
|
+
status: verification.latestVerification?.passed === true
|
|
431
|
+
? "passed"
|
|
432
|
+
: verification.latestVerification?.passed === false
|
|
433
|
+
? "failed"
|
|
434
|
+
: "unavailable",
|
|
435
|
+
latestVerification: verification.latestVerification,
|
|
436
|
+
verificationCount: verification.verificationCount,
|
|
437
|
+
verificationHistory: verification.verificationHistory.slice(-3),
|
|
438
|
+
warnings: [...latest.detail.warnings, ...verification.warnings],
|
|
439
|
+
nextSafeAction: inferAgentNextStep(loop, verification)
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
async function buildLatestRollbackEvidenceResource(runsRoot) {
|
|
443
|
+
const latest = await loadLatestRunForCompactResource(runsRoot);
|
|
444
|
+
if (latest.empty || !latest.detail) {
|
|
445
|
+
return compactEmptyState("rollback-evidence", runsRoot, latest.warnings);
|
|
446
|
+
}
|
|
447
|
+
const loop = latest.detail.loop;
|
|
448
|
+
const artifacts = loop.artifacts ?? [];
|
|
449
|
+
const rollbackArtifacts = artifacts.filter((artifact) => /rollback|restore|diff|patch/iu.test(`${artifact.kind} ${artifact.label} ${artifact.uri}`));
|
|
450
|
+
return {
|
|
451
|
+
kind: "rollback-evidence",
|
|
452
|
+
loopId: loop.loopId,
|
|
453
|
+
artifactCount: artifacts.length,
|
|
454
|
+
rollbackEvidenceCount: rollbackArtifacts.length,
|
|
455
|
+
rollbackEvidence: rollbackArtifacts.slice(0, 5).map((artifact) => ({
|
|
456
|
+
artifactId: artifact.artifactId,
|
|
457
|
+
kind: artifact.kind,
|
|
458
|
+
label: artifact.label,
|
|
459
|
+
uri: artifact.uri
|
|
460
|
+
})),
|
|
461
|
+
boundary: rollbackArtifacts.length > 0
|
|
462
|
+
? "Rollback or diff evidence exists in the local run artifacts."
|
|
463
|
+
: "No rollback artifact was found in this compact view; inspect the full dossier before claiming rollback evidence.",
|
|
464
|
+
nextSafeAction: "If rollback evidence is required, call `martin_run_dossier` or read `martin://runs/{loopId}` before proceeding."
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
async function buildAgentNextStepResource(runsRoot) {
|
|
468
|
+
const latest = await loadLatestRunForCompactResource(runsRoot);
|
|
469
|
+
if (latest.empty || !latest.detail) {
|
|
470
|
+
return {
|
|
471
|
+
...compactEmptyState("agent-next-step", runsRoot, latest.warnings),
|
|
472
|
+
nextTool: "martin_doctor",
|
|
473
|
+
reason: "No run store evidence exists yet; confirm environment and run-store visibility first."
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
const ledgerEvents = await readLedgerEvents(latest.detail);
|
|
477
|
+
const loop = latest.detail.loop;
|
|
478
|
+
const verification = buildVerificationHistorySnapshot(loop, ledgerEvents);
|
|
479
|
+
const nextStep = inferAgentNextStep(loop, verification);
|
|
480
|
+
return {
|
|
481
|
+
kind: "agent-next-step",
|
|
482
|
+
loopId: loop.loopId,
|
|
483
|
+
nextStep,
|
|
484
|
+
compactContext: {
|
|
485
|
+
status: loop.status,
|
|
486
|
+
lifecycleState: loop.lifecycleState,
|
|
487
|
+
attempts: loop.attempts.length,
|
|
488
|
+
latestFailureClass: loop.attempts.at(-1)?.failureClass,
|
|
489
|
+
verifier: verification.latestVerification?.passed === true
|
|
490
|
+
? "passed"
|
|
491
|
+
: verification.latestVerification?.passed === false
|
|
492
|
+
? "failed"
|
|
493
|
+
: "unavailable"
|
|
494
|
+
},
|
|
495
|
+
requiredWorkflow: [
|
|
496
|
+
"martin_doctor",
|
|
497
|
+
"martin_plan",
|
|
498
|
+
"martin_preflight",
|
|
499
|
+
"martin_run",
|
|
500
|
+
"martin_dossier",
|
|
501
|
+
"martin_eval"
|
|
502
|
+
],
|
|
503
|
+
preferredResource: MARTIN_STATIC_RESOURCE_URIS.latestSummary,
|
|
504
|
+
proofCard: MARTIN_STATIC_RESOURCE_URIS.latestProofCard,
|
|
505
|
+
operatingRules: MARTIN_STATIC_RESOURCE_URIS.operatingRulesGuide
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
async function buildLatestProofCardResource(runsRoot) {
|
|
509
|
+
const latest = await loadLatestRunForCompactResource(runsRoot);
|
|
510
|
+
if (latest.empty || !latest.detail) {
|
|
511
|
+
return [
|
|
512
|
+
"# Martin Proof Card",
|
|
513
|
+
"",
|
|
514
|
+
"Status: no run evidence yet",
|
|
515
|
+
"",
|
|
516
|
+
"What happened: Martin has not found a local run record in this runs root.",
|
|
517
|
+
"What Martin prevented: unknown until a governed run executes.",
|
|
518
|
+
"Next safe action: call `martin_doctor`, run `npx martin-loop demo`, then inspect `martin://runs/latest/summary`.",
|
|
519
|
+
"",
|
|
520
|
+
"Estimate note: no cost or token savings are claimed without run evidence.",
|
|
521
|
+
""
|
|
522
|
+
].join("\n");
|
|
523
|
+
}
|
|
524
|
+
const ledgerEvents = await readLedgerEvents(latest.detail);
|
|
525
|
+
const loop = latest.detail.loop;
|
|
526
|
+
const verification = buildVerificationHistorySnapshot(loop, ledgerEvents);
|
|
527
|
+
const preview = buildPersistedLoopPreview(loop);
|
|
528
|
+
const latestAttempt = loop.attempts.at(-1);
|
|
529
|
+
const verifierStatus = verification.latestVerification?.passed === true
|
|
530
|
+
? "passed"
|
|
531
|
+
: verification.latestVerification?.passed === false
|
|
532
|
+
? "failed honestly"
|
|
533
|
+
: "unavailable";
|
|
534
|
+
return [
|
|
535
|
+
"# Martin Proof Card",
|
|
536
|
+
"",
|
|
537
|
+
`Run: \`${loop.loopId}\``,
|
|
538
|
+
`Status: ${loop.status} / ${loop.lifecycleState}`,
|
|
539
|
+
`Attempts: ${loop.attempts.length}`,
|
|
540
|
+
`Spend: $${loop.cost.actualUsd.toFixed(2)} actual, $${(loop.cost.avoidedUsd ?? 0).toFixed(2)} avoided estimate`,
|
|
541
|
+
`Tokens: ${loop.cost.tokensIn} in / ${loop.cost.tokensOut} out`,
|
|
542
|
+
`Verifier: ${verifierStatus}`,
|
|
543
|
+
"",
|
|
544
|
+
`What happened: ${latestAttempt?.summary ?? loop.task?.objective ?? "Martin produced a persisted governed run record."}`,
|
|
545
|
+
`What Martin prevented: ${describePrevention(loop).join("; ")}`,
|
|
546
|
+
`Budget state: ${preview.shouldStop ? "stop condition reached" : "budget still available"}; ${preview.remainingIterations} iteration(s) and ${preview.remainingTokens} token(s) remain.`,
|
|
547
|
+
`Next safe action: ${inferAgentNextStep(loop, verification).instruction}`,
|
|
548
|
+
"",
|
|
549
|
+
"Evidence links:",
|
|
550
|
+
`- Summary: \`${MARTIN_STATIC_RESOURCE_URIS.latestSummary}\``,
|
|
551
|
+
`- Verifier: \`${MARTIN_STATIC_RESOURCE_URIS.latestVerifierEvidence}\``,
|
|
552
|
+
`- Rollback/artifacts: \`${MARTIN_STATIC_RESOURCE_URIS.latestRollbackEvidence}\``,
|
|
553
|
+
"",
|
|
554
|
+
"Estimate note: avoided spend and token savings are directional local estimates unless backed by adapter/provider usage receipts.",
|
|
555
|
+
""
|
|
556
|
+
].join("\n");
|
|
557
|
+
}
|
|
558
|
+
function compactEmptyState(kind, runsRoot, warnings) {
|
|
559
|
+
return {
|
|
560
|
+
kind,
|
|
561
|
+
status: "empty",
|
|
562
|
+
runsRoot,
|
|
563
|
+
summary: "No Martin run records are available yet.",
|
|
564
|
+
nextStep: "Run `martin doctor`, create the demo workspace with `npx martin-loop demo`, then run a no-spend stub task with MARTIN_LIVE=false.",
|
|
565
|
+
warnings
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
function buildCurrentPoliciesResource(workingDirectory) {
|
|
569
|
+
const signals = inspectRepoSignals(workingDirectory);
|
|
570
|
+
const recommended = buildPolicyPackDefinition(undefined, signals);
|
|
571
|
+
return {
|
|
572
|
+
recommended: recommended.name,
|
|
573
|
+
packs: [
|
|
574
|
+
buildPolicyPackDefinition("solo-founder", signals),
|
|
575
|
+
buildPolicyPackDefinition("startup-team", signals),
|
|
576
|
+
buildPolicyPackDefinition("enterprise-strict", signals),
|
|
577
|
+
buildPolicyPackDefinition("oss-maintainer", signals),
|
|
578
|
+
buildPolicyPackDefinition("security-sensitive", signals)
|
|
86
579
|
]
|
|
87
580
|
};
|
|
88
581
|
}
|
|
89
|
-
|
|
582
|
+
function describePrevention(loop) {
|
|
583
|
+
const prevented = [];
|
|
584
|
+
const latestAttempt = loop.attempts.at(-1);
|
|
585
|
+
if (loop.lifecycleState === "budget_exit" || loop.lifecycleState === "diminishing_returns") {
|
|
586
|
+
prevented.push("unsafe or uneconomical retry continuation");
|
|
587
|
+
}
|
|
588
|
+
if (latestAttempt?.failureClass) {
|
|
589
|
+
prevented.push(`unlabeled failure drift (${latestAttempt.failureClass})`);
|
|
590
|
+
}
|
|
591
|
+
if ((loop.cost.avoidedUsd ?? 0) > 0) {
|
|
592
|
+
prevented.push("estimated additional spend");
|
|
593
|
+
}
|
|
594
|
+
if (loop.status !== "completed") {
|
|
595
|
+
prevented.push("false success claims before verifier-backed completion");
|
|
596
|
+
}
|
|
597
|
+
return prevented.length > 0 ? prevented : ["no extra prevention claim available from this compact record"];
|
|
598
|
+
}
|
|
599
|
+
function inferAgentNextStep(loop, verification) {
|
|
600
|
+
if (verification.latestVerification?.passed === false) {
|
|
601
|
+
return {
|
|
602
|
+
action: "debug_failed_run",
|
|
603
|
+
toolOrResource: "martin_debug_failed_run",
|
|
604
|
+
instruction: `Use prompt \`martin_debug_failed_run\` for loop \`${loop.loopId}\`, then rerun only after the verifier failure is understood.`
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
if (loop.lifecycleState === "budget_exit" || loop.lifecycleState === "diminishing_returns") {
|
|
608
|
+
return {
|
|
609
|
+
action: "triage_before_retry",
|
|
610
|
+
toolOrResource: "martin_triage_runs",
|
|
611
|
+
instruction: "Call `martin_triage_runs` and inspect the proof card before spending another attempt."
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
if (loop.status === "completed" && verification.latestVerification?.passed === true) {
|
|
615
|
+
return {
|
|
616
|
+
action: "prove_and_share",
|
|
617
|
+
toolOrResource: MARTIN_STATIC_RESOURCE_URIS.latestProofCard,
|
|
618
|
+
instruction: "Read the proof card and full dossier before sharing or promoting the result."
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
return {
|
|
622
|
+
action: "preflight_next_attempt",
|
|
623
|
+
toolOrResource: "martin_preflight",
|
|
624
|
+
instruction: "Call `martin_preflight` with explicit verifier, budget, and path scope before the next run."
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
function buildMcpUsageGuide(runsRoot) {
|
|
628
|
+
const metadata = buildMartinDiscoveryMetadata(MARTIN_MCP_PACKAGE_VERSION);
|
|
629
|
+
return `# Martin Loop MCP Usage
|
|
630
|
+
|
|
631
|
+
Discovery revision: \`${metadata.discoveryRevision}\`
|
|
632
|
+
Server version: \`${metadata.serverVersion}\`
|
|
633
|
+
Runs root: \`${runsRoot}\`
|
|
634
|
+
|
|
635
|
+
Martin Loop exposes governed coding workflows over MCP. Use the server health and run-store views to decide when to preflight, execute, inspect, or escalate.
|
|
636
|
+
|
|
637
|
+
## Recommended Flow
|
|
638
|
+
|
|
639
|
+
1. Read \`${MARTIN_STATIC_RESOURCE_URIS.serverHealth}\` or call \`martin_doctor\` to confirm the environment and run-store visibility.
|
|
640
|
+
2. Use the \`martin_governed_coding_kickoff\` prompt to frame a governed coding request.
|
|
641
|
+
3. Call \`martin_preflight\` before \`martin_run\` when the task or safety envelope is non-trivial.
|
|
642
|
+
4. After execution, inspect \`${MARTIN_STATIC_RESOURCE_URIS.recentRuns}\`, \`martin://runs/{loopId}\`, and \`martin://runs/{loopId}/verification\`.
|
|
643
|
+
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.
|
|
644
|
+
6. Read \`${MARTIN_STATIC_RESOURCE_URIS.triage}\` or call \`martin_triage_runs\` to prioritize which run needs attention first.
|
|
645
|
+
7. Use \`martin_debug_failed_run\` when a loop exits failed, budget-bound, or escalated.
|
|
646
|
+
|
|
647
|
+
## Current Martin MCP Surface
|
|
648
|
+
|
|
649
|
+
- 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\`
|
|
650
|
+
- 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.mcpUsageGuide}\`, \`${MARTIN_STATIC_RESOURCE_URIS.agentStartGuide}\`, \`${MARTIN_STATIC_RESOURCE_URIS.publishReadinessGuide}\`
|
|
651
|
+
- Resource templates: \`martin://runs/{loopId}\`, \`martin://runs/{loopId}/attempts/{attemptIndex}\`, \`martin://runs/{loopId}/verification\`
|
|
652
|
+
- 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\`
|
|
653
|
+
|
|
654
|
+
## Notes
|
|
655
|
+
|
|
656
|
+
- Discovery helpers read the existing Martin run-store; they do not create new schema.
|
|
657
|
+
- Verification history is derived from persisted \`verification.completed\` evidence in loop records and ledgers.
|
|
658
|
+
- Attempt inspection stays aligned with the same loop selectors used by \`martin_status\` and \`martin_inspect\`.
|
|
659
|
+
`;
|
|
660
|
+
}
|
|
661
|
+
function buildAgentStartGuide(runsRoot) {
|
|
662
|
+
const metadata = buildMartinDiscoveryMetadata(MARTIN_MCP_PACKAGE_VERSION);
|
|
663
|
+
return `# Agent Start Here
|
|
664
|
+
|
|
665
|
+
Discovery revision: \`${metadata.discoveryRevision}\`
|
|
666
|
+
Server version: \`${metadata.serverVersion}\`
|
|
667
|
+
Runs root: \`${runsRoot}\`
|
|
668
|
+
|
|
669
|
+
Use Martin Loop as the local governor before you spend agent tokens or retry a failed coding loop.
|
|
670
|
+
|
|
671
|
+
## Cheap Default Flow
|
|
672
|
+
|
|
673
|
+
1. Read \`${MARTIN_STATIC_RESOURCE_URIS.agentNextStep}\` first. It is the smallest "what should I do now?" payload.
|
|
674
|
+
2. If no runs exist, call \`martin_doctor\`, then \`martin_preflight\`.
|
|
675
|
+
3. If a run exists, read \`${MARTIN_STATIC_RESOURCE_URIS.latestSummary}\` before reading full run JSON.
|
|
676
|
+
4. If the verifier failed, use prompt \`martin_debug_failed_run\` or \`martin_triage\`.
|
|
677
|
+
5. If you need a shareable receipt, read \`${MARTIN_STATIC_RESOURCE_URIS.latestProofCard}\`.
|
|
678
|
+
|
|
679
|
+
## Install Profiles
|
|
680
|
+
|
|
681
|
+
- \`minimal\` (default): doctor, preflight, list, triage, dossier. Good for low tool bloat.
|
|
682
|
+
- \`diagnostic\`: read-only inspection tools for debugging without execution.
|
|
683
|
+
- \`full-local\`: all local tools, including \`martin_run\`.
|
|
684
|
+
- \`github-review\`: review-oriented local profile for PR drafting and reviewer evidence.
|
|
685
|
+
- \`starter\` and \`full\`: compatibility aliases.
|
|
686
|
+
|
|
687
|
+
## Copy-Paste Agent Rule
|
|
688
|
+
|
|
689
|
+
Before running or retrying an autonomous coding task, call Martin. Prefer compact resources first, then full dossiers only when the compact receipt says more evidence is needed. Never claim success unless Martin shows verifier-backed completion or a clear blocked reason.
|
|
690
|
+
`;
|
|
691
|
+
}
|
|
692
|
+
function buildCommandMapGuide(runsRoot) {
|
|
693
|
+
const metadata = buildMartinDiscoveryMetadata(MARTIN_MCP_PACKAGE_VERSION);
|
|
694
|
+
return `# Martin Command Map
|
|
695
|
+
|
|
696
|
+
Discovery revision: \`${metadata.discoveryRevision}\`
|
|
697
|
+
Server version: \`${metadata.serverVersion}\`
|
|
698
|
+
Runs root: \`${runsRoot}\`
|
|
699
|
+
|
|
700
|
+
Use this guide when an IDE or agent needs to know which Martin surface to call next.
|
|
701
|
+
|
|
702
|
+
## Default Governed Sequence
|
|
703
|
+
|
|
704
|
+
1. \`martin_doctor\` — confirm environment and visibility.
|
|
705
|
+
2. \`martin_plan\` — propose the bounded approach without spending a run.
|
|
706
|
+
3. \`martin_preflight\` — turn the plan into an explicit contract.
|
|
707
|
+
4. \`martin_run\` — execute only after the contract is safe.
|
|
708
|
+
5. \`martin_dossier\` — inspect what happened and what Martin prevented.
|
|
709
|
+
6. \`martin_eval\` — convert the result into review posture when needed.
|
|
710
|
+
|
|
711
|
+
## When To Use Which Surface
|
|
712
|
+
|
|
713
|
+
- Need the smallest next action: \`${MARTIN_STATIC_RESOURCE_URIS.agentNextStep}\`
|
|
714
|
+
- Need a quick receipt: \`${MARTIN_STATIC_RESOURCE_URIS.latestSummary}\`
|
|
715
|
+
- Need a shareable proof object: \`${MARTIN_STATIC_RESOURCE_URIS.latestProofCard}\`
|
|
716
|
+
- Need a full run review: \`martin_dossier\`
|
|
717
|
+
- Need to decide whether to retry: \`martin_triage_runs\`
|
|
718
|
+
- Need IDE setup guidance: \`${MARTIN_STATIC_RESOURCE_URIS.ideOnboardingGuide}\`
|
|
719
|
+
`;
|
|
720
|
+
}
|
|
721
|
+
function buildIdeOnboardingGuide(runsRoot) {
|
|
722
|
+
const metadata = buildMartinDiscoveryMetadata(MARTIN_MCP_PACKAGE_VERSION);
|
|
723
|
+
return `# Martin IDE Onboarding
|
|
724
|
+
|
|
725
|
+
Discovery revision: \`${metadata.discoveryRevision}\`
|
|
726
|
+
Server version: \`${metadata.serverVersion}\`
|
|
727
|
+
Runs root: \`${runsRoot}\`
|
|
728
|
+
|
|
729
|
+
Use this guide after the MCP server is installed so the host naturally uses MartinLoop during real work.
|
|
730
|
+
|
|
731
|
+
## IDE Default Flow
|
|
732
|
+
|
|
733
|
+
1. Read \`${MARTIN_STATIC_RESOURCE_URIS.agentStartGuide}\`
|
|
734
|
+
2. Read \`${MARTIN_STATIC_RESOURCE_URIS.operatingRulesGuide}\`
|
|
735
|
+
3. Use prompt \`martin_start\` or \`martin_governed_coding_kickoff\`
|
|
736
|
+
4. Call \`martin_doctor\`
|
|
737
|
+
5. Call \`martin_plan\`
|
|
738
|
+
6. Call \`martin_preflight\`
|
|
739
|
+
7. Only then call \`martin_run\`
|
|
740
|
+
|
|
741
|
+
## Goal
|
|
742
|
+
|
|
743
|
+
MartinLoop should become the normal path for coding work in the host, not a manual extra step the human has to remember.
|
|
744
|
+
`;
|
|
745
|
+
}
|
|
746
|
+
function buildOperatingRulesGuide(runsRoot) {
|
|
747
|
+
const metadata = buildMartinDiscoveryMetadata(MARTIN_MCP_PACKAGE_VERSION);
|
|
748
|
+
return `# Martin Operating Rules
|
|
749
|
+
|
|
750
|
+
Discovery revision: \`${metadata.discoveryRevision}\`
|
|
751
|
+
Server version: \`${metadata.serverVersion}\`
|
|
752
|
+
Runs root: \`${runsRoot}\`
|
|
753
|
+
|
|
754
|
+
Use these rules inside the IDE or MCP host as the default MartinLoop operating posture.
|
|
755
|
+
|
|
756
|
+
## Required Sequence Before Real Work
|
|
757
|
+
|
|
758
|
+
1. \`martin_doctor\`
|
|
759
|
+
2. \`martin_plan\`
|
|
760
|
+
3. \`martin_preflight\`
|
|
761
|
+
4. \`martin_run\`
|
|
762
|
+
5. \`martin_dossier\`
|
|
763
|
+
|
|
764
|
+
## Enforcement Rule
|
|
765
|
+
|
|
766
|
+
Do not execute real coding work through MartinLoop until doctor and preflight have both been used for the current task.
|
|
767
|
+
|
|
768
|
+
## Completion Rule
|
|
769
|
+
|
|
770
|
+
Do not claim success until MartinLoop shows verifier-backed completion or an explicit blocked reason backed by evidence.
|
|
771
|
+
`;
|
|
772
|
+
}
|
|
773
|
+
function buildPublishReadinessGuide(runsRoot) {
|
|
774
|
+
const metadata = buildMartinDiscoveryMetadata(MARTIN_MCP_PACKAGE_VERSION);
|
|
775
|
+
return `# Martin MCP Publish Readiness
|
|
776
|
+
|
|
777
|
+
Discovery revision: \`${metadata.discoveryRevision}\`
|
|
778
|
+
Server version: \`${metadata.serverVersion}\`
|
|
779
|
+
Runs root: \`${runsRoot}\`
|
|
780
|
+
|
|
781
|
+
Use this guide when reviewing whether the public MCP package is ready to publish, promote, or hand off for registry submission.
|
|
782
|
+
|
|
783
|
+
## Review Areas
|
|
784
|
+
|
|
785
|
+
1. Environment health: confirm \`${MARTIN_STATIC_RESOURCE_URIS.serverHealth}\` shows a sane working directory, runs root, and engine availability for the target mode.
|
|
786
|
+
2. Discovery surface: verify tools, prompts, static resources, and resource templates are all discoverable and named consistently.
|
|
787
|
+
3. Run evidence: inspect \`${MARTIN_STATIC_RESOURCE_URIS.recentRuns}\` and, when relevant, \`martin://runs/{loopId}/verification\` to confirm verification outcomes are explainable from persisted data.
|
|
788
|
+
4. Packaging lane: run the MCP package test, build, and smoke-pack commands before calling the package publish-ready.
|
|
789
|
+
5. Findings-first reporting: call out missing schema, integration gaps, triage-critical runs, and verification blockers before summarizing strengths.
|
|
790
|
+
|
|
791
|
+
## Evidence Expectations
|
|
792
|
+
|
|
793
|
+
- Prefer concrete run IDs, attempt indices, and verification summaries over vague statements.
|
|
794
|
+
- Distinguish local package validation from live registry readiness.
|
|
795
|
+
- 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.
|
|
796
|
+
`;
|
|
797
|
+
}
|
|
798
|
+
function withDiscoveryMetadata(value, runsRoot) {
|
|
799
|
+
return {
|
|
800
|
+
metadata: {
|
|
801
|
+
...buildMartinDiscoveryMetadata(MARTIN_MCP_PACKAGE_VERSION),
|
|
802
|
+
...(runsRoot ? { runsRoot } : {})
|
|
803
|
+
},
|
|
804
|
+
value
|
|
805
|
+
};
|
|
806
|
+
}
|