@martinloop/mcp 0.3.4 → 0.3.6

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 (48) hide show
  1. package/README.md +10 -2
  2. package/dist/discovery-metadata.d.ts +6 -6
  3. package/dist/discovery-metadata.js +8 -0
  4. package/dist/package-version.d.ts +1 -1
  5. package/dist/package-version.js +1 -1
  6. package/dist/prompts.js +19 -1
  7. package/dist/resources.d.ts +3 -0
  8. package/dist/resources.js +264 -148
  9. package/dist/server-validation.d.ts +1 -1
  10. package/dist/server-validation.js +17 -0
  11. package/dist/server.d.ts +23 -0
  12. package/dist/server.js +244 -2
  13. package/dist/tools/doctor.js +6 -0
  14. package/dist/tools/run-store.js +4 -4
  15. package/dist/tools/tool-support.d.ts +3 -1
  16. package/dist/tools/tool-support.js +17 -2
  17. package/dist/vendor/adapters/claude-cli.d.ts +2 -2
  18. package/dist/vendor/adapters/claude-cli.js +53 -9
  19. package/dist/vendor/adapters/cli-bridge.d.ts +17 -0
  20. package/dist/vendor/adapters/cli-bridge.js +124 -8
  21. package/dist/vendor/adapters/codex-launcher.d.ts +2 -0
  22. package/dist/vendor/adapters/codex-launcher.js +77 -9
  23. package/dist/vendor/adapters/openai-compatible.js +90 -57
  24. package/dist/vendor/contracts/execution-policy.d.ts +16 -0
  25. package/dist/vendor/contracts/execution-policy.js +9 -0
  26. package/dist/vendor/contracts/index.d.ts +29 -2
  27. package/dist/vendor/contracts/index.js +2 -0
  28. package/dist/vendor/core/index.d.ts +13 -3
  29. package/dist/vendor/core/index.js +123 -30
  30. package/dist/vendor/core/persistence/memory-store.d.ts +63 -0
  31. package/dist/vendor/core/persistence/memory-store.js +115 -0
  32. package/dist/vendor/core/persistence/store.js +13 -0
  33. package/dist/vendor/core/persistence/trace-store.d.ts +85 -0
  34. package/dist/vendor/core/persistence/trace-store.js +125 -0
  35. package/dist/vendor/core/policy.d.ts +13 -0
  36. package/dist/vendor/core/policy.js +13 -0
  37. package/dist/vendor/core/repo-analyzer.d.ts +53 -0
  38. package/dist/vendor/core/repo-analyzer.js +263 -0
  39. package/dist/vendor/core/rollback.d.ts +4 -0
  40. package/dist/vendor/core/rollback.js +15 -0
  41. package/dist/vendor/core/routing.d.ts +82 -0
  42. package/dist/vendor/core/routing.js +336 -0
  43. package/dist/vendor/core/test-integrity.d.ts +64 -0
  44. package/dist/vendor/core/test-integrity.js +197 -0
  45. package/dist/workflow-state.d.ts +17 -1
  46. package/dist/workflow-state.js +13 -5
  47. package/package.json +76 -76
  48. package/server.json +21 -21
package/README.md CHANGED
@@ -60,6 +60,14 @@ gemini mcp add martin-loop -- npx -y @martinloop/mcp
60
60
  npx -y @martinloop/mcp
61
61
  ```
62
62
 
63
+ ### Optional HTTP Endpoint
64
+
65
+ If you need a local HTTP endpoint for a bridge or proxy, start the server in HTTP mode:
66
+
67
+ ```sh
68
+ npx -y @martinloop/mcp --http --port 3033
69
+ ```
70
+
63
71
  ## How a Governed Run Works
64
72
 
65
73
  ```
@@ -87,11 +95,11 @@ Every attempt runs your verifier. Every dollar is tracked. If the agent drifts o
87
95
  **Ship the work:**
88
96
  `martin_pr_summary` `martin_create_pr` `martin_review_pr`
89
97
 
90
- ### 11 Read-Only Resources
98
+ ### Key Read-Only Resources
91
99
 
92
100
  Your agent can pull context without side effects:
93
101
 
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`
102
+ `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://agent/governance-status` · `martin://agent/mode-status` · `martin://agent/memory-summary` · `martin://guides/mcp-usage` · `martin://guides/agent-start` · `martin://repo/risk-map`
95
103
 
96
104
  ### Configuration Profiles
97
105
 
@@ -1,10 +1,10 @@
1
- export declare const MARTIN_TOOL_NAMES: readonly ["martin_run", "martin_inspect", "martin_status", "martin_doctor", "martin_plan", "martin_preflight", "martin_logs", "martin_pause", "martin_cancel", "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
- export declare const MARTIN_STARTER_TOOL_NAMES: readonly ["martin_doctor", "martin_plan", "martin_preflight", "martin_run", "martin_triage_runs", "martin_dossier"];
3
- export declare const MARTIN_MINIMAL_TOOL_NAMES: readonly ["martin_doctor", "martin_plan", "martin_preflight", "martin_list_runs", "martin_triage_runs", "martin_dossier"];
4
- export declare const MARTIN_DIAGNOSTIC_TOOL_NAMES: readonly ["martin_doctor", "martin_plan", "martin_preflight", "martin_logs", "martin_list_runs", "martin_triage_runs", "martin_get_run", "martin_get_attempt", "martin_get_verification_results", "martin_dossier", "martin_eval"];
1
+ export declare const MARTIN_TOOL_NAMES: readonly ["martin_run", "martin_inspect", "martin_status", "martin_doctor", "martin_plan", "martin_preflight", "martin_estimate", "martin_logs", "martin_pause", "martin_cancel", "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
+ export declare const MARTIN_STARTER_TOOL_NAMES: readonly ["martin_doctor", "martin_plan", "martin_preflight", "martin_estimate", "martin_run", "martin_triage_runs", "martin_dossier"];
3
+ export declare const MARTIN_MINIMAL_TOOL_NAMES: readonly ["martin_doctor", "martin_plan", "martin_preflight", "martin_estimate", "martin_list_runs", "martin_triage_runs", "martin_dossier"];
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
- export declare const MARTIN_PAID_REMOTE_TOOL_NAMES: readonly ["martin_doctor", "martin_plan", "martin_preflight", "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/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://guides/mcp-usage", "martin://guides/agent-start", "martin://guides/command-map", "martin://guides/ide-onboarding", "martin://guides/operating-rules", "martin://guides/publish-readiness"];
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/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 {
@@ -6,6 +6,7 @@ export const MARTIN_TOOL_NAMES = [
6
6
  "martin_doctor",
7
7
  "martin_plan",
8
8
  "martin_preflight",
9
+ "martin_estimate",
9
10
  "martin_logs",
10
11
  "martin_pause",
11
12
  "martin_cancel",
@@ -26,6 +27,7 @@ export const MARTIN_STARTER_TOOL_NAMES = [
26
27
  "martin_doctor",
27
28
  "martin_plan",
28
29
  "martin_preflight",
30
+ "martin_estimate",
29
31
  "martin_run",
30
32
  "martin_triage_runs",
31
33
  "martin_dossier"
@@ -34,6 +36,7 @@ export const MARTIN_MINIMAL_TOOL_NAMES = [
34
36
  "martin_doctor",
35
37
  "martin_plan",
36
38
  "martin_preflight",
39
+ "martin_estimate",
37
40
  "martin_list_runs",
38
41
  "martin_triage_runs",
39
42
  "martin_dossier"
@@ -42,6 +45,7 @@ export const MARTIN_DIAGNOSTIC_TOOL_NAMES = [
42
45
  "martin_doctor",
43
46
  "martin_plan",
44
47
  "martin_preflight",
48
+ "martin_estimate",
45
49
  "martin_logs",
46
50
  "martin_list_runs",
47
51
  "martin_triage_runs",
@@ -65,6 +69,7 @@ export const MARTIN_PAID_REMOTE_TOOL_NAMES = [
65
69
  "martin_doctor",
66
70
  "martin_plan",
67
71
  "martin_preflight",
72
+ "martin_estimate",
68
73
  "martin_run",
69
74
  "martin_list_runs",
70
75
  "martin_triage_runs",
@@ -87,6 +92,9 @@ export const MARTIN_RESOURCE_URIS = [
87
92
  "martin://repo/risk-map",
88
93
  "martin://verifiers/results",
89
94
  "martin://agent/next-step",
95
+ "martin://agent/governance-status",
96
+ "martin://agent/mode-status",
97
+ "martin://agent/memory-summary",
90
98
  "martin://guides/mcp-usage",
91
99
  "martin://guides/agent-start",
92
100
  "martin://guides/command-map",
@@ -1 +1 @@
1
- export declare const MARTIN_MCP_PACKAGE_VERSION = "0.3.2";
1
+ export declare const MARTIN_MCP_PACKAGE_VERSION = "0.3.6";
@@ -1,3 +1,3 @@
1
1
  // Keep this aligned with packages/mcp/package.json during version bumps so the
2
2
  // runtime does not depend on package.json being present in every hosted bundle.
3
- export const MARTIN_MCP_PACKAGE_VERSION = "0.3.2";
3
+ export const MARTIN_MCP_PACKAGE_VERSION = "0.3.6";
package/dist/prompts.js CHANGED
@@ -247,7 +247,25 @@ async function buildKickoffPrompt(input) {
247
247
  return {
248
248
  description: appendPromptMetadata("Kick off a Martin-governed coding session with explicit scope, budgets, and verification expectations."),
249
249
  messages: [
250
- textMessage("assistant", "You are helping prepare a Martin Loop coding run. Keep the plan governed: validate the environment first, plan before spend, preflight non-trivial work, preserve scope discipline, and make verification requirements explicit. Do not skip Martin commands and do not treat Martin as optional."),
250
+ textMessage("assistant", [
251
+ "You are operating under MartinLoop governance. All coding work MUST follow the governed sequence. This is not optional.",
252
+ "",
253
+ "REQUIRED before any code changes:",
254
+ "1. Read martin://agent/governance-status — check if this session is governed",
255
+ "2. Call martin_doctor — confirm environment readiness",
256
+ "3. Call martin_estimate — preview cost and recommended route BEFORE spending",
257
+ "4. Call martin_plan — scope the bounded approach",
258
+ "5. Call martin_preflight — validate the run contract",
259
+ "6. Only then call martin_run",
260
+ "7. Call martin_dossier — inspect what happened and generate receipt",
261
+ "",
262
+ "RULES:",
263
+ "- Never skip governance steps. Never claim success without verifier-backed evidence.",
264
+ "- Never generate fake tests. All tests must exercise real code paths with real assertions.",
265
+ "- Match the existing repo's code style (naming, formatting, test framework, module system).",
266
+ "- Budget caps are hard limits. If the estimate exceeds budget, ask the user before proceeding.",
267
+ "- Every run produces a receipt. No silent failures."
268
+ ].join("\n")),
251
269
  embeddedResourceMessage("assistant", firstResourceContent(usageGuide)),
252
270
  embeddedResourceMessage("assistant", firstResourceContent(commandMapGuide)),
253
271
  embeddedResourceMessage("assistant", firstResourceContent(operatingRulesGuide)),
@@ -20,6 +20,9 @@ export declare const MARTIN_STATIC_RESOURCE_URIS: {
20
20
  readonly ideOnboardingGuide: "martin://guides/ide-onboarding";
21
21
  readonly operatingRulesGuide: "martin://guides/operating-rules";
22
22
  readonly publishReadinessGuide: "martin://guides/publish-readiness";
23
+ readonly governanceStatus: "martin://agent/governance-status";
24
+ readonly modeStatus: "martin://agent/mode-status";
25
+ readonly memorySummary: "martin://agent/memory-summary";
23
26
  };
24
27
  export declare const MARTIN_RESOURCE_TEMPLATES: ResourceTemplate[];
25
28
  export declare const MARTIN_STATIC_RESOURCES: Resource[];
package/dist/resources.js CHANGED
@@ -1,3 +1,6 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
1
4
  import { buildMartinDiscoveryMetadata } from "./discovery-metadata.js";
2
5
  import { MARTIN_MCP_PACKAGE_VERSION } from "./package-version.js";
3
6
  import { inspectLoopTool } from "./tools/inspect-loop.js";
@@ -5,6 +8,8 @@ import { martinDoctorTool } from "./tools/doctor.js";
5
8
  import { martinTriageRunsTool } from "./tools/triage-runs.js";
6
9
  import { martinRunDossierTool } from "./tools/run-dossier.js";
7
10
  import { inspectRepoSignals, buildPolicyPackDefinition, buildRepoRiskMap } from "./tools/workflow-governance.js";
11
+ import { readWorkflowState } from "./workflow-state.js";
12
+ import { readMemoryEntries, buildMemorySummary } from "./vendor/core/index.js";
8
13
  import { buildAttemptSnapshot, buildPersistedLoopPreview, buildVerificationHistorySnapshot, parseAttemptIndex, resolveMartinDiscoveryContext, toPrettyJson } from "./discovery-support.js";
9
14
  import { loadDetailedLoopRecord, readLedgerEvents } from "./tools/run-store.js";
10
15
  import { invalidArgumentsError, MartinToolError } from "./tools/tool-errors.js";
@@ -27,7 +32,10 @@ export const MARTIN_STATIC_RESOURCE_URIS = {
27
32
  commandMapGuide: "martin://guides/command-map",
28
33
  ideOnboardingGuide: "martin://guides/ide-onboarding",
29
34
  operatingRulesGuide: "martin://guides/operating-rules",
30
- publishReadinessGuide: "martin://guides/publish-readiness"
35
+ publishReadinessGuide: "martin://guides/publish-readiness",
36
+ governanceStatus: "martin://agent/governance-status",
37
+ modeStatus: "martin://agent/mode-status",
38
+ memorySummary: "martin://agent/memory-summary"
31
39
  };
32
40
  export const MARTIN_RESOURCE_TEMPLATES = [
33
41
  {
@@ -188,6 +196,27 @@ export const MARTIN_STATIC_RESOURCES = [
188
196
  title: "Martin Publish Readiness Guide",
189
197
  description: "Checklist-oriented guide for MCP publish readiness reviews.",
190
198
  mimeType: "text/markdown"
199
+ },
200
+ {
201
+ uri: MARTIN_STATIC_RESOURCE_URIS.governanceStatus,
202
+ name: "martin_governance_status",
203
+ title: "Martin Governance Status",
204
+ description: "Proactive governance status: whether work is governed, budget remaining, unreceipted runs, and recommended next action. Read this before starting agent work.",
205
+ mimeType: "application/json"
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
+ },
214
+ {
215
+ uri: MARTIN_STATIC_RESOURCE_URIS.memorySummary,
216
+ name: "martin_memory_summary",
217
+ title: "Martin Memory Summary",
218
+ description: "MartinLoop persistent memory: user preferences, consent signals, budget patterns, and behavioral observations aggregated over time. Read at session start to personalize recommendations.",
219
+ mimeType: "application/json"
191
220
  }
192
221
  ];
193
222
  export function listMartinResources() {
@@ -237,6 +266,15 @@ export async function readMartinResource(input) {
237
266
  return jsonResource(input.uri, withDiscoveryMetadata(buildRepoRiskMap(inspectRepoSignals(context.workingDirectory)), context.runsRoot));
238
267
  case MARTIN_STATIC_RESOURCE_URIS.verifierResults:
239
268
  return jsonResource(input.uri, withDiscoveryMetadata(await buildLatestVerifierEvidenceResource(context.runsRoot), context.runsRoot));
269
+ case MARTIN_STATIC_RESOURCE_URIS.memorySummary: {
270
+ const entries = await readMemoryEntries(context.runsRoot);
271
+ const summary = buildMemorySummary(entries);
272
+ return jsonResource(input.uri, withDiscoveryMetadata(summary, context.runsRoot));
273
+ }
274
+ case MARTIN_STATIC_RESOURCE_URIS.governanceStatus:
275
+ return jsonResource(input.uri, withDiscoveryMetadata(await buildGovernanceStatusResource(context.runsRoot, context.workingDirectory), context.runsRoot));
276
+ case MARTIN_STATIC_RESOURCE_URIS.modeStatus:
277
+ return jsonResource(input.uri, withDiscoveryMetadata(await buildModeStatusResource(context.workingDirectory), context.runsRoot));
240
278
  case MARTIN_STATIC_RESOURCE_URIS.agentNextStep:
241
279
  return jsonResource(input.uri, withDiscoveryMetadata(await buildAgentNextStepResource(context.runsRoot), context.runsRoot));
242
280
  case MARTIN_STATIC_RESOURCE_URIS.mcpUsageGuide:
@@ -565,6 +603,84 @@ function compactEmptyState(kind, runsRoot, warnings) {
565
603
  warnings
566
604
  };
567
605
  }
606
+ async function buildGovernanceStatusResource(runsRoot, workingDirectory) {
607
+ const state = await readWorkflowState(runsRoot);
608
+ const mcpState = state.mcp ?? {};
609
+ const hasDoctor = Boolean(mcpState.doctor);
610
+ const hasPlan = Boolean(mcpState.plan);
611
+ const hasPreflight = Boolean(mcpState.preflight);
612
+ const governed = hasDoctor && hasPlan && hasPreflight;
613
+ const latest = await loadLatestRunForCompactResource(runsRoot);
614
+ const budgetRemaining = (!latest.empty && latest.detail)
615
+ ? buildPersistedLoopPreview(latest.detail.loop).remainingBudgetUsd
616
+ : null;
617
+ let unreceiptedRuns = 0;
618
+ try {
619
+ const inspection = await inspectLoopTool({ runsDir: runsRoot });
620
+ const total = inspection.loopCount ?? 0;
621
+ const completed = (inspection.statusBreakdown?.completed ?? 0) + (inspection.statusBreakdown?.failed ?? 0);
622
+ unreceiptedRuns = Math.max(0, total - completed);
623
+ }
624
+ catch {
625
+ // No runs yet
626
+ }
627
+ const missingSteps = [];
628
+ if (!hasDoctor)
629
+ missingSteps.push("martin_doctor");
630
+ if (!hasPlan)
631
+ missingSteps.push("martin_plan");
632
+ if (!hasPreflight)
633
+ missingSteps.push("martin_preflight");
634
+ const recommendedAction = !hasDoctor
635
+ ? "Run martin_doctor to confirm environment before any work."
636
+ : !hasPlan
637
+ ? "Run martin_plan with your objective to scope the task."
638
+ : !hasPreflight
639
+ ? "Run martin_preflight to validate the run contract before execution."
640
+ : "Governance complete. You may proceed with martin_run.";
641
+ return {
642
+ kind: "governance-status",
643
+ governed,
644
+ workflowReceipts: {
645
+ doctor: hasDoctor ? { recordedAt: mcpState.doctor.recordedAt } : null,
646
+ plan: hasPlan ? { recordedAt: mcpState.plan.recordedAt } : null,
647
+ preflight: hasPreflight ? { recordedAt: mcpState.preflight.recordedAt } : null
648
+ },
649
+ missingSteps,
650
+ budgetRemaining,
651
+ unreceiptedRuns,
652
+ recommendedAction,
653
+ requiredSequence: ["martin_doctor", "martin_plan", "martin_preflight", "martin_run", "martin_dossier"],
654
+ warning: governed ? undefined : "This session is NOT governed. Complete the required sequence before making changes."
655
+ };
656
+ }
657
+ async function buildModeStatusResource(workingDirectory) {
658
+ const configPath = join(homedir(), ".martin", "config.json");
659
+ let config = {};
660
+ try {
661
+ config = JSON.parse(await readFile(configPath, "utf8"));
662
+ }
663
+ catch {
664
+ // Fresh config means the implicit auto default is in effect.
665
+ }
666
+ const projectMode = config.projectOverrides?.[workingDirectory];
667
+ const defaultMode = config.defaultMode ?? "auto";
668
+ const effectiveMode = projectMode ?? defaultMode;
669
+ return {
670
+ kind: "mode-status",
671
+ effectiveMode,
672
+ defaultMode,
673
+ scope: projectMode ? "project" : config.defaultMode ? "global" : "implicit_default",
674
+ configured: Boolean(projectMode || config.defaultMode),
675
+ projectOverride: projectMode ?? null,
676
+ workingDirectory,
677
+ switchCommands: {
678
+ auto: "martin mode auto",
679
+ plan: "martin mode plan",
680
+ edits: "martin mode edits"
681
+ }
682
+ };
683
+ }
568
684
  function buildCurrentPoliciesResource(workingDirectory) {
569
685
  const signals = inspectRepoSignals(workingDirectory);
570
686
  const recommended = buildPolicyPackDefinition(undefined, signals);
@@ -626,173 +742,173 @@ function inferAgentNextStep(loop, verification) {
626
742
  }
627
743
  function buildMcpUsageGuide(runsRoot) {
628
744
  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\`.
745
+ return `# Martin Loop MCP Usage
746
+
747
+ Discovery revision: \`${metadata.discoveryRevision}\`
748
+ Server version: \`${metadata.serverVersion}\`
749
+ Runs root: \`${runsRoot}\`
750
+
751
+ 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.
752
+
753
+ ## Recommended Flow
754
+
755
+ 1. Read \`${MARTIN_STATIC_RESOURCE_URIS.serverHealth}\` or call \`martin_doctor\` to confirm the environment and run-store visibility.
756
+ 2. Use the \`martin_governed_coding_kickoff\` prompt to frame a governed coding request.
757
+ 3. Call \`martin_preflight\` before \`martin_run\` when the task or safety envelope is non-trivial.
758
+ 4. After execution, inspect \`${MARTIN_STATIC_RESOURCE_URIS.recentRuns}\`, \`martin://runs/{loopId}\`, and \`martin://runs/{loopId}/verification\`.
759
+ 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.
760
+ 6. Read \`${MARTIN_STATIC_RESOURCE_URIS.triage}\` or call \`martin_triage_runs\` to prioritize which run needs attention first.
761
+ 7. Use \`martin_debug_failed_run\` when a loop exits failed, budget-bound, or escalated.
762
+
763
+ ## Current Martin MCP Surface
764
+
765
+ - 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\`
766
+ - 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}\`
767
+ - Resource templates: \`martin://runs/{loopId}\`, \`martin://runs/{loopId}/attempts/{attemptIndex}\`, \`martin://runs/{loopId}/verification\`
768
+ - 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\`
769
+
770
+ ## Notes
771
+
772
+ - Discovery helpers read the existing Martin run-store; they do not create new schema.
773
+ - Verification history is derived from persisted \`verification.completed\` evidence in loop records and ledgers.
774
+ - Attempt inspection stays aligned with the same loop selectors used by \`martin_status\` and \`martin_inspect\`.
659
775
  `;
660
776
  }
661
777
  function buildAgentStartGuide(runsRoot) {
662
778
  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.
779
+ return `# Agent Start Here
780
+
781
+ Discovery revision: \`${metadata.discoveryRevision}\`
782
+ Server version: \`${metadata.serverVersion}\`
783
+ Runs root: \`${runsRoot}\`
784
+
785
+ Use Martin Loop as the local governor before you spend agent tokens or retry a failed coding loop.
786
+
787
+ ## Cheap Default Flow
788
+
789
+ 1. Read \`${MARTIN_STATIC_RESOURCE_URIS.agentNextStep}\` first. It is the smallest "what should I do now?" payload.
790
+ 2. If no runs exist, call \`martin_doctor\`, then \`martin_preflight\`.
791
+ 3. If a run exists, read \`${MARTIN_STATIC_RESOURCE_URIS.latestSummary}\` before reading full run JSON.
792
+ 4. If the verifier failed, use prompt \`martin_debug_failed_run\` or \`martin_triage\`.
793
+ 5. If you need a shareable receipt, read \`${MARTIN_STATIC_RESOURCE_URIS.latestProofCard}\`.
794
+
795
+ ## Install Profiles
796
+
797
+ - \`minimal\` (default): doctor, preflight, list, triage, dossier. Good for low tool bloat.
798
+ - \`diagnostic\`: read-only inspection tools for debugging without execution.
799
+ - \`full-local\`: all local tools, including \`martin_run\`.
800
+ - \`github-review\`: review-oriented local profile for PR drafting and reviewer evidence.
801
+ - \`starter\` and \`full\`: compatibility aliases.
802
+
803
+ ## Copy-Paste Agent Rule
804
+
805
+ 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
806
  `;
691
807
  }
692
808
  function buildCommandMapGuide(runsRoot) {
693
809
  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}\`
810
+ return `# Martin Command Map
811
+
812
+ Discovery revision: \`${metadata.discoveryRevision}\`
813
+ Server version: \`${metadata.serverVersion}\`
814
+ Runs root: \`${runsRoot}\`
815
+
816
+ Use this guide when an IDE or agent needs to know which Martin surface to call next.
817
+
818
+ ## Default Governed Sequence
819
+
820
+ 1. \`martin_doctor\` — confirm environment and visibility.
821
+ 2. \`martin_plan\` — propose the bounded approach without spending a run.
822
+ 3. \`martin_preflight\` — turn the plan into an explicit contract.
823
+ 4. \`martin_run\` — execute only after the contract is safe.
824
+ 5. \`martin_dossier\` — inspect what happened and what Martin prevented.
825
+ 6. \`martin_eval\` — convert the result into review posture when needed.
826
+
827
+ ## When To Use Which Surface
828
+
829
+ - Need the smallest next action: \`${MARTIN_STATIC_RESOURCE_URIS.agentNextStep}\`
830
+ - Need a quick receipt: \`${MARTIN_STATIC_RESOURCE_URIS.latestSummary}\`
831
+ - Need a shareable proof object: \`${MARTIN_STATIC_RESOURCE_URIS.latestProofCard}\`
832
+ - Need a full run review: \`martin_dossier\`
833
+ - Need to decide whether to retry: \`martin_triage_runs\`
834
+ - Need IDE setup guidance: \`${MARTIN_STATIC_RESOURCE_URIS.ideOnboardingGuide}\`
719
835
  `;
720
836
  }
721
837
  function buildIdeOnboardingGuide(runsRoot) {
722
838
  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.
839
+ return `# Martin IDE Onboarding
840
+
841
+ Discovery revision: \`${metadata.discoveryRevision}\`
842
+ Server version: \`${metadata.serverVersion}\`
843
+ Runs root: \`${runsRoot}\`
844
+
845
+ Use this guide after the MCP server is installed so the host naturally uses MartinLoop during real work.
846
+
847
+ ## IDE Default Flow
848
+
849
+ 1. Read \`${MARTIN_STATIC_RESOURCE_URIS.agentStartGuide}\`
850
+ 2. Read \`${MARTIN_STATIC_RESOURCE_URIS.operatingRulesGuide}\`
851
+ 3. Use prompt \`martin_start\` or \`martin_governed_coding_kickoff\`
852
+ 4. Call \`martin_doctor\`
853
+ 5. Call \`martin_plan\`
854
+ 6. Call \`martin_preflight\`
855
+ 7. Only then call \`martin_run\`
856
+
857
+ ## Goal
858
+
859
+ MartinLoop should become the normal path for coding work in the host, not a manual extra step the human has to remember.
744
860
  `;
745
861
  }
746
862
  function buildOperatingRulesGuide(runsRoot) {
747
863
  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.
864
+ return `# Martin Operating Rules
865
+
866
+ Discovery revision: \`${metadata.discoveryRevision}\`
867
+ Server version: \`${metadata.serverVersion}\`
868
+ Runs root: \`${runsRoot}\`
869
+
870
+ Use these rules inside the IDE or MCP host as the default MartinLoop operating posture.
871
+
872
+ ## Required Sequence Before Real Work
873
+
874
+ 1. \`martin_doctor\`
875
+ 2. \`martin_plan\`
876
+ 3. \`martin_preflight\`
877
+ 4. \`martin_run\`
878
+ 5. \`martin_dossier\`
879
+
880
+ ## Enforcement Rule
881
+
882
+ Do not execute real coding work through MartinLoop until doctor and preflight have both been used for the current task.
883
+
884
+ ## Completion Rule
885
+
886
+ Do not claim success until MartinLoop shows verifier-backed completion or an explicit blocked reason backed by evidence.
771
887
  `;
772
888
  }
773
889
  function buildPublishReadinessGuide(runsRoot) {
774
890
  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.
891
+ return `# Martin MCP Publish Readiness
892
+
893
+ Discovery revision: \`${metadata.discoveryRevision}\`
894
+ Server version: \`${metadata.serverVersion}\`
895
+ Runs root: \`${runsRoot}\`
896
+
897
+ Use this guide when reviewing whether the public MCP package is ready to publish, promote, or hand off for registry submission.
898
+
899
+ ## Review Areas
900
+
901
+ 1. Environment health: confirm \`${MARTIN_STATIC_RESOURCE_URIS.serverHealth}\` shows a sane working directory, runs root, and engine availability for the target mode.
902
+ 2. Discovery surface: verify tools, prompts, static resources, and resource templates are all discoverable and named consistently.
903
+ 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.
904
+ 4. Packaging lane: run the MCP package test, build, and smoke-pack commands before calling the package publish-ready.
905
+ 5. Findings-first reporting: call out missing schema, integration gaps, triage-critical runs, and verification blockers before summarizing strengths.
906
+
907
+ ## Evidence Expectations
908
+
909
+ - Prefer concrete run IDs, attempt indices, and verification summaries over vague statements.
910
+ - Distinguish local package validation from live registry readiness.
911
+ - 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
912
  `;
797
913
  }
798
914
  function withDiscoveryMetadata(value, runsRoot) {
@@ -1,4 +1,4 @@
1
- type ToolName = "martin_run" | "martin_inspect" | "martin_status" | "martin_doctor" | "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;