martin-loop 0.1.4 → 1.3.0

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 (286) hide show
  1. package/CODE_OF_CONDUCT.md +32 -0
  2. package/README.md +172 -227
  3. package/demo/seeded-workspace/README.md +35 -0
  4. package/demo/seeded-workspace/TASKS.md +29 -0
  5. package/demo/seeded-workspace/martin.config.yaml +11 -0
  6. package/demo/seeded-workspace/package.json +8 -0
  7. package/demo/seeded-workspace/src/invoice-summary.js +11 -0
  8. package/demo/seeded-workspace/test/invoice-summary.test.js +20 -0
  9. package/dist/bin/martin-loop.js +0 -0
  10. package/dist/vendor/adapters/claude-cli.d.ts +19 -4
  11. package/dist/vendor/adapters/claude-cli.js +55 -24
  12. package/dist/vendor/adapters/cli-bridge.d.ts +1 -0
  13. package/dist/vendor/adapters/cli-bridge.js +154 -28
  14. package/dist/vendor/adapters/counter.d.ts +1 -0
  15. package/dist/vendor/adapters/counter.js +4 -0
  16. package/dist/vendor/adapters/git-baseline.d.ts +50 -0
  17. package/dist/vendor/adapters/git-baseline.js +233 -0
  18. package/dist/vendor/adapters/index.d.ts +1 -0
  19. package/dist/vendor/adapters/index.js +1 -0
  20. package/dist/vendor/adapters/openrouter-adapter.d.ts +15 -0
  21. package/dist/vendor/adapters/openrouter-adapter.js +302 -0
  22. package/dist/vendor/adapters/usage.d.ts +48 -0
  23. package/dist/vendor/adapters/usage.js +66 -0
  24. package/dist/vendor/adapters/verifier-only.d.ts +7 -0
  25. package/dist/vendor/adapters/verifier-only.js +57 -0
  26. package/dist/vendor/cli/bin/exit.d.ts +12 -0
  27. package/dist/vendor/cli/bin/exit.js +28 -0
  28. package/dist/vendor/cli/commands/analyze.d.ts +5 -0
  29. package/dist/vendor/cli/commands/analyze.js +58 -0
  30. package/dist/vendor/cli/commands/audit-log-verify.d.ts +34 -0
  31. package/dist/vendor/cli/commands/audit-log-verify.js +99 -0
  32. package/dist/vendor/cli/commands/audit.d.ts +8 -0
  33. package/dist/vendor/cli/commands/audit.js +199 -0
  34. package/dist/vendor/cli/commands/corpus.d.ts +5 -0
  35. package/dist/vendor/cli/commands/corpus.js +60 -0
  36. package/dist/vendor/cli/commands/doctor.d.ts +8 -0
  37. package/dist/vendor/cli/commands/doctor.js +219 -0
  38. package/dist/vendor/cli/commands/explain.d.ts +17 -0
  39. package/dist/vendor/cli/commands/explain.js +176 -0
  40. package/dist/vendor/cli/commands/export.d.ts +5 -0
  41. package/dist/vendor/cli/commands/export.js +60 -0
  42. package/dist/vendor/cli/commands/governance.d.ts +8 -0
  43. package/dist/vendor/cli/commands/governance.js +95 -0
  44. package/dist/vendor/cli/commands/improve.d.ts +18 -0
  45. package/dist/vendor/cli/commands/improve.js +396 -0
  46. package/dist/vendor/cli/commands/init.d.ts +8 -0
  47. package/dist/vendor/cli/commands/init.js +281 -0
  48. package/dist/vendor/cli/commands/migration.d.ts +8 -0
  49. package/dist/vendor/cli/commands/migration.js +67 -0
  50. package/dist/vendor/cli/commands/prior.d.ts +23 -0
  51. package/dist/vendor/cli/commands/prior.js +145 -0
  52. package/dist/vendor/cli/commands/resume.d.ts +21 -0
  53. package/dist/vendor/cli/commands/resume.js +73 -0
  54. package/dist/vendor/cli/commands/verify.d.ts +6 -0
  55. package/dist/vendor/cli/commands/verify.js +43 -0
  56. package/dist/vendor/cli/index.d.ts +6 -1
  57. package/dist/vendor/cli/index.js +124 -7
  58. package/dist/vendor/cli/research/public-corpus.d.ts +43 -0
  59. package/dist/vendor/cli/research/public-corpus.js +151 -0
  60. package/dist/vendor/cli/ui/error-card.d.ts +38 -0
  61. package/dist/vendor/cli/ui/error-card.js +103 -0
  62. package/dist/vendor/cli/ui/mission-brief.d.ts +41 -0
  63. package/dist/vendor/cli/ui/mission-brief.js +173 -0
  64. package/dist/vendor/cli/ui/summary-card.d.ts +34 -0
  65. package/dist/vendor/cli/ui/summary-card.js +102 -0
  66. package/dist/vendor/contracts/audit.d.ts +46 -0
  67. package/dist/vendor/contracts/audit.js +360 -0
  68. package/dist/vendor/contracts/index.d.ts +3 -1
  69. package/dist/vendor/contracts/post-phase15.d.ts +240 -0
  70. package/dist/vendor/contracts/post-phase15.js +166 -0
  71. package/dist/vendor/core/agent/mandates.d.ts +46 -0
  72. package/dist/vendor/core/agent/mandates.js +178 -0
  73. package/dist/vendor/core/agent/receipts.d.ts +38 -0
  74. package/dist/vendor/core/agent/receipts.js +131 -0
  75. package/dist/vendor/core/agent/signing.d.ts +17 -0
  76. package/dist/vendor/core/agent/signing.js +91 -0
  77. package/dist/vendor/core/attestation/sign.d.ts +25 -0
  78. package/dist/vendor/core/attestation/sign.js +216 -0
  79. package/dist/vendor/core/autonomy/autonomous-promotion.d.ts +120 -0
  80. package/dist/vendor/core/autonomy/autonomous-promotion.js +346 -0
  81. package/dist/vendor/core/autonomy/envelope-v2.d.ts +29 -0
  82. package/dist/vendor/core/autonomy/envelope-v2.js +60 -0
  83. package/dist/vendor/core/autonomy/envelope.d.ts +17 -0
  84. package/dist/vendor/core/autonomy/envelope.js +27 -0
  85. package/dist/vendor/core/autonomy/escalation-ledger.d.ts +20 -0
  86. package/dist/vendor/core/autonomy/escalation-ledger.js +18 -0
  87. package/dist/vendor/core/autonomy/resume.d.ts +15 -0
  88. package/dist/vendor/core/autonomy/resume.js +23 -0
  89. package/dist/vendor/core/circuit/circuit-breaker.d.ts +60 -0
  90. package/dist/vendor/core/circuit/circuit-breaker.js +143 -0
  91. package/dist/vendor/core/compiler.d.ts +2 -0
  92. package/dist/vendor/core/compiler.js +10 -4
  93. package/dist/vendor/core/context-distillation.d.ts +3 -0
  94. package/dist/vendor/core/context-distillation.js +44 -0
  95. package/dist/vendor/core/context-flow/compile-context.d.ts +8 -0
  96. package/dist/vendor/core/context-flow/compile-context.js +111 -0
  97. package/dist/vendor/core/context-flow/entities.d.ts +2 -0
  98. package/dist/vendor/core/context-flow/entities.js +44 -0
  99. package/dist/vendor/core/context-flow/evaluate-policy.d.ts +2 -0
  100. package/dist/vendor/core/context-flow/evaluate-policy.js +42 -0
  101. package/dist/vendor/core/context-flow/index.d.ts +11 -0
  102. package/dist/vendor/core/context-flow/index.js +24 -0
  103. package/dist/vendor/core/context-flow/labels.d.ts +3 -0
  104. package/dist/vendor/core/context-flow/labels.js +17 -0
  105. package/dist/vendor/core/context-flow/normalizer.d.ts +9 -0
  106. package/dist/vendor/core/context-flow/normalizer.js +69 -0
  107. package/dist/vendor/core/context-flow/profiles.d.ts +33 -0
  108. package/dist/vendor/core/context-flow/profiles.js +36 -0
  109. package/dist/vendor/core/context-flow/redaction.d.ts +1 -0
  110. package/dist/vendor/core/context-flow/redaction.js +6 -0
  111. package/dist/vendor/core/context-flow/sensitivity.d.ts +2 -0
  112. package/dist/vendor/core/context-flow/sensitivity.js +27 -0
  113. package/dist/vendor/core/context-flow/sync-preview.d.ts +2 -0
  114. package/dist/vendor/core/context-flow/sync-preview.js +22 -0
  115. package/dist/vendor/core/context-flow/token-estimator.d.ts +3 -0
  116. package/dist/vendor/core/context-flow/token-estimator.js +13 -0
  117. package/dist/vendor/core/context-flow/types.d.ts +91 -0
  118. package/dist/vendor/core/context-flow/types.js +2 -0
  119. package/dist/vendor/core/context-integrity.d.ts +26 -0
  120. package/dist/vendor/core/context-integrity.js +56 -0
  121. package/dist/vendor/core/context-utility.d.ts +47 -0
  122. package/dist/vendor/core/context-utility.js +405 -0
  123. package/dist/vendor/core/cost/pipeline.d.ts +92 -0
  124. package/dist/vendor/core/cost/pipeline.js +141 -0
  125. package/dist/vendor/core/cost/tagged-cost.d.ts +27 -0
  126. package/dist/vendor/core/cost/tagged-cost.js +55 -0
  127. package/dist/vendor/core/cost-governor.d.ts +2 -0
  128. package/dist/vendor/core/cost-governor.js +50 -0
  129. package/dist/vendor/core/cve/cve-check.d.ts +80 -0
  130. package/dist/vendor/core/cve/cve-check.js +172 -0
  131. package/dist/vendor/core/digital-twin/index.d.ts +27 -0
  132. package/dist/vendor/core/digital-twin/index.js +90 -0
  133. package/dist/vendor/core/drift/drift-graph.d.ts +47 -0
  134. package/dist/vendor/core/drift/drift-graph.js +100 -0
  135. package/dist/vendor/core/drift/objective-lock.d.ts +69 -0
  136. package/dist/vendor/core/drift/objective-lock.js +88 -0
  137. package/dist/vendor/core/drift/scope.d.ts +46 -0
  138. package/dist/vendor/core/drift/scope.js +102 -0
  139. package/dist/vendor/core/drift/signature-lock.d.ts +48 -0
  140. package/dist/vendor/core/drift/signature-lock.js +202 -0
  141. package/dist/vendor/core/drift/stale-proof-gate.d.ts +21 -0
  142. package/dist/vendor/core/drift/stale-proof-gate.js +19 -0
  143. package/dist/vendor/core/eval/known-bad-world-runner.d.ts +24 -0
  144. package/dist/vendor/core/eval/known-bad-world-runner.js +256 -0
  145. package/dist/vendor/core/evidence/claim-audit.d.ts +18 -0
  146. package/dist/vendor/core/evidence/claim-audit.js +89 -0
  147. package/dist/vendor/core/exit-intelligence.d.ts +2 -0
  148. package/dist/vendor/core/exit-intelligence.js +58 -0
  149. package/dist/vendor/core/explain/formatter.d.ts +42 -0
  150. package/dist/vendor/core/explain/formatter.js +171 -0
  151. package/dist/vendor/core/explain/timeline.d.ts +29 -0
  152. package/dist/vendor/core/explain/timeline.js +213 -0
  153. package/dist/vendor/core/failure-taxonomy.d.ts +2 -0
  154. package/dist/vendor/core/failure-taxonomy.js +76 -0
  155. package/dist/vendor/core/gateway/index.d.ts +10 -0
  156. package/dist/vendor/core/gateway/index.js +12 -0
  157. package/dist/vendor/core/gateway/registry.d.ts +40 -0
  158. package/dist/vendor/core/gateway/registry.js +97 -0
  159. package/dist/vendor/core/gateway/transport.d.ts +31 -0
  160. package/dist/vendor/core/gateway/transport.js +82 -0
  161. package/dist/vendor/core/gateway/vault.d.ts +19 -0
  162. package/dist/vendor/core/gateway/vault.js +29 -0
  163. package/dist/vendor/core/graph/adapters.d.ts +43 -0
  164. package/dist/vendor/core/graph/adapters.js +91 -0
  165. package/dist/vendor/core/graph/hotspots.d.ts +22 -0
  166. package/dist/vendor/core/graph/hotspots.js +30 -0
  167. package/dist/vendor/core/graph/index.d.ts +1 -0
  168. package/dist/vendor/core/graph/index.js +2 -0
  169. package/dist/vendor/core/honey/honey-tokens.d.ts +32 -0
  170. package/dist/vendor/core/honey/honey-tokens.js +44 -0
  171. package/dist/vendor/core/index.d.ts +7 -4
  172. package/dist/vendor/core/index.js +222 -64
  173. package/dist/vendor/core/learning/bayesian-update.d.ts +31 -0
  174. package/dist/vendor/core/learning/bayesian-update.js +60 -0
  175. package/dist/vendor/core/learning/prior-sets.d.ts +42 -0
  176. package/dist/vendor/core/learning/prior-sets.js +111 -0
  177. package/dist/vendor/core/learning/promotion-gate.d.ts +17 -0
  178. package/dist/vendor/core/learning/promotion-gate.js +23 -0
  179. package/dist/vendor/core/leash/blast-radius.d.ts +42 -0
  180. package/dist/vendor/core/leash/blast-radius.js +156 -0
  181. package/dist/vendor/core/leash/policy-leash.d.ts +31 -0
  182. package/dist/vendor/core/leash/policy-leash.js +117 -0
  183. package/dist/vendor/core/memo/memo.d.ts +63 -0
  184. package/dist/vendor/core/memo/memo.js +97 -0
  185. package/dist/vendor/core/memory/learning-pipeline.d.ts +154 -0
  186. package/dist/vendor/core/memory/learning-pipeline.js +391 -0
  187. package/dist/vendor/core/memory/palace.d.ts +84 -0
  188. package/dist/vendor/core/memory/palace.js +379 -0
  189. package/dist/vendor/core/merge/ast-merge.d.ts +22 -0
  190. package/dist/vendor/core/merge/ast-merge.js +350 -0
  191. package/dist/vendor/core/merge/text-merge.d.ts +12 -0
  192. package/dist/vendor/core/merge/text-merge.js +182 -0
  193. package/dist/vendor/core/otel/tracer.d.ts +45 -0
  194. package/dist/vendor/core/otel/tracer.js +116 -0
  195. package/dist/vendor/core/parallel/parallel-attempts.d.ts +28 -0
  196. package/dist/vendor/core/parallel/parallel-attempts.js +41 -0
  197. package/dist/vendor/core/parallel/scorer.d.ts +24 -0
  198. package/dist/vendor/core/parallel/scorer.js +65 -0
  199. package/dist/vendor/core/pattern-detection.d.ts +64 -0
  200. package/dist/vendor/core/pattern-detection.js +108 -0
  201. package/dist/vendor/core/persistence/checkpoint.d.ts +44 -0
  202. package/dist/vendor/core/persistence/checkpoint.js +156 -0
  203. package/dist/vendor/core/persistence/cleanup.d.ts +22 -0
  204. package/dist/vendor/core/persistence/cleanup.js +131 -0
  205. package/dist/vendor/core/persistence/index.d.ts +2 -0
  206. package/dist/vendor/core/persistence/index.js +1 -0
  207. package/dist/vendor/core/persistence/runs-reader.d.ts +52 -0
  208. package/dist/vendor/core/persistence/runs-reader.js +84 -0
  209. package/dist/vendor/core/persistence/store.d.ts +6 -1
  210. package/dist/vendor/core/persistence/store.js +5 -0
  211. package/dist/vendor/core/policy/file-touch-quota.d.ts +60 -0
  212. package/dist/vendor/core/policy/file-touch-quota.js +105 -0
  213. package/dist/vendor/core/policy/policy-loader.d.ts +30 -0
  214. package/dist/vendor/core/policy/policy-loader.js +170 -0
  215. package/dist/vendor/core/policy/policy-schema.d.ts +55 -0
  216. package/dist/vendor/core/policy/policy-schema.js +78 -0
  217. package/dist/vendor/core/policy.d.ts +6 -0
  218. package/dist/vendor/core/probe/probe.d.ts +49 -0
  219. package/dist/vendor/core/probe/probe.js +115 -0
  220. package/dist/vendor/core/proof/patch-proof.d.ts +58 -0
  221. package/dist/vendor/core/proof/patch-proof.js +84 -0
  222. package/dist/vendor/core/proof/semantic-probe.d.ts +25 -0
  223. package/dist/vendor/core/proof/semantic-probe.js +82 -0
  224. package/dist/vendor/core/recovery/failure-mode-runner.d.ts +29 -0
  225. package/dist/vendor/core/recovery/failure-mode-runner.js +39 -0
  226. package/dist/vendor/core/red-blue/red-phase.d.ts +64 -0
  227. package/dist/vendor/core/red-blue/red-phase.js +141 -0
  228. package/dist/vendor/core/red-blue/risk-tiers.d.ts +22 -0
  229. package/dist/vendor/core/red-blue/risk-tiers.js +33 -0
  230. package/dist/vendor/core/replay/replay.d.ts +85 -0
  231. package/dist/vendor/core/replay/replay.js +109 -0
  232. package/dist/vendor/core/router/engine.d.ts +54 -0
  233. package/dist/vendor/core/router/engine.js +131 -0
  234. package/dist/vendor/core/router/index.d.ts +1 -0
  235. package/dist/vendor/core/router/index.js +2 -0
  236. package/dist/vendor/core/router/trust-calibration.d.ts +57 -0
  237. package/dist/vendor/core/router/trust-calibration.js +127 -0
  238. package/dist/vendor/core/run-martin.d.ts +2 -0
  239. package/dist/vendor/core/run-martin.js +287 -0
  240. package/dist/vendor/core/security/cve-scanner.d.ts +62 -0
  241. package/dist/vendor/core/security/cve-scanner.js +178 -0
  242. package/dist/vendor/core/sentinel/efficiency-sentinel.d.ts +29 -0
  243. package/dist/vendor/core/sentinel/efficiency-sentinel.js +30 -0
  244. package/dist/vendor/core/sentinel/progress-guard.d.ts +35 -0
  245. package/dist/vendor/core/sentinel/progress-guard.js +46 -0
  246. package/dist/vendor/core/siem/siem-emitter.d.ts +49 -0
  247. package/dist/vendor/core/siem/siem-emitter.js +157 -0
  248. package/dist/vendor/core/strategy/attempt-brief.d.ts +22 -0
  249. package/dist/vendor/core/strategy/attempt-brief.js +89 -0
  250. package/dist/vendor/core/summarize/diff-summary.d.ts +35 -0
  251. package/dist/vendor/core/summarize/diff-summary.js +204 -0
  252. package/dist/vendor/core/surface-signals.d.ts +21 -0
  253. package/dist/vendor/core/surface-signals.js +139 -0
  254. package/dist/vendor/core/truth/truth-wall.d.ts +51 -0
  255. package/dist/vendor/core/truth/truth-wall.js +69 -0
  256. package/dist/vendor/core/truth-spine.d.ts +26 -0
  257. package/dist/vendor/core/truth-spine.js +62 -0
  258. package/dist/vendor/core/types.d.ts +115 -0
  259. package/dist/vendor/core/types.js +2 -0
  260. package/dist/vendor/core/verification/tiered-verify.d.ts +17 -0
  261. package/dist/vendor/core/verification/tiered-verify.js +29 -0
  262. package/dist/vendor/core/verifier-pyramid.d.ts +32 -0
  263. package/dist/vendor/core/verifier-pyramid.js +111 -0
  264. package/dist/vendor/core/workflow-artifacts.d.ts +99 -0
  265. package/dist/vendor/core/workflow-artifacts.js +668 -0
  266. package/dist/vendor/core/wrap/supervised-run.d.ts +96 -0
  267. package/dist/vendor/core/wrap/supervised-run.js +178 -0
  268. package/docs/assets/cli-animated.svg +139 -0
  269. package/docs/assets/cli-static.svg +34 -0
  270. package/docs/assets/github-hero-v2.svg +23 -0
  271. package/docs/assets/martin-raplph.png.jpg +0 -0
  272. package/docs/assets/martinloop-logo.png +0 -0
  273. package/docs/assets/nvidia-inception-program-light.png +0 -0
  274. package/docs/assets/nvidia-inception-program.png +0 -0
  275. package/docs/assets/phase3c-sidesidebyside-demo.html +228 -0
  276. package/docs/assets/side-by-side.svg +134 -0
  277. package/docs/oss/CLAUDE-CODE-WALKTHROUGH.md +142 -0
  278. package/docs/oss/EXAMPLES.md +9 -1
  279. package/docs/oss/OSS-BOUNDARY-REPORT.json +109 -113
  280. package/docs/oss/OSS-BOUNDARY-REPORT.md +48 -48
  281. package/docs/oss/QUICKSTART.md +39 -4
  282. package/docs/oss/RALPH-LOOP-SAFETY.md +113 -0
  283. package/docs/oss/README.md +7 -4
  284. package/docs/oss/RELEASE-SURFACE-REPORT.json +46 -45
  285. package/docs/oss/RELEASE-SURFACE-REPORT.md +36 -35
  286. package/package.json +129 -49
@@ -0,0 +1,115 @@
1
+ import type { FailureClass, InterventionType, LoopArtifact, LoopAttempt, LoopBudget, LoopCost, LoopLifecycleState, LoopRecord, LoopTask } from "../contracts/index.js";
2
+ export type AdapterExecutionStatus = "completed" | "failed" | "stalled";
3
+ export interface DistillContextOptions {
4
+ maxRecentAttempts?: number;
5
+ }
6
+ export interface DistilledAttempt {
7
+ attemptId: string;
8
+ index: number;
9
+ summary: string;
10
+ failureClass?: FailureClass;
11
+ intervention?: InterventionType;
12
+ }
13
+ export interface DistilledContext {
14
+ taskTitle: string;
15
+ objective: string;
16
+ repoRoot?: string;
17
+ verificationPlan: string[];
18
+ recentAttempts: DistilledAttempt[];
19
+ constraints: {
20
+ remainingBudgetUsd: number;
21
+ remainingIterations: number;
22
+ remainingTokens: number;
23
+ };
24
+ focus: string;
25
+ }
26
+ export interface CostGovernorInput {
27
+ budget: LoopBudget;
28
+ cost: LoopCost;
29
+ attemptsUsed: number;
30
+ projectedUsage?: Partial<Pick<LoopCost, "actualUsd" | "tokensIn" | "tokensOut">>;
31
+ }
32
+ export interface CostGovernorState {
33
+ pressure: "healthy" | "soft_limit" | "hard_limit";
34
+ shouldStop: boolean;
35
+ remainingBudgetUsd: number;
36
+ remainingIterations: number;
37
+ remainingTokens: number;
38
+ recommendedIntervention?: InterventionType;
39
+ }
40
+ export interface MartinAdapterRequest {
41
+ loopId: string;
42
+ workspaceId: string;
43
+ projectId: string;
44
+ teamId?: string;
45
+ attemptIndex: number;
46
+ task: LoopTask;
47
+ context: DistilledContext;
48
+ budget: LoopBudget;
49
+ costState: CostGovernorState;
50
+ }
51
+ export interface MartinAdapterUsage {
52
+ actualUsd: number;
53
+ avoidedUsd?: number;
54
+ tokensIn: number;
55
+ tokensOut: number;
56
+ }
57
+ export interface MartinAdapterVerification {
58
+ passed: boolean;
59
+ summary: string;
60
+ }
61
+ export interface MartinAdapterFailure {
62
+ message: string;
63
+ classHint?: FailureClass;
64
+ }
65
+ export interface MartinAdapterResult {
66
+ status: AdapterExecutionStatus;
67
+ summary: string;
68
+ usage: MartinAdapterUsage;
69
+ verification: MartinAdapterVerification;
70
+ failure?: MartinAdapterFailure;
71
+ artifacts?: LoopArtifact[];
72
+ }
73
+ export interface MartinAdapter {
74
+ adapterId: string;
75
+ kind: string;
76
+ label: string;
77
+ metadata: Record<string, string>;
78
+ execute(request: MartinAdapterRequest): Promise<MartinAdapterResult> | MartinAdapterResult;
79
+ }
80
+ export interface FailureClassificationInput {
81
+ attempts: LoopAttempt[];
82
+ result: MartinAdapterResult;
83
+ }
84
+ export interface FailureAssessment {
85
+ failureClass: FailureClass;
86
+ rationale: string;
87
+ retryable: boolean;
88
+ recommendedIntervention: InterventionType;
89
+ }
90
+ export interface ExitIntelligenceInput {
91
+ loop: Pick<LoopRecord, "budget" | "cost" | "attempts">;
92
+ lastResult?: MartinAdapterResult;
93
+ lastFailure?: FailureAssessment;
94
+ costState: CostGovernorState;
95
+ }
96
+ export interface ExitDecision {
97
+ shouldExit: boolean;
98
+ lifecycleState: LoopLifecycleState;
99
+ reason: string;
100
+ }
101
+ export interface RunMartinOptions {
102
+ workspaceId: string;
103
+ projectId: string;
104
+ teamId?: string;
105
+ task: LoopTask;
106
+ budget?: Partial<LoopBudget>;
107
+ adapter: MartinAdapter;
108
+ now?: () => string;
109
+ idFactory?: (prefix: string) => string;
110
+ }
111
+ export interface RunMartinResult {
112
+ loop: LoopRecord;
113
+ decision: ExitDecision;
114
+ finalContext: DistilledContext;
115
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,17 @@
1
+ export interface RiskTierVerificationInput {
2
+ scenarioId: string;
3
+ riskTier: "low" | "medium" | "high" | "critical";
4
+ blastRadiusScore: number;
5
+ claimSurfaceTouched: boolean;
6
+ privilegedAction: boolean;
7
+ securitySensitive: boolean;
8
+ }
9
+ export interface RiskTierVerificationPlan {
10
+ scenarioId: string;
11
+ tier: "standard" | "independent" | "consensus";
12
+ requiredVerifiers: string[];
13
+ mustPassAll: boolean;
14
+ allowedClaimWording: string;
15
+ nonClaims: string[];
16
+ }
17
+ export declare function buildRiskTierVerificationPlan(input: RiskTierVerificationInput): RiskTierVerificationPlan;
@@ -0,0 +1,29 @@
1
+ export function buildRiskTierVerificationPlan(input) {
2
+ const tier = input.riskTier === "critical" || input.privilegedAction || (input.claimSurfaceTouched && input.riskTier !== "low")
3
+ ? "consensus"
4
+ : input.riskTier === "high" || input.securitySensitive || input.claimSurfaceTouched
5
+ ? "independent"
6
+ : "standard";
7
+ const requiredVerifiers = ["targeted_verifier"];
8
+ if (tier !== "standard") {
9
+ requiredVerifiers.push("independent_reviewer");
10
+ }
11
+ if (input.securitySensitive) {
12
+ requiredVerifiers.push("security_review");
13
+ }
14
+ if (input.claimSurfaceTouched) {
15
+ requiredVerifiers.push("claim_boundary_audit");
16
+ }
17
+ if (input.privilegedAction) {
18
+ requiredVerifiers.push("human_owner");
19
+ }
20
+ return {
21
+ scenarioId: input.scenarioId,
22
+ tier,
23
+ requiredVerifiers: [...new Set(requiredVerifiers)],
24
+ mustPassAll: tier !== "standard",
25
+ allowedClaimWording: "risk-tiered cross-verification adds independent review only where blast radius, privileges, or claim boundaries justify it.",
26
+ nonClaims: ["universal multi-model consensus", "consensus on every low-risk run"]
27
+ };
28
+ }
29
+ //# sourceMappingURL=tiered-verify.js.map
@@ -0,0 +1,32 @@
1
+ import { type PatchDecisionReasonCode } from "../contracts/index.js";
2
+ export interface StreamScanResult {
3
+ isTrap: boolean;
4
+ reasonCode?: PatchDecisionReasonCode;
5
+ detail?: string;
6
+ severity: "fatal" | "warning" | "info";
7
+ corroborated: boolean;
8
+ }
9
+ /**
10
+ * Trap 9: Severity-Tiered, Corroboration-Aware Stream Scanner
11
+ *
12
+ * Mandated by CTO:
13
+ * - Fatal by default: Triggers trap immediately.
14
+ * - Warning by default: Logged as evidence but not fatal unless corroborated.
15
+ * - Corroboration: exitCode !== 0, or verifier failure, or critical denylist matches.
16
+ */
17
+ export declare function scanStreamsForTraps(stdout: string, stderr: string, options: {
18
+ exitCode: number;
19
+ verifierPassed: boolean;
20
+ }): StreamScanResult;
21
+ export interface HallucinatedTestOutputResult {
22
+ trapId: "T05";
23
+ detail: string;
24
+ }
25
+ /**
26
+ * Detects when stdout claims tests passed but the process exit code indicates
27
+ * failure — a hallucinated or fabricated test result.
28
+ */
29
+ export declare function detectHallucinatedTestOutput(input: {
30
+ stdout: string;
31
+ exitCode: number;
32
+ }): HallucinatedTestOutputResult | null;
@@ -0,0 +1,111 @@
1
+ const FATAL_PATTERNS = [
2
+ /\bERROR\b/i,
3
+ /\bEXCEPTION\b/i,
4
+ /\bFATAL\b/i,
5
+ /\bTraceback\b/i,
6
+ /\bUnhandled\b/i,
7
+ /\bpanic\b/i,
8
+ /\bSegmentation fault\b/i,
9
+ /\bAssertion failed\b/i
10
+ ];
11
+ const WARNING_PATTERNS = [
12
+ /\bWarning:\b/i,
13
+ /\bDeprecated\b/i,
14
+ /\bNotice\b/i,
15
+ /generic lint warning/i
16
+ ];
17
+ const CRITICAL_DENYLIST = [
18
+ /module not found/i,
19
+ /cannot resolve/i,
20
+ /failed to compile/i,
21
+ /permission denied/i,
22
+ /budget exceeded/i,
23
+ /authentication failed/i
24
+ ];
25
+ /**
26
+ * Trap 9: Severity-Tiered, Corroboration-Aware Stream Scanner
27
+ *
28
+ * Mandated by CTO:
29
+ * - Fatal by default: Triggers trap immediately.
30
+ * - Warning by default: Logged as evidence but not fatal unless corroborated.
31
+ * - Corroboration: exitCode !== 0, or verifier failure, or critical denylist matches.
32
+ */
33
+ export function scanStreamsForTraps(stdout, stderr, options) {
34
+ const combined = `${stdout}\n${stderr}`;
35
+ // 1. Check Fatal Patterns (Fast Track)
36
+ for (const pattern of FATAL_PATTERNS) {
37
+ if (pattern.test(combined)) {
38
+ return {
39
+ isTrap: true,
40
+ reasonCode: "severity_stream_trap",
41
+ detail: `Fatal pattern detected in stream: ${pattern.toString()}`,
42
+ severity: "fatal",
43
+ corroborated: true
44
+ };
45
+ }
46
+ }
47
+ // 2. Check Critical Denylist (Escalated regardless of severity)
48
+ for (const pattern of CRITICAL_DENYLIST) {
49
+ if (pattern.test(combined)) {
50
+ return {
51
+ isTrap: true,
52
+ reasonCode: "severity_stream_trap",
53
+ detail: `Critical failure matched in stream: ${pattern.toString()}`,
54
+ severity: "fatal",
55
+ corroborated: true
56
+ };
57
+ }
58
+ }
59
+ // 3. Check Warning Patterns
60
+ let hasWarning = false;
61
+ let matchingWarning = "";
62
+ for (const pattern of WARNING_PATTERNS) {
63
+ if (pattern.test(combined)) {
64
+ hasWarning = true;
65
+ matchingWarning = pattern.toString();
66
+ break;
67
+ }
68
+ }
69
+ if (hasWarning) {
70
+ const corroborated = options.exitCode !== 0 || !options.verifierPassed;
71
+ return {
72
+ isTrap: corroborated,
73
+ ...(corroborated ? { reasonCode: "severity_stream_trap" } : {}),
74
+ detail: corroborated
75
+ ? `Warning corroborated as failure: ${matchingWarning} (Exit Code: ${options.exitCode})`
76
+ : `Non-blocking warning detected: ${matchingWarning}`,
77
+ severity: "warning",
78
+ corroborated
79
+ };
80
+ }
81
+ return {
82
+ isTrap: false,
83
+ severity: "info",
84
+ corroborated: false
85
+ };
86
+ }
87
+ const SUCCESS_CLAIM_PATTERNS = [
88
+ /all tests? passed/i,
89
+ /\d+\/\d+ passing/i,
90
+ /\d+ tests? passed/i,
91
+ /test suite passed/i,
92
+ /ok \d+ passed/i
93
+ ];
94
+ /**
95
+ * Detects when stdout claims tests passed but the process exit code indicates
96
+ * failure — a hallucinated or fabricated test result.
97
+ */
98
+ export function detectHallucinatedTestOutput(input) {
99
+ if (input.exitCode === 0)
100
+ return null;
101
+ for (const pattern of SUCCESS_CLAIM_PATTERNS) {
102
+ if (pattern.test(input.stdout)) {
103
+ return {
104
+ trapId: "T05",
105
+ detail: `stdout claims success ("${input.stdout.trim().slice(0, 120)}") but exitCode=${input.exitCode}`
106
+ };
107
+ }
108
+ }
109
+ return null;
110
+ }
111
+ //# sourceMappingURL=verifier-pyramid.js.map
@@ -0,0 +1,99 @@
1
+ import { type LoopLifecycleState, type LoopRecord, type MachineState } from "../contracts/index.js";
2
+ import { type SignedAgentReceipt } from "./agent/receipts.js";
3
+ import { type AttestationVerificationResult } from "./attestation/sign.js";
4
+ import { type ContextUtilityScoreArtifact } from "./context-utility.js";
5
+ export interface WorkflowArtifactPaths {
6
+ runRoot: string;
7
+ contractPath: string;
8
+ statePath: string;
9
+ loopRecordPath: string;
10
+ loopRecordSignaturePath: string;
11
+ loopRecordPublicKeyPath: string;
12
+ ledgerPath: string;
13
+ artifactsRoot: string;
14
+ contextUtilityScorePath: string;
15
+ workflowReceiptPath: string;
16
+ workflowHandoffJsonPath: string;
17
+ workflowHandoffMarkdownPath: string;
18
+ }
19
+ export interface WorkflowHandoffSourceDigest {
20
+ path: string;
21
+ kind: "contract" | "state" | "ledger" | "artifact";
22
+ sha256: string;
23
+ }
24
+ export interface WorkflowHandoffCompaction {
25
+ schemaVersion: "martin.workflow.handoff.compaction.v1";
26
+ sourceManifestDigest: string;
27
+ sources: WorkflowHandoffSourceDigest[];
28
+ state: {
29
+ phase?: MachineState["phase"];
30
+ currentAttempt?: number;
31
+ activeModel?: string;
32
+ lastFailureSurface?: string;
33
+ openAlerts: string[];
34
+ };
35
+ verification: {
36
+ status: "verified" | "unverified";
37
+ summary: string;
38
+ attemptIndex?: number;
39
+ };
40
+ verificationPlan?: WorkflowVerificationPlanSummary;
41
+ contextUtility?: ContextUtilityScoreArtifact;
42
+ touchedSurfaces: string[];
43
+ blockers: string[];
44
+ nextPrompt: string;
45
+ }
46
+ export interface WorkflowVerificationPlanSummary {
47
+ tier?: string;
48
+ mustPassAll: boolean;
49
+ requiredChecks: string[];
50
+ optionalChecks: string[];
51
+ requiredVerifiers: string[];
52
+ summary: string;
53
+ }
54
+ export interface WorkflowHandoffArtifact {
55
+ schemaVersion: "martin.workflow.handoff.v1";
56
+ loopId: string;
57
+ workspaceId: string;
58
+ projectId: string;
59
+ status: LoopRecord["status"];
60
+ lifecycleState: LoopLifecycleState;
61
+ objective: string;
62
+ verificationPlan: string[];
63
+ attemptCount: number;
64
+ actualUsd: number;
65
+ reportedTotalUsd: number;
66
+ ledgerHash: string;
67
+ verificationStatus: "passed" | "blocked";
68
+ nextAction: string;
69
+ runRoot: string;
70
+ loopRecordPath: string;
71
+ workflowReceiptPath: string;
72
+ ledgerPath: string;
73
+ compaction: WorkflowHandoffCompaction;
74
+ createdAt: string;
75
+ updatedAt: string;
76
+ }
77
+ export interface PersistedWorkflowArtifacts {
78
+ paths: WorkflowArtifactPaths;
79
+ ledgerHash: string;
80
+ receipt: SignedAgentReceipt;
81
+ handoff: WorkflowHandoffArtifact;
82
+ }
83
+ export interface WorkflowHandoffVerificationResult {
84
+ ok: boolean;
85
+ reason?: string;
86
+ changedSources: string[];
87
+ attestation?: AttestationVerificationResult;
88
+ }
89
+ export declare function resolveWorkflowArtifactPaths(runsRoot: string, loopId: string): WorkflowArtifactPaths;
90
+ export declare function persistWorkflowArtifacts(input: {
91
+ loop: LoopRecord;
92
+ runsRoot: string;
93
+ martinHome: string;
94
+ }): Promise<PersistedWorkflowArtifacts>;
95
+ export declare function buildWorkflowHandoffArtifact(loop: LoopRecord, paths: WorkflowArtifactPaths, ledgerHash: string, compaction: WorkflowHandoffCompaction): WorkflowHandoffArtifact;
96
+ export declare function renderWorkflowHandoffMarkdown(handoff: WorkflowHandoffArtifact): string;
97
+ export declare function computeLedgerHash(ledgerPath: string): Promise<string>;
98
+ export declare function compactWorkflowHandoffSources(paths: WorkflowArtifactPaths): Promise<WorkflowHandoffCompaction>;
99
+ export declare function verifyWorkflowHandoffForResume(runRoot: string): Promise<WorkflowHandoffVerificationResult>;