@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,14 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Public Merger Role run: derive active-merge envelope → force package
|
|
3
|
-
* merge-only method →
|
|
4
|
-
*
|
|
3
|
+
* merge-only method → post-admission coordinator → settle Terminal result (#114 / #517).
|
|
4
|
+
* #526: execution via RoleTurnHost; argv is Pi adapter internal.
|
|
5
5
|
*/
|
|
6
|
+
import type {
|
|
7
|
+
DurablePrincipalAuthority,
|
|
8
|
+
MethodBinding,
|
|
9
|
+
RoleTurnKnownFailure,
|
|
10
|
+
RoleTurnRequest,
|
|
11
|
+
} from "../host-contracts.ts";
|
|
6
12
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
7
13
|
import { join, resolve } from "node:path";
|
|
8
14
|
|
|
9
15
|
import { ensureRealDirectoryTree } from "../activation-ledger-topology.ts";
|
|
10
|
-
import { roleRunSessionCoordinates } from "../archivist-role-run-coordinates.ts";
|
|
11
|
-
import { applyEngineChildEnv } from "../engine-detour.ts";
|
|
12
16
|
import { engineSessionMaterialFromOptions } from "../package-resources/engine-material.ts";
|
|
13
17
|
import {
|
|
14
18
|
loadPackagedMethodSkillMaterial,
|
|
@@ -17,400 +21,94 @@ import {
|
|
|
17
21
|
type PackagedMethodSkillProvenance,
|
|
18
22
|
} from "../package-resources/method-skill.ts";
|
|
19
23
|
import { uuidv7 } from "../uuidv7.ts";
|
|
20
|
-
import {
|
|
21
|
-
runExplicitInternalActivation,
|
|
22
|
-
type ExplicitInternalKnownFailure,
|
|
23
|
-
type ExplicitInternalPiRunner,
|
|
24
|
-
type ExplicitInternalPiResult,
|
|
25
|
-
} from "./explicit-internal.ts";
|
|
26
24
|
import { CliUsageError } from "./cli-errors.ts";
|
|
27
25
|
import {
|
|
28
26
|
admitMergerInvocation,
|
|
29
27
|
buildMergerTransportPrompt,
|
|
28
|
+
issueAdmissionPlacement,
|
|
30
29
|
MergerEnvelopeDerivationError,
|
|
31
30
|
type AdmittedMergerInvocation,
|
|
32
31
|
} from "./invocation.ts";
|
|
33
32
|
import {
|
|
34
|
-
buildSeatModelCliArgs,
|
|
35
|
-
type CredentialProviders,
|
|
36
|
-
type SeatModelConfig,
|
|
37
|
-
} from "./config.ts";
|
|
38
|
-
import {
|
|
39
|
-
missingCredentialPreDispatchFailure,
|
|
40
|
-
postRunMissingCredentialFailure,
|
|
41
|
-
} from "./public-run-credentials.ts";
|
|
42
|
-
import {
|
|
43
|
-
acquireRunWriterLease,
|
|
44
|
-
clearTypedProviderHttpObservation,
|
|
45
|
-
isSessionPrincipalAvailable,
|
|
46
|
-
isV1ResumableFailure,
|
|
47
33
|
loadResumableMergerRun,
|
|
48
34
|
markRunAdmitted,
|
|
49
|
-
markRunResumable,
|
|
50
|
-
markRunRunning,
|
|
51
|
-
markRunTerminal,
|
|
52
|
-
renderResumeCommand,
|
|
53
|
-
type PublicResumeRequest,
|
|
54
35
|
selectResumeContinuationPrompt,
|
|
55
|
-
|
|
56
|
-
type RunWriterLease,
|
|
57
|
-
type TypedProviderHttpObservation,
|
|
36
|
+
type PublicResumeRequest,
|
|
58
37
|
} from "./run-lifecycle.ts";
|
|
59
|
-
import { runWithAutoResumeLoop } from "./auto-resume.ts";
|
|
60
38
|
import {
|
|
61
|
-
classifyPostAdmissionFailure,
|
|
62
|
-
exitCodeForTerminalOutcome,
|
|
63
|
-
formatCliDiagnostic,
|
|
64
|
-
formatTerminalResult,
|
|
65
39
|
hasLawfulMergerTerminalResult,
|
|
66
|
-
|
|
67
|
-
presentFailureTerminal,
|
|
40
|
+
isLawfulTypedTerminalOutcome,
|
|
68
41
|
presentStructuralRejection,
|
|
69
|
-
explicitInternalKnownFailureClassificationInput,
|
|
70
|
-
resolveAuditedRunnerFailureResolution,
|
|
71
|
-
resolveControlledFailureResumeObservation,
|
|
72
|
-
controlledFailureInputFromResolution,
|
|
73
|
-
settleFailureTerminalResult,
|
|
74
42
|
trySettleMergerTerminalResult,
|
|
75
43
|
} from "./settlement.ts";
|
|
76
44
|
import type { CliIo } from "./cli-io.ts";
|
|
77
|
-
import type {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
45
|
+
import type { TerminalResult } from "./terminal.ts";
|
|
46
|
+
import {
|
|
47
|
+
projectRoleTurnRequest,
|
|
48
|
+
type RoleTurnRequestProjectionOptions,
|
|
49
|
+
} from "./turn-request.ts";
|
|
50
|
+
import {
|
|
51
|
+
presentControlledFailure,
|
|
52
|
+
runPostAdmissionManualResume,
|
|
53
|
+
runPostAdmissionResumable,
|
|
54
|
+
type PostAdmissionAdapters,
|
|
55
|
+
type PostAdmissionEnv,
|
|
56
|
+
} from "./post-admission.ts";
|
|
81
57
|
|
|
82
|
-
export type MergerRunEnv = {
|
|
83
|
-
home: string;
|
|
84
|
-
agentDir: string;
|
|
85
|
-
packageRoot: string;
|
|
86
|
-
cwd: string;
|
|
87
|
-
correlationId?: string;
|
|
88
|
-
piRunner?: ExplicitInternalPiRunner;
|
|
89
|
-
model?: SeatModelConfig;
|
|
90
|
-
/** Optional labor engine name (config→activation; session material + env signal). */
|
|
91
|
-
engine?: string;
|
|
92
|
-
credentials?: CredentialProviders;
|
|
58
|
+
export type MergerRunEnv = PostAdmissionEnv & {
|
|
93
59
|
createRunId?: () => string;
|
|
94
|
-
/** #422: effective single-call auto-resume ceiling; undefined = package default (AUTO_RESUME_LIMIT). */
|
|
95
|
-
autoResumeLimit?: number;
|
|
96
|
-
extraPiArgs?: readonly string[];
|
|
97
|
-
timeoutMs?: number;
|
|
98
60
|
};
|
|
99
61
|
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Build Internal activation extra-args for an admitted Merger run.
|
|
103
|
-
* Package resolving-merge-conflicts Skill is forced via --skill; ambient home off.
|
|
104
|
-
* Transport prompt forces `/skill:resolving-merge-conflicts` expansion first.
|
|
105
|
-
*/
|
|
106
|
-
export function buildMergerActivationExtraArgs(
|
|
107
|
-
admitted: AdmittedMergerInvocation,
|
|
108
|
-
options: {
|
|
109
|
-
packageRoot: string;
|
|
110
|
-
model?: SeatModelConfig;
|
|
111
|
-
engine?: string;
|
|
112
|
-
extraPiArgs?: readonly string[];
|
|
113
|
-
},
|
|
114
|
-
): string[] {
|
|
115
|
-
const prompt = buildMergerTransportPrompt(
|
|
116
|
-
admitted,
|
|
117
|
-
engineSessionMaterialFromOptions(options),
|
|
118
|
-
);
|
|
119
|
-
const skillPath = resolvePackagedMethodSkillPath(
|
|
120
|
-
options.packageRoot,
|
|
121
|
-
"resolving-merge-conflicts",
|
|
122
|
-
);
|
|
62
|
+
function mergerMethods(packageRoot: string): readonly MethodBinding[] {
|
|
123
63
|
return [
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
"--no-themes",
|
|
129
|
-
"--no-context-files",
|
|
130
|
-
"--session",
|
|
131
|
-
admitted.sessionFile,
|
|
132
|
-
"--session-dir",
|
|
133
|
-
admitted.sessionDirectory,
|
|
134
|
-
...(options.extraPiArgs ?? []),
|
|
135
|
-
"--ak-role",
|
|
136
|
-
"merger",
|
|
137
|
-
"--ak-merger-input",
|
|
138
|
-
admitted.mergerInputPath,
|
|
139
|
-
"--mode",
|
|
140
|
-
"json",
|
|
141
|
-
...buildSeatModelCliArgs(options.model),
|
|
142
|
-
prompt,
|
|
64
|
+
{
|
|
65
|
+
kind: "skill",
|
|
66
|
+
path: resolvePackagedMethodSkillPath(packageRoot, "resolving-merge-conflicts"),
|
|
67
|
+
},
|
|
143
68
|
];
|
|
144
69
|
}
|
|
145
70
|
|
|
146
|
-
/**
|
|
147
|
-
|
|
148
|
-
* package method binding; does not resubmit the original instruction.
|
|
149
|
-
*/
|
|
150
|
-
export function buildMergerResumeActivationExtraArgs(
|
|
71
|
+
/** Project admitted Merger invocation onto the host-neutral turn request. */
|
|
72
|
+
export function buildMergerTurnRequest(
|
|
151
73
|
admitted: AdmittedMergerInvocation,
|
|
152
|
-
options:
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
74
|
+
options: RoleTurnRequestProjectionOptions,
|
|
75
|
+
): RoleTurnRequest {
|
|
76
|
+
return projectRoleTurnRequest(
|
|
77
|
+
admitted,
|
|
78
|
+
{
|
|
79
|
+
activation: {
|
|
80
|
+
role: "merger",
|
|
81
|
+
inputPath: admitted.mergerInputPath,
|
|
82
|
+
},
|
|
83
|
+
methods: mergerMethods(options.packageRoot),
|
|
84
|
+
},
|
|
85
|
+
options,
|
|
162
86
|
);
|
|
163
|
-
return [
|
|
164
|
-
"--no-skills",
|
|
165
|
-
"--skill",
|
|
166
|
-
skillPath,
|
|
167
|
-
"--no-prompt-templates",
|
|
168
|
-
"--no-themes",
|
|
169
|
-
"--no-context-files",
|
|
170
|
-
"--session",
|
|
171
|
-
admitted.sessionFile,
|
|
172
|
-
"--session-dir",
|
|
173
|
-
admitted.sessionDirectory,
|
|
174
|
-
...(options.extraPiArgs ?? []),
|
|
175
|
-
"--ak-role",
|
|
176
|
-
"merger",
|
|
177
|
-
"--ak-merger-input",
|
|
178
|
-
admitted.mergerInputPath,
|
|
179
|
-
"--mode",
|
|
180
|
-
"json",
|
|
181
|
-
...buildSeatModelCliArgs(options.model),
|
|
182
|
-
selectResumeContinuationPrompt(options.message),
|
|
183
|
-
];
|
|
184
87
|
}
|
|
185
88
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
code: number | null;
|
|
191
|
-
stderr: string;
|
|
192
|
-
thrown?: unknown;
|
|
193
|
-
knownFailure?: ExplicitInternalKnownFailure;
|
|
194
|
-
knownCause?: ControlledFailureCause;
|
|
195
|
-
knownIdentity?: {
|
|
196
|
-
readonly name?: string;
|
|
197
|
-
readonly code?: string | number;
|
|
198
|
-
};
|
|
199
|
-
knownDiagnostic?: string;
|
|
200
|
-
typedHttpObservationSettled?: true;
|
|
201
|
-
typedHttpObservation?: TypedProviderHttpObservation;
|
|
202
|
-
},
|
|
203
|
-
io: CliIo,
|
|
204
|
-
): Promise<{
|
|
205
|
-
exitCode: number;
|
|
206
|
-
admitted: AdmittedMergerInvocation;
|
|
207
|
-
terminal: TerminalResult;
|
|
208
|
-
}> {
|
|
209
|
-
const hasThrown = Object.hasOwn(failureInput, "thrown");
|
|
210
|
-
const resumeObservation = await resolveControlledFailureResumeObservation({
|
|
211
|
-
runDirectory: admitted.runDirectory,
|
|
212
|
-
...(failureInput.typedHttpObservationSettled === true
|
|
213
|
-
? {
|
|
214
|
-
typedHttpObservationSettled: true as const,
|
|
215
|
-
...(failureInput.typedHttpObservation === undefined
|
|
216
|
-
? {}
|
|
217
|
-
: { typedHttpObservation: failureInput.typedHttpObservation }),
|
|
218
|
-
}
|
|
219
|
-
: {}),
|
|
220
|
-
});
|
|
221
|
-
const knownFailure =
|
|
222
|
-
failureInput.knownFailure ?? resumeObservation.observationReadFailure;
|
|
223
|
-
const session =
|
|
224
|
-
!hasThrown &&
|
|
225
|
-
!failureInput.timedOut &&
|
|
226
|
-
knownFailure === undefined &&
|
|
227
|
-
failureInput.knownCause === undefined
|
|
228
|
-
? await inspectJudgeSession(admitted.sessionFile)
|
|
229
|
-
: undefined;
|
|
230
|
-
const failure = classifyPostAdmissionFailure({
|
|
231
|
-
timedOut: failureInput.timedOut,
|
|
232
|
-
code: failureInput.code,
|
|
233
|
-
stderr: failureInput.stderr,
|
|
234
|
-
...(hasThrown ? { thrown: failureInput.thrown } : {}),
|
|
235
|
-
...explicitInternalKnownFailureClassificationInput(knownFailure),
|
|
236
|
-
...(failureInput.knownCause === undefined
|
|
237
|
-
? {}
|
|
238
|
-
: { knownCause: failureInput.knownCause }),
|
|
239
|
-
...(failureInput.knownIdentity === undefined
|
|
240
|
-
? {}
|
|
241
|
-
: { knownIdentity: failureInput.knownIdentity }),
|
|
242
|
-
...(failureInput.knownDiagnostic === undefined
|
|
243
|
-
? {}
|
|
244
|
-
: { knownDiagnostic: failureInput.knownDiagnostic }),
|
|
245
|
-
...(session === undefined ? {} : { session }),
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
const hasLawfulTerminalResult = await hasLawfulMergerTerminalResult(admitted);
|
|
249
|
-
const typedHttp429 = resumeObservation.typedHttp429;
|
|
250
|
-
const sessionPrincipalAvailable = await isSessionPrincipalAvailable(
|
|
251
|
-
admitted.sessionFile,
|
|
252
|
-
);
|
|
253
|
-
const resumable =
|
|
254
|
-
sessionPrincipalAvailable &&
|
|
255
|
-
isV1ResumableFailure({
|
|
256
|
-
hasLawfulTerminalResult,
|
|
257
|
-
...(typedHttp429 === undefined ? {} : { typedHttp429 }),
|
|
258
|
-
});
|
|
259
|
-
if (resumable && typedHttp429 !== undefined) {
|
|
260
|
-
await markRunResumable(admitted.runDirectory, typedHttp429);
|
|
261
|
-
} else {
|
|
262
|
-
await markRunTerminal(admitted.runDirectory).catch(() => undefined);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
const terminal = await settleFailureTerminalResult(
|
|
266
|
-
admitted,
|
|
267
|
-
failure,
|
|
268
|
-
resumable
|
|
269
|
-
? { resume: { command: renderResumeCommand(admitted.runId) } }
|
|
270
|
-
: {},
|
|
271
|
-
);
|
|
272
|
-
presentFailureTerminal(terminal, io);
|
|
89
|
+
function mergerAdapters(
|
|
90
|
+
packageRoot: string,
|
|
91
|
+
methodMaterial?: PackagedMethodSkillMaterial,
|
|
92
|
+
): PostAdmissionAdapters<AdmittedMergerInvocation> {
|
|
273
93
|
return {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
94
|
+
trySettle: (admitted, authority) =>
|
|
95
|
+
methodMaterial === undefined
|
|
96
|
+
? Promise.resolve(undefined)
|
|
97
|
+
: trySettleMergerTerminalResult(admitted, authority, {
|
|
98
|
+
methodProvenance: methodMaterial.provenance,
|
|
99
|
+
methodSkillPath: methodMaterial.skillPath,
|
|
100
|
+
methodSkillConfiguredPath: resolvePackagedMethodSkillPath(
|
|
101
|
+
packageRoot,
|
|
102
|
+
"resolving-merge-conflicts",
|
|
103
|
+
),
|
|
104
|
+
}),
|
|
105
|
+
shouldPresentSettled: (t) =>
|
|
106
|
+
isLawfulTypedTerminalOutcome(t.roleOutcome) || t.roleOutcome.kind === "incomplete",
|
|
107
|
+
hasLawfulTerminalResult: (admitted, authority) => hasLawfulMergerTerminalResult(admitted, authority),
|
|
108
|
+
isResumableRole: true,
|
|
277
109
|
};
|
|
278
110
|
}
|
|
279
111
|
|
|
280
|
-
async function dispatchAdmittedMerger(input: {
|
|
281
|
-
admitted: AdmittedMergerInvocation;
|
|
282
|
-
env: MergerRunEnv;
|
|
283
|
-
io: CliIo;
|
|
284
|
-
extraArgs: string[];
|
|
285
|
-
lease: RunWriterLease;
|
|
286
|
-
methodMaterial: PackagedMethodSkillMaterial;
|
|
287
|
-
effectiveEngine?: string;
|
|
288
|
-
}): Promise<{
|
|
289
|
-
exitCode: number;
|
|
290
|
-
admitted: AdmittedMergerInvocation;
|
|
291
|
-
terminal?: TerminalResult;
|
|
292
|
-
}> {
|
|
293
|
-
const { admitted, env, io, extraArgs, lease, methodMaterial, effectiveEngine } = input;
|
|
294
|
-
try {
|
|
295
|
-
const missingCredential = missingCredentialPreDispatchFailure(
|
|
296
|
-
env.model,
|
|
297
|
-
env.credentials,
|
|
298
|
-
);
|
|
299
|
-
if (missingCredential !== undefined) {
|
|
300
|
-
return await presentControlledFailure(
|
|
301
|
-
admitted,
|
|
302
|
-
missingCredential,
|
|
303
|
-
io,
|
|
304
|
-
);
|
|
305
|
-
}
|
|
306
|
-
await markRunRunning(admitted.runDirectory, env.model, effectiveEngine);
|
|
307
|
-
await clearTypedProviderHttpObservation(admitted.runDirectory);
|
|
308
|
-
|
|
309
|
-
const childEnv: NodeJS.ProcessEnv = {
|
|
310
|
-
...process.env,
|
|
311
|
-
HOME: env.home,
|
|
312
|
-
PI_CODING_AGENT_DIR: env.agentDir,
|
|
313
|
-
AK_ROLE_RUN_DIR: admitted.runDirectory,
|
|
314
|
-
};
|
|
315
|
-
applyEngineChildEnv(childEnv, env.engine);
|
|
316
|
-
const correlationId = admitted.correlationId ?? env.correlationId;
|
|
317
|
-
if (correlationId !== undefined && correlationId.trim() !== "") {
|
|
318
|
-
childEnv.AK_CORRELATION_ID = correlationId;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
let result: ExplicitInternalPiResult;
|
|
322
|
-
try {
|
|
323
|
-
result = await runExplicitInternalActivation({
|
|
324
|
-
packageRoot: env.packageRoot,
|
|
325
|
-
extraArgs,
|
|
326
|
-
cwd: admitted.projectRoot,
|
|
327
|
-
home: env.home,
|
|
328
|
-
agentDir: env.agentDir,
|
|
329
|
-
env: childEnv,
|
|
330
|
-
timeoutMs: env.timeoutMs,
|
|
331
|
-
...(env.piRunner === undefined ? {} : { runner: env.piRunner }),
|
|
332
|
-
});
|
|
333
|
-
} catch (error) {
|
|
334
|
-
return await presentControlledFailure(
|
|
335
|
-
admitted,
|
|
336
|
-
{
|
|
337
|
-
timedOut: false,
|
|
338
|
-
code: null,
|
|
339
|
-
stderr: "",
|
|
340
|
-
thrown: error,
|
|
341
|
-
},
|
|
342
|
-
io,
|
|
343
|
-
);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
try {
|
|
347
|
-
await writeFile(
|
|
348
|
-
join(admitted.runDirectory, "stderr.log"),
|
|
349
|
-
result.stderr,
|
|
350
|
-
"utf8",
|
|
351
|
-
);
|
|
352
|
-
} catch {
|
|
353
|
-
// continue to lawful / controlled-failure settlement
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
let lawful: TerminalResult | undefined;
|
|
357
|
-
try {
|
|
358
|
-
lawful = await trySettleMergerTerminalResult(admitted, {
|
|
359
|
-
methodProvenance: methodMaterial.provenance,
|
|
360
|
-
methodSkillPath: methodMaterial.skillPath,
|
|
361
|
-
methodSkillConfiguredPath: resolvePackagedMethodSkillPath(
|
|
362
|
-
env.packageRoot,
|
|
363
|
-
"resolving-merge-conflicts",
|
|
364
|
-
),
|
|
365
|
-
});
|
|
366
|
-
} catch (error) {
|
|
367
|
-
return await presentControlledFailure(
|
|
368
|
-
admitted,
|
|
369
|
-
{
|
|
370
|
-
timedOut: false,
|
|
371
|
-
code: result.code,
|
|
372
|
-
stderr: result.stderr,
|
|
373
|
-
thrown: error,
|
|
374
|
-
},
|
|
375
|
-
io,
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
if (lawful !== undefined) {
|
|
379
|
-
await markRunTerminal(admitted.runDirectory).catch(() => undefined);
|
|
380
|
-
io.stdout(formatTerminalResult(lawful));
|
|
381
|
-
return {
|
|
382
|
-
exitCode: exitCodeForTerminalOutcome(lawful.roleOutcome),
|
|
383
|
-
admitted,
|
|
384
|
-
terminal: lawful,
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
const credentialFailure = postRunMissingCredentialFailure(
|
|
389
|
-
result,
|
|
390
|
-
env.model,
|
|
391
|
-
env.credentials,
|
|
392
|
-
);
|
|
393
|
-
const resolution = await resolveAuditedRunnerFailureResolution({
|
|
394
|
-
runner: result.knownFailure,
|
|
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
|
-
}
|
|
412
|
-
}
|
|
413
|
-
|
|
414
112
|
async function loadMergerMethodMaterial(
|
|
415
113
|
packageRoot: string,
|
|
416
114
|
): Promise<PackagedMethodSkillMaterial> {
|
|
@@ -431,11 +129,23 @@ async function admitMergerShellForActivationFailure(options: {
|
|
|
431
129
|
instruction: string;
|
|
432
130
|
project?: string;
|
|
433
131
|
createRunId?: () => string;
|
|
132
|
+
principalAuthority: DurablePrincipalAuthority;
|
|
434
133
|
}): Promise<AdmittedMergerInvocation> {
|
|
435
134
|
const projectRoot = resolve(options.project ?? options.cwd);
|
|
436
135
|
const runId = (options.createRunId ?? uuidv7)();
|
|
437
|
-
const {
|
|
438
|
-
|
|
136
|
+
const {
|
|
137
|
+
principal,
|
|
138
|
+
sessionDirectory,
|
|
139
|
+
sessionFile,
|
|
140
|
+
runDirectory,
|
|
141
|
+
ledgerHome,
|
|
142
|
+
bookKey,
|
|
143
|
+
} = issueAdmissionPlacement(options.principalAuthority, {
|
|
144
|
+
cwd: projectRoot,
|
|
145
|
+
runId,
|
|
146
|
+
role: "merger",
|
|
147
|
+
home: options.home,
|
|
148
|
+
});
|
|
439
149
|
ensureRealDirectoryTree(ledgerHome, sessionDirectory);
|
|
440
150
|
await mkdir(runDirectory, { recursive: true });
|
|
441
151
|
const emptyDerived = {
|
|
@@ -460,6 +170,8 @@ async function admitMergerShellForActivationFailure(options: {
|
|
|
460
170
|
mergerInputPath,
|
|
461
171
|
derived: emptyDerived,
|
|
462
172
|
attachments: [],
|
|
173
|
+
sessionDirectory,
|
|
174
|
+
sessionFile,
|
|
463
175
|
},
|
|
464
176
|
null,
|
|
465
177
|
2,
|
|
@@ -475,14 +187,38 @@ async function admitMergerShellForActivationFailure(options: {
|
|
|
475
187
|
instructionEmpty: false,
|
|
476
188
|
attachments: [],
|
|
477
189
|
runDirectory,
|
|
478
|
-
|
|
479
|
-
sessionFile,
|
|
190
|
+
principal,
|
|
480
191
|
admittedRequestPath,
|
|
481
192
|
mergerInputPath,
|
|
482
193
|
derived: emptyDerived,
|
|
483
194
|
};
|
|
484
195
|
}
|
|
485
196
|
|
|
197
|
+
function mergerTurnOptions(
|
|
198
|
+
admitted: AdmittedMergerInvocation,
|
|
199
|
+
env: MergerRunEnv,
|
|
200
|
+
): {
|
|
201
|
+
packageRoot: string;
|
|
202
|
+
home: string;
|
|
203
|
+
agentDir: string;
|
|
204
|
+
model?: import("./config.ts").SeatModelConfig;
|
|
205
|
+
engine?: string;
|
|
206
|
+
timeoutMs?: number;
|
|
207
|
+
correlationId?: string;
|
|
208
|
+
} {
|
|
209
|
+
return {
|
|
210
|
+
packageRoot: env.packageRoot,
|
|
211
|
+
home: env.home,
|
|
212
|
+
agentDir: env.agentDir,
|
|
213
|
+
...(env.model === undefined ? {} : { model: env.model }),
|
|
214
|
+
...(env.engine === undefined ? {} : { engine: env.engine }),
|
|
215
|
+
...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
|
|
216
|
+
...(admitted.correlationId === undefined && env.correlationId === undefined
|
|
217
|
+
? {}
|
|
218
|
+
: { correlationId: admitted.correlationId ?? env.correlationId }),
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
486
222
|
export async function runPublicMerger(
|
|
487
223
|
argv: readonly string[],
|
|
488
224
|
env: MergerRunEnv,
|
|
@@ -516,6 +252,7 @@ export async function runPublicMerger(
|
|
|
516
252
|
try {
|
|
517
253
|
admitted = await admitMergerInvocation({
|
|
518
254
|
home: env.home,
|
|
255
|
+
principalAuthority: env.principalAuthority,
|
|
519
256
|
cwd: env.cwd,
|
|
520
257
|
instruction: parsed.instruction,
|
|
521
258
|
attachmentPaths: parsed.attachmentPaths,
|
|
@@ -529,10 +266,9 @@ export async function runPublicMerger(
|
|
|
529
266
|
return { exitCode: 2 };
|
|
530
267
|
}
|
|
531
268
|
if (error instanceof MergerEnvelopeDerivationError) {
|
|
532
|
-
// No active merge / incomplete conflict set: honest activation failure.
|
|
533
|
-
// Place a shell admitted run so Terminal identity stays role-correct.
|
|
534
269
|
const shell = await admitMergerShellForActivationFailure({
|
|
535
270
|
home: env.home,
|
|
271
|
+
principalAuthority: env.principalAuthority,
|
|
536
272
|
cwd: env.cwd,
|
|
537
273
|
instruction: parsed.instruction,
|
|
538
274
|
...(parsed.project === undefined ? {} : { project: parsed.project }),
|
|
@@ -540,8 +276,8 @@ export async function runPublicMerger(
|
|
|
540
276
|
? {}
|
|
541
277
|
: { createRunId: env.createRunId }),
|
|
542
278
|
});
|
|
543
|
-
await markRunAdmitted(shell);
|
|
544
|
-
return await presentControlledFailure(
|
|
279
|
+
await markRunAdmitted(shell, env.principalAuthority);
|
|
280
|
+
return (await presentControlledFailure(
|
|
545
281
|
shell,
|
|
546
282
|
{
|
|
547
283
|
timedOut: false,
|
|
@@ -551,19 +287,21 @@ export async function runPublicMerger(
|
|
|
551
287
|
knownCause: "activation",
|
|
552
288
|
knownDiagnostic: error.message,
|
|
553
289
|
},
|
|
290
|
+
mergerAdapters(env.packageRoot),
|
|
291
|
+
env.principalAuthority,
|
|
554
292
|
io,
|
|
555
|
-
);
|
|
293
|
+
)) as { exitCode: number; admitted: AdmittedMergerInvocation; terminal: TerminalResult };
|
|
556
294
|
}
|
|
557
295
|
throw error;
|
|
558
296
|
}
|
|
559
297
|
|
|
560
|
-
await markRunAdmitted(admitted);
|
|
298
|
+
await markRunAdmitted(admitted, env.principalAuthority);
|
|
561
299
|
|
|
562
300
|
let methodMaterial: PackagedMethodSkillMaterial;
|
|
563
301
|
try {
|
|
564
302
|
methodMaterial = await loadMergerMethodMaterial(env.packageRoot);
|
|
565
303
|
} catch (error) {
|
|
566
|
-
return await presentControlledFailure(
|
|
304
|
+
return (await presentControlledFailure(
|
|
567
305
|
admitted,
|
|
568
306
|
{
|
|
569
307
|
timedOut: false,
|
|
@@ -572,41 +310,48 @@ export async function runPublicMerger(
|
|
|
572
310
|
thrown: error,
|
|
573
311
|
knownCause: "activation",
|
|
574
312
|
},
|
|
313
|
+
mergerAdapters(env.packageRoot),
|
|
314
|
+
env.principalAuthority,
|
|
575
315
|
io,
|
|
576
|
-
);
|
|
316
|
+
)) as { exitCode: number; admitted: AdmittedMergerInvocation; terminal: TerminalResult };
|
|
577
317
|
}
|
|
578
318
|
|
|
579
|
-
return
|
|
319
|
+
return await runPostAdmissionResumable({
|
|
580
320
|
admitted,
|
|
321
|
+
env,
|
|
581
322
|
io,
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
323
|
+
buildInitialRequest: () =>
|
|
324
|
+
buildMergerTurnRequest(admitted, {
|
|
325
|
+
...mergerTurnOptions(admitted, env),
|
|
326
|
+
continuation: {
|
|
327
|
+
kind: "initial",
|
|
328
|
+
prompt: buildMergerTransportPrompt(
|
|
329
|
+
admitted,
|
|
330
|
+
engineSessionMaterialFromOptions({
|
|
331
|
+
...(env.engine === undefined ? {} : { engine: env.engine }),
|
|
332
|
+
packageRoot: env.packageRoot,
|
|
333
|
+
}),
|
|
334
|
+
),
|
|
335
|
+
},
|
|
590
336
|
}),
|
|
591
|
-
|
|
592
|
-
|
|
337
|
+
buildResumeRequest: () =>
|
|
338
|
+
buildMergerTurnRequest(admitted, {
|
|
593
339
|
packageRoot: env.packageRoot,
|
|
340
|
+
home: env.home,
|
|
341
|
+
agentDir: env.agentDir,
|
|
594
342
|
...(env.model === undefined ? {} : { model: env.model }),
|
|
595
|
-
...(env.
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
343
|
+
...(env.engine === undefined ? {} : { engine: env.engine }),
|
|
344
|
+
...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
|
|
345
|
+
...(admitted.correlationId === undefined && env.correlationId === undefined
|
|
346
|
+
? {}
|
|
347
|
+
: { correlationId: admitted.correlationId ?? env.correlationId }),
|
|
348
|
+
continuation: {
|
|
349
|
+
kind: "resume",
|
|
350
|
+
prompt: selectResumeContinuationPrompt(),
|
|
603
351
|
},
|
|
604
|
-
io: attemptIo,
|
|
605
|
-
extraArgs,
|
|
606
|
-
lease,
|
|
607
|
-
methodMaterial,
|
|
608
|
-
...(isFirst && env.engine !== undefined ? { effectiveEngine: env.engine } : {}),
|
|
609
352
|
}),
|
|
353
|
+
adapters: mergerAdapters(env.packageRoot, methodMaterial),
|
|
354
|
+
...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
|
|
610
355
|
});
|
|
611
356
|
}
|
|
612
357
|
|
|
@@ -625,7 +370,7 @@ export async function runPublicMergerResume(
|
|
|
625
370
|
}> {
|
|
626
371
|
let loaded;
|
|
627
372
|
try {
|
|
628
|
-
loaded = await loadResumableMergerRun(env.home, request.runId);
|
|
373
|
+
loaded = await loadResumableMergerRun(env.home, request.runId, env.principalAuthority);
|
|
629
374
|
} catch (error) {
|
|
630
375
|
if (error instanceof CliUsageError) {
|
|
631
376
|
presentStructuralRejection(error, io);
|
|
@@ -636,23 +381,11 @@ export async function runPublicMergerResume(
|
|
|
636
381
|
|
|
637
382
|
const { admitted } = loaded;
|
|
638
383
|
|
|
639
|
-
let lease: RunWriterLease;
|
|
640
|
-
try {
|
|
641
|
-
lease = await acquireRunWriterLease(admitted.runDirectory, (diagnostic) => io.stderr(diagnostic));
|
|
642
|
-
} catch (error) {
|
|
643
|
-
if (error instanceof RunWriterLeaseHeldError) {
|
|
644
|
-
io.stderr(formatCliDiagnostic(error.message));
|
|
645
|
-
return { exitCode: 1 };
|
|
646
|
-
}
|
|
647
|
-
throw error;
|
|
648
|
-
}
|
|
649
|
-
|
|
650
384
|
let methodMaterial: PackagedMethodSkillMaterial;
|
|
651
385
|
try {
|
|
652
386
|
methodMaterial = await loadMergerMethodMaterial(env.packageRoot);
|
|
653
387
|
} catch (error) {
|
|
654
|
-
await
|
|
655
|
-
return await presentControlledFailure(
|
|
388
|
+
return (await presentControlledFailure(
|
|
656
389
|
admitted,
|
|
657
390
|
{
|
|
658
391
|
timedOut: false,
|
|
@@ -661,30 +394,35 @@ export async function runPublicMergerResume(
|
|
|
661
394
|
thrown: error,
|
|
662
395
|
knownCause: "activation",
|
|
663
396
|
},
|
|
397
|
+
mergerAdapters(env.packageRoot),
|
|
398
|
+
env.principalAuthority,
|
|
664
399
|
io,
|
|
665
|
-
);
|
|
400
|
+
)) as { exitCode: number; admitted: AdmittedMergerInvocation; terminal: TerminalResult };
|
|
666
401
|
}
|
|
667
402
|
|
|
668
|
-
const
|
|
403
|
+
const turnRequest = buildMergerTurnRequest(admitted, {
|
|
669
404
|
packageRoot: env.packageRoot,
|
|
405
|
+
home: env.home,
|
|
406
|
+
agentDir: env.agentDir,
|
|
670
407
|
...(env.model === undefined ? {} : { model: env.model }),
|
|
671
|
-
...(env.
|
|
672
|
-
...(
|
|
408
|
+
...(env.engine === undefined ? {} : { engine: env.engine }),
|
|
409
|
+
...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
|
|
410
|
+
...(admitted.correlationId === undefined && env.correlationId === undefined
|
|
411
|
+
? {}
|
|
412
|
+
: { correlationId: admitted.correlationId ?? env.correlationId }),
|
|
413
|
+
continuation: {
|
|
414
|
+
kind: "resume",
|
|
415
|
+
prompt: selectResumeContinuationPrompt(request.message),
|
|
416
|
+
},
|
|
673
417
|
});
|
|
674
418
|
|
|
675
|
-
|
|
419
|
+
return await runPostAdmissionManualResume({
|
|
676
420
|
admitted,
|
|
677
|
-
env
|
|
678
|
-
...env,
|
|
679
|
-
...(admitted.correlationId === undefined ? {} : { correlationId: admitted.correlationId }),
|
|
680
|
-
},
|
|
421
|
+
env,
|
|
681
422
|
io,
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
methodMaterial,
|
|
423
|
+
request: turnRequest,
|
|
424
|
+
adapters: mergerAdapters(env.packageRoot, methodMaterial),
|
|
685
425
|
});
|
|
686
|
-
if (result.terminal !== undefined) (result.terminal as { autoResumeCount?: number }).autoResumeCount = 0;
|
|
687
|
-
return result;
|
|
688
426
|
}
|
|
689
427
|
|
|
690
|
-
export type {
|
|
428
|
+
export type { RoleTurnKnownFailure, PackagedMethodSkillProvenance };
|