@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.
Files changed (109) hide show
  1. package/README.md +129 -39
  2. package/README.zh-CN.md +128 -39
  3. package/dist/activation-ledger-topology.js +1 -1
  4. package/dist/archivist-record-entry.js +47 -26
  5. package/dist/auditor-dossier-tool.js +3 -1
  6. package/dist/compliance-transport.js +17 -26
  7. package/dist/doctor-contracts.js +1 -2
  8. package/dist/dossier-resolution.js +4 -8
  9. package/dist/engine-detour-tool.js +33 -8
  10. package/dist/engine-detour.js +1 -0
  11. package/dist/evidence-child-executor.js +277 -424
  12. package/dist/host-contracts.js +22 -0
  13. package/dist/institutional-resolution.js +88 -0
  14. package/dist/merger-contracts.js +1 -2
  15. package/dist/navigator-attendance.js +16 -0
  16. package/dist/notary-contracts.js +2 -3
  17. package/dist/package-contracts/fixer-output.js +1 -2
  18. package/dist/packaged-role-registry.js +102 -9
  19. package/dist/pi/in-process-session.js +671 -0
  20. package/dist/public-cli/config.js +7 -5
  21. package/dist/public-cli/main.js +3767 -4113
  22. package/dist/reviewer-child-executor.js +6 -1
  23. package/dist/session-opening-materials.js +10 -38
  24. package/dist/sitian-appender.js +146 -0
  25. package/dist/sitian-contracts.js +21 -0
  26. package/dist/sitian-facade.js +15 -0
  27. package/dist/sitian-reader.js +52 -0
  28. package/extensions/role-runtime.ts +9 -7
  29. package/package.json +5 -5
  30. package/resources/engines/cursor.md +12 -26
  31. package/resources/engines/hermes.md +2 -23
  32. package/resources/engines/opus.md +1 -16
  33. package/resources/navigator-route-playbook.md +2 -2
  34. package/scripts/build-package.mjs +0 -1
  35. package/souls/quality-law.md +1 -1
  36. package/src/activation-ledger-topology.ts +1 -1
  37. package/src/archivist-record-entry.ts +57 -45
  38. package/src/auditor-dossier-tool.ts +4 -2
  39. package/src/canonical-skill-binding.ts +37 -27
  40. package/src/collector-role.ts +11 -20
  41. package/src/collector-tool-schemas.ts +1 -4
  42. package/src/compliance-transport.ts +19 -44
  43. package/src/doctor-auditor.ts +1 -5
  44. package/src/doctor-contracts.ts +1 -4
  45. package/src/doctor-role.ts +31 -8
  46. package/src/dossier-resolution.ts +8 -8
  47. package/src/engine-detour-tool.ts +48 -19
  48. package/src/engine-detour.ts +3 -0
  49. package/src/evidence-child-executor.ts +277 -485
  50. package/src/factory-board.ts +3 -3
  51. package/src/gatekeeper-role.ts +21 -10
  52. package/src/host-contracts.ts +386 -0
  53. package/src/in-process-session.ts +1 -115
  54. package/src/institutional-resolution.ts +135 -0
  55. package/src/judge-auditor.ts +1 -5
  56. package/src/judge-role.ts +37 -51
  57. package/src/merger-contracts.ts +1 -4
  58. package/src/merger-role.ts +7 -11
  59. package/src/navigator-attendance.ts +20 -1
  60. package/src/notary-contracts.ts +8 -11
  61. package/src/notary-role.ts +7 -23
  62. package/src/notary-source-run.ts +4 -3
  63. package/src/package-contracts/fixer-output.ts +1 -4
  64. package/src/package-resources/method-skill-binding.ts +10 -34
  65. package/src/packaged-role-registry.ts +122 -12
  66. package/src/pi/adapter.ts +192 -0
  67. package/src/pi/durable-principal.ts +98 -0
  68. package/src/pi/in-process-session.ts +819 -0
  69. package/src/pi/known-failure.ts +77 -0
  70. package/src/pi/pi-normalization.ts +284 -0
  71. package/src/pi/role-turn-host.ts +459 -0
  72. package/src/public-cli/auto-resume.ts +42 -44
  73. package/src/public-cli/cli.ts +171 -257
  74. package/src/public-cli/coder-run.ts +115 -433
  75. package/src/public-cli/collector-run.ts +62 -314
  76. package/src/public-cli/config.ts +7 -5
  77. package/src/public-cli/doctor-run.ts +41 -52
  78. package/src/public-cli/fixer-run.ts +122 -427
  79. package/src/public-cli/invocation.ts +287 -96
  80. package/src/public-cli/judge-run.ts +92 -422
  81. package/src/public-cli/merger-run.ts +167 -429
  82. package/src/public-cli/notary-run.ts +41 -47
  83. package/src/public-cli/option-definitions.ts +136 -3
  84. package/src/public-cli/post-admission.ts +497 -0
  85. package/src/public-cli/public-run-credentials.ts +4 -4
  86. package/src/public-cli/reviewer-dispatch-rejection.ts +106 -0
  87. package/src/public-cli/reviewer-run.ts +132 -449
  88. package/src/public-cli/run-lifecycle.ts +339 -327
  89. package/src/public-cli/settlement.ts +251 -134
  90. package/src/public-cli/terminal.ts +3 -9
  91. package/src/public-cli/turn-request.ts +87 -0
  92. package/src/reviewer-child-executor.ts +9 -1
  93. package/src/reviewer-role.ts +11 -20
  94. package/src/role-runtime.ts +129 -78
  95. package/src/session-opening-materials.ts +25 -39
  96. package/src/sitian-appender.ts +171 -0
  97. package/src/sitian-contracts.ts +106 -0
  98. package/src/sitian-facade.ts +18 -0
  99. package/src/sitian-reader.ts +62 -0
  100. package/src/worker-role.ts +42 -40
  101. package/src/worker-submission-gates.ts +33 -0
  102. package/dist/archivist-role-run-coordinates.js +0 -28
  103. package/dist/package-contracts/terminating-infrastructure.js +0 -90
  104. package/resources/engines/sonnet.md +0 -27
  105. package/resources/engines/zcode.md +0 -63
  106. package/src/archivist-role-run-coordinates.ts +0 -45
  107. package/src/package-contracts/terminating-infrastructure.ts +0 -132
  108. package/src/public-cli/explicit-internal.ts +0 -427
  109. package/src/public-cli/one-shot-dispatch.ts +0 -300
@@ -1,19 +1,14 @@
1
1
  /**
2
- * Public Judge Role run: admit → explicit Internal activate → settle Terminal result.
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 { writeFile } from "node:fs/promises";
7
- import { join } from "node:path";
8
-
9
- import { applyEngineChildEnv } from "../engine-detour.ts";
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
- RunWriterLeaseHeldError,
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
- ControlledFailureCause,
71
- TerminalResult,
72
- } from "./terminal.ts";
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
- model?: SeatModelConfig;
111
- engine?: string;
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
- exitCode: exitCodeForTerminalOutcome(terminal.roleOutcome),
252
- admitted,
253
- terminal,
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
- sessionFile: admitted.sessionFile,
396
- credential: credentialFailure,
397
- runDirectory: admitted.runDirectory,
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 runWithAutoResumeLoop({
115
+ return await runPostAdmissionResumable({
452
116
  admitted,
117
+ env,
453
118
  io,
454
- // #422: pass-through only; the loop entry resolves the default and validates the domain once.
455
- autoResumeLimit: env.autoResumeLimit,
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.extraPiArgs === undefined ? {} : { extraPiArgs: env.extraPiArgs }),
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
- buildResumeArgs: () =>
464
- buildJudgeResumeActivationExtraArgs(admitted, {
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.extraPiArgs === undefined ? {} : { extraPiArgs: env.extraPiArgs }),
467
- }),
468
- dispatch: (extraArgs, lease, isFirst, attemptIo) =>
469
- dispatchAdmittedJudge({
470
- admitted,
471
- env: {
472
- ...env,
473
- ...(admitted.correlationId === undefined ? {} : { correlationId: admitted.correlationId }),
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
- let lease: RunWriterLease;
511
- try {
512
- lease = await acquireRunWriterLease(admitted.runDirectory, (diagnostic) => io.stderr(diagnostic));
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.extraPiArgs === undefined ? {} : { extraPiArgs: env.extraPiArgs }),
525
- ...(request.message === undefined ? {} : { message: request.message }),
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
- const result = await dispatchAdmittedJudge({
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
- extraArgs,
536
- lease,
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 };