@akagilnc/pi-workflow-roles 0.1.6115 → 0.1.6126
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/README.md +3 -3
- package/README.zh-CN.md +3 -3
- package/dist/acp-host/production-host.js +354 -250
- package/dist/engine-detour-usage.js +2 -1
- package/dist/gatekeeper-role.js +3 -15
- package/dist/headless-host/description.js +4 -1
- package/dist/headless-host/production-host.js +340 -236
- package/dist/migrate-book-topology.js +39 -22
- package/dist/notary-source-run.js +8 -8
- package/dist/public-cli/auto-resume.js +3 -3
- package/dist/public-cli/cli.js +38 -32
- package/dist/public-cli/instruction-seat-run.js +2 -5
- package/dist/public-cli/main.js +310 -208
- package/dist/public-cli/option-definitions.js +22 -21
- package/dist/public-cli/run-lifecycle.js +27 -26
- package/dist/public-cli/seat-ticket-binding.js +2 -1
- package/dist/public-cli/settlement.js +33 -8
- package/dist/public-cli/terminal.js +13 -3
- package/dist/public-role-summons.js +1 -7
- package/dist/role-run-placement.js +1 -1
- package/dist/run-dossier-files.js +4 -2
- package/dist/submission-gate.js +3 -3
- package/dist/submission-ledger.js +29 -3
- package/dist/ticket-address.js +77 -0
- package/dist/ticket-progress.js +31 -0
- package/package.json +1 -1
- package/src/engine-detour-usage.ts +2 -1
- package/src/gatekeeper-role.ts +5 -18
- package/src/headless-host/description.ts +4 -1
- package/src/notary-source-run.ts +8 -8
- package/src/public-cli/auto-resume.ts +4 -3
- package/src/public-cli/cli.ts +53 -32
- package/src/public-cli/instruction-seat-run.ts +2 -5
- package/src/public-cli/option-definitions.ts +22 -21
- package/src/public-cli/run-lifecycle.ts +31 -31
- package/src/public-cli/seat-ticket-binding.ts +2 -1
- package/src/public-cli/settlement.ts +43 -7
- package/src/public-cli/terminal.ts +33 -14
- package/src/public-role-summons.ts +3 -15
- package/src/role-run-placement.ts +1 -1
- package/src/run-dossier-files.ts +5 -2
- package/src/submission-gate.ts +3 -2
- package/src/submission-ledger.ts +32 -2
- package/src/ticket-address.ts +91 -0
- package/src/ticket-progress.ts +42 -0
|
@@ -86,16 +86,15 @@ export type RoleRunRecord = {
|
|
|
86
86
|
readonly phase?: CoderPhase | FixerPhase;
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
-
/**
|
|
89
|
+
/** Resume request for one located leg: the public address (ticket + seat) or an internal re-summons. */
|
|
90
90
|
export type PublicResumeRequest = {
|
|
91
91
|
readonly runId: string;
|
|
92
92
|
/**
|
|
93
|
-
* When already known (gate pass / same-ticket locator),
|
|
94
|
-
* instead of re-resolving runId across every book (#1195).
|
|
95
|
-
* Explicit public `ak-role resume <runId>` leaves this unset.
|
|
93
|
+
* When already known (public ticket address / gate pass / same-ticket locator),
|
|
94
|
+
* load this directory instead of re-resolving runId across every book (#1195).
|
|
96
95
|
*/
|
|
97
96
|
readonly runDirectory?: string;
|
|
98
|
-
/** Present when the caller supplied the
|
|
97
|
+
/** Present when the caller supplied the message argv (including empty string). */
|
|
99
98
|
readonly message?: string;
|
|
100
99
|
/**
|
|
101
100
|
* Same-ticket re-summons materials (#637). Present only when a public seat
|
|
@@ -860,7 +859,7 @@ export async function findRunDirectoryById(
|
|
|
860
859
|
const parsed = parseRunLeaf(basename(knownRunDirectory));
|
|
861
860
|
if (parsed === undefined || parsed.runId !== runId) {
|
|
862
861
|
throw new CliUsageError(
|
|
863
|
-
`run directory
|
|
862
|
+
`run directory is not the expected role run: ${knownRunDirectory}`,
|
|
864
863
|
);
|
|
865
864
|
}
|
|
866
865
|
return knownRunDirectory;
|
|
@@ -941,7 +940,7 @@ async function runHasFormedSessionPrincipal(runDirectory: string): Promise<boole
|
|
|
941
940
|
* parent run path (officer / gate seats, #747 / #987), narrowed to a supplied
|
|
942
941
|
* typed ticket for same-ticket gate re-summons. runId is UUIDv7 — lexicographic
|
|
943
942
|
* max is latest among runs that formed a session principal. No parallel index;
|
|
944
|
-
* callers
|
|
943
|
+
* callers address a leg explicitly with `ak-role resume <ticket> <seat>`.
|
|
945
944
|
* Only a truly missing book directory means no history; damage/permission errors propagate.
|
|
946
945
|
*/
|
|
947
946
|
export async function findLatestRunIdForSeatTicket(input: {
|
|
@@ -1068,19 +1067,20 @@ async function loadResumableRunRecord(
|
|
|
1068
1067
|
readonly admittedFields: LoadedAdmittedRequestFields;
|
|
1069
1068
|
}> {
|
|
1070
1069
|
const runDirectory = await findRunDirectoryById(home, runId, undefined, undefined, knownRunDirectory);
|
|
1070
|
+
// Diagnostics name the leg by its directory; the run id is not a caller-facing identity (#1201).
|
|
1071
1071
|
if (runDirectory === undefined) {
|
|
1072
|
-
throw new CliUsageError(`unknown role run
|
|
1072
|
+
throw new CliUsageError(`unknown role run: no run directory found under ${home}`);
|
|
1073
1073
|
}
|
|
1074
1074
|
const disk = await readRoleRunStateDisk(runDirectory);
|
|
1075
1075
|
if (disk === undefined) {
|
|
1076
|
-
throw new CliUsageError(`
|
|
1076
|
+
throw new CliUsageError(`role run has no readable state: ${runDirectory}`);
|
|
1077
1077
|
}
|
|
1078
1078
|
// #416 / #1091: removed terminal/resumable and local session-file gates.
|
|
1079
1079
|
// The load seam locates the run and recovers identity; host CLI answers continuation.
|
|
1080
1080
|
// One authority.decode of the uninterpreted wire yields both principal and record.
|
|
1081
1081
|
const materialized = materializeRoleRunFromDisk(disk, authority);
|
|
1082
1082
|
if (materialized === undefined) {
|
|
1083
|
-
throw new CliUsageError(`
|
|
1083
|
+
throw new CliUsageError(`role run has no readable state: ${runDirectory}`);
|
|
1084
1084
|
}
|
|
1085
1085
|
const { run, principal } = materialized;
|
|
1086
1086
|
// Reconstruct admitted identity from durable run record + the admitted section.
|
|
@@ -1249,7 +1249,7 @@ async function loadResumableRunRecord(
|
|
|
1249
1249
|
// Preserve unique --authority-ref grammar failures; do not collapse to unreadable.
|
|
1250
1250
|
if (error instanceof CliUsageError) throw error;
|
|
1251
1251
|
throw new CliUsageError(
|
|
1252
|
-
`role run admitted request is unreadable: ${
|
|
1252
|
+
`role run admitted request is unreadable: ${run.runDirectory}`,
|
|
1253
1253
|
{ cause: error },
|
|
1254
1254
|
);
|
|
1255
1255
|
}
|
|
@@ -1280,7 +1280,7 @@ async function loadResumableRunRecord(
|
|
|
1280
1280
|
}
|
|
1281
1281
|
if (!isEnoent(error)) {
|
|
1282
1282
|
throw new CliUsageError(
|
|
1283
|
-
`role run invocation identity is unreadable: ${
|
|
1283
|
+
`role run invocation identity is unreadable: ${run.runDirectory}`,
|
|
1284
1284
|
{ cause: error },
|
|
1285
1285
|
);
|
|
1286
1286
|
}
|
|
@@ -1408,7 +1408,7 @@ function admitResumedRole(loaded: {
|
|
|
1408
1408
|
readonly admittedFields: LoadedAdmittedRequestFields;
|
|
1409
1409
|
}): AdmittedRoleInvocation {
|
|
1410
1410
|
const role = loaded.run.role;
|
|
1411
|
-
const
|
|
1411
|
+
const leg = loaded.run.runDirectory;
|
|
1412
1412
|
const record = packagedRoleMetadata(role);
|
|
1413
1413
|
if (record === undefined) {
|
|
1414
1414
|
throw new CliUsageError(`unknown role: ${role}`);
|
|
@@ -1446,10 +1446,10 @@ function admitResumedRole(loaded: {
|
|
|
1446
1446
|
return admitted;
|
|
1447
1447
|
}
|
|
1448
1448
|
case "worker-task": {
|
|
1449
|
-
const phase = resumedWorkerPhase(fields.phase ?? loaded.run.phase, record.phases, role,
|
|
1449
|
+
const phase = resumedWorkerPhase(fields.phase ?? loaded.run.phase, record.phases, role, leg);
|
|
1450
1450
|
if (fields.instruction.trim() === "") {
|
|
1451
1451
|
throw new CliUsageError(
|
|
1452
|
-
`role run admitted coder task is blank: ${
|
|
1452
|
+
`role run admitted coder task is blank: ${leg}`,
|
|
1453
1453
|
);
|
|
1454
1454
|
}
|
|
1455
1455
|
const admitted: AdmittedCoderInvocation = {
|
|
@@ -1461,10 +1461,10 @@ function admitResumedRole(loaded: {
|
|
|
1461
1461
|
return admitted;
|
|
1462
1462
|
}
|
|
1463
1463
|
case "worker-packet": {
|
|
1464
|
-
const phase = resumedWorkerPhase(fields.phase ?? loaded.run.phase, record.phases, role,
|
|
1464
|
+
const phase = resumedWorkerPhase(fields.phase ?? loaded.run.phase, record.phases, role, leg);
|
|
1465
1465
|
if (fields.instruction.trim() === "") {
|
|
1466
1466
|
throw new CliUsageError(
|
|
1467
|
-
`role run admitted fixer instruction is blank: ${
|
|
1467
|
+
`role run admitted fixer instruction is blank: ${leg}`,
|
|
1468
1468
|
);
|
|
1469
1469
|
}
|
|
1470
1470
|
const admitted: AdmittedFixerInvocation = {
|
|
@@ -1484,20 +1484,20 @@ function admitResumedRole(loaded: {
|
|
|
1484
1484
|
if (baseFault !== undefined || rawBase === undefined) {
|
|
1485
1485
|
throw new CliUsageError(
|
|
1486
1486
|
baseFault === "damaged"
|
|
1487
|
-
? `role run admitted reviewer base revision is damaged: ${
|
|
1488
|
-
: `role run admitted reviewer base revision is missing: ${
|
|
1487
|
+
? `role run admitted reviewer base revision is damaged: ${leg}`
|
|
1488
|
+
: `role run admitted reviewer base revision is missing: ${leg}`,
|
|
1489
1489
|
);
|
|
1490
1490
|
}
|
|
1491
1491
|
const lens = fields.lens;
|
|
1492
1492
|
if (!isReviewerLens(lens)) {
|
|
1493
1493
|
throw new CliUsageError(
|
|
1494
|
-
`role run admitted reviewer lens is missing: ${
|
|
1494
|
+
`role run admitted reviewer lens is missing: ${leg}`,
|
|
1495
1495
|
);
|
|
1496
1496
|
}
|
|
1497
1497
|
const authorityRefs = Object.freeze([...(fields.authorityRefs ?? [])]);
|
|
1498
1498
|
if (authorityRefs.length === 0) {
|
|
1499
1499
|
throw new CliUsageError(
|
|
1500
|
-
`role run admitted reviewer authority refs are missing: ${
|
|
1500
|
+
`role run admitted reviewer authority refs are missing: ${leg}`,
|
|
1501
1501
|
);
|
|
1502
1502
|
}
|
|
1503
1503
|
const admitted: AdmittedReviewerInvocation = {
|
|
@@ -1513,7 +1513,7 @@ function admitResumedRole(loaded: {
|
|
|
1513
1513
|
const baseRevision = fields.baseRevision;
|
|
1514
1514
|
if (baseRevision === undefined || baseRevision.trim() === "") {
|
|
1515
1515
|
throw new CliUsageError(
|
|
1516
|
-
`role run admitted gleaner-left base revision is missing: ${
|
|
1516
|
+
`role run admitted gleaner-left base revision is missing: ${leg}`,
|
|
1517
1517
|
);
|
|
1518
1518
|
}
|
|
1519
1519
|
const admitted: AdmittedGleanerLeftInvocation = {
|
|
@@ -1527,18 +1527,18 @@ function admitResumedRole(loaded: {
|
|
|
1527
1527
|
const mergerInputPath = fields.mergerInputPath;
|
|
1528
1528
|
if (mergerInputPath === undefined) {
|
|
1529
1529
|
throw new CliUsageError(
|
|
1530
|
-
`role run admitted merger input path is missing: ${
|
|
1530
|
+
`role run admitted merger input path is missing: ${leg}`,
|
|
1531
1531
|
);
|
|
1532
1532
|
}
|
|
1533
1533
|
const derived = fields.derived;
|
|
1534
1534
|
if (derived === undefined) {
|
|
1535
1535
|
throw new CliUsageError(
|
|
1536
|
-
`role run admitted merger envelope is missing: ${
|
|
1536
|
+
`role run admitted merger envelope is missing: ${leg}`,
|
|
1537
1537
|
);
|
|
1538
1538
|
}
|
|
1539
1539
|
if (fields.instruction.trim() === "") {
|
|
1540
1540
|
throw new CliUsageError(
|
|
1541
|
-
`role run admitted merger task is blank: ${
|
|
1541
|
+
`role run admitted merger task is blank: ${leg}`,
|
|
1542
1542
|
);
|
|
1543
1543
|
}
|
|
1544
1544
|
const admitted: AdmittedMergerInvocation = {
|
|
@@ -1554,7 +1554,7 @@ function admitResumedRole(loaded: {
|
|
|
1554
1554
|
const { prNumber, repository, repositoryDisplay } = fields;
|
|
1555
1555
|
if (repository === undefined || repositoryDisplay === undefined) {
|
|
1556
1556
|
throw new CliUsageError(
|
|
1557
|
-
`role run admitted collector repository identity is missing: ${
|
|
1557
|
+
`role run admitted collector repository identity is missing: ${leg}`,
|
|
1558
1558
|
);
|
|
1559
1559
|
}
|
|
1560
1560
|
let parsedRepository;
|
|
@@ -1566,7 +1566,7 @@ function admitResumedRole(loaded: {
|
|
|
1566
1566
|
}
|
|
1567
1567
|
if (parsedRepository.canonical !== repository) {
|
|
1568
1568
|
throw new CliUsageError(
|
|
1569
|
-
`role run admitted collector repository does not match its canonical form: ${
|
|
1569
|
+
`role run admitted collector repository does not match its canonical form: ${leg}`,
|
|
1570
1570
|
);
|
|
1571
1571
|
}
|
|
1572
1572
|
const admitted: AdmittedCollectorInvocation = {
|
|
@@ -1589,7 +1589,7 @@ function admitResumedRole(loaded: {
|
|
|
1589
1589
|
caseIdentity === undefined
|
|
1590
1590
|
) {
|
|
1591
1591
|
throw new CliUsageError(
|
|
1592
|
-
`role run admitted doctor case identity is missing: ${
|
|
1592
|
+
`role run admitted doctor case identity is missing: ${leg}`,
|
|
1593
1593
|
);
|
|
1594
1594
|
}
|
|
1595
1595
|
const admitted: AdmittedDoctorInvocation = {
|
|
@@ -1605,7 +1605,7 @@ function admitResumedRole(loaded: {
|
|
|
1605
1605
|
const { sourceRunPath, sourceRun } = fields;
|
|
1606
1606
|
if (sourceRunPath === undefined || sourceRun === undefined) {
|
|
1607
1607
|
throw new CliUsageError(
|
|
1608
|
-
`role run admitted notary source-run locator is missing: ${
|
|
1608
|
+
`role run admitted notary source-run locator is missing: ${leg}`,
|
|
1609
1609
|
);
|
|
1610
1610
|
}
|
|
1611
1611
|
const admitted: AdmittedNotaryInvocation = {
|
|
@@ -1624,12 +1624,12 @@ function resumedWorkerPhase(
|
|
|
1624
1624
|
phase: string | undefined,
|
|
1625
1625
|
phases: readonly (string | null)[],
|
|
1626
1626
|
role: string,
|
|
1627
|
-
|
|
1627
|
+
leg: string,
|
|
1628
1628
|
): "plan" | "apply" {
|
|
1629
1629
|
if (phase === "plan" || phase === "apply") {
|
|
1630
1630
|
if (phases.some((item) => item === phase)) {
|
|
1631
1631
|
return phase;
|
|
1632
1632
|
}
|
|
1633
1633
|
}
|
|
1634
|
-
throw new CliUsageError(`role run admitted ${role} phase is missing: ${
|
|
1634
|
+
throw new CliUsageError(`role run admitted ${role} phase is missing: ${leg}`);
|
|
1635
1635
|
}
|
|
@@ -20,7 +20,8 @@ function resumedSessionIdMissing(result: unknown, runId: string): boolean {
|
|
|
20
20
|
if (typeof result !== "object" || result === null) return false;
|
|
21
21
|
const terminal = (result as { terminal?: unknown }).terminal;
|
|
22
22
|
if (typeof terminal !== "object" || terminal === null) return false;
|
|
23
|
-
|
|
23
|
+
// The failure belongs to the resumed leg, not to another seat presented in its place.
|
|
24
|
+
if ((result as { admitted?: { runId?: unknown } }).admitted?.runId !== runId) return false;
|
|
24
25
|
const outcome = (terminal as { roleOutcome?: unknown }).roleOutcome;
|
|
25
26
|
if (typeof outcome !== "object" || outcome === null) return false;
|
|
26
27
|
if ((outcome as { kind?: unknown }).kind !== "failure") return false;
|
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
* Controlled failures and audit human decisions settle here without washing causes.
|
|
5
5
|
*/
|
|
6
6
|
import { randomUUID } from "node:crypto";
|
|
7
|
-
import {
|
|
7
|
+
import { basename, join } from "node:path";
|
|
8
8
|
import { lstat, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
9
9
|
|
|
10
|
-
import { sessionFileOf } from "../role-run-placement.ts";
|
|
10
|
+
import { sessionFileOf, subjectDirectoryOfRun } from "../role-run-placement.ts";
|
|
11
|
+
import { parseTicketNumber } from "../run-ticket-number.ts";
|
|
11
12
|
|
|
12
13
|
import { sitianReport, type RecordPointer } from "../sitian-facade.ts";
|
|
13
14
|
import {
|
|
@@ -186,8 +187,34 @@ type SealedLedgerSettle = {
|
|
|
186
187
|
readonly outcome: Extract<TerminalRoleOutcome, { kind: "accepted" | "audit_escalation" }>;
|
|
187
188
|
/** Tool-call identity of the latest this-settle terminal row (#1171 F2-R8). */
|
|
188
189
|
readonly submissionToolCallId?: string;
|
|
190
|
+
/** Progress rows written for this settle's accepted submissions (#1201). */
|
|
191
|
+
readonly filed: readonly FiledReceipt[];
|
|
189
192
|
};
|
|
190
193
|
|
|
194
|
+
/** Receipt reference and round as the progress row carries them. */
|
|
195
|
+
type FiledReceipt = { readonly receipt: string; readonly round?: string };
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* #1201 public identity of a leg's terminal: the ticket it is filed under and
|
|
199
|
+
* the receipts this settle accepted. Row references resolve under the leg's
|
|
200
|
+
* subject directory as it stands now; a leg that has reported no ticket names
|
|
201
|
+
* no ticket and no round.
|
|
202
|
+
*/
|
|
203
|
+
export function filedIdentity(
|
|
204
|
+
runDirectory: string,
|
|
205
|
+
filed: readonly FiledReceipt[] = [],
|
|
206
|
+
): Pick<TerminalResult, "ticket" | "receipts"> {
|
|
207
|
+
const subjectDirectory = subjectDirectoryOfRun(runDirectory);
|
|
208
|
+
if (subjectDirectory === undefined) return {};
|
|
209
|
+
const ticket = parseTicketNumber(basename(subjectDirectory));
|
|
210
|
+
return {
|
|
211
|
+
...(ticket === undefined ? {} : { ticket }),
|
|
212
|
+
...(filed.length === 0 ? {} : {
|
|
213
|
+
receipts: filed.map((row) => ({ ...row, receipt: join(subjectDirectory, row.receipt) })),
|
|
214
|
+
}),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
191
218
|
function roleOutcomeFromRows(
|
|
192
219
|
role: TerminalRoleName,
|
|
193
220
|
rows: readonly {
|
|
@@ -197,6 +224,8 @@ function roleOutcomeFromRows(
|
|
|
197
224
|
readonly auditReceipt?: unknown;
|
|
198
225
|
readonly auditOfficer?: unknown;
|
|
199
226
|
readonly toolCallId?: string;
|
|
227
|
+
readonly receipt?: string;
|
|
228
|
+
readonly round?: string;
|
|
200
229
|
}[],
|
|
201
230
|
): SealedLedgerSettle | undefined {
|
|
202
231
|
const mine = rows.filter((row) => row.role === role);
|
|
@@ -215,8 +244,13 @@ function roleOutcomeFromRows(
|
|
|
215
244
|
typeof latest.toolCallId === "string" && latest.toolCallId.length > 0
|
|
216
245
|
? latest.toolCallId
|
|
217
246
|
: undefined;
|
|
218
|
-
const
|
|
219
|
-
|
|
247
|
+
const filed = mine.flatMap((row): FiledReceipt[] => row.receipt === undefined
|
|
248
|
+
? []
|
|
249
|
+
: [{ receipt: row.receipt, ...(row.round === undefined ? {} : { round: row.round }) }]);
|
|
250
|
+
const belonging = {
|
|
251
|
+
...(submissionToolCallId === undefined ? {} : { submissionToolCallId }),
|
|
252
|
+
filed,
|
|
253
|
+
};
|
|
220
254
|
if (latest.kind === "audit-escalation") {
|
|
221
255
|
return {
|
|
222
256
|
outcome: {
|
|
@@ -468,7 +502,7 @@ async function settleNoReceiptTerminal(
|
|
|
468
502
|
scope,
|
|
469
503
|
),
|
|
470
504
|
artifacts: [],
|
|
471
|
-
|
|
505
|
+
...filedIdentity(admitted.runDirectory),
|
|
472
506
|
}, coordinates.sessionDirectory, detourUsageContext(admitted, scope));
|
|
473
507
|
}
|
|
474
508
|
|
|
@@ -1449,6 +1483,7 @@ async function settleSealedSeat(
|
|
|
1449
1483
|
settled.outcome,
|
|
1450
1484
|
scope,
|
|
1451
1485
|
settled.submissionToolCallId,
|
|
1486
|
+
settled.filed,
|
|
1452
1487
|
);
|
|
1453
1488
|
}
|
|
1454
1489
|
|
|
@@ -1459,6 +1494,7 @@ async function finishLawfulSeat(
|
|
|
1459
1494
|
roleOutcome: TerminalRoleOutcome,
|
|
1460
1495
|
scope: SettlementCourtScope | undefined,
|
|
1461
1496
|
submissionToolCallId?: string,
|
|
1497
|
+
filed?: readonly FiledReceipt[],
|
|
1462
1498
|
): Promise<TerminalResult> {
|
|
1463
1499
|
const artifacts = scope?.previewOnly === true
|
|
1464
1500
|
? []
|
|
@@ -1467,7 +1503,7 @@ async function finishLawfulSeat(
|
|
|
1467
1503
|
roleOutcome,
|
|
1468
1504
|
navigator: isNavigatorSeat(admitted.role) ? NAVIGATOR_SEAT_OWN_FACT : extractNavigatorFact(entries),
|
|
1469
1505
|
artifacts,
|
|
1470
|
-
|
|
1506
|
+
...filedIdentity(admitted.runDirectory, filed),
|
|
1471
1507
|
...(submissionToolCallId === undefined || submissionToolCallId.length === 0
|
|
1472
1508
|
? {}
|
|
1473
1509
|
: { submissionToolCallId }),
|
|
@@ -1714,7 +1750,7 @@ export async function settleFailureTerminalResult(
|
|
|
1714
1750
|
decisiveFacts,
|
|
1715
1751
|
};
|
|
1716
1752
|
return attachEngineDetourToolUsage(
|
|
1717
|
-
{ roleOutcome, navigator, artifacts,
|
|
1753
|
+
{ roleOutcome, navigator, artifacts, ...filedIdentity(admitted.runDirectory) },
|
|
1718
1754
|
sessionDirectory,
|
|
1719
1755
|
detourUsageContext(admitted, options),
|
|
1720
1756
|
);
|
|
@@ -142,17 +142,25 @@ export type TerminalResult = {
|
|
|
142
142
|
submissionToolCallId?: string;
|
|
143
143
|
/** Call-local auto-resume observation (0..2) for this single LLM call; read-only, not persisted. */
|
|
144
144
|
autoResumeCount?: number;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
145
|
+
/**
|
|
146
|
+
* #1201 public identity: ticket + seat + round + receipt. The seat is
|
|
147
|
+
* roleOutcome.role. Absent while the leg has reported no ticket, and on a
|
|
148
|
+
* reviewer batch: a batch is no leg, each lens in reviewerChildren carries its own.
|
|
149
|
+
*/
|
|
150
|
+
ticket?: number;
|
|
151
|
+
/** One per accepted submission in roleOutcome.payloads, in ledger order. */
|
|
152
|
+
receipts?: readonly TerminalReceiptRef[];
|
|
153
|
+
/** Deterministic public batch projection; no parent Role run exists. */
|
|
154
|
+
batch?: "reviewer";
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/** One accepted receipt as the ticket's progress row names it (#1201). */
|
|
158
|
+
export type TerminalReceiptRef = {
|
|
159
|
+
/** Seat-local round on the ticket; absent while the leg has reported no ticket. */
|
|
160
|
+
readonly round?: string;
|
|
161
|
+
/** Path of the receipt original: the row's reference under its subject directory. */
|
|
162
|
+
readonly receipt: string;
|
|
163
|
+
};
|
|
156
164
|
|
|
157
165
|
/**
|
|
158
166
|
* Build an advice navigator fact (#959). Prose is presented as submitted;
|
|
@@ -162,6 +170,16 @@ export function adviceNavigatorFact(input: { prose: string }): TerminalNavigator
|
|
|
162
170
|
return { disposition: "advice", prose: input.prose };
|
|
163
171
|
}
|
|
164
172
|
|
|
173
|
+
/** One leg's public identity rows (#1201): its ticket, then its receipts newest first. */
|
|
174
|
+
function identityRows(leg: TerminalResult): string[] {
|
|
175
|
+
const seat = leg.roleOutcome.role;
|
|
176
|
+
return [
|
|
177
|
+
...(leg.ticket === undefined ? [] : [`ticket\t${leg.ticket}`]),
|
|
178
|
+
...[...(leg.receipts ?? [])].reverse().map((filed) =>
|
|
179
|
+
`receipt\t${encodeTerminalField(filed.round === undefined ? seat : `${seat}#${filed.round}`)}\t${encodeTerminalField(filed.receipt)}`),
|
|
180
|
+
];
|
|
181
|
+
}
|
|
182
|
+
|
|
165
183
|
/**
|
|
166
184
|
* Present one Terminal result for humans. Labels, row order, wording, and layout
|
|
167
185
|
* are unfrozen (ADR 0052). Machine consumers and tests must read typed
|
|
@@ -227,11 +245,12 @@ export function formatTerminalResult(result: TerminalResult): string {
|
|
|
227
245
|
if (child.stderr !== undefined && child.stderr !== "") {
|
|
228
246
|
lines.push(`reviewer-child-diagnostic\t${axis}\t${encodeTerminalField(child.stderr)}`);
|
|
229
247
|
}
|
|
248
|
+
// Each lens reports under its own ticket: the two may have reported different ones.
|
|
249
|
+
const lens = result.reviewerChildren?.[axis];
|
|
250
|
+
if (lens !== undefined) lines.push(...identityRows(lens));
|
|
230
251
|
}
|
|
231
252
|
}
|
|
232
|
-
|
|
233
|
-
lines.push(`run\t${encodeTerminalField(result.runId)}`);
|
|
234
|
-
}
|
|
253
|
+
lines.push(...identityRows(result));
|
|
235
254
|
if (result.autoResumeCount !== undefined) {
|
|
236
255
|
lines.push(`autoResumeCount\t${encodeTerminalField(String(result.autoResumeCount))}`);
|
|
237
256
|
}
|
|
@@ -522,21 +522,9 @@ export async function summonPublicRole(
|
|
|
522
522
|
}
|
|
523
523
|
|
|
524
524
|
const stderr = captured?.stderrText();
|
|
525
|
-
// Nested escalate
|
|
526
|
-
//
|
|
527
|
-
|
|
528
|
-
if (
|
|
529
|
-
result.terminal !== undefined
|
|
530
|
-
&& result.terminal.roleOutcome.role !== options.role
|
|
531
|
-
&& typeof result.terminal.runId === "string"
|
|
532
|
-
&& result.admitted?.runId !== result.terminal.runId
|
|
533
|
-
) {
|
|
534
|
-
// Compatibility surface with no admitted locator for that terminal.
|
|
535
|
-
runDirectory = await (await import("./public-cli/run-lifecycle.ts")).findRunDirectoryById(
|
|
536
|
-
home,
|
|
537
|
-
result.terminal.runId,
|
|
538
|
-
) ?? runDirectory;
|
|
539
|
-
}
|
|
525
|
+
// Nested escalate returns the officer's terminal with that officer's admitted
|
|
526
|
+
// leg beside it — the run directory in hand is the one that terminal belongs to (#1195).
|
|
527
|
+
const runDirectory = result.admitted?.runDirectory;
|
|
540
528
|
return {
|
|
541
529
|
exitCode: result.exitCode,
|
|
542
530
|
...(result.terminal === undefined ? {} : { terminal: result.terminal }),
|
|
@@ -143,7 +143,7 @@ export async function findRoleRunDirectory(
|
|
|
143
143
|
}
|
|
144
144
|
if (matches.length === 0) return undefined;
|
|
145
145
|
if (matches.length === 1) return matches[0];
|
|
146
|
-
throw new Error(`ambiguous role run
|
|
146
|
+
throw new Error(`ambiguous role run: ${matches.join(", ")}`);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
/** The single authority for every path belonging to an admitted role run. */
|
package/src/run-dossier-files.ts
CHANGED
|
@@ -10,13 +10,16 @@ export const RUN_STATE_FILE = "state.jsonl" as const;
|
|
|
10
10
|
/**
|
|
11
11
|
* Record kinds that make a leg's history: they land in `history.jsonl`. The
|
|
12
12
|
* original submission ledger and attempt history, the prompt/schema each turn was
|
|
13
|
-
* started with, and
|
|
13
|
+
* started with, officer pointers, and the ticket progress rows a leg wrote.
|
|
14
14
|
*/
|
|
15
15
|
export const RUN_HISTORY_KINDS: ReadonlySet<string> = new Set([
|
|
16
16
|
"candidate", "roundContext", "outcome", "sealed", "post-seal-anomaly",
|
|
17
|
-
"attempt-history", "turn-delivery", "officer-pointer",
|
|
17
|
+
"attempt-history", "turn-delivery", "officer-pointer", "progress",
|
|
18
18
|
]);
|
|
19
19
|
|
|
20
|
+
/** History record kind of a ticket progress row carried to settlement (#1201). */
|
|
21
|
+
export const PROGRESS_RECORD_KIND = "progress" as const;
|
|
22
|
+
|
|
20
23
|
/** History record kind of a booked officer pointer (appender routes it to history.jsonl). */
|
|
21
24
|
export const OFFICER_POINTER_RECORD_KIND = "officer-pointer" as const;
|
|
22
25
|
|
package/src/submission-gate.ts
CHANGED
|
@@ -21,6 +21,7 @@ import { persistAdmittedAuditedSubmissionToolCallId } from "./public-cli/invocat
|
|
|
21
21
|
import { readRunParentPath, readRoleRunIdentity } from "./public-cli/run-lifecycle.ts";
|
|
22
22
|
import {
|
|
23
23
|
officerConclusionReask,
|
|
24
|
+
officerRunIdFromSummoned,
|
|
24
25
|
projectGatekeeperRun,
|
|
25
26
|
type GatekeeperSubject,
|
|
26
27
|
type GateOfficer,
|
|
@@ -262,7 +263,7 @@ export async function requireSubmissionGate(options: {
|
|
|
262
263
|
officer: projected.officer,
|
|
263
264
|
receipt: gatekeeper.submission ?? { reason: gatekeeper.reason },
|
|
264
265
|
reason: gatekeeper.reason,
|
|
265
|
-
runId: projected.summoned
|
|
266
|
+
runId: projected.summoned === undefined ? undefined : officerRunIdFromSummoned(projected.summoned),
|
|
266
267
|
runDirectory: projected.summoned?.runDirectory,
|
|
267
268
|
terminal: projected.summoned?.terminal,
|
|
268
269
|
});
|
|
@@ -285,7 +286,7 @@ export async function requireSubmissionGate(options: {
|
|
|
285
286
|
officer: projected.officer,
|
|
286
287
|
receipt: gatekeeper.facts ?? { reason: gatekeeper.reason },
|
|
287
288
|
reason: gatekeeper.reason,
|
|
288
|
-
runId: projected.summoned
|
|
289
|
+
runId: projected.summoned === undefined ? undefined : officerRunIdFromSummoned(projected.summoned),
|
|
289
290
|
runDirectory: projected.summoned?.runDirectory,
|
|
290
291
|
terminal: projected.summoned?.terminal,
|
|
291
292
|
});
|
package/src/submission-ledger.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
import { runIdFromRunDirectory } from "./run-terminal-artifacts.ts";
|
|
17
17
|
import { readSitianRecords, resolveSitianRecordPathInLedger, sitianReport, type RecordPointer } from "./sitian-facade.ts";
|
|
18
18
|
import type { SitianRecord } from "./sitian-contracts.ts";
|
|
19
|
+
import { PROGRESS_RECORD_KIND } from "./run-dossier-files.ts";
|
|
19
20
|
import { findRunDirectoryById } from "./public-cli/run-lifecycle.ts";
|
|
20
21
|
import type { TerminalRoleName } from "./public-cli/terminal.ts";
|
|
21
22
|
import { isCorrectableExecuteError } from "./submission-correctable-error.ts";
|
|
@@ -116,6 +117,12 @@ export type RecordedSubmissionRow = {
|
|
|
116
117
|
readonly auditOfficer?: unknown;
|
|
117
118
|
/** Present when the ledger row names the tool call — used to dedupe candidate+outcome. */
|
|
118
119
|
readonly toolCallId?: string;
|
|
120
|
+
/**
|
|
121
|
+
* #1201: the ticket progress row written for this accepted submission — its
|
|
122
|
+
* receipt reference, and its round once the leg is filed under a ticket.
|
|
123
|
+
*/
|
|
124
|
+
readonly receipt?: string;
|
|
125
|
+
readonly round?: string;
|
|
119
126
|
};
|
|
120
127
|
|
|
121
128
|
/** Closed-submission callback: original payload, no status/facts projection (#836). */
|
|
@@ -285,8 +292,23 @@ function rowFromPayload(
|
|
|
285
292
|
*/
|
|
286
293
|
function mapOwnedToSubmissionRows(
|
|
287
294
|
owned: readonly { kind?: unknown; subject?: unknown; payload?: unknown }[],
|
|
295
|
+
/** Whole-leg records: a round filled at bind carries no court attempt (#1201). */
|
|
296
|
+
leg: readonly { kind?: unknown; subject?: unknown; payload?: unknown }[] = owned,
|
|
288
297
|
): readonly RecordedSubmissionRow[] {
|
|
289
298
|
const scoped = owned;
|
|
299
|
+
const receiptByCall = new Map<string, string>();
|
|
300
|
+
const roundByReceipt = new Map<string, string>();
|
|
301
|
+
for (const record of leg) {
|
|
302
|
+
if (record.kind !== PROGRESS_RECORD_KIND) continue;
|
|
303
|
+
const payload = record.payload as { toolCallId?: unknown; receipt?: unknown; round?: unknown } | undefined;
|
|
304
|
+
if (typeof payload?.receipt !== "string") continue;
|
|
305
|
+
if (typeof payload.toolCallId === "string") {
|
|
306
|
+
receiptByCall.set(submissionCallKey(recordAttemptId(record), payload.toolCallId), payload.receipt);
|
|
307
|
+
}
|
|
308
|
+
if (typeof payload.round === "string" && payload.round !== "") {
|
|
309
|
+
roundByReceipt.set(payload.receipt, payload.round);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
290
312
|
const out: RecordedSubmissionRow[] = [];
|
|
291
313
|
const indexByCall = new Map<string, number>();
|
|
292
314
|
// Recover seat identity for historical non-sealed rows that omitted role (#881).
|
|
@@ -359,7 +381,13 @@ function mapOwnedToSubmissionRows(
|
|
|
359
381
|
? submissionCallKey(recordAttemptId(record), payload.toolCallId)
|
|
360
382
|
: undefined;
|
|
361
383
|
const fallback = callKey === undefined ? undefined : roleByCall.get(callKey);
|
|
362
|
-
|
|
384
|
+
const receipt = kind === "accepted" && callKey !== undefined ? receiptByCall.get(callKey) : undefined;
|
|
385
|
+
const round = receipt === undefined ? undefined : roundByReceipt.get(receipt);
|
|
386
|
+
take({
|
|
387
|
+
...rowFromPayload(kind, payload, original, fallback),
|
|
388
|
+
...(receipt === undefined ? {} : { receipt }),
|
|
389
|
+
...(round === undefined ? {} : { round }),
|
|
390
|
+
}, callKey);
|
|
363
391
|
}
|
|
364
392
|
return out;
|
|
365
393
|
}
|
|
@@ -394,7 +422,7 @@ export async function readAttemptScopedSubmissionRows(
|
|
|
394
422
|
if (attemptId.length === 0) return [];
|
|
395
423
|
const scope = resolveReadScope(homeOrScope);
|
|
396
424
|
const { owned } = await readOwnedSubmissionRecords(cwd, runId, scope);
|
|
397
|
-
return mapOwnedToSubmissionRows(owned.filter((record) => recordAttemptId(record) === attemptId));
|
|
425
|
+
return mapOwnedToSubmissionRows(owned.filter((record) => recordAttemptId(record) === attemptId), owned);
|
|
398
426
|
}
|
|
399
427
|
|
|
400
428
|
/** #1214 R2c: the court-turn attempt that recorded this tool call's submission, if any. */
|
|
@@ -511,6 +539,7 @@ export function sealAcceptedSubmission(options: {
|
|
|
511
539
|
sealHead,
|
|
512
540
|
sessionFile: undefined,
|
|
513
541
|
instruction: options.instruction ?? "",
|
|
542
|
+
call: { attemptId, toolCallId: options.toolCallId },
|
|
514
543
|
});
|
|
515
544
|
}
|
|
516
545
|
|
|
@@ -668,6 +697,7 @@ export function createSubmissionLedgerHost(
|
|
|
668
697
|
...(rawLens === "completeness" || rawLens === "correctness"
|
|
669
698
|
? { lens: rawLens }
|
|
670
699
|
: {}),
|
|
700
|
+
call: { attemptId, toolCallId },
|
|
671
701
|
});
|
|
672
702
|
// Native structured-output hosts have no tool-result reply to the model.
|
|
673
703
|
// Keep the conversation open only after the receipt is durably sealed.
|