@holmes-lab/holmes-kit 0.29.0 → 0.31.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 (169) hide show
  1. package/CHANGELOG.md +556 -0
  2. package/README.md +15 -5
  3. package/bin/holmes-hook-antigravity.js +4 -0
  4. package/bin/holmes-kit.js +4 -0
  5. package/bin/holmes-pre-push.js +3 -0
  6. package/bin/holmes-stop-antigravity.js +4 -0
  7. package/dist/.build-id +1 -1
  8. package/dist/holmes/cli/agents-guidance-history.d.ts +1 -1
  9. package/dist/holmes/cli/agents-guidance-history.js +11 -2
  10. package/dist/holmes/cli/agents-guidance.d.ts +1 -0
  11. package/dist/holmes/cli/agents-guidance.js +11 -8
  12. package/dist/holmes/cli/agents.d.ts +41 -0
  13. package/dist/holmes/cli/agents.js +382 -2
  14. package/dist/holmes/cli/attest.d.ts +2 -0
  15. package/dist/holmes/cli/attest.js +66 -15
  16. package/dist/holmes/cli/ci-gate.js +16 -1
  17. package/dist/holmes/cli/claude-switches.d.ts +95 -0
  18. package/dist/holmes/cli/claude-switches.js +967 -0
  19. package/dist/holmes/cli/codex-hooks.d.ts +77 -0
  20. package/dist/holmes/cli/codex-hooks.js +802 -0
  21. package/dist/holmes/cli/codex-oracle.d.ts +194 -0
  22. package/dist/holmes/cli/codex-oracle.js +1245 -0
  23. package/dist/holmes/cli/codex-toml.d.ts +58 -1
  24. package/dist/holmes/cli/codex-toml.js +456 -40
  25. package/dist/holmes/cli/doctor.d.ts +108 -8
  26. package/dist/holmes/cli/doctor.js +1408 -98
  27. package/dist/holmes/cli/index.js +23 -11
  28. package/dist/holmes/cli/init.d.ts +13 -0
  29. package/dist/holmes/cli/init.js +749 -77
  30. package/dist/holmes/cli/interactive-prompt.js +2 -2
  31. package/dist/holmes/cli/mcp-launcher.d.ts +64 -6
  32. package/dist/holmes/cli/mcp-launcher.js +189 -6
  33. package/dist/holmes/cli/mcp-version.js +13 -2
  34. package/dist/holmes/cli/settings-merge.js +8 -2
  35. package/dist/holmes/cli/upgrade.d.ts +13 -0
  36. package/dist/holmes/cli/upgrade.js +116 -23
  37. package/dist/holmes/cli/workspace-scope.d.ts +22 -0
  38. package/dist/holmes/cli/workspace-scope.js +375 -0
  39. package/dist/holmes/cli/worktree-readiness.d.ts +1 -0
  40. package/dist/holmes/cli/worktree-readiness.js +17 -3
  41. package/dist/holmes/cpg/cpg-scanner.d.ts +29 -0
  42. package/dist/holmes/cpg/cpg-scanner.js +403 -3
  43. package/dist/holmes/cpg/cycle-detect.js +2 -1
  44. package/dist/holmes/cpg/forbidden-edges.js +9 -2
  45. package/dist/holmes/cpg/required-calls.js +8 -1
  46. package/dist/holmes/governance/autonomy.d.ts +9 -0
  47. package/dist/holmes/governance/autonomy.js +28 -1
  48. package/dist/holmes/governance/constitution-debt.js +3 -2
  49. package/dist/holmes/governance/constitution.js +15 -3
  50. package/dist/holmes/governance/provenance-chain.js +3 -2
  51. package/dist/holmes/governance/push-gate-runner.js +4 -3
  52. package/dist/holmes/guardrail/dependency-delta.js +4 -3
  53. package/dist/holmes/guardrail/linear-match.d.ts +57 -0
  54. package/dist/holmes/guardrail/linear-match.js +256 -0
  55. package/dist/holmes/guardrail/risk-classifier.d.ts +6 -7
  56. package/dist/holmes/guardrail/risk-classifier.js +931 -44
  57. package/dist/holmes/guardrail/risk-types.d.ts +6 -0
  58. package/dist/holmes/guardrail/scope-judgment.d.ts +4 -24
  59. package/dist/holmes/guardrail/scope-judgment.js +100 -23
  60. package/dist/holmes/guardrail/shell-words.d.ts +42 -0
  61. package/dist/holmes/guardrail/shell-words.js +1720 -0
  62. package/dist/holmes/guardrail/write-target.d.ts +168 -3
  63. package/dist/holmes/guardrail/write-target.js +2379 -87
  64. package/dist/holmes/hooks/adapters/antigravity.d.ts +3 -1
  65. package/dist/holmes/hooks/adapters/antigravity.js +115 -11
  66. package/dist/holmes/hooks/pre-tool-use.d.ts +32 -6
  67. package/dist/holmes/hooks/pre-tool-use.js +923 -87
  68. package/dist/holmes/hooks/rtm-refresh-child.d.ts +22 -1
  69. package/dist/holmes/hooks/rtm-refresh-child.js +102 -18
  70. package/dist/holmes/hooks/rtm-refresh.d.ts +20 -1
  71. package/dist/holmes/hooks/rtm-refresh.js +60 -15
  72. package/dist/holmes/hooks/session-start.d.ts +10 -0
  73. package/dist/holmes/hooks/session-start.js +31 -7
  74. package/dist/holmes/hooks/stop.d.ts +2 -1
  75. package/dist/holmes/hooks/stop.js +197 -91
  76. package/dist/holmes/mcp/approval-adapters.d.ts +22 -0
  77. package/dist/holmes/mcp/approval-adapters.js +21 -0
  78. package/dist/holmes/mcp/approval-commit.d.ts +20 -0
  79. package/dist/holmes/mcp/approval-commit.js +108 -0
  80. package/dist/holmes/mcp/approval-intent.d.ts +44 -0
  81. package/dist/holmes/mcp/approval-intent.js +67 -0
  82. package/dist/holmes/mcp/approval-policy.d.ts +14 -0
  83. package/dist/holmes/mcp/approval-policy.js +18 -0
  84. package/dist/holmes/mcp/elicit-approval.d.ts +2 -0
  85. package/dist/holmes/mcp/elicit-approval.js +8 -3
  86. package/dist/holmes/mcp/handlers/graph-operations.d.ts +17 -1
  87. package/dist/holmes/mcp/handlers/graph-operations.js +15 -6
  88. package/dist/holmes/mcp/handlers/maintenance-analysis.js +11 -5
  89. package/dist/holmes/mcp/handlers/maintenance-evidence.js +3 -2
  90. package/dist/holmes/mcp/handlers/phase-queries.d.ts +22 -7
  91. package/dist/holmes/mcp/handlers/phase-queries.js +81 -2
  92. package/dist/holmes/mcp/handlers/requirement-triage.d.ts +26 -0
  93. package/dist/holmes/mcp/handlers/requirement-triage.js +48 -11
  94. package/dist/holmes/mcp/handlers/review-evidence.d.ts +2 -1
  95. package/dist/holmes/mcp/handlers/review-evidence.js +15 -5
  96. package/dist/holmes/mcp/handlers/slice-orchestration.d.ts +18 -0
  97. package/dist/holmes/mcp/handlers/slice-orchestration.js +122 -16
  98. package/dist/holmes/mcp/handlers/spec-approval.d.ts +35 -2
  99. package/dist/holmes/mcp/handlers/spec-approval.js +175 -57
  100. package/dist/holmes/mcp/handlers/spec-authoring.js +36 -3
  101. package/dist/holmes/mcp/handlers/spec-queries.d.ts +39 -3
  102. package/dist/holmes/mcp/handlers/spec-queries.js +114 -7
  103. package/dist/holmes/mcp/handlers/test-execution.js +9 -3
  104. package/dist/holmes/mcp/handlers.d.ts +126 -8
  105. package/dist/holmes/mcp/handlers.js +109 -18
  106. package/dist/holmes/mcp/harness-attestation.d.ts +20 -0
  107. package/dist/holmes/mcp/harness-attestation.js +179 -0
  108. package/dist/holmes/mcp/maintenance-analyze.js +28 -4
  109. package/dist/holmes/mcp/maintenance-evidence.js +1 -1
  110. package/dist/holmes/mcp/requirement-triage-evidence.d.ts +72 -2
  111. package/dist/holmes/mcp/requirement-triage-evidence.js +227 -1
  112. package/dist/holmes/mcp/server.js +24 -3
  113. package/dist/holmes/mcp/supervisor.js +7 -3
  114. package/dist/holmes/mcp/tool-schemas.d.ts +8 -0
  115. package/dist/holmes/mcp/tool-schemas.js +54 -7
  116. package/dist/holmes/mcp/validate-args.js +12 -0
  117. package/dist/holmes/project/bounded-io.d.ts +102 -0
  118. package/dist/holmes/project/bounded-io.js +212 -0
  119. package/dist/holmes/project/change-source.js +3 -1
  120. package/dist/holmes/project/ci-runs.js +3 -2
  121. package/dist/holmes/project/ignore.d.ts +31 -2
  122. package/dist/holmes/project/ignore.js +409 -50
  123. package/dist/holmes/project/regular-file-guard.d.ts +13 -0
  124. package/dist/holmes/project/regular-file-guard.js +149 -0
  125. package/dist/holmes/project/root.js +12 -3
  126. package/dist/holmes/refresh/freshness-coordinator.d.ts +67 -0
  127. package/dist/holmes/refresh/freshness-coordinator.js +230 -0
  128. package/dist/holmes/reverse/anchor.js +4 -3
  129. package/dist/holmes/reverse/scan.js +6 -2
  130. package/dist/holmes/review/commit-text.js +3 -2
  131. package/dist/holmes/review/condition-hunk-replay.d.ts +12 -0
  132. package/dist/holmes/review/condition-hunk-replay.js +13 -2
  133. package/dist/holmes/review/condition-hunk-resolution.js +59 -8
  134. package/dist/holmes/review/failed-test-names.js +13 -10
  135. package/dist/holmes/review/findings.js +3 -1
  136. package/dist/holmes/review/kills-check.js +6 -1
  137. package/dist/holmes/review/point-in-time-replay.js +5 -4
  138. package/dist/holmes/review/replay-corpus.js +5 -4
  139. package/dist/holmes/review/requirement-triage-human-records.d.ts +59 -0
  140. package/dist/holmes/review/requirement-triage-human-records.js +119 -0
  141. package/dist/holmes/review/run-replay.js +3 -2
  142. package/dist/holmes/review/scope.js +6 -1
  143. package/dist/holmes/review/temporal-prior.js +3 -2
  144. package/dist/holmes/review/test-evidence.js +3 -2
  145. package/dist/holmes/review/test-outcomes.d.ts +28 -0
  146. package/dist/holmes/review/test-outcomes.js +92 -2
  147. package/dist/holmes/review/test-runner.d.ts +6 -0
  148. package/dist/holmes/review/test-runner.js +36 -15
  149. package/dist/holmes/rtm/advisory-outcomes.js +3 -2
  150. package/dist/holmes/rtm/anchor-ids.js +42 -2
  151. package/dist/holmes/rtm/file-anchors.js +4 -1
  152. package/dist/holmes/rtm/ftt-fulfilment.js +8 -3
  153. package/dist/holmes/rtm/git-changes.js +3 -1
  154. package/dist/holmes/rtm/graph-store.js +3 -2
  155. package/dist/holmes/rtm/test-scope.js +9 -4
  156. package/dist/holmes/spec/compat-impact.d.ts +25 -4
  157. package/dist/holmes/spec/compat-impact.js +682 -11
  158. package/dist/holmes/spec/entity-git-snapshot.js +3 -2
  159. package/dist/holmes/spec/entity-integration.js +3 -2
  160. package/dist/holmes/spec/entity-renumber-transaction.d.ts +19 -0
  161. package/dist/holmes/spec/entity-renumber-transaction.js +79 -6
  162. package/dist/holmes/spec/remote-spec-refs.js +3 -2
  163. package/dist/holmes/spec/renumber.js +25 -10
  164. package/dist/holmes/spec/spec-parser.js +9 -3
  165. package/dist/holmes/spec/yaml-scalar.js +2 -2
  166. package/dist/holmes/update/refresh.js +3 -1
  167. package/dist/holmes/update/update-notice.d.ts +6 -0
  168. package/dist/holmes/update/update-notice.js +18 -1
  169. package/package.json +11 -4
@@ -5,6 +5,8 @@ import { type DecisionRecord, type DecisionCitation } from '../rtm/rtm-builder';
5
5
  import { Basis } from './basis';
6
6
  import { Approval } from '../guardrail/risk-gate';
7
7
  import { Elicitor } from './elicit-approval';
8
+ import { ApprovalContinuationStore } from './approval-commit';
9
+ import { ApprovalIntent } from './approval-intent';
8
10
  /**
9
11
  * @implements A-SPEC-189 §7 (round 10)
10
12
  * A DELIBERATE refusal, distinguished by construction rather than by class.
@@ -32,8 +34,25 @@ import { ChangeSourceInfo } from '../project/change-source';
32
34
  */
33
35
  export interface ElicitOpts {
34
36
  elicit?: Elicitor;
37
+ /** The negotiated MCP capability, not the presence of our injected wrapper. */
38
+ elicitationAvailable?: () => boolean;
35
39
  clientName?: () => string;
36
40
  observeInvocation?: (root: string) => void | Promise<void>;
41
+ /** @implements A-SPEC-732 — whether a harness launched this server; absent means attested (in-process callers). */
42
+ harnessAttestation?: () => {
43
+ attested: boolean;
44
+ reason?: string;
45
+ chain?: string[];
46
+ };
47
+ /**
48
+ * @implements A-SPEC-732 (round 3) — internal: inner handler sets (spec_slice_approve's) share the
49
+ * caller's continuation store and run id, so an intent they issue is committed by the caller's
50
+ * approval_commit and consumed by their retry.
51
+ */
52
+ approvalSession?: {
53
+ continuations: ApprovalContinuationStore;
54
+ runId: string;
55
+ };
37
56
  }
38
57
  /**
39
58
  * @implements A-SPEC-299
@@ -62,6 +81,12 @@ export declare function collectDecisions(root: string, scanned: readonly Scanned
62
81
  citations: DecisionCitation[];
63
82
  };
64
83
  declare function makeRawHandlers(store: SpecStore, opts?: ElicitOpts): {
84
+ approval_commit: (a: ApprovalIntent) => Promise<{
85
+ ok: true;
86
+ } | {
87
+ ok: boolean;
88
+ reason: string;
89
+ }>;
65
90
  entity_integrate(a: {
66
91
  root?: string;
67
92
  operation?: string;
@@ -555,12 +580,19 @@ declare function makeRawHandlers(store: SpecStore, opts?: ElicitOpts): {
555
580
  title: string;
556
581
  objective: string;
557
582
  filesToTouch: string[];
583
+ triage_evidence?: unknown;
558
584
  }) => Promise<{
559
585
  ok: boolean;
560
586
  reason: string;
561
587
  existing: string[];
562
588
  specsCreated: string[];
563
589
  unreadable: string[];
590
+ } | {
591
+ ok: boolean;
592
+ reason: string;
593
+ specsCreated: string[];
594
+ unreadable: string[];
595
+ existing?: undefined;
564
596
  } | {
565
597
  ok: boolean;
566
598
  specsCreated: string[];
@@ -572,6 +604,7 @@ declare function makeRawHandlers(store: SpecStore, opts?: ElicitOpts): {
572
604
  root?: string;
573
605
  sliceName: string;
574
606
  }) => Promise<{
607
+ approvalIntent?: {} | null | undefined;
575
608
  ok: boolean;
576
609
  approvedSpecs: string[];
577
610
  alreadySealed: string[];
@@ -606,6 +639,7 @@ declare function makeRawHandlers(store: SpecStore, opts?: ElicitOpts): {
606
639
  semantic: {
607
640
  localState?: import("../semantic/model-cache").LocalModelState | undefined;
608
641
  recovery?: string | undefined;
642
+ suppressed?: true | undefined;
609
643
  tier: "local" | "none" | "cloud";
610
644
  covered: number;
611
645
  total: number;
@@ -641,6 +675,16 @@ declare function makeRawHandlers(store: SpecStore, opts?: ElicitOpts): {
641
675
  governedDocumentCount: number;
642
676
  scannedSourceCount: number;
643
677
  };
678
+ freshness: import("../refresh/freshness-coordinator").FreshnessReceipt | {
679
+ state: string;
680
+ };
681
+ refresh: {
682
+ status: "spawned" | "coalesced" | "failed";
683
+ generation?: string;
684
+ } | {
685
+ status: "unavailable" | "not-needed";
686
+ };
687
+ lexicalOnly?: true | undefined;
644
688
  verdict: import("../review/requirement-triage").RequirementVerdict;
645
689
  candidates: import("../review/requirement-triage").RequirementTriageCandidate[];
646
690
  reasons: string[];
@@ -657,6 +701,7 @@ declare function makeRawHandlers(store: SpecStore, opts?: ElicitOpts): {
657
701
  semantic: {
658
702
  localState?: import("../semantic/model-cache").LocalModelState | undefined;
659
703
  recovery?: string | undefined;
704
+ suppressed?: true | undefined;
660
705
  tier: "local" | "none" | "cloud";
661
706
  covered: number;
662
707
  total: number;
@@ -692,6 +737,16 @@ declare function makeRawHandlers(store: SpecStore, opts?: ElicitOpts): {
692
737
  governedDocumentCount: number;
693
738
  scannedSourceCount: number;
694
739
  };
740
+ freshness: import("../refresh/freshness-coordinator").FreshnessReceipt | {
741
+ state: string;
742
+ };
743
+ refresh: {
744
+ status: "spawned" | "coalesced" | "failed";
745
+ generation?: string;
746
+ } | {
747
+ status: "unavailable" | "not-needed";
748
+ };
749
+ lexicalOnly?: true | undefined;
695
750
  verdict: import("../review/requirement-triage").RequirementVerdict;
696
751
  candidates: import("../review/requirement-triage").RequirementTriageCandidate[];
697
752
  reasons: string[];
@@ -983,11 +1038,18 @@ declare function makeRawHandlers(store: SpecStore, opts?: ElicitOpts): {
983
1038
  } | {
984
1039
  ok: boolean;
985
1040
  reason: string;
1041
+ approvalIntent?: undefined;
1042
+ conflict?: undefined;
1043
+ } | {
1044
+ ok: boolean;
1045
+ reason: string;
1046
+ approvalIntent: ApprovalIntent;
986
1047
  conflict?: undefined;
987
1048
  } | {
988
1049
  ok: boolean;
989
1050
  reason: string;
990
1051
  conflict: import("../spec/version-conflict").ConflictDetail;
1052
+ approvalIntent?: undefined;
991
1053
  } | {
992
1054
  dismissUnknown?: string[] | undefined;
993
1055
  advisoryHistory?: import("../rtm/advisory-outcomes").AdvisoryState[] | undefined;
@@ -1007,6 +1069,7 @@ declare function makeRawHandlers(store: SpecStore, opts?: ElicitOpts): {
1007
1069
  digest: string;
1008
1070
  ok?: undefined;
1009
1071
  reason?: undefined;
1072
+ approvalIntent?: undefined;
1010
1073
  conflict?: undefined;
1011
1074
  }>;
1012
1075
  spec_list: (a: any) => Promise<{
@@ -1018,10 +1081,48 @@ declare function makeRawHandlers(store: SpecStore, opts?: ElicitOpts): {
1018
1081
  status: "draft" | "review" | "approved" | "outdated";
1019
1082
  }[];
1020
1083
  }>;
1021
- spec_next: () => Promise<{
1022
- next: import("../spec/spec-types").SpecType;
1084
+ spec_next: (a?: {
1085
+ id?: string;
1086
+ }) => Promise<{
1087
+ ok: boolean;
1088
+ reason: string;
1089
+ next?: undefined;
1090
+ actions?: undefined;
1091
+ actionsTotal?: undefined;
1092
+ chain?: undefined;
1093
+ chainTotal?: undefined;
1094
+ note?: undefined;
1023
1095
  } | {
1024
- next: null;
1096
+ next: import("../spec/spec-types").SpecType | null;
1097
+ actions: {
1098
+ id: string;
1099
+ action: "seal" | "fill-then-seal" | "fix-then-seal" | "after-parent" | "create-parent" | "author-tspec";
1100
+ reason: string;
1101
+ }[];
1102
+ actionsTotal: number;
1103
+ chain: {
1104
+ id: string;
1105
+ type: import("../spec/spec-types").SpecType;
1106
+ status: "draft" | "review" | "approved" | "outdated";
1107
+ sealed: boolean;
1108
+ }[];
1109
+ chainTotal: number;
1110
+ note: string;
1111
+ ok?: undefined;
1112
+ reason?: undefined;
1113
+ } | {
1114
+ next: import("../spec/spec-types").SpecType | null;
1115
+ actions: {
1116
+ id: string;
1117
+ action: "seal" | "fill-then-seal" | "fix-then-seal" | "after-parent" | "create-parent" | "author-tspec";
1118
+ reason: string;
1119
+ }[];
1120
+ actionsTotal: number;
1121
+ note: string;
1122
+ ok?: undefined;
1123
+ reason?: undefined;
1124
+ chain?: undefined;
1125
+ chainTotal?: undefined;
1025
1126
  }>;
1026
1127
  rtm_check: (a?: {
1027
1128
  root?: string;
@@ -1067,18 +1168,35 @@ declare function makeRawHandlers(store: SpecStore, opts?: ElicitOpts): {
1067
1168
  }>;
1068
1169
  phase_status: (a: {
1069
1170
  root?: string;
1171
+ ids?: string[];
1172
+ type?: string;
1173
+ status?: string;
1174
+ limit?: number;
1175
+ cursor?: string;
1070
1176
  }) => Promise<{
1071
1177
  ok: boolean;
1072
1178
  reason: string;
1073
- specs?: undefined;
1074
- note?: undefined;
1075
1179
  } | {
1180
+ note: string;
1181
+ unknownIds?: string[] | undefined;
1182
+ unknownIdsTotal?: number | undefined;
1183
+ nextCursor?: string | undefined;
1184
+ summary: {
1185
+ total: number;
1186
+ counts: Record<string, Record<string, number>>;
1187
+ notApproved: {
1188
+ id: string;
1189
+ type: string;
1190
+ status: string;
1191
+ }[];
1192
+ notApprovedTotal: number;
1193
+ };
1076
1194
  specs: {
1077
1195
  id: string;
1078
- type: import("../spec/spec-types").SpecType;
1079
- status: "draft" | "review" | "approved" | "outdated";
1196
+ type: string;
1197
+ status: string;
1080
1198
  }[];
1081
- note: string;
1199
+ matched: number;
1082
1200
  ok?: undefined;
1083
1201
  reason?: undefined;
1084
1202
  }>;
@@ -38,7 +38,7 @@ exports.isHandlerRefusal = isHandlerRefusal;
38
38
  exports.unreadableAmong = unreadableAmong;
39
39
  exports.makeHandlers = makeHandlers;
40
40
  exports.collectDecisions = collectDecisions;
41
- // @implements A-SPEC-703, A-SPEC-629, A-SPEC-628, A-SPEC-599, A-SPEC-603, A-SPEC-604, A-SPEC-605, A-SPEC-606, A-SPEC-607, A-SPEC-608, A-SPEC-609, A-SPEC-610, A-SPEC-611, A-SPEC-612, A-SPEC-613, A-SPEC-614, A-SPEC-615, A-SPEC-616, A-SPEC-617, A-SPEC-618, A-SPEC-621, A-SPEC-622, A-SPEC-624, A-SPEC-625, A-SPEC-627, A-SPEC-713
41
+ // @implements A-SPEC-723, A-SPEC-720, A-SPEC-718, A-SPEC-703, A-SPEC-629, A-SPEC-628, A-SPEC-599, A-SPEC-603, A-SPEC-604, A-SPEC-605, A-SPEC-606, A-SPEC-607, A-SPEC-608, A-SPEC-609, A-SPEC-610, A-SPEC-611, A-SPEC-612, A-SPEC-613, A-SPEC-614, A-SPEC-615, A-SPEC-616, A-SPEC-617, A-SPEC-618, A-SPEC-621, A-SPEC-622, A-SPEC-624, A-SPEC-625, A-SPEC-627, A-SPEC-713, A-SPEC-732
42
42
  // @implements A-SPEC-643
43
43
  // @implements A-SPEC-642
44
44
  // @implements A-SPEC-642
@@ -83,6 +83,7 @@ const graph_operations_1 = require("./handlers/graph-operations");
83
83
  const graph_operations_2 = require("./handlers/graph-operations");
84
84
  const maintenance_analysis_1 = require("./handlers/maintenance-analysis");
85
85
  const requirement_triage_1 = require("./handlers/requirement-triage");
86
+ const rtm_refresh_1 = require("../hooks/rtm-refresh");
86
87
  const taint_screening_1 = require("./handlers/taint-screening");
87
88
  const cpg_scanner_1 = require("../cpg/cpg-scanner");
88
89
  const scan_cache_1 = require("../cpg/scan-cache");
@@ -119,6 +120,9 @@ const write_target_1 = require("../guardrail/write-target");
119
120
  const spec_store_1 = require("../spec/spec-store");
120
121
  const risk_gate_1 = require("../guardrail/risk-gate");
121
122
  const elicit_approval_1 = require("./elicit-approval");
123
+ const approval_commit_1 = require("./approval-commit");
124
+ const approval_intent_1 = require("./approval-intent");
125
+ const approval_adapters_1 = require("./approval-adapters");
122
126
  const approval_queue_1 = require("../governance/approval-queue");
123
127
  const approval_grants_1 = require("../governance/approval-grants");
124
128
  const ledger_store_1 = require("../governance/ledger-store");
@@ -437,8 +441,11 @@ function makeChangeSource(root, a) {
437
441
  return new change_source_1.GitChangeSource(root, a.base, a.head);
438
442
  // @implements A-SPEC-134 — verify against the provenance chain so a tampered baseline degrades to
439
443
  // full scope instead of narrowing against a forged reference point.
444
+ // A-SPEC-733 (round 12): the ignore file is loaded ONCE, not re-read and re-parsed per path (measured:
445
+ // a planted 2 MB `.gitignore` cost 443 ms per path here).
446
+ const ignore = (0, ignore_1.loadIgnore)(root);
440
447
  return new change_source_1.SnapshotChangeSource(root, a.since ?? DEFAULT_BASELINE, {
441
- isIgnored: (p) => (0, ignore_1.loadIgnore)(root).isIgnored(p),
448
+ isIgnored: (p) => ignore.isIgnored(p),
442
449
  verify: path.join(root, '.ax', 'ledger', 'provenance.jsonl'),
443
450
  });
444
451
  }
@@ -678,6 +685,50 @@ function collectDecisions(root, scanned, specs) {
678
685
  return { decisions, citations };
679
686
  }
680
687
  function makeRawHandlers(store, opts) {
688
+ // These values are process/session scoped and intentionally never reach disk or config. A
689
+ // restarted MCP process invalidates every pending host-gated continuation.
690
+ const approvalContinuations = opts?.approvalSession?.continuations ?? new approval_commit_1.ApprovalContinuationStore();
691
+ const approvalRunId = opts?.approvalSession?.runId ?? crypto.randomUUID();
692
+ // @implements A-SPEC-732 (round 2) — exact names: `my-claude-helper` is not Claude Code.
693
+ const HARNESS_NAMES = {
694
+ 'claude-code': 'claude', claude: 'claude', 'codex-mcp-client': 'codex', codex: 'codex',
695
+ 'antigravity-client': 'antigravity', antigravity: 'antigravity', agy: 'antigravity',
696
+ };
697
+ const canonicalHarness = () => {
698
+ const raw = opts?.clientName?.().trim().toLowerCase() ?? 'unknown';
699
+ return HARNESS_NAMES[raw] ?? raw;
700
+ };
701
+ const attestation = () => {
702
+ try {
703
+ return opts?.harnessAttestation?.() ?? { attested: true };
704
+ }
705
+ catch {
706
+ return { attested: false, reason: 'the server could not tell who launched it' };
707
+ }
708
+ };
709
+ // @implements A-SPEC-732 (round 2) — no in-session route when the operator turned forms off or when
710
+ // no harness launched this server: the queue is the only door.
711
+ const approvalAdapter = () => ((0, elicit_approval_1.elicitationDisabled)(process.env) || !attestation().attested
712
+ ? (0, approval_adapters_1.selectApprovalAdapter)({ harness: 'unattested', formElicitation: false })
713
+ : (0, approval_adapters_1.selectApprovalAdapter)({
714
+ harness: canonicalHarness(),
715
+ formElicitation: opts?.elicitationAvailable?.() ?? Boolean(opts?.elicit),
716
+ }));
717
+ const approvalWorkspace = (root) => projectRootOf(root ?? store.specsRoot);
718
+ const prepareHostApproval = (input) => {
719
+ // @implements A-SPEC-732 — `root` only resolves the workspace; it is not an intent field. Spreading
720
+ // it in made a rootless call (the way harnesses call spec_approve) fail with "root is required".
721
+ const intent = (0, approval_intent_1.createApprovalIntent)({
722
+ kind: input.kind, target: input.target, subject: input.subject,
723
+ workspace: approvalWorkspace(input.root), runId: approvalRunId, harness: canonicalHarness(),
724
+ });
725
+ approvalContinuations.prepare(intent);
726
+ return intent;
727
+ };
728
+ const consumeHostApproval = (input) => approvalContinuations.consumeForAction({
729
+ kind: input.kind, target: input.target, subject: input.subject,
730
+ workspace: approvalWorkspace(input.root), runId: approvalRunId,
731
+ });
681
732
  // @implements A-SPEC-100.2, A-SPEC-102.1, A-SPEC-111.1, A-SPEC-121.2, A-SPEC-121.3, A-SPEC-121.4, A-SPEC-128, A-SPEC-130, A-SPEC-131, A-SPEC-189, A-SPEC-233, A-SPEC-419, A-SPEC-433, A-SPEC-614
682
733
  // @implements A-SPEC-616, A-SPEC-100.2, A-SPEC-102.1, A-SPEC-121.2, A-SPEC-121.3, A-SPEC-128, A-SPEC-130, A-SPEC-189, A-SPEC-233, A-SPEC-419, A-SPEC-433, A-SPEC-534.5, A-SPEC-534.8, A-SPEC-578.4, A-SPEC-614
683
734
  const testExecution = (0, test_execution_1.createTestExecutionHandlers)({
@@ -724,6 +775,7 @@ function makeRawHandlers(store, opts) {
724
775
  cachedScan,
725
776
  assertStoreReachable: (tool, root) => assertSpecStoreReachable(tool, store, root),
726
777
  refusal: reason => new HandlerRefusal(reason),
778
+ requestFreshness: rtm_refresh_1.requestBackgroundFreshness,
727
779
  });
728
780
  const resolver = (specs) => (id) => specs.find((s) => s.id === id) ?? null;
729
781
  // @implements A-SPEC-100.2, A-SPEC-128, A-SPEC-138, A-SPEC-140.2, A-SPEC-189, A-SPEC-461, A-SPEC-512.2, A-SPEC-513.1, A-SPEC-524.1
@@ -758,16 +810,18 @@ function makeRawHandlers(store, opts) {
758
810
  // other failure mode (no channel, wrong kind, a throwing elicitor) is `silent`, whose refusal
759
811
  // stays byte-identical to the pre-elicitation one — nothing is ever worse than before the
760
812
  // channel existed.
761
- const tryElicit = async (kind, target, summary) => {
813
+ const tryElicit = async (kind, target, summary, timeoutBehavior = 'queue') => {
762
814
  // @implements A-SPEC-540.1 — operator opt-out: with HOLMES_ELICIT=off the server never shows the
763
815
  // in-client prompt, folding to the byte-identical `silent` (refuse+enqueue) path so claude/agy/
764
816
  // codex all converge on one out-of-band surface (holmes-kit approve). Unset ⇒ unchanged.
765
817
  if ((0, elicit_approval_1.elicitationDisabled)(process.env))
766
818
  return { kind: 'silent' };
819
+ if (!attestation().attested)
820
+ return { kind: 'silent' };
767
821
  if (!opts?.elicit || !elicit_approval_1.ELICITABLE_KINDS.has(kind))
768
822
  return { kind: 'silent' };
769
823
  try {
770
- return await opts.elicit({ kind, target, summary });
824
+ return await opts.elicit({ kind, target, summary, timeoutBehavior });
771
825
  }
772
826
  catch {
773
827
  return { kind: 'silent' };
@@ -776,10 +830,24 @@ function makeRawHandlers(store, opts) {
776
830
  // A granted answer becomes a synthesized Approval that rides the EXISTING seal path unchanged —
777
831
  // the ledger's authorizationRef then honestly names the channel (`elicitation:<client>`), and
778
832
  // single-use is structural: the object exists only inside this call, persisted nowhere.
779
- const elicitApproval = (reason) => ({
780
- actor: `elicitation:${opts?.clientName?.() ?? 'unknown'}`,
833
+ const elicitApproval = (reason) => {
834
+ const chain = attestation().chain;
835
+ return {
836
+ actor: `elicitation:${opts?.clientName?.() ?? 'unknown'}`,
837
+ token: crypto.randomUUID(),
838
+ // @implements A-SPEC-732 (round 2) — the attested launcher chain rides the audit line.
839
+ rationale: `${reason ?? 'elicitation grant'}${chain && chain.length > 0 ? ` [launched by ${chain.join(' <- ')}]` : ''}`,
840
+ };
841
+ };
842
+ // @implements A-SPEC-532.2 — the autonomous channel: the SAME synthesized-Approval shape that
843
+ // rides the existing seal path, but its actor names `autonomous:<client>` so an audit can tell a
844
+ // self-approved seal from a human-approved (elicitation) or operator (env/grant) one. Single-use
845
+ // by construction — it exists only inside this call, persisted nowhere.
846
+ const autonomousApproval = (derivedFrom, source = 'immediate') => ({
847
+ actor: `${source === 'timeout' ? 'autonomous-timeout' : 'autonomous'}:${opts?.clientName?.() ?? 'unknown'}`,
781
848
  token: crypto.randomUUID(),
782
- rationale: reason ?? 'elicitation grant',
849
+ // @implements A-SPEC-587 — an upstream grade is DERIVED; the audit line names the A-SPECs it came from.
850
+ rationale: `autonomous grant (${'HOLMES_AUTONOMOUS_APPROVAL'} enabled, ${source === 'timeout' ? 'in-session approval timeout' : 'spec grade auto'}${derivedFrom && derivedFrom.length > 0 ? ` — derived from ${derivedFrom.join(', ')}` : ''})`,
783
851
  });
784
852
  // @implements A-SPEC-617, A-SPEC-100.2, A-SPEC-102.1, A-SPEC-133, A-SPEC-135, A-SPEC-141, A-SPEC-157, A-SPEC-160, A-SPEC-189, A-SPEC-191, A-SPEC-244, A-SPEC-245, A-SPEC-263.1, A-SPEC-497.1
785
853
  const reviewEvidence = (0, review_evidence_1.createReviewEvidenceHandlers)({
@@ -792,22 +860,18 @@ function makeRawHandlers(store, opts) {
792
860
  hasElicitor: () => Boolean(opts?.elicit),
793
861
  tryElicit,
794
862
  elicitApproval,
863
+ autonomousApproval,
795
864
  resolveHandlerApproval: (root, approval, action, now) => resolveHandlerApproval(root, store, approval, action, now),
796
865
  refusalQueueHint: (root, request) => refusalQueueHint(root, store, request),
797
866
  });
798
- // @implements A-SPEC-532.2 — the autonomous channel: the SAME synthesized-Approval shape that
799
- // rides the existing seal path, but its actor names `autonomous:<client>` so an audit can tell a
800
- // self-approved seal from a human-approved (elicitation) or operator (env/grant) one. Single-use
801
- // by construction — it exists only inside this call, persisted nowhere.
802
- const autonomousApproval = (derivedFrom) => ({
803
- actor: `autonomous:${opts?.clientName?.() ?? 'unknown'}`,
804
- token: crypto.randomUUID(),
805
- // @implements A-SPEC-587 — an upstream grade is DERIVED; the audit line names the A-SPECs it came from.
806
- rationale: `autonomous grant (${'HOLMES_AUTONOMOUS_APPROVAL'} enabled, spec grade auto${derivedFrom && derivedFrom.length > 0 ? ` — derived from ${derivedFrom.join(', ')}` : ''})`,
807
- });
808
867
  // @implements A-SPEC-622, A-SPEC-100.2, A-SPEC-128, A-SPEC-132, A-SPEC-133, A-SPEC-151, A-SPEC-188, A-SPEC-189, A-SPEC-244, A-SPEC-245
809
868
  const specApproval = (0, spec_approval_1.createSpecApprovalHandlers)({
810
869
  store, resolver, projectRootOf, cachedScan, tryElicit, elicitApproval, autonomousApproval,
870
+ approvalAdapter,
871
+ approvalHarness: canonicalHarness,
872
+ approvalRouteNote: () => { const at = attestation(); return at.attested ? '' : `\n[in-session approval unavailable: ${at.reason ?? 'not launched by a harness'}]`; },
873
+ prepareHostApproval,
874
+ consumeHostApproval,
811
875
  resolveHandlerApproval: (root, approval, action, now) => resolveHandlerApproval(root, store, approval, action, now),
812
876
  refusalQueueHint: (root, request) => refusalQueueHint(root, store, request),
813
877
  foreignRootReason: (root) => foreignRootReason(store, root),
@@ -892,7 +956,28 @@ function makeRawHandlers(store, opts) {
892
956
  const sliceOrchestration = (0, slice_orchestration_1.createSliceOrchestrationHandlers)({
893
957
  listSpecs: () => store.list(),
894
958
  unreadableAmong,
895
- rawHandlersForStore: rawStore => makeRawHandlers(rawStore),
959
+ // @implements A-SPEC-732 (round 3) — no options here meant no elicitor, client "unknown" and a
960
+ // private continuation store: the slice asked 0 times and offered no intent.
961
+ rawHandlersForStore: rawStore => makeRawHandlers(rawStore, { ...opts, approvalSession: { continuations: approvalContinuations, runId: approvalRunId } }),
962
+ // @implements A-SPEC-732 (round 4) — measured: `root:P2` or a cwd of P3 made the slice ask the
963
+ // session's form and seal P2's/P3's spec. The bound store decides; another project is refused.
964
+ sliceStore: (root) => {
965
+ const refusal = foreignRootReason(store, root);
966
+ if (refusal)
967
+ return { refusal };
968
+ // A bound store that anchors a project decides; one that does not (a fresh tree, no `.ax` yet)
969
+ // has nothing to compare against — the same rule foreignRootReason applies.
970
+ if (store instanceof spec_store_1.LocalMarkdownRepository) {
971
+ try {
972
+ const derived = projectRootOf(store.specsRoot);
973
+ if (fs.existsSync(path.join(derived, '.ax')))
974
+ return { store, root: derived };
975
+ }
976
+ catch { /* unanchored: fall through */ }
977
+ }
978
+ const r = root ? (0, root_1.resolveProjectRoot)(root).root : process.cwd();
979
+ return { store: new spec_store_1.LocalMarkdownRepository(path.join(r, '.ax', 'specs')), root: r };
980
+ },
896
981
  });
897
982
  // @implements A-SPEC-126, A-SPEC-129, A-SPEC-181, A-SPEC-182, A-SPEC-184, A-SPEC-188, A-SPEC-189, A-SPEC-299
898
983
  // Adoption contracts retain their shared root and configured-store obligations here.
@@ -979,5 +1064,11 @@ function makeRawHandlers(store, opts) {
979
1064
  };
980
1065
  },
981
1066
  }),
1067
+ // The client must render this sensitive invocation before it reaches the server. The handler
1068
+ // still validates every server-derived binding; a tool argument alone is never authority.
1069
+ // Kept at the unpinned tail: historical public-neighbour order remains a wire contract.
1070
+ // @implements A-SPEC-732 (round 2) — a missing or malformed intent is refused, never thrown.
1071
+ approval_commit: async (a) => (a && typeof a === 'object' && !Array.isArray(a)
1072
+ ? approvalContinuations.commit(a) : { ok: false, reason: 'approval_commit needs the approvalIntent object spec_approve returned' }),
982
1073
  };
983
1074
  }
@@ -0,0 +1,20 @@
1
+ /** `image` is the real executable (symlinks resolved); absent when it could not be read. */
2
+ export interface ProcRow {
3
+ pid: number;
4
+ ppid: number;
5
+ args: string;
6
+ image?: string;
7
+ /** The executable path on its own (`ps -o comm=`, Windows ExecutablePath) — unambiguous where args are not. */
8
+ exe?: string;
9
+ }
10
+ export type ProcLookup = (pid: number) => ProcRow | null;
11
+ export interface HarnessAttestation {
12
+ attested: boolean;
13
+ chain: string[];
14
+ harness?: string;
15
+ reason?: string;
16
+ }
17
+ /** Walk up from `pid` (the server's parent) through launchers to a harness executable. */
18
+ export declare function attestHarness(pid: number, lookup: ProcLookup, maxDepth?: number): HarnessAttestation;
19
+ /** The live process table: `ps` on POSIX, CIM through PowerShell on Windows. Null when unreadable. */
20
+ export declare function systemProcLookup(platform?: NodeJS.Platform): ProcLookup;
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.attestHarness = attestHarness;
37
+ exports.systemProcLookup = systemProcLookup;
38
+ // @implements A-SPEC-732
39
+ // In-session approval (a form, or the host-gated continuation) trusts the client that answers it. An
40
+ // agent can start its own copy of this server, name itself `claude-code` and answer for a person
41
+ // (measured, H7 round 1). So before offering either route, the server asks who launched it: the
42
+ // harness itself, possibly through the launchers the harnesses use (`npm exec`/`npx`, the holmes-mcp
43
+ // autoreload supervisor). Measured chains on macOS: node ← claude, node ← codex, node ← agy,
44
+ // node ← npm exec … ← claude. Anything else — or a process table that cannot be read — is not a
45
+ // harness, and the request goes to the operator queue.
46
+ //
47
+ // Round 4 (measured): the argv name alone was forgeable — a symlink named `claude` to node, ARGV0,
48
+ // process.title. The harness row must also show its REAL executable image. Round 5: that image must
49
+ // positively be the harness's own executable (see imageIsHarness).
50
+ const fs = __importStar(require("node:fs"));
51
+ const path = __importStar(require("node:path"));
52
+ const node_child_process_1 = require("node:child_process");
53
+ const HARNESS_EXES = new Set(['claude', 'codex', 'agy', 'antigravity']);
54
+ const imageName = (image) => path.win32.basename(path.posix.basename(image)).toLowerCase().replace(/\.exe$/, '');
55
+ /** `agy` and `antigravity` name the same harness. */
56
+ const IMAGE_NAMES = { claude: ['claude'], codex: ['codex'], agy: ['agy', 'antigravity'], antigravity: ['agy', 'antigravity'] };
57
+ /** The native Claude installer keeps each version as `…/claude/versions/<version>` (measured 2.1.281). */
58
+ const CLAUDE_NATIVE_LAYOUT = /[\\/]claude[\\/]versions[\\/]\d+(?:\.\d+)+(?:\.exe)?$/i;
59
+ /**
60
+ * @implements A-SPEC-732 (round 5) — the image must BE the harness: "not an interpreter" let any
61
+ * system binary started with argv0 `claude` (`/usr/bin/time`, `find -exec`, `awk system()`) attest,
62
+ * and a forged client sealed a REQ through the form (measured). Named residual: a binary copied or
63
+ * hard-linked under a harness's name or layout still attests; a code-signature check was declined.
64
+ */
65
+ function imageIsHarness(image, harness) {
66
+ if ((IMAGE_NAMES[harness] ?? []).includes(imageName(image)))
67
+ return true;
68
+ return harness === 'claude' && CLAUDE_NATIVE_LAYOUT.test(image);
69
+ }
70
+ const firstToken = (args) => {
71
+ const t = args.trim();
72
+ if (t.startsWith('"')) {
73
+ const end = t.indexOf('"', 1);
74
+ return end > 0 ? t.slice(1, end) : t.slice(1);
75
+ }
76
+ return t.split(/\s+/)[0] ?? '';
77
+ };
78
+ const exeName = (args) => path.win32.basename(path.posix.basename(firstToken(args))).toLowerCase().replace(/\.exe$/, '');
79
+ function harnessOf(args, exe) {
80
+ const name = exeName(args);
81
+ if (HARNESS_EXES.has(name))
82
+ return name;
83
+ // @implements A-SPEC-732 (round 6) — a harness under a path with spaces (Claude Desktop's
84
+ // `…/Application Support/…/claude`) split at the first space and read as `application` (measured).
85
+ if (typeof exe === 'string' && exe !== '') {
86
+ const fromExe = path.win32.basename(path.posix.basename(exe)).toLowerCase().replace(/\.exe$/, '');
87
+ if (HARNESS_EXES.has(fromExe))
88
+ return fromExe;
89
+ }
90
+ return null;
91
+ }
92
+ /** The launchers a harness starts the server through; a plain `node <script>` is not one. */
93
+ function isLauncher(args) {
94
+ if (/^npm exec\b/.test(args.trim()))
95
+ return true; // npm's process title
96
+ const name = exeName(args);
97
+ if (name === 'npm' || name === 'npx')
98
+ return true;
99
+ if (name === 'node' || name === 'nodejs') {
100
+ return /[\\/](?:npm|npx)-cli\.js\b|[\\/]bin[\\/]npx\b|[\\/]bin[\\/]holmes-mcp(?:\.js)?\b/.test(args);
101
+ }
102
+ return false;
103
+ }
104
+ /** Walk up from `pid` (the server's parent) through launchers to a harness executable. */
105
+ function attestHarness(pid, lookup, maxDepth = 8) {
106
+ const chain = [];
107
+ const seen = new Set();
108
+ let cur = pid;
109
+ for (let depth = 0; depth < maxDepth; depth++) {
110
+ if (seen.has(cur))
111
+ return { attested: false, chain, reason: 'launcher chain loops' };
112
+ seen.add(cur);
113
+ const row = lookup(cur);
114
+ if (row === null)
115
+ return { attested: false, chain, reason: 'the process table could not be read' };
116
+ const harness = harnessOf(row.args, row.exe);
117
+ const shown = harness ?? (exeName(row.args) || '?');
118
+ chain.push(shown);
119
+ if (harness !== null) {
120
+ if (typeof row.image !== 'string' || row.image === '') {
121
+ return { attested: false, chain, reason: `the executable image of ${shown} could not be read` };
122
+ }
123
+ if (!imageIsHarness(row.image, harness)) {
124
+ return { attested: false, chain, reason: `${shown} is really ${imageName(row.image)} (${row.image}), not the ${harness} executable` };
125
+ }
126
+ return { attested: true, chain, harness };
127
+ }
128
+ if (!isLauncher(row.args))
129
+ return { attested: false, chain, reason: `the server's parent ${shown} is not a harness (${row.args.slice(0, 80)})` };
130
+ cur = row.ppid;
131
+ }
132
+ return { attested: false, chain, reason: 'launcher chain too deep' };
133
+ }
134
+ /** The live process table: `ps` on POSIX, CIM through PowerShell on Windows. Null when unreadable. */
135
+ function systemProcLookup(platform = process.platform) {
136
+ return (pid) => {
137
+ try {
138
+ if (platform === 'win32') {
139
+ const r = (0, node_child_process_1.spawnSync)('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command',
140
+ `$p = Get-CimInstance Win32_Process -Filter "ProcessId=${Math.trunc(pid)}"; if ($p) { "$($p.ParentProcessId)\`t$($p.ExecutablePath)\`t$($p.CommandLine)" }`], { encoding: 'utf8', timeout: 5000, windowsHide: true });
141
+ const m = /^(\d+)\t([^\t]*)\t([\s\S]*)$/.exec((r.stdout ?? '').trim());
142
+ return m ? { pid, ppid: Number(m[1]), args: m[3].trim(), ...(m[2].trim() ? { image: m[2].trim(), exe: m[2].trim() } : {}) } : null;
143
+ }
144
+ const r = (0, node_child_process_1.spawnSync)('ps', ['-o', 'ppid=,args=', '-p', String(Math.trunc(pid))], { encoding: 'utf8', timeout: 5000 });
145
+ const m = /^\s*(\d+)\s+([\s\S]*)$/.exec((r.stdout ?? '').trim());
146
+ if (!m)
147
+ return null;
148
+ const row = { pid, ppid: Number(m[1]), args: m[2].trim() };
149
+ // Round 6: the executable path alone (macOS prints it whole; Linux its name) — no args to split.
150
+ const comm = (0, node_child_process_1.spawnSync)('ps', ['-o', 'comm=', '-p', String(Math.trunc(pid))], { encoding: 'utf8', timeout: 5000 });
151
+ const exe = (comm.stdout ?? '').trim();
152
+ if (exe !== '')
153
+ row.exe = exe;
154
+ // The image costs a process spawn on macOS: read it only for a row that names a harness.
155
+ if (harnessOf(row.args, row.exe) !== null) {
156
+ const image = imageOf(pid, platform);
157
+ if (image !== undefined)
158
+ row.image = image;
159
+ }
160
+ return row;
161
+ }
162
+ catch {
163
+ return null;
164
+ }
165
+ };
166
+ }
167
+ /** The real executable of `pid`: Linux `/proc/<pid>/exe`, macOS the `txt` descriptor from lsof. */
168
+ function imageOf(pid, platform) {
169
+ try {
170
+ if (platform === 'linux')
171
+ return fs.readlinkSync(`/proc/${Math.trunc(pid)}/exe`);
172
+ const r = (0, node_child_process_1.spawnSync)('lsof', ['-a', '-p', String(Math.trunc(pid)), '-d', 'txt', '-Fn'], { encoding: 'utf8', timeout: 5000 });
173
+ const line = (r.stdout ?? '').split('\n').find((l) => l.startsWith('n'));
174
+ return line ? line.slice(1) : undefined;
175
+ }
176
+ catch {
177
+ return undefined;
178
+ }
179
+ }