@akagilnc/pi-workflow-roles 0.1.5245 → 0.1.5270
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/dist/acp-host/production-host.js +125 -217
- package/dist/headless-host/production-host.js +381 -470
- package/dist/host-descriptions.js +0 -2
- package/dist/navigator-invocation-identity.js +0 -57
- package/dist/navigator-public-session.js +6 -1
- package/dist/pi/durable-principal.js +1 -12
- package/dist/public-cli/auto-resume.js +59 -87
- package/dist/public-cli/instruction-seat-run.js +3 -3
- package/dist/public-cli/main.js +86 -206
- package/dist/public-cli/post-admission.js +7 -15
- package/dist/public-cli/run-lifecycle.js +5 -15
- package/dist/public-cli/settlement.js +10 -59
- package/dist/public-cli/terminal.js +4 -2
- package/dist/session-identity.js +0 -18
- package/package.json +1 -1
- package/src/acp-host/description.ts +0 -2
- package/src/acp-host/production-host.ts +0 -1
- package/src/acp-host/role-turn-host.ts +12 -6
- package/src/headless-host/role-turn-host.ts +11 -3
- package/src/host-contracts.ts +0 -1
- package/src/host-descriptions.ts +0 -2
- package/src/navigator-invocation-identity.ts +4 -121
- package/src/navigator-public-session.ts +12 -1
- package/src/pi/durable-principal.ts +1 -11
- package/src/prepared-role-turn.ts +1 -1
- package/src/public-cli/auto-resume.ts +67 -109
- package/src/public-cli/instruction-seat-run.ts +3 -3
- package/src/public-cli/post-admission.ts +7 -21
- package/src/public-cli/run-lifecycle.ts +3 -21
- package/src/public-cli/settlement.ts +8 -75
- package/src/public-cli/terminal.ts +4 -2
- package/src/role-envelope.ts +3 -3
- package/src/role-runtime.ts +23 -5
- package/src/session-identity.ts +0 -22
package/dist/public-cli/main.js
CHANGED
|
@@ -538,7 +538,6 @@ __export(durable_principal_exports, {
|
|
|
538
538
|
issuePiDurablePrincipalCoordinates: () => issuePiDurablePrincipalCoordinates,
|
|
539
539
|
piDurablePrincipalAuthority: () => piDurablePrincipalAuthority
|
|
540
540
|
});
|
|
541
|
-
import { lstat } from "node:fs/promises";
|
|
542
541
|
import { join as join5 } from "node:path";
|
|
543
542
|
function encode(coordinates) {
|
|
544
543
|
return coordinates;
|
|
@@ -591,15 +590,6 @@ var init_durable_principal = __esm({
|
|
|
591
590
|
sessionDirectory: record4.sessionDirectory,
|
|
592
591
|
sessionFile: typeof record4.sessionFile === "string" && record4.sessionFile.trim() !== "" ? record4.sessionFile : join5(record4.sessionDirectory, "session.jsonl")
|
|
593
592
|
};
|
|
594
|
-
},
|
|
595
|
-
async isAvailable(principal) {
|
|
596
|
-
const { sessionFile } = this.decode(principal);
|
|
597
|
-
try {
|
|
598
|
-
const stat2 = await lstat(sessionFile);
|
|
599
|
-
return stat2.isFile() && !stat2.isSymbolicLink();
|
|
600
|
-
} catch {
|
|
601
|
-
return false;
|
|
602
|
-
}
|
|
603
593
|
}
|
|
604
594
|
};
|
|
605
595
|
}
|
|
@@ -15828,7 +15818,6 @@ var init_host_descriptions = __esm({
|
|
|
15828
15818
|
modelFlag: "--model"
|
|
15829
15819
|
}),
|
|
15830
15820
|
modelPassing: "argv",
|
|
15831
|
-
boundResume: "session/load",
|
|
15832
15821
|
sessionBindingFile: "grok-acp-session.json"
|
|
15833
15822
|
}),
|
|
15834
15823
|
/**
|
|
@@ -15846,7 +15835,6 @@ var init_host_descriptions = __esm({
|
|
|
15846
15835
|
thinkingFlag: "--reasoning"
|
|
15847
15836
|
}),
|
|
15848
15837
|
modelPassing: "set_model",
|
|
15849
|
-
boundResume: "session/load",
|
|
15850
15838
|
sessionBindingFile: "hermes-acp-session.json",
|
|
15851
15839
|
seatProfileSoul: Object.freeze({
|
|
15852
15840
|
flag: "-p",
|
|
@@ -16618,7 +16606,7 @@ var init_cli_errors = __esm({
|
|
|
16618
16606
|
|
|
16619
16607
|
// src/public-cli/machine-method-skills.ts
|
|
16620
16608
|
import { accessSync, constants, statSync as statSync2 } from "node:fs";
|
|
16621
|
-
import { lstat
|
|
16609
|
+
import { lstat, mkdir as mkdir2, symlink } from "node:fs/promises";
|
|
16622
16610
|
import { join as join9 } from "node:path";
|
|
16623
16611
|
import { spawnSync } from "node:child_process";
|
|
16624
16612
|
function skillRoot(home) {
|
|
@@ -16648,7 +16636,7 @@ function linkedSkillRoot(home, host) {
|
|
|
16648
16636
|
}
|
|
16649
16637
|
async function occupied(path) {
|
|
16650
16638
|
try {
|
|
16651
|
-
await
|
|
16639
|
+
await lstat(path);
|
|
16652
16640
|
return true;
|
|
16653
16641
|
} catch (error) {
|
|
16654
16642
|
if (error.code !== "ENOENT") throw error;
|
|
@@ -17371,8 +17359,8 @@ function formatTerminalResult(result) {
|
|
|
17371
17359
|
`diagnostic ${encodeTerminalField(result.roleOutcome.diagnostic)}`
|
|
17372
17360
|
);
|
|
17373
17361
|
}
|
|
17374
|
-
if (result.roleOutcome.kind === "failure" || result.roleOutcome.kind === "no_receipt" || result.roleOutcome.kind === "audit_escalation") {
|
|
17375
|
-
const facts = result.roleOutcome.decisiveFacts ?? {};
|
|
17362
|
+
if (result.roleOutcome.kind === "failure" || result.roleOutcome.kind === "no_receipt" || result.roleOutcome.kind === "audit_escalation" || result.roleOutcome.decisiveFacts?.failedAttempts !== void 0) {
|
|
17363
|
+
const facts = result.roleOutcome.kind === "accepted" ? { failedAttempts: result.roleOutcome.decisiveFacts?.failedAttempts } : result.roleOutcome.decisiveFacts ?? {};
|
|
17376
17364
|
for (const [key, value] of Object.entries(facts)) {
|
|
17377
17365
|
if (value === void 0) continue;
|
|
17378
17366
|
const rendered = typeof value === "string" ? value : JSON.stringify(value);
|
|
@@ -18798,7 +18786,7 @@ var init_uuidv7 = __esm({
|
|
|
18798
18786
|
|
|
18799
18787
|
// src/notary-source-run.ts
|
|
18800
18788
|
import { dirname as dirname11, isAbsolute as isAbsolute5, join as join17, resolve as resolve8, basename as basename5 } from "node:path";
|
|
18801
|
-
import { lstat as
|
|
18789
|
+
import { lstat as lstat2, realpath as realpath3 } from "node:fs/promises";
|
|
18802
18790
|
async function readRetainedIdentity(runDirectory) {
|
|
18803
18791
|
try {
|
|
18804
18792
|
return await readRoleRunIdentity(runDirectory);
|
|
@@ -18826,7 +18814,7 @@ async function requireRunDirectory(candidate, display) {
|
|
|
18826
18814
|
}
|
|
18827
18815
|
let stat2;
|
|
18828
18816
|
try {
|
|
18829
|
-
stat2 = await
|
|
18817
|
+
stat2 = await lstat2(real);
|
|
18830
18818
|
} catch (error) {
|
|
18831
18819
|
throw new NotarySourceRunError(
|
|
18832
18820
|
`notary --source-run is not a readable run directory: ${display}`,
|
|
@@ -19965,7 +19953,7 @@ var init_option_definitions = __esm({
|
|
|
19965
19953
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
19966
19954
|
import { existsSync as existsSync4 } from "node:fs";
|
|
19967
19955
|
import {
|
|
19968
|
-
lstat as
|
|
19956
|
+
lstat as lstat3,
|
|
19969
19957
|
mkdtemp,
|
|
19970
19958
|
readFile as readFile12,
|
|
19971
19959
|
realpath as realpath4,
|
|
@@ -20527,7 +20515,7 @@ async function readRegularFileAttachment(sourcePath) {
|
|
|
20527
20515
|
const absolute = isAbsolute6(sourcePath) ? sourcePath : resolve9(sourcePath);
|
|
20528
20516
|
let st;
|
|
20529
20517
|
try {
|
|
20530
|
-
st = await
|
|
20518
|
+
st = await lstat3(absolute);
|
|
20531
20519
|
} catch (error) {
|
|
20532
20520
|
throw new CliUsageError(
|
|
20533
20521
|
`attachment is not a readable regular file: ${sourcePath}`,
|
|
@@ -23840,11 +23828,6 @@ async function appendRunAttemptHistory(source, outcome) {
|
|
|
23840
23828
|
} catch {
|
|
23841
23829
|
}
|
|
23842
23830
|
}
|
|
23843
|
-
function navigatorAttendanceCorrelatedWithBoundMarker(details, attendanceIndex, terminalIndex, marker) {
|
|
23844
|
-
if (attendanceIndex <= terminalIndex) return false;
|
|
23845
|
-
if (details.invocationId !== marker.invocationId) return false;
|
|
23846
|
-
return true;
|
|
23847
|
-
}
|
|
23848
23831
|
function parseNavigatorAttendanceDetails(details) {
|
|
23849
23832
|
const disposition = details.disposition;
|
|
23850
23833
|
const advisoryDiagnostic = typeof details.routePlaybookReadFailure === "string" ? { advisoryDiagnostic: details.routePlaybookReadFailure } : {};
|
|
@@ -23995,54 +23978,12 @@ function extractNavigatorAttendanceFact(entries) {
|
|
|
23995
23978
|
reason: "Navigator attendance has no durable packaged role terminal"
|
|
23996
23979
|
};
|
|
23997
23980
|
}
|
|
23998
|
-
let
|
|
23999
|
-
for (let i = terminal.index - 1; i >= 0; i -= 1) {
|
|
23981
|
+
for (let i = terminal.index; i < entries.length; i += 1) {
|
|
24000
23982
|
const entry = entries[i];
|
|
24001
|
-
if (entry?.type
|
|
24002
|
-
|
|
24003
|
-
|
|
24004
|
-
|
|
24005
|
-
}
|
|
24006
|
-
if (markerIndex < 0) {
|
|
24007
|
-
return {
|
|
24008
|
-
disposition: "unavailable",
|
|
24009
|
-
source: "unknown",
|
|
24010
|
-
reason: "Navigator attendance is uncorrelated with session invocation facts"
|
|
24011
|
-
};
|
|
24012
|
-
}
|
|
24013
|
-
const marker = parseInvocationMarkerIdentity(entries[markerIndex]?.data);
|
|
24014
|
-
if (marker === void 0) {
|
|
24015
|
-
return {
|
|
24016
|
-
disposition: "unavailable",
|
|
24017
|
-
source: "unknown",
|
|
24018
|
-
reason: "Navigator attendance is uncorrelated with session invocation facts"
|
|
24019
|
-
};
|
|
24020
|
-
}
|
|
24021
|
-
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
24022
|
-
const entry = entries[i];
|
|
24023
|
-
if (entry?.type === "custom_message" && entry.customType === "ak-navigator-attendance") {
|
|
24024
|
-
const details = entry.message?.details ?? entry.details;
|
|
24025
|
-
if (!isRecord8(details)) {
|
|
24026
|
-
return {
|
|
24027
|
-
disposition: "unavailable",
|
|
24028
|
-
source: "unknown",
|
|
24029
|
-
reason: "Navigator attendance is unparseable"
|
|
24030
|
-
};
|
|
24031
|
-
}
|
|
24032
|
-
if (!navigatorAttendanceCorrelatedWithBoundMarker(
|
|
24033
|
-
details,
|
|
24034
|
-
i,
|
|
24035
|
-
terminal.index,
|
|
24036
|
-
marker
|
|
24037
|
-
)) {
|
|
24038
|
-
return {
|
|
24039
|
-
disposition: "unavailable",
|
|
24040
|
-
source: "unknown",
|
|
24041
|
-
reason: "Navigator attendance is uncorrelated with session invocation facts"
|
|
24042
|
-
};
|
|
24043
|
-
}
|
|
24044
|
-
return parseNavigatorAttendanceDetails(details);
|
|
24045
|
-
}
|
|
23983
|
+
if (entry?.type !== "custom" || entry.customType !== "ak-role-submission-closure") continue;
|
|
23984
|
+
const details = isRecord8(entry.data) ? entry.data.navigator : void 0;
|
|
23985
|
+
if (!isRecord8(details)) break;
|
|
23986
|
+
return parseNavigatorAttendanceDetails(details);
|
|
24046
23987
|
}
|
|
24047
23988
|
return {
|
|
24048
23989
|
disposition: "unavailable",
|
|
@@ -26080,7 +26021,7 @@ async function runPublicInstructionSeatResume(request, env, io) {
|
|
|
26080
26021
|
};
|
|
26081
26022
|
let binding;
|
|
26082
26023
|
try {
|
|
26083
|
-
const loaded = await loadResumablePublicRole(env.home, request.runId, env.principalAuthority
|
|
26024
|
+
const loaded = await loadResumablePublicRole(env.home, request.runId, env.principalAuthority);
|
|
26084
26025
|
binding = loaded.admitted.role === "auditor" ? await readAuditorResumeBinding(loaded.admitted.runDirectory) : void 0;
|
|
26085
26026
|
} catch (error) {
|
|
26086
26027
|
if (!(error instanceof CliUsageError)) throw error;
|
|
@@ -26123,7 +26064,7 @@ async function queueConclusionFromChild(child, env, io) {
|
|
|
26123
26064
|
}
|
|
26124
26065
|
}
|
|
26125
26066
|
async function continueParentAfterChild(parentRunId, child, env, io) {
|
|
26126
|
-
const loaded = await loadResumablePublicRole(env.home, parentRunId, env.principalAuthority
|
|
26067
|
+
const loaded = await loadResumablePublicRole(env.home, parentRunId, env.principalAuthority);
|
|
26127
26068
|
if (loaded.run.state !== "admitted" && !AUDITED_ROLES.has(loaded.admitted.role)) {
|
|
26128
26069
|
return runPublicInstructionSeatResume({ runId: parentRunId }, env, io);
|
|
26129
26070
|
}
|
|
@@ -26318,7 +26259,7 @@ async function auditSubmittedRole(turn, env, io, passedOfficer, passedReceipt, p
|
|
|
26318
26259
|
const escalation = chain.passes.at(-1);
|
|
26319
26260
|
const escalatedRunId = escalation?.runId ?? (escalation?.runDirectory === void 0 ? void 0 : runIdFromRunDirectory(escalation.runDirectory));
|
|
26320
26261
|
if (escalatedRunId === void 0) throw new Error("escalated audit has no resumable run identity");
|
|
26321
|
-
const officer = await loadResumablePublicRole(env.home, escalatedRunId, env.principalAuthority
|
|
26262
|
+
const officer = await loadResumablePublicRole(env.home, escalatedRunId, env.principalAuthority);
|
|
26322
26263
|
const terminal2 = await trySettlePublicSeat(officer.admitted, env.principalAuthority, void 0);
|
|
26323
26264
|
if (terminal2 === void 0) throw new Error("escalated audit has no terminal result");
|
|
26324
26265
|
io.stdout(formatTerminalResult(terminal2));
|
|
@@ -27185,7 +27126,6 @@ __export(run_lifecycle_exports, {
|
|
|
27185
27126
|
describeErrorIdentity: () => describeErrorIdentity,
|
|
27186
27127
|
findLatestRunIdForSeatTicket: () => findLatestRunIdForSeatTicket,
|
|
27187
27128
|
findRunDirectoryById: () => findRunDirectoryById,
|
|
27188
|
-
isDurablePrincipalAvailable: () => isDurablePrincipalAvailable,
|
|
27189
27129
|
isV1ResumableProvider: () => isV1ResumableProvider,
|
|
27190
27130
|
loadResumablePublicRole: () => loadResumablePublicRole,
|
|
27191
27131
|
markRunAdmitted: () => markRunAdmitted,
|
|
@@ -27205,7 +27145,7 @@ __export(run_lifecycle_exports, {
|
|
|
27205
27145
|
renderResumeCommand: () => renderResumeCommand,
|
|
27206
27146
|
writeRoleRunState: () => writeRoleRunState
|
|
27207
27147
|
});
|
|
27208
|
-
import { chmod, lstat as
|
|
27148
|
+
import { chmod, lstat as lstat5, open, readdir as readdir6, readFile as readFile16, unlink as unlink4, writeFile as writeFile5 } from "node:fs/promises";
|
|
27209
27149
|
import { basename as basename8, join as join30 } from "node:path";
|
|
27210
27150
|
function buildAutoResumeContinuationPrompt(options) {
|
|
27211
27151
|
return appendEngineSessionMaterial(
|
|
@@ -27519,9 +27459,6 @@ async function clearCurrentCourt(runDirectory, expectedCourtAttemptId) {
|
|
|
27519
27459
|
...current.resumable === void 0 ? {} : { resumable: current.resumable }
|
|
27520
27460
|
});
|
|
27521
27461
|
}
|
|
27522
|
-
async function isDurablePrincipalAvailable(principal, authority) {
|
|
27523
|
-
return authority.isAvailable(principal);
|
|
27524
|
-
}
|
|
27525
27462
|
function describeErrorIdentity(error) {
|
|
27526
27463
|
const candidate = error;
|
|
27527
27464
|
const name = typeof candidate?.name === "string" && candidate.name !== "" ? candidate.name : typeof error;
|
|
@@ -27763,7 +27700,7 @@ async function runHasFormedSessionPrincipal(runDirectory) {
|
|
|
27763
27700
|
if (disk === void 0) return false;
|
|
27764
27701
|
const sessionFile = typeof disk.principalWire.sessionFile === "string" && disk.principalWire.sessionFile.trim() !== "" ? disk.principalWire.sessionFile : join30(disk.principalWire.sessionDirectory, "session.jsonl");
|
|
27765
27702
|
try {
|
|
27766
|
-
const stat2 = await
|
|
27703
|
+
const stat2 = await lstat5(sessionFile);
|
|
27767
27704
|
return stat2.isFile() && !stat2.isSymbolicLink();
|
|
27768
27705
|
} catch (error) {
|
|
27769
27706
|
if (errorCodeOf(error) === "ENOENT") return false;
|
|
@@ -27855,7 +27792,7 @@ function restoredTicketFields(fields) {
|
|
|
27855
27792
|
...fields.courtTicketNumbers === void 0 ? {} : { courtTicketNumbers: fields.courtTicketNumbers }
|
|
27856
27793
|
};
|
|
27857
27794
|
}
|
|
27858
|
-
async function loadResumableRunRecord(home, runId, authority
|
|
27795
|
+
async function loadResumableRunRecord(home, runId, authority) {
|
|
27859
27796
|
const runDirectory = await findRunDirectoryById(home, runId);
|
|
27860
27797
|
if (runDirectory === void 0) {
|
|
27861
27798
|
throw new CliUsageError(`unknown role run id: ${runId}`);
|
|
@@ -27869,11 +27806,6 @@ async function loadResumableRunRecord(home, runId, authority, allowUnformedAdmit
|
|
|
27869
27806
|
throw new CliUsageError(`unknown role run id: ${runId}`);
|
|
27870
27807
|
}
|
|
27871
27808
|
const { run, principal } = materialized;
|
|
27872
|
-
if (!(allowUnformedAdmitted && run.state === "admitted") && !await isDurablePrincipalAvailable(principal, authority)) {
|
|
27873
|
-
throw new CliUsageError(
|
|
27874
|
-
`role run Pi session principal is unavailable: ${runId}`
|
|
27875
|
-
);
|
|
27876
|
-
}
|
|
27877
27809
|
let instruction = "";
|
|
27878
27810
|
let instructionEmpty = true;
|
|
27879
27811
|
let attachments = [];
|
|
@@ -28150,8 +28082,8 @@ async function peekRoleRunRole(home, runId) {
|
|
|
28150
28082
|
const run = await readRoleRunIdentity(runDirectory);
|
|
28151
28083
|
return run?.role;
|
|
28152
28084
|
}
|
|
28153
|
-
async function loadResumablePublicRole(home, runId, authority
|
|
28154
|
-
const loaded = await loadResumableRunRecord(home, runId, authority
|
|
28085
|
+
async function loadResumablePublicRole(home, runId, authority) {
|
|
28086
|
+
const loaded = await loadResumableRunRecord(home, runId, authority);
|
|
28155
28087
|
return seatLoadedResult(loaded, admitResumedRole(loaded));
|
|
28156
28088
|
}
|
|
28157
28089
|
function admitResumedRole(loaded) {
|
|
@@ -28443,12 +28375,6 @@ function createSessionIdentityAuthority(authority, sessionBindingFile) {
|
|
|
28443
28375
|
}
|
|
28444
28376
|
};
|
|
28445
28377
|
}
|
|
28446
|
-
function resolveHostAwareSessionAvailability(host, principalAuthority) {
|
|
28447
|
-
if (host === void 0 || host === DEFAULT_ROLE_TURN_HOST) {
|
|
28448
|
-
return (principal) => principalAuthority.isAvailable(principal);
|
|
28449
|
-
}
|
|
28450
|
-
return async (principal) => await readStoredHostSessionId(host, principalAuthority, principal) !== void 0;
|
|
28451
|
-
}
|
|
28452
28378
|
async function readStoredHostSessionId(host, authority, principal) {
|
|
28453
28379
|
if (host === void 0 || host === DEFAULT_ROLE_TURN_HOST) return void 0;
|
|
28454
28380
|
const description = lookupHostDescription(host) ?? lookupHeadlessHostDescription(host);
|
|
@@ -28556,9 +28482,9 @@ var init_host_session_record = __esm({
|
|
|
28556
28482
|
// src/public-cli/auto-resume.ts
|
|
28557
28483
|
import { constants as fsConstants2 } from "node:fs";
|
|
28558
28484
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
28559
|
-
import { lstat as
|
|
28485
|
+
import { lstat as lstat6, mkdir as mkdir4, open as open2 } from "node:fs/promises";
|
|
28560
28486
|
import { join as join33 } from "node:path";
|
|
28561
|
-
async function persistReturnedRunState(admitted,
|
|
28487
|
+
async function persistReturnedRunState(admitted, options) {
|
|
28562
28488
|
if (options?.lawful === true) {
|
|
28563
28489
|
await markRunTerminal(admitted.runDirectory);
|
|
28564
28490
|
return;
|
|
@@ -28568,10 +28494,8 @@ async function persistReturnedRunState(admitted, authority, options) {
|
|
|
28568
28494
|
});
|
|
28569
28495
|
const typedHttp429 = resumeObservation.typedHttp429;
|
|
28570
28496
|
if (admitted.principal !== void 0 && typedHttp429 !== void 0) {
|
|
28571
|
-
|
|
28572
|
-
|
|
28573
|
-
return;
|
|
28574
|
-
}
|
|
28497
|
+
await markRunResumable(admitted.runDirectory, typedHttp429);
|
|
28498
|
+
return;
|
|
28575
28499
|
}
|
|
28576
28500
|
await markRunTerminal(admitted.runDirectory);
|
|
28577
28501
|
}
|
|
@@ -28593,20 +28517,20 @@ async function finalizeExceptionRunBestEffort(runDirectory, io) {
|
|
|
28593
28517
|
}
|
|
28594
28518
|
}
|
|
28595
28519
|
async function ensureRealArtifactsDirectory(runDirectory) {
|
|
28596
|
-
const runStat = await
|
|
28520
|
+
const runStat = await lstat6(runDirectory);
|
|
28597
28521
|
if (runStat.isSymbolicLink() || !runStat.isDirectory()) {
|
|
28598
28522
|
throw new Error("run artifact retention: run directory is not a real directory");
|
|
28599
28523
|
}
|
|
28600
28524
|
const artifactsDir = roleRunArtifactsDirectory(runDirectory);
|
|
28601
28525
|
try {
|
|
28602
|
-
const existing = await
|
|
28526
|
+
const existing = await lstat6(artifactsDir);
|
|
28603
28527
|
if (existing.isSymbolicLink() || !existing.isDirectory()) {
|
|
28604
28528
|
throw new Error("run artifact retention: artifacts path is not a real directory");
|
|
28605
28529
|
}
|
|
28606
28530
|
} catch (error) {
|
|
28607
28531
|
if (!isMissingPathError5(error)) throw error;
|
|
28608
28532
|
await mkdir4(artifactsDir, { recursive: true });
|
|
28609
|
-
const created = await
|
|
28533
|
+
const created = await lstat6(artifactsDir);
|
|
28610
28534
|
if (created.isSymbolicLink() || !created.isDirectory()) {
|
|
28611
28535
|
throw new Error("run artifact retention: artifacts directory is not a real directory");
|
|
28612
28536
|
}
|
|
@@ -28737,7 +28661,6 @@ function dispatchExceptionFailureTerminal(input) {
|
|
|
28737
28661
|
async function runWithAutoResumeLoop(options) {
|
|
28738
28662
|
const limit = options.autoResumeLimit ?? AUTO_RESUME_LIMIT;
|
|
28739
28663
|
parseAutoResumeLimit(limit);
|
|
28740
|
-
const isPrincipalAvailable = options.isPrincipalAvailable ?? ((principal) => options.principalAuthority.isAvailable(principal));
|
|
28741
28664
|
let autoResumeAttempts = 0;
|
|
28742
28665
|
let isFirst = true;
|
|
28743
28666
|
let currentPayload = options.buildInitialPayload();
|
|
@@ -28745,6 +28668,9 @@ async function runWithAutoResumeLoop(options) {
|
|
|
28745
28668
|
let lastThrownError;
|
|
28746
28669
|
let everyAttemptThrew = true;
|
|
28747
28670
|
const retainedErrorFiles = [];
|
|
28671
|
+
const failedAttempts = [];
|
|
28672
|
+
let stoppedResult;
|
|
28673
|
+
let endReason;
|
|
28748
28674
|
while (true) {
|
|
28749
28675
|
let result;
|
|
28750
28676
|
let turnStartedBeforeThrow = false;
|
|
@@ -28753,6 +28679,11 @@ async function runWithAutoResumeLoop(options) {
|
|
|
28753
28679
|
result = await options.dispatch(currentPayload, lease, isFirst, dummyIo);
|
|
28754
28680
|
} catch (error) {
|
|
28755
28681
|
lastThrownError = error;
|
|
28682
|
+
const failedAttempt = {
|
|
28683
|
+
attempt: dispatchOrdinal,
|
|
28684
|
+
diagnostic: describeErrorIdentity(unwrapTurnDispatchedFailure(error))
|
|
28685
|
+
};
|
|
28686
|
+
failedAttempts.push(failedAttempt);
|
|
28756
28687
|
turnStartedBeforeThrow = error instanceof TurnDispatchedFailure;
|
|
28757
28688
|
const attempt = dispatchOrdinal;
|
|
28758
28689
|
try {
|
|
@@ -28764,6 +28695,7 @@ async function runWithAutoResumeLoop(options) {
|
|
|
28764
28695
|
error
|
|
28765
28696
|
);
|
|
28766
28697
|
retainedErrorFiles.push(file);
|
|
28698
|
+
failedAttempt.errorFile = file;
|
|
28767
28699
|
options.io.stderr(
|
|
28768
28700
|
`dispatch attempt ${attempt} threw (${describeErrorIdentity(error)}); full error retained at ${file}
|
|
28769
28701
|
`
|
|
@@ -28784,100 +28716,30 @@ async function runWithAutoResumeLoop(options) {
|
|
|
28784
28716
|
dispatchOrdinal += 1;
|
|
28785
28717
|
if (result !== void 0) {
|
|
28786
28718
|
everyAttemptThrew = false;
|
|
28787
|
-
const
|
|
28788
|
-
if (
|
|
28789
|
-
|
|
28790
|
-
|
|
28791
|
-
|
|
28792
|
-
|
|
28793
|
-
|
|
28794
|
-
|
|
28719
|
+
const terminal2 = result.terminal;
|
|
28720
|
+
if (terminal2 !== void 0) {
|
|
28721
|
+
terminal2.autoResumeCount = autoResumeAttempts;
|
|
28722
|
+
if (terminal2.roleOutcome.kind === "failure") {
|
|
28723
|
+
failedAttempts.push({
|
|
28724
|
+
attempt: dispatchOrdinal - 1,
|
|
28725
|
+
diagnostic: terminal2.roleOutcome.diagnostic,
|
|
28726
|
+
decisiveFacts: terminal2.roleOutcome.decisiveFacts
|
|
28727
|
+
});
|
|
28795
28728
|
}
|
|
28796
|
-
return result;
|
|
28797
|
-
}
|
|
28798
|
-
if (result.skipAutoResume === true) {
|
|
28799
|
-
if (terminal !== void 0) presentTerminal(terminal, options.io);
|
|
28800
|
-
return result;
|
|
28801
|
-
}
|
|
28802
|
-
if (processCancelSignalName(options.signal) !== void 0) {
|
|
28803
|
-
if (terminal !== void 0) presentTerminal(terminal, options.io);
|
|
28804
|
-
return result;
|
|
28805
28729
|
}
|
|
28806
|
-
|
|
28807
|
-
|
|
28808
|
-
|
|
28809
|
-
if (autoResumeAttempts >= limit) {
|
|
28810
|
-
if (terminal !== void 0) presentTerminal(terminal, options.io);
|
|
28811
|
-
return result;
|
|
28812
|
-
}
|
|
28813
|
-
if (result.turnDispatched === true && !await isPrincipalAvailable(options.admitted.principal)) {
|
|
28814
|
-
if (terminal !== void 0) presentTerminal(terminal, options.io);
|
|
28815
|
-
return result;
|
|
28730
|
+
if (terminal2 !== void 0 && isLawfulTypedTerminalOutcome(terminal2.roleOutcome) || result.skipAutoResume === true || autoResumeAttempts >= limit || processCancelSignalName(options.signal) !== void 0) {
|
|
28731
|
+
stoppedResult = result;
|
|
28732
|
+
break;
|
|
28816
28733
|
}
|
|
28817
28734
|
} else {
|
|
28818
28735
|
if (autoResumeAttempts >= limit) {
|
|
28819
|
-
|
|
28820
|
-
|
|
28821
|
-
dispatchExceptionFailureTerminal({
|
|
28822
|
-
role: options.admitted.role,
|
|
28823
|
-
runId: options.admitted.runId,
|
|
28824
|
-
causeError: lastThrownError,
|
|
28825
|
-
errorFiles: retainedErrorFiles,
|
|
28826
|
-
autoResumeAttempts,
|
|
28827
|
-
endReason: "auto-resume budget exhausted",
|
|
28828
|
-
everyAttemptThrew
|
|
28829
|
-
}),
|
|
28830
|
-
options.io
|
|
28831
|
-
);
|
|
28832
|
-
await finalizeExceptionRunBestEffort(options.admitted.runDirectory, options.io);
|
|
28833
|
-
presentTerminal(terminal, options.io);
|
|
28834
|
-
return {
|
|
28835
|
-
exitCode: 1,
|
|
28836
|
-
terminal
|
|
28837
|
-
};
|
|
28736
|
+
endReason = "auto-resume budget exhausted";
|
|
28737
|
+
break;
|
|
28838
28738
|
}
|
|
28839
28739
|
const cancelName = processCancelSignalName(options.signal);
|
|
28840
28740
|
if (cancelName !== void 0) {
|
|
28841
|
-
|
|
28842
|
-
|
|
28843
|
-
dispatchExceptionFailureTerminal({
|
|
28844
|
-
role: options.admitted.role,
|
|
28845
|
-
runId: options.admitted.runId,
|
|
28846
|
-
causeError: lastThrownError,
|
|
28847
|
-
errorFiles: retainedErrorFiles,
|
|
28848
|
-
autoResumeAttempts,
|
|
28849
|
-
endReason: `ak-role terminated by ${cancelName}`,
|
|
28850
|
-
everyAttemptThrew
|
|
28851
|
-
}),
|
|
28852
|
-
options.io
|
|
28853
|
-
);
|
|
28854
|
-
await finalizeExceptionRunBestEffort(options.admitted.runDirectory, options.io);
|
|
28855
|
-
presentTerminal(terminal, options.io);
|
|
28856
|
-
return {
|
|
28857
|
-
exitCode: 1,
|
|
28858
|
-
terminal
|
|
28859
|
-
};
|
|
28860
|
-
}
|
|
28861
|
-
if (!await isPrincipalAvailable(options.admitted.principal)) {
|
|
28862
|
-
const terminal = await attachDispatchExceptionTerminal(
|
|
28863
|
-
options.admitted,
|
|
28864
|
-
dispatchExceptionFailureTerminal({
|
|
28865
|
-
role: options.admitted.role,
|
|
28866
|
-
runId: options.admitted.runId,
|
|
28867
|
-
causeError: lastThrownError,
|
|
28868
|
-
errorFiles: retainedErrorFiles,
|
|
28869
|
-
autoResumeAttempts,
|
|
28870
|
-
endReason: "session principal unavailable before further resume",
|
|
28871
|
-
everyAttemptThrew
|
|
28872
|
-
}),
|
|
28873
|
-
options.io
|
|
28874
|
-
);
|
|
28875
|
-
await finalizeExceptionRunBestEffort(options.admitted.runDirectory, options.io);
|
|
28876
|
-
presentTerminal(terminal, options.io);
|
|
28877
|
-
return {
|
|
28878
|
-
exitCode: 1,
|
|
28879
|
-
terminal
|
|
28880
|
-
};
|
|
28741
|
+
endReason = `ak-role terminated by ${cancelName}`;
|
|
28742
|
+
break;
|
|
28881
28743
|
}
|
|
28882
28744
|
}
|
|
28883
28745
|
autoResumeAttempts++;
|
|
@@ -28886,6 +28748,34 @@ async function runWithAutoResumeLoop(options) {
|
|
|
28886
28748
|
isFirst = false;
|
|
28887
28749
|
}
|
|
28888
28750
|
}
|
|
28751
|
+
const terminal = stoppedResult === void 0 ? await attachDispatchExceptionTerminal(
|
|
28752
|
+
options.admitted,
|
|
28753
|
+
dispatchExceptionFailureTerminal({
|
|
28754
|
+
role: options.admitted.role,
|
|
28755
|
+
runId: options.admitted.runId,
|
|
28756
|
+
causeError: lastThrownError,
|
|
28757
|
+
errorFiles: retainedErrorFiles,
|
|
28758
|
+
autoResumeAttempts,
|
|
28759
|
+
endReason,
|
|
28760
|
+
everyAttemptThrew
|
|
28761
|
+
}),
|
|
28762
|
+
options.io
|
|
28763
|
+
) : stoppedResult.terminal;
|
|
28764
|
+
if (stoppedResult === void 0) {
|
|
28765
|
+
await finalizeExceptionRunBestEffort(options.admitted.runDirectory, options.io);
|
|
28766
|
+
}
|
|
28767
|
+
const complete = terminal !== void 0 && failedAttempts.length > 0 ? { ...terminal, roleOutcome: {
|
|
28768
|
+
...terminal.roleOutcome,
|
|
28769
|
+
decisiveFacts: { ...terminal.roleOutcome.decisiveFacts, failedAttempts }
|
|
28770
|
+
} } : terminal;
|
|
28771
|
+
if (complete !== void 0) {
|
|
28772
|
+
if (isLawfulTypedTerminalOutcome(complete.roleOutcome)) {
|
|
28773
|
+
options.io.stdout(formatTerminalResult(complete));
|
|
28774
|
+
} else {
|
|
28775
|
+
presentTerminal(complete, options.io);
|
|
28776
|
+
}
|
|
28777
|
+
}
|
|
28778
|
+
return stoppedResult === void 0 ? { exitCode: 1, terminal: complete } : { ...stoppedResult, ...complete === void 0 ? {} : { terminal: complete } };
|
|
28889
28779
|
}
|
|
28890
28780
|
var dummyIo, TurnDispatchedFailure, DISPATCH_ERROR_RETENTION_ENTRY_TYPE;
|
|
28891
28781
|
var init_auto_resume = __esm({
|
|
@@ -29054,14 +28944,9 @@ async function presentControlledFailure2(admitted, failureInput, adapters, autho
|
|
|
29054
28944
|
...failureInput.knownDiagnostic === void 0 ? {} : { knownDiagnostic: failureInput.knownDiagnostic },
|
|
29055
28945
|
...session === void 0 ? {} : { session }
|
|
29056
28946
|
});
|
|
29057
|
-
|
|
29058
|
-
const typedHttp429 = resumeObservation.typedHttp429;
|
|
29059
|
-
if (admitted.principal !== void 0) {
|
|
29060
|
-
const sessionPrincipalAvailable = await authority.isAvailable(admitted.principal);
|
|
29061
|
-
resumable = sessionPrincipalAvailable && typedHttp429 !== void 0;
|
|
29062
|
-
}
|
|
28947
|
+
const resumable = admitted.principal !== void 0 && resumeObservation.typedHttp429 !== void 0;
|
|
29063
28948
|
if (persistRunState && !failureInput.skipRunStateWrite) {
|
|
29064
|
-
await persistReturnedRunState(admitted
|
|
28949
|
+
await persistReturnedRunState(admitted);
|
|
29065
28950
|
}
|
|
29066
28951
|
let publishedErrorPath;
|
|
29067
28952
|
let terminal;
|
|
@@ -29106,7 +28991,7 @@ async function settleDeferredPersist(admitted, authority, adapters, io, result)
|
|
|
29106
28991
|
const { needsPersist: _needsPersist, ...settledResult } = result;
|
|
29107
28992
|
const lawful = isLawfulTypedTerminalOutcome(result.terminal.roleOutcome);
|
|
29108
28993
|
try {
|
|
29109
|
-
await persistReturnedRunState(admitted,
|
|
28994
|
+
await persistReturnedRunState(admitted, lawful ? { lawful: true } : void 0);
|
|
29110
28995
|
return settledResult;
|
|
29111
28996
|
} catch (error) {
|
|
29112
28997
|
const failed = await settleAfterTurnStarted(
|
|
@@ -29384,7 +29269,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
29384
29269
|
}
|
|
29385
29270
|
if (persistRunState) {
|
|
29386
29271
|
try {
|
|
29387
|
-
await persistReturnedRunState(admitted,
|
|
29272
|
+
await persistReturnedRunState(admitted, { lawful: true });
|
|
29388
29273
|
} catch (error) {
|
|
29389
29274
|
await recordBestEffortPostDispatchDiagnostic(
|
|
29390
29275
|
admitted,
|
|
@@ -29469,7 +29354,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
29469
29354
|
}
|
|
29470
29355
|
if (persistRunState) {
|
|
29471
29356
|
try {
|
|
29472
|
-
await persistReturnedRunState(admitted,
|
|
29357
|
+
await persistReturnedRunState(admitted, { lawful: true });
|
|
29473
29358
|
} catch (error) {
|
|
29474
29359
|
await recordBestEffortPostDispatchDiagnostic(
|
|
29475
29360
|
admitted,
|
|
@@ -29686,10 +29571,6 @@ async function runPostAdmissionSeatResume(input) {
|
|
|
29686
29571
|
return await runWithAutoResumeLoop({
|
|
29687
29572
|
admitted: loaded.admitted,
|
|
29688
29573
|
principalAuthority: env.principalAuthority,
|
|
29689
|
-
isPrincipalAvailable: resolveHostAwareSessionAvailability(
|
|
29690
|
-
env.host,
|
|
29691
|
-
env.principalAuthority
|
|
29692
|
-
),
|
|
29693
29574
|
io: input.io,
|
|
29694
29575
|
sessionAppender: env.sessionAppender,
|
|
29695
29576
|
autoResumeLimit: env.autoResumeLimit,
|
|
@@ -29877,7 +29758,6 @@ async function runPostAdmissionResumable(input) {
|
|
|
29877
29758
|
return runWithAutoResumeLoop({
|
|
29878
29759
|
admitted,
|
|
29879
29760
|
principalAuthority: env.principalAuthority,
|
|
29880
|
-
isPrincipalAvailable: resolveHostAwareSessionAvailability(env.host, env.principalAuthority),
|
|
29881
29761
|
io,
|
|
29882
29762
|
sessionAppender: env.sessionAppender,
|
|
29883
29763
|
autoResumeLimit: env.autoResumeLimit,
|
|
@@ -15,7 +15,7 @@ import { readRecordedSubmissionRows } from "../submission-ledger.js";
|
|
|
15
15
|
import { readDeclaredTicketNumber } from "../run-ticket-number.js";
|
|
16
16
|
import { pathContainedIn } from "../activation-ledger-topology.js";
|
|
17
17
|
import { pickEngineAxis } from "../package-resources/engine-material.js";
|
|
18
|
-
import { readStoredHostSessionId
|
|
18
|
+
import { readStoredHostSessionId } from "../session-identity.js";
|
|
19
19
|
import { rewriteRunDirectoryPathValue } from "../role-run-relocation.js";
|
|
20
20
|
import { isOfficerReviewSeat } from "../packaged-role-registry.js";
|
|
21
21
|
/** Original error bytes, never relabeled — a secondary fact riding beside a classified cause. */
|
|
@@ -223,16 +223,10 @@ export async function presentControlledFailure(admitted, failureInput, adapters,
|
|
|
223
223
|
: { knownDiagnostic: failureInput.knownDiagnostic }),
|
|
224
224
|
...(session === undefined ? {} : { session }),
|
|
225
225
|
});
|
|
226
|
-
// #665 / #416:
|
|
227
|
-
|
|
228
|
-
let resumable = false;
|
|
229
|
-
const typedHttp429 = resumeObservation.typedHttp429;
|
|
230
|
-
if (admitted.principal !== undefined) {
|
|
231
|
-
const sessionPrincipalAvailable = await authority.isAvailable(admitted.principal);
|
|
232
|
-
resumable = sessionPrincipalAvailable && typedHttp429 !== undefined;
|
|
233
|
-
}
|
|
226
|
+
// #665 / #416: typed 429 with a run principal offers resume; the host decides availability.
|
|
227
|
+
const resumable = admitted.principal !== undefined && resumeObservation.typedHttp429 !== undefined;
|
|
234
228
|
if (persistRunState && !failureInput.skipRunStateWrite) {
|
|
235
|
-
await persistReturnedRunState(admitted
|
|
229
|
+
await persistReturnedRunState(admitted);
|
|
236
230
|
}
|
|
237
231
|
let publishedErrorPath;
|
|
238
232
|
let terminal;
|
|
@@ -302,7 +296,7 @@ async function settleDeferredPersist(admitted, authority, adapters, io, result)
|
|
|
302
296
|
const { needsPersist: _needsPersist, ...settledResult } = result;
|
|
303
297
|
const lawful = isLawfulTypedTerminalOutcome(result.terminal.roleOutcome);
|
|
304
298
|
try {
|
|
305
|
-
await persistReturnedRunState(admitted,
|
|
299
|
+
await persistReturnedRunState(admitted, lawful ? { lawful: true } : undefined);
|
|
306
300
|
return settledResult;
|
|
307
301
|
}
|
|
308
302
|
catch (error) {
|
|
@@ -675,7 +669,7 @@ export async function dispatchPostAdmissionTurn(input) {
|
|
|
675
669
|
}
|
|
676
670
|
if (persistRunState) {
|
|
677
671
|
try {
|
|
678
|
-
await persistReturnedRunState(admitted,
|
|
672
|
+
await persistReturnedRunState(admitted, { lawful: true });
|
|
679
673
|
}
|
|
680
674
|
catch (error) {
|
|
681
675
|
await recordBestEffortPostDispatchDiagnostic(admitted, env, `run-state persistence failed beside host terminal (best-effort continue): ${describeErrorIdentity(error)}`, io);
|
|
@@ -747,7 +741,7 @@ export async function dispatchPostAdmissionTurn(input) {
|
|
|
747
741
|
}
|
|
748
742
|
if (persistRunState) {
|
|
749
743
|
try {
|
|
750
|
-
await persistReturnedRunState(admitted,
|
|
744
|
+
await persistReturnedRunState(admitted, { lawful: true });
|
|
751
745
|
}
|
|
752
746
|
catch (error) {
|
|
753
747
|
await recordBestEffortPostDispatchDiagnostic(admitted, env, `run-state persistence failed beside host terminal (best-effort continue): ${describeErrorIdentity(error)}`, io);
|
|
@@ -1046,7 +1040,6 @@ export async function runPostAdmissionSeatResume(input) {
|
|
|
1046
1040
|
return await runWithAutoResumeLoop({
|
|
1047
1041
|
admitted: loaded.admitted,
|
|
1048
1042
|
principalAuthority: env.principalAuthority,
|
|
1049
|
-
isPrincipalAvailable: resolveHostAwareSessionAvailability(env.host, env.principalAuthority),
|
|
1050
1043
|
io: input.io,
|
|
1051
1044
|
sessionAppender: env.sessionAppender,
|
|
1052
1045
|
autoResumeLimit: env.autoResumeLimit,
|
|
@@ -1237,7 +1230,6 @@ export async function runPostAdmissionResumable(input) {
|
|
|
1237
1230
|
return runWithAutoResumeLoop({
|
|
1238
1231
|
admitted,
|
|
1239
1232
|
principalAuthority: env.principalAuthority,
|
|
1240
|
-
isPrincipalAvailable: resolveHostAwareSessionAvailability(env.host, env.principalAuthority),
|
|
1241
1233
|
io,
|
|
1242
1234
|
sessionAppender: env.sessionAppender,
|
|
1243
1235
|
autoResumeLimit: env.autoResumeLimit,
|