@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.
Files changed (45) hide show
  1. package/README.md +3 -3
  2. package/README.zh-CN.md +3 -3
  3. package/dist/acp-host/production-host.js +354 -250
  4. package/dist/engine-detour-usage.js +2 -1
  5. package/dist/gatekeeper-role.js +3 -15
  6. package/dist/headless-host/description.js +4 -1
  7. package/dist/headless-host/production-host.js +340 -236
  8. package/dist/migrate-book-topology.js +39 -22
  9. package/dist/notary-source-run.js +8 -8
  10. package/dist/public-cli/auto-resume.js +3 -3
  11. package/dist/public-cli/cli.js +38 -32
  12. package/dist/public-cli/instruction-seat-run.js +2 -5
  13. package/dist/public-cli/main.js +310 -208
  14. package/dist/public-cli/option-definitions.js +22 -21
  15. package/dist/public-cli/run-lifecycle.js +27 -26
  16. package/dist/public-cli/seat-ticket-binding.js +2 -1
  17. package/dist/public-cli/settlement.js +33 -8
  18. package/dist/public-cli/terminal.js +13 -3
  19. package/dist/public-role-summons.js +1 -7
  20. package/dist/role-run-placement.js +1 -1
  21. package/dist/run-dossier-files.js +4 -2
  22. package/dist/submission-gate.js +3 -3
  23. package/dist/submission-ledger.js +29 -3
  24. package/dist/ticket-address.js +77 -0
  25. package/dist/ticket-progress.js +31 -0
  26. package/package.json +1 -1
  27. package/src/engine-detour-usage.ts +2 -1
  28. package/src/gatekeeper-role.ts +5 -18
  29. package/src/headless-host/description.ts +4 -1
  30. package/src/notary-source-run.ts +8 -8
  31. package/src/public-cli/auto-resume.ts +4 -3
  32. package/src/public-cli/cli.ts +53 -32
  33. package/src/public-cli/instruction-seat-run.ts +2 -5
  34. package/src/public-cli/option-definitions.ts +22 -21
  35. package/src/public-cli/run-lifecycle.ts +31 -31
  36. package/src/public-cli/seat-ticket-binding.ts +2 -1
  37. package/src/public-cli/settlement.ts +43 -7
  38. package/src/public-cli/terminal.ts +33 -14
  39. package/src/public-role-summons.ts +3 -15
  40. package/src/role-run-placement.ts +1 -1
  41. package/src/run-dossier-files.ts +5 -2
  42. package/src/submission-gate.ts +3 -2
  43. package/src/submission-ledger.ts +32 -2
  44. package/src/ticket-address.ts +91 -0
  45. package/src/ticket-progress.ts +42 -0
@@ -0,0 +1,91 @@
1
+ /**
2
+ * #1201 public address: ticket + seat (+ round). One locator shared by
3
+ * `ak-role resume <ticket> <seat>[#<round>]` and
4
+ * `--source-run <ticket>:<seat>#<round>` (ADR 0088).
5
+ *
6
+ * Only legs filed under the ticket are visible here. A leg that has reported no
7
+ * ticket stays in `unbound/` and is not in this address.
8
+ */
9
+ import { existsSync, readdirSync, statSync } from "node:fs";
10
+ import { join } from "node:path";
11
+
12
+ import { CliUsageError } from "./public-cli/cli-errors.ts";
13
+ import { parseRunLeaf } from "./role-run-placement.ts";
14
+ import { parseTicketNumber } from "./run-ticket-number.ts";
15
+ import { readTicketProgressLines } from "./ticket-progress.ts";
16
+
17
+ export type TicketLegAddress = {
18
+ readonly ticketNumber: number;
19
+ readonly seat: string;
20
+ /** Round as written on the progress row (`2`, `1.completeness`). */
21
+ readonly round?: string;
22
+ };
23
+
24
+ /** Bare digits; a quoted leading `#` is accepted. */
25
+ export function parseAddressTicket(token: string): number | undefined {
26
+ return parseTicketNumber(token.startsWith("#") ? token.slice(1) : token);
27
+ }
28
+
29
+ /** `<seat>` or `<seat>#<round>`. */
30
+ export function parseSeatRound(token: string): { readonly seat: string; readonly round?: string } {
31
+ const hash = token.indexOf("#");
32
+ return hash === -1
33
+ ? { seat: token }
34
+ : { seat: token.slice(0, hash), round: token.slice(hash + 1) };
35
+ }
36
+
37
+ /** `<ticket>:<seat>#<round>`; undefined when the token is not that spelling. */
38
+ export function parseTicketLegLocator(token: string): Required<TicketLegAddress> | undefined {
39
+ const colon = token.indexOf(":");
40
+ if (colon === -1) return undefined;
41
+ const ticketNumber = parseAddressTicket(token.slice(0, colon));
42
+ const { seat, round } = parseSeatRound(token.slice(colon + 1));
43
+ if (ticketNumber === undefined || seat === "" || round === undefined || round === "") {
44
+ return undefined;
45
+ }
46
+ return { ticketNumber, seat, round };
47
+ }
48
+
49
+ /**
50
+ * Run directory of the addressed leg under the caller's book directory.
51
+ * With a round: the leg that sealed that progress row (the row's receipt
52
+ * reference names it). Without: the seat's most recently active leg under the
53
+ * ticket, read off the leg directories themselves — rows exist only for accepted
54
+ * receipts, so a leg that has not submitted yet is still found. Activity is the
55
+ * leg directory's mtime: every turn takes and releases the leg's writer lease
56
+ * there. One `runs/` listing and one stat per leg of the seat.
57
+ */
58
+ export function locateTicketLeg(bookDirectory: string, input: TicketLegAddress): string {
59
+ const ticketDirectory = join(bookDirectory, String(input.ticketNumber));
60
+ if (!existsSync(ticketDirectory)) {
61
+ throw new CliUsageError(`ticket ${input.ticketNumber} has no records in this project's book: ${ticketDirectory}`);
62
+ }
63
+ if (input.round !== undefined) {
64
+ const row = readTicketProgressLines(ticketDirectory)
65
+ .find((line) => line.seat === input.seat && line.round === input.round);
66
+ if (row === undefined) {
67
+ throw new CliUsageError(
68
+ `ticket ${input.ticketNumber} has no progress row ${input.seat}#${input.round}`,
69
+ );
70
+ }
71
+ // `runs/<leg>/receipts/<n>.json`
72
+ return join(ticketDirectory, ...row.receipt.split("/").slice(0, 2));
73
+ }
74
+ const runsDirectory = join(ticketDirectory, "runs");
75
+ let latest: { readonly leaf: string; readonly mtimeMs: number } | undefined;
76
+ for (const entry of existsSync(runsDirectory) ? readdirSync(runsDirectory, { withFileTypes: true }) : []) {
77
+ if (!entry.isDirectory() || parseRunLeaf(entry.name)?.role !== input.seat) continue;
78
+ const { mtimeMs } = statSync(join(runsDirectory, entry.name));
79
+ if (
80
+ latest === undefined
81
+ || mtimeMs > latest.mtimeMs
82
+ || (mtimeMs === latest.mtimeMs && entry.name > latest.leaf)
83
+ ) {
84
+ latest = { leaf: entry.name, mtimeMs };
85
+ }
86
+ }
87
+ if (latest === undefined) {
88
+ throw new CliUsageError(`ticket ${input.ticketNumber} has no ${input.seat} leg`);
89
+ }
90
+ return join(runsDirectory, latest.leaf);
91
+ }
@@ -34,6 +34,9 @@ import {
34
34
  subjectDirectoryOfRun,
35
35
  } from "./role-run-placement.ts";
36
36
  import { readPageSync } from "./run-dossier.ts";
37
+ import { PROGRESS_RECORD_KIND } from "./run-dossier-files.ts";
38
+ import { runIdFromRunDirectory } from "./run-terminal-artifacts.ts";
39
+ import { sitianReport } from "./sitian-facade.ts";
37
40
  import { parseSitianRecordText } from "./sitian-reader.ts";
38
41
  import { errorText, isRecord } from "./unknown-value.ts";
39
42
 
@@ -260,6 +263,40 @@ export function captureWorktreeHead(projectRoot: string): WorktreeHeadCapture {
260
263
  }
261
264
  }
262
265
 
266
+ /** The sealing tool call a progress row belongs to, as the submission ledger names it. */
267
+ export type ProgressRowCall = {
268
+ readonly attemptId: string;
269
+ readonly toolCallId: string;
270
+ };
271
+
272
+ /**
273
+ * #1201: the row just written rides the leg's submission ledger to the process
274
+ * that prints the terminal — settlement reads round and receipt beside the
275
+ * sealed payload, and never picks rows out of current.jsonl after the turn.
276
+ * A seal names its tool call; a publish (round filled at bind) names the receipt.
277
+ */
278
+ function carryProgressRow(
279
+ runDirectory: string,
280
+ line: TicketProgressLine,
281
+ call?: ProgressRowCall,
282
+ ): void {
283
+ const runId = runIdFromRunDirectory(runDirectory);
284
+ if (runId === undefined) return;
285
+ sitianReport({
286
+ level: "event",
287
+ kind: PROGRESS_RECORD_KIND,
288
+ subject: { runId, ...(call === undefined ? {} : { attemptId: call.attemptId }) },
289
+ payload: {
290
+ type: PROGRESS_RECORD_KIND,
291
+ ...(call === undefined ? {} : { toolCallId: call.toolCallId }),
292
+ receipt: line.receipt,
293
+ round: line.round,
294
+ },
295
+ source: "ticket-progress",
296
+ sessionParent: sessionFileOf(runDirectory),
297
+ });
298
+ }
299
+
263
300
  function progressSessionAbsolute(runDirectory: string, context: HostContext): string {
264
301
  const host = typeof context.host === "string" ? context.host.trim() : "";
265
302
  const sessionDirectory = sessionDirectoryOf(runDirectory);
@@ -292,6 +329,7 @@ export function landTicketProgressForSealedSubmission(input: {
292
329
  readonly accepted: unknown;
293
330
  readonly sealHead: WorktreeHeadCapture;
294
331
  readonly lens?: string;
332
+ readonly call: ProgressRowCall;
295
333
  }): TicketProgressLine | undefined {
296
334
  const runDirectory = runDirectoryFromHostContext(input.context);
297
335
  if (runDirectory === undefined) return undefined;
@@ -300,6 +338,7 @@ export function landTicketProgressForSealedSubmission(input: {
300
338
  role: input.role,
301
339
  accepted: input.accepted,
302
340
  sealHead: input.sealHead,
341
+ call: input.call,
303
342
  ...(input.lens === undefined ? {} : { lens: input.lens }),
304
343
  sessionFile: progressSessionAbsolute(runDirectory, input.context),
305
344
  instruction: typeof input.context.summonsInstruction === "string"
@@ -321,6 +360,7 @@ export function landTicketProgress(input: {
321
360
  readonly lens?: string;
322
361
  readonly sessionFile: string | undefined;
323
362
  readonly instruction: string;
363
+ readonly call: ProgressRowCall;
324
364
  }): TicketProgressLine | undefined {
325
365
  const { runDirectory } = input;
326
366
 
@@ -379,6 +419,7 @@ export function landTicketProgress(input: {
379
419
 
380
420
  mkdirSync(dirname(progressPath), { recursive: true });
381
421
  appendFileSync(progressPath, `${JSON.stringify(line)}\n`, "utf8");
422
+ carryProgressRow(runDirectory, line, input.call);
382
423
  // HEAD capture fault: keep the raw cause on stderr. Do not invent a second
383
424
  // dossier custom-frame channel beside post-admission's existing retain path.
384
425
  if (input.sealHead.fault !== undefined) {
@@ -450,4 +491,5 @@ export function relocateTicketProgressForLeg(input: {
450
491
  );
451
492
  // Append succeeded — drop staging. Failure above leaves progress.jsonl in place.
452
493
  rmSync(stagedPath, { force: true });
494
+ for (const moved of movedLines) carryProgressRow(input.runDirectory, moved);
453
495
  }