@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,19 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Public Judge Role run: admit →
|
|
2
|
+
* Public Judge Role run: admit → post-admission coordinator → settle Terminal result (#106 / #517).
|
|
3
3
|
* #107: controlled post-admission failures and human decisions settle honestly.
|
|
4
4
|
* #108: typed HTTP 429 resume of the exact Pi session.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
import type {
|
|
7
|
+
DurablePrincipalAuthority,
|
|
8
|
+
RoleTurnKnownFailure,
|
|
9
|
+
RoleTurnRequest,
|
|
10
|
+
} from "../host-contracts.ts";
|
|
10
11
|
import { engineSessionMaterialFromOptions } from "../package-resources/engine-material.ts";
|
|
11
|
-
import {
|
|
12
|
-
runExplicitInternalActivation,
|
|
13
|
-
type ExplicitInternalKnownFailure,
|
|
14
|
-
type ExplicitInternalPiRunner,
|
|
15
|
-
type ExplicitInternalPiResult,
|
|
16
|
-
} from "./explicit-internal.ts";
|
|
17
12
|
import { CliUsageError } from "./cli-errors.ts";
|
|
18
13
|
import {
|
|
19
14
|
admitJudgeInvocation,
|
|
@@ -21,367 +16,50 @@ import {
|
|
|
21
16
|
type AdmittedJudgeInvocation,
|
|
22
17
|
} from "./invocation.ts";
|
|
23
18
|
import {
|
|
24
|
-
buildSeatModelCliArgs,
|
|
25
|
-
type CredentialProviders,
|
|
26
|
-
type SeatModelConfig,
|
|
27
|
-
} from "./config.ts";
|
|
28
|
-
import {
|
|
29
|
-
missingCredentialPreDispatchFailure,
|
|
30
|
-
postRunMissingCredentialFailure,
|
|
31
|
-
} from "./public-run-credentials.ts";
|
|
32
|
-
import {
|
|
33
|
-
acquireRunWriterLease,
|
|
34
|
-
clearTypedProviderHttpObservation,
|
|
35
|
-
isSessionPrincipalAvailable,
|
|
36
|
-
isV1ResumableFailure,
|
|
37
19
|
loadResumableJudgeRun,
|
|
38
20
|
markRunAdmitted,
|
|
39
|
-
markRunResumable,
|
|
40
|
-
markRunRunning,
|
|
41
|
-
markRunTerminal,
|
|
42
|
-
renderResumeCommand,
|
|
43
|
-
type TypedProviderHttpObservation,
|
|
44
|
-
type PublicResumeRequest,
|
|
45
21
|
selectResumeContinuationPrompt,
|
|
46
|
-
|
|
47
|
-
type RunWriterLease,
|
|
22
|
+
type PublicResumeRequest,
|
|
48
23
|
} from "./run-lifecycle.ts";
|
|
49
|
-
import { runWithAutoResumeLoop } from "./auto-resume.ts";
|
|
50
24
|
import {
|
|
51
|
-
classifyPostAdmissionFailure,
|
|
52
|
-
exitCodeForTerminalOutcome,
|
|
53
|
-
formatCliDiagnostic,
|
|
54
|
-
formatTerminalResult,
|
|
55
25
|
hasLawfulJudgeTerminalResult,
|
|
56
|
-
inspectJudgeSession,
|
|
57
|
-
isLawfulTypedTerminalOutcome,
|
|
58
|
-
presentFailureTerminal,
|
|
59
26
|
presentStructuralRejection,
|
|
60
|
-
resolveAuditedRunnerFailureResolution,
|
|
61
|
-
resolveControlledFailureResumeObservation,
|
|
62
|
-
controlledFailureInputFromResolution,
|
|
63
|
-
explicitInternalKnownFailureClassificationInput,
|
|
64
27
|
readEngineDetourInfrastructureFailure,
|
|
65
|
-
settleJudgeFailureTerminalResult,
|
|
66
28
|
trySettleJudgeTerminalResult,
|
|
67
29
|
} from "./settlement.ts";
|
|
68
30
|
import type { CliIo } from "./cli-io.ts";
|
|
69
|
-
import type {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
31
|
+
import type { TerminalResult } from "./terminal.ts";
|
|
32
|
+
import {
|
|
33
|
+
projectRoleTurnRequest,
|
|
34
|
+
type RoleTurnRequestProjectionOptions,
|
|
35
|
+
} from "./turn-request.ts";
|
|
36
|
+
import {
|
|
37
|
+
runPostAdmissionManualResume,
|
|
38
|
+
runPostAdmissionResumable,
|
|
39
|
+
type PostAdmissionAdapters,
|
|
40
|
+
type PostAdmissionEnv,
|
|
41
|
+
} from "./post-admission.ts";
|
|
73
42
|
|
|
74
|
-
export type JudgeRunEnv = {
|
|
75
|
-
home: string;
|
|
76
|
-
agentDir: string;
|
|
77
|
-
packageRoot: string;
|
|
78
|
-
cwd: string;
|
|
79
|
-
correlationId?: string;
|
|
80
|
-
piRunner?: ExplicitInternalPiRunner;
|
|
81
|
-
/** Effective judge seat model (persistent/startup/invocation). */
|
|
82
|
-
model?: SeatModelConfig;
|
|
83
|
-
/** Optional labor engine name (config→activation; session material only). */
|
|
84
|
-
engine?: string;
|
|
85
|
-
/**
|
|
86
|
-
* Credential presence for public providers (auth.json shape).
|
|
87
|
-
* Used as the production-owned typed channel when a selected public provider
|
|
88
|
-
* has no configured credential — never inferred from child stderr prose.
|
|
89
|
-
*/
|
|
90
|
-
credentials?: CredentialProviders;
|
|
43
|
+
export type JudgeRunEnv = PostAdmissionEnv & {
|
|
91
44
|
createRunId?: () => string;
|
|
92
|
-
/** #422: effective single-call auto-resume ceiling; undefined = package default (AUTO_RESUME_LIMIT). */
|
|
93
|
-
autoResumeLimit?: number;
|
|
94
|
-
/** Extra Pi args inserted before the prompt (tests: faux provider extension). */
|
|
95
|
-
extraPiArgs?: readonly string[];
|
|
96
|
-
/** Override default role-run timeout. */
|
|
97
|
-
timeoutMs?: number;
|
|
98
45
|
};
|
|
99
46
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Build Internal activation extra-args for an admitted Judge run
|
|
104
|
-
* (everything after `--no-extensions -e <entrypoint>`).
|
|
105
|
-
* No public burden selector. Session placed under the #78 ledger book.
|
|
106
|
-
*/
|
|
107
|
-
export function buildJudgeActivationExtraArgs(
|
|
47
|
+
/** Project admitted invocation onto the host-neutral turn request. */
|
|
48
|
+
export function buildJudgeTurnRequest(
|
|
108
49
|
admitted: AdmittedJudgeInvocation,
|
|
109
|
-
options:
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
packageRoot?: string;
|
|
113
|
-
extraPiArgs?: readonly string[];
|
|
114
|
-
} = {},
|
|
115
|
-
): string[] {
|
|
116
|
-
const prompt = buildJudgeTransportPrompt(
|
|
117
|
-
admitted,
|
|
118
|
-
engineSessionMaterialFromOptions(options),
|
|
119
|
-
);
|
|
120
|
-
return [
|
|
121
|
-
"--no-skills",
|
|
122
|
-
"--no-prompt-templates",
|
|
123
|
-
"--no-themes",
|
|
124
|
-
"--no-context-files",
|
|
125
|
-
// Exact Pi session file principal (SessionManager.open), not directory-latest.
|
|
126
|
-
"--session",
|
|
127
|
-
admitted.sessionFile,
|
|
128
|
-
"--session-dir",
|
|
129
|
-
admitted.sessionDirectory,
|
|
130
|
-
...(options.extraPiArgs ?? []),
|
|
131
|
-
"--ak-role",
|
|
132
|
-
"judge",
|
|
133
|
-
"--mode",
|
|
134
|
-
"json",
|
|
135
|
-
...buildSeatModelCliArgs(options.model),
|
|
136
|
-
prompt,
|
|
137
|
-
];
|
|
50
|
+
options: RoleTurnRequestProjectionOptions,
|
|
51
|
+
): RoleTurnRequest {
|
|
52
|
+
return projectRoleTurnRequest(admitted, { activation: { role: "judge" as const } }, options);
|
|
138
53
|
}
|
|
139
54
|
|
|
140
|
-
|
|
141
|
-
* Build Internal activation args that reopen the exact Pi session for resume.
|
|
142
|
-
* Does not resubmit the admitted instruction; uses the package resume envelope.
|
|
143
|
-
* Reopens the durable session file principal explicitly — never --continue latest.
|
|
144
|
-
*/
|
|
145
|
-
export function buildJudgeResumeActivationExtraArgs(
|
|
146
|
-
admitted: AdmittedJudgeInvocation,
|
|
147
|
-
options: {
|
|
148
|
-
model?: SeatModelConfig;
|
|
149
|
-
extraPiArgs?: readonly string[];
|
|
150
|
-
message?: string;
|
|
151
|
-
} = {},
|
|
152
|
-
): string[] {
|
|
153
|
-
return [
|
|
154
|
-
"--no-skills",
|
|
155
|
-
"--no-prompt-templates",
|
|
156
|
-
"--no-themes",
|
|
157
|
-
"--no-context-files",
|
|
158
|
-
"--session",
|
|
159
|
-
admitted.sessionFile,
|
|
160
|
-
"--session-dir",
|
|
161
|
-
admitted.sessionDirectory,
|
|
162
|
-
...(options.extraPiArgs ?? []),
|
|
163
|
-
"--ak-role",
|
|
164
|
-
"judge",
|
|
165
|
-
"--mode",
|
|
166
|
-
"json",
|
|
167
|
-
...buildSeatModelCliArgs(options.model),
|
|
168
|
-
selectResumeContinuationPrompt(options.message),
|
|
169
|
-
];
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
async function presentControlledFailure(
|
|
173
|
-
admitted: AdmittedJudgeInvocation,
|
|
174
|
-
failureInput: {
|
|
175
|
-
timedOut: boolean;
|
|
176
|
-
code: number | null;
|
|
177
|
-
stderr: string;
|
|
178
|
-
thrown?: unknown;
|
|
179
|
-
knownFailure?: ExplicitInternalKnownFailure;
|
|
180
|
-
/** Pre-resolved typed-HTTP outcome — no second sidecar read when settled. */
|
|
181
|
-
typedHttpObservationSettled?: true;
|
|
182
|
-
typedHttpObservation?: TypedProviderHttpObservation;
|
|
183
|
-
},
|
|
184
|
-
io: CliIo,
|
|
185
|
-
): Promise<{
|
|
186
|
-
exitCode: number;
|
|
187
|
-
admitted: AdmittedJudgeInvocation;
|
|
188
|
-
terminal: TerminalResult;
|
|
189
|
-
}> {
|
|
190
|
-
// Own-key presence, not value: `throw undefined` must not look like "no throw".
|
|
191
|
-
const hasThrown = Object.hasOwn(failureInput, "thrown");
|
|
192
|
-
// v1 resume observation: reuse audited resolution when present; otherwise one
|
|
193
|
-
// controlled read. Non-absence failures fold into knownFailure — never escape.
|
|
194
|
-
const resumeObservation = await resolveControlledFailureResumeObservation({
|
|
195
|
-
runDirectory: admitted.runDirectory,
|
|
196
|
-
...(failureInput.typedHttpObservationSettled === true
|
|
197
|
-
? {
|
|
198
|
-
typedHttpObservationSettled: true as const,
|
|
199
|
-
...(failureInput.typedHttpObservation === undefined
|
|
200
|
-
? {}
|
|
201
|
-
: { typedHttpObservation: failureInput.typedHttpObservation }),
|
|
202
|
-
}
|
|
203
|
-
: {}),
|
|
204
|
-
});
|
|
205
|
-
const knownFailure =
|
|
206
|
-
failureInput.knownFailure ?? resumeObservation.observationReadFailure;
|
|
207
|
-
const session =
|
|
208
|
-
!hasThrown &&
|
|
209
|
-
!failureInput.timedOut &&
|
|
210
|
-
knownFailure === undefined
|
|
211
|
-
? await inspectJudgeSession(admitted.sessionFile)
|
|
212
|
-
: undefined;
|
|
213
|
-
const failure = classifyPostAdmissionFailure({
|
|
214
|
-
timedOut: failureInput.timedOut,
|
|
215
|
-
code: failureInput.code,
|
|
216
|
-
stderr: failureInput.stderr,
|
|
217
|
-
...(hasThrown ? { thrown: failureInput.thrown } : {}),
|
|
218
|
-
...explicitInternalKnownFailureClassificationInput(knownFailure),
|
|
219
|
-
...(session === undefined ? {} : { session }),
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
// v1 resume: only *this attempt's* typed HTTP 429 with independently confirmed
|
|
223
|
-
// absence of a lawful Judge result, and a durable exact Pi session principal.
|
|
224
|
-
// Lawful presence is session-owned and must not depend on artifact publication.
|
|
225
|
-
const hasLawfulTerminalResult = await hasLawfulJudgeTerminalResult(admitted);
|
|
226
|
-
const typedHttp429 = resumeObservation.typedHttp429;
|
|
227
|
-
const sessionPrincipalAvailable = await isSessionPrincipalAvailable(
|
|
228
|
-
admitted.sessionFile,
|
|
229
|
-
);
|
|
230
|
-
const resumable =
|
|
231
|
-
sessionPrincipalAvailable &&
|
|
232
|
-
isV1ResumableFailure({
|
|
233
|
-
hasLawfulTerminalResult,
|
|
234
|
-
...(typedHttp429 === undefined ? {} : { typedHttp429 }),
|
|
235
|
-
});
|
|
236
|
-
if (resumable && typedHttp429 !== undefined) {
|
|
237
|
-
await markRunResumable(admitted.runDirectory, typedHttp429);
|
|
238
|
-
} else {
|
|
239
|
-
await markRunTerminal(admitted.runDirectory).catch(() => undefined);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const terminal = await settleJudgeFailureTerminalResult(
|
|
243
|
-
admitted,
|
|
244
|
-
failure,
|
|
245
|
-
resumable
|
|
246
|
-
? { resume: { command: renderResumeCommand(admitted.runId) } }
|
|
247
|
-
: {},
|
|
248
|
-
);
|
|
249
|
-
presentFailureTerminal(terminal, io);
|
|
55
|
+
function judgeAdapters(): PostAdmissionAdapters<AdmittedJudgeInvocation> {
|
|
250
56
|
return {
|
|
251
|
-
|
|
252
|
-
admitted,
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
async function dispatchAdmittedJudge(input: {
|
|
258
|
-
admitted: AdmittedJudgeInvocation;
|
|
259
|
-
env: JudgeRunEnv;
|
|
260
|
-
io: CliIo;
|
|
261
|
-
extraArgs: string[];
|
|
262
|
-
lease: RunWriterLease;
|
|
263
|
-
/**
|
|
264
|
-
* Mechanical engine provenance for initial Judge dispatch only.
|
|
265
|
-
* Explicit — never read from env.engine here, so resume cannot rewrite it.
|
|
266
|
-
*/
|
|
267
|
-
effectiveEngine?: string;
|
|
268
|
-
}): Promise<{
|
|
269
|
-
exitCode: number;
|
|
270
|
-
admitted: AdmittedJudgeInvocation;
|
|
271
|
-
terminal?: TerminalResult;
|
|
272
|
-
}> {
|
|
273
|
-
const { admitted, env, io, extraArgs, lease, effectiveEngine } = input;
|
|
274
|
-
try {
|
|
275
|
-
// Fail closed at the public credential seam before model dispatch: missing
|
|
276
|
-
// selected-provider auth must not be washed by ambient keys or zero-exit runs.
|
|
277
|
-
const missingCredential = missingCredentialPreDispatchFailure(
|
|
278
|
-
env.model,
|
|
279
|
-
env.credentials,
|
|
280
|
-
);
|
|
281
|
-
if (missingCredential !== undefined) {
|
|
282
|
-
return await presentControlledFailure(
|
|
283
|
-
admitted,
|
|
284
|
-
missingCredential,
|
|
285
|
-
io,
|
|
286
|
-
);
|
|
287
|
-
}
|
|
288
|
-
await markRunRunning(
|
|
289
|
-
admitted.runDirectory,
|
|
290
|
-
env.model,
|
|
291
|
-
effectiveEngine,
|
|
292
|
-
);
|
|
293
|
-
// Attempt-scoped observation: drop any prior dispatch's 429 evidence so only
|
|
294
|
-
// the current initial/resume attempt can qualify v1 resume.
|
|
295
|
-
await clearTypedProviderHttpObservation(admitted.runDirectory);
|
|
296
|
-
|
|
297
|
-
const childEnv: NodeJS.ProcessEnv = {
|
|
298
|
-
...process.env,
|
|
299
|
-
HOME: env.home,
|
|
300
|
-
PI_CODING_AGENT_DIR: env.agentDir,
|
|
301
|
-
// Public-run marker so Navigator work context prefers admitted instruction
|
|
302
|
-
// and role-runtime can record typed provider HTTP observations.
|
|
303
|
-
AK_ROLE_RUN_DIR: admitted.runDirectory,
|
|
304
|
-
};
|
|
305
|
-
applyEngineChildEnv(childEnv, env.engine);
|
|
306
|
-
const correlationId = admitted.correlationId ?? env.correlationId;
|
|
307
|
-
if (correlationId !== undefined && correlationId.trim() !== "") {
|
|
308
|
-
childEnv.AK_CORRELATION_ID = correlationId;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
let result: ExplicitInternalPiResult;
|
|
312
|
-
try {
|
|
313
|
-
result = await runExplicitInternalActivation({
|
|
314
|
-
packageRoot: env.packageRoot,
|
|
315
|
-
extraArgs,
|
|
316
|
-
cwd: admitted.projectRoot,
|
|
317
|
-
home: env.home,
|
|
318
|
-
agentDir: env.agentDir,
|
|
319
|
-
env: childEnv,
|
|
320
|
-
timeoutMs: env.timeoutMs,
|
|
321
|
-
...(env.piRunner === undefined ? {} : { runner: env.piRunner }),
|
|
322
|
-
});
|
|
323
|
-
} catch (error) {
|
|
324
|
-
return await presentControlledFailure(
|
|
325
|
-
admitted,
|
|
326
|
-
{
|
|
327
|
-
timedOut: false,
|
|
328
|
-
code: null,
|
|
329
|
-
stderr: "",
|
|
330
|
-
thrown: error,
|
|
331
|
-
},
|
|
332
|
-
io,
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
// stderr.log is a best-effort ledger mirror.
|
|
337
|
-
try {
|
|
338
|
-
await writeFile(
|
|
339
|
-
join(admitted.runDirectory, "stderr.log"),
|
|
340
|
-
result.stderr,
|
|
341
|
-
"utf8",
|
|
342
|
-
);
|
|
343
|
-
} catch {
|
|
344
|
-
// continue to lawful / controlled-failure settlement below
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
let lawful: TerminalResult | undefined;
|
|
348
|
-
try {
|
|
349
|
-
lawful = await trySettleJudgeTerminalResult(admitted);
|
|
350
|
-
} catch (error) {
|
|
351
|
-
return await presentControlledFailure(
|
|
352
|
-
admitted,
|
|
353
|
-
{
|
|
354
|
-
timedOut: false,
|
|
355
|
-
code: result.code,
|
|
356
|
-
stderr: result.stderr,
|
|
357
|
-
thrown: error,
|
|
358
|
-
},
|
|
359
|
-
io,
|
|
360
|
-
);
|
|
361
|
-
}
|
|
362
|
-
if (lawful !== undefined && isLawfulTypedTerminalOutcome(lawful.roleOutcome)) {
|
|
363
|
-
await markRunTerminal(admitted.runDirectory).catch(() => undefined);
|
|
364
|
-
io.stdout(formatTerminalResult(lawful));
|
|
365
|
-
return {
|
|
366
|
-
exitCode: exitCodeForTerminalOutcome(lawful.roleOutcome),
|
|
367
|
-
admitted,
|
|
368
|
-
terminal: lawful,
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
// Prefer engine-detour infrastructure failure already on the session principal
|
|
373
|
-
// over a later secondary provider-stop after abort (#357 T2 / collector-isomorphic).
|
|
374
|
-
const infrastructureFailure = await readEngineDetourInfrastructureFailure(
|
|
375
|
-
admitted.sessionFile,
|
|
376
|
-
);
|
|
377
|
-
// Production-owned typed cause channel — never inferred from stderr wording.
|
|
378
|
-
const credentialFailure = postRunMissingCredentialFailure(
|
|
379
|
-
result,
|
|
380
|
-
env.model,
|
|
381
|
-
env.credentials,
|
|
382
|
-
);
|
|
383
|
-
const resolution = await resolveAuditedRunnerFailureResolution({
|
|
384
|
-
runner:
|
|
57
|
+
trySettle: (admitted, authority) => trySettleJudgeTerminalResult(admitted, authority),
|
|
58
|
+
hasLawfulTerminalResult: (admitted, authority) => hasLawfulJudgeTerminalResult(admitted, authority),
|
|
59
|
+
isResumableRole: true,
|
|
60
|
+
resolveRunnerKnownFailure: async ({ result, sessionFile }) => {
|
|
61
|
+
const infrastructureFailure = await readEngineDetourInfrastructureFailure(sessionFile);
|
|
62
|
+
return (
|
|
385
63
|
result.knownFailure ??
|
|
386
64
|
(infrastructureFailure === undefined
|
|
387
65
|
? undefined
|
|
@@ -391,24 +69,10 @@ async function dispatchAdmittedJudge(input: {
|
|
|
391
69
|
...(infrastructureFailure.identity === undefined
|
|
392
70
|
? {}
|
|
393
71
|
: { identity: infrastructureFailure.identity }),
|
|
394
|
-
})
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
});
|
|
399
|
-
return await presentControlledFailure(
|
|
400
|
-
admitted,
|
|
401
|
-
{
|
|
402
|
-
timedOut: result.timedOut,
|
|
403
|
-
code: result.code,
|
|
404
|
-
stderr: result.stderr,
|
|
405
|
-
...controlledFailureInputFromResolution(resolution),
|
|
406
|
-
},
|
|
407
|
-
io,
|
|
408
|
-
);
|
|
409
|
-
} finally {
|
|
410
|
-
await lease.release();
|
|
411
|
-
}
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
},
|
|
75
|
+
};
|
|
412
76
|
}
|
|
413
77
|
|
|
414
78
|
export async function runPublicJudge(
|
|
@@ -425,12 +89,12 @@ export async function runPublicJudge(
|
|
|
425
89
|
admitted?: AdmittedJudgeInvocation;
|
|
426
90
|
terminal?: TerminalResult;
|
|
427
91
|
}> {
|
|
428
|
-
// Structural parse/admit rejects before model dispatch via shared settlement presenter.
|
|
429
92
|
let admitted: AdmittedJudgeInvocation;
|
|
430
93
|
try {
|
|
431
94
|
const parsed = parseJudgeArgv(argv);
|
|
432
95
|
admitted = await admitJudgeInvocation({
|
|
433
96
|
home: env.home,
|
|
97
|
+
principalAuthority: env.principalAuthority,
|
|
434
98
|
cwd: env.cwd,
|
|
435
99
|
instruction: parsed.instruction,
|
|
436
100
|
attachmentPaths: parsed.attachmentPaths,
|
|
@@ -446,37 +110,52 @@ export async function runPublicJudge(
|
|
|
446
110
|
throw error;
|
|
447
111
|
}
|
|
448
112
|
|
|
449
|
-
await markRunAdmitted(admitted);
|
|
113
|
+
await markRunAdmitted(admitted, env.principalAuthority);
|
|
450
114
|
|
|
451
|
-
return
|
|
115
|
+
return await runPostAdmissionResumable({
|
|
452
116
|
admitted,
|
|
117
|
+
env,
|
|
453
118
|
io,
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
buildInitialArgs: () =>
|
|
457
|
-
buildJudgeActivationExtraArgs(admitted, {
|
|
119
|
+
buildInitialRequest: () =>
|
|
120
|
+
buildJudgeTurnRequest(admitted, {
|
|
458
121
|
packageRoot: env.packageRoot,
|
|
122
|
+
home: env.home,
|
|
123
|
+
agentDir: env.agentDir,
|
|
459
124
|
...(env.model === undefined ? {} : { model: env.model }),
|
|
460
125
|
...(env.engine === undefined ? {} : { engine: env.engine }),
|
|
461
|
-
...(env.
|
|
126
|
+
...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
|
|
127
|
+
...(admitted.correlationId === undefined && env.correlationId === undefined
|
|
128
|
+
? {}
|
|
129
|
+
: { correlationId: admitted.correlationId ?? env.correlationId }),
|
|
130
|
+
continuation: {
|
|
131
|
+
kind: "initial",
|
|
132
|
+
prompt: buildJudgeTransportPrompt(
|
|
133
|
+
admitted,
|
|
134
|
+
engineSessionMaterialFromOptions({
|
|
135
|
+
...(env.engine === undefined ? {} : { engine: env.engine }),
|
|
136
|
+
packageRoot: env.packageRoot,
|
|
137
|
+
}),
|
|
138
|
+
),
|
|
139
|
+
},
|
|
462
140
|
}),
|
|
463
|
-
|
|
464
|
-
|
|
141
|
+
buildResumeRequest: () =>
|
|
142
|
+
buildJudgeTurnRequest(admitted, {
|
|
143
|
+
packageRoot: env.packageRoot,
|
|
144
|
+
home: env.home,
|
|
145
|
+
agentDir: env.agentDir,
|
|
465
146
|
...(env.model === undefined ? {} : { model: env.model }),
|
|
466
|
-
...(env.
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
147
|
+
...(env.engine === undefined ? {} : { engine: env.engine }),
|
|
148
|
+
...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
|
|
149
|
+
...(admitted.correlationId === undefined && env.correlationId === undefined
|
|
150
|
+
? {}
|
|
151
|
+
: { correlationId: admitted.correlationId ?? env.correlationId }),
|
|
152
|
+
continuation: {
|
|
153
|
+
kind: "resume",
|
|
154
|
+
prompt: selectResumeContinuationPrompt(),
|
|
474
155
|
},
|
|
475
|
-
io: attemptIo,
|
|
476
|
-
extraArgs,
|
|
477
|
-
lease,
|
|
478
|
-
...(isFirst && env.engine !== undefined ? { effectiveEngine: env.engine } : {}),
|
|
479
156
|
}),
|
|
157
|
+
adapters: judgeAdapters(),
|
|
158
|
+
...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
|
|
480
159
|
});
|
|
481
160
|
}
|
|
482
161
|
|
|
@@ -496,7 +175,7 @@ export async function runPublicResume(
|
|
|
496
175
|
}> {
|
|
497
176
|
let loaded;
|
|
498
177
|
try {
|
|
499
|
-
loaded = await loadResumableJudgeRun(env.home, request.runId);
|
|
178
|
+
loaded = await loadResumableJudgeRun(env.home, request.runId, env.principalAuthority);
|
|
500
179
|
} catch (error) {
|
|
501
180
|
if (error instanceof CliUsageError) {
|
|
502
181
|
presentStructuralRejection(error, io);
|
|
@@ -506,38 +185,29 @@ export async function runPublicResume(
|
|
|
506
185
|
}
|
|
507
186
|
|
|
508
187
|
const { admitted } = loaded;
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
} catch (error) {
|
|
514
|
-
if (error instanceof RunWriterLeaseHeldError) {
|
|
515
|
-
// Concurrent resume: reject without second writer or dispatch.
|
|
516
|
-
io.stderr(formatCliDiagnostic(error.message));
|
|
517
|
-
return { exitCode: 1 };
|
|
518
|
-
}
|
|
519
|
-
throw error;
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
const extraArgs = buildJudgeResumeActivationExtraArgs(admitted, {
|
|
188
|
+
const turnRequest = buildJudgeTurnRequest(admitted, {
|
|
189
|
+
packageRoot: env.packageRoot,
|
|
190
|
+
home: env.home,
|
|
191
|
+
agentDir: env.agentDir,
|
|
523
192
|
...(env.model === undefined ? {} : { model: env.model }),
|
|
524
|
-
...(env.
|
|
525
|
-
...(
|
|
193
|
+
...(env.engine === undefined ? {} : { engine: env.engine }),
|
|
194
|
+
...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
|
|
195
|
+
...(admitted.correlationId === undefined && env.correlationId === undefined
|
|
196
|
+
? {}
|
|
197
|
+
: { correlationId: admitted.correlationId ?? env.correlationId }),
|
|
198
|
+
continuation: {
|
|
199
|
+
kind: "resume",
|
|
200
|
+
prompt: selectResumeContinuationPrompt(request.message),
|
|
201
|
+
},
|
|
526
202
|
});
|
|
527
203
|
|
|
528
|
-
|
|
204
|
+
return await runPostAdmissionManualResume({
|
|
529
205
|
admitted,
|
|
530
|
-
env
|
|
531
|
-
...env,
|
|
532
|
-
...(admitted.correlationId === undefined ? {} : { correlationId: admitted.correlationId }),
|
|
533
|
-
},
|
|
206
|
+
env,
|
|
534
207
|
io,
|
|
535
|
-
|
|
536
|
-
|
|
208
|
+
request: turnRequest,
|
|
209
|
+
adapters: judgeAdapters(),
|
|
537
210
|
});
|
|
538
|
-
// Manual resume: distinct scope from per-call auto retry; just expose observation.
|
|
539
|
-
if (result.terminal !== undefined) {
|
|
540
|
-
(result.terminal as { autoResumeCount?: number }).autoResumeCount = 0;
|
|
541
|
-
}
|
|
542
|
-
return result;
|
|
543
211
|
}
|
|
212
|
+
|
|
213
|
+
export type { RoleTurnKnownFailure };
|