@martinloop/mcp 0.3.5 → 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.
- package/README.md +10 -2
- package/dist/discovery-metadata.d.ts +1 -1
- package/dist/discovery-metadata.js +2 -0
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -1
- package/dist/prompts.js +19 -1
- package/dist/resources.d.ts +2 -0
- package/dist/resources.js +202 -148
- package/dist/server-validation.d.ts +1 -1
- package/dist/server-validation.js +17 -0
- package/dist/server.d.ts +23 -0
- package/dist/server.js +161 -5
- package/dist/tools/doctor.js +6 -0
- package/dist/tools/tool-support.d.ts +1 -1
- package/dist/tools/tool-support.js +1 -1
- package/dist/vendor/adapters/claude-cli.d.ts +2 -2
- package/dist/vendor/adapters/claude-cli.js +22 -7
- package/dist/vendor/adapters/cli-bridge.d.ts +7 -0
- package/dist/vendor/adapters/cli-bridge.js +94 -8
- package/dist/vendor/adapters/codex-launcher.js +18 -7
- package/dist/vendor/adapters/openai-compatible.js +90 -57
- package/dist/vendor/contracts/index.d.ts +1 -1
- package/dist/vendor/contracts/index.js +1 -0
- package/dist/vendor/core/index.d.ts +10 -2
- package/dist/vendor/core/index.js +31 -3
- package/dist/vendor/core/persistence/memory-store.d.ts +63 -0
- package/dist/vendor/core/persistence/memory-store.js +115 -0
- package/dist/vendor/core/persistence/trace-store.d.ts +85 -0
- package/dist/vendor/core/persistence/trace-store.js +125 -0
- package/dist/vendor/core/repo-analyzer.d.ts +53 -0
- package/dist/vendor/core/repo-analyzer.js +263 -0
- package/dist/vendor/core/routing.d.ts +42 -0
- package/dist/vendor/core/routing.js +156 -5
- package/dist/vendor/core/test-integrity.d.ts +64 -0
- package/dist/vendor/core/test-integrity.js +197 -0
- package/dist/workflow-state.d.ts +1 -1
- package/dist/workflow-state.js +12 -4
- package/package.json +76 -76
- package/server.json +21 -21
|
@@ -84,6 +84,144 @@ function calculateDirectConfidence(signals, input) {
|
|
|
84
84
|
// ---------------------------------------------------------------------------
|
|
85
85
|
// Public API
|
|
86
86
|
// ---------------------------------------------------------------------------
|
|
87
|
+
// ---------------------------------------------------------------------------
|
|
88
|
+
// Cost-aware model tier routing
|
|
89
|
+
//
|
|
90
|
+
// Engine-agnostic tier system — each engine maps tiers to real model IDs.
|
|
91
|
+
// Never pay for reasoning/orchestration on simple tasks.
|
|
92
|
+
//
|
|
93
|
+
// Tier → concrete model per engine:
|
|
94
|
+
// haiku → claude-haiku-4-5, gpt-4o-mini, gemini-2.5-flash, deepseek-chat, qwen3-8b, llama-3.1-8b
|
|
95
|
+
// sonnet → claude-sonnet-4-6, gpt-4o, gemini-2.5-pro, deepseek-r1, qwen3-32b, llama-3.3-70b
|
|
96
|
+
// opus → claude-opus-4-6, o3, gemini-2.5-ultra, deepseek-r1-671b, qwen3-235b, llama-3.1-405b
|
|
97
|
+
//
|
|
98
|
+
// Pricing reference (USD per 1M tokens, approx 2026):
|
|
99
|
+
// haiku: $0.80 input / $4.00 output (~1x baseline)
|
|
100
|
+
// sonnet: $3.00 input / $15.00 output (~4x haiku)
|
|
101
|
+
// opus: $15.00 input / $75.00 output (~19x haiku)
|
|
102
|
+
// ---------------------------------------------------------------------------
|
|
103
|
+
const SONNET_AVG_COST_PER_USD_BUDGET = 0.35; // sonnet uses ~35% of budget on average
|
|
104
|
+
const HAIKU_AVG_COST_PER_USD_BUDGET = 0.10; // haiku uses ~10% — ~3.5x cheaper
|
|
105
|
+
function selectModelTier(mode) {
|
|
106
|
+
// Route already encodes complexity. Direct = passed the simplicity check → haiku.
|
|
107
|
+
if (mode === "direct")
|
|
108
|
+
return "haiku";
|
|
109
|
+
if (mode === "manager")
|
|
110
|
+
return "sonnet";
|
|
111
|
+
return "opus";
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Resolve a tier to a concrete model ID for a specific engine.
|
|
115
|
+
* Allows downstream adapters to switch models automatically.
|
|
116
|
+
*/
|
|
117
|
+
export function resolveModelForTier(tier, engine) {
|
|
118
|
+
const matrix = {
|
|
119
|
+
claude: {
|
|
120
|
+
haiku: "claude-haiku-4-5-20251001",
|
|
121
|
+
sonnet: "claude-sonnet-4-6",
|
|
122
|
+
opus: "claude-opus-4-6"
|
|
123
|
+
},
|
|
124
|
+
codex: {
|
|
125
|
+
haiku: "gpt-4o-mini",
|
|
126
|
+
sonnet: "gpt-4.1",
|
|
127
|
+
opus: "o3"
|
|
128
|
+
},
|
|
129
|
+
gemini: {
|
|
130
|
+
haiku: "gemini-2.5-flash",
|
|
131
|
+
sonnet: "gemini-2.5-pro",
|
|
132
|
+
opus: "gemini-2.5-ultra"
|
|
133
|
+
},
|
|
134
|
+
openai: {
|
|
135
|
+
haiku: "gpt-4o-mini",
|
|
136
|
+
sonnet: "gpt-4o",
|
|
137
|
+
opus: "o3"
|
|
138
|
+
},
|
|
139
|
+
deepseek: {
|
|
140
|
+
haiku: "deepseek-chat",
|
|
141
|
+
sonnet: "deepseek-r1",
|
|
142
|
+
opus: "deepseek-r1"
|
|
143
|
+
},
|
|
144
|
+
qwen: {
|
|
145
|
+
haiku: "qwen/qwen3-8b",
|
|
146
|
+
sonnet: "qwen/qwen3-32b",
|
|
147
|
+
opus: "qwen/qwen3-235b-a22b"
|
|
148
|
+
},
|
|
149
|
+
llama: {
|
|
150
|
+
haiku: "meta-llama/llama-3.1-8b-instruct",
|
|
151
|
+
sonnet: "meta-llama/llama-3.3-70b-instruct",
|
|
152
|
+
opus: "meta-llama/llama-3.1-405b-instruct"
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
const engineKey = engine.toLowerCase().split("-")[0] ?? engine;
|
|
156
|
+
const claudeMatrix = matrix.claude;
|
|
157
|
+
return matrix[engineKey]?.[tier] ?? claudeMatrix?.[tier] ?? "claude-sonnet-4-6";
|
|
158
|
+
}
|
|
159
|
+
function estimateSavingVsSonnet(tier, budgetUsd) {
|
|
160
|
+
if (tier === "sonnet")
|
|
161
|
+
return 0;
|
|
162
|
+
if (tier === "haiku")
|
|
163
|
+
return Math.round((SONNET_AVG_COST_PER_USD_BUDGET - HAIKU_AVG_COST_PER_USD_BUDGET) * budgetUsd * 100) / 100;
|
|
164
|
+
// opus costs more than sonnet — negative saving
|
|
165
|
+
return Math.round(-1 * SONNET_AVG_COST_PER_USD_BUDGET * budgetUsd * 0.5 * 100) / 100;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Select the best available engine for a given tier requirement.
|
|
169
|
+
*
|
|
170
|
+
* When multiple engines are available, picks the cheapest that meets
|
|
171
|
+
* the capability requirement. Falls back gracefully:
|
|
172
|
+
* - If required tier unavailable, upgrades to next tier of same engine
|
|
173
|
+
* - If only one engine family available, uses its best equivalent
|
|
174
|
+
*
|
|
175
|
+
* @param requiredTier - Minimum capability tier needed
|
|
176
|
+
* @param availableEngines - What's installed and authenticated
|
|
177
|
+
* @returns Best engine ID and concrete model to use
|
|
178
|
+
*/
|
|
179
|
+
export function selectBestEngine(requiredTier, availableEngines) {
|
|
180
|
+
const available = availableEngines.filter((e) => e.available);
|
|
181
|
+
if (available.length === 0) {
|
|
182
|
+
// Nothing detected — default to claude (user must install)
|
|
183
|
+
return {
|
|
184
|
+
engineId: "claude",
|
|
185
|
+
model: resolveModelForTier(requiredTier, "claude"),
|
|
186
|
+
reasoning: "No engines detected. Defaulting to claude. Run martin doctor for setup instructions."
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
const tierRank = {
|
|
190
|
+
haiku: 0, sonnet: 1, opus: 2
|
|
191
|
+
};
|
|
192
|
+
const requiredRank = tierRank[requiredTier];
|
|
193
|
+
// Find the cheapest engine that meets or exceeds the required tier
|
|
194
|
+
const eligible = available
|
|
195
|
+
.filter((e) => tierRank[e.capabilityTier] >= requiredRank)
|
|
196
|
+
.sort((a, b) => {
|
|
197
|
+
// Sort by cost (cheap first), then by exact tier match
|
|
198
|
+
const costOrder = { cheap: 0, mid: 1, expensive: 2 };
|
|
199
|
+
if (costOrder[a.costTier] !== costOrder[b.costTier]) {
|
|
200
|
+
return costOrder[a.costTier] - costOrder[b.costTier];
|
|
201
|
+
}
|
|
202
|
+
// Prefer exact tier match over overqualified
|
|
203
|
+
const aExact = a.capabilityTier === requiredTier ? 0 : 1;
|
|
204
|
+
const bExact = b.capabilityTier === requiredTier ? 0 : 1;
|
|
205
|
+
return aExact - bExact;
|
|
206
|
+
});
|
|
207
|
+
if (eligible.length > 0) {
|
|
208
|
+
const best = eligible[0];
|
|
209
|
+
const model = resolveModelForTier(requiredTier, best.id);
|
|
210
|
+
return {
|
|
211
|
+
engineId: best.id,
|
|
212
|
+
model,
|
|
213
|
+
reasoning: `Selected ${best.id} (${model}) as cheapest available engine for ${requiredTier}-tier task.`
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
// All available engines are below required tier — upgrade to best available
|
|
217
|
+
const best = available.sort((a, b) => tierRank[b.capabilityTier] - tierRank[a.capabilityTier])[0];
|
|
218
|
+
const model = resolveModelForTier(best.capabilityTier, best.id);
|
|
219
|
+
return {
|
|
220
|
+
engineId: best.id,
|
|
221
|
+
model,
|
|
222
|
+
reasoning: `No ${requiredTier}-tier engine available. Upgrading to ${best.id} (${model}) — best available.`
|
|
223
|
+
};
|
|
224
|
+
}
|
|
87
225
|
export function classifyRoute(input) {
|
|
88
226
|
const policy = { ...DEFAULT_ROUTING_POLICY, ...input.policy };
|
|
89
227
|
const signals = extractComplexitySignals(input);
|
|
@@ -92,6 +230,7 @@ export function classifyRoute(input) {
|
|
|
92
230
|
const blockedSteps = [];
|
|
93
231
|
// Policy override: forced mode
|
|
94
232
|
if (policy.mode === "direct") {
|
|
233
|
+
const tier = selectModelTier("direct");
|
|
95
234
|
return {
|
|
96
235
|
selectedMode: "direct",
|
|
97
236
|
confidence: 1,
|
|
@@ -100,10 +239,13 @@ export function classifyRoute(input) {
|
|
|
100
239
|
reason: ["Policy forces direct execution mode."],
|
|
101
240
|
blockedSteps: ["manager", "planner", "router", "consensus"],
|
|
102
241
|
compressed: true,
|
|
103
|
-
compressionSummary: "Policy: direct mode — skipping all orchestration."
|
|
242
|
+
compressionSummary: "Policy: direct mode — skipping all orchestration.",
|
|
243
|
+
recommendedModelTier: tier,
|
|
244
|
+
estimatedSavingVsSonnetUsd: estimateSavingVsSonnet(tier, input.budgetUsd)
|
|
104
245
|
};
|
|
105
246
|
}
|
|
106
247
|
if (policy.mode === "consensus") {
|
|
248
|
+
const tier = selectModelTier("consensus");
|
|
107
249
|
return {
|
|
108
250
|
selectedMode: "consensus",
|
|
109
251
|
confidence: 0.5,
|
|
@@ -111,7 +253,9 @@ export function classifyRoute(input) {
|
|
|
111
253
|
expectedPreworkBurnPct: 35,
|
|
112
254
|
reason: ["Policy forces consensus mode."],
|
|
113
255
|
blockedSteps: [],
|
|
114
|
-
compressed: false
|
|
256
|
+
compressed: false,
|
|
257
|
+
recommendedModelTier: tier,
|
|
258
|
+
estimatedSavingVsSonnetUsd: estimateSavingVsSonnet(tier, input.budgetUsd)
|
|
115
259
|
};
|
|
116
260
|
}
|
|
117
261
|
// Adaptive routing
|
|
@@ -124,6 +268,7 @@ export function classifyRoute(input) {
|
|
|
124
268
|
if (signals.scopeRestricted)
|
|
125
269
|
reason.push("Path scope is restricted.");
|
|
126
270
|
blockedSteps.push("manager", "consensus");
|
|
271
|
+
const tier = selectModelTier("direct");
|
|
127
272
|
return {
|
|
128
273
|
selectedMode: "direct",
|
|
129
274
|
confidence: directConfidence,
|
|
@@ -132,7 +277,9 @@ export function classifyRoute(input) {
|
|
|
132
277
|
reason,
|
|
133
278
|
blockedSteps,
|
|
134
279
|
compressed: true,
|
|
135
|
-
compressionSummary: `Compressed from manager→planner→worker to direct worker. Estimated savings: ${String(Math.round(input.budgetUsd * 0.3 * 100) / 100)} USD
|
|
280
|
+
compressionSummary: `Compressed from manager→planner→worker to direct worker. Estimated savings: ${String(Math.round(input.budgetUsd * 0.3 * 100) / 100)} USD.`,
|
|
281
|
+
recommendedModelTier: tier,
|
|
282
|
+
estimatedSavingVsSonnetUsd: estimateSavingVsSonnet(tier, input.budgetUsd)
|
|
136
283
|
};
|
|
137
284
|
}
|
|
138
285
|
// Complex task — needs orchestration
|
|
@@ -145,14 +292,18 @@ export function classifyRoute(input) {
|
|
|
145
292
|
if (signals.fileCount > 5)
|
|
146
293
|
reason.push(`Touches ${String(signals.fileCount)}+ files.`);
|
|
147
294
|
const needsConsensus = signals.hasSecurityKeywords && signals.hasMigrationKeywords;
|
|
295
|
+
const mode = needsConsensus ? "consensus" : "manager";
|
|
296
|
+
const tier = selectModelTier(mode);
|
|
148
297
|
return {
|
|
149
|
-
selectedMode:
|
|
298
|
+
selectedMode: mode,
|
|
150
299
|
confidence: directConfidence,
|
|
151
300
|
expectedCostUsd: input.budgetUsd * (needsConsensus ? 0.8 : 0.6),
|
|
152
301
|
expectedPreworkBurnPct: needsConsensus ? 40 : 25,
|
|
153
302
|
reason,
|
|
154
303
|
blockedSteps: needsConsensus ? [] : ["consensus"],
|
|
155
|
-
compressed: false
|
|
304
|
+
compressed: false,
|
|
305
|
+
recommendedModelTier: tier,
|
|
306
|
+
estimatedSavingVsSonnetUsd: estimateSavingVsSonnet(tier, input.budgetUsd)
|
|
156
307
|
};
|
|
157
308
|
}
|
|
158
309
|
function estimateDirectCost(budgetUsd) {
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test Integrity Validator
|
|
3
|
+
*
|
|
4
|
+
* Detects circular test validation — the problem where AI agents generate
|
|
5
|
+
* tests that only pass because they test the agent's own output, not real
|
|
6
|
+
* behavior. A test that passes on both the pre-change and post-change
|
|
7
|
+
* codebase proves nothing about the change.
|
|
8
|
+
*
|
|
9
|
+
* Strategy:
|
|
10
|
+
* 1. Snapshot which test files existed before the agent ran
|
|
11
|
+
* 2. After the run, identify NEW test files the agent created
|
|
12
|
+
* 3. For each new test: check if it imports/references pre-existing code
|
|
13
|
+
* (real test) or only references agent-generated code (circular test)
|
|
14
|
+
* 4. Flag tests that don't exercise any pre-existing function
|
|
15
|
+
*
|
|
16
|
+
* This module provides the analysis primitives. The verification pipeline
|
|
17
|
+
* calls these during the post-run verification step.
|
|
18
|
+
*/
|
|
19
|
+
export interface TestIntegrityReport {
|
|
20
|
+
totalNewTests: number;
|
|
21
|
+
realTests: number;
|
|
22
|
+
suspiciousTests: number;
|
|
23
|
+
findings: TestIntegrityFinding[];
|
|
24
|
+
verdict: "pass" | "warn" | "fail";
|
|
25
|
+
summary: string;
|
|
26
|
+
}
|
|
27
|
+
export interface TestIntegrityFinding {
|
|
28
|
+
filePath: string;
|
|
29
|
+
issue: "no_pre_existing_imports" | "self_referential" | "trivial_assertion" | "empty_test";
|
|
30
|
+
severity: "high" | "medium" | "low";
|
|
31
|
+
detail: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Detect test files in a directory tree.
|
|
35
|
+
*/
|
|
36
|
+
export declare function findTestFiles(rootDir: string): string[];
|
|
37
|
+
/**
|
|
38
|
+
* Check if a filename matches test file patterns.
|
|
39
|
+
*/
|
|
40
|
+
export declare function isTestFile(filename: string, fullPath?: string): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Snapshot existing test files before an agent run.
|
|
43
|
+
*/
|
|
44
|
+
export declare function snapshotTestFiles(rootDir: string): Set<string>;
|
|
45
|
+
/**
|
|
46
|
+
* Identify new test files created during an agent run.
|
|
47
|
+
*/
|
|
48
|
+
export declare function identifyNewTests(rootDir: string, preRunSnapshot: Set<string>): string[];
|
|
49
|
+
/**
|
|
50
|
+
* Extract import paths from a TypeScript/JavaScript file.
|
|
51
|
+
*/
|
|
52
|
+
export declare function extractImports(content: string): string[];
|
|
53
|
+
/**
|
|
54
|
+
* Check if a test file contains only trivial assertions.
|
|
55
|
+
*/
|
|
56
|
+
export declare function hasTrivialAssertionsOnly(content: string): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Check if a test file imports any pre-existing source files.
|
|
59
|
+
*/
|
|
60
|
+
export declare function importsPreExistingCode(testContent: string, preRunSourceFiles: Set<string>): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Validate the integrity of tests created during a governed run.
|
|
63
|
+
*/
|
|
64
|
+
export declare function validateTestIntegrity(rootDir: string, preRunTestSnapshot: Set<string>, preRunSourceFiles: Set<string>): TestIntegrityReport;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test Integrity Validator
|
|
3
|
+
*
|
|
4
|
+
* Detects circular test validation — the problem where AI agents generate
|
|
5
|
+
* tests that only pass because they test the agent's own output, not real
|
|
6
|
+
* behavior. A test that passes on both the pre-change and post-change
|
|
7
|
+
* codebase proves nothing about the change.
|
|
8
|
+
*
|
|
9
|
+
* Strategy:
|
|
10
|
+
* 1. Snapshot which test files existed before the agent ran
|
|
11
|
+
* 2. After the run, identify NEW test files the agent created
|
|
12
|
+
* 3. For each new test: check if it imports/references pre-existing code
|
|
13
|
+
* (real test) or only references agent-generated code (circular test)
|
|
14
|
+
* 4. Flag tests that don't exercise any pre-existing function
|
|
15
|
+
*
|
|
16
|
+
* This module provides the analysis primitives. The verification pipeline
|
|
17
|
+
* calls these during the post-run verification step.
|
|
18
|
+
*/
|
|
19
|
+
import { readFileSync, readdirSync, existsSync } from "node:fs";
|
|
20
|
+
import { join, relative } from "node:path";
|
|
21
|
+
const TEST_FILE_PATTERNS = [
|
|
22
|
+
/\.test\.[tj]sx?$/,
|
|
23
|
+
/\.spec\.[tj]sx?$/,
|
|
24
|
+
/\/__tests__\//,
|
|
25
|
+
/\/tests?\//
|
|
26
|
+
];
|
|
27
|
+
const TRIVIAL_ASSERTION_PATTERNS = [
|
|
28
|
+
/expect\(true\)\.toBe\(true\)/,
|
|
29
|
+
/expect\(1\)\.toBe\(1\)/,
|
|
30
|
+
/expect\(\)\.toBeUndefined\(\)/,
|
|
31
|
+
/assert\.ok\(true\)/,
|
|
32
|
+
/expect\(.*\)\.toBeDefined\(\)/,
|
|
33
|
+
/expect\(typeof\s+\w+\)\.toBe\(['"]\w+['"]\)/
|
|
34
|
+
];
|
|
35
|
+
const IMPORT_PATTERN = /(?:import\s+.*from\s+['"]([^'"]+)['"]|require\s*\(\s*['"]([^'"]+)['"]\s*\))/g;
|
|
36
|
+
/**
|
|
37
|
+
* Detect test files in a directory tree.
|
|
38
|
+
*/
|
|
39
|
+
export function findTestFiles(rootDir) {
|
|
40
|
+
const results = [];
|
|
41
|
+
function walk(dir) {
|
|
42
|
+
if (!existsSync(dir))
|
|
43
|
+
return;
|
|
44
|
+
try {
|
|
45
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
46
|
+
for (const entry of entries) {
|
|
47
|
+
const fullPath = join(dir, entry.name);
|
|
48
|
+
if (entry.name === "node_modules" || entry.name === "dist" || entry.name === ".git")
|
|
49
|
+
continue;
|
|
50
|
+
if (entry.isDirectory()) {
|
|
51
|
+
walk(fullPath);
|
|
52
|
+
}
|
|
53
|
+
else if (entry.isFile() && isTestFile(entry.name, fullPath)) {
|
|
54
|
+
results.push(relative(rootDir, fullPath));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// Permission denied or inaccessible — skip silently
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
walk(rootDir);
|
|
63
|
+
return results;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Check if a filename matches test file patterns.
|
|
67
|
+
*/
|
|
68
|
+
export function isTestFile(filename, fullPath) {
|
|
69
|
+
const checkPath = fullPath ?? filename;
|
|
70
|
+
return TEST_FILE_PATTERNS.some((pattern) => pattern.test(checkPath));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Snapshot existing test files before an agent run.
|
|
74
|
+
*/
|
|
75
|
+
export function snapshotTestFiles(rootDir) {
|
|
76
|
+
return new Set(findTestFiles(rootDir));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Identify new test files created during an agent run.
|
|
80
|
+
*/
|
|
81
|
+
export function identifyNewTests(rootDir, preRunSnapshot) {
|
|
82
|
+
const currentTests = findTestFiles(rootDir);
|
|
83
|
+
return currentTests.filter((testPath) => !preRunSnapshot.has(testPath));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Extract import paths from a TypeScript/JavaScript file.
|
|
87
|
+
*/
|
|
88
|
+
export function extractImports(content) {
|
|
89
|
+
const imports = [];
|
|
90
|
+
let match;
|
|
91
|
+
const pattern = new RegExp(IMPORT_PATTERN.source, "g");
|
|
92
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
93
|
+
const importPath = match[1] ?? match[2];
|
|
94
|
+
if (importPath)
|
|
95
|
+
imports.push(importPath);
|
|
96
|
+
}
|
|
97
|
+
return imports;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Check if a test file contains only trivial assertions.
|
|
101
|
+
*/
|
|
102
|
+
export function hasTrivialAssertionsOnly(content) {
|
|
103
|
+
const assertionLines = content.split("\n").filter((line) => /expect\(|assert\.|should\./i.test(line));
|
|
104
|
+
if (assertionLines.length === 0)
|
|
105
|
+
return true;
|
|
106
|
+
return assertionLines.every((line) => TRIVIAL_ASSERTION_PATTERNS.some((pattern) => pattern.test(line)));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Check if a test file imports any pre-existing source files.
|
|
110
|
+
*/
|
|
111
|
+
export function importsPreExistingCode(testContent, preRunSourceFiles) {
|
|
112
|
+
const imports = extractImports(testContent);
|
|
113
|
+
return imports.some((importPath) => {
|
|
114
|
+
// Relative imports that reference pre-existing files
|
|
115
|
+
if (importPath.startsWith(".") || importPath.startsWith("/")) {
|
|
116
|
+
// Normalize: strip extension, check if any pre-existing source matches
|
|
117
|
+
const normalized = importPath.replace(/\.[tj]sx?$/, "");
|
|
118
|
+
return [...preRunSourceFiles].some((srcFile) => {
|
|
119
|
+
const normalizedSrc = srcFile.replace(/\.[tj]sx?$/, "");
|
|
120
|
+
return normalizedSrc.endsWith(normalized) || normalized.endsWith(normalizedSrc);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
// Package imports always count as real (they reference pre-existing deps)
|
|
124
|
+
return true;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Validate the integrity of tests created during a governed run.
|
|
129
|
+
*/
|
|
130
|
+
export function validateTestIntegrity(rootDir, preRunTestSnapshot, preRunSourceFiles) {
|
|
131
|
+
const newTests = identifyNewTests(rootDir, preRunTestSnapshot);
|
|
132
|
+
const findings = [];
|
|
133
|
+
for (const testPath of newTests) {
|
|
134
|
+
const fullPath = join(rootDir, testPath);
|
|
135
|
+
let content;
|
|
136
|
+
try {
|
|
137
|
+
content = readFileSync(fullPath, "utf8");
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
findings.push({
|
|
141
|
+
filePath: testPath,
|
|
142
|
+
issue: "empty_test",
|
|
143
|
+
severity: "high",
|
|
144
|
+
detail: "Test file could not be read."
|
|
145
|
+
});
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (content.trim().length === 0) {
|
|
149
|
+
findings.push({
|
|
150
|
+
filePath: testPath,
|
|
151
|
+
issue: "empty_test",
|
|
152
|
+
severity: "high",
|
|
153
|
+
detail: "Test file is empty."
|
|
154
|
+
});
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (hasTrivialAssertionsOnly(content)) {
|
|
158
|
+
findings.push({
|
|
159
|
+
filePath: testPath,
|
|
160
|
+
issue: "trivial_assertion",
|
|
161
|
+
severity: "high",
|
|
162
|
+
detail: "Test contains only trivial assertions (expect(true).toBe(true) or equivalent)."
|
|
163
|
+
});
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (!importsPreExistingCode(content, preRunSourceFiles)) {
|
|
167
|
+
findings.push({
|
|
168
|
+
filePath: testPath,
|
|
169
|
+
issue: "no_pre_existing_imports",
|
|
170
|
+
severity: "medium",
|
|
171
|
+
detail: "Test does not import any pre-existing source code. May be testing only agent-generated output."
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const suspiciousTests = findings.filter((f) => f.severity === "high").length;
|
|
176
|
+
const realTests = newTests.length - suspiciousTests;
|
|
177
|
+
const verdict = suspiciousTests > 0 && suspiciousTests >= newTests.length * 0.5
|
|
178
|
+
? "fail"
|
|
179
|
+
: suspiciousTests > 0
|
|
180
|
+
? "warn"
|
|
181
|
+
: "pass";
|
|
182
|
+
const summary = newTests.length === 0
|
|
183
|
+
? "No new test files detected."
|
|
184
|
+
: verdict === "pass"
|
|
185
|
+
? `${newTests.length} new test(s) validated — all reference pre-existing code.`
|
|
186
|
+
: verdict === "warn"
|
|
187
|
+
? `${suspiciousTests} of ${newTests.length} new test(s) flagged for review.`
|
|
188
|
+
: `Test integrity check failed: ${suspiciousTests} of ${newTests.length} new test(s) appear circular or trivial.`;
|
|
189
|
+
return {
|
|
190
|
+
totalNewTests: newTests.length,
|
|
191
|
+
realTests,
|
|
192
|
+
suspiciousTests,
|
|
193
|
+
findings,
|
|
194
|
+
verdict,
|
|
195
|
+
summary
|
|
196
|
+
};
|
|
197
|
+
}
|
package/dist/workflow-state.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LoopBudget, ReceiptScope } from "./vendor/contracts/index.js";
|
|
2
|
-
type McpWorkflowStepName = "doctor" | "plan" | "preflight";
|
|
2
|
+
type McpWorkflowStepName = "doctor" | "plan" | "preflight" | "estimate" | "start";
|
|
3
3
|
interface McpWorkflowReceipt {
|
|
4
4
|
step: McpWorkflowStepName;
|
|
5
5
|
recordedAt: string;
|
package/dist/workflow-state.js
CHANGED
|
@@ -4,6 +4,7 @@ import { join, resolve } from "node:path";
|
|
|
4
4
|
const WORKFLOW_STATE_DIRECTORY = "_martin";
|
|
5
5
|
const WORKFLOW_STATE_FILENAME = "workflow-state.json";
|
|
6
6
|
const DOCTOR_TTL_MS = 24 * 60 * 60 * 1000;
|
|
7
|
+
const ESTIMATE_TTL_MS = 6 * 60 * 60 * 1000; // Estimate expires after 6h — re-estimate if objective changes
|
|
7
8
|
const PLAN_TTL_MS = 24 * 60 * 60 * 1000;
|
|
8
9
|
const PREFLIGHT_TTL_MS = 6 * 60 * 60 * 1000;
|
|
9
10
|
export async function recordMcpWorkflowStep(input) {
|
|
@@ -42,6 +43,11 @@ export async function evaluateMcpRunGate(input) {
|
|
|
42
43
|
receipt.scopeKey === scopeKey)) {
|
|
43
44
|
missingSteps.push("doctor");
|
|
44
45
|
}
|
|
46
|
+
// Estimate is required before any run — it proves the agent assessed cost first.
|
|
47
|
+
// The estimate TTL is 6h; it doesn't need to match the exact objective key.
|
|
48
|
+
if (!isFresh(mcpState["estimate"], ESTIMATE_TTL_MS, (receipt) => receipt.workingDirectory === workingDirectory)) {
|
|
49
|
+
missingSteps.push("estimate");
|
|
50
|
+
}
|
|
45
51
|
if (!isFresh(mcpState["plan"], PLAN_TTL_MS, (receipt) => receipt.workingDirectory === workingDirectory &&
|
|
46
52
|
receipt.scopeKey === scopeKey &&
|
|
47
53
|
receipt.objectiveKey === objectiveKey)) {
|
|
@@ -65,10 +71,12 @@ export async function evaluateMcpRunGate(input) {
|
|
|
65
71
|
};
|
|
66
72
|
}
|
|
67
73
|
const nextAction = missingSteps[0] === "doctor"
|
|
68
|
-
? "Call martin_doctor
|
|
69
|
-
: missingSteps[0] === "
|
|
70
|
-
? "Call
|
|
71
|
-
:
|
|
74
|
+
? "Call martin_doctor to confirm environment before any work."
|
|
75
|
+
: missingSteps[0] === "estimate"
|
|
76
|
+
? "Call martin_estimate with the objective to get cost and route before spending."
|
|
77
|
+
: missingSteps[0] === "plan"
|
|
78
|
+
? "Call martin_plan with the exact objective before martin_run."
|
|
79
|
+
: "Call martin_preflight with the exact objective, verifier plan, and engine before martin_run.";
|
|
72
80
|
return {
|
|
73
81
|
allowed: false,
|
|
74
82
|
nextAction,
|
package/package.json
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@martinloop/mcp",
|
|
3
|
-
"version": "0.3.
|
|
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
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@martinloop/mcp",
|
|
3
|
+
"version": "0.3.6",
|
|
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
|
+
}
|