@akagilnc/pi-workflow-roles 0.1.4800 → 0.1.4870

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 (143) hide show
  1. package/dist/acp-host/production-host.js +19434 -18218
  2. package/dist/analyst-book-key.js +63 -0
  3. package/dist/analyst-cohort.js +167 -0
  4. package/dist/analyst-entry.js +320 -0
  5. package/dist/analyst-index.js +247 -0
  6. package/dist/analyst-ledger.js +561 -0
  7. package/dist/analyst-median.js +16 -0
  8. package/dist/analyst-metric-families/acceptance-success-rework.js +249 -0
  9. package/dist/analyst-metric-families/b2-frame-buckets-actions.js +189 -0
  10. package/dist/analyst-metric-families/gate-cycles.js +77 -0
  11. package/dist/analyst-metric-families/leg-wall-clock.js +56 -0
  12. package/dist/analyst-metric-families/round-timeline.js +126 -0
  13. package/dist/analyst-metric-families.js +23 -0
  14. package/dist/analyst-metric-family.js +11 -0
  15. package/dist/analyst-model-groups.js +135 -0
  16. package/dist/analyst-page.js +182 -0
  17. package/dist/atomic-write.js +23 -0
  18. package/dist/auditor-soul.js +1 -1
  19. package/dist/countersign-contracts.js +0 -2
  20. package/dist/diarist-contracts.js +0 -1
  21. package/dist/doctor-contracts.js +2 -2
  22. package/dist/gatekeeper-role.js +15 -16
  23. package/dist/gleaner-left-contracts.js +0 -2
  24. package/dist/headless-host/production-host.js +16967 -15749
  25. package/dist/host-contracts.js +0 -4
  26. package/dist/inspector-contracts.js +0 -2
  27. package/dist/institutional-resolution.js +4 -2
  28. package/dist/merger-contracts.js +0 -2
  29. package/dist/migrate-book-topology.js +3908 -3089
  30. package/dist/navigator-public-session.js +4 -3
  31. package/dist/notary-contracts.js +0 -2
  32. package/dist/package-contracts/auditor-output.js +0 -1
  33. package/dist/package-contracts/collector-output.js +0 -2
  34. package/dist/package-contracts/fixer-output.js +0 -2
  35. package/dist/package-contracts/gatekeeper-output.js +0 -2
  36. package/dist/package-contracts/judge-output.js +0 -2
  37. package/dist/package-contracts/navigator-output.js +0 -2
  38. package/dist/package-contracts/reviewer-output.js +0 -2
  39. package/dist/package-contracts/terminating-tools.js +32 -92
  40. package/dist/package-contracts/worker-output.js +0 -4
  41. package/dist/packaged-role-registry.js +518 -36
  42. package/dist/pi/role-turn-host.js +2 -1
  43. package/dist/public-cli/analyst-run.js +185 -0
  44. package/dist/public-cli/cli.js +885 -0
  45. package/dist/public-cli/config.js +12 -9
  46. package/dist/public-cli/countersign-run.js +4 -311
  47. package/dist/public-cli/instruction-seat-run.js +628 -158
  48. package/dist/public-cli/invocation.js +806 -1550
  49. package/dist/public-cli/main.js +6962 -9882
  50. package/dist/public-cli/option-definitions.js +51 -99
  51. package/dist/public-cli/post-admission.js +30 -2
  52. package/dist/public-cli/run-lifecycle.js +234 -353
  53. package/dist/public-cli/seat-ticket-binding.js +6 -0
  54. package/dist/public-cli/settlement.js +261 -675
  55. package/dist/public-cli/turn-request.js +76 -0
  56. package/dist/public-role-summons.js +38 -112
  57. package/dist/role-activation-flags.js +23 -45
  58. package/dist/secretariat-contracts.js +0 -2
  59. package/dist/session-identity.js +17 -8
  60. package/dist/session-opening-materials.js +3 -2
  61. package/extensions/role-runtime.ts +6 -80
  62. package/package.json +1 -1
  63. package/souls/coder.md +1 -2
  64. package/src/acp-host/role-turn-host.ts +4 -1
  65. package/src/analyst-metric-families/acceptance-success-rework.ts +3 -2
  66. package/src/auditor-role.ts +1 -2
  67. package/src/auditor-soul.ts +1 -1
  68. package/src/collector-role.ts +2 -2
  69. package/src/countersign-contracts.ts +0 -1
  70. package/src/countersign-role.ts +1 -1
  71. package/src/diarist-contracts.ts +0 -1
  72. package/src/diarist-role.ts +0 -1
  73. package/src/doctor-auditor.ts +1 -2
  74. package/src/doctor-contracts.ts +1 -1
  75. package/src/doctor-role.ts +3 -2
  76. package/src/external-host-turn-loop.ts +1 -1
  77. package/src/factory-board.ts +10 -7
  78. package/src/gatekeeper-role.ts +16 -10
  79. package/src/gleaner-left-contracts.ts +0 -1
  80. package/src/gleaner-left-role.ts +0 -1
  81. package/src/headless-host/role-turn-host.ts +7 -1
  82. package/src/host-contracts.ts +10 -6
  83. package/src/inspector-contracts.ts +0 -1
  84. package/src/inspector-role.ts +0 -2
  85. package/src/institutional-resolution.ts +6 -4
  86. package/src/judge-role.ts +3 -3
  87. package/src/merger-contracts.ts +0 -1
  88. package/src/merger-role.ts +2 -2
  89. package/src/navigator-public-session.ts +7 -6
  90. package/src/navigator-work-context.ts +6 -8
  91. package/src/notary-contracts.ts +0 -1
  92. package/src/notary-role.ts +2 -3
  93. package/src/package-contracts/auditor-output.ts +0 -1
  94. package/src/package-contracts/collector-output.ts +0 -1
  95. package/src/package-contracts/fixer-output.ts +0 -1
  96. package/src/package-contracts/gatekeeper-output.ts +0 -1
  97. package/src/package-contracts/judge-output.ts +0 -1
  98. package/src/package-contracts/navigator-output.ts +0 -1
  99. package/src/package-contracts/reviewer-output.ts +0 -1
  100. package/src/package-contracts/terminating-tools.ts +27 -99
  101. package/src/package-contracts/worker-output.ts +0 -2
  102. package/src/packaged-role-registry.ts +604 -35
  103. package/src/pi/role-turn-host.ts +2 -1
  104. package/src/public-cli/cli.ts +64 -259
  105. package/src/public-cli/config.ts +18 -10
  106. package/src/public-cli/countersign-run.ts +14 -449
  107. package/src/public-cli/instruction-seat-run.ts +758 -277
  108. package/src/public-cli/invocation.ts +1097 -2051
  109. package/src/public-cli/option-definitions.ts +62 -127
  110. package/src/public-cli/post-admission.ts +47 -2
  111. package/src/public-cli/run-lifecycle.ts +303 -613
  112. package/src/public-cli/seat-ticket-binding.ts +6 -0
  113. package/src/public-cli/settlement.ts +399 -1185
  114. package/src/public-cli/turn-request.ts +92 -1
  115. package/src/public-role-summons.ts +44 -128
  116. package/src/reviewer-role.ts +3 -2
  117. package/src/role-activation-flags.ts +20 -41
  118. package/src/role-runtime-dependencies.ts +25 -26
  119. package/src/role-runtime.ts +121 -232
  120. package/src/secretariat-contracts.ts +0 -1
  121. package/src/secretariat-role.ts +0 -2
  122. package/src/session-identity.ts +23 -8
  123. package/src/session-opening-materials.ts +2 -1
  124. package/src/worker-role.ts +3 -4
  125. package/dist/doctor-auditor.js +0 -25
  126. package/dist/public-cli/diarist-run.js +0 -130
  127. package/dist/public-cli/doctor-run.js +0 -87
  128. package/dist/public-cli/inspector-run.js +0 -151
  129. package/dist/public-cli/judge-run.js +0 -114
  130. package/dist/public-cli/notary-run.js +0 -174
  131. package/dist/public-cli/reviewer-run.js +0 -339
  132. package/src/public-cli/coder-run.ts +0 -255
  133. package/src/public-cli/collector-run.ts +0 -189
  134. package/src/public-cli/diarist-run.ts +0 -233
  135. package/src/public-cli/doctor-run.ts +0 -167
  136. package/src/public-cli/fixer-run.ts +0 -265
  137. package/src/public-cli/gleaner-left-run.ts +0 -167
  138. package/src/public-cli/inspector-run.ts +0 -261
  139. package/src/public-cli/judge-run.ts +0 -196
  140. package/src/public-cli/merger-run.ts +0 -294
  141. package/src/public-cli/notary-run.ts +0 -279
  142. package/src/public-cli/reviewer-run.ts +0 -480
  143. package/src/public-cli/secretariat-run.ts +0 -265
@@ -1,174 +0,0 @@
1
- import { NotarySourceRunError, resolveNotarySourceRunLocator, } from "../notary-source-run.js";
2
- import { engineSessionMaterialFromOptions, pickEngineAxis } from "../package-resources/engine-material.js";
3
- import { CliUsageError } from "./cli-errors.js";
4
- import { admitNotaryInvocation, buildNotaryTransportPrompt, } from "./invocation.js";
5
- import { tryResumeSameTicketSeatRun } from "./seat-ticket-binding.js";
6
- import { prepareSummonsResumeMaterials, runPostAdmissionOneShot, runPostAdmissionSeatResume, resumeTurnRequestProjectionOptions, } from "./post-admission.js";
7
- import { loadResumableNotaryRun, markRunAdmitted, } from "./run-lifecycle.js";
8
- import { presentStructuralRejection, trySettleNotaryTerminalResult, } from "./settlement.js";
9
- import { projectRoleTurnRequest, } from "./turn-request.js";
10
- /** Project admitted invocation onto the host-neutral turn request. */
11
- export function buildNotaryTurnRequest(admitted, options) {
12
- return projectRoleTurnRequest(admitted, {
13
- activation: {
14
- role: "notary",
15
- sourceRun: admitted.sourceRunPath,
16
- // Ticket from source-run admitted form rides activation → flag → role read surface (#635).
17
- ...(admitted.ticketNumber === undefined
18
- ? {}
19
- : { ticketNumber: admitted.ticketNumber }),
20
- },
21
- }, options);
22
- }
23
- export async function runPublicNotary(argv, env, io, parseNotaryArgv) {
24
- let parsed;
25
- try {
26
- parsed = parseNotaryArgv(argv);
27
- }
28
- catch (error) {
29
- if (error instanceof CliUsageError) {
30
- presentStructuralRejection(error, io);
31
- return { exitCode: 2 };
32
- }
33
- throw error;
34
- }
35
- // #637: same ticket → resume prior notary run with this summons' source-run pointer.
36
- // Source-run structural failures stay usage rejections; lookup/resume failures surface
37
- // (no bare catch→fresh). Only true absence of a prior run mints new.
38
- const projectRoot = parsed.project ?? env.cwd;
39
- let source;
40
- try {
41
- source = await resolveNotarySourceRunLocator({
42
- projectRoot,
43
- sourceRun: parsed.sourceRun,
44
- home: env.home,
45
- });
46
- }
47
- catch (error) {
48
- if (error instanceof NotarySourceRunError) {
49
- presentStructuralRejection(new CliUsageError(error.message, { cause: error }), io);
50
- return { exitCode: 2 };
51
- }
52
- throw error;
53
- }
54
- // #747: officer resume key is this parent source-run path (not ticket number).
55
- // #753/#879: gate re-ask and verbatim submission body share summons.instruction
56
- // (reask wins when both present; no parallel stack). Binding stays sourceRunPath.
57
- {
58
- const resumeInstruction = env.reviewReask ?? env.gateReviewInstruction;
59
- const summons = {
60
- sourceRunPath: source.runDirectory,
61
- sourceRun: source,
62
- ...(resumeInstruction === undefined
63
- ? {}
64
- : { instruction: resumeInstruction, instructionEmpty: false }),
65
- };
66
- const resumed = await tryResumeSameTicketSeatRun({
67
- home: env.home,
68
- projectRoot,
69
- role: "notary",
70
- parentRunPath: source.runDirectory,
71
- freshSummons: env.freshSummons,
72
- summons,
73
- resume: (runId, materials) => runPublicNotaryResume({ runId, ...(materials === undefined ? {} : { summons: materials }) }, env, io),
74
- });
75
- if (resumed !== undefined)
76
- return resumed;
77
- }
78
- let admitted;
79
- try {
80
- admitted = await admitNotaryInvocation({
81
- home: env.home,
82
- principalAuthority: env.principalAuthority,
83
- cwd: env.cwd,
84
- sourceRun: parsed.sourceRun,
85
- ...(parsed.project === undefined ? {} : { project: parsed.project }),
86
- ...(env.createRunId === undefined ? {} : { createRunId: env.createRunId }),
87
- ...(env.model === undefined ? {} : { model: env.model }),
88
- ...(env.correlationId === undefined ? {} : { correlationId: env.correlationId }),
89
- });
90
- }
91
- catch (error) {
92
- if (error instanceof CliUsageError) {
93
- presentStructuralRejection(error, io);
94
- return { exitCode: 2 };
95
- }
96
- throw error;
97
- }
98
- await markRunAdmitted(admitted, env.principalAuthority);
99
- const engineMaterial = engineSessionMaterialFromOptions({
100
- ...pickEngineAxis(env),
101
- packageRoot: env.packageRoot,
102
- });
103
- const turnRequest = buildNotaryTurnRequest(admitted, {
104
- packageRoot: env.packageRoot,
105
- home: env.home,
106
- agentDir: env.agentDir,
107
- ...(env.model === undefined ? {} : { model: env.model }),
108
- ...pickEngineAxis(env),
109
- ...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
110
- ...(env.correlationId === undefined || env.correlationId.trim() === ""
111
- ? {}
112
- : { correlationId: env.correlationId }),
113
- continuation: {
114
- kind: "initial",
115
- // #879: gate path first mint carries parent payload as dialogue content;
116
- // external zero-prompt kickoff unchanged when no body/reask.
117
- prompt: (env.reviewReask ?? env.gateReviewInstruction)
118
- ?? buildNotaryTransportPrompt(admitted, engineMaterial),
119
- },
120
- });
121
- return await runPostAdmissionOneShot({
122
- admitted,
123
- env,
124
- io,
125
- request: turnRequest,
126
- adapters: notaryAdapters(),
127
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
128
- });
129
- }
130
- function notaryAdapters() {
131
- return {
132
- trySettle: (admitted, authority, scope) => trySettleNotaryTerminalResult(admitted, authority, scope),
133
- // Accepted receipts and failure terminals both present via shared path.
134
- shouldPresentSettled: () => true,
135
- };
136
- }
137
- /**
138
- * Resume a previously admitted Notary run (#633 / #637). Manual resume restores
139
- * source-run from the durable admitted request. Same-ticket re-summons deliver
140
- * this turn's source-run activation pointer while reopening the same session.
141
- */
142
- export async function runPublicNotaryResume(request, env, io) {
143
- return await runPostAdmissionSeatResume({
144
- request,
145
- env,
146
- io,
147
- load: async (effective) => {
148
- const loaded = await loadResumableNotaryRun(env.home, effective.runId, env.principalAuthority);
149
- const summons = effective.summons;
150
- if (summons?.sourceRunPath !== undefined &&
151
- summons.sourceRun !== undefined) {
152
- return {
153
- admitted: {
154
- ...loaded.admitted,
155
- sourceRunPath: summons.sourceRunPath,
156
- sourceRun: summons.sourceRun,
157
- },
158
- };
159
- }
160
- return loaded;
161
- },
162
- buildTurnRequest: async (admitted, effective) => {
163
- // #755: review continuation is plain dialogue / resume envelope — no
164
- //「重新读」candidate line, no engine handbook packaging.
165
- // #753: non-three-state re-ask rides as summons.instruction (人话重问).
166
- const summonsPrepared = effective.summons === undefined
167
- ? undefined
168
- : await prepareSummonsResumeMaterials(admitted.runDirectory, effective.summons);
169
- return buildNotaryTurnRequest(admitted, resumeTurnRequestProjectionOptions(admitted, effective, env, summonsPrepared));
170
- },
171
- adapters: notaryAdapters(),
172
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
173
- });
174
- }
@@ -1,339 +0,0 @@
1
- /**
2
- * Public Reviewer Role run: admit → post-admission coordinator → settle Terminal result (#917 / #517).
3
- * Package-owned ak-cross-m-review method is forced; users never submit
4
- * extra packets. Controlled-failure settlement reuses #107.
5
- * #526: execution via RoleTurnHost; argv is Pi adapter internal.
6
- */
7
- import { resolve } from "node:path";
8
- import { appendEngineSessionMaterial, engineSessionMaterialFromOptions, pickEngineAxis, } from "../package-resources/engine-material.js";
9
- import { loadPackagedMethodSkillMaterial, resolvePackagedMethodSkillPath, } from "../package-resources/method-skill.js";
10
- import { CliUsageError } from "./cli-errors.js";
11
- import { admitReviewerInvocation, buildReviewerTransportPrompt, } from "./invocation.js";
12
- import { loadResumableReviewerRun, markRunAdmitted, RESUME_TRANSPORT_ENVELOPE, } from "./run-lifecycle.js";
13
- import { presentStructuralRejection, readEngineDetourInfrastructureFailure, trySettleReviewerTerminalResult, } from "./settlement.js";
14
- import { formatTerminalResult, isLawfulTypedTerminalOutcome, } from "./terminal.js";
15
- import { projectRoleTurnRequest, } from "./turn-request.js";
16
- import { presentControlledFailure, resolveResumeMethodMaterialAdapters, runPostAdmissionResumable, runPostAdmissionSeatResume, resumeTurnRequestProjectionOptions, } from "./post-admission.js";
17
- function reviewerMethods(packageRoot) {
18
- return [{ kind: "skill", path: resolvePackagedMethodSkillPath(packageRoot, "ak-cross-m-review") }];
19
- }
20
- /**
21
- * All Reviewer turns (explicit --lens, dual-lens child, resume) execute in a
22
- * fresh worktree of the source tree's current HEAD (#946 统一新副本). Dual-lens
23
- * summon already injects executionCwd; only mint when absent. Cleanup failure
24
- * is diagnostic only and does not flip the exit code. Mint failure propagates
25
- * so the caller can settle a controlled failure against the admitted run.
26
- */
27
- async function runReviewerTurnInFreshCopy(env, projectRoot, io, body) {
28
- if (env.executionCwd !== undefined) {
29
- return body(env);
30
- }
31
- const { withEphemeralReviewerWorktree } = await import("../public-role-summons.js");
32
- return await withEphemeralReviewerWorktree({
33
- projectRoot,
34
- onCleanupDiagnostic: (diagnostic) => {
35
- io.stderr(`${diagnostic}\n`);
36
- },
37
- run: (executionCwd) => body({ ...env, executionCwd }),
38
- });
39
- }
40
- /** Project admitted Reviewer invocation onto the host-neutral turn request. */
41
- export function buildReviewerTurnRequest(admitted, options) {
42
- return projectRoleTurnRequest(admitted, {
43
- activation: {
44
- role: "reviewer",
45
- baseRevision: admitted.baseRevision,
46
- lens: admitted.lens,
47
- authorityRefs: admitted.authorityRefs,
48
- ...(admitted.ticketNumber === undefined ? {} : { ticketNumber: admitted.ticketNumber }),
49
- },
50
- methods: reviewerMethods(options.packageRoot),
51
- }, options);
52
- }
53
- function reviewerAdapters(packageRoot, methodMaterial) {
54
- return {
55
- trySettle: (admitted, authority, scope) => methodMaterial === undefined
56
- ? Promise.resolve(undefined)
57
- : trySettleReviewerTerminalResult(admitted, authority, {
58
- methodProvenance: methodMaterial.provenance,
59
- methodSkillPath: methodMaterial.skillPath,
60
- methodSkillConfiguredPath: resolvePackagedMethodSkillPath(packageRoot, "ak-cross-m-review"),
61
- }, scope),
62
- resolveRunnerKnownFailure: async ({ result, sessionFile }) => {
63
- const infrastructureFailure = await readEngineDetourInfrastructureFailure(sessionFile);
64
- return infrastructureFailure === undefined
65
- ? result.knownFailure
66
- : {
67
- ...(infrastructureFailure.cause === undefined
68
- ? {}
69
- : { cause: infrastructureFailure.cause }),
70
- diagnostic: infrastructureFailure.diagnostic,
71
- ...(infrastructureFailure.identity === undefined
72
- ? {}
73
- : { identity: infrastructureFailure.identity }),
74
- };
75
- },
76
- };
77
- }
78
- async function loadReviewerMethodMaterial(packageRoot) {
79
- return await loadPackagedMethodSkillMaterial(packageRoot, "ak-cross-m-review");
80
- }
81
- /** Continue the existing method turn; frozen axes remain on typed activation fields. */
82
- function reviewerResumePrompt(env, message) {
83
- const lines = [RESUME_TRANSPORT_ENVELOPE];
84
- if (message !== undefined)
85
- lines.push("", message);
86
- return appendEngineSessionMaterial(lines, engineSessionMaterialFromOptions({
87
- ...pickEngineAxis(env),
88
- packageRoot: env.packageRoot,
89
- })).join("\n");
90
- }
91
- export async function runPublicReviewer(argv, env, io, parseReviewerArgv) {
92
- let parsed;
93
- try {
94
- parsed = parseReviewerArgv(argv);
95
- }
96
- catch (error) {
97
- if (error instanceof CliUsageError) {
98
- presentStructuralRejection(error, io);
99
- return { exitCode: 2 };
100
- }
101
- throw error;
102
- }
103
- // Omitted public lens is the parallel two-axis branch mark; never admitted as a parent run.
104
- // Each leg reuses this call's public argv and only adds --lens (#946 / 10a).
105
- if (parsed.lens === undefined) {
106
- const { summonParallelReviewerLenses } = await import("../public-role-summons.js");
107
- const children = await summonParallelReviewerLenses({
108
- argv,
109
- // Replay argv under the same cwd the single-axis entry would see (10a).
110
- // Do not substitute the resolved project path — relative --project must
111
- // not be re-resolved against a shifted cwd.
112
- cwd: env.cwd,
113
- projectRoot: resolve(parsed.project ?? env.cwd),
114
- // Typed base from the public parse — precheck only; child argv stays verbatim.
115
- baseRevision: parsed.baseRevision,
116
- home: env.home,
117
- agentDir: env.agentDir,
118
- ...(env.credentials === undefined ? {} : { credentials: env.credentials }),
119
- ...(env.model === undefined ? {} : { model: env.model }),
120
- ...(env.host === undefined ? {} : { host: env.host }),
121
- ...(env.engine === undefined ? {} : { engine: env.engine }),
122
- ...(env.engineModel === undefined ? {} : { engineModel: env.engineModel }),
123
- packageRoot: env.packageRoot,
124
- ...(env.signal === undefined ? {} : { signal: env.signal }),
125
- ...(env.correlationId === undefined ? {} : { correlationId: env.correlationId }),
126
- roleTurnHost: env.roleTurnHost,
127
- ...(env.hostAdapters === undefined ? {} : { hostAdapters: env.hostAdapters }),
128
- principalAuthority: env.principalAuthority,
129
- ...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
130
- });
131
- const childResults = [children.completeness, children.correctness];
132
- const terminals = childResults
133
- .map((child) => child.terminal)
134
- .filter((terminal) => terminal !== undefined);
135
- // ADR 0052 / terminal.ts: lawful typed child terminals (accepted / no_receipt /
136
- // audit_escalation) are not batch failures. Child exitCode remains the live
137
- // surface for seal/infrastructure overlays that keep the original Terminal.
138
- // failedChildren counts only non-lawful/missing child Terminals; seal overlays
139
- // that flip exitCode while keeping lawful Terminals are a separate identity.
140
- const failedChildren = childResults.filter((child) => child.terminal === undefined
141
- || !isLawfulTypedTerminalOutcome(child.terminal.roleOutcome)).length;
142
- const overlayExit = childResults.some((child) => child.exitCode !== 0);
143
- const failed = failedChildren > 0 || overlayExit;
144
- const overlayDiagnostics = [...new Set(childResults
145
- .map((child) => child.stderr)
146
- .filter((text) => typeof text === "string" && text !== ""))];
147
- const terminal = {
148
- batch: "reviewer",
149
- roleOutcome: failed
150
- ? {
151
- kind: "failure",
152
- role: "reviewer",
153
- diagnostic: failedChildren > 0
154
- ? "Reviewer batch child failure"
155
- : (overlayDiagnostics[0] ?? "Reviewer batch infrastructure failure"),
156
- decisiveFacts: { failedChildren },
157
- payloads: terminals,
158
- }
159
- : { kind: "accepted", role: "reviewer", payloads: terminals },
160
- reviewerChildren: {
161
- ...(children.completeness.terminal === undefined ? {} : { completeness: children.completeness.terminal }),
162
- ...(children.correctness.terminal === undefined ? {} : { correctness: children.correctness.terminal }),
163
- },
164
- reviewerChildOutcomes: {
165
- completeness: { exitCode: children.completeness.exitCode, ...(children.completeness.stderr === undefined ? {} : { stderr: children.completeness.stderr }) },
166
- correctness: { exitCode: children.correctness.exitCode, ...(children.correctness.stderr === undefined ? {} : { stderr: children.correctness.stderr }) },
167
- },
168
- // Batch has no parent run and no own attendance; no-advice is affirmative
169
- // only (navigator-attendance.ts). Children carry their own navigator facts.
170
- navigator: {
171
- disposition: "unavailable",
172
- source: "unknown",
173
- reason: "Reviewer batch has no parent-run Navigator attendance",
174
- },
175
- artifacts: terminals.flatMap((item) => item.artifacts),
176
- };
177
- io.stdout(formatTerminalResult(terminal));
178
- return { exitCode: failed ? 1 : 0, terminal };
179
- }
180
- let admitted;
181
- try {
182
- admitted = await admitReviewerInvocation({
183
- home: env.home,
184
- principalAuthority: env.principalAuthority,
185
- cwd: env.cwd,
186
- instruction: parsed.instruction,
187
- attachmentPaths: parsed.attachmentPaths,
188
- baseRevision: parsed.baseRevision,
189
- lens: parsed.lens,
190
- authorityRefs: parsed.authorityRefs,
191
- ...(parsed.project === undefined ? {} : { project: parsed.project }),
192
- ...(env.createRunId === undefined ? {} : { createRunId: env.createRunId }),
193
- ...(env.correlationId === undefined ? {} : { correlationId: env.correlationId }),
194
- ...(env.model === undefined ? {} : { model: env.model }),
195
- });
196
- }
197
- catch (error) {
198
- if (error instanceof CliUsageError) {
199
- presentStructuralRejection(error, io);
200
- return { exitCode: 2 };
201
- }
202
- throw error;
203
- }
204
- await markRunAdmitted(admitted, env.principalAuthority);
205
- let methodMaterial;
206
- try {
207
- methodMaterial = await loadReviewerMethodMaterial(env.packageRoot);
208
- }
209
- catch (error) {
210
- return (await presentControlledFailure(admitted, {
211
- timedOut: false,
212
- code: null,
213
- stderr: "",
214
- thrown: error,
215
- }, reviewerAdapters(env.packageRoot), env.principalAuthority, io));
216
- }
217
- // Fresh copy for this call (explicit --lens or dual-lens child with pre-set cwd).
218
- // Durable projectRoot stays the caller project; only the host turn uses the sandbox.
219
- try {
220
- return await runReviewerTurnInFreshCopy(env, admitted.projectRoot, io, async (sandboxedEnv) => await runPostAdmissionResumable({
221
- admitted,
222
- env: sandboxedEnv,
223
- io,
224
- buildInitialRequest: () => buildReviewerTurnRequest(admitted, {
225
- packageRoot: sandboxedEnv.packageRoot,
226
- home: sandboxedEnv.home,
227
- agentDir: sandboxedEnv.agentDir,
228
- ...(sandboxedEnv.model === undefined ? {} : { model: sandboxedEnv.model }),
229
- ...pickEngineAxis(sandboxedEnv),
230
- ...(sandboxedEnv.timeoutMs === undefined ? {} : { timeoutMs: sandboxedEnv.timeoutMs }),
231
- ...(admitted.correlationId === undefined && sandboxedEnv.correlationId === undefined
232
- ? {}
233
- : { correlationId: admitted.correlationId ?? sandboxedEnv.correlationId }),
234
- // Ephemeral worktree cwd; durable projectRoot stays on admitted caller project.
235
- ...(sandboxedEnv.executionCwd === undefined ? {} : { cwd: sandboxedEnv.executionCwd }),
236
- continuation: {
237
- kind: "initial",
238
- prompt: buildReviewerTransportPrompt(admitted, engineSessionMaterialFromOptions({
239
- ...pickEngineAxis(sandboxedEnv),
240
- packageRoot: sandboxedEnv.packageRoot,
241
- })),
242
- },
243
- }),
244
- buildResumeRequest: () => buildReviewerTurnRequest(admitted, {
245
- packageRoot: sandboxedEnv.packageRoot,
246
- home: sandboxedEnv.home,
247
- agentDir: sandboxedEnv.agentDir,
248
- ...(sandboxedEnv.model === undefined ? {} : { model: sandboxedEnv.model }),
249
- ...pickEngineAxis(sandboxedEnv),
250
- ...(sandboxedEnv.timeoutMs === undefined ? {} : { timeoutMs: sandboxedEnv.timeoutMs }),
251
- ...(admitted.correlationId === undefined && sandboxedEnv.correlationId === undefined
252
- ? {}
253
- : { correlationId: admitted.correlationId ?? sandboxedEnv.correlationId }),
254
- // In-batch auto-resume keeps the same call's sandbox (dual-lens or single).
255
- ...(sandboxedEnv.executionCwd === undefined ? {} : { cwd: sandboxedEnv.executionCwd }),
256
- continuation: {
257
- kind: "resume",
258
- prompt: reviewerResumePrompt(sandboxedEnv),
259
- },
260
- }),
261
- adapters: reviewerAdapters(sandboxedEnv.packageRoot, methodMaterial),
262
- ...(sandboxedEnv.engine === undefined ? {} : { effectiveEngine: sandboxedEnv.engine }),
263
- }));
264
- }
265
- catch (error) {
266
- return (await presentControlledFailure(admitted, {
267
- timedOut: false,
268
- code: null,
269
- stderr: "",
270
- thrown: error,
271
- }, reviewerAdapters(env.packageRoot, methodMaterial), env.principalAuthority, io));
272
- }
273
- }
274
- /**
275
- * Resume a previously admitted Reviewer Role run after a typed HTTP 429.
276
- * Restores task/base/session identity; model override is temporary.
277
- * Execution always uses a fresh worktree of the source tree at resume time
278
- * (#946 统一新副本 / 10a) — no old worktree, no ownership record.
279
- * Fresh-copy mint reuses the coordinator's single pre-lease load via
280
- * afterAdmittedPrepare; does not pre-load outside the coordinator.
281
- */
282
- export async function runPublicReviewerResume(request, env, io) {
283
- // Call-local cell: afterAdmittedPrepare writes executionCwd; buildTurnRequest reads it.
284
- // Keeps the single-load coordinator contract — no preliminary load outside.
285
- const sandbox = {
286
- ...(env.executionCwd === undefined ? {} : { executionCwd: env.executionCwd }),
287
- };
288
- return await runPostAdmissionSeatResume({
289
- request,
290
- env,
291
- io,
292
- load: (effective) => loadResumableReviewerRun(env.home, effective.runId, env.principalAuthority),
293
- buildTurnRequest: (admitted, effective) => {
294
- const activeEnv = sandbox.executionCwd === undefined
295
- ? env
296
- : { ...env, executionCwd: sandbox.executionCwd };
297
- const base = resumeTurnRequestProjectionOptions(admitted, effective, activeEnv);
298
- return buildReviewerTurnRequest(admitted, {
299
- ...base,
300
- // Fresh copy at resume time; durable projectRoot unchanged.
301
- ...(sandbox.executionCwd === undefined ? {} : { cwd: sandbox.executionCwd }),
302
- continuation: {
303
- kind: "resume",
304
- prompt: effective.message ?? "",
305
- },
306
- });
307
- },
308
- adapters: reviewerAdapters(env.packageRoot),
309
- afterAdmittedLoad: async (admitted) => {
310
- return resolveResumeMethodMaterialAdapters({
311
- admitted,
312
- authority: env.principalAuthority,
313
- io,
314
- loadMaterial: () => loadReviewerMethodMaterial(env.packageRoot),
315
- adaptersWith: (material) => reviewerAdapters(env.packageRoot, material),
316
- emptyAdapters: reviewerAdapters(env.packageRoot),
317
- });
318
- },
319
- afterAdmittedPrepare: async (admitted) => {
320
- // Already sandboxed (in-batch auto-resume path) — nothing to mint.
321
- if (sandbox.executionCwd !== undefined) {
322
- return { env: { ...env, executionCwd: sandbox.executionCwd } };
323
- }
324
- const { openEphemeralReviewerWorktree } = await import("../public-role-summons.js");
325
- const opened = await openEphemeralReviewerWorktree({
326
- projectRoot: admitted.projectRoot,
327
- onCleanupDiagnostic: (diagnostic) => {
328
- io.stderr(`${diagnostic}\n`);
329
- },
330
- });
331
- sandbox.executionCwd = opened.executionCwd;
332
- return {
333
- env: { ...env, executionCwd: opened.executionCwd },
334
- cleanup: opened.close,
335
- };
336
- },
337
- ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
338
- });
339
- }