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