@holmes-lab/holmes-kit 0.39.0 → 0.40.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 (298) hide show
  1. package/CHANGELOG.md +344 -6
  2. package/README.md +54 -41
  3. package/dist/.build-id +1 -1
  4. package/dist/holmes/admission/core/admission-policy.d.ts +37 -0
  5. package/dist/holmes/admission/core/admission-policy.js +147 -0
  6. package/dist/holmes/admission/core/bounded-reader.d.ts +56 -0
  7. package/dist/holmes/admission/core/bounded-reader.js +135 -0
  8. package/dist/holmes/admission/core/change-classifier.d.ts +34 -0
  9. package/dist/holmes/admission/core/change-classifier.js +278 -0
  10. package/dist/holmes/admission/core/config-loader.d.ts +30 -0
  11. package/dist/holmes/admission/core/config-loader.js +145 -0
  12. package/dist/holmes/admission/core/event-judgement.d.ts +37 -0
  13. package/dist/holmes/admission/core/event-judgement.js +251 -0
  14. package/dist/holmes/admission/core/path-rules.d.ts +35 -0
  15. package/dist/holmes/admission/core/path-rules.js +88 -0
  16. package/dist/holmes/admission/core/pin.d.ts +7 -0
  17. package/dist/holmes/admission/core/pin.js +29 -0
  18. package/dist/holmes/admission/core/ports.d.ts +48 -0
  19. package/dist/holmes/admission/core/ports.js +11 -0
  20. package/dist/holmes/admission/core/range-resolver.d.ts +32 -0
  21. package/dist/holmes/admission/core/range-resolver.js +51 -0
  22. package/dist/holmes/admission/core/self-containment.d.ts +1 -0
  23. package/dist/holmes/admission/core/self-containment.js +125 -0
  24. package/dist/holmes/admission/core/signature-source.d.ts +9 -0
  25. package/dist/holmes/admission/core/signature-source.js +4 -0
  26. package/dist/holmes/admission/core/transition-planner.d.ts +15 -0
  27. package/dist/holmes/admission/core/transition-planner.js +14 -0
  28. package/dist/holmes/admission/core/verdict.d.ts +38 -0
  29. package/dist/holmes/admission/core/verdict.js +17 -0
  30. package/dist/holmes/admission/core/wiring.d.ts +44 -0
  31. package/dist/holmes/admission/core/wiring.js +618 -0
  32. package/dist/holmes/admission/forge/git-object-port.d.ts +4 -0
  33. package/dist/holmes/admission/forge/git-object-port.js +132 -0
  34. package/dist/holmes/assoc/assoc-arm.d.ts +1 -1
  35. package/dist/holmes/assoc/assoc-arm.js +1 -1
  36. package/dist/holmes/cli/agents.d.ts +8 -0
  37. package/dist/holmes/cli/agents.js +9 -5
  38. package/dist/holmes/cli/approve-cli.d.ts +2 -0
  39. package/dist/holmes/cli/approve-cli.js +392 -0
  40. package/dist/holmes/cli/approve-ref.d.ts +13 -7
  41. package/dist/holmes/cli/approve-ref.js +30 -10
  42. package/dist/holmes/cli/approve-status.d.ts +26 -2
  43. package/dist/holmes/cli/approve-status.js +98 -18
  44. package/dist/holmes/cli/approve-watch.d.ts +5 -0
  45. package/dist/holmes/cli/approve-watch.js +10 -5
  46. package/dist/holmes/cli/approve.d.ts +49 -13
  47. package/dist/holmes/cli/approve.js +249 -67
  48. package/dist/holmes/cli/attest.js +2 -1
  49. package/dist/holmes/cli/autonomy.d.ts +4 -1
  50. package/dist/holmes/cli/autonomy.js +17 -10
  51. package/dist/holmes/cli/codex-oracle.d.ts +11 -0
  52. package/dist/holmes/cli/codex-oracle.js +5 -1
  53. package/dist/holmes/cli/codex-toml.d.ts +10 -0
  54. package/dist/holmes/cli/codex-toml.js +36 -2
  55. package/dist/holmes/cli/doctor-boundary.d.ts +76 -0
  56. package/dist/holmes/cli/doctor-boundary.js +308 -0
  57. package/dist/holmes/cli/doctor-locks.d.ts +15 -0
  58. package/dist/holmes/cli/doctor-locks.js +119 -0
  59. package/dist/holmes/cli/doctor.d.ts +2 -0
  60. package/dist/holmes/cli/doctor.js +34 -5
  61. package/dist/holmes/cli/flags.d.ts +23 -0
  62. package/dist/holmes/cli/flags.js +89 -0
  63. package/dist/holmes/cli/index.d.ts +5 -1
  64. package/dist/holmes/cli/index.js +202 -424
  65. package/dist/holmes/cli/init.js +33 -0
  66. package/dist/holmes/cli/lock-recover.d.ts +5 -0
  67. package/dist/holmes/cli/lock-recover.js +126 -0
  68. package/dist/holmes/cli/mcp-processes.js +1 -1
  69. package/dist/holmes/cli/release-docs.js +1 -1
  70. package/dist/holmes/cli/run-exec.d.ts +141 -0
  71. package/dist/holmes/cli/run-exec.js +1435 -0
  72. package/dist/holmes/cli/run-provision.d.ts +3 -1
  73. package/dist/holmes/cli/run-provision.js +255 -44
  74. package/dist/holmes/cli/run-wiring.d.ts +69 -0
  75. package/dist/holmes/cli/run-wiring.js +270 -0
  76. package/dist/holmes/cli/run.d.ts +21 -0
  77. package/dist/holmes/cli/run.js +341 -92
  78. package/dist/holmes/cli/runtime-binding-approval.js +32 -19
  79. package/dist/holmes/cli/screen-safe.d.ts +3 -92
  80. package/dist/holmes/cli/screen-safe.js +18 -756
  81. package/dist/holmes/config/config.d.ts +2 -0
  82. package/dist/holmes/config/config.js +5 -2
  83. package/dist/holmes/cpg/foundation/language-matrix.js +2 -2
  84. package/dist/holmes/cpg/import-resolver.js +1 -1
  85. package/dist/holmes/governance/approval-decisions.d.ts +47 -0
  86. package/dist/holmes/governance/approval-decisions.js +29 -0
  87. package/dist/holmes/governance/approval-grants.d.ts +220 -1
  88. package/dist/holmes/governance/approval-grants.js +612 -33
  89. package/dist/holmes/governance/approval-queue.d.ts +26 -0
  90. package/dist/holmes/governance/approval-queue.js +109 -11
  91. package/dist/holmes/governance/approval-spend.d.ts +95 -0
  92. package/dist/holmes/governance/approval-spend.js +191 -0
  93. package/dist/holmes/governance/autonomous-shell.d.ts +61 -0
  94. package/dist/holmes/governance/autonomous-shell.js +332 -0
  95. package/dist/holmes/governance/autonomy.d.ts +5 -0
  96. package/dist/holmes/governance/autonomy.js +16 -11
  97. package/dist/holmes/governance/constitution.d.ts +5 -0
  98. package/dist/holmes/governance/constitution.js +32 -12
  99. package/dist/holmes/governance/full-autonomy.d.ts +10 -0
  100. package/dist/holmes/governance/full-autonomy.js +103 -7
  101. package/dist/holmes/governance/harness-catalog.d.ts +103 -0
  102. package/dist/holmes/governance/harness-catalog.js +348 -0
  103. package/dist/holmes/governance/human-channel.d.ts +38 -0
  104. package/dist/holmes/governance/human-channel.js +49 -0
  105. package/dist/holmes/governance/install-manifest.d.ts +22 -0
  106. package/dist/holmes/governance/install-manifest.js +160 -0
  107. package/dist/holmes/governance/ledger-rechain.js +2 -0
  108. package/dist/holmes/governance/ledger-store.conformance.d.ts +7 -1
  109. package/dist/holmes/governance/ledger-store.conformance.js +66 -0
  110. package/dist/holmes/governance/ledger-store.d.ts +88 -11
  111. package/dist/holmes/governance/ledger-store.js +186 -8
  112. package/dist/holmes/governance/provenance-chain.d.ts +16 -4
  113. package/dist/holmes/governance/provenance-chain.js +19 -4
  114. package/dist/holmes/governance/provenance-ledger.d.ts +6 -3
  115. package/dist/holmes/governance/provenance-ledger.js +53 -18
  116. package/dist/holmes/governance/push-gate-runner.js +11 -7
  117. package/dist/holmes/governance/recorded-pairs.d.ts +96 -0
  118. package/dist/holmes/governance/recorded-pairs.js +522 -0
  119. package/dist/holmes/governance/replica-id.d.ts +1 -1
  120. package/dist/holmes/governance/replica-id.js +1 -1
  121. package/dist/holmes/governance/spec-seam.d.ts +59 -0
  122. package/dist/holmes/governance/spec-seam.js +587 -0
  123. package/dist/holmes/governance/spend-kinds.d.ts +16 -0
  124. package/dist/holmes/governance/spend-kinds.js +18 -0
  125. package/dist/holmes/guardrail/decision-ledger.d.ts +2 -1
  126. package/dist/holmes/guardrail/decision-ledger.js +2 -1
  127. package/dist/holmes/guardrail/impact-gate.d.ts +1 -0
  128. package/dist/holmes/guardrail/impact-gate.js +1 -1
  129. package/dist/holmes/guardrail/line-continuation.d.ts +8 -0
  130. package/dist/holmes/guardrail/line-continuation.js +39 -0
  131. package/dist/holmes/guardrail/operator-person.d.ts +28 -4
  132. package/dist/holmes/guardrail/operator-person.js +57 -11
  133. package/dist/holmes/guardrail/refusal-codes.d.ts +8 -3
  134. package/dist/holmes/guardrail/refusal-codes.js +64 -10
  135. package/dist/holmes/guardrail/risk-classifier.d.ts +15 -9
  136. package/dist/holmes/guardrail/risk-classifier.js +228 -16
  137. package/dist/holmes/guardrail/risk-gate.d.ts +2 -8
  138. package/dist/holmes/guardrail/risk-gate.js +7 -34
  139. package/dist/holmes/guardrail/risk-types.d.ts +10 -0
  140. package/dist/holmes/guardrail/run-plan-scope.js +3 -1
  141. package/dist/holmes/guardrail/run-refusals.js +24 -8
  142. package/dist/holmes/guardrail/run-stages.d.ts +5 -0
  143. package/dist/holmes/guardrail/run-stages.js +25 -5
  144. package/dist/holmes/guardrail/scope-judgment.js +1 -1
  145. package/dist/holmes/guardrail/shell-words.js +24 -3
  146. package/dist/holmes/guardrail/unresolved-write.d.ts +40 -0
  147. package/dist/holmes/guardrail/unresolved-write.js +556 -0
  148. package/dist/holmes/guardrail/write-target.d.ts +3 -0
  149. package/dist/holmes/guardrail/write-target.js +26 -5
  150. package/dist/holmes/hooks/pre-tool-use.d.ts +105 -1
  151. package/dist/holmes/hooks/pre-tool-use.js +1134 -167
  152. package/dist/holmes/hooks/rtm-refresh-child.d.ts +1 -1
  153. package/dist/holmes/hooks/rtm-refresh-child.js +1 -1
  154. package/dist/holmes/hooks/stop.d.ts +23 -0
  155. package/dist/holmes/hooks/stop.js +86 -33
  156. package/dist/holmes/mcp/approval-adapters.js +3 -1
  157. package/dist/holmes/mcp/approval-commit.js +3 -2
  158. package/dist/holmes/mcp/approval-policy.d.ts +2 -1
  159. package/dist/holmes/mcp/approval-policy.js +3 -1
  160. package/dist/holmes/mcp/handlers/adoption.d.ts +1 -1
  161. package/dist/holmes/mcp/handlers/approval-ask.d.ts +3 -0
  162. package/dist/holmes/mcp/handlers/approval-ask.js +18 -7
  163. package/dist/holmes/mcp/handlers/entity-integration.d.ts +3 -3
  164. package/dist/holmes/mcp/handlers/entity-integration.js +29 -11
  165. package/dist/holmes/mcp/handlers/entity-renumber.d.ts +4 -4
  166. package/dist/holmes/mcp/handlers/entity-renumber.js +29 -11
  167. package/dist/holmes/mcp/handlers/entity-store.d.ts +2 -2
  168. package/dist/holmes/mcp/handlers/entity-store.js +133 -59
  169. package/dist/holmes/mcp/handlers/operator-inspection.d.ts +9 -5
  170. package/dist/holmes/mcp/handlers/operator-inspection.js +79 -16
  171. package/dist/holmes/mcp/handlers/phase-queries.d.ts +1 -1
  172. package/dist/holmes/mcp/handlers/requirement-triage.d.ts +4 -4
  173. package/dist/holmes/mcp/handlers/review-evidence.d.ts +2 -2
  174. package/dist/holmes/mcp/handlers/review-evidence.js +35 -11
  175. package/dist/holmes/mcp/handlers/review-queries.d.ts +5 -0
  176. package/dist/holmes/mcp/handlers/review-queries.js +8 -1
  177. package/dist/holmes/mcp/handlers/review-verdict.d.ts +3 -0
  178. package/dist/holmes/mcp/handlers/review-verdict.js +10 -3
  179. package/dist/holmes/mcp/handlers/risk-assessment.d.ts +7 -2
  180. package/dist/holmes/mcp/handlers/risk-assessment.js +34 -12
  181. package/dist/holmes/mcp/handlers/runtime-binding-tool.d.ts +2 -2
  182. package/dist/holmes/mcp/handlers/slice-orchestration.d.ts +6 -1
  183. package/dist/holmes/mcp/handlers/slice-orchestration.js +14 -1
  184. package/dist/holmes/mcp/handlers/spec-approval.d.ts +15 -3
  185. package/dist/holmes/mcp/handlers/spec-approval.js +32 -5
  186. package/dist/holmes/mcp/handlers/spec-authoring.d.ts +2 -2
  187. package/dist/holmes/mcp/handlers/spec-authoring.js +19 -2
  188. package/dist/holmes/mcp/handlers/spec-lifecycle.d.ts +11 -38
  189. package/dist/holmes/mcp/handlers/spec-lifecycle.js +441 -94
  190. package/dist/holmes/mcp/handlers/spec-queries.d.ts +2 -2
  191. package/dist/holmes/mcp/handlers/taint-screening.d.ts +1 -1
  192. package/dist/holmes/mcp/handlers/taint-screening.js +2 -2
  193. package/dist/holmes/mcp/handlers/test-execution.d.ts +1 -1
  194. package/dist/holmes/mcp/handlers/workspace-queries.d.ts +2 -2
  195. package/dist/holmes/mcp/handlers.d.ts +89 -79
  196. package/dist/holmes/mcp/handlers.js +69 -22
  197. package/dist/holmes/mcp/harness-attestation.d.ts +78 -5
  198. package/dist/holmes/mcp/harness-attestation.js +325 -53
  199. package/dist/holmes/mcp/maintenance-analyze.d.ts +1 -1
  200. package/dist/holmes/mcp/maintenance-analyze.js +9 -9
  201. package/dist/holmes/mcp/maintenance-evidence.js +31 -2
  202. package/dist/holmes/mcp/requirement-triage-evidence.js +22 -13
  203. package/dist/holmes/mcp/server-staleness.js +1 -1
  204. package/dist/holmes/mcp/server.js +9 -8
  205. package/dist/holmes/mcp/spec-id-guard.js +1 -1
  206. package/dist/holmes/mcp/tool-schemas.d.ts +13 -0
  207. package/dist/holmes/mcp/tool-schemas.js +29 -2
  208. package/dist/holmes/project/act-root.d.ts +19 -0
  209. package/dist/holmes/project/act-root.js +100 -0
  210. package/dist/holmes/project/baseline.js +4 -3
  211. package/dist/holmes/project/bounded-group.d.ts +47 -0
  212. package/dist/holmes/project/bounded-group.js +140 -0
  213. package/dist/holmes/project/bounded-io.d.ts +50 -2
  214. package/dist/holmes/project/bounded-io.js +138 -6
  215. package/dist/holmes/project/change-source.js +2 -2
  216. package/dist/holmes/project/instance-id.d.ts +10 -0
  217. package/dist/holmes/project/instance-id.js +233 -0
  218. package/dist/holmes/project/machine-identity.d.ts +25 -0
  219. package/dist/holmes/project/machine-identity.js +133 -0
  220. package/dist/holmes/project/owned-lock.d.ts +84 -0
  221. package/dist/holmes/project/owned-lock.js +263 -0
  222. package/dist/holmes/project/plain-lock-fs.d.ts +2 -0
  223. package/dist/holmes/project/plain-lock-fs.js +126 -0
  224. package/dist/holmes/project/request-lock.d.ts +85 -0
  225. package/dist/holmes/project/request-lock.js +459 -0
  226. package/dist/holmes/project/root.d.ts +12 -4
  227. package/dist/holmes/project/root.js +26 -7
  228. package/dist/holmes/project/run-records.d.ts +19 -0
  229. package/dist/holmes/project/run-records.js +94 -12
  230. package/dist/holmes/project/screen-text.d.ts +94 -0
  231. package/dist/holmes/project/screen-text.js +763 -0
  232. package/dist/holmes/project/spend-lock.d.ts +82 -0
  233. package/dist/holmes/project/spend-lock.js +413 -0
  234. package/dist/holmes/refresh/freshness-coordinator.d.ts +1 -1
  235. package/dist/holmes/refresh/freshness-coordinator.js +1 -1
  236. package/dist/holmes/review/condition-hunk-replay.js +4 -2
  237. package/dist/holmes/review/confidence-calibration.d.ts +1 -1
  238. package/dist/holmes/review/confidence-calibration.js +1 -1
  239. package/dist/holmes/review/content-verify.js +1 -1
  240. package/dist/holmes/review/hop-ablation.d.ts +4 -4
  241. package/dist/holmes/review/hop-ablation.js +5 -5
  242. package/dist/holmes/review/point-in-time-replay.js +12 -3
  243. package/dist/holmes/review/rank-diagnosis.d.ts +2 -2
  244. package/dist/holmes/review/rank-diagnosis.js +1 -1
  245. package/dist/holmes/review/replay-corpus.d.ts +10 -4
  246. package/dist/holmes/review/replay-corpus.js +25 -9
  247. package/dist/holmes/review/requirement-triage.js +2 -2
  248. package/dist/holmes/review/semantic-arm.d.ts +3 -3
  249. package/dist/holmes/review/semantic-arm.js +3 -3
  250. package/dist/holmes/review/test-outcomes.js +3 -1
  251. package/dist/holmes/review/test-runner.d.ts +11 -0
  252. package/dist/holmes/review/test-runner.js +31 -10
  253. package/dist/holmes/review/test-selection-breadth.js +2 -2
  254. package/dist/holmes/review/verdicts.d.ts +105 -8
  255. package/dist/holmes/review/verdicts.js +640 -36
  256. package/dist/holmes/rtm/anchor-census.d.ts +9 -0
  257. package/dist/holmes/rtm/anchor-census.js +151 -0
  258. package/dist/holmes/rtm/anchor-ids.d.ts +25 -1
  259. package/dist/holmes/rtm/anchor-ids.js +45 -2
  260. package/dist/holmes/rtm/comment-ranges.d.ts +2 -0
  261. package/dist/holmes/rtm/comment-ranges.js +104 -0
  262. package/dist/holmes/rtm/counted-tests.d.ts +1 -0
  263. package/dist/holmes/rtm/counted-tests.js +63 -0
  264. package/dist/holmes/rtm/impact-advisory.d.ts +1 -1
  265. package/dist/holmes/rtm/known-defects.js +1 -1
  266. package/dist/holmes/rtm/localize.js +1 -1
  267. package/dist/holmes/rtm/taint-benchmark.d.ts +1 -1
  268. package/dist/holmes/rtm/taint-vocabulary.d.ts +1 -1
  269. package/dist/holmes/rtm/test-scope.d.ts +31 -0
  270. package/dist/holmes/rtm/test-scope.js +166 -5
  271. package/dist/holmes/rtm/trace-gaps.js +1 -1
  272. package/dist/holmes/runtime/dispatch.d.ts +10 -0
  273. package/dist/holmes/runtime/dispatch.js +12 -1
  274. package/dist/holmes/semantic/cloud-usage.d.ts +1 -1
  275. package/dist/holmes/semantic/cloud-usage.js +1 -1
  276. package/dist/holmes/semantic/unreadable-paths.d.ts +1 -1
  277. package/dist/holmes/semantic/unreadable-paths.js +1 -1
  278. package/dist/holmes/spec/approval-blockers.js +1 -1
  279. package/dist/holmes/spec/entity-store.d.ts +6 -1
  280. package/dist/holmes/spec/entity-store.js +16 -2
  281. package/dist/holmes/spec/entity-transaction.d.ts +7 -2
  282. package/dist/holmes/spec/entity-transaction.js +87 -170
  283. package/dist/holmes/spec/spec-store.d.ts +12 -6
  284. package/dist/holmes/spec/spec-store.js +4 -2
  285. package/dist/holmes/spec/spec-types.js +1 -1
  286. package/dist/holmes/spec/succession-guard.d.ts +56 -0
  287. package/dist/holmes/spec/succession-guard.js +187 -0
  288. package/dist/holmes/spec/succession.d.ts +70 -0
  289. package/dist/holmes/spec/succession.js +171 -0
  290. package/dist/holmes/spec/transition-policy.d.ts +2 -2
  291. package/docs/install-guide.md +9 -3
  292. package/docs/language-support.md +78 -0
  293. package/package.json +4 -3
  294. package/playbooks/author-slice/PLAYBOOK.md +1 -1
  295. package/playbooks/promote-slice/PLAYBOOK.md +5 -1
  296. package/playbooks/publish/PLAYBOOK.md +45 -33
  297. package/dist/holmes/review/manual-baseline.d.ts +0 -209
  298. package/dist/holmes/review/manual-baseline.js +0 -2847
@@ -33,12 +33,19 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.PROC_GONE = void 0;
36
+ exports.LAYOUT_RULE = exports.PROC_GONE = void 0;
37
+ exports.nativeInstallDirs = nativeInstallDirs;
38
+ exports.harnessByName = harnessByName;
37
39
  exports.harnessOf = harnessOf;
38
40
  exports.dispatcherVerifier = dispatcherVerifier;
39
41
  exports.attestHarness = attestHarness;
42
+ exports.liveAttestation = liveAttestation;
43
+ exports.serverAttestation = serverAttestation;
44
+ exports.operatorLookup = operatorLookup;
40
45
  exports.systemProcLookup = systemProcLookup;
41
- // @implements A-SPEC-732, A-SPEC-751.3, A-SPEC-102.8, A-SPEC-779.6
46
+ exports.imageRead = imageRead;
47
+ exports.imageOf = imageOf;
48
+ // @implements A-SPEC-732.13, A-SPEC-732.12, A-SPEC-732, A-SPEC-751.3, A-SPEC-102.8, A-SPEC-779.6, A-SPEC-732.2, A-SPEC-732.3, A-SPEC-732.4, A-SPEC-732.5, A-SPEC-732.6, A-SPEC-732.7, A-SPEC-732.8, A-SPEC-732.9, A-SPEC-732.10, A-SPEC-732.11
42
49
  // In-session approval (a form, or the host-gated continuation) trusts the client that answers it. An
43
50
  // agent can start its own copy of this server, name itself `claude-code` and answer for a person
44
51
  // (measured, H7 round 1). So before offering either route, the server asks who launched it: the
@@ -60,30 +67,109 @@ const HARNESS_EXES = new Set(['claude', 'codex', 'agy', 'antigravity']);
60
67
  const imageName = (image) => path.win32.basename(path.posix.basename(image)).toLowerCase().replace(/\.exe$/, '');
61
68
  /** `agy` and `antigravity` name the same harness. */
62
69
  const IMAGE_NAMES = { claude: ['claude'], codex: ['codex'], agy: ['agy', 'antigravity'], antigravity: ['agy', 'antigravity'] };
70
+ exports.LAYOUT_RULE = { kind: 'layout' };
71
+ /** A semver version: the core without leading zeros, an optional prerelease and build (A-SPEC-732.2 L2). */
72
+ const SEMVER = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
63
73
  /** The native Claude installer keeps each version as `…/claude/versions/<version>` (measured 2.1.281). */
64
- const CLAUDE_NATIVE_LAYOUT = /[\\/]claude[\\/]versions[\\/]\d+(?:\.\d+)+(?:\.exe)?$/i;
74
+ function versionLayout(segments, win) {
75
+ if (segments.length < 3)
76
+ return false;
77
+ const [claude, versions, file] = segments.slice(-3).map((s) => (win ? s.toLowerCase() : s));
78
+ return claude === 'claude' && versions === 'versions' && SEMVER.test(win ? file.replace(/\.exe$/, '') : file);
79
+ }
80
+ /**
81
+ * @implements A-SPEC-732.2 — `p` is a version file directly inside one of the rule's install directories, comparing
82
+ * realpaths; `follow` resolves `p` itself first (an image: a version entry that links elsewhere is where it links). The
83
+ * platform argument chooses the path grammar and whether case counts, never the path's shape (L3).
84
+ */
85
+ function installedVersion(p, rule, follow) {
86
+ const win = rule.platform === 'win32';
87
+ const lib = win ? path.win32 : path.posix;
88
+ if (!lib.isAbsolute(p))
89
+ return false;
90
+ const real = rule.realpath ?? fs.realpathSync.native;
91
+ const at = (q) => { try {
92
+ return real(q);
93
+ }
94
+ catch {
95
+ return null;
96
+ } };
97
+ const target = follow ? at(p) : lib.normalize(p);
98
+ if (target === null || !versionLayout(target.split(win ? /[\\/]/ : '/'), win))
99
+ return false;
100
+ const dir = at(lib.dirname(target));
101
+ if (dir === null)
102
+ return false;
103
+ const same = (d) => { const r = at(d); return r !== null && (win ? r.toLowerCase() === dir.toLowerCase() : r === dir); };
104
+ return rule.installDirs.some(same);
105
+ }
106
+ /** Whether `p` is a claude version path under `rule`. */
107
+ function versionPath(p, rule) {
108
+ if (typeof p !== 'string' || p === '')
109
+ return false;
110
+ return rule.kind === 'layout' ? versionLayout(p.split(/[\\/]/), true) : installedVersion(p, rule, false);
111
+ }
65
112
  /**
66
113
  * @implements A-SPEC-732 (round 5) — the image must BE the harness: "not an interpreter" let any
67
114
  * system binary started with argv0 `claude` (`/usr/bin/time`, `find -exec`, `awk system()`) attest,
68
115
  * and a forged client sealed a REQ through the form (measured). Named residual: a binary copied or
69
116
  * hard-linked under a harness's name or layout still attests; a code-signature check was declined.
117
+ * @implements A-SPEC-732.2 (M1) — the layout branch only directly inside an install directory, by the image's realpath:
118
+ * a scratch copy at `<scratch>/claude/versions/9.9.9` attested (measured by the reviewer)
70
119
  */
71
- function imageIsHarness(image, harness) {
120
+ function imageIsHarness(image, harness, rule) {
72
121
  if ((IMAGE_NAMES[harness] ?? []).includes(imageName(image)))
73
122
  return true;
74
- return harness === 'claude' && CLAUDE_NATIVE_LAYOUT.test(image);
123
+ return harness === 'claude' && installedVersion(image, rule, true);
75
124
  }
76
- const firstToken = (args) => {
77
- const t = args.trim();
78
- if (t.startsWith('"')) {
79
- const end = t.indexOf('"', 1);
80
- return end > 0 ? t.slice(1, end) : t.slice(1);
125
+ /**
126
+ * @implements A-SPEC-732.8 — argv0 by the program-name rule, the one reader of it in this module: a double quote toggles
127
+ * quoting, a backslash is literal, and white space outside quotes ends it (the C runtime reads a program name so; read by
128
+ * the argument rule, `"node\" /tmp/evil.js "` became one word and node ran /tmp/evil.js). `rest` is what follows.
129
+ */
130
+ // @implements A-SPEC-732.9 (defect 2) — leading white space is kept: the C runtime reads argv0 as "" there and node.exe
131
+ // runs the next word, so ` node <script>` has an empty program name and is no dispatcher (stripped, it walked through).
132
+ // @implements A-SPEC-732.10 — trim policy: none, the program name is read as the runtime reads it
133
+ function programName(args) {
134
+ const t = args;
135
+ let name = '';
136
+ let quoted = false;
137
+ let i = 0;
138
+ for (; i < t.length; i++) {
139
+ const c = t[i];
140
+ if (c === '"') {
141
+ quoted = !quoted;
142
+ continue;
143
+ }
144
+ if (!quoted && (c === ' ' || c === '\t'))
145
+ break;
146
+ name += c;
81
147
  }
82
- return t.split(/\s+/)[0] ?? '';
83
- };
148
+ return { name, rest: t.slice(i) };
149
+ }
150
+ // @implements A-SPEC-732.9 (info 4) — the quote toggle reads a POSIX argv0 too, where ps prints argv unquoted. argv0 is
151
+ // the launcher's own choice on every platform (`exec -a`), so reading a quote in it grants no name a launcher could not
152
+ // write plainly. @implements A-SPEC-732.11 (low 1) — for a harness the image check carries the trust; for the dispatcher
153
+ // hop nothing does: the verifier checks the script word, not who runs it, and an argv0 of `node <script>` (one argument
154
+ // holding a space) over a stdin program walks through (A, measured; named in the Limits with the exec residual)
155
+ // @implements A-SPEC-732.10 — trim policy: trimmed, because this is a name for exeName and harnessOf; a blank around argv0
156
+ // is judged where it matters, by the dispatcher's word reader (argWords keeps it, so `node <script>` behind it refuses)
157
+ const firstToken = (args) => programName(args.trim()).name;
84
158
  const exeName = (args) => path.win32.basename(path.posix.basename(firstToken(args))).toLowerCase().replace(/\.exe$/, '');
85
- /** Exported for A-SPEC-102.8 (review independence walks the same names). */
86
- function harnessOf(args, exe) {
159
+ /**
160
+ * @implements A-SPEC-732.1 — the directories a native Claude install keeps its versions in: `$XDG_DATA_HOME/claude/versions`
161
+ * when XDG_DATA_HOME is absolute, and `<home>/.local/share/claude/versions` (on Windows under the profile). `home` is an
162
+ * argument, so nothing here reads the process's own home.
163
+ */
164
+ function nativeInstallDirs(env, home, platform = process.platform) {
165
+ if (platform === 'win32')
166
+ return [path.win32.join(home, '.local', 'share', 'claude', 'versions')];
167
+ const xdg = env.XDG_DATA_HOME;
168
+ return [...(typeof xdg === 'string' && path.posix.isAbsolute(xdg) ? [path.posix.join(xdg, 'claude', 'versions')] : []),
169
+ path.posix.join(home, '.local', 'share', 'claude', 'versions')];
170
+ }
171
+ /** The executable names only: argv0's, then exe's. */
172
+ function harnessByName(args, exe) {
87
173
  const name = exeName(args);
88
174
  if (HARNESS_EXES.has(name))
89
175
  return name;
@@ -96,10 +182,40 @@ function harnessOf(args, exe) {
96
182
  }
97
183
  return null;
98
184
  }
185
+ /** Exported for A-SPEC-102.8 (review independence walks the same names, under its own rule). */
186
+ function harnessOf(args, exe, rule) {
187
+ const named = harnessByName(args, exe);
188
+ if (named !== null)
189
+ return named;
190
+ // @implements A-SPEC-732.1 — a session started through the native installer's version path has that path as argv0
191
+ // and comm (measured: `…/versions/2.1.310 --session-id …`); it is claude only inside the install directories
192
+ if (versionPath(firstToken(args), rule) || versionPath(exe, rule))
193
+ return 'claude';
194
+ return null;
195
+ }
196
+ /** @implements A-SPEC-732.1 — why an image file cannot be a harness's, or null: regular, non-empty, executable on POSIX. */
197
+ function imageFileProblem(image, statImage, platform) {
198
+ let st;
199
+ try {
200
+ st = statImage(image);
201
+ }
202
+ catch (e) {
203
+ return `cannot be inspected (${e.code ?? 'unreadable'})`;
204
+ }
205
+ if (!st.isFile())
206
+ return 'is not a regular file';
207
+ if (st.size === 0)
208
+ return 'is empty';
209
+ if (platform !== 'win32' && (st.mode & 0o111) === 0)
210
+ return 'is not executable';
211
+ return null;
212
+ }
99
213
  /** The launchers a harness starts the server through; a plain `node <script>` is not one. */
100
214
  function isLauncher(args) {
101
- if (/^npm exec\b/.test(args.trim()))
102
- return true; // npm's process title
215
+ // @implements A-SPEC-732.11 (TP2) — npm's process title (`npm exec …`) is read by its name like every launcher: a separate
216
+ // title match decided nothing exeName's `npm` did not (TP2, its trim removed, was equivalent), so it is gone; the name
217
+ // trims as firstToken does, so ` npx …` and ` npm exec …` are launchers alike (a test pins it). The looseness of this
218
+ // check (unverified launchers) is held with the shell-tool exec residual until the owner decides (A-SPEC-732.9 Limits)
103
219
  const name = exeName(args);
104
220
  if (name === 'npm' || name === 'npx')
105
221
  return true;
@@ -109,28 +225,100 @@ function isLauncher(args) {
109
225
  return false;
110
226
  }
111
227
  const NODE_PROGRAM_OPTIONS = new Set(['-e', '-p', '-r', '--eval', '--print', '--require', '--import', '--loader', '--experimental-loader']);
112
- /** Quote-aware words of a process's argument string (the first is the executable). */
113
- function argWords(args) {
114
- const out = [];
115
- const re = /"([^"]*)"|'([^']*)'|(\S+)/g;
116
- for (let m = re.exec(args); m !== null; m = re.exec(args))
117
- out.push(m[1] ?? m[2] ?? m[3]);
228
+ /** @implements A-SPEC-732.5 — the node options a dispatcher launch may carry; the measured launch carries none. */
229
+ const NODE_HARMLESS_OPTIONS = new Set(['--no-warnings', '--no-deprecation', '--enable-source-maps']);
230
+ /**
231
+ * The words of a process's argument string (the first is the executable). @implements A-SPEC-732.6 — quote-aware on
232
+ * Windows only, where CIM's CommandLine carries the quotes it was started with; `ps` prints argv unquoted, so a quote
233
+ * there is part of the word. @implements A-SPEC-732.7 — `ps` joins argv with one space, so the words are split on single
234
+ * spaces and an empty word (two spaces) or one holding other white space stays visible to the caller.
235
+ */
236
+ function argWords(args, platform) {
237
+ return platform === 'win32' ? windowsArgv(args) : args.split(' ');
238
+ }
239
+ /**
240
+ * @implements A-SPEC-732.7 (A W2, W5) — a Windows command line read by CommandLineToArgvW's rules: white space outside
241
+ * double quotes separates; 2n backslashes before a quote give n and the quote toggles quoting, 2n+1 give n and a literal
242
+ * quote; `""` inside quotes is a literal quote. A single quote is an ordinary character (the C runtime keeps it).
243
+ */
244
+ function windowsArgv(line) {
245
+ // @implements A-SPEC-732.8 — argv0 by the program-name rule, the arguments after it by the argument rule
246
+ const { name, rest: args } = programName(line);
247
+ const out = [name];
248
+ let cur = '';
249
+ let quoted = false;
250
+ let started = false;
251
+ for (let i = 0; i < args.length;) {
252
+ const c = args[i];
253
+ if (c === '\\') {
254
+ let n = 0;
255
+ while (args[i] === '\\') {
256
+ n++;
257
+ i++;
258
+ }
259
+ if (args[i] === '"') {
260
+ cur += '\\'.repeat(n >> 1);
261
+ if (n % 2 === 1) {
262
+ cur += '"';
263
+ i++;
264
+ }
265
+ }
266
+ else
267
+ cur += '\\'.repeat(n);
268
+ started = true;
269
+ }
270
+ else if (c === '"') {
271
+ if (quoted && args[i + 1] === '"') {
272
+ cur += '"';
273
+ i += 2;
274
+ }
275
+ else {
276
+ quoted = !quoted;
277
+ i++;
278
+ }
279
+ started = true;
280
+ }
281
+ else if (!quoted && (c === ' ' || c === '\t')) {
282
+ if (started) {
283
+ out.push(cur);
284
+ cur = '';
285
+ started = false;
286
+ }
287
+ i++;
288
+ }
289
+ else {
290
+ cur += c;
291
+ started = true;
292
+ i++;
293
+ }
294
+ }
295
+ if (started)
296
+ out.push(cur);
118
297
  return out;
119
298
  }
120
299
  /**
121
300
  * @implements A-SPEC-751.3 — the script a `node` process runs, or null when an option names a program or a preload
122
301
  * (`-e`, `-r`, `--require`, `--import`, `--loader` …: such a process runs something other than its script).
123
- * Options that take no program are stepped over; `--` ends options.
302
+ * Only the allowlisted options are stepped over (A-SPEC-732.5); `--` ends options.
303
+ * @implements A-SPEC-732.6 (Q1, Q1b) — off Windows a quoted script word stays quoted: it is the literal, relative path
304
+ * node resolves under its cwd, which the verifier refuses as not absolute (stripped, the verifier read the registry's file)
124
305
  */
125
- function nodeScriptOf(args) {
126
- const words = argWords(args).slice(1);
306
+ function nodeScriptOf(args, platform) {
307
+ const words = argWords(args, platform).slice(1);
127
308
  for (let i = 0; i < words.length; i++) {
128
309
  const w = words[i];
310
+ // @implements A-SPEC-732.7 (B L-1, A W2) — a boundary the table cannot show fails closed with no check of its own: an
311
+ // empty or white-space argument (node ran stdin for `""` and a file in its cwd for `" "`, reproduced) is the word read
312
+ // here, and a Windows single quote stays in its word; none is an absolute path, which the verifier requires
129
313
  if (w === '--')
130
- return words[i + 1] ?? null;
314
+ return i + 1 === words.length - 1 ? words[i + 1] : null;
315
+ // @implements A-SPEC-732.8 — the script is the last word: a word after it (`rest`, `--require x`) is an argument ps
316
+ // cannot tell from a space inside the script's own argument, and the runtime binding launches the script alone
131
317
  if (!w.startsWith('-'))
132
- return w;
133
- if (NODE_PROGRAM_OPTIONS.has(w.split('=')[0]) || !w.startsWith('--'))
318
+ return i === words.length - 1 ? w : null;
319
+ // @implements A-SPEC-732.5 — only the harmless options on the allowlist are stepped over: `--env-file=` can load
320
+ // NODE_OPTIONS (a preload), `--inspect` opens the process to a debugger, and any option not known is not trusted
321
+ if (NODE_PROGRAM_OPTIONS.has(w.split('=')[0]) || !NODE_HARMLESS_OPTIONS.has(w))
134
322
  return null;
135
323
  }
136
324
  return null;
@@ -167,7 +355,11 @@ function dispatcherVerifier(registryPath) {
167
355
  };
168
356
  }
169
357
  /** Walk up from `pid` (the server's parent) through launchers to a harness executable. */
170
- function attestHarness(pid, lookup, maxDepth = 8, isDispatcher) {
358
+ function attestHarness(pid, lookup, maxDepth, isDispatcher, options) {
359
+ // @implements A-SPEC-732.3 (19:16) — the rule's platform is the only one: a separate platform could disagree
360
+ const { rule } = options;
361
+ const platform = rule.platform;
362
+ const statImage = options.statImage ?? ((p) => fs.statSync(p));
171
363
  const chain = [];
172
364
  const seen = new Set();
173
365
  let cur = pid;
@@ -181,10 +373,10 @@ function attestHarness(pid, lookup, maxDepth = 8, isDispatcher) {
181
373
  // A-SPEC-779.6: a launcher that has exited attests nothing — fail closed, with the true reason.
182
374
  if (row === exports.PROC_GONE)
183
375
  return { attested: false, chain, reason: `process ${cur} exited before it could be read` };
184
- const harness = harnessOf(row.args, row.exe);
376
+ const harness = harnessOf(row.args, row.exe, rule);
185
377
  // @implements A-SPEC-751.3 — the receipted runtime dispatcher is a launcher; the chain records the hop as such.
186
378
  const viaDispatcher = harness === null && isDispatcher !== undefined && ['node', 'nodejs'].includes(exeName(row.args))
187
- && (() => { const script = nodeScriptOf(row.args); return script !== null && isDispatcher(script); })();
379
+ && (() => { const script = nodeScriptOf(row.args, platform); return script !== null && isDispatcher(script); })();
188
380
  const shown = viaDispatcher ? 'dispatcher' : harness ?? (exeName(row.args) || '?');
189
381
  chain.push(shown);
190
382
  if (viaDispatcher) {
@@ -193,11 +385,16 @@ function attestHarness(pid, lookup, maxDepth = 8, isDispatcher) {
193
385
  }
194
386
  if (harness !== null) {
195
387
  if (typeof row.image !== 'string' || row.image === '') {
196
- return { attested: false, chain, reason: `the executable image of ${shown} could not be read` };
388
+ // @implements A-SPEC-732.1 — the refusal always names its cause, so the failing path is visible
389
+ return { attested: false, chain, reason: `the executable image of ${shown} could not be read (${row.imageError || 'no image in the process table'})` };
197
390
  }
198
- if (!imageIsHarness(row.image, harness)) {
391
+ if (!imageIsHarness(row.image, harness, rule)) {
199
392
  return { attested: false, chain, reason: `${shown} is really ${imageName(row.image)} (${row.image}), not the ${harness} executable` };
200
393
  }
394
+ // @implements A-SPEC-732.1 — the name is not enough: an updater can leave a version entry empty and non-executable
395
+ const problem = imageFileProblem(row.image, statImage, platform);
396
+ if (problem !== null)
397
+ return { attested: false, chain, reason: `the executable image of ${shown} (${row.image}) ${problem}` };
201
398
  return { attested: true, chain, harness };
202
399
  }
203
400
  if (!isLauncher(row.args))
@@ -206,6 +403,39 @@ function attestHarness(pid, lookup, maxDepth = 8, isDispatcher) {
206
403
  }
207
404
  return { attested: false, chain, reason: 'launcher chain too deep' };
208
405
  }
406
+ /**
407
+ * @implements A-SPEC-732.3 (L-d, 19:16) — the live attestation the server runs: one InstalledRule, handed to the process
408
+ * lookup and the walk alike, its platform read from the rule only. The server called the two with separate defaults,
409
+ * equal today by accident. `deps` is for tests: the lookup maker and the stat.
410
+ */
411
+ function liveAttestation(pid, isDispatcher, deps) {
412
+ // A-SPEC-732.5 — the rule is required: every caller builds it (serverAttestation), and the default was a dead path
413
+ const rule = deps.rule;
414
+ const lookupOf = deps.lookupOf ?? systemProcLookup;
415
+ return attestHarness(pid, lookupOf(rule.platform, node_child_process_1.spawnSync, rule), 8, isDispatcher, { rule, ...(deps.statImage ? { statImage: deps.statImage } : {}) });
416
+ }
417
+ /**
418
+ * @implements A-SPEC-732.4 — the server's live attestation, in the one entry its tests reach: the install directories
419
+ * from `env` and `home`, the runtime registry's dispatcher under `home`, and the walk of `liveAttestation`. `server.ts`
420
+ * builds nothing else; home and env are arguments, so a test gives them (jest's process.env never reaches os.homedir()).
421
+ */
422
+ function serverAttestation(ppid, ctx) {
423
+ // A-SPEC-732.5 (P11) — a home that is not absolute would be read against the cwd: it attests nothing
424
+ if (!path.isAbsolute(ctx.home))
425
+ return { attested: false, chain: [], reason: 'the home directory is not an absolute path' };
426
+ const platform = ctx.platform ?? process.platform;
427
+ const rule = { kind: 'installed', installDirs: nativeInstallDirs(ctx.env, ctx.home, platform), platform };
428
+ // A-SPEC-751.3 — the registry's fixed default under this home, never taken from a request
429
+ const registry = path.join(ctx.home, '.holmes', 'runtime', 'bindings.json');
430
+ return liveAttestation(ppid, dispatcherVerifier(registry), { rule, ...(ctx.lookupOf ? { lookupOf: ctx.lookupOf } : {}), ...(ctx.statImage ? { statImage: ctx.statImage } : {}) });
431
+ }
432
+ /**
433
+ * @implements A-SPEC-732.5 — the operator walk's process lookup, given the walk's own layout rule. verdicts.ts built it
434
+ * with `spawnSync` itself; every live lookup is now assembled here.
435
+ */
436
+ function operatorLookup(make = systemProcLookup) {
437
+ return make(process.platform, node_child_process_1.spawnSync, exports.LAYOUT_RULE);
438
+ }
209
439
  /** FILETIME (100 ns ticks since 1601) to ms since 1970; BigInt because the ticks exceed 2^53. */
210
440
  const fileTimeToMs = (ticks) => Number(BigInt(ticks) / BigInt(10000)) - 11644473600000;
211
441
  /**
@@ -216,7 +446,8 @@ const fileTimeToMs = (ticks) => Number(BigInt(ticks) / BigInt(10000)) - 11644473
216
446
  * print GONE; only status 0 without a spawn error is believed. POSIX reparents an orphan to pid 1 and is unchanged.
217
447
  * `spawn` is injectable so the Windows branch is tested on every OS.
218
448
  */
219
- function systemProcLookup(platform = process.platform, spawn = node_child_process_1.spawnSync) {
449
+ // A-SPEC-732.4 — the operator walk's layout rule too; A-SPEC-732.6 — the rule is given, no default (only tests used it)
450
+ function systemProcLookup(platform, spawn, rule) {
220
451
  return (pid) => {
221
452
  try {
222
453
  if (platform === 'win32') {
@@ -224,7 +455,11 @@ function systemProcLookup(platform = process.platform, spawn = node_child_proces
224
455
  `$p = Get-CimInstance Win32_Process -Filter "ProcessId=${Math.trunc(pid)}" -ErrorAction Stop; if ($p) { $c = if ($p.CreationDate) { $p.CreationDate.ToFileTimeUtc() } else { '' }; "$($p.ParentProcessId)\`t$c\`t$($p.ExecutablePath)\`t$($p.CommandLine)" } else { 'GONE' }`], { encoding: 'utf8', timeout: 5000, windowsHide: true });
225
456
  if (r.error !== undefined || r.status !== 0)
226
457
  return null;
227
- const out = String(r.stdout ?? '').trim();
458
+ // @implements A-SPEC-732.9 (defect 2) — the line end only: a leading space in the command line is argv0 ""
459
+ // @implements A-SPEC-732.10 — every trailing line end (a CIM `\r\n\r\n` refused a normal launch), nothing else.
460
+ // Trim policy (A-SPEC-732.11 corrects 732.10's wording): the args are kept as printed and the readers decide what a
461
+ // blank means; the exe field is a path read apart, and is trimmed
462
+ const out = String(r.stdout ?? '').replace(/(\r?\n)+$/, '');
228
463
  if (out === 'GONE')
229
464
  return exports.PROC_GONE;
230
465
  const m = /^(\d+)\t(\d*)\t([^\t]*)\t([\s\S]*)$/.exec(out);
@@ -232,26 +467,46 @@ function systemProcLookup(platform = process.platform, spawn = node_child_proces
232
467
  return null;
233
468
  const exe = m[3].trim();
234
469
  return {
235
- pid, ppid: Number(m[1]), args: m[4].trim(),
470
+ pid, ppid: Number(m[1]), args: m[4],
236
471
  ...(exe ? { image: exe, exe } : {}),
237
472
  ...(m[2] !== '' ? { created: fileTimeToMs(m[2]) } : {}),
238
473
  };
239
474
  }
240
- const r = spawn('ps', ['-o', 'ppid=,args=', '-p', String(Math.trunc(pid))], { encoding: 'utf8', timeout: 5000 });
241
- const m = /^\s*(\d+)\s+([\s\S]*)$/.exec((r.stdout ?? '').trim());
475
+ // @implements A-SPEC-245.20 (item 1) — the system's ps with an empty environment: a ps planted first on PATH
476
+ // (`env -i PATH=<dir>:…`) answered for every operator act's ancestry. Named gap: powershell.exe on Windows.
477
+ // @implements A-SPEC-732.8 — -ww: the whole command line, whatever width ps would assume (macOS printed 20,019
478
+ // characters whole without it, measured; procps decides its width otherwise)
479
+ const r = spawn('/bin/ps', ['-ww', '-o', 'ppid=,args=', '-p', String(Math.trunc(pid))], { encoding: 'utf8', timeout: 5000, env: {} });
480
+ // @implements A-SPEC-245.22 (item 3) — a ps that failed or was killed (a timeout's partial output) is not believed
481
+ if (r.error !== undefined || r.status !== 0 || r.signal)
482
+ return null;
483
+ // @implements A-SPEC-732.9 (defect 1, RA5) — the line end only, then the padded pid and the one space ps puts
484
+ // after it: a trailing empty argument (`node <script> ""` prints `node <script> `) stays, and the walk refuses it
485
+ // @implements A-SPEC-732.10 — every trailing line end, nothing else (the same rule as the win32 branch); the args are
486
+ // kept as printed, the comm field (the exe path, below) is trimmed
487
+ const m = /^ *(\d+) ([\s\S]*)$/.exec(String(r.stdout ?? '').replace(/(\r?\n)+$/, ''));
242
488
  if (!m)
243
489
  return null;
244
- const row = { pid, ppid: Number(m[1]), args: m[2].trim() };
245
- // Round 6: the executable path alone (macOS prints it whole; Linux its name) — no args to split.
246
- const comm = spawn('ps', ['-o', 'comm=', '-p', String(Math.trunc(pid))], { encoding: 'utf8', timeout: 5000 });
490
+ const row = { pid, ppid: Number(m[1]), args: m[2] };
491
+ // Round 6: the executable field alone — no args to split. A-SPEC-732.12 — macOS prints argv[0] here (the launcher's
492
+ // choice, measured); A-SPEC-732.13 — Linux prints the task name, which the process itself can set (PR_SET_NAME).
493
+ // Neither is the file; only the image (lsof, /proc) is.
494
+ const comm = spawn('/bin/ps', ['-o', 'comm=', '-p', String(Math.trunc(pid))], { encoding: 'utf8', timeout: 5000, env: {} });
495
+ // @implements A-SPEC-245.23 (item 4) — checked as the first read is
496
+ // @implements A-SPEC-245.24 (item 4) — and closed the same way: a row whose executable could not be read is not a
497
+ // person's row (it could hide the harness image the name check needs), so the whole row is unreadable
498
+ if (comm.error !== undefined || comm.status !== 0 || comm.signal)
499
+ return null;
247
500
  const exe = (comm.stdout ?? '').trim();
248
501
  if (exe !== '')
249
502
  row.exe = exe;
250
503
  // The image costs a process spawn on macOS: read it only for a row that names a harness.
251
- if (harnessOf(row.args, row.exe) !== null) {
252
- const image = imageOf(pid, platform);
253
- if (image !== undefined)
254
- row.image = image;
504
+ if (harnessOf(row.args, row.exe, rule) !== null) { // @implements A-SPEC-732.1 — the same rule as the walk
505
+ const read = imageRead(pid, platform, process.env, spawn);
506
+ if ('image' in read)
507
+ row.image = read.image;
508
+ else
509
+ row.imageError = read.reason;
255
510
  }
256
511
  return row;
257
512
  }
@@ -260,16 +515,33 @@ function systemProcLookup(platform = process.platform, spawn = node_child_proces
260
515
  }
261
516
  };
262
517
  }
263
- /** The real executable of `pid`: Linux `/proc/<pid>/exe`, macOS the `txt` descriptor from lsof. */
264
- function imageOf(pid, platform) {
518
+ /**
519
+ * The real executable of `pid`: Linux `/proc/<pid>/exe`, macOS the `txt` descriptor from lsof, or why it could not be read.
520
+ * @implements A-SPEC-792.17 — lsof by absolute path: a server whose PATH lacks /usr/sbin found no lsof (measured).
521
+ * @implements A-SPEC-792.19 — lsof alone. `ps -o comm=` is argv[0] on macOS, chosen by the launcher, so standing it in
522
+ * for the image let `exec -a …/bin/claude /bin/sleep` attest whenever lsof gave no line (review 18:26, F2.1-a).
523
+ */
524
+ function imageRead(pid, platform, env = process.env, spawn = node_child_process_1.spawnSync) {
265
525
  try {
266
526
  if (platform === 'linux')
267
- return fs.readlinkSync(`/proc/${Math.trunc(pid)}/exe`);
268
- const r = (0, node_child_process_1.spawnSync)('lsof', ['-a', '-p', String(Math.trunc(pid)), '-d', 'txt', '-Fn'], { encoding: 'utf8', timeout: 5000 });
269
- const line = (r.stdout ?? '').split('\n').find((l) => l.startsWith('n'));
270
- return line ? line.slice(1) : undefined;
527
+ return { image: fs.readlinkSync(`/proc/${Math.trunc(pid)}/exe`) };
528
+ const r = spawn('/usr/sbin/lsof', ['-a', '-p', String(Math.trunc(pid)), '-d', 'txt', '-Fn'], { encoding: 'utf8', timeout: 5000, env });
529
+ // @implements A-SPEC-245.24 (item 4) — lsof's output is believed only when lsof succeeded (a timeout's partial output
530
+ // or a failed run is no image)
531
+ if (r.error !== undefined)
532
+ return { reason: `lsof: ${r.error.code ?? r.error.message}` };
533
+ if (r.status !== 0 || r.signal)
534
+ return { reason: r.signal ? `lsof: ${r.signal}` : `lsof: exit ${r.status}` };
535
+ const line = String(r.stdout ?? '').split('\n').find((l) => l.startsWith('n'));
536
+ if (line)
537
+ return { image: line.slice(1) };
538
+ return { reason: r.status !== 0 && r.status !== null ? `lsof: exit ${r.status}` : 'lsof: no txt line' };
271
539
  }
272
- catch {
273
- return undefined;
540
+ catch (e) {
541
+ return { reason: `image: ${e.code ?? 'unreadable'}` };
274
542
  }
275
543
  }
544
+ function imageOf(pid, platform, env = process.env) {
545
+ const r = imageRead(pid, platform, env);
546
+ return 'image' in r ? r.image : undefined;
547
+ }
@@ -297,7 +297,7 @@ export interface MaintenanceAnalysis {
297
297
  * recall 0.404 vs 0.554, then 0.833 vs 0.938). The gap was traced to judgement, not retrieval:
298
298
  * reranking the fused top-20 by hand moved Top-1 to 0.500 and Top-5 recall to 0.575 on eight
299
299
  * cases whose truth was unread at the time. The reachable recall of the wider list is measured —
300
- * holmes 0.634 at ten to 0.691 at twenty, jarvis 0.612 to 0.739, and jarvis is flat by thirty.
300
+ * holmes 0.634 at ten to 0.691 at twenty, the consumer corpus 0.612 to 0.739, and it is flat by thirty.
301
301
  *
302
302
  * This field buys none of that on its own. It hands the calling agent the material; whether recall
303
303
  * actually improves depends on how well that agent reranks, and that is not measured here.
@@ -5,7 +5,7 @@ exports.testNameMatches = testNameMatches;
5
5
  exports.unquoteGitPath = unquoteGitPath;
6
6
  exports.analyzeMaintenance = analyzeMaintenance;
7
7
  exports.boundAnalysis = boundAnalysis;
8
- // @implements A-SPEC-745, A-SPEC-745.1, A-SPEC-469.1, A-SPEC-469.2, A-SPEC-741, A-SPEC-741.1, A-SPEC-740, A-SPEC-725, A-SPEC-310
8
+ // @implements A-SPEC-745, A-SPEC-745.1, A-SPEC-469.1, A-SPEC-469.2, A-SPEC-741, A-SPEC-741.1, A-SPEC-740, A-SPEC-725, A-SPEC-310, A-SPEC-794.56
9
9
  // @implements A-SPEC-295
10
10
  // @implements A-SPEC-294
11
11
  // @implements A-SPEC-293
@@ -283,13 +283,13 @@ function analyzeMaintenance(input) {
283
283
  // layer did score.
284
284
  //
285
285
  // Rank fusion is scale-free and fixes exactly that. Measured on the 30-case clean slice of both
286
- // corpora, plain fusion also COST Top-1 (jarvis 0.533 -> 0.367) because it discards the margin by
286
+ // corpora, plain fusion also COST Top-1 (consumer 0.533 -> 0.367) because it discards the margin by
287
287
  // which a strong lexical winner won, and no weighting recovered it (best 0.433 across w=2/3/4/6).
288
288
  // So the score-ranked head is kept verbatim and only the tail is fused: Top-1 is preserved by
289
289
  // construction rather than by luck.
290
290
  // holmes Top-5 recall 0.382 -> 0.493, Top-10 0.604 -> 0.633, Top-10 precision 0.117 -> 0.127
291
- // jarvis Top-5 recall 0.459 -> 0.488, Top-10 0.612 -> 0.612, Top-10 precision 0.145 -> 0.135
292
- // The jarvis precision dip is real and is recorded rather than smoothed over.
291
+ // consumer Top-5 recall 0.459 -> 0.488, Top-10 0.612 -> 0.612, Top-10 precision 0.145 -> 0.135
292
+ // The consumer corpus's precision dip is real and is recorded rather than smoothed over.
293
293
  const RRF_K = 60;
294
294
  const fuseTail = () => {
295
295
  if (!hasPrior && !hasBoost)
@@ -309,7 +309,7 @@ function analyzeMaintenance(input) {
309
309
  // is not a rule against admission but the seed count.
310
310
  //
311
311
  // FIVE seeds, measured rather than chosen: at 20 both corpora get worse (holmes Top-5 recall
312
- // 0.554 -> 0.482, jarvis 0.517 -> 0.506). A wide seed set is what turned this axis into noise
312
+ // 0.554 -> 0.482, consumer 0.517 -> 0.506). A wide seed set is what turned this axis into noise
313
313
  // before, and the narrowness is the mechanism, not a tuning detail.
314
314
  const HOP_SEEDS = 5;
315
315
  // @implements A-SPEC-407
@@ -404,11 +404,11 @@ function analyzeMaintenance(input) {
404
404
  // on forty; with a third corpus and the clean slices re-measured, sixty is where the gain actually
405
405
  // arrives. Truth inside the exposed window, measured through this path:
406
406
  //
407
- // width 40 holmes 48/65 jarvis 52/70 gemini 14/19
408
- // width 60 holmes 49/65 jarvis 59/70 gemini 14/19
409
- // width 80 holmes 50/65 jarvis 59/70 gemini 14/19
407
+ // width 40 holmes 48/65 consumer 52/70 gemini 14/19
408
+ // width 60 holmes 49/65 consumer 59/70 gemini 14/19
409
+ // width 80 holmes 50/65 consumer 59/70 gemini 14/19
410
410
  //
411
- // Jarvis's whole gain is in by sixty; eighty buys one more file on this repository for double the
411
+ // The consumer corpus's whole gain is in by sixty; eighty buys one more file on this repository for double the
412
412
  // caller's context, so sixty is the knee rather than the maximum. No corpus is worse at sixty than
413
413
  // at forty — the first width or signal change in this line of work that clears A-SPEC-425's bar
414
414
  // instead of trading one corpus against another.
@@ -171,7 +171,9 @@ function writeArtifact(dir, artifact) {
171
171
  // corruption, and refusing to write here would strand the directory in its broken state.
172
172
  }
173
173
  }
174
- writeAtomic(file, `${JSON.stringify(merged, null, 2)}\n`);
174
+ const text = `${JSON.stringify(merged, null, 2)}\n`;
175
+ writeAtomic(file, text);
176
+ recordPersisted(dir, merged.digest, text); // @implements A-SPEC-792.28
175
177
  return file;
176
178
  }
177
179
  function readArtifacts(dir) {
@@ -233,9 +235,36 @@ function recordOutcome(dir, digest, outcome, recordedAt) {
233
235
  ...(classification ? { actualClassification: classification } : {}),
234
236
  },
235
237
  };
236
- writeAtomic(file, `${JSON.stringify(updated, null, 2)}\n`);
238
+ const text = `${JSON.stringify(updated, null, 2)}\n`;
239
+ writeAtomic(file, text);
240
+ recordPersisted(dir, updated.digest, text); // @implements A-SPEC-792.28 — the outcome changes the content: recorded again
237
241
  return updated;
238
242
  }
243
+ /**
244
+ * @implements A-SPEC-792.28 — the tool's own record of each write: the evidence digest and the file's content hash, on
245
+ * the workspace's provenance ledger (`<root>/.ax/ledger`, two levels above `.ax/evidence/maintenance`). Best effort: a
246
+ * ledger that cannot take the line leaves the file unproven for autonomous staging, never the write failed.
247
+ */
248
+ function recordPersisted(dir, digest, text) {
249
+ try {
250
+ // only beside a real `<root>/.ax/evidence/maintenance`, into a ledger that already exists: a writer pointed at any
251
+ // other directory must create nothing above it (measured: a test's evidence dir made a ledger in the temp root's parent)
252
+ const abs = path.resolve(dir);
253
+ const ax = path.dirname(path.dirname(abs));
254
+ const ledgerDir = path.join(ax, 'ledger');
255
+ if (path.basename(abs) !== 'maintenance' || path.basename(path.dirname(abs)) !== 'evidence' || path.basename(ax) !== '.ax')
256
+ return;
257
+ if (!fs.existsSync(ledgerDir) || !fs.lstatSync(ledgerDir).isDirectory())
258
+ return;
259
+ const { FileLedgerStore } = require('../governance/ledger-store');
260
+ const content = require('node:crypto').createHash('sha256').update(text).digest('hex');
261
+ new FileLedgerStore(ledgerDir).append({
262
+ ts: new Date().toISOString(), actor: 'holmes-kit', kind: 'analysis-persisted', summary: `analysis evidence ${digest.slice(0, 19)} written`,
263
+ inputs: [digest, `content:${content}`],
264
+ });
265
+ }
266
+ catch { /* unproven, not failed */ }
267
+ }
239
268
  // @implements A-SPEC-578.4
240
269
  /**
241
270
  * Predictions still waiting to be scored — the loop's missing second half.