@akagilnc/pi-workflow-roles 0.1.4243 → 0.1.4259
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 +1 -1
- package/README.zh-CN.md +1 -1
- package/dist/acp-host/production-host.js +547 -221
- package/dist/engine-detour-tool.js +64 -5
- package/dist/engine-detour-usage.js +285 -0
- package/dist/headless-host/production-host.js +557 -231
- package/dist/pi/role-turn-host.js +10 -0
- package/dist/public-cli/main.js +433 -202
- package/dist/public-cli/post-admission.js +72 -43
- package/dist/public-cli/settlement.js +80 -24
- package/dist/public-cli/turn-request.js +3 -0
- package/package.json +1 -1
- package/src/engine-detour-tool.ts +106 -8
- package/src/engine-detour-usage.ts +373 -0
- package/src/host-contracts.ts +12 -1
- package/src/pi/adapter.ts +6 -0
- package/src/pi/role-turn-host.ts +6 -0
- package/src/public-cli/post-admission.ts +91 -49
- package/src/public-cli/settlement.ts +148 -23
- package/src/public-cli/turn-request.ts +5 -0
- package/src/role-envelope.ts +2 -0
|
@@ -3181,6 +3181,10 @@ ${paths.join("\n")}`
|
|
|
3181
3181
|
};
|
|
3182
3182
|
if (request.courtAttemptId === void 0) delete env.AK_ROLE_COURT_ATTEMPT;
|
|
3183
3183
|
else env.AK_ROLE_COURT_ATTEMPT = request.courtAttemptId;
|
|
3184
|
+
if (request.invocationScopeId === void 0) delete env.AK_ROLE_INVOCATION_SCOPE;
|
|
3185
|
+
else env.AK_ROLE_INVOCATION_SCOPE = request.invocationScopeId;
|
|
3186
|
+
if (request.host === void 0 || request.host.trim() === "") delete env.AK_ROLE_HOST;
|
|
3187
|
+
else env.AK_ROLE_HOST = request.host.trim();
|
|
3184
3188
|
applyEngineChildEnv(env, request.engine);
|
|
3185
3189
|
if (typeof process.env.AK_ROLE_AUDITOR_SOURCE_RUN === "string" && process.env.AK_ROLE_AUDITOR_SOURCE_RUN.trim() !== "") {
|
|
3186
3190
|
env.AK_ROLE_AUDITOR_SOURCE_RUN = process.env.AK_ROLE_AUDITOR_SOURCE_RUN;
|
|
@@ -3384,10 +3388,10 @@ __export(session_assistant_usage_exports, {
|
|
|
3384
3388
|
});
|
|
3385
3389
|
import { join as join13 } from "node:path";
|
|
3386
3390
|
async function readAssistantUsageFromSessionFile(sessionFile) {
|
|
3387
|
-
const { readFile:
|
|
3391
|
+
const { readFile: readFile25 } = await import("node:fs/promises");
|
|
3388
3392
|
let text;
|
|
3389
3393
|
try {
|
|
3390
|
-
text = await
|
|
3394
|
+
text = await readFile25(sessionFile, "utf8");
|
|
3391
3395
|
} catch (error) {
|
|
3392
3396
|
if (error?.code === "ENOENT") return void 0;
|
|
3393
3397
|
throw error;
|
|
@@ -11466,9 +11470,209 @@ var init_case_dossier_delivery = __esm({
|
|
|
11466
11470
|
}
|
|
11467
11471
|
});
|
|
11468
11472
|
|
|
11473
|
+
// src/engine-detour-usage.ts
|
|
11474
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
11475
|
+
import { readFileSync as readFileSync4 } from "node:fs";
|
|
11476
|
+
import { dirname as dirname14, join as join26 } from "node:path";
|
|
11477
|
+
function engineDetourStdoutByteLength(stdout) {
|
|
11478
|
+
return Buffer.byteLength(stdout, "utf8");
|
|
11479
|
+
}
|
|
11480
|
+
function engineDetourCallIdentity(input) {
|
|
11481
|
+
const scope = input.invocationScopeId ?? "";
|
|
11482
|
+
return `engine-detour-call:${scope}:${input.toolCallId}`;
|
|
11483
|
+
}
|
|
11484
|
+
function reportEngineDetourCall(input) {
|
|
11485
|
+
const payload = {
|
|
11486
|
+
tool: ENGINE_DETOUR_TOOL_NAME,
|
|
11487
|
+
toolCallId: input.toolCallId,
|
|
11488
|
+
durationMs: input.durationMs
|
|
11489
|
+
};
|
|
11490
|
+
if (input.code !== void 0) payload.code = input.code;
|
|
11491
|
+
if (input.stdoutByteLength !== void 0) {
|
|
11492
|
+
payload.stdoutByteLength = input.stdoutByteLength;
|
|
11493
|
+
}
|
|
11494
|
+
if (input.invocationScopeId !== void 0) {
|
|
11495
|
+
payload.invocationScopeId = input.invocationScopeId;
|
|
11496
|
+
}
|
|
11497
|
+
if (input.runId !== void 0) payload.runId = input.runId;
|
|
11498
|
+
const subject = input.runId === void 0 ? void 0 : {
|
|
11499
|
+
runId: input.runId,
|
|
11500
|
+
...input.invocationScopeId === void 0 ? {} : { invocationScopeId: input.invocationScopeId }
|
|
11501
|
+
};
|
|
11502
|
+
const pointer = sitianReport({
|
|
11503
|
+
level: "event",
|
|
11504
|
+
kind: ENGINE_DETOUR_CALL_KIND,
|
|
11505
|
+
identity: engineDetourCallIdentity({
|
|
11506
|
+
toolCallId: input.toolCallId,
|
|
11507
|
+
...input.invocationScopeId === void 0 ? {} : { invocationScopeId: input.invocationScopeId }
|
|
11508
|
+
}),
|
|
11509
|
+
cwd: input.cwd,
|
|
11510
|
+
sessionParent: input.sessionParent,
|
|
11511
|
+
source: "engine-detour-tool",
|
|
11512
|
+
payload,
|
|
11513
|
+
raw: {
|
|
11514
|
+
sessionFile: input.sessionParent,
|
|
11515
|
+
entryId: input.toolCallId
|
|
11516
|
+
},
|
|
11517
|
+
...input.home === void 0 ? {} : { home: input.home },
|
|
11518
|
+
...input.host === void 0 ? {} : { host: input.host },
|
|
11519
|
+
...subject === void 0 ? {} : { subject }
|
|
11520
|
+
});
|
|
11521
|
+
return {
|
|
11522
|
+
toolCallId: input.toolCallId,
|
|
11523
|
+
durationMs: input.durationMs,
|
|
11524
|
+
...input.code === void 0 ? {} : { code: input.code },
|
|
11525
|
+
...input.stdoutByteLength === void 0 ? {} : { stdoutByteLength: input.stdoutByteLength },
|
|
11526
|
+
recordPointer: pointer
|
|
11527
|
+
};
|
|
11528
|
+
}
|
|
11529
|
+
function isRecord7(value) {
|
|
11530
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11531
|
+
}
|
|
11532
|
+
function callFactFromSitianPayload(payload, pointer) {
|
|
11533
|
+
if (!isRecord7(payload)) return void 0;
|
|
11534
|
+
if (payload.tool !== ENGINE_DETOUR_TOOL_NAME) return void 0;
|
|
11535
|
+
if (typeof payload.toolCallId !== "string" || payload.toolCallId.length === 0) {
|
|
11536
|
+
return void 0;
|
|
11537
|
+
}
|
|
11538
|
+
if (typeof payload.durationMs !== "number" || !Number.isFinite(payload.durationMs)) {
|
|
11539
|
+
return void 0;
|
|
11540
|
+
}
|
|
11541
|
+
return {
|
|
11542
|
+
toolCallId: payload.toolCallId,
|
|
11543
|
+
durationMs: payload.durationMs,
|
|
11544
|
+
...typeof payload.code === "number" ? { code: payload.code } : {},
|
|
11545
|
+
...typeof payload.stdoutByteLength === "number" ? { stdoutByteLength: payload.stdoutByteLength } : {},
|
|
11546
|
+
recordPointer: pointer
|
|
11547
|
+
};
|
|
11548
|
+
}
|
|
11549
|
+
function invocationScopeIdOfRecord(record4) {
|
|
11550
|
+
if (isRecord7(record4.subject)) {
|
|
11551
|
+
const fromSubject = record4.subject.invocationScopeId;
|
|
11552
|
+
if (typeof fromSubject === "string" && fromSubject.length > 0) return fromSubject;
|
|
11553
|
+
}
|
|
11554
|
+
if (isRecord7(record4.payload)) {
|
|
11555
|
+
const fromPayload = record4.payload.invocationScopeId;
|
|
11556
|
+
if (typeof fromPayload === "string" && fromPayload.length > 0) return fromPayload;
|
|
11557
|
+
}
|
|
11558
|
+
return void 0;
|
|
11559
|
+
}
|
|
11560
|
+
async function readEngineDetourToolUsage(input) {
|
|
11561
|
+
if (!input.engineMounted) return void 0;
|
|
11562
|
+
const { recordFile } = resolveSitianRecordPath({
|
|
11563
|
+
level: "event",
|
|
11564
|
+
kind: ENGINE_DETOUR_CALL_KIND,
|
|
11565
|
+
sessionParent: input.sessionParent,
|
|
11566
|
+
...input.home === void 0 ? {} : { home: input.home },
|
|
11567
|
+
...input.cwd === void 0 ? {} : { cwd: input.cwd }
|
|
11568
|
+
});
|
|
11569
|
+
const { records } = await readSitianRecords(recordFile);
|
|
11570
|
+
const calls = [];
|
|
11571
|
+
for (const record4 of records) {
|
|
11572
|
+
if (record4.kind !== ENGINE_DETOUR_CALL_KIND) continue;
|
|
11573
|
+
const boundScope = invocationScopeIdOfRecord(record4);
|
|
11574
|
+
if (input.invocationScopeId !== void 0 && input.invocationScopeId.length > 0) {
|
|
11575
|
+
if (boundScope !== input.invocationScopeId) continue;
|
|
11576
|
+
} else if (boundScope !== void 0) {
|
|
11577
|
+
continue;
|
|
11578
|
+
}
|
|
11579
|
+
const pointer = {
|
|
11580
|
+
identity: record4.identity,
|
|
11581
|
+
recordFile,
|
|
11582
|
+
kind: record4.kind,
|
|
11583
|
+
level: record4.level
|
|
11584
|
+
};
|
|
11585
|
+
const fact = callFactFromSitianPayload(record4.payload, pointer);
|
|
11586
|
+
if (fact === void 0) continue;
|
|
11587
|
+
calls.push(fact);
|
|
11588
|
+
}
|
|
11589
|
+
return { callCount: calls.length, calls };
|
|
11590
|
+
}
|
|
11591
|
+
function projectEngineDetourToolUsageForPublicTerminal(usage, options) {
|
|
11592
|
+
if (options.discloseRecordFile) return usage;
|
|
11593
|
+
return {
|
|
11594
|
+
callCount: usage.callCount,
|
|
11595
|
+
calls: usage.calls.map((call) => ({
|
|
11596
|
+
toolCallId: call.toolCallId,
|
|
11597
|
+
durationMs: call.durationMs,
|
|
11598
|
+
...call.code === void 0 ? {} : { code: call.code },
|
|
11599
|
+
...call.stdoutByteLength === void 0 ? {} : { stdoutByteLength: call.stdoutByteLength },
|
|
11600
|
+
recordPointer: {
|
|
11601
|
+
identity: call.recordPointer.identity,
|
|
11602
|
+
kind: call.recordPointer.kind,
|
|
11603
|
+
level: call.recordPointer.level,
|
|
11604
|
+
recordFile: ENGINE_DETOUR_CALL_RECORD_FILE_RELATIVE
|
|
11605
|
+
}
|
|
11606
|
+
}))
|
|
11607
|
+
};
|
|
11608
|
+
}
|
|
11609
|
+
function readInvocationRecord(runDirectory) {
|
|
11610
|
+
try {
|
|
11611
|
+
const raw = JSON.parse(
|
|
11612
|
+
readFileSync4(join26(runDirectory, "invocation.json"), "utf8")
|
|
11613
|
+
);
|
|
11614
|
+
return isRecord7(raw) ? raw : void 0;
|
|
11615
|
+
} catch (error) {
|
|
11616
|
+
if (error?.code === "ENOENT") return void 0;
|
|
11617
|
+
throw error;
|
|
11618
|
+
}
|
|
11619
|
+
}
|
|
11620
|
+
async function readInvocationEngineMounted(runDirectory) {
|
|
11621
|
+
const raw = readInvocationRecord(runDirectory);
|
|
11622
|
+
if (raw === void 0) return false;
|
|
11623
|
+
return typeof raw.engine === "string" && raw.engine.trim() !== "";
|
|
11624
|
+
}
|
|
11625
|
+
function readInvocationSelectedHost(runDirectory) {
|
|
11626
|
+
const raw = readInvocationRecord(runDirectory);
|
|
11627
|
+
if (raw === void 0) return void 0;
|
|
11628
|
+
return typeof raw.host === "string" && raw.host.trim() !== "" ? raw.host.trim() : void 0;
|
|
11629
|
+
}
|
|
11630
|
+
function withEngineDetourToolUsageFact(outcome, usage) {
|
|
11631
|
+
if (usage === void 0) return outcome;
|
|
11632
|
+
const prior = isRecord7(outcome.decisiveFacts) ? outcome.decisiveFacts : {};
|
|
11633
|
+
return {
|
|
11634
|
+
...outcome,
|
|
11635
|
+
decisiveFacts: {
|
|
11636
|
+
...prior,
|
|
11637
|
+
[ENGINE_DETOUR_TOOL_USAGE_FACT_KEY]: usage
|
|
11638
|
+
}
|
|
11639
|
+
};
|
|
11640
|
+
}
|
|
11641
|
+
function runDirectoryFromSessionDirectory(sessionDirectory) {
|
|
11642
|
+
return dirname14(sessionDirectory);
|
|
11643
|
+
}
|
|
11644
|
+
function sessionFileFromSessionDirectory(sessionDirectory) {
|
|
11645
|
+
return join26(sessionDirectory, "session.jsonl");
|
|
11646
|
+
}
|
|
11647
|
+
function mintEngineDetourInvocationScope(input) {
|
|
11648
|
+
const engine = input.effectiveEngine?.trim();
|
|
11649
|
+
if (engine === void 0 || engine.length === 0) return void 0;
|
|
11650
|
+
return randomUUID4();
|
|
11651
|
+
}
|
|
11652
|
+
function withEngineDetourInvocationScope(request, invocationScopeId) {
|
|
11653
|
+
if (invocationScopeId === void 0 || invocationScopeId.length === 0) {
|
|
11654
|
+
return request;
|
|
11655
|
+
}
|
|
11656
|
+
if (typeof request.invocationScopeId === "string" && request.invocationScopeId.length > 0) {
|
|
11657
|
+
return request;
|
|
11658
|
+
}
|
|
11659
|
+
return { ...request, invocationScopeId };
|
|
11660
|
+
}
|
|
11661
|
+
var ENGINE_DETOUR_CALL_KIND, ENGINE_DETOUR_TOOL_USAGE_FACT_KEY, ENGINE_DETOUR_CALL_RECORD_FILE_RELATIVE;
|
|
11662
|
+
var init_engine_detour_usage = __esm({
|
|
11663
|
+
"src/engine-detour-usage.ts"() {
|
|
11664
|
+
"use strict";
|
|
11665
|
+
init_engine_detour();
|
|
11666
|
+
init_sitian_facade();
|
|
11667
|
+
ENGINE_DETOUR_CALL_KIND = "engine-detour-call";
|
|
11668
|
+
ENGINE_DETOUR_TOOL_USAGE_FACT_KEY = "engineDetourToolUsage";
|
|
11669
|
+
ENGINE_DETOUR_CALL_RECORD_FILE_RELATIVE = `session/${ENGINE_DETOUR_CALL_KIND}/records.jsonl`;
|
|
11670
|
+
}
|
|
11671
|
+
});
|
|
11672
|
+
|
|
11469
11673
|
// src/host-transition-prior-native.ts
|
|
11470
11674
|
import { access as access3, readdir as readdir5 } from "node:fs/promises";
|
|
11471
|
-
import { dirname as
|
|
11675
|
+
import { dirname as dirname15, join as join27 } from "node:path";
|
|
11472
11676
|
function isEnoent3(error) {
|
|
11473
11677
|
return typeof error === "object" && error !== null && error.code === "ENOENT";
|
|
11474
11678
|
}
|
|
@@ -11482,7 +11686,7 @@ async function listPiNativeRecordPaths(sessionFile) {
|
|
|
11482
11686
|
}
|
|
11483
11687
|
}
|
|
11484
11688
|
async function listSitianRecordPaths(sessionParent) {
|
|
11485
|
-
const sessionRoot =
|
|
11689
|
+
const sessionRoot = dirname15(sessionParent);
|
|
11486
11690
|
let entries;
|
|
11487
11691
|
try {
|
|
11488
11692
|
entries = await readdir5(sessionRoot, { withFileTypes: true });
|
|
@@ -11493,7 +11697,7 @@ async function listSitianRecordPaths(sessionParent) {
|
|
|
11493
11697
|
const recordPaths = [];
|
|
11494
11698
|
for (const entry of entries) {
|
|
11495
11699
|
if (!entry.isDirectory()) continue;
|
|
11496
|
-
const recordFile =
|
|
11700
|
+
const recordFile = join27(sessionRoot, entry.name, "records.jsonl");
|
|
11497
11701
|
try {
|
|
11498
11702
|
await access3(recordFile);
|
|
11499
11703
|
recordPaths.push(recordFile);
|
|
@@ -11885,12 +12089,12 @@ var init_reviewer_dispatch = __esm({
|
|
|
11885
12089
|
|
|
11886
12090
|
// src/public-cli/reviewer-dispatch-rejection.ts
|
|
11887
12091
|
import { readFile as readFile16, unlink as unlink3 } from "node:fs/promises";
|
|
11888
|
-
import { join as
|
|
12092
|
+
import { join as join28 } from "node:path";
|
|
11889
12093
|
function isReviewerPreflightViolation(value) {
|
|
11890
12094
|
return typeof value === "string" && REVIEWER_PREFLIGHT_VIOLATIONS.includes(value);
|
|
11891
12095
|
}
|
|
11892
12096
|
function reviewerDispatchRejectionPath(runDirectory) {
|
|
11893
|
-
return
|
|
12097
|
+
return join28(runDirectory, REVIEWER_DISPATCH_REJECTION_FILE);
|
|
11894
12098
|
}
|
|
11895
12099
|
async function clearReviewerDispatchRejection(runDirectory) {
|
|
11896
12100
|
try {
|
|
@@ -11942,8 +12146,8 @@ var init_reviewer_dispatch_rejection = __esm({
|
|
|
11942
12146
|
|
|
11943
12147
|
// src/analyst-gate-cycles-read.ts
|
|
11944
12148
|
import { readdir as readdir6 } from "node:fs/promises";
|
|
11945
|
-
import { join as
|
|
11946
|
-
function
|
|
12149
|
+
import { join as join29 } from "node:path";
|
|
12150
|
+
function isRecord8(value) {
|
|
11947
12151
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11948
12152
|
}
|
|
11949
12153
|
function isParentAttemptBindingRow(row) {
|
|
@@ -11973,7 +12177,7 @@ function isGateTerminatingToolName(toolName) {
|
|
|
11973
12177
|
function acceptedGateReceiptIds(rows) {
|
|
11974
12178
|
const accepted = /* @__PURE__ */ new Set();
|
|
11975
12179
|
for (const row of rows) {
|
|
11976
|
-
const message =
|
|
12180
|
+
const message = isRecord8(row.message) ? row.message : void 0;
|
|
11977
12181
|
if (message?.role !== "toolResult") continue;
|
|
11978
12182
|
if (typeof message.toolCallId !== "string" || message.toolCallId.length === 0) continue;
|
|
11979
12183
|
if (message.isError === false) accepted.add(message.toolCallId);
|
|
@@ -12008,7 +12212,7 @@ function nearestAttemptBindingBefore(rows, beforeIndex) {
|
|
|
12008
12212
|
for (let i = beforeIndex - 1; i >= 0; i -= 1) {
|
|
12009
12213
|
const row = rows[i];
|
|
12010
12214
|
if (!isParentAttemptBindingRow(row)) continue;
|
|
12011
|
-
if (!
|
|
12215
|
+
if (!isRecord8(row.data) || !isRecord8(row.data.parent)) continue;
|
|
12012
12216
|
const id = row.data.parent.attemptEntryId;
|
|
12013
12217
|
const sessionFile = row.data.parent.sessionFile;
|
|
12014
12218
|
return {
|
|
@@ -12023,10 +12227,10 @@ function extractAllAcceptedGateToolCalls(rows) {
|
|
|
12023
12227
|
const out = [];
|
|
12024
12228
|
for (let rowIndex = 0; rowIndex < rows.length; rowIndex += 1) {
|
|
12025
12229
|
const row = rows[rowIndex];
|
|
12026
|
-
const message =
|
|
12230
|
+
const message = isRecord8(row.message) ? row.message : void 0;
|
|
12027
12231
|
if (message?.role !== "assistant" || !Array.isArray(message.content)) continue;
|
|
12028
12232
|
for (const part of message.content) {
|
|
12029
|
-
if (!
|
|
12233
|
+
if (!isRecord8(part) || part.type !== "toolCall") continue;
|
|
12030
12234
|
if (typeof part.id !== "string" || part.id.length === 0) continue;
|
|
12031
12235
|
if (typeof part.name !== "string" || part.name.length === 0) continue;
|
|
12032
12236
|
if (!isGateTerminatingToolName(part.name)) continue;
|
|
@@ -12034,7 +12238,7 @@ function extractAllAcceptedGateToolCalls(rows) {
|
|
|
12034
12238
|
const binding = nearestAttemptBindingBefore(rows, rowIndex);
|
|
12035
12239
|
out.push({
|
|
12036
12240
|
toolName: part.name,
|
|
12037
|
-
args:
|
|
12241
|
+
args: isRecord8(part.arguments) ? part.arguments : void 0,
|
|
12038
12242
|
accepted: true,
|
|
12039
12243
|
rowIndex,
|
|
12040
12244
|
...binding
|
|
@@ -12157,17 +12361,17 @@ function pairGateRounds(volumes) {
|
|
|
12157
12361
|
return rounds.sort((a, b) => a.officerStartedAt.localeCompare(b.officerStartedAt)).map((round, index) => ({ ...round, roundIndex: index + 1 }));
|
|
12158
12362
|
}
|
|
12159
12363
|
async function resolveOfficerSessionFromPointerFile(pointerPath) {
|
|
12160
|
-
const { readFile:
|
|
12364
|
+
const { readFile: readFile25 } = await import("node:fs/promises");
|
|
12161
12365
|
let raw;
|
|
12162
12366
|
try {
|
|
12163
|
-
raw = JSON.parse(await
|
|
12367
|
+
raw = JSON.parse(await readFile25(pointerPath, "utf8"));
|
|
12164
12368
|
} catch (error) {
|
|
12165
12369
|
throw new Error(
|
|
12166
12370
|
`direct officer run pointer unreadable in ${pointerPath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
12167
12371
|
{ cause: error }
|
|
12168
12372
|
);
|
|
12169
12373
|
}
|
|
12170
|
-
if (!
|
|
12374
|
+
if (!isRecord8(raw) || raw.kind !== "direct-officer-run-pointer" || raw.version !== 1) {
|
|
12171
12375
|
throw new Error(`direct officer run pointer has unknown shape in ${pointerPath}`);
|
|
12172
12376
|
}
|
|
12173
12377
|
const sessionFile = raw.sessionFile;
|
|
@@ -12192,7 +12396,7 @@ async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory, opti
|
|
|
12192
12396
|
throw error;
|
|
12193
12397
|
}
|
|
12194
12398
|
for (const name of names) {
|
|
12195
|
-
const path =
|
|
12399
|
+
const path = join29(directory, name);
|
|
12196
12400
|
const fromPointer = name.endsWith(".pointer.json");
|
|
12197
12401
|
const sessionPath = fromPointer ? await resolveOfficerSessionFromPointerFile(path) : path;
|
|
12198
12402
|
if (sessionPath === void 0) continue;
|
|
@@ -12331,7 +12535,7 @@ var init_audit_escalation = __esm({
|
|
|
12331
12535
|
});
|
|
12332
12536
|
|
|
12333
12537
|
// src/run-terminal-artifacts.ts
|
|
12334
|
-
import { basename as basename8, dirname as
|
|
12538
|
+
import { basename as basename8, dirname as dirname16, join as join30 } from "node:path";
|
|
12335
12539
|
function runIdFromRunDirectory(runDirectory) {
|
|
12336
12540
|
const name = basename8(runDirectory);
|
|
12337
12541
|
const at = name.lastIndexOf("@");
|
|
@@ -12346,7 +12550,7 @@ var init_run_terminal_artifacts = __esm({
|
|
|
12346
12550
|
});
|
|
12347
12551
|
|
|
12348
12552
|
// src/submission-ledger.ts
|
|
12349
|
-
import { join as
|
|
12553
|
+
import { join as join31 } from "node:path";
|
|
12350
12554
|
function runIdentity(context) {
|
|
12351
12555
|
const directory = runDirectoryFromHostContext(context);
|
|
12352
12556
|
if (directory !== void 0) {
|
|
@@ -12368,7 +12572,7 @@ async function submissionRecordFile(cwd, runId, scope) {
|
|
|
12368
12572
|
if (sessionParent === void 0) {
|
|
12369
12573
|
const discoveredRun = await findRunDirectoryById(scope.home, runId);
|
|
12370
12574
|
if (discoveredRun === void 0) return void 0;
|
|
12371
|
-
sessionParent =
|
|
12575
|
+
sessionParent = join31(discoveredRun, "session", "session.jsonl");
|
|
12372
12576
|
}
|
|
12373
12577
|
return resolveSitianRecordPathInLedger({
|
|
12374
12578
|
level: "event",
|
|
@@ -12573,13 +12777,13 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
|
|
|
12573
12777
|
const sessionParentFromContext = (context) => {
|
|
12574
12778
|
const runDirectory = runDirectoryFromHostContext(context);
|
|
12575
12779
|
if (runDirectory !== void 0) {
|
|
12576
|
-
return
|
|
12780
|
+
return join31(runDirectory, "session", "session.jsonl");
|
|
12577
12781
|
}
|
|
12578
12782
|
const sessionFile = context.sessionManager.getSessionFile?.();
|
|
12579
12783
|
if (typeof sessionFile === "string" && sessionFile.length > 0) return sessionFile;
|
|
12580
12784
|
const sessionDir = context.sessionManager.getSessionDir?.();
|
|
12581
12785
|
if (typeof sessionDir === "string" && sessionDir.length > 0) {
|
|
12582
|
-
return
|
|
12786
|
+
return join31(sessionDir, "session.jsonl");
|
|
12583
12787
|
}
|
|
12584
12788
|
return void 0;
|
|
12585
12789
|
};
|
|
@@ -12742,15 +12946,15 @@ var init_submission_ledger = __esm({
|
|
|
12742
12946
|
// src/session-opening-materials.ts
|
|
12743
12947
|
import { existsSync as existsSync9 } from "node:fs";
|
|
12744
12948
|
import { readFile as readFile17 } from "node:fs/promises";
|
|
12745
|
-
import { dirname as
|
|
12949
|
+
import { dirname as dirname17, join as join32 } from "node:path";
|
|
12746
12950
|
import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "node:url";
|
|
12747
12951
|
function resolvePackageRootDir(moduleUrl = import.meta.url) {
|
|
12748
|
-
let dir =
|
|
12952
|
+
let dir = dirname17(fileURLToPath(moduleUrl));
|
|
12749
12953
|
for (let i = 0; i < 8; i += 1) {
|
|
12750
|
-
if (existsSync9(
|
|
12954
|
+
if (existsSync9(join32(dir, "package.json")) && existsSync9(join32(dir, "souls"))) {
|
|
12751
12955
|
return dir;
|
|
12752
12956
|
}
|
|
12753
|
-
const parent =
|
|
12957
|
+
const parent = dirname17(dir);
|
|
12754
12958
|
if (parent === dir) break;
|
|
12755
12959
|
dir = parent;
|
|
12756
12960
|
}
|
|
@@ -12883,13 +13087,13 @@ function resolveAuditDossier(source) {
|
|
|
12883
13087
|
}
|
|
12884
13088
|
return { status: "ok", runDirectory };
|
|
12885
13089
|
}
|
|
12886
|
-
function
|
|
13090
|
+
function isRecord9(value) {
|
|
12887
13091
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12888
13092
|
}
|
|
12889
13093
|
function readDoctorAuditSubjects(context) {
|
|
12890
13094
|
const entries = context.sessionManager.getEntries?.() ?? [];
|
|
12891
13095
|
for (const entry of entries) {
|
|
12892
|
-
if (
|
|
13096
|
+
if (isRecord9(entry) && entry.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
|
|
12893
13097
|
return { status: "ok" };
|
|
12894
13098
|
}
|
|
12895
13099
|
}
|
|
@@ -14177,7 +14381,7 @@ var init_collector_ledger = __esm({
|
|
|
14177
14381
|
// src/package-resources/method-skill.ts
|
|
14178
14382
|
import { createHash as createHash7 } from "node:crypto";
|
|
14179
14383
|
import { readFile as readFile18, realpath as realpath6 } from "node:fs/promises";
|
|
14180
|
-
import { join as
|
|
14384
|
+
import { join as join33 } from "node:path";
|
|
14181
14385
|
function gitBlobOid(bytes) {
|
|
14182
14386
|
const body = typeof bytes === "string" ? Buffer.from(bytes, "utf8") : Buffer.from(bytes);
|
|
14183
14387
|
const header = Buffer.from(`blob ${body.byteLength}\0`, "utf8");
|
|
@@ -14194,16 +14398,16 @@ function packagedMethodSkillRelativeDirectory(name) {
|
|
|
14194
14398
|
return `${METHOD_SKILL_RELATIVE_ROOT}/${name}`;
|
|
14195
14399
|
}
|
|
14196
14400
|
function resolvePackagedMethodSkillRoot(packageRoot, name) {
|
|
14197
|
-
return
|
|
14401
|
+
return join33(packageRoot, packagedMethodSkillRelativeDirectory(name));
|
|
14198
14402
|
}
|
|
14199
14403
|
function resolvePackagedMethodSkillPath(packageRoot, name) {
|
|
14200
|
-
return
|
|
14404
|
+
return join33(resolvePackagedMethodSkillRoot(packageRoot, name), "SKILL.md");
|
|
14201
14405
|
}
|
|
14202
|
-
function
|
|
14406
|
+
function isRecord10(value) {
|
|
14203
14407
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14204
14408
|
}
|
|
14205
14409
|
function parseProvenance(raw, expectedName) {
|
|
14206
|
-
if (!
|
|
14410
|
+
if (!isRecord10(raw)) {
|
|
14207
14411
|
throw new Error(`Packaged method provenance must be an object for ${expectedName}`);
|
|
14208
14412
|
}
|
|
14209
14413
|
if (raw.name !== expectedName) {
|
|
@@ -14217,7 +14421,7 @@ function parseProvenance(raw, expectedName) {
|
|
|
14217
14421
|
if (typeof raw.packageAdaptation !== "string" || raw.packageAdaptation.trim() === "") {
|
|
14218
14422
|
throw new Error(`Packaged method provenance packageAdaptation must be nonblank`);
|
|
14219
14423
|
}
|
|
14220
|
-
if (!
|
|
14424
|
+
if (!isRecord10(raw.upstream)) {
|
|
14221
14425
|
throw new Error(`Packaged method provenance upstream must be an object`);
|
|
14222
14426
|
}
|
|
14223
14427
|
const upstream = raw.upstream;
|
|
@@ -14244,12 +14448,12 @@ function parseProvenance(raw, expectedName) {
|
|
|
14244
14448
|
`Packaged method provenance upstream must include nonblank tag or version`
|
|
14245
14449
|
);
|
|
14246
14450
|
}
|
|
14247
|
-
if (!
|
|
14451
|
+
if (!isRecord10(raw.files)) {
|
|
14248
14452
|
throw new Error(`Packaged method provenance files must be an object`);
|
|
14249
14453
|
}
|
|
14250
14454
|
const files = {};
|
|
14251
14455
|
for (const [rel, entry] of Object.entries(raw.files)) {
|
|
14252
|
-
if (!
|
|
14456
|
+
if (!isRecord10(entry)) {
|
|
14253
14457
|
throw new Error(`Packaged method provenance file entry must be an object: ${rel}`);
|
|
14254
14458
|
}
|
|
14255
14459
|
if (typeof entry.sha256 !== "string" || !SHA256_RE.test(entry.sha256)) {
|
|
@@ -14291,8 +14495,8 @@ function parseProvenance(raw, expectedName) {
|
|
|
14291
14495
|
}
|
|
14292
14496
|
async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
14293
14497
|
const rootDirectory = resolvePackagedMethodSkillRoot(packageRoot, name);
|
|
14294
|
-
const skillPathConfigured =
|
|
14295
|
-
const provenancePath =
|
|
14498
|
+
const skillPathConfigured = join33(rootDirectory, "SKILL.md");
|
|
14499
|
+
const provenancePath = join33(rootDirectory, "provenance.json");
|
|
14296
14500
|
let provenanceRaw;
|
|
14297
14501
|
try {
|
|
14298
14502
|
provenanceRaw = await readFile18(provenancePath, "utf8");
|
|
@@ -14309,7 +14513,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
|
14309
14513
|
}
|
|
14310
14514
|
const provenance = parseProvenance(provenanceJson, name);
|
|
14311
14515
|
for (const [rel, expected] of Object.entries(provenance.files)) {
|
|
14312
|
-
const absolute =
|
|
14516
|
+
const absolute = join33(rootDirectory, rel);
|
|
14313
14517
|
let bytes;
|
|
14314
14518
|
try {
|
|
14315
14519
|
bytes = await readFile18(absolute);
|
|
@@ -14592,11 +14796,11 @@ var init_navigator_invocation_identity = __esm({
|
|
|
14592
14796
|
});
|
|
14593
14797
|
|
|
14594
14798
|
// src/receipt-delivery-policy.ts
|
|
14595
|
-
function
|
|
14799
|
+
function isRecord11(value) {
|
|
14596
14800
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14597
14801
|
}
|
|
14598
14802
|
function parseNoReceiptLifecycleFacts(input) {
|
|
14599
|
-
if (!
|
|
14803
|
+
if (!isRecord11(input) || typeof input.terminalToolCalled !== "boolean" || input.deliveryTurns !== RECEIPT_DELIVERY_TURN_LIMIT || input.sessionCompletion !== "settled-without-accepted-receipt" || input.acceptedReceipt !== false || typeof input.runPointer !== "string" || input.runPointer.trim() === "" || typeof input.attemptPointer !== "string" || input.attemptPointer.trim() === "" || !Array.isArray(input.rejectedReceipts) || !input.rejectedReceipts.every((item) => isRecord11(item) && typeof item.reason === "string")) {
|
|
14600
14804
|
throw new TypeError("malformed no-receipt lifecycle facts");
|
|
14601
14805
|
}
|
|
14602
14806
|
return {
|
|
@@ -14814,16 +15018,16 @@ var init_terminal = __esm({
|
|
|
14814
15018
|
});
|
|
14815
15019
|
|
|
14816
15020
|
// src/public-cli/settlement.ts
|
|
14817
|
-
import { randomUUID as
|
|
15021
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
14818
15022
|
import { appendFile as appendFile2, readFile as readFile19, readdir as readdir7, writeFile as writeFile10 } from "node:fs/promises";
|
|
14819
|
-
import { dirname as
|
|
15023
|
+
import { dirname as dirname18, join as join34 } from "node:path";
|
|
14820
15024
|
function sealedLedgerHome(admitted) {
|
|
14821
15025
|
return homeFromRunDirectory(admitted.runDirectory);
|
|
14822
15026
|
}
|
|
14823
15027
|
function ledgerReadScope(admitted, scope) {
|
|
14824
15028
|
return {
|
|
14825
15029
|
home: sealedLedgerHome(admitted),
|
|
14826
|
-
sessionParent:
|
|
15030
|
+
sessionParent: join34(admitted.runDirectory, "session", "session.jsonl"),
|
|
14827
15031
|
...scope?.courtAttemptId === void 0 || scope.courtAttemptId.length === 0 ? {} : { attemptId: scope.courtAttemptId }
|
|
14828
15032
|
};
|
|
14829
15033
|
}
|
|
@@ -14886,7 +15090,7 @@ async function attachRecordedSubmissions(admitted, terminal, scope) {
|
|
|
14886
15090
|
await recordedSubmissionPayloads(admitted, void 0)
|
|
14887
15091
|
);
|
|
14888
15092
|
}
|
|
14889
|
-
async function settleHostEndedNoReceipt(admitted, authority) {
|
|
15093
|
+
async function settleHostEndedNoReceipt(admitted, authority, scope) {
|
|
14890
15094
|
const facts = noReceiptLifecycleFacts({
|
|
14891
15095
|
terminalToolCalled: false,
|
|
14892
15096
|
rejectedReceipts: [],
|
|
@@ -14908,7 +15112,8 @@ async function settleHostEndedNoReceipt(admitted, authority) {
|
|
|
14908
15112
|
artifacts: [],
|
|
14909
15113
|
runId: admitted.runId
|
|
14910
15114
|
},
|
|
14911
|
-
coordinates.sessionDirectory
|
|
15115
|
+
coordinates.sessionDirectory,
|
|
15116
|
+
detourGateContext(admitted, scope)
|
|
14912
15117
|
);
|
|
14913
15118
|
}
|
|
14914
15119
|
async function closedLedgerOutcome(admitted, role, scope) {
|
|
@@ -15246,12 +15451,12 @@ async function readSitianRetainedAuditorProviderStop(sessionFile) {
|
|
|
15246
15451
|
kind: "auditor",
|
|
15247
15452
|
sessionParent: sessionFile,
|
|
15248
15453
|
// Path is driven by sessionParent when under ledger home; cwd is a fallback only.
|
|
15249
|
-
cwd:
|
|
15454
|
+
cwd: dirname18(sessionFile)
|
|
15250
15455
|
});
|
|
15251
15456
|
const { records } = await readSitianRecords(recordFile);
|
|
15252
15457
|
for (let i = records.length - 1; i >= 0; i -= 1) {
|
|
15253
15458
|
const payload = records[i]?.payload;
|
|
15254
|
-
if (!
|
|
15459
|
+
if (!isRecord12(payload) || !isRecord12(payload.response)) continue;
|
|
15255
15460
|
if (typeof payload.type === "string") continue;
|
|
15256
15461
|
const stop = sessionProviderStopFromAssistant(payload.response);
|
|
15257
15462
|
if (stop !== void 0) return stop;
|
|
@@ -15272,7 +15477,7 @@ async function readSessionProviderStop(sessionFile) {
|
|
|
15272
15477
|
}
|
|
15273
15478
|
}
|
|
15274
15479
|
async function readBoundEvidenceChildKnownFailure(sessionFile) {
|
|
15275
|
-
const childDirectory =
|
|
15480
|
+
const childDirectory = join34(dirname18(sessionFile), "evidence-children");
|
|
15276
15481
|
let names;
|
|
15277
15482
|
try {
|
|
15278
15483
|
names = await readdir7(childDirectory);
|
|
@@ -15283,12 +15488,12 @@ async function readBoundEvidenceChildKnownFailure(sessionFile) {
|
|
|
15283
15488
|
for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
|
|
15284
15489
|
let entries;
|
|
15285
15490
|
try {
|
|
15286
|
-
entries = await readBoundSessionEntries(
|
|
15491
|
+
entries = await readBoundSessionEntries(join34(childDirectory, file));
|
|
15287
15492
|
} catch (error) {
|
|
15288
15493
|
throw sessionReadFailure(error, "failed to read discovered evidence-child session");
|
|
15289
15494
|
}
|
|
15290
15495
|
const header = entries.find((entry) => entry.type === "session");
|
|
15291
|
-
if (!
|
|
15496
|
+
if (!isRecord12(header) || header.parentSession !== sessionFile) continue;
|
|
15292
15497
|
const stop = extractSessionProviderStop(entries);
|
|
15293
15498
|
if (stop === void 0) continue;
|
|
15294
15499
|
const primary = knownFailureFromProviderStop(stop);
|
|
@@ -15321,12 +15526,12 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
15321
15526
|
return body.startsWith("\u672C\u6B21\u914D\u7F6E\u7684\u52B3\u52A1\u5F15\u64CE\u53CA\u5176\u624B\u518C\uFF1A") || body.startsWith("- engine:");
|
|
15322
15527
|
};
|
|
15323
15528
|
const isResumeEnvelope = (msg) => {
|
|
15324
|
-
if (!
|
|
15529
|
+
if (!isRecord12(msg) || msg.role !== "user") return false;
|
|
15325
15530
|
const text = typeof msg.text === "string" ? msg.text : typeof msg.content === "string" ? msg.content : void 0;
|
|
15326
15531
|
if (isResumeEnvelopeBytes(text)) return true;
|
|
15327
15532
|
const content = msg.content;
|
|
15328
15533
|
if (Array.isArray(content)) {
|
|
15329
|
-
return content.some((p) =>
|
|
15534
|
+
return content.some((p) => isRecord12(p) && (isResumeEnvelopeBytes(p.text) || isResumeEnvelopeBytes(p.content)));
|
|
15330
15535
|
}
|
|
15331
15536
|
return false;
|
|
15332
15537
|
};
|
|
@@ -15338,7 +15543,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
15338
15543
|
latestParentUserIndex = i;
|
|
15339
15544
|
break;
|
|
15340
15545
|
}
|
|
15341
|
-
const childDirectories = [
|
|
15546
|
+
const childDirectories = [join34(dirname18(sessionFile), "auditor-roles")];
|
|
15342
15547
|
const valid = [];
|
|
15343
15548
|
let sawAnyDirectory = false;
|
|
15344
15549
|
for (const childDirectory of childDirectories) {
|
|
@@ -15353,12 +15558,12 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
15353
15558
|
for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
|
|
15354
15559
|
let entries;
|
|
15355
15560
|
try {
|
|
15356
|
-
entries = await readBoundSessionEntries(
|
|
15561
|
+
entries = await readBoundSessionEntries(join34(childDirectory, file));
|
|
15357
15562
|
} catch (error) {
|
|
15358
15563
|
throw sessionReadFailure(error, "failed to read discovered auditor session");
|
|
15359
15564
|
}
|
|
15360
15565
|
const header = entries.find((entry) => entry.type === "session");
|
|
15361
|
-
if (!
|
|
15566
|
+
if (!isRecord12(header)) continue;
|
|
15362
15567
|
const bindingIndexes = [];
|
|
15363
15568
|
for (let i = 0; i < entries.length; i += 1) {
|
|
15364
15569
|
const entry = entries[i];
|
|
@@ -15372,7 +15577,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
15372
15577
|
end: idx + 1 < bindingIndexes.length ? bindingIndexes[idx + 1] : entries.length
|
|
15373
15578
|
})) : [{ entry: void 0, start: 0, end: entries.length }];
|
|
15374
15579
|
for (const { entry: bindingEntry, start, end } of bindingPasses) {
|
|
15375
|
-
const bindingParent = bindingEntry !== void 0 &&
|
|
15580
|
+
const bindingParent = bindingEntry !== void 0 && isRecord12(bindingEntry.data) && isRecord12(bindingEntry.data.parent) ? bindingEntry.data.parent : void 0;
|
|
15376
15581
|
const attemptEntryId = typeof bindingParent?.attemptEntryId === "string" ? bindingParent.attemptEntryId : void 0;
|
|
15377
15582
|
const attemptEntryIndex = attemptEntryId === void 0 ? -1 : parentEntries.findIndex((entry) => entry.id === attemptEntryId);
|
|
15378
15583
|
const boundSessionFile = typeof bindingParent?.sessionFile === "string" ? bindingParent.sessionFile : typeof header.parentSession === "string" ? header.parentSession : void 0;
|
|
@@ -15399,12 +15604,12 @@ function complianceFailureFromAuditorVolumes(volumes) {
|
|
|
15399
15604
|
if (stop === void 0) continue;
|
|
15400
15605
|
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
15401
15606
|
const entry = entries[i];
|
|
15402
|
-
if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !
|
|
15403
|
-
const parent =
|
|
15404
|
-
const failure2 =
|
|
15607
|
+
if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !isRecord12(entry.data)) continue;
|
|
15608
|
+
const parent = isRecord12(entry.data.parent) ? entry.data.parent : void 0;
|
|
15609
|
+
const failure2 = isRecord12(entry.data.failure) ? entry.data.failure : void 0;
|
|
15405
15610
|
if (parent?.sessionId !== parentId || parent.sessionFile !== sessionFile || parent.attemptEntryId !== attemptEntryId) continue;
|
|
15406
15611
|
if (failure2 === void 0) continue;
|
|
15407
|
-
const identity =
|
|
15612
|
+
const identity = isRecord12(failure2.identity) ? failure2.identity : void 0;
|
|
15408
15613
|
const typedCause = failure2.cause === "provider" || failure2.cause === "activation" || failure2.cause === "session" || failure2.cause === "output" || failure2.cause === "timeout" ? failure2.cause : void 0;
|
|
15409
15614
|
return {
|
|
15410
15615
|
...typedCause === void 0 ? {} : { cause: typedCause },
|
|
@@ -15413,7 +15618,7 @@ function complianceFailureFromAuditorVolumes(volumes) {
|
|
|
15413
15618
|
...typeof identity.code === "string" || typeof identity.code === "number" ? { code: identity.code } : {}
|
|
15414
15619
|
} },
|
|
15415
15620
|
...typeof failure2.diagnostic === "string" ? { diagnostic: failure2.diagnostic } : {},
|
|
15416
|
-
...
|
|
15621
|
+
...isRecord12(failure2.details) ? { details: failure2.details } : {}
|
|
15417
15622
|
};
|
|
15418
15623
|
}
|
|
15419
15624
|
}
|
|
@@ -15460,9 +15665,9 @@ function typedFailedTerminatingToolKnownFailure(entries) {
|
|
|
15460
15665
|
if (classification.kind !== "infrastructure") continue;
|
|
15461
15666
|
if (typeof message.toolCallId !== "string" || typeof message.toolName !== "string") continue;
|
|
15462
15667
|
if (boundRoleToolCallForResult(attemptEntries, i, message, message.toolName) === void 0) continue;
|
|
15463
|
-
const textPart = Array.isArray(message.content) ? message.content.find((part) =>
|
|
15464
|
-
const diagnostic =
|
|
15465
|
-
const details =
|
|
15668
|
+
const textPart = Array.isArray(message.content) ? message.content.find((part) => isRecord12(part) && part.type === "text" && typeof part.text === "string") : void 0;
|
|
15669
|
+
const diagnostic = isRecord12(textPart) ? textPart.text : void 0;
|
|
15670
|
+
const details = isRecord12(message.details) ? message.details : classification.fact;
|
|
15466
15671
|
return {
|
|
15467
15672
|
cause: "activation",
|
|
15468
15673
|
identity: { name: message.toolName, code: message.toolCallId },
|
|
@@ -15620,7 +15825,7 @@ function controlledFailureInputFromResolution(resolution) {
|
|
|
15620
15825
|
} : {}
|
|
15621
15826
|
};
|
|
15622
15827
|
}
|
|
15623
|
-
function
|
|
15828
|
+
function isRecord12(value) {
|
|
15624
15829
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
15625
15830
|
}
|
|
15626
15831
|
function toolResultText(message) {
|
|
@@ -15645,7 +15850,7 @@ function extractCollectorTargetBindRejection(entries) {
|
|
|
15645
15850
|
const diagnostic = toolResultText(message);
|
|
15646
15851
|
if (diagnostic.length === 0) return void 0;
|
|
15647
15852
|
const details = message.details;
|
|
15648
|
-
const code =
|
|
15853
|
+
const code = isRecord12(details) && typeof details.code === "string" && details.code.trim() !== "" ? details.code : void 0;
|
|
15649
15854
|
return code === void 0 ? { diagnostic } : { diagnostic, code };
|
|
15650
15855
|
}
|
|
15651
15856
|
return void 0;
|
|
@@ -15706,7 +15911,7 @@ function boundRoleToolCallForResult(entries, resultIndex, message, outputToolNam
|
|
|
15706
15911
|
const candidateMessage = entries[index]?.message;
|
|
15707
15912
|
if (candidateMessage?.role === "assistant" && Array.isArray(candidateMessage.content)) {
|
|
15708
15913
|
for (const part of candidateMessage.content) {
|
|
15709
|
-
if (!
|
|
15914
|
+
if (!isRecord12(part) || part.type !== "toolCall" || part.id !== callId) {
|
|
15710
15915
|
continue;
|
|
15711
15916
|
}
|
|
15712
15917
|
if (part.name !== outputToolName) return void 0;
|
|
@@ -15743,7 +15948,7 @@ async function appendRunAttemptHistory(source, outcome) {
|
|
|
15743
15948
|
type: "custom",
|
|
15744
15949
|
customType: ATTEMPT_HISTORY_ENTRY_TYPE,
|
|
15745
15950
|
data: attemptData,
|
|
15746
|
-
id:
|
|
15951
|
+
id: randomUUID5(),
|
|
15747
15952
|
parentId,
|
|
15748
15953
|
timestamp: timestamp2
|
|
15749
15954
|
})}
|
|
@@ -15778,7 +15983,7 @@ function parseNavigatorAttendanceDetails(details) {
|
|
|
15778
15983
|
const advisoryDiagnostic = typeof details.routePlaybookReadFailure === "string" ? { advisoryDiagnostic: details.routePlaybookReadFailure } : {};
|
|
15779
15984
|
if (disposition === "recommendation") {
|
|
15780
15985
|
const next = details.next;
|
|
15781
|
-
if (!
|
|
15986
|
+
if (!isRecord12(next) || typeof next.role !== "string") {
|
|
15782
15987
|
return {
|
|
15783
15988
|
disposition: "unavailable",
|
|
15784
15989
|
source: "unknown",
|
|
@@ -15786,7 +15991,7 @@ function parseNavigatorAttendanceDetails(details) {
|
|
|
15786
15991
|
};
|
|
15787
15992
|
}
|
|
15788
15993
|
const reason = typeof details.reason === "string" ? details.reason : "";
|
|
15789
|
-
const route = Array.isArray(details.route) ? details.route.filter(
|
|
15994
|
+
const route = Array.isArray(details.route) ? details.route.filter(isRecord12).map((target) => ({
|
|
15790
15995
|
role: String(target.role),
|
|
15791
15996
|
phase: navigatorPhaseValue(target.phase)
|
|
15792
15997
|
})) : void 0;
|
|
@@ -15849,18 +16054,50 @@ function projectTerminalGateFact(rounds) {
|
|
|
15849
16054
|
};
|
|
15850
16055
|
}
|
|
15851
16056
|
async function extractGateFactFromSessionDirectory(sessionDirectory, options = {}) {
|
|
15852
|
-
const directories = [
|
|
15853
|
-
const parentSessionFile = options.parentSessionFile ??
|
|
16057
|
+
const directories = [join34(sessionDirectory, "auditor-roles")];
|
|
16058
|
+
const parentSessionFile = options.parentSessionFile ?? join34(sessionDirectory, "session.jsonl");
|
|
15854
16059
|
const rounds = await readAnalystGateCyclesFromAuditorRoles(directories, {
|
|
15855
16060
|
parentSessionFile
|
|
15856
16061
|
});
|
|
15857
16062
|
return projectTerminalGateFact(rounds);
|
|
15858
16063
|
}
|
|
16064
|
+
async function attachEngineDetourToolUsage(base, sessionDirectory, gateContext = {}) {
|
|
16065
|
+
const runDirectory = typeof gateContext.runDirectory === "string" && gateContext.runDirectory.length > 0 ? gateContext.runDirectory : runDirectoryFromSessionDirectory(sessionDirectory);
|
|
16066
|
+
const engineMounted = await readInvocationEngineMounted(runDirectory);
|
|
16067
|
+
if (!engineMounted) return base;
|
|
16068
|
+
const invocationScopeId = typeof gateContext.invocationScopeId === "string" && gateContext.invocationScopeId.length > 0 ? gateContext.invocationScopeId : void 0;
|
|
16069
|
+
const sessionFile = sessionFileFromSessionDirectory(sessionDirectory);
|
|
16070
|
+
const usage = await readEngineDetourToolUsage({
|
|
16071
|
+
sessionParent: sessionFile,
|
|
16072
|
+
engineMounted: true,
|
|
16073
|
+
...invocationScopeId === void 0 ? {} : { invocationScopeId },
|
|
16074
|
+
cwd: runDirectory
|
|
16075
|
+
});
|
|
16076
|
+
const projected = usage === void 0 ? void 0 : projectEngineDetourToolUsageForPublicTerminal(usage, {
|
|
16077
|
+
// Resumable Terminal: run ID only in resume.command — relative openable path.
|
|
16078
|
+
discloseRecordFile: base.resume === void 0
|
|
16079
|
+
});
|
|
16080
|
+
return {
|
|
16081
|
+
...base,
|
|
16082
|
+
roleOutcome: withEngineDetourToolUsageFact(base.roleOutcome, projected)
|
|
16083
|
+
};
|
|
16084
|
+
}
|
|
16085
|
+
function detourGateContext(admitted, scope) {
|
|
16086
|
+
return {
|
|
16087
|
+
runDirectory: admitted.runDirectory,
|
|
16088
|
+
...scope?.courtAttemptId === void 0 || scope.courtAttemptId.length === 0 ? {} : { courtAttemptId: scope.courtAttemptId },
|
|
16089
|
+
...scope?.invocationScopeId === void 0 || scope.invocationScopeId.length === 0 ? {} : { invocationScopeId: scope.invocationScopeId }
|
|
16090
|
+
};
|
|
16091
|
+
}
|
|
15859
16092
|
async function withOptionalGateProjection(base, sessionDirectory, gateContext = {}) {
|
|
15860
16093
|
const secondaryEvidence = base.roleOutcome.kind === "failure" ? base.roleOutcome.decisiveFacts.secondaryEvidence : void 0;
|
|
15861
|
-
|
|
15862
|
-
|
|
15863
|
-
|
|
16094
|
+
const skipGate = isRecord12(secondaryEvidence) && secondaryEvidence.kind === "role_infrastructure_failure" && (secondaryEvidence.stage === "gatekeeper" || secondaryEvidence.stage === "inspector" || secondaryEvidence.stage === "notary");
|
|
16095
|
+
let next = base;
|
|
16096
|
+
if (!skipGate) {
|
|
16097
|
+
const gate = await extractGateFactFromSessionDirectory(sessionDirectory, gateContext);
|
|
16098
|
+
if (gate !== void 0) next = { ...base, gate };
|
|
16099
|
+
}
|
|
16100
|
+
return attachEngineDetourToolUsage(next, sessionDirectory, gateContext);
|
|
15864
16101
|
}
|
|
15865
16102
|
function extractNavigatorFact(entries) {
|
|
15866
16103
|
const terminal = findLatestDurablePackagedRoleTerminal(entries);
|
|
@@ -15898,7 +16135,7 @@ function extractNavigatorFact(entries) {
|
|
|
15898
16135
|
const entry = entries[i];
|
|
15899
16136
|
if (entry?.type === "custom_message" && entry.customType === "ak-navigator-attendance") {
|
|
15900
16137
|
const details = entry.message?.details ?? entry.details;
|
|
15901
|
-
if (!
|
|
16138
|
+
if (!isRecord12(details)) {
|
|
15902
16139
|
return {
|
|
15903
16140
|
disposition: "unavailable",
|
|
15904
16141
|
source: "unknown",
|
|
@@ -15948,8 +16185,8 @@ async function extractNavigatorFactFromAdmittedSession(sessionFile) {
|
|
|
15948
16185
|
async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
|
|
15949
16186
|
await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
|
|
15950
16187
|
const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
|
|
15951
|
-
const reportPath =
|
|
15952
|
-
const evidencePath =
|
|
16188
|
+
const reportPath = join34(artifactsDir, "report.json");
|
|
16189
|
+
const evidencePath = join34(artifactsDir, "evidence.json");
|
|
15953
16190
|
await writeFile10(
|
|
15954
16191
|
reportPath,
|
|
15955
16192
|
`${JSON.stringify(
|
|
@@ -16019,7 +16256,8 @@ async function settleLawfulJudgeTerminalResult(admitted, authority, scope) {
|
|
|
16019
16256
|
artifacts,
|
|
16020
16257
|
runId: admitted.runId
|
|
16021
16258
|
},
|
|
16022
|
-
coordinates.sessionDirectory
|
|
16259
|
+
coordinates.sessionDirectory,
|
|
16260
|
+
detourGateContext(admitted, scope)
|
|
16023
16261
|
);
|
|
16024
16262
|
}
|
|
16025
16263
|
async function trySettleJudgeTerminalResult(admitted, authority, scope) {
|
|
@@ -16031,7 +16269,7 @@ function extractDoctorCandidateCostFact(entries) {
|
|
|
16031
16269
|
const entry = entries[i];
|
|
16032
16270
|
if (entry?.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
|
|
16033
16271
|
const data = entry.data;
|
|
16034
|
-
return
|
|
16272
|
+
return isRecord12(data) ? data.cost : void 0;
|
|
16035
16273
|
}
|
|
16036
16274
|
}
|
|
16037
16275
|
return void 0;
|
|
@@ -16042,7 +16280,7 @@ function extractDoctorCandidateAuditNoReceiptFact(entries) {
|
|
|
16042
16280
|
const entry = entries[i];
|
|
16043
16281
|
if (entry?.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
|
|
16044
16282
|
const data = entry.data;
|
|
16045
|
-
return
|
|
16283
|
+
return isRecord12(data) ? data.auditNoReceipt : void 0;
|
|
16046
16284
|
}
|
|
16047
16285
|
}
|
|
16048
16286
|
return void 0;
|
|
@@ -16050,8 +16288,8 @@ function extractDoctorCandidateAuditNoReceiptFact(entries) {
|
|
|
16050
16288
|
async function publishDoctorArtifacts(admitted, roleOutcome, coordinates, options = {}) {
|
|
16051
16289
|
await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
|
|
16052
16290
|
const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
|
|
16053
|
-
const reportPath =
|
|
16054
|
-
const evidencePath =
|
|
16291
|
+
const reportPath = join34(artifactsDir, "report.json");
|
|
16292
|
+
const evidencePath = join34(artifactsDir, "evidence.json");
|
|
16055
16293
|
await writeFile10(
|
|
16056
16294
|
reportPath,
|
|
16057
16295
|
`${JSON.stringify(
|
|
@@ -16113,7 +16351,8 @@ async function settleLawfulDoctorTerminalResult(admitted, authority, scope) {
|
|
|
16113
16351
|
artifacts: artifacts2,
|
|
16114
16352
|
runId: admitted.runId
|
|
16115
16353
|
},
|
|
16116
|
-
sessionDirectory
|
|
16354
|
+
sessionDirectory,
|
|
16355
|
+
detourGateContext(admitted, scope)
|
|
16117
16356
|
);
|
|
16118
16357
|
}
|
|
16119
16358
|
const roleOutcome = sealed;
|
|
@@ -16136,7 +16375,8 @@ async function settleLawfulDoctorTerminalResult(admitted, authority, scope) {
|
|
|
16136
16375
|
artifacts,
|
|
16137
16376
|
runId: admitted.runId
|
|
16138
16377
|
},
|
|
16139
|
-
sessionDirectory
|
|
16378
|
+
sessionDirectory,
|
|
16379
|
+
detourGateContext(admitted, scope)
|
|
16140
16380
|
);
|
|
16141
16381
|
}
|
|
16142
16382
|
async function trySettleDoctorTerminalResult(admitted, authority, scope) {
|
|
@@ -16167,12 +16407,17 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
|
|
|
16167
16407
|
spec.toolName
|
|
16168
16408
|
);
|
|
16169
16409
|
if (residual !== void 0) {
|
|
16170
|
-
const details =
|
|
16171
|
-
const failed = await settleFailureTerminalResult(
|
|
16172
|
-
|
|
16173
|
-
|
|
16174
|
-
|
|
16175
|
-
|
|
16410
|
+
const details = isRecord12(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
|
|
16411
|
+
const failed = await settleFailureTerminalResult(
|
|
16412
|
+
admitted,
|
|
16413
|
+
{
|
|
16414
|
+
cause: "output",
|
|
16415
|
+
diagnostic: residual.diagnostic,
|
|
16416
|
+
details
|
|
16417
|
+
},
|
|
16418
|
+
authority,
|
|
16419
|
+
scope ?? {}
|
|
16420
|
+
);
|
|
16176
16421
|
return withSubmissions(failed, submissions);
|
|
16177
16422
|
}
|
|
16178
16423
|
}
|
|
@@ -16187,7 +16432,8 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
|
|
|
16187
16432
|
artifacts: [],
|
|
16188
16433
|
runId: admitted.runId
|
|
16189
16434
|
},
|
|
16190
|
-
sessionDirectory
|
|
16435
|
+
sessionDirectory,
|
|
16436
|
+
detourGateContext(admitted, scope)
|
|
16191
16437
|
),
|
|
16192
16438
|
submissions
|
|
16193
16439
|
);
|
|
@@ -16202,7 +16448,8 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
|
|
|
16202
16448
|
artifacts: [],
|
|
16203
16449
|
runId: admitted.runId
|
|
16204
16450
|
},
|
|
16205
|
-
sessionDirectory
|
|
16451
|
+
sessionDirectory,
|
|
16452
|
+
detourGateContext(admitted, scope)
|
|
16206
16453
|
),
|
|
16207
16454
|
submissions
|
|
16208
16455
|
);
|
|
@@ -16282,7 +16529,7 @@ function publicationAttemptFromError(path, error) {
|
|
|
16282
16529
|
}
|
|
16283
16530
|
function uniqueFailureFallbackDirs(runDirectory, baseDir) {
|
|
16284
16531
|
const dirs = [];
|
|
16285
|
-
for (const dir of [baseDir, runDirectory,
|
|
16532
|
+
for (const dir of [baseDir, runDirectory, dirname18(runDirectory)]) {
|
|
16286
16533
|
if (!dirs.includes(dir)) dirs.push(dir);
|
|
16287
16534
|
}
|
|
16288
16535
|
return dirs;
|
|
@@ -16304,7 +16551,7 @@ async function writeFailureJsonRetainingCause(preferredCandidates, uniqueFallbac
|
|
|
16304
16551
|
const candidates = [
|
|
16305
16552
|
...preferredCandidates,
|
|
16306
16553
|
// One unique name per fallback dir — collisions on fixed names cannot exhaust this.
|
|
16307
|
-
...uniqueFallbackDirs.map((dir) =>
|
|
16554
|
+
...uniqueFallbackDirs.map((dir) => join34(dir, `${stem}.${randomUUID5()}.json`))
|
|
16308
16555
|
];
|
|
16309
16556
|
for (let i = 0; i < candidates.length; i += 1) {
|
|
16310
16557
|
const path = candidates[i];
|
|
@@ -16355,20 +16602,20 @@ async function publishFailureArtifacts(admitted, failure2, authority) {
|
|
|
16355
16602
|
baseDir
|
|
16356
16603
|
);
|
|
16357
16604
|
const errorCandidates = underArtifacts ? [
|
|
16358
|
-
|
|
16359
|
-
|
|
16360
|
-
|
|
16605
|
+
join34(baseDir, "error.json"),
|
|
16606
|
+
join34(baseDir, "error.settlement.json"),
|
|
16607
|
+
join34(admitted.runDirectory, "error.settlement.json")
|
|
16361
16608
|
] : [
|
|
16362
|
-
|
|
16363
|
-
|
|
16609
|
+
join34(baseDir, "error.settlement.json"),
|
|
16610
|
+
join34(baseDir, "error.json")
|
|
16364
16611
|
];
|
|
16365
16612
|
const evidenceCandidates = underArtifacts ? [
|
|
16366
|
-
|
|
16367
|
-
|
|
16368
|
-
|
|
16613
|
+
join34(baseDir, "evidence.json"),
|
|
16614
|
+
join34(baseDir, "evidence.settlement.json"),
|
|
16615
|
+
join34(admitted.runDirectory, "evidence.settlement.json")
|
|
16369
16616
|
] : [
|
|
16370
|
-
|
|
16371
|
-
|
|
16617
|
+
join34(baseDir, "evidence.settlement.json"),
|
|
16618
|
+
join34(baseDir, "evidence.json")
|
|
16372
16619
|
];
|
|
16373
16620
|
const errorPayloadBase = {
|
|
16374
16621
|
kind: "error",
|
|
@@ -16450,7 +16697,8 @@ async function settleFailureTerminalResult(admitted, failure2, authority, option
|
|
|
16450
16697
|
artifacts: [],
|
|
16451
16698
|
runId: admitted.runId
|
|
16452
16699
|
},
|
|
16453
|
-
sessionDirectory
|
|
16700
|
+
sessionDirectory,
|
|
16701
|
+
detourGateContext(admitted, options)
|
|
16454
16702
|
);
|
|
16455
16703
|
}
|
|
16456
16704
|
} catch {
|
|
@@ -16488,7 +16736,8 @@ async function settleFailureTerminalResult(admitted, failure2, authority, option
|
|
|
16488
16736
|
artifacts: [],
|
|
16489
16737
|
resume: options.resume
|
|
16490
16738
|
},
|
|
16491
|
-
sessionDirectory
|
|
16739
|
+
sessionDirectory,
|
|
16740
|
+
detourGateContext(admitted, options)
|
|
16492
16741
|
);
|
|
16493
16742
|
}
|
|
16494
16743
|
const roleOutcome = {
|
|
@@ -16505,7 +16754,8 @@ async function settleFailureTerminalResult(admitted, failure2, authority, option
|
|
|
16505
16754
|
artifacts,
|
|
16506
16755
|
runId: admitted.runId
|
|
16507
16756
|
},
|
|
16508
|
-
sessionDirectory
|
|
16757
|
+
sessionDirectory,
|
|
16758
|
+
detourGateContext(admitted, options)
|
|
16509
16759
|
);
|
|
16510
16760
|
}
|
|
16511
16761
|
function presentFailureTerminal(terminal, io) {
|
|
@@ -16579,6 +16829,7 @@ var init_settlement = __esm({
|
|
|
16579
16829
|
init_compliance_transport();
|
|
16580
16830
|
init_collector_ledger();
|
|
16581
16831
|
init_engine_detour();
|
|
16832
|
+
init_engine_detour_usage();
|
|
16582
16833
|
init_judge_output();
|
|
16583
16834
|
init_collector_output();
|
|
16584
16835
|
init_worker_output();
|
|
@@ -16612,9 +16863,9 @@ var init_settlement = __esm({
|
|
|
16612
16863
|
|
|
16613
16864
|
// src/public-cli/auto-resume.ts
|
|
16614
16865
|
import { constants as fsConstants2 } from "node:fs";
|
|
16615
|
-
import { randomUUID as
|
|
16866
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
16616
16867
|
import { lstat as lstat6, mkdir as mkdir4, open as open2 } from "node:fs/promises";
|
|
16617
|
-
import { join as
|
|
16868
|
+
import { join as join35 } from "node:path";
|
|
16618
16869
|
async function persistReturnedRunState(admitted, authority, options) {
|
|
16619
16870
|
if (options?.lawful === true) {
|
|
16620
16871
|
await markRunTerminal(admitted.runDirectory);
|
|
@@ -16729,7 +16980,7 @@ function jsonSafeReplacer() {
|
|
|
16729
16980
|
};
|
|
16730
16981
|
}
|
|
16731
16982
|
async function writeHardenedArtifactFile(artifactsDir, namePrefix, payload) {
|
|
16732
|
-
const filePath =
|
|
16983
|
+
const filePath = join35(artifactsDir, `${namePrefix}-${randomUUID6()}.json`);
|
|
16733
16984
|
const body = `${JSON.stringify(payload, jsonSafeReplacer(), 2)}
|
|
16734
16985
|
`;
|
|
16735
16986
|
const noFollowFlag = typeof fsConstants2.O_NOFOLLOW === "number" ? fsConstants2.O_NOFOLLOW : 0;
|
|
@@ -17000,9 +17251,9 @@ var init_auto_resume = __esm({
|
|
|
17000
17251
|
});
|
|
17001
17252
|
|
|
17002
17253
|
// src/public-cli/post-admission.ts
|
|
17003
|
-
import { randomUUID as
|
|
17004
|
-
import {
|
|
17005
|
-
import { isAbsolute as isAbsolute8, join as
|
|
17254
|
+
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
17255
|
+
import { writeFile as writeFile11 } from "node:fs/promises";
|
|
17256
|
+
import { isAbsolute as isAbsolute8, join as join36, resolve as resolve13 } from "node:path";
|
|
17006
17257
|
function describeCaughtError(error) {
|
|
17007
17258
|
if (error instanceof Error) {
|
|
17008
17259
|
const code = error.code;
|
|
@@ -17047,7 +17298,7 @@ async function recordBestEffortPostDispatchDiagnostic(admitted, env, diagnostic,
|
|
|
17047
17298
|
try {
|
|
17048
17299
|
const artifactsDir = await ensureRealArtifactsDirectory(admitted.runDirectory);
|
|
17049
17300
|
await writeFile11(
|
|
17050
|
-
|
|
17301
|
+
join36(artifactsDir, `post-admission-diagnostic-${randomUUID7()}.json`),
|
|
17051
17302
|
`${JSON.stringify({ version: 1, ...payload }, null, 2)}
|
|
17052
17303
|
`,
|
|
17053
17304
|
{ encoding: "utf8", flag: "wx" }
|
|
@@ -17061,15 +17312,6 @@ async function recordBestEffortPostDispatchDiagnostic(admitted, env, diagnostic,
|
|
|
17061
17312
|
}
|
|
17062
17313
|
}
|
|
17063
17314
|
}
|
|
17064
|
-
async function readInvocationHost(runDirectory) {
|
|
17065
|
-
try {
|
|
17066
|
-
const raw = JSON.parse(await readFile20(join35(runDirectory, "invocation.json"), "utf8"));
|
|
17067
|
-
return typeof raw.host === "string" && raw.host.trim() !== "" ? raw.host : void 0;
|
|
17068
|
-
} catch (error) {
|
|
17069
|
-
if (error.code === "ENOENT") return void 0;
|
|
17070
|
-
throw error;
|
|
17071
|
-
}
|
|
17072
|
-
}
|
|
17073
17315
|
async function presentControlledFailure(admitted, failureInput, adapters, authority, io, persistRunState = true) {
|
|
17074
17316
|
const hasThrown = Object.hasOwn(failureInput, "thrown");
|
|
17075
17317
|
const resumeObservation = await resolveControlledFailureResumeObservation({
|
|
@@ -17109,7 +17351,10 @@ async function presentControlledFailure(admitted, failureInput, adapters, author
|
|
|
17109
17351
|
admitted,
|
|
17110
17352
|
failure2,
|
|
17111
17353
|
authority,
|
|
17112
|
-
|
|
17354
|
+
{
|
|
17355
|
+
...resumable ? { resume: { command: renderResumeCommand(admitted.runId) } } : {},
|
|
17356
|
+
...failureInput.invocationScopeId === void 0 || failureInput.invocationScopeId.length === 0 ? {} : { invocationScopeId: failureInput.invocationScopeId }
|
|
17357
|
+
}
|
|
17113
17358
|
)
|
|
17114
17359
|
);
|
|
17115
17360
|
presentFailureTerminal(terminal, io);
|
|
@@ -17178,12 +17423,12 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
17178
17423
|
return {
|
|
17179
17424
|
...await presentControlledFailure(
|
|
17180
17425
|
admitted,
|
|
17181
|
-
{
|
|
17426
|
+
withEngineDetourInvocationScope({
|
|
17182
17427
|
timedOut: false,
|
|
17183
17428
|
code: null,
|
|
17184
17429
|
stderr: "",
|
|
17185
17430
|
thrown: error
|
|
17186
|
-
},
|
|
17431
|
+
}, request.invocationScopeId),
|
|
17187
17432
|
adapters,
|
|
17188
17433
|
env.principalAuthority,
|
|
17189
17434
|
io,
|
|
@@ -17204,7 +17449,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
17204
17449
|
return {
|
|
17205
17450
|
...await presentControlledFailure(
|
|
17206
17451
|
admitted,
|
|
17207
|
-
missingCredential,
|
|
17452
|
+
withEngineDetourInvocationScope(missingCredential, request.invocationScopeId),
|
|
17208
17453
|
adapters,
|
|
17209
17454
|
env.principalAuthority,
|
|
17210
17455
|
io,
|
|
@@ -17218,7 +17463,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
17218
17463
|
const principalCoordinates = admitted.principal === void 0 ? void 0 : env.principalAuthority.decode(admitted.principal);
|
|
17219
17464
|
let hostTransition;
|
|
17220
17465
|
try {
|
|
17221
|
-
previousHost =
|
|
17466
|
+
previousHost = readInvocationSelectedHost(admitted.runDirectory);
|
|
17222
17467
|
hostTransition = previousHost !== void 0 && liveHost !== void 0 && principalCoordinates !== void 0 ? await projectHostTransitionPriorNative({
|
|
17223
17468
|
previousHost,
|
|
17224
17469
|
liveHost,
|
|
@@ -17228,12 +17473,12 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
17228
17473
|
return {
|
|
17229
17474
|
...await presentControlledFailure(
|
|
17230
17475
|
admitted,
|
|
17231
|
-
{
|
|
17476
|
+
withEngineDetourInvocationScope({
|
|
17232
17477
|
timedOut: false,
|
|
17233
17478
|
code: null,
|
|
17234
17479
|
stderr: "",
|
|
17235
17480
|
thrown: error
|
|
17236
|
-
},
|
|
17481
|
+
}, request.invocationScopeId),
|
|
17237
17482
|
adapters,
|
|
17238
17483
|
env.principalAuthority,
|
|
17239
17484
|
io,
|
|
@@ -17250,12 +17495,12 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
17250
17495
|
} catch (error) {
|
|
17251
17496
|
const settled2 = await presentControlledFailure(
|
|
17252
17497
|
admitted,
|
|
17253
|
-
{
|
|
17498
|
+
withEngineDetourInvocationScope({
|
|
17254
17499
|
timedOut: false,
|
|
17255
17500
|
code: null,
|
|
17256
17501
|
stderr: "",
|
|
17257
17502
|
thrown: error
|
|
17258
|
-
},
|
|
17503
|
+
}, request.invocationScopeId),
|
|
17259
17504
|
adapters,
|
|
17260
17505
|
env.principalAuthority,
|
|
17261
17506
|
io,
|
|
@@ -17274,6 +17519,9 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
17274
17519
|
if (hostTransition !== void 0) {
|
|
17275
17520
|
turnRequest = { ...turnRequest, hostTransition };
|
|
17276
17521
|
}
|
|
17522
|
+
if (typeof liveHost === "string" && liveHost.trim() !== "") {
|
|
17523
|
+
turnRequest = { ...turnRequest, host: liveHost.trim() };
|
|
17524
|
+
}
|
|
17277
17525
|
if (isStationChildOfficerDialogue(admitted.role, env)) {
|
|
17278
17526
|
await deliverCaseDossierAsAttachment({
|
|
17279
17527
|
ticketNumber: admitted.ticketNumber,
|
|
@@ -17310,12 +17558,12 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
17310
17558
|
} catch (error) {
|
|
17311
17559
|
const settled2 = await settleAfterTurnStarted(
|
|
17312
17560
|
admitted,
|
|
17313
|
-
{
|
|
17561
|
+
withEngineDetourInvocationScope({
|
|
17314
17562
|
timedOut: false,
|
|
17315
17563
|
code: null,
|
|
17316
17564
|
stderr: "",
|
|
17317
17565
|
thrown: error
|
|
17318
|
-
},
|
|
17566
|
+
}, request.invocationScopeId),
|
|
17319
17567
|
adapters,
|
|
17320
17568
|
env.principalAuthority,
|
|
17321
17569
|
io,
|
|
@@ -17326,7 +17574,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
17326
17574
|
let stderrLogWriteFailure;
|
|
17327
17575
|
try {
|
|
17328
17576
|
await writeFile11(
|
|
17329
|
-
|
|
17577
|
+
join36(admitted.runDirectory, "stderr.log"),
|
|
17330
17578
|
result.stderr,
|
|
17331
17579
|
"utf8"
|
|
17332
17580
|
);
|
|
@@ -17339,7 +17587,10 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
17339
17587
|
io
|
|
17340
17588
|
);
|
|
17341
17589
|
}
|
|
17342
|
-
const courtScope = request.courtAttemptId === void 0 || request.courtAttemptId.length === 0 ? void 0 : {
|
|
17590
|
+
const courtScope = (request.courtAttemptId === void 0 || request.courtAttemptId.length === 0) && (request.invocationScopeId === void 0 || request.invocationScopeId.length === 0) ? void 0 : {
|
|
17591
|
+
...request.courtAttemptId === void 0 || request.courtAttemptId.length === 0 ? {} : { courtAttemptId: request.courtAttemptId },
|
|
17592
|
+
...request.invocationScopeId === void 0 || request.invocationScopeId.length === 0 ? {} : { invocationScopeId: request.invocationScopeId }
|
|
17593
|
+
};
|
|
17343
17594
|
let settled;
|
|
17344
17595
|
let settledOutcome;
|
|
17345
17596
|
let hostSignalFailed = false;
|
|
@@ -17389,12 +17640,12 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
17389
17640
|
} catch (error) {
|
|
17390
17641
|
const settledFailure = await settleAfterTurnStarted(
|
|
17391
17642
|
admitted,
|
|
17392
|
-
{
|
|
17643
|
+
withEngineDetourInvocationScope({
|
|
17393
17644
|
timedOut: false,
|
|
17394
17645
|
code: result.code,
|
|
17395
17646
|
stderr: result.stderr,
|
|
17396
17647
|
thrown: error
|
|
17397
|
-
},
|
|
17648
|
+
}, request.invocationScopeId),
|
|
17398
17649
|
adapters,
|
|
17399
17650
|
env.principalAuthority,
|
|
17400
17651
|
io,
|
|
@@ -17409,13 +17660,13 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
17409
17660
|
} catch (error) {
|
|
17410
17661
|
const failed = await settleAfterTurnStarted(
|
|
17411
17662
|
admitted,
|
|
17412
|
-
{
|
|
17663
|
+
withEngineDetourInvocationScope({
|
|
17413
17664
|
timedOut: false,
|
|
17414
17665
|
code: null,
|
|
17415
17666
|
stderr: "",
|
|
17416
17667
|
thrown: error,
|
|
17417
17668
|
skipRunStateWrite: true
|
|
17418
|
-
},
|
|
17669
|
+
}, request.invocationScopeId),
|
|
17419
17670
|
adapters,
|
|
17420
17671
|
env.principalAuthority,
|
|
17421
17672
|
io,
|
|
@@ -17431,7 +17682,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
17431
17682
|
const stderrLogWriteDetails = stderrLogWriteFailure === void 0 ? void 0 : { stderrLogWriteFailure: describeCaughtError(stderrLogWriteFailure) };
|
|
17432
17683
|
const failed = await settleAfterTurnStarted(
|
|
17433
17684
|
admitted,
|
|
17434
|
-
{
|
|
17685
|
+
withEngineDetourInvocationScope({
|
|
17435
17686
|
timedOut: result.timedOut,
|
|
17436
17687
|
code: result.code,
|
|
17437
17688
|
stderr: result.stderr,
|
|
@@ -17445,7 +17696,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
17445
17696
|
details: { ...resolutionInput.knownFailure.details ?? {}, ...stderrLogWriteDetails }
|
|
17446
17697
|
}
|
|
17447
17698
|
} : { knownDetails: stderrLogWriteDetails }
|
|
17448
|
-
},
|
|
17699
|
+
}, request.invocationScopeId),
|
|
17449
17700
|
adapters,
|
|
17450
17701
|
env.principalAuthority,
|
|
17451
17702
|
io,
|
|
@@ -17456,12 +17707,12 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
17456
17707
|
if (stderrLogWriteFailure !== void 0) {
|
|
17457
17708
|
const failed = await settleAfterTurnStarted(
|
|
17458
17709
|
admitted,
|
|
17459
|
-
{
|
|
17710
|
+
withEngineDetourInvocationScope({
|
|
17460
17711
|
timedOut: false,
|
|
17461
17712
|
code: result.code,
|
|
17462
17713
|
stderr: result.stderr,
|
|
17463
17714
|
thrown: stderrLogWriteFailure
|
|
17464
|
-
},
|
|
17715
|
+
}, request.invocationScopeId),
|
|
17465
17716
|
adapters,
|
|
17466
17717
|
env.principalAuthority,
|
|
17467
17718
|
io,
|
|
@@ -17471,7 +17722,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
17471
17722
|
}
|
|
17472
17723
|
const noReceipt = await attachRecordedSubmissions(
|
|
17473
17724
|
admitted,
|
|
17474
|
-
await settleHostEndedNoReceipt(admitted, env.principalAuthority),
|
|
17725
|
+
await settleHostEndedNoReceipt(admitted, env.principalAuthority, courtScope),
|
|
17475
17726
|
courtScope
|
|
17476
17727
|
);
|
|
17477
17728
|
if (persistRunState) {
|
|
@@ -17480,13 +17731,13 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
17480
17731
|
} catch (error) {
|
|
17481
17732
|
const failed = await settleAfterTurnStarted(
|
|
17482
17733
|
admitted,
|
|
17483
|
-
{
|
|
17734
|
+
withEngineDetourInvocationScope({
|
|
17484
17735
|
timedOut: false,
|
|
17485
17736
|
code: null,
|
|
17486
17737
|
stderr: "",
|
|
17487
17738
|
thrown: error,
|
|
17488
17739
|
skipRunStateWrite: true
|
|
17489
|
-
},
|
|
17740
|
+
}, request.invocationScopeId),
|
|
17490
17741
|
adapters,
|
|
17491
17742
|
env.principalAuthority,
|
|
17492
17743
|
io,
|
|
@@ -17555,7 +17806,7 @@ function resumeTurnRequestProjectionOptions(admitted, request, env, summonsPrepa
|
|
|
17555
17806
|
kind: "resume",
|
|
17556
17807
|
prompt
|
|
17557
17808
|
},
|
|
17558
|
-
...request.message === void 0 ? {} : { courtAttemptId:
|
|
17809
|
+
...request.message === void 0 ? {} : { courtAttemptId: randomUUID7() },
|
|
17559
17810
|
...env.stationChild === void 0 ? {} : { stationChild: env.stationChild }
|
|
17560
17811
|
};
|
|
17561
17812
|
}
|
|
@@ -17573,7 +17824,7 @@ async function dispatchAfterWriterLease(input) {
|
|
|
17573
17824
|
}
|
|
17574
17825
|
function isAlreadyFrozenSummonsAttachment(runDirectory, attachmentPath) {
|
|
17575
17826
|
const absolute = isAbsolute8(attachmentPath) ? attachmentPath : resolve13(attachmentPath);
|
|
17576
|
-
return pathContainedIn(
|
|
17827
|
+
return pathContainedIn(join36(runDirectory, "attachments"), absolute);
|
|
17577
17828
|
}
|
|
17578
17829
|
async function prepareSummonsResumeMaterials(runDirectory, summons) {
|
|
17579
17830
|
if (summons === void 0) return void 0;
|
|
@@ -17652,7 +17903,7 @@ async function runPostAdmissionSeatResume(input) {
|
|
|
17652
17903
|
}
|
|
17653
17904
|
let turnRequest = await input.buildTurnRequest(admittedForBuild, request);
|
|
17654
17905
|
if (openCourtAttemptId !== void 0 || request.summons !== void 0 || request.message !== void 0) {
|
|
17655
|
-
const courtAttemptId = openCourtAttemptId ?? (turnRequest.courtAttemptId !== void 0 && turnRequest.courtAttemptId.length > 0 ? turnRequest.courtAttemptId :
|
|
17906
|
+
const courtAttemptId = openCourtAttemptId ?? (turnRequest.courtAttemptId !== void 0 && turnRequest.courtAttemptId.length > 0 ? turnRequest.courtAttemptId : randomUUID7());
|
|
17656
17907
|
turnRequest = { ...turnRequest, courtAttemptId };
|
|
17657
17908
|
if (openCourtAttemptId === void 0) {
|
|
17658
17909
|
const court = {
|
|
@@ -17668,6 +17919,9 @@ async function runPostAdmissionSeatResume(input) {
|
|
|
17668
17919
|
if (input.env.stationChild === true) {
|
|
17669
17920
|
let firstTurn;
|
|
17670
17921
|
const stationAdapters = withOnceSuccessfulBeforeDispatch(adapters);
|
|
17922
|
+
const invocationScopeId = mintEngineDetourInvocationScope({
|
|
17923
|
+
...input.effectiveEngine === void 0 ? {} : { effectiveEngine: input.effectiveEngine }
|
|
17924
|
+
});
|
|
17671
17925
|
return await runWithAutoResumeLoop({
|
|
17672
17926
|
admitted: loaded.admitted,
|
|
17673
17927
|
principalAuthority: input.env.principalAuthority,
|
|
@@ -17694,7 +17948,10 @@ async function runPostAdmissionSeatResume(input) {
|
|
|
17694
17948
|
}
|
|
17695
17949
|
};
|
|
17696
17950
|
}
|
|
17697
|
-
const turnRequest =
|
|
17951
|
+
const turnRequest = withEngineDetourInvocationScope(
|
|
17952
|
+
await buildRequestAfterLease(),
|
|
17953
|
+
invocationScopeId
|
|
17954
|
+
);
|
|
17698
17955
|
firstTurn = turnRequest;
|
|
17699
17956
|
return turnRequest;
|
|
17700
17957
|
},
|
|
@@ -17765,6 +18022,11 @@ async function runPostAdmissionOneShot(input) {
|
|
|
17765
18022
|
async function runPostAdmissionResumable(input) {
|
|
17766
18023
|
const { admitted, env, io, buildInitialRequest, buildResumeRequest, effectiveEngine } = input;
|
|
17767
18024
|
const adapters = withOnceSuccessfulBeforeDispatch(input.adapters);
|
|
18025
|
+
const invocationScopeId = mintEngineDetourInvocationScope({
|
|
18026
|
+
...effectiveEngine === void 0 ? {} : { effectiveEngine }
|
|
18027
|
+
});
|
|
18028
|
+
const buildScopedInitial = () => withEngineDetourInvocationScope(buildInitialRequest(), invocationScopeId);
|
|
18029
|
+
const buildScopedResume = () => withEngineDetourInvocationScope(buildResumeRequest(), invocationScopeId);
|
|
17768
18030
|
return runWithAutoResumeLoop({
|
|
17769
18031
|
admitted,
|
|
17770
18032
|
principalAuthority: env.principalAuthority,
|
|
@@ -17772,8 +18034,8 @@ async function runPostAdmissionResumable(input) {
|
|
|
17772
18034
|
io,
|
|
17773
18035
|
sessionAppender: env.sessionAppender,
|
|
17774
18036
|
autoResumeLimit: env.autoResumeLimit,
|
|
17775
|
-
buildInitialPayload:
|
|
17776
|
-
buildResumePayload:
|
|
18037
|
+
buildInitialPayload: buildScopedInitial,
|
|
18038
|
+
buildResumePayload: buildScopedResume,
|
|
17777
18039
|
dispatch: async (request, lease, _isFirst, attemptIo) => {
|
|
17778
18040
|
const result = await dispatchPostAdmissionTurn({
|
|
17779
18041
|
admitted,
|
|
@@ -17821,6 +18083,9 @@ async function runPostAdmissionManualResume(input) {
|
|
|
17821
18083
|
}
|
|
17822
18084
|
throw error;
|
|
17823
18085
|
}
|
|
18086
|
+
const invocationScopeId = mintEngineDetourInvocationScope({
|
|
18087
|
+
...effectiveEngine === void 0 ? {} : { effectiveEngine }
|
|
18088
|
+
});
|
|
17824
18089
|
const result = await dispatchAfterWriterLease({
|
|
17825
18090
|
lease,
|
|
17826
18091
|
build: async () => {
|
|
@@ -17832,6 +18097,7 @@ async function runPostAdmissionManualResume(input) {
|
|
|
17832
18097
|
}
|
|
17833
18098
|
request = await buildRequestAfterLease();
|
|
17834
18099
|
}
|
|
18100
|
+
request = withEngineDetourInvocationScope(request, invocationScopeId);
|
|
17835
18101
|
return request;
|
|
17836
18102
|
},
|
|
17837
18103
|
dispatch: (turnRequest) => dispatchPostAdmissionTurn({
|
|
@@ -17871,6 +18137,7 @@ var init_post_admission = __esm({
|
|
|
17871
18137
|
init_session_identity();
|
|
17872
18138
|
init_host_contracts();
|
|
17873
18139
|
init_case_dossier_delivery();
|
|
18140
|
+
init_engine_detour_usage();
|
|
17874
18141
|
init_host_transition_prior_native();
|
|
17875
18142
|
init_public_run_credentials();
|
|
17876
18143
|
init_run_lifecycle();
|
|
@@ -17905,6 +18172,7 @@ function projectRoleTurnRequest(admitted, roleDetails, options) {
|
|
|
17905
18172
|
...options.correlationId === void 0 || options.correlationId.trim() === "" ? {} : { correlationId: options.correlationId },
|
|
17906
18173
|
...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs },
|
|
17907
18174
|
...options.courtAttemptId === void 0 || options.courtAttemptId.length === 0 ? {} : { courtAttemptId: options.courtAttemptId },
|
|
18175
|
+
...options.invocationScopeId === void 0 || options.invocationScopeId.length === 0 ? {} : { invocationScopeId: options.invocationScopeId },
|
|
17908
18176
|
...options.stationChild === void 0 ? {} : { stationChild: options.stationChild }
|
|
17909
18177
|
};
|
|
17910
18178
|
}
|
|
@@ -18923,7 +19191,7 @@ __export(public_role_summons_exports, {
|
|
|
18923
19191
|
summonPublicRole: () => summonPublicRole
|
|
18924
19192
|
});
|
|
18925
19193
|
import { existsSync as existsSync11 } from "node:fs";
|
|
18926
|
-
import { join as
|
|
19194
|
+
import { join as join37 } from "node:path";
|
|
18927
19195
|
function createCapturingIo() {
|
|
18928
19196
|
const chunks = [];
|
|
18929
19197
|
return {
|
|
@@ -18946,7 +19214,7 @@ function parentDir(path) {
|
|
|
18946
19214
|
function walkPackageRoot(start) {
|
|
18947
19215
|
let dir = start;
|
|
18948
19216
|
for (let i = 0; i < 12; i += 1) {
|
|
18949
|
-
if (existsSync11(
|
|
19217
|
+
if (existsSync11(join37(dir, "package.json")) && existsSync11(join37(dir, "souls"))) {
|
|
18950
19218
|
return dir;
|
|
18951
19219
|
}
|
|
18952
19220
|
const parent = parentDir(dir);
|
|
@@ -19040,7 +19308,7 @@ async function createSummonEnv(options) {
|
|
|
19040
19308
|
async function summonPublicRole(options) {
|
|
19041
19309
|
const packageRoot = resolveSummonsPackageRoot(options.packageRoot);
|
|
19042
19310
|
const home = await resolveSummonHome(options);
|
|
19043
|
-
const agentDir = options.agentDir ?? process.env.PI_CODING_AGENT_DIR ??
|
|
19311
|
+
const agentDir = options.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? join37(home, ".pi", "agent");
|
|
19044
19312
|
const {
|
|
19045
19313
|
loadCredentialProviders: loadCredentialProviders2,
|
|
19046
19314
|
loadPublicCliConfig: loadPublicCliConfig2,
|
|
@@ -19416,14 +19684,14 @@ var init_gatekeeper_role = __esm({
|
|
|
19416
19684
|
});
|
|
19417
19685
|
|
|
19418
19686
|
// src/acp-host/production-host.ts
|
|
19419
|
-
import { randomUUID as
|
|
19687
|
+
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
19420
19688
|
|
|
19421
19689
|
// src/role-envelope.ts
|
|
19422
19690
|
init_engine_detour();
|
|
19423
|
-
import { randomUUID as
|
|
19424
|
-
import { mkdir as mkdir5, readFile as
|
|
19691
|
+
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
19692
|
+
import { mkdir as mkdir5, readFile as readFile21, writeFile as writeFile12 } from "node:fs/promises";
|
|
19425
19693
|
import { createServer } from "node:net";
|
|
19426
|
-
import { basename as
|
|
19694
|
+
import { basename as basename10, dirname as dirname21, join as join41 } from "node:path";
|
|
19427
19695
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
19428
19696
|
|
|
19429
19697
|
// src/gatekeeper-pass-envelope.ts
|
|
@@ -19497,8 +19765,8 @@ init_host_contracts();
|
|
|
19497
19765
|
init_sitian_facade();
|
|
19498
19766
|
init_submission_ledger();
|
|
19499
19767
|
init_collector_ledger();
|
|
19500
|
-
import { readFileSync as
|
|
19501
|
-
import { join as
|
|
19768
|
+
import { readFileSync as readFileSync6, writeSync as writeSync4 } from "node:fs";
|
|
19769
|
+
import { join as join40 } from "node:path";
|
|
19502
19770
|
import { Value as Value4 } from "typebox/value";
|
|
19503
19771
|
|
|
19504
19772
|
// src/activation-trace.ts
|
|
@@ -19548,7 +19816,7 @@ import {
|
|
|
19548
19816
|
openSync as openSync2,
|
|
19549
19817
|
writeSync
|
|
19550
19818
|
} from "node:fs";
|
|
19551
|
-
import { dirname as
|
|
19819
|
+
import { dirname as dirname19, isAbsolute as isAbsolute10, resolve as resolve15 } from "node:path";
|
|
19552
19820
|
|
|
19553
19821
|
// src/activation-ledger-session.ts
|
|
19554
19822
|
init_activation_ledger_topology();
|
|
@@ -19697,7 +19965,7 @@ function appendActivationLedgerLine(ledgerPath, line2, options) {
|
|
|
19697
19965
|
}
|
|
19698
19966
|
const resolvedLedger = resolve15(ledgerPath);
|
|
19699
19967
|
const resolvedHome = resolve15(options.ledgerHome);
|
|
19700
|
-
const parent =
|
|
19968
|
+
const parent = dirname19(resolvedLedger);
|
|
19701
19969
|
ensureRealDirectoryTree(resolvedHome, parent);
|
|
19702
19970
|
assertLedgerFileInsideHome(resolvedLedger, resolvedHome);
|
|
19703
19971
|
if (typeof constants2.O_NOFOLLOW !== "number") {
|
|
@@ -19911,7 +20179,15 @@ init_engine_material();
|
|
|
19911
20179
|
|
|
19912
20180
|
// src/engine-detour-tool.ts
|
|
19913
20181
|
init_engine_detour();
|
|
20182
|
+
init_engine_detour_usage();
|
|
20183
|
+
import { basename as basename9 } from "node:path";
|
|
19914
20184
|
import { Type as Type14 } from "typebox";
|
|
20185
|
+
function basenameRunId(runDirectory) {
|
|
20186
|
+
const leaf = basename9(runDirectory);
|
|
20187
|
+
const at = leaf.indexOf("@");
|
|
20188
|
+
if (at <= 0) return void 0;
|
|
20189
|
+
return leaf.slice(0, at);
|
|
20190
|
+
}
|
|
19915
20191
|
var engineDetourArgsSchema = Type14.Object(
|
|
19916
20192
|
{
|
|
19917
20193
|
argv: Type14.Array(Type14.String({ minLength: 1 }), {
|
|
@@ -19928,6 +20204,9 @@ function isCallerCancellation(error, signal) {
|
|
|
19928
20204
|
}
|
|
19929
20205
|
return false;
|
|
19930
20206
|
}
|
|
20207
|
+
function asError(error, fallback) {
|
|
20208
|
+
return error instanceof Error ? error : new Error(String(error).trim() || fallback);
|
|
20209
|
+
}
|
|
19931
20210
|
function createEngineDetourToolDefinition(input) {
|
|
19932
20211
|
const engineName = input.engineName;
|
|
19933
20212
|
const engineModel = input.engineModel;
|
|
@@ -19948,6 +20227,45 @@ function createEngineDetourToolDefinition(input) {
|
|
|
19948
20227
|
ctx
|
|
19949
20228
|
);
|
|
19950
20229
|
}
|
|
20230
|
+
const sessionParent = ctx.sessionManager?.getSessionFile?.();
|
|
20231
|
+
const startedAt = Date.now();
|
|
20232
|
+
const runDirectory = typeof ctx.runDirectory === "string" && ctx.runDirectory.length > 0 ? ctx.runDirectory : void 0;
|
|
20233
|
+
const runId = runDirectory === void 0 ? void 0 : basenameRunId(runDirectory);
|
|
20234
|
+
const invocationScopeId = typeof ctx.invocationScopeId === "string" && ctx.invocationScopeId.trim() !== "" ? ctx.invocationScopeId.trim() : void 0;
|
|
20235
|
+
const host = typeof ctx.host === "string" && ctx.host.trim() !== "" ? ctx.host.trim() : void 0;
|
|
20236
|
+
const recordCall = (observed2) => {
|
|
20237
|
+
if (typeof sessionParent !== "string" || sessionParent.length === 0) return;
|
|
20238
|
+
reportEngineDetourCall({
|
|
20239
|
+
toolCallId,
|
|
20240
|
+
durationMs: Math.max(0, Date.now() - startedAt),
|
|
20241
|
+
cwd: ctx.cwd,
|
|
20242
|
+
sessionParent,
|
|
20243
|
+
...runId === void 0 ? {} : { runId },
|
|
20244
|
+
...invocationScopeId === void 0 ? {} : { invocationScopeId },
|
|
20245
|
+
...host === void 0 ? {} : { host },
|
|
20246
|
+
...observed2.code === void 0 ? {} : { code: observed2.code },
|
|
20247
|
+
...observed2.stdoutByteLength === void 0 ? {} : { stdoutByteLength: observed2.stdoutByteLength }
|
|
20248
|
+
});
|
|
20249
|
+
};
|
|
20250
|
+
const failAfterLedger = (engineCause, observed2, aggregateMessage) => {
|
|
20251
|
+
try {
|
|
20252
|
+
recordCall(observed2);
|
|
20253
|
+
} catch (recordError) {
|
|
20254
|
+
input.fail(
|
|
20255
|
+
new AggregateError(
|
|
20256
|
+
[
|
|
20257
|
+
engineCause,
|
|
20258
|
+
asError(recordError, "engine detour usage ledger write failed")
|
|
20259
|
+
],
|
|
20260
|
+
aggregateMessage,
|
|
20261
|
+
{ cause: engineCause }
|
|
20262
|
+
),
|
|
20263
|
+
toolCallId,
|
|
20264
|
+
ctx
|
|
20265
|
+
);
|
|
20266
|
+
}
|
|
20267
|
+
input.fail(engineCause, toolCallId, ctx);
|
|
20268
|
+
};
|
|
19951
20269
|
let result;
|
|
19952
20270
|
try {
|
|
19953
20271
|
result = await runEngineDetourOnce({
|
|
@@ -19957,16 +20275,22 @@ function createEngineDetourToolDefinition(input) {
|
|
|
19957
20275
|
});
|
|
19958
20276
|
} catch (error) {
|
|
19959
20277
|
if (isCallerCancellation(error, signal)) throw error;
|
|
19960
|
-
|
|
19961
|
-
|
|
20278
|
+
return failAfterLedger(
|
|
20279
|
+
asError(error, "\u52B3\u52A1\u5F15\u64CE spawn \u5931\u8D25"),
|
|
20280
|
+
{},
|
|
20281
|
+
"engine detour spawn and usage ledger both failed"
|
|
20282
|
+
);
|
|
19962
20283
|
}
|
|
20284
|
+
const stdoutByteLength = engineDetourStdoutByteLength(result.stdout);
|
|
20285
|
+
const observed = { code: result.code, stdoutByteLength };
|
|
19963
20286
|
if (isEngineDetourFailure(result)) {
|
|
19964
|
-
|
|
20287
|
+
return failAfterLedger(
|
|
19965
20288
|
new Error(engineDetourFailureDiagnostic(result)),
|
|
19966
|
-
|
|
19967
|
-
|
|
20289
|
+
observed,
|
|
20290
|
+
"engine detour child-close and usage ledger both failed"
|
|
19968
20291
|
);
|
|
19969
20292
|
}
|
|
20293
|
+
recordCall(observed);
|
|
19970
20294
|
return {
|
|
19971
20295
|
content: [{ type: "text", text: result.stdout }],
|
|
19972
20296
|
details: {
|
|
@@ -20007,8 +20331,8 @@ init_collector_github();
|
|
|
20007
20331
|
// src/collector-handbook.ts
|
|
20008
20332
|
init_atomic_write();
|
|
20009
20333
|
init_activation_ledger_topology();
|
|
20010
|
-
import { readFile as
|
|
20011
|
-
import { join as
|
|
20334
|
+
import { readFile as readFile20 } from "node:fs/promises";
|
|
20335
|
+
import { join as join38, sep as sep5 } from "node:path";
|
|
20012
20336
|
|
|
20013
20337
|
// src/collector-tool-schemas.ts
|
|
20014
20338
|
init_open_tool_schema();
|
|
@@ -20123,7 +20447,7 @@ function resolveCollectorHandbookRoot(sessionPath) {
|
|
|
20123
20447
|
throw new Error(`\u901A\u8FDB\u53F8\u624B\u518C\u62D2\u7EDD\u4E0D\u5B89\u5168 bookKey ${JSON.stringify(bookKey)}`);
|
|
20124
20448
|
}
|
|
20125
20449
|
const ledgerHome = resolveActivationLedgerHomeForPath(sessionPath);
|
|
20126
|
-
const root =
|
|
20450
|
+
const root = join38(activationBookDirectory(ledgerHome, bookKey), "collector-handbook");
|
|
20127
20451
|
return { ledgerHome, bookKey, root };
|
|
20128
20452
|
}
|
|
20129
20453
|
function collectorHandbookRepoFileName(repositoryCanonical) {
|
|
@@ -20135,9 +20459,9 @@ function collectorHandbookRepoFileName(repositoryCanonical) {
|
|
|
20135
20459
|
return `${repositoryCanonical.replaceAll("/", "__")}.md`;
|
|
20136
20460
|
}
|
|
20137
20461
|
function createCollectorHandbookStore(input) {
|
|
20138
|
-
const generalPath =
|
|
20139
|
-
const repoDir =
|
|
20140
|
-
const repoPath =
|
|
20462
|
+
const generalPath = join38(input.handbookRoot, "general.md");
|
|
20463
|
+
const repoDir = join38(input.handbookRoot, "repos");
|
|
20464
|
+
const repoPath = join38(repoDir, collectorHandbookRepoFileName(input.repositoryCanonical));
|
|
20141
20465
|
const assertHandbookBudget = (body, label) => {
|
|
20142
20466
|
const byteLength = Buffer.byteLength(body, "utf8");
|
|
20143
20467
|
if (byteLength > COLLECTOR_HANDBOOK_MAX_BYTES) {
|
|
@@ -20151,7 +20475,7 @@ function createCollectorHandbookStore(input) {
|
|
|
20151
20475
|
ensureRealDirectoryTree(input.ledgerHome, parentDir2);
|
|
20152
20476
|
assertLedgerFileInsideHome(path, input.ledgerHome);
|
|
20153
20477
|
try {
|
|
20154
|
-
const body = await
|
|
20478
|
+
const body = await readFile20(path, "utf8");
|
|
20155
20479
|
assertHandbookBudget(body, "\u6B63\u6587");
|
|
20156
20480
|
return body;
|
|
20157
20481
|
} catch (error) {
|
|
@@ -22385,7 +22709,7 @@ init_sitian_facade();
|
|
|
22385
22709
|
init_submission_errors();
|
|
22386
22710
|
init_submission_errors();
|
|
22387
22711
|
import { execFileSync as execFileSync4 } from "node:child_process";
|
|
22388
|
-
import { existsSync as existsSync12, lstatSync as lstatSync3, readdirSync as readdirSync3, readFileSync as
|
|
22712
|
+
import { existsSync as existsSync12, lstatSync as lstatSync3, readdirSync as readdirSync3, readFileSync as readFileSync5, rmdirSync, rmSync } from "node:fs";
|
|
22389
22713
|
import { resolve as resolve17 } from "node:path";
|
|
22390
22714
|
var WORKER_SUBMISSION_GATE_RECORD_KIND = WORKER_SUBMISSION_GATE_KIND;
|
|
22391
22715
|
var WORKER_COMMIT_BASELINE_ENTRY_TYPE = "commit-baseline";
|
|
@@ -22427,7 +22751,7 @@ function tryGetAll(file, key) {
|
|
|
22427
22751
|
}
|
|
22428
22752
|
function ownedHook(path) {
|
|
22429
22753
|
if (!existsSync12(path)) return false;
|
|
22430
|
-
return
|
|
22754
|
+
return readFileSync5(path, "utf8").includes(HOOK_MARKER);
|
|
22431
22755
|
}
|
|
22432
22756
|
function escapeGitConfigValueRegex(value) {
|
|
22433
22757
|
return value.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
|
|
@@ -22482,7 +22806,7 @@ function uninstallPackageWorkerHooks(cwd) {
|
|
|
22482
22806
|
rmOwnedDir(resolve17(gitDir, HOOKS_DIR));
|
|
22483
22807
|
}
|
|
22484
22808
|
}
|
|
22485
|
-
function
|
|
22809
|
+
function isRecord13(value) {
|
|
22486
22810
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22487
22811
|
}
|
|
22488
22812
|
function unfinishedReasonPresent(details) {
|
|
@@ -22498,7 +22822,7 @@ function readGateState(session) {
|
|
|
22498
22822
|
if (entry.type !== "custom") continue;
|
|
22499
22823
|
if (entry.customType === WORKER_COMMIT_BASELINE_ENTRY_TYPE) {
|
|
22500
22824
|
const data = entry.data;
|
|
22501
|
-
if (
|
|
22825
|
+
if (isRecord13(data) && (data.head === null || typeof data.head === "string")) {
|
|
22502
22826
|
baseline = data.head;
|
|
22503
22827
|
}
|
|
22504
22828
|
} else if (entry.customType === WORKER_COMMIT_REMINDER_BOUNCE_ENTRY_TYPE) {
|
|
@@ -23469,8 +23793,8 @@ function readDiaristRunCoordinates(ctx) {
|
|
|
23469
23793
|
if (runDirectory === void 0) {
|
|
23470
23794
|
throw new Error("diarist accept requires AK_ROLE_RUN_DIR");
|
|
23471
23795
|
}
|
|
23472
|
-
const admittedPath =
|
|
23473
|
-
const admitted = JSON.parse(
|
|
23796
|
+
const admittedPath = join40(runDirectory, "admitted-request.json");
|
|
23797
|
+
const admitted = JSON.parse(readFileSync6(admittedPath, "utf8"));
|
|
23474
23798
|
if (typeof admitted.projectRoot !== "string" || admitted.projectRoot.trim() === "") {
|
|
23475
23799
|
throw new Error(`diarist admitted-request missing projectRoot (${admittedPath})`);
|
|
23476
23800
|
}
|
|
@@ -24488,16 +24812,16 @@ async function prepareRoleEnvelope(options) {
|
|
|
24488
24812
|
let rejection;
|
|
24489
24813
|
let infrastructureRoundFailure;
|
|
24490
24814
|
const hostAbort = new AbortController();
|
|
24491
|
-
const runId = request.runDirectory.split("/").filter(Boolean).at(-1) ??
|
|
24815
|
+
const runId = request.runDirectory.split("/").filter(Boolean).at(-1) ?? randomUUID8();
|
|
24492
24816
|
await mkdir5(request.runDirectory, { recursive: true });
|
|
24493
24817
|
for (const method of request.methods) {
|
|
24494
24818
|
if (method.kind !== "skill") continue;
|
|
24495
|
-
const name =
|
|
24496
|
-
const raw = await
|
|
24819
|
+
const name = basename10(dirname21(method.path));
|
|
24820
|
+
const raw = await readFile21(method.path, "utf8");
|
|
24497
24821
|
methodSkills.set(name, { path: method.path, body: stripSkillFrontmatter(raw).trim() });
|
|
24498
24822
|
}
|
|
24499
|
-
let sessionFile = options.sessionFile ??
|
|
24500
|
-
await mkdir5(
|
|
24823
|
+
let sessionFile = options.sessionFile ?? join41(request.runDirectory, "session", "session.jsonl");
|
|
24824
|
+
await mkdir5(dirname21(sessionFile), { recursive: true });
|
|
24501
24825
|
if (request.continuation.kind !== "resume") {
|
|
24502
24826
|
try {
|
|
24503
24827
|
await writeFile12(
|
|
@@ -24522,11 +24846,13 @@ async function prepareRoleEnvelope(options) {
|
|
|
24522
24846
|
model: request.model === void 0 ? void 0 : { provider: request.model.provider },
|
|
24523
24847
|
runDirectory: request.runDirectory,
|
|
24524
24848
|
...request.courtAttemptId === void 0 ? {} : { courtAttemptId: request.courtAttemptId },
|
|
24849
|
+
...request.invocationScopeId === void 0 ? {} : { invocationScopeId: request.invocationScopeId },
|
|
24850
|
+
...request.host === void 0 || request.host.trim() === "" ? {} : { host: request.host.trim() },
|
|
24525
24851
|
sessionManager: {
|
|
24526
24852
|
getLeafEntry: () => sessionEntries.at(-1),
|
|
24527
24853
|
getLeafId: () => runId,
|
|
24528
24854
|
getEntries: () => sessionEntries,
|
|
24529
|
-
getSessionDir: () =>
|
|
24855
|
+
getSessionDir: () => dirname21(sessionFile),
|
|
24530
24856
|
getSessionFile: () => sessionFile,
|
|
24531
24857
|
getHeader: () => ({ type: "session", id: runId }),
|
|
24532
24858
|
setSessionFile(path) {
|
|
@@ -24627,7 +24953,7 @@ async function prepareRoleEnvelope(options) {
|
|
|
24627
24953
|
}
|
|
24628
24954
|
};
|
|
24629
24955
|
createRoleRuntimeExtension(options.dependencies)(envelope);
|
|
24630
|
-
const token =
|
|
24956
|
+
const token = randomUUID8();
|
|
24631
24957
|
const server = createServer((socket) => serveSocket(socket));
|
|
24632
24958
|
function rememberProjectedRejection(details, toolCallId, content) {
|
|
24633
24959
|
if (typeof details !== "object" || details === null) return;
|
|
@@ -24708,7 +25034,7 @@ async function prepareRoleEnvelope(options) {
|
|
|
24708
25034
|
async function invokeAkTool(name, args) {
|
|
24709
25035
|
const tool = tools.get(name);
|
|
24710
25036
|
if (tool === void 0) throw new Error(`Unknown AK tool: ${name}`);
|
|
24711
|
-
const toolCallId =
|
|
25037
|
+
const toolCallId = randomUUID8();
|
|
24712
25038
|
calls.push({ toolCallId, toolName: name });
|
|
24713
25039
|
sessionEntries.push({
|
|
24714
25040
|
type: "message",
|
|
@@ -24901,7 +25227,7 @@ async function prepareRoleEnvelope(options) {
|
|
|
24901
25227
|
message: { role: "user", content: prompt }
|
|
24902
25228
|
});
|
|
24903
25229
|
}
|
|
24904
|
-
const methodPrompt = (await Promise.all(request.methods.map(({ path }) =>
|
|
25230
|
+
const methodPrompt = (await Promise.all(request.methods.map(({ path }) => readFile21(path, "utf8")))).join("\n\n");
|
|
24905
25231
|
const promptResults = await emit("before_agent_start", {
|
|
24906
25232
|
prompt,
|
|
24907
25233
|
systemPrompt: methodPrompt,
|
|
@@ -24959,18 +25285,18 @@ async function prepareRoleEnvelope(options) {
|
|
|
24959
25285
|
}
|
|
24960
25286
|
|
|
24961
25287
|
// src/role-runtime-dependencies.ts
|
|
24962
|
-
import { readFile as
|
|
25288
|
+
import { readFile as readFile24 } from "node:fs/promises";
|
|
24963
25289
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
24964
25290
|
|
|
24965
25291
|
// src/canonical-skill-binding.ts
|
|
24966
|
-
import { readFile as
|
|
25292
|
+
import { readFile as readFile22, realpath as realpath7 } from "node:fs/promises";
|
|
24967
25293
|
import { homedir } from "node:os";
|
|
24968
|
-
import { dirname as
|
|
25294
|
+
import { dirname as dirname22, resolve as resolve18 } from "node:path";
|
|
24969
25295
|
import { stripFrontmatter } from "@earendil-works/pi-coding-agent";
|
|
24970
25296
|
function captureCanonicalSkillExpansion(name, snapshot, configuredPath, evidence, originalRequest) {
|
|
24971
25297
|
const matchedPath = evidence?.location === configuredPath ? configuredPath : evidence?.location === snapshot.path ? snapshot.path : void 0;
|
|
24972
25298
|
const expectedContent = matchedPath === void 0 ? void 0 : snapshot.body;
|
|
24973
|
-
const prefixedContent = matchedPath === void 0 ? void 0 : `References are relative to ${
|
|
25299
|
+
const prefixedContent = matchedPath === void 0 ? void 0 : `References are relative to ${dirname22(matchedPath)}.
|
|
24974
25300
|
|
|
24975
25301
|
${snapshot.body}`;
|
|
24976
25302
|
if (evidence?.name !== name || matchedPath === void 0 || evidence.content !== expectedContent && evidence.content !== prefixedContent || evidence.userMessage !== originalRequest) {
|
|
@@ -24996,7 +25322,7 @@ async function loadCanonicalSkillBinding(name) {
|
|
|
24996
25322
|
let raw;
|
|
24997
25323
|
try {
|
|
24998
25324
|
path = await realpath7(configuredPath);
|
|
24999
|
-
raw = await
|
|
25325
|
+
raw = await readFile22(path, "utf8");
|
|
25000
25326
|
} catch (error) {
|
|
25001
25327
|
throw new CanonicalSkillUnavailableError(name, configuredPath, error);
|
|
25002
25328
|
}
|
|
@@ -25007,7 +25333,7 @@ async function loadCanonicalSkillBinding(name) {
|
|
|
25007
25333
|
const snapshot = Object.freeze({
|
|
25008
25334
|
raw,
|
|
25009
25335
|
path,
|
|
25010
|
-
baseDir:
|
|
25336
|
+
baseDir: dirname22(path),
|
|
25011
25337
|
body,
|
|
25012
25338
|
snapshotIdentity: Object.freeze({ text: raw })
|
|
25013
25339
|
});
|
|
@@ -25035,7 +25361,7 @@ init_doctor_evidence();
|
|
|
25035
25361
|
// src/navigator-work-context.ts
|
|
25036
25362
|
init_doctor_evidence();
|
|
25037
25363
|
init_host_contracts();
|
|
25038
|
-
import { readFile as
|
|
25364
|
+
import { readFile as readFile23 } from "node:fs/promises";
|
|
25039
25365
|
import { resolve as resolve19 } from "node:path";
|
|
25040
25366
|
init_notary_source_run();
|
|
25041
25367
|
init_packaged_role_registry();
|
|
@@ -25048,7 +25374,7 @@ function navigatorInputReference(getFlag, role) {
|
|
|
25048
25374
|
}
|
|
25049
25375
|
async function loadNavigatorWorkContext(options) {
|
|
25050
25376
|
const reference = navigatorInputReference(options.getFlag, options.role);
|
|
25051
|
-
const input = reference === void 0 || options.role === "doctor" || options.role === "notary" ? void 0 : await
|
|
25377
|
+
const input = reference === void 0 || options.role === "doctor" || options.role === "notary" ? void 0 : await readFile23(reference, "utf8");
|
|
25052
25378
|
const subjectRoot = subjectPath(reference ?? options.context.sessionManager.getSessionDir(), options.context.cwd);
|
|
25053
25379
|
let subjectKey = reference === void 0 ? subjectRoot : navigatorSubjectKeyForInput(subjectRoot, reference, options.context.cwd);
|
|
25054
25380
|
let subject = input ?? `work subject: ${subjectKey}`;
|
|
@@ -25105,7 +25431,7 @@ async function loadNavigatorWorkContext(options) {
|
|
|
25105
25431
|
let authorityMaterial;
|
|
25106
25432
|
for (const path of authorityFiles) {
|
|
25107
25433
|
try {
|
|
25108
|
-
const content = await
|
|
25434
|
+
const content = await readFile23(path, "utf8");
|
|
25109
25435
|
if (content.trim() !== "") {
|
|
25110
25436
|
authorityMaterial = content;
|
|
25111
25437
|
break;
|
|
@@ -25130,7 +25456,7 @@ async function loadNavigatorWorkContext(options) {
|
|
|
25130
25456
|
init_notary_source_run();
|
|
25131
25457
|
|
|
25132
25458
|
// src/package-resources/method-skill-binding.ts
|
|
25133
|
-
import { dirname as
|
|
25459
|
+
import { dirname as dirname23 } from "node:path";
|
|
25134
25460
|
init_method_skill();
|
|
25135
25461
|
async function loadPackagedCanonicalSkillBinding(packageRoot, name) {
|
|
25136
25462
|
const material = await loadPackagedMethodSkillMaterial(packageRoot, name);
|
|
@@ -25138,7 +25464,7 @@ async function loadPackagedCanonicalSkillBinding(packageRoot, name) {
|
|
|
25138
25464
|
const snapshot = Object.freeze({
|
|
25139
25465
|
raw: material.raw,
|
|
25140
25466
|
path: material.skillPath,
|
|
25141
|
-
baseDir:
|
|
25467
|
+
baseDir: dirname23(material.skillPath),
|
|
25142
25468
|
body: material.body,
|
|
25143
25469
|
snapshotIdentity: Object.freeze({ text: material.raw })
|
|
25144
25470
|
});
|
|
@@ -25175,13 +25501,13 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
25175
25501
|
packageRoot,
|
|
25176
25502
|
loadJudgeSoul: () => loadMainRoleSessionMaterials("judge"),
|
|
25177
25503
|
loadFixerSoul: () => loadMainRoleSessionMaterials("fixer"),
|
|
25178
|
-
loadFixPacket: (path) =>
|
|
25504
|
+
loadFixPacket: (path) => readFile24(path, "utf8"),
|
|
25179
25505
|
loadCoderSoul: () => loadMainRoleSessionMaterials("coder"),
|
|
25180
|
-
loadCoderTask: (path) =>
|
|
25506
|
+
loadCoderTask: (path) => readFile24(path, "utf8"),
|
|
25181
25507
|
loadReviewerSoul: () => loadMainRoleSessionMaterials("reviewer"),
|
|
25182
25508
|
createReviewerPinnedGitReader: () => createReviewerPinnedGitReader(),
|
|
25183
25509
|
loadCollectorSoul: () => loadMainRoleSessionMaterials("collector"),
|
|
25184
|
-
loadCollectorHandbookSeed: () =>
|
|
25510
|
+
loadCollectorHandbookSeed: () => readFile24(collectorHandbookSeedPath, "utf8"),
|
|
25185
25511
|
createCollectorTransport: () => createGhCollectorGitHubTransport(),
|
|
25186
25512
|
loadDoctorSoul: () => loadMainRoleSessionMaterials("doctor"),
|
|
25187
25513
|
loadDoctorCase,
|
|
@@ -25195,7 +25521,7 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
25195
25521
|
loadDiaristSoul: () => loadMainRoleSessionMaterials("diarist"),
|
|
25196
25522
|
loadNotarySourceRun: loadNotarySourceRunLocator,
|
|
25197
25523
|
loadMergerSoul: () => loadMainRoleSessionMaterials("merger"),
|
|
25198
|
-
loadMergerInput: async (path) => JSON.parse(await
|
|
25524
|
+
loadMergerInput: async (path) => JSON.parse(await readFile24(path, "utf8")),
|
|
25199
25525
|
async loadCanonicalSkillBinding(name) {
|
|
25200
25526
|
if (name === "tdd") {
|
|
25201
25527
|
return loadPackagedCanonicalSkillBinding(packageRoot, "tdd");
|
|
@@ -25221,7 +25547,7 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
25221
25547
|
authority: options.authority,
|
|
25222
25548
|
invocationId: options.invocationId,
|
|
25223
25549
|
loadSoul: () => loadMainRoleSessionMaterials("navigator"),
|
|
25224
|
-
loadRoutePlaybook: () =>
|
|
25550
|
+
loadRoutePlaybook: () => readFile24(navigatorRoutePlaybookPath, "utf8"),
|
|
25225
25551
|
loadRoleHelp: async (role) => formatNavigatorRoleHelp(role),
|
|
25226
25552
|
createSession: navigatorSessionFactory,
|
|
25227
25553
|
...options.contextError === void 0 ? {} : { contextError: options.contextError },
|
|
@@ -25234,9 +25560,9 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
25234
25560
|
init_session_identity();
|
|
25235
25561
|
|
|
25236
25562
|
// src/acp-host/description.ts
|
|
25237
|
-
import { join as
|
|
25563
|
+
import { join as join42 } from "node:path";
|
|
25238
25564
|
function resolveAcpBinary(description, operatorHome) {
|
|
25239
|
-
return
|
|
25565
|
+
return join42(operatorHome, ...description.binaryFromHome);
|
|
25240
25566
|
}
|
|
25241
25567
|
function acpStdioArgs(description, model, seat) {
|
|
25242
25568
|
const { prefix, suffix, modelFlag, thinkingFlag } = description.argv;
|
|
@@ -25683,12 +26009,12 @@ function createAcpRoleTurnHost(config) {
|
|
|
25683
26009
|
// src/acp-host/seat-profile-soul.ts
|
|
25684
26010
|
import { constants as constants3 } from "node:fs";
|
|
25685
26011
|
import { access as access5, copyFile, lstat as lstat7, mkdir as mkdir6, readlink, symlink, unlink as unlink4 } from "node:fs/promises";
|
|
25686
|
-
import { dirname as
|
|
26012
|
+
import { dirname as dirname24, join as join43, relative as relative3, resolve as resolve20 } from "node:path";
|
|
25687
26013
|
function seatProfileName(spec, role) {
|
|
25688
26014
|
return `${spec.namePrefix}${role}`;
|
|
25689
26015
|
}
|
|
25690
26016
|
function packageRoleSoulPath(packageRoot, role) {
|
|
25691
|
-
return
|
|
26017
|
+
return join43(packageRoot, "souls", `${role}.md`);
|
|
25692
26018
|
}
|
|
25693
26019
|
async function pathExists2(path) {
|
|
25694
26020
|
try {
|
|
@@ -25705,16 +26031,16 @@ async function ensureSeatProfileSoul(options) {
|
|
|
25705
26031
|
if (!await pathExists2(soulTarget)) {
|
|
25706
26032
|
throw new Error(`packaged role soul missing: ${soulTarget}`);
|
|
25707
26033
|
}
|
|
25708
|
-
const profilesRoot =
|
|
25709
|
-
const profileDir =
|
|
25710
|
-
const hostRoot =
|
|
25711
|
-
const soulPath =
|
|
26034
|
+
const profilesRoot = join43(operatorHome, ...spec.profilesRootFromHome);
|
|
26035
|
+
const profileDir = join43(profilesRoot, profileName);
|
|
26036
|
+
const hostRoot = dirname24(profilesRoot);
|
|
26037
|
+
const soulPath = join43(profileDir, spec.soulFileName);
|
|
25712
26038
|
if (!await pathExists2(profileDir)) {
|
|
25713
26039
|
await mkdir6(profileDir, { recursive: true });
|
|
25714
26040
|
for (const name of ["auth.json", ".env", "config.yaml"]) {
|
|
25715
|
-
const source =
|
|
26041
|
+
const source = join43(hostRoot, name);
|
|
25716
26042
|
if (!await pathExists2(source)) continue;
|
|
25717
|
-
await copyFile(source,
|
|
26043
|
+
await copyFile(source, join43(profileDir, name));
|
|
25718
26044
|
}
|
|
25719
26045
|
} else {
|
|
25720
26046
|
await mkdir6(profileDir, { recursive: true });
|
|
@@ -25747,7 +26073,7 @@ function createComposedAcpRoleTurnHost(config) {
|
|
|
25747
26073
|
request,
|
|
25748
26074
|
dependencies: config.roleRuntimeDependencies,
|
|
25749
26075
|
sessionFile: config.sessionIdentity.resolveSessionFile(request.principal),
|
|
25750
|
-
socketPath: config.socketPath?.(request) ?? `/tmp/ak-acp-mcp-${
|
|
26076
|
+
socketPath: config.socketPath?.(request) ?? `/tmp/ak-acp-mcp-${randomUUID9()}.sock`
|
|
25751
26077
|
})
|
|
25752
26078
|
});
|
|
25753
26079
|
}
|