@akagilnc/pi-workflow-roles 0.1.3932 → 0.1.3975

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 (162) hide show
  1. package/CLAUDE.md +1 -1
  2. package/dist/acp-host/production-host.js +2389 -6018
  3. package/dist/analyst-gate-cycles-read.js +15 -19
  4. package/dist/audit-escalation.js +16 -46
  5. package/dist/auditor-dossier-tool.js +7 -62
  6. package/dist/collector-identity.js +0 -157
  7. package/dist/collector-ledger.js +2 -42
  8. package/dist/compliance-transport.js +40 -14
  9. package/dist/diarist-contracts.js +2 -40
  10. package/dist/doctor-contracts.js +39 -108
  11. package/dist/doctor-evidence.js +1 -5
  12. package/dist/engine-detour-tool.js +1 -1
  13. package/dist/gatekeeper-role.js +49 -38
  14. package/dist/headless-host/production-host.js +4814 -8450
  15. package/dist/host-contracts.js +0 -5
  16. package/dist/merger-contracts.js +4 -6
  17. package/dist/navigator-attendance.js +30 -52
  18. package/dist/navigator-invocation-identity.js +0 -1
  19. package/dist/navigator-public-session.js +2 -1
  20. package/dist/notary-contracts.js +4 -10
  21. package/dist/package-contracts/auditor-output.js +5 -23
  22. package/dist/package-contracts/fixer-output.js +25 -49
  23. package/dist/package-contracts/gatekeeper-output.js +3 -13
  24. package/dist/package-contracts/navigator-output.js +4 -7
  25. package/dist/package-contracts/reviewer-output.js +1 -95
  26. package/dist/package-contracts/terminating-tools.js +33 -144
  27. package/dist/package-contracts/worker-output.js +1 -3
  28. package/dist/public-cli/auto-resume.js +30 -68
  29. package/dist/public-cli/case-dossier-delivery.js +5 -17
  30. package/dist/public-cli/diarist-run.js +9 -4
  31. package/dist/public-cli/inspector-run.js +2 -8
  32. package/dist/public-cli/instruction-seat-run.js +3 -7
  33. package/dist/public-cli/invocation.js +5 -2
  34. package/dist/public-cli/main.js +6068 -6964
  35. package/dist/public-cli/notary-run.js +1 -8
  36. package/dist/public-cli/post-admission.js +314 -113
  37. package/dist/public-cli/run-lifecycle.js +14 -38
  38. package/dist/public-cli/settlement.js +209 -390
  39. package/dist/public-cli/terminal.js +51 -45
  40. package/dist/public-role-summons.js +1 -12
  41. package/dist/reviewer-dispatch.js +12 -258
  42. package/dist/submission-correctable-error.js +0 -12
  43. package/dist/submission-errors.js +6 -1
  44. package/dist/submission-ledger.js +125 -168
  45. package/dist/ticket-provenance-contracts.js +2 -49
  46. package/dist/ticket-provenance.js +82 -31
  47. package/extensions/role-runtime.ts +1 -6
  48. package/package.json +1 -1
  49. package/resources/836-deleted-machine-instruction-inventory.md +18 -0
  50. package/src/acp-host/role-turn-host.ts +8 -3
  51. package/src/analyst-gate-cycles-read.ts +17 -29
  52. package/src/audit-escalation.ts +20 -50
  53. package/src/auditor-dossier-tool.ts +5 -103
  54. package/src/canonical-skill-binding.ts +3 -2
  55. package/src/collector-identity.ts +0 -179
  56. package/src/collector-ledger.ts +3 -46
  57. package/src/collector-role.ts +32 -61
  58. package/src/collector-tool-schemas.ts +20 -14
  59. package/src/compliance-transport.ts +55 -17
  60. package/src/countersign-role.ts +17 -8
  61. package/src/diarist-contracts.ts +3 -36
  62. package/src/diarist-role.ts +13 -7
  63. package/src/diarist.ts +4 -16
  64. package/src/doctor-contracts.ts +73 -94
  65. package/src/doctor-evidence.ts +1 -1
  66. package/src/doctor-role.ts +3 -3
  67. package/src/engine-detour-tool.ts +4 -1
  68. package/src/external-host-turn-loop.ts +9 -3
  69. package/src/gatekeeper-pass-envelope.ts +7 -12
  70. package/src/gatekeeper-role.ts +56 -50
  71. package/src/gleaner-left-role.ts +4 -2
  72. package/src/headless-host/role-turn-host.ts +4 -5
  73. package/src/host-contracts.ts +3 -8
  74. package/src/judge-role.ts +19 -13
  75. package/src/merger-contracts.ts +10 -6
  76. package/src/merger-role.ts +1 -5
  77. package/src/navigator-attendance.ts +37 -74
  78. package/src/navigator-invocation-identity.ts +0 -6
  79. package/src/navigator-public-session.ts +2 -1
  80. package/src/notary-contracts.ts +7 -10
  81. package/src/package-contracts/auditor-output.ts +4 -21
  82. package/src/package-contracts/fixer-output.ts +34 -52
  83. package/src/package-contracts/gatekeeper-output.ts +5 -22
  84. package/src/package-contracts/navigator-output.ts +7 -7
  85. package/src/package-contracts/reviewer-output.ts +2 -150
  86. package/src/package-contracts/terminating-tools.ts +32 -147
  87. package/src/package-contracts/worker-output.ts +0 -1
  88. package/src/pi/adapter.ts +3 -8
  89. package/src/public-cli/auto-resume.ts +41 -94
  90. package/src/public-cli/case-dossier-delivery.ts +5 -15
  91. package/src/public-cli/countersign-run.ts +14 -6
  92. package/src/public-cli/diarist-run.ts +11 -9
  93. package/src/public-cli/inspector-run.ts +2 -18
  94. package/src/public-cli/instruction-seat-run.ts +3 -17
  95. package/src/public-cli/invocation.ts +5 -2
  96. package/src/public-cli/merger-run.ts +1 -1
  97. package/src/public-cli/notary-run.ts +1 -18
  98. package/src/public-cli/post-admission.ts +385 -115
  99. package/src/public-cli/run-lifecycle.ts +13 -44
  100. package/src/public-cli/settlement.ts +314 -562
  101. package/src/public-cli/terminal.ts +66 -72
  102. package/src/public-role-summons.ts +5 -30
  103. package/src/reviewer-dispatch.ts +29 -331
  104. package/src/reviewer-role.ts +16 -83
  105. package/src/role-envelope.ts +16 -24
  106. package/src/role-runtime-dependencies.ts +1 -6
  107. package/src/role-runtime.ts +65 -201
  108. package/src/submission-correctable-error.ts +0 -14
  109. package/src/submission-errors.ts +6 -1
  110. package/src/submission-ledger.ts +187 -187
  111. package/src/ticket-provenance-contracts.ts +4 -60
  112. package/src/ticket-provenance.ts +98 -32
  113. package/src/worker-role.ts +35 -36
  114. package/dist/activation-ledger-session.js +0 -105
  115. package/dist/activation-ledger.js +0 -139
  116. package/dist/activation-trace.js +0 -33
  117. package/dist/atomic-write.js +0 -23
  118. package/dist/auditor-role.js +0 -12
  119. package/dist/canonical-skill-binding.js +0 -61
  120. package/dist/collector-handbook.js +0 -142
  121. package/dist/collector-receipt.js +0 -107
  122. package/dist/collector-role.js +0 -566
  123. package/dist/collector-tool-schemas.js +0 -107
  124. package/dist/countersign-role.js +0 -28
  125. package/dist/diarist-role.js +0 -44
  126. package/dist/diarist.js +0 -66
  127. package/dist/doctor-role.js +0 -75
  128. package/dist/fixer-bash-seatbelt.js +0 -13
  129. package/dist/gatekeeper-pass-envelope.js +0 -77
  130. package/dist/gleaner-left-role.js +0 -26
  131. package/dist/inspector-role.js +0 -29
  132. package/dist/judge-role.js +0 -104
  133. package/dist/merger-role.js +0 -55
  134. package/dist/navigator-role.js +0 -12
  135. package/dist/notary-role.js +0 -134
  136. package/dist/oauth-keepalive.js +0 -158
  137. package/dist/pi/adapter.js +0 -223
  138. package/dist/reviewer-agent.js +0 -122
  139. package/dist/reviewer-child-executor.js +0 -194
  140. package/dist/reviewer-construction.js +0 -103
  141. package/dist/reviewer-execution-ledger.js +0 -166
  142. package/dist/reviewer-failure-diagnostic.js +0 -17
  143. package/dist/reviewer-role.js +0 -159
  144. package/dist/reviewer-scope-prompt.js +0 -21
  145. package/dist/reviewer-settlement.js +0 -66
  146. package/dist/reviewer-workspace.js +0 -132
  147. package/dist/role-runtime.js +0 -1604
  148. package/dist/stderr-jsonl.js +0 -26
  149. package/dist/tool-execution-observation.js +0 -141
  150. package/dist/worker-role.js +0 -345
  151. package/dist/worker-submission-gates.js +0 -305
  152. package/src/collector-receipt.ts +0 -140
  153. package/src/diagnostic-tail.ts +0 -18
  154. package/src/reviewer-agent.ts +0 -135
  155. package/src/reviewer-child-executor.ts +0 -252
  156. package/src/reviewer-construction.ts +0 -195
  157. package/src/reviewer-execution-ledger.ts +0 -212
  158. package/src/reviewer-failure-diagnostic.ts +0 -18
  159. package/src/reviewer-scope-prompt.ts +0 -24
  160. package/src/reviewer-settlement.ts +0 -74
  161. package/src/reviewer-workspace.ts +0 -105
  162. package/src/shape-unreadable-failure.ts +0 -49
@@ -2,14 +2,13 @@ import { readFile } from "node:fs/promises";
2
2
  import { fileURLToPath } from "node:url";
3
3
 
4
4
  import { loadCanonicalSkillBinding as loadHomeCanonicalSkillBinding } from "./canonical-skill-binding.ts";
5
- import { createGhCollectorGitHubTransport, createGhIssueSoftFetcher } from "./collector-github.ts";
5
+ import { createGhCollectorGitHubTransport } from "./collector-github.ts";
6
6
  import { createPiDoctorAuditor } from "./doctor-auditor.ts";
7
7
  import { loadDoctorCase } from "./doctor-evidence.ts";
8
8
  import { createNativeNavigatorSessionFactory, createNavigatorAttendance } from "./navigator-attendance.ts";
9
9
  import { loadNavigatorWorkContext } from "./navigator-work-context.ts";
10
10
  import { loadNotarySourceRunLocator } from "./notary-source-run.ts";
11
11
  import { loadPackagedCanonicalSkillBinding } from "./package-resources/method-skill-binding.ts";
12
- import { createPerDispatchReviewerAgent } from "./reviewer-agent.ts";
13
12
  import { formatNavigatorRoleHelp, type RoleRuntimeDependencies } from "./role-runtime.ts";
14
13
  import { createReviewerPinnedGitReader } from "./reviewer-pinned-git.ts";
15
14
  import { loadAuditorSoulFromSubjectInput } from "./auditor-soul.ts";
@@ -25,7 +24,6 @@ const collectorHandbookSeedPath = fileURLToPath(
25
24
  /** Host-neutral packaged role runtime deps for the parent-process envelope. */
26
25
  export function createRoleRuntimeDependencies(packageRoot: string): RoleRuntimeDependencies {
27
26
  const doctorAuditor = createPiDoctorAuditor();
28
- const reviewerAgent = createPerDispatchReviewerAgent({ packageRoot });
29
27
  const navigatorSessionFactory = createNativeNavigatorSessionFactory();
30
28
  return {
31
29
  loadJudgeSoul: () => loadMainRoleSessionMaterials("judge"),
@@ -35,7 +33,6 @@ export function createRoleRuntimeDependencies(packageRoot: string): RoleRuntimeD
35
33
  loadCoderTask: (path) => readFile(path, "utf8"),
36
34
  loadReviewerSoul: () => loadMainRoleSessionMaterials("reviewer"),
37
35
  createReviewerPinnedGitReader: () => createReviewerPinnedGitReader(),
38
- createReviewerIssueFetcher: () => createGhIssueSoftFetcher(),
39
36
  loadCollectorSoul: () => loadMainRoleSessionMaterials("collector"),
40
37
  loadCollectorHandbookSeed: () => readFile(collectorHandbookSeedPath, "utf8"),
41
38
  createCollectorTransport: () => createGhCollectorGitHubTransport(),
@@ -63,8 +60,6 @@ export function createRoleRuntimeDependencies(packageRoot: string): RoleRuntimeD
63
60
  },
64
61
  // #590: doctor compliance still on disposeCompliance path; judge→auditor is gate queue (#756).
65
62
  auditDoctorCompliance: (options) => doctorAuditor(options),
66
- runReviewerDispatch: (dispatch, options) => reviewerAgent.run(dispatch, options),
67
- shutdownReviewerAgent: () => reviewerAgent.shutdown(),
68
63
  loadNavigatorWorkContext: (options) => loadNavigatorWorkContext({
69
64
  context: options.context,
70
65
  role: options.role,
@@ -7,7 +7,7 @@ import {
7
7
  type RoleEnvelopeHost,
8
8
  type RoleHost,
9
9
  } from "./host-contracts.ts";
10
- import { recordReviewerDispatchRejectionSync } from "./public-cli/reviewer-dispatch-rejection.ts";
10
+
11
11
  import { Value } from "typebox/value";
12
12
  import { sitianReport } from "./sitian-facade.ts";
13
13
  import { createSubmissionLedgerHost } from "./submission-ledger.ts";
@@ -97,7 +97,7 @@ import {
97
97
  import { AUDITOR_ACCEPTED_TEXT } from "./package-contracts/auditor-output.ts";
98
98
  import { GATEKEEPER_ACCEPTED_TEXT } from "./package-contracts/gatekeeper-output.ts";
99
99
  import { NAVIGATOR_ACCEPTED_TEXT } from "./package-contracts/navigator-output.ts";
100
- import { decorateSettlementWithNavigation, formatNavigatorReport, NAVIGATOR_EVENT_TYPE, navigatorSubjectKey, navigatorUnavailableError, subjectPath, type NavigatorAttendance, type NavigatorAttendanceOptions, type NavigatorEvent, type NavigatorPhase, type NavigatorReport, type NavigatorSettlement, type NavigatorSubjectProvenance, type NavigatorTargetRole, type NavigatorWorkContext } from "./navigator-attendance.ts";
100
+ import { formatNavigatorReport, NAVIGATOR_EVENT_TYPE, navigatorSubjectKey, navigatorUnavailableError, subjectPath, type NavigatorAttendance, type NavigatorAttendanceOptions, type NavigatorEvent, type NavigatorPhase, type NavigatorReport, type NavigatorSettlement, type NavigatorSubjectProvenance, type NavigatorTargetRole, type NavigatorWorkContext } from "./navigator-attendance.ts";
101
101
  import {
102
102
  buildNavigatorInfrastructureFailureFact,
103
103
  classifyPackagedRoleTerminalResult,
@@ -117,11 +117,7 @@ import {
117
117
  type ReviewerActivation,
118
118
  type ReviewerAdmittedInputs,
119
119
  } from "./reviewer-role.ts";
120
- import type { AcceptedReviewerExecution, ReviewerIssueFetcher, ReviewerPinnedGitReader } from "./reviewer-dispatch.ts";
121
- import type { ReviewerDispatchRunResult } from "./reviewer-agent.ts";
122
- import {
123
- type ReviewerSpecDisposition,
124
- } from "./reviewer-construction.ts";
120
+ import type { ReviewerPinnedGitReader } from "./reviewer-dispatch.ts";
125
121
  import type { GatekeeperNonPassResult } from "./gatekeeper-role.ts";
126
122
 
127
123
  /**
@@ -247,24 +243,13 @@ function decodeReviewerAdmittedInputs(getFlag: (name: string) => unknown): Revie
247
243
  function assembleReviewerParentSystemPrompt(input: {
248
244
  baseSystemPrompt: string;
249
245
  soul: string;
250
- specDisposition?: ReviewerSpecDisposition;
251
246
  }): string {
252
- const specDispositionNote =
253
- input.specDisposition === "skipped-missing"
254
- ? [
255
- "",
256
- "<reviewer_spec_disposition>",
257
- "权威 Spec 不存在;未启动 Spec 取证腿。",
258
- "</reviewer_spec_disposition>",
259
- ]
260
- : [];
261
247
  return [
262
248
  input.baseSystemPrompt,
263
249
  "",
264
250
  "<reviewer_soul>",
265
251
  input.soul,
266
252
  "</reviewer_soul>",
267
- ...specDispositionNote,
268
253
  ].join("\n");
269
254
  }
270
255
  import {
@@ -391,7 +376,7 @@ export {
391
376
  type FixerOutput,
392
377
  type WorkerOutput,
393
378
  } from "./worker-role.ts";
394
- export { fixerOutputSchema, validateFixerOutput, validateFixerOutputForPacket } from "./package-contracts/fixer-output.ts";
379
+ export { fixerOutputSchema, validateFixerOutput } from "./package-contracts/fixer-output.ts";
395
380
  export type { FixerBlocker, FixerClassResult, FixerPhase, FixerTestEvidence } from "./package-contracts/fixer-output.ts";
396
381
  export { fixerPrerequisiteSchema, fixerPrerequisitesSchema, parseFixerPrerequisites, validateFixerPrerequisites } from "./package-contracts/fixer-packet.ts";
397
382
  export type { FixerInvocationInput, FixerPrerequisite } from "./package-contracts/fixer-packet.ts";
@@ -415,15 +400,8 @@ export {
415
400
  COLLECTOR_REQUEST_TOOL,
416
401
  COLLECTOR_WAIT_TOOL,
417
402
  } from "./collector-role.ts";
418
- export type {
419
- ReviewerExecutionRecord,
420
- ReviewerTargetSnapshot,
421
- ReviewerUsage,
422
- ReviewerWorkspaceDisposition,
423
- } from "./reviewer-execution-ledger.ts";
424
- export type { AcceptedReviewerDispatch, AcceptedReviewerExecution, ReviewerPinnedGitReader } from "./reviewer-dispatch.ts";
425
- export type { ReviewerDispatchRunResult } from "./reviewer-agent.ts";
426
- export type { CollectorReceipt } from "./collector-receipt.ts";
403
+ export type { ReviewerPinnedGitReader } from "./reviewer-dispatch.ts";
404
+ export type { CollectorReceipt } from "./package-contracts/collector-output.ts";
427
405
  export type { CollectorGitHubTransport } from "./collector-github.ts";
428
406
  export type { CollectorClock } from "./collector-evidence.ts";
429
407
  export * from "./navigator-attendance.ts";
@@ -479,31 +457,10 @@ function activationStage(role: PackagedRole, runtime: ActivationRuntime): { id:
479
457
  case "judge": return { id: "load-and-install", run: async () => runtime.judge.activate() };
480
458
  case "fixer": return { id: "load-and-install", run: async () => runtime.fixer.activate() };
481
459
  case "coder": return { id: "load-and-install", run: async () => runtime.coder.activate(runtime.context) };
482
- case "reviewer": return { id: "load-install-and-dispatch", run: async () => {
483
- // Envelope owns flag decode inside the activation stage (trace + fail-closed path).
460
+ case "reviewer": return { id: "load-and-install", run: async () => {
484
461
  const admitted = runtime.decodeReviewerAdmitted();
485
462
  const activation = await runtime.reviewer.activate(runtime.context, admitted);
486
463
  runtime.bindReviewerParent(activation);
487
- const result = await activation.dispatcher.dispatch(activation.fixedBaseRevision, { context: runtime.context });
488
- if (result.status !== "accepted") {
489
- const rejection = new ExplicitInternalActivationError(
490
- `Fixed Reviewer dispatch was not accepted: ${result.status}: ${result.diagnostic}`,
491
- {
492
- knownCause: "activation",
493
- name: "ReviewerDispatchRejectionError",
494
- },
495
- );
496
- // Pi stderr cannot carry the structured violations. Do not mask a durable
497
- // write failure: its infrastructure cause is truer than the unwritten page.
498
- const runDir = process.env.AK_ROLE_RUN_DIR;
499
- if (typeof runDir === "string" && runDir.trim() !== "") {
500
- recordReviewerDispatchRejectionSync(runDir, {
501
- diagnostic: rejection.message,
502
- violations: result.violations,
503
- });
504
- }
505
- throw rejection;
506
- }
507
464
  } };
508
465
  case "collector": return { id: "load-and-install", run: async () => runtime.collector.activate(runtime.context, runtime.event) };
509
466
  case "doctor": return { id: "load-and-install", run: async () => runtime.doctor.activate() };
@@ -616,8 +573,6 @@ export type RoleRuntimeDependencies = {
616
573
  loadCoderTask?(path: string): Promise<string>;
617
574
  loadReviewerSoul?(): Promise<string>;
618
575
  createReviewerPinnedGitReader?(): Promise<ReviewerPinnedGitReader>;
619
- /** Shared-seam issue-fetch capability for Reviewer Spec self-fetch (#343). */
620
- createReviewerIssueFetcher?(): ReviewerIssueFetcher;
621
576
  loadCollectorSoul?(): Promise<string>;
622
577
  /** #677: optional packaged seed for first-use general bot handbook. */
623
578
  loadCollectorHandbookSeed?(): Promise<string>;
@@ -642,16 +597,6 @@ export type RoleRuntimeDependencies = {
642
597
  loadCanonicalSkillBinding?(
643
598
  name: "tdd" | "code-review",
644
599
  ): Promise<AnyCanonicalSkillBinding>;
645
- runReviewerDispatch?(
646
- dispatch: AcceptedReviewerExecution,
647
- options: {
648
- context: HostContext;
649
- signal?: AbortSignal;
650
- /** Request-scoped RoleHost flag reader for engine axis (#818). */
651
- getFlag?: (name: string) => boolean | string | undefined;
652
- },
653
- ): Promise<ReviewerDispatchRunResult>;
654
- shutdownReviewerAgent?(): Promise<void>;
655
600
  activationClock?(): string;
656
601
  activationTraceWriter?: (record: ActivationTraceRecord) => void | Promise<void>;
657
602
  /** Wall-clock ISO timestamps for tool-execution observation records; defaults to activationClock/Date. */
@@ -728,7 +673,7 @@ export function publicNavigatorSettlement(role: string, phase: NavigatorPhase, e
728
673
  }
729
674
 
730
675
  export async function projectClosedSubmissionLifecycle(
731
- projection: import("./submission-ledger.ts").ClosedSubmissionProjection,
676
+ closed: import("./submission-ledger.ts").ClosedSubmission,
732
677
  context: HostContext,
733
678
  phase: NavigatorPhase,
734
679
  recordAccepted: () => void,
@@ -736,12 +681,12 @@ export async function projectClosedSubmissionLifecycle(
736
681
  ): Promise<void> {
737
682
  recordAccepted();
738
683
  const closure = {
739
- toolName: navigatorOutputTool(projection.role)!,
684
+ toolName: navigatorOutputTool(closed.role)!,
740
685
  isError: false,
741
- details: projection.decisiveFacts,
686
+ details: closed.accepted,
742
687
  };
743
688
  context.sessionManager.appendCustomEntry?.("ak-role-submission-closure", closure);
744
- await settle(publicNavigatorSettlement(projection.role, phase, closure));
689
+ await settle(publicNavigatorSettlement(closed.role, phase, closure));
745
690
  }
746
691
 
747
692
  /**
@@ -934,7 +879,7 @@ export function createAuditorRoleRuntime(
934
879
  */
935
880
  function readDiaristTicketAssertion(
936
881
  submitted: Record<string, unknown> | undefined,
937
- ): { kind: "true-unbound" } | { kind: "ticket"; ticketNumber: number } {
882
+ ): { kind: "true-unbound" } | { kind: "ticket"; ticketNumber: number } | { kind: "invalid" } {
938
883
  if (submitted === undefined || !("ticketNumber" in submitted)) {
939
884
  return { kind: "true-unbound" };
940
885
  }
@@ -949,9 +894,7 @@ function readDiaristTicketAssertion(
949
894
  return { kind: "ticket", ticketNumber: n };
950
895
  }
951
896
  }
952
- throw new Error(
953
- "diarist ticketNumber must be a safe integer >= 1, null, or absent",
954
- );
897
+ return { kind: "invalid" };
955
898
  }
956
899
 
957
900
  /** Run coordinates + optional pre-bound ticket from durable pages (#779). */
@@ -1010,61 +953,22 @@ export function createDiaristRoleRuntime(
1010
953
  parameters !== null && typeof parameters === "object" && !Array.isArray(parameters)
1011
954
  ? (parameters as Record<string, unknown>)
1012
955
  : undefined;
1013
-
1014
- // LLM cannot identify the court target — escalate without machine facts.
1015
- // Strip sitian (锚定宪法) and ticketNumber (must not leak into
1016
- // caller-visible admitted typed key via decisiveFacts mirror).
1017
- if (submitted?.status === "escalate") {
1018
- if (!("sitian" in submitted) && !("ticketNumber" in submitted)) {
1019
- return submitted;
1020
- }
1021
- const stripped = { ...submitted };
1022
- delete stripped.sitian;
1023
- delete stripped.ticketNumber;
1024
- return stripped;
1025
- }
1026
-
1027
956
  const assertion = readDiaristTicketAssertion(submitted);
1028
957
  const coords = readDiaristRunCoordinates();
1029
-
1030
- // Already bound before the turn (typed handoff / resume): skip re-recognition
1031
- // and commit under that identity (ADR 0075 已绑定 ticket 优先).
1032
- const ticketNumber =
1033
- coords.boundTicketNumber !== undefined
1034
- ? coords.boundTicketNumber
1035
- : assertion.kind === "ticket"
1036
- ? assertion.ticketNumber
1037
- : undefined;
1038
-
1039
- // true-unbound → 无录 (no volume). Cannot-identify must arrive as
1040
- // status=escalate above — never as silent unbound.
1041
- if (ticketNumber === undefined) {
1042
- if (submitted === undefined || !("sitian" in submitted)) {
1043
- return { ...(submitted ?? { receipt: parameters }), ticketNumber: null };
958
+ // #836 7.3: pre-bound ticket is material for the LLM, not an override.
959
+ const ticketNumber = assertion.kind === "ticket" ? assertion.ticketNumber : undefined;
960
+ if (ticketNumber !== undefined) {
961
+ if (coords.boundTicketNumber === undefined) {
962
+ await bindTicketNumberOnRunDirectory(coords.runDirectory, ticketNumber);
1044
963
  }
1045
- const stripped: Record<string, unknown> = {
1046
- ...submitted,
1047
- ticketNumber: null,
1048
- };
1049
- delete stripped.sitian;
1050
- return stripped;
1051
- }
1052
-
1053
- if (coords.boundTicketNumber === undefined) {
1054
- await bindTicketNumberOnRunDirectory(coords.runDirectory, ticketNumber);
964
+ await commitDiaristEntries({
965
+ ticketNumber,
966
+ cwd: coords.projectRoot,
967
+ home: coords.home,
968
+ entries: projectDiaristEntries(parameters),
969
+ });
1055
970
  }
1056
-
1057
- const facts = await commitDiaristEntries({
1058
- ticketNumber,
1059
- cwd: coords.projectRoot,
1060
- home: coords.home,
1061
- entries: projectDiaristEntries(parameters),
1062
- });
1063
- return {
1064
- ...(submitted ?? { receipt: parameters }),
1065
- ticketNumber,
1066
- sitian: facts,
1067
- };
971
+ return parameters;
1068
972
  },
1069
973
  },
1070
974
  dependencies,
@@ -1136,14 +1040,14 @@ export function createRoleRuntimeExtension(
1136
1040
  dependencies: RoleRuntimeDependencies,
1137
1041
  ): (envelopeHost: RoleEnvelopeHost) => void {
1138
1042
  return (envelopeHost) => {
1139
- let projectClosedSubmission: (projection: import("./submission-ledger.ts").ClosedSubmissionProjection, context: HostContext) => Promise<void> = async () => {
1043
+ let projectClosedSubmission: (closed: import("./submission-ledger.ts").ClosedSubmission, context: HostContext) => Promise<void> = async () => {
1140
1044
  throw new Error("角色终局投射接缝尚未初始化");
1141
1045
  };
1142
1046
  const roleHost = createSubmissionLedgerHost(
1143
1047
  envelopeHost.host,
1144
1048
  new Map(PACKAGED_ROLE_REGISTRY.map(({ role, outputTool }) => [outputTool, role])),
1145
1049
  failInfrastructure,
1146
- async (projection, context) => projectClosedSubmission(projection, context),
1050
+ async (closed, context) => projectClosedSubmission(closed, context),
1147
1051
  );
1148
1052
  roleHost.registerFlag(ROLE_FLAG.name, ROLE_FLAG.definition);
1149
1053
  // Reviewer transport flags: shared envelope owns registration (ADR 0018).
@@ -1225,15 +1129,36 @@ export function createRoleRuntimeExtension(
1225
1129
  };
1226
1130
  pendingNavigatorPresentation = { event, report };
1227
1131
  }
1228
- await attendance.dispose();
1132
+ // 过时不候: do not await sidecar teardown — parent court must close.
1133
+ // Dispose failure is recorded, not washed; it must not re-block the court.
1134
+ void Promise.resolve(attendance.dispose()).then(
1135
+ undefined,
1136
+ (error) => {
1137
+ try {
1138
+ sitianReport({
1139
+ level: "event",
1140
+ kind: "navigator-dispose-failure",
1141
+ payload: {
1142
+ diagnostic: error instanceof Error ? error.message : String(error),
1143
+ },
1144
+ source: "role-runtime",
1145
+ });
1146
+ } catch (recordError) {
1147
+ envelopeHost.appendEntry?.("ak-navigator-dispose-failure", {
1148
+ diagnostic: error instanceof Error ? error.message : String(error),
1149
+ recordFailure: recordError instanceof Error ? recordError.message : String(recordError),
1150
+ });
1151
+ }
1152
+ },
1153
+ );
1229
1154
  })();
1230
1155
  pendingNavigatorSettlement = pending;
1231
1156
  await pending;
1232
1157
  };
1233
- projectClosedSubmission = async (projection, context) => projectClosedSubmissionLifecycle(
1234
- projection,
1158
+ projectClosedSubmission = async (closed, context) => projectClosedSubmissionLifecycle(
1159
+ closed,
1235
1160
  context,
1236
- navigatorPhase(roleHost, projection.role),
1161
+ navigatorPhase(roleHost, closed.role),
1237
1162
  () => receiptDelivery.recordAccepted(),
1238
1163
  settleNavigatorProjection,
1239
1164
  );
@@ -1278,6 +1203,10 @@ export function createRoleRuntimeExtension(
1278
1203
  // Soft session_start placeholders (no materials yet) recover here; hard
1279
1204
  // contextError from true loader failures stays poisoned and honest.
1280
1205
  if (navigatorWorkContext.subjectProvenance === "placeholder") {
1206
+ // Navigator's own input bootstrap, not a rewrite of another role's
1207
+ // output payload (#836 targets the latter): the human's own raw
1208
+ // prompt bytes, copied verbatim into Navigator's work context when
1209
+ // nothing else has supplied a subject yet.
1281
1210
  const subject = event.prompt.trim();
1282
1211
  if (subject !== "") {
1283
1212
  const root = subjectPath(ctx.sessionManager.getSessionDir(), ctx.cwd);
@@ -1300,53 +1229,23 @@ export function createRoleRuntimeExtension(
1300
1229
  // Envelope-owned Reviewer expansion capture + parent prompt assembly (no role-module callback).
1301
1230
  if (role === "reviewer" && activeReviewerParent !== undefined) {
1302
1231
  if (!reviewerExpansionCaptured) {
1303
- if (
1304
- reviewerOriginalRequest === undefined
1305
- || activeReviewerParent.skillBinding.captureExpansion(
1232
+ if (reviewerOriginalRequest !== undefined) {
1233
+ activeReviewerParent.skillBinding.captureExpansion(
1306
1234
  roleHost.capabilities?.skillExpansion(event.prompt),
1307
1235
  reviewerOriginalRequest,
1308
- ) === undefined
1309
- ) {
1310
- failInfrastructure(
1311
- new Error("Canonical code-review Skill expansion did not match the captured request"),
1312
- ctx,
1313
1236
  );
1314
1237
  }
1315
1238
  reviewerExpansionCaptured = true;
1316
1239
  }
1317
- const specDisposition = activeReviewerParent.getSpecDisposition();
1318
1240
  return {
1319
1241
  systemPrompt: assembleReviewerParentSystemPrompt({
1320
1242
  baseSystemPrompt: event.systemPrompt,
1321
1243
  soul: activeReviewerParent.soul,
1322
- ...(specDisposition === undefined ? {} : { specDisposition }),
1323
1244
  }),
1324
1245
  };
1325
1246
  }
1326
1247
  // #676 E / J1: collector materials + drift gates share this envelope hook (no parallel register).
1327
1248
  if (role === "collector" && activeCollector !== undefined) {
1328
- const options = event.systemPromptOptions;
1329
- if (options.skills && options.skills.length > 0) {
1330
- failInfrastructure(
1331
- activeCollector.ledger.latchFatal("通进司检测到系统提示中的环境 skills"),
1332
- ctx,
1333
- );
1334
- }
1335
- if (options.contextFiles && options.contextFiles.length > 0) {
1336
- failInfrastructure(
1337
- activeCollector.ledger.latchFatal("通进司检测到系统提示中的环境 context files"),
1338
- ctx,
1339
- );
1340
- }
1341
- if (
1342
- typeof options.appendSystemPrompt === "string"
1343
- && options.appendSystemPrompt.trim().length > 0
1344
- ) {
1345
- failInfrastructure(
1346
- activeCollector.ledger.latchFatal("通进司检测到 appendSystemPrompt 漂移"),
1347
- ctx,
1348
- );
1349
- }
1350
1249
  if (!collectorFirstDispatchDone) {
1351
1250
  collectorFirstDispatchDone = true;
1352
1251
  activeCollector.ledger.recordActivation(activeCollector.clock);
@@ -1379,7 +1278,7 @@ export function createRoleRuntimeExtension(
1379
1278
  const reason = (event.content ?? [])
1380
1279
  .map((part) => part.type === "text" && "text" in part ? part.text : "")
1381
1280
  .join("")
1382
- .trim() || "terminating tool rejected";
1281
+ .trim();
1383
1282
  receiptDelivery.recordRejected(reason);
1384
1283
  }
1385
1284
  // Accepted/human terminal projection belongs exclusively to typed ledger
@@ -1391,7 +1290,7 @@ export function createRoleRuntimeExtension(
1391
1290
  // Persist typed infrastructure-failure fact onto the role session toolResult so
1392
1291
  // exact-session restart shares the same durable completion classification.
1393
1292
  if (infrastructureDetails !== undefined) {
1394
- return { details: infrastructureDetails, isError: true };
1293
+ return { isError: true };
1395
1294
  }
1396
1295
  // Submission non-pass: throw kept message text for the model; project the
1397
1296
  // envelope-bound structured result onto session details at this tool_result seam.
@@ -1405,11 +1304,7 @@ export function createRoleRuntimeExtension(
1405
1304
  // a second file, grep, or nesting step. Receipt details stay contract-pure;
1406
1305
  // unavailable/no-advice leave the settlement untouched.
1407
1306
  if (event.isError) return;
1408
- const decorated = decorateSettlementWithNavigation(event, pendingNavigatorPresentation);
1409
- if (decorated === undefined) return;
1410
- return {
1411
- content: decorated.content as typeof event.content,
1412
- };
1307
+ return;
1413
1308
  });
1414
1309
  // Queue receipt delivery before `agent_settled`: that event means Pi has
1415
1310
  // already decided no queued continuation will run, so a triggerTurn there is
@@ -1419,9 +1314,10 @@ export function createRoleRuntimeExtension(
1419
1314
  const lastMessage = event.messages.at(-1);
1420
1315
  if (lastMessage?.role === "assistant"
1421
1316
  && (lastMessage.stopReason === "error" || lastMessage.stopReason === "aborted")) {
1422
- // Provider failure/abort has no tool_result event; classify it here so the
1423
- // receipt policy cannot turn infrastructure death into an exit-0 lifecycle.
1424
- receiptDelivery.stopForInfrastructure();
1317
+ // Abort after an already-recorded receipt must not un-accept or催交.
1318
+ if (receiptDelivery.nextAction() !== "accepted") {
1319
+ receiptDelivery.stopForInfrastructure();
1320
+ }
1425
1321
  return;
1426
1322
  }
1427
1323
  if (receiptDelivery.nextAction() === "request-delivery") {
@@ -1606,21 +1502,6 @@ export function createRoleRuntimeExtension(
1606
1502
  }
1607
1503
  return dependencies.loadCanonicalSkillBinding(name);
1608
1504
  },
1609
- ...(dependencies.createReviewerIssueFetcher === undefined
1610
- ? {}
1611
- : { fetchIssue: dependencies.createReviewerIssueFetcher() }),
1612
- async runDispatch(dispatch, options) {
1613
- if (dependencies.runReviewerDispatch === undefined) throw new Error("Reviewer runtime dependencies are not configured");
1614
- // #818: request-scoped engine flag reaches axis sub-session via same RoleHost
1615
- // that parent registerEngineDetourTool reads — never ambient process.env.
1616
- return dependencies.runReviewerDispatch(dispatch, {
1617
- ...options,
1618
- getFlag: (name) => roleHost.getFlag(name),
1619
- });
1620
- },
1621
- ...(dependencies.shutdownReviewerAgent === undefined
1622
- ? {}
1623
- : { shutdownAgent: dependencies.shutdownReviewerAgent }),
1624
1505
  },
1625
1506
  hostActions,
1626
1507
  );
@@ -1767,23 +1648,6 @@ export function createRoleRuntimeExtension(
1767
1648
  `Collector does not support session_start reason ${event.reason}`,
1768
1649
  );
1769
1650
  }
1770
- // #676 J4: ambient skill/prompt/template commands fail closed at activation.
1771
- const commands = roleHost.getCommands?.() ?? [];
1772
- const ambientCommands = commands.filter((command) => {
1773
- const name = command.name.toLowerCase();
1774
- return (
1775
- name.includes("skill")
1776
- || name.includes("prompt")
1777
- || name.startsWith("template")
1778
- );
1779
- });
1780
- if (ambientCommands.length > 0) {
1781
- throw new Error(
1782
- `Collector detected ambient instruction commands: ${
1783
- ambientCommands.map((c) => c.name).join(", ")
1784
- }`,
1785
- );
1786
- }
1787
1651
  // Business tools behind admission barrier (inert-without-role invariant).
1788
1652
  // First activation: fail closed if a required name is already occupied.
1789
1653
  // Later activations reuse the once-registered tools (registerBusinessTools is idempotent).
@@ -6,20 +6,6 @@ import {
6
6
  WorkerUnfinishedReasonReminderError,
7
7
  } from "./submission-errors.ts";
8
8
 
9
- /**
10
- * Mechanical non-sole resume text — one shared authority for Pi followUp and
11
- * ACP/headless closeRound retry (#813). Officer bounce/escalate use projected
12
- * receipt text instead; this string is only the round-shape correction.
13
- */
14
- export const NON_SOLE_ROUND_RESUME_MESSAGE =
15
- "终局交卷并非本轮唯一工具调用。";
16
-
17
- /** Resume text for mechanical deliverSubmissionRejection codes (no officer receipt). */
18
- export function mechanicalSubmissionRejectionResumeMessage(code: string): string {
19
- if (code === "non-sole-round") return NON_SOLE_ROUND_RESUME_MESSAGE;
20
- return code;
21
- }
22
-
23
9
  /** Shared, unforgeable identity for submission errors that the same session may correct. */
24
10
  const correctableSubmissionErrorBrand = Symbol("ak-roles.correctable-submission-error");
25
11
 
@@ -15,7 +15,12 @@ function gatekeeperNonPassMessage(result: GatekeeperNonPassResult): string {
15
15
  if (result.status === "bounce" || result.status === "escalate") {
16
16
  return serializeReceipt(result.receipt);
17
17
  }
18
- // no_receipt
18
+ if (result.status === "transport_failure") {
19
+ const head = `门下省 ${result.status}(${result.stage}):${result.reason}`;
20
+ return result.submission === undefined
21
+ ? head
22
+ : `${head}\n${serializeReceipt(result.submission)}`;
23
+ }
19
24
  return `门下省 ${result.status}(${result.stage}):${result.reason}`;
20
25
  }
21
26