@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
@@ -0,0 +1,108 @@
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.ApprovalContinuationStore = void 0;
37
+ // @implements A-SPEC-718, A-SPEC-732
38
+ const crypto = __importStar(require("node:crypto"));
39
+ const approval_intent_1 = require("./approval-intent");
40
+ /**
41
+ * Memory-only continuations deliberately die with the MCP session. A rejected or malformed
42
+ * commit never burns a valid pending intent; only an exact, live host-gated commit can be consumed
43
+ * by the original action, exactly once.
44
+ */
45
+ /** Live pending intents kept per session; the oldest leaves first. */
46
+ const MAX_PENDING = 256;
47
+ class ApprovalContinuationStore {
48
+ pending = new Map();
49
+ committed = new Map();
50
+ prepare(intent, now = new Date()) {
51
+ // @implements A-SPEC-732 (round 3) — refused host-gated calls left ~800 bytes each, forever:
52
+ // the only deletion was a successful commit. Expired intents can never commit or be consumed.
53
+ const expired = (i) => Date.parse(i.expiresAt) <= now.getTime();
54
+ for (const [id, i] of this.pending)
55
+ if (expired(i))
56
+ this.pending.delete(id);
57
+ for (const [id, i] of this.committed)
58
+ if (expired(i))
59
+ this.committed.delete(id);
60
+ while (this.pending.size >= MAX_PENDING)
61
+ this.pending.delete(this.pending.keys().next().value);
62
+ this.pending.set(intent.id, intent);
63
+ }
64
+ size() {
65
+ return { pending: this.pending.size, committed: this.committed.size };
66
+ }
67
+ commit(candidate, now = new Date()) {
68
+ const pending = this.pending.get(candidate.id);
69
+ if (!pending)
70
+ return { ok: false, reason: 'unknown-or-consumed-intent' };
71
+ const binding = candidate;
72
+ const failure = (0, approval_intent_1.intentBindingFailure)(pending, binding, now);
73
+ if (failure !== null)
74
+ return { ok: false, reason: failure };
75
+ this.pending.delete(candidate.id);
76
+ this.committed.set(candidate.id, pending);
77
+ return { ok: true };
78
+ }
79
+ consume(candidate, now = new Date()) {
80
+ const committed = this.committed.get(candidate.id);
81
+ if (!committed || (0, approval_intent_1.intentBindingFailure)(committed, candidate, now) !== null)
82
+ return undefined;
83
+ this.committed.delete(candidate.id);
84
+ return {
85
+ actor: `host-gated:${committed.harness}`,
86
+ token: crypto.randomUUID(),
87
+ rationale: `host-gated in-session approval for ${committed.kind} ${committed.target}`,
88
+ };
89
+ }
90
+ /** The retried original action has no authority fields; match only server-derived action identity. */
91
+ consumeForAction(candidate, now = new Date()) {
92
+ for (const intent of this.committed.values()) {
93
+ if (Date.parse(intent.expiresAt) <= now.getTime())
94
+ continue;
95
+ if (intent.kind !== candidate.kind || intent.target !== candidate.target || intent.subject !== candidate.subject
96
+ || intent.workspace !== candidate.workspace || intent.runId !== candidate.runId)
97
+ continue;
98
+ this.committed.delete(intent.id);
99
+ return {
100
+ actor: `host-gated:${intent.harness}`,
101
+ token: crypto.randomUUID(),
102
+ rationale: `host-gated in-session approval for ${intent.kind} ${intent.target}`,
103
+ };
104
+ }
105
+ return undefined;
106
+ }
107
+ }
108
+ exports.ApprovalContinuationStore = ApprovalContinuationStore;
@@ -0,0 +1,44 @@
1
+ export type ApprovalPresentationResult = {
2
+ kind: 'approve';
3
+ reason?: string;
4
+ } | {
5
+ kind: 'deny';
6
+ reason?: string;
7
+ } | {
8
+ kind: 'question';
9
+ reason: string;
10
+ } | {
11
+ kind: 'cancel';
12
+ } | {
13
+ kind: 'timeout';
14
+ } | {
15
+ kind: 'malformed';
16
+ } | {
17
+ kind: 'unavailable';
18
+ };
19
+ export interface ApprovalIntent {
20
+ id: string;
21
+ challenge: string;
22
+ kind: string;
23
+ target: string;
24
+ subject: string;
25
+ workspace: string;
26
+ runId: string;
27
+ harness: string;
28
+ expiresAt: string;
29
+ }
30
+ export interface ApprovalIntentInput {
31
+ kind: string;
32
+ target: string;
33
+ subject: string;
34
+ workspace: string;
35
+ runId: string;
36
+ harness: string;
37
+ now?: Date;
38
+ ttlMs?: number;
39
+ }
40
+ /** Create an opaque, single-use action identity. The caller owns storage and consumption. */
41
+ export declare function createApprovalIntent(input: ApprovalIntentInput): ApprovalIntent;
42
+ export type IntentBinding = Pick<ApprovalIntent, 'challenge' | 'kind' | 'target' | 'subject' | 'workspace' | 'runId'>;
43
+ /** Verify every server-derived binding before an intent is consumed. */
44
+ export declare function intentBindingFailure(intent: ApprovalIntent, candidate: IntentBinding, now?: Date): string | null;
@@ -0,0 +1,67 @@
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.createApprovalIntent = createApprovalIntent;
37
+ exports.intentBindingFailure = intentBindingFailure;
38
+ // @implements A-SPEC-718
39
+ const crypto = __importStar(require("node:crypto"));
40
+ /** Create an opaque, single-use action identity. The caller owns storage and consumption. */
41
+ function createApprovalIntent(input) {
42
+ const now = input.now ?? new Date();
43
+ const ttlMs = input.ttlMs ?? 120_000;
44
+ if (!Number.isFinite(ttlMs) || ttlMs <= 0)
45
+ throw new Error('approval intent ttl must be positive');
46
+ for (const [name, value] of Object.entries(input)) {
47
+ if (['now', 'ttlMs'].includes(name))
48
+ continue;
49
+ if (typeof value !== 'string' || value.trim() === '')
50
+ throw new Error(`approval intent ${name} is required`);
51
+ }
52
+ return {
53
+ id: crypto.randomUUID(), challenge: crypto.randomBytes(32).toString('base64url'),
54
+ kind: input.kind, target: input.target, subject: input.subject, workspace: input.workspace,
55
+ runId: input.runId, harness: input.harness, expiresAt: new Date(now.getTime() + ttlMs).toISOString(),
56
+ };
57
+ }
58
+ /** Verify every server-derived binding before an intent is consumed. */
59
+ function intentBindingFailure(intent, candidate, now = new Date()) {
60
+ if (Date.parse(intent.expiresAt) <= now.getTime())
61
+ return 'expired';
62
+ for (const key of ['challenge', 'kind', 'target', 'subject', 'workspace', 'runId']) {
63
+ if (candidate[key] !== intent[key])
64
+ return `mismatched-${key}`;
65
+ }
66
+ return null;
67
+ }
@@ -0,0 +1,14 @@
1
+ import { ApprovalPresentationResult } from './approval-intent';
2
+ export type ApprovalPolicyDecision = {
3
+ kind: 'approved';
4
+ actor: string;
5
+ reason?: string;
6
+ } | {
7
+ kind: 'hold';
8
+ reason: string;
9
+ };
10
+ /** The sole response transition table; timeout is never a synonym for cancel or deny. */
11
+ export declare function resolveApprovalPresentation(result: ApprovalPresentationResult, options: {
12
+ autonomous: boolean;
13
+ harness: string;
14
+ }): ApprovalPolicyDecision;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveApprovalPresentation = resolveApprovalPresentation;
4
+ /** The sole response transition table; timeout is never a synonym for cancel or deny. */
5
+ function resolveApprovalPresentation(result, options) {
6
+ const harness = options.harness.trim() || 'unknown';
7
+ switch (result.kind) {
8
+ case 'approve': return { kind: 'approved', actor: `elicitation:${harness}`, ...(result.reason ? { reason: result.reason } : {}) };
9
+ case 'timeout': return options.autonomous
10
+ ? { kind: 'approved', actor: `autonomous-timeout:${harness}`, reason: 'in-session approval timeout' }
11
+ : { kind: 'hold', reason: 'approval prompt timed out' };
12
+ case 'deny': return { kind: 'hold', reason: result.reason ? `denied: ${result.reason}` : 'denied' };
13
+ case 'question': return { kind: 'hold', reason: `question: ${result.reason}` };
14
+ case 'cancel': return { kind: 'hold', reason: 'cancelled' };
15
+ case 'malformed': return { kind: 'hold', reason: 'malformed response' };
16
+ case 'unavailable': return { kind: 'hold', reason: 'in-session approval unavailable' };
17
+ }
18
+ }
@@ -34,6 +34,8 @@ export interface ElicitApprovalRequest {
34
34
  target: string;
35
35
  /** Human-facing one-liner: what is being approved (id, title, sealed-or-not). */
36
36
  summary: string;
37
+ /** Server-derived outcome wording; only explicit autonomy may select automatic approval. */
38
+ timeoutBehavior?: 'queue' | 'autonomous-approve';
37
39
  }
38
40
  /** The human's decision. `null` from interpretElicitResult means "no answer in this shape". */
39
41
  export interface ElicitDecision {
@@ -9,7 +9,7 @@ exports.buildDecisionForm = buildDecisionForm;
9
9
  exports.buildReasonForm = buildReasonForm;
10
10
  exports.runElicitFlow = runElicitFlow;
11
11
  exports.interpretElicitResult = interpretElicitResult;
12
- // @implements A-SPEC-263.1
12
+ // @implements A-SPEC-718, A-SPEC-263.1, A-SPEC-732
13
13
  const npx_bin_1 = require("../project/npx-bin");
14
14
  /**
15
15
  * The decision comes INTO the session (REQ-263): an approval-shaped refusal (spec_approve without a
@@ -108,11 +108,14 @@ const flat = (s, max) => s.replace(/[\u0000-\u001f\u007f\u0085\u2028\u2029\u200b
108
108
  */
109
109
  function buildDecisionForm(req, attempt, timeoutMs) {
110
110
  const redisplay = attempt > 1 ? `⚠ 재표시 ${attempt}/${exports.MAX_PRESENTATIONS} — 이전 다이얼로그는 만료되어 무효입니다\n` : '';
111
+ const timeoutNotice = req.timeoutBehavior === 'autonomous-approve'
112
+ ? `⏱ ${timeoutMs / 1000}초 내 미결정 시 이 요청만 자동 승인됩니다(autonomous mode).`
113
+ : `⏱ ${timeoutMs / 1000}초 내 미결정 시 승인 큐로 회송됩니다(운영자: ${(0, npx_bin_1.npxBin)()} holmes-kit approve).`;
111
114
  return {
112
115
  // @implements A-SPEC-497.1 — the forewarning is the LAST line and template-owned: it survives a
113
116
  // cap-filling summary (appended after the caps) and tells the human, before the clock runs out,
114
117
  // where an undecided request goes and where the decision still lives.
115
- message: `${redisplay}[Holmes-Kit 승인 요청] ${flat(req.kind, 40)} — ${flat(req.target, 80)}\n${flat(req.summary, 200)}\n승인(approve) / 거부(deny) / 질문(question) 을 선택하세요. 사유는 거부·질문을 고르면 이어서 묻습니다.\n⏱ ${timeoutMs / 1000}초 내 미결정 시 승인 큐로 회송됩니다(운영자: ${(0, npx_bin_1.npxBin)()} holmes-kit approve).`,
118
+ message: `${redisplay}[Holmes-Kit 승인 요청] ${flat(req.kind, 40)} — ${flat(req.target, 80)}\n${flat(req.summary, 200)}\n승인(approve) / 거부(deny) / 질문(question) 을 선택하세요. 사유는 거부·질문을 고르면 이어서 묻습니다.\n${timeoutNotice}`,
116
119
  requestedSchema: {
117
120
  type: 'object',
118
121
  properties: {
@@ -211,8 +214,10 @@ async function collectReason(raw, decision) {
211
214
  function interpretElicitResult(r) {
212
215
  if (!r || typeof r !== 'object')
213
216
  return null;
217
+ // @implements A-SPEC-732 — the protocol cannot tell a person's decline from a client that declines
218
+ // forms automatically (codex exec, measured 2026-09-24), so the reason names both and the fallback.
214
219
  if (r.action === 'decline')
215
- return { granted: false, reason: '사람이 세션에서 거절했습니다(decline)' };
220
+ return { granted: false, reason: 'the session client declined the approval form (decline) — a person declined, or a client that cannot show forms (e.g. codex exec) declined automatically. If nobody saw the form, set HOLMES_ELICIT=off in the holmes-kit MCP server environment and decide with holmes-kit approve' };
216
221
  if (r.action !== 'accept')
217
222
  return null; // cancel, absent, anything else: no decision
218
223
  const content = r.content;
@@ -42,6 +42,20 @@ export type SemanticWarmOutcome = {
42
42
  status: 'unavailable';
43
43
  tier: string;
44
44
  };
45
+ /** Durable outcome for the background source-vector lane. `null` would conflate owner non-adoption,
46
+ * an explicit suppression, and an unavailable embedder — each has a different recovery contract. */
47
+ export type SourceSemanticRefreshOutcome = {
48
+ lane: 'current';
49
+ coverage: PersistedCoverage;
50
+ } | {
51
+ lane: 'not-adopted';
52
+ } | {
53
+ lane: 'suppressed';
54
+ coverage: PersistedCoverage;
55
+ } | {
56
+ lane: 'failed';
57
+ reason: 'unavailable' | 'failed';
58
+ };
45
59
  /**
46
60
  * @implements A-SPEC-478 — the semantic cache WARMING lives in explicit heavy operations, so the
47
61
  * ranking hot path only ever LOOKS UP vectors. Idempotent through the cache. The outcome says
@@ -51,6 +65,8 @@ export type SemanticWarmOutcome = {
51
65
  export declare function warmSemanticCache(root: string, scanned: readonly ScannedFile[]): Promise<SemanticWarmOutcome>;
52
66
  /** Requirement prose is warmed only by the explicit reindex operation. */
53
67
  export declare function warmRequirementSemanticCache(root: string, specs: readonly Spec[]): Promise<SemanticWarmOutcome>;
68
+ /** The commit the verdict describes. null when this is not a Git tree — never a fabricated value. */
69
+ export declare function headOf(root: string): string | null;
54
70
  /**
55
71
  * @implements A-SPEC-683 — vectors refresh on the channel that keeps the graph fresh.
56
72
  *
@@ -64,7 +80,7 @@ export declare function warmRequirementSemanticCache(root: string, specs: readon
64
80
  * with a switch; silent automatic transfer was considered and refused. `HOLMES_NO_SEMANTIC_WARM`
65
81
  * records SUPPRESSED rather than a failure, so an owner who turned it off is never shown a fault.
66
82
  */
67
- export declare function refreshSemanticVectors(root: string, env?: NodeJS.ProcessEnv, warm?: (r: string, s: readonly ScannedFile[]) => Promise<SemanticWarmOutcome>, scan?: () => readonly ScannedFile[]): Promise<PersistedCoverage | null>;
83
+ export declare function refreshSemanticVectors(root: string, env?: NodeJS.ProcessEnv, warm?: (r: string, s: readonly ScannedFile[]) => Promise<SemanticWarmOutcome>, scan?: () => readonly ScannedFile[]): Promise<SourceSemanticRefreshOutcome>;
68
84
  export declare function createGraphOperationsHandlers(context: GraphOperationsContext): {
69
85
  rtm_impact(a: {
70
86
  root: string;
@@ -36,8 +36,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.publishCurrentGraph = publishCurrentGraph;
37
37
  exports.warmSemanticCache = warmSemanticCache;
38
38
  exports.warmRequirementSemanticCache = warmRequirementSemanticCache;
39
+ exports.headOf = headOf;
39
40
  exports.refreshSemanticVectors = refreshSemanticVectors;
40
41
  exports.createGraphOperationsHandlers = createGraphOperationsHandlers;
42
+ // @implements A-SPEC-719, A-SPEC-734
41
43
  // @implements A-SPEC-614, A-SPEC-613, A-SPEC-100.2, A-SPEC-121.2, A-SPEC-128, A-SPEC-139, A-SPEC-189, A-SPEC-280, A-SPEC-282, A-SPEC-283, A-SPEC-419, A-SPEC-433, A-SPEC-469, A-SPEC-478, A-SPEC-568.1, A-SPEC-568.2, A-SPEC-569.1, A-SPEC-569.2, A-SPEC-569.3, A-SPEC-589
42
44
  // @implements A-SPEC-632
43
45
  const fs = __importStar(require("node:fs"));
@@ -52,6 +54,7 @@ const trace_gaps_1 = require("../../rtm/trace-gaps");
52
54
  const tier_1 = require("../../semantic/tier");
53
55
  const vector_cache_1 = require("../../semantic/vector-cache");
54
56
  const embedder_1 = require("../../semantic/embedder");
57
+ const bounded_io_1 = require("../../project/bounded-io");
55
58
  const vector_coverage_1 = require("../../semantic/vector-coverage");
56
59
  // @implements A-SPEC-283 — bumped whenever the graph's node/edge shape changes, so a store written
57
60
  // by an older build is rebuilt rather than read with new assumptions.
@@ -126,7 +129,7 @@ async function warmRequirementSemanticCache(root, specs) {
126
129
  function headOf(root) {
127
130
  try {
128
131
  const { execFileSync } = require('node:child_process');
129
- return execFileSync('git', ['-C', root, 'rev-parse', 'HEAD'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || null;
132
+ return execFileSync('git', ['-C', root, 'rev-parse', 'HEAD'], { timeout: bounded_io_1.GIT_TIMEOUT_MS, maxBuffer: bounded_io_1.GIT_MAX_BUFFER, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || null;
130
133
  }
131
134
  catch {
132
135
  return null;
@@ -148,7 +151,7 @@ function headOf(root) {
148
151
  async function refreshSemanticVectors(root, env = process.env, warm = warmSemanticCache, scan) {
149
152
  const tier = (0, tier_1.resolveSemanticTier)();
150
153
  if (tier.tier === 'none')
151
- return null; // never opted in: nothing transferred, nothing said
154
+ return { lane: 'not-adopted' }; // never opted in: nothing transferred
152
155
  const at = new Date().toISOString();
153
156
  const scanned = scan ? scan() : [];
154
157
  const off = typeof env.HOLMES_NO_SEMANTIC_WARM === 'string' && env.HOLMES_NO_SEMANTIC_WARM !== '';
@@ -162,11 +165,17 @@ async function refreshSemanticVectors(root, env = process.env, warm = warmSemant
162
165
  reason: 'suppressed', at, ...(head !== null ? { head } : {}),
163
166
  };
164
167
  (0, vector_coverage_1.writeCoverageState)(root, state);
165
- return state;
168
+ return { lane: 'suppressed', coverage: state };
169
+ }
170
+ let outcome;
171
+ try {
172
+ outcome = await warm(root, scanned);
173
+ }
174
+ catch {
175
+ return { lane: 'failed', reason: 'failed' };
166
176
  }
167
- const outcome = await warm(root, scanned); // throws leave the previous verdict untouched
168
177
  if (outcome.status !== 'discharged')
169
- return null;
178
+ return { lane: 'failed', reason: 'unavailable' };
170
179
  // What LANDED, not what was attempted. Measured 2026-09-19 the warm answered `computed: 603`
171
180
  // while 26 vectors were never stored; a count of attempts reported as a success is the same
172
181
  // class of dishonesty as a tier that says PASS while covering nothing.
@@ -180,7 +189,7 @@ async function refreshSemanticVectors(root, env = process.env, warm = warmSemant
180
189
  ...(headOf(root) !== null ? { head: headOf(root) } : {}),
181
190
  };
182
191
  (0, vector_coverage_1.writeCoverageState)(root, state);
183
- return state;
192
+ return { lane: 'current', coverage: state };
184
193
  }
185
194
  function createGraphOperationsHandlers(context) {
186
195
  return {
@@ -34,7 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.createMaintenanceAnalysisHandlers = createMaintenanceAnalysisHandlers;
37
- // @implements A-SPEC-612, A-SPEC-100.2, A-SPEC-128, A-SPEC-189, A-SPEC-267, A-SPEC-268, A-SPEC-269, A-SPEC-277, A-SPEC-283, A-SPEC-290, A-SPEC-292, A-SPEC-293, A-SPEC-378, A-SPEC-388, A-SPEC-418, A-SPEC-478, A-SPEC-571.2, A-SPEC-573.4, A-SPEC-578.5
37
+ // @implements A-SPEC-612, A-SPEC-100.2, A-SPEC-128, A-SPEC-189, A-SPEC-267, A-SPEC-268, A-SPEC-269, A-SPEC-277, A-SPEC-283, A-SPEC-290, A-SPEC-292, A-SPEC-293, A-SPEC-378, A-SPEC-388, A-SPEC-418, A-SPEC-478, A-SPEC-571.2, A-SPEC-573.4, A-SPEC-578.5, A-SPEC-734
38
38
  const fs = __importStar(require("node:fs"));
39
39
  const path = __importStar(require("node:path"));
40
40
  const node_child_process_1 = require("node:child_process");
@@ -54,6 +54,7 @@ const embedder_1 = require("../../semantic/embedder");
54
54
  const maintenance_analyze_1 = require("../maintenance-analyze");
55
55
  const maintenance_evidence_1 = require("../maintenance-evidence");
56
56
  const defuse_bound_1 = require("../defuse-bound");
57
+ const bounded_io_1 = require("../../project/bounded-io");
57
58
  function createMaintenanceAnalysisHandlers(context) {
58
59
  return {
59
60
  async maintenance_analyze(a) {
@@ -71,21 +72,26 @@ function createMaintenanceAnalysisHandlers(context) {
71
72
  const detail = context.basisFor(root, true);
72
73
  let head = '';
73
74
  try {
74
- head = (0, node_child_process_1.execFileSync)('git', ['-C', root, 'rev-parse', 'HEAD'], { encoding: 'utf8', env: (0, root_1.cleanSubprocessEnv)(), stdio: ['ignore', 'pipe', 'pipe'] }).trim();
75
+ head = (0, node_child_process_1.execFileSync)('git', ['-C', root, 'rev-parse', 'HEAD'], { maxBuffer: bounded_io_1.GIT_MAX_BUFFER, timeout: 5000, encoding: 'utf8', env: (0, root_1.cleanSubprocessEnv)(), stdio: ['ignore', 'pipe', 'pipe'] }).trim();
75
76
  }
76
77
  catch { /* non-git */ }
77
78
  const supportedExtensions = new Set(cpg_scanner_1.SCANNABLE_EXTENSIONS);
78
79
  const knownCodeExtensions = new Set(['.rb', '.php', '.kt', '.kts', '.swift', '.scala', '.sh', '.ex', '.exs', '.lua', '.r']);
79
80
  const unsupportedLanguages = new Set();
80
81
  try {
81
- const files = (0, node_child_process_1.execFileSync)('git', ['-C', root, 'ls-files', '-z', '--cached', '--others', '--exclude-standard'], { encoding: 'utf8', env: (0, root_1.cleanSubprocessEnv)(), maxBuffer: 8 * 1024 * 1024 }).split('\0');
82
+ // A-SPEC-734 (round 12): a root whose git timed out is not asked again (the shared memory).
83
+ if ((0, bounded_io_1.gitRootBlocked)(root))
84
+ throw new Error('git blocked on this root');
85
+ // A-SPEC-734 (round 15): with the fsmonitor hook off.
86
+ const files = (0, node_child_process_1.execFileSync)('git', ['-c', 'core.fsmonitor=false', '-C', root, 'ls-files', '-z', '--cached', '--others', '--exclude-standard'], { timeout: 5000, encoding: 'utf8', env: (0, root_1.cleanSubprocessEnv)(), maxBuffer: bounded_io_1.GIT_MAX_BUFFER }).split('\0'); // round 16: the shared bound
82
87
  for (const file of files) {
83
88
  const ext = path.extname(file).toLowerCase();
84
89
  if (knownCodeExtensions.has(ext) && !supportedExtensions.has(ext))
85
90
  unsupportedLanguages.add(ext);
86
91
  }
87
92
  }
88
- catch {
93
+ catch (e) {
94
+ (0, bounded_io_1.noteGitFailure)(root, e);
89
95
  // A non-git tree cannot be enumerated cheaply without reimplementing the scanner's ignore
90
96
  // rules. Surface the missing axis rather than claiming every language was covered.
91
97
  unsupportedLanguages.add('not-enumerated(non-git)');
@@ -141,7 +147,7 @@ function createMaintenanceAnalysisHandlers(context) {
141
147
  let historyStatus = limit === 0 || candidateFiles.length === 0 ? 'not-requested' : 'unavailable';
142
148
  if (limit > 0 && candidateFiles.length > 0) {
143
149
  try {
144
- const raw = (0, node_child_process_1.execFileSync)('git', ['-C', root, 'log', `-${limit}`, '--date=short', '--format=%H%x00%ad%x00%s', '--name-only', '--', ...candidateFiles], { encoding: 'utf8', env: (0, root_1.cleanSubprocessEnv)(), maxBuffer: 2 * 1024 * 1024 });
150
+ const raw = (0, node_child_process_1.execFileSync)('git', ['-C', root, 'log', `-${limit}`, '--date=short', '--format=%H%x00%ad%x00%s', '--name-only', '--', ...candidateFiles], { timeout: 5000, encoding: 'utf8', env: (0, root_1.cleanSubprocessEnv)(), maxBuffer: 2 * 1024 * 1024 });
145
151
  let current = null;
146
152
  for (const line of raw.split('\n')) {
147
153
  if (line.includes('\0')) {
@@ -34,7 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.createMaintenanceEvidenceHandlers = createMaintenanceEvidenceHandlers;
37
- // @implements A-SPEC-603
37
+ // @implements A-SPEC-724.1, A-SPEC-603, A-SPEC-734
38
38
  const fs = __importStar(require("node:fs"));
39
39
  const path = __importStar(require("node:path"));
40
40
  const node_child_process_1 = require("node:child_process");
@@ -42,6 +42,7 @@ const maintenance_evidence_1 = require("../maintenance-evidence");
42
42
  const impact_gate_1 = require("../../guardrail/impact-gate");
43
43
  const root_1 = require("../../project/root");
44
44
  const trace_gaps_1 = require("../../rtm/trace-gaps");
45
+ const bounded_io_1 = require("../../project/bounded-io");
45
46
  /** Raw handlers: the public facade attaches basis exactly once. */
46
47
  function createMaintenanceEvidenceHandlers(context) {
47
48
  return {
@@ -66,7 +67,7 @@ function createMaintenanceEvidenceHandlers(context) {
66
67
  const root = context.projectRootOf(a.root);
67
68
  let head = '';
68
69
  try {
69
- head = (0, node_child_process_1.execFileSync)('git', ['-C', root, 'rev-parse', 'HEAD'], { encoding: 'utf8', env: (0, root_1.cleanSubprocessEnv)(), stdio: ['ignore', 'pipe', 'pipe'] }).trim();
70
+ head = (0, node_child_process_1.execFileSync)('git', ['-C', root, 'rev-parse', 'HEAD'], { timeout: bounded_io_1.GIT_TIMEOUT_MS, maxBuffer: bounded_io_1.GIT_MAX_BUFFER, encoding: 'utf8', env: (0, root_1.cleanSubprocessEnv)(), stdio: ['ignore', 'pipe', 'pipe'] }).trim();
70
71
  }
71
72
  catch { /* non-git */ }
72
73
  let artifact = null;
@@ -5,21 +5,35 @@ export interface PhaseQueryContext {
5
5
  boundSpecsRoot(): string | undefined;
6
6
  projectRootOf(root: string): string;
7
7
  }
8
+ type PhaseRow = {
9
+ id: string;
10
+ type: string;
11
+ status: string;
12
+ };
8
13
  export declare function createPhaseQueryHandlers(context: PhaseQueryContext): {
9
14
  phase_status(a: {
10
15
  root?: string;
16
+ ids?: string[];
17
+ type?: string;
18
+ status?: string;
19
+ limit?: number;
20
+ cursor?: string;
11
21
  }): Promise<{
12
22
  ok: boolean;
13
23
  reason: string;
14
- specs?: undefined;
15
- note?: undefined;
16
24
  } | {
17
- specs: {
18
- id: string;
19
- type: import("../../spec/spec-types").SpecType;
20
- status: "draft" | "review" | "approved" | "outdated";
21
- }[];
22
25
  note: string;
26
+ unknownIds?: string[] | undefined;
27
+ unknownIdsTotal?: number | undefined;
28
+ nextCursor?: string | undefined;
29
+ summary: {
30
+ total: number;
31
+ counts: Record<string, Record<string, number>>;
32
+ notApproved: PhaseRow[];
33
+ notApprovedTotal: number;
34
+ };
35
+ specs: PhaseRow[];
36
+ matched: number;
23
37
  ok?: undefined;
24
38
  reason?: undefined;
25
39
  }>;
@@ -32,3 +46,4 @@ export declare function createPhaseQueryHandlers(context: PhaseQueryContext): {
32
46
  note: string;
33
47
  }>;
34
48
  };
49
+ export {};
@@ -34,11 +34,87 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.createPhaseQueryHandlers = createPhaseQueryHandlers;
37
- // @implements A-SPEC-606, A-SPEC-100.2
37
+ // @implements A-SPEC-606, A-SPEC-100.2, A-SPEC-735
38
38
  const fs = __importStar(require("node:fs"));
39
39
  const path = __importStar(require("node:path"));
40
40
  const phase_1 = require("../../guardrail/phase");
41
41
  const write_target_1 = require("../../guardrail/write-target");
42
+ // @implements A-SPEC-735 — the whole corpus in one answer was 153,888 characters here, past what a
43
+ // client accepts, so the overview could not be read. A bounded summary plus a stateless page.
44
+ const PAGE_DEFAULT = 100;
45
+ const PAGE_MAX = 500;
46
+ const NOT_APPROVED_SHOWN = 50;
47
+ // @implements A-SPEC-735 (round 2) — a TOTAL order: numeric-aware alone ties REQ-1/REQ-01/REQ-001
48
+ // (and NFC/NFD), and a strictly-after cursor then dropped the tied rows across pages (measured).
49
+ const codepoint = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
50
+ const byId = (a, b) => a.id.localeCompare(b.id, 'en', { numeric: true })
51
+ || codepoint(a.id, b.id) || codepoint(a.type, b.type) || codepoint(a.status, b.status);
52
+ const CURSOR_SEP = '\u0001';
53
+ const UNKNOWN_SHOWN = 50;
54
+ function limitProblem(limit) {
55
+ if (limit === undefined || limit === null)
56
+ return undefined;
57
+ if (typeof limit === 'number' && Number.isInteger(limit) && limit >= 1 && limit <= PAGE_MAX)
58
+ return undefined;
59
+ return `limit은 1..${PAGE_MAX} 범위의 정수여야 합니다 (받은 값: ${JSON.stringify(limit)}).`;
60
+ }
61
+ function phasePage(all, a) {
62
+ const rows = [...all].sort(byId);
63
+ // @implements A-SPEC-735 (round 2) — Maps, never assignment into a plain object: `type: __proto__`
64
+ // set ({}).approved = 1 for the whole process (measured).
65
+ const byType = new Map();
66
+ for (const r of rows) {
67
+ const t = byType.get(r.type) ?? new Map();
68
+ t.set(r.status, (t.get(r.status) ?? 0) + 1);
69
+ byType.set(r.type, t);
70
+ }
71
+ const counts = Object.fromEntries([...byType].map(([t, m]) => [t, Object.fromEntries(m)]));
72
+ const pending = rows.filter((r) => r.status !== 'approved');
73
+ const wanted = Array.isArray(a.ids) ? new Set(a.ids.filter((x) => typeof x === 'string')) : undefined;
74
+ const known = new Set(rows.map((r) => r.id));
75
+ const unknownIds = wanted ? [...wanted].filter((id) => !known.has(id)) : [];
76
+ const selected = rows.filter((r) => (!wanted || wanted.has(r.id))
77
+ && (typeof a.type !== 'string' || r.type === a.type)
78
+ && (typeof a.status !== 'string' || r.status === a.status));
79
+ // Cursor = the last row's key, plus how many rows EQUAL to that key were already returned (so
80
+ // identical rows — duplicate files — are neither lost nor repeated).
81
+ const key = (r) => `${r.id}${CURSOR_SEP}${r.type}${CURSOR_SEP}${r.status}`;
82
+ let start = 0;
83
+ if (typeof a.cursor === 'string' && a.cursor !== '') {
84
+ const parts = a.cursor.split(CURSOR_SEP);
85
+ const probe = { id: parts[0], type: parts[1] ?? '', status: parts[2] ?? '' };
86
+ const seenEqual = Number.parseInt(parts[3] ?? '0', 10) || 0;
87
+ const exact = parts.length >= 3;
88
+ start = selected.findIndex((r) => byId(r, probe) > 0 || (exact && byId(r, probe) === 0));
89
+ if (start < 0)
90
+ start = selected.length;
91
+ if (exact) {
92
+ let k = 0;
93
+ while (start < selected.length && byId(selected[start], probe) === 0 && k < seenEqual) {
94
+ start++;
95
+ k++;
96
+ }
97
+ }
98
+ else {
99
+ while (start < selected.length && byId(selected[start], { id: probe.id, type: '', status: '' }) <= 0 && selected[start].id === probe.id)
100
+ start++;
101
+ }
102
+ }
103
+ const limit = typeof a.limit === 'number' ? a.limit : PAGE_DEFAULT;
104
+ const specs = selected.slice(start, start + limit);
105
+ const last = specs[specs.length - 1];
106
+ let equalTaken = 0;
107
+ if (last)
108
+ for (let i = start + specs.length - 1; i >= 0 && byId(selected[i], last) === 0; i--)
109
+ equalTaken++;
110
+ return {
111
+ summary: { total: rows.length, counts, notApproved: pending.slice(0, NOT_APPROVED_SHOWN), notApprovedTotal: pending.length },
112
+ specs,
113
+ matched: selected.length,
114
+ ...(start + limit < selected.length ? { nextCursor: `${key(last)}${CURSOR_SEP}${equalTaken}` } : {}),
115
+ ...(unknownIds.length > 0 ? { unknownIds: unknownIds.slice(0, UNKNOWN_SHOWN), unknownIdsTotal: unknownIds.length } : {}),
116
+ };
117
+ }
42
118
  function createPhaseQueryHandlers(context) {
43
119
  return {
44
120
  async phase_status(a) {
@@ -72,8 +148,11 @@ function createPhaseQueryHandlers(context) {
72
148
  };
73
149
  }
74
150
  }
151
+ const badLimit = limitProblem(a?.limit);
152
+ if (badLimit)
153
+ return { ok: false, reason: badLimit };
75
154
  const specs = await context.listSpecs();
76
- return { specs: specs.map((s) => ({ id: s.id, type: s.type, status: s.status })), note: 'derive phase via phase_check' };
155
+ return { ...phasePage(specs.map((s) => ({ id: s.id, type: s.type, status: s.status })), a ?? {}), note: 'derive phase via phase_check' };
77
156
  },
78
157
  async phase_check(a) {
79
158
  const specs = await context.listSpecs();