@akagilnc/pi-workflow-roles 0.1.2521 → 0.1.2653-next.71811ca
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/README.md +129 -39
- package/README.zh-CN.md +128 -39
- package/dist/activation-ledger-topology.js +1 -1
- package/dist/archivist-record-entry.js +47 -26
- package/dist/auditor-dossier-tool.js +3 -1
- package/dist/compliance-transport.js +17 -26
- package/dist/doctor-contracts.js +1 -2
- package/dist/dossier-resolution.js +4 -8
- package/dist/engine-detour-tool.js +33 -8
- package/dist/engine-detour.js +1 -0
- package/dist/evidence-child-executor.js +277 -424
- package/dist/host-contracts.js +22 -0
- package/dist/institutional-resolution.js +88 -0
- package/dist/merger-contracts.js +1 -2
- package/dist/navigator-attendance.js +16 -0
- package/dist/notary-contracts.js +2 -3
- package/dist/package-contracts/fixer-output.js +1 -2
- package/dist/packaged-role-registry.js +102 -9
- package/dist/pi/in-process-session.js +671 -0
- package/dist/public-cli/config.js +7 -5
- package/dist/public-cli/main.js +3767 -4113
- package/dist/reviewer-child-executor.js +6 -1
- package/dist/session-opening-materials.js +10 -38
- package/dist/sitian-appender.js +146 -0
- package/dist/sitian-contracts.js +21 -0
- package/dist/sitian-facade.js +15 -0
- package/dist/sitian-reader.js +52 -0
- package/extensions/role-runtime.ts +9 -7
- package/package.json +5 -5
- package/resources/engines/cursor.md +12 -26
- package/resources/engines/hermes.md +2 -23
- package/resources/engines/opus.md +1 -16
- package/resources/navigator-route-playbook.md +2 -2
- package/scripts/build-package.mjs +0 -1
- package/souls/quality-law.md +1 -1
- package/src/activation-ledger-topology.ts +1 -1
- package/src/archivist-record-entry.ts +57 -45
- package/src/auditor-dossier-tool.ts +4 -2
- package/src/canonical-skill-binding.ts +37 -27
- package/src/collector-role.ts +11 -20
- package/src/collector-tool-schemas.ts +1 -4
- package/src/compliance-transport.ts +19 -44
- package/src/doctor-auditor.ts +1 -5
- package/src/doctor-contracts.ts +1 -4
- package/src/doctor-role.ts +31 -8
- package/src/dossier-resolution.ts +8 -8
- package/src/engine-detour-tool.ts +48 -19
- package/src/engine-detour.ts +3 -0
- package/src/evidence-child-executor.ts +277 -485
- package/src/factory-board.ts +3 -3
- package/src/gatekeeper-role.ts +21 -10
- package/src/host-contracts.ts +386 -0
- package/src/in-process-session.ts +1 -115
- package/src/institutional-resolution.ts +135 -0
- package/src/judge-auditor.ts +1 -5
- package/src/judge-role.ts +37 -51
- package/src/merger-contracts.ts +1 -4
- package/src/merger-role.ts +7 -11
- package/src/navigator-attendance.ts +20 -1
- package/src/notary-contracts.ts +8 -11
- package/src/notary-role.ts +7 -23
- package/src/notary-source-run.ts +4 -3
- package/src/package-contracts/fixer-output.ts +1 -4
- package/src/package-resources/method-skill-binding.ts +10 -34
- package/src/packaged-role-registry.ts +122 -12
- package/src/pi/adapter.ts +192 -0
- package/src/pi/durable-principal.ts +98 -0
- package/src/pi/in-process-session.ts +819 -0
- package/src/pi/known-failure.ts +77 -0
- package/src/pi/pi-normalization.ts +284 -0
- package/src/pi/role-turn-host.ts +459 -0
- package/src/public-cli/auto-resume.ts +42 -44
- package/src/public-cli/cli.ts +171 -257
- package/src/public-cli/coder-run.ts +115 -433
- package/src/public-cli/collector-run.ts +62 -314
- package/src/public-cli/config.ts +7 -5
- package/src/public-cli/doctor-run.ts +41 -52
- package/src/public-cli/fixer-run.ts +122 -427
- package/src/public-cli/invocation.ts +287 -96
- package/src/public-cli/judge-run.ts +92 -422
- package/src/public-cli/merger-run.ts +167 -429
- package/src/public-cli/notary-run.ts +41 -47
- package/src/public-cli/option-definitions.ts +136 -3
- package/src/public-cli/post-admission.ts +497 -0
- package/src/public-cli/public-run-credentials.ts +4 -4
- package/src/public-cli/reviewer-dispatch-rejection.ts +106 -0
- package/src/public-cli/reviewer-run.ts +132 -449
- package/src/public-cli/run-lifecycle.ts +339 -327
- package/src/public-cli/settlement.ts +251 -134
- package/src/public-cli/terminal.ts +3 -9
- package/src/public-cli/turn-request.ts +87 -0
- package/src/reviewer-child-executor.ts +9 -1
- package/src/reviewer-role.ts +11 -20
- package/src/role-runtime.ts +129 -78
- package/src/session-opening-materials.ts +25 -39
- package/src/sitian-appender.ts +171 -0
- package/src/sitian-contracts.ts +106 -0
- package/src/sitian-facade.ts +18 -0
- package/src/sitian-reader.ts +62 -0
- package/src/worker-role.ts +42 -40
- package/src/worker-submission-gates.ts +33 -0
- package/dist/archivist-role-run-coordinates.js +0 -28
- package/dist/package-contracts/terminating-infrastructure.js +0 -90
- package/resources/engines/sonnet.md +0 -27
- package/resources/engines/zcode.md +0 -63
- package/src/archivist-role-run-coordinates.ts +0 -45
- package/src/package-contracts/terminating-infrastructure.ts +0 -132
- package/src/public-cli/explicit-internal.ts +0 -427
- package/src/public-cli/one-shot-dispatch.ts +0 -300
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Public Reviewer Role run: admit →
|
|
3
|
-
* activate → settle Terminal result (#111).
|
|
2
|
+
* Public Reviewer Role run: admit → post-admission coordinator → settle Terminal result (#111 / #517).
|
|
4
3
|
* Package-owned adapted code-review method is forced; users never submit
|
|
5
4
|
* extra packets. Controlled-failure settlement reuses #107.
|
|
5
|
+
* #526: execution via RoleTurnHost; argv is Pi adapter internal.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
import type {
|
|
8
|
+
DurablePrincipalAuthority,
|
|
9
|
+
MethodBinding,
|
|
10
|
+
RoleTurnKnownFailure,
|
|
11
|
+
RoleTurnRequest,
|
|
12
|
+
} from "../host-contracts.ts";
|
|
11
13
|
import { engineSessionMaterialFromOptions } from "../package-resources/engine-material.ts";
|
|
12
14
|
import {
|
|
13
15
|
loadPackagedMethodSkillMaterial,
|
|
@@ -15,13 +17,6 @@ import {
|
|
|
15
17
|
type PackagedMethodSkillMaterial,
|
|
16
18
|
type PackagedMethodSkillProvenance,
|
|
17
19
|
} from "../package-resources/method-skill.ts";
|
|
18
|
-
import {
|
|
19
|
-
clearReviewerDispatchRejection,
|
|
20
|
-
runExplicitInternalActivation,
|
|
21
|
-
type ExplicitInternalKnownFailure,
|
|
22
|
-
type ExplicitInternalPiRunner,
|
|
23
|
-
type ExplicitInternalPiResult,
|
|
24
|
-
} from "./explicit-internal.ts";
|
|
25
20
|
import { CliUsageError } from "./cli-errors.ts";
|
|
26
21
|
import {
|
|
27
22
|
admitReviewerInvocation,
|
|
@@ -29,415 +24,94 @@ import {
|
|
|
29
24
|
type AdmittedReviewerInvocation,
|
|
30
25
|
} from "./invocation.ts";
|
|
31
26
|
import {
|
|
32
|
-
buildSeatModelCliArgs,
|
|
33
|
-
type CredentialProviders,
|
|
34
|
-
type SeatModelConfig,
|
|
35
|
-
} from "./config.ts";
|
|
36
|
-
import {
|
|
37
|
-
missingCredentialPreDispatchFailure,
|
|
38
|
-
postRunMissingCredentialFailure,
|
|
39
|
-
} from "./public-run-credentials.ts";
|
|
40
|
-
import {
|
|
41
|
-
acquireRunWriterLease,
|
|
42
|
-
clearTypedProviderHttpObservation,
|
|
43
|
-
isSessionPrincipalAvailable,
|
|
44
|
-
isV1ResumableFailure,
|
|
45
27
|
loadResumableReviewerRun,
|
|
46
28
|
markRunAdmitted,
|
|
47
|
-
markRunResumable,
|
|
48
|
-
markRunRunning,
|
|
49
|
-
markRunTerminal,
|
|
50
|
-
renderResumeCommand,
|
|
51
|
-
type PublicResumeRequest,
|
|
52
29
|
selectResumeContinuationPrompt,
|
|
53
|
-
|
|
54
|
-
type RunWriterLease,
|
|
55
|
-
type TypedProviderHttpObservation,
|
|
30
|
+
type PublicResumeRequest,
|
|
56
31
|
} from "./run-lifecycle.ts";
|
|
57
|
-
import {
|
|
32
|
+
import { clearReviewerDispatchRejection } from "./reviewer-dispatch-rejection.ts";
|
|
58
33
|
import {
|
|
59
|
-
classifyPostAdmissionFailure,
|
|
60
|
-
exitCodeForTerminalOutcome,
|
|
61
|
-
formatCliDiagnostic,
|
|
62
|
-
formatTerminalResult,
|
|
63
34
|
hasLawfulReviewerTerminalResult,
|
|
64
|
-
inspectJudgeSession,
|
|
65
|
-
isLawfulTypedTerminalOutcome,
|
|
66
|
-
presentFailureTerminal,
|
|
67
35
|
presentStructuralRejection,
|
|
68
|
-
resolveAuditedRunnerFailureResolution,
|
|
69
|
-
resolveControlledFailureResumeObservation,
|
|
70
|
-
controlledFailureInputFromResolution,
|
|
71
|
-
explicitInternalKnownFailureClassificationInput,
|
|
72
36
|
readEngineDetourInfrastructureFailure,
|
|
73
|
-
settleFailureTerminalResult,
|
|
74
37
|
trySettleReviewerTerminalResult,
|
|
75
38
|
} from "./settlement.ts";
|
|
76
39
|
import type { CliIo } from "./cli-io.ts";
|
|
77
|
-
import type {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
40
|
+
import type { TerminalResult } from "./terminal.ts";
|
|
41
|
+
import {
|
|
42
|
+
projectRoleTurnRequest,
|
|
43
|
+
type RoleTurnRequestProjectionOptions,
|
|
44
|
+
} from "./turn-request.ts";
|
|
45
|
+
import {
|
|
46
|
+
presentControlledFailure,
|
|
47
|
+
runPostAdmissionManualResume,
|
|
48
|
+
runPostAdmissionResumable,
|
|
49
|
+
type PostAdmissionAdapters,
|
|
50
|
+
type PostAdmissionEnv,
|
|
51
|
+
} from "./post-admission.ts";
|
|
81
52
|
|
|
82
|
-
export type ReviewerRunEnv = {
|
|
83
|
-
home: string;
|
|
84
|
-
agentDir: string;
|
|
85
|
-
packageRoot: string;
|
|
86
|
-
cwd: string;
|
|
87
|
-
correlationId?: string;
|
|
88
|
-
piRunner?: ExplicitInternalPiRunner;
|
|
89
|
-
model?: SeatModelConfig;
|
|
90
|
-
/** Optional labor engine name (config→activation; session material + leg channel). */
|
|
91
|
-
engine?: string;
|
|
92
|
-
credentials?: CredentialProviders;
|
|
53
|
+
export type ReviewerRunEnv = PostAdmissionEnv & {
|
|
93
54
|
createRunId?: () => string;
|
|
94
|
-
/** #422: effective single-call auto-resume ceiling; undefined = package default (AUTO_RESUME_LIMIT). */
|
|
95
|
-
autoResumeLimit?: number;
|
|
96
|
-
extraPiArgs?: readonly string[];
|
|
97
|
-
timeoutMs?: number;
|
|
98
55
|
};
|
|
99
56
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
function buildReviewerTicketNumberArgs(
|
|
103
|
-
ticketNumber: number | undefined,
|
|
104
|
-
): string[] {
|
|
105
|
-
return ticketNumber === undefined
|
|
106
|
-
? []
|
|
107
|
-
: ["--ak-review-ticket-number", String(ticketNumber)];
|
|
57
|
+
function reviewerMethods(packageRoot: string): readonly MethodBinding[] {
|
|
58
|
+
return [{ kind: "skill", path: resolvePackagedMethodSkillPath(packageRoot, "code-review") }];
|
|
108
59
|
}
|
|
109
60
|
|
|
110
|
-
/**
|
|
111
|
-
|
|
112
|
-
* Package code-review Skill is forced via --skill; ambient home skills stay off.
|
|
113
|
-
* Capabilities path is adapter-derived at admission — never a caller packet.
|
|
114
|
-
*/
|
|
115
|
-
export function buildReviewerActivationExtraArgs(
|
|
61
|
+
/** Project admitted Reviewer invocation onto the host-neutral turn request. */
|
|
62
|
+
export function buildReviewerTurnRequest(
|
|
116
63
|
admitted: AdmittedReviewerInvocation,
|
|
117
|
-
options:
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
engine?: string;
|
|
121
|
-
extraPiArgs?: readonly string[];
|
|
122
|
-
},
|
|
123
|
-
): string[] {
|
|
124
|
-
const prompt = buildReviewerTransportPrompt(
|
|
64
|
+
options: RoleTurnRequestProjectionOptions,
|
|
65
|
+
): RoleTurnRequest {
|
|
66
|
+
return projectRoleTurnRequest(
|
|
125
67
|
admitted,
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const ticketNumberArgs = buildReviewerTicketNumberArgs(admitted.ticketNumber);
|
|
137
|
-
return [
|
|
138
|
-
"--no-skills",
|
|
139
|
-
"--skill",
|
|
140
|
-
skillPath,
|
|
141
|
-
"--no-prompt-templates",
|
|
142
|
-
"--no-themes",
|
|
143
|
-
"--no-context-files",
|
|
144
|
-
"--session",
|
|
145
|
-
admitted.sessionFile,
|
|
146
|
-
"--session-dir",
|
|
147
|
-
admitted.sessionDirectory,
|
|
148
|
-
...(options.extraPiArgs ?? []),
|
|
149
|
-
"--ak-role",
|
|
150
|
-
"reviewer",
|
|
151
|
-
"--ak-review-base",
|
|
152
|
-
admitted.baseRevision,
|
|
153
|
-
...authorityRefArgs,
|
|
154
|
-
...ticketNumberArgs,
|
|
155
|
-
"--mode",
|
|
156
|
-
"json",
|
|
157
|
-
...buildSeatModelCliArgs(options.model),
|
|
158
|
-
prompt,
|
|
159
|
-
];
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Reopen the exact Reviewer Pi session for resume. Preserves fixed Reviewer base
|
|
164
|
-
* and package code-review binding; never resubmits caller instruction as control.
|
|
165
|
-
*/
|
|
166
|
-
export function buildReviewerResumeActivationExtraArgs(
|
|
167
|
-
admitted: AdmittedReviewerInvocation,
|
|
168
|
-
options: {
|
|
169
|
-
packageRoot: string;
|
|
170
|
-
model?: SeatModelConfig;
|
|
171
|
-
extraPiArgs?: readonly string[];
|
|
172
|
-
message?: string;
|
|
173
|
-
},
|
|
174
|
-
): string[] {
|
|
175
|
-
const skillPath = resolvePackagedMethodSkillPath(
|
|
176
|
-
options.packageRoot,
|
|
177
|
-
"code-review",
|
|
68
|
+
{
|
|
69
|
+
activation: {
|
|
70
|
+
role: "reviewer",
|
|
71
|
+
baseRevision: admitted.baseRevision,
|
|
72
|
+
authorityRefs: admitted.authorityRefs,
|
|
73
|
+
...(admitted.ticketNumber === undefined ? {} : { ticketNumber: admitted.ticketNumber }),
|
|
74
|
+
},
|
|
75
|
+
methods: reviewerMethods(options.packageRoot),
|
|
76
|
+
},
|
|
77
|
+
options,
|
|
178
78
|
);
|
|
179
|
-
const authorityRefArgs =
|
|
180
|
-
admitted.authorityRefs.length === 0
|
|
181
|
-
? []
|
|
182
|
-
: ["--ak-review-authority-refs", JSON.stringify([...admitted.authorityRefs])];
|
|
183
|
-
const ticketNumberArgs = buildReviewerTicketNumberArgs(admitted.ticketNumber);
|
|
184
|
-
return [
|
|
185
|
-
"--no-skills",
|
|
186
|
-
"--skill",
|
|
187
|
-
skillPath,
|
|
188
|
-
"--no-prompt-templates",
|
|
189
|
-
"--no-themes",
|
|
190
|
-
"--no-context-files",
|
|
191
|
-
"--session",
|
|
192
|
-
admitted.sessionFile,
|
|
193
|
-
"--session-dir",
|
|
194
|
-
admitted.sessionDirectory,
|
|
195
|
-
...(options.extraPiArgs ?? []),
|
|
196
|
-
"--ak-role",
|
|
197
|
-
"reviewer",
|
|
198
|
-
"--ak-review-base",
|
|
199
|
-
admitted.baseRevision,
|
|
200
|
-
...authorityRefArgs,
|
|
201
|
-
...ticketNumberArgs,
|
|
202
|
-
"--mode",
|
|
203
|
-
"json",
|
|
204
|
-
...buildSeatModelCliArgs(options.model),
|
|
205
|
-
selectResumeContinuationPrompt(options.message),
|
|
206
|
-
];
|
|
207
79
|
}
|
|
208
80
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
code: number | null;
|
|
214
|
-
stderr: string;
|
|
215
|
-
thrown?: unknown;
|
|
216
|
-
knownFailure?: ExplicitInternalKnownFailure;
|
|
217
|
-
typedHttpObservationSettled?: true;
|
|
218
|
-
typedHttpObservation?: TypedProviderHttpObservation;
|
|
219
|
-
},
|
|
220
|
-
io: CliIo,
|
|
221
|
-
): Promise<{
|
|
222
|
-
exitCode: number;
|
|
223
|
-
admitted: AdmittedReviewerInvocation;
|
|
224
|
-
terminal: TerminalResult;
|
|
225
|
-
}> {
|
|
226
|
-
const hasThrown = Object.hasOwn(failureInput, "thrown");
|
|
227
|
-
const resumeObservation = await resolveControlledFailureResumeObservation({
|
|
228
|
-
runDirectory: admitted.runDirectory,
|
|
229
|
-
...(failureInput.typedHttpObservationSettled === true
|
|
230
|
-
? {
|
|
231
|
-
typedHttpObservationSettled: true as const,
|
|
232
|
-
...(failureInput.typedHttpObservation === undefined
|
|
233
|
-
? {}
|
|
234
|
-
: { typedHttpObservation: failureInput.typedHttpObservation }),
|
|
235
|
-
}
|
|
236
|
-
: {}),
|
|
237
|
-
});
|
|
238
|
-
const knownFailure =
|
|
239
|
-
failureInput.knownFailure ?? resumeObservation.observationReadFailure;
|
|
240
|
-
const session =
|
|
241
|
-
!hasThrown &&
|
|
242
|
-
!failureInput.timedOut &&
|
|
243
|
-
knownFailure === undefined
|
|
244
|
-
? await inspectJudgeSession(admitted.sessionFile)
|
|
245
|
-
: undefined;
|
|
246
|
-
const failure = classifyPostAdmissionFailure({
|
|
247
|
-
timedOut: failureInput.timedOut,
|
|
248
|
-
code: failureInput.code,
|
|
249
|
-
stderr: failureInput.stderr,
|
|
250
|
-
...(hasThrown ? { thrown: failureInput.thrown } : {}),
|
|
251
|
-
...explicitInternalKnownFailureClassificationInput(knownFailure),
|
|
252
|
-
...(session === undefined ? {} : { session }),
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
const hasLawfulTerminalResult = await hasLawfulReviewerTerminalResult(admitted);
|
|
256
|
-
const typedHttp429 = resumeObservation.typedHttp429;
|
|
257
|
-
const sessionPrincipalAvailable = await isSessionPrincipalAvailable(
|
|
258
|
-
admitted.sessionFile,
|
|
259
|
-
);
|
|
260
|
-
const resumable =
|
|
261
|
-
sessionPrincipalAvailable &&
|
|
262
|
-
isV1ResumableFailure({
|
|
263
|
-
hasLawfulTerminalResult,
|
|
264
|
-
...(typedHttp429 === undefined ? {} : { typedHttp429 }),
|
|
265
|
-
});
|
|
266
|
-
if (resumable && typedHttp429 !== undefined) {
|
|
267
|
-
await markRunResumable(admitted.runDirectory, typedHttp429);
|
|
268
|
-
} else {
|
|
269
|
-
await markRunTerminal(admitted.runDirectory).catch(() => undefined);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
const terminal = await settleFailureTerminalResult(
|
|
273
|
-
admitted,
|
|
274
|
-
failure,
|
|
275
|
-
resumable
|
|
276
|
-
? { resume: { command: renderResumeCommand(admitted.runId) } }
|
|
277
|
-
: {},
|
|
278
|
-
);
|
|
279
|
-
presentFailureTerminal(terminal, io);
|
|
81
|
+
function reviewerAdapters(
|
|
82
|
+
packageRoot: string,
|
|
83
|
+
methodMaterial?: PackagedMethodSkillMaterial,
|
|
84
|
+
): PostAdmissionAdapters<AdmittedReviewerInvocation> {
|
|
280
85
|
return {
|
|
281
|
-
|
|
282
|
-
admitted,
|
|
283
|
-
|
|
86
|
+
beforeDispatch: (admitted) => clearReviewerDispatchRejection(admitted.runDirectory),
|
|
87
|
+
trySettle: (admitted, authority) =>
|
|
88
|
+
methodMaterial === undefined
|
|
89
|
+
? Promise.resolve(undefined)
|
|
90
|
+
: trySettleReviewerTerminalResult(admitted, authority, {
|
|
91
|
+
methodProvenance: methodMaterial.provenance,
|
|
92
|
+
methodSkillPath: methodMaterial.skillPath,
|
|
93
|
+
methodSkillConfiguredPath: resolvePackagedMethodSkillPath(
|
|
94
|
+
packageRoot,
|
|
95
|
+
"code-review",
|
|
96
|
+
),
|
|
97
|
+
}),
|
|
98
|
+
hasLawfulTerminalResult: (admitted, authority) => hasLawfulReviewerTerminalResult(admitted, authority),
|
|
99
|
+
isResumableRole: true,
|
|
100
|
+
resolveRunnerKnownFailure: async ({ result, sessionFile }) => {
|
|
101
|
+
const infrastructureFailure = await readEngineDetourInfrastructureFailure(sessionFile);
|
|
102
|
+
return infrastructureFailure === undefined
|
|
103
|
+
? result.knownFailure
|
|
104
|
+
: {
|
|
105
|
+
cause: infrastructureFailure.cause,
|
|
106
|
+
diagnostic: infrastructureFailure.diagnostic,
|
|
107
|
+
...(infrastructureFailure.identity === undefined
|
|
108
|
+
? {}
|
|
109
|
+
: { identity: infrastructureFailure.identity }),
|
|
110
|
+
};
|
|
111
|
+
},
|
|
284
112
|
};
|
|
285
113
|
}
|
|
286
114
|
|
|
287
|
-
async function dispatchAdmittedReviewer(input: {
|
|
288
|
-
admitted: AdmittedReviewerInvocation;
|
|
289
|
-
env: ReviewerRunEnv;
|
|
290
|
-
io: CliIo;
|
|
291
|
-
extraArgs: string[];
|
|
292
|
-
lease: RunWriterLease;
|
|
293
|
-
methodMaterial: PackagedMethodSkillMaterial;
|
|
294
|
-
/**
|
|
295
|
-
* Mechanical engine provenance for initial Reviewer dispatch only.
|
|
296
|
-
* Explicit — never read from env.engine here, so resume cannot rewrite it.
|
|
297
|
-
*/
|
|
298
|
-
effectiveEngine?: string;
|
|
299
|
-
}): Promise<{
|
|
300
|
-
exitCode: number;
|
|
301
|
-
admitted: AdmittedReviewerInvocation;
|
|
302
|
-
terminal?: TerminalResult;
|
|
303
|
-
}> {
|
|
304
|
-
const { admitted, env, io, extraArgs, lease, methodMaterial, effectiveEngine } = input;
|
|
305
|
-
try {
|
|
306
|
-
const missingCredential = missingCredentialPreDispatchFailure(
|
|
307
|
-
env.model,
|
|
308
|
-
env.credentials,
|
|
309
|
-
);
|
|
310
|
-
if (missingCredential !== undefined) {
|
|
311
|
-
return await presentControlledFailure(
|
|
312
|
-
admitted,
|
|
313
|
-
missingCredential,
|
|
314
|
-
io,
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
|
-
await markRunRunning(admitted.runDirectory, env.model, effectiveEngine);
|
|
318
|
-
await clearTypedProviderHttpObservation(admitted.runDirectory);
|
|
319
|
-
await clearReviewerDispatchRejection(admitted.runDirectory);
|
|
320
|
-
|
|
321
|
-
const childEnv: NodeJS.ProcessEnv = {
|
|
322
|
-
...process.env,
|
|
323
|
-
HOME: env.home,
|
|
324
|
-
PI_CODING_AGENT_DIR: env.agentDir,
|
|
325
|
-
AK_ROLE_RUN_DIR: admitted.runDirectory,
|
|
326
|
-
};
|
|
327
|
-
applyEngineChildEnv(childEnv, env.engine);
|
|
328
|
-
const correlationId = admitted.correlationId ?? env.correlationId;
|
|
329
|
-
if (correlationId !== undefined && correlationId.trim() !== "") {
|
|
330
|
-
childEnv.AK_CORRELATION_ID = correlationId;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
let result: ExplicitInternalPiResult;
|
|
334
|
-
try {
|
|
335
|
-
result = await runExplicitInternalActivation({
|
|
336
|
-
packageRoot: env.packageRoot,
|
|
337
|
-
extraArgs,
|
|
338
|
-
cwd: admitted.projectRoot,
|
|
339
|
-
home: env.home,
|
|
340
|
-
agentDir: env.agentDir,
|
|
341
|
-
env: childEnv,
|
|
342
|
-
timeoutMs: env.timeoutMs,
|
|
343
|
-
...(env.piRunner === undefined ? {} : { runner: env.piRunner }),
|
|
344
|
-
});
|
|
345
|
-
} catch (error) {
|
|
346
|
-
return await presentControlledFailure(
|
|
347
|
-
admitted,
|
|
348
|
-
{
|
|
349
|
-
timedOut: false,
|
|
350
|
-
code: null,
|
|
351
|
-
stderr: "",
|
|
352
|
-
thrown: error,
|
|
353
|
-
},
|
|
354
|
-
io,
|
|
355
|
-
);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
try {
|
|
359
|
-
await writeFile(
|
|
360
|
-
join(admitted.runDirectory, "stderr.log"),
|
|
361
|
-
result.stderr,
|
|
362
|
-
"utf8",
|
|
363
|
-
);
|
|
364
|
-
} catch {
|
|
365
|
-
// continue to lawful / controlled-failure settlement
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
let lawful: TerminalResult | undefined;
|
|
369
|
-
try {
|
|
370
|
-
lawful = await trySettleReviewerTerminalResult(admitted, {
|
|
371
|
-
methodProvenance: methodMaterial.provenance,
|
|
372
|
-
methodSkillPath: methodMaterial.skillPath,
|
|
373
|
-
methodSkillConfiguredPath: resolvePackagedMethodSkillPath(
|
|
374
|
-
env.packageRoot,
|
|
375
|
-
"code-review",
|
|
376
|
-
),
|
|
377
|
-
});
|
|
378
|
-
} catch (error) {
|
|
379
|
-
return await presentControlledFailure(
|
|
380
|
-
admitted,
|
|
381
|
-
{
|
|
382
|
-
timedOut: false,
|
|
383
|
-
code: result.code,
|
|
384
|
-
stderr: result.stderr,
|
|
385
|
-
thrown: error,
|
|
386
|
-
},
|
|
387
|
-
io,
|
|
388
|
-
);
|
|
389
|
-
}
|
|
390
|
-
if (lawful !== undefined && isLawfulTypedTerminalOutcome(lawful.roleOutcome)) {
|
|
391
|
-
await markRunTerminal(admitted.runDirectory).catch(() => undefined);
|
|
392
|
-
io.stdout(formatTerminalResult(lawful));
|
|
393
|
-
return {
|
|
394
|
-
exitCode: exitCodeForTerminalOutcome(lawful.roleOutcome),
|
|
395
|
-
admitted,
|
|
396
|
-
terminal: lawful,
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
// Prefer engine-detour infrastructure failure already on the session principal
|
|
402
|
-
// over a later secondary knownFailure / provider-stop after abort (#357 T2 / #378).
|
|
403
|
-
const infrastructureFailure = await readEngineDetourInfrastructureFailure(
|
|
404
|
-
admitted.sessionFile,
|
|
405
|
-
);
|
|
406
|
-
const credentialFailure = postRunMissingCredentialFailure(
|
|
407
|
-
result,
|
|
408
|
-
env.model,
|
|
409
|
-
env.credentials,
|
|
410
|
-
);
|
|
411
|
-
const resolution = await resolveAuditedRunnerFailureResolution({
|
|
412
|
-
runner:
|
|
413
|
-
infrastructureFailure === undefined
|
|
414
|
-
? result.knownFailure
|
|
415
|
-
: {
|
|
416
|
-
cause: infrastructureFailure.cause,
|
|
417
|
-
diagnostic: infrastructureFailure.diagnostic,
|
|
418
|
-
...(infrastructureFailure.identity === undefined
|
|
419
|
-
? {}
|
|
420
|
-
: { identity: infrastructureFailure.identity }),
|
|
421
|
-
},
|
|
422
|
-
sessionFile: admitted.sessionFile,
|
|
423
|
-
credential: credentialFailure,
|
|
424
|
-
runDirectory: admitted.runDirectory,
|
|
425
|
-
});
|
|
426
|
-
return await presentControlledFailure(
|
|
427
|
-
admitted,
|
|
428
|
-
{
|
|
429
|
-
timedOut: result.timedOut,
|
|
430
|
-
code: result.code,
|
|
431
|
-
stderr: result.stderr,
|
|
432
|
-
...controlledFailureInputFromResolution(resolution),
|
|
433
|
-
},
|
|
434
|
-
io,
|
|
435
|
-
);
|
|
436
|
-
} finally {
|
|
437
|
-
await lease.release();
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
|
|
441
115
|
async function loadReviewerMethodMaterial(
|
|
442
116
|
packageRoot: string,
|
|
443
117
|
): Promise<PackagedMethodSkillMaterial> {
|
|
@@ -465,6 +139,7 @@ export async function runPublicReviewer(
|
|
|
465
139
|
const parsed = parseReviewerArgv(argv);
|
|
466
140
|
admitted = await admitReviewerInvocation({
|
|
467
141
|
home: env.home,
|
|
142
|
+
principalAuthority: env.principalAuthority,
|
|
468
143
|
cwd: env.cwd,
|
|
469
144
|
instruction: parsed.instruction,
|
|
470
145
|
attachmentPaths: parsed.attachmentPaths,
|
|
@@ -482,13 +157,13 @@ export async function runPublicReviewer(
|
|
|
482
157
|
throw error;
|
|
483
158
|
}
|
|
484
159
|
|
|
485
|
-
await markRunAdmitted(admitted);
|
|
160
|
+
await markRunAdmitted(admitted, env.principalAuthority);
|
|
486
161
|
|
|
487
162
|
let methodMaterial: PackagedMethodSkillMaterial;
|
|
488
163
|
try {
|
|
489
164
|
methodMaterial = await loadReviewerMethodMaterial(env.packageRoot);
|
|
490
165
|
} catch (error) {
|
|
491
|
-
return await presentControlledFailure(
|
|
166
|
+
return (await presentControlledFailure(
|
|
492
167
|
admitted,
|
|
493
168
|
{
|
|
494
169
|
timedOut: false,
|
|
@@ -496,41 +171,56 @@ export async function runPublicReviewer(
|
|
|
496
171
|
stderr: "",
|
|
497
172
|
thrown: error,
|
|
498
173
|
},
|
|
174
|
+
reviewerAdapters(env.packageRoot),
|
|
175
|
+
env.principalAuthority,
|
|
499
176
|
io,
|
|
500
|
-
);
|
|
177
|
+
)) as { exitCode: number; admitted: AdmittedReviewerInvocation; terminal: TerminalResult };
|
|
501
178
|
}
|
|
502
179
|
|
|
503
|
-
return
|
|
180
|
+
return await runPostAdmissionResumable({
|
|
504
181
|
admitted,
|
|
182
|
+
env,
|
|
505
183
|
io,
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
buildInitialArgs: () =>
|
|
509
|
-
buildReviewerActivationExtraArgs(admitted, {
|
|
184
|
+
buildInitialRequest: () =>
|
|
185
|
+
buildReviewerTurnRequest(admitted, {
|
|
510
186
|
packageRoot: env.packageRoot,
|
|
187
|
+
home: env.home,
|
|
188
|
+
agentDir: env.agentDir,
|
|
511
189
|
...(env.model === undefined ? {} : { model: env.model }),
|
|
512
190
|
...(env.engine === undefined ? {} : { engine: env.engine }),
|
|
513
|
-
...(env.
|
|
191
|
+
...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
|
|
192
|
+
...(admitted.correlationId === undefined && env.correlationId === undefined
|
|
193
|
+
? {}
|
|
194
|
+
: { correlationId: admitted.correlationId ?? env.correlationId }),
|
|
195
|
+
continuation: {
|
|
196
|
+
kind: "initial",
|
|
197
|
+
prompt: buildReviewerTransportPrompt(
|
|
198
|
+
admitted,
|
|
199
|
+
engineSessionMaterialFromOptions({
|
|
200
|
+
...(env.engine === undefined ? {} : { engine: env.engine }),
|
|
201
|
+
packageRoot: env.packageRoot,
|
|
202
|
+
}),
|
|
203
|
+
),
|
|
204
|
+
},
|
|
514
205
|
}),
|
|
515
|
-
|
|
516
|
-
|
|
206
|
+
buildResumeRequest: () =>
|
|
207
|
+
buildReviewerTurnRequest(admitted, {
|
|
517
208
|
packageRoot: env.packageRoot,
|
|
209
|
+
home: env.home,
|
|
210
|
+
agentDir: env.agentDir,
|
|
518
211
|
...(env.model === undefined ? {} : { model: env.model }),
|
|
519
|
-
...(env.
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
212
|
+
...(env.engine === undefined ? {} : { engine: env.engine }),
|
|
213
|
+
...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
|
|
214
|
+
...(admitted.correlationId === undefined && env.correlationId === undefined
|
|
215
|
+
? {}
|
|
216
|
+
: { correlationId: admitted.correlationId ?? env.correlationId }),
|
|
217
|
+
continuation: {
|
|
218
|
+
kind: "resume",
|
|
219
|
+
prompt: selectResumeContinuationPrompt(),
|
|
527
220
|
},
|
|
528
|
-
io: attemptIo,
|
|
529
|
-
extraArgs,
|
|
530
|
-
lease,
|
|
531
|
-
methodMaterial,
|
|
532
|
-
...(isFirst && env.engine !== undefined ? { effectiveEngine: env.engine } : {}),
|
|
533
221
|
}),
|
|
222
|
+
adapters: reviewerAdapters(env.packageRoot, methodMaterial),
|
|
223
|
+
...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
|
|
534
224
|
});
|
|
535
225
|
}
|
|
536
226
|
|
|
@@ -549,7 +239,7 @@ export async function runPublicReviewerResume(
|
|
|
549
239
|
}> {
|
|
550
240
|
let loaded;
|
|
551
241
|
try {
|
|
552
|
-
loaded = await loadResumableReviewerRun(env.home, request.runId);
|
|
242
|
+
loaded = await loadResumableReviewerRun(env.home, request.runId, env.principalAuthority);
|
|
553
243
|
} catch (error) {
|
|
554
244
|
if (error instanceof CliUsageError) {
|
|
555
245
|
presentStructuralRejection(error, io);
|
|
@@ -560,23 +250,11 @@ export async function runPublicReviewerResume(
|
|
|
560
250
|
|
|
561
251
|
const { admitted } = loaded;
|
|
562
252
|
|
|
563
|
-
let lease: RunWriterLease;
|
|
564
|
-
try {
|
|
565
|
-
lease = await acquireRunWriterLease(admitted.runDirectory, (diagnostic) => io.stderr(diagnostic));
|
|
566
|
-
} catch (error) {
|
|
567
|
-
if (error instanceof RunWriterLeaseHeldError) {
|
|
568
|
-
io.stderr(formatCliDiagnostic(error.message));
|
|
569
|
-
return { exitCode: 1 };
|
|
570
|
-
}
|
|
571
|
-
throw error;
|
|
572
|
-
}
|
|
573
|
-
|
|
574
253
|
let methodMaterial: PackagedMethodSkillMaterial;
|
|
575
254
|
try {
|
|
576
255
|
methodMaterial = await loadReviewerMethodMaterial(env.packageRoot);
|
|
577
256
|
} catch (error) {
|
|
578
|
-
await
|
|
579
|
-
return await presentControlledFailure(
|
|
257
|
+
return (await presentControlledFailure(
|
|
580
258
|
admitted,
|
|
581
259
|
{
|
|
582
260
|
timedOut: false,
|
|
@@ -584,30 +262,35 @@ export async function runPublicReviewerResume(
|
|
|
584
262
|
stderr: "",
|
|
585
263
|
thrown: error,
|
|
586
264
|
},
|
|
265
|
+
reviewerAdapters(env.packageRoot),
|
|
266
|
+
env.principalAuthority,
|
|
587
267
|
io,
|
|
588
|
-
);
|
|
268
|
+
)) as { exitCode: number; admitted: AdmittedReviewerInvocation; terminal: TerminalResult };
|
|
589
269
|
}
|
|
590
270
|
|
|
591
|
-
const
|
|
271
|
+
const turnRequest = buildReviewerTurnRequest(admitted, {
|
|
592
272
|
packageRoot: env.packageRoot,
|
|
273
|
+
home: env.home,
|
|
274
|
+
agentDir: env.agentDir,
|
|
593
275
|
...(env.model === undefined ? {} : { model: env.model }),
|
|
594
|
-
...(env.
|
|
595
|
-
...(
|
|
276
|
+
...(env.engine === undefined ? {} : { engine: env.engine }),
|
|
277
|
+
...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
|
|
278
|
+
...(admitted.correlationId === undefined && env.correlationId === undefined
|
|
279
|
+
? {}
|
|
280
|
+
: { correlationId: admitted.correlationId ?? env.correlationId }),
|
|
281
|
+
continuation: {
|
|
282
|
+
kind: "resume",
|
|
283
|
+
prompt: selectResumeContinuationPrompt(request.message),
|
|
284
|
+
},
|
|
596
285
|
});
|
|
597
286
|
|
|
598
|
-
|
|
287
|
+
return await runPostAdmissionManualResume({
|
|
599
288
|
admitted,
|
|
600
|
-
env
|
|
601
|
-
...env,
|
|
602
|
-
...(admitted.correlationId === undefined ? {} : { correlationId: admitted.correlationId }),
|
|
603
|
-
},
|
|
289
|
+
env,
|
|
604
290
|
io,
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
methodMaterial,
|
|
291
|
+
request: turnRequest,
|
|
292
|
+
adapters: reviewerAdapters(env.packageRoot, methodMaterial),
|
|
608
293
|
});
|
|
609
|
-
if (result.terminal !== undefined) (result.terminal as { autoResumeCount?: number }).autoResumeCount = 0;
|
|
610
|
-
return result;
|
|
611
294
|
}
|
|
612
295
|
|
|
613
|
-
export type {
|
|
296
|
+
export type { RoleTurnKnownFailure, PackagedMethodSkillProvenance };
|