@akagilnc/pi-workflow-roles 0.1.1751
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/LICENSE +202 -0
- package/README.md +104 -0
- package/README.zh-CN.md +133 -0
- package/THIRD_PARTY_NOTICES.md +60 -0
- package/dist/activation-ledger-git.js +68 -0
- package/dist/activation-ledger-session.js +120 -0
- package/dist/activation-ledger-topology.js +239 -0
- package/dist/activation-reconciliation.js +61 -0
- package/dist/audit-escalation.js +108 -0
- package/dist/auditor-dossier-tool.js +35 -0
- package/dist/canonical-json.js +78 -0
- package/dist/compliance-transport.js +77 -0
- package/dist/doctor-contracts.js +172 -0
- package/dist/dossier-resolution.js +103 -0
- package/dist/evidence-child-executor.js +661 -0
- package/dist/exact-utf8.js +12 -0
- package/dist/git-object-id.js +7 -0
- package/dist/in-process-session.js +50 -0
- package/dist/merger-contracts.js +76 -0
- package/dist/navigator-attendance.js +995 -0
- package/dist/navigator-invocation-identity.js +220 -0
- package/dist/open-tool-schema.js +39 -0
- package/dist/package-contracts/collector-output.js +50 -0
- package/dist/package-contracts/fixer-output.js +72 -0
- package/dist/package-contracts/fixer-packet.js +77 -0
- package/dist/package-contracts/judge-output.js +17 -0
- package/dist/package-contracts/reviewer-output.js +82 -0
- package/dist/package-contracts/terminating-tools.js +173 -0
- package/dist/package-contracts/worker-output.js +13 -0
- package/dist/package-owned-tool-idle.js +104 -0
- package/dist/packaged-role-registry.js +34 -0
- package/dist/public-cli/main.js +23867 -0
- package/dist/public-command-renderer.js +20 -0
- package/dist/reviewer-agent.js +93 -0
- package/dist/reviewer-child-executor.js +23 -0
- package/dist/reviewer-construction.js +95 -0
- package/dist/reviewer-dispatch.js +77 -0
- package/dist/reviewer-execution-ledger.js +160 -0
- package/dist/reviewer-failure-diagnostic.js +17 -0
- package/dist/reviewer-git-snapshot.js +38 -0
- package/dist/reviewer-pinned-git.js +146 -0
- package/dist/reviewer-preflight-error.js +15 -0
- package/dist/reviewer-prompt-identity.js +10 -0
- package/dist/reviewer-scope-prompt.js +21 -0
- package/dist/reviewer-workspace.js +151 -0
- package/dist/sha256.js +5 -0
- package/dist/sitian-record-entry.js +33 -0
- package/dist/stderr-jsonl.js +26 -0
- package/dist/stream-idle-guard.js +75 -0
- package/dist/tool-execution-observation.js +141 -0
- package/dist/uuidv7.js +21 -0
- package/dist/work-subject-identity.js +53 -0
- package/extensions/role-runtime.ts +303 -0
- package/package.json +69 -0
- package/packets/fixer-prerequisites.json +6 -0
- package/packets/fixer-repair.md +5 -0
- package/packets/judge-apply.md +77 -0
- package/packets/judge-authority.md +64 -0
- package/packets/judge-plan.md +55 -0
- package/packets/judge-review.md +49 -0
- package/packets/judge-submission.md +34 -0
- package/resources/methods/code-review/SKILL.md +92 -0
- package/resources/methods/code-review/agents/openai.yaml +3 -0
- package/resources/methods/code-review/provenance.json +26 -0
- package/resources/methods/diagnosing-bugs/SKILL.md +134 -0
- package/resources/methods/diagnosing-bugs/agents/openai.yaml +3 -0
- package/resources/methods/diagnosing-bugs/provenance.json +31 -0
- package/resources/methods/diagnosing-bugs/scripts/hitl-loop.template.sh +41 -0
- package/resources/methods/resolving-merge-conflicts/SKILL.md +14 -0
- package/resources/methods/resolving-merge-conflicts/agents/openai.yaml +3 -0
- package/resources/methods/resolving-merge-conflicts/provenance.json +26 -0
- package/resources/methods/tdd/SKILL.md +38 -0
- package/resources/methods/tdd/agents/openai.yaml +3 -0
- package/resources/methods/tdd/mocking.md +59 -0
- package/resources/methods/tdd/provenance.json +36 -0
- package/resources/methods/tdd/tests.md +77 -0
- package/resources/navigator-route-playbook.md +32 -0
- package/schemas/tool-execution-observation.schema.json +107 -0
- package/scripts/build-package.mjs +65 -0
- package/scripts/generate-tool-execution-observation-schema.ts +7 -0
- package/souls/coder.md +10 -0
- package/souls/collector.md +11 -0
- package/souls/doctor-auditor.md +23 -0
- package/souls/doctor.md +8 -0
- package/souls/fixer-auditor.md +33 -0
- package/souls/fixer.md +13 -0
- package/souls/judge-auditor.md +33 -0
- package/souls/judge.md +74 -0
- package/souls/merger.md +5 -0
- package/souls/navigator.md +5 -0
- package/souls/reviewer-auditor.md +25 -0
- package/souls/reviewer.md +11 -0
- package/src/activation-ledger-git.ts +96 -0
- package/src/activation-ledger-session.ts +188 -0
- package/src/activation-ledger-topology.ts +301 -0
- package/src/activation-ledger.ts +240 -0
- package/src/activation-reconciliation.ts +163 -0
- package/src/activation-trace.ts +38 -0
- package/src/audit-escalation.ts +177 -0
- package/src/auditor-dossier-tool.ts +48 -0
- package/src/auditor-soul.ts +28 -0
- package/src/canonical-json.ts +74 -0
- package/src/canonical-skill-binding.ts +107 -0
- package/src/collector-config.ts +89 -0
- package/src/collector-evidence.ts +461 -0
- package/src/collector-github.ts +656 -0
- package/src/collector-identity.ts +161 -0
- package/src/collector-ledger.ts +827 -0
- package/src/collector-receipt.ts +87 -0
- package/src/collector-role.ts +592 -0
- package/src/collector-tool-schemas.ts +19 -0
- package/src/compliance-transport.ts +130 -0
- package/src/doctor-auditor.ts +53 -0
- package/src/doctor-contracts.ts +166 -0
- package/src/doctor-evidence.ts +47 -0
- package/src/doctor-role.ts +18 -0
- package/src/dossier-resolution.ts +137 -0
- package/src/evidence-child-executor.ts +775 -0
- package/src/exact-utf8.ts +9 -0
- package/src/factory-board.ts +1822 -0
- package/src/git-object-id.ts +11 -0
- package/src/human-format.ts +65 -0
- package/src/in-process-session.ts +78 -0
- package/src/judge-auditor.ts +55 -0
- package/src/judge-recording-anti-forge.ts +53 -0
- package/src/judge-role.ts +160 -0
- package/src/merger-contracts.ts +71 -0
- package/src/merger-git-state.ts +76 -0
- package/src/merger-role.ts +60 -0
- package/src/navigator-attendance.ts +1254 -0
- package/src/navigator-invocation-identity.ts +446 -0
- package/src/open-tool-schema.ts +46 -0
- package/src/package-contracts/collector-output.ts +109 -0
- package/src/package-contracts/fixer-output.ts +81 -0
- package/src/package-contracts/fixer-packet.ts +93 -0
- package/src/package-contracts/judge-output.ts +39 -0
- package/src/package-contracts/reviewer-output.ts +115 -0
- package/src/package-contracts/terminating-tools.ts +259 -0
- package/src/package-contracts/worker-output.ts +36 -0
- package/src/package-owned-tool-idle.ts +134 -0
- package/src/package-resources/method-skill-binding.ts +87 -0
- package/src/package-resources/method-skill.ts +358 -0
- package/src/packaged-role-registry.ts +36 -0
- package/src/public-cli/cli-errors.ts +11 -0
- package/src/public-cli/cli-io.ts +4 -0
- package/src/public-cli/cli.ts +912 -0
- package/src/public-cli/coder-run.ts +575 -0
- package/src/public-cli/collector-run.ts +375 -0
- package/src/public-cli/command-renderer.ts +8 -0
- package/src/public-cli/config.ts +346 -0
- package/src/public-cli/doctor-run.ts +355 -0
- package/src/public-cli/explicit-internal.ts +274 -0
- package/src/public-cli/fixer-run.ts +587 -0
- package/src/public-cli/host-pi-runtime.ts +112 -0
- package/src/public-cli/invocation.ts +1958 -0
- package/src/public-cli/judge-run.ts +507 -0
- package/src/public-cli/main.ts +15 -0
- package/src/public-cli/merger-run.ts +681 -0
- package/src/public-cli/public-run-credentials.ts +71 -0
- package/src/public-cli/registry.ts +153 -0
- package/src/public-cli/reviewer-run.ts +561 -0
- package/src/public-cli/run-lifecycle.ts +884 -0
- package/src/public-cli/settlement.ts +3765 -0
- package/src/public-cli/terminal.ts +325 -0
- package/src/public-command-renderer.ts +43 -0
- package/src/reviewer-agent.ts +94 -0
- package/src/reviewer-auditor.ts +53 -0
- package/src/reviewer-child-executor.ts +31 -0
- package/src/reviewer-construction.ts +137 -0
- package/src/reviewer-dispatch.ts +94 -0
- package/src/reviewer-execution-ledger.ts +206 -0
- package/src/reviewer-failure-diagnostic.ts +18 -0
- package/src/reviewer-git-snapshot.ts +53 -0
- package/src/reviewer-pinned-git.ts +144 -0
- package/src/reviewer-preflight-error.ts +14 -0
- package/src/reviewer-prompt-identity.ts +17 -0
- package/src/reviewer-role.ts +193 -0
- package/src/reviewer-scope-prompt.ts +24 -0
- package/src/reviewer-settlement.ts +63 -0
- package/src/reviewer-workspace.ts +111 -0
- package/src/role-runtime.ts +884 -0
- package/src/sha256.ts +6 -0
- package/src/sitian-record-entry.ts +57 -0
- package/src/stderr-jsonl.ts +28 -0
- package/src/stream-idle-guard.ts +98 -0
- package/src/ticket-snapshot.ts +662 -0
- package/src/ticket-trajectory.ts +1000 -0
- package/src/tool-execution-observation.ts +168 -0
- package/src/uuidv7.ts +1 -0
- package/src/work-subject-identity.ts +94 -0
- package/src/worker-role.ts +434 -0
- package/src/worker-submission-gates.ts +225 -0
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public Judge Role run: admit → explicit Internal activate → settle Terminal result.
|
|
3
|
+
* #107: controlled post-admission failures and human decisions settle honestly.
|
|
4
|
+
* #108: typed HTTP 429 resume of the exact Pi session.
|
|
5
|
+
*/
|
|
6
|
+
import { writeFile } from "node:fs/promises";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
runExplicitInternalActivation,
|
|
11
|
+
type ExplicitInternalKnownFailure,
|
|
12
|
+
type ExplicitInternalPiRunner,
|
|
13
|
+
type ExplicitInternalPiResult,
|
|
14
|
+
} from "./explicit-internal.ts";
|
|
15
|
+
import { CliUsageError } from "./cli-errors.ts";
|
|
16
|
+
import {
|
|
17
|
+
admitJudgeInvocation,
|
|
18
|
+
buildJudgeTransportPrompt,
|
|
19
|
+
type AdmittedJudgeInvocation,
|
|
20
|
+
} from "./invocation.ts";
|
|
21
|
+
import {
|
|
22
|
+
type CredentialProviders,
|
|
23
|
+
type SeatModelConfig,
|
|
24
|
+
} from "./config.ts";
|
|
25
|
+
import {
|
|
26
|
+
missingCredentialPreDispatchFailure,
|
|
27
|
+
postRunMissingCredentialFailure,
|
|
28
|
+
} from "./public-run-credentials.ts";
|
|
29
|
+
import {
|
|
30
|
+
acquireRunWriterLease,
|
|
31
|
+
clearTypedProviderHttpObservation,
|
|
32
|
+
isSessionPrincipalAvailable,
|
|
33
|
+
isV1ResumableFailure,
|
|
34
|
+
loadResumableJudgeRun,
|
|
35
|
+
markRunAdmitted,
|
|
36
|
+
markRunResumable,
|
|
37
|
+
markRunRunning,
|
|
38
|
+
markRunTerminal,
|
|
39
|
+
readTypedHttp429Observation,
|
|
40
|
+
renderResumeCommand,
|
|
41
|
+
RESUME_TRANSPORT_ENVELOPE,
|
|
42
|
+
RunWriterLeaseHeldError,
|
|
43
|
+
type RunWriterLease,
|
|
44
|
+
} from "./run-lifecycle.ts";
|
|
45
|
+
import {
|
|
46
|
+
classifyPostAdmissionFailure,
|
|
47
|
+
exitCodeForTerminalOutcome,
|
|
48
|
+
formatCliDiagnostic,
|
|
49
|
+
formatTerminalResult,
|
|
50
|
+
hasLawfulJudgeTerminalResult,
|
|
51
|
+
inspectJudgeSession,
|
|
52
|
+
isLawfulTypedTerminalOutcome,
|
|
53
|
+
presentFailureTerminal,
|
|
54
|
+
presentStructuralRejection,
|
|
55
|
+
resolveAuditedRunnerKnownFailure,
|
|
56
|
+
explicitInternalKnownFailureClassificationInput,
|
|
57
|
+
settleJudgeFailureTerminalResult,
|
|
58
|
+
trySettleJudgeTerminalResult,
|
|
59
|
+
trySettleComplianceAuditIncompleteTerminalResult,
|
|
60
|
+
} from "./settlement.ts";
|
|
61
|
+
import type { CliIo } from "./cli-io.ts";
|
|
62
|
+
import type {
|
|
63
|
+
ControlledFailureCause,
|
|
64
|
+
TerminalResult,
|
|
65
|
+
} from "./terminal.ts";
|
|
66
|
+
|
|
67
|
+
export type JudgeRunEnv = {
|
|
68
|
+
home: string;
|
|
69
|
+
agentDir: string;
|
|
70
|
+
packageRoot: string;
|
|
71
|
+
cwd: string;
|
|
72
|
+
correlationId?: string;
|
|
73
|
+
piRunner?: ExplicitInternalPiRunner;
|
|
74
|
+
/** Effective judge seat model (persistent/startup/invocation). */
|
|
75
|
+
model?: SeatModelConfig;
|
|
76
|
+
/**
|
|
77
|
+
* Credential presence for public providers (auth.json shape).
|
|
78
|
+
* Used as the production-owned typed channel when a selected public provider
|
|
79
|
+
* has no configured credential — never inferred from child stderr prose.
|
|
80
|
+
*/
|
|
81
|
+
credentials?: CredentialProviders;
|
|
82
|
+
createRunId?: () => string;
|
|
83
|
+
/** Extra Pi args inserted before the prompt (tests: faux provider extension). */
|
|
84
|
+
extraPiArgs?: readonly string[];
|
|
85
|
+
/** Override default role-run timeout. */
|
|
86
|
+
timeoutMs?: number;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
function buildModelArgs(model: SeatModelConfig | undefined): string[] {
|
|
91
|
+
if (model === undefined) return [];
|
|
92
|
+
return [
|
|
93
|
+
"--provider",
|
|
94
|
+
model.provider,
|
|
95
|
+
"--model",
|
|
96
|
+
model.model,
|
|
97
|
+
"--thinking",
|
|
98
|
+
model.thinking,
|
|
99
|
+
];
|
|
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(
|
|
108
|
+
admitted: AdmittedJudgeInvocation,
|
|
109
|
+
options: {
|
|
110
|
+
model?: SeatModelConfig;
|
|
111
|
+
extraPiArgs?: readonly string[];
|
|
112
|
+
} = {},
|
|
113
|
+
): string[] {
|
|
114
|
+
const prompt = buildJudgeTransportPrompt(admitted);
|
|
115
|
+
return [
|
|
116
|
+
"--no-skills",
|
|
117
|
+
"--no-prompt-templates",
|
|
118
|
+
"--no-themes",
|
|
119
|
+
"--no-context-files",
|
|
120
|
+
// Exact Pi session file principal (SessionManager.open), not directory-latest.
|
|
121
|
+
"--session",
|
|
122
|
+
admitted.sessionFile,
|
|
123
|
+
"--session-dir",
|
|
124
|
+
admitted.sessionDirectory,
|
|
125
|
+
...(options.extraPiArgs ?? []),
|
|
126
|
+
"--ak-role",
|
|
127
|
+
"judge",
|
|
128
|
+
"--mode",
|
|
129
|
+
"json",
|
|
130
|
+
...buildModelArgs(options.model),
|
|
131
|
+
prompt,
|
|
132
|
+
];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Build Internal activation args that reopen the exact Pi session for resume.
|
|
137
|
+
* Does not resubmit the admitted instruction; uses the package resume envelope.
|
|
138
|
+
* Reopens the durable session file principal explicitly — never --continue latest.
|
|
139
|
+
*/
|
|
140
|
+
export function buildJudgeResumeActivationExtraArgs(
|
|
141
|
+
admitted: AdmittedJudgeInvocation,
|
|
142
|
+
options: {
|
|
143
|
+
model?: SeatModelConfig;
|
|
144
|
+
extraPiArgs?: readonly string[];
|
|
145
|
+
} = {},
|
|
146
|
+
): string[] {
|
|
147
|
+
return [
|
|
148
|
+
"--no-skills",
|
|
149
|
+
"--no-prompt-templates",
|
|
150
|
+
"--no-themes",
|
|
151
|
+
"--no-context-files",
|
|
152
|
+
"--session",
|
|
153
|
+
admitted.sessionFile,
|
|
154
|
+
"--session-dir",
|
|
155
|
+
admitted.sessionDirectory,
|
|
156
|
+
...(options.extraPiArgs ?? []),
|
|
157
|
+
"--ak-role",
|
|
158
|
+
"judge",
|
|
159
|
+
"--mode",
|
|
160
|
+
"json",
|
|
161
|
+
...buildModelArgs(options.model),
|
|
162
|
+
RESUME_TRANSPORT_ENVELOPE,
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async function presentControlledFailure(
|
|
167
|
+
admitted: AdmittedJudgeInvocation,
|
|
168
|
+
failureInput: {
|
|
169
|
+
timedOut: boolean;
|
|
170
|
+
code: number | null;
|
|
171
|
+
stderr: string;
|
|
172
|
+
thrown?: unknown;
|
|
173
|
+
knownFailure?: ExplicitInternalKnownFailure;
|
|
174
|
+
},
|
|
175
|
+
io: CliIo,
|
|
176
|
+
): Promise<{
|
|
177
|
+
exitCode: number;
|
|
178
|
+
admitted: AdmittedJudgeInvocation;
|
|
179
|
+
terminal: TerminalResult;
|
|
180
|
+
}> {
|
|
181
|
+
// Own-key presence, not value: `throw undefined` must not look like "no throw".
|
|
182
|
+
const hasThrown = Object.hasOwn(failureInput, "thrown");
|
|
183
|
+
const session =
|
|
184
|
+
!hasThrown &&
|
|
185
|
+
!failureInput.timedOut &&
|
|
186
|
+
failureInput.knownFailure === undefined
|
|
187
|
+
? await inspectJudgeSession(admitted.sessionFile)
|
|
188
|
+
: undefined;
|
|
189
|
+
const failure = classifyPostAdmissionFailure({
|
|
190
|
+
timedOut: failureInput.timedOut,
|
|
191
|
+
code: failureInput.code,
|
|
192
|
+
stderr: failureInput.stderr,
|
|
193
|
+
...(hasThrown ? { thrown: failureInput.thrown } : {}),
|
|
194
|
+
...explicitInternalKnownFailureClassificationInput(failureInput.knownFailure),
|
|
195
|
+
...(session === undefined ? {} : { session }),
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// v1 resume: only *this attempt's* typed HTTP 429 with independently confirmed
|
|
199
|
+
// absence of a lawful Judge result, and a durable exact Pi session principal.
|
|
200
|
+
// Lawful presence is session-owned and must not depend on artifact publication.
|
|
201
|
+
const hasLawfulTerminalResult = await hasLawfulJudgeTerminalResult(admitted);
|
|
202
|
+
const typedHttp429 = await readTypedHttp429Observation(admitted.runDirectory);
|
|
203
|
+
const sessionPrincipalAvailable = await isSessionPrincipalAvailable(
|
|
204
|
+
admitted.sessionFile,
|
|
205
|
+
);
|
|
206
|
+
const resumable =
|
|
207
|
+
sessionPrincipalAvailable &&
|
|
208
|
+
isV1ResumableFailure({
|
|
209
|
+
hasLawfulTerminalResult,
|
|
210
|
+
...(typedHttp429 === undefined ? {} : { typedHttp429 }),
|
|
211
|
+
});
|
|
212
|
+
if (resumable && typedHttp429 !== undefined) {
|
|
213
|
+
await markRunResumable(admitted.runDirectory, typedHttp429);
|
|
214
|
+
} else {
|
|
215
|
+
await markRunTerminal(admitted.runDirectory).catch(() => undefined);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const terminal = await settleJudgeFailureTerminalResult(
|
|
219
|
+
admitted,
|
|
220
|
+
failure,
|
|
221
|
+
resumable
|
|
222
|
+
? { resume: { command: renderResumeCommand(admitted.runId) } }
|
|
223
|
+
: {},
|
|
224
|
+
);
|
|
225
|
+
presentFailureTerminal(terminal, io);
|
|
226
|
+
return {
|
|
227
|
+
exitCode: exitCodeForTerminalOutcome(terminal.roleOutcome),
|
|
228
|
+
admitted,
|
|
229
|
+
terminal,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async function dispatchAdmittedJudge(input: {
|
|
234
|
+
admitted: AdmittedJudgeInvocation;
|
|
235
|
+
env: JudgeRunEnv;
|
|
236
|
+
io: CliIo;
|
|
237
|
+
extraArgs: string[];
|
|
238
|
+
lease: RunWriterLease;
|
|
239
|
+
}): Promise<{
|
|
240
|
+
exitCode: number;
|
|
241
|
+
admitted: AdmittedJudgeInvocation;
|
|
242
|
+
terminal?: TerminalResult;
|
|
243
|
+
}> {
|
|
244
|
+
const { admitted, env, io, extraArgs, lease } = input;
|
|
245
|
+
try {
|
|
246
|
+
// Fail closed at the public credential seam before model dispatch: missing
|
|
247
|
+
// selected-provider auth must not be washed by ambient keys or zero-exit runs.
|
|
248
|
+
const missingCredential = missingCredentialPreDispatchFailure(
|
|
249
|
+
env.model,
|
|
250
|
+
env.credentials,
|
|
251
|
+
);
|
|
252
|
+
if (missingCredential !== undefined) {
|
|
253
|
+
return await presentControlledFailure(
|
|
254
|
+
admitted,
|
|
255
|
+
missingCredential,
|
|
256
|
+
io,
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
await markRunRunning(admitted.runDirectory);
|
|
260
|
+
// Attempt-scoped observation: drop any prior dispatch's 429 evidence so only
|
|
261
|
+
// the current initial/resume attempt can qualify v1 resume.
|
|
262
|
+
await clearTypedProviderHttpObservation(admitted.runDirectory);
|
|
263
|
+
|
|
264
|
+
const childEnv: NodeJS.ProcessEnv = {
|
|
265
|
+
...process.env,
|
|
266
|
+
HOME: env.home,
|
|
267
|
+
PI_CODING_AGENT_DIR: env.agentDir,
|
|
268
|
+
// Public-run marker so Navigator work context prefers admitted instruction
|
|
269
|
+
// and role-runtime can record typed provider HTTP observations.
|
|
270
|
+
AK_ROLE_RUN_DIR: admitted.runDirectory,
|
|
271
|
+
};
|
|
272
|
+
if (env.correlationId !== undefined && env.correlationId.trim() !== "") {
|
|
273
|
+
childEnv.AK_CORRELATION_ID = env.correlationId;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
let result: ExplicitInternalPiResult;
|
|
277
|
+
try {
|
|
278
|
+
result = await runExplicitInternalActivation({
|
|
279
|
+
packageRoot: env.packageRoot,
|
|
280
|
+
extraArgs,
|
|
281
|
+
cwd: admitted.projectRoot,
|
|
282
|
+
home: env.home,
|
|
283
|
+
agentDir: env.agentDir,
|
|
284
|
+
env: childEnv,
|
|
285
|
+
timeoutMs: env.timeoutMs,
|
|
286
|
+
...(env.piRunner === undefined ? {} : { runner: env.piRunner }),
|
|
287
|
+
});
|
|
288
|
+
} catch (error) {
|
|
289
|
+
return await presentControlledFailure(
|
|
290
|
+
admitted,
|
|
291
|
+
{
|
|
292
|
+
timedOut: false,
|
|
293
|
+
code: null,
|
|
294
|
+
stderr: "",
|
|
295
|
+
thrown: error,
|
|
296
|
+
},
|
|
297
|
+
io,
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// stderr.log is a best-effort ledger mirror.
|
|
302
|
+
try {
|
|
303
|
+
await writeFile(
|
|
304
|
+
join(admitted.runDirectory, "stderr.log"),
|
|
305
|
+
result.stderr,
|
|
306
|
+
"utf8",
|
|
307
|
+
);
|
|
308
|
+
} catch {
|
|
309
|
+
// continue to lawful / controlled-failure settlement below
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
let lawful: TerminalResult | undefined;
|
|
313
|
+
try {
|
|
314
|
+
lawful = await trySettleJudgeTerminalResult(admitted);
|
|
315
|
+
} catch (error) {
|
|
316
|
+
return await presentControlledFailure(
|
|
317
|
+
admitted,
|
|
318
|
+
{
|
|
319
|
+
timedOut: false,
|
|
320
|
+
code: result.code,
|
|
321
|
+
stderr: result.stderr,
|
|
322
|
+
thrown: error,
|
|
323
|
+
},
|
|
324
|
+
io,
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
if (lawful !== undefined && isLawfulTypedTerminalOutcome(lawful.roleOutcome)) {
|
|
328
|
+
await markRunTerminal(admitted.runDirectory).catch(() => undefined);
|
|
329
|
+
io.stdout(formatTerminalResult(lawful));
|
|
330
|
+
return {
|
|
331
|
+
exitCode: exitCodeForTerminalOutcome(lawful.roleOutcome),
|
|
332
|
+
admitted,
|
|
333
|
+
terminal: lawful,
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const auditIncomplete = await trySettleComplianceAuditIncompleteTerminalResult(admitted);
|
|
338
|
+
if (auditIncomplete !== undefined) {
|
|
339
|
+
await markRunTerminal(admitted.runDirectory).catch(() => undefined);
|
|
340
|
+
if (auditIncomplete.roleOutcome.kind === "failure") {
|
|
341
|
+
presentFailureTerminal(auditIncomplete, io);
|
|
342
|
+
} else {
|
|
343
|
+
io.stdout(formatTerminalResult(auditIncomplete));
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
exitCode: exitCodeForTerminalOutcome(auditIncomplete.roleOutcome),
|
|
347
|
+
admitted,
|
|
348
|
+
terminal: auditIncomplete,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// Production-owned typed cause channel — never inferred from stderr wording.
|
|
353
|
+
const credentialFailure = postRunMissingCredentialFailure(
|
|
354
|
+
result,
|
|
355
|
+
env.model,
|
|
356
|
+
env.credentials,
|
|
357
|
+
);
|
|
358
|
+
const knownFailure = await resolveAuditedRunnerKnownFailure({
|
|
359
|
+
runner: result.knownFailure,
|
|
360
|
+
sessionFile: admitted.sessionFile,
|
|
361
|
+
credential: credentialFailure,
|
|
362
|
+
});
|
|
363
|
+
return await presentControlledFailure(
|
|
364
|
+
admitted,
|
|
365
|
+
{
|
|
366
|
+
timedOut: result.timedOut,
|
|
367
|
+
code: result.code,
|
|
368
|
+
stderr: result.stderr,
|
|
369
|
+
...(knownFailure === undefined ? {} : { knownFailure }),
|
|
370
|
+
},
|
|
371
|
+
io,
|
|
372
|
+
);
|
|
373
|
+
} finally {
|
|
374
|
+
await lease.release();
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export async function runPublicJudge(
|
|
379
|
+
argv: readonly string[],
|
|
380
|
+
env: JudgeRunEnv,
|
|
381
|
+
io: CliIo,
|
|
382
|
+
parseJudgeArgv: (args: readonly string[]) => {
|
|
383
|
+
instruction: string;
|
|
384
|
+
attachmentPaths: string[];
|
|
385
|
+
project?: string;
|
|
386
|
+
},
|
|
387
|
+
): Promise<{
|
|
388
|
+
exitCode: number;
|
|
389
|
+
admitted?: AdmittedJudgeInvocation;
|
|
390
|
+
terminal?: TerminalResult;
|
|
391
|
+
}> {
|
|
392
|
+
// Structural parse/admit rejects before model dispatch via shared settlement presenter.
|
|
393
|
+
let admitted: AdmittedJudgeInvocation;
|
|
394
|
+
try {
|
|
395
|
+
const parsed = parseJudgeArgv(argv);
|
|
396
|
+
admitted = await admitJudgeInvocation({
|
|
397
|
+
home: env.home,
|
|
398
|
+
cwd: env.cwd,
|
|
399
|
+
instruction: parsed.instruction,
|
|
400
|
+
attachmentPaths: parsed.attachmentPaths,
|
|
401
|
+
...(parsed.project === undefined ? {} : { project: parsed.project }),
|
|
402
|
+
...(env.createRunId === undefined ? {} : { createRunId: env.createRunId }),
|
|
403
|
+
});
|
|
404
|
+
} catch (error) {
|
|
405
|
+
if (error instanceof CliUsageError) {
|
|
406
|
+
presentStructuralRejection(error, io);
|
|
407
|
+
return { exitCode: 2 };
|
|
408
|
+
}
|
|
409
|
+
throw error;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
await markRunAdmitted(admitted);
|
|
413
|
+
|
|
414
|
+
let lease: RunWriterLease;
|
|
415
|
+
try {
|
|
416
|
+
lease = await acquireRunWriterLease(admitted.runDirectory);
|
|
417
|
+
} catch (error) {
|
|
418
|
+
if (error instanceof RunWriterLeaseHeldError) {
|
|
419
|
+
presentStructuralRejection(error, io);
|
|
420
|
+
return { exitCode: 2 };
|
|
421
|
+
}
|
|
422
|
+
throw error;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
const extraArgs = buildJudgeActivationExtraArgs(admitted, {
|
|
426
|
+
...(env.model === undefined ? {} : { model: env.model }),
|
|
427
|
+
...(env.extraPiArgs === undefined ? {} : { extraPiArgs: env.extraPiArgs }),
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
return await dispatchAdmittedJudge({
|
|
431
|
+
admitted,
|
|
432
|
+
env,
|
|
433
|
+
io,
|
|
434
|
+
extraArgs,
|
|
435
|
+
lease,
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Resume a previously admitted Role run after a typed HTTP 429 interruption.
|
|
441
|
+
* Restores role/project/instruction/attachments/session identity; model override
|
|
442
|
+
* is temporary for this invocation only.
|
|
443
|
+
*/
|
|
444
|
+
export async function runPublicResume(
|
|
445
|
+
argv: readonly string[],
|
|
446
|
+
env: JudgeRunEnv,
|
|
447
|
+
io: CliIo,
|
|
448
|
+
): Promise<{
|
|
449
|
+
exitCode: number;
|
|
450
|
+
admitted?: AdmittedJudgeInvocation;
|
|
451
|
+
terminal?: TerminalResult;
|
|
452
|
+
}> {
|
|
453
|
+
const runId = argv[0];
|
|
454
|
+
if (runId === undefined || runId.trim() === "" || runId.startsWith("-")) {
|
|
455
|
+
presentStructuralRejection(
|
|
456
|
+
new CliUsageError("usage: ak-role resume <runId>"),
|
|
457
|
+
io,
|
|
458
|
+
);
|
|
459
|
+
return { exitCode: 2 };
|
|
460
|
+
}
|
|
461
|
+
if (argv.length > 1) {
|
|
462
|
+
// Resume does not accept free positionals beyond runId (model/thinking are global).
|
|
463
|
+
presentStructuralRejection(
|
|
464
|
+
new CliUsageError("resume takes exactly one run id"),
|
|
465
|
+
io,
|
|
466
|
+
);
|
|
467
|
+
return { exitCode: 2 };
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
let loaded;
|
|
471
|
+
try {
|
|
472
|
+
loaded = await loadResumableJudgeRun(env.home, runId);
|
|
473
|
+
} catch (error) {
|
|
474
|
+
if (error instanceof CliUsageError) {
|
|
475
|
+
presentStructuralRejection(error, io);
|
|
476
|
+
return { exitCode: 2 };
|
|
477
|
+
}
|
|
478
|
+
throw error;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
const { admitted } = loaded;
|
|
482
|
+
|
|
483
|
+
let lease: RunWriterLease;
|
|
484
|
+
try {
|
|
485
|
+
lease = await acquireRunWriterLease(admitted.runDirectory);
|
|
486
|
+
} catch (error) {
|
|
487
|
+
if (error instanceof RunWriterLeaseHeldError) {
|
|
488
|
+
// Concurrent resume: reject without second writer or dispatch.
|
|
489
|
+
io.stderr(formatCliDiagnostic(error.message));
|
|
490
|
+
return { exitCode: 1 };
|
|
491
|
+
}
|
|
492
|
+
throw error;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
const extraArgs = buildJudgeResumeActivationExtraArgs(admitted, {
|
|
496
|
+
...(env.model === undefined ? {} : { model: env.model }),
|
|
497
|
+
...(env.extraPiArgs === undefined ? {} : { extraPiArgs: env.extraPiArgs }),
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
return await dispatchAdmittedJudge({
|
|
501
|
+
admitted,
|
|
502
|
+
env,
|
|
503
|
+
io,
|
|
504
|
+
extraArgs,
|
|
505
|
+
lease,
|
|
506
|
+
});
|
|
507
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { dirname, join } from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
|
|
4
|
+
import { ensureHostPiRuntimeResolvable } from "./host-pi-runtime.ts";
|
|
5
|
+
|
|
6
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
// dist/public-cli/main.js → package root is ../..
|
|
8
|
+
const packageRoot = join(here, "..", "..");
|
|
9
|
+
|
|
10
|
+
// The host-provided runtime must be resolvable before the CLI module graph loads it.
|
|
11
|
+
ensureHostPiRuntimeResolvable(packageRoot);
|
|
12
|
+
|
|
13
|
+
const { runAkRole } = await import("./cli.ts");
|
|
14
|
+
const result = await runAkRole(process.argv.slice(2), { packageRoot });
|
|
15
|
+
process.exitCode = result.exitCode;
|