@martinloop/mcp 0.3.8 → 0.3.9
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 +148 -105
- package/dist/resources.js +148 -148
- package/dist/server.js +0 -0
- package/dist/tools/preflight.d.ts +0 -2
- package/dist/tools/preflight.js +2 -42
- package/dist/vendor/adapters/openai-compatible.js +6 -6
- package/dist/vendor/contracts/index.d.ts +0 -2
- package/dist/vendor/contracts/index.js +0 -2
- package/dist/vendor/core/index.d.ts +0 -2
- package/dist/vendor/core/index.js +0 -2
- package/package.json +86 -83
- package/server.json +21 -21
- package/LICENSE +0 -216
- package/dist/vendor/adapters/adapters/src/claude-cli.d.ts +0 -146
- package/dist/vendor/adapters/adapters/src/claude-cli.js +0 -1100
- package/dist/vendor/adapters/adapters/src/cli-bridge.d.ts +0 -103
- package/dist/vendor/adapters/adapters/src/cli-bridge.js +0 -569
- package/dist/vendor/adapters/adapters/src/codex-launcher.d.ts +0 -78
- package/dist/vendor/adapters/adapters/src/codex-launcher.js +0 -663
- package/dist/vendor/adapters/adapters/src/direct-provider.d.ts +0 -10
- package/dist/vendor/adapters/adapters/src/direct-provider.js +0 -40
- package/dist/vendor/adapters/adapters/src/index.d.ts +0 -8
- package/dist/vendor/adapters/adapters/src/index.js +0 -8
- package/dist/vendor/adapters/adapters/src/openai-compatible.d.ts +0 -62
- package/dist/vendor/adapters/adapters/src/openai-compatible.js +0 -306
- package/dist/vendor/adapters/adapters/src/runtime-support.d.ts +0 -17
- package/dist/vendor/adapters/adapters/src/runtime-support.js +0 -59
- package/dist/vendor/adapters/adapters/src/stub-agent-cli.d.ts +0 -8
- package/dist/vendor/adapters/adapters/src/stub-agent-cli.js +0 -40
- package/dist/vendor/adapters/adapters/src/stub-direct-provider.d.ts +0 -8
- package/dist/vendor/adapters/adapters/src/stub-direct-provider.js +0 -12
- package/dist/vendor/adapters/adapters/src/verifier-only.d.ts +0 -9
- package/dist/vendor/adapters/adapters/src/verifier-only.js +0 -63
- package/dist/vendor/adapters/contracts/src/context-graph.d.ts +0 -48
- package/dist/vendor/adapters/contracts/src/context-graph.js +0 -26
- package/dist/vendor/adapters/contracts/src/execution-policy.d.ts +0 -78
- package/dist/vendor/adapters/contracts/src/execution-policy.js +0 -43
- package/dist/vendor/adapters/contracts/src/governance.d.ts +0 -24
- package/dist/vendor/adapters/contracts/src/governance.js +0 -11
- package/dist/vendor/adapters/contracts/src/identity.d.ts +0 -29
- package/dist/vendor/adapters/contracts/src/identity.js +0 -30
- package/dist/vendor/adapters/contracts/src/index.d.ts +0 -412
- package/dist/vendor/adapters/contracts/src/index.js +0 -225
- package/dist/vendor/adapters/contracts/src/operator.d.ts +0 -19
- package/dist/vendor/adapters/contracts/src/operator.js +0 -11
- package/dist/vendor/adapters/contracts/src/trajectory.d.ts +0 -26
- package/dist/vendor/adapters/contracts/src/trajectory.js +0 -27
- package/dist/vendor/adapters/core/src/compiler.d.ts +0 -52
- package/dist/vendor/adapters/core/src/compiler.js +0 -52
- package/dist/vendor/adapters/core/src/context-graph.d.ts +0 -3
- package/dist/vendor/adapters/core/src/context-graph.js +0 -371
- package/dist/vendor/adapters/core/src/context-integrity.d.ts +0 -26
- package/dist/vendor/adapters/core/src/context-integrity.js +0 -80
- package/dist/vendor/adapters/core/src/grounding.d.ts +0 -38
- package/dist/vendor/adapters/core/src/grounding.js +0 -273
- package/dist/vendor/adapters/core/src/identity.d.ts +0 -20
- package/dist/vendor/adapters/core/src/identity.js +0 -86
- package/dist/vendor/adapters/core/src/index.d.ts +0 -186
- package/dist/vendor/adapters/core/src/index.js +0 -1495
- package/dist/vendor/adapters/core/src/leash.d.ts +0 -48
- package/dist/vendor/adapters/core/src/leash.js +0 -497
- package/dist/vendor/adapters/core/src/persistence/compiler.d.ts +0 -18
- package/dist/vendor/adapters/core/src/persistence/compiler.js +0 -34
- package/dist/vendor/adapters/core/src/persistence/index.d.ts +0 -10
- package/dist/vendor/adapters/core/src/persistence/index.js +0 -5
- package/dist/vendor/adapters/core/src/persistence/integrity.d.ts +0 -39
- package/dist/vendor/adapters/core/src/persistence/integrity.js +0 -252
- package/dist/vendor/adapters/core/src/persistence/ledger.d.ts +0 -23
- package/dist/vendor/adapters/core/src/persistence/ledger.js +0 -9
- package/dist/vendor/adapters/core/src/persistence/memory-store.d.ts +0 -63
- package/dist/vendor/adapters/core/src/persistence/memory-store.js +0 -115
- package/dist/vendor/adapters/core/src/persistence/runs-reader.d.ts +0 -66
- package/dist/vendor/adapters/core/src/persistence/runs-reader.js +0 -140
- package/dist/vendor/adapters/core/src/persistence/store.d.ts +0 -89
- package/dist/vendor/adapters/core/src/persistence/store.js +0 -125
- package/dist/vendor/adapters/core/src/persistence/trace-store.d.ts +0 -85
- package/dist/vendor/adapters/core/src/persistence/trace-store.js +0 -125
- package/dist/vendor/adapters/core/src/policy-compiler.d.ts +0 -2
- package/dist/vendor/adapters/core/src/policy-compiler.js +0 -195
- package/dist/vendor/adapters/core/src/policy.d.ts +0 -156
- package/dist/vendor/adapters/core/src/policy.js +0 -704
- package/dist/vendor/adapters/core/src/repo-analyzer.d.ts +0 -53
- package/dist/vendor/adapters/core/src/repo-analyzer.js +0 -263
- package/dist/vendor/adapters/core/src/rollback.d.ts +0 -15
- package/dist/vendor/adapters/core/src/rollback.js +0 -253
- package/dist/vendor/adapters/core/src/routing.d.ts +0 -82
- package/dist/vendor/adapters/core/src/routing.js +0 -336
- package/dist/vendor/adapters/core/src/test-integrity.d.ts +0 -64
- package/dist/vendor/adapters/core/src/test-integrity.js +0 -197
- package/dist/vendor/adapters/core/src/trajectory.d.ts +0 -18
- package/dist/vendor/adapters/core/src/trajectory.js +0 -295
- package/dist/vendor/contracts/delivery.d.ts +0 -47
- package/dist/vendor/contracts/delivery.js +0 -18
- package/dist/vendor/core/delivery/index.d.ts +0 -6
- package/dist/vendor/core/delivery/index.js +0 -4
- package/dist/vendor/core/delivery/message-client.d.ts +0 -18
- package/dist/vendor/core/delivery/message-client.js +0 -38
- package/dist/vendor/core/delivery/message-ledger.d.ts +0 -35
- package/dist/vendor/core/delivery/message-ledger.js +0 -97
- package/dist/vendor/core/delivery/message-schema.d.ts +0 -16
- package/dist/vendor/core/delivery/message-schema.js +0 -111
- package/dist/vendor/core/delivery/update-check.d.ts +0 -19
- package/dist/vendor/core/delivery/update-check.js +0 -107
|
@@ -1,412 +0,0 @@
|
|
|
1
|
-
export type LoopStatus = "queued" | "running" | "verifying" | "completed" | "failed" | "exited";
|
|
2
|
-
export type LoopLifecycleState = "created" | "running" | "verifying" | "completed" | "budget_exit" | "diminishing_returns" | "stuck_exit" | "human_escalation";
|
|
3
|
-
export declare const FAILURE_CLASSES: readonly ["logic_error", "hallucination", "syntax_error", "type_error", "test_regression", "scope_creep", "no_progress", "repo_grounding_failure", "verification_failure", "environment_mismatch", "budget_pressure", "safety_leash_blocked", "sandbox_write_blocked"];
|
|
4
|
-
export type FailureClass = (typeof FAILURE_CLASSES)[number];
|
|
5
|
-
export type InterventionType = "compress_context" | "change_model" | "tighten_task" | "switch_adapter" | "run_verifier" | "escalate_human" | "stop_loop";
|
|
6
|
-
export type LoopEventType = "run.started" | "attempt.started" | "attempt.completed" | "failure.classified" | "intervention.selected" | "verification.completed" | "budget.updated" | "run.completed";
|
|
7
|
-
export interface LoopTask {
|
|
8
|
-
title: string;
|
|
9
|
-
objective: string;
|
|
10
|
-
repoRoot?: string;
|
|
11
|
-
verificationPlan: string[];
|
|
12
|
-
verificationTimeoutMs?: number;
|
|
13
|
-
verificationStack?: VerificationStep[];
|
|
14
|
-
mutationMode?: MutationMode;
|
|
15
|
-
executionProfile?: ExecutionProfile;
|
|
16
|
-
allowedNetworkDomains?: string[];
|
|
17
|
-
approvalPolicy?: ApprovalPolicy;
|
|
18
|
-
/** Glob patterns for files the agent is allowed to modify. Empty = no restriction. */
|
|
19
|
-
allowedPaths?: string[];
|
|
20
|
-
/** Glob patterns for files the agent must never modify. */
|
|
21
|
-
deniedPaths?: string[];
|
|
22
|
-
/** Human-readable acceptance criteria injected into the prompt as a checklist. */
|
|
23
|
-
acceptanceCriteria?: string[];
|
|
24
|
-
}
|
|
25
|
-
export type ExecutionProfile = "strict_local" | "ci_safe" | "staging_controlled" | "research_untrusted";
|
|
26
|
-
export type MutationMode = "edit" | "verify_only";
|
|
27
|
-
export interface ApprovalPolicy {
|
|
28
|
-
dependencyAdds?: boolean;
|
|
29
|
-
migrations?: boolean;
|
|
30
|
-
configChanges?: boolean;
|
|
31
|
-
externalWrites?: boolean;
|
|
32
|
-
}
|
|
33
|
-
export interface VerificationStep {
|
|
34
|
-
/** Shell command to run. */
|
|
35
|
-
command: string;
|
|
36
|
-
/** Classification for reporting and intervention selection. */
|
|
37
|
-
type: "lint" | "typecheck" | "test_targeted" | "test_full" | "custom";
|
|
38
|
-
/** Stop the verification stack immediately on failure. Defaults to true. */
|
|
39
|
-
fastFail?: boolean;
|
|
40
|
-
/** Relative weight for partial scoring (0.0-1.0). */
|
|
41
|
-
weight?: number;
|
|
42
|
-
}
|
|
43
|
-
export interface LoopBudget {
|
|
44
|
-
maxUsd: number;
|
|
45
|
-
softLimitUsd: number;
|
|
46
|
-
maxIterations: number;
|
|
47
|
-
maxTokens: number;
|
|
48
|
-
}
|
|
49
|
-
export interface LoopCost {
|
|
50
|
-
actualUsd: number;
|
|
51
|
-
avoidedUsd: number;
|
|
52
|
-
tokensIn: number;
|
|
53
|
-
tokensOut: number;
|
|
54
|
-
estimatedUsd?: number;
|
|
55
|
-
provenance?: CostProvenance;
|
|
56
|
-
providerSettlement?: ProviderUsageSettlement;
|
|
57
|
-
}
|
|
58
|
-
export type UsageSettlementSource = "claude_json" | "codex_jsonl" | "gemini_json" | "estimated_fallback" | "unavailable";
|
|
59
|
-
export interface ProviderUsageSettlement {
|
|
60
|
-
providerId: string;
|
|
61
|
-
model: string;
|
|
62
|
-
transport?: "cli" | "http" | "routed_http";
|
|
63
|
-
source: UsageSettlementSource;
|
|
64
|
-
inputTokens: number;
|
|
65
|
-
cachedInputTokens?: number;
|
|
66
|
-
outputTokens: number;
|
|
67
|
-
reasoningOutputTokens?: number;
|
|
68
|
-
rawUsageAvailable: boolean;
|
|
69
|
-
settledAt: string;
|
|
70
|
-
}
|
|
71
|
-
export interface ReceiptScope {
|
|
72
|
-
repoRoot?: string;
|
|
73
|
-
workingDirectory?: string;
|
|
74
|
-
invocationRoot?: string;
|
|
75
|
-
runsRoot?: string;
|
|
76
|
-
}
|
|
77
|
-
export type ReceiptIntegrityState = "verified" | "unsigned" | "tamper_detected" | "relocated" | "material_missing" | "selector_noncanonical";
|
|
78
|
-
export interface ReceiptIntegritySummary {
|
|
79
|
-
state: ReceiptIntegrityState;
|
|
80
|
-
keyId?: string;
|
|
81
|
-
signedAt?: string;
|
|
82
|
-
loopRecordSha256?: string;
|
|
83
|
-
ledgerSha256?: string;
|
|
84
|
-
ledgerHeadHash?: string;
|
|
85
|
-
entryCount?: number;
|
|
86
|
-
reason?: string;
|
|
87
|
-
warnings?: string[];
|
|
88
|
-
}
|
|
89
|
-
export interface LoopArtifact {
|
|
90
|
-
artifactId: string;
|
|
91
|
-
kind: "diff" | "trace" | "report" | "transcript" | "screenshot" | "other";
|
|
92
|
-
label: string;
|
|
93
|
-
uri: string;
|
|
94
|
-
}
|
|
95
|
-
export type CallStage = "routing" | "planning" | "execution" | "verification" | "retry" | "rollback" | "receipt";
|
|
96
|
-
export type AgentRole = "manager" | "router" | "planner" | "worker" | "verifier" | "reviewer" | "fixer" | "system";
|
|
97
|
-
export interface FirstDelta {
|
|
98
|
-
detected: boolean;
|
|
99
|
-
timestampMs?: number;
|
|
100
|
-
filePath?: string;
|
|
101
|
-
changeType?: "create" | "modify" | "delete" | "patch_proposed";
|
|
102
|
-
/** Elapsed ms from run start to first meaningful workspace change. */
|
|
103
|
-
timeToFirstDeltaMs?: number;
|
|
104
|
-
}
|
|
105
|
-
export interface RoutingEconomics {
|
|
106
|
-
preworkCostUsd: number;
|
|
107
|
-
executionCostUsd: number;
|
|
108
|
-
verificationCostUsd: number;
|
|
109
|
-
retryCostUsd: number;
|
|
110
|
-
totalCostUsd: number;
|
|
111
|
-
preworkBurnPct: number;
|
|
112
|
-
timeToFirstDeltaMs?: number;
|
|
113
|
-
firstDelta?: FirstDelta;
|
|
114
|
-
costPerAcceptedChange?: number;
|
|
115
|
-
routeRecommendation?: "same_route" | "direct_worker" | "manager_required" | "consensus_required";
|
|
116
|
-
routeRecommendationReason?: string;
|
|
117
|
-
}
|
|
118
|
-
export interface LoopAttempt {
|
|
119
|
-
attemptId: string;
|
|
120
|
-
index: number;
|
|
121
|
-
adapterId: string;
|
|
122
|
-
model: string;
|
|
123
|
-
startedAt: string;
|
|
124
|
-
completedAt?: string;
|
|
125
|
-
summary?: string;
|
|
126
|
-
failureClass?: FailureClass;
|
|
127
|
-
intervention?: InterventionType;
|
|
128
|
-
/** Actionable diagnosis from failure classification, injected into the next attempt's prompt. */
|
|
129
|
-
diagnosticHint?: string;
|
|
130
|
-
/** Which stage of the run lifecycle this attempt represents. */
|
|
131
|
-
callStage?: CallStage;
|
|
132
|
-
}
|
|
133
|
-
export interface LoopEvent {
|
|
134
|
-
eventId: string;
|
|
135
|
-
type: LoopEventType;
|
|
136
|
-
timestamp: string;
|
|
137
|
-
lifecycleState: LoopLifecycleState;
|
|
138
|
-
payload: Record<string, unknown>;
|
|
139
|
-
}
|
|
140
|
-
export interface LoopRecord {
|
|
141
|
-
loopId: string;
|
|
142
|
-
workspaceId: string;
|
|
143
|
-
projectId: string;
|
|
144
|
-
teamId?: string;
|
|
145
|
-
status: LoopStatus;
|
|
146
|
-
lifecycleState: LoopLifecycleState;
|
|
147
|
-
task: LoopTask;
|
|
148
|
-
budget: LoopBudget;
|
|
149
|
-
cost: LoopCost;
|
|
150
|
-
artifacts: LoopArtifact[];
|
|
151
|
-
attempts: LoopAttempt[];
|
|
152
|
-
events: LoopEvent[];
|
|
153
|
-
metadata: Record<string, string>;
|
|
154
|
-
createdAt: string;
|
|
155
|
-
updatedAt: string;
|
|
156
|
-
receiptScope?: ReceiptScope;
|
|
157
|
-
receiptIntegrity?: ReceiptIntegritySummary;
|
|
158
|
-
routingEconomics?: RoutingEconomics;
|
|
159
|
-
}
|
|
160
|
-
export interface LoopRecordDraft {
|
|
161
|
-
loopId?: string;
|
|
162
|
-
workspaceId: string;
|
|
163
|
-
projectId: string;
|
|
164
|
-
teamId?: string;
|
|
165
|
-
status?: LoopStatus;
|
|
166
|
-
lifecycleState?: LoopLifecycleState;
|
|
167
|
-
task: LoopTask;
|
|
168
|
-
budget?: Partial<LoopBudget>;
|
|
169
|
-
cost?: Partial<LoopCost>;
|
|
170
|
-
artifacts?: LoopArtifact[];
|
|
171
|
-
attempts?: LoopAttempt[];
|
|
172
|
-
events?: LoopEvent[];
|
|
173
|
-
metadata?: Record<string, string>;
|
|
174
|
-
createdAt?: string;
|
|
175
|
-
updatedAt?: string;
|
|
176
|
-
receiptScope?: ReceiptScope;
|
|
177
|
-
receiptIntegrity?: ReceiptIntegritySummary;
|
|
178
|
-
}
|
|
179
|
-
export type { MartinErrorCategory, MartinOutputMode, MartinRunListFilters, MartinRunSelector } from "./operator.js";
|
|
180
|
-
export { MARTIN_ERROR_CATEGORIES } from "./operator.js";
|
|
181
|
-
export interface LoopEventDraft {
|
|
182
|
-
type: LoopEventType;
|
|
183
|
-
lifecycleState?: LoopLifecycleState;
|
|
184
|
-
payload: Record<string, unknown>;
|
|
185
|
-
timestamp?: string;
|
|
186
|
-
}
|
|
187
|
-
export type TelemetryEnvironment = "local" | "ci" | "staging" | "production";
|
|
188
|
-
export interface TelemetrySource {
|
|
189
|
-
runtimeVersion: string;
|
|
190
|
-
adapterId: string;
|
|
191
|
-
provider: string;
|
|
192
|
-
model: string;
|
|
193
|
-
}
|
|
194
|
-
export interface TelemetryEvent {
|
|
195
|
-
eventId: string;
|
|
196
|
-
loopId: string;
|
|
197
|
-
attemptId?: string;
|
|
198
|
-
type: LoopEventType;
|
|
199
|
-
lifecycleState: LoopLifecycleState;
|
|
200
|
-
timestamp: string;
|
|
201
|
-
sequence: number;
|
|
202
|
-
payload: Record<string, unknown>;
|
|
203
|
-
}
|
|
204
|
-
export interface TelemetryEventDraft {
|
|
205
|
-
loopId: string;
|
|
206
|
-
attemptId?: string;
|
|
207
|
-
type: LoopEventType;
|
|
208
|
-
lifecycleState: LoopLifecycleState;
|
|
209
|
-
timestamp?: string;
|
|
210
|
-
payload: Record<string, unknown>;
|
|
211
|
-
}
|
|
212
|
-
export interface TelemetryEnvelope {
|
|
213
|
-
schemaVersion: string;
|
|
214
|
-
envelopeId: string;
|
|
215
|
-
workspaceId: string;
|
|
216
|
-
projectId: string;
|
|
217
|
-
ingestKeyId: string;
|
|
218
|
-
environment: TelemetryEnvironment;
|
|
219
|
-
emittedAt: string;
|
|
220
|
-
sequence: number;
|
|
221
|
-
source: TelemetrySource;
|
|
222
|
-
events: TelemetryEvent[];
|
|
223
|
-
}
|
|
224
|
-
export interface TelemetryEnvelopeDraft {
|
|
225
|
-
schemaVersion?: string;
|
|
226
|
-
workspaceId: string;
|
|
227
|
-
projectId: string;
|
|
228
|
-
ingestKeyId: string;
|
|
229
|
-
environment: TelemetryEnvironment;
|
|
230
|
-
source: TelemetrySource;
|
|
231
|
-
events: TelemetryEventDraft[];
|
|
232
|
-
}
|
|
233
|
-
export interface TelemetryLoopSnapshot {
|
|
234
|
-
loopId: string;
|
|
235
|
-
status: LoopStatus;
|
|
236
|
-
lifecycleState: LoopLifecycleState;
|
|
237
|
-
cost: LoopCost;
|
|
238
|
-
}
|
|
239
|
-
export interface TelemetryBatch {
|
|
240
|
-
workspaceId: string;
|
|
241
|
-
projectId: string;
|
|
242
|
-
loops: TelemetryLoopSnapshot[];
|
|
243
|
-
}
|
|
244
|
-
export interface ValidationResult {
|
|
245
|
-
ok: boolean;
|
|
246
|
-
errors: string[];
|
|
247
|
-
}
|
|
248
|
-
export interface PortfolioSnapshot {
|
|
249
|
-
totalActualUsd: number;
|
|
250
|
-
totalAvoidedUsd: number;
|
|
251
|
-
totalTokensIn: number;
|
|
252
|
-
totalTokensOut: number;
|
|
253
|
-
activeLoops: number;
|
|
254
|
-
optimizedLoops: number;
|
|
255
|
-
failuresCaught: number;
|
|
256
|
-
averageExitSeconds: number;
|
|
257
|
-
}
|
|
258
|
-
export interface ContractOptions {
|
|
259
|
-
now?: string;
|
|
260
|
-
idFactory?: (prefix: string) => string;
|
|
261
|
-
}
|
|
262
|
-
export declare const DEFAULT_BUDGET: LoopBudget;
|
|
263
|
-
export declare const EMPTY_COST: LoopCost;
|
|
264
|
-
export declare function createLoopRecord(draft: LoopRecordDraft, options?: ContractOptions): LoopRecord;
|
|
265
|
-
export declare function appendLoopEvent(loop: LoopRecord, eventDraft: LoopEventDraft, options?: ContractOptions): LoopRecord;
|
|
266
|
-
export declare function validateTelemetryBatch(batch: TelemetryBatch): ValidationResult;
|
|
267
|
-
export declare function buildPortfolioSnapshot(loops: LoopRecord[]): PortfolioSnapshot;
|
|
268
|
-
export declare function createTelemetryEnvelope(draft: TelemetryEnvelopeDraft, options?: ContractOptions): TelemetryEnvelope;
|
|
269
|
-
export declare function validateTelemetryEnvelope(envelope: TelemetryEnvelope): ValidationResult;
|
|
270
|
-
export type PolicyPhase = "GATHER" | "ADMIT" | "PATCH" | "VERIFY" | "RECOVER" | "ESCALATE" | "ABORT" | "HANDOFF";
|
|
271
|
-
export interface EvidenceVector {
|
|
272
|
-
/** Count of compile/build errors in the last attempt output. */
|
|
273
|
-
compileErrors: number;
|
|
274
|
-
/** Count of TypeScript type errors. */
|
|
275
|
-
typeErrors: number;
|
|
276
|
-
/** Count of failing test cases. */
|
|
277
|
-
failingTests: number;
|
|
278
|
-
/** Verifier score 0.0–1.0 (1.0 = full pass). */
|
|
279
|
-
verifierScore: number;
|
|
280
|
-
/** Patch novelty 0.0–1.0 (0.0 = identical to previous attempt). */
|
|
281
|
-
diffNovelty: number;
|
|
282
|
-
/** Number of forbidden files touched by the last patch. */
|
|
283
|
-
forbiddenTouchedFileCount: number;
|
|
284
|
-
/** Count of unresolvable symbols/modules referenced in the patch. */
|
|
285
|
-
missingSymbolCount: number;
|
|
286
|
-
/** Actual USD cost divided by verifier score improvement. */
|
|
287
|
-
costPerProgressUnit: number;
|
|
288
|
-
/** How many times this failure surface has been retried. */
|
|
289
|
-
retryCountForSurface: number;
|
|
290
|
-
/** Safety risk score 0.0–1.0 from leash evaluation. */
|
|
291
|
-
safetyRiskScore: number;
|
|
292
|
-
}
|
|
293
|
-
export interface MachineState {
|
|
294
|
-
phase: PolicyPhase;
|
|
295
|
-
currentAttempt: number;
|
|
296
|
-
activeModel: string;
|
|
297
|
-
remainingBudgetUsd: number;
|
|
298
|
-
/** Retry counter per FailureClass surface. */
|
|
299
|
-
attemptCountersBySurface: Record<string, number>;
|
|
300
|
-
lastFailureSurface?: FailureClass;
|
|
301
|
-
lastVerifierScore: number;
|
|
302
|
-
openAlerts: string[];
|
|
303
|
-
policyHistory: Array<{
|
|
304
|
-
phase: PolicyPhase;
|
|
305
|
-
reason: string;
|
|
306
|
-
timestamp: string;
|
|
307
|
-
}>;
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Cost provenance label — every budget metric must carry this.
|
|
311
|
-
* Never conflate actual with estimated or unavailable.
|
|
312
|
-
*/
|
|
313
|
-
export type CostProvenance = "actual" | "estimated" | "unavailable";
|
|
314
|
-
/**
|
|
315
|
-
* Per-attempt budget preflight estimate produced before admission.
|
|
316
|
-
* Used to gate attempts before any tokens are spent.
|
|
317
|
-
*/
|
|
318
|
-
export interface BudgetPreflightEstimate {
|
|
319
|
-
estimatedPromptTokens: number;
|
|
320
|
-
estimatedToolOverheadTokens: number;
|
|
321
|
-
estimatedOutputTokensMax: number;
|
|
322
|
-
estimatedVerifierCostUsd: number;
|
|
323
|
-
estimatedAttemptCostUsd: number;
|
|
324
|
-
provenance: CostProvenance;
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Actual cost settlement written to the ledger after an attempt completes.
|
|
328
|
-
* Separates patch cost from verification cost.
|
|
329
|
-
*/
|
|
330
|
-
export interface BudgetSettlement {
|
|
331
|
-
runId: string;
|
|
332
|
-
attemptIndex: number;
|
|
333
|
-
patchCost: {
|
|
334
|
-
usd: number;
|
|
335
|
-
tokensIn: number;
|
|
336
|
-
tokensOut: number;
|
|
337
|
-
provenance: CostProvenance;
|
|
338
|
-
};
|
|
339
|
-
verificationCost: {
|
|
340
|
-
usd: number;
|
|
341
|
-
provenance: CostProvenance;
|
|
342
|
-
};
|
|
343
|
-
providerSettlement?: ProviderUsageSettlement;
|
|
344
|
-
totalActualUsd: number;
|
|
345
|
-
preflightEstimateUsd: number;
|
|
346
|
-
varianceUsd: number;
|
|
347
|
-
settledAt: string;
|
|
348
|
-
}
|
|
349
|
-
export type PatchDecision = "KEEP" | "DISCARD" | "ESCALATE" | "HANDOFF";
|
|
350
|
-
export type PatchDecisionReasonCode = "verifier_passed" | "verifier_regressed" | "grounding_failure" | "scope_violation" | "no_code_change" | "large_diff_no_improvement" | "low_novelty_no_progress" | "human_approval_required" | "safety_violation" | "verifier_not_improved";
|
|
351
|
-
export interface PatchScore {
|
|
352
|
-
score: number;
|
|
353
|
-
verifierScore: number;
|
|
354
|
-
verifierDelta: number;
|
|
355
|
-
groundingViolationCount: number;
|
|
356
|
-
scopeViolationCount: number;
|
|
357
|
-
safetyViolationCount: number;
|
|
358
|
-
changedFileCount: number;
|
|
359
|
-
diffRiskScore: number;
|
|
360
|
-
noveltyScore: number;
|
|
361
|
-
costUsd: number;
|
|
362
|
-
reasonCodes: PatchDecisionReasonCode[];
|
|
363
|
-
}
|
|
364
|
-
export interface PatchDecisionArtifact {
|
|
365
|
-
decision: PatchDecision;
|
|
366
|
-
summary: string;
|
|
367
|
-
reasonCodes: PatchDecisionReasonCode[];
|
|
368
|
-
}
|
|
369
|
-
export type RollbackBoundaryStrategy = "git_head_plus_snapshot" | "no_repo_root";
|
|
370
|
-
export interface RollbackFileSnapshot {
|
|
371
|
-
path: string;
|
|
372
|
-
existed: boolean;
|
|
373
|
-
encoding: "base64";
|
|
374
|
-
contentBase64?: string;
|
|
375
|
-
}
|
|
376
|
-
export interface RollbackBoundaryArtifact {
|
|
377
|
-
strategy: RollbackBoundaryStrategy;
|
|
378
|
-
capturedAt: string;
|
|
379
|
-
headRef?: string;
|
|
380
|
-
trackedDirtyFiles: string[];
|
|
381
|
-
untrackedFiles: string[];
|
|
382
|
-
snapshots: RollbackFileSnapshot[];
|
|
383
|
-
}
|
|
384
|
-
export type RollbackOutcomeStatus = "restored" | "not_required" | "failed" | "unavailable";
|
|
385
|
-
export interface RollbackOutcomeArtifact {
|
|
386
|
-
attempted: boolean;
|
|
387
|
-
status: RollbackOutcomeStatus;
|
|
388
|
-
restoredAt: string;
|
|
389
|
-
decision: PatchDecision;
|
|
390
|
-
before: {
|
|
391
|
-
trackedDirtyFiles: string[];
|
|
392
|
-
untrackedFiles: string[];
|
|
393
|
-
};
|
|
394
|
-
after: {
|
|
395
|
-
trackedDirtyFiles: string[];
|
|
396
|
-
untrackedFiles: string[];
|
|
397
|
-
};
|
|
398
|
-
restoredFiles: string[];
|
|
399
|
-
deletedFiles: string[];
|
|
400
|
-
error?: string;
|
|
401
|
-
}
|
|
402
|
-
export { createGovernanceSnapshot } from "./governance.js";
|
|
403
|
-
export type { DestructiveActionPolicy, GovernanceSnapshot, PolicyProfile, TelemetryDestination } from "./governance.js";
|
|
404
|
-
export { cloneExecutionPolicy } from "./execution-policy.js";
|
|
405
|
-
export type { ExecutionPolicy, ExecutionPolicyCompileInput, ExecutionPolicyConfigInput, ExecutionPolicyDefaults, ExecutionPolicyProvenanceEntry, ExecutionPolicyRequestInput, RoutingPolicy, RoutingMode } from "./execution-policy.js";
|
|
406
|
-
export { DEFAULT_ROUTING_POLICY } from "./execution-policy.js";
|
|
407
|
-
export { cloneContextGraphSnapshot } from "./context-graph.js";
|
|
408
|
-
export type { ContextGraphBuildOptions, ContextGraphEdge, ContextGraphHit, ContextGraphNode, ContextGraphNodeKind, ContextGraphSnapshot, ContextQuery } from "./context-graph.js";
|
|
409
|
-
export { cloneIdentityAttestation, cloneIdentityClaims, cloneIdentityToken } from "./identity.js";
|
|
410
|
-
export type { IdentityAttestation, IdentityClaims, IdentityToken } from "./identity.js";
|
|
411
|
-
export { cloneCircuitBreakDecision, cloneTrajectoryAssessment } from "./trajectory.js";
|
|
412
|
-
export type { CircuitBreakDecision, TrajectoryAssessment, TrajectorySignal } from "./trajectory.js";
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
export const FAILURE_CLASSES = [
|
|
2
|
-
"logic_error",
|
|
3
|
-
"hallucination",
|
|
4
|
-
"syntax_error",
|
|
5
|
-
"type_error",
|
|
6
|
-
"test_regression",
|
|
7
|
-
"scope_creep",
|
|
8
|
-
"no_progress",
|
|
9
|
-
"repo_grounding_failure",
|
|
10
|
-
"verification_failure",
|
|
11
|
-
"environment_mismatch",
|
|
12
|
-
"budget_pressure",
|
|
13
|
-
"safety_leash_blocked",
|
|
14
|
-
"sandbox_write_blocked",
|
|
15
|
-
];
|
|
16
|
-
export { MARTIN_ERROR_CATEGORIES } from "./operator.js";
|
|
17
|
-
export const DEFAULT_BUDGET = {
|
|
18
|
-
maxUsd: 25,
|
|
19
|
-
softLimitUsd: 15,
|
|
20
|
-
maxIterations: 8,
|
|
21
|
-
maxTokens: 80_000
|
|
22
|
-
};
|
|
23
|
-
export const EMPTY_COST = {
|
|
24
|
-
actualUsd: 0,
|
|
25
|
-
avoidedUsd: 0,
|
|
26
|
-
tokensIn: 0,
|
|
27
|
-
tokensOut: 0
|
|
28
|
-
};
|
|
29
|
-
export function createLoopRecord(draft, options = {}) {
|
|
30
|
-
const now = options.now ?? new Date().toISOString();
|
|
31
|
-
return {
|
|
32
|
-
loopId: draft.loopId ?? makeId("loop", options),
|
|
33
|
-
workspaceId: draft.workspaceId,
|
|
34
|
-
projectId: draft.projectId,
|
|
35
|
-
status: draft.status ?? "queued",
|
|
36
|
-
lifecycleState: draft.lifecycleState ?? "created",
|
|
37
|
-
task: draft.task,
|
|
38
|
-
budget: {
|
|
39
|
-
...DEFAULT_BUDGET,
|
|
40
|
-
...draft.budget
|
|
41
|
-
},
|
|
42
|
-
cost: {
|
|
43
|
-
...EMPTY_COST,
|
|
44
|
-
...draft.cost
|
|
45
|
-
},
|
|
46
|
-
artifacts: [...(draft.artifacts ?? [])],
|
|
47
|
-
attempts: [...(draft.attempts ?? [])],
|
|
48
|
-
events: [...(draft.events ?? [])],
|
|
49
|
-
metadata: {
|
|
50
|
-
...(draft.metadata ?? {})
|
|
51
|
-
},
|
|
52
|
-
createdAt: draft.createdAt ?? now,
|
|
53
|
-
updatedAt: draft.updatedAt ?? now,
|
|
54
|
-
...(draft.receiptScope ? { receiptScope: draft.receiptScope } : {}),
|
|
55
|
-
...(draft.receiptIntegrity ? { receiptIntegrity: draft.receiptIntegrity } : {}),
|
|
56
|
-
...(draft.teamId ? { teamId: draft.teamId } : {})
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
export function appendLoopEvent(loop, eventDraft, options = {}) {
|
|
60
|
-
const timestamp = eventDraft.timestamp ?? options.now ?? new Date().toISOString();
|
|
61
|
-
const lifecycleState = eventDraft.lifecycleState ?? loop.lifecycleState;
|
|
62
|
-
const event = {
|
|
63
|
-
eventId: makeId("evt", options),
|
|
64
|
-
type: eventDraft.type,
|
|
65
|
-
timestamp,
|
|
66
|
-
lifecycleState,
|
|
67
|
-
payload: eventDraft.payload
|
|
68
|
-
};
|
|
69
|
-
return {
|
|
70
|
-
...loop,
|
|
71
|
-
lifecycleState,
|
|
72
|
-
status: nextStatus(loop.status, event.type),
|
|
73
|
-
events: [...loop.events, event],
|
|
74
|
-
updatedAt: timestamp
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
export function validateTelemetryBatch(batch) {
|
|
78
|
-
const errors = [];
|
|
79
|
-
if (!hasText(batch.workspaceId)) {
|
|
80
|
-
errors.push("workspaceId is required");
|
|
81
|
-
}
|
|
82
|
-
if (!hasText(batch.projectId)) {
|
|
83
|
-
errors.push("projectId is required");
|
|
84
|
-
}
|
|
85
|
-
batch.loops.forEach((loop, index) => {
|
|
86
|
-
if (!hasText(loop.loopId)) {
|
|
87
|
-
errors.push(`loop[${index}].loopId is required`);
|
|
88
|
-
}
|
|
89
|
-
if (loop.cost.actualUsd < 0) {
|
|
90
|
-
errors.push(`loop[${index}].cost.actualUsd must be greater than or equal to 0`);
|
|
91
|
-
}
|
|
92
|
-
if (loop.cost.avoidedUsd < 0) {
|
|
93
|
-
errors.push(`loop[${index}].cost.avoidedUsd must be greater than or equal to 0`);
|
|
94
|
-
}
|
|
95
|
-
if (loop.cost.tokensIn < 0) {
|
|
96
|
-
errors.push(`loop[${index}].cost.tokensIn must be greater than or equal to 0`);
|
|
97
|
-
}
|
|
98
|
-
if (loop.cost.tokensOut < 0) {
|
|
99
|
-
errors.push(`loop[${index}].cost.tokensOut must be greater than or equal to 0`);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
return {
|
|
103
|
-
ok: errors.length === 0,
|
|
104
|
-
errors
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
export function buildPortfolioSnapshot(loops) {
|
|
108
|
-
const exitedLoops = loops.filter((loop) => ["completed", "budget_exit", "diminishing_returns", "stuck_exit", "human_escalation"].includes(loop.lifecycleState));
|
|
109
|
-
const totalExitSeconds = exitedLoops.reduce((total, loop) => {
|
|
110
|
-
const created = Date.parse(loop.createdAt);
|
|
111
|
-
const updated = Date.parse(loop.updatedAt);
|
|
112
|
-
if (Number.isNaN(created) || Number.isNaN(updated) || updated < created) {
|
|
113
|
-
return total;
|
|
114
|
-
}
|
|
115
|
-
return total + Math.round((updated - created) / 1000);
|
|
116
|
-
}, 0);
|
|
117
|
-
return {
|
|
118
|
-
totalActualUsd: loops.reduce((total, loop) => total + loop.cost.actualUsd, 0),
|
|
119
|
-
totalAvoidedUsd: loops.reduce((total, loop) => total + loop.cost.avoidedUsd, 0),
|
|
120
|
-
totalTokensIn: loops.reduce((total, loop) => total + loop.cost.tokensIn, 0),
|
|
121
|
-
totalTokensOut: loops.reduce((total, loop) => total + loop.cost.tokensOut, 0),
|
|
122
|
-
activeLoops: loops.filter((loop) => ["queued", "running", "verifying"].includes(loop.status))
|
|
123
|
-
.length,
|
|
124
|
-
optimizedLoops: loops.filter((loop) => loop.cost.avoidedUsd > loop.cost.actualUsd).length,
|
|
125
|
-
failuresCaught: loops.reduce((total, loop) => total + loop.events.filter((event) => event.type === "failure.classified").length, 0),
|
|
126
|
-
averageExitSeconds: exitedLoops.length === 0 ? 0 : Math.round(totalExitSeconds / exitedLoops.length)
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
export function createTelemetryEnvelope(draft, options = {}) {
|
|
130
|
-
const emittedAt = options.now ?? new Date().toISOString();
|
|
131
|
-
const usedIds = new Set();
|
|
132
|
-
return {
|
|
133
|
-
schemaVersion: draft.schemaVersion ?? "martin.telemetry.v1",
|
|
134
|
-
envelopeId: makeId("env", options),
|
|
135
|
-
workspaceId: draft.workspaceId,
|
|
136
|
-
projectId: draft.projectId,
|
|
137
|
-
ingestKeyId: draft.ingestKeyId,
|
|
138
|
-
environment: draft.environment,
|
|
139
|
-
emittedAt,
|
|
140
|
-
sequence: draft.events.length,
|
|
141
|
-
source: draft.source,
|
|
142
|
-
events: draft.events.map((event, index) => {
|
|
143
|
-
const baseId = makeId("evt", options);
|
|
144
|
-
const eventId = usedIds.has(baseId) ? `${baseId}_${index + 1}` : baseId;
|
|
145
|
-
usedIds.add(eventId);
|
|
146
|
-
return {
|
|
147
|
-
eventId,
|
|
148
|
-
loopId: event.loopId,
|
|
149
|
-
type: event.type,
|
|
150
|
-
lifecycleState: event.lifecycleState,
|
|
151
|
-
timestamp: event.timestamp ?? emittedAt,
|
|
152
|
-
sequence: index + 1,
|
|
153
|
-
payload: event.payload,
|
|
154
|
-
...(event.attemptId ? { attemptId: event.attemptId } : {})
|
|
155
|
-
};
|
|
156
|
-
})
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
export function validateTelemetryEnvelope(envelope) {
|
|
160
|
-
const errors = [];
|
|
161
|
-
if (!hasText(envelope.schemaVersion)) {
|
|
162
|
-
errors.push("schemaVersion is required");
|
|
163
|
-
}
|
|
164
|
-
if (!hasText(envelope.workspaceId)) {
|
|
165
|
-
errors.push("workspaceId is required");
|
|
166
|
-
}
|
|
167
|
-
if (!hasText(envelope.projectId)) {
|
|
168
|
-
errors.push("projectId is required");
|
|
169
|
-
}
|
|
170
|
-
if (!hasText(envelope.ingestKeyId)) {
|
|
171
|
-
errors.push("ingestKeyId is required");
|
|
172
|
-
}
|
|
173
|
-
if (envelope.sequence !== envelope.events.length) {
|
|
174
|
-
errors.push("sequence must equal the number of events in the envelope");
|
|
175
|
-
}
|
|
176
|
-
const sequenceLooksValid = envelope.events.every((event, index) => event.sequence === index + 1);
|
|
177
|
-
if (!sequenceLooksValid) {
|
|
178
|
-
errors.push("events must use a strictly increasing sequence starting at 1");
|
|
179
|
-
}
|
|
180
|
-
envelope.events.forEach((event, index) => {
|
|
181
|
-
if (!hasText(event.eventId)) {
|
|
182
|
-
errors.push(`events[${index}].eventId is required`);
|
|
183
|
-
}
|
|
184
|
-
if (!hasText(event.loopId)) {
|
|
185
|
-
errors.push(`events[${index}].loopId is required`);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
return {
|
|
189
|
-
ok: errors.length === 0,
|
|
190
|
-
errors
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
function makeId(prefix, options) {
|
|
194
|
-
if (options.idFactory) {
|
|
195
|
-
return options.idFactory(prefix);
|
|
196
|
-
}
|
|
197
|
-
const entropy = Math.random().toString(36).slice(2, 10);
|
|
198
|
-
return `${prefix}_${entropy}`;
|
|
199
|
-
}
|
|
200
|
-
function nextStatus(current, eventType) {
|
|
201
|
-
switch (eventType) {
|
|
202
|
-
case "run.started":
|
|
203
|
-
case "attempt.started":
|
|
204
|
-
case "attempt.completed":
|
|
205
|
-
case "failure.classified":
|
|
206
|
-
case "intervention.selected":
|
|
207
|
-
case "budget.updated":
|
|
208
|
-
return "running";
|
|
209
|
-
case "verification.completed":
|
|
210
|
-
return "verifying";
|
|
211
|
-
case "run.completed":
|
|
212
|
-
return current === "failed" ? "failed" : "completed";
|
|
213
|
-
default:
|
|
214
|
-
return current;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
function hasText(value) {
|
|
218
|
-
return typeof value === "string" && value.trim().length > 0;
|
|
219
|
-
}
|
|
220
|
-
export { createGovernanceSnapshot } from "./governance.js";
|
|
221
|
-
export { cloneExecutionPolicy } from "./execution-policy.js";
|
|
222
|
-
export { DEFAULT_ROUTING_POLICY } from "./execution-policy.js";
|
|
223
|
-
export { cloneContextGraphSnapshot } from "./context-graph.js";
|
|
224
|
-
export { cloneIdentityAttestation, cloneIdentityClaims, cloneIdentityToken } from "./identity.js";
|
|
225
|
-
export { cloneCircuitBreakDecision, cloneTrajectoryAssessment } from "./trajectory.js";
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export declare const MARTIN_ERROR_CATEGORIES: readonly ["invalid_input", "environment", "auth", "not_found", "store_unreadable", "verification_failed", "policy_blocked", "budget_exit", "transient"];
|
|
2
|
-
export type MartinErrorCategory = (typeof MARTIN_ERROR_CATEGORIES)[number];
|
|
3
|
-
export type MartinOutputMode = "human" | "json" | "quiet";
|
|
4
|
-
export interface MartinRunSelector {
|
|
5
|
-
runsDir?: string;
|
|
6
|
-
file?: string;
|
|
7
|
-
loopId?: string;
|
|
8
|
-
latest?: boolean;
|
|
9
|
-
attemptIndex?: number;
|
|
10
|
-
}
|
|
11
|
-
export interface MartinRunListFilters {
|
|
12
|
-
runsDir?: string;
|
|
13
|
-
limit?: number;
|
|
14
|
-
status?: string;
|
|
15
|
-
lifecycleState?: string;
|
|
16
|
-
adapterId?: string;
|
|
17
|
-
model?: string;
|
|
18
|
-
updatedAfter?: string;
|
|
19
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { InterventionType } from "./index.js";
|
|
2
|
-
export type TrajectoryStatus = "healthy" | "watch" | "drifting" | "stalled";
|
|
3
|
-
export type TrajectoryConfidence = "low" | "medium" | "high";
|
|
4
|
-
export type TrajectorySignalCode = "failure_oscillation" | "attempt_repetition" | "verification_stall" | "objective_drift";
|
|
5
|
-
export interface TrajectorySignal {
|
|
6
|
-
code: TrajectorySignalCode;
|
|
7
|
-
severity: "low" | "medium" | "high";
|
|
8
|
-
summary: string;
|
|
9
|
-
attemptIndexes: number[];
|
|
10
|
-
matchedTerms?: string[];
|
|
11
|
-
}
|
|
12
|
-
export interface TrajectoryAssessment {
|
|
13
|
-
status: TrajectoryStatus;
|
|
14
|
-
confidence: TrajectoryConfidence;
|
|
15
|
-
summary: string;
|
|
16
|
-
signals: TrajectorySignal[];
|
|
17
|
-
recommendedIntervention?: InterventionType;
|
|
18
|
-
}
|
|
19
|
-
export interface CircuitBreakDecision {
|
|
20
|
-
shouldStop: boolean;
|
|
21
|
-
reason: string;
|
|
22
|
-
assessment: TrajectoryAssessment;
|
|
23
|
-
recommendedIntervention?: InterventionType;
|
|
24
|
-
}
|
|
25
|
-
export declare function cloneTrajectoryAssessment(assessment: TrajectoryAssessment): TrajectoryAssessment;
|
|
26
|
-
export declare function cloneCircuitBreakDecision(decision: CircuitBreakDecision): CircuitBreakDecision;
|