@akagilnc/pi-workflow-roles 0.1.4620 → 0.1.4631
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.zh-CN.md +1 -1
- package/dist/acp-host/production-host.js +231 -218
- package/dist/activation-ledger-topology.js +0 -4
- package/dist/headless-host/production-host.js +215 -202
- package/dist/pi/role-turn-host.js +0 -3
- package/dist/public-cli/auto-resume.js +26 -0
- package/dist/public-cli/main.js +1054 -780
- package/dist/public-cli/post-admission.js +101 -7
- package/dist/public-cli/process-cancel.js +57 -0
- package/package.json +1 -1
- package/scripts/build-package.mjs +0 -1
- package/src/activation-ledger-topology.ts +1 -6
- package/src/activation-ledger.ts +5 -236
- package/src/analyst-entry.ts +19 -2
- package/src/analyst-ledger.ts +111 -6
- package/src/archivist-record-entry.ts +1 -1
- package/src/pi/role-turn-host.ts +0 -3
- package/src/public-cli/auto-resume.ts +34 -0
- package/src/public-cli/cli.ts +30 -0
- package/src/public-cli/main.ts +25 -3
- package/src/public-cli/post-admission.ts +173 -6
- package/src/public-cli/process-cancel.ts +75 -0
- package/src/role-runtime.ts +4 -51
- package/dist/activation-reconciliation.js +0 -61
- package/src/activation-reconciliation.ts +0 -163
|
@@ -62,7 +62,7 @@ async function spawnEngineDetourOnce(input) {
|
|
|
62
62
|
}
|
|
63
63
|
const command = input.argv[0];
|
|
64
64
|
const args = input.argv.slice(1);
|
|
65
|
-
return await new Promise((
|
|
65
|
+
return await new Promise((resolve21, reject) => {
|
|
66
66
|
let settled = false;
|
|
67
67
|
const signal = input.signal;
|
|
68
68
|
const child = spawn(command, args, {
|
|
@@ -92,7 +92,7 @@ async function spawnEngineDetourOnce(input) {
|
|
|
92
92
|
if (signal !== void 0) {
|
|
93
93
|
signal.removeEventListener("abort", onAbort);
|
|
94
94
|
}
|
|
95
|
-
|
|
95
|
+
resolve21(result);
|
|
96
96
|
};
|
|
97
97
|
const onAbort = () => {
|
|
98
98
|
fail4(signal !== void 0 ? abortReasonError(signal) : new Error("aborted"));
|
|
@@ -202,7 +202,6 @@ var activation_ledger_topology_exports = {};
|
|
|
202
202
|
__export(activation_ledger_topology_exports, {
|
|
203
203
|
ActivationLedgerError: () => ActivationLedgerError,
|
|
204
204
|
activationBookDirectory: () => activationBookDirectory,
|
|
205
|
-
activationWaitingLedgerPath: () => activationWaitingLedgerPath,
|
|
206
205
|
assertLedgerFileInsideHome: () => assertLedgerFileInsideHome,
|
|
207
206
|
ensureRealDirectoryTree: () => ensureRealDirectoryTree,
|
|
208
207
|
errnoCode: () => errnoCode,
|
|
@@ -265,9 +264,6 @@ function resolveActivationLedgerHomeForPath(path) {
|
|
|
265
264
|
function activationBookDirectory(ledgerHome, bookKey) {
|
|
266
265
|
return join2(ledgerHome, "books", bookKey);
|
|
267
266
|
}
|
|
268
|
-
function activationWaitingLedgerPath(ledgerHome, bookKey) {
|
|
269
|
-
return join2(activationBookDirectory(ledgerHome, bookKey), "waiting.jsonl");
|
|
270
|
-
}
|
|
271
267
|
function pathContainedIn(root, candidate) {
|
|
272
268
|
const rel = relative(root, candidate);
|
|
273
269
|
return rel !== "" && rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel);
|
|
@@ -3443,9 +3439,6 @@ ${paths.join("\n")}`
|
|
|
3443
3439
|
if (typeof process.env.AK_ROLE_AUDITOR_SUBJECT === "string" && process.env.AK_ROLE_AUDITOR_SUBJECT.trim() !== "") {
|
|
3444
3440
|
env.AK_ROLE_AUDITOR_SUBJECT = process.env.AK_ROLE_AUDITOR_SUBJECT;
|
|
3445
3441
|
}
|
|
3446
|
-
if (request.correlationId !== void 0 && request.correlationId.trim() !== "") {
|
|
3447
|
-
env.AK_CORRELATION_ID = request.correlationId;
|
|
3448
|
-
}
|
|
3449
3442
|
if (config.recordLaunchedRolePackageIdentity !== void 0 && config.observeLaunchedRolePackageIdentity !== void 0) {
|
|
3450
3443
|
await config.recordLaunchedRolePackageIdentity(
|
|
3451
3444
|
request.runDirectory,
|
|
@@ -4792,7 +4785,7 @@ function normalizeReviewComment(raw) {
|
|
|
4792
4785
|
function createGhApiRunner(options = {}) {
|
|
4793
4786
|
const spawnImpl = options.spawnImpl ?? spawn3;
|
|
4794
4787
|
return async (args, runOptions = {}) => {
|
|
4795
|
-
return await new Promise((
|
|
4788
|
+
return await new Promise((resolve21, reject) => {
|
|
4796
4789
|
const signal = runOptions.signal;
|
|
4797
4790
|
if (signal?.aborted) {
|
|
4798
4791
|
reject(signal.reason ?? new Error("aborted"));
|
|
@@ -4865,11 +4858,11 @@ function createGhApiRunner(options = {}) {
|
|
|
4865
4858
|
const value = line2.slice(idx + 1).trim();
|
|
4866
4859
|
headers[name] = value;
|
|
4867
4860
|
}
|
|
4868
|
-
|
|
4861
|
+
resolve21({ status, headers, bodyText });
|
|
4869
4862
|
return;
|
|
4870
4863
|
}
|
|
4871
4864
|
if (code === 0) {
|
|
4872
|
-
|
|
4865
|
+
resolve21({ status: 200, headers: {}, bodyText: stdout });
|
|
4873
4866
|
return;
|
|
4874
4867
|
}
|
|
4875
4868
|
const failure2 = new Error(
|
|
@@ -12618,12 +12611,12 @@ function createSystemCollectorClock() {
|
|
|
12618
12611
|
return {
|
|
12619
12612
|
wallNow: () => /* @__PURE__ */ new Date(),
|
|
12620
12613
|
monoNow: () => Number(process.hrtime.bigint() - start) / 1e6,
|
|
12621
|
-
sleep: (ms, signal) => new Promise((
|
|
12614
|
+
sleep: (ms, signal) => new Promise((resolve21, reject) => {
|
|
12622
12615
|
if (signal?.aborted) {
|
|
12623
12616
|
reject(signal.reason ?? new Error("aborted"));
|
|
12624
12617
|
return;
|
|
12625
12618
|
}
|
|
12626
|
-
const timer = setTimeout(
|
|
12619
|
+
const timer = setTimeout(resolve21, ms);
|
|
12627
12620
|
const onAbort = () => {
|
|
12628
12621
|
clearTimeout(timer);
|
|
12629
12622
|
reject(signal?.reason ?? new Error("aborted"));
|
|
@@ -17033,10 +17026,10 @@ function presentFailureTerminal(terminal, io) {
|
|
|
17033
17026
|
}
|
|
17034
17027
|
function defaultNavigatorGraceSleep() {
|
|
17035
17028
|
let timer;
|
|
17036
|
-
const sleep = ((ms) => new Promise((
|
|
17029
|
+
const sleep = ((ms) => new Promise((resolve21) => {
|
|
17037
17030
|
timer = setTimeout(() => {
|
|
17038
17031
|
timer = void 0;
|
|
17039
|
-
|
|
17032
|
+
resolve21();
|
|
17040
17033
|
}, ms);
|
|
17041
17034
|
}));
|
|
17042
17035
|
sleep.cancel = () => {
|
|
@@ -17048,7 +17041,7 @@ function defaultNavigatorGraceSleep() {
|
|
|
17048
17041
|
return sleep;
|
|
17049
17042
|
}
|
|
17050
17043
|
function raceNavigatorGrace(work, graceMs = NAVIGATOR_POST_ROLE_GRACE_MS, sleep = defaultNavigatorGraceSleep()) {
|
|
17051
|
-
return new Promise((
|
|
17044
|
+
return new Promise((resolve21, reject) => {
|
|
17052
17045
|
let settled = false;
|
|
17053
17046
|
const finish = (action) => {
|
|
17054
17047
|
if (settled) return;
|
|
@@ -17057,11 +17050,11 @@ function raceNavigatorGrace(work, graceMs = NAVIGATOR_POST_ROLE_GRACE_MS, sleep
|
|
|
17057
17050
|
action();
|
|
17058
17051
|
};
|
|
17059
17052
|
void work.then(
|
|
17060
|
-
(value) => finish(() =>
|
|
17053
|
+
(value) => finish(() => resolve21({ status: "done", value })),
|
|
17061
17054
|
(error) => finish(() => reject(error))
|
|
17062
17055
|
);
|
|
17063
17056
|
void sleep(graceMs).then(() => {
|
|
17064
|
-
finish(() =>
|
|
17057
|
+
finish(() => resolve21({ status: "timeout" }));
|
|
17065
17058
|
});
|
|
17066
17059
|
});
|
|
17067
17060
|
}
|
|
@@ -18067,6 +18060,24 @@ var init_public_run_credentials = __esm({
|
|
|
18067
18060
|
}
|
|
18068
18061
|
});
|
|
18069
18062
|
|
|
18063
|
+
// src/public-cli/process-cancel.ts
|
|
18064
|
+
function processCancelSignalName(signal) {
|
|
18065
|
+
if (signal === void 0 || signal.aborted !== true) return void 0;
|
|
18066
|
+
const reason = signal.reason;
|
|
18067
|
+
if (reason === "SIGTERM" || reason === "SIGINT" || reason === "SIGHUP") {
|
|
18068
|
+
return reason;
|
|
18069
|
+
}
|
|
18070
|
+
return void 0;
|
|
18071
|
+
}
|
|
18072
|
+
function processCancelDiagnostic(signalName) {
|
|
18073
|
+
return `ak-role terminated by ${signalName}`;
|
|
18074
|
+
}
|
|
18075
|
+
var init_process_cancel = __esm({
|
|
18076
|
+
"src/public-cli/process-cancel.ts"() {
|
|
18077
|
+
"use strict";
|
|
18078
|
+
}
|
|
18079
|
+
});
|
|
18080
|
+
|
|
18070
18081
|
// src/public-cli/auto-resume.ts
|
|
18071
18082
|
import { constants as fsConstants2 } from "node:fs";
|
|
18072
18083
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
@@ -18369,6 +18380,10 @@ async function runWithAutoResumeLoop(options) {
|
|
|
18369
18380
|
if (terminal !== void 0) presentTerminal(terminal, options.io);
|
|
18370
18381
|
return result;
|
|
18371
18382
|
}
|
|
18383
|
+
if (processCancelSignalName(options.signal) !== void 0) {
|
|
18384
|
+
if (terminal !== void 0) presentTerminal(terminal, options.io);
|
|
18385
|
+
return result;
|
|
18386
|
+
}
|
|
18372
18387
|
}
|
|
18373
18388
|
if (result !== void 0) {
|
|
18374
18389
|
const terminal = result.terminal;
|
|
@@ -18402,6 +18417,28 @@ async function runWithAutoResumeLoop(options) {
|
|
|
18402
18417
|
terminal
|
|
18403
18418
|
};
|
|
18404
18419
|
}
|
|
18420
|
+
const cancelName = processCancelSignalName(options.signal);
|
|
18421
|
+
if (cancelName !== void 0) {
|
|
18422
|
+
const terminal = await attachDispatchExceptionTerminal(
|
|
18423
|
+
options.admitted,
|
|
18424
|
+
dispatchExceptionFailureTerminal({
|
|
18425
|
+
role: options.admitted.role,
|
|
18426
|
+
runId: options.admitted.runId,
|
|
18427
|
+
causeError: lastThrownError,
|
|
18428
|
+
errorFiles: retainedErrorFiles,
|
|
18429
|
+
autoResumeAttempts,
|
|
18430
|
+
endReason: `ak-role terminated by ${cancelName}`,
|
|
18431
|
+
everyAttemptThrew
|
|
18432
|
+
}),
|
|
18433
|
+
options.io
|
|
18434
|
+
);
|
|
18435
|
+
await finalizeExceptionRunBestEffort(options.admitted.runDirectory, options.io);
|
|
18436
|
+
presentTerminal(terminal, options.io);
|
|
18437
|
+
return {
|
|
18438
|
+
exitCode: 1,
|
|
18439
|
+
terminal
|
|
18440
|
+
};
|
|
18441
|
+
}
|
|
18405
18442
|
if (!await isPrincipalAvailable(options.admitted.principal)) {
|
|
18406
18443
|
const terminal = await attachDispatchExceptionTerminal(
|
|
18407
18444
|
options.admitted,
|
|
@@ -18438,6 +18475,7 @@ var init_auto_resume = __esm({
|
|
|
18438
18475
|
init_role_run_placement();
|
|
18439
18476
|
init_run_lifecycle();
|
|
18440
18477
|
init_config();
|
|
18478
|
+
init_process_cancel();
|
|
18441
18479
|
init_terminal();
|
|
18442
18480
|
init_settlement();
|
|
18443
18481
|
dummyIo = { stdout: () => {
|
|
@@ -18470,6 +18508,36 @@ function describeCaughtError(error) {
|
|
|
18470
18508
|
function isStationChildOfficerDialogue(role, env) {
|
|
18471
18509
|
return env.stationChild === true && isOfficerReviewSeat(role);
|
|
18472
18510
|
}
|
|
18511
|
+
function withProcessCancelSkipAutoResume(result, signal) {
|
|
18512
|
+
if (processCancelSignalName(signal) === void 0) {
|
|
18513
|
+
return result;
|
|
18514
|
+
}
|
|
18515
|
+
return { ...result, skipAutoResume: true };
|
|
18516
|
+
}
|
|
18517
|
+
async function settleProcessCancelAfterTurn(input) {
|
|
18518
|
+
const failed = await settleAfterTurnStarted(
|
|
18519
|
+
input.admitted,
|
|
18520
|
+
withEngineDetourInvocationScope(
|
|
18521
|
+
{
|
|
18522
|
+
timedOut: input.result.timedOut,
|
|
18523
|
+
code: input.result.code,
|
|
18524
|
+
stderr: input.result.stderr,
|
|
18525
|
+
knownDiagnostic: processCancelDiagnostic(input.cancelName)
|
|
18526
|
+
},
|
|
18527
|
+
input.invocationScopeId
|
|
18528
|
+
),
|
|
18529
|
+
input.adapters,
|
|
18530
|
+
input.env.principalAuthority,
|
|
18531
|
+
input.io,
|
|
18532
|
+
input.persistRunState
|
|
18533
|
+
);
|
|
18534
|
+
return {
|
|
18535
|
+
...failed,
|
|
18536
|
+
turnDispatched: true,
|
|
18537
|
+
skipAutoResume: true,
|
|
18538
|
+
...input.deferredPersist
|
|
18539
|
+
};
|
|
18540
|
+
}
|
|
18473
18541
|
function withOnceSuccessfulBeforeDispatch(adapters) {
|
|
18474
18542
|
const hook = adapters.beforeDispatch;
|
|
18475
18543
|
if (hook === void 0) return adapters;
|
|
@@ -18630,6 +18698,31 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
18630
18698
|
const finishAfterTurn = async (result) => {
|
|
18631
18699
|
if (afterDispatchApplied) return result;
|
|
18632
18700
|
afterDispatchApplied = true;
|
|
18701
|
+
const cancelBeforeFinish = processCancelSignalName(env.signal);
|
|
18702
|
+
if (cancelBeforeFinish !== void 0 && result.terminal !== void 0 && isLawfulTypedTerminalOutcome(result.terminal.roleOutcome)) {
|
|
18703
|
+
result = {
|
|
18704
|
+
...await settleAfterTurnStarted(
|
|
18705
|
+
admitted,
|
|
18706
|
+
withEngineDetourInvocationScope(
|
|
18707
|
+
{
|
|
18708
|
+
timedOut: false,
|
|
18709
|
+
code: null,
|
|
18710
|
+
stderr: "",
|
|
18711
|
+
knownDiagnostic: processCancelDiagnostic(cancelBeforeFinish),
|
|
18712
|
+
skipRunStateWrite: true
|
|
18713
|
+
},
|
|
18714
|
+
request.invocationScopeId
|
|
18715
|
+
),
|
|
18716
|
+
adapters,
|
|
18717
|
+
env.principalAuthority,
|
|
18718
|
+
io,
|
|
18719
|
+
persistRunState
|
|
18720
|
+
),
|
|
18721
|
+
turnDispatched: true,
|
|
18722
|
+
skipAutoResume: true,
|
|
18723
|
+
...deferredPersist
|
|
18724
|
+
};
|
|
18725
|
+
}
|
|
18633
18726
|
try {
|
|
18634
18727
|
if (admitted.ticketNumber === void 0) {
|
|
18635
18728
|
const rows = await readRecordedSubmissionRows(
|
|
@@ -18776,20 +18869,26 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
18776
18869
|
try {
|
|
18777
18870
|
result = await env.roleTurnHost.executeTurn(turnRequest);
|
|
18778
18871
|
} catch (error) {
|
|
18872
|
+
const processCancelName = processCancelSignalName(env.signal);
|
|
18779
18873
|
const settled2 = await settleAfterTurnStarted(
|
|
18780
18874
|
admitted,
|
|
18781
18875
|
withEngineDetourInvocationScope({
|
|
18782
18876
|
timedOut: false,
|
|
18783
18877
|
code: null,
|
|
18784
18878
|
stderr: "",
|
|
18785
|
-
thrown: error
|
|
18879
|
+
thrown: processCancelName === void 0 ? error : new Error(processCancelDiagnostic(processCancelName), { cause: error })
|
|
18786
18880
|
}, request.invocationScopeId),
|
|
18787
18881
|
adapters,
|
|
18788
18882
|
env.principalAuthority,
|
|
18789
18883
|
io,
|
|
18790
18884
|
persistRunState
|
|
18791
18885
|
);
|
|
18792
|
-
return await finishAfterTurn(
|
|
18886
|
+
return await finishAfterTurn(
|
|
18887
|
+
withProcessCancelSkipAutoResume(
|
|
18888
|
+
{ ...settled2, turnDispatched: true, ...deferredPersist },
|
|
18889
|
+
env.signal
|
|
18890
|
+
)
|
|
18891
|
+
);
|
|
18793
18892
|
}
|
|
18794
18893
|
let stderrLogWriteFailure;
|
|
18795
18894
|
try {
|
|
@@ -18829,7 +18928,8 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
18829
18928
|
credential: credentialFailure,
|
|
18830
18929
|
runDirectory: admitted.runDirectory
|
|
18831
18930
|
});
|
|
18832
|
-
const
|
|
18931
|
+
const processCancelName = processCancelSignalName(env.signal);
|
|
18932
|
+
const directHostFailureSignal = result.timedOut || result.knownFailure !== void 0 || runnerKnownFailure !== void 0 || credentialFailure !== void 0 || processCancelName !== void 0;
|
|
18833
18933
|
hostSignalFailed = directHostFailureSignal || result.code !== null && result.code !== 0 || resolution.knownFailure !== void 0;
|
|
18834
18934
|
settled = await adapters.trySettle(admitted, env.principalAuthority, courtScope);
|
|
18835
18935
|
if (settled !== void 0) {
|
|
@@ -18837,7 +18937,8 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
18837
18937
|
}
|
|
18838
18938
|
const settledIsFreshThisAttempt = settled === void 0 || settled.roleOutcome.kind !== "accepted" && settled.roleOutcome.kind !== "audit_escalation" ? true : await attemptProducedFreshSubmission(admitted, courtScope);
|
|
18839
18939
|
const staleAcceptanceOutranksRealFailure = !settledIsFreshThisAttempt && hostSignalFailed;
|
|
18840
|
-
|
|
18940
|
+
const cancelAfterSettle = processCancelSignalName(env.signal);
|
|
18941
|
+
if (settled !== void 0 && shouldPresent(settled) && !directHostFailureSignal && !staleAcceptanceOutranksRealFailure && stderrLogWriteFailure === void 0 && cancelAfterSettle === void 0) {
|
|
18841
18942
|
if (settled.roleOutcome.kind === "accepted" && request.courtAttemptId !== void 0 && request.courtAttemptId.length > 0) {
|
|
18842
18943
|
try {
|
|
18843
18944
|
await clearCurrentCourt(admitted.runDirectory, request.courtAttemptId);
|
|
@@ -18874,6 +18975,22 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
18874
18975
|
return await finishAfterTurn({ ...settledFailure, turnDispatched: true, ...deferredPersist });
|
|
18875
18976
|
}
|
|
18876
18977
|
if (settledOutcome !== void 0) {
|
|
18978
|
+
const lateCancel = processCancelSignalName(env.signal);
|
|
18979
|
+
if (lateCancel !== void 0) {
|
|
18980
|
+
return await finishAfterTurn(
|
|
18981
|
+
await settleProcessCancelAfterTurn({
|
|
18982
|
+
admitted,
|
|
18983
|
+
cancelName: lateCancel,
|
|
18984
|
+
result,
|
|
18985
|
+
adapters,
|
|
18986
|
+
env,
|
|
18987
|
+
io,
|
|
18988
|
+
persistRunState,
|
|
18989
|
+
deferredPersist,
|
|
18990
|
+
invocationScopeId: request.invocationScopeId
|
|
18991
|
+
})
|
|
18992
|
+
);
|
|
18993
|
+
}
|
|
18877
18994
|
if (persistRunState) {
|
|
18878
18995
|
try {
|
|
18879
18996
|
await persistReturnedRunState(admitted, env.principalAuthority, { lawful: true });
|
|
@@ -18892,13 +19009,19 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
18892
19009
|
io,
|
|
18893
19010
|
persistRunState
|
|
18894
19011
|
);
|
|
18895
|
-
return await finishAfterTurn(
|
|
19012
|
+
return await finishAfterTurn(
|
|
19013
|
+
withProcessCancelSkipAutoResume(
|
|
19014
|
+
{ ...failed, turnDispatched: true, ...deferredPersist },
|
|
19015
|
+
env.signal
|
|
19016
|
+
)
|
|
19017
|
+
);
|
|
18896
19018
|
}
|
|
18897
19019
|
}
|
|
18898
19020
|
return await finishAfterTurn({ ...settledOutcome, ...deferredPersist });
|
|
18899
19021
|
}
|
|
18900
19022
|
if (hostSignalFailed) {
|
|
18901
19023
|
const resolutionInput = controlledFailureInputFromResolution(resolution);
|
|
19024
|
+
const processCancelName = processCancelSignalName(env.signal);
|
|
18902
19025
|
const stderrLogWriteDetails = stderrLogWriteFailure === void 0 ? void 0 : { stderrLogWriteFailure: describeCaughtError(stderrLogWriteFailure) };
|
|
18903
19026
|
const failed = await settleAfterTurnStarted(
|
|
18904
19027
|
admitted,
|
|
@@ -18907,6 +19030,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
18907
19030
|
code: result.code,
|
|
18908
19031
|
stderr: result.stderr,
|
|
18909
19032
|
...resolutionInput,
|
|
19033
|
+
...processCancelName === void 0 ? {} : { knownDiagnostic: processCancelDiagnostic(processCancelName) },
|
|
18910
19034
|
// Secondary fact only — never the cause. Rides on whichever channel
|
|
18911
19035
|
// classification actually reads (knownFailure.details owns it when
|
|
18912
19036
|
// a knownFailure exists; the top-level knownDetails otherwise).
|
|
@@ -18922,7 +19046,12 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
18922
19046
|
io,
|
|
18923
19047
|
persistRunState
|
|
18924
19048
|
);
|
|
18925
|
-
return await finishAfterTurn(
|
|
19049
|
+
return await finishAfterTurn(
|
|
19050
|
+
withProcessCancelSkipAutoResume(
|
|
19051
|
+
{ ...failed, turnDispatched: true, ...deferredPersist },
|
|
19052
|
+
env.signal
|
|
19053
|
+
)
|
|
19054
|
+
);
|
|
18926
19055
|
}
|
|
18927
19056
|
if (stderrLogWriteFailure !== void 0) {
|
|
18928
19057
|
const failed = await settleAfterTurnStarted(
|
|
@@ -18945,6 +19074,22 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
18945
19074
|
await settleHostEndedNoReceipt(admitted, env.principalAuthority, courtScope),
|
|
18946
19075
|
courtScope
|
|
18947
19076
|
);
|
|
19077
|
+
const noReceiptCancel = processCancelSignalName(env.signal);
|
|
19078
|
+
if (noReceiptCancel !== void 0) {
|
|
19079
|
+
return await finishAfterTurn(
|
|
19080
|
+
await settleProcessCancelAfterTurn({
|
|
19081
|
+
admitted,
|
|
19082
|
+
cancelName: noReceiptCancel,
|
|
19083
|
+
result,
|
|
19084
|
+
adapters,
|
|
19085
|
+
env,
|
|
19086
|
+
io,
|
|
19087
|
+
persistRunState,
|
|
19088
|
+
deferredPersist,
|
|
19089
|
+
invocationScopeId: request.invocationScopeId
|
|
19090
|
+
})
|
|
19091
|
+
);
|
|
19092
|
+
}
|
|
18948
19093
|
if (persistRunState) {
|
|
18949
19094
|
try {
|
|
18950
19095
|
await persistReturnedRunState(admitted, env.principalAuthority, { lawful: true });
|
|
@@ -18963,7 +19108,12 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
18963
19108
|
io,
|
|
18964
19109
|
persistRunState
|
|
18965
19110
|
);
|
|
18966
|
-
return await finishAfterTurn(
|
|
19111
|
+
return await finishAfterTurn(
|
|
19112
|
+
withProcessCancelSkipAutoResume(
|
|
19113
|
+
{ ...failed, turnDispatched: true, ...deferredPersist },
|
|
19114
|
+
env.signal
|
|
19115
|
+
)
|
|
19116
|
+
);
|
|
18967
19117
|
}
|
|
18968
19118
|
}
|
|
18969
19119
|
return await finishAfterTurn({
|
|
@@ -19159,6 +19309,7 @@ async function runPostAdmissionSeatResume(input) {
|
|
|
19159
19309
|
io: input.io,
|
|
19160
19310
|
sessionAppender: env.sessionAppender,
|
|
19161
19311
|
autoResumeLimit: env.autoResumeLimit,
|
|
19312
|
+
...env.signal === void 0 ? {} : { signal: env.signal },
|
|
19162
19313
|
buildInitialPayload: () => ({ resumeTurn: false }),
|
|
19163
19314
|
buildResumePayload: () => ({ resumeTurn: true }),
|
|
19164
19315
|
// Same as public manual resume: prior-court sealed acceptance is not a
|
|
@@ -19262,6 +19413,7 @@ async function runPostAdmissionResumable(input) {
|
|
|
19262
19413
|
io,
|
|
19263
19414
|
sessionAppender: env.sessionAppender,
|
|
19264
19415
|
autoResumeLimit: env.autoResumeLimit,
|
|
19416
|
+
...env.signal === void 0 ? {} : { signal: env.signal },
|
|
19265
19417
|
buildInitialPayload: buildScopedInitial,
|
|
19266
19418
|
buildResumePayload: buildScopedResume,
|
|
19267
19419
|
dispatch: async (request, lease, _isFirst, attemptIo) => {
|
|
@@ -19370,6 +19522,7 @@ var init_post_admission = __esm({
|
|
|
19370
19522
|
init_host_transition_prior_native();
|
|
19371
19523
|
init_public_run_credentials();
|
|
19372
19524
|
init_run_lifecycle();
|
|
19525
|
+
init_process_cancel();
|
|
19373
19526
|
init_activation_ledger_topology();
|
|
19374
19527
|
init_settlement();
|
|
19375
19528
|
init_terminal();
|
|
@@ -21935,7 +22088,7 @@ init_engine_detour();
|
|
|
21935
22088
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
21936
22089
|
import { appendFile as appendFile3, mkdir as mkdir7, writeFile as writeFile12 } from "node:fs/promises";
|
|
21937
22090
|
import { createServer } from "node:net";
|
|
21938
|
-
import { dirname as
|
|
22091
|
+
import { dirname as dirname21, join as join41 } from "node:path";
|
|
21939
22092
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
21940
22093
|
|
|
21941
22094
|
// src/gatekeeper-pass-envelope.ts
|
|
@@ -22064,7 +22217,7 @@ init_sitian_facade();
|
|
|
22064
22217
|
init_submission_ledger();
|
|
22065
22218
|
init_collector_ledger();
|
|
22066
22219
|
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
22067
|
-
import { readFileSync as readFileSync6, writeSync as
|
|
22220
|
+
import { readFileSync as readFileSync6, writeSync as writeSync3 } from "node:fs";
|
|
22068
22221
|
import { join as join40 } from "node:path";
|
|
22069
22222
|
import { Value as Value4 } from "typebox/value";
|
|
22070
22223
|
|
|
@@ -22106,16 +22259,7 @@ function namedActivationCause(error) {
|
|
|
22106
22259
|
init_activation_ledger_topology();
|
|
22107
22260
|
|
|
22108
22261
|
// src/activation-ledger.ts
|
|
22109
|
-
init_activation_ledger_topology();
|
|
22110
22262
|
init_activation_ledger_git();
|
|
22111
|
-
import {
|
|
22112
|
-
constants as constants2,
|
|
22113
|
-
closeSync as closeSync2,
|
|
22114
|
-
fstatSync,
|
|
22115
|
-
openSync as openSync2,
|
|
22116
|
-
writeSync
|
|
22117
|
-
} from "node:fs";
|
|
22118
|
-
import { dirname as dirname19, isAbsolute as isAbsolute10, resolve as resolve16 } from "node:path";
|
|
22119
22263
|
|
|
22120
22264
|
// src/activation-ledger-session.ts
|
|
22121
22265
|
init_activation_ledger_topology();
|
|
@@ -22219,129 +22363,11 @@ function durableSessionPointer(sessionManager) {
|
|
|
22219
22363
|
|
|
22220
22364
|
// src/activation-ledger.ts
|
|
22221
22365
|
init_activation_ledger_topology();
|
|
22222
|
-
var ACTIVATION_LEDGER_APPEND_OPEN_FLAGS = constants2.O_APPEND | constants2.O_CREAT | constants2.O_WRONLY | constants2.O_NOFOLLOW;
|
|
22223
|
-
var ACCEPTED_ACTIVATION_EVENT = "accepted-activation";
|
|
22224
|
-
var ACCEPTED_ACTIVATION_FACT_KEYS = Object.freeze([
|
|
22225
|
-
"event",
|
|
22226
|
-
"role",
|
|
22227
|
-
"observedAt",
|
|
22228
|
-
"bookKey",
|
|
22229
|
-
"session",
|
|
22230
|
-
"correlation"
|
|
22231
|
-
]);
|
|
22232
|
-
function correlationIdentityFromEnv(env = process.env) {
|
|
22233
|
-
const raw = env.AK_CORRELATION_ID;
|
|
22234
|
-
if (typeof raw === "string" && raw.trim().length > 0) {
|
|
22235
|
-
return { kind: "caller", id: raw };
|
|
22236
|
-
}
|
|
22237
|
-
return { kind: "absent" };
|
|
22238
|
-
}
|
|
22239
|
-
function projectAcceptedActivationFact(input) {
|
|
22240
|
-
const closed = {
|
|
22241
|
-
event: ACCEPTED_ACTIVATION_EVENT,
|
|
22242
|
-
role: input.role,
|
|
22243
|
-
observedAt: input.observedAt,
|
|
22244
|
-
bookKey: input.bookKey,
|
|
22245
|
-
session: { kind: "session-file", path: input.session.path },
|
|
22246
|
-
correlation: input.correlation.kind === "caller" ? { kind: "caller", id: input.correlation.id } : { kind: "absent" }
|
|
22247
|
-
};
|
|
22248
|
-
return Object.fromEntries(
|
|
22249
|
-
ACCEPTED_ACTIVATION_FACT_KEYS.map((key) => [key, closed[key]])
|
|
22250
|
-
);
|
|
22251
|
-
}
|
|
22252
|
-
function buildAcceptedActivationFact(input) {
|
|
22253
|
-
return projectAcceptedActivationFact(input);
|
|
22254
|
-
}
|
|
22255
|
-
function serializeAcceptedActivationFact(fact) {
|
|
22256
|
-
return `${JSON.stringify(projectAcceptedActivationFact(fact))}
|
|
22257
|
-
`;
|
|
22258
|
-
}
|
|
22259
|
-
function appendActivationLedgerLine(ledgerPath, line2, options) {
|
|
22260
|
-
if (!isAbsolute10(options.ledgerHome)) {
|
|
22261
|
-
throw new ActivationLedgerError(
|
|
22262
|
-
`activation ledger home must be absolute: ${options.ledgerHome}`
|
|
22263
|
-
);
|
|
22264
|
-
}
|
|
22265
|
-
const resolvedLedger = resolve16(ledgerPath);
|
|
22266
|
-
const resolvedHome = resolve16(options.ledgerHome);
|
|
22267
|
-
const parent = dirname19(resolvedLedger);
|
|
22268
|
-
ensureRealDirectoryTree(resolvedHome, parent);
|
|
22269
|
-
assertLedgerFileInsideHome(resolvedLedger, resolvedHome);
|
|
22270
|
-
if (typeof constants2.O_NOFOLLOW !== "number") {
|
|
22271
|
-
throw new ActivationLedgerError(
|
|
22272
|
-
"activation ledger append requires O_NOFOLLOW open-flag support (anti-symlink TOCTOU protection must not be silently dropped); refusing to append"
|
|
22273
|
-
);
|
|
22274
|
-
}
|
|
22275
|
-
const bytes = Buffer.isBuffer(line2) ? line2 : Buffer.from(line2);
|
|
22276
|
-
let ledgerFd;
|
|
22277
|
-
let primaryFailure;
|
|
22278
|
-
try {
|
|
22279
|
-
try {
|
|
22280
|
-
ledgerFd = openSync2(resolvedLedger, ACTIVATION_LEDGER_APPEND_OPEN_FLAGS, 420);
|
|
22281
|
-
} catch (error) {
|
|
22282
|
-
throw new ActivationLedgerError(
|
|
22283
|
-
`activation ledger failed to open ledger file (${resolvedLedger}): ${errorText(error)}`,
|
|
22284
|
-
{ cause: error }
|
|
22285
|
-
);
|
|
22286
|
-
}
|
|
22287
|
-
let opened;
|
|
22288
|
-
try {
|
|
22289
|
-
opened = fstatSync(ledgerFd);
|
|
22290
|
-
} catch (error) {
|
|
22291
|
-
throw new ActivationLedgerError(
|
|
22292
|
-
`activation ledger failed to fstat ledger file (${resolvedLedger}): ${errorText(error)}`,
|
|
22293
|
-
{ cause: error }
|
|
22294
|
-
);
|
|
22295
|
-
}
|
|
22296
|
-
if (!opened.isFile()) {
|
|
22297
|
-
throw new ActivationLedgerError(
|
|
22298
|
-
`activation ledger is not a regular file: ${resolvedLedger}`
|
|
22299
|
-
);
|
|
22300
|
-
}
|
|
22301
|
-
const written = writeSync(ledgerFd, bytes, 0, bytes.length, null);
|
|
22302
|
-
if (written !== bytes.length) {
|
|
22303
|
-
throw new ActivationLedgerError(
|
|
22304
|
-
`activation ledger short write: wrote ${written} of ${bytes.length} bytes to ${resolvedLedger}`
|
|
22305
|
-
);
|
|
22306
|
-
}
|
|
22307
|
-
} catch (error) {
|
|
22308
|
-
primaryFailure = error;
|
|
22309
|
-
}
|
|
22310
|
-
if (ledgerFd !== void 0) {
|
|
22311
|
-
try {
|
|
22312
|
-
closeSync2(ledgerFd);
|
|
22313
|
-
} catch (closeFailure) {
|
|
22314
|
-
if (primaryFailure !== void 0) {
|
|
22315
|
-
throw new AggregateError(
|
|
22316
|
-
[primaryFailure, closeFailure],
|
|
22317
|
-
"activation ledger operation and close failed",
|
|
22318
|
-
{ cause: primaryFailure }
|
|
22319
|
-
);
|
|
22320
|
-
}
|
|
22321
|
-
throw closeFailure;
|
|
22322
|
-
}
|
|
22323
|
-
}
|
|
22324
|
-
if (primaryFailure !== void 0) throw primaryFailure;
|
|
22325
|
-
}
|
|
22326
|
-
function appendAcceptedActivationFact(ledgerPath, fact, options) {
|
|
22327
|
-
appendActivationLedgerLine(
|
|
22328
|
-
ledgerPath,
|
|
22329
|
-
Buffer.from(serializeAcceptedActivationFact(fact), "utf8"),
|
|
22330
|
-
{ ledgerHome: options.ledgerHome }
|
|
22331
|
-
);
|
|
22332
|
-
}
|
|
22333
|
-
function appendAcceptedActivationToBook(options) {
|
|
22334
|
-
appendAcceptedActivationFact(
|
|
22335
|
-
activationWaitingLedgerPath(options.ledgerHome, options.fact.bookKey),
|
|
22336
|
-
options.fact,
|
|
22337
|
-
{ ledgerHome: options.ledgerHome }
|
|
22338
|
-
);
|
|
22339
|
-
}
|
|
22340
22366
|
|
|
22341
22367
|
// src/stderr-jsonl.ts
|
|
22342
|
-
import { writeSync
|
|
22368
|
+
import { writeSync } from "node:fs";
|
|
22343
22369
|
var STDERR_JSONL_WRITE_RETRY_LIMIT = 100;
|
|
22344
|
-
function writeStderrJsonlRecord(record4, write =
|
|
22370
|
+
function writeStderrJsonlRecord(record4, write = writeSync) {
|
|
22345
22371
|
const bytes = Buffer.from(`${JSON.stringify(record4)}
|
|
22346
22372
|
`);
|
|
22347
22373
|
let offset = 0;
|
|
@@ -22361,7 +22387,7 @@ function writeStderrJsonlRecord(record4, write = writeSync2) {
|
|
|
22361
22387
|
}
|
|
22362
22388
|
|
|
22363
22389
|
// src/tool-execution-observation.ts
|
|
22364
|
-
import { writeSync as
|
|
22390
|
+
import { writeSync as writeSync2 } from "node:fs";
|
|
22365
22391
|
import { Type as Type13 } from "typebox";
|
|
22366
22392
|
import { Value as Value2 } from "typebox/value";
|
|
22367
22393
|
var TOOL_EXECUTION_UPDATE_THROTTLE_MS = 3e4;
|
|
@@ -22392,7 +22418,7 @@ function validateToolExecutionObservationRecord(record4) {
|
|
|
22392
22418
|
}
|
|
22393
22419
|
return record4;
|
|
22394
22420
|
}
|
|
22395
|
-
function writeToolExecutionObservationRecord(record4, write =
|
|
22421
|
+
function writeToolExecutionObservationRecord(record4, write = writeSync2) {
|
|
22396
22422
|
writeStderrJsonlRecord(validateToolExecutionObservationRecord(record4), write);
|
|
22397
22423
|
}
|
|
22398
22424
|
function isProducingToolUpdate(partialResult) {
|
|
@@ -22629,9 +22655,9 @@ import { join as join38, sep as sep6 } from "node:path";
|
|
|
22629
22655
|
// src/atomic-write.ts
|
|
22630
22656
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
22631
22657
|
import { rename as rename3, rm as rm5, writeFile as writeFile11 } from "node:fs/promises";
|
|
22632
|
-
import { dirname as
|
|
22658
|
+
import { dirname as dirname19, join as join37 } from "node:path";
|
|
22633
22659
|
async function writeFileAtomically(destination, contents) {
|
|
22634
|
-
const parent =
|
|
22660
|
+
const parent = dirname19(destination);
|
|
22635
22661
|
const temporary = join37(parent, `.atomic-write-${randomUUID7()}.tmp`);
|
|
22636
22662
|
try {
|
|
22637
22663
|
await writeFile11(temporary, contents);
|
|
@@ -23935,7 +23961,7 @@ import { createHash as createHash9 } from "node:crypto";
|
|
|
23935
23961
|
init_navigator_invocation_identity();
|
|
23936
23962
|
init_packaged_role_registry();
|
|
23937
23963
|
init_activation_ledger_topology();
|
|
23938
|
-
import { resolve as
|
|
23964
|
+
import { resolve as resolve16 } from "node:path";
|
|
23939
23965
|
import "@earendil-works/pi-coding-agent";
|
|
23940
23966
|
import { Type as Type22 } from "typebox";
|
|
23941
23967
|
|
|
@@ -24383,7 +24409,7 @@ function navigatorSubjectKey(subjectRoot, subject, provenance = "role_input") {
|
|
|
24383
24409
|
}
|
|
24384
24410
|
function navigatorSubjectKeyForInput(subjectRoot, reference, cwd = process.cwd()) {
|
|
24385
24411
|
if (issueRoot(subjectRoot) !== void 0 || !subjectRoot.includes("/.ak/work/")) return subjectRoot;
|
|
24386
|
-
const resolvedReference =
|
|
24412
|
+
const resolvedReference = resolve16(cwd, reference);
|
|
24387
24413
|
const marker = "/runs/";
|
|
24388
24414
|
if (resolvedReference.includes(marker)) {
|
|
24389
24415
|
return subjectRoot;
|
|
@@ -25085,7 +25111,7 @@ init_submission_errors();
|
|
|
25085
25111
|
init_submission_errors();
|
|
25086
25112
|
import { execFileSync as execFileSync4 } from "node:child_process";
|
|
25087
25113
|
import { existsSync as existsSync12, lstatSync as lstatSync3, readdirSync as readdirSync3, readFileSync as readFileSync5, rmdirSync, rmSync } from "node:fs";
|
|
25088
|
-
import { resolve as
|
|
25114
|
+
import { resolve as resolve17 } from "node:path";
|
|
25089
25115
|
var WORKER_SUBMISSION_GATE_RECORD_KIND = WORKER_SUBMISSION_GATE_KIND;
|
|
25090
25116
|
var WORKER_COMMIT_BASELINE_ENTRY_TYPE = "commit-baseline";
|
|
25091
25117
|
var WORKER_COMMIT_REMINDER_BOUNCE_ENTRY_TYPE = "commit-reminder-bounce";
|
|
@@ -25134,7 +25160,7 @@ function escapeGitConfigValueRegex(value) {
|
|
|
25134
25160
|
function unsetOwnedHooksPath(file) {
|
|
25135
25161
|
const owned = [];
|
|
25136
25162
|
for (const value of tryGetAll(file, "core.hooksPath")) {
|
|
25137
|
-
if (!ownedHook(
|
|
25163
|
+
if (!ownedHook(resolve17(value, HOOK_FILE))) continue;
|
|
25138
25164
|
try {
|
|
25139
25165
|
gitFile(file, [
|
|
25140
25166
|
"--unset-all",
|
|
@@ -25149,15 +25175,15 @@ function unsetOwnedHooksPath(file) {
|
|
|
25149
25175
|
return owned;
|
|
25150
25176
|
}
|
|
25151
25177
|
function rmOwnedDir(dir) {
|
|
25152
|
-
const hookPath =
|
|
25178
|
+
const hookPath = resolve17(dir, HOOK_FILE);
|
|
25153
25179
|
if (!ownedHook(hookPath)) return;
|
|
25154
25180
|
rmSync(hookPath, { force: true });
|
|
25155
25181
|
if (existsSync12(dir) && readdirSync3(dir).length === 0) rmdirSync(dir);
|
|
25156
25182
|
}
|
|
25157
25183
|
function linkedGitDirs(commonDir) {
|
|
25158
|
-
const root =
|
|
25184
|
+
const root = resolve17(commonDir, "worktrees");
|
|
25159
25185
|
if (!existsSync12(root)) return [];
|
|
25160
|
-
return readdirSync3(root).map((name) =>
|
|
25186
|
+
return readdirSync3(root).map((name) => resolve17(root, name)).filter((dir) => lstatSync3(dir).isDirectory());
|
|
25161
25187
|
}
|
|
25162
25188
|
function uninstallPackageWorkerHooks(cwd) {
|
|
25163
25189
|
let inside;
|
|
@@ -25171,14 +25197,14 @@ function uninstallPackageWorkerHooks(cwd) {
|
|
|
25171
25197
|
const clear = (configFile) => {
|
|
25172
25198
|
for (const hooks of unsetOwnedHooksPath(configFile)) rmOwnedDir(hooks);
|
|
25173
25199
|
};
|
|
25174
|
-
clear(
|
|
25175
|
-
clear(
|
|
25176
|
-
rmOwnedDir(
|
|
25177
|
-
const legacy =
|
|
25200
|
+
clear(resolve17(commonDir, "config"));
|
|
25201
|
+
clear(resolve17(commonDir, "config.worktree"));
|
|
25202
|
+
rmOwnedDir(resolve17(commonDir, HOOKS_DIR));
|
|
25203
|
+
const legacy = resolve17(commonDir, "hooks", HOOK_FILE);
|
|
25178
25204
|
if (ownedHook(legacy)) rmSync(legacy, { force: true });
|
|
25179
25205
|
for (const gitDir of linkedGitDirs(commonDir)) {
|
|
25180
|
-
clear(
|
|
25181
|
-
rmOwnedDir(
|
|
25206
|
+
clear(resolve17(gitDir, "config.worktree"));
|
|
25207
|
+
rmOwnedDir(resolve17(gitDir, HOOKS_DIR));
|
|
25182
25208
|
}
|
|
25183
25209
|
}
|
|
25184
25210
|
function isRecord13(value) {
|
|
@@ -25931,7 +25957,7 @@ async function executeActivationStage(role, stage, infrastructure) {
|
|
|
25931
25957
|
throw activationError;
|
|
25932
25958
|
}
|
|
25933
25959
|
}
|
|
25934
|
-
function writeActivationTraceRecord(record4, write =
|
|
25960
|
+
function writeActivationTraceRecord(record4, write = writeSync3) {
|
|
25935
25961
|
writeStderrJsonlRecord(record4, write);
|
|
25936
25962
|
}
|
|
25937
25963
|
var ActivationBarrierError = class extends Error {
|
|
@@ -27163,11 +27189,8 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
27163
27189
|
}
|
|
27164
27190
|
};
|
|
27165
27191
|
try {
|
|
27166
|
-
|
|
27167
|
-
|
|
27168
|
-
const sessionFile = ctx.sessionManager.getSessionFile?.() || ctx.sessionManager.getSessionDir?.();
|
|
27169
|
-
const ledgerHome = resolveActivationLedgerHomeForPath(sessionFile);
|
|
27170
|
-
const session = durableSessionPointer(ctx.sessionManager);
|
|
27192
|
+
resolveBookKeyFromGit(ctx.cwd);
|
|
27193
|
+
durableSessionPointer(ctx.sessionManager);
|
|
27171
27194
|
const isStationChild = roleHost.getFlag(STATION_CHILD_FLAG.name) === true;
|
|
27172
27195
|
if (dependencies.createNavigatorAttendance !== void 0 && entry.role !== "navigator" && !isStationChild) {
|
|
27173
27196
|
navigatorSessionParent = ctx.sessionManager.getSessionFile();
|
|
@@ -27254,16 +27277,6 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
27254
27277
|
if (entry.role === "coder") coder.armSubmissionGate(ctx.cwd, ctx.sessionManager);
|
|
27255
27278
|
else fixer.armSubmissionGate(ctx.cwd, ctx.sessionManager);
|
|
27256
27279
|
}
|
|
27257
|
-
appendAcceptedActivationToBook({
|
|
27258
|
-
ledgerHome,
|
|
27259
|
-
fact: buildAcceptedActivationFact({
|
|
27260
|
-
role: entry.role,
|
|
27261
|
-
observedAt: clock(),
|
|
27262
|
-
bookKey,
|
|
27263
|
-
session,
|
|
27264
|
-
correlation
|
|
27265
|
-
})
|
|
27266
|
-
});
|
|
27267
27280
|
admitted = true;
|
|
27268
27281
|
} catch (error) {
|
|
27269
27282
|
failInfrastructure(error, ctx);
|
|
@@ -27277,11 +27290,11 @@ init_role_activation_flags();
|
|
|
27277
27290
|
init_submission_correctable_error();
|
|
27278
27291
|
init_navigator_invocation_identity();
|
|
27279
27292
|
async function listen(server, path) {
|
|
27280
|
-
await new Promise((
|
|
27293
|
+
await new Promise((resolve21, reject) => {
|
|
27281
27294
|
server.once("error", reject);
|
|
27282
27295
|
server.listen(path, () => {
|
|
27283
27296
|
server.off("error", reject);
|
|
27284
|
-
|
|
27297
|
+
resolve21();
|
|
27285
27298
|
});
|
|
27286
27299
|
});
|
|
27287
27300
|
}
|
|
@@ -27317,7 +27330,7 @@ async function prepareRoleEnvelope(options) {
|
|
|
27317
27330
|
const runId = request.runDirectory.split("/").filter(Boolean).at(-1) ?? randomUUID9();
|
|
27318
27331
|
await mkdir7(request.runDirectory, { recursive: true });
|
|
27319
27332
|
let sessionFile = options.sessionFile ?? join41(request.runDirectory, "session", "session.jsonl");
|
|
27320
|
-
await mkdir7(
|
|
27333
|
+
await mkdir7(dirname21(sessionFile), { recursive: true });
|
|
27321
27334
|
if (request.continuation.kind !== "resume") {
|
|
27322
27335
|
try {
|
|
27323
27336
|
await writeFile12(
|
|
@@ -27367,7 +27380,7 @@ async function prepareRoleEnvelope(options) {
|
|
|
27367
27380
|
getLeafEntry: () => sessionEntries.at(-1),
|
|
27368
27381
|
getLeafId: () => runId,
|
|
27369
27382
|
getEntries: () => sessionEntries,
|
|
27370
|
-
getSessionDir: () =>
|
|
27383
|
+
getSessionDir: () => dirname21(sessionFile),
|
|
27371
27384
|
getSessionFile: () => sessionFile,
|
|
27372
27385
|
getHeader: () => ({ type: "session", id: runId }),
|
|
27373
27386
|
setSessionFile(path) {
|
|
@@ -27714,8 +27727,8 @@ async function prepareRoleEnvelope(options) {
|
|
|
27714
27727
|
try {
|
|
27715
27728
|
const closeAll = server.closeAllConnections;
|
|
27716
27729
|
if (typeof closeAll === "function") closeAll.call(server);
|
|
27717
|
-
await new Promise((
|
|
27718
|
-
server.close((error) => error ? reject(error) :
|
|
27730
|
+
await new Promise((resolve21, reject) => {
|
|
27731
|
+
server.close((error) => error ? reject(error) : resolve21());
|
|
27719
27732
|
});
|
|
27720
27733
|
} catch (error) {
|
|
27721
27734
|
cleanupFailures.push(error);
|
|
@@ -27857,12 +27870,12 @@ import { join as join42 } from "node:path";
|
|
|
27857
27870
|
// src/canonical-skill-binding.ts
|
|
27858
27871
|
import { readFile as readFile20, realpath as realpath8 } from "node:fs/promises";
|
|
27859
27872
|
import { homedir } from "node:os";
|
|
27860
|
-
import { dirname as
|
|
27873
|
+
import { dirname as dirname22, resolve as resolve18 } from "node:path";
|
|
27861
27874
|
import { stripFrontmatter } from "@earendil-works/pi-coding-agent";
|
|
27862
27875
|
function captureCanonicalSkillExpansion(name, snapshot, configuredPath, evidence, originalRequest) {
|
|
27863
27876
|
const matchedPath = evidence?.location === configuredPath ? configuredPath : evidence?.location === snapshot.path ? snapshot.path : void 0;
|
|
27864
27877
|
const expectedContent = matchedPath === void 0 ? void 0 : snapshot.body;
|
|
27865
|
-
const prefixedContent = matchedPath === void 0 ? void 0 : `References are relative to ${
|
|
27878
|
+
const prefixedContent = matchedPath === void 0 ? void 0 : `References are relative to ${dirname22(matchedPath)}.
|
|
27866
27879
|
|
|
27867
27880
|
${snapshot.body}`;
|
|
27868
27881
|
if (evidence?.name !== name || matchedPath === void 0 || evidence.content !== expectedContent && evidence.content !== prefixedContent || evidence.userMessage !== originalRequest) {
|
|
@@ -27880,7 +27893,7 @@ var CanonicalSkillUnavailableError = class extends Error {
|
|
|
27880
27893
|
code = "canonical-skill-unavailable";
|
|
27881
27894
|
};
|
|
27882
27895
|
async function loadCanonicalSkillBinding(name) {
|
|
27883
|
-
const configuredPath =
|
|
27896
|
+
const configuredPath = resolve18(
|
|
27884
27897
|
homedir(),
|
|
27885
27898
|
`.agents/skills/${name}/SKILL.md`
|
|
27886
27899
|
);
|
|
@@ -27899,7 +27912,7 @@ async function loadCanonicalSkillBinding(name) {
|
|
|
27899
27912
|
const snapshot = Object.freeze({
|
|
27900
27913
|
raw,
|
|
27901
27914
|
path,
|
|
27902
|
-
baseDir:
|
|
27915
|
+
baseDir: dirname22(path),
|
|
27903
27916
|
body,
|
|
27904
27917
|
snapshotIdentity: Object.freeze({ text: raw })
|
|
27905
27918
|
});
|
|
@@ -27928,7 +27941,7 @@ init_doctor_evidence();
|
|
|
27928
27941
|
init_doctor_evidence();
|
|
27929
27942
|
init_host_contracts();
|
|
27930
27943
|
import { readFile as readFile21 } from "node:fs/promises";
|
|
27931
|
-
import { resolve as
|
|
27944
|
+
import { resolve as resolve19 } from "node:path";
|
|
27932
27945
|
init_notary_source_run();
|
|
27933
27946
|
init_packaged_role_registry();
|
|
27934
27947
|
init_invocation();
|
|
@@ -27936,7 +27949,7 @@ function navigatorInputReference(getFlag, role) {
|
|
|
27936
27949
|
if (getFlag === void 0) return void 0;
|
|
27937
27950
|
const name = packagedRoleInputFlag(role);
|
|
27938
27951
|
const value = name === void 0 ? void 0 : getFlag(name);
|
|
27939
|
-
return typeof value === "string" && value !== "" ?
|
|
27952
|
+
return typeof value === "string" && value !== "" ? resolve19(value) : void 0;
|
|
27940
27953
|
}
|
|
27941
27954
|
async function loadNavigatorWorkContext(options) {
|
|
27942
27955
|
const reference = navigatorInputReference(options.getFlag, options.role);
|
|
@@ -27957,7 +27970,7 @@ async function loadNavigatorWorkContext(options) {
|
|
|
27957
27970
|
}
|
|
27958
27971
|
const publicRunDir = runDirectoryFromHostContext(options.context);
|
|
27959
27972
|
const currentSessionDir = options.context.sessionManager.getSessionDir();
|
|
27960
|
-
const isBoundPublicRun = publicRunDir !== void 0 &&
|
|
27973
|
+
const isBoundPublicRun = publicRunDir !== void 0 && resolve19(currentSessionDir) === resolve19(publicRunDir, "session");
|
|
27961
27974
|
if (options.role === "judge" && isBoundPublicRun) {
|
|
27962
27975
|
let admitted;
|
|
27963
27976
|
try {
|
|
@@ -27990,9 +28003,9 @@ async function loadNavigatorWorkContext(options) {
|
|
|
27990
28003
|
}
|
|
27991
28004
|
const workRoot = subjectRoot.includes("/.ak/work/") ? subjectRoot : void 0;
|
|
27992
28005
|
const authorityFiles = workRoot === void 0 ? [] : [
|
|
27993
|
-
|
|
27994
|
-
|
|
27995
|
-
|
|
28006
|
+
resolve19(workRoot, "authority.md"),
|
|
28007
|
+
resolve19(workRoot, "authority.txt"),
|
|
28008
|
+
resolve19(workRoot, "design-v2/owner-direction.md")
|
|
27996
28009
|
];
|
|
27997
28010
|
let authorityMaterial;
|
|
27998
28011
|
for (const path of authorityFiles) {
|
|
@@ -28022,7 +28035,7 @@ async function loadNavigatorWorkContext(options) {
|
|
|
28022
28035
|
init_notary_source_run();
|
|
28023
28036
|
|
|
28024
28037
|
// src/package-resources/method-skill-binding.ts
|
|
28025
|
-
import { dirname as
|
|
28038
|
+
import { dirname as dirname23 } from "node:path";
|
|
28026
28039
|
init_method_skill();
|
|
28027
28040
|
async function loadPackagedCanonicalSkillBinding(packageRoot, name) {
|
|
28028
28041
|
const material = await loadPackagedMethodSkillMaterial(packageRoot, name);
|
|
@@ -28030,7 +28043,7 @@ async function loadPackagedCanonicalSkillBinding(packageRoot, name) {
|
|
|
28030
28043
|
const snapshot = Object.freeze({
|
|
28031
28044
|
raw: material.raw,
|
|
28032
28045
|
path: material.skillPath,
|
|
28033
|
-
baseDir:
|
|
28046
|
+
baseDir: dirname23(material.skillPath),
|
|
28034
28047
|
body: material.body,
|
|
28035
28048
|
snapshotIdentity: Object.freeze({ text: material.raw })
|
|
28036
28049
|
});
|
|
@@ -28176,7 +28189,7 @@ function hostAbortedError(message = "host aborted") {
|
|
|
28176
28189
|
function raceAgainstHostAbort(work, abortSignal, message = "host aborted") {
|
|
28177
28190
|
if (abortSignal?.aborted) return Promise.reject(hostAbortedError(message));
|
|
28178
28191
|
if (abortSignal === void 0) return work;
|
|
28179
|
-
return new Promise((
|
|
28192
|
+
return new Promise((resolve21, reject) => {
|
|
28180
28193
|
let settled = false;
|
|
28181
28194
|
const onAbort = () => {
|
|
28182
28195
|
if (settled) return;
|
|
@@ -28191,7 +28204,7 @@ function raceAgainstHostAbort(work, abortSignal, message = "host aborted") {
|
|
|
28191
28204
|
if (settled) return;
|
|
28192
28205
|
settled = true;
|
|
28193
28206
|
abortSignal.removeEventListener("abort", onAbort);
|
|
28194
|
-
|
|
28207
|
+
resolve21(value);
|
|
28195
28208
|
},
|
|
28196
28209
|
(error) => {
|
|
28197
28210
|
if (settled) return;
|
|
@@ -28431,8 +28444,8 @@ function connectAcpStdio(options) {
|
|
|
28431
28444
|
request(method, params) {
|
|
28432
28445
|
if (closed) return Promise.reject(terminalError ?? acpError("acp-connection-closed", "ACP connection is closed"));
|
|
28433
28446
|
const id = ++nextId;
|
|
28434
|
-
return new Promise((
|
|
28435
|
-
pending.set(id, { resolve:
|
|
28447
|
+
return new Promise((resolve21, reject) => {
|
|
28448
|
+
pending.set(id, { resolve: resolve21, reject });
|
|
28436
28449
|
child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", id, method, params })}
|
|
28437
28450
|
`, (error) => {
|
|
28438
28451
|
if (error === null || error === void 0) return;
|
|
@@ -28459,7 +28472,7 @@ function connectAcpStdio(options) {
|
|
|
28459
28472
|
settleClosed(acpError("acp-connection-closed", "ACP connection is closed"));
|
|
28460
28473
|
child.stdin.end();
|
|
28461
28474
|
child.kill("SIGTERM");
|
|
28462
|
-
await new Promise((
|
|
28475
|
+
await new Promise((resolve21) => child.once("close", () => resolve21()));
|
|
28463
28476
|
}
|
|
28464
28477
|
});
|
|
28465
28478
|
}
|
|
@@ -28657,9 +28670,9 @@ function createAcpRoleTurnHost(config) {
|
|
|
28657
28670
|
}
|
|
28658
28671
|
|
|
28659
28672
|
// src/acp-host/seat-profile-soul.ts
|
|
28660
|
-
import { constants as
|
|
28673
|
+
import { constants as constants2 } from "node:fs";
|
|
28661
28674
|
import { access as access4, copyFile, lstat as lstat8, mkdir as mkdir8, readlink as readlink2, symlink as symlink2, unlink as unlink3 } from "node:fs/promises";
|
|
28662
|
-
import { dirname as
|
|
28675
|
+
import { dirname as dirname24, join as join44, relative as relative4, resolve as resolve20 } from "node:path";
|
|
28663
28676
|
function seatProfileName(spec, role) {
|
|
28664
28677
|
return `${spec.namePrefix}${role}`;
|
|
28665
28678
|
}
|
|
@@ -28668,7 +28681,7 @@ function packageRoleSoulPath(packageRoot, role) {
|
|
|
28668
28681
|
}
|
|
28669
28682
|
async function pathExists2(path) {
|
|
28670
28683
|
try {
|
|
28671
|
-
await access4(path,
|
|
28684
|
+
await access4(path, constants2.F_OK);
|
|
28672
28685
|
return true;
|
|
28673
28686
|
} catch {
|
|
28674
28687
|
return false;
|
|
@@ -28677,13 +28690,13 @@ async function pathExists2(path) {
|
|
|
28677
28690
|
async function ensureSeatProfileSoul(options) {
|
|
28678
28691
|
const { spec, operatorHome, packageRoot, role } = options;
|
|
28679
28692
|
const profileName = seatProfileName(spec, role);
|
|
28680
|
-
const soulTarget =
|
|
28693
|
+
const soulTarget = resolve20(packageRoleSoulPath(packageRoot, role));
|
|
28681
28694
|
if (!await pathExists2(soulTarget)) {
|
|
28682
28695
|
throw new Error(`packaged role soul missing: ${soulTarget}`);
|
|
28683
28696
|
}
|
|
28684
28697
|
const profilesRoot = join44(operatorHome, ...spec.profilesRootFromHome);
|
|
28685
28698
|
const profileDir = join44(profilesRoot, profileName);
|
|
28686
|
-
const hostRoot =
|
|
28699
|
+
const hostRoot = dirname24(profilesRoot);
|
|
28687
28700
|
const soulPath = join44(profileDir, spec.soulFileName);
|
|
28688
28701
|
if (!await pathExists2(profileDir)) {
|
|
28689
28702
|
await mkdir8(profileDir, { recursive: true });
|