@holmes-lab/holmes-kit 0.40.1 → 0.41.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.
- package/CHANGELOG.md +78 -0
- package/README.md +11 -3
- package/dist/.build-id +1 -1
- package/dist/holmes/cli/approve-context.js +4 -3
- package/dist/holmes/cli/approve.js +22 -12
- package/dist/holmes/cli/autonomy.d.ts +21 -0
- package/dist/holmes/cli/autonomy.js +35 -5
- package/dist/holmes/cli/doctor.js +58 -6
- package/dist/holmes/cli/index.js +371 -250
- package/dist/holmes/cli/init.js +17 -6
- package/dist/holmes/cli/ledger-witness.d.ts +61 -0
- package/dist/holmes/cli/ledger-witness.js +212 -0
- package/dist/holmes/cli/playbook-skills.d.ts +3 -56
- package/dist/holmes/cli/playbook-skills.js +26 -349
- package/dist/holmes/config/config.d.ts +4 -0
- package/dist/holmes/config/config.js +10 -3
- package/dist/holmes/governance/approval-queue.d.ts +65 -1
- package/dist/holmes/governance/approval-queue.js +279 -9
- package/dist/holmes/governance/autonomous-shell.d.ts +13 -1
- package/dist/holmes/governance/autonomous-shell.js +157 -4
- package/dist/holmes/governance/autonomy.d.ts +209 -0
- package/dist/holmes/governance/autonomy.js +1127 -6
- package/dist/holmes/governance/install-manifest.d.ts +7 -4
- package/dist/holmes/governance/install-manifest.js +144 -14
- package/dist/holmes/governance/ledger-witness.d.ts +63 -0
- package/dist/holmes/governance/ledger-witness.js +296 -0
- package/dist/holmes/governance/provenance-chain.d.ts +8 -1
- package/dist/holmes/governance/provenance-chain.js +23 -4
- package/dist/holmes/governance/recorded-pairs.d.ts +4 -0
- package/dist/holmes/governance/recorded-pairs.js +25 -1
- package/dist/holmes/governance/session-context.d.ts +7 -0
- package/dist/holmes/governance/session-context.js +34 -6
- package/dist/holmes/guardrail/anchor-scope-text.d.ts +9 -0
- package/dist/holmes/guardrail/anchor-scope-text.js +7 -0
- package/dist/holmes/guardrail/command-traits.d.ts +102 -0
- package/dist/holmes/guardrail/command-traits.js +379 -0
- package/dist/holmes/guardrail/fixtures/manager-builtins.json +23 -0
- package/dist/holmes/guardrail/fixtures/npm-commands.json +7 -0
- package/dist/holmes/guardrail/outward-acts.d.ts +47 -0
- package/dist/holmes/guardrail/outward-acts.js +1102 -0
- package/dist/holmes/guardrail/refusal-codes.js +8 -1
- package/dist/holmes/guardrail/refusal-templates.d.ts +15 -0
- package/dist/holmes/guardrail/refusal-templates.js +71 -0
- package/dist/holmes/guardrail/risk-classifier.d.ts +22 -6
- package/dist/holmes/guardrail/risk-classifier.js +12 -118
- package/dist/holmes/guardrail/shell-lexer.d.ts +69 -0
- package/dist/holmes/guardrail/shell-lexer.js +567 -0
- package/dist/holmes/guardrail/write-target.js +7 -1
- package/dist/holmes/hooks/pre-tool-use.d.ts +60 -0
- package/dist/holmes/hooks/pre-tool-use.js +1423 -10
- package/dist/holmes/hooks/session-start.js +11 -1
- package/dist/holmes/hooks/stop.d.ts +7 -0
- package/dist/holmes/hooks/stop.js +39 -2
- package/dist/holmes/mcp/elicit-approval.d.ts +0 -21
- package/dist/holmes/mcp/elicit-approval.js +5 -2
- package/dist/holmes/mcp/handlers/approval-ask.js +3 -2
- package/dist/holmes/mcp/handlers/entity-integration.d.ts +1 -1
- package/dist/holmes/mcp/handlers/entity-integration.js +9 -6
- package/dist/holmes/mcp/handlers/entity-renumber.js +2 -1
- package/dist/holmes/mcp/handlers/entity-store.js +7 -2
- package/dist/holmes/mcp/handlers/operator-inspection.d.ts +2 -0
- package/dist/holmes/mcp/handlers/operator-inspection.js +25 -4
- package/dist/holmes/mcp/handlers/spec-approval.d.ts +3 -1
- package/dist/holmes/mcp/handlers/spec-approval.js +28 -10
- package/dist/holmes/mcp/handlers/spec-lifecycle.js +10 -7
- package/dist/holmes/mcp/handlers/test-execution.js +4 -2
- package/dist/holmes/mcp/handlers.d.ts +5 -5
- package/dist/holmes/mcp/handlers.js +2 -1
- package/dist/holmes/mcp/tool-schemas.js +4 -4
- package/dist/holmes/project/playbook-reference.d.ts +50 -0
- package/dist/holmes/project/playbook-reference.js +259 -0
- package/dist/holmes/project/playbook-skill-states.d.ts +94 -0
- package/dist/holmes/project/playbook-skill-states.js +396 -0
- package/dist/holmes/project/root.d.ts +9 -1
- package/dist/holmes/project/root.js +23 -2
- package/dist/holmes/project/running-package.d.ts +15 -0
- package/dist/holmes/project/running-package.js +87 -0
- package/dist/holmes/review/test-runner.d.ts +2 -0
- package/dist/holmes/review/test-runner.js +27 -10
- package/dist/holmes/spec/entity-integration-transaction.d.ts +19 -2
- package/dist/holmes/spec/entity-integration-transaction.js +68 -7
- package/package.json +5 -2
|
@@ -33,7 +33,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.DEV_KEYS = exports.DECISION_KINDS = exports.QUEUE_RELPATH = void 0;
|
|
36
|
+
exports.CLOSED_EXPIRED_ACTOR = exports.REQUEST_EXPIRY_MS = exports.DEV_KEYS = exports.DECISION_KINDS = exports.SPEC_TRANSITION_KIND = exports.QUEUE_RELPATH = void 0;
|
|
37
|
+
exports.specTransitionOfStatus = specTransitionOfStatus;
|
|
38
|
+
exports.isSpecTransitionKind = isSpecTransitionKind;
|
|
37
39
|
exports.requestLabel = requestLabel;
|
|
38
40
|
exports.pendingRequestLine = pendingRequestLine;
|
|
39
41
|
exports.approvalAskLine = approvalAskLine;
|
|
@@ -41,6 +43,7 @@ exports.refusalsFilename = refusalsFilename;
|
|
|
41
43
|
exports.isRefusalsFilename = isRefusalsFilename;
|
|
42
44
|
exports.readRefusals = readRefusals;
|
|
43
45
|
exports.setRequesterServer = setRequesterServer;
|
|
46
|
+
exports.requesterServerInstance = requesterServerInstance;
|
|
44
47
|
exports.approvalRequestId = approvalRequestId;
|
|
45
48
|
exports.devFiledNote = devFiledNote;
|
|
46
49
|
exports.devFiledRefusal = devFiledRefusal;
|
|
@@ -51,10 +54,15 @@ exports.appendQueueEvent = appendQueueEvent;
|
|
|
51
54
|
exports.readQueue = readQueue;
|
|
52
55
|
exports.queueHint = queueHint;
|
|
53
56
|
exports.refusalsOutsideInbox = refusalsOutsideInbox;
|
|
57
|
+
exports.closingOf = closingOf;
|
|
58
|
+
exports.closedExpiredNote = closedExpiredNote;
|
|
59
|
+
exports.closeExpiredRequests = closeExpiredRequests;
|
|
60
|
+
exports.withQueueLock = withQueueLock;
|
|
61
|
+
exports.appendQueueEvents = appendQueueEvents;
|
|
54
62
|
exports.grantableRequests = grantableRequests;
|
|
55
63
|
exports.openOccurrences = openOccurrences;
|
|
56
64
|
exports.asPendingRequest = asPendingRequest;
|
|
57
|
-
// @implements A-SPEC-134.2, A-SPEC-794.31, A-SPEC-794.32, A-SPEC-794.33, A-SPEC-794.34,A-SPEC-244,A-SPEC-626, A-SPEC-752, A-SPEC-754, A-SPEC-770.3, A-SPEC-770.6, A-SPEC-770.12, A-SPEC-779.2
|
|
65
|
+
// @implements A-SPEC-794.95, A-SPEC-794.92, A-SPEC-794.90, A-SPEC-794.85, A-SPEC-794.84, A-SPEC-794.81, A-SPEC-134.2, A-SPEC-794.31, A-SPEC-794.32, A-SPEC-794.33, A-SPEC-794.34,A-SPEC-244,A-SPEC-626, A-SPEC-752, A-SPEC-754, A-SPEC-770.3, A-SPEC-770.6, A-SPEC-770.12, A-SPEC-779.2
|
|
58
66
|
const execution_context_1 = require("../project/execution-context");
|
|
59
67
|
const run_mode_1 = require("./run-mode");
|
|
60
68
|
const root_1 = require("../project/root");
|
|
@@ -97,8 +105,25 @@ exports.QUEUE_RELPATH = path.join('.ax', 'approvals', 'queue.jsonl');
|
|
|
97
105
|
// @implements A-SPEC-134.2 — `code-write` is a decision too: the constitution-debt refusal points the operator at
|
|
98
106
|
// `holmes-kit approve`, and its target is a project-relative path, not a command line, so the reason shell
|
|
99
107
|
// requests stay out of the tracked queue does not apply.
|
|
108
|
+
/**
|
|
109
|
+
* @implements A-SPEC-794.85 — the one table from a spec lifecycle transition to the approval kind that authorizes it.
|
|
110
|
+
* Every path that seals, un-seals or retires a spec (the MCP acts, entity recovery, the integration audit, renumber,
|
|
111
|
+
* approval_status) names the kind through it; the review of 794.81 found five files holding their own literal.
|
|
112
|
+
*/
|
|
113
|
+
exports.SPEC_TRANSITION_KIND = { seal: 'spec-approve', unseal: 'spec-unseal', retire: 'spec-retire' };
|
|
114
|
+
/** @implements A-SPEC-794.85 — the transition a spec's target status makes: approved seals, draft un-seals, outdated retires. */
|
|
115
|
+
function specTransitionOfStatus(status) {
|
|
116
|
+
return status === 'approved' ? 'seal' : status === 'draft' ? 'unseal' : status === 'outdated' ? 'retire' : null;
|
|
117
|
+
}
|
|
118
|
+
/** @implements A-SPEC-794.90 — true for the three kinds of the table. */
|
|
119
|
+
function isSpecTransitionKind(kind) {
|
|
120
|
+
return kind === exports.SPEC_TRANSITION_KIND.seal || kind === exports.SPEC_TRANSITION_KIND.unseal || kind === exports.SPEC_TRANSITION_KIND.retire;
|
|
121
|
+
}
|
|
100
122
|
exports.DECISION_KINDS = new Set([
|
|
101
123
|
'spec-approve', 'config-write', 'autonomy-grant', 'spec-reappraisal', 'review-resolve', 'governance-wiring', 'code-write',
|
|
124
|
+
'spec-unseal', 'spec-retire', // A-SPEC-794.81 — un-seal and retire are decided under their own kinds
|
|
125
|
+
// A-SPEC-794.114 — a person vouches for this repository's provenance chain as it is, and approves a rechain's plan
|
|
126
|
+
'ledger-witness', 'ledger-rechain',
|
|
102
127
|
]);
|
|
103
128
|
/**
|
|
104
129
|
* The line a refusal ends with to name its pending request and the operator command.
|
|
@@ -185,6 +210,10 @@ let requesterServer;
|
|
|
185
210
|
function setRequesterServer(instance) {
|
|
186
211
|
requesterServer = typeof instance === 'string' && instance !== '' ? instance.slice(0, 120) : undefined;
|
|
187
212
|
}
|
|
213
|
+
/** @implements A-SPEC-794.81 — the MCP server instance this process runs as, or undefined outside the server. */
|
|
214
|
+
function requesterServerInstance() {
|
|
215
|
+
return requesterServer;
|
|
216
|
+
}
|
|
188
217
|
/**
|
|
189
218
|
* Deterministic request id from the action's identity.
|
|
190
219
|
*
|
|
@@ -248,6 +277,22 @@ function foldQueue(lines, opts) {
|
|
|
248
277
|
const holds = {};
|
|
249
278
|
const subjects = {};
|
|
250
279
|
const devFiled = {};
|
|
280
|
+
const closed = {}; // A-SPEC-794.84
|
|
281
|
+
// @implements A-SPEC-794.92 — each id's last outcome bound, and a decision row's bound: `through` when 0.41 wrote it,
|
|
282
|
+
// else the last outcome's bound plus `covered` (a 0.40 CLI counts the occurrences it decided from the last outcome)
|
|
283
|
+
const lastBound = new Map();
|
|
284
|
+
// A-SPEC-794.92 (round 2, review B H1) — a row without `through` cannot bound more occurrences than were filed by its own
|
|
285
|
+
// time: a consumer workspace's 0.40.1 rows reached 121 for 27 occurrences and hid a request filed again after them
|
|
286
|
+
const boundOf = (rid, row) => {
|
|
287
|
+
let b = typeof row.through === 'number' ? row.through
|
|
288
|
+
: typeof row.covered === 'number' ? (lastBound.get(rid) ?? 0) + row.covered : undefined;
|
|
289
|
+
if (b !== undefined && typeof row.through !== 'number' && opts?.occurrencesThrough && typeof row.ts === 'string') {
|
|
290
|
+
b = Math.min(b, opts.occurrencesThrough(rid, row.ts));
|
|
291
|
+
}
|
|
292
|
+
if (b !== undefined)
|
|
293
|
+
lastBound.set(rid, b);
|
|
294
|
+
return b;
|
|
295
|
+
};
|
|
251
296
|
let malformedLines = 0;
|
|
252
297
|
for (const raw of Array.isArray(lines) ? lines : []) {
|
|
253
298
|
const line = String(raw ?? '').trim();
|
|
@@ -312,6 +357,7 @@ function foldQueue(lines, opts) {
|
|
|
312
357
|
malformedLines++;
|
|
313
358
|
break;
|
|
314
359
|
}
|
|
360
|
+
delete closed[id]; // A-SPEC-794.84 — asking again reopens a closed request
|
|
315
361
|
// @implements A-SPEC-650 — remembered for every kind, before the inbox filter: a decided shell
|
|
316
362
|
// refusal still has a subject to show on the status surface.
|
|
317
363
|
if (!subjects[id])
|
|
@@ -357,14 +403,17 @@ function foldQueue(lines, opts) {
|
|
|
357
403
|
}
|
|
358
404
|
case 'granted':
|
|
359
405
|
case 'denied':
|
|
406
|
+
// A-SPEC-794.90 — a closure is not a decision: every decision a person wrote after it is recorded and stands
|
|
407
|
+
// (794.84 dropped one that did not cover more than the closure, while its grant file still covered)
|
|
360
408
|
if (id) {
|
|
361
409
|
pending.delete(id);
|
|
362
410
|
delete holds[id]; // @implements A-SPEC-563.2 — a decision answers the question
|
|
411
|
+
const b = boundOf(id, e);
|
|
363
412
|
decisions[id] = {
|
|
364
413
|
event: e.event,
|
|
365
414
|
...(typeof e.reason === 'string' ? { reason: e.reason } : {}),
|
|
366
415
|
ts: typeof e.ts === 'string' ? e.ts : '',
|
|
367
|
-
...(
|
|
416
|
+
...(b !== undefined ? { covered: b } : {}),
|
|
368
417
|
...(execution ? { execution } : {}),
|
|
369
418
|
// @implements A-SPEC-650 — when a grant expires and who decided, for the outcome rows.
|
|
370
419
|
...(typeof e.expires === 'string' ? { expires: e.expires } : {}),
|
|
@@ -393,16 +442,29 @@ function foldQueue(lines, opts) {
|
|
|
393
442
|
if (id) {
|
|
394
443
|
pending.delete(id);
|
|
395
444
|
delete holds[id];
|
|
445
|
+
const b = boundOf(id, e);
|
|
396
446
|
decisions[id] = {
|
|
397
447
|
event: 'withdrawn',
|
|
398
448
|
...(typeof e.reason === 'string' ? { reason: e.reason } : {}),
|
|
399
449
|
ts: typeof e.ts === 'string' ? e.ts : '',
|
|
400
|
-
...(
|
|
450
|
+
...(b !== undefined ? { covered: b } : {}),
|
|
401
451
|
...(typeof e.run === 'string' ? { run: e.run } : {}),
|
|
402
452
|
...(execution ? { execution } : {}),
|
|
403
453
|
};
|
|
404
454
|
}
|
|
405
455
|
break;
|
|
456
|
+
// @implements A-SPEC-794.84 — closed unrun after 24 hours without a requester: it leaves pending, and it is not a
|
|
457
|
+
// decision (no denial to finalise, no id that must not be filed again)
|
|
458
|
+
case 'closed-expired':
|
|
459
|
+
if (id) {
|
|
460
|
+
pending.delete(id);
|
|
461
|
+
// A-SPEC-794.92 — a closure's bound: `through`, or (794.84's rows) its covered, which was already a bound
|
|
462
|
+
const cb = typeof e.through === 'number' ? e.through : typeof e.covered === 'number' ? e.covered : undefined;
|
|
463
|
+
if (cb !== undefined)
|
|
464
|
+
lastBound.set(id, cb);
|
|
465
|
+
closed[id] = { ts: typeof e.ts === 'string' ? e.ts : '', ...(cb !== undefined ? { covered: cb } : {}) };
|
|
466
|
+
}
|
|
467
|
+
break;
|
|
406
468
|
case 'held': {
|
|
407
469
|
const entry = id ? pending.get(id) : undefined;
|
|
408
470
|
if (entry) {
|
|
@@ -440,7 +502,8 @@ function foldQueue(lines, opts) {
|
|
|
440
502
|
const all = [...pending.values()];
|
|
441
503
|
const ttl = typeof opts?.ttlMs === 'number' && typeof opts?.now === 'number'
|
|
442
504
|
? { ttlMs: opts.ttlMs, now: opts.now } : null;
|
|
443
|
-
const withSubjects = { ...(Object.keys(subjects).length > 0 ? { subjects } : {}), ...(Object.keys(devFiled).length > 0 ? { devFiled } : {})
|
|
505
|
+
const withSubjects = { ...(Object.keys(subjects).length > 0 ? { subjects } : {}), ...(Object.keys(devFiled).length > 0 ? { devFiled } : {}),
|
|
506
|
+
...(Object.keys(closed).length > 0 ? { closed } : {}) };
|
|
444
507
|
if (ttl === null)
|
|
445
508
|
return { pending: all, expired: [], malformedLines, decisions, holds, ...withSubjects };
|
|
446
509
|
// @implements A-SPEC-507.1 — strict excess only, and an unparseable lastTs stays ACTIVE: a
|
|
@@ -612,6 +675,44 @@ function appendQueueEvent(root, event) {
|
|
|
612
675
|
return false;
|
|
613
676
|
}
|
|
614
677
|
}
|
|
678
|
+
/**
|
|
679
|
+
* @implements A-SPEC-794.92 (round 2) — occurrences of an id filed at or before a time, from the refusal logs, read once
|
|
680
|
+
* and only when a row without `through` asks. An unreadable log cuts nothing (the row's own bound stands).
|
|
681
|
+
*/
|
|
682
|
+
function occurrenceCounter(root) {
|
|
683
|
+
let index;
|
|
684
|
+
return (id, ts) => {
|
|
685
|
+
if (index === undefined) {
|
|
686
|
+
try {
|
|
687
|
+
index = new Map();
|
|
688
|
+
for (const r of readRefusals(root)) {
|
|
689
|
+
const l = index.get(r.id);
|
|
690
|
+
if (l)
|
|
691
|
+
l.push(r.ts);
|
|
692
|
+
else
|
|
693
|
+
index.set(r.id, [r.ts]);
|
|
694
|
+
}
|
|
695
|
+
for (const l of index.values())
|
|
696
|
+
l.sort();
|
|
697
|
+
}
|
|
698
|
+
catch {
|
|
699
|
+
index = null;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
if (index === null)
|
|
703
|
+
return Number.POSITIVE_INFINITY;
|
|
704
|
+
const l = index.get(id) ?? [];
|
|
705
|
+
let lo = 0, hi = l.length;
|
|
706
|
+
while (lo < hi) {
|
|
707
|
+
const mid = (lo + hi) >> 1;
|
|
708
|
+
if (l[mid] <= ts)
|
|
709
|
+
lo = mid + 1;
|
|
710
|
+
else
|
|
711
|
+
hi = mid;
|
|
712
|
+
}
|
|
713
|
+
return lo;
|
|
714
|
+
};
|
|
715
|
+
}
|
|
615
716
|
/** Read and fold the queue on disk. A missing file is an empty queue, not an error. */
|
|
616
717
|
function readQueue(root, opts) {
|
|
617
718
|
const file = path.join(root, exports.QUEUE_RELPATH);
|
|
@@ -624,7 +725,7 @@ function readQueue(root, opts) {
|
|
|
624
725
|
if (!fs.lstatSync(file).isFile())
|
|
625
726
|
return { pending: [], expired: [], malformedLines: 1, decisions: {}, holds: {} };
|
|
626
727
|
const raw = fs.readFileSync(file, 'utf8');
|
|
627
|
-
return foldQueue(raw.split('\n'), opts);
|
|
728
|
+
return foldQueue(raw.split('\n'), { ...opts, occurrencesThrough: occurrenceCounter(root) });
|
|
628
729
|
}
|
|
629
730
|
catch {
|
|
630
731
|
return { pending: [], expired: [], malformedLines: 0, decisions: {}, holds: {} };
|
|
@@ -711,6 +812,174 @@ function refusalsOutsideInbox(root) {
|
|
|
711
812
|
return 0;
|
|
712
813
|
}
|
|
713
814
|
}
|
|
815
|
+
/**
|
|
816
|
+
* @implements A-SPEC-794.84 — what last ended a request: its decision or its closure, whichever covered more occurrences
|
|
817
|
+
* (else the later). The refusal-log fallback reads the occurrences past it, so a filing after a closure is a new request.
|
|
818
|
+
*/
|
|
819
|
+
function closingOf(state, id) {
|
|
820
|
+
const d = state.decisions[id];
|
|
821
|
+
const c = state.closed?.[id];
|
|
822
|
+
if (c === undefined)
|
|
823
|
+
return d;
|
|
824
|
+
if (d === undefined)
|
|
825
|
+
return c;
|
|
826
|
+
// A-SPEC-794.90 — on an equal bound the decision stands
|
|
827
|
+
if (typeof d.covered === 'number' && typeof c.covered === 'number')
|
|
828
|
+
return c.covered > d.covered ? c : d;
|
|
829
|
+
return c.ts > d.ts ? c : d;
|
|
830
|
+
}
|
|
831
|
+
/** @implements A-SPEC-794.84 — the request expiry: 24 hours after the last filing. */
|
|
832
|
+
exports.REQUEST_EXPIRY_MS = 24 * 3_600_000;
|
|
833
|
+
exports.CLOSED_EXPIRED_ACTOR = 'policy:ttl';
|
|
834
|
+
/** @implements A-SPEC-794.84 — what a lookup says about a closed id, or null. */
|
|
835
|
+
function closedExpiredNote(state, id) {
|
|
836
|
+
const c = state.closed?.[id];
|
|
837
|
+
if (c === undefined)
|
|
838
|
+
return null;
|
|
839
|
+
const d = state.decisions[id];
|
|
840
|
+
if (d !== undefined && d.ts >= c.ts)
|
|
841
|
+
return null; // A-SPEC-794.90 — a later decision is what the id says now
|
|
842
|
+
return `[expired] request ${id.slice(0, 40)} was closed unrun after 24 hours without a requester (closed-expired) — nothing ran; asking again files a new request`;
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* @implements A-SPEC-794.84 — closes, unrun, each grantable request that no requester can follow up (no requester run,
|
|
846
|
+
* no requester server: a hook's or a CLI's filing), that no person held, and whose last filing is more than 24 hours
|
|
847
|
+
* old. One `closed-expired` event per request, actor `policy:ttl`; the refusal log is not touched. Returns how many.
|
|
848
|
+
*/
|
|
849
|
+
function closeExpiredRequests(root, now = Date.now(), deps) {
|
|
850
|
+
if (!fs.existsSync(path.join(root, '.ax')))
|
|
851
|
+
return 0;
|
|
852
|
+
// A-SPEC-794.92 (L-2) — read and close under the queue lock; a lock this sweep cannot take closes nothing (a closure
|
|
853
|
+
// waits for the next session, a person's write does not wait for a closure)
|
|
854
|
+
return withQueueLock(root, () => sweepExpired(root, now, deps?.append ?? ((rows) => appendQueueEvents(root, rows))), 0);
|
|
855
|
+
}
|
|
856
|
+
const QUEUE_LOCK_STALE_MS = 30_000;
|
|
857
|
+
const QUEUE_LOCK_WAIT_MS = 2_000;
|
|
858
|
+
/** @implements A-SPEC-794.95 (A-L1, B-L2) — re-entry is per root: holding one root's lock is not holding another's. */
|
|
859
|
+
const queueLockDepth = new Map();
|
|
860
|
+
/**
|
|
861
|
+
* @implements A-SPEC-794.92 (L-2) — the queue's writer lock: a directory beside the queue, taken by mkdir. It is
|
|
862
|
+
* re-entrant within this process; a lock older than 30 s is a holder that died and is broken; a lock not taken within
|
|
863
|
+
* 2 s returns `fallback` without running `fn`. Every caller decides which way that fails.
|
|
864
|
+
*/
|
|
865
|
+
function withQueueLock(root, fn, fallback) {
|
|
866
|
+
const lock = path.join(root, '.ax', 'approvals', 'queue.lock');
|
|
867
|
+
const held = queueLockDepth.get(lock) ?? 0;
|
|
868
|
+
if (held > 0) {
|
|
869
|
+
queueLockDepth.set(lock, held + 1);
|
|
870
|
+
try {
|
|
871
|
+
return fn();
|
|
872
|
+
}
|
|
873
|
+
finally {
|
|
874
|
+
queueLockDepth.set(lock, (queueLockDepth.get(lock) ?? 1) - 1);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
try {
|
|
878
|
+
fs.mkdirSync(path.dirname(lock), { recursive: true });
|
|
879
|
+
}
|
|
880
|
+
catch {
|
|
881
|
+
return fallback;
|
|
882
|
+
}
|
|
883
|
+
const deadline = Date.now() + QUEUE_LOCK_WAIT_MS;
|
|
884
|
+
for (;;) {
|
|
885
|
+
try {
|
|
886
|
+
fs.mkdirSync(lock);
|
|
887
|
+
break;
|
|
888
|
+
}
|
|
889
|
+
catch (e) {
|
|
890
|
+
if (e.code !== 'EEXIST')
|
|
891
|
+
return fallback;
|
|
892
|
+
try {
|
|
893
|
+
const st = fs.lstatSync(lock);
|
|
894
|
+
// A-SPEC-794.95 (B-L2) — a stale lock is reclaimed by renaming it away first: two processes that both judged it
|
|
895
|
+
// stale cannot both remove it, and neither removes a lock the other just took
|
|
896
|
+
if (st.isDirectory() && Date.now() - st.mtimeMs > QUEUE_LOCK_STALE_MS) {
|
|
897
|
+
const aside = `${lock}.stale-${process.pid}-${Date.now()}`;
|
|
898
|
+
try {
|
|
899
|
+
fs.renameSync(lock, aside);
|
|
900
|
+
fs.rmdirSync(aside);
|
|
901
|
+
}
|
|
902
|
+
catch { /* another process reclaimed it */ }
|
|
903
|
+
continue;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
catch {
|
|
907
|
+
continue;
|
|
908
|
+
}
|
|
909
|
+
if (Date.now() >= deadline)
|
|
910
|
+
return fallback;
|
|
911
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 25);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
queueLockDepth.set(lock, 1);
|
|
915
|
+
try {
|
|
916
|
+
return fn();
|
|
917
|
+
}
|
|
918
|
+
finally {
|
|
919
|
+
queueLockDepth.delete(lock);
|
|
920
|
+
try {
|
|
921
|
+
fs.rmdirSync(lock);
|
|
922
|
+
}
|
|
923
|
+
catch { /* already broken */ }
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* @implements A-SPEC-794.95 — several queue events in one write, under the same discipline as appendQueueEvent (an
|
|
928
|
+
* existing `.ax`, a plain queue file, the actor judged at the seam, the time and execution attached).
|
|
929
|
+
*/
|
|
930
|
+
function appendQueueEvents(root, events) {
|
|
931
|
+
if (events.length === 0)
|
|
932
|
+
return true;
|
|
933
|
+
try {
|
|
934
|
+
let execution;
|
|
935
|
+
try {
|
|
936
|
+
execution = (0, execution_context_1.executionForRoot)((0, root_1.resolveProjectRoot)(root).root);
|
|
937
|
+
}
|
|
938
|
+
catch {
|
|
939
|
+
execution = undefined;
|
|
940
|
+
}
|
|
941
|
+
const file = path.join(root, exports.QUEUE_RELPATH);
|
|
942
|
+
if (!fs.existsSync(path.join(root, '.ax')))
|
|
943
|
+
return false;
|
|
944
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
945
|
+
if (!isPlainFile(file))
|
|
946
|
+
return false;
|
|
947
|
+
const ts = new Date().toISOString();
|
|
948
|
+
fs.appendFileSync(file, events.map((event) => {
|
|
949
|
+
const judged = 'actor' in event ? { ...event, actor: (0, human_channel_1.ledgerActor)(event.actor) } : event;
|
|
950
|
+
return JSON.stringify({ ...judged, ts, ...(execution ? { execution } : {}) });
|
|
951
|
+
}).join('\n') + '\n');
|
|
952
|
+
return true;
|
|
953
|
+
}
|
|
954
|
+
catch {
|
|
955
|
+
return false;
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
function sweepExpired(root, now, append) {
|
|
959
|
+
const state = readQueue(root, { includeAllKinds: true });
|
|
960
|
+
const totals = new Map();
|
|
961
|
+
try {
|
|
962
|
+
for (const r of readRefusals(root))
|
|
963
|
+
totals.set(r.id, (totals.get(r.id) ?? 0) + 1);
|
|
964
|
+
}
|
|
965
|
+
catch { /* the log's requests stay open */ }
|
|
966
|
+
const queued = new Set(state.pending.map((p) => p.id));
|
|
967
|
+
const rows = [];
|
|
968
|
+
for (const p of grantableRequests(root)) {
|
|
969
|
+
if (p.requesterRun !== undefined || p.requesterServer !== undefined)
|
|
970
|
+
continue;
|
|
971
|
+
if (p.hold === true || state.holds[p.id] !== undefined)
|
|
972
|
+
continue;
|
|
973
|
+
const last = Date.parse(p.lastTs);
|
|
974
|
+
if (!Number.isFinite(last) || last + exports.REQUEST_EXPIRY_MS >= now)
|
|
975
|
+
continue;
|
|
976
|
+
const covered = queued.has(p.id) ? p.count : (totals.get(p.id) ?? p.count);
|
|
977
|
+
rows.push({ event: 'closed-expired', id: p.id, actor: exports.CLOSED_EXPIRED_ACTOR,
|
|
978
|
+
reason: 'no requester can follow it up and no one decided it in 24 hours; nothing ran', covered, through: covered }); // A-SPEC-794.92
|
|
979
|
+
}
|
|
980
|
+
// A-SPEC-794.95 — one write for the sweep (each row was its own append: 6.3 s on a consumer workspace's first sweep, 18.9 s here)
|
|
981
|
+
return rows.length > 0 && append(rows) ? rows.length : 0;
|
|
982
|
+
}
|
|
714
983
|
function grantableRequests(root) {
|
|
715
984
|
const state = readQueue(root, { includeAllKinds: true });
|
|
716
985
|
const seen = new Set(state.pending.map((p) => p.id));
|
|
@@ -738,10 +1007,10 @@ function grantableRequests(root) {
|
|
|
738
1007
|
// not. When both exist the queue wins, or granting once would stop closing the request.
|
|
739
1008
|
if (seen.has(id))
|
|
740
1009
|
continue;
|
|
741
|
-
const live = openOccurrences(all, state
|
|
1010
|
+
const live = openOccurrences(all, closingOf(state, id)); // A-SPEC-794.84 — past a decision or a closure
|
|
742
1011
|
if (live.length === 0)
|
|
743
1012
|
continue;
|
|
744
|
-
out.push(asPendingRequest(id, live));
|
|
1013
|
+
out.push(asPendingRequest(id, live, all.length)); // A-SPEC-794.90 — the occurrence bound a decision records
|
|
745
1014
|
}
|
|
746
1015
|
return out;
|
|
747
1016
|
}
|
|
@@ -766,10 +1035,11 @@ function openOccurrences(all, decided) {
|
|
|
766
1035
|
* One id's refusals, in the shape a queue entry has — so the decision surface reads the same
|
|
767
1036
|
* whichever store the request came from.
|
|
768
1037
|
*/
|
|
769
|
-
function asPendingRequest(id, occurrences) {
|
|
1038
|
+
function asPendingRequest(id, occurrences, through) {
|
|
770
1039
|
const latest = occurrences[occurrences.length - 1];
|
|
771
1040
|
return {
|
|
772
1041
|
id,
|
|
1042
|
+
...(typeof through === 'number' ? { through } : {}), // A-SPEC-794.90
|
|
773
1043
|
// The NEWEST occurrence is what the operator just saw, so it is what the decision names.
|
|
774
1044
|
kind: latest.kind,
|
|
775
1045
|
target: latest.target,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Spec } from '../spec/spec-parser';
|
|
1
2
|
export type ShellVerdict = {
|
|
2
3
|
ok: true;
|
|
3
4
|
paths: string[];
|
|
@@ -37,7 +38,17 @@ export interface ShellDeps {
|
|
|
37
38
|
readBytes(rel: string): Buffer | null;
|
|
38
39
|
/** The repository's object format, which names its blobs (SHA-1 when absent). */
|
|
39
40
|
objectFormat?(): 'sha1' | 'sha256';
|
|
41
|
+
/** @implements A-SPEC-794.86 — a spec of the store by id (R1 reads parents), or null. */
|
|
42
|
+
specById?(id: string): Spec | null;
|
|
43
|
+
/** @implements A-SPEC-794.91 (L-a) — every spec of the store (R1 reads the A-SPECs beneath a REQ or an H-SPEC). */
|
|
44
|
+
allSpecs?(): Spec[];
|
|
40
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* @implements A-SPEC-794.86 — R1 sealed-spec-staging: a staged spec is approved without a person only when its approval
|
|
48
|
+
* chain is unbroken and its scope is outside the gate category. The seal itself is the prover's (the seal holds and a
|
|
49
|
+
* trusted spec-approved event names [id, digest]); this adds the chain and the scope. Null when R1 holds.
|
|
50
|
+
*/
|
|
51
|
+
export declare function r1Problem(rel: string, text: string, deps: ShellDeps): string | null;
|
|
41
52
|
export declare function governanceStagingOnly(reasons: readonly string[]): boolean;
|
|
42
53
|
/** 1. Grammar: `git add|stage` (-A, --all or literal paths), then `&& git status …` with an optional counted pipe. */
|
|
43
54
|
export declare function stagingGrammar(command: string): {
|
|
@@ -54,8 +65,9 @@ export declare function autonomousShellVerdict(input: {
|
|
|
54
65
|
specsRel?: string;
|
|
55
66
|
base?: string;
|
|
56
67
|
specStaging?: boolean;
|
|
68
|
+
specRow?: 'on' | 'off';
|
|
57
69
|
}, deps: ShellDeps): ShellVerdict;
|
|
58
70
|
/** The real readers: git in the workspace, its provenance ledger, its queue and its install manifest. */
|
|
59
|
-
export declare function realShellDeps(root: string): ShellDeps;
|
|
71
|
+
export declare function realShellDeps(root: string, specsRel?: string): ShellDeps;
|
|
60
72
|
/** For approve --list: the last autonomous shell approvals (time, command digest, path count). */
|
|
61
73
|
export declare function renderAutonomousApprovals(events: LedgerEventLike[], limit?: number): string;
|
|
@@ -33,6 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.r1Problem = r1Problem;
|
|
36
37
|
exports.governanceStagingOnly = governanceStagingOnly;
|
|
37
38
|
exports.stagingGrammar = stagingGrammar;
|
|
38
39
|
exports.autonomousShellVerdict = autonomousShellVerdict;
|
|
@@ -42,8 +43,112 @@ const crypto = __importStar(require("node:crypto"));
|
|
|
42
43
|
const fs = __importStar(require("node:fs"));
|
|
43
44
|
const path = __importStar(require("node:path"));
|
|
44
45
|
const spec_parser_1 = require("../spec/spec-parser");
|
|
46
|
+
const scope_judgment_1 = require("../guardrail/scope-judgment"); // @implements A-SPEC-794.86
|
|
47
|
+
const autonomy_1 = require("./autonomy"); // @implements A-SPEC-794.89, A-SPEC-794.91
|
|
45
48
|
const succession_1 = require("../spec/succession");
|
|
46
49
|
const spec_seam_1 = require("./spec-seam");
|
|
50
|
+
/** @implements A-SPEC-794.86 — where R1 expects each type it covers: `<dir>/…/<id>.md` (an H-SPEC may sit in a sub-folder). */
|
|
51
|
+
const R1_DIR = { REQ: '01_req', 'H-SPEC': '02_h-spec', 'A-SPEC': '03_a-spec', 'T-SPEC': '05_t-spec' };
|
|
52
|
+
/**
|
|
53
|
+
* The A-SPEC's code scope is outside the gate category and not root-only, or why not.
|
|
54
|
+
* A-SPEC-794.89 — the category is principle 7's (one judgement with the R7 grader), and a root-only scope goes to a
|
|
55
|
+
* person as the grader's A-SPEC-654 rule does.
|
|
56
|
+
*/
|
|
57
|
+
function r1ScopeProblem(a) {
|
|
58
|
+
const paths = (0, scope_judgment_1.fttPathTokens)(a.sections['Files to Touch'] ?? '');
|
|
59
|
+
if (paths.length === 0)
|
|
60
|
+
return `${a.id}'s Files to Touch names no path, so its scope is unbounded`;
|
|
61
|
+
const gate = (0, autonomy_1.principle7Category)(a);
|
|
62
|
+
if (gate !== null)
|
|
63
|
+
return `${a.id}'s Files to Touch names ${gate}, in the gate category (principle 7: a person reviews it)`;
|
|
64
|
+
if (!paths.some((p) => p.includes('/')))
|
|
65
|
+
return `${a.id}'s Files to Touch is root-only (project-wide configuration goes to a person)`;
|
|
66
|
+
// A-SPEC-794.91 (M-b) — one judgement with the grader: a root configuration file in the scope goes to a person
|
|
67
|
+
const cfg = paths.find(autonomy_1.rootConfigToken);
|
|
68
|
+
if (cfg !== undefined)
|
|
69
|
+
return `${a.id}'s Files to Touch names ${cfg}, a root-level configuration file (project-wide configuration goes to a person)`;
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* @implements A-SPEC-794.89 — every ancestor up to the REQ: in the store, approved, its seal holding, pinned by its child
|
|
74
|
+
* and named by a trusted spec-approved event with that digest. Null when the whole chain holds.
|
|
75
|
+
*/
|
|
76
|
+
function r1ChainProblem(s, deps, events, seen) {
|
|
77
|
+
const pins = (s.frontmatter.parent_digests ?? {});
|
|
78
|
+
for (const id of s.dependsOn ?? []) {
|
|
79
|
+
if (seen.has(id))
|
|
80
|
+
continue;
|
|
81
|
+
seen.add(id);
|
|
82
|
+
const p = deps.specById?.(id) ?? null;
|
|
83
|
+
if (p === null)
|
|
84
|
+
return `${s.id}'s parent ${id} is not in the store`;
|
|
85
|
+
const d = p.frontmatter.approved_digest;
|
|
86
|
+
if (p.status !== 'approved' || !(0, succession_1.sealHolds)(p) || typeof d !== 'string')
|
|
87
|
+
return `${s.id}'s parent ${id} is not sealed`;
|
|
88
|
+
if (pins[id] !== d)
|
|
89
|
+
return `${s.id}'s parent ${id} is sealed as ${d}, not as ${s.id} pins it`;
|
|
90
|
+
if (!events.some((e) => e.kind === 'spec-approved' && inputsOf(e)[0] === id && inputsOf(e)[1] === d))
|
|
91
|
+
return `${s.id}'s parent ${id}: no trusted spec-approved event names its seal`;
|
|
92
|
+
const up = r1ChainProblem(p, deps, events, seen);
|
|
93
|
+
if (up !== null)
|
|
94
|
+
return up;
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* @implements A-SPEC-794.86 — R1 sealed-spec-staging: a staged spec is approved without a person only when its approval
|
|
100
|
+
* chain is unbroken and its scope is outside the gate category. The seal itself is the prover's (the seal holds and a
|
|
101
|
+
* trusted spec-approved event names [id, digest]); this adds the chain and the scope. Null when R1 holds.
|
|
102
|
+
*/
|
|
103
|
+
function r1Problem(rel, text, deps) {
|
|
104
|
+
let s;
|
|
105
|
+
try {
|
|
106
|
+
s = (0, spec_parser_1.parseSpec)(text);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return `${rel} is not a readable spec`;
|
|
110
|
+
}
|
|
111
|
+
if (s.status !== 'approved')
|
|
112
|
+
return `${s.id} is ${s.status}: R1 covers sealed specs only`;
|
|
113
|
+
const dir = R1_DIR[s.type];
|
|
114
|
+
if (dir === undefined)
|
|
115
|
+
return `${s.id} is a ${s.type}, which goes to a person`;
|
|
116
|
+
const parts = rel.split('/');
|
|
117
|
+
if (parts[2] !== dir || parts[parts.length - 1] !== `${s.id}.md` || (s.type !== 'H-SPEC' && parts.length !== 4)) {
|
|
118
|
+
return `${rel} is not where its type and id say (${dir}/${s.id}.md)`;
|
|
119
|
+
}
|
|
120
|
+
// A-SPEC-794.89 — an A-SPEC or T-SPEC hangs from a parent; the whole chain to the REQ holds
|
|
121
|
+
if ((s.type === 'A-SPEC' || s.type === 'T-SPEC') && (s.dependsOn ?? []).length === 0)
|
|
122
|
+
return `${s.id} has no parent, so its chain is not judged`;
|
|
123
|
+
const chain = r1ChainProblem(s, deps, deps.ledgerEvents(), new Set());
|
|
124
|
+
if (chain !== null)
|
|
125
|
+
return chain;
|
|
126
|
+
const parents = (s.dependsOn ?? []).map((id) => deps.specById?.(id) ?? null).filter((p) => p !== null);
|
|
127
|
+
if (s.type === 'A-SPEC')
|
|
128
|
+
return r1ScopeProblem(s);
|
|
129
|
+
// A-SPEC-794.91 (L-a) — a REQ or an H-SPEC is judged by the A-SPECs beneath it, as the seal path judges it
|
|
130
|
+
if (s.type === 'REQ' || s.type === 'H-SPEC') {
|
|
131
|
+
const beneath = (0, autonomy_1.descendantAspecs)(s, deps.allSpecs?.() ?? []);
|
|
132
|
+
if (beneath.length === 0)
|
|
133
|
+
return `${s.id} has no A-SPEC beneath it, so its scope is unknown (a person reviews it)`;
|
|
134
|
+
for (const a of beneath) {
|
|
135
|
+
const why = r1ScopeProblem(a);
|
|
136
|
+
if (why !== null)
|
|
137
|
+
return why;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (s.type === 'T-SPEC') {
|
|
141
|
+
const aspecs = parents.filter((p) => p.type === 'A-SPEC');
|
|
142
|
+
if (aspecs.length === 0)
|
|
143
|
+
return `${s.id} depends on no A-SPEC, so its scope is unknown`;
|
|
144
|
+
for (const a of aspecs) {
|
|
145
|
+
const why = r1ScopeProblem(a);
|
|
146
|
+
if (why !== null)
|
|
147
|
+
return why;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
47
152
|
/** The classifier's two verdicts on staging the governance store (risk-classifier.ts; full-autonomy.ts reads the same). */
|
|
48
153
|
const STAGING_REASONS = [/^staging command reaches changed files in the protected \.ax spec store/, /^shell command over a protected \.ax governance path is not recognisably read-only/];
|
|
49
154
|
function governanceStagingOnly(reasons) {
|
|
@@ -250,13 +355,59 @@ function autonomousShellVerdict(input, deps) {
|
|
|
250
355
|
// @implements A-SPEC-792.31 — last, so every other condition is still named as before: a spec path is out of scope
|
|
251
356
|
// (A-SPEC-792.32: `specStaging` lifts the stop for the tests only; the gate sets it from no environment or config)
|
|
252
357
|
const specsRel = (input.specsRel ?? '.ax/specs').replace(/\/+$/, '');
|
|
253
|
-
const
|
|
254
|
-
|
|
358
|
+
const specs = governance.filter((s) => s.path === specsRel || s.path.startsWith(`${specsRel}/`));
|
|
359
|
+
const spec = specs[0];
|
|
360
|
+
// @implements A-SPEC-794.86 — the R1 row lifts the stop for a spec path whose chain and scope hold; off, it stands
|
|
361
|
+
if (spec && input.specStaging !== true && input.specRow !== 'on')
|
|
255
362
|
return fail('scope', `${spec.path} is in the spec store, which autonomous approval does not cover; a person approves spec staging`);
|
|
256
|
-
|
|
363
|
+
if (spec && input.specStaging !== true) {
|
|
364
|
+
for (const s of specs) {
|
|
365
|
+
const bytes = deps.readBytes(s.path);
|
|
366
|
+
const why = bytes === null ? `${s.path} cannot be read` : r1Problem(s.path.replace(new RegExp(`^${specsRel.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}/`), '.ax/specs/'), bytes.toString('utf8'), deps);
|
|
367
|
+
if (why !== null)
|
|
368
|
+
return fail('scope', `${s.path}: R1 (sealed-spec staging) does not hold — ${why}; a person approves this staging`);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return { ok: true, paths: governance.map((s) => s.path).sort(), proven,
|
|
372
|
+
conditions: { grammar: 'pass', reversible: 'pass', 'product-installed': 'pass', integrity: 'pass', provenance: 'pass', ...(spec ? { R1: 'pass' } : {}) } };
|
|
257
373
|
}
|
|
258
374
|
/** The real readers: git in the workspace, its provenance ledger, its queue and its install manifest. */
|
|
259
|
-
function realShellDeps(root) {
|
|
375
|
+
function realShellDeps(root, specsRel = '.ax/specs') {
|
|
376
|
+
// @implements A-SPEC-794.86 — the store's specs by id, read once per verdict (R1 reads parents)
|
|
377
|
+
let byId;
|
|
378
|
+
const specIndex = () => {
|
|
379
|
+
if (byId !== undefined)
|
|
380
|
+
return byId;
|
|
381
|
+
byId = new Map();
|
|
382
|
+
const walk = (dir, depth) => {
|
|
383
|
+
if (depth > 6)
|
|
384
|
+
return;
|
|
385
|
+
let entries;
|
|
386
|
+
try {
|
|
387
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
388
|
+
}
|
|
389
|
+
catch {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
for (const e of entries) {
|
|
393
|
+
const p = path.join(dir, e.name);
|
|
394
|
+
if (e.isDirectory()) {
|
|
395
|
+
walk(p, depth + 1);
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
if (!e.isFile() || !e.name.endsWith('.md'))
|
|
399
|
+
continue;
|
|
400
|
+
try {
|
|
401
|
+
const s = (0, spec_parser_1.parseSpec)(fs.readFileSync(p, 'utf8'));
|
|
402
|
+
if (s.id === e.name.slice(0, -3) && !byId.has(s.id))
|
|
403
|
+
byId.set(s.id, s);
|
|
404
|
+
}
|
|
405
|
+
catch { /* not a spec */ }
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
walk(path.join(root, specsRel), 0);
|
|
409
|
+
return byId;
|
|
410
|
+
};
|
|
260
411
|
const { FileLedgerStore } = require('./ledger-store');
|
|
261
412
|
const store = new FileLedgerStore(path.join(root, '.ax', 'ledger'));
|
|
262
413
|
// @implements A-SPEC-222.9 — H1: a proof is taken only from trusted events (one port with the gate and spec_retire);
|
|
@@ -316,6 +467,8 @@ function realShellDeps(root) {
|
|
|
316
467
|
// target, an executable is not the 100644 entry the seam grants
|
|
317
468
|
readBytes: (rel) => (0, spec_seam_1.grantableBytes)(path.join(root, rel)),
|
|
318
469
|
objectFormat: () => (0, spec_seam_1.objectFormatOf)(root),
|
|
470
|
+
specById: (id) => specIndex().get(id) ?? null,
|
|
471
|
+
allSpecs: () => [...specIndex().values()],
|
|
319
472
|
};
|
|
320
473
|
}
|
|
321
474
|
/** For approve --list: the last autonomous shell approvals (time, command digest, path count). */
|