@akagilnc/pi-workflow-roles 0.1.5483 → 0.1.5571

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 (112) hide show
  1. package/README.md +1 -1
  2. package/README.zh-CN.md +1 -1
  3. package/dist/acp-host/production-host.js +6312 -6376
  4. package/dist/analyst-gate-cycles-read.js +28 -78
  5. package/dist/analyst-ledger.js +26 -42
  6. package/dist/analyst-metric-families/acceptance-success-rework.js +25 -1
  7. package/dist/analyst-metric-families/round-timeline.js +2 -5
  8. package/dist/archivist-record-entry.js +4 -3
  9. package/dist/archivist-record-pointer.js +71 -36
  10. package/dist/atomic-write.js +2 -2
  11. package/dist/auditor-dossier-tool.js +11 -6
  12. package/dist/auditor-soul.js +5 -12
  13. package/dist/collector-config.js +6 -5
  14. package/dist/doctor-evidence.js +8 -4
  15. package/dist/engine-detour-usage.js +8 -22
  16. package/dist/headless-host/production-host.js +5969 -6011
  17. package/dist/host-descriptions.js +0 -4
  18. package/dist/host-session-record.js +266 -267
  19. package/dist/ledger-session-read.js +5 -0
  20. package/dist/migrate-book-topology.js +1369 -722
  21. package/dist/navigator-public-session.js +13 -17
  22. package/dist/notary-source-run.js +8 -16
  23. package/dist/packaged-role-registry.js +5 -56
  24. package/dist/pi/durable-principal.js +2 -3
  25. package/dist/pi/role-turn-host.js +79 -15
  26. package/dist/public-cli/auto-resume.js +8 -47
  27. package/dist/public-cli/instruction-seat-run.js +9 -7
  28. package/dist/public-cli/invocation.js +67 -100
  29. package/dist/public-cli/main.js +2689 -2532
  30. package/dist/public-cli/post-admission.js +96 -55
  31. package/dist/public-cli/run-lifecycle.js +44 -100
  32. package/dist/public-cli/settlement.js +184 -429
  33. package/dist/public-cli/terminal.js +0 -12
  34. package/dist/role-run-placement.js +53 -16
  35. package/dist/role-run-relocation.js +111 -52
  36. package/dist/run-dossier-files.js +30 -0
  37. package/dist/run-dossier.js +322 -0
  38. package/dist/run-terminal-artifacts.js +69 -202
  39. package/dist/run-ticket-number.js +49 -7
  40. package/dist/session-assistant-usage.js +9 -18
  41. package/dist/session-identity.js +49 -19
  42. package/dist/sitian-appender.js +29 -18
  43. package/dist/sitian-facade.js +11 -0
  44. package/dist/sitian-reader.js +44 -29
  45. package/dist/submission-gate.js +1 -1
  46. package/dist/submission-ledger.js +4 -4
  47. package/dist/ticket-provenance-contracts.js +2 -8
  48. package/dist/ticket-provenance.js +25 -9
  49. package/package.json +1 -1
  50. package/scripts/build-package.mjs +2 -0
  51. package/src/acp-host/production-host.ts +1 -1
  52. package/src/acp-host/role-turn-host.ts +11 -4
  53. package/src/analyst-gate-cycles-read.ts +31 -88
  54. package/src/analyst-ledger.ts +36 -51
  55. package/src/analyst-metric-families/acceptance-success-rework.ts +24 -1
  56. package/src/analyst-metric-families/gate-cycles.ts +1 -1
  57. package/src/analyst-metric-families/round-timeline.ts +2 -5
  58. package/src/analyst-page.ts +3 -3
  59. package/src/archivist-record-entry.ts +6 -5
  60. package/src/archivist-record-pointer.ts +92 -42
  61. package/src/atomic-write.ts +3 -1
  62. package/src/auditor-dossier-tool.ts +14 -8
  63. package/src/auditor-soul.ts +5 -10
  64. package/src/book-topology-migration-placement.ts +16 -3
  65. package/src/book-topology-record-class-migrators.ts +4 -2
  66. package/src/book-topology-runs-migrator.ts +6 -3
  67. package/src/collector-config.ts +5 -3
  68. package/src/doctor-contracts.ts +1 -1
  69. package/src/doctor-evidence.ts +7 -3
  70. package/src/engine-detour-tool.ts +1 -1
  71. package/src/engine-detour-usage.ts +12 -25
  72. package/src/external-host-turn-loop.ts +25 -0
  73. package/src/factory-board.ts +16 -81
  74. package/src/headless-host/production-host.ts +1 -4
  75. package/src/headless-host/role-turn-host.ts +56 -21
  76. package/src/host-descriptions.ts +0 -6
  77. package/src/host-session-record.ts +224 -140
  78. package/src/ledger-session-read.ts +6 -0
  79. package/src/navigator-public-session.ts +13 -18
  80. package/src/navigator-work-context.ts +3 -1
  81. package/src/notary-role.ts +2 -1
  82. package/src/notary-source-run.ts +8 -18
  83. package/src/packaged-role-registry.ts +1 -65
  84. package/src/pi/adapter.ts +50 -7
  85. package/src/pi/durable-principal.ts +2 -4
  86. package/src/pi/role-turn-host.ts +85 -14
  87. package/src/public-cli/auto-resume.ts +7 -43
  88. package/src/public-cli/instruction-seat-run.ts +13 -6
  89. package/src/public-cli/invocation.ts +90 -144
  90. package/src/public-cli/post-admission.ts +111 -72
  91. package/src/public-cli/run-lifecycle.ts +47 -115
  92. package/src/public-cli/settlement.ts +221 -589
  93. package/src/public-cli/terminal.ts +1 -61
  94. package/src/role-envelope.ts +4 -2
  95. package/src/role-run-placement.ts +65 -17
  96. package/src/role-run-relocation.ts +110 -70
  97. package/src/role-runtime.ts +46 -69
  98. package/src/run-dossier-files.ts +33 -0
  99. package/src/run-dossier.ts +357 -0
  100. package/src/run-terminal-artifacts.ts +84 -240
  101. package/src/run-ticket-number.ts +82 -14
  102. package/src/session-assistant-usage.ts +8 -20
  103. package/src/session-identity.ts +52 -21
  104. package/src/sitian-appender.ts +33 -26
  105. package/src/sitian-facade.ts +22 -0
  106. package/src/sitian-reader.ts +62 -32
  107. package/src/submission-gate.ts +1 -1
  108. package/src/submission-ledger.ts +4 -4
  109. package/src/ticket-provenance-contracts.ts +3 -6
  110. package/src/ticket-provenance.ts +23 -11
  111. package/src/ticket-snapshot.ts +3 -2
  112. package/src/ticket-trajectory.ts +95 -109
@@ -1,6 +1,7 @@
1
1
  import { readdir, readFile, realpath, stat } from "node:fs/promises";
2
2
  import { dirname, relative, resolve, sep } from "node:path";
3
3
  import { sha256Hex } from "./sha256.js";
4
+ import { physicallyContainedIn } from "./activation-ledger-topology.js";
4
5
  import { AcceptedDetailsContractError, acceptedFacts, isTerminatingToolName, validateAcceptedDetails } from "./package-contracts/terminating-tools.js";
5
6
  import { isRecord, isMissingPathError } from "./unknown-value.js";
6
7
  async function discoverCaseFiles(root) { const found = []; async function walk(dir, depth) { for (const item of await readdir(dir, { withFileTypes: true })) {
@@ -8,7 +9,7 @@ async function discoverCaseFiles(root) { const found = []; async function walk(d
8
9
  if (item.isDirectory()) {
9
10
  await walk(path, depth + 1);
10
11
  }
11
- else if (item.isFile() && (item.name.endsWith(".jsonl") || (item.name === "stderr.log" && depth === 1)))
12
+ else if (item.isFile() && ((item.name.endsWith(".jsonl") && item.name !== "state.jsonl" && !(item.name === "log.jsonl" && depth === 1)) || (item.name === "log.jsonl" && depth === 1)))
12
13
  found.push(path);
13
14
  } } await walk(root, 0); return found.sort(); }
14
15
  function sourceList(count, sources) { return { count, sources: [...new Set(sources)].sort() }; }
@@ -106,8 +107,11 @@ function deriveSession(content, id) {
106
107
  return { session, turns, calls, tokens, statuses, commits };
107
108
  }
108
109
  /** Read Pi's retained session directory as the sole raw material for one case. */
109
- export async function loadDoctorCase(runsPath) {
110
+ export async function loadDoctorCase(runsPath, projectRoot) {
110
111
  const root = await realpath(runsPath);
112
+ if (projectRoot !== undefined && !physicallyContainedIn(projectRoot, root)) {
113
+ throw new Error("doctor --runs escapes the project root");
114
+ }
111
115
  // Canonical <book>/<ticket>/runs; legacy issues/<n>/runs remains read-only compatible.
112
116
  const match = root.split(sep).join("/").match(/\/\.ak-roles\/books\/[^/]+\/(?:issues\/)?([1-9]\d*)\/runs$/);
113
117
  if (!match)
@@ -118,9 +122,9 @@ export async function loadDoctorCase(runsPath) {
118
122
  const id = relative(root, path).split(sep).join("/");
119
123
  const bytes = await readFile(path);
120
124
  const content = bytes.toString("utf8");
121
- const kind = id.endsWith(".jsonl") ? "session" : "stderr";
125
+ const kind = id.split("/").length === 2 && id.endsWith("/log.jsonl") ? "log" : "session";
122
126
  evidence.push({ id, kind, byteLength: bytes.byteLength, contentLength: content.length, sha256: sha256Hex(bytes), content });
123
- if (kind === "stderr")
127
+ if (kind === "log")
124
128
  continue;
125
129
  const result = deriveSession(content, id);
126
130
  sessions.push(result.session);
@@ -15,9 +15,11 @@
15
15
  * `ak-role resume`) mints a new one. Never courtAttemptId, never Pi session
16
16
  * toolResult join keys, and never a detour-owned sidecar file.
17
17
  */
18
+ import { readPageSync, RUN_LOG_FILE } from "./run-dossier.js";
18
19
  import { randomUUID } from "node:crypto";
19
20
  import { readFileSync } from "node:fs";
20
- import { dirname, join } from "node:path";
21
+ import { join } from "node:path";
22
+ export { runDirectoryFromSessionDirectory, sessionFileIn as sessionFileFromSessionDirectory, } from "./role-run-placement.js";
21
23
  import { ENGINE_DETOUR_TOOL_NAME } from "./engine-detour.js";
22
24
  import { readSitianRecords, resolveSitianRecordPath, sitianReport, } from "./sitian-facade.js";
23
25
  import { isRecord } from "./unknown-value.js";
@@ -26,11 +28,11 @@ export const ENGINE_DETOUR_CALL_KIND = "engine-detour-call";
26
28
  /** decisiveFacts key — name states detour-tool scope, not full engine usage. */
27
29
  export const ENGINE_DETOUR_TOOL_USAGE_FACT_KEY = "engineDetourToolUsage";
28
30
  /**
29
- * Run-relative sitian volume path for one detour call.
31
+ * Run-relative path of the log that holds one detour call's record.
30
32
  * Openable once the run directory is known from the terminal's run id.
31
33
  * Contains no runId bytes itself (#108 + #537).
32
34
  */
33
- export const ENGINE_DETOUR_CALL_RECORD_FILE_RELATIVE = `session/${ENGINE_DETOUR_CALL_KIND}/records.jsonl`;
35
+ export const ENGINE_DETOUR_CALL_RECORD_FILE_RELATIVE = RUN_LOG_FILE;
34
36
  /** stdout UTF-8 byte length (ticket-frozen metric; empty stdout is real 0). */
35
37
  export function engineDetourStdoutByteLength(stdout) {
36
38
  return Buffer.byteLength(stdout, "utf8");
@@ -180,19 +182,11 @@ export async function readEngineDetourToolUsage(input) {
180
182
  const calls = Array.from(callsByToolCallId.values());
181
183
  return { callCount: calls.length, calls };
182
184
  }
183
- /** One shared invocation.json reader (ENOENT → undefined; other errors propagate). */
185
+ /** One shared state.jsonl invocation-row reader (absent → undefined; other errors propagate). */
184
186
  function readInvocationRecord(runDirectory) {
185
- try {
186
- const raw = JSON.parse(readFileSync(join(runDirectory, "invocation.json"), "utf8"));
187
- return isRecord(raw) ? raw : undefined;
188
- }
189
- catch (error) {
190
- if (error?.code === "ENOENT")
191
- return undefined;
192
- throw error;
193
- }
187
+ return readPageSync(runDirectory, "invocation");
194
188
  }
195
- /** True when invocation.json carries a non-empty engine axis. */
189
+ /** True when the invocation section carries a non-empty engine axis. */
196
190
  export async function readInvocationEngineMounted(runDirectory) {
197
191
  const raw = readInvocationRecord(runDirectory);
198
192
  if (raw === undefined)
@@ -212,14 +206,6 @@ export function withEngineDetourToolUsageFact(outcome, usage) {
212
206
  },
213
207
  };
214
208
  }
215
- /** runDirectory owning a session directory (.../runs/<id>@role/session). */
216
- export function runDirectoryFromSessionDirectory(sessionDirectory) {
217
- return dirname(sessionDirectory);
218
- }
219
- /** session.jsonl under a session directory. */
220
- export function sessionFileFromSessionDirectory(sessionDirectory) {
221
- return join(sessionDirectory, "session.jsonl");
222
- }
223
209
  /**
224
210
  * Mint one public-invocation scope id.
225
211
  * Call once at the public-entry boundary — never inside the auto-resume loop.