@akagilnc/pi-workflow-roles 0.1.4239 → 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
package/dist/public-cli/main.js
CHANGED
|
@@ -16849,6 +16849,10 @@ ${paths.join("\n")}`
|
|
|
16849
16849
|
};
|
|
16850
16850
|
if (request.courtAttemptId === void 0) delete env.AK_ROLE_COURT_ATTEMPT;
|
|
16851
16851
|
else env.AK_ROLE_COURT_ATTEMPT = request.courtAttemptId;
|
|
16852
|
+
if (request.invocationScopeId === void 0) delete env.AK_ROLE_INVOCATION_SCOPE;
|
|
16853
|
+
else env.AK_ROLE_INVOCATION_SCOPE = request.invocationScopeId;
|
|
16854
|
+
if (request.host === void 0 || request.host.trim() === "") delete env.AK_ROLE_HOST;
|
|
16855
|
+
else env.AK_ROLE_HOST = request.host.trim();
|
|
16852
16856
|
applyEngineChildEnv(env, request.engine);
|
|
16853
16857
|
if (typeof process.env.AK_ROLE_AUDITOR_SOURCE_RUN === "string" && process.env.AK_ROLE_AUDITOR_SOURCE_RUN.trim() !== "") {
|
|
16854
16858
|
env.AK_ROLE_AUDITOR_SOURCE_RUN = process.env.AK_ROLE_AUDITOR_SOURCE_RUN;
|
|
@@ -23719,10 +23723,10 @@ function pairGateRounds(volumes) {
|
|
|
23719
23723
|
return rounds.sort((a, b) => a.officerStartedAt.localeCompare(b.officerStartedAt)).map((round, index) => ({ ...round, roundIndex: index + 1 }));
|
|
23720
23724
|
}
|
|
23721
23725
|
async function resolveOfficerSessionFromPointerFile(pointerPath) {
|
|
23722
|
-
const { readFile:
|
|
23726
|
+
const { readFile: readFile24 } = await import("node:fs/promises");
|
|
23723
23727
|
let raw;
|
|
23724
23728
|
try {
|
|
23725
|
-
raw = JSON.parse(await
|
|
23729
|
+
raw = JSON.parse(await readFile24(pointerPath, "utf8"));
|
|
23726
23730
|
} catch (error) {
|
|
23727
23731
|
throw new Error(
|
|
23728
23732
|
`direct officer run pointer unreadable in ${pointerPath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
@@ -24484,6 +24488,154 @@ var init_collector_ledger = __esm({
|
|
|
24484
24488
|
}
|
|
24485
24489
|
});
|
|
24486
24490
|
|
|
24491
|
+
// src/engine-detour-usage.ts
|
|
24492
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
24493
|
+
import { readFileSync as readFileSync3 } from "node:fs";
|
|
24494
|
+
import { dirname as dirname13, join as join25 } from "node:path";
|
|
24495
|
+
function isRecord8(value) {
|
|
24496
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24497
|
+
}
|
|
24498
|
+
function callFactFromSitianPayload(payload, pointer) {
|
|
24499
|
+
if (!isRecord8(payload)) return void 0;
|
|
24500
|
+
if (payload.tool !== ENGINE_DETOUR_TOOL_NAME) return void 0;
|
|
24501
|
+
if (typeof payload.toolCallId !== "string" || payload.toolCallId.length === 0) {
|
|
24502
|
+
return void 0;
|
|
24503
|
+
}
|
|
24504
|
+
if (typeof payload.durationMs !== "number" || !Number.isFinite(payload.durationMs)) {
|
|
24505
|
+
return void 0;
|
|
24506
|
+
}
|
|
24507
|
+
return {
|
|
24508
|
+
toolCallId: payload.toolCallId,
|
|
24509
|
+
durationMs: payload.durationMs,
|
|
24510
|
+
...typeof payload.code === "number" ? { code: payload.code } : {},
|
|
24511
|
+
...typeof payload.stdoutByteLength === "number" ? { stdoutByteLength: payload.stdoutByteLength } : {},
|
|
24512
|
+
recordPointer: pointer
|
|
24513
|
+
};
|
|
24514
|
+
}
|
|
24515
|
+
function invocationScopeIdOfRecord(record4) {
|
|
24516
|
+
if (isRecord8(record4.subject)) {
|
|
24517
|
+
const fromSubject = record4.subject.invocationScopeId;
|
|
24518
|
+
if (typeof fromSubject === "string" && fromSubject.length > 0) return fromSubject;
|
|
24519
|
+
}
|
|
24520
|
+
if (isRecord8(record4.payload)) {
|
|
24521
|
+
const fromPayload = record4.payload.invocationScopeId;
|
|
24522
|
+
if (typeof fromPayload === "string" && fromPayload.length > 0) return fromPayload;
|
|
24523
|
+
}
|
|
24524
|
+
return void 0;
|
|
24525
|
+
}
|
|
24526
|
+
async function readEngineDetourToolUsage(input) {
|
|
24527
|
+
if (!input.engineMounted) return void 0;
|
|
24528
|
+
const { recordFile } = resolveSitianRecordPath({
|
|
24529
|
+
level: "event",
|
|
24530
|
+
kind: ENGINE_DETOUR_CALL_KIND,
|
|
24531
|
+
sessionParent: input.sessionParent,
|
|
24532
|
+
...input.home === void 0 ? {} : { home: input.home },
|
|
24533
|
+
...input.cwd === void 0 ? {} : { cwd: input.cwd }
|
|
24534
|
+
});
|
|
24535
|
+
const { records } = await readSitianRecords(recordFile);
|
|
24536
|
+
const calls = [];
|
|
24537
|
+
for (const record4 of records) {
|
|
24538
|
+
if (record4.kind !== ENGINE_DETOUR_CALL_KIND) continue;
|
|
24539
|
+
const boundScope = invocationScopeIdOfRecord(record4);
|
|
24540
|
+
if (input.invocationScopeId !== void 0 && input.invocationScopeId.length > 0) {
|
|
24541
|
+
if (boundScope !== input.invocationScopeId) continue;
|
|
24542
|
+
} else if (boundScope !== void 0) {
|
|
24543
|
+
continue;
|
|
24544
|
+
}
|
|
24545
|
+
const pointer = {
|
|
24546
|
+
identity: record4.identity,
|
|
24547
|
+
recordFile,
|
|
24548
|
+
kind: record4.kind,
|
|
24549
|
+
level: record4.level
|
|
24550
|
+
};
|
|
24551
|
+
const fact = callFactFromSitianPayload(record4.payload, pointer);
|
|
24552
|
+
if (fact === void 0) continue;
|
|
24553
|
+
calls.push(fact);
|
|
24554
|
+
}
|
|
24555
|
+
return { callCount: calls.length, calls };
|
|
24556
|
+
}
|
|
24557
|
+
function projectEngineDetourToolUsageForPublicTerminal(usage, options) {
|
|
24558
|
+
if (options.discloseRecordFile) return usage;
|
|
24559
|
+
return {
|
|
24560
|
+
callCount: usage.callCount,
|
|
24561
|
+
calls: usage.calls.map((call) => ({
|
|
24562
|
+
toolCallId: call.toolCallId,
|
|
24563
|
+
durationMs: call.durationMs,
|
|
24564
|
+
...call.code === void 0 ? {} : { code: call.code },
|
|
24565
|
+
...call.stdoutByteLength === void 0 ? {} : { stdoutByteLength: call.stdoutByteLength },
|
|
24566
|
+
recordPointer: {
|
|
24567
|
+
identity: call.recordPointer.identity,
|
|
24568
|
+
kind: call.recordPointer.kind,
|
|
24569
|
+
level: call.recordPointer.level,
|
|
24570
|
+
recordFile: ENGINE_DETOUR_CALL_RECORD_FILE_RELATIVE
|
|
24571
|
+
}
|
|
24572
|
+
}))
|
|
24573
|
+
};
|
|
24574
|
+
}
|
|
24575
|
+
function readInvocationRecord(runDirectory) {
|
|
24576
|
+
try {
|
|
24577
|
+
const raw = JSON.parse(
|
|
24578
|
+
readFileSync3(join25(runDirectory, "invocation.json"), "utf8")
|
|
24579
|
+
);
|
|
24580
|
+
return isRecord8(raw) ? raw : void 0;
|
|
24581
|
+
} catch (error) {
|
|
24582
|
+
if (error?.code === "ENOENT") return void 0;
|
|
24583
|
+
throw error;
|
|
24584
|
+
}
|
|
24585
|
+
}
|
|
24586
|
+
async function readInvocationEngineMounted(runDirectory) {
|
|
24587
|
+
const raw = readInvocationRecord(runDirectory);
|
|
24588
|
+
if (raw === void 0) return false;
|
|
24589
|
+
return typeof raw.engine === "string" && raw.engine.trim() !== "";
|
|
24590
|
+
}
|
|
24591
|
+
function readInvocationSelectedHost(runDirectory) {
|
|
24592
|
+
const raw = readInvocationRecord(runDirectory);
|
|
24593
|
+
if (raw === void 0) return void 0;
|
|
24594
|
+
return typeof raw.host === "string" && raw.host.trim() !== "" ? raw.host.trim() : void 0;
|
|
24595
|
+
}
|
|
24596
|
+
function withEngineDetourToolUsageFact(outcome, usage) {
|
|
24597
|
+
if (usage === void 0) return outcome;
|
|
24598
|
+
const prior = isRecord8(outcome.decisiveFacts) ? outcome.decisiveFacts : {};
|
|
24599
|
+
return {
|
|
24600
|
+
...outcome,
|
|
24601
|
+
decisiveFacts: {
|
|
24602
|
+
...prior,
|
|
24603
|
+
[ENGINE_DETOUR_TOOL_USAGE_FACT_KEY]: usage
|
|
24604
|
+
}
|
|
24605
|
+
};
|
|
24606
|
+
}
|
|
24607
|
+
function runDirectoryFromSessionDirectory(sessionDirectory) {
|
|
24608
|
+
return dirname13(sessionDirectory);
|
|
24609
|
+
}
|
|
24610
|
+
function sessionFileFromSessionDirectory(sessionDirectory) {
|
|
24611
|
+
return join25(sessionDirectory, "session.jsonl");
|
|
24612
|
+
}
|
|
24613
|
+
function mintEngineDetourInvocationScope(input) {
|
|
24614
|
+
const engine = input.effectiveEngine?.trim();
|
|
24615
|
+
if (engine === void 0 || engine.length === 0) return void 0;
|
|
24616
|
+
return randomUUID4();
|
|
24617
|
+
}
|
|
24618
|
+
function withEngineDetourInvocationScope(request, invocationScopeId) {
|
|
24619
|
+
if (invocationScopeId === void 0 || invocationScopeId.length === 0) {
|
|
24620
|
+
return request;
|
|
24621
|
+
}
|
|
24622
|
+
if (typeof request.invocationScopeId === "string" && request.invocationScopeId.length > 0) {
|
|
24623
|
+
return request;
|
|
24624
|
+
}
|
|
24625
|
+
return { ...request, invocationScopeId };
|
|
24626
|
+
}
|
|
24627
|
+
var ENGINE_DETOUR_CALL_KIND, ENGINE_DETOUR_TOOL_USAGE_FACT_KEY, ENGINE_DETOUR_CALL_RECORD_FILE_RELATIVE;
|
|
24628
|
+
var init_engine_detour_usage = __esm({
|
|
24629
|
+
"src/engine-detour-usage.ts"() {
|
|
24630
|
+
"use strict";
|
|
24631
|
+
init_engine_detour();
|
|
24632
|
+
init_sitian_facade();
|
|
24633
|
+
ENGINE_DETOUR_CALL_KIND = "engine-detour-call";
|
|
24634
|
+
ENGINE_DETOUR_TOOL_USAGE_FACT_KEY = "engineDetourToolUsage";
|
|
24635
|
+
ENGINE_DETOUR_CALL_RECORD_FILE_RELATIVE = `session/${ENGINE_DETOUR_CALL_KIND}/records.jsonl`;
|
|
24636
|
+
}
|
|
24637
|
+
});
|
|
24638
|
+
|
|
24487
24639
|
// src/work-subject-identity.ts
|
|
24488
24640
|
var init_work_subject_identity = __esm({
|
|
24489
24641
|
"src/work-subject-identity.ts"() {
|
|
@@ -24591,11 +24743,11 @@ var init_navigator_invocation_identity = __esm({
|
|
|
24591
24743
|
});
|
|
24592
24744
|
|
|
24593
24745
|
// src/receipt-delivery-policy.ts
|
|
24594
|
-
function
|
|
24746
|
+
function isRecord9(value) {
|
|
24595
24747
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24596
24748
|
}
|
|
24597
24749
|
function parseNoReceiptLifecycleFacts(input) {
|
|
24598
|
-
if (!
|
|
24750
|
+
if (!isRecord9(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) => isRecord9(item) && typeof item.reason === "string")) {
|
|
24599
24751
|
throw new TypeError("malformed no-receipt lifecycle facts");
|
|
24600
24752
|
}
|
|
24601
24753
|
return {
|
|
@@ -24771,16 +24923,16 @@ var init_terminal = __esm({
|
|
|
24771
24923
|
});
|
|
24772
24924
|
|
|
24773
24925
|
// src/public-cli/settlement.ts
|
|
24774
|
-
import { randomUUID as
|
|
24926
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
24775
24927
|
import { appendFile as appendFile2, readFile as readFile17, readdir as readdir7, writeFile as writeFile7 } from "node:fs/promises";
|
|
24776
|
-
import { dirname as
|
|
24928
|
+
import { dirname as dirname14, join as join26 } from "node:path";
|
|
24777
24929
|
function sealedLedgerHome(admitted) {
|
|
24778
24930
|
return homeFromRunDirectory(admitted.runDirectory);
|
|
24779
24931
|
}
|
|
24780
24932
|
function ledgerReadScope(admitted, scope) {
|
|
24781
24933
|
return {
|
|
24782
24934
|
home: sealedLedgerHome(admitted),
|
|
24783
|
-
sessionParent:
|
|
24935
|
+
sessionParent: join26(admitted.runDirectory, "session", "session.jsonl"),
|
|
24784
24936
|
...scope?.courtAttemptId === void 0 || scope.courtAttemptId.length === 0 ? {} : { attemptId: scope.courtAttemptId }
|
|
24785
24937
|
};
|
|
24786
24938
|
}
|
|
@@ -24843,7 +24995,7 @@ async function attachRecordedSubmissions(admitted, terminal, scope) {
|
|
|
24843
24995
|
await recordedSubmissionPayloads(admitted, void 0)
|
|
24844
24996
|
);
|
|
24845
24997
|
}
|
|
24846
|
-
async function settleHostEndedNoReceipt(admitted, authority) {
|
|
24998
|
+
async function settleHostEndedNoReceipt(admitted, authority, scope) {
|
|
24847
24999
|
const facts = noReceiptLifecycleFacts({
|
|
24848
25000
|
terminalToolCalled: false,
|
|
24849
25001
|
rejectedReceipts: [],
|
|
@@ -24865,7 +25017,8 @@ async function settleHostEndedNoReceipt(admitted, authority) {
|
|
|
24865
25017
|
artifacts: [],
|
|
24866
25018
|
runId: admitted.runId
|
|
24867
25019
|
},
|
|
24868
|
-
coordinates.sessionDirectory
|
|
25020
|
+
coordinates.sessionDirectory,
|
|
25021
|
+
detourGateContext(admitted, scope)
|
|
24869
25022
|
);
|
|
24870
25023
|
}
|
|
24871
25024
|
async function closedLedgerOutcome(admitted, role, scope) {
|
|
@@ -25208,12 +25361,12 @@ async function readSitianRetainedAuditorProviderStop(sessionFile) {
|
|
|
25208
25361
|
kind: "auditor",
|
|
25209
25362
|
sessionParent: sessionFile,
|
|
25210
25363
|
// Path is driven by sessionParent when under ledger home; cwd is a fallback only.
|
|
25211
|
-
cwd:
|
|
25364
|
+
cwd: dirname14(sessionFile)
|
|
25212
25365
|
});
|
|
25213
25366
|
const { records } = await readSitianRecords(recordFile);
|
|
25214
25367
|
for (let i = records.length - 1; i >= 0; i -= 1) {
|
|
25215
25368
|
const payload = records[i]?.payload;
|
|
25216
|
-
if (!
|
|
25369
|
+
if (!isRecord10(payload) || !isRecord10(payload.response)) continue;
|
|
25217
25370
|
if (typeof payload.type === "string") continue;
|
|
25218
25371
|
const stop = sessionProviderStopFromAssistant(payload.response);
|
|
25219
25372
|
if (stop !== void 0) return stop;
|
|
@@ -25234,7 +25387,7 @@ async function readSessionProviderStop(sessionFile) {
|
|
|
25234
25387
|
}
|
|
25235
25388
|
}
|
|
25236
25389
|
async function readBoundEvidenceChildKnownFailure(sessionFile) {
|
|
25237
|
-
const childDirectory =
|
|
25390
|
+
const childDirectory = join26(dirname14(sessionFile), "evidence-children");
|
|
25238
25391
|
let names;
|
|
25239
25392
|
try {
|
|
25240
25393
|
names = await readdir7(childDirectory);
|
|
@@ -25245,12 +25398,12 @@ async function readBoundEvidenceChildKnownFailure(sessionFile) {
|
|
|
25245
25398
|
for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
|
|
25246
25399
|
let entries;
|
|
25247
25400
|
try {
|
|
25248
|
-
entries = await readBoundSessionEntries(
|
|
25401
|
+
entries = await readBoundSessionEntries(join26(childDirectory, file));
|
|
25249
25402
|
} catch (error) {
|
|
25250
25403
|
throw sessionReadFailure(error, "failed to read discovered evidence-child session");
|
|
25251
25404
|
}
|
|
25252
25405
|
const header = entries.find((entry) => entry.type === "session");
|
|
25253
|
-
if (!
|
|
25406
|
+
if (!isRecord10(header) || header.parentSession !== sessionFile) continue;
|
|
25254
25407
|
const stop = extractSessionProviderStop(entries);
|
|
25255
25408
|
if (stop === void 0) continue;
|
|
25256
25409
|
const primary = knownFailureFromProviderStop(stop);
|
|
@@ -25283,12 +25436,12 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
25283
25436
|
return body.startsWith("\u672C\u6B21\u914D\u7F6E\u7684\u52B3\u52A1\u5F15\u64CE\u53CA\u5176\u624B\u518C\uFF1A") || body.startsWith("- engine:");
|
|
25284
25437
|
};
|
|
25285
25438
|
const isResumeEnvelope = (msg) => {
|
|
25286
|
-
if (!
|
|
25439
|
+
if (!isRecord10(msg) || msg.role !== "user") return false;
|
|
25287
25440
|
const text = typeof msg.text === "string" ? msg.text : typeof msg.content === "string" ? msg.content : void 0;
|
|
25288
25441
|
if (isResumeEnvelopeBytes(text)) return true;
|
|
25289
25442
|
const content = msg.content;
|
|
25290
25443
|
if (Array.isArray(content)) {
|
|
25291
|
-
return content.some((p) =>
|
|
25444
|
+
return content.some((p) => isRecord10(p) && (isResumeEnvelopeBytes(p.text) || isResumeEnvelopeBytes(p.content)));
|
|
25292
25445
|
}
|
|
25293
25446
|
return false;
|
|
25294
25447
|
};
|
|
@@ -25300,7 +25453,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
25300
25453
|
latestParentUserIndex = i;
|
|
25301
25454
|
break;
|
|
25302
25455
|
}
|
|
25303
|
-
const childDirectories = [
|
|
25456
|
+
const childDirectories = [join26(dirname14(sessionFile), "auditor-roles")];
|
|
25304
25457
|
const valid = [];
|
|
25305
25458
|
let sawAnyDirectory = false;
|
|
25306
25459
|
for (const childDirectory of childDirectories) {
|
|
@@ -25315,12 +25468,12 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
25315
25468
|
for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
|
|
25316
25469
|
let entries;
|
|
25317
25470
|
try {
|
|
25318
|
-
entries = await readBoundSessionEntries(
|
|
25471
|
+
entries = await readBoundSessionEntries(join26(childDirectory, file));
|
|
25319
25472
|
} catch (error) {
|
|
25320
25473
|
throw sessionReadFailure(error, "failed to read discovered auditor session");
|
|
25321
25474
|
}
|
|
25322
25475
|
const header = entries.find((entry) => entry.type === "session");
|
|
25323
|
-
if (!
|
|
25476
|
+
if (!isRecord10(header)) continue;
|
|
25324
25477
|
const bindingIndexes = [];
|
|
25325
25478
|
for (let i = 0; i < entries.length; i += 1) {
|
|
25326
25479
|
const entry = entries[i];
|
|
@@ -25334,7 +25487,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
25334
25487
|
end: idx + 1 < bindingIndexes.length ? bindingIndexes[idx + 1] : entries.length
|
|
25335
25488
|
})) : [{ entry: void 0, start: 0, end: entries.length }];
|
|
25336
25489
|
for (const { entry: bindingEntry, start, end } of bindingPasses) {
|
|
25337
|
-
const bindingParent = bindingEntry !== void 0 &&
|
|
25490
|
+
const bindingParent = bindingEntry !== void 0 && isRecord10(bindingEntry.data) && isRecord10(bindingEntry.data.parent) ? bindingEntry.data.parent : void 0;
|
|
25338
25491
|
const attemptEntryId = typeof bindingParent?.attemptEntryId === "string" ? bindingParent.attemptEntryId : void 0;
|
|
25339
25492
|
const attemptEntryIndex = attemptEntryId === void 0 ? -1 : parentEntries.findIndex((entry) => entry.id === attemptEntryId);
|
|
25340
25493
|
const boundSessionFile = typeof bindingParent?.sessionFile === "string" ? bindingParent.sessionFile : typeof header.parentSession === "string" ? header.parentSession : void 0;
|
|
@@ -25361,12 +25514,12 @@ function complianceFailureFromAuditorVolumes(volumes) {
|
|
|
25361
25514
|
if (stop === void 0) continue;
|
|
25362
25515
|
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
25363
25516
|
const entry = entries[i];
|
|
25364
|
-
if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !
|
|
25365
|
-
const parent =
|
|
25366
|
-
const failure =
|
|
25517
|
+
if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !isRecord10(entry.data)) continue;
|
|
25518
|
+
const parent = isRecord10(entry.data.parent) ? entry.data.parent : void 0;
|
|
25519
|
+
const failure = isRecord10(entry.data.failure) ? entry.data.failure : void 0;
|
|
25367
25520
|
if (parent?.sessionId !== parentId || parent.sessionFile !== sessionFile || parent.attemptEntryId !== attemptEntryId) continue;
|
|
25368
25521
|
if (failure === void 0) continue;
|
|
25369
|
-
const identity =
|
|
25522
|
+
const identity = isRecord10(failure.identity) ? failure.identity : void 0;
|
|
25370
25523
|
const typedCause = failure.cause === "provider" || failure.cause === "activation" || failure.cause === "session" || failure.cause === "output" || failure.cause === "timeout" ? failure.cause : void 0;
|
|
25371
25524
|
return {
|
|
25372
25525
|
...typedCause === void 0 ? {} : { cause: typedCause },
|
|
@@ -25375,7 +25528,7 @@ function complianceFailureFromAuditorVolumes(volumes) {
|
|
|
25375
25528
|
...typeof identity.code === "string" || typeof identity.code === "number" ? { code: identity.code } : {}
|
|
25376
25529
|
} },
|
|
25377
25530
|
...typeof failure.diagnostic === "string" ? { diagnostic: failure.diagnostic } : {},
|
|
25378
|
-
...
|
|
25531
|
+
...isRecord10(failure.details) ? { details: failure.details } : {}
|
|
25379
25532
|
};
|
|
25380
25533
|
}
|
|
25381
25534
|
}
|
|
@@ -25422,9 +25575,9 @@ function typedFailedTerminatingToolKnownFailure(entries) {
|
|
|
25422
25575
|
if (classification.kind !== "infrastructure") continue;
|
|
25423
25576
|
if (typeof message.toolCallId !== "string" || typeof message.toolName !== "string") continue;
|
|
25424
25577
|
if (boundRoleToolCallForResult(attemptEntries, i, message, message.toolName) === void 0) continue;
|
|
25425
|
-
const textPart = Array.isArray(message.content) ? message.content.find((part) =>
|
|
25426
|
-
const diagnostic =
|
|
25427
|
-
const details =
|
|
25578
|
+
const textPart = Array.isArray(message.content) ? message.content.find((part) => isRecord10(part) && part.type === "text" && typeof part.text === "string") : void 0;
|
|
25579
|
+
const diagnostic = isRecord10(textPart) ? textPart.text : void 0;
|
|
25580
|
+
const details = isRecord10(message.details) ? message.details : classification.fact;
|
|
25428
25581
|
return {
|
|
25429
25582
|
cause: "activation",
|
|
25430
25583
|
identity: { name: message.toolName, code: message.toolCallId },
|
|
@@ -25582,7 +25735,7 @@ function controlledFailureInputFromResolution(resolution) {
|
|
|
25582
25735
|
} : {}
|
|
25583
25736
|
};
|
|
25584
25737
|
}
|
|
25585
|
-
function
|
|
25738
|
+
function isRecord10(value) {
|
|
25586
25739
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25587
25740
|
}
|
|
25588
25741
|
function toolResultText(message) {
|
|
@@ -25607,7 +25760,7 @@ function extractCollectorTargetBindRejection(entries) {
|
|
|
25607
25760
|
const diagnostic = toolResultText(message);
|
|
25608
25761
|
if (diagnostic.length === 0) return void 0;
|
|
25609
25762
|
const details = message.details;
|
|
25610
|
-
const code =
|
|
25763
|
+
const code = isRecord10(details) && typeof details.code === "string" && details.code.trim() !== "" ? details.code : void 0;
|
|
25611
25764
|
return code === void 0 ? { diagnostic } : { diagnostic, code };
|
|
25612
25765
|
}
|
|
25613
25766
|
return void 0;
|
|
@@ -25677,7 +25830,7 @@ function boundRoleToolCallForResult(entries, resultIndex, message, outputToolNam
|
|
|
25677
25830
|
const candidateMessage = entries[index]?.message;
|
|
25678
25831
|
if (candidateMessage?.role === "assistant" && Array.isArray(candidateMessage.content)) {
|
|
25679
25832
|
for (const part of candidateMessage.content) {
|
|
25680
|
-
if (!
|
|
25833
|
+
if (!isRecord10(part) || part.type !== "toolCall" || part.id !== callId) {
|
|
25681
25834
|
continue;
|
|
25682
25835
|
}
|
|
25683
25836
|
if (part.name !== outputToolName) return void 0;
|
|
@@ -25714,7 +25867,7 @@ async function appendRunAttemptHistory(source, outcome) {
|
|
|
25714
25867
|
type: "custom",
|
|
25715
25868
|
customType: ATTEMPT_HISTORY_ENTRY_TYPE,
|
|
25716
25869
|
data: attemptData,
|
|
25717
|
-
id:
|
|
25870
|
+
id: randomUUID5(),
|
|
25718
25871
|
parentId,
|
|
25719
25872
|
timestamp: timestamp2
|
|
25720
25873
|
})}
|
|
@@ -25749,7 +25902,7 @@ function parseNavigatorAttendanceDetails(details) {
|
|
|
25749
25902
|
const advisoryDiagnostic = typeof details.routePlaybookReadFailure === "string" ? { advisoryDiagnostic: details.routePlaybookReadFailure } : {};
|
|
25750
25903
|
if (disposition === "recommendation") {
|
|
25751
25904
|
const next = details.next;
|
|
25752
|
-
if (!
|
|
25905
|
+
if (!isRecord10(next) || typeof next.role !== "string") {
|
|
25753
25906
|
return {
|
|
25754
25907
|
disposition: "unavailable",
|
|
25755
25908
|
source: "unknown",
|
|
@@ -25757,7 +25910,7 @@ function parseNavigatorAttendanceDetails(details) {
|
|
|
25757
25910
|
};
|
|
25758
25911
|
}
|
|
25759
25912
|
const reason = typeof details.reason === "string" ? details.reason : "";
|
|
25760
|
-
const route = Array.isArray(details.route) ? details.route.filter(
|
|
25913
|
+
const route = Array.isArray(details.route) ? details.route.filter(isRecord10).map((target) => ({
|
|
25761
25914
|
role: String(target.role),
|
|
25762
25915
|
phase: navigatorPhaseValue(target.phase)
|
|
25763
25916
|
})) : void 0;
|
|
@@ -25820,18 +25973,50 @@ function projectTerminalGateFact(rounds) {
|
|
|
25820
25973
|
};
|
|
25821
25974
|
}
|
|
25822
25975
|
async function extractGateFactFromSessionDirectory(sessionDirectory, options = {}) {
|
|
25823
|
-
const directories = [
|
|
25824
|
-
const parentSessionFile = options.parentSessionFile ??
|
|
25976
|
+
const directories = [join26(sessionDirectory, "auditor-roles")];
|
|
25977
|
+
const parentSessionFile = options.parentSessionFile ?? join26(sessionDirectory, "session.jsonl");
|
|
25825
25978
|
const rounds = await readAnalystGateCyclesFromAuditorRoles(directories, {
|
|
25826
25979
|
parentSessionFile
|
|
25827
25980
|
});
|
|
25828
25981
|
return projectTerminalGateFact(rounds);
|
|
25829
25982
|
}
|
|
25983
|
+
async function attachEngineDetourToolUsage(base, sessionDirectory, gateContext = {}) {
|
|
25984
|
+
const runDirectory = typeof gateContext.runDirectory === "string" && gateContext.runDirectory.length > 0 ? gateContext.runDirectory : runDirectoryFromSessionDirectory(sessionDirectory);
|
|
25985
|
+
const engineMounted = await readInvocationEngineMounted(runDirectory);
|
|
25986
|
+
if (!engineMounted) return base;
|
|
25987
|
+
const invocationScopeId = typeof gateContext.invocationScopeId === "string" && gateContext.invocationScopeId.length > 0 ? gateContext.invocationScopeId : void 0;
|
|
25988
|
+
const sessionFile = sessionFileFromSessionDirectory(sessionDirectory);
|
|
25989
|
+
const usage = await readEngineDetourToolUsage({
|
|
25990
|
+
sessionParent: sessionFile,
|
|
25991
|
+
engineMounted: true,
|
|
25992
|
+
...invocationScopeId === void 0 ? {} : { invocationScopeId },
|
|
25993
|
+
cwd: runDirectory
|
|
25994
|
+
});
|
|
25995
|
+
const projected = usage === void 0 ? void 0 : projectEngineDetourToolUsageForPublicTerminal(usage, {
|
|
25996
|
+
// Resumable Terminal: run ID only in resume.command — relative openable path.
|
|
25997
|
+
discloseRecordFile: base.resume === void 0
|
|
25998
|
+
});
|
|
25999
|
+
return {
|
|
26000
|
+
...base,
|
|
26001
|
+
roleOutcome: withEngineDetourToolUsageFact(base.roleOutcome, projected)
|
|
26002
|
+
};
|
|
26003
|
+
}
|
|
26004
|
+
function detourGateContext(admitted, scope) {
|
|
26005
|
+
return {
|
|
26006
|
+
runDirectory: admitted.runDirectory,
|
|
26007
|
+
...scope?.courtAttemptId === void 0 || scope.courtAttemptId.length === 0 ? {} : { courtAttemptId: scope.courtAttemptId },
|
|
26008
|
+
...scope?.invocationScopeId === void 0 || scope.invocationScopeId.length === 0 ? {} : { invocationScopeId: scope.invocationScopeId }
|
|
26009
|
+
};
|
|
26010
|
+
}
|
|
25830
26011
|
async function withOptionalGateProjection(base, sessionDirectory, gateContext = {}) {
|
|
25831
26012
|
const secondaryEvidence = base.roleOutcome.kind === "failure" ? base.roleOutcome.decisiveFacts.secondaryEvidence : void 0;
|
|
25832
|
-
|
|
25833
|
-
|
|
25834
|
-
|
|
26013
|
+
const skipGate = isRecord10(secondaryEvidence) && secondaryEvidence.kind === "role_infrastructure_failure" && (secondaryEvidence.stage === "gatekeeper" || secondaryEvidence.stage === "inspector" || secondaryEvidence.stage === "notary");
|
|
26014
|
+
let next = base;
|
|
26015
|
+
if (!skipGate) {
|
|
26016
|
+
const gate = await extractGateFactFromSessionDirectory(sessionDirectory, gateContext);
|
|
26017
|
+
if (gate !== void 0) next = { ...base, gate };
|
|
26018
|
+
}
|
|
26019
|
+
return attachEngineDetourToolUsage(next, sessionDirectory, gateContext);
|
|
25835
26020
|
}
|
|
25836
26021
|
function extractNavigatorFact(entries) {
|
|
25837
26022
|
const terminal = findLatestDurablePackagedRoleTerminal(entries);
|
|
@@ -25869,7 +26054,7 @@ function extractNavigatorFact(entries) {
|
|
|
25869
26054
|
const entry = entries[i];
|
|
25870
26055
|
if (entry?.type === "custom_message" && entry.customType === "ak-navigator-attendance") {
|
|
25871
26056
|
const details = entry.message?.details ?? entry.details;
|
|
25872
|
-
if (!
|
|
26057
|
+
if (!isRecord10(details)) {
|
|
25873
26058
|
return {
|
|
25874
26059
|
disposition: "unavailable",
|
|
25875
26060
|
source: "unknown",
|
|
@@ -25919,8 +26104,8 @@ async function extractNavigatorFactFromAdmittedSession(sessionFile) {
|
|
|
25919
26104
|
async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
|
|
25920
26105
|
await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
|
|
25921
26106
|
const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
|
|
25922
|
-
const reportPath =
|
|
25923
|
-
const evidencePath =
|
|
26107
|
+
const reportPath = join26(artifactsDir, "report.json");
|
|
26108
|
+
const evidencePath = join26(artifactsDir, "evidence.json");
|
|
25924
26109
|
await writeFile7(
|
|
25925
26110
|
reportPath,
|
|
25926
26111
|
`${JSON.stringify(
|
|
@@ -25964,8 +26149,8 @@ async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
|
|
|
25964
26149
|
async function publishCoderArtifacts(admitted, roleOutcome, coordinates, options = {}) {
|
|
25965
26150
|
await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
|
|
25966
26151
|
const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
|
|
25967
|
-
const reportPath =
|
|
25968
|
-
const evidencePath =
|
|
26152
|
+
const reportPath = join26(artifactsDir, "report.json");
|
|
26153
|
+
const evidencePath = join26(artifactsDir, "evidence.json");
|
|
25969
26154
|
await writeFile7(
|
|
25970
26155
|
reportPath,
|
|
25971
26156
|
`${JSON.stringify(
|
|
@@ -26040,7 +26225,8 @@ async function settleLawfulJudgeTerminalResult(admitted, authority, scope) {
|
|
|
26040
26225
|
artifacts,
|
|
26041
26226
|
runId: admitted.runId
|
|
26042
26227
|
},
|
|
26043
|
-
coordinates.sessionDirectory
|
|
26228
|
+
coordinates.sessionDirectory,
|
|
26229
|
+
detourGateContext(admitted, scope)
|
|
26044
26230
|
);
|
|
26045
26231
|
}
|
|
26046
26232
|
async function trySettleJudgeTerminalResult(admitted, authority, scope) {
|
|
@@ -26068,7 +26254,8 @@ async function settleLawfulCoderTerminalResult(admitted, authority, options = {}
|
|
|
26068
26254
|
artifacts,
|
|
26069
26255
|
runId: admitted.runId
|
|
26070
26256
|
},
|
|
26071
|
-
coordinates.sessionDirectory
|
|
26257
|
+
coordinates.sessionDirectory,
|
|
26258
|
+
detourGateContext(admitted, scope)
|
|
26072
26259
|
);
|
|
26073
26260
|
}
|
|
26074
26261
|
function sessionMessageText(message) {
|
|
@@ -26102,8 +26289,8 @@ function extractFixerMethodInvocations(entries, options) {
|
|
|
26102
26289
|
async function publishFixerArtifacts(admitted, roleOutcome, coordinates, options) {
|
|
26103
26290
|
await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
|
|
26104
26291
|
const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
|
|
26105
|
-
const reportPath =
|
|
26106
|
-
const evidencePath =
|
|
26292
|
+
const reportPath = join26(artifactsDir, "report.json");
|
|
26293
|
+
const evidencePath = join26(artifactsDir, "evidence.json");
|
|
26107
26294
|
await writeFile7(
|
|
26108
26295
|
reportPath,
|
|
26109
26296
|
`${JSON.stringify(
|
|
@@ -26184,14 +26371,15 @@ async function settleLawfulFixerTerminalResult(admitted, authority, options, sco
|
|
|
26184
26371
|
artifacts,
|
|
26185
26372
|
runId: admitted.runId
|
|
26186
26373
|
},
|
|
26187
|
-
sessionDirectory
|
|
26374
|
+
sessionDirectory,
|
|
26375
|
+
detourGateContext(admitted, scope)
|
|
26188
26376
|
);
|
|
26189
26377
|
}
|
|
26190
26378
|
async function publishCollectorArtifacts(admitted, roleOutcome, coordinates) {
|
|
26191
26379
|
await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
|
|
26192
26380
|
const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
|
|
26193
|
-
const reportPath =
|
|
26194
|
-
const evidencePath =
|
|
26381
|
+
const reportPath = join26(artifactsDir, "report.json");
|
|
26382
|
+
const evidencePath = join26(artifactsDir, "evidence.json");
|
|
26195
26383
|
await writeFile7(
|
|
26196
26384
|
reportPath,
|
|
26197
26385
|
`${JSON.stringify(
|
|
@@ -26249,12 +26437,17 @@ async function settleLawfulCollectorTerminalResult(admitted, authority, scope) {
|
|
|
26249
26437
|
const residual = boundErroredToolCandidate(entries, index, message, COLLECTOR_WAIT_TOOL);
|
|
26250
26438
|
if (residual === void 0) continue;
|
|
26251
26439
|
const candidate = residual.candidate;
|
|
26252
|
-
const details =
|
|
26253
|
-
const failed = await settleFailureTerminalResult(
|
|
26254
|
-
|
|
26255
|
-
|
|
26256
|
-
|
|
26257
|
-
|
|
26440
|
+
const details = isRecord10(candidate) ? candidate : { candidate };
|
|
26441
|
+
const failed = await settleFailureTerminalResult(
|
|
26442
|
+
admitted,
|
|
26443
|
+
{
|
|
26444
|
+
cause: "output",
|
|
26445
|
+
diagnostic: residual.diagnostic,
|
|
26446
|
+
details
|
|
26447
|
+
},
|
|
26448
|
+
authority,
|
|
26449
|
+
scope ?? {}
|
|
26450
|
+
);
|
|
26258
26451
|
return attachRecordedSubmissions(admitted, failed, scope);
|
|
26259
26452
|
}
|
|
26260
26453
|
return void 0;
|
|
@@ -26275,7 +26468,8 @@ async function settleLawfulCollectorTerminalResult(admitted, authority, scope) {
|
|
|
26275
26468
|
artifacts,
|
|
26276
26469
|
runId: admitted.runId
|
|
26277
26470
|
},
|
|
26278
|
-
sessionDirectory
|
|
26471
|
+
sessionDirectory,
|
|
26472
|
+
detourGateContext(admitted, scope)
|
|
26279
26473
|
),
|
|
26280
26474
|
scope
|
|
26281
26475
|
);
|
|
@@ -26289,7 +26483,7 @@ function extractDoctorCandidateCostFact(entries) {
|
|
|
26289
26483
|
const entry = entries[i];
|
|
26290
26484
|
if (entry?.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
|
|
26291
26485
|
const data = entry.data;
|
|
26292
|
-
return
|
|
26486
|
+
return isRecord10(data) ? data.cost : void 0;
|
|
26293
26487
|
}
|
|
26294
26488
|
}
|
|
26295
26489
|
return void 0;
|
|
@@ -26300,7 +26494,7 @@ function extractDoctorCandidateAuditNoReceiptFact(entries) {
|
|
|
26300
26494
|
const entry = entries[i];
|
|
26301
26495
|
if (entry?.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
|
|
26302
26496
|
const data = entry.data;
|
|
26303
|
-
return
|
|
26497
|
+
return isRecord10(data) ? data.auditNoReceipt : void 0;
|
|
26304
26498
|
}
|
|
26305
26499
|
}
|
|
26306
26500
|
return void 0;
|
|
@@ -26308,8 +26502,8 @@ function extractDoctorCandidateAuditNoReceiptFact(entries) {
|
|
|
26308
26502
|
async function publishDoctorArtifacts(admitted, roleOutcome, coordinates, options = {}) {
|
|
26309
26503
|
await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
|
|
26310
26504
|
const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
|
|
26311
|
-
const reportPath =
|
|
26312
|
-
const evidencePath =
|
|
26505
|
+
const reportPath = join26(artifactsDir, "report.json");
|
|
26506
|
+
const evidencePath = join26(artifactsDir, "evidence.json");
|
|
26313
26507
|
await writeFile7(
|
|
26314
26508
|
reportPath,
|
|
26315
26509
|
`${JSON.stringify(
|
|
@@ -26371,7 +26565,8 @@ async function settleLawfulDoctorTerminalResult(admitted, authority, scope) {
|
|
|
26371
26565
|
artifacts: artifacts2,
|
|
26372
26566
|
runId: admitted.runId
|
|
26373
26567
|
},
|
|
26374
|
-
sessionDirectory
|
|
26568
|
+
sessionDirectory,
|
|
26569
|
+
detourGateContext(admitted, scope)
|
|
26375
26570
|
);
|
|
26376
26571
|
}
|
|
26377
26572
|
const roleOutcome = sealed;
|
|
@@ -26394,7 +26589,8 @@ async function settleLawfulDoctorTerminalResult(admitted, authority, scope) {
|
|
|
26394
26589
|
artifacts,
|
|
26395
26590
|
runId: admitted.runId
|
|
26396
26591
|
},
|
|
26397
|
-
sessionDirectory
|
|
26592
|
+
sessionDirectory,
|
|
26593
|
+
detourGateContext(admitted, scope)
|
|
26398
26594
|
);
|
|
26399
26595
|
}
|
|
26400
26596
|
async function trySettleDoctorTerminalResult(admitted, authority, scope) {
|
|
@@ -26425,12 +26621,17 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
|
|
|
26425
26621
|
spec.toolName
|
|
26426
26622
|
);
|
|
26427
26623
|
if (residual !== void 0) {
|
|
26428
|
-
const details =
|
|
26429
|
-
const failed = await settleFailureTerminalResult(
|
|
26430
|
-
|
|
26431
|
-
|
|
26432
|
-
|
|
26433
|
-
|
|
26624
|
+
const details = isRecord10(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
|
|
26625
|
+
const failed = await settleFailureTerminalResult(
|
|
26626
|
+
admitted,
|
|
26627
|
+
{
|
|
26628
|
+
cause: "output",
|
|
26629
|
+
diagnostic: residual.diagnostic,
|
|
26630
|
+
details
|
|
26631
|
+
},
|
|
26632
|
+
authority,
|
|
26633
|
+
scope ?? {}
|
|
26634
|
+
);
|
|
26434
26635
|
return withSubmissions(failed, submissions);
|
|
26435
26636
|
}
|
|
26436
26637
|
}
|
|
@@ -26445,7 +26646,8 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
|
|
|
26445
26646
|
artifacts: [],
|
|
26446
26647
|
runId: admitted.runId
|
|
26447
26648
|
},
|
|
26448
|
-
sessionDirectory
|
|
26649
|
+
sessionDirectory,
|
|
26650
|
+
detourGateContext(admitted, scope)
|
|
26449
26651
|
),
|
|
26450
26652
|
submissions
|
|
26451
26653
|
);
|
|
@@ -26460,7 +26662,8 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
|
|
|
26460
26662
|
artifacts: [],
|
|
26461
26663
|
runId: admitted.runId
|
|
26462
26664
|
},
|
|
26463
|
-
sessionDirectory
|
|
26665
|
+
sessionDirectory,
|
|
26666
|
+
detourGateContext(admitted, scope)
|
|
26464
26667
|
),
|
|
26465
26668
|
submissions
|
|
26466
26669
|
);
|
|
@@ -26564,8 +26767,8 @@ function extractReviewerMethodInvocations(entries, options) {
|
|
|
26564
26767
|
async function publishReviewerArtifacts(admitted, roleOutcome, coordinates, options) {
|
|
26565
26768
|
await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
|
|
26566
26769
|
const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
|
|
26567
|
-
const reportPath =
|
|
26568
|
-
const evidencePath =
|
|
26770
|
+
const reportPath = join26(artifactsDir, "report.json");
|
|
26771
|
+
const evidencePath = join26(artifactsDir, "evidence.json");
|
|
26569
26772
|
await writeFile7(
|
|
26570
26773
|
reportPath,
|
|
26571
26774
|
`${JSON.stringify(
|
|
@@ -26644,7 +26847,8 @@ async function settleLawfulReviewerTerminalResult(admitted, authority, options,
|
|
|
26644
26847
|
artifacts,
|
|
26645
26848
|
runId: admitted.runId
|
|
26646
26849
|
},
|
|
26647
|
-
sessionDirectory
|
|
26850
|
+
sessionDirectory,
|
|
26851
|
+
detourGateContext(admitted, scope)
|
|
26648
26852
|
);
|
|
26649
26853
|
}
|
|
26650
26854
|
async function trySettleReviewerTerminalResult(admitted, authority, options, scope) {
|
|
@@ -26669,8 +26873,8 @@ function extractMergerMethodInvocations(entries, options) {
|
|
|
26669
26873
|
async function publishMergerArtifacts(admitted, roleOutcome, coordinates, options) {
|
|
26670
26874
|
await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
|
|
26671
26875
|
const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
|
|
26672
|
-
const reportPath =
|
|
26673
|
-
const evidencePath =
|
|
26876
|
+
const reportPath = join26(artifactsDir, "report.json");
|
|
26877
|
+
const evidencePath = join26(artifactsDir, "evidence.json");
|
|
26674
26878
|
await writeFile7(
|
|
26675
26879
|
reportPath,
|
|
26676
26880
|
`${JSON.stringify(
|
|
@@ -26729,12 +26933,17 @@ async function settleLawfulMergerTerminalResult(admitted, authority, options, sc
|
|
|
26729
26933
|
const residual = boundErroredToolCandidate(entries, index, message, MERGER_OUTPUT_TOOL_NAME);
|
|
26730
26934
|
if (residual === void 0) continue;
|
|
26731
26935
|
const candidate = residual.candidate;
|
|
26732
|
-
const details =
|
|
26733
|
-
const failed = await settleFailureTerminalResult(
|
|
26734
|
-
|
|
26735
|
-
|
|
26736
|
-
|
|
26737
|
-
|
|
26936
|
+
const details = isRecord10(candidate) ? candidate : { candidate };
|
|
26937
|
+
const failed = await settleFailureTerminalResult(
|
|
26938
|
+
admitted,
|
|
26939
|
+
{
|
|
26940
|
+
cause: "output",
|
|
26941
|
+
diagnostic: residual.diagnostic,
|
|
26942
|
+
details
|
|
26943
|
+
},
|
|
26944
|
+
authority,
|
|
26945
|
+
scope ?? {}
|
|
26946
|
+
);
|
|
26738
26947
|
return attachRecordedSubmissions(admitted, failed, scope);
|
|
26739
26948
|
}
|
|
26740
26949
|
return void 0;
|
|
@@ -26762,7 +26971,8 @@ async function settleLawfulMergerTerminalResult(admitted, authority, options, sc
|
|
|
26762
26971
|
artifacts,
|
|
26763
26972
|
runId: admitted.runId
|
|
26764
26973
|
},
|
|
26765
|
-
sessionDirectory
|
|
26974
|
+
sessionDirectory,
|
|
26975
|
+
detourGateContext(admitted, scope)
|
|
26766
26976
|
),
|
|
26767
26977
|
scope
|
|
26768
26978
|
);
|
|
@@ -26789,7 +26999,7 @@ function publicationAttemptFromError(path, error) {
|
|
|
26789
26999
|
}
|
|
26790
27000
|
function uniqueFailureFallbackDirs(runDirectory, baseDir) {
|
|
26791
27001
|
const dirs = [];
|
|
26792
|
-
for (const dir of [baseDir, runDirectory,
|
|
27002
|
+
for (const dir of [baseDir, runDirectory, dirname14(runDirectory)]) {
|
|
26793
27003
|
if (!dirs.includes(dir)) dirs.push(dir);
|
|
26794
27004
|
}
|
|
26795
27005
|
return dirs;
|
|
@@ -26811,7 +27021,7 @@ async function writeFailureJsonRetainingCause(preferredCandidates, uniqueFallbac
|
|
|
26811
27021
|
const candidates = [
|
|
26812
27022
|
...preferredCandidates,
|
|
26813
27023
|
// One unique name per fallback dir — collisions on fixed names cannot exhaust this.
|
|
26814
|
-
...uniqueFallbackDirs.map((dir) =>
|
|
27024
|
+
...uniqueFallbackDirs.map((dir) => join26(dir, `${stem}.${randomUUID5()}.json`))
|
|
26815
27025
|
];
|
|
26816
27026
|
for (let i = 0; i < candidates.length; i += 1) {
|
|
26817
27027
|
const path = candidates[i];
|
|
@@ -26862,20 +27072,20 @@ async function publishFailureArtifacts(admitted, failure, authority) {
|
|
|
26862
27072
|
baseDir
|
|
26863
27073
|
);
|
|
26864
27074
|
const errorCandidates = underArtifacts ? [
|
|
26865
|
-
|
|
26866
|
-
|
|
26867
|
-
|
|
27075
|
+
join26(baseDir, "error.json"),
|
|
27076
|
+
join26(baseDir, "error.settlement.json"),
|
|
27077
|
+
join26(admitted.runDirectory, "error.settlement.json")
|
|
26868
27078
|
] : [
|
|
26869
|
-
|
|
26870
|
-
|
|
27079
|
+
join26(baseDir, "error.settlement.json"),
|
|
27080
|
+
join26(baseDir, "error.json")
|
|
26871
27081
|
];
|
|
26872
27082
|
const evidenceCandidates = underArtifacts ? [
|
|
26873
|
-
|
|
26874
|
-
|
|
26875
|
-
|
|
27083
|
+
join26(baseDir, "evidence.json"),
|
|
27084
|
+
join26(baseDir, "evidence.settlement.json"),
|
|
27085
|
+
join26(admitted.runDirectory, "evidence.settlement.json")
|
|
26876
27086
|
] : [
|
|
26877
|
-
|
|
26878
|
-
|
|
27087
|
+
join26(baseDir, "evidence.settlement.json"),
|
|
27088
|
+
join26(baseDir, "evidence.json")
|
|
26879
27089
|
];
|
|
26880
27090
|
const errorPayloadBase = {
|
|
26881
27091
|
kind: "error",
|
|
@@ -26957,7 +27167,8 @@ async function settleFailureTerminalResult(admitted, failure, authority, options
|
|
|
26957
27167
|
artifacts: [],
|
|
26958
27168
|
runId: admitted.runId
|
|
26959
27169
|
},
|
|
26960
|
-
sessionDirectory
|
|
27170
|
+
sessionDirectory,
|
|
27171
|
+
detourGateContext(admitted, options)
|
|
26961
27172
|
);
|
|
26962
27173
|
}
|
|
26963
27174
|
} catch {
|
|
@@ -26995,7 +27206,8 @@ async function settleFailureTerminalResult(admitted, failure, authority, options
|
|
|
26995
27206
|
artifacts: [],
|
|
26996
27207
|
resume: options.resume
|
|
26997
27208
|
},
|
|
26998
|
-
sessionDirectory
|
|
27209
|
+
sessionDirectory,
|
|
27210
|
+
detourGateContext(admitted, options)
|
|
26999
27211
|
);
|
|
27000
27212
|
}
|
|
27001
27213
|
const roleOutcome = {
|
|
@@ -27012,7 +27224,8 @@ async function settleFailureTerminalResult(admitted, failure, authority, options
|
|
|
27012
27224
|
artifacts,
|
|
27013
27225
|
runId: admitted.runId
|
|
27014
27226
|
},
|
|
27015
|
-
sessionDirectory
|
|
27227
|
+
sessionDirectory,
|
|
27228
|
+
detourGateContext(admitted, options)
|
|
27016
27229
|
);
|
|
27017
27230
|
}
|
|
27018
27231
|
function presentFailureTerminal(terminal, io) {
|
|
@@ -27052,6 +27265,7 @@ var init_settlement = __esm({
|
|
|
27052
27265
|
init_compliance_transport();
|
|
27053
27266
|
init_collector_ledger();
|
|
27054
27267
|
init_engine_detour();
|
|
27268
|
+
init_engine_detour_usage();
|
|
27055
27269
|
init_judge_output();
|
|
27056
27270
|
init_collector_output();
|
|
27057
27271
|
init_worker_output();
|
|
@@ -27115,6 +27329,7 @@ function projectRoleTurnRequest(admitted, roleDetails, options) {
|
|
|
27115
27329
|
...options.correlationId === void 0 || options.correlationId.trim() === "" ? {} : { correlationId: options.correlationId },
|
|
27116
27330
|
...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs },
|
|
27117
27331
|
...options.courtAttemptId === void 0 || options.courtAttemptId.length === 0 ? {} : { courtAttemptId: options.courtAttemptId },
|
|
27332
|
+
...options.invocationScopeId === void 0 || options.invocationScopeId.length === 0 ? {} : { invocationScopeId: options.invocationScopeId },
|
|
27118
27333
|
...options.stationChild === void 0 ? {} : { stationChild: options.stationChild }
|
|
27119
27334
|
};
|
|
27120
27335
|
}
|
|
@@ -27127,9 +27342,9 @@ var init_turn_request = __esm({
|
|
|
27127
27342
|
|
|
27128
27343
|
// src/session-identity.ts
|
|
27129
27344
|
import { mkdir as mkdir3, readFile as readFile18, rename as rename3, writeFile as writeFile8 } from "node:fs/promises";
|
|
27130
|
-
import { dirname as
|
|
27345
|
+
import { dirname as dirname15, join as join27 } from "node:path";
|
|
27131
27346
|
function createSessionIdentityAuthority(authority, sessionBindingFile) {
|
|
27132
|
-
const bindingPath = (principal) =>
|
|
27347
|
+
const bindingPath = (principal) => join27(authority.decode(principal).sessionDirectory, sessionBindingFile);
|
|
27133
27348
|
return {
|
|
27134
27349
|
resolveSessionFile(principal) {
|
|
27135
27350
|
return authority.decode(principal).sessionFile;
|
|
@@ -27148,7 +27363,7 @@ function createSessionIdentityAuthority(authority, sessionBindingFile) {
|
|
|
27148
27363
|
},
|
|
27149
27364
|
async bind(principal, sessionId) {
|
|
27150
27365
|
const target = bindingPath(principal);
|
|
27151
|
-
await mkdir3(
|
|
27366
|
+
await mkdir3(dirname15(target), { recursive: true });
|
|
27152
27367
|
const temporary = `${target}.${process.pid}.tmp`;
|
|
27153
27368
|
await writeFile8(temporary, `${JSON.stringify({ sessionId })}
|
|
27154
27369
|
`, { encoding: "utf8", mode: 384 });
|
|
@@ -27218,7 +27433,7 @@ var init_ticket_provenance = __esm({
|
|
|
27218
27433
|
// src/public-cli/case-dossier-delivery.ts
|
|
27219
27434
|
import { mkdtemp, readFile as readFile19, rm as rm2, writeFile as writeFile9 } from "node:fs/promises";
|
|
27220
27435
|
import { tmpdir } from "node:os";
|
|
27221
|
-
import { join as
|
|
27436
|
+
import { join as join28 } from "node:path";
|
|
27222
27437
|
function describeDossierFile(path) {
|
|
27223
27438
|
return path;
|
|
27224
27439
|
}
|
|
@@ -27243,9 +27458,9 @@ async function deliverCaseDossierAsAttachment(input) {
|
|
|
27243
27458
|
home: input.home
|
|
27244
27459
|
});
|
|
27245
27460
|
if (section === void 0) return void 0;
|
|
27246
|
-
const stagingDir = await mkdtemp(
|
|
27461
|
+
const stagingDir = await mkdtemp(join28(tmpdir(), "ak-case-dossier-"));
|
|
27247
27462
|
try {
|
|
27248
|
-
const stagingPath =
|
|
27463
|
+
const stagingPath = join28(stagingDir, CASE_DOSSIER_ATTACH_FILE);
|
|
27249
27464
|
await writeFile9(stagingPath, `${section}
|
|
27250
27465
|
`, "utf8");
|
|
27251
27466
|
return await freezeAttachmentsIntoRun(
|
|
@@ -27271,7 +27486,7 @@ var init_case_dossier_delivery = __esm({
|
|
|
27271
27486
|
|
|
27272
27487
|
// src/host-transition-prior-native.ts
|
|
27273
27488
|
import { access as access3, readdir as readdir8 } from "node:fs/promises";
|
|
27274
|
-
import { dirname as
|
|
27489
|
+
import { dirname as dirname16, join as join29 } from "node:path";
|
|
27275
27490
|
function isEnoent3(error) {
|
|
27276
27491
|
return typeof error === "object" && error !== null && error.code === "ENOENT";
|
|
27277
27492
|
}
|
|
@@ -27285,7 +27500,7 @@ async function listPiNativeRecordPaths(sessionFile) {
|
|
|
27285
27500
|
}
|
|
27286
27501
|
}
|
|
27287
27502
|
async function listSitianRecordPaths(sessionParent) {
|
|
27288
|
-
const sessionRoot =
|
|
27503
|
+
const sessionRoot = dirname16(sessionParent);
|
|
27289
27504
|
let entries;
|
|
27290
27505
|
try {
|
|
27291
27506
|
entries = await readdir8(sessionRoot, { withFileTypes: true });
|
|
@@ -27296,7 +27511,7 @@ async function listSitianRecordPaths(sessionParent) {
|
|
|
27296
27511
|
const recordPaths = [];
|
|
27297
27512
|
for (const entry of entries) {
|
|
27298
27513
|
if (!entry.isDirectory()) continue;
|
|
27299
|
-
const recordFile =
|
|
27514
|
+
const recordFile = join29(sessionRoot, entry.name, "records.jsonl");
|
|
27300
27515
|
try {
|
|
27301
27516
|
await access3(recordFile);
|
|
27302
27517
|
recordPaths.push(recordFile);
|
|
@@ -27364,9 +27579,9 @@ var init_public_run_credentials = __esm({
|
|
|
27364
27579
|
|
|
27365
27580
|
// src/public-cli/auto-resume.ts
|
|
27366
27581
|
import { constants as fsConstants2 } from "node:fs";
|
|
27367
|
-
import { randomUUID as
|
|
27582
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
27368
27583
|
import { lstat as lstat6, mkdir as mkdir4, open as open2 } from "node:fs/promises";
|
|
27369
|
-
import { join as
|
|
27584
|
+
import { join as join30 } from "node:path";
|
|
27370
27585
|
async function persistReturnedRunState(admitted, authority, options) {
|
|
27371
27586
|
if (options?.lawful === true) {
|
|
27372
27587
|
await markRunTerminal(admitted.runDirectory);
|
|
@@ -27481,7 +27696,7 @@ function jsonSafeReplacer() {
|
|
|
27481
27696
|
};
|
|
27482
27697
|
}
|
|
27483
27698
|
async function writeHardenedArtifactFile(artifactsDir, namePrefix, payload) {
|
|
27484
|
-
const filePath =
|
|
27699
|
+
const filePath = join30(artifactsDir, `${namePrefix}-${randomUUID6()}.json`);
|
|
27485
27700
|
const body = `${JSON.stringify(payload, jsonSafeReplacer(), 2)}
|
|
27486
27701
|
`;
|
|
27487
27702
|
const noFollowFlag = typeof fsConstants2.O_NOFOLLOW === "number" ? fsConstants2.O_NOFOLLOW : 0;
|
|
@@ -27752,9 +27967,9 @@ var init_auto_resume = __esm({
|
|
|
27752
27967
|
});
|
|
27753
27968
|
|
|
27754
27969
|
// src/public-cli/post-admission.ts
|
|
27755
|
-
import { randomUUID as
|
|
27756
|
-
import {
|
|
27757
|
-
import { isAbsolute as isAbsolute8, join as
|
|
27970
|
+
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
27971
|
+
import { writeFile as writeFile10 } from "node:fs/promises";
|
|
27972
|
+
import { isAbsolute as isAbsolute8, join as join31, resolve as resolve8 } from "node:path";
|
|
27758
27973
|
function describeCaughtError(error) {
|
|
27759
27974
|
if (error instanceof Error) {
|
|
27760
27975
|
const code = error.code;
|
|
@@ -27799,7 +28014,7 @@ async function recordBestEffortPostDispatchDiagnostic(admitted, env, diagnostic,
|
|
|
27799
28014
|
try {
|
|
27800
28015
|
const artifactsDir = await ensureRealArtifactsDirectory(admitted.runDirectory);
|
|
27801
28016
|
await writeFile10(
|
|
27802
|
-
|
|
28017
|
+
join31(artifactsDir, `post-admission-diagnostic-${randomUUID7()}.json`),
|
|
27803
28018
|
`${JSON.stringify({ version: 1, ...payload }, null, 2)}
|
|
27804
28019
|
`,
|
|
27805
28020
|
{ encoding: "utf8", flag: "wx" }
|
|
@@ -27813,15 +28028,6 @@ async function recordBestEffortPostDispatchDiagnostic(admitted, env, diagnostic,
|
|
|
27813
28028
|
}
|
|
27814
28029
|
}
|
|
27815
28030
|
}
|
|
27816
|
-
async function readInvocationHost(runDirectory) {
|
|
27817
|
-
try {
|
|
27818
|
-
const raw = JSON.parse(await readFile20(join30(runDirectory, "invocation.json"), "utf8"));
|
|
27819
|
-
return typeof raw.host === "string" && raw.host.trim() !== "" ? raw.host : void 0;
|
|
27820
|
-
} catch (error) {
|
|
27821
|
-
if (error.code === "ENOENT") return void 0;
|
|
27822
|
-
throw error;
|
|
27823
|
-
}
|
|
27824
|
-
}
|
|
27825
28031
|
async function resolveResumeMethodMaterialAdapters(input) {
|
|
27826
28032
|
if (input.shouldLoad === false) {
|
|
27827
28033
|
return { kind: "continue", adapters: input.emptyAdapters };
|
|
@@ -27885,7 +28091,10 @@ async function presentControlledFailure2(admitted, failureInput, adapters, autho
|
|
|
27885
28091
|
admitted,
|
|
27886
28092
|
failure,
|
|
27887
28093
|
authority,
|
|
27888
|
-
|
|
28094
|
+
{
|
|
28095
|
+
...resumable ? { resume: { command: renderResumeCommand(admitted.runId) } } : {},
|
|
28096
|
+
...failureInput.invocationScopeId === void 0 || failureInput.invocationScopeId.length === 0 ? {} : { invocationScopeId: failureInput.invocationScopeId }
|
|
28097
|
+
}
|
|
27889
28098
|
)
|
|
27890
28099
|
);
|
|
27891
28100
|
presentFailureTerminal(terminal, io);
|
|
@@ -27954,12 +28163,12 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
27954
28163
|
return {
|
|
27955
28164
|
...await presentControlledFailure2(
|
|
27956
28165
|
admitted,
|
|
27957
|
-
{
|
|
28166
|
+
withEngineDetourInvocationScope({
|
|
27958
28167
|
timedOut: false,
|
|
27959
28168
|
code: null,
|
|
27960
28169
|
stderr: "",
|
|
27961
28170
|
thrown: error
|
|
27962
|
-
},
|
|
28171
|
+
}, request.invocationScopeId),
|
|
27963
28172
|
adapters,
|
|
27964
28173
|
env.principalAuthority,
|
|
27965
28174
|
io,
|
|
@@ -27980,7 +28189,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
27980
28189
|
return {
|
|
27981
28190
|
...await presentControlledFailure2(
|
|
27982
28191
|
admitted,
|
|
27983
|
-
missingCredential,
|
|
28192
|
+
withEngineDetourInvocationScope(missingCredential, request.invocationScopeId),
|
|
27984
28193
|
adapters,
|
|
27985
28194
|
env.principalAuthority,
|
|
27986
28195
|
io,
|
|
@@ -27994,7 +28203,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
27994
28203
|
const principalCoordinates = admitted.principal === void 0 ? void 0 : env.principalAuthority.decode(admitted.principal);
|
|
27995
28204
|
let hostTransition;
|
|
27996
28205
|
try {
|
|
27997
|
-
previousHost =
|
|
28206
|
+
previousHost = readInvocationSelectedHost(admitted.runDirectory);
|
|
27998
28207
|
hostTransition = previousHost !== void 0 && liveHost !== void 0 && principalCoordinates !== void 0 ? await projectHostTransitionPriorNative({
|
|
27999
28208
|
previousHost,
|
|
28000
28209
|
liveHost,
|
|
@@ -28004,12 +28213,12 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
28004
28213
|
return {
|
|
28005
28214
|
...await presentControlledFailure2(
|
|
28006
28215
|
admitted,
|
|
28007
|
-
{
|
|
28216
|
+
withEngineDetourInvocationScope({
|
|
28008
28217
|
timedOut: false,
|
|
28009
28218
|
code: null,
|
|
28010
28219
|
stderr: "",
|
|
28011
28220
|
thrown: error
|
|
28012
|
-
},
|
|
28221
|
+
}, request.invocationScopeId),
|
|
28013
28222
|
adapters,
|
|
28014
28223
|
env.principalAuthority,
|
|
28015
28224
|
io,
|
|
@@ -28026,12 +28235,12 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
28026
28235
|
} catch (error) {
|
|
28027
28236
|
const settled2 = await presentControlledFailure2(
|
|
28028
28237
|
admitted,
|
|
28029
|
-
{
|
|
28238
|
+
withEngineDetourInvocationScope({
|
|
28030
28239
|
timedOut: false,
|
|
28031
28240
|
code: null,
|
|
28032
28241
|
stderr: "",
|
|
28033
28242
|
thrown: error
|
|
28034
|
-
},
|
|
28243
|
+
}, request.invocationScopeId),
|
|
28035
28244
|
adapters,
|
|
28036
28245
|
env.principalAuthority,
|
|
28037
28246
|
io,
|
|
@@ -28050,6 +28259,9 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
28050
28259
|
if (hostTransition !== void 0) {
|
|
28051
28260
|
turnRequest = { ...turnRequest, hostTransition };
|
|
28052
28261
|
}
|
|
28262
|
+
if (typeof liveHost === "string" && liveHost.trim() !== "") {
|
|
28263
|
+
turnRequest = { ...turnRequest, host: liveHost.trim() };
|
|
28264
|
+
}
|
|
28053
28265
|
if (isStationChildOfficerDialogue(admitted.role, env)) {
|
|
28054
28266
|
await deliverCaseDossierAsAttachment({
|
|
28055
28267
|
ticketNumber: admitted.ticketNumber,
|
|
@@ -28086,12 +28298,12 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
28086
28298
|
} catch (error) {
|
|
28087
28299
|
const settled2 = await settleAfterTurnStarted(
|
|
28088
28300
|
admitted,
|
|
28089
|
-
{
|
|
28301
|
+
withEngineDetourInvocationScope({
|
|
28090
28302
|
timedOut: false,
|
|
28091
28303
|
code: null,
|
|
28092
28304
|
stderr: "",
|
|
28093
28305
|
thrown: error
|
|
28094
|
-
},
|
|
28306
|
+
}, request.invocationScopeId),
|
|
28095
28307
|
adapters,
|
|
28096
28308
|
env.principalAuthority,
|
|
28097
28309
|
io,
|
|
@@ -28102,7 +28314,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
28102
28314
|
let stderrLogWriteFailure;
|
|
28103
28315
|
try {
|
|
28104
28316
|
await writeFile10(
|
|
28105
|
-
|
|
28317
|
+
join31(admitted.runDirectory, "stderr.log"),
|
|
28106
28318
|
result2.stderr,
|
|
28107
28319
|
"utf8"
|
|
28108
28320
|
);
|
|
@@ -28115,7 +28327,10 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
28115
28327
|
io
|
|
28116
28328
|
);
|
|
28117
28329
|
}
|
|
28118
|
-
const courtScope = request.courtAttemptId === void 0 || request.courtAttemptId.length === 0 ? void 0 : {
|
|
28330
|
+
const courtScope = (request.courtAttemptId === void 0 || request.courtAttemptId.length === 0) && (request.invocationScopeId === void 0 || request.invocationScopeId.length === 0) ? void 0 : {
|
|
28331
|
+
...request.courtAttemptId === void 0 || request.courtAttemptId.length === 0 ? {} : { courtAttemptId: request.courtAttemptId },
|
|
28332
|
+
...request.invocationScopeId === void 0 || request.invocationScopeId.length === 0 ? {} : { invocationScopeId: request.invocationScopeId }
|
|
28333
|
+
};
|
|
28119
28334
|
let settled;
|
|
28120
28335
|
let settledOutcome;
|
|
28121
28336
|
let hostSignalFailed = false;
|
|
@@ -28165,12 +28380,12 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
28165
28380
|
} catch (error) {
|
|
28166
28381
|
const settledFailure = await settleAfterTurnStarted(
|
|
28167
28382
|
admitted,
|
|
28168
|
-
{
|
|
28383
|
+
withEngineDetourInvocationScope({
|
|
28169
28384
|
timedOut: false,
|
|
28170
28385
|
code: result2.code,
|
|
28171
28386
|
stderr: result2.stderr,
|
|
28172
28387
|
thrown: error
|
|
28173
|
-
},
|
|
28388
|
+
}, request.invocationScopeId),
|
|
28174
28389
|
adapters,
|
|
28175
28390
|
env.principalAuthority,
|
|
28176
28391
|
io,
|
|
@@ -28185,13 +28400,13 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
28185
28400
|
} catch (error) {
|
|
28186
28401
|
const failed = await settleAfterTurnStarted(
|
|
28187
28402
|
admitted,
|
|
28188
|
-
{
|
|
28403
|
+
withEngineDetourInvocationScope({
|
|
28189
28404
|
timedOut: false,
|
|
28190
28405
|
code: null,
|
|
28191
28406
|
stderr: "",
|
|
28192
28407
|
thrown: error,
|
|
28193
28408
|
skipRunStateWrite: true
|
|
28194
|
-
},
|
|
28409
|
+
}, request.invocationScopeId),
|
|
28195
28410
|
adapters,
|
|
28196
28411
|
env.principalAuthority,
|
|
28197
28412
|
io,
|
|
@@ -28207,7 +28422,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
28207
28422
|
const stderrLogWriteDetails = stderrLogWriteFailure === void 0 ? void 0 : { stderrLogWriteFailure: describeCaughtError(stderrLogWriteFailure) };
|
|
28208
28423
|
const failed = await settleAfterTurnStarted(
|
|
28209
28424
|
admitted,
|
|
28210
|
-
{
|
|
28425
|
+
withEngineDetourInvocationScope({
|
|
28211
28426
|
timedOut: result2.timedOut,
|
|
28212
28427
|
code: result2.code,
|
|
28213
28428
|
stderr: result2.stderr,
|
|
@@ -28221,7 +28436,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
28221
28436
|
details: { ...resolutionInput.knownFailure.details ?? {}, ...stderrLogWriteDetails }
|
|
28222
28437
|
}
|
|
28223
28438
|
} : { knownDetails: stderrLogWriteDetails }
|
|
28224
|
-
},
|
|
28439
|
+
}, request.invocationScopeId),
|
|
28225
28440
|
adapters,
|
|
28226
28441
|
env.principalAuthority,
|
|
28227
28442
|
io,
|
|
@@ -28232,12 +28447,12 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
28232
28447
|
if (stderrLogWriteFailure !== void 0) {
|
|
28233
28448
|
const failed = await settleAfterTurnStarted(
|
|
28234
28449
|
admitted,
|
|
28235
|
-
{
|
|
28450
|
+
withEngineDetourInvocationScope({
|
|
28236
28451
|
timedOut: false,
|
|
28237
28452
|
code: result2.code,
|
|
28238
28453
|
stderr: result2.stderr,
|
|
28239
28454
|
thrown: stderrLogWriteFailure
|
|
28240
|
-
},
|
|
28455
|
+
}, request.invocationScopeId),
|
|
28241
28456
|
adapters,
|
|
28242
28457
|
env.principalAuthority,
|
|
28243
28458
|
io,
|
|
@@ -28247,7 +28462,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
28247
28462
|
}
|
|
28248
28463
|
const noReceipt = await attachRecordedSubmissions(
|
|
28249
28464
|
admitted,
|
|
28250
|
-
await settleHostEndedNoReceipt(admitted, env.principalAuthority),
|
|
28465
|
+
await settleHostEndedNoReceipt(admitted, env.principalAuthority, courtScope),
|
|
28251
28466
|
courtScope
|
|
28252
28467
|
);
|
|
28253
28468
|
if (persistRunState) {
|
|
@@ -28256,13 +28471,13 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
28256
28471
|
} catch (error) {
|
|
28257
28472
|
const failed = await settleAfterTurnStarted(
|
|
28258
28473
|
admitted,
|
|
28259
|
-
{
|
|
28474
|
+
withEngineDetourInvocationScope({
|
|
28260
28475
|
timedOut: false,
|
|
28261
28476
|
code: null,
|
|
28262
28477
|
stderr: "",
|
|
28263
28478
|
thrown: error,
|
|
28264
28479
|
skipRunStateWrite: true
|
|
28265
|
-
},
|
|
28480
|
+
}, request.invocationScopeId),
|
|
28266
28481
|
adapters,
|
|
28267
28482
|
env.principalAuthority,
|
|
28268
28483
|
io,
|
|
@@ -28331,7 +28546,7 @@ function resumeTurnRequestProjectionOptions(admitted, request, env, summonsPrepa
|
|
|
28331
28546
|
kind: "resume",
|
|
28332
28547
|
prompt
|
|
28333
28548
|
},
|
|
28334
|
-
...request.message === void 0 ? {} : { courtAttemptId:
|
|
28549
|
+
...request.message === void 0 ? {} : { courtAttemptId: randomUUID7() },
|
|
28335
28550
|
...env.stationChild === void 0 ? {} : { stationChild: env.stationChild }
|
|
28336
28551
|
};
|
|
28337
28552
|
}
|
|
@@ -28349,7 +28564,7 @@ async function dispatchAfterWriterLease(input) {
|
|
|
28349
28564
|
}
|
|
28350
28565
|
function isAlreadyFrozenSummonsAttachment(runDirectory, attachmentPath) {
|
|
28351
28566
|
const absolute = isAbsolute8(attachmentPath) ? attachmentPath : resolve8(attachmentPath);
|
|
28352
|
-
return pathContainedIn(
|
|
28567
|
+
return pathContainedIn(join31(runDirectory, "attachments"), absolute);
|
|
28353
28568
|
}
|
|
28354
28569
|
async function prepareSummonsResumeMaterials(runDirectory, summons) {
|
|
28355
28570
|
if (summons === void 0) return void 0;
|
|
@@ -28428,7 +28643,7 @@ async function runPostAdmissionSeatResume(input) {
|
|
|
28428
28643
|
}
|
|
28429
28644
|
let turnRequest = await input.buildTurnRequest(admittedForBuild, request);
|
|
28430
28645
|
if (openCourtAttemptId !== void 0 || request.summons !== void 0 || request.message !== void 0) {
|
|
28431
|
-
const courtAttemptId = openCourtAttemptId ?? (turnRequest.courtAttemptId !== void 0 && turnRequest.courtAttemptId.length > 0 ? turnRequest.courtAttemptId :
|
|
28646
|
+
const courtAttemptId = openCourtAttemptId ?? (turnRequest.courtAttemptId !== void 0 && turnRequest.courtAttemptId.length > 0 ? turnRequest.courtAttemptId : randomUUID7());
|
|
28432
28647
|
turnRequest = { ...turnRequest, courtAttemptId };
|
|
28433
28648
|
if (openCourtAttemptId === void 0) {
|
|
28434
28649
|
const court = {
|
|
@@ -28444,6 +28659,9 @@ async function runPostAdmissionSeatResume(input) {
|
|
|
28444
28659
|
if (input.env.stationChild === true) {
|
|
28445
28660
|
let firstTurn;
|
|
28446
28661
|
const stationAdapters = withOnceSuccessfulBeforeDispatch(adapters);
|
|
28662
|
+
const invocationScopeId = mintEngineDetourInvocationScope({
|
|
28663
|
+
...input.effectiveEngine === void 0 ? {} : { effectiveEngine: input.effectiveEngine }
|
|
28664
|
+
});
|
|
28447
28665
|
return await runWithAutoResumeLoop({
|
|
28448
28666
|
admitted: loaded.admitted,
|
|
28449
28667
|
principalAuthority: input.env.principalAuthority,
|
|
@@ -28470,7 +28688,10 @@ async function runPostAdmissionSeatResume(input) {
|
|
|
28470
28688
|
}
|
|
28471
28689
|
};
|
|
28472
28690
|
}
|
|
28473
|
-
const turnRequest =
|
|
28691
|
+
const turnRequest = withEngineDetourInvocationScope(
|
|
28692
|
+
await buildRequestAfterLease(),
|
|
28693
|
+
invocationScopeId
|
|
28694
|
+
);
|
|
28474
28695
|
firstTurn = turnRequest;
|
|
28475
28696
|
return turnRequest;
|
|
28476
28697
|
},
|
|
@@ -28541,6 +28762,11 @@ async function runPostAdmissionOneShot(input) {
|
|
|
28541
28762
|
async function runPostAdmissionResumable(input) {
|
|
28542
28763
|
const { admitted, env, io, buildInitialRequest, buildResumeRequest, effectiveEngine } = input;
|
|
28543
28764
|
const adapters = withOnceSuccessfulBeforeDispatch(input.adapters);
|
|
28765
|
+
const invocationScopeId = mintEngineDetourInvocationScope({
|
|
28766
|
+
...effectiveEngine === void 0 ? {} : { effectiveEngine }
|
|
28767
|
+
});
|
|
28768
|
+
const buildScopedInitial = () => withEngineDetourInvocationScope(buildInitialRequest(), invocationScopeId);
|
|
28769
|
+
const buildScopedResume = () => withEngineDetourInvocationScope(buildResumeRequest(), invocationScopeId);
|
|
28544
28770
|
return runWithAutoResumeLoop({
|
|
28545
28771
|
admitted,
|
|
28546
28772
|
principalAuthority: env.principalAuthority,
|
|
@@ -28548,8 +28774,8 @@ async function runPostAdmissionResumable(input) {
|
|
|
28548
28774
|
io,
|
|
28549
28775
|
sessionAppender: env.sessionAppender,
|
|
28550
28776
|
autoResumeLimit: env.autoResumeLimit,
|
|
28551
|
-
buildInitialPayload:
|
|
28552
|
-
buildResumePayload:
|
|
28777
|
+
buildInitialPayload: buildScopedInitial,
|
|
28778
|
+
buildResumePayload: buildScopedResume,
|
|
28553
28779
|
dispatch: async (request, lease, _isFirst, attemptIo) => {
|
|
28554
28780
|
const result2 = await dispatchPostAdmissionTurn({
|
|
28555
28781
|
admitted,
|
|
@@ -28597,6 +28823,9 @@ async function runPostAdmissionManualResume(input) {
|
|
|
28597
28823
|
}
|
|
28598
28824
|
throw error;
|
|
28599
28825
|
}
|
|
28826
|
+
const invocationScopeId = mintEngineDetourInvocationScope({
|
|
28827
|
+
...effectiveEngine === void 0 ? {} : { effectiveEngine }
|
|
28828
|
+
});
|
|
28600
28829
|
const result2 = await dispatchAfterWriterLease({
|
|
28601
28830
|
lease,
|
|
28602
28831
|
build: async () => {
|
|
@@ -28608,6 +28837,7 @@ async function runPostAdmissionManualResume(input) {
|
|
|
28608
28837
|
}
|
|
28609
28838
|
request = await buildRequestAfterLease();
|
|
28610
28839
|
}
|
|
28840
|
+
request = withEngineDetourInvocationScope(request, invocationScopeId);
|
|
28611
28841
|
return request;
|
|
28612
28842
|
},
|
|
28613
28843
|
dispatch: (turnRequest) => dispatchPostAdmissionTurn({
|
|
@@ -28647,6 +28877,7 @@ var init_post_admission = __esm({
|
|
|
28647
28877
|
init_session_identity();
|
|
28648
28878
|
init_host_contracts();
|
|
28649
28879
|
init_case_dossier_delivery();
|
|
28880
|
+
init_engine_detour_usage();
|
|
28650
28881
|
init_host_transition_prior_native();
|
|
28651
28882
|
init_public_run_credentials();
|
|
28652
28883
|
init_run_lifecycle();
|
|
@@ -29969,7 +30200,7 @@ __export(public_role_summons_exports, {
|
|
|
29969
30200
|
summonPublicRole: () => summonPublicRole
|
|
29970
30201
|
});
|
|
29971
30202
|
import { existsSync as existsSync10 } from "node:fs";
|
|
29972
|
-
import { join as
|
|
30203
|
+
import { join as join32 } from "node:path";
|
|
29973
30204
|
function createCapturingIo() {
|
|
29974
30205
|
const chunks = [];
|
|
29975
30206
|
return {
|
|
@@ -29992,7 +30223,7 @@ function parentDir(path) {
|
|
|
29992
30223
|
function walkPackageRoot(start) {
|
|
29993
30224
|
let dir = start;
|
|
29994
30225
|
for (let i = 0; i < 12; i += 1) {
|
|
29995
|
-
if (existsSync10(
|
|
30226
|
+
if (existsSync10(join32(dir, "package.json")) && existsSync10(join32(dir, "souls"))) {
|
|
29996
30227
|
return dir;
|
|
29997
30228
|
}
|
|
29998
30229
|
const parent = parentDir(dir);
|
|
@@ -30086,7 +30317,7 @@ async function createSummonEnv(options) {
|
|
|
30086
30317
|
async function summonPublicRole(options) {
|
|
30087
30318
|
const packageRoot2 = resolveSummonsPackageRoot(options.packageRoot);
|
|
30088
30319
|
const home = await resolveSummonHome(options);
|
|
30089
|
-
const agentDir = options.agentDir ?? process.env.PI_CODING_AGENT_DIR ??
|
|
30320
|
+
const agentDir = options.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? join32(home, ".pi", "agent");
|
|
30090
30321
|
const {
|
|
30091
30322
|
loadCredentialProviders: loadCredentialProviders2,
|
|
30092
30323
|
loadPublicCliConfig: loadPublicCliConfig2,
|
|
@@ -31325,8 +31556,8 @@ var init_analyst_book_key = __esm({
|
|
|
31325
31556
|
});
|
|
31326
31557
|
|
|
31327
31558
|
// src/analyst-index.ts
|
|
31328
|
-
import { open as open3, readFile as
|
|
31329
|
-
import { dirname as
|
|
31559
|
+
import { open as open3, readFile as readFile20, unlink as unlink4 } from "node:fs/promises";
|
|
31560
|
+
import { dirname as dirname17, join as join33 } from "node:path";
|
|
31330
31561
|
function sleep(ms) {
|
|
31331
31562
|
return new Promise((resolve10) => {
|
|
31332
31563
|
setTimeout(resolve10, ms);
|
|
@@ -31334,8 +31565,8 @@ function sleep(ms) {
|
|
|
31334
31565
|
}
|
|
31335
31566
|
async function withAnalystLibraryIndexLock(ledgerHome, fn) {
|
|
31336
31567
|
const indexPath = analystLibraryIndexPath(ledgerHome);
|
|
31337
|
-
ensureRealDirectoryTree(ledgerHome,
|
|
31338
|
-
const lockPath =
|
|
31568
|
+
ensureRealDirectoryTree(ledgerHome, dirname17(indexPath));
|
|
31569
|
+
const lockPath = join33(dirname17(indexPath), LIBRARY_INDEX_LOCK_NAME);
|
|
31339
31570
|
assertLedgerFileInsideHome(lockPath, ledgerHome);
|
|
31340
31571
|
const startedAt = Date.now();
|
|
31341
31572
|
while (true) {
|
|
@@ -31362,7 +31593,7 @@ async function withAnalystLibraryIndexLock(ledgerHome, fn) {
|
|
|
31362
31593
|
}
|
|
31363
31594
|
}
|
|
31364
31595
|
function analystLibraryIndexPath(ledgerHome) {
|
|
31365
|
-
return
|
|
31596
|
+
return join33(ledgerHome, "analyst", "library-index.json");
|
|
31366
31597
|
}
|
|
31367
31598
|
function rowFromIssueMetricsPage(page) {
|
|
31368
31599
|
return {
|
|
@@ -31453,7 +31684,7 @@ async function readAnalystLibraryIndexPage(ledgerHome) {
|
|
|
31453
31684
|
const path = analystLibraryIndexPath(ledgerHome);
|
|
31454
31685
|
let raw;
|
|
31455
31686
|
try {
|
|
31456
|
-
raw = await
|
|
31687
|
+
raw = await readFile20(path, "utf8");
|
|
31457
31688
|
} catch (error) {
|
|
31458
31689
|
if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
|
|
31459
31690
|
return void 0;
|
|
@@ -31471,7 +31702,7 @@ async function readAnalystLibraryIndexPage(ledgerHome) {
|
|
|
31471
31702
|
}
|
|
31472
31703
|
async function writeAnalystLibraryIndexPage(ledgerHome, page) {
|
|
31473
31704
|
const path = analystLibraryIndexPath(ledgerHome);
|
|
31474
|
-
ensureRealDirectoryTree(ledgerHome,
|
|
31705
|
+
ensureRealDirectoryTree(ledgerHome, dirname17(path));
|
|
31475
31706
|
assertLedgerFileInsideHome(path, ledgerHome);
|
|
31476
31707
|
await writeFileAtomically(path, `${JSON.stringify(page, null, 2)}
|
|
31477
31708
|
`);
|
|
@@ -31657,23 +31888,23 @@ var init_analyst_cohort = __esm({
|
|
|
31657
31888
|
});
|
|
31658
31889
|
|
|
31659
31890
|
// src/analyst-ledger.ts
|
|
31660
|
-
import { readdir as readdir9, readFile as
|
|
31661
|
-
import { basename as basename8, join as
|
|
31891
|
+
import { readdir as readdir9, readFile as readFile21 } from "node:fs/promises";
|
|
31892
|
+
import { basename as basename8, join as join34 } from "node:path";
|
|
31662
31893
|
function isMissingPathError6(error) {
|
|
31663
31894
|
return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
|
|
31664
31895
|
}
|
|
31665
31896
|
function errorText3(error) {
|
|
31666
31897
|
return error instanceof Error ? error.message : String(error);
|
|
31667
31898
|
}
|
|
31668
|
-
function
|
|
31899
|
+
function isRecord11(value) {
|
|
31669
31900
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31670
31901
|
}
|
|
31671
31902
|
async function readExistingRunLifecycleState(runDirectory) {
|
|
31672
31903
|
try {
|
|
31673
31904
|
const raw = JSON.parse(
|
|
31674
|
-
await
|
|
31905
|
+
await readFile21(join34(runDirectory, "run-state.json"), "utf8")
|
|
31675
31906
|
);
|
|
31676
|
-
if (!
|
|
31907
|
+
if (!isRecord11(raw) || typeof raw.state !== "string") return void 0;
|
|
31677
31908
|
return raw.state;
|
|
31678
31909
|
} catch {
|
|
31679
31910
|
return void 0;
|
|
@@ -31703,13 +31934,13 @@ async function listLedgerBookNames(booksRoot) {
|
|
|
31703
31934
|
async function readInvocationScopeFields(runDirectory) {
|
|
31704
31935
|
let raw;
|
|
31705
31936
|
try {
|
|
31706
|
-
raw = await
|
|
31937
|
+
raw = await readFile21(join34(runDirectory, "invocation.json"), "utf8");
|
|
31707
31938
|
} catch (error) {
|
|
31708
31939
|
if (isMissingPathError6(error)) return void 0;
|
|
31709
31940
|
throw error;
|
|
31710
31941
|
}
|
|
31711
31942
|
const parsed = JSON.parse(raw);
|
|
31712
|
-
if (!
|
|
31943
|
+
if (!isRecord11(parsed)) return void 0;
|
|
31713
31944
|
if (typeof parsed.projectRoot !== "string" || parsed.projectRoot.trim() === "") {
|
|
31714
31945
|
return void 0;
|
|
31715
31946
|
}
|
|
@@ -31736,15 +31967,15 @@ function decideIssueScope(input) {
|
|
|
31736
31967
|
}
|
|
31737
31968
|
async function resolveSessionFile(runDirectory) {
|
|
31738
31969
|
try {
|
|
31739
|
-
const raw = await
|
|
31970
|
+
const raw = await readFile21(join34(runDirectory, "invocation.json"), "utf8");
|
|
31740
31971
|
const parsed = JSON.parse(raw);
|
|
31741
|
-
if (
|
|
31972
|
+
if (isRecord11(parsed) && typeof parsed.sessionFile === "string" && parsed.sessionFile.trim() !== "") {
|
|
31742
31973
|
return parsed.sessionFile;
|
|
31743
31974
|
}
|
|
31744
31975
|
} catch (error) {
|
|
31745
31976
|
if (!isMissingPathError6(error)) throw error;
|
|
31746
31977
|
}
|
|
31747
|
-
return
|
|
31978
|
+
return join34(runDirectory, "session", "session.jsonl");
|
|
31748
31979
|
}
|
|
31749
31980
|
function attributeSessionRowsForRun(input) {
|
|
31750
31981
|
if (pathContainedIn(input.runDirectory, input.sessionFile)) {
|
|
@@ -31916,9 +32147,9 @@ async function classifyScopedRun(input) {
|
|
|
31916
32147
|
}
|
|
31917
32148
|
let gateCycles;
|
|
31918
32149
|
try {
|
|
31919
|
-
const parentSessionFile =
|
|
32150
|
+
const parentSessionFile = join34(input.runDirectory, "session", "session.jsonl");
|
|
31920
32151
|
gateCycles = await readAnalystGateCyclesFromAuditorRoles(
|
|
31921
|
-
|
|
32152
|
+
join34(input.runDirectory, "session", "auditor-roles"),
|
|
31922
32153
|
{ parentSessionFile }
|
|
31923
32154
|
);
|
|
31924
32155
|
} catch (error) {
|
|
@@ -31951,7 +32182,7 @@ async function classifyScopedRun(input) {
|
|
|
31951
32182
|
async function scanAnalystIssueRuns(input) {
|
|
31952
32183
|
const ledgerHome = resolveActivationLedgerHome(input.home);
|
|
31953
32184
|
const scopeTicketNumber = input.ticketNumber;
|
|
31954
|
-
const booksRoot =
|
|
32185
|
+
const booksRoot = join34(ledgerHome, "books");
|
|
31955
32186
|
let wholeBook = false;
|
|
31956
32187
|
let scopeRootIdentity;
|
|
31957
32188
|
let bookNames;
|
|
@@ -31983,7 +32214,7 @@ async function scanAnalystIssueRuns(input) {
|
|
|
31983
32214
|
const unreadable = [];
|
|
31984
32215
|
const scopeConflicts = [];
|
|
31985
32216
|
for (const book of bookNames) {
|
|
31986
|
-
const bookDir =
|
|
32217
|
+
const bookDir = join34(booksRoot, book);
|
|
31987
32218
|
let runDirectories;
|
|
31988
32219
|
try {
|
|
31989
32220
|
runDirectories = await listBookRunDirectories(bookDir);
|
|
@@ -32044,7 +32275,7 @@ var init_analyst_ledger = __esm({
|
|
|
32044
32275
|
});
|
|
32045
32276
|
|
|
32046
32277
|
// src/analyst-metric-families/acceptance-success-rework.ts
|
|
32047
|
-
function
|
|
32278
|
+
function isRecord12(value) {
|
|
32048
32279
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
32049
32280
|
}
|
|
32050
32281
|
function wallMsFromSpan(span) {
|
|
@@ -32053,21 +32284,21 @@ function wallMsFromSpan(span) {
|
|
|
32053
32284
|
function findCollectorGroups(body) {
|
|
32054
32285
|
if (Array.isArray(body.groups)) return body.groups;
|
|
32055
32286
|
const receipt = body.receipt;
|
|
32056
|
-
if (
|
|
32287
|
+
if (isRecord12(receipt) && Array.isArray(receipt.groups)) return receipt.groups;
|
|
32057
32288
|
const outcome = body.outcome;
|
|
32058
|
-
if (
|
|
32289
|
+
if (isRecord12(outcome)) {
|
|
32059
32290
|
const facts = outcome.decisiveFacts;
|
|
32060
|
-
if (
|
|
32291
|
+
if (isRecord12(facts) && Array.isArray(facts.groups)) return facts.groups;
|
|
32061
32292
|
}
|
|
32062
32293
|
return void 0;
|
|
32063
32294
|
}
|
|
32064
32295
|
function extractStatus(body) {
|
|
32065
32296
|
const outcome = body.outcome;
|
|
32066
|
-
if (
|
|
32297
|
+
if (isRecord12(outcome) && typeof outcome.status === "string" && outcome.status.trim() !== "") {
|
|
32067
32298
|
return outcome.status;
|
|
32068
32299
|
}
|
|
32069
32300
|
const receipt = body.receipt;
|
|
32070
|
-
if (
|
|
32301
|
+
if (isRecord12(receipt) && typeof receipt.status === "string" && receipt.status.trim() !== "") {
|
|
32071
32302
|
return receipt.status;
|
|
32072
32303
|
}
|
|
32073
32304
|
if (typeof body.status === "string" && body.status.trim() !== "") {
|
|
@@ -32692,21 +32923,21 @@ var init_leg_wall_clock = __esm({
|
|
|
32692
32923
|
});
|
|
32693
32924
|
|
|
32694
32925
|
// src/analyst-metric-families/round-timeline.ts
|
|
32695
|
-
function
|
|
32926
|
+
function isRecord13(value) {
|
|
32696
32927
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
32697
32928
|
}
|
|
32698
32929
|
function wallMsFromSpan2(startedAt, endedAt) {
|
|
32699
32930
|
return Date.parse(endedAt) - Date.parse(startedAt);
|
|
32700
32931
|
}
|
|
32701
32932
|
function readOutcomeStatus(body) {
|
|
32702
|
-
if (!
|
|
32933
|
+
if (!isRecord13(body.outcome)) return void 0;
|
|
32703
32934
|
const status = body.outcome.status;
|
|
32704
32935
|
if (typeof status !== "string" || status.trim() === "") return void 0;
|
|
32705
32936
|
return status;
|
|
32706
32937
|
}
|
|
32707
32938
|
function readClassCount(body) {
|
|
32708
|
-
if (!
|
|
32709
|
-
if (!
|
|
32939
|
+
if (!isRecord13(body.outcome)) return void 0;
|
|
32940
|
+
if (!isRecord13(body.outcome.decisiveFacts)) return void 0;
|
|
32710
32941
|
const classCount = body.outcome.decisiveFacts.classCount;
|
|
32711
32942
|
if (typeof classCount !== "number" || !Number.isFinite(classCount)) {
|
|
32712
32943
|
return void 0;
|
|
@@ -32850,7 +33081,7 @@ var init_analyst_metric_family = __esm({
|
|
|
32850
33081
|
|
|
32851
33082
|
// src/analyst-page.ts
|
|
32852
33083
|
import { createHash as createHash5 } from "node:crypto";
|
|
32853
|
-
import { dirname as
|
|
33084
|
+
import { dirname as dirname18, join as join35 } from "node:path";
|
|
32854
33085
|
function analystIssuePageKey(address) {
|
|
32855
33086
|
const parts = ["book", address.bookKey];
|
|
32856
33087
|
if (address.issueNumber !== void 0) {
|
|
@@ -32861,7 +33092,7 @@ function analystIssuePageKey(address) {
|
|
|
32861
33092
|
return createHash5("sha256").update(parts.join("\0")).digest("hex").slice(0, 32);
|
|
32862
33093
|
}
|
|
32863
33094
|
function analystIssuePagePath(ledgerHome, address) {
|
|
32864
|
-
return
|
|
33095
|
+
return join35(ledgerHome, "analyst", "issues", `${analystIssuePageKey(address)}.json`);
|
|
32865
33096
|
}
|
|
32866
33097
|
function analystIssuePageAddressFromPage(page) {
|
|
32867
33098
|
return {
|
|
@@ -32980,7 +33211,7 @@ async function buildAnalystIssueMetricsPage(input) {
|
|
|
32980
33211
|
}
|
|
32981
33212
|
async function writeAnalystIssueMetricsPage(ledgerHome, page) {
|
|
32982
33213
|
const path = analystIssuePagePath(ledgerHome, analystIssuePageAddressFromPage(page));
|
|
32983
|
-
ensureRealDirectoryTree(ledgerHome,
|
|
33214
|
+
ensureRealDirectoryTree(ledgerHome, dirname18(path));
|
|
32984
33215
|
assertLedgerFileInsideHome(path, ledgerHome);
|
|
32985
33216
|
await writeFileAtomically(path, `${JSON.stringify(page, null, 2)}
|
|
32986
33217
|
`);
|
|
@@ -32997,7 +33228,7 @@ var init_analyst_page = __esm({
|
|
|
32997
33228
|
});
|
|
32998
33229
|
|
|
32999
33230
|
// src/analyst-entry.ts
|
|
33000
|
-
import { readFile as
|
|
33231
|
+
import { readFile as readFile22 } from "node:fs/promises";
|
|
33001
33232
|
function isMissingPathError7(error) {
|
|
33002
33233
|
return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
|
|
33003
33234
|
}
|
|
@@ -33027,7 +33258,7 @@ async function readOrComputeAnalystIssuePage(input, options) {
|
|
|
33027
33258
|
...issueNumber === void 0 && input.bookKey === void 0 ? { scopeRootIdentity: projectRoot } : {}
|
|
33028
33259
|
});
|
|
33029
33260
|
try {
|
|
33030
|
-
const raw = await
|
|
33261
|
+
const raw = await readFile22(pagePath, "utf8");
|
|
33031
33262
|
const page = JSON.parse(raw);
|
|
33032
33263
|
if (cachedPageMatchesRequestedScope(page, { bookKey, ...input })) {
|
|
33033
33264
|
return { mode: "issue", page, pagePath };
|
|
@@ -33122,7 +33353,7 @@ async function runAnalystModelGroupsMode(input, home) {
|
|
|
33122
33353
|
scopeRootIdentity: projectRoot
|
|
33123
33354
|
});
|
|
33124
33355
|
try {
|
|
33125
|
-
const raw = await
|
|
33356
|
+
const raw = await readFile22(pagePath, "utf8");
|
|
33126
33357
|
JSON.parse(raw);
|
|
33127
33358
|
} catch (error) {
|
|
33128
33359
|
if (!isMissingPathError7(error)) {
|
|
@@ -33221,7 +33452,7 @@ var init_analyst_entry = __esm({
|
|
|
33221
33452
|
});
|
|
33222
33453
|
|
|
33223
33454
|
// src/public-cli/analyst-run.ts
|
|
33224
|
-
import { readFile as
|
|
33455
|
+
import { readFile as readFile23 } from "node:fs/promises";
|
|
33225
33456
|
import { isAbsolute as isAbsolute10, resolve as resolve9 } from "node:path";
|
|
33226
33457
|
function resolveAnalystIssueBookKeyFromCwd(cwd = process.cwd()) {
|
|
33227
33458
|
try {
|
|
@@ -33274,7 +33505,7 @@ async function buildAnalystSweepModeInputFromAttachmentPaths(attachmentPaths) {
|
|
|
33274
33505
|
const absolute = isAbsolute10(sourcePath) ? sourcePath : resolve9(sourcePath);
|
|
33275
33506
|
let bytes;
|
|
33276
33507
|
try {
|
|
33277
|
-
bytes = await
|
|
33508
|
+
bytes = await readFile23(absolute);
|
|
33278
33509
|
} catch (error) {
|
|
33279
33510
|
throw new CliUsageError(
|
|
33280
33511
|
`analyst sweep attachment is not a readable regular file: ${sourcePath}`,
|
|
@@ -33394,7 +33625,7 @@ __export(cli_exports, {
|
|
|
33394
33625
|
runAkRole: () => runAkRole
|
|
33395
33626
|
});
|
|
33396
33627
|
import { realpath as realpath6 } from "node:fs/promises";
|
|
33397
|
-
import { join as
|
|
33628
|
+
import { join as join36 } from "node:path";
|
|
33398
33629
|
function takePublicGlobalFlag(argv, index, options) {
|
|
33399
33630
|
const tokens = argv.slice(index);
|
|
33400
33631
|
const taken = options.takeDashed(tokens);
|
|
@@ -33491,7 +33722,7 @@ function resolveHome(env) {
|
|
|
33491
33722
|
return env.home ?? packageMachineHome();
|
|
33492
33723
|
}
|
|
33493
33724
|
function resolveAgentDir(env, home) {
|
|
33494
|
-
return env.agentDir ?? process.env.PI_CODING_AGENT_DIR ??
|
|
33725
|
+
return env.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? join36(home, ".pi", "agent");
|
|
33495
33726
|
}
|
|
33496
33727
|
function parseThinking(value) {
|
|
33497
33728
|
return value;
|
|
@@ -34506,7 +34737,7 @@ var init_cli = __esm({
|
|
|
34506
34737
|
|
|
34507
34738
|
// src/public-cli/main.ts
|
|
34508
34739
|
import { existsSync as existsSync11 } from "node:fs";
|
|
34509
|
-
import { dirname as
|
|
34740
|
+
import { dirname as dirname19, join as join37 } from "node:path";
|
|
34510
34741
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
34511
34742
|
|
|
34512
34743
|
// src/public-cli/host-pi-runtime.ts
|
|
@@ -34593,10 +34824,10 @@ function linkPackage(packageRoot2, name, targetDir) {
|
|
|
34593
34824
|
}
|
|
34594
34825
|
|
|
34595
34826
|
// src/public-cli/main.ts
|
|
34596
|
-
var here =
|
|
34827
|
+
var here = dirname19(fileURLToPath2(import.meta.url));
|
|
34597
34828
|
function resolvePackageRoot(binDir) {
|
|
34598
|
-
const canonical =
|
|
34599
|
-
if (existsSync11(
|
|
34829
|
+
const canonical = join37(binDir, "..", "..");
|
|
34830
|
+
if (existsSync11(join37(canonical, "package.json"))) {
|
|
34600
34831
|
return canonical;
|
|
34601
34832
|
}
|
|
34602
34833
|
return binDir;
|