@akagilnc/pi-workflow-roles 0.1.5153 → 0.1.5194

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 (50) hide show
  1. package/dist/acp-host/production-host.js +13086 -13034
  2. package/dist/archivist-record-entry.js +4 -20
  3. package/dist/archivist-record-pointer.js +28 -0
  4. package/dist/audit-escalation.js +3 -119
  5. package/dist/auditor-soul.js +32 -0
  6. package/dist/doctor-auditor.js +26 -0
  7. package/dist/headless-host/production-host.js +11218 -11166
  8. package/dist/judge-role.js +73 -0
  9. package/dist/migrate-book-topology.js +8 -0
  10. package/dist/package-contracts/judge-output.js +1 -18
  11. package/dist/package-contracts/terminating-tools.js +2 -2
  12. package/dist/public-cli/cli.js +2 -2
  13. package/dist/public-cli/countersign-run.js +11 -0
  14. package/dist/public-cli/instruction-seat-run.js +428 -48
  15. package/dist/public-cli/invocation.js +10 -5
  16. package/dist/public-cli/main.js +10049 -8911
  17. package/dist/public-cli/settlement.js +28 -8
  18. package/dist/public-role-summons.js +6 -4
  19. package/dist/submission-errors.js +1 -1
  20. package/dist/submission-gate.js +165 -0
  21. package/dist/submission-ledger.js +0 -27
  22. package/dist/worker-submission-contracts.js +8 -0
  23. package/package.json +1 -1
  24. package/src/archivist-record-entry.ts +5 -49
  25. package/src/archivist-record-pointer.ts +49 -0
  26. package/src/audit-escalation.ts +4 -217
  27. package/src/auditor-soul.ts +33 -0
  28. package/src/doctor-role.ts +11 -5
  29. package/src/gatekeeper-role.ts +2 -2
  30. package/src/host-contracts.ts +0 -25
  31. package/src/judge-role.ts +63 -90
  32. package/src/package-contracts/judge-output.ts +0 -17
  33. package/src/package-contracts/terminating-tools.ts +0 -2
  34. package/src/pi/adapter.ts +1 -33
  35. package/src/public-cli/cli.ts +2 -2
  36. package/src/public-cli/countersign-run.ts +11 -0
  37. package/src/public-cli/instruction-seat-run.ts +433 -16
  38. package/src/public-cli/invocation.ts +9 -3
  39. package/src/public-cli/post-admission.ts +0 -1
  40. package/src/public-cli/settlement.ts +32 -8
  41. package/src/public-role-summons.ts +9 -6
  42. package/src/role-envelope.ts +0 -32
  43. package/src/role-runtime-dependencies.ts +0 -4
  44. package/src/role-runtime.ts +15 -218
  45. package/src/submission-errors.ts +1 -1
  46. package/src/submission-gate.ts +46 -10
  47. package/src/submission-ledger.ts +0 -27
  48. package/src/worker-role.ts +23 -102
  49. package/src/worker-submission-contracts.ts +8 -0
  50. package/src/worker-submission-gates.ts +2 -2
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  closeSync,
3
3
  existsSync,
4
- mkdirSync,
5
4
  openSync,
6
5
  readdirSync,
7
6
  readFileSync,
@@ -26,6 +25,10 @@ import {
26
25
  resolveNavigatorWorkSubjectPlacement
27
26
  } from "./archivist-record-topology.js";
28
27
  import { piRecordSessionHost } from "./pi/record-session-host.js";
28
+ import {
29
+ DIRECT_OFFICER_RUN_POINTER_KIND,
30
+ bookDirectOfficerRunPointer
31
+ } from "./archivist-record-pointer.js";
29
32
  import {
30
33
  NAVIGATOR_RECORD_KIND as NAVIGATOR_RECORD_KIND2,
31
34
  resolveNavigatorWorkSubjectPlacement as resolveNavigatorWorkSubjectPlacement2
@@ -311,25 +314,6 @@ function createRecordSessionOpen(options, host = piRecordSessionHost) {
311
314
  function createRecordSession(options) {
312
315
  return createRecordSessionOpen(options).session;
313
316
  }
314
- const DIRECT_OFFICER_RUN_POINTER_KIND = "direct-officer-run-pointer";
315
- function bookDirectOfficerRunPointer(options) {
316
- const nest = join(dirname(options.parentSessionFile), "auditor-roles");
317
- mkdirSync(nest, { recursive: true });
318
- const pointer = {
319
- version: 1,
320
- kind: DIRECT_OFFICER_RUN_POINTER_KIND,
321
- officer: options.officer,
322
- sessionFile: options.sessionFile,
323
- ...options.runDirectory !== void 0 && options.runDirectory.trim() !== "" ? { runDirectory: options.runDirectory } : {}
324
- };
325
- writeFileSync(
326
- join(nest, `${options.officer}.pointer.json`),
327
- `${JSON.stringify(pointer)}
328
- `,
329
- "utf8"
330
- );
331
- return pointer;
332
- }
333
317
  export {
334
318
  DIRECT_OFFICER_RUN_POINTER_KIND,
335
319
  NAVIGATOR_RECORD_KIND2 as NAVIGATOR_RECORD_KIND,
@@ -0,0 +1,28 @@
1
+ import { mkdirSync, writeFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ /** Typed parent-side pointer to an independent officer run 正本 (ADR 0079 / #675). */
4
+ export const DIRECT_OFFICER_RUN_POINTER_KIND = "direct-officer-run-pointer";
5
+ /**
6
+ * Book a typed pointer under parent session/auditor-roles (same nest owner as
7
+ * createRecordSession). Never fabricates user/assistant/toolResult rows (#675).
8
+ * Directory placement stays with the archivist record entry (ADR 0018 / 0065).
9
+ *
10
+ * Stable leaf per officer under one parent (#753 gate-round accounting):
11
+ * same-parent re-summons upsert the same pointer instead of minting N files that
12
+ * each re-scan the full officer session and multiply terminal gate-round counts.
13
+ */
14
+ export function bookDirectOfficerRunPointer(options) {
15
+ const nest = join(dirname(options.parentSessionFile), "auditor-roles");
16
+ mkdirSync(nest, { recursive: true });
17
+ const pointer = {
18
+ version: 1,
19
+ kind: DIRECT_OFFICER_RUN_POINTER_KIND,
20
+ officer: options.officer,
21
+ sessionFile: options.sessionFile,
22
+ ...(options.runDirectory !== undefined && options.runDirectory.trim() !== ""
23
+ ? { runDirectory: options.runDirectory }
24
+ : {}),
25
+ };
26
+ writeFileSync(join(nest, `${options.officer}.pointer.json`), `${JSON.stringify(pointer)}\n`, "utf8");
27
+ return pointer;
28
+ }
@@ -1,122 +1,6 @@
1
- import { GatekeeperDecisionError } from "./submission-errors.js";
1
+ /** Historical audit-escalation discriminator retained for reading pre-#1057 run artifacts. */
2
2
  export const AUDIT_ESCALATION_KIND = "audit_escalation";
3
- // Live Navigator settlement may consume only the projection produced by this
4
- // owner. Its private WeakSet cannot be authored by role output; persisted/
5
- // replayed records are re-authenticated by the retained audit evidence binder.
6
- const AUDIT_ESCALATION_LIVE_REGISTRY = new WeakSet();
7
- /**
8
- * Build the escalation delivery face.
9
- * Role-delivered fields ride under the escalation discriminator (ADR 0055).
10
- * `kind` always wins so the discriminator cannot be laundered.
11
- * `conflicts` and `auditDecisionGate`, when present, always come from the
12
- * audit (why we escalated and its gate). Raw ancillary values are not repaired.
13
- * A role `decisionGate`, when present, stays at its own key via spread and is
14
- * never overwritten (not folded, not dropped, not swapped into the audit home).
15
- */
16
- export function buildAuditEscalationResult(decision, deliveredOutput) {
17
- const auditOwned = {
18
- kind: AUDIT_ESCALATION_KIND,
19
- };
20
- if (Object.hasOwn(decision, "receipt")) {
21
- auditOwned.receipt = decision.receipt;
22
- }
23
- if (Object.hasOwn(decision, "conflicts")) {
24
- auditOwned.conflicts = decision.conflicts;
25
- }
26
- if (Object.hasOwn(decision, "decisionGate")) {
27
- auditOwned.auditDecisionGate = decision.decisionGate;
28
- }
29
- if (Object.hasOwn(decision, "reason") && decision.reason !== undefined) {
30
- auditOwned.reason = decision.reason;
31
- }
32
- if (Object.hasOwn(decision, "officer") && decision.officer !== undefined) {
33
- auditOwned.officer = decision.officer;
34
- }
35
- if (Object.hasOwn(decision, "findings") && decision.findings !== undefined) {
36
- auditOwned.findings = decision.findings;
37
- }
38
- const result = {
39
- kind: AUDIT_ESCALATION_KIND,
40
- ...(deliveredOutput !== undefined ? { receipt: deliveredOutput } : {}),
41
- audit: auditOwned,
42
- };
43
- AUDIT_ESCALATION_LIVE_REGISTRY.add(result);
44
- return result;
45
- }
46
- /** True only for the audit-owned live projection, never for role-shaped data. */
47
- export function isAuditEscalationProjection(value) {
48
- if (!isAuditEscalationResult(value))
49
- return false;
50
- return AUDIT_ESCALATION_LIVE_REGISTRY.has(value);
51
- }
52
- export function projectAuditEscalation(decision, deliveredOutput) {
53
- const details = buildAuditEscalationResult(decision, deliveredOutput);
54
- return {
55
- content: [],
56
- details,
57
- terminate: true,
58
- ...(decision.usage === undefined ? {} : { usage: decision.usage }),
59
- };
60
- }
61
- /** Preserve the escalating officer's own gate alongside the raw receipt. */
62
- export function projectGatekeeperEscalation(result, deliveredOutput) {
63
- const receipt = result.receipt;
64
- const record = receipt !== null && typeof receipt === "object" && !Array.isArray(receipt)
65
- ? receipt
66
- : undefined;
67
- return projectAuditEscalation({
68
- status: "escalate",
69
- officer: result.officer,
70
- conflicts: receipt,
71
- ...(record !== undefined && Object.hasOwn(record, "decisionGate")
72
- ? { decisionGate: record.decisionGate }
73
- : {}),
74
- }, deliveredOutput);
75
- }
76
- /**
77
- * Discriminator-only recognition (ADR 0040). Shape of conflicts/options/gate
78
- * is not a reject gate — element types and cardinality are delivery content.
79
- */
80
3
  export function isAuditEscalationResult(value) {
81
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
82
- return false;
83
- }
84
- return value.kind === AUDIT_ESCALATION_KIND;
85
- }
86
- /**
87
- * Dispose a parsed audit decision without repeating status handling in roles.
88
- * Role output already delivered is preserved on the escalate face (ADR 0055).
89
- */
90
- export async function disposeComplianceDecision(decision, handlers, deliveredOutput) {
91
- switch (decision.status) {
92
- case "converged":
93
- return await handlers.converged(decision.usage);
94
- case "no-receipt":
95
- // The parent candidate remains accepted, but its parallel audit leg is a
96
- // public typed fact and must not be collapsed into an ordinary pass.
97
- if (handlers.noReceipt === undefined) {
98
- throw new Error("Compliance no-receipt projection handler is unavailable");
99
- }
100
- return await handlers.noReceipt(decision, decision.usage === undefined ? {} : { usage: decision.usage });
101
- case "received":
102
- // Parent candidate stands; raw auditor reply rides beside — not judged unreadable (#757).
103
- if (handlers.received === undefined) {
104
- throw new Error("Compliance received projection handler is unavailable");
105
- }
106
- return await handlers.received(decision, decision.usage === undefined ? {} : { usage: decision.usage });
107
- case "continue":
108
- return await handlers.continue(decision.violations);
109
- case "escalate":
110
- return await handlers.escalate(projectAuditEscalation(decision, deliveredOutput));
111
- case "transport_failure":
112
- if (handlers.transportFailure !== undefined) {
113
- return await handlers.transportFailure(decision);
114
- }
115
- throw new GatekeeperDecisionError({
116
- status: "transport_failure",
117
- stage: "auditor",
118
- reason: decision.diagnostic,
119
- submission: decision.submissions ?? decision.terminal,
120
- });
121
- }
4
+ return typeof value === "object" && value !== null && !Array.isArray(value)
5
+ && value.kind === AUDIT_ESCALATION_KIND;
122
6
  }
@@ -1,3 +1,5 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { basename, join } from "node:path";
1
3
  import { joinPackageMaterials, readPackageMaterial, } from "./session-opening-materials.js";
2
4
  /**
3
5
  * Active auditor seats.
@@ -80,3 +82,33 @@ export async function loadAuditorSoulFromSubjectInput(raw) {
80
82
  export function loadAuditorReferenceMaterialsFromSubjectInput(raw) {
81
83
  return loadAuditorReferenceMaterials(resolveAuditorSubject(raw));
82
84
  }
85
+ function subjectFromSourceDirectory(sourceRunDirectory) {
86
+ const role = basename(sourceRunDirectory).split("@")[1];
87
+ return isAuditorSoulRole(role) ? role : undefined;
88
+ }
89
+ /**
90
+ * Resume binding already on the admitted page.
91
+ * Explicit subject wins; otherwise the source-run role is the audited object.
92
+ */
93
+ export async function readAuditorResumeBinding(runDirectory) {
94
+ let raw;
95
+ try {
96
+ raw = JSON.parse(await readFile(join(runDirectory, "admitted-request.json"), "utf8"));
97
+ }
98
+ catch (error) {
99
+ if (error.code === "ENOENT")
100
+ return undefined;
101
+ throw error;
102
+ }
103
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw))
104
+ return undefined;
105
+ const record = raw;
106
+ if (typeof record.sourceRunPath !== "string" || record.sourceRunPath.trim() === "")
107
+ return undefined;
108
+ const subject = isAuditorSoulRole(record.auditorSubject)
109
+ ? record.auditorSubject
110
+ : subjectFromSourceDirectory(record.sourceRunPath);
111
+ if (subject === undefined)
112
+ return undefined;
113
+ return { subject, sourceRunDirectory: record.sourceRunPath };
114
+ }
@@ -0,0 +1,26 @@
1
+ import { auditorRunDirectory } from "./auditor-dossier-tool.js";
2
+ import { runComplianceAudit, } from "./compliance-transport.js";
3
+ import { readDoctorAuditSubjects, requireAuditMaterials, resolveAuditDossier, } from "./dossier-resolution.js";
4
+ export { DOCTOR_AUDIT_TOOL_NAME } from "./doctor-contracts.js";
5
+ /**
6
+ * Doctor compliance via public auditor activation (#675 / ADR 0062 / owner r11).
7
+ * 审刑院 is an independent role; subject=doctor selects souls/doctor-auditor.md.
8
+ */
9
+ export function createPiDoctorAuditor() {
10
+ return async (options) => {
11
+ const dossier = resolveAuditDossier(options.context);
12
+ requireAuditMaterials(dossier);
13
+ const subjects = readDoctorAuditSubjects(options.context);
14
+ requireAuditMaterials(subjects);
15
+ return runComplianceAudit({
16
+ subject: "doctor",
17
+ context: options.context,
18
+ submission: options.submission,
19
+ ...(auditorRunDirectory(options.context) === undefined
20
+ ? {}
21
+ : { runDirectory: auditorRunDirectory(options.context) }),
22
+ ...(options.signal === undefined ? {} : { signal: options.signal }),
23
+ ...(options.summonAuditor === undefined ? {} : { summonAuditor: options.summonAuditor }),
24
+ });
25
+ };
26
+ }