@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.
- package/dist/acp-host/production-host.js +19434 -18218
- package/dist/analyst-book-key.js +63 -0
- package/dist/analyst-cohort.js +167 -0
- package/dist/analyst-entry.js +320 -0
- package/dist/analyst-index.js +247 -0
- package/dist/analyst-ledger.js +561 -0
- package/dist/analyst-median.js +16 -0
- package/dist/analyst-metric-families/acceptance-success-rework.js +249 -0
- package/dist/analyst-metric-families/b2-frame-buckets-actions.js +189 -0
- package/dist/analyst-metric-families/gate-cycles.js +77 -0
- package/dist/analyst-metric-families/leg-wall-clock.js +56 -0
- package/dist/analyst-metric-families/round-timeline.js +126 -0
- package/dist/analyst-metric-families.js +23 -0
- package/dist/analyst-metric-family.js +11 -0
- package/dist/analyst-model-groups.js +135 -0
- package/dist/analyst-page.js +182 -0
- package/dist/atomic-write.js +23 -0
- package/dist/auditor-soul.js +1 -1
- package/dist/countersign-contracts.js +0 -2
- package/dist/diarist-contracts.js +0 -1
- package/dist/doctor-contracts.js +2 -2
- package/dist/gatekeeper-role.js +15 -16
- package/dist/gleaner-left-contracts.js +0 -2
- package/dist/headless-host/production-host.js +16967 -15749
- package/dist/host-contracts.js +0 -4
- package/dist/inspector-contracts.js +0 -2
- package/dist/institutional-resolution.js +4 -2
- package/dist/merger-contracts.js +0 -2
- package/dist/migrate-book-topology.js +3908 -3089
- package/dist/navigator-public-session.js +4 -3
- package/dist/notary-contracts.js +0 -2
- package/dist/package-contracts/auditor-output.js +0 -1
- package/dist/package-contracts/collector-output.js +0 -2
- package/dist/package-contracts/fixer-output.js +0 -2
- package/dist/package-contracts/gatekeeper-output.js +0 -2
- package/dist/package-contracts/judge-output.js +0 -2
- package/dist/package-contracts/navigator-output.js +0 -2
- package/dist/package-contracts/reviewer-output.js +0 -2
- package/dist/package-contracts/terminating-tools.js +32 -92
- package/dist/package-contracts/worker-output.js +0 -4
- package/dist/packaged-role-registry.js +518 -36
- package/dist/pi/role-turn-host.js +2 -1
- package/dist/public-cli/analyst-run.js +185 -0
- package/dist/public-cli/cli.js +885 -0
- package/dist/public-cli/config.js +12 -9
- package/dist/public-cli/countersign-run.js +4 -311
- package/dist/public-cli/instruction-seat-run.js +628 -158
- package/dist/public-cli/invocation.js +806 -1550
- package/dist/public-cli/main.js +6962 -9882
- package/dist/public-cli/option-definitions.js +51 -99
- package/dist/public-cli/post-admission.js +30 -2
- package/dist/public-cli/run-lifecycle.js +234 -353
- package/dist/public-cli/seat-ticket-binding.js +6 -0
- package/dist/public-cli/settlement.js +261 -675
- package/dist/public-cli/turn-request.js +76 -0
- package/dist/public-role-summons.js +38 -112
- package/dist/role-activation-flags.js +23 -45
- package/dist/secretariat-contracts.js +0 -2
- package/dist/session-identity.js +17 -8
- package/dist/session-opening-materials.js +3 -2
- package/extensions/role-runtime.ts +6 -80
- package/package.json +1 -1
- package/souls/coder.md +1 -2
- package/src/acp-host/role-turn-host.ts +4 -1
- package/src/analyst-metric-families/acceptance-success-rework.ts +3 -2
- package/src/auditor-role.ts +1 -2
- package/src/auditor-soul.ts +1 -1
- package/src/collector-role.ts +2 -2
- package/src/countersign-contracts.ts +0 -1
- package/src/countersign-role.ts +1 -1
- package/src/diarist-contracts.ts +0 -1
- package/src/diarist-role.ts +0 -1
- package/src/doctor-auditor.ts +1 -2
- package/src/doctor-contracts.ts +1 -1
- package/src/doctor-role.ts +3 -2
- package/src/external-host-turn-loop.ts +1 -1
- package/src/factory-board.ts +10 -7
- package/src/gatekeeper-role.ts +16 -10
- package/src/gleaner-left-contracts.ts +0 -1
- package/src/gleaner-left-role.ts +0 -1
- package/src/headless-host/role-turn-host.ts +7 -1
- package/src/host-contracts.ts +10 -6
- package/src/inspector-contracts.ts +0 -1
- package/src/inspector-role.ts +0 -2
- package/src/institutional-resolution.ts +6 -4
- package/src/judge-role.ts +3 -3
- package/src/merger-contracts.ts +0 -1
- package/src/merger-role.ts +2 -2
- package/src/navigator-public-session.ts +7 -6
- package/src/navigator-work-context.ts +6 -8
- package/src/notary-contracts.ts +0 -1
- package/src/notary-role.ts +2 -3
- package/src/package-contracts/auditor-output.ts +0 -1
- package/src/package-contracts/collector-output.ts +0 -1
- package/src/package-contracts/fixer-output.ts +0 -1
- package/src/package-contracts/gatekeeper-output.ts +0 -1
- package/src/package-contracts/judge-output.ts +0 -1
- package/src/package-contracts/navigator-output.ts +0 -1
- package/src/package-contracts/reviewer-output.ts +0 -1
- package/src/package-contracts/terminating-tools.ts +27 -99
- package/src/package-contracts/worker-output.ts +0 -2
- package/src/packaged-role-registry.ts +604 -35
- package/src/pi/role-turn-host.ts +2 -1
- package/src/public-cli/cli.ts +64 -259
- package/src/public-cli/config.ts +18 -10
- package/src/public-cli/countersign-run.ts +14 -449
- package/src/public-cli/instruction-seat-run.ts +758 -277
- package/src/public-cli/invocation.ts +1097 -2051
- package/src/public-cli/option-definitions.ts +62 -127
- package/src/public-cli/post-admission.ts +47 -2
- package/src/public-cli/run-lifecycle.ts +303 -613
- package/src/public-cli/seat-ticket-binding.ts +6 -0
- package/src/public-cli/settlement.ts +399 -1185
- package/src/public-cli/turn-request.ts +92 -1
- package/src/public-role-summons.ts +44 -128
- package/src/reviewer-role.ts +3 -2
- package/src/role-activation-flags.ts +20 -41
- package/src/role-runtime-dependencies.ts +25 -26
- package/src/role-runtime.ts +121 -232
- package/src/secretariat-contracts.ts +0 -1
- package/src/secretariat-role.ts +0 -2
- package/src/session-identity.ts +23 -8
- package/src/session-opening-materials.ts +2 -1
- package/src/worker-role.ts +3 -4
- package/dist/doctor-auditor.js +0 -25
- package/dist/public-cli/diarist-run.js +0 -130
- package/dist/public-cli/doctor-run.js +0 -87
- package/dist/public-cli/inspector-run.js +0 -151
- package/dist/public-cli/judge-run.js +0 -114
- package/dist/public-cli/notary-run.js +0 -174
- package/dist/public-cli/reviewer-run.js +0 -339
- package/src/public-cli/coder-run.ts +0 -255
- package/src/public-cli/collector-run.ts +0 -189
- package/src/public-cli/diarist-run.ts +0 -233
- package/src/public-cli/doctor-run.ts +0 -167
- package/src/public-cli/fixer-run.ts +0 -265
- package/src/public-cli/gleaner-left-run.ts +0 -167
- package/src/public-cli/inspector-run.ts +0 -261
- package/src/public-cli/judge-run.ts +0 -196
- package/src/public-cli/merger-run.ts +0 -294
- package/src/public-cli/notary-run.ts +0 -279
- package/src/public-cli/reviewer-run.ts +0 -480
- 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
|
-
}
|