@martinloop/mcp 0.3.2 → 0.3.4

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 (64) hide show
  1. package/README.md +112 -107
  2. package/dist/discovery-support.js +2 -2
  3. package/dist/prompts.d.ts +2 -1
  4. package/dist/resources.d.ts +2 -1
  5. package/dist/resources.js +147 -147
  6. package/dist/server-validation.js +5 -2
  7. package/dist/server.js +5 -4
  8. package/dist/tools/eval.js +29 -5
  9. package/dist/tools/execution-policy.d.ts +11 -0
  10. package/dist/tools/execution-policy.js +47 -0
  11. package/dist/tools/run-dossier.js +2 -2
  12. package/dist/tools/run-loop.d.ts +2 -1
  13. package/dist/tools/run-loop.js +15 -2
  14. package/dist/tools/run-store.js +166 -6
  15. package/dist/tools/tool-support.d.ts +3 -2
  16. package/dist/tools/tool-support.js +112 -18
  17. package/dist/tools/triage-runs.js +31 -6
  18. package/dist/vendor/adapters/claude-cli.d.ts +1 -1
  19. package/dist/vendor/adapters/claude-cli.js +71 -20
  20. package/dist/vendor/adapters/cli-bridge.d.ts +6 -0
  21. package/dist/vendor/adapters/cli-bridge.js +91 -7
  22. package/dist/vendor/adapters/codex-launcher.js +65 -8
  23. package/dist/vendor/adapters/openai-compatible.d.ts +1 -1
  24. package/dist/vendor/adapters/openai-compatible.js +7 -7
  25. package/dist/vendor/adapters/verifier-only.js +1 -1
  26. package/dist/vendor/contracts/adapter-capabilities.d.ts +17 -0
  27. package/dist/vendor/contracts/adapter-capabilities.js +35 -0
  28. package/dist/vendor/contracts/context-graph.d.ts +48 -0
  29. package/dist/vendor/contracts/context-graph.js +26 -0
  30. package/dist/vendor/contracts/execution-policy.d.ts +62 -0
  31. package/dist/vendor/contracts/execution-policy.js +34 -0
  32. package/dist/vendor/contracts/governance.d.ts +6 -3
  33. package/dist/vendor/contracts/identity.d.ts +29 -0
  34. package/dist/vendor/contracts/identity.js +30 -0
  35. package/dist/vendor/contracts/index.d.ts +13 -2
  36. package/dist/vendor/contracts/index.js +4 -0
  37. package/dist/vendor/contracts/observation.d.ts +21 -0
  38. package/dist/vendor/contracts/observation.js +27 -0
  39. package/dist/vendor/contracts/trajectory.d.ts +26 -0
  40. package/dist/vendor/contracts/trajectory.js +27 -0
  41. package/dist/vendor/contracts/verification.d.ts +28 -0
  42. package/dist/vendor/contracts/verification.js +7 -0
  43. package/dist/vendor/core/context-graph.d.ts +3 -0
  44. package/dist/vendor/core/context-graph.js +371 -0
  45. package/dist/vendor/core/context-integrity.js +1 -1
  46. package/dist/vendor/core/grounding.js +1 -1
  47. package/dist/vendor/core/identity.d.ts +20 -0
  48. package/dist/vendor/core/identity.js +86 -0
  49. package/dist/vendor/core/index.d.ts +7 -0
  50. package/dist/vendor/core/index.js +63 -9
  51. package/dist/vendor/core/leash.js +1 -1
  52. package/dist/vendor/core/persistence/integrity.d.ts +1 -0
  53. package/dist/vendor/core/persistence/integrity.js +7 -3
  54. package/dist/vendor/core/persistence/runs-reader.d.ts +14 -0
  55. package/dist/vendor/core/persistence/runs-reader.js +61 -4
  56. package/dist/vendor/core/policy-compiler.d.ts +2 -0
  57. package/dist/vendor/core/policy-compiler.js +195 -0
  58. package/dist/vendor/core/policy.d.ts +2 -0
  59. package/dist/vendor/core/policy.js +71 -4
  60. package/dist/vendor/core/rollback.js +32 -12
  61. package/dist/vendor/core/trajectory.d.ts +18 -0
  62. package/dist/vendor/core/trajectory.js +295 -0
  63. package/package.json +76 -75
  64. package/server.json +21 -21
@@ -0,0 +1,295 @@
1
+ import { cloneCircuitBreakDecision, cloneTrajectoryAssessment } from "../contracts/index.js";
2
+ const STOP_WORDS = new Set([
3
+ "about",
4
+ "after",
5
+ "again",
6
+ "along",
7
+ "also",
8
+ "been",
9
+ "before",
10
+ "being",
11
+ "between",
12
+ "could",
13
+ "failed",
14
+ "failure",
15
+ "from",
16
+ "have",
17
+ "into",
18
+ "just",
19
+ "keep",
20
+ "made",
21
+ "make",
22
+ "need",
23
+ "only",
24
+ "over",
25
+ "same",
26
+ "should",
27
+ "still",
28
+ "than",
29
+ "that",
30
+ "their",
31
+ "them",
32
+ "then",
33
+ "there",
34
+ "these",
35
+ "they",
36
+ "this",
37
+ "those",
38
+ "touching",
39
+ "without",
40
+ "would"
41
+ ]);
42
+ const STALL_FAILURE_CLASSES = new Set([
43
+ "logic_error",
44
+ "verification_failure",
45
+ "repo_grounding_failure",
46
+ "scope_creep",
47
+ "no_progress"
48
+ ]);
49
+ export function assessTrajectory(input) {
50
+ const attempts = input.attempts.filter((attempt) => attempt.index > 0);
51
+ if (attempts.length === 0) {
52
+ return cloneTrajectoryAssessment({
53
+ status: "healthy",
54
+ confidence: "low",
55
+ summary: "No prior attempts exist, so Martin has no drift evidence yet.",
56
+ signals: []
57
+ });
58
+ }
59
+ const signals = [];
60
+ const recentAttempts = attempts.slice(-4);
61
+ const lastThree = recentAttempts.slice(-3);
62
+ const lastTwo = recentAttempts.slice(-2);
63
+ const oscillation = detectFailureOscillation(lastThree);
64
+ if (oscillation) {
65
+ signals.push(oscillation);
66
+ }
67
+ const repetition = detectAttemptRepetition(lastThree);
68
+ if (repetition) {
69
+ signals.push(repetition);
70
+ }
71
+ const verificationStall = detectVerificationStall(lastTwo);
72
+ if (verificationStall) {
73
+ signals.push(verificationStall);
74
+ }
75
+ const objectiveDrift = detectObjectiveDrift({
76
+ objective: input.objective,
77
+ verificationPlan: input.verificationPlan,
78
+ attempts: lastTwo
79
+ });
80
+ if (objectiveDrift) {
81
+ signals.push(objectiveDrift);
82
+ }
83
+ const status = deriveTrajectoryStatus(signals);
84
+ const confidence = deriveTrajectoryConfidence(signals);
85
+ const recommendedIntervention = deriveRecommendedIntervention(signals);
86
+ if (signals.length === 0) {
87
+ return cloneTrajectoryAssessment({
88
+ status: "healthy",
89
+ confidence: "medium",
90
+ summary: "Recent attempts stay aligned enough that Martin does not need a circuit break yet.",
91
+ signals: []
92
+ });
93
+ }
94
+ const summary = summarizeTrajectory(status, signals);
95
+ return cloneTrajectoryAssessment({
96
+ status,
97
+ confidence,
98
+ summary,
99
+ signals,
100
+ ...(recommendedIntervention ? { recommendedIntervention } : {})
101
+ });
102
+ }
103
+ export function decideCircuitBreak(input) {
104
+ const assessment = assessTrajectory(input);
105
+ const remainingIterations = input.remainingIterations ?? Number.POSITIVE_INFINITY;
106
+ const stopForHighSignal = assessment.signals.some((signal) => signal.severity === "high");
107
+ const stopForLateDrift = assessment.status === "drifting" &&
108
+ remainingIterations <= 1 &&
109
+ assessment.signals.some((signal) => signal.code === "objective_drift");
110
+ const stopForLateStall = assessment.status === "watch" &&
111
+ remainingIterations <= 1 &&
112
+ assessment.signals.some((signal) => signal.code === "verification_stall");
113
+ const shouldStop = stopForHighSignal || stopForLateDrift || stopForLateStall;
114
+ return cloneCircuitBreakDecision({
115
+ shouldStop,
116
+ reason: shouldStop
117
+ ? assessment.summary
118
+ : "Trajectory signals do not justify a hard circuit break yet.",
119
+ assessment,
120
+ ...(assessment.recommendedIntervention
121
+ ? { recommendedIntervention: assessment.recommendedIntervention }
122
+ : {})
123
+ });
124
+ }
125
+ function detectFailureOscillation(attempts) {
126
+ if (attempts.length < 3) {
127
+ return undefined;
128
+ }
129
+ const [first, second, third] = attempts;
130
+ if (!first?.failureClass ||
131
+ !second?.failureClass ||
132
+ !third?.failureClass ||
133
+ first.failureClass === second.failureClass ||
134
+ first.failureClass !== third.failureClass) {
135
+ return undefined;
136
+ }
137
+ return {
138
+ code: "failure_oscillation",
139
+ severity: "high",
140
+ summary: `Attempts ${first.index}, ${second.index}, and ${third.index} oscillate between failure classes instead of converging.`,
141
+ attemptIndexes: [first.index, second.index, third.index]
142
+ };
143
+ }
144
+ function detectAttemptRepetition(attempts) {
145
+ if (attempts.length < 3) {
146
+ return undefined;
147
+ }
148
+ const tokenSets = attempts.map((attempt) => toTokenSet(attempt.summary));
149
+ if (tokenSets.some((tokens) => tokens.size < 4)) {
150
+ return undefined;
151
+ }
152
+ const pairScores = [
153
+ jaccardSimilarity(tokenSets[0], tokenSets[1]),
154
+ jaccardSimilarity(tokenSets[1], tokenSets[2]),
155
+ jaccardSimilarity(tokenSets[0], tokenSets[2])
156
+ ];
157
+ if (pairScores.every((score) => score >= 0.55)) {
158
+ const matchedTerms = intersectSets(tokenSets[0], new Set(intersectSets(tokenSets[1], tokenSets[2])));
159
+ return {
160
+ code: "attempt_repetition",
161
+ severity: "high",
162
+ summary: `Attempts ${attempts.map((attempt) => attempt.index).join(", ")} are materially repetitive and are not exploring a new path.`,
163
+ attemptIndexes: attempts.map((attempt) => attempt.index),
164
+ ...(matchedTerms.length > 0 ? { matchedTerms: matchedTerms.slice(0, 6) } : {})
165
+ };
166
+ }
167
+ return undefined;
168
+ }
169
+ function detectVerificationStall(attempts) {
170
+ if (attempts.length < 2) {
171
+ return undefined;
172
+ }
173
+ const relevant = attempts.filter((attempt) => {
174
+ const failureClass = attempt.failureClass;
175
+ return failureClass !== undefined && STALL_FAILURE_CLASSES.has(failureClass);
176
+ });
177
+ if (relevant.length < 2) {
178
+ return undefined;
179
+ }
180
+ const tokenSets = relevant.map((attempt) => toTokenSet(attempt.summary));
181
+ const overlap = tokenSets
182
+ .slice(1)
183
+ .map((tokens, index) => jaccardSimilarity(tokenSets[index], tokens))
184
+ .reduce((highest, score) => Math.max(highest, score), 0);
185
+ if (overlap < 0.35) {
186
+ return undefined;
187
+ }
188
+ const latest = relevant.at(-1);
189
+ return {
190
+ code: "verification_stall",
191
+ severity: "medium",
192
+ summary: `Recent attempts keep landing on the same verifier-facing failure surface (${latest.failureClass}).`,
193
+ attemptIndexes: relevant.map((attempt) => attempt.index)
194
+ };
195
+ }
196
+ function detectObjectiveDrift(input) {
197
+ if (input.attempts.length < 2) {
198
+ return undefined;
199
+ }
200
+ const objectiveTerms = toTokenSet(`${input.objective} ${(input.verificationPlan ?? []).join(" ")}`);
201
+ if (objectiveTerms.size < 4) {
202
+ return undefined;
203
+ }
204
+ const summaryTerms = input.attempts.map((attempt) => toTokenSet(attempt.summary));
205
+ const overlaps = summaryTerms.map((terms) => jaccardSimilarity(terms, objectiveTerms));
206
+ if (overlaps.some((score) => score >= 0.18)) {
207
+ return undefined;
208
+ }
209
+ const sharedDriftTerms = intersectSets(summaryTerms[0], summaryTerms[1]);
210
+ if (sharedDriftTerms.length < 3) {
211
+ return undefined;
212
+ }
213
+ return {
214
+ code: "objective_drift",
215
+ severity: "medium",
216
+ summary: "Recent attempt summaries are converging on work that does not overlap with the original objective or verifier plan.",
217
+ attemptIndexes: input.attempts.map((attempt) => attempt.index),
218
+ matchedTerms: sharedDriftTerms.slice(0, 6)
219
+ };
220
+ }
221
+ function deriveTrajectoryStatus(signals) {
222
+ if (signals.some((signal) => signal.severity === "high")) {
223
+ return "stalled";
224
+ }
225
+ if (signals.some((signal) => signal.code === "objective_drift")) {
226
+ return "drifting";
227
+ }
228
+ if (signals.some((signal) => signal.severity === "medium")) {
229
+ return "watch";
230
+ }
231
+ return "healthy";
232
+ }
233
+ function deriveTrajectoryConfidence(signals) {
234
+ if (signals.some((signal) => signal.severity === "high")) {
235
+ return "high";
236
+ }
237
+ if (signals.some((signal) => signal.severity === "medium")) {
238
+ return "medium";
239
+ }
240
+ return "low";
241
+ }
242
+ function deriveRecommendedIntervention(signals) {
243
+ if (signals.some((signal) => signal.code === "failure_oscillation" || signal.code === "attempt_repetition")) {
244
+ return "escalate_human";
245
+ }
246
+ if (signals.some((signal) => signal.code === "objective_drift")) {
247
+ return "tighten_task";
248
+ }
249
+ if (signals.some((signal) => signal.code === "verification_stall")) {
250
+ return "run_verifier";
251
+ }
252
+ return undefined;
253
+ }
254
+ function summarizeTrajectory(status, signals) {
255
+ const lead = signals[0];
256
+ if (!lead) {
257
+ return "Trajectory is healthy.";
258
+ }
259
+ switch (status) {
260
+ case "stalled":
261
+ return `Trajectory stalled: ${lead.summary}`;
262
+ case "drifting":
263
+ return `Trajectory drift detected: ${lead.summary}`;
264
+ case "watch":
265
+ return `Trajectory warning: ${lead.summary}`;
266
+ default:
267
+ return lead.summary;
268
+ }
269
+ }
270
+ function toTokenSet(text) {
271
+ return new Set((text ?? "")
272
+ .toLowerCase()
273
+ .match(/[a-z][a-z0-9_/-]{2,}/g)
274
+ ?.flatMap((token) => splitCompositeToken(token))
275
+ .map((token) => token.trim())
276
+ .filter((token) => token.length >= 3 && !STOP_WORDS.has(token)) ?? []);
277
+ }
278
+ function splitCompositeToken(token) {
279
+ return token
280
+ .split(/[-_/]/g)
281
+ .flatMap((part) => part.split(/(?=[A-Z])/g))
282
+ .map((part) => part.toLowerCase())
283
+ .filter(Boolean);
284
+ }
285
+ function jaccardSimilarity(left, right) {
286
+ if (left.size === 0 || right.size === 0) {
287
+ return 0;
288
+ }
289
+ const intersection = intersectSets(left, right).length;
290
+ const union = new Set([...left, ...right]).size;
291
+ return union === 0 ? 0 : intersection / union;
292
+ }
293
+ function intersectSets(left, right) {
294
+ return [...left].filter((term) => right.has(term));
295
+ }
package/package.json CHANGED
@@ -1,75 +1,76 @@
1
- {
2
- "name": "@martinloop/mcp",
3
- "version": "0.3.2",
4
- "mcpName": "io.github.Keesan12/martin-loop",
5
- "private": false,
6
- "type": "module",
7
- "description": "Governed MCP server for AI coding agents with budgets, verifier gates, and inspectable runs.",
8
- "license": "Apache-2.0",
9
- "author": "MartinLoop contributors",
10
- "homepage": "https://martinloop.com/",
11
- "repository": {
12
- "type": "git",
13
- "url": "git+https://github.com/Keesan12/martin-loop.git",
14
- "directory": "packages/mcp"
15
- },
16
- "bugs": {
17
- "url": "https://github.com/Keesan12/martin-loop/issues"
18
- },
19
- "keywords": [
20
- "mcp",
21
- "model-context-protocol",
22
- "martin-loop",
23
- "ai-agent",
24
- "claude",
25
- "codex",
26
- "martin_doctor",
27
- "martin_triage_runs",
28
- "martin_run_dossier",
29
- "mcp-resources",
30
- "mcp-prompts"
31
- ],
32
- "bin": {
33
- "mcp": "./dist/server.js",
34
- "martin-loop-mcp": "./dist/server.js"
35
- },
36
- "exports": {
37
- "./server.json": "./server.json",
38
- "./package.json": "./package.json"
39
- },
40
- "files": [
41
- "dist",
42
- "README.md",
43
- "server.json"
44
- ],
45
- "engines": {
46
- "node": ">=20.0.0"
47
- },
48
- "publishConfig": {
49
- "access": "public"
50
- },
51
- "scripts": {
52
- "build": "node ./scripts/build-package.mjs",
53
- "prepack": "pnpm build",
54
- "smoke:pack": "node ./scripts/smoke-package.mjs",
55
- "smoke:published": "node ./scripts/smoke-published-package.mjs",
56
- "smoke:published:pack": "node ./scripts/smoke-published-package.mjs --package-spec=pack",
57
- "verify:release": "node --test ../../scripts/tests/publish-mcp-workflow.test.mjs ../../scripts/tests/mcp-publish-reliability.test.mjs ../../scripts/tests/mcp-release-docs.test.mjs",
58
- "test": "vitest run --maxWorkers=1",
59
- "lint": "tsc -p tsconfig.json --noEmit",
60
- "start": "node dist/server.js",
61
- "inspect:live": "node ./scripts/inspect-live.mjs"
62
- },
63
- "dependencies": {
64
- "@modelcontextprotocol/sdk": "^1.29.0",
65
- "@open-policy-agent/opa-wasm": "^1.10.0",
66
- "@opentelemetry/api-logs": "^0.214.0",
67
- "@opentelemetry/exporter-logs-otlp-http": "^0.214.0",
68
- "@opentelemetry/resources": "^2.6.1",
69
- "@opentelemetry/sdk-logs": "^0.214.0",
70
- "ts-morph": "^21.0.0"
71
- },
72
- "devDependencies": {
73
- "@martin/contracts": "workspace:*"
74
- }
75
- }
1
+ {
2
+ "name": "@martinloop/mcp",
3
+ "version": "0.3.4",
4
+ "mcpName": "io.github.Keesan12/martin-loop",
5
+ "private": false,
6
+ "type": "module",
7
+ "description": "Governed MCP server for AI coding agents with budgets, verifier gates, and inspectable runs.",
8
+ "license": "Apache-2.0",
9
+ "author": "MartinLoop contributors",
10
+ "homepage": "https://martinloop.com/",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/Keesan12/martin-loop.git",
14
+ "directory": "packages/mcp"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/Keesan12/martin-loop/issues"
18
+ },
19
+ "keywords": [
20
+ "mcp",
21
+ "model-context-protocol",
22
+ "martin-loop",
23
+ "ai-agent",
24
+ "claude",
25
+ "codex",
26
+ "martin_doctor",
27
+ "martin_triage_runs",
28
+ "martin_run_dossier",
29
+ "mcp-resources",
30
+ "mcp-prompts"
31
+ ],
32
+ "bin": {
33
+ "mcp": "./dist/server.js",
34
+ "martin-loop-mcp": "./dist/server.js"
35
+ },
36
+ "exports": {
37
+ "./server.json": "./server.json",
38
+ "./package.json": "./package.json"
39
+ },
40
+ "files": [
41
+ "dist",
42
+ "README.md",
43
+ "server.json"
44
+ ],
45
+ "engines": {
46
+ "node": ">=20.0.0"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "scripts": {
52
+ "build": "node ./scripts/build-package.mjs",
53
+ "prepack": "pnpm build",
54
+ "smoke:pack": "node ./scripts/smoke-package.mjs",
55
+ "smoke:published": "node ./scripts/smoke-published-package.mjs",
56
+ "smoke:published:pack": "node ./scripts/smoke-published-package.mjs --package-spec=pack",
57
+ "verify:release": "node --test ../../scripts/tests/publish-mcp-workflow.test.mjs ../../scripts/tests/mcp-publish-reliability.test.mjs ../../scripts/tests/mcp-release-docs.test.mjs",
58
+ "test:baseline": "node ./scripts/run-test-lane.mjs baseline",
59
+ "test": "vitest run --maxWorkers=1",
60
+ "lint": "tsc -p tsconfig.json --noEmit",
61
+ "start": "node dist/server.js",
62
+ "inspect:live": "node ./scripts/inspect-live.mjs"
63
+ },
64
+ "dependencies": {
65
+ "@modelcontextprotocol/sdk": "^1.29.0",
66
+ "@open-policy-agent/opa-wasm": "^1.10.0",
67
+ "@opentelemetry/api-logs": "^0.214.0",
68
+ "@opentelemetry/exporter-logs-otlp-http": "^0.214.0",
69
+ "@opentelemetry/resources": "^2.6.1",
70
+ "@opentelemetry/sdk-logs": "^0.214.0",
71
+ "ts-morph": "^21.0.0"
72
+ },
73
+ "devDependencies": {
74
+ "@martin/contracts": "workspace:*"
75
+ }
76
+ }
package/server.json CHANGED
@@ -1,21 +1,21 @@
1
- {
2
- "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
- "name": "io.github.Keesan12/martin-loop",
4
- "title": "Martin Loop",
5
- "description": "Governed MCP server for AI coding agents with budgets, verifier gates, and inspectable runs.",
6
- "repository": {
7
- "url": "https://github.com/Keesan12/martin-loop",
8
- "source": "github"
9
- },
10
- "version": "0.3.2",
11
- "packages": [
12
- {
13
- "registryType": "npm",
14
- "identifier": "@martinloop/mcp",
15
- "version": "0.3.2",
16
- "transport": {
17
- "type": "stdio"
18
- }
19
- }
20
- ]
21
- }
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
+ "name": "io.github.Keesan12/martin-loop",
4
+ "title": "Martin Loop",
5
+ "description": "Governed MCP server for AI coding agents with budgets, verifier gates, and inspectable runs.",
6
+ "repository": {
7
+ "url": "https://github.com/Keesan12/martin-loop",
8
+ "source": "github"
9
+ },
10
+ "version": "0.3.4",
11
+ "packages": [
12
+ {
13
+ "registryType": "npm",
14
+ "identifier": "@martinloop/mcp",
15
+ "version": "0.3.4",
16
+ "transport": {
17
+ "type": "stdio"
18
+ }
19
+ }
20
+ ]
21
+ }