@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,24 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Public Coder Role run: admit →
|
|
2
|
+
* Public Coder Role run: admit → post-admission coordinator → settle Terminal result (#109 / #517).
|
|
3
3
|
* #109: package-owned TDD method, default apply / explicit plan, shared #106 success interface.
|
|
4
|
-
*
|
|
4
|
+
* #526: execution via RoleTurnHost; argv is Pi adapter internal.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
import type {
|
|
7
|
+
DurablePrincipalAuthority,
|
|
8
|
+
MethodBinding,
|
|
9
|
+
RoleTurnKnownFailure,
|
|
10
|
+
RoleTurnRequest,
|
|
11
|
+
} from "../host-contracts.ts";
|
|
10
12
|
import { engineSessionMaterialFromOptions } from "../package-resources/engine-material.ts";
|
|
11
13
|
import {
|
|
12
14
|
loadPackagedMethodSkillMaterial,
|
|
13
15
|
resolvePackagedMethodSkillPath,
|
|
14
16
|
type PackagedMethodSkillProvenance,
|
|
15
17
|
} from "../package-resources/method-skill.ts";
|
|
16
|
-
import {
|
|
17
|
-
runExplicitInternalActivation,
|
|
18
|
-
type ExplicitInternalKnownFailure,
|
|
19
|
-
type ExplicitInternalPiRunner,
|
|
20
|
-
type ExplicitInternalPiResult,
|
|
21
|
-
} from "./explicit-internal.ts";
|
|
22
18
|
import { CliUsageError } from "./cli-errors.ts";
|
|
23
19
|
import {
|
|
24
20
|
admitCoderInvocation,
|
|
@@ -26,394 +22,75 @@ import {
|
|
|
26
22
|
type AdmittedCoderInvocation,
|
|
27
23
|
} from "./invocation.ts";
|
|
28
24
|
import {
|
|
29
|
-
buildSeatModelCliArgs,
|
|
30
|
-
type CredentialProviders,
|
|
31
|
-
type SeatModelConfig,
|
|
32
|
-
} from "./config.ts";
|
|
33
|
-
import {
|
|
34
|
-
missingCredentialPreDispatchFailure,
|
|
35
|
-
postRunMissingCredentialFailure,
|
|
36
|
-
} from "./public-run-credentials.ts";
|
|
37
|
-
import {
|
|
38
|
-
acquireRunWriterLease,
|
|
39
|
-
clearTypedProviderHttpObservation,
|
|
40
|
-
isSessionPrincipalAvailable,
|
|
41
|
-
isV1ResumableFailure,
|
|
42
25
|
loadResumableCoderRun,
|
|
43
26
|
markRunAdmitted,
|
|
44
|
-
markRunResumable,
|
|
45
|
-
markRunRunning,
|
|
46
|
-
markRunTerminal,
|
|
47
|
-
renderResumeCommand,
|
|
48
|
-
type PublicResumeRequest,
|
|
49
27
|
selectResumeContinuationPrompt,
|
|
50
|
-
|
|
51
|
-
type RunWriterLease,
|
|
52
|
-
type TypedProviderHttpObservation,
|
|
28
|
+
type PublicResumeRequest,
|
|
53
29
|
} from "./run-lifecycle.ts";
|
|
54
|
-
import { runWithAutoResumeLoop } from "./auto-resume.ts";
|
|
55
30
|
import {
|
|
56
|
-
classifyPostAdmissionFailure,
|
|
57
|
-
exitCodeForTerminalOutcome,
|
|
58
|
-
formatCliDiagnostic,
|
|
59
|
-
formatTerminalResult,
|
|
60
31
|
hasLawfulCoderTerminalResult,
|
|
61
|
-
inspectJudgeSession,
|
|
62
|
-
isLawfulTypedTerminalOutcome,
|
|
63
|
-
presentFailureTerminal,
|
|
64
32
|
presentStructuralRejection,
|
|
65
|
-
explicitInternalKnownFailureClassificationInput,
|
|
66
|
-
resolveAuditedRunnerFailureResolution,
|
|
67
|
-
resolveControlledFailureResumeObservation,
|
|
68
|
-
controlledFailureInputFromResolution,
|
|
69
|
-
settleFailureTerminalResult,
|
|
70
33
|
trySettleCoderTerminalResult,
|
|
71
34
|
} from "./settlement.ts";
|
|
72
35
|
import type { CliIo } from "./cli-io.ts";
|
|
73
|
-
import type {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
36
|
+
import type { TerminalResult } from "./terminal.ts";
|
|
37
|
+
import {
|
|
38
|
+
projectRoleTurnRequest,
|
|
39
|
+
type RoleTurnRequestProjectionOptions,
|
|
40
|
+
} from "./turn-request.ts";
|
|
41
|
+
import {
|
|
42
|
+
presentControlledFailure,
|
|
43
|
+
runPostAdmissionManualResume,
|
|
44
|
+
runPostAdmissionResumable,
|
|
45
|
+
type PostAdmissionAdapters,
|
|
46
|
+
type PostAdmissionEnv,
|
|
47
|
+
} from "./post-admission.ts";
|
|
77
48
|
|
|
78
|
-
export type CoderRunEnv = {
|
|
79
|
-
home: string;
|
|
80
|
-
agentDir: string;
|
|
81
|
-
packageRoot: string;
|
|
82
|
-
cwd: string;
|
|
83
|
-
correlationId?: string;
|
|
84
|
-
piRunner?: ExplicitInternalPiRunner;
|
|
85
|
-
model?: SeatModelConfig;
|
|
86
|
-
/** Optional labor engine name (config→activation; session material + env signal). */
|
|
87
|
-
engine?: string;
|
|
88
|
-
credentials?: CredentialProviders;
|
|
49
|
+
export type CoderRunEnv = PostAdmissionEnv & {
|
|
89
50
|
createRunId?: () => string;
|
|
90
|
-
/** #422: effective single-call auto-resume ceiling; undefined = package default (AUTO_RESUME_LIMIT). */
|
|
91
|
-
autoResumeLimit?: number;
|
|
92
|
-
extraPiArgs?: readonly string[];
|
|
93
|
-
timeoutMs?: number;
|
|
94
51
|
};
|
|
95
52
|
|
|
53
|
+
function coderMethods(
|
|
54
|
+
phase: string,
|
|
55
|
+
packageRoot: string,
|
|
56
|
+
): readonly MethodBinding[] {
|
|
57
|
+
return phase === "apply"
|
|
58
|
+
? [{ kind: "skill", path: resolvePackagedMethodSkillPath(packageRoot, "tdd") }]
|
|
59
|
+
: [];
|
|
60
|
+
}
|
|
96
61
|
|
|
97
|
-
/**
|
|
98
|
-
|
|
99
|
-
* Apply phase pins the package-owned TDD Skill via --skill (no ambient home).
|
|
100
|
-
* Plan phase keeps --no-skills without a method Skill.
|
|
101
|
-
*/
|
|
102
|
-
export function buildCoderActivationExtraArgs(
|
|
62
|
+
/** Project admitted Coder invocation onto the host-neutral turn request. */
|
|
63
|
+
export function buildCoderTurnRequest(
|
|
103
64
|
admitted: AdmittedCoderInvocation,
|
|
104
|
-
options:
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
engine?: string;
|
|
108
|
-
extraPiArgs?: readonly string[];
|
|
109
|
-
},
|
|
110
|
-
): string[] {
|
|
111
|
-
const prompt = buildCoderTransportPrompt(
|
|
65
|
+
options: RoleTurnRequestProjectionOptions,
|
|
66
|
+
): RoleTurnRequest {
|
|
67
|
+
return projectRoleTurnRequest(
|
|
112
68
|
admitted,
|
|
113
|
-
|
|
69
|
+
{
|
|
70
|
+
activation: {
|
|
71
|
+
role: "coder",
|
|
72
|
+
phase: admitted.phase,
|
|
73
|
+
taskPath: admitted.taskPath,
|
|
74
|
+
},
|
|
75
|
+
methods: coderMethods(admitted.phase, options.packageRoot),
|
|
76
|
+
},
|
|
77
|
+
options,
|
|
114
78
|
);
|
|
115
|
-
const skillArgs =
|
|
116
|
-
admitted.phase === "apply"
|
|
117
|
-
? [
|
|
118
|
-
"--skill",
|
|
119
|
-
resolvePackagedMethodSkillPath(options.packageRoot, "tdd"),
|
|
120
|
-
]
|
|
121
|
-
: [];
|
|
122
|
-
return [
|
|
123
|
-
"--no-skills",
|
|
124
|
-
...skillArgs,
|
|
125
|
-
"--no-prompt-templates",
|
|
126
|
-
"--no-themes",
|
|
127
|
-
"--no-context-files",
|
|
128
|
-
"--session",
|
|
129
|
-
admitted.sessionFile,
|
|
130
|
-
"--session-dir",
|
|
131
|
-
admitted.sessionDirectory,
|
|
132
|
-
...(options.extraPiArgs ?? []),
|
|
133
|
-
"--ak-role",
|
|
134
|
-
"coder",
|
|
135
|
-
"--ak-coder-phase",
|
|
136
|
-
admitted.phase,
|
|
137
|
-
"--ak-coder-task",
|
|
138
|
-
admitted.taskPath,
|
|
139
|
-
"--mode",
|
|
140
|
-
"json",
|
|
141
|
-
...buildSeatModelCliArgs(options.model),
|
|
142
|
-
prompt,
|
|
143
|
-
];
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Reopen the exact Coder Pi session for resume. Preserves admitted phase and
|
|
148
|
-
* package TDD binding; does not resubmit the original instruction.
|
|
149
|
-
*/
|
|
150
|
-
export function buildCoderResumeActivationExtraArgs(
|
|
151
|
-
admitted: AdmittedCoderInvocation,
|
|
152
|
-
options: {
|
|
153
|
-
packageRoot: string;
|
|
154
|
-
model?: SeatModelConfig;
|
|
155
|
-
extraPiArgs?: readonly string[];
|
|
156
|
-
message?: string;
|
|
157
|
-
},
|
|
158
|
-
): string[] {
|
|
159
|
-
const skillArgs =
|
|
160
|
-
admitted.phase === "apply"
|
|
161
|
-
? [
|
|
162
|
-
"--skill",
|
|
163
|
-
resolvePackagedMethodSkillPath(options.packageRoot, "tdd"),
|
|
164
|
-
]
|
|
165
|
-
: [];
|
|
166
|
-
return [
|
|
167
|
-
"--no-skills",
|
|
168
|
-
...skillArgs,
|
|
169
|
-
"--no-prompt-templates",
|
|
170
|
-
"--no-themes",
|
|
171
|
-
"--no-context-files",
|
|
172
|
-
"--session",
|
|
173
|
-
admitted.sessionFile,
|
|
174
|
-
"--session-dir",
|
|
175
|
-
admitted.sessionDirectory,
|
|
176
|
-
...(options.extraPiArgs ?? []),
|
|
177
|
-
"--ak-role",
|
|
178
|
-
"coder",
|
|
179
|
-
"--ak-coder-phase",
|
|
180
|
-
admitted.phase,
|
|
181
|
-
"--ak-coder-task",
|
|
182
|
-
admitted.taskPath,
|
|
183
|
-
"--mode",
|
|
184
|
-
"json",
|
|
185
|
-
...buildSeatModelCliArgs(options.model),
|
|
186
|
-
selectResumeContinuationPrompt(options.message),
|
|
187
|
-
];
|
|
188
79
|
}
|
|
189
80
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
timedOut: boolean;
|
|
194
|
-
code: number | null;
|
|
195
|
-
stderr: string;
|
|
196
|
-
thrown?: unknown;
|
|
197
|
-
knownFailure?: ExplicitInternalKnownFailure;
|
|
198
|
-
knownCause?: ControlledFailureCause;
|
|
199
|
-
knownIdentity?: {
|
|
200
|
-
readonly name?: string;
|
|
201
|
-
readonly code?: string | number;
|
|
202
|
-
};
|
|
203
|
-
knownDiagnostic?: string;
|
|
204
|
-
typedHttpObservationSettled?: true;
|
|
205
|
-
typedHttpObservation?: TypedProviderHttpObservation;
|
|
206
|
-
},
|
|
207
|
-
io: CliIo,
|
|
208
|
-
): Promise<{
|
|
209
|
-
exitCode: number;
|
|
210
|
-
admitted: AdmittedCoderInvocation;
|
|
211
|
-
terminal: TerminalResult;
|
|
212
|
-
}> {
|
|
213
|
-
const hasThrown = Object.hasOwn(failureInput, "thrown");
|
|
214
|
-
const resumeObservation = await resolveControlledFailureResumeObservation({
|
|
215
|
-
runDirectory: admitted.runDirectory,
|
|
216
|
-
...(failureInput.typedHttpObservationSettled === true
|
|
217
|
-
? {
|
|
218
|
-
typedHttpObservationSettled: true as const,
|
|
219
|
-
...(failureInput.typedHttpObservation === undefined
|
|
220
|
-
? {}
|
|
221
|
-
: { typedHttpObservation: failureInput.typedHttpObservation }),
|
|
222
|
-
}
|
|
223
|
-
: {}),
|
|
224
|
-
});
|
|
225
|
-
const knownFailure =
|
|
226
|
-
failureInput.knownFailure ?? resumeObservation.observationReadFailure;
|
|
227
|
-
const session =
|
|
228
|
-
!hasThrown &&
|
|
229
|
-
!failureInput.timedOut &&
|
|
230
|
-
knownFailure === undefined &&
|
|
231
|
-
failureInput.knownCause === undefined
|
|
232
|
-
? await inspectJudgeSession(admitted.sessionFile)
|
|
233
|
-
: undefined;
|
|
234
|
-
const failure = classifyPostAdmissionFailure({
|
|
235
|
-
timedOut: failureInput.timedOut,
|
|
236
|
-
code: failureInput.code,
|
|
237
|
-
stderr: failureInput.stderr,
|
|
238
|
-
...(hasThrown ? { thrown: failureInput.thrown } : {}),
|
|
239
|
-
...explicitInternalKnownFailureClassificationInput(knownFailure),
|
|
240
|
-
...(failureInput.knownCause === undefined
|
|
241
|
-
? {}
|
|
242
|
-
: { knownCause: failureInput.knownCause }),
|
|
243
|
-
...(failureInput.knownIdentity === undefined
|
|
244
|
-
? {}
|
|
245
|
-
: { knownIdentity: failureInput.knownIdentity }),
|
|
246
|
-
...(failureInput.knownDiagnostic === undefined
|
|
247
|
-
? {}
|
|
248
|
-
: { knownDiagnostic: failureInput.knownDiagnostic }),
|
|
249
|
-
...(session === undefined ? {} : { session }),
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
const hasLawfulTerminalResult = await hasLawfulCoderTerminalResult(admitted);
|
|
253
|
-
const typedHttp429 = resumeObservation.typedHttp429;
|
|
254
|
-
const sessionPrincipalAvailable = await isSessionPrincipalAvailable(
|
|
255
|
-
admitted.sessionFile,
|
|
256
|
-
);
|
|
257
|
-
const resumable =
|
|
258
|
-
sessionPrincipalAvailable &&
|
|
259
|
-
isV1ResumableFailure({
|
|
260
|
-
hasLawfulTerminalResult,
|
|
261
|
-
...(typedHttp429 === undefined ? {} : { typedHttp429 }),
|
|
262
|
-
});
|
|
263
|
-
if (resumable && typedHttp429 !== undefined) {
|
|
264
|
-
await markRunResumable(admitted.runDirectory, typedHttp429);
|
|
265
|
-
} else {
|
|
266
|
-
await markRunTerminal(admitted.runDirectory).catch(() => undefined);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// #107 owns generic controlled-failure settlement — consume, do not re-own.
|
|
270
|
-
const terminal = await settleFailureTerminalResult(
|
|
271
|
-
admitted,
|
|
272
|
-
failure,
|
|
273
|
-
resumable
|
|
274
|
-
? { resume: { command: renderResumeCommand(admitted.runId) } }
|
|
275
|
-
: {},
|
|
276
|
-
);
|
|
277
|
-
presentFailureTerminal(terminal, io);
|
|
81
|
+
function coderAdapters(
|
|
82
|
+
methodProvenance?: PackagedMethodSkillProvenance,
|
|
83
|
+
): PostAdmissionAdapters<AdmittedCoderInvocation> {
|
|
278
84
|
return {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
85
|
+
trySettle: (admitted, authority) =>
|
|
86
|
+
trySettleCoderTerminalResult(admitted, authority, {
|
|
87
|
+
...(methodProvenance === undefined ? {} : { methodProvenance }),
|
|
88
|
+
}),
|
|
89
|
+
hasLawfulTerminalResult: (admitted, authority) => hasLawfulCoderTerminalResult(admitted, authority),
|
|
90
|
+
isResumableRole: true,
|
|
282
91
|
};
|
|
283
92
|
}
|
|
284
93
|
|
|
285
|
-
async function dispatchAdmittedCoder(input: {
|
|
286
|
-
admitted: AdmittedCoderInvocation;
|
|
287
|
-
env: CoderRunEnv;
|
|
288
|
-
io: CliIo;
|
|
289
|
-
extraArgs: string[];
|
|
290
|
-
lease: RunWriterLease;
|
|
291
|
-
methodProvenance?: PackagedMethodSkillProvenance;
|
|
292
|
-
/** Mechanical engine provenance for initial Coder dispatch only. */
|
|
293
|
-
effectiveEngine?: string;
|
|
294
|
-
}): Promise<{
|
|
295
|
-
exitCode: number;
|
|
296
|
-
admitted: AdmittedCoderInvocation;
|
|
297
|
-
terminal?: TerminalResult;
|
|
298
|
-
}> {
|
|
299
|
-
const { admitted, env, io, extraArgs, lease, methodProvenance, effectiveEngine } = input;
|
|
300
|
-
try {
|
|
301
|
-
const missingCredential = missingCredentialPreDispatchFailure(
|
|
302
|
-
env.model,
|
|
303
|
-
env.credentials,
|
|
304
|
-
);
|
|
305
|
-
if (missingCredential !== undefined) {
|
|
306
|
-
return await presentControlledFailure(
|
|
307
|
-
admitted,
|
|
308
|
-
missingCredential,
|
|
309
|
-
io,
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
-
await markRunRunning(admitted.runDirectory, env.model, effectiveEngine);
|
|
313
|
-
await clearTypedProviderHttpObservation(admitted.runDirectory);
|
|
314
|
-
|
|
315
|
-
const childEnv: NodeJS.ProcessEnv = {
|
|
316
|
-
...process.env,
|
|
317
|
-
HOME: env.home,
|
|
318
|
-
PI_CODING_AGENT_DIR: env.agentDir,
|
|
319
|
-
AK_ROLE_RUN_DIR: admitted.runDirectory,
|
|
320
|
-
};
|
|
321
|
-
applyEngineChildEnv(childEnv, env.engine);
|
|
322
|
-
const correlationId = admitted.correlationId ?? env.correlationId;
|
|
323
|
-
if (correlationId !== undefined && correlationId.trim() !== "") {
|
|
324
|
-
childEnv.AK_CORRELATION_ID = correlationId;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
let result: ExplicitInternalPiResult;
|
|
328
|
-
try {
|
|
329
|
-
result = await runExplicitInternalActivation({
|
|
330
|
-
packageRoot: env.packageRoot,
|
|
331
|
-
extraArgs,
|
|
332
|
-
cwd: admitted.projectRoot,
|
|
333
|
-
home: env.home,
|
|
334
|
-
agentDir: env.agentDir,
|
|
335
|
-
env: childEnv,
|
|
336
|
-
timeoutMs: env.timeoutMs,
|
|
337
|
-
...(env.piRunner === undefined ? {} : { runner: env.piRunner }),
|
|
338
|
-
});
|
|
339
|
-
} catch (error) {
|
|
340
|
-
return await presentControlledFailure(
|
|
341
|
-
admitted,
|
|
342
|
-
{
|
|
343
|
-
timedOut: false,
|
|
344
|
-
code: null,
|
|
345
|
-
stderr: "",
|
|
346
|
-
thrown: error,
|
|
347
|
-
},
|
|
348
|
-
io,
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
try {
|
|
353
|
-
await writeFile(
|
|
354
|
-
join(admitted.runDirectory, "stderr.log"),
|
|
355
|
-
result.stderr,
|
|
356
|
-
"utf8",
|
|
357
|
-
);
|
|
358
|
-
} catch {
|
|
359
|
-
// continue to lawful / controlled-failure settlement
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
let lawful: TerminalResult | undefined;
|
|
363
|
-
try {
|
|
364
|
-
lawful = await trySettleCoderTerminalResult(admitted, {
|
|
365
|
-
...(methodProvenance === undefined
|
|
366
|
-
? {}
|
|
367
|
-
: { methodProvenance }),
|
|
368
|
-
});
|
|
369
|
-
} catch (error) {
|
|
370
|
-
return await presentControlledFailure(
|
|
371
|
-
admitted,
|
|
372
|
-
{
|
|
373
|
-
timedOut: false,
|
|
374
|
-
code: result.code,
|
|
375
|
-
stderr: result.stderr,
|
|
376
|
-
thrown: error,
|
|
377
|
-
},
|
|
378
|
-
io,
|
|
379
|
-
);
|
|
380
|
-
}
|
|
381
|
-
if (lawful !== undefined && isLawfulTypedTerminalOutcome(lawful.roleOutcome)) {
|
|
382
|
-
await markRunTerminal(admitted.runDirectory).catch(() => undefined);
|
|
383
|
-
io.stdout(formatTerminalResult(lawful));
|
|
384
|
-
return {
|
|
385
|
-
exitCode: exitCodeForTerminalOutcome(lawful.roleOutcome),
|
|
386
|
-
admitted,
|
|
387
|
-
terminal: lawful,
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
const credentialFailure = postRunMissingCredentialFailure(
|
|
392
|
-
result,
|
|
393
|
-
env.model,
|
|
394
|
-
env.credentials,
|
|
395
|
-
);
|
|
396
|
-
const resolution = await resolveAuditedRunnerFailureResolution({
|
|
397
|
-
runner: result.knownFailure,
|
|
398
|
-
sessionFile: admitted.sessionFile,
|
|
399
|
-
credential: credentialFailure,
|
|
400
|
-
runDirectory: admitted.runDirectory,
|
|
401
|
-
});
|
|
402
|
-
return await presentControlledFailure(
|
|
403
|
-
admitted,
|
|
404
|
-
{
|
|
405
|
-
timedOut: result.timedOut,
|
|
406
|
-
code: result.code,
|
|
407
|
-
stderr: result.stderr,
|
|
408
|
-
...controlledFailureInputFromResolution(resolution),
|
|
409
|
-
},
|
|
410
|
-
io,
|
|
411
|
-
);
|
|
412
|
-
} finally {
|
|
413
|
-
await lease.release();
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
|
|
417
94
|
export async function runPublicCoder(
|
|
418
95
|
argv: readonly string[],
|
|
419
96
|
env: CoderRunEnv,
|
|
@@ -434,6 +111,7 @@ export async function runPublicCoder(
|
|
|
434
111
|
const parsed = parseCoderArgv(argv);
|
|
435
112
|
admitted = await admitCoderInvocation({
|
|
436
113
|
home: env.home,
|
|
114
|
+
principalAuthority: env.principalAuthority,
|
|
437
115
|
cwd: env.cwd,
|
|
438
116
|
phase: parsed.phase,
|
|
439
117
|
instruction: parsed.instruction,
|
|
@@ -450,8 +128,7 @@ export async function runPublicCoder(
|
|
|
450
128
|
throw error;
|
|
451
129
|
}
|
|
452
130
|
|
|
453
|
-
await markRunAdmitted(admitted);
|
|
454
|
-
// #416 scope = single LLM call: call-local retry counter, no persistence.
|
|
131
|
+
await markRunAdmitted(admitted, env.principalAuthority);
|
|
455
132
|
|
|
456
133
|
let methodProvenance: PackagedMethodSkillProvenance | undefined;
|
|
457
134
|
if (admitted.phase === "apply") {
|
|
@@ -462,7 +139,7 @@ export async function runPublicCoder(
|
|
|
462
139
|
);
|
|
463
140
|
methodProvenance = material.provenance;
|
|
464
141
|
} catch (error) {
|
|
465
|
-
return await presentControlledFailure(
|
|
142
|
+
return (await presentControlledFailure(
|
|
466
143
|
admitted,
|
|
467
144
|
{
|
|
468
145
|
timedOut: false,
|
|
@@ -471,42 +148,57 @@ export async function runPublicCoder(
|
|
|
471
148
|
thrown: error,
|
|
472
149
|
knownCause: "activation",
|
|
473
150
|
},
|
|
151
|
+
coderAdapters(),
|
|
152
|
+
env.principalAuthority,
|
|
474
153
|
io,
|
|
475
|
-
);
|
|
154
|
+
)) as { exitCode: number; admitted: AdmittedCoderInvocation; terminal: TerminalResult };
|
|
476
155
|
}
|
|
477
156
|
}
|
|
478
157
|
|
|
479
|
-
return
|
|
158
|
+
return await runPostAdmissionResumable({
|
|
480
159
|
admitted,
|
|
160
|
+
env,
|
|
481
161
|
io,
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
buildInitialArgs: () =>
|
|
485
|
-
buildCoderActivationExtraArgs(admitted, {
|
|
162
|
+
buildInitialRequest: () =>
|
|
163
|
+
buildCoderTurnRequest(admitted, {
|
|
486
164
|
packageRoot: env.packageRoot,
|
|
165
|
+
home: env.home,
|
|
166
|
+
agentDir: env.agentDir,
|
|
487
167
|
...(env.model === undefined ? {} : { model: env.model }),
|
|
488
168
|
...(env.engine === undefined ? {} : { engine: env.engine }),
|
|
489
|
-
...(env.
|
|
169
|
+
...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
|
|
170
|
+
...(admitted.correlationId === undefined && env.correlationId === undefined
|
|
171
|
+
? {}
|
|
172
|
+
: { correlationId: admitted.correlationId ?? env.correlationId }),
|
|
173
|
+
continuation: {
|
|
174
|
+
kind: "initial",
|
|
175
|
+
prompt: buildCoderTransportPrompt(
|
|
176
|
+
admitted,
|
|
177
|
+
engineSessionMaterialFromOptions({
|
|
178
|
+
...(env.engine === undefined ? {} : { engine: env.engine }),
|
|
179
|
+
packageRoot: env.packageRoot,
|
|
180
|
+
}),
|
|
181
|
+
),
|
|
182
|
+
},
|
|
490
183
|
}),
|
|
491
|
-
|
|
492
|
-
|
|
184
|
+
buildResumeRequest: () =>
|
|
185
|
+
buildCoderTurnRequest(admitted, {
|
|
493
186
|
packageRoot: env.packageRoot,
|
|
187
|
+
home: env.home,
|
|
188
|
+
agentDir: env.agentDir,
|
|
494
189
|
...(env.model === undefined ? {} : { model: env.model }),
|
|
495
|
-
...(env.
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
190
|
+
...(env.engine === undefined ? {} : { engine: env.engine }),
|
|
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: "resume",
|
|
197
|
+
prompt: selectResumeContinuationPrompt(),
|
|
503
198
|
},
|
|
504
|
-
io: attemptIo,
|
|
505
|
-
extraArgs,
|
|
506
|
-
lease,
|
|
507
|
-
...(methodProvenance === undefined ? {} : { methodProvenance }),
|
|
508
|
-
...(isFirst && env.engine !== undefined ? { effectiveEngine: env.engine } : {}),
|
|
509
199
|
}),
|
|
200
|
+
adapters: coderAdapters(methodProvenance),
|
|
201
|
+
...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
|
|
510
202
|
});
|
|
511
203
|
}
|
|
512
204
|
|
|
@@ -525,7 +217,7 @@ export async function runPublicCoderResume(
|
|
|
525
217
|
}> {
|
|
526
218
|
let loaded;
|
|
527
219
|
try {
|
|
528
|
-
loaded = await loadResumableCoderRun(env.home, request.runId);
|
|
220
|
+
loaded = await loadResumableCoderRun(env.home, request.runId, env.principalAuthority);
|
|
529
221
|
} catch (error) {
|
|
530
222
|
if (error instanceof CliUsageError) {
|
|
531
223
|
presentStructuralRejection(error, io);
|
|
@@ -536,18 +228,6 @@ export async function runPublicCoderResume(
|
|
|
536
228
|
|
|
537
229
|
const { admitted } = loaded;
|
|
538
230
|
|
|
539
|
-
let lease: RunWriterLease;
|
|
540
|
-
try {
|
|
541
|
-
lease = await acquireRunWriterLease(admitted.runDirectory, (diagnostic) => io.stderr(diagnostic));
|
|
542
|
-
} catch (error) {
|
|
543
|
-
if (error instanceof RunWriterLeaseHeldError) {
|
|
544
|
-
// Concurrent resume: reject without second writer or dispatch.
|
|
545
|
-
io.stderr(formatCliDiagnostic(error.message));
|
|
546
|
-
return { exitCode: 1 };
|
|
547
|
-
}
|
|
548
|
-
throw error;
|
|
549
|
-
}
|
|
550
|
-
|
|
551
231
|
let methodProvenance: PackagedMethodSkillProvenance | undefined;
|
|
552
232
|
if (admitted.phase === "apply") {
|
|
553
233
|
try {
|
|
@@ -557,8 +237,7 @@ export async function runPublicCoderResume(
|
|
|
557
237
|
);
|
|
558
238
|
methodProvenance = material.provenance;
|
|
559
239
|
} catch (error) {
|
|
560
|
-
await
|
|
561
|
-
return await presentControlledFailure(
|
|
240
|
+
return (await presentControlledFailure(
|
|
562
241
|
admitted,
|
|
563
242
|
{
|
|
564
243
|
timedOut: false,
|
|
@@ -567,34 +246,37 @@ export async function runPublicCoderResume(
|
|
|
567
246
|
thrown: error,
|
|
568
247
|
knownCause: "activation",
|
|
569
248
|
},
|
|
249
|
+
coderAdapters(),
|
|
250
|
+
env.principalAuthority,
|
|
570
251
|
io,
|
|
571
|
-
);
|
|
252
|
+
)) as { exitCode: number; admitted: AdmittedCoderInvocation; terminal: TerminalResult };
|
|
572
253
|
}
|
|
573
254
|
}
|
|
574
255
|
|
|
575
|
-
const
|
|
256
|
+
const turnRequest = buildCoderTurnRequest(admitted, {
|
|
576
257
|
packageRoot: env.packageRoot,
|
|
258
|
+
home: env.home,
|
|
259
|
+
agentDir: env.agentDir,
|
|
577
260
|
...(env.model === undefined ? {} : { model: env.model }),
|
|
578
|
-
...(env.
|
|
579
|
-
...(
|
|
261
|
+
...(env.engine === undefined ? {} : { engine: env.engine }),
|
|
262
|
+
...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
|
|
263
|
+
...(admitted.correlationId === undefined && env.correlationId === undefined
|
|
264
|
+
? {}
|
|
265
|
+
: { correlationId: admitted.correlationId ?? env.correlationId }),
|
|
266
|
+
continuation: {
|
|
267
|
+
kind: "resume",
|
|
268
|
+
prompt: selectResumeContinuationPrompt(request.message),
|
|
269
|
+
},
|
|
580
270
|
});
|
|
581
271
|
|
|
582
|
-
|
|
272
|
+
return await runPostAdmissionManualResume({
|
|
583
273
|
admitted,
|
|
584
|
-
env
|
|
585
|
-
...env,
|
|
586
|
-
...(admitted.correlationId === undefined ? {} : { correlationId: admitted.correlationId }),
|
|
587
|
-
},
|
|
274
|
+
env,
|
|
588
275
|
io,
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
...(methodProvenance === undefined ? {} : { methodProvenance }),
|
|
276
|
+
request: turnRequest,
|
|
277
|
+
adapters: coderAdapters(methodProvenance),
|
|
592
278
|
});
|
|
593
|
-
if (result.terminal !== undefined) {
|
|
594
|
-
(result.terminal as { autoResumeCount?: number }).autoResumeCount = 0;
|
|
595
|
-
}
|
|
596
|
-
return result;
|
|
597
279
|
}
|
|
598
280
|
|
|
599
281
|
// Re-export for tests that assert typed credential failure channel shape.
|
|
600
|
-
export type {
|
|
282
|
+
export type { RoleTurnKnownFailure, PackagedMethodSkillProvenance };
|