@akagilnc/pi-workflow-roles 0.1.4204 → 0.1.4228
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acp-host/production-host.js +1203 -770
- package/dist/atomic-write.js +23 -0
- package/dist/diarist-contracts.js +22 -8
- package/dist/headless-host/production-host.js +1191 -758
- package/dist/ledger-session-read.js +52 -21
- package/dist/migrate-book-topology.js +238 -205
- package/dist/public-cli/case-dossier-delivery.js +0 -1
- package/dist/public-cli/main.js +303 -261
- package/dist/session-dialogue.js +221 -0
- package/dist/sitian-facade.js +1 -0
- package/dist/sitian-volume.js +67 -0
- package/dist/ticket-provenance-contracts.js +122 -39
- package/dist/ticket-provenance.js +289 -204
- package/package.json +1 -1
- package/src/book-topology-migration.ts +0 -7
- package/src/book-topology-record-class-migrators.ts +203 -99
- package/src/diarist-contracts.ts +42 -29
- package/src/diarist-role.ts +77 -31
- package/src/diarist.ts +31 -67
- package/src/ledger-session-read.ts +70 -27
- package/src/package-contracts/reviewer-output.ts +1 -1
- package/src/public-cli/case-dossier-delivery.ts +0 -1
- package/src/reviewer-role.ts +3 -3
- package/src/role-runtime.ts +56 -14
- package/src/session-dialogue.ts +225 -0
- package/src/sitian-appender.ts +1 -1
- package/src/sitian-facade.ts +7 -1
- package/src/sitian-volume.ts +91 -0
- package/src/ticket-provenance-contracts.ts +158 -101
- package/src/ticket-provenance.ts +387 -263
|
@@ -417,7 +417,7 @@ function normalizeReviewComment(raw) {
|
|
|
417
417
|
function createGhApiRunner(options = {}) {
|
|
418
418
|
const spawnImpl = options.spawnImpl ?? spawn;
|
|
419
419
|
return async (args, runOptions = {}) => {
|
|
420
|
-
return await new Promise((
|
|
420
|
+
return await new Promise((resolve21, reject) => {
|
|
421
421
|
const signal = runOptions.signal;
|
|
422
422
|
if (signal?.aborted) {
|
|
423
423
|
reject(signal.reason ?? new Error("aborted"));
|
|
@@ -490,11 +490,11 @@ function createGhApiRunner(options = {}) {
|
|
|
490
490
|
const value = line2.slice(idx + 1).trim();
|
|
491
491
|
headers[name] = value;
|
|
492
492
|
}
|
|
493
|
-
|
|
493
|
+
resolve21({ status, headers, bodyText });
|
|
494
494
|
return;
|
|
495
495
|
}
|
|
496
496
|
if (code === 0) {
|
|
497
|
-
|
|
497
|
+
resolve21({ status: 200, headers: {}, bodyText: stdout });
|
|
498
498
|
return;
|
|
499
499
|
}
|
|
500
500
|
const failure2 = new Error(
|
|
@@ -1700,7 +1700,7 @@ async function spawnEngineDetourOnce(input) {
|
|
|
1700
1700
|
}
|
|
1701
1701
|
const command = input.argv[0];
|
|
1702
1702
|
const args = input.argv.slice(1);
|
|
1703
|
-
return await new Promise((
|
|
1703
|
+
return await new Promise((resolve21, reject) => {
|
|
1704
1704
|
let settled = false;
|
|
1705
1705
|
const signal = input.signal;
|
|
1706
1706
|
const child = spawn2(command, args, {
|
|
@@ -1730,7 +1730,7 @@ async function spawnEngineDetourOnce(input) {
|
|
|
1730
1730
|
if (signal !== void 0) {
|
|
1731
1731
|
signal.removeEventListener("abort", onAbort);
|
|
1732
1732
|
}
|
|
1733
|
-
|
|
1733
|
+
resolve21(result);
|
|
1734
1734
|
};
|
|
1735
1735
|
const onAbort = () => {
|
|
1736
1736
|
fail4(signal !== void 0 ? abortReasonError(signal) : new Error("aborted"));
|
|
@@ -2354,6 +2354,114 @@ var init_auditor_output = __esm({
|
|
|
2354
2354
|
}
|
|
2355
2355
|
});
|
|
2356
2356
|
|
|
2357
|
+
// src/ticket-provenance-contracts.ts
|
|
2358
|
+
function isRecord2(value) {
|
|
2359
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2360
|
+
}
|
|
2361
|
+
function positiveInteger(value) {
|
|
2362
|
+
if (typeof value === "number" && Number.isSafeInteger(value) && value >= 1) return value;
|
|
2363
|
+
if (typeof value === "string" && /^[1-9][0-9]*$/.test(value)) {
|
|
2364
|
+
const parsed = Number(value);
|
|
2365
|
+
if (Number.isSafeInteger(parsed)) return parsed;
|
|
2366
|
+
}
|
|
2367
|
+
return void 0;
|
|
2368
|
+
}
|
|
2369
|
+
function nonNegativeInteger(value) {
|
|
2370
|
+
if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0) return value;
|
|
2371
|
+
if (typeof value === "string" && /^(0|[1-9][0-9]*)$/.test(value)) {
|
|
2372
|
+
const parsed = Number(value);
|
|
2373
|
+
if (Number.isSafeInteger(parsed)) return parsed;
|
|
2374
|
+
}
|
|
2375
|
+
return void 0;
|
|
2376
|
+
}
|
|
2377
|
+
function projectSpeaker(value) {
|
|
2378
|
+
return value === "owner" || value === "runner" ? value : void 0;
|
|
2379
|
+
}
|
|
2380
|
+
function projectBound(value) {
|
|
2381
|
+
if (!isRecord2(value)) return void 0;
|
|
2382
|
+
const id = typeof value.id === "string" && value.id !== "" ? value.id : void 0;
|
|
2383
|
+
const line2 = positiveInteger(value.line);
|
|
2384
|
+
if (id === void 0 && line2 === void 0) return void 0;
|
|
2385
|
+
return { ...id === void 0 ? {} : { id }, ...line2 === void 0 ? {} : { line: line2 } };
|
|
2386
|
+
}
|
|
2387
|
+
function projectTicketProvenanceSessions(value) {
|
|
2388
|
+
if (!Array.isArray(value)) return void 0;
|
|
2389
|
+
if (value.length === 0) return [];
|
|
2390
|
+
const sessions = [];
|
|
2391
|
+
for (const raw of value) {
|
|
2392
|
+
if (!isRecord2(raw)) return void 0;
|
|
2393
|
+
const path = raw.path;
|
|
2394
|
+
if (typeof path !== "string" || path.trim() === "") return void 0;
|
|
2395
|
+
if (!Array.isArray(raw.ranges) || raw.ranges.length === 0) return void 0;
|
|
2396
|
+
const ranges = [];
|
|
2397
|
+
for (const rawRange of raw.ranges) {
|
|
2398
|
+
if (!isRecord2(rawRange)) return void 0;
|
|
2399
|
+
const from = projectBound(rawRange.from);
|
|
2400
|
+
const to = projectBound(rawRange.to);
|
|
2401
|
+
if (from === void 0 || to === void 0) return void 0;
|
|
2402
|
+
ranges.push({ from, to });
|
|
2403
|
+
}
|
|
2404
|
+
sessions.push({ path, ranges });
|
|
2405
|
+
}
|
|
2406
|
+
return sessions;
|
|
2407
|
+
}
|
|
2408
|
+
function projectTicketProvenanceAmendments(value) {
|
|
2409
|
+
if (!Array.isArray(value)) return [];
|
|
2410
|
+
const out = [];
|
|
2411
|
+
for (const raw of value) {
|
|
2412
|
+
if (!isRecord2(raw)) continue;
|
|
2413
|
+
const s = nonNegativeInteger(raw.s);
|
|
2414
|
+
const line2 = positiveInteger(raw.line);
|
|
2415
|
+
const speaker = projectSpeaker(raw.speaker);
|
|
2416
|
+
const text = raw.text;
|
|
2417
|
+
if (s === void 0 || line2 === void 0 || speaker === void 0) continue;
|
|
2418
|
+
if (typeof text !== "string") continue;
|
|
2419
|
+
out.push({ s, line: line2, speaker, text });
|
|
2420
|
+
}
|
|
2421
|
+
return out;
|
|
2422
|
+
}
|
|
2423
|
+
function projectTicketProvenanceHeader(value) {
|
|
2424
|
+
if (!isRecord2(value)) return void 0;
|
|
2425
|
+
const ticket = positiveInteger(value.ticket);
|
|
2426
|
+
if (ticket === void 0) return void 0;
|
|
2427
|
+
if (typeof value.repo !== "string") return void 0;
|
|
2428
|
+
if (typeof value.createdAt !== "string" || typeof value.updatedAt !== "string") {
|
|
2429
|
+
return void 0;
|
|
2430
|
+
}
|
|
2431
|
+
const sessions = projectTicketProvenanceSessions(value.sessions);
|
|
2432
|
+
if (sessions === void 0) return void 0;
|
|
2433
|
+
return {
|
|
2434
|
+
repo: value.repo,
|
|
2435
|
+
ticket,
|
|
2436
|
+
createdAt: value.createdAt,
|
|
2437
|
+
updatedAt: value.updatedAt,
|
|
2438
|
+
sessions
|
|
2439
|
+
};
|
|
2440
|
+
}
|
|
2441
|
+
function projectTicketProvenanceLine(value) {
|
|
2442
|
+
if (!isRecord2(value)) return void 0;
|
|
2443
|
+
const speaker = projectSpeaker(value.speaker);
|
|
2444
|
+
const s = nonNegativeInteger(value.s);
|
|
2445
|
+
if (speaker === void 0 || s === void 0) return void 0;
|
|
2446
|
+
if (typeof value.text !== "string") return void 0;
|
|
2447
|
+
const line2 = positiveInteger(value.line);
|
|
2448
|
+
const id = typeof value.id === "string" && value.id !== "" ? value.id : void 0;
|
|
2449
|
+
return {
|
|
2450
|
+
speaker,
|
|
2451
|
+
s,
|
|
2452
|
+
...line2 === void 0 ? {} : { line: line2 },
|
|
2453
|
+
...id === void 0 ? {} : { id },
|
|
2454
|
+
text: value.text
|
|
2455
|
+
};
|
|
2456
|
+
}
|
|
2457
|
+
var TICKET_PROVENANCE_KIND;
|
|
2458
|
+
var init_ticket_provenance_contracts = __esm({
|
|
2459
|
+
"src/ticket-provenance-contracts.ts"() {
|
|
2460
|
+
"use strict";
|
|
2461
|
+
TICKET_PROVENANCE_KIND = "ticket-provenance";
|
|
2462
|
+
}
|
|
2463
|
+
});
|
|
2464
|
+
|
|
2357
2465
|
// src/diarist-contracts.ts
|
|
2358
2466
|
function projectCourtTicketNumbers(raw, options) {
|
|
2359
2467
|
if (!Array.isArray(raw)) return null;
|
|
@@ -2428,14 +2536,21 @@ function sameCourtTicketNumbers(left, right) {
|
|
|
2428
2536
|
}
|
|
2429
2537
|
return true;
|
|
2430
2538
|
}
|
|
2431
|
-
function
|
|
2432
|
-
const
|
|
2433
|
-
|
|
2539
|
+
function projectDiaristSessions(value) {
|
|
2540
|
+
const raw = value?.sessions;
|
|
2541
|
+
if (raw === void 0) return [];
|
|
2542
|
+
return projectTicketProvenanceSessions(raw);
|
|
2543
|
+
}
|
|
2544
|
+
function projectDiaristAmendments(value) {
|
|
2545
|
+
const raw = value?.amendments;
|
|
2546
|
+
if (raw === void 0) return [];
|
|
2547
|
+
return projectTicketProvenanceAmendments(raw);
|
|
2434
2548
|
}
|
|
2435
2549
|
var DIARIST_OUTPUT_TOOL_NAME, DIARIST_ACCEPTED_TEXT;
|
|
2436
2550
|
var init_diarist_contracts = __esm({
|
|
2437
2551
|
"src/diarist-contracts.ts"() {
|
|
2438
2552
|
"use strict";
|
|
2553
|
+
init_ticket_provenance_contracts();
|
|
2439
2554
|
init_run_ticket_number();
|
|
2440
2555
|
DIARIST_OUTPUT_TOOL_NAME = "ak_diarist_output";
|
|
2441
2556
|
DIARIST_ACCEPTED_TEXT = "\u8D77\u5C45\u90CE\u56DE\u6267\u5DF2\u63A5\u53D7";
|
|
@@ -2766,7 +2881,7 @@ import {
|
|
|
2766
2881
|
writeFileSync
|
|
2767
2882
|
} from "node:fs";
|
|
2768
2883
|
import { dirname as dirname5, join as join8 } from "node:path";
|
|
2769
|
-
function
|
|
2884
|
+
function isRecord3(value) {
|
|
2770
2885
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2771
2886
|
}
|
|
2772
2887
|
function errorCodeOf(error) {
|
|
@@ -2794,7 +2909,7 @@ function findIdentityPointer(recordFile, identity, kind, level) {
|
|
|
2794
2909
|
if (!trimmed) continue;
|
|
2795
2910
|
try {
|
|
2796
2911
|
const parsed = JSON.parse(trimmed);
|
|
2797
|
-
if (
|
|
2912
|
+
if (isRecord3(parsed) && parsed.identity === identity) {
|
|
2798
2913
|
return { identity, recordFile, kind, level };
|
|
2799
2914
|
}
|
|
2800
2915
|
} catch {
|
|
@@ -2967,7 +3082,7 @@ var init_sitian_appender = __esm({
|
|
|
2967
3082
|
// src/sitian-reader.ts
|
|
2968
3083
|
import { existsSync as existsSync3 } from "node:fs";
|
|
2969
3084
|
import { readFile as readFile4 } from "node:fs/promises";
|
|
2970
|
-
function
|
|
3085
|
+
function isRecord4(value) {
|
|
2971
3086
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2972
3087
|
}
|
|
2973
3088
|
async function readSitianRecords(recordFile) {
|
|
@@ -2983,7 +3098,7 @@ async function readSitianRecords(recordFile) {
|
|
|
2983
3098
|
if (!line2.trim()) continue;
|
|
2984
3099
|
try {
|
|
2985
3100
|
const parsed = JSON.parse(line2);
|
|
2986
|
-
if (
|
|
3101
|
+
if (isRecord4(parsed)) {
|
|
2987
3102
|
records.push(parsed);
|
|
2988
3103
|
} else {
|
|
2989
3104
|
const typeDesc = parsed === null ? "null" : Array.isArray(parsed) ? "array" : typeof parsed;
|
|
@@ -3011,6 +3126,85 @@ var init_sitian_reader = __esm({
|
|
|
3011
3126
|
}
|
|
3012
3127
|
});
|
|
3013
3128
|
|
|
3129
|
+
// src/atomic-write.ts
|
|
3130
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
3131
|
+
import { rename, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
3132
|
+
import { dirname as dirname6, join as join9 } from "node:path";
|
|
3133
|
+
async function writeFileAtomically(destination, contents) {
|
|
3134
|
+
const parent = dirname6(destination);
|
|
3135
|
+
const temporary = join9(parent, `.atomic-write-${randomUUID2()}.tmp`);
|
|
3136
|
+
try {
|
|
3137
|
+
await writeFile2(temporary, contents);
|
|
3138
|
+
await rename(temporary, destination);
|
|
3139
|
+
} catch (error) {
|
|
3140
|
+
await rm2(temporary, { force: true }).catch(() => void 0);
|
|
3141
|
+
throw error;
|
|
3142
|
+
}
|
|
3143
|
+
}
|
|
3144
|
+
var init_atomic_write = __esm({
|
|
3145
|
+
"src/atomic-write.ts"() {
|
|
3146
|
+
"use strict";
|
|
3147
|
+
}
|
|
3148
|
+
});
|
|
3149
|
+
|
|
3150
|
+
// src/sitian-volume.ts
|
|
3151
|
+
import { appendFileSync as appendFileSync2 } from "node:fs";
|
|
3152
|
+
import { readFile as readFile5 } from "node:fs/promises";
|
|
3153
|
+
function resolveSitianVolume(input) {
|
|
3154
|
+
const path = resolveSitianRecordPath(input);
|
|
3155
|
+
return { recordFile: path.recordFile, volumeDir: path.sessionDir };
|
|
3156
|
+
}
|
|
3157
|
+
function ensureSitianVolume(input) {
|
|
3158
|
+
try {
|
|
3159
|
+
const { sessionDir, recordFile, ledgerHome } = resolveSitianRecordPath(input);
|
|
3160
|
+
ensureRealDirectoryTree(ledgerHome, sessionDir);
|
|
3161
|
+
appendFileSync2(recordFile, "", "utf8");
|
|
3162
|
+
return { recordFile, volumeDir: sessionDir };
|
|
3163
|
+
} catch (error) {
|
|
3164
|
+
if (error instanceof SitianInfrastructureError) throw error;
|
|
3165
|
+
throw new SitianInfrastructureError(
|
|
3166
|
+
`Sitian volume ensure failure: ${errorText(error)}`,
|
|
3167
|
+
{ cause: error }
|
|
3168
|
+
);
|
|
3169
|
+
}
|
|
3170
|
+
}
|
|
3171
|
+
async function readSitianVolumeText(input) {
|
|
3172
|
+
const { recordFile } = resolveSitianVolume(input);
|
|
3173
|
+
try {
|
|
3174
|
+
return { recordFile, text: await readFile5(recordFile, "utf8") };
|
|
3175
|
+
} catch (error) {
|
|
3176
|
+
if (error.code === "ENOENT") {
|
|
3177
|
+
return { recordFile, text: void 0 };
|
|
3178
|
+
}
|
|
3179
|
+
throw new SitianInfrastructureError(
|
|
3180
|
+
`Sitian volume read failure: ${errorText(error)}`,
|
|
3181
|
+
{ cause: error }
|
|
3182
|
+
);
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
3185
|
+
async function rewriteSitianVolume(input) {
|
|
3186
|
+
try {
|
|
3187
|
+
const volume = ensureSitianVolume(input);
|
|
3188
|
+
await writeFileAtomically(volume.recordFile, input.body);
|
|
3189
|
+
return volume;
|
|
3190
|
+
} catch (error) {
|
|
3191
|
+
if (error instanceof SitianInfrastructureError) throw error;
|
|
3192
|
+
throw new SitianInfrastructureError(
|
|
3193
|
+
`Sitian volume rewrite failure: ${errorText(error)}`,
|
|
3194
|
+
{ cause: error }
|
|
3195
|
+
);
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
var init_sitian_volume = __esm({
|
|
3199
|
+
"src/sitian-volume.ts"() {
|
|
3200
|
+
"use strict";
|
|
3201
|
+
init_activation_ledger_topology();
|
|
3202
|
+
init_atomic_write();
|
|
3203
|
+
init_sitian_appender();
|
|
3204
|
+
init_sitian_contracts();
|
|
3205
|
+
}
|
|
3206
|
+
});
|
|
3207
|
+
|
|
3014
3208
|
// src/sitian-facade.ts
|
|
3015
3209
|
function sitianReport(input) {
|
|
3016
3210
|
return appendSitianRecord(input);
|
|
@@ -3022,6 +3216,7 @@ var init_sitian_facade = __esm({
|
|
|
3022
3216
|
init_sitian_contracts();
|
|
3023
3217
|
init_sitian_appender();
|
|
3024
3218
|
init_sitian_reader();
|
|
3219
|
+
init_sitian_volume();
|
|
3025
3220
|
}
|
|
3026
3221
|
});
|
|
3027
3222
|
|
|
@@ -3039,13 +3234,13 @@ __export(role_turn_host_exports, {
|
|
|
3039
3234
|
});
|
|
3040
3235
|
import { execFile, spawn as spawn3 } from "node:child_process";
|
|
3041
3236
|
import { constants } from "node:fs";
|
|
3042
|
-
import { access, appendFile, readFile as
|
|
3043
|
-
import { basename as basename3, delimiter, dirname as
|
|
3237
|
+
import { access, appendFile, readFile as readFile6, realpath as realpath2 } from "node:fs/promises";
|
|
3238
|
+
import { basename as basename3, delimiter, dirname as dirname7, isAbsolute as isAbsolute3, join as join10, resolve as resolve5 } from "node:path";
|
|
3044
3239
|
import { platform } from "node:process";
|
|
3045
3240
|
import { promisify } from "node:util";
|
|
3046
|
-
import { randomUUID as
|
|
3241
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
3047
3242
|
function resolveInternalRoleEntrypoint(packageRoot) {
|
|
3048
|
-
return
|
|
3243
|
+
return join10(packageRoot, INTERNAL_ROLE_ENTRYPOINT_RELATIVE);
|
|
3049
3244
|
}
|
|
3050
3245
|
function buildExplicitInternalActivationArgs(selectedRoleEntry, extraArgs = []) {
|
|
3051
3246
|
return ["--no-extensions", "-e", selectedRoleEntry, ...extraArgs];
|
|
@@ -3081,7 +3276,7 @@ function buildMethodArgs(methods) {
|
|
|
3081
3276
|
function applyPiNativeSkillInvocation(methods, prompt) {
|
|
3082
3277
|
const skills = methods.filter((method) => method.kind === "skill");
|
|
3083
3278
|
if (skills.length !== 1) return prompt;
|
|
3084
|
-
const name = basename3(
|
|
3279
|
+
const name = basename3(dirname7(skills[0].path));
|
|
3085
3280
|
if (name.length === 0) return prompt;
|
|
3086
3281
|
const token = `/skill:${name}`;
|
|
3087
3282
|
const trimmed = prompt.trimStart();
|
|
@@ -3318,7 +3513,7 @@ ${paths.join("\n")}`
|
|
|
3318
3513
|
}
|
|
3319
3514
|
async function appendPiSessionCustomEntry(authority, principal, customType, data) {
|
|
3320
3515
|
const { sessionFile } = authority.decode(principal);
|
|
3321
|
-
const text = await
|
|
3516
|
+
const text = await readFile6(sessionFile, "utf8");
|
|
3322
3517
|
let parentId = null;
|
|
3323
3518
|
for (const line2 of text.trim().split("\n").filter(Boolean)) {
|
|
3324
3519
|
const entry = JSON.parse(line2);
|
|
@@ -3329,7 +3524,7 @@ async function appendPiSessionCustomEntry(authority, principal, customType, data
|
|
|
3329
3524
|
type: "custom",
|
|
3330
3525
|
customType,
|
|
3331
3526
|
data,
|
|
3332
|
-
id:
|
|
3527
|
+
id: randomUUID3(),
|
|
3333
3528
|
parentId,
|
|
3334
3529
|
timestamp: timestamp2
|
|
3335
3530
|
})}
|
|
@@ -3485,8 +3680,8 @@ var init_host_descriptions = __esm({
|
|
|
3485
3680
|
|
|
3486
3681
|
// src/role-run-relocation.ts
|
|
3487
3682
|
import { existsSync as existsSync4 } from "node:fs";
|
|
3488
|
-
import { readdir as readdir2, readFile as
|
|
3489
|
-
import { join as
|
|
3683
|
+
import { readdir as readdir2, readFile as readFile7, writeFile as writeFile3 } from "node:fs/promises";
|
|
3684
|
+
import { join as join11, sep as sep2 } from "node:path";
|
|
3490
3685
|
function isEnoent2(error) {
|
|
3491
3686
|
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
3492
3687
|
}
|
|
@@ -3575,15 +3770,15 @@ function rewriteSummonsMaterials(value, rewrites) {
|
|
|
3575
3770
|
}
|
|
3576
3771
|
async function rewriteJsonObjectFile(path, fields, rewrites) {
|
|
3577
3772
|
if (!existsSync4(path)) return;
|
|
3578
|
-
const page = JSON.parse(await
|
|
3773
|
+
const page = JSON.parse(await readFile7(path, "utf8"));
|
|
3579
3774
|
if (!isPlainObject(page)) return;
|
|
3580
3775
|
rewriteRunDirectoryPathFieldsAgainstRewrites(page, fields, rewrites);
|
|
3581
|
-
await
|
|
3776
|
+
await writeFile3(path, `${JSON.stringify(page, null, 2)}
|
|
3582
3777
|
`, "utf8");
|
|
3583
3778
|
}
|
|
3584
3779
|
async function rewriteOfficerPointerFile(path, rewrites) {
|
|
3585
3780
|
if (!existsSync4(path)) return;
|
|
3586
|
-
const page = JSON.parse(await
|
|
3781
|
+
const page = JSON.parse(await readFile7(path, "utf8"));
|
|
3587
3782
|
if (!isPlainObject(page)) return;
|
|
3588
3783
|
if (page.kind !== "direct-officer-run-pointer") return;
|
|
3589
3784
|
rewriteRunDirectoryPathFieldsAgainstRewrites(
|
|
@@ -3591,12 +3786,12 @@ async function rewriteOfficerPointerFile(path, rewrites) {
|
|
|
3591
3786
|
OFFICER_POINTER_FIELDS,
|
|
3592
3787
|
rewrites
|
|
3593
3788
|
);
|
|
3594
|
-
await
|
|
3789
|
+
await writeFile3(path, `${JSON.stringify(page)}
|
|
3595
3790
|
`, "utf8");
|
|
3596
3791
|
}
|
|
3597
3792
|
async function rewriteSitianRecordsJsonl(path, rewrites) {
|
|
3598
3793
|
if (!existsSync4(path)) return;
|
|
3599
|
-
const raw = await
|
|
3794
|
+
const raw = await readFile7(path, "utf8");
|
|
3600
3795
|
if (raw.length === 0) return;
|
|
3601
3796
|
const endsWithNewline = raw.endsWith("\n");
|
|
3602
3797
|
const lines = raw.split("\n");
|
|
@@ -3638,7 +3833,7 @@ async function rewriteSitianRecordsJsonl(path, rewrites) {
|
|
|
3638
3833
|
}
|
|
3639
3834
|
if (!changed) return;
|
|
3640
3835
|
const body = out.join("\n");
|
|
3641
|
-
await
|
|
3836
|
+
await writeFile3(
|
|
3642
3837
|
path,
|
|
3643
3838
|
endsWithNewline && !body.endsWith("\n") ? `${body}
|
|
3644
3839
|
` : body,
|
|
@@ -3647,7 +3842,7 @@ async function rewriteSitianRecordsJsonl(path, rewrites) {
|
|
|
3647
3842
|
}
|
|
3648
3843
|
async function rewriteSessionTranscriptBindings(path, rewrites) {
|
|
3649
3844
|
if (!existsSync4(path)) return;
|
|
3650
|
-
const raw = await
|
|
3845
|
+
const raw = await readFile7(path, "utf8");
|
|
3651
3846
|
if (raw.length === 0) return;
|
|
3652
3847
|
const endsWithNewline = raw.endsWith("\n");
|
|
3653
3848
|
const lines = raw.split("\n");
|
|
@@ -3698,7 +3893,7 @@ async function rewriteSessionTranscriptBindings(path, rewrites) {
|
|
|
3698
3893
|
}
|
|
3699
3894
|
if (!changed) return;
|
|
3700
3895
|
const body = out.join("\n");
|
|
3701
|
-
await
|
|
3896
|
+
await writeFile3(
|
|
3702
3897
|
path,
|
|
3703
3898
|
endsWithNewline && !body.endsWith("\n") ? `${body}
|
|
3704
3899
|
` : body,
|
|
@@ -3706,7 +3901,7 @@ async function rewriteSessionTranscriptBindings(path, rewrites) {
|
|
|
3706
3901
|
);
|
|
3707
3902
|
}
|
|
3708
3903
|
async function rewriteNestedMachinePathPages(pagesDirectory, rewrites) {
|
|
3709
|
-
const sessionRoot =
|
|
3904
|
+
const sessionRoot = join11(pagesDirectory, "session");
|
|
3710
3905
|
async function walk(directory) {
|
|
3711
3906
|
let entries;
|
|
3712
3907
|
try {
|
|
@@ -3716,7 +3911,7 @@ async function rewriteNestedMachinePathPages(pagesDirectory, rewrites) {
|
|
|
3716
3911
|
throw error;
|
|
3717
3912
|
}
|
|
3718
3913
|
for (const entry of entries) {
|
|
3719
|
-
const path =
|
|
3914
|
+
const path = join11(directory, entry.name);
|
|
3720
3915
|
if (entry.isDirectory()) {
|
|
3721
3916
|
await walk(path);
|
|
3722
3917
|
continue;
|
|
@@ -3738,9 +3933,9 @@ async function rewriteNestedMachinePathPages(pagesDirectory, rewrites) {
|
|
|
3738
3933
|
async function rewriteRoleRunDurablePages(input) {
|
|
3739
3934
|
const { pagesDirectory } = input;
|
|
3740
3935
|
const rewrites = collectRewrites(input);
|
|
3741
|
-
const admittedPath =
|
|
3936
|
+
const admittedPath = join11(pagesDirectory, "admitted-request.json");
|
|
3742
3937
|
if (existsSync4(admittedPath)) {
|
|
3743
|
-
const page = JSON.parse(await
|
|
3938
|
+
const page = JSON.parse(await readFile7(admittedPath, "utf8"));
|
|
3744
3939
|
rewriteRunDirectoryPathFieldsAgainstRewrites(
|
|
3745
3940
|
page,
|
|
3746
3941
|
ADMITTED_PAGE_FIELDS,
|
|
@@ -3765,27 +3960,27 @@ async function rewriteRoleRunDurablePages(input) {
|
|
|
3765
3960
|
rewrites
|
|
3766
3961
|
);
|
|
3767
3962
|
}
|
|
3768
|
-
await
|
|
3963
|
+
await writeFile3(admittedPath, `${JSON.stringify(page, null, 2)}
|
|
3769
3964
|
`, "utf8");
|
|
3770
3965
|
}
|
|
3771
|
-
const invocationPath =
|
|
3966
|
+
const invocationPath = join11(pagesDirectory, "invocation.json");
|
|
3772
3967
|
if (existsSync4(invocationPath)) {
|
|
3773
|
-
const page = JSON.parse(await
|
|
3968
|
+
const page = JSON.parse(await readFile7(invocationPath, "utf8"));
|
|
3774
3969
|
rewriteRunDirectoryPathFieldsAgainstRewrites(
|
|
3775
3970
|
page,
|
|
3776
3971
|
INVOCATION_PAGE_FIELDS,
|
|
3777
3972
|
rewrites
|
|
3778
3973
|
);
|
|
3779
|
-
await
|
|
3974
|
+
await writeFile3(
|
|
3780
3975
|
invocationPath,
|
|
3781
3976
|
`${JSON.stringify(page, null, 2)}
|
|
3782
3977
|
`,
|
|
3783
3978
|
"utf8"
|
|
3784
3979
|
);
|
|
3785
3980
|
}
|
|
3786
|
-
const statePath =
|
|
3981
|
+
const statePath = join11(pagesDirectory, "run-state.json");
|
|
3787
3982
|
if (existsSync4(statePath)) {
|
|
3788
|
-
const page = JSON.parse(await
|
|
3983
|
+
const page = JSON.parse(await readFile7(statePath, "utf8"));
|
|
3789
3984
|
rewriteRunDirectoryPathFieldsAgainstRewrites(
|
|
3790
3985
|
page,
|
|
3791
3986
|
RUN_STATE_PAGE_FIELDS,
|
|
@@ -3801,7 +3996,7 @@ async function rewriteRoleRunDurablePages(input) {
|
|
|
3801
3996
|
if (isPlainObject(page.currentCourt)) {
|
|
3802
3997
|
rewriteSummonsMaterials(page.currentCourt.summons, rewrites);
|
|
3803
3998
|
}
|
|
3804
|
-
await
|
|
3999
|
+
await writeFile3(statePath, `${JSON.stringify(page, null, 2)}
|
|
3805
4000
|
`, "utf8");
|
|
3806
4001
|
}
|
|
3807
4002
|
await rewriteNestedMachinePathPages(pagesDirectory, rewrites);
|
|
@@ -3969,8 +4164,8 @@ var init_terminating_tools = __esm({
|
|
|
3969
4164
|
});
|
|
3970
4165
|
|
|
3971
4166
|
// src/doctor-evidence.ts
|
|
3972
|
-
import { readdir as readdir3, readFile as
|
|
3973
|
-
import { dirname as
|
|
4167
|
+
import { readdir as readdir3, readFile as readFile8, realpath as realpath3, stat } from "node:fs/promises";
|
|
4168
|
+
import { dirname as dirname8, relative as relative2, resolve as resolve6, sep as sep3 } from "node:path";
|
|
3974
4169
|
function record3(value) {
|
|
3975
4170
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3976
4171
|
}
|
|
@@ -4009,7 +4204,7 @@ async function stableRunsIdentity(root) {
|
|
|
4009
4204
|
} catch (error) {
|
|
4010
4205
|
if (!isMissingPathError2(error)) throw error;
|
|
4011
4206
|
}
|
|
4012
|
-
const parent =
|
|
4207
|
+
const parent = dirname8(cursor);
|
|
4013
4208
|
if (parent === cursor) return root;
|
|
4014
4209
|
cursor = parent;
|
|
4015
4210
|
}
|
|
@@ -4085,7 +4280,7 @@ async function loadDoctorCase(runsPath) {
|
|
|
4085
4280
|
const turns = { count: 0, sources: [] }, calls = { count: 0, sources: [] }, tokens = { count: 0, sources: [] };
|
|
4086
4281
|
for (const path of await discoverCaseFiles(root)) {
|
|
4087
4282
|
const id = relative2(root, path).split(sep3).join("/");
|
|
4088
|
-
const bytes = await
|
|
4283
|
+
const bytes = await readFile8(path);
|
|
4089
4284
|
const content = bytes.toString("utf8");
|
|
4090
4285
|
const kind = id.endsWith(".jsonl") ? "session" : "stderr";
|
|
4091
4286
|
evidence.push({ id, kind, byteLength: bytes.byteLength, contentLength: content.length, sha256: sha256Hex(bytes), content });
|
|
@@ -4321,7 +4516,7 @@ var init_git_object_id = __esm({
|
|
|
4321
4516
|
|
|
4322
4517
|
// src/merger-git-state.ts
|
|
4323
4518
|
import { execFile as execFile2 } from "node:child_process";
|
|
4324
|
-
import { access as access2, readFile as
|
|
4519
|
+
import { access as access2, readFile as readFile9 } from "node:fs/promises";
|
|
4325
4520
|
import { constants as fsConstants } from "node:fs";
|
|
4326
4521
|
import { isAbsolute as isAbsolute4, resolve as resolve7 } from "node:path";
|
|
4327
4522
|
import { promisify as promisify2 } from "node:util";
|
|
@@ -4391,7 +4586,7 @@ function createProductionMergerGitState(repositoryRoot = process.cwd()) {
|
|
|
4391
4586
|
const mergeHeadPath = isAbsolute4(mergeHeadReported) ? mergeHeadReported : resolve7(repositoryRoot, mergeHeadReported);
|
|
4392
4587
|
let sourceObjectId = "";
|
|
4393
4588
|
if (await pathExists(mergeHeadPath)) {
|
|
4394
|
-
const raw = exactUtf8(await
|
|
4589
|
+
const raw = exactUtf8(await readFile9(mergeHeadPath), "Git MERGE_HEAD");
|
|
4395
4590
|
const mergeHeads = raw.trim().split(/\r?\n/).map((row) => row.trim()).filter(Boolean);
|
|
4396
4591
|
if (mergeHeads.length === 0) throw new Error("Git MERGE_HEAD is empty");
|
|
4397
4592
|
if (mergeHeads.length !== 1) throw new Error("Assigned repository does not have one ordinary in-progress merge");
|
|
@@ -4443,10 +4638,10 @@ var init_uuidv7 = __esm({
|
|
|
4443
4638
|
});
|
|
4444
4639
|
|
|
4445
4640
|
// src/typed-provider-http.ts
|
|
4446
|
-
import { readFile as
|
|
4447
|
-
import { join as
|
|
4641
|
+
import { readFile as readFile10, unlink, writeFile as writeFile4 } from "node:fs/promises";
|
|
4642
|
+
import { join as join12 } from "node:path";
|
|
4448
4643
|
function typedProviderHttpPath(runDirectory) {
|
|
4449
|
-
return
|
|
4644
|
+
return join12(runDirectory, TYPED_HTTP_FILE);
|
|
4450
4645
|
}
|
|
4451
4646
|
async function clearTypedProviderHttpObservation(runDirectory) {
|
|
4452
4647
|
try {
|
|
@@ -4467,7 +4662,7 @@ async function recordTypedProviderHttpStatus(runDirectory, observation) {
|
|
|
4467
4662
|
httpStatus: observation.httpStatus,
|
|
4468
4663
|
provider: observation.provider
|
|
4469
4664
|
};
|
|
4470
|
-
await
|
|
4665
|
+
await writeFile4(
|
|
4471
4666
|
typedProviderHttpPath(runDirectory),
|
|
4472
4667
|
`${JSON.stringify(body)}
|
|
4473
4668
|
`,
|
|
@@ -4477,7 +4672,7 @@ async function recordTypedProviderHttpStatus(runDirectory, observation) {
|
|
|
4477
4672
|
async function readLatestTypedProviderHttpObservation(runDirectory) {
|
|
4478
4673
|
let text;
|
|
4479
4674
|
try {
|
|
4480
|
-
text = await
|
|
4675
|
+
text = await readFile10(typedProviderHttpPath(runDirectory), "utf8");
|
|
4481
4676
|
} catch (error) {
|
|
4482
4677
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
4483
4678
|
return void 0;
|
|
@@ -4506,8 +4701,8 @@ var init_typed_provider_http = __esm({
|
|
|
4506
4701
|
});
|
|
4507
4702
|
|
|
4508
4703
|
// src/public-cli/run-lifecycle.ts
|
|
4509
|
-
import { chmod, lstat as lstat2, open, readdir as readdir4, readFile as
|
|
4510
|
-
import { basename as basename4, join as
|
|
4704
|
+
import { chmod, lstat as lstat2, open, readdir as readdir4, readFile as readFile11, unlink as unlink2, writeFile as writeFile5 } from "node:fs/promises";
|
|
4705
|
+
import { basename as basename4, join as join13 } from "node:path";
|
|
4511
4706
|
function selectResumeContinuationPrompt(message, engineMaterial) {
|
|
4512
4707
|
const lines = message !== void 0 ? [message] : [];
|
|
4513
4708
|
return appendEngineSessionMaterial(lines, engineMaterial).join("\n");
|
|
@@ -4536,8 +4731,8 @@ function renderResumeCommand(runId) {
|
|
|
4536
4731
|
}
|
|
4537
4732
|
async function writeRoleRunState(runDirectory, record4) {
|
|
4538
4733
|
const payload = { ...record4, runDirectory };
|
|
4539
|
-
await
|
|
4540
|
-
|
|
4734
|
+
await writeFile5(
|
|
4735
|
+
join13(runDirectory, RUN_STATE_FILE),
|
|
4541
4736
|
`${JSON.stringify(payload, null, 2)}
|
|
4542
4737
|
`,
|
|
4543
4738
|
"utf8"
|
|
@@ -4587,7 +4782,7 @@ function parseCurrentCourtState(raw) {
|
|
|
4587
4782
|
async function readRoleRunStateDisk(runDirectory) {
|
|
4588
4783
|
let raw;
|
|
4589
4784
|
try {
|
|
4590
|
-
raw = JSON.parse(await
|
|
4785
|
+
raw = JSON.parse(await readFile11(join13(runDirectory, RUN_STATE_FILE), "utf8"));
|
|
4591
4786
|
} catch (error) {
|
|
4592
4787
|
if (errorCodeOf2(error) === "ENOENT") return void 0;
|
|
4593
4788
|
throw error;
|
|
@@ -4654,8 +4849,8 @@ async function writeRoleRunStateDisk(runDirectory, disk) {
|
|
|
4654
4849
|
...disk.resumable === void 0 ? {} : { resumable: disk.resumable },
|
|
4655
4850
|
...disk.currentCourt === void 0 ? {} : { currentCourt: disk.currentCourt }
|
|
4656
4851
|
};
|
|
4657
|
-
await
|
|
4658
|
-
|
|
4852
|
+
await writeFile5(
|
|
4853
|
+
join13(runDirectory, RUN_STATE_FILE),
|
|
4659
4854
|
`${JSON.stringify(payload, null, 2)}
|
|
4660
4855
|
`,
|
|
4661
4856
|
"utf8"
|
|
@@ -4822,7 +5017,7 @@ function isProcessAlive(pid) {
|
|
|
4822
5017
|
async function autopsyWriterLock(lockPath) {
|
|
4823
5018
|
let content;
|
|
4824
5019
|
try {
|
|
4825
|
-
content = await
|
|
5020
|
+
content = await readFile11(lockPath, "utf8");
|
|
4826
5021
|
} catch (error) {
|
|
4827
5022
|
if (errorCodeOf2(error) === "ENOENT") return { verdict: "absent" };
|
|
4828
5023
|
return { verdict: "unknown", reason: "unreadable", readFailure: error };
|
|
@@ -4881,7 +5076,7 @@ async function createWriterLease(lockPath, runDirectory, reportCleanupFailure) {
|
|
|
4881
5076
|
},
|
|
4882
5077
|
relocate(nextRunDirectory) {
|
|
4883
5078
|
currentRunDirectory = nextRunDirectory;
|
|
4884
|
-
currentLockPath =
|
|
5079
|
+
currentLockPath = join13(nextRunDirectory, WRITER_LOCK_FILE);
|
|
4885
5080
|
},
|
|
4886
5081
|
async release() {
|
|
4887
5082
|
if (released) return;
|
|
@@ -4920,10 +5115,10 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
|
|
|
4920
5115
|
};
|
|
4921
5116
|
const reportReadFailure = (error) => {
|
|
4922
5117
|
reportDiagnostic(
|
|
4923
|
-
`writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${
|
|
5118
|
+
`writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${join13(runDirectory, WRITER_LOCK_FILE)}: ${describeErrorIdentity(error)}`
|
|
4924
5119
|
);
|
|
4925
5120
|
};
|
|
4926
|
-
const lockPath =
|
|
5121
|
+
const lockPath = join13(runDirectory, WRITER_LOCK_FILE);
|
|
4927
5122
|
let lastAutopsy = { verdict: "absent" };
|
|
4928
5123
|
let lastReclaimFailure;
|
|
4929
5124
|
for (let reclaimsLeft = WRITER_LEASE_RECLAIM_ROUNDS; ; reclaimsLeft -= 1) {
|
|
@@ -4978,7 +5173,7 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
|
|
|
4978
5173
|
async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole) {
|
|
4979
5174
|
if (runId.trim() === "") return void 0;
|
|
4980
5175
|
const ledgerHome = resolveActivationLedgerHome(home);
|
|
4981
|
-
const booksRoot =
|
|
5176
|
+
const booksRoot = join13(ledgerHome, "books");
|
|
4982
5177
|
let bookKeys;
|
|
4983
5178
|
try {
|
|
4984
5179
|
bookKeys = await readdir4(booksRoot);
|
|
@@ -5019,7 +5214,7 @@ async function readRunParentPath(runDirectory) {
|
|
|
5019
5214
|
let raw;
|
|
5020
5215
|
try {
|
|
5021
5216
|
raw = JSON.parse(
|
|
5022
|
-
await
|
|
5217
|
+
await readFile11(join13(runDirectory, "admitted-request.json"), "utf8")
|
|
5023
5218
|
);
|
|
5024
5219
|
} catch (error) {
|
|
5025
5220
|
if (errorCodeOf2(error) === "ENOENT") return void 0;
|
|
@@ -5040,7 +5235,7 @@ async function readRunParentPath(runDirectory) {
|
|
|
5040
5235
|
async function runHasFormedSessionPrincipal(runDirectory) {
|
|
5041
5236
|
const disk = await readRoleRunStateDisk(runDirectory);
|
|
5042
5237
|
if (disk === void 0) return false;
|
|
5043
|
-
const sessionFile = typeof disk.principalWire.sessionFile === "string" && disk.principalWire.sessionFile.trim() !== "" ? disk.principalWire.sessionFile :
|
|
5238
|
+
const sessionFile = typeof disk.principalWire.sessionFile === "string" && disk.principalWire.sessionFile.trim() !== "" ? disk.principalWire.sessionFile : join13(disk.principalWire.sessionDirectory, "session.jsonl");
|
|
5044
5239
|
try {
|
|
5045
5240
|
const stat2 = await lstat2(sessionFile);
|
|
5046
5241
|
return stat2.isFile() && !stat2.isSymbolicLink();
|
|
@@ -5187,7 +5382,7 @@ async function loadResumableRunRecord(home, runId, authority) {
|
|
|
5187
5382
|
let sourceRun;
|
|
5188
5383
|
try {
|
|
5189
5384
|
const raw = JSON.parse(
|
|
5190
|
-
await
|
|
5385
|
+
await readFile11(run.admittedRequestPath, "utf8")
|
|
5191
5386
|
);
|
|
5192
5387
|
if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
|
|
5193
5388
|
const record4 = raw;
|
|
@@ -5302,7 +5497,7 @@ async function loadResumableRunRecord(home, runId, authority) {
|
|
|
5302
5497
|
let model;
|
|
5303
5498
|
try {
|
|
5304
5499
|
const invocationRaw = JSON.parse(
|
|
5305
|
-
await
|
|
5500
|
+
await readFile11(join13(run.runDirectory, "invocation.json"), "utf8")
|
|
5306
5501
|
);
|
|
5307
5502
|
if (invocationRaw !== null && typeof invocationRaw === "object" && !Array.isArray(invocationRaw)) {
|
|
5308
5503
|
const rec = invocationRaw;
|
|
@@ -5533,7 +5728,7 @@ __export(notary_source_run_exports, {
|
|
|
5533
5728
|
loadNotarySourceRunLocator: () => loadNotarySourceRunLocator,
|
|
5534
5729
|
resolveNotarySourceRunLocator: () => resolveNotarySourceRunLocator
|
|
5535
5730
|
});
|
|
5536
|
-
import { dirname as
|
|
5731
|
+
import { dirname as dirname9, isAbsolute as isAbsolute6, join as join14, resolve as resolve8, basename as basename5 } from "node:path";
|
|
5537
5732
|
import { lstat as lstat3, realpath as realpath4 } from "node:fs/promises";
|
|
5538
5733
|
function parseRunDirectoryName(name) {
|
|
5539
5734
|
const match = RUN_DIR_NAME.exec(name);
|
|
@@ -5579,20 +5774,20 @@ async function resolveNotarySourceRunLocator(options) {
|
|
|
5579
5774
|
}
|
|
5580
5775
|
const ledgerHome = resolveActivationLedgerHome(options.home);
|
|
5581
5776
|
const bookKey = resolveBookKeyFromGit(options.projectRoot);
|
|
5582
|
-
const bookRunsRoot =
|
|
5777
|
+
const bookRunsRoot = join14(activationBookDirectory(ledgerHome, bookKey), "runs");
|
|
5583
5778
|
let candidate;
|
|
5584
5779
|
const bare = parseRunDirectoryName(raw);
|
|
5585
5780
|
if (bare !== void 0 && !raw.includes("/") && !raw.includes("\\")) {
|
|
5586
|
-
candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ??
|
|
5781
|
+
candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ?? join14(bookRunsRoot, `${bare.runId}@${bare.role}`);
|
|
5587
5782
|
} else {
|
|
5588
5783
|
candidate = isAbsolute6(raw) ? raw : resolve8(options.projectRoot, raw);
|
|
5589
5784
|
}
|
|
5590
5785
|
const real = await requireRunDirectory(candidate, raw);
|
|
5591
5786
|
const identity = parseRunDirectoryName(basename5(real));
|
|
5592
5787
|
const bookIdentity = physicalPathIdentity(activationBookDirectory(ledgerHome, bookKey));
|
|
5593
|
-
const parentIdentity = physicalPathIdentity(
|
|
5594
|
-
const subjectBookIdentity = physicalPathIdentity(
|
|
5595
|
-
if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(basename5(
|
|
5788
|
+
const parentIdentity = physicalPathIdentity(dirname9(real));
|
|
5789
|
+
const subjectBookIdentity = physicalPathIdentity(dirname9(dirname9(dirname9(real))));
|
|
5790
|
+
if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(basename5(dirname9(real)) === "runs" && subjectBookIdentity === bookIdentity)) {
|
|
5596
5791
|
throw new NotarySourceRunError(
|
|
5597
5792
|
"notary --source-run must resolve to a retained run under the project machine-ledger book"
|
|
5598
5793
|
);
|
|
@@ -6733,12 +6928,12 @@ import { execFileSync as execFileSync3 } from "node:child_process";
|
|
|
6733
6928
|
import { existsSync as existsSync5 } from "node:fs";
|
|
6734
6929
|
import {
|
|
6735
6930
|
lstat as lstat4,
|
|
6736
|
-
readFile as
|
|
6931
|
+
readFile as readFile12,
|
|
6737
6932
|
realpath as realpath5,
|
|
6738
|
-
rename,
|
|
6739
|
-
writeFile as
|
|
6933
|
+
rename as rename2,
|
|
6934
|
+
writeFile as writeFile6
|
|
6740
6935
|
} from "node:fs/promises";
|
|
6741
|
-
import { basename as basename6, dirname as
|
|
6936
|
+
import { basename as basename6, dirname as dirname10, isAbsolute as isAbsolute7, join as join15, resolve as resolve9, sep as sep4 } from "node:path";
|
|
6742
6937
|
function issueAdmissionPlacement(authority, request) {
|
|
6743
6938
|
const ledgerHome = resolveActivationLedgerHome(request.home);
|
|
6744
6939
|
const bookKey = resolveBookKeyFromGit(request.cwd);
|
|
@@ -6763,7 +6958,7 @@ async function writeAdmittedRequestPersistence(admittedRequestPath, body, coordi
|
|
|
6763
6958
|
sessionDirectory: coordinates.sessionDirectory,
|
|
6764
6959
|
sessionFile: coordinates.sessionFile
|
|
6765
6960
|
};
|
|
6766
|
-
await
|
|
6961
|
+
await writeFile6(
|
|
6767
6962
|
admittedRequestPath,
|
|
6768
6963
|
`${JSON.stringify(projection, null, 2)}
|
|
6769
6964
|
`,
|
|
@@ -6791,16 +6986,16 @@ async function writeRoleInvocationLedger(source, role, effectiveModel) {
|
|
|
6791
6986
|
...source.ticketNumber === void 0 ? {} : { ticketNumber: source.ticketNumber },
|
|
6792
6987
|
...effectiveModelLedgerFields(effectiveModel)
|
|
6793
6988
|
};
|
|
6794
|
-
await
|
|
6795
|
-
|
|
6989
|
+
await writeFile6(
|
|
6990
|
+
join15(source.runDirectory, "invocation.json"),
|
|
6796
6991
|
`${JSON.stringify(identity, null, 2)}
|
|
6797
6992
|
`,
|
|
6798
6993
|
"utf8"
|
|
6799
6994
|
);
|
|
6800
6995
|
}
|
|
6801
6996
|
async function recordEffectiveInvocationModel(runDirectory, model, engine, host, engineModel) {
|
|
6802
|
-
const ledgerPath =
|
|
6803
|
-
const current = JSON.parse(await
|
|
6997
|
+
const ledgerPath = join15(runDirectory, "invocation.json");
|
|
6998
|
+
const current = JSON.parse(await readFile12(ledgerPath, "utf8"));
|
|
6804
6999
|
const next = { ...current };
|
|
6805
7000
|
if (model !== void 0) {
|
|
6806
7001
|
next.provider = model.provider;
|
|
@@ -6824,7 +7019,7 @@ async function recordEffectiveInvocationModel(runDirectory, model, engine, host,
|
|
|
6824
7019
|
if (host !== void 0) {
|
|
6825
7020
|
next.host = host;
|
|
6826
7021
|
}
|
|
6827
|
-
await
|
|
7022
|
+
await writeFile6(
|
|
6828
7023
|
ledgerPath,
|
|
6829
7024
|
`${JSON.stringify(next, null, 2)}
|
|
6830
7025
|
`,
|
|
@@ -6832,9 +7027,9 @@ async function recordEffectiveInvocationModel(runDirectory, model, engine, host,
|
|
|
6832
7027
|
);
|
|
6833
7028
|
}
|
|
6834
7029
|
async function mergeInvocationIdentityPage(runDirectory, fields) {
|
|
6835
|
-
const ledgerPath =
|
|
6836
|
-
const current = JSON.parse(await
|
|
6837
|
-
await
|
|
7030
|
+
const ledgerPath = join15(runDirectory, "invocation.json");
|
|
7031
|
+
const current = JSON.parse(await readFile12(ledgerPath, "utf8"));
|
|
7032
|
+
await writeFile6(
|
|
6838
7033
|
ledgerPath,
|
|
6839
7034
|
`${JSON.stringify({
|
|
6840
7035
|
...current,
|
|
@@ -6849,14 +7044,14 @@ async function persistAdmittedSourceRunPath(admitted, sourceRunPath) {
|
|
|
6849
7044
|
throw new Error("persistAdmittedSourceRunPath requires a non-empty sourceRunPath");
|
|
6850
7045
|
}
|
|
6851
7046
|
const admittedPath = admitted.admittedRequestPath;
|
|
6852
|
-
const current = JSON.parse(await
|
|
7047
|
+
const current = JSON.parse(await readFile12(admittedPath, "utf8"));
|
|
6853
7048
|
if (typeof current.sourceRunPath === "string") {
|
|
6854
7049
|
if (current.sourceRunPath === sourceRunPath) return;
|
|
6855
7050
|
throw new Error(
|
|
6856
7051
|
`persistAdmittedSourceRunPath refuses to replace ${current.sourceRunPath} with ${sourceRunPath}`
|
|
6857
7052
|
);
|
|
6858
7053
|
}
|
|
6859
|
-
await
|
|
7054
|
+
await writeFile6(
|
|
6860
7055
|
admittedPath,
|
|
6861
7056
|
`${JSON.stringify({ ...current, sourceRunPath }, null, 2)}
|
|
6862
7057
|
`,
|
|
@@ -6898,8 +7093,8 @@ async function bindCourtTicketNumbersOnAdmitted(admitted, courtTicketNumbers) {
|
|
|
6898
7093
|
}
|
|
6899
7094
|
const frozen = Object.freeze([...projected]);
|
|
6900
7095
|
const admittedPath = admitted.admittedRequestPath;
|
|
6901
|
-
const current = JSON.parse(await
|
|
6902
|
-
await
|
|
7096
|
+
const current = JSON.parse(await readFile12(admittedPath, "utf8"));
|
|
7097
|
+
await writeFile6(
|
|
6903
7098
|
admittedPath,
|
|
6904
7099
|
`${JSON.stringify({ ...current, courtTicketNumbers: frozen }, null, 2)}
|
|
6905
7100
|
`,
|
|
@@ -6920,8 +7115,8 @@ async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
|
|
|
6920
7115
|
runId: admitted.runId,
|
|
6921
7116
|
role: admitted.role
|
|
6922
7117
|
});
|
|
6923
|
-
ensureRoleRunDirectory(ledgerHome,
|
|
6924
|
-
await
|
|
7118
|
+
ensureRoleRunDirectory(ledgerHome, dirname10(target.runDirectory));
|
|
7119
|
+
await rename2(oldRunDirectory, target.runDirectory);
|
|
6925
7120
|
heldLease?.relocate(target.runDirectory);
|
|
6926
7121
|
const admittedRecord = admitted;
|
|
6927
7122
|
rewriteRunDirectoryPathFields(
|
|
@@ -6958,9 +7153,9 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
|
|
|
6958
7153
|
ticketNumber,
|
|
6959
7154
|
"bindTicketNumberOnRunDirectory"
|
|
6960
7155
|
);
|
|
6961
|
-
const admittedPath =
|
|
6962
|
-
const invocationPath =
|
|
6963
|
-
const admitted = JSON.parse(await
|
|
7156
|
+
const admittedPath = join15(runDirectory, "admitted-request.json");
|
|
7157
|
+
const invocationPath = join15(runDirectory, "invocation.json");
|
|
7158
|
+
const admitted = JSON.parse(await readFile12(admittedPath, "utf8"));
|
|
6964
7159
|
const existing = admitted.ticketNumber;
|
|
6965
7160
|
if (typeof existing === "number") {
|
|
6966
7161
|
if (existing === ticketNumber) return;
|
|
@@ -6970,7 +7165,7 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
|
|
|
6970
7165
|
}
|
|
6971
7166
|
if (existsSync5(invocationPath)) {
|
|
6972
7167
|
const invocation = JSON.parse(
|
|
6973
|
-
await
|
|
7168
|
+
await readFile12(invocationPath, "utf8")
|
|
6974
7169
|
);
|
|
6975
7170
|
if (typeof invocation.ticketNumber === "number" && invocation.ticketNumber !== ticketNumber) {
|
|
6976
7171
|
throw new Error(
|
|
@@ -6978,7 +7173,7 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
|
|
|
6978
7173
|
);
|
|
6979
7174
|
}
|
|
6980
7175
|
}
|
|
6981
|
-
await
|
|
7176
|
+
await writeFile6(
|
|
6982
7177
|
admittedPath,
|
|
6983
7178
|
`${JSON.stringify({ ...admitted, ticketNumber }, null, 2)}
|
|
6984
7179
|
`,
|
|
@@ -6995,7 +7190,7 @@ async function recordLaunchedPiIdentity(runDirectory, identity) {
|
|
|
6995
7190
|
async function observeLaunchedRolePackageIdentity(packageRoot, selectedRoleEntry) {
|
|
6996
7191
|
const rolePackageRoot = packageRoot;
|
|
6997
7192
|
const raw = JSON.parse(
|
|
6998
|
-
await
|
|
7193
|
+
await readFile12(join15(rolePackageRoot, "package.json"), "utf8")
|
|
6999
7194
|
);
|
|
7000
7195
|
if (typeof raw.version !== "string" || raw.version.trim() === "") {
|
|
7001
7196
|
throw new Error(
|
|
@@ -7251,10 +7446,10 @@ async function freezeRegularFileAttachment(sourcePath, destinationDir, index) {
|
|
|
7251
7446
|
`attachment must be a regular file (not a directory or symlink): ${sourcePath}`
|
|
7252
7447
|
);
|
|
7253
7448
|
}
|
|
7254
|
-
const bytes = await
|
|
7449
|
+
const bytes = await readFile12(absolute);
|
|
7255
7450
|
const name = `${String(index).padStart(2, "0")}-${basename6(absolute)}`;
|
|
7256
|
-
const frozenPath =
|
|
7257
|
-
await
|
|
7451
|
+
const frozenPath = join15(destinationDir, name);
|
|
7452
|
+
await writeFile6(frozenPath, bytes);
|
|
7258
7453
|
return {
|
|
7259
7454
|
attachment: {
|
|
7260
7455
|
provenancePath: absolute,
|
|
@@ -7281,7 +7476,7 @@ async function freezeAttachments(attachmentPaths, attachmentsDirectory) {
|
|
|
7281
7476
|
async function freezeAttachmentsIntoRun(attachmentPaths, runDirectory, summonsKey = `s-${Date.now().toString(36)}`) {
|
|
7282
7477
|
if (attachmentPaths.length === 0) return [];
|
|
7283
7478
|
const ledgerHome = resolveActivationLedgerHome(homeFromRunDirectory(runDirectory));
|
|
7284
|
-
const attachmentsDirectory =
|
|
7479
|
+
const attachmentsDirectory = join15(runDirectory, "attachments", summonsKey);
|
|
7285
7480
|
ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
|
|
7286
7481
|
return freezeAttachments(attachmentPaths, attachmentsDirectory);
|
|
7287
7482
|
}
|
|
@@ -7339,7 +7534,7 @@ async function admitStandardMaterialInvocation(role, options) {
|
|
|
7339
7534
|
})),
|
|
7340
7535
|
...ticketFields
|
|
7341
7536
|
};
|
|
7342
|
-
const admittedRequestPath =
|
|
7537
|
+
const admittedRequestPath = join15(runDirectory, "admitted-request.json");
|
|
7343
7538
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
7344
7539
|
sessionDirectory,
|
|
7345
7540
|
sessionFile
|
|
@@ -7441,7 +7636,7 @@ async function admitCountersignInvocation(options) {
|
|
|
7441
7636
|
mediaKind: a.mediaKind
|
|
7442
7637
|
}))
|
|
7443
7638
|
};
|
|
7444
|
-
const admittedRequestPath =
|
|
7639
|
+
const admittedRequestPath = join15(runDirectory, "admitted-request.json");
|
|
7445
7640
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
7446
7641
|
sessionDirectory,
|
|
7447
7642
|
sessionFile
|
|
@@ -7467,7 +7662,7 @@ function buildCountersignTransportPrompt(admitted, engineMaterial) {
|
|
|
7467
7662
|
async function loadAdmittedJudgeRequest(runDirectory) {
|
|
7468
7663
|
try {
|
|
7469
7664
|
const raw = JSON.parse(
|
|
7470
|
-
await
|
|
7665
|
+
await readFile12(join15(runDirectory, "admitted-request.json"), "utf8")
|
|
7471
7666
|
);
|
|
7472
7667
|
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return void 0;
|
|
7473
7668
|
const record4 = raw;
|
|
@@ -7522,8 +7717,8 @@ async function admitCoderInvocation(options) {
|
|
|
7522
7717
|
home: options.home
|
|
7523
7718
|
});
|
|
7524
7719
|
const attachments = await freezeAttachments(options.attachmentPaths, attachmentsDirectory);
|
|
7525
|
-
const taskPath =
|
|
7526
|
-
await
|
|
7720
|
+
const taskPath = join15(runDirectory, "task.md");
|
|
7721
|
+
await writeFile6(taskPath, instruction, "utf8");
|
|
7527
7722
|
const admitted = {
|
|
7528
7723
|
role: "coder",
|
|
7529
7724
|
phase: options.phase,
|
|
@@ -7543,7 +7738,7 @@ async function admitCoderInvocation(options) {
|
|
|
7543
7738
|
mediaKind: a.mediaKind
|
|
7544
7739
|
}))
|
|
7545
7740
|
};
|
|
7546
|
-
const admittedRequestPath =
|
|
7741
|
+
const admittedRequestPath = join15(runDirectory, "admitted-request.json");
|
|
7547
7742
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
7548
7743
|
sessionDirectory,
|
|
7549
7744
|
sessionFile
|
|
@@ -7593,7 +7788,7 @@ async function admitFixerInvocation(options) {
|
|
|
7593
7788
|
if (options.prerequisitesPath !== void 0) {
|
|
7594
7789
|
const absolutePrereq = isAbsolute7(options.prerequisitesPath) ? options.prerequisitesPath : resolve9(options.prerequisitesPath);
|
|
7595
7790
|
try {
|
|
7596
|
-
prerequisitesSource = await
|
|
7791
|
+
prerequisitesSource = await readFile12(absolutePrereq, "utf8");
|
|
7597
7792
|
} catch (error) {
|
|
7598
7793
|
throw new CliUsageError(
|
|
7599
7794
|
`fixer prerequisites path is unreadable: ${options.prerequisitesPath}`,
|
|
@@ -7629,16 +7824,16 @@ async function admitFixerInvocation(options) {
|
|
|
7629
7824
|
const attachments = await freezeAttachments(options.attachmentPaths, attachmentsDirectory);
|
|
7630
7825
|
let prerequisitesPath;
|
|
7631
7826
|
if (prerequisitesSource !== void 0) {
|
|
7632
|
-
prerequisitesPath =
|
|
7633
|
-
await
|
|
7827
|
+
prerequisitesPath = join15(runDirectory, "prerequisites.json");
|
|
7828
|
+
await writeFile6(
|
|
7634
7829
|
prerequisitesPath,
|
|
7635
7830
|
`${JSON.stringify(prerequisites, null, 2)}
|
|
7636
7831
|
`,
|
|
7637
7832
|
"utf8"
|
|
7638
7833
|
);
|
|
7639
7834
|
}
|
|
7640
|
-
const packetPath =
|
|
7641
|
-
await
|
|
7835
|
+
const packetPath = join15(runDirectory, "fix-packet.md");
|
|
7836
|
+
await writeFile6(packetPath, instruction, "utf8");
|
|
7642
7837
|
const admitted = {
|
|
7643
7838
|
role: "fixer",
|
|
7644
7839
|
phase: options.phase,
|
|
@@ -7663,7 +7858,7 @@ async function admitFixerInvocation(options) {
|
|
|
7663
7858
|
mediaKind: a.mediaKind
|
|
7664
7859
|
}))
|
|
7665
7860
|
};
|
|
7666
|
-
const admittedRequestPath =
|
|
7861
|
+
const admittedRequestPath = join15(runDirectory, "admitted-request.json");
|
|
7667
7862
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
7668
7863
|
sessionDirectory,
|
|
7669
7864
|
sessionFile
|
|
@@ -7883,8 +8078,8 @@ async function admitCollectorInvocation(options) {
|
|
|
7883
8078
|
const prNumber = target.kind === "bound" ? target.prNumber : void 0;
|
|
7884
8079
|
let requestManifestPath;
|
|
7885
8080
|
if (manifestCanonicalJson !== void 0) {
|
|
7886
|
-
requestManifestPath =
|
|
7887
|
-
await
|
|
8081
|
+
requestManifestPath = join15(runDirectory, "request-manifest.json");
|
|
8082
|
+
await writeFile6(requestManifestPath, manifestCanonicalJson, "utf8");
|
|
7888
8083
|
}
|
|
7889
8084
|
const admitted = {
|
|
7890
8085
|
role: "collector",
|
|
@@ -7909,7 +8104,7 @@ async function admitCollectorInvocation(options) {
|
|
|
7909
8104
|
mediaKind: a.mediaKind
|
|
7910
8105
|
}))
|
|
7911
8106
|
};
|
|
7912
|
-
const admittedRequestPath =
|
|
8107
|
+
const admittedRequestPath = join15(runDirectory, "admitted-request.json");
|
|
7913
8108
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
7914
8109
|
sessionDirectory,
|
|
7915
8110
|
sessionFile
|
|
@@ -8007,7 +8202,7 @@ function parseDoctorArgv(args) {
|
|
|
8007
8202
|
}
|
|
8008
8203
|
async function resolveDoctorCaseRunsPath(options) {
|
|
8009
8204
|
const ledgerHome = resolveActivationLedgerHome(options.home);
|
|
8010
|
-
const defaultRuns =
|
|
8205
|
+
const defaultRuns = join15(
|
|
8011
8206
|
activationBookDirectory(ledgerHome, options.bookKey),
|
|
8012
8207
|
String(options.issueNumber),
|
|
8013
8208
|
"runs"
|
|
@@ -8138,7 +8333,7 @@ async function admitDoctorInvocation(options) {
|
|
|
8138
8333
|
mediaKind: a.mediaKind
|
|
8139
8334
|
}))
|
|
8140
8335
|
};
|
|
8141
|
-
const admittedRequestPath =
|
|
8336
|
+
const admittedRequestPath = join15(runDirectory, "admitted-request.json");
|
|
8142
8337
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
8143
8338
|
sessionDirectory,
|
|
8144
8339
|
sessionFile
|
|
@@ -8270,7 +8465,7 @@ async function admitNotaryInvocation(options) {
|
|
|
8270
8465
|
...ticketFields,
|
|
8271
8466
|
...options.correlationId === void 0 ? {} : { correlationId: options.correlationId }
|
|
8272
8467
|
};
|
|
8273
|
-
const admittedRequestPath =
|
|
8468
|
+
const admittedRequestPath = join15(runDirectory, "admitted-request.json");
|
|
8274
8469
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
8275
8470
|
sessionDirectory,
|
|
8276
8471
|
sessionFile
|
|
@@ -8373,7 +8568,7 @@ async function admitGleanerLeftInvocation(options) {
|
|
|
8373
8568
|
attachments: [],
|
|
8374
8569
|
...options.correlationId === void 0 ? {} : { correlationId: options.correlationId }
|
|
8375
8570
|
};
|
|
8376
|
-
const admittedRequestPath =
|
|
8571
|
+
const admittedRequestPath = join15(runDirectory, "admitted-request.json");
|
|
8377
8572
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
8378
8573
|
sessionDirectory,
|
|
8379
8574
|
sessionFile
|
|
@@ -8502,7 +8697,7 @@ async function admitReviewerInvocation(options) {
|
|
|
8502
8697
|
mediaKind: a.mediaKind
|
|
8503
8698
|
}))
|
|
8504
8699
|
};
|
|
8505
|
-
const admittedRequestPath =
|
|
8700
|
+
const admittedRequestPath = join15(runDirectory, "admitted-request.json");
|
|
8506
8701
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
8507
8702
|
sessionDirectory,
|
|
8508
8703
|
sessionFile
|
|
@@ -8647,8 +8842,8 @@ async function admitMergerInvocation(options) {
|
|
|
8647
8842
|
resolutionScope: [...derived.resolutionScope],
|
|
8648
8843
|
authorizedChecks: []
|
|
8649
8844
|
});
|
|
8650
|
-
const mergerInputPath =
|
|
8651
|
-
await
|
|
8845
|
+
const mergerInputPath = join15(runDirectory, "merger-input.json");
|
|
8846
|
+
await writeFile6(
|
|
8652
8847
|
mergerInputPath,
|
|
8653
8848
|
`${JSON.stringify(mergerInput, null, 2)}
|
|
8654
8849
|
`,
|
|
@@ -8678,7 +8873,7 @@ async function admitMergerInvocation(options) {
|
|
|
8678
8873
|
mediaKind: a.mediaKind
|
|
8679
8874
|
}))
|
|
8680
8875
|
};
|
|
8681
|
-
const admittedRequestPath =
|
|
8876
|
+
const admittedRequestPath = join15(runDirectory, "admitted-request.json");
|
|
8682
8877
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
8683
8878
|
sessionDirectory,
|
|
8684
8879
|
sessionFile
|
|
@@ -8962,15 +9157,15 @@ var init_invocation = __esm({
|
|
|
8962
9157
|
|
|
8963
9158
|
// src/public-cli/load-production-acp-host.ts
|
|
8964
9159
|
import { existsSync as existsSync6 } from "node:fs";
|
|
8965
|
-
import { join as
|
|
9160
|
+
import { join as join16 } from "node:path";
|
|
8966
9161
|
import { pathToFileURL } from "node:url";
|
|
8967
9162
|
async function loadProductionAcpHostFactory(packageRoot, host) {
|
|
8968
9163
|
const description = lookupHostDescription(host);
|
|
8969
9164
|
if (description === void 0) {
|
|
8970
9165
|
throw new Error(`unregistered host: ${host}`);
|
|
8971
9166
|
}
|
|
8972
|
-
const built =
|
|
8973
|
-
const source =
|
|
9167
|
+
const built = join16(packageRoot, "dist/acp-host/production-host.js");
|
|
9168
|
+
const source = join16(packageRoot, "src/acp-host/production-host.ts");
|
|
8974
9169
|
const target = existsSync6(built) ? built : source;
|
|
8975
9170
|
const href = pathToFileURL(target).href;
|
|
8976
9171
|
const mod = await import(href);
|
|
@@ -8986,15 +9181,15 @@ var init_load_production_acp_host = __esm({
|
|
|
8986
9181
|
|
|
8987
9182
|
// src/public-cli/load-production-headless-host.ts
|
|
8988
9183
|
import { existsSync as existsSync7 } from "node:fs";
|
|
8989
|
-
import { join as
|
|
9184
|
+
import { join as join17 } from "node:path";
|
|
8990
9185
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
8991
9186
|
async function loadProductionHeadlessHostFactory(packageRoot, host) {
|
|
8992
9187
|
const description = lookupHeadlessHostDescription(host);
|
|
8993
9188
|
if (description === void 0) {
|
|
8994
9189
|
throw new Error(`unregistered headless host: ${host}`);
|
|
8995
9190
|
}
|
|
8996
|
-
const built =
|
|
8997
|
-
const source =
|
|
9191
|
+
const built = join17(packageRoot, "dist/headless-host/production-host.js");
|
|
9192
|
+
const source = join17(packageRoot, "src/headless-host/production-host.ts");
|
|
8998
9193
|
const target = existsSync7(built) ? built : source;
|
|
8999
9194
|
const href = pathToFileURL2(target).href;
|
|
9000
9195
|
const mod = await import(href);
|
|
@@ -9133,15 +9328,15 @@ __export(host_providers_exports, {
|
|
|
9133
9328
|
renderHostProvidersTable: () => renderHostProvidersTable
|
|
9134
9329
|
});
|
|
9135
9330
|
import { readFileSync as readFileSync2 } from "node:fs";
|
|
9136
|
-
import { join as
|
|
9331
|
+
import { join as join18 } from "node:path";
|
|
9137
9332
|
function hostProvidersPath(home) {
|
|
9138
9333
|
if (typeof home !== "string" || home.trim() === "") {
|
|
9139
9334
|
throw new Error("home must be explicitly provided");
|
|
9140
9335
|
}
|
|
9141
|
-
return
|
|
9336
|
+
return join18(home, ".ak-roles", "host-providers.json");
|
|
9142
9337
|
}
|
|
9143
9338
|
function hermesProviderModelsCachePath(home) {
|
|
9144
|
-
return
|
|
9339
|
+
return join18(home, ".hermes", "provider_models_cache.json");
|
|
9145
9340
|
}
|
|
9146
9341
|
function parseHostProvidersTable(value) {
|
|
9147
9342
|
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
@@ -9474,8 +9669,8 @@ __export(config_exports, {
|
|
|
9474
9669
|
setPersistentSeatHost: () => setPersistentSeatHost,
|
|
9475
9670
|
validatePublicCliConfigAxes: () => validatePublicCliConfigAxes
|
|
9476
9671
|
});
|
|
9477
|
-
import { mkdir, readFile as
|
|
9478
|
-
import { dirname as
|
|
9672
|
+
import { mkdir, readFile as readFile13, writeFile as writeFile7 } from "node:fs/promises";
|
|
9673
|
+
import { dirname as dirname11, join as join19 } from "node:path";
|
|
9479
9674
|
function isGateOfficerSeat(value) {
|
|
9480
9675
|
return GATE_OFFICER_SEATS.includes(value);
|
|
9481
9676
|
}
|
|
@@ -9483,12 +9678,12 @@ function publicCliConfigPath(home) {
|
|
|
9483
9678
|
if (typeof home !== "string" || home.trim() === "") {
|
|
9484
9679
|
throw new Error("home must be explicitly provided");
|
|
9485
9680
|
}
|
|
9486
|
-
return
|
|
9681
|
+
return join19(home, ".ak-roles", "public-cli.json");
|
|
9487
9682
|
}
|
|
9488
9683
|
async function loadPublicCliConfig(home) {
|
|
9489
9684
|
const path = publicCliConfigPath(home);
|
|
9490
9685
|
try {
|
|
9491
|
-
const raw = await
|
|
9686
|
+
const raw = await readFile13(path, "utf8");
|
|
9492
9687
|
return parsePublicCliConfig(JSON.parse(raw));
|
|
9493
9688
|
} catch (error) {
|
|
9494
9689
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
@@ -9499,9 +9694,9 @@ async function loadPublicCliConfig(home) {
|
|
|
9499
9694
|
}
|
|
9500
9695
|
async function savePublicCliConfig(config, home) {
|
|
9501
9696
|
const path = publicCliConfigPath(home);
|
|
9502
|
-
await mkdir(
|
|
9697
|
+
await mkdir(dirname11(path), { recursive: true });
|
|
9503
9698
|
const normalized = parsePublicCliConfig(config);
|
|
9504
|
-
await
|
|
9699
|
+
await writeFile7(
|
|
9505
9700
|
path,
|
|
9506
9701
|
`${JSON.stringify(serializePublicCliConfig(normalized), null, 2)}
|
|
9507
9702
|
`,
|
|
@@ -9951,7 +10146,7 @@ function credentialProvidersFromAuthData(data) {
|
|
|
9951
10146
|
}
|
|
9952
10147
|
async function loadCredentialProviders(agentDir) {
|
|
9953
10148
|
try {
|
|
9954
|
-
const raw = await
|
|
10149
|
+
const raw = await readFile13(join19(agentDir, "auth.json"), "utf8");
|
|
9955
10150
|
return credentialProvidersFromAuthData(JSON.parse(raw));
|
|
9956
10151
|
} catch (error) {
|
|
9957
10152
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
@@ -10001,17 +10196,17 @@ var init_seat_ticket_binding = __esm({
|
|
|
10001
10196
|
});
|
|
10002
10197
|
|
|
10003
10198
|
// src/session-identity.ts
|
|
10004
|
-
import { mkdir as mkdir2, readFile as
|
|
10005
|
-
import { dirname as
|
|
10199
|
+
import { mkdir as mkdir2, readFile as readFile14, rename as rename3, writeFile as writeFile8 } from "node:fs/promises";
|
|
10200
|
+
import { dirname as dirname12, join as join20 } from "node:path";
|
|
10006
10201
|
function createSessionIdentityAuthority(authority, sessionBindingFile) {
|
|
10007
|
-
const bindingPath = (principal) =>
|
|
10202
|
+
const bindingPath = (principal) => join20(authority.decode(principal).sessionDirectory, sessionBindingFile);
|
|
10008
10203
|
return {
|
|
10009
10204
|
resolveSessionFile(principal) {
|
|
10010
10205
|
return authority.decode(principal).sessionFile;
|
|
10011
10206
|
},
|
|
10012
10207
|
async load(principal) {
|
|
10013
10208
|
try {
|
|
10014
|
-
const value = JSON.parse(await
|
|
10209
|
+
const value = JSON.parse(await readFile14(bindingPath(principal), "utf8"));
|
|
10015
10210
|
if (typeof value !== "object" || value === null || typeof value.sessionId !== "string") {
|
|
10016
10211
|
throw new Error("durable session binding is invalid");
|
|
10017
10212
|
}
|
|
@@ -10023,11 +10218,11 @@ function createSessionIdentityAuthority(authority, sessionBindingFile) {
|
|
|
10023
10218
|
},
|
|
10024
10219
|
async bind(principal, sessionId) {
|
|
10025
10220
|
const target = bindingPath(principal);
|
|
10026
|
-
await mkdir2(
|
|
10221
|
+
await mkdir2(dirname12(target), { recursive: true });
|
|
10027
10222
|
const temporary = `${target}.${process.pid}.tmp`;
|
|
10028
|
-
await
|
|
10223
|
+
await writeFile8(temporary, `${JSON.stringify({ sessionId })}
|
|
10029
10224
|
`, { encoding: "utf8", mode: 384 });
|
|
10030
|
-
await
|
|
10225
|
+
await rename3(temporary, target);
|
|
10031
10226
|
}
|
|
10032
10227
|
};
|
|
10033
10228
|
}
|
|
@@ -10049,254 +10244,539 @@ var init_session_identity = __esm({
|
|
|
10049
10244
|
}
|
|
10050
10245
|
});
|
|
10051
10246
|
|
|
10052
|
-
// src/
|
|
10053
|
-
|
|
10247
|
+
// src/ledger-session-read.ts
|
|
10248
|
+
import { readFile as readFile15 } from "node:fs/promises";
|
|
10249
|
+
function isRecord5(value) {
|
|
10054
10250
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10055
10251
|
}
|
|
10056
|
-
function
|
|
10057
|
-
|
|
10058
|
-
|
|
10059
|
-
|
|
10060
|
-
|
|
10061
|
-
|
|
10062
|
-
|
|
10252
|
+
async function readLedgerSessionJsonlLines(path) {
|
|
10253
|
+
const text = await readFile15(path, "utf8");
|
|
10254
|
+
const lines = text.split("\n");
|
|
10255
|
+
const out = [];
|
|
10256
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
10257
|
+
const raw = lines[index];
|
|
10258
|
+
if (!raw.trim()) continue;
|
|
10259
|
+
const lineNumber = index + 1;
|
|
10260
|
+
let row;
|
|
10261
|
+
try {
|
|
10262
|
+
row = JSON.parse(raw);
|
|
10263
|
+
} catch (error) {
|
|
10264
|
+
if (!(error instanceof SyntaxError)) throw error;
|
|
10265
|
+
const completedByTerminator = index < lines.length - 1;
|
|
10266
|
+
if (!completedByTerminator) break;
|
|
10267
|
+
out.push({
|
|
10268
|
+
line: lineNumber,
|
|
10269
|
+
raw,
|
|
10270
|
+
error: `malformed JSONL record in ${path} at line ${lineNumber}: ${error.message}`
|
|
10271
|
+
});
|
|
10272
|
+
continue;
|
|
10273
|
+
}
|
|
10274
|
+
if (!isRecord5(row)) {
|
|
10275
|
+
const kind = row === null ? "null" : Array.isArray(row) ? "array" : typeof row;
|
|
10276
|
+
out.push({
|
|
10277
|
+
line: lineNumber,
|
|
10278
|
+
raw,
|
|
10279
|
+
error: `complete non-object JSONL record in ${path} at line ${lineNumber}: expected object, got ${kind}`
|
|
10280
|
+
});
|
|
10281
|
+
continue;
|
|
10282
|
+
}
|
|
10283
|
+
out.push({ line: lineNumber, raw, row });
|
|
10063
10284
|
}
|
|
10064
|
-
|
|
10065
|
-
|
|
10285
|
+
return out;
|
|
10286
|
+
}
|
|
10287
|
+
async function readLedgerSessionJsonl(path) {
|
|
10288
|
+
const rows = [];
|
|
10289
|
+
for (const line2 of await readLedgerSessionJsonlLines(path)) {
|
|
10290
|
+
if (line2.row === void 0) {
|
|
10291
|
+
throw new LedgerSessionJsonlError(line2.error ?? `unreadable JSONL record in ${path} at line ${line2.line}`, {
|
|
10292
|
+
path,
|
|
10293
|
+
line: line2.line,
|
|
10294
|
+
prefixRows: rows
|
|
10295
|
+
});
|
|
10296
|
+
}
|
|
10297
|
+
rows.push(line2.row);
|
|
10066
10298
|
}
|
|
10067
|
-
|
|
10068
|
-
|
|
10299
|
+
return rows;
|
|
10300
|
+
}
|
|
10301
|
+
function extractSessionTimestampSpan(rows) {
|
|
10302
|
+
let startedAt;
|
|
10303
|
+
let endedAt;
|
|
10304
|
+
for (const row of rows) {
|
|
10305
|
+
if (typeof row.timestamp !== "string" || !row.timestamp) continue;
|
|
10306
|
+
if (startedAt === void 0) startedAt = row.timestamp;
|
|
10307
|
+
endedAt = row.timestamp;
|
|
10069
10308
|
}
|
|
10070
10309
|
return {
|
|
10071
|
-
|
|
10072
|
-
|
|
10073
|
-
cause: value.cause,
|
|
10074
|
-
recordedAt: value.recordedAt,
|
|
10075
|
-
...typeof value.reason === "string" ? { reason: value.reason } : {}
|
|
10310
|
+
...startedAt !== void 0 ? { startedAt } : {},
|
|
10311
|
+
...endedAt !== void 0 ? { endedAt } : {}
|
|
10076
10312
|
};
|
|
10077
10313
|
}
|
|
10078
|
-
function
|
|
10079
|
-
|
|
10080
|
-
|
|
10081
|
-
|
|
10314
|
+
function intervalRowsAroundAnchor(rows, anchorIndex, isBindingRow) {
|
|
10315
|
+
let start = 0;
|
|
10316
|
+
for (let i = anchorIndex; i >= 0; i -= 1) {
|
|
10317
|
+
if (isBindingRow(rows[i])) {
|
|
10318
|
+
start = i;
|
|
10319
|
+
break;
|
|
10320
|
+
}
|
|
10082
10321
|
}
|
|
10083
|
-
|
|
10084
|
-
|
|
10322
|
+
let end = rows.length;
|
|
10323
|
+
for (let i = Math.max(anchorIndex, start) + 1; i < rows.length; i += 1) {
|
|
10324
|
+
if (isBindingRow(rows[i])) {
|
|
10325
|
+
end = i;
|
|
10326
|
+
break;
|
|
10327
|
+
}
|
|
10085
10328
|
}
|
|
10086
|
-
return
|
|
10329
|
+
return { rows: rows.slice(start, end), closed: end < rows.length };
|
|
10087
10330
|
}
|
|
10088
|
-
var
|
|
10089
|
-
var
|
|
10090
|
-
"src/
|
|
10331
|
+
var LedgerSessionJsonlError;
|
|
10332
|
+
var init_ledger_session_read = __esm({
|
|
10333
|
+
"src/ledger-session-read.ts"() {
|
|
10091
10334
|
"use strict";
|
|
10092
|
-
|
|
10093
|
-
|
|
10094
|
-
|
|
10095
|
-
|
|
10096
|
-
|
|
10097
|
-
|
|
10098
|
-
|
|
10099
|
-
|
|
10335
|
+
LedgerSessionJsonlError = class extends Error {
|
|
10336
|
+
path;
|
|
10337
|
+
line;
|
|
10338
|
+
prefixRows;
|
|
10339
|
+
constructor(message, init) {
|
|
10340
|
+
super(message);
|
|
10341
|
+
this.name = "LedgerSessionJsonlError";
|
|
10342
|
+
this.path = init.path;
|
|
10343
|
+
this.line = init.line;
|
|
10344
|
+
this.prefixRows = init.prefixRows;
|
|
10345
|
+
}
|
|
10346
|
+
};
|
|
10100
10347
|
}
|
|
10101
10348
|
});
|
|
10102
10349
|
|
|
10103
|
-
// src/
|
|
10104
|
-
|
|
10105
|
-
|
|
10106
|
-
|
|
10107
|
-
function
|
|
10108
|
-
|
|
10109
|
-
|
|
10350
|
+
// src/session-dialogue.ts
|
|
10351
|
+
function isRecord6(value) {
|
|
10352
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10353
|
+
}
|
|
10354
|
+
function nativeEventId(row) {
|
|
10355
|
+
for (const key of ["uuid", "id"]) {
|
|
10356
|
+
const value = row[key];
|
|
10357
|
+
if (typeof value === "string" && value !== "") return value;
|
|
10110
10358
|
}
|
|
10111
|
-
|
|
10359
|
+
for (const nestKey of ["message", "payload"]) {
|
|
10360
|
+
const nested = row[nestKey];
|
|
10361
|
+
if (!isRecord6(nested)) continue;
|
|
10362
|
+
for (const key of ["uuid", "id"]) {
|
|
10363
|
+
const value = nested[key];
|
|
10364
|
+
if (typeof value === "string" && value !== "") return value;
|
|
10365
|
+
}
|
|
10366
|
+
}
|
|
10367
|
+
return void 0;
|
|
10112
10368
|
}
|
|
10113
|
-
function
|
|
10114
|
-
|
|
10115
|
-
|
|
10116
|
-
|
|
10117
|
-
|
|
10118
|
-
|
|
10119
|
-
|
|
10120
|
-
|
|
10121
|
-
|
|
10122
|
-
|
|
10123
|
-
|
|
10124
|
-
|
|
10125
|
-
|
|
10126
|
-
|
|
10127
|
-
return
|
|
10128
|
-
}
|
|
10129
|
-
function
|
|
10130
|
-
if (
|
|
10131
|
-
|
|
10132
|
-
|
|
10133
|
-
|
|
10134
|
-
|
|
10135
|
-
|
|
10136
|
-
|
|
10137
|
-
|
|
10138
|
-
|
|
10139
|
-
|
|
10369
|
+
function textParts(content) {
|
|
10370
|
+
if (typeof content === "string") return content === "" ? [] : [content];
|
|
10371
|
+
if (!Array.isArray(content)) return [];
|
|
10372
|
+
const out = [];
|
|
10373
|
+
for (const part of content) {
|
|
10374
|
+
if (!isRecord6(part) || !SPEAKER_TEXT_PART_TYPES.has(String(part.type))) continue;
|
|
10375
|
+
const text = part.text;
|
|
10376
|
+
if (typeof text === "string" && text !== "") out.push(text);
|
|
10377
|
+
}
|
|
10378
|
+
return out;
|
|
10379
|
+
}
|
|
10380
|
+
function responseItemMessage(row) {
|
|
10381
|
+
if (row.type !== "response_item" || !isRecord6(row.payload)) return void 0;
|
|
10382
|
+
if (row.payload.type !== "message") return void 0;
|
|
10383
|
+
return row.payload;
|
|
10384
|
+
}
|
|
10385
|
+
function messageBody(row) {
|
|
10386
|
+
if (isRecord6(row.message)) return row.message;
|
|
10387
|
+
return responseItemMessage(row);
|
|
10388
|
+
}
|
|
10389
|
+
function speakerOf(message) {
|
|
10390
|
+
if (message.role === "assistant") return "runner";
|
|
10391
|
+
if (message.role === "user") return "owner";
|
|
10392
|
+
return void 0;
|
|
10393
|
+
}
|
|
10394
|
+
function codexContentItemKinds(message) {
|
|
10395
|
+
const pass = message.internal_chat_message_metadata_passthrough;
|
|
10396
|
+
if (!isRecord6(pass) || !Array.isArray(pass.content_item_kinds)) return void 0;
|
|
10397
|
+
const kinds = [];
|
|
10398
|
+
for (const kind of pass.content_item_kinds) {
|
|
10399
|
+
if (typeof kind === "string" && kind !== "") kinds.push(kind);
|
|
10400
|
+
}
|
|
10401
|
+
return kinds;
|
|
10402
|
+
}
|
|
10403
|
+
function isCodexOwnerResponseItemUser(message) {
|
|
10404
|
+
if (message.role !== "user") return false;
|
|
10405
|
+
const kinds = codexContentItemKinds(message);
|
|
10406
|
+
if (kinds === void 0) return false;
|
|
10407
|
+
return kinds.some((kind) => kind.startsWith("user."));
|
|
10408
|
+
}
|
|
10409
|
+
function fromQueueEvent(row) {
|
|
10410
|
+
if (row.type !== "queue-operation" || row.operation !== "enqueue") return [];
|
|
10411
|
+
const content = row.content;
|
|
10412
|
+
if (typeof content !== "string" || content === "") return [];
|
|
10413
|
+
const id = nativeEventId(row);
|
|
10414
|
+
return [{ speaker: "owner", text: content, ...id === void 0 ? {} : { id } }];
|
|
10415
|
+
}
|
|
10416
|
+
function fromMessageEvent(row) {
|
|
10417
|
+
const message = messageBody(row);
|
|
10418
|
+
if (message === void 0) return [];
|
|
10419
|
+
if (message.role === "toolResult") return [];
|
|
10420
|
+
const speaker = speakerOf(message);
|
|
10421
|
+
if (speaker === void 0) return [];
|
|
10422
|
+
if (row.type === "response_item" && speaker === "owner") {
|
|
10423
|
+
if (!isCodexOwnerResponseItemUser(message)) return [];
|
|
10424
|
+
}
|
|
10425
|
+
const parts = textParts(message.content);
|
|
10426
|
+
if (parts.length === 0) return [];
|
|
10427
|
+
const text = parts.join("");
|
|
10428
|
+
if (text === "") return [];
|
|
10429
|
+
const id = nativeEventId(row);
|
|
10430
|
+
return [{ speaker, text, ...id === void 0 ? {} : { id } }];
|
|
10431
|
+
}
|
|
10432
|
+
function isOwnerDialogueMessage(row) {
|
|
10433
|
+
if (row.type === "response_item" || row.type === "event_msg") return false;
|
|
10434
|
+
return fromMessageEvent(row).some((event) => event.speaker === "owner");
|
|
10435
|
+
}
|
|
10436
|
+
function isRunnerMessage(row) {
|
|
10437
|
+
const message = messageBody(row);
|
|
10438
|
+
return message !== void 0 && message.role === "assistant";
|
|
10439
|
+
}
|
|
10440
|
+
function ownerMessagesMaterializingQueue(rows) {
|
|
10441
|
+
const skip = /* @__PURE__ */ new Set();
|
|
10442
|
+
const retainedByEnqueue = [];
|
|
10443
|
+
let pendingSkips = 0;
|
|
10444
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
10445
|
+
const row = rows[index];
|
|
10446
|
+
if (row === void 0) continue;
|
|
10447
|
+
if (row.type === "queue-operation") {
|
|
10448
|
+
if (row.operation === "enqueue") {
|
|
10449
|
+
retainedByEnqueue.push(fromQueueEvent(row).length > 0);
|
|
10450
|
+
continue;
|
|
10451
|
+
}
|
|
10452
|
+
if (row.operation === "dequeue" || row.operation === "remove") {
|
|
10453
|
+
const retained = retainedByEnqueue.shift();
|
|
10454
|
+
if (row.operation === "dequeue" && retained === true) {
|
|
10455
|
+
pendingSkips += 1;
|
|
10456
|
+
}
|
|
10457
|
+
continue;
|
|
10458
|
+
}
|
|
10459
|
+
}
|
|
10460
|
+
if (isRunnerMessage(row)) {
|
|
10461
|
+
pendingSkips = 0;
|
|
10462
|
+
continue;
|
|
10463
|
+
}
|
|
10464
|
+
if (pendingSkips > 0 && isOwnerDialogueMessage(row)) {
|
|
10465
|
+
skip.add(index);
|
|
10466
|
+
pendingSkips -= 1;
|
|
10140
10467
|
}
|
|
10141
10468
|
}
|
|
10142
|
-
return
|
|
10469
|
+
return skip;
|
|
10143
10470
|
}
|
|
10144
|
-
function
|
|
10145
|
-
const
|
|
10146
|
-
|
|
10147
|
-
|
|
10148
|
-
|
|
10149
|
-
|
|
10150
|
-
|
|
10151
|
-
|
|
10152
|
-
identity,
|
|
10153
|
-
subject,
|
|
10154
|
-
cwd: input.cwd,
|
|
10155
|
-
sessionParent: input.sessionParent,
|
|
10156
|
-
...input.home === void 0 ? {} : { home: input.home },
|
|
10157
|
-
host: input.host ?? "diarist",
|
|
10158
|
-
source: input.source ?? "diarist",
|
|
10159
|
-
payload: input.payload,
|
|
10160
|
-
raw: sourceRef !== void 0 && typeof sourceRef.sessionFile === "string" && (typeof sourceRef.entryId === "string" || typeof sourceRef.entryId === "number") ? {
|
|
10161
|
-
sessionFile: sourceRef.sessionFile,
|
|
10162
|
-
entryId: sourceRef.entryId
|
|
10163
|
-
} : void 0
|
|
10471
|
+
function adaptSessionDialogue(rows) {
|
|
10472
|
+
const skipOwner = ownerMessagesMaterializingQueue(rows);
|
|
10473
|
+
return rows.map((row, index) => {
|
|
10474
|
+
if (row === void 0) return [];
|
|
10475
|
+
const queued = fromQueueEvent(row);
|
|
10476
|
+
if (queued.length > 0) return queued;
|
|
10477
|
+
if (skipOwner.has(index)) return [];
|
|
10478
|
+
return fromMessageEvent(row);
|
|
10164
10479
|
});
|
|
10165
10480
|
}
|
|
10166
|
-
|
|
10167
|
-
|
|
10481
|
+
var SPEAKER_TEXT_PART_TYPES;
|
|
10482
|
+
var init_session_dialogue = __esm({
|
|
10483
|
+
"src/session-dialogue.ts"() {
|
|
10484
|
+
"use strict";
|
|
10485
|
+
SPEAKER_TEXT_PART_TYPES = /* @__PURE__ */ new Set(["text", "input_text", "output_text"]);
|
|
10486
|
+
}
|
|
10487
|
+
});
|
|
10488
|
+
|
|
10489
|
+
// src/ticket-provenance.ts
|
|
10490
|
+
import { basename as basename7, dirname as dirname13, join as join21, resolve as resolve10 } from "node:path";
|
|
10491
|
+
function dialogueSessionSourceRoots(home) {
|
|
10492
|
+
const machineHome = typeof home === "string" && home.trim() !== "" ? home : packageMachineHome();
|
|
10493
|
+
return [
|
|
10494
|
+
join21(machineHome, ".claude", "projects"),
|
|
10495
|
+
join21(machineHome, ".codex", "sessions"),
|
|
10496
|
+
join21(machineHome, ".pi", "agent", "sessions")
|
|
10497
|
+
];
|
|
10498
|
+
}
|
|
10499
|
+
function isLedgerRoleSessionFile(absolute, home) {
|
|
10500
|
+
const machineHome = typeof home === "string" && home.trim() !== "" ? home : packageMachineHome();
|
|
10501
|
+
const ledgerHome = resolveActivationLedgerHome(machineHome);
|
|
10502
|
+
if (!physicallyContainedIn(ledgerHome, absolute)) return false;
|
|
10503
|
+
return basename7(absolute) === "session.jsonl" && basename7(dirname13(absolute)) === "session";
|
|
10504
|
+
}
|
|
10505
|
+
function assertDialogueSessionSourcePath(path, home) {
|
|
10506
|
+
const absolute = resolve10(path);
|
|
10507
|
+
for (const root of dialogueSessionSourceRoots(home)) {
|
|
10508
|
+
if (physicallyContainedIn(root, absolute)) return;
|
|
10509
|
+
}
|
|
10510
|
+
if (isLedgerRoleSessionFile(absolute, home)) return;
|
|
10511
|
+
throw new TicketProvenanceInputError(
|
|
10512
|
+
`session unreadable: ${path} (outside authorized source roots)`
|
|
10513
|
+
);
|
|
10514
|
+
}
|
|
10515
|
+
function ticketProvenanceSubject(ticketNumber) {
|
|
10516
|
+
if (!isSafePositiveTicketNumber(ticketNumber)) {
|
|
10517
|
+
throw new Error(
|
|
10518
|
+
`ticket-provenance subject requires a positive ticket number, got ${String(ticketNumber)}`
|
|
10519
|
+
);
|
|
10520
|
+
}
|
|
10521
|
+
return String(ticketNumber);
|
|
10522
|
+
}
|
|
10523
|
+
function ticketProvenanceRecordInput(ticketNumber, cwd, home) {
|
|
10524
|
+
return {
|
|
10168
10525
|
level: "event",
|
|
10169
10526
|
kind: TICKET_PROVENANCE_KIND,
|
|
10170
10527
|
subject: ticketProvenanceSubject(ticketNumber),
|
|
10171
10528
|
cwd,
|
|
10172
10529
|
...home === void 0 ? {} : { home }
|
|
10173
|
-
});
|
|
10174
|
-
return {
|
|
10175
|
-
recordFile: path.recordFile,
|
|
10176
|
-
volumeDir: path.sessionDir,
|
|
10177
|
-
humanViewFile: join20(path.sessionDir, TICKET_PROVENANCE_HUMAN_VIEW)
|
|
10178
10530
|
};
|
|
10179
10531
|
}
|
|
10532
|
+
function resolveTicketProvenanceVolume(ticketNumber, cwd, home) {
|
|
10533
|
+
return resolveSitianVolume(ticketProvenanceRecordInput(ticketNumber, cwd, home));
|
|
10534
|
+
}
|
|
10180
10535
|
async function readTicketProvenance(ticketNumber, cwd, home) {
|
|
10181
|
-
const { recordFile } =
|
|
10182
|
-
|
|
10183
|
-
|
|
10184
|
-
|
|
10185
|
-
|
|
10186
|
-
|
|
10187
|
-
|
|
10188
|
-
|
|
10189
|
-
|
|
10190
|
-
|
|
10191
|
-
|
|
10192
|
-
const
|
|
10193
|
-
if (
|
|
10194
|
-
|
|
10536
|
+
const { recordFile, text } = await readSitianVolumeText(
|
|
10537
|
+
ticketProvenanceRecordInput(ticketNumber, cwd, home)
|
|
10538
|
+
);
|
|
10539
|
+
if (text === void 0) {
|
|
10540
|
+
return { header: void 0, lines: [], recordFile };
|
|
10541
|
+
}
|
|
10542
|
+
const physical = text.split("\n");
|
|
10543
|
+
let header;
|
|
10544
|
+
const lines = [];
|
|
10545
|
+
let sawFirst = false;
|
|
10546
|
+
for (let index = 0; index < physical.length; index += 1) {
|
|
10547
|
+
const raw = physical[index];
|
|
10548
|
+
if (!raw.trim()) continue;
|
|
10549
|
+
let parsed;
|
|
10550
|
+
try {
|
|
10551
|
+
parsed = JSON.parse(raw);
|
|
10552
|
+
} catch {
|
|
10195
10553
|
continue;
|
|
10196
10554
|
}
|
|
10197
|
-
|
|
10198
|
-
|
|
10199
|
-
|
|
10200
|
-
continue;
|
|
10555
|
+
if (!sawFirst) {
|
|
10556
|
+
sawFirst = true;
|
|
10557
|
+
header = projectTicketProvenanceHeader(parsed);
|
|
10558
|
+
if (header !== void 0) continue;
|
|
10201
10559
|
}
|
|
10202
|
-
|
|
10560
|
+
const line2 = projectTicketProvenanceLine(parsed);
|
|
10561
|
+
if (line2 !== void 0) lines.push(line2);
|
|
10203
10562
|
}
|
|
10204
|
-
return {
|
|
10563
|
+
return { header, lines, recordFile };
|
|
10205
10564
|
}
|
|
10206
|
-
function
|
|
10207
|
-
|
|
10208
|
-
|
|
10209
|
-
|
|
10210
|
-
|
|
10211
|
-
if (
|
|
10565
|
+
function resolveBoundIndex(bound, sessionLines) {
|
|
10566
|
+
if (typeof bound.id === "string" && bound.id !== "") {
|
|
10567
|
+
for (let index = 0; index < sessionLines.length; index += 1) {
|
|
10568
|
+
const row = sessionLines[index].row;
|
|
10569
|
+
if (row === void 0) continue;
|
|
10570
|
+
if (nativeEventId(row) === bound.id) return index;
|
|
10212
10571
|
}
|
|
10572
|
+
return void 0;
|
|
10213
10573
|
}
|
|
10214
|
-
|
|
10215
|
-
|
|
10216
|
-
|
|
10217
|
-
const unprojected = input.unprojected ?? [];
|
|
10218
|
-
const lines = [
|
|
10219
|
-
`# \u8D77\u5C45\u5F55 \xB7 #${input.ticketNumber}`,
|
|
10220
|
-
"",
|
|
10221
|
-
`\u6761\u76EE\u6570\uFF1A${input.entries.length + unprojected.length}`,
|
|
10222
|
-
""
|
|
10223
|
-
];
|
|
10224
|
-
let index = 0;
|
|
10225
|
-
for (const entry of input.entries) {
|
|
10226
|
-
index += 1;
|
|
10227
|
-
const sourceKind = typeof entry.sourceKind === "string" ? entry.sourceKind : "\u672A\u6295\u5F71";
|
|
10228
|
-
const timestamp2 = typeof entry.timestamp === "string" ? entry.timestamp : "";
|
|
10229
|
-
lines.push(`## ${index}. ${sourceKind} \xB7 ${timestamp2}`);
|
|
10230
|
-
lines.push("");
|
|
10231
|
-
const basis = entry.basis;
|
|
10232
|
-
const method = typeof basis === "object" && basis !== null && !Array.isArray(basis) && typeof basis.method === "string" ? basis.method : "\u672A\u6295\u5F71";
|
|
10233
|
-
lines.push(`- basis.method: \`${method}\``);
|
|
10234
|
-
if (typeof basis === "object" && basis !== null && !Array.isArray(basis) && Array.isArray(basis.anchors) && basis.anchors.length > 0) {
|
|
10235
|
-
lines.push(`- anchors: ${basis.anchors.map((a) => `\`${String(a)}\``).join(", ")}`);
|
|
10574
|
+
if (typeof bound.line === "number") {
|
|
10575
|
+
for (let index = 0; index < sessionLines.length; index += 1) {
|
|
10576
|
+
if (sessionLines[index].line === bound.line) return index;
|
|
10236
10577
|
}
|
|
10237
|
-
|
|
10238
|
-
|
|
10578
|
+
return void 0;
|
|
10579
|
+
}
|
|
10580
|
+
return void 0;
|
|
10581
|
+
}
|
|
10582
|
+
function amendmentKey(s, line2) {
|
|
10583
|
+
return `${s}:${line2}`;
|
|
10584
|
+
}
|
|
10585
|
+
function normalizeResolvedRanges(ranges, sessionLines, sessionPath) {
|
|
10586
|
+
const resolved = [];
|
|
10587
|
+
for (const range of ranges) {
|
|
10588
|
+
const fromIndex = resolveBoundIndex(range.from, sessionLines);
|
|
10589
|
+
const toIndex = resolveBoundIndex(range.to, sessionLines);
|
|
10590
|
+
if (fromIndex === void 0 || toIndex === void 0) {
|
|
10591
|
+
throw new TicketProvenanceInputError(
|
|
10592
|
+
`bound endpoint not found in ${sessionPath} (from=${JSON.stringify(range.from)} to=${JSON.stringify(range.to)})`
|
|
10593
|
+
);
|
|
10239
10594
|
}
|
|
10240
|
-
|
|
10241
|
-
|
|
10242
|
-
|
|
10243
|
-
|
|
10595
|
+
if (fromIndex > toIndex) {
|
|
10596
|
+
throw new TicketProvenanceInputError(
|
|
10597
|
+
`bound range inverted in ${sessionPath} (from index ${fromIndex} > to index ${toIndex})`
|
|
10598
|
+
);
|
|
10244
10599
|
}
|
|
10245
|
-
|
|
10246
|
-
|
|
10600
|
+
resolved.push({ fromIndex, toIndex });
|
|
10601
|
+
}
|
|
10602
|
+
resolved.sort(
|
|
10603
|
+
(left, right) => left.fromIndex - right.fromIndex || left.toIndex - right.toIndex
|
|
10604
|
+
);
|
|
10605
|
+
const merged = [];
|
|
10606
|
+
for (const range of resolved) {
|
|
10607
|
+
const last = merged[merged.length - 1];
|
|
10608
|
+
if (last !== void 0 && range.fromIndex <= last.toIndex + 1) {
|
|
10609
|
+
last.toIndex = Math.max(last.toIndex, range.toIndex);
|
|
10610
|
+
continue;
|
|
10247
10611
|
}
|
|
10248
|
-
|
|
10249
|
-
|
|
10612
|
+
merged.push({ fromIndex: range.fromIndex, toIndex: range.toIndex });
|
|
10613
|
+
}
|
|
10614
|
+
return merged;
|
|
10615
|
+
}
|
|
10616
|
+
async function projectSessionRanges(input) {
|
|
10617
|
+
assertDialogueSessionSourcePath(input.session.path, input.home);
|
|
10618
|
+
let sessionLines;
|
|
10619
|
+
try {
|
|
10620
|
+
sessionLines = await readLedgerSessionJsonlLines(input.session.path);
|
|
10621
|
+
} catch (error) {
|
|
10622
|
+
if (error instanceof TicketProvenanceInputError) throw error;
|
|
10623
|
+
const code = errnoCode(error);
|
|
10624
|
+
if (code === "ENOENT" || code === "ENOTDIR" || code === "EISDIR") {
|
|
10625
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
10626
|
+
throw new TicketProvenanceInputError(
|
|
10627
|
+
`session unreadable: ${input.session.path} (${detail})`,
|
|
10628
|
+
{ cause: error }
|
|
10629
|
+
);
|
|
10250
10630
|
}
|
|
10251
|
-
|
|
10252
|
-
|
|
10631
|
+
throw error;
|
|
10632
|
+
}
|
|
10633
|
+
const rows = sessionLines.map((entry) => entry.row);
|
|
10634
|
+
const dialogue = adaptSessionDialogue(rows);
|
|
10635
|
+
const seenIds = input.seenIds;
|
|
10636
|
+
const lines = [];
|
|
10637
|
+
const unparsable = [];
|
|
10638
|
+
const ranges = normalizeResolvedRanges(
|
|
10639
|
+
input.session.ranges,
|
|
10640
|
+
sessionLines,
|
|
10641
|
+
input.session.path
|
|
10642
|
+
);
|
|
10643
|
+
for (const range of ranges) {
|
|
10644
|
+
for (let index = range.fromIndex; index <= range.toIndex; index += 1) {
|
|
10645
|
+
const entry = sessionLines[index];
|
|
10646
|
+
if (entry.row === void 0) {
|
|
10647
|
+
const key = amendmentKey(input.s, entry.line);
|
|
10648
|
+
const amendment = input.amendmentsByKey.get(key);
|
|
10649
|
+
if (amendment !== void 0) {
|
|
10650
|
+
lines.push({
|
|
10651
|
+
speaker: amendment.speaker,
|
|
10652
|
+
s: input.s,
|
|
10653
|
+
line: entry.line,
|
|
10654
|
+
text: amendment.text
|
|
10655
|
+
});
|
|
10656
|
+
} else {
|
|
10657
|
+
unparsable.push({ s: input.s, line: entry.line, raw: entry.raw });
|
|
10658
|
+
}
|
|
10659
|
+
continue;
|
|
10660
|
+
}
|
|
10661
|
+
for (const event of dialogue[index] ?? []) {
|
|
10662
|
+
if (event.id !== void 0) {
|
|
10663
|
+
if (seenIds.has(event.id)) continue;
|
|
10664
|
+
seenIds.add(event.id);
|
|
10665
|
+
}
|
|
10666
|
+
lines.push({
|
|
10667
|
+
speaker: event.speaker,
|
|
10668
|
+
s: input.s,
|
|
10669
|
+
line: entry.line,
|
|
10670
|
+
...event.id === void 0 ? {} : { id: event.id },
|
|
10671
|
+
text: event.text
|
|
10672
|
+
});
|
|
10673
|
+
}
|
|
10253
10674
|
}
|
|
10254
|
-
|
|
10255
|
-
|
|
10675
|
+
}
|
|
10676
|
+
return { lines, unparsable };
|
|
10677
|
+
}
|
|
10678
|
+
async function reprojectTicketProvenance(input) {
|
|
10679
|
+
const recordInput = ticketProvenanceRecordInput(
|
|
10680
|
+
input.ticketNumber,
|
|
10681
|
+
input.cwd,
|
|
10682
|
+
input.home
|
|
10683
|
+
);
|
|
10684
|
+
const prior = await readTicketProvenance(input.ticketNumber, input.cwd, input.home);
|
|
10685
|
+
const priorRaw = await readSitianVolumeText(recordInput);
|
|
10686
|
+
const priorNonEmpty = priorRaw.text !== void 0 && priorRaw.text.trim() !== "";
|
|
10687
|
+
const amendments = input.amendments ?? [];
|
|
10688
|
+
let sessions = input.sessions;
|
|
10689
|
+
if (sessions.length === 0) {
|
|
10690
|
+
if (amendments.length > 0) {
|
|
10691
|
+
const priorSessions = prior.header?.sessions;
|
|
10692
|
+
if (priorSessions === void 0 || priorSessions.length === 0) {
|
|
10693
|
+
throw new TicketProvenanceInputError(
|
|
10694
|
+
"amendments require sessions bounds (none submitted and no prior header sessions)"
|
|
10695
|
+
);
|
|
10696
|
+
}
|
|
10697
|
+
sessions = priorSessions;
|
|
10698
|
+
} else if (priorNonEmpty) {
|
|
10699
|
+
const now2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
10700
|
+
const header2 = prior.header ?? {
|
|
10701
|
+
repo: resolveBookKeyFromGit(input.cwd),
|
|
10702
|
+
ticket: input.ticketNumber,
|
|
10703
|
+
createdAt: now2,
|
|
10704
|
+
updatedAt: now2,
|
|
10705
|
+
sessions: []
|
|
10706
|
+
};
|
|
10707
|
+
return {
|
|
10708
|
+
recordFile: prior.recordFile,
|
|
10709
|
+
header: header2,
|
|
10710
|
+
lines: prior.lines,
|
|
10711
|
+
unparsable: []
|
|
10712
|
+
};
|
|
10256
10713
|
}
|
|
10257
|
-
lines.push("");
|
|
10258
|
-
const transcript = typeof entry.transcript === "string" ? entry.transcript : JSON.stringify(entry);
|
|
10259
|
-
const fence = markdownFenceFor(transcript);
|
|
10260
|
-
lines.push(fence);
|
|
10261
|
-
lines.push(transcript);
|
|
10262
|
-
lines.push(fence);
|
|
10263
|
-
lines.push("");
|
|
10264
10714
|
}
|
|
10265
|
-
|
|
10266
|
-
|
|
10267
|
-
|
|
10268
|
-
lines.push("");
|
|
10269
|
-
const text = typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
10270
|
-
const fence = markdownFenceFor(text);
|
|
10271
|
-
lines.push(fence);
|
|
10272
|
-
lines.push(text);
|
|
10273
|
-
lines.push(fence);
|
|
10274
|
-
lines.push("");
|
|
10715
|
+
const amendmentsByKey = /* @__PURE__ */ new Map();
|
|
10716
|
+
for (const amendment of amendments) {
|
|
10717
|
+
amendmentsByKey.set(amendmentKey(amendment.s, amendment.line), amendment);
|
|
10275
10718
|
}
|
|
10276
|
-
|
|
10277
|
-
|
|
10278
|
-
|
|
10279
|
-
|
|
10280
|
-
|
|
10281
|
-
|
|
10282
|
-
|
|
10283
|
-
|
|
10284
|
-
|
|
10285
|
-
|
|
10286
|
-
|
|
10287
|
-
|
|
10288
|
-
|
|
10289
|
-
|
|
10290
|
-
|
|
10291
|
-
|
|
10292
|
-
|
|
10719
|
+
const lines = [];
|
|
10720
|
+
const unparsable = [];
|
|
10721
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
10722
|
+
for (let s = 0; s < sessions.length; s += 1) {
|
|
10723
|
+
const projected = await projectSessionRanges({
|
|
10724
|
+
s,
|
|
10725
|
+
session: sessions[s],
|
|
10726
|
+
amendmentsByKey,
|
|
10727
|
+
seenIds,
|
|
10728
|
+
...input.home === void 0 ? {} : { home: input.home }
|
|
10729
|
+
});
|
|
10730
|
+
lines.push(...projected.lines);
|
|
10731
|
+
unparsable.push(...projected.unparsable);
|
|
10732
|
+
}
|
|
10733
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
10734
|
+
const header = {
|
|
10735
|
+
repo: resolveBookKeyFromGit(input.cwd),
|
|
10736
|
+
ticket: input.ticketNumber,
|
|
10737
|
+
createdAt: prior.header?.createdAt ?? now,
|
|
10738
|
+
updatedAt: now,
|
|
10739
|
+
sessions
|
|
10740
|
+
};
|
|
10741
|
+
if (unparsable.length > 0) {
|
|
10742
|
+
return {
|
|
10743
|
+
recordFile: prior.recordFile,
|
|
10744
|
+
header,
|
|
10745
|
+
lines,
|
|
10746
|
+
unparsable
|
|
10747
|
+
};
|
|
10748
|
+
}
|
|
10749
|
+
const body = `${[JSON.stringify(header), ...lines.map((line2) => JSON.stringify(line2))].join("\n")}
|
|
10750
|
+
`;
|
|
10751
|
+
const volume = await rewriteSitianVolume({ ...recordInput, body });
|
|
10752
|
+
return {
|
|
10753
|
+
recordFile: volume.recordFile,
|
|
10754
|
+
header,
|
|
10755
|
+
lines,
|
|
10756
|
+
unparsable
|
|
10757
|
+
};
|
|
10293
10758
|
}
|
|
10759
|
+
var TicketProvenanceInputError;
|
|
10294
10760
|
var init_ticket_provenance = __esm({
|
|
10295
10761
|
"src/ticket-provenance.ts"() {
|
|
10296
10762
|
"use strict";
|
|
10297
|
-
|
|
10763
|
+
init_activation_ledger_git();
|
|
10764
|
+
init_activation_ledger_topology();
|
|
10765
|
+
init_ledger_session_read();
|
|
10298
10766
|
init_run_ticket_number();
|
|
10767
|
+
init_session_dialogue();
|
|
10768
|
+
init_sitian_facade();
|
|
10299
10769
|
init_ticket_provenance_contracts();
|
|
10770
|
+
TicketProvenanceInputError = class extends Error {
|
|
10771
|
+
code = "ticket-provenance-input";
|
|
10772
|
+
constructor(message, options) {
|
|
10773
|
+
super(
|
|
10774
|
+
message,
|
|
10775
|
+
options?.cause === void 0 ? void 0 : { cause: options.cause }
|
|
10776
|
+
);
|
|
10777
|
+
this.name = "TicketProvenanceInputError";
|
|
10778
|
+
}
|
|
10779
|
+
};
|
|
10300
10780
|
}
|
|
10301
10781
|
});
|
|
10302
10782
|
|
|
@@ -10307,9 +10787,9 @@ __export(case_dossier_delivery_exports, {
|
|
|
10307
10787
|
loadCaseDossierReadingMaterial: () => loadCaseDossierReadingMaterial,
|
|
10308
10788
|
projectCaseDossierPointerSection: () => projectCaseDossierPointerSection
|
|
10309
10789
|
});
|
|
10310
|
-
import { mkdtemp as mkdtemp2, readFile as
|
|
10790
|
+
import { mkdtemp as mkdtemp2, readFile as readFile16, rm as rm3, writeFile as writeFile9 } from "node:fs/promises";
|
|
10311
10791
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
10312
|
-
import { join as
|
|
10792
|
+
import { join as join22 } from "node:path";
|
|
10313
10793
|
function describeDossierFile(path) {
|
|
10314
10794
|
return path;
|
|
10315
10795
|
}
|
|
@@ -10324,7 +10804,6 @@ async function projectCaseDossierPointerSection(input) {
|
|
|
10324
10804
|
CASE_DOSSIER_SECTION_HEADING,
|
|
10325
10805
|
"",
|
|
10326
10806
|
`\u7968\u53F7\uFF1A#${input.ticketNumber}`,
|
|
10327
|
-
`\u4EBA\u8BFB\u89C6\u56FE\uFF1A${describeDossierFile(volume.humanViewFile)}`,
|
|
10328
10807
|
`\u8BB0\u5F55\u5377\u5B97\uFF1A${describeDossierFile(volume.recordFile)}`
|
|
10329
10808
|
].join("\n");
|
|
10330
10809
|
}
|
|
@@ -10335,10 +10814,10 @@ async function deliverCaseDossierAsAttachment(input) {
|
|
|
10335
10814
|
home: input.home
|
|
10336
10815
|
});
|
|
10337
10816
|
if (section === void 0) return void 0;
|
|
10338
|
-
const stagingDir = await mkdtemp2(
|
|
10817
|
+
const stagingDir = await mkdtemp2(join22(tmpdir2(), "ak-case-dossier-"));
|
|
10339
10818
|
try {
|
|
10340
|
-
const stagingPath =
|
|
10341
|
-
await
|
|
10819
|
+
const stagingPath = join22(stagingDir, CASE_DOSSIER_ATTACH_FILE);
|
|
10820
|
+
await writeFile9(stagingPath, `${section}
|
|
10342
10821
|
`, "utf8");
|
|
10343
10822
|
return await freezeAttachmentsIntoRun(
|
|
10344
10823
|
[stagingPath],
|
|
@@ -10346,11 +10825,11 @@ async function deliverCaseDossierAsAttachment(input) {
|
|
|
10346
10825
|
CASE_DOSSIER_ATTACH_KEY
|
|
10347
10826
|
);
|
|
10348
10827
|
} finally {
|
|
10349
|
-
await
|
|
10828
|
+
await rm3(stagingDir, { recursive: true, force: true });
|
|
10350
10829
|
}
|
|
10351
10830
|
}
|
|
10352
10831
|
async function loadCaseDossierReadingMaterial(runDirectory) {
|
|
10353
|
-
const frozenPath =
|
|
10832
|
+
const frozenPath = join22(
|
|
10354
10833
|
runDirectory,
|
|
10355
10834
|
"attachments",
|
|
10356
10835
|
CASE_DOSSIER_ATTACH_KEY,
|
|
@@ -10358,7 +10837,7 @@ async function loadCaseDossierReadingMaterial(runDirectory) {
|
|
|
10358
10837
|
);
|
|
10359
10838
|
let section;
|
|
10360
10839
|
try {
|
|
10361
|
-
section = await
|
|
10840
|
+
section = await readFile16(frozenPath, "utf8");
|
|
10362
10841
|
} catch (error) {
|
|
10363
10842
|
if (error.code === "ENOENT") return void 0;
|
|
10364
10843
|
throw error;
|
|
@@ -10380,7 +10859,7 @@ var init_case_dossier_delivery = __esm({
|
|
|
10380
10859
|
|
|
10381
10860
|
// src/host-transition-prior-native.ts
|
|
10382
10861
|
import { access as access3, readdir as readdir5 } from "node:fs/promises";
|
|
10383
|
-
import { dirname as
|
|
10862
|
+
import { dirname as dirname14, join as join23 } from "node:path";
|
|
10384
10863
|
function isEnoent3(error) {
|
|
10385
10864
|
return typeof error === "object" && error !== null && error.code === "ENOENT";
|
|
10386
10865
|
}
|
|
@@ -10394,7 +10873,7 @@ async function listPiNativeRecordPaths(sessionFile) {
|
|
|
10394
10873
|
}
|
|
10395
10874
|
}
|
|
10396
10875
|
async function listSitianRecordPaths(sessionParent) {
|
|
10397
|
-
const sessionRoot =
|
|
10876
|
+
const sessionRoot = dirname14(sessionParent);
|
|
10398
10877
|
let entries;
|
|
10399
10878
|
try {
|
|
10400
10879
|
entries = await readdir5(sessionRoot, { withFileTypes: true });
|
|
@@ -10405,7 +10884,7 @@ async function listSitianRecordPaths(sessionParent) {
|
|
|
10405
10884
|
const recordPaths = [];
|
|
10406
10885
|
for (const entry of entries) {
|
|
10407
10886
|
if (!entry.isDirectory()) continue;
|
|
10408
|
-
const recordFile =
|
|
10887
|
+
const recordFile = join23(sessionRoot, entry.name, "records.jsonl");
|
|
10409
10888
|
try {
|
|
10410
10889
|
await access3(recordFile);
|
|
10411
10890
|
recordPaths.push(recordFile);
|
|
@@ -10796,13 +11275,13 @@ var init_reviewer_dispatch = __esm({
|
|
|
10796
11275
|
});
|
|
10797
11276
|
|
|
10798
11277
|
// src/public-cli/reviewer-dispatch-rejection.ts
|
|
10799
|
-
import { readFile as
|
|
10800
|
-
import { join as
|
|
11278
|
+
import { readFile as readFile17, unlink as unlink3 } from "node:fs/promises";
|
|
11279
|
+
import { join as join24 } from "node:path";
|
|
10801
11280
|
function isReviewerPreflightViolation(value) {
|
|
10802
11281
|
return typeof value === "string" && REVIEWER_PREFLIGHT_VIOLATIONS.includes(value);
|
|
10803
11282
|
}
|
|
10804
11283
|
function reviewerDispatchRejectionPath(runDirectory) {
|
|
10805
|
-
return
|
|
11284
|
+
return join24(runDirectory, REVIEWER_DISPATCH_REJECTION_FILE);
|
|
10806
11285
|
}
|
|
10807
11286
|
async function clearReviewerDispatchRejection(runDirectory) {
|
|
10808
11287
|
try {
|
|
@@ -10817,7 +11296,7 @@ async function clearReviewerDispatchRejection(runDirectory) {
|
|
|
10817
11296
|
async function readReviewerDispatchRejection(runDirectory) {
|
|
10818
11297
|
let raw;
|
|
10819
11298
|
try {
|
|
10820
|
-
raw = await
|
|
11299
|
+
raw = await readFile17(reviewerDispatchRejectionPath(runDirectory), "utf8");
|
|
10821
11300
|
} catch (error) {
|
|
10822
11301
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
10823
11302
|
return void 0;
|
|
@@ -10852,96 +11331,10 @@ var init_reviewer_dispatch_rejection = __esm({
|
|
|
10852
11331
|
}
|
|
10853
11332
|
});
|
|
10854
11333
|
|
|
10855
|
-
// src/ledger-session-read.ts
|
|
10856
|
-
import { readFile as readFile16 } from "node:fs/promises";
|
|
10857
|
-
function isRecord5(value) {
|
|
10858
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10859
|
-
}
|
|
10860
|
-
async function readLedgerSessionJsonl(path) {
|
|
10861
|
-
const text = await readFile16(path, "utf8");
|
|
10862
|
-
const lines = text.split("\n");
|
|
10863
|
-
const rows = [];
|
|
10864
|
-
for (let index = 0; index < lines.length; index += 1) {
|
|
10865
|
-
const line2 = lines[index];
|
|
10866
|
-
if (!line2.trim()) continue;
|
|
10867
|
-
let row;
|
|
10868
|
-
try {
|
|
10869
|
-
row = JSON.parse(line2);
|
|
10870
|
-
} catch (error) {
|
|
10871
|
-
if (!(error instanceof SyntaxError)) throw error;
|
|
10872
|
-
const completedByTerminator = index < lines.length - 1;
|
|
10873
|
-
if (completedByTerminator) {
|
|
10874
|
-
throw new LedgerSessionJsonlError(
|
|
10875
|
-
`malformed JSONL record in ${path} at line ${index + 1}: ${error.message}`,
|
|
10876
|
-
{ path, line: index + 1, prefixRows: rows }
|
|
10877
|
-
);
|
|
10878
|
-
}
|
|
10879
|
-
break;
|
|
10880
|
-
}
|
|
10881
|
-
if (!isRecord5(row)) {
|
|
10882
|
-
const kind = row === null ? "null" : Array.isArray(row) ? "array" : typeof row;
|
|
10883
|
-
throw new LedgerSessionJsonlError(
|
|
10884
|
-
`complete non-object JSONL record in ${path} at line ${index + 1}: expected object, got ${kind}`,
|
|
10885
|
-
{ path, line: index + 1, prefixRows: rows }
|
|
10886
|
-
);
|
|
10887
|
-
}
|
|
10888
|
-
rows.push(row);
|
|
10889
|
-
}
|
|
10890
|
-
return rows;
|
|
10891
|
-
}
|
|
10892
|
-
function extractSessionTimestampSpan(rows) {
|
|
10893
|
-
let startedAt;
|
|
10894
|
-
let endedAt;
|
|
10895
|
-
for (const row of rows) {
|
|
10896
|
-
if (typeof row.timestamp !== "string" || !row.timestamp) continue;
|
|
10897
|
-
if (startedAt === void 0) startedAt = row.timestamp;
|
|
10898
|
-
endedAt = row.timestamp;
|
|
10899
|
-
}
|
|
10900
|
-
return {
|
|
10901
|
-
...startedAt !== void 0 ? { startedAt } : {},
|
|
10902
|
-
...endedAt !== void 0 ? { endedAt } : {}
|
|
10903
|
-
};
|
|
10904
|
-
}
|
|
10905
|
-
function intervalRowsAroundAnchor(rows, anchorIndex, isBindingRow) {
|
|
10906
|
-
let start = 0;
|
|
10907
|
-
for (let i = anchorIndex; i >= 0; i -= 1) {
|
|
10908
|
-
if (isBindingRow(rows[i])) {
|
|
10909
|
-
start = i;
|
|
10910
|
-
break;
|
|
10911
|
-
}
|
|
10912
|
-
}
|
|
10913
|
-
let end = rows.length;
|
|
10914
|
-
for (let i = Math.max(anchorIndex, start) + 1; i < rows.length; i += 1) {
|
|
10915
|
-
if (isBindingRow(rows[i])) {
|
|
10916
|
-
end = i;
|
|
10917
|
-
break;
|
|
10918
|
-
}
|
|
10919
|
-
}
|
|
10920
|
-
return { rows: rows.slice(start, end), closed: end < rows.length };
|
|
10921
|
-
}
|
|
10922
|
-
var LedgerSessionJsonlError;
|
|
10923
|
-
var init_ledger_session_read = __esm({
|
|
10924
|
-
"src/ledger-session-read.ts"() {
|
|
10925
|
-
"use strict";
|
|
10926
|
-
LedgerSessionJsonlError = class extends Error {
|
|
10927
|
-
path;
|
|
10928
|
-
line;
|
|
10929
|
-
prefixRows;
|
|
10930
|
-
constructor(message, init) {
|
|
10931
|
-
super(message);
|
|
10932
|
-
this.name = "LedgerSessionJsonlError";
|
|
10933
|
-
this.path = init.path;
|
|
10934
|
-
this.line = init.line;
|
|
10935
|
-
this.prefixRows = init.prefixRows;
|
|
10936
|
-
}
|
|
10937
|
-
};
|
|
10938
|
-
}
|
|
10939
|
-
});
|
|
10940
|
-
|
|
10941
11334
|
// src/analyst-gate-cycles-read.ts
|
|
10942
11335
|
import { readdir as readdir6 } from "node:fs/promises";
|
|
10943
|
-
import { join as
|
|
10944
|
-
function
|
|
11336
|
+
import { join as join25 } from "node:path";
|
|
11337
|
+
function isRecord7(value) {
|
|
10945
11338
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10946
11339
|
}
|
|
10947
11340
|
function isParentAttemptBindingRow(row) {
|
|
@@ -10971,7 +11364,7 @@ function isGateTerminatingToolName(toolName) {
|
|
|
10971
11364
|
function acceptedGateReceiptIds(rows) {
|
|
10972
11365
|
const accepted = /* @__PURE__ */ new Set();
|
|
10973
11366
|
for (const row of rows) {
|
|
10974
|
-
const message =
|
|
11367
|
+
const message = isRecord7(row.message) ? row.message : void 0;
|
|
10975
11368
|
if (message?.role !== "toolResult") continue;
|
|
10976
11369
|
if (typeof message.toolCallId !== "string" || message.toolCallId.length === 0) continue;
|
|
10977
11370
|
if (message.isError === false) accepted.add(message.toolCallId);
|
|
@@ -11006,7 +11399,7 @@ function nearestAttemptBindingBefore(rows, beforeIndex) {
|
|
|
11006
11399
|
for (let i = beforeIndex - 1; i >= 0; i -= 1) {
|
|
11007
11400
|
const row = rows[i];
|
|
11008
11401
|
if (!isParentAttemptBindingRow(row)) continue;
|
|
11009
|
-
if (!
|
|
11402
|
+
if (!isRecord7(row.data) || !isRecord7(row.data.parent)) continue;
|
|
11010
11403
|
const id = row.data.parent.attemptEntryId;
|
|
11011
11404
|
const sessionFile = row.data.parent.sessionFile;
|
|
11012
11405
|
return {
|
|
@@ -11021,10 +11414,10 @@ function extractAllAcceptedGateToolCalls(rows) {
|
|
|
11021
11414
|
const out = [];
|
|
11022
11415
|
for (let rowIndex = 0; rowIndex < rows.length; rowIndex += 1) {
|
|
11023
11416
|
const row = rows[rowIndex];
|
|
11024
|
-
const message =
|
|
11417
|
+
const message = isRecord7(row.message) ? row.message : void 0;
|
|
11025
11418
|
if (message?.role !== "assistant" || !Array.isArray(message.content)) continue;
|
|
11026
11419
|
for (const part of message.content) {
|
|
11027
|
-
if (!
|
|
11420
|
+
if (!isRecord7(part) || part.type !== "toolCall") continue;
|
|
11028
11421
|
if (typeof part.id !== "string" || part.id.length === 0) continue;
|
|
11029
11422
|
if (typeof part.name !== "string" || part.name.length === 0) continue;
|
|
11030
11423
|
if (!isGateTerminatingToolName(part.name)) continue;
|
|
@@ -11032,7 +11425,7 @@ function extractAllAcceptedGateToolCalls(rows) {
|
|
|
11032
11425
|
const binding = nearestAttemptBindingBefore(rows, rowIndex);
|
|
11033
11426
|
out.push({
|
|
11034
11427
|
toolName: part.name,
|
|
11035
|
-
args:
|
|
11428
|
+
args: isRecord7(part.arguments) ? part.arguments : void 0,
|
|
11036
11429
|
accepted: true,
|
|
11037
11430
|
rowIndex,
|
|
11038
11431
|
...binding
|
|
@@ -11155,17 +11548,17 @@ function pairGateRounds(volumes) {
|
|
|
11155
11548
|
return rounds.sort((a, b) => a.officerStartedAt.localeCompare(b.officerStartedAt)).map((round, index) => ({ ...round, roundIndex: index + 1 }));
|
|
11156
11549
|
}
|
|
11157
11550
|
async function resolveOfficerSessionFromPointerFile(pointerPath) {
|
|
11158
|
-
const { readFile:
|
|
11551
|
+
const { readFile: readFile26 } = await import("node:fs/promises");
|
|
11159
11552
|
let raw;
|
|
11160
11553
|
try {
|
|
11161
|
-
raw = JSON.parse(await
|
|
11554
|
+
raw = JSON.parse(await readFile26(pointerPath, "utf8"));
|
|
11162
11555
|
} catch (error) {
|
|
11163
11556
|
throw new Error(
|
|
11164
11557
|
`direct officer run pointer unreadable in ${pointerPath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
11165
11558
|
{ cause: error }
|
|
11166
11559
|
);
|
|
11167
11560
|
}
|
|
11168
|
-
if (!
|
|
11561
|
+
if (!isRecord7(raw) || raw.kind !== "direct-officer-run-pointer" || raw.version !== 1) {
|
|
11169
11562
|
throw new Error(`direct officer run pointer has unknown shape in ${pointerPath}`);
|
|
11170
11563
|
}
|
|
11171
11564
|
const sessionFile = raw.sessionFile;
|
|
@@ -11190,7 +11583,7 @@ async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory, opti
|
|
|
11190
11583
|
throw error;
|
|
11191
11584
|
}
|
|
11192
11585
|
for (const name of names) {
|
|
11193
|
-
const path =
|
|
11586
|
+
const path = join25(directory, name);
|
|
11194
11587
|
const fromPointer = name.endsWith(".pointer.json");
|
|
11195
11588
|
const sessionPath = fromPointer ? await resolveOfficerSessionFromPointerFile(path) : path;
|
|
11196
11589
|
if (sessionPath === void 0) continue;
|
|
@@ -11329,9 +11722,9 @@ var init_audit_escalation = __esm({
|
|
|
11329
11722
|
});
|
|
11330
11723
|
|
|
11331
11724
|
// src/run-terminal-artifacts.ts
|
|
11332
|
-
import { basename as
|
|
11725
|
+
import { basename as basename8, dirname as dirname15, join as join26 } from "node:path";
|
|
11333
11726
|
function runIdFromRunDirectory(runDirectory) {
|
|
11334
|
-
const name =
|
|
11727
|
+
const name = basename8(runDirectory);
|
|
11335
11728
|
const at = name.lastIndexOf("@");
|
|
11336
11729
|
if (at <= 0 || at === name.length - 1) return void 0;
|
|
11337
11730
|
return name.slice(0, at);
|
|
@@ -11344,7 +11737,7 @@ var init_run_terminal_artifacts = __esm({
|
|
|
11344
11737
|
});
|
|
11345
11738
|
|
|
11346
11739
|
// src/submission-ledger.ts
|
|
11347
|
-
import { join as
|
|
11740
|
+
import { join as join27 } from "node:path";
|
|
11348
11741
|
function runIdentity(context) {
|
|
11349
11742
|
const directory = runDirectoryFromHostContext(context);
|
|
11350
11743
|
if (directory !== void 0) {
|
|
@@ -11366,7 +11759,7 @@ async function submissionRecordFile(cwd, runId, scope) {
|
|
|
11366
11759
|
if (sessionParent === void 0) {
|
|
11367
11760
|
const discoveredRun = await findRunDirectoryById(scope.home, runId);
|
|
11368
11761
|
if (discoveredRun === void 0) return void 0;
|
|
11369
|
-
sessionParent =
|
|
11762
|
+
sessionParent = join27(discoveredRun, "session", "session.jsonl");
|
|
11370
11763
|
}
|
|
11371
11764
|
return resolveSitianRecordPathInLedger({
|
|
11372
11765
|
level: "event",
|
|
@@ -11571,13 +11964,13 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
|
|
|
11571
11964
|
const sessionParentFromContext = (context) => {
|
|
11572
11965
|
const runDirectory = runDirectoryFromHostContext(context);
|
|
11573
11966
|
if (runDirectory !== void 0) {
|
|
11574
|
-
return
|
|
11967
|
+
return join27(runDirectory, "session", "session.jsonl");
|
|
11575
11968
|
}
|
|
11576
11969
|
const sessionFile = context.sessionManager.getSessionFile?.();
|
|
11577
11970
|
if (typeof sessionFile === "string" && sessionFile.length > 0) return sessionFile;
|
|
11578
11971
|
const sessionDir = context.sessionManager.getSessionDir?.();
|
|
11579
11972
|
if (typeof sessionDir === "string" && sessionDir.length > 0) {
|
|
11580
|
-
return
|
|
11973
|
+
return join27(sessionDir, "session.jsonl");
|
|
11581
11974
|
}
|
|
11582
11975
|
return void 0;
|
|
11583
11976
|
};
|
|
@@ -11739,23 +12132,23 @@ var init_submission_ledger = __esm({
|
|
|
11739
12132
|
|
|
11740
12133
|
// src/session-opening-materials.ts
|
|
11741
12134
|
import { existsSync as existsSync8 } from "node:fs";
|
|
11742
|
-
import { readFile as
|
|
11743
|
-
import { dirname as
|
|
12135
|
+
import { readFile as readFile18 } from "node:fs/promises";
|
|
12136
|
+
import { dirname as dirname16, join as join28 } from "node:path";
|
|
11744
12137
|
import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "node:url";
|
|
11745
12138
|
function resolvePackageRootDir(moduleUrl = import.meta.url) {
|
|
11746
|
-
let dir =
|
|
12139
|
+
let dir = dirname16(fileURLToPath(moduleUrl));
|
|
11747
12140
|
for (let i = 0; i < 8; i += 1) {
|
|
11748
|
-
if (existsSync8(
|
|
12141
|
+
if (existsSync8(join28(dir, "package.json")) && existsSync8(join28(dir, "souls"))) {
|
|
11749
12142
|
return dir;
|
|
11750
12143
|
}
|
|
11751
|
-
const parent =
|
|
12144
|
+
const parent = dirname16(dir);
|
|
11752
12145
|
if (parent === dir) break;
|
|
11753
12146
|
dir = parent;
|
|
11754
12147
|
}
|
|
11755
12148
|
return fileURLToPath(new URL("..", moduleUrl));
|
|
11756
12149
|
}
|
|
11757
12150
|
async function readPackageMaterial(relativePath) {
|
|
11758
|
-
return
|
|
12151
|
+
return readFile18(fileURLToPath(new URL(relativePath, packageRootUrl)), "utf8");
|
|
11759
12152
|
}
|
|
11760
12153
|
async function joinPackageMaterials(relativePaths) {
|
|
11761
12154
|
const chunks = [];
|
|
@@ -11923,18 +12316,18 @@ var init_known_failure = __esm({
|
|
|
11923
12316
|
});
|
|
11924
12317
|
|
|
11925
12318
|
// src/collector-evidence.ts
|
|
11926
|
-
import { createHash as
|
|
12319
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
11927
12320
|
function createSystemCollectorClock() {
|
|
11928
12321
|
const start = process.hrtime.bigint();
|
|
11929
12322
|
return {
|
|
11930
12323
|
wallNow: () => /* @__PURE__ */ new Date(),
|
|
11931
12324
|
monoNow: () => Number(process.hrtime.bigint() - start) / 1e6,
|
|
11932
|
-
sleep: (ms, signal) => new Promise((
|
|
12325
|
+
sleep: (ms, signal) => new Promise((resolve21, reject) => {
|
|
11933
12326
|
if (signal?.aborted) {
|
|
11934
12327
|
reject(signal.reason ?? new Error("aborted"));
|
|
11935
12328
|
return;
|
|
11936
12329
|
}
|
|
11937
|
-
const timer = setTimeout(
|
|
12330
|
+
const timer = setTimeout(resolve21, ms);
|
|
11938
12331
|
const onAbort = () => {
|
|
11939
12332
|
clearTimeout(timer);
|
|
11940
12333
|
reject(signal?.reason ?? new Error("aborted"));
|
|
@@ -11944,7 +12337,7 @@ function createSystemCollectorClock() {
|
|
|
11944
12337
|
};
|
|
11945
12338
|
}
|
|
11946
12339
|
function sha256Text(text) {
|
|
11947
|
-
return
|
|
12340
|
+
return createHash5("sha256").update(text, "utf8").digest("hex");
|
|
11948
12341
|
}
|
|
11949
12342
|
function computeWindowRelation(authoritativeTime, activationTime, deadlineTime) {
|
|
11950
12343
|
if (authoritativeTime === void 0 || authoritativeTime === null || authoritativeTime.length === 0) {
|
|
@@ -13082,7 +13475,7 @@ var init_collector_ledger = __esm({
|
|
|
13082
13475
|
|
|
13083
13476
|
// src/dossier-resolution.ts
|
|
13084
13477
|
import { existsSync as existsSync9, statSync as statSync2 } from "node:fs";
|
|
13085
|
-
import { resolve as
|
|
13478
|
+
import { resolve as resolve11 } from "node:path";
|
|
13086
13479
|
function isHostContext(value) {
|
|
13087
13480
|
return "sessionManager" in value;
|
|
13088
13481
|
}
|
|
@@ -13099,7 +13492,7 @@ function resolveAuditDossier(source) {
|
|
|
13099
13492
|
if (raw === void 0) {
|
|
13100
13493
|
return { status: "ok" };
|
|
13101
13494
|
}
|
|
13102
|
-
const runDirectory =
|
|
13495
|
+
const runDirectory = resolve11(raw);
|
|
13103
13496
|
try {
|
|
13104
13497
|
if (!existsSync9(runDirectory) || !statSync2(runDirectory).isDirectory()) {
|
|
13105
13498
|
return { status: "incomplete", observation: { kind: "missing-dossier" } };
|
|
@@ -13109,13 +13502,13 @@ function resolveAuditDossier(source) {
|
|
|
13109
13502
|
}
|
|
13110
13503
|
return { status: "ok", runDirectory };
|
|
13111
13504
|
}
|
|
13112
|
-
function
|
|
13505
|
+
function isRecord8(value) {
|
|
13113
13506
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13114
13507
|
}
|
|
13115
13508
|
function readDoctorAuditSubjects(context) {
|
|
13116
13509
|
const entries = context.sessionManager.getEntries?.() ?? [];
|
|
13117
13510
|
for (const entry of entries) {
|
|
13118
|
-
if (
|
|
13511
|
+
if (isRecord8(entry) && entry.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
|
|
13119
13512
|
return { status: "ok" };
|
|
13120
13513
|
}
|
|
13121
13514
|
}
|
|
@@ -13148,13 +13541,13 @@ var init_dossier_resolution = __esm({
|
|
|
13148
13541
|
});
|
|
13149
13542
|
|
|
13150
13543
|
// src/package-resources/method-skill.ts
|
|
13151
|
-
import { createHash as
|
|
13152
|
-
import { readFile as
|
|
13153
|
-
import { join as
|
|
13544
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
13545
|
+
import { readFile as readFile19, realpath as realpath7 } from "node:fs/promises";
|
|
13546
|
+
import { join as join29 } from "node:path";
|
|
13154
13547
|
function gitBlobOid(bytes) {
|
|
13155
13548
|
const body = typeof bytes === "string" ? Buffer.from(bytes, "utf8") : Buffer.from(bytes);
|
|
13156
13549
|
const header = Buffer.from(`blob ${body.byteLength}\0`, "utf8");
|
|
13157
|
-
return
|
|
13550
|
+
return createHash6("sha1").update(header).update(body).digest("hex");
|
|
13158
13551
|
}
|
|
13159
13552
|
function stripSkillFrontmatter(content) {
|
|
13160
13553
|
if (!content.startsWith("---")) return content;
|
|
@@ -13167,16 +13560,16 @@ function packagedMethodSkillRelativeDirectory(name) {
|
|
|
13167
13560
|
return `${METHOD_SKILL_RELATIVE_ROOT}/${name}`;
|
|
13168
13561
|
}
|
|
13169
13562
|
function resolvePackagedMethodSkillRoot(packageRoot, name) {
|
|
13170
|
-
return
|
|
13563
|
+
return join29(packageRoot, packagedMethodSkillRelativeDirectory(name));
|
|
13171
13564
|
}
|
|
13172
13565
|
function resolvePackagedMethodSkillPath(packageRoot, name) {
|
|
13173
|
-
return
|
|
13566
|
+
return join29(resolvePackagedMethodSkillRoot(packageRoot, name), "SKILL.md");
|
|
13174
13567
|
}
|
|
13175
|
-
function
|
|
13568
|
+
function isRecord9(value) {
|
|
13176
13569
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13177
13570
|
}
|
|
13178
13571
|
function parseProvenance(raw, expectedName) {
|
|
13179
|
-
if (!
|
|
13572
|
+
if (!isRecord9(raw)) {
|
|
13180
13573
|
throw new Error(`Packaged method provenance must be an object for ${expectedName}`);
|
|
13181
13574
|
}
|
|
13182
13575
|
if (raw.name !== expectedName) {
|
|
@@ -13190,7 +13583,7 @@ function parseProvenance(raw, expectedName) {
|
|
|
13190
13583
|
if (typeof raw.packageAdaptation !== "string" || raw.packageAdaptation.trim() === "") {
|
|
13191
13584
|
throw new Error(`Packaged method provenance packageAdaptation must be nonblank`);
|
|
13192
13585
|
}
|
|
13193
|
-
if (!
|
|
13586
|
+
if (!isRecord9(raw.upstream)) {
|
|
13194
13587
|
throw new Error(`Packaged method provenance upstream must be an object`);
|
|
13195
13588
|
}
|
|
13196
13589
|
const upstream = raw.upstream;
|
|
@@ -13217,12 +13610,12 @@ function parseProvenance(raw, expectedName) {
|
|
|
13217
13610
|
`Packaged method provenance upstream must include nonblank tag or version`
|
|
13218
13611
|
);
|
|
13219
13612
|
}
|
|
13220
|
-
if (!
|
|
13613
|
+
if (!isRecord9(raw.files)) {
|
|
13221
13614
|
throw new Error(`Packaged method provenance files must be an object`);
|
|
13222
13615
|
}
|
|
13223
13616
|
const files = {};
|
|
13224
13617
|
for (const [rel, entry] of Object.entries(raw.files)) {
|
|
13225
|
-
if (!
|
|
13618
|
+
if (!isRecord9(entry)) {
|
|
13226
13619
|
throw new Error(`Packaged method provenance file entry must be an object: ${rel}`);
|
|
13227
13620
|
}
|
|
13228
13621
|
if (typeof entry.sha256 !== "string" || !SHA256_RE.test(entry.sha256)) {
|
|
@@ -13264,11 +13657,11 @@ function parseProvenance(raw, expectedName) {
|
|
|
13264
13657
|
}
|
|
13265
13658
|
async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
13266
13659
|
const rootDirectory = resolvePackagedMethodSkillRoot(packageRoot, name);
|
|
13267
|
-
const skillPathConfigured =
|
|
13268
|
-
const provenancePath =
|
|
13660
|
+
const skillPathConfigured = join29(rootDirectory, "SKILL.md");
|
|
13661
|
+
const provenancePath = join29(rootDirectory, "provenance.json");
|
|
13269
13662
|
let provenanceRaw;
|
|
13270
13663
|
try {
|
|
13271
|
-
provenanceRaw = await
|
|
13664
|
+
provenanceRaw = await readFile19(provenancePath, "utf8");
|
|
13272
13665
|
} catch (error) {
|
|
13273
13666
|
throw new PackagedMethodSkillUnavailableError(name, provenancePath, error);
|
|
13274
13667
|
}
|
|
@@ -13282,10 +13675,10 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
|
13282
13675
|
}
|
|
13283
13676
|
const provenance = parseProvenance(provenanceJson, name);
|
|
13284
13677
|
for (const [rel, expected] of Object.entries(provenance.files)) {
|
|
13285
|
-
const absolute =
|
|
13678
|
+
const absolute = join29(rootDirectory, rel);
|
|
13286
13679
|
let bytes;
|
|
13287
13680
|
try {
|
|
13288
|
-
bytes = await
|
|
13681
|
+
bytes = await readFile19(absolute);
|
|
13289
13682
|
} catch (error) {
|
|
13290
13683
|
throw new PackagedMethodSkillUnavailableError(name, absolute, error);
|
|
13291
13684
|
}
|
|
@@ -13301,7 +13694,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
|
13301
13694
|
let raw;
|
|
13302
13695
|
try {
|
|
13303
13696
|
skillPath = await realpath7(skillPathConfigured);
|
|
13304
|
-
raw = await
|
|
13697
|
+
raw = await readFile19(skillPath, "utf8");
|
|
13305
13698
|
} catch (error) {
|
|
13306
13699
|
throw new PackagedMethodSkillUnavailableError(name, skillPathConfigured, error);
|
|
13307
13700
|
}
|
|
@@ -13357,7 +13750,7 @@ var init_method_skill = __esm({
|
|
|
13357
13750
|
});
|
|
13358
13751
|
|
|
13359
13752
|
// src/work-subject-identity.ts
|
|
13360
|
-
import { resolve as
|
|
13753
|
+
import { resolve as resolve12 } from "node:path";
|
|
13361
13754
|
function issueRoot(value) {
|
|
13362
13755
|
const normalized = value.replaceAll("\\", "/");
|
|
13363
13756
|
const marker = ".ak/work/issues/";
|
|
@@ -13367,7 +13760,7 @@ function issueRoot(value) {
|
|
|
13367
13760
|
return issue === void 0 || issue === "" ? void 0 : normalized.slice(0, index + marker.length) + issue;
|
|
13368
13761
|
}
|
|
13369
13762
|
function workIdentityFromCwd(cwd) {
|
|
13370
|
-
const resolvedCwd =
|
|
13763
|
+
const resolvedCwd = resolve12(cwd, ".");
|
|
13371
13764
|
const cwdIssue = issueRoot(resolvedCwd);
|
|
13372
13765
|
if (cwdIssue !== void 0) return cwdIssue;
|
|
13373
13766
|
if (resolvedCwd.includes("/.ak/work/")) return resolvedCwd;
|
|
@@ -13378,11 +13771,11 @@ function isMachineLedgerSessionPath(sessionPath) {
|
|
|
13378
13771
|
}
|
|
13379
13772
|
function subjectPath(sessionDir, cwd = process.cwd()) {
|
|
13380
13773
|
if (sessionDir === "") {
|
|
13381
|
-
return workIdentityFromCwd(cwd) ??
|
|
13774
|
+
return workIdentityFromCwd(cwd) ?? resolve12(cwd, ".ak/work");
|
|
13382
13775
|
}
|
|
13383
|
-
const resolvedSession =
|
|
13776
|
+
const resolvedSession = resolve12(cwd, sessionDir || ".ak/work");
|
|
13384
13777
|
if (isMachineLedgerSessionPath(resolvedSession)) {
|
|
13385
|
-
return workIdentityFromCwd(cwd) ??
|
|
13778
|
+
return workIdentityFromCwd(cwd) ?? resolve12(cwd, ".ak/work");
|
|
13386
13779
|
}
|
|
13387
13780
|
const issue = issueRoot(resolvedSession);
|
|
13388
13781
|
if (issue !== void 0) return issue;
|
|
@@ -13565,11 +13958,11 @@ var init_navigator_invocation_identity = __esm({
|
|
|
13565
13958
|
});
|
|
13566
13959
|
|
|
13567
13960
|
// src/receipt-delivery-policy.ts
|
|
13568
|
-
function
|
|
13961
|
+
function isRecord10(value) {
|
|
13569
13962
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13570
13963
|
}
|
|
13571
13964
|
function parseNoReceiptLifecycleFacts(input) {
|
|
13572
|
-
if (!
|
|
13965
|
+
if (!isRecord10(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) => isRecord10(item) && typeof item.reason === "string")) {
|
|
13573
13966
|
throw new TypeError("malformed no-receipt lifecycle facts");
|
|
13574
13967
|
}
|
|
13575
13968
|
return {
|
|
@@ -13787,16 +14180,16 @@ var init_terminal = __esm({
|
|
|
13787
14180
|
});
|
|
13788
14181
|
|
|
13789
14182
|
// src/public-cli/settlement.ts
|
|
13790
|
-
import { randomUUID as
|
|
13791
|
-
import { appendFile as appendFile2, readFile as
|
|
13792
|
-
import { dirname as
|
|
14183
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
14184
|
+
import { appendFile as appendFile2, readFile as readFile20, readdir as readdir7, writeFile as writeFile10 } from "node:fs/promises";
|
|
14185
|
+
import { dirname as dirname17, join as join30 } from "node:path";
|
|
13793
14186
|
function sealedLedgerHome(admitted) {
|
|
13794
14187
|
return homeFromRunDirectory(admitted.runDirectory);
|
|
13795
14188
|
}
|
|
13796
14189
|
function ledgerReadScope(admitted, scope) {
|
|
13797
14190
|
return {
|
|
13798
14191
|
home: sealedLedgerHome(admitted),
|
|
13799
|
-
sessionParent:
|
|
14192
|
+
sessionParent: join30(admitted.runDirectory, "session", "session.jsonl"),
|
|
13800
14193
|
...scope?.courtAttemptId === void 0 || scope.courtAttemptId.length === 0 ? {} : { attemptId: scope.courtAttemptId }
|
|
13801
14194
|
};
|
|
13802
14195
|
}
|
|
@@ -13926,7 +14319,7 @@ function presentStructuralRejection(error, io) {
|
|
|
13926
14319
|
}
|
|
13927
14320
|
async function inspectJudgeSession(sessionFile) {
|
|
13928
14321
|
try {
|
|
13929
|
-
await
|
|
14322
|
+
await readFile20(sessionFile, "utf8");
|
|
13930
14323
|
return { state: "present" };
|
|
13931
14324
|
} catch (error) {
|
|
13932
14325
|
if (isMissingPathError3(error)) return { state: "missing" };
|
|
@@ -14158,7 +14551,7 @@ function sessionReadFailure(error, fallbackMessage) {
|
|
|
14158
14551
|
return failed;
|
|
14159
14552
|
}
|
|
14160
14553
|
async function readBoundSessionEntries(sessionFile) {
|
|
14161
|
-
const text = await
|
|
14554
|
+
const text = await readFile20(sessionFile, "utf8");
|
|
14162
14555
|
const entries = [];
|
|
14163
14556
|
for (const line2 of text.trim().split("\n").filter(Boolean)) {
|
|
14164
14557
|
try {
|
|
@@ -14219,12 +14612,12 @@ async function readSitianRetainedAuditorProviderStop(sessionFile) {
|
|
|
14219
14612
|
kind: "auditor",
|
|
14220
14613
|
sessionParent: sessionFile,
|
|
14221
14614
|
// Path is driven by sessionParent when under ledger home; cwd is a fallback only.
|
|
14222
|
-
cwd:
|
|
14615
|
+
cwd: dirname17(sessionFile)
|
|
14223
14616
|
});
|
|
14224
14617
|
const { records } = await readSitianRecords(recordFile);
|
|
14225
14618
|
for (let i = records.length - 1; i >= 0; i -= 1) {
|
|
14226
14619
|
const payload = records[i]?.payload;
|
|
14227
|
-
if (!
|
|
14620
|
+
if (!isRecord11(payload) || !isRecord11(payload.response)) continue;
|
|
14228
14621
|
if (typeof payload.type === "string") continue;
|
|
14229
14622
|
const stop = sessionProviderStopFromAssistant(payload.response);
|
|
14230
14623
|
if (stop !== void 0) return stop;
|
|
@@ -14245,7 +14638,7 @@ async function readSessionProviderStop(sessionFile) {
|
|
|
14245
14638
|
}
|
|
14246
14639
|
}
|
|
14247
14640
|
async function readBoundEvidenceChildKnownFailure(sessionFile) {
|
|
14248
|
-
const childDirectory =
|
|
14641
|
+
const childDirectory = join30(dirname17(sessionFile), "evidence-children");
|
|
14249
14642
|
let names;
|
|
14250
14643
|
try {
|
|
14251
14644
|
names = await readdir7(childDirectory);
|
|
@@ -14256,12 +14649,12 @@ async function readBoundEvidenceChildKnownFailure(sessionFile) {
|
|
|
14256
14649
|
for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
|
|
14257
14650
|
let entries;
|
|
14258
14651
|
try {
|
|
14259
|
-
entries = await readBoundSessionEntries(
|
|
14652
|
+
entries = await readBoundSessionEntries(join30(childDirectory, file));
|
|
14260
14653
|
} catch (error) {
|
|
14261
14654
|
throw sessionReadFailure(error, "failed to read discovered evidence-child session");
|
|
14262
14655
|
}
|
|
14263
14656
|
const header = entries.find((entry) => entry.type === "session");
|
|
14264
|
-
if (!
|
|
14657
|
+
if (!isRecord11(header) || header.parentSession !== sessionFile) continue;
|
|
14265
14658
|
const stop = extractSessionProviderStop(entries);
|
|
14266
14659
|
if (stop === void 0) continue;
|
|
14267
14660
|
const primary = knownFailureFromProviderStop(stop);
|
|
@@ -14294,12 +14687,12 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
14294
14687
|
return body.startsWith("\u672C\u6B21\u914D\u7F6E\u7684\u52B3\u52A1\u5F15\u64CE\u53CA\u5176\u624B\u518C\uFF1A") || body.startsWith("- engine:");
|
|
14295
14688
|
};
|
|
14296
14689
|
const isResumeEnvelope = (msg) => {
|
|
14297
|
-
if (!
|
|
14690
|
+
if (!isRecord11(msg) || msg.role !== "user") return false;
|
|
14298
14691
|
const text = typeof msg.text === "string" ? msg.text : typeof msg.content === "string" ? msg.content : void 0;
|
|
14299
14692
|
if (isResumeEnvelopeBytes(text)) return true;
|
|
14300
14693
|
const content = msg.content;
|
|
14301
14694
|
if (Array.isArray(content)) {
|
|
14302
|
-
return content.some((p) =>
|
|
14695
|
+
return content.some((p) => isRecord11(p) && (isResumeEnvelopeBytes(p.text) || isResumeEnvelopeBytes(p.content)));
|
|
14303
14696
|
}
|
|
14304
14697
|
return false;
|
|
14305
14698
|
};
|
|
@@ -14311,7 +14704,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
14311
14704
|
latestParentUserIndex = i;
|
|
14312
14705
|
break;
|
|
14313
14706
|
}
|
|
14314
|
-
const childDirectories = [
|
|
14707
|
+
const childDirectories = [join30(dirname17(sessionFile), "auditor-roles")];
|
|
14315
14708
|
const valid = [];
|
|
14316
14709
|
let sawAnyDirectory = false;
|
|
14317
14710
|
for (const childDirectory of childDirectories) {
|
|
@@ -14326,12 +14719,12 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
14326
14719
|
for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
|
|
14327
14720
|
let entries;
|
|
14328
14721
|
try {
|
|
14329
|
-
entries = await readBoundSessionEntries(
|
|
14722
|
+
entries = await readBoundSessionEntries(join30(childDirectory, file));
|
|
14330
14723
|
} catch (error) {
|
|
14331
14724
|
throw sessionReadFailure(error, "failed to read discovered auditor session");
|
|
14332
14725
|
}
|
|
14333
14726
|
const header = entries.find((entry) => entry.type === "session");
|
|
14334
|
-
if (!
|
|
14727
|
+
if (!isRecord11(header)) continue;
|
|
14335
14728
|
const bindingIndexes = [];
|
|
14336
14729
|
for (let i = 0; i < entries.length; i += 1) {
|
|
14337
14730
|
const entry = entries[i];
|
|
@@ -14345,7 +14738,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
14345
14738
|
end: idx + 1 < bindingIndexes.length ? bindingIndexes[idx + 1] : entries.length
|
|
14346
14739
|
})) : [{ entry: void 0, start: 0, end: entries.length }];
|
|
14347
14740
|
for (const { entry: bindingEntry, start, end } of bindingPasses) {
|
|
14348
|
-
const bindingParent = bindingEntry !== void 0 &&
|
|
14741
|
+
const bindingParent = bindingEntry !== void 0 && isRecord11(bindingEntry.data) && isRecord11(bindingEntry.data.parent) ? bindingEntry.data.parent : void 0;
|
|
14349
14742
|
const attemptEntryId = typeof bindingParent?.attemptEntryId === "string" ? bindingParent.attemptEntryId : void 0;
|
|
14350
14743
|
const attemptEntryIndex = attemptEntryId === void 0 ? -1 : parentEntries.findIndex((entry) => entry.id === attemptEntryId);
|
|
14351
14744
|
const boundSessionFile = typeof bindingParent?.sessionFile === "string" ? bindingParent.sessionFile : typeof header.parentSession === "string" ? header.parentSession : void 0;
|
|
@@ -14372,12 +14765,12 @@ function complianceFailureFromAuditorVolumes(volumes) {
|
|
|
14372
14765
|
if (stop === void 0) continue;
|
|
14373
14766
|
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
14374
14767
|
const entry = entries[i];
|
|
14375
|
-
if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !
|
|
14376
|
-
const parent =
|
|
14377
|
-
const failure2 =
|
|
14768
|
+
if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !isRecord11(entry.data)) continue;
|
|
14769
|
+
const parent = isRecord11(entry.data.parent) ? entry.data.parent : void 0;
|
|
14770
|
+
const failure2 = isRecord11(entry.data.failure) ? entry.data.failure : void 0;
|
|
14378
14771
|
if (parent?.sessionId !== parentId || parent.sessionFile !== sessionFile || parent.attemptEntryId !== attemptEntryId) continue;
|
|
14379
14772
|
if (failure2 === void 0) continue;
|
|
14380
|
-
const identity =
|
|
14773
|
+
const identity = isRecord11(failure2.identity) ? failure2.identity : void 0;
|
|
14381
14774
|
const typedCause = failure2.cause === "provider" || failure2.cause === "activation" || failure2.cause === "session" || failure2.cause === "output" || failure2.cause === "timeout" ? failure2.cause : void 0;
|
|
14382
14775
|
return {
|
|
14383
14776
|
...typedCause === void 0 ? {} : { cause: typedCause },
|
|
@@ -14386,7 +14779,7 @@ function complianceFailureFromAuditorVolumes(volumes) {
|
|
|
14386
14779
|
...typeof identity.code === "string" || typeof identity.code === "number" ? { code: identity.code } : {}
|
|
14387
14780
|
} },
|
|
14388
14781
|
...typeof failure2.diagnostic === "string" ? { diagnostic: failure2.diagnostic } : {},
|
|
14389
|
-
...
|
|
14782
|
+
...isRecord11(failure2.details) ? { details: failure2.details } : {}
|
|
14390
14783
|
};
|
|
14391
14784
|
}
|
|
14392
14785
|
}
|
|
@@ -14433,9 +14826,9 @@ function typedFailedTerminatingToolKnownFailure(entries) {
|
|
|
14433
14826
|
if (classification.kind !== "infrastructure") continue;
|
|
14434
14827
|
if (typeof message.toolCallId !== "string" || typeof message.toolName !== "string") continue;
|
|
14435
14828
|
if (boundRoleToolCallForResult(attemptEntries, i, message, message.toolName) === void 0) continue;
|
|
14436
|
-
const textPart = Array.isArray(message.content) ? message.content.find((part) =>
|
|
14437
|
-
const diagnostic =
|
|
14438
|
-
const details =
|
|
14829
|
+
const textPart = Array.isArray(message.content) ? message.content.find((part) => isRecord11(part) && part.type === "text" && typeof part.text === "string") : void 0;
|
|
14830
|
+
const diagnostic = isRecord11(textPart) ? textPart.text : void 0;
|
|
14831
|
+
const details = isRecord11(message.details) ? message.details : classification.fact;
|
|
14439
14832
|
return {
|
|
14440
14833
|
cause: "activation",
|
|
14441
14834
|
identity: { name: message.toolName, code: message.toolCallId },
|
|
@@ -14593,7 +14986,7 @@ function controlledFailureInputFromResolution(resolution) {
|
|
|
14593
14986
|
} : {}
|
|
14594
14987
|
};
|
|
14595
14988
|
}
|
|
14596
|
-
function
|
|
14989
|
+
function isRecord11(value) {
|
|
14597
14990
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14598
14991
|
}
|
|
14599
14992
|
function toolResultText(message) {
|
|
@@ -14618,7 +15011,7 @@ function extractCollectorTargetBindRejection(entries) {
|
|
|
14618
15011
|
const diagnostic = toolResultText(message);
|
|
14619
15012
|
if (diagnostic.length === 0) return void 0;
|
|
14620
15013
|
const details = message.details;
|
|
14621
|
-
const code =
|
|
15014
|
+
const code = isRecord11(details) && typeof details.code === "string" && details.code.trim() !== "" ? details.code : void 0;
|
|
14622
15015
|
return code === void 0 ? { diagnostic } : { diagnostic, code };
|
|
14623
15016
|
}
|
|
14624
15017
|
return void 0;
|
|
@@ -14679,7 +15072,7 @@ function boundRoleToolCallForResult(entries, resultIndex, message, outputToolNam
|
|
|
14679
15072
|
const candidateMessage = entries[index]?.message;
|
|
14680
15073
|
if (candidateMessage?.role === "assistant" && Array.isArray(candidateMessage.content)) {
|
|
14681
15074
|
for (const part of candidateMessage.content) {
|
|
14682
|
-
if (!
|
|
15075
|
+
if (!isRecord11(part) || part.type !== "toolCall" || part.id !== callId) {
|
|
14683
15076
|
continue;
|
|
14684
15077
|
}
|
|
14685
15078
|
if (part.name !== outputToolName) return void 0;
|
|
@@ -14716,7 +15109,7 @@ async function appendRunAttemptHistory(source, outcome) {
|
|
|
14716
15109
|
type: "custom",
|
|
14717
15110
|
customType: ATTEMPT_HISTORY_ENTRY_TYPE,
|
|
14718
15111
|
data: attemptData,
|
|
14719
|
-
id:
|
|
15112
|
+
id: randomUUID4(),
|
|
14720
15113
|
parentId,
|
|
14721
15114
|
timestamp: timestamp2
|
|
14722
15115
|
})}
|
|
@@ -14751,7 +15144,7 @@ function parseNavigatorAttendanceDetails(details) {
|
|
|
14751
15144
|
const advisoryDiagnostic = typeof details.routePlaybookReadFailure === "string" ? { advisoryDiagnostic: details.routePlaybookReadFailure } : {};
|
|
14752
15145
|
if (disposition === "recommendation") {
|
|
14753
15146
|
const next = details.next;
|
|
14754
|
-
if (!
|
|
15147
|
+
if (!isRecord11(next) || typeof next.role !== "string") {
|
|
14755
15148
|
return {
|
|
14756
15149
|
disposition: "unavailable",
|
|
14757
15150
|
source: "unknown",
|
|
@@ -14759,7 +15152,7 @@ function parseNavigatorAttendanceDetails(details) {
|
|
|
14759
15152
|
};
|
|
14760
15153
|
}
|
|
14761
15154
|
const reason = typeof details.reason === "string" ? details.reason : "";
|
|
14762
|
-
const route = Array.isArray(details.route) ? details.route.filter(
|
|
15155
|
+
const route = Array.isArray(details.route) ? details.route.filter(isRecord11).map((target) => ({
|
|
14763
15156
|
role: String(target.role),
|
|
14764
15157
|
phase: navigatorPhaseValue(target.phase)
|
|
14765
15158
|
})) : void 0;
|
|
@@ -14822,8 +15215,8 @@ function projectTerminalGateFact(rounds) {
|
|
|
14822
15215
|
};
|
|
14823
15216
|
}
|
|
14824
15217
|
async function extractGateFactFromSessionDirectory(sessionDirectory, options = {}) {
|
|
14825
|
-
const directories = [
|
|
14826
|
-
const parentSessionFile = options.parentSessionFile ??
|
|
15218
|
+
const directories = [join30(sessionDirectory, "auditor-roles")];
|
|
15219
|
+
const parentSessionFile = options.parentSessionFile ?? join30(sessionDirectory, "session.jsonl");
|
|
14827
15220
|
const rounds = await readAnalystGateCyclesFromAuditorRoles(directories, {
|
|
14828
15221
|
parentSessionFile
|
|
14829
15222
|
});
|
|
@@ -14831,7 +15224,7 @@ async function extractGateFactFromSessionDirectory(sessionDirectory, options = {
|
|
|
14831
15224
|
}
|
|
14832
15225
|
async function withOptionalGateProjection(base, sessionDirectory, gateContext = {}) {
|
|
14833
15226
|
const secondaryEvidence = base.roleOutcome.kind === "failure" ? base.roleOutcome.decisiveFacts.secondaryEvidence : void 0;
|
|
14834
|
-
if (
|
|
15227
|
+
if (isRecord11(secondaryEvidence) && secondaryEvidence.kind === "role_infrastructure_failure" && (secondaryEvidence.stage === "gatekeeper" || secondaryEvidence.stage === "inspector" || secondaryEvidence.stage === "notary")) return base;
|
|
14835
15228
|
const gate = await extractGateFactFromSessionDirectory(sessionDirectory, gateContext);
|
|
14836
15229
|
return gate === void 0 ? base : { ...base, gate };
|
|
14837
15230
|
}
|
|
@@ -14871,7 +15264,7 @@ function extractNavigatorFact(entries) {
|
|
|
14871
15264
|
const entry = entries[i];
|
|
14872
15265
|
if (entry?.type === "custom_message" && entry.customType === "ak-navigator-attendance") {
|
|
14873
15266
|
const details = entry.message?.details ?? entry.details;
|
|
14874
|
-
if (!
|
|
15267
|
+
if (!isRecord11(details)) {
|
|
14875
15268
|
return {
|
|
14876
15269
|
disposition: "unavailable",
|
|
14877
15270
|
source: "unknown",
|
|
@@ -14921,9 +15314,9 @@ async function extractNavigatorFactFromAdmittedSession(sessionFile) {
|
|
|
14921
15314
|
async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
|
|
14922
15315
|
await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
|
|
14923
15316
|
const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
|
|
14924
|
-
const reportPath =
|
|
14925
|
-
const evidencePath =
|
|
14926
|
-
await
|
|
15317
|
+
const reportPath = join30(artifactsDir, "report.json");
|
|
15318
|
+
const evidencePath = join30(artifactsDir, "evidence.json");
|
|
15319
|
+
await writeFile10(
|
|
14927
15320
|
reportPath,
|
|
14928
15321
|
`${JSON.stringify(
|
|
14929
15322
|
{
|
|
@@ -14937,7 +15330,7 @@ async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
|
|
|
14937
15330
|
`,
|
|
14938
15331
|
"utf8"
|
|
14939
15332
|
);
|
|
14940
|
-
await
|
|
15333
|
+
await writeFile10(
|
|
14941
15334
|
evidencePath,
|
|
14942
15335
|
`${JSON.stringify(
|
|
14943
15336
|
{
|
|
@@ -15004,7 +15397,7 @@ function extractDoctorCandidateCostFact(entries) {
|
|
|
15004
15397
|
const entry = entries[i];
|
|
15005
15398
|
if (entry?.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
|
|
15006
15399
|
const data = entry.data;
|
|
15007
|
-
return
|
|
15400
|
+
return isRecord11(data) ? data.cost : void 0;
|
|
15008
15401
|
}
|
|
15009
15402
|
}
|
|
15010
15403
|
return void 0;
|
|
@@ -15015,7 +15408,7 @@ function extractDoctorCandidateAuditNoReceiptFact(entries) {
|
|
|
15015
15408
|
const entry = entries[i];
|
|
15016
15409
|
if (entry?.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
|
|
15017
15410
|
const data = entry.data;
|
|
15018
|
-
return
|
|
15411
|
+
return isRecord11(data) ? data.auditNoReceipt : void 0;
|
|
15019
15412
|
}
|
|
15020
15413
|
}
|
|
15021
15414
|
return void 0;
|
|
@@ -15023,9 +15416,9 @@ function extractDoctorCandidateAuditNoReceiptFact(entries) {
|
|
|
15023
15416
|
async function publishDoctorArtifacts(admitted, roleOutcome, coordinates, options = {}) {
|
|
15024
15417
|
await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
|
|
15025
15418
|
const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
|
|
15026
|
-
const reportPath =
|
|
15027
|
-
const evidencePath =
|
|
15028
|
-
await
|
|
15419
|
+
const reportPath = join30(artifactsDir, "report.json");
|
|
15420
|
+
const evidencePath = join30(artifactsDir, "evidence.json");
|
|
15421
|
+
await writeFile10(
|
|
15029
15422
|
reportPath,
|
|
15030
15423
|
`${JSON.stringify(
|
|
15031
15424
|
{
|
|
@@ -15041,7 +15434,7 @@ async function publishDoctorArtifacts(admitted, roleOutcome, coordinates, option
|
|
|
15041
15434
|
`,
|
|
15042
15435
|
"utf8"
|
|
15043
15436
|
);
|
|
15044
|
-
await
|
|
15437
|
+
await writeFile10(
|
|
15045
15438
|
evidencePath,
|
|
15046
15439
|
`${JSON.stringify(
|
|
15047
15440
|
{
|
|
@@ -15140,7 +15533,7 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
|
|
|
15140
15533
|
spec.toolName
|
|
15141
15534
|
);
|
|
15142
15535
|
if (residual !== void 0) {
|
|
15143
|
-
const details =
|
|
15536
|
+
const details = isRecord11(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
|
|
15144
15537
|
const failed = await settleFailureTerminalResult(admitted, {
|
|
15145
15538
|
cause: "output",
|
|
15146
15539
|
diagnostic: residual.diagnostic,
|
|
@@ -15255,7 +15648,7 @@ function publicationAttemptFromError(path, error) {
|
|
|
15255
15648
|
}
|
|
15256
15649
|
function uniqueFailureFallbackDirs(runDirectory, baseDir) {
|
|
15257
15650
|
const dirs = [];
|
|
15258
|
-
for (const dir of [baseDir, runDirectory,
|
|
15651
|
+
for (const dir of [baseDir, runDirectory, dirname17(runDirectory)]) {
|
|
15259
15652
|
if (!dirs.includes(dir)) dirs.push(dir);
|
|
15260
15653
|
}
|
|
15261
15654
|
return dirs;
|
|
@@ -15277,13 +15670,13 @@ async function writeFailureJsonRetainingCause(preferredCandidates, uniqueFallbac
|
|
|
15277
15670
|
const candidates = [
|
|
15278
15671
|
...preferredCandidates,
|
|
15279
15672
|
// One unique name per fallback dir — collisions on fixed names cannot exhaust this.
|
|
15280
|
-
...uniqueFallbackDirs.map((dir) =>
|
|
15673
|
+
...uniqueFallbackDirs.map((dir) => join30(dir, `${stem}.${randomUUID4()}.json`))
|
|
15281
15674
|
];
|
|
15282
15675
|
for (let i = 0; i < candidates.length; i += 1) {
|
|
15283
15676
|
const path = candidates[i];
|
|
15284
15677
|
const payload = issues.length === 0 ? basePayload : { ...basePayload, publicationIssues: issues };
|
|
15285
15678
|
try {
|
|
15286
|
-
await
|
|
15679
|
+
await writeFile10(
|
|
15287
15680
|
path,
|
|
15288
15681
|
`${JSON.stringify(payload, null, 2)}
|
|
15289
15682
|
`,
|
|
@@ -15328,20 +15721,20 @@ async function publishFailureArtifacts(admitted, failure2, authority) {
|
|
|
15328
15721
|
baseDir
|
|
15329
15722
|
);
|
|
15330
15723
|
const errorCandidates = underArtifacts ? [
|
|
15331
|
-
|
|
15332
|
-
|
|
15333
|
-
|
|
15724
|
+
join30(baseDir, "error.json"),
|
|
15725
|
+
join30(baseDir, "error.settlement.json"),
|
|
15726
|
+
join30(admitted.runDirectory, "error.settlement.json")
|
|
15334
15727
|
] : [
|
|
15335
|
-
|
|
15336
|
-
|
|
15728
|
+
join30(baseDir, "error.settlement.json"),
|
|
15729
|
+
join30(baseDir, "error.json")
|
|
15337
15730
|
];
|
|
15338
15731
|
const evidenceCandidates = underArtifacts ? [
|
|
15339
|
-
|
|
15340
|
-
|
|
15341
|
-
|
|
15732
|
+
join30(baseDir, "evidence.json"),
|
|
15733
|
+
join30(baseDir, "evidence.settlement.json"),
|
|
15734
|
+
join30(admitted.runDirectory, "evidence.settlement.json")
|
|
15342
15735
|
] : [
|
|
15343
|
-
|
|
15344
|
-
|
|
15736
|
+
join30(baseDir, "evidence.settlement.json"),
|
|
15737
|
+
join30(baseDir, "evidence.json")
|
|
15345
15738
|
];
|
|
15346
15739
|
const errorPayloadBase = {
|
|
15347
15740
|
kind: "error",
|
|
@@ -15503,10 +15896,10 @@ function presentFailureTerminal(terminal, io) {
|
|
|
15503
15896
|
}
|
|
15504
15897
|
function defaultNavigatorGraceSleep() {
|
|
15505
15898
|
let timer;
|
|
15506
|
-
const sleep = ((ms) => new Promise((
|
|
15899
|
+
const sleep = ((ms) => new Promise((resolve21) => {
|
|
15507
15900
|
timer = setTimeout(() => {
|
|
15508
15901
|
timer = void 0;
|
|
15509
|
-
|
|
15902
|
+
resolve21();
|
|
15510
15903
|
}, ms);
|
|
15511
15904
|
}));
|
|
15512
15905
|
sleep.cancel = () => {
|
|
@@ -15518,7 +15911,7 @@ function defaultNavigatorGraceSleep() {
|
|
|
15518
15911
|
return sleep;
|
|
15519
15912
|
}
|
|
15520
15913
|
function raceNavigatorGrace(work, graceMs = NAVIGATOR_POST_ROLE_GRACE_MS, sleep = defaultNavigatorGraceSleep()) {
|
|
15521
|
-
return new Promise((
|
|
15914
|
+
return new Promise((resolve21, reject) => {
|
|
15522
15915
|
let settled = false;
|
|
15523
15916
|
const finish = (action) => {
|
|
15524
15917
|
if (settled) return;
|
|
@@ -15527,11 +15920,11 @@ function raceNavigatorGrace(work, graceMs = NAVIGATOR_POST_ROLE_GRACE_MS, sleep
|
|
|
15527
15920
|
action();
|
|
15528
15921
|
};
|
|
15529
15922
|
void work.then(
|
|
15530
|
-
(value) => finish(() =>
|
|
15923
|
+
(value) => finish(() => resolve21({ status: "done", value })),
|
|
15531
15924
|
(error) => finish(() => reject(error))
|
|
15532
15925
|
);
|
|
15533
15926
|
void sleep(graceMs).then(() => {
|
|
15534
|
-
finish(() =>
|
|
15927
|
+
finish(() => resolve21({ status: "timeout" }));
|
|
15535
15928
|
});
|
|
15536
15929
|
});
|
|
15537
15930
|
}
|
|
@@ -15585,9 +15978,9 @@ var init_settlement = __esm({
|
|
|
15585
15978
|
|
|
15586
15979
|
// src/public-cli/auto-resume.ts
|
|
15587
15980
|
import { constants as fsConstants2 } from "node:fs";
|
|
15588
|
-
import { randomUUID as
|
|
15981
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
15589
15982
|
import { lstat as lstat6, mkdir as mkdir4, open as open2 } from "node:fs/promises";
|
|
15590
|
-
import { join as
|
|
15983
|
+
import { join as join31 } from "node:path";
|
|
15591
15984
|
async function persistReturnedRunState(admitted, authority, options) {
|
|
15592
15985
|
if (options?.lawful === true) {
|
|
15593
15986
|
await markRunTerminal(admitted.runDirectory);
|
|
@@ -15702,7 +16095,7 @@ function jsonSafeReplacer() {
|
|
|
15702
16095
|
};
|
|
15703
16096
|
}
|
|
15704
16097
|
async function writeHardenedArtifactFile(artifactsDir, namePrefix, payload) {
|
|
15705
|
-
const filePath =
|
|
16098
|
+
const filePath = join31(artifactsDir, `${namePrefix}-${randomUUID5()}.json`);
|
|
15706
16099
|
const body = `${JSON.stringify(payload, jsonSafeReplacer(), 2)}
|
|
15707
16100
|
`;
|
|
15708
16101
|
const noFollowFlag = typeof fsConstants2.O_NOFOLLOW === "number" ? fsConstants2.O_NOFOLLOW : 0;
|
|
@@ -15973,9 +16366,9 @@ var init_auto_resume = __esm({
|
|
|
15973
16366
|
});
|
|
15974
16367
|
|
|
15975
16368
|
// src/public-cli/post-admission.ts
|
|
15976
|
-
import { randomUUID as
|
|
15977
|
-
import { readFile as
|
|
15978
|
-
import { isAbsolute as isAbsolute8, join as
|
|
16369
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
16370
|
+
import { readFile as readFile21, writeFile as writeFile11 } from "node:fs/promises";
|
|
16371
|
+
import { isAbsolute as isAbsolute8, join as join32, resolve as resolve13 } from "node:path";
|
|
15979
16372
|
function describeCaughtError(error) {
|
|
15980
16373
|
if (error instanceof Error) {
|
|
15981
16374
|
const code = error.code;
|
|
@@ -16019,8 +16412,8 @@ async function recordBestEffortPostDispatchDiagnostic(admitted, env, diagnostic,
|
|
|
16019
16412
|
} catch (appendError) {
|
|
16020
16413
|
try {
|
|
16021
16414
|
const artifactsDir = await ensureRealArtifactsDirectory(admitted.runDirectory);
|
|
16022
|
-
await
|
|
16023
|
-
|
|
16415
|
+
await writeFile11(
|
|
16416
|
+
join32(artifactsDir, `post-admission-diagnostic-${randomUUID6()}.json`),
|
|
16024
16417
|
`${JSON.stringify({ version: 1, ...payload }, null, 2)}
|
|
16025
16418
|
`,
|
|
16026
16419
|
{ encoding: "utf8", flag: "wx" }
|
|
@@ -16036,7 +16429,7 @@ async function recordBestEffortPostDispatchDiagnostic(admitted, env, diagnostic,
|
|
|
16036
16429
|
}
|
|
16037
16430
|
async function readInvocationHost(runDirectory) {
|
|
16038
16431
|
try {
|
|
16039
|
-
const raw = JSON.parse(await
|
|
16432
|
+
const raw = JSON.parse(await readFile21(join32(runDirectory, "invocation.json"), "utf8"));
|
|
16040
16433
|
return typeof raw.host === "string" && raw.host.trim() !== "" ? raw.host : void 0;
|
|
16041
16434
|
} catch (error) {
|
|
16042
16435
|
if (error.code === "ENOENT") return void 0;
|
|
@@ -16298,8 +16691,8 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
16298
16691
|
}
|
|
16299
16692
|
let stderrLogWriteFailure;
|
|
16300
16693
|
try {
|
|
16301
|
-
await
|
|
16302
|
-
|
|
16694
|
+
await writeFile11(
|
|
16695
|
+
join32(admitted.runDirectory, "stderr.log"),
|
|
16303
16696
|
result.stderr,
|
|
16304
16697
|
"utf8"
|
|
16305
16698
|
);
|
|
@@ -16528,7 +16921,7 @@ function resumeTurnRequestProjectionOptions(admitted, request, env, summonsPrepa
|
|
|
16528
16921
|
kind: "resume",
|
|
16529
16922
|
prompt
|
|
16530
16923
|
},
|
|
16531
|
-
...request.message === void 0 ? {} : { courtAttemptId:
|
|
16924
|
+
...request.message === void 0 ? {} : { courtAttemptId: randomUUID6() },
|
|
16532
16925
|
...env.stationChild === void 0 ? {} : { stationChild: env.stationChild }
|
|
16533
16926
|
};
|
|
16534
16927
|
}
|
|
@@ -16545,8 +16938,8 @@ async function dispatchAfterWriterLease(input) {
|
|
|
16545
16938
|
}
|
|
16546
16939
|
}
|
|
16547
16940
|
function isAlreadyFrozenSummonsAttachment(runDirectory, attachmentPath) {
|
|
16548
|
-
const absolute = isAbsolute8(attachmentPath) ? attachmentPath :
|
|
16549
|
-
return pathContainedIn(
|
|
16941
|
+
const absolute = isAbsolute8(attachmentPath) ? attachmentPath : resolve13(attachmentPath);
|
|
16942
|
+
return pathContainedIn(join32(runDirectory, "attachments"), absolute);
|
|
16550
16943
|
}
|
|
16551
16944
|
async function prepareSummonsResumeMaterials(runDirectory, summons) {
|
|
16552
16945
|
if (summons === void 0) return void 0;
|
|
@@ -16625,7 +17018,7 @@ async function runPostAdmissionSeatResume(input) {
|
|
|
16625
17018
|
}
|
|
16626
17019
|
let turnRequest = await input.buildTurnRequest(admittedForBuild, request);
|
|
16627
17020
|
if (openCourtAttemptId !== void 0 || request.summons !== void 0 || request.message !== void 0) {
|
|
16628
|
-
const courtAttemptId = openCourtAttemptId ?? (turnRequest.courtAttemptId !== void 0 && turnRequest.courtAttemptId.length > 0 ? turnRequest.courtAttemptId :
|
|
17021
|
+
const courtAttemptId = openCourtAttemptId ?? (turnRequest.courtAttemptId !== void 0 && turnRequest.courtAttemptId.length > 0 ? turnRequest.courtAttemptId : randomUUID6());
|
|
16629
17022
|
turnRequest = { ...turnRequest, courtAttemptId };
|
|
16630
17023
|
if (openCourtAttemptId === void 0) {
|
|
16631
17024
|
const court = {
|
|
@@ -17896,7 +18289,7 @@ __export(public_role_summons_exports, {
|
|
|
17896
18289
|
summonPublicRole: () => summonPublicRole
|
|
17897
18290
|
});
|
|
17898
18291
|
import { existsSync as existsSync10 } from "node:fs";
|
|
17899
|
-
import { join as
|
|
18292
|
+
import { join as join33 } from "node:path";
|
|
17900
18293
|
function createCapturingIo() {
|
|
17901
18294
|
const chunks = [];
|
|
17902
18295
|
return {
|
|
@@ -17919,7 +18312,7 @@ function parentDir(path) {
|
|
|
17919
18312
|
function walkPackageRoot(start) {
|
|
17920
18313
|
let dir = start;
|
|
17921
18314
|
for (let i = 0; i < 12; i += 1) {
|
|
17922
|
-
if (existsSync10(
|
|
18315
|
+
if (existsSync10(join33(dir, "package.json")) && existsSync10(join33(dir, "souls"))) {
|
|
17923
18316
|
return dir;
|
|
17924
18317
|
}
|
|
17925
18318
|
const parent = parentDir(dir);
|
|
@@ -18013,7 +18406,7 @@ async function createSummonEnv(options) {
|
|
|
18013
18406
|
async function summonPublicRole(options) {
|
|
18014
18407
|
const packageRoot = resolveSummonsPackageRoot(options.packageRoot);
|
|
18015
18408
|
const home = await resolveSummonHome(options);
|
|
18016
|
-
const agentDir = options.agentDir ?? process.env.PI_CODING_AGENT_DIR ??
|
|
18409
|
+
const agentDir = options.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? join33(home, ".pi", "agent");
|
|
18017
18410
|
const {
|
|
18018
18411
|
loadCredentialProviders: loadCredentialProviders2,
|
|
18019
18412
|
loadPublicCliConfig: loadPublicCliConfig2,
|
|
@@ -18395,12 +18788,12 @@ __export(session_assistant_usage_exports, {
|
|
|
18395
18788
|
sessionFileFromPublicSummon: () => sessionFileFromPublicSummon,
|
|
18396
18789
|
usageFromPublicSummon: () => usageFromPublicSummon
|
|
18397
18790
|
});
|
|
18398
|
-
import { join as
|
|
18791
|
+
import { join as join34 } from "node:path";
|
|
18399
18792
|
async function readAssistantUsageFromSessionFile(sessionFile) {
|
|
18400
|
-
const { readFile:
|
|
18793
|
+
const { readFile: readFile26 } = await import("node:fs/promises");
|
|
18401
18794
|
let text;
|
|
18402
18795
|
try {
|
|
18403
|
-
text = await
|
|
18796
|
+
text = await readFile26(sessionFile, "utf8");
|
|
18404
18797
|
} catch (error) {
|
|
18405
18798
|
if (error?.code === "ENOENT") return void 0;
|
|
18406
18799
|
throw error;
|
|
@@ -18465,7 +18858,7 @@ async function readAssistantUsageFromSessionFile(sessionFile) {
|
|
|
18465
18858
|
}
|
|
18466
18859
|
function sessionFileFromPublicSummon(summoned) {
|
|
18467
18860
|
if (typeof summoned.runDirectory === "string" && summoned.runDirectory.trim() !== "") {
|
|
18468
|
-
return
|
|
18861
|
+
return join34(summoned.runDirectory, "session", "session.jsonl");
|
|
18469
18862
|
}
|
|
18470
18863
|
const fromArtifacts = summoned.terminal?.artifacts?.map((a) => a.path).find((p) => typeof p === "string" && p.endsWith("session.jsonl"));
|
|
18471
18864
|
if (fromArtifacts !== void 0) return fromArtifacts;
|
|
@@ -18474,7 +18867,7 @@ function sessionFileFromPublicSummon(summoned) {
|
|
|
18474
18867
|
const facts = outcome.decisiveFacts;
|
|
18475
18868
|
const pointer = facts?.runPointer;
|
|
18476
18869
|
if (typeof pointer === "string" && pointer.trim() !== "") {
|
|
18477
|
-
return
|
|
18870
|
+
return join34(pointer, "session", "session.jsonl");
|
|
18478
18871
|
}
|
|
18479
18872
|
return void 0;
|
|
18480
18873
|
}
|
|
@@ -18653,8 +19046,8 @@ var init_doctor_auditor = __esm({
|
|
|
18653
19046
|
});
|
|
18654
19047
|
|
|
18655
19048
|
// src/archivist-record-topology.ts
|
|
18656
|
-
import { createHash as
|
|
18657
|
-
import { join as
|
|
19049
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
19050
|
+
import { join as join35 } from "node:path";
|
|
18658
19051
|
function resolveNavigatorWorkSubjectPlacement(input) {
|
|
18659
19052
|
let ledgerHome;
|
|
18660
19053
|
if (input.parentSessionFile !== void 0 && input.parentSessionFile.length > 0) {
|
|
@@ -18664,10 +19057,10 @@ function resolveNavigatorWorkSubjectPlacement(input) {
|
|
|
18664
19057
|
}
|
|
18665
19058
|
}
|
|
18666
19059
|
ledgerHome ??= resolveActivationLedgerHome(input.home);
|
|
18667
|
-
const digest =
|
|
19060
|
+
const digest = createHash7("sha256").update(input.subject).digest("hex").slice(0, 32);
|
|
18668
19061
|
return {
|
|
18669
19062
|
ledgerHome,
|
|
18670
|
-
sessionDir:
|
|
19063
|
+
sessionDir: join35(
|
|
18671
19064
|
activationBookDirectory(ledgerHome, resolveBookKeyFromGit(input.cwd)),
|
|
18672
19065
|
NAVIGATOR_RECORD_KIND,
|
|
18673
19066
|
digest
|
|
@@ -18698,20 +19091,20 @@ __export(archivist_record_entry_exports, {
|
|
|
18698
19091
|
import {
|
|
18699
19092
|
closeSync,
|
|
18700
19093
|
existsSync as existsSync11,
|
|
18701
|
-
mkdirSync as
|
|
19094
|
+
mkdirSync as mkdirSync2,
|
|
18702
19095
|
openSync,
|
|
18703
19096
|
readdirSync as readdirSync2,
|
|
18704
19097
|
readFileSync as readFileSync3,
|
|
18705
19098
|
readSync,
|
|
18706
19099
|
realpathSync as realpathSync2,
|
|
18707
19100
|
statSync as statSync3,
|
|
18708
|
-
writeFileSync as
|
|
19101
|
+
writeFileSync as writeFileSync2
|
|
18709
19102
|
} from "node:fs";
|
|
18710
|
-
import { dirname as
|
|
19103
|
+
import { dirname as dirname18, resolve as resolve14, join as join36 } from "node:path";
|
|
18711
19104
|
import { StringDecoder } from "node:string_decoder";
|
|
18712
19105
|
import { SessionManager } from "@earendil-works/pi-coding-agent";
|
|
18713
19106
|
function readCurrentSession(sessionDir) {
|
|
18714
|
-
const ledger =
|
|
19107
|
+
const ledger = join36(sessionDir, CURRENT_SESSION_LEDGER);
|
|
18715
19108
|
try {
|
|
18716
19109
|
const value = JSON.parse(readFileSync3(ledger, "utf8"));
|
|
18717
19110
|
if (typeof value !== "object" || value === null || typeof value.sessionFile !== "string" || value.sessionFile.length === 0) {
|
|
@@ -18726,9 +19119,9 @@ function readCurrentSession(sessionDir) {
|
|
|
18726
19119
|
}
|
|
18727
19120
|
}
|
|
18728
19121
|
function writeCurrentSession(sessionDir, sessionFile) {
|
|
18729
|
-
const ledger =
|
|
19122
|
+
const ledger = join36(sessionDir, CURRENT_SESSION_LEDGER);
|
|
18730
19123
|
try {
|
|
18731
|
-
|
|
19124
|
+
writeFileSync2(ledger, `${JSON.stringify({ sessionFile })}
|
|
18732
19125
|
`, { flag: "wx" });
|
|
18733
19126
|
} catch (error) {
|
|
18734
19127
|
throw new ActivationLedgerError(
|
|
@@ -18742,7 +19135,7 @@ function isCurrentSessionClaimRace(error) {
|
|
|
18742
19135
|
return errnoCode(error.cause) === "EEXIST";
|
|
18743
19136
|
}
|
|
18744
19137
|
function currentSessionLedgerPath(sessionDir) {
|
|
18745
|
-
return
|
|
19138
|
+
return join36(sessionDir, CURRENT_SESSION_LEDGER);
|
|
18746
19139
|
}
|
|
18747
19140
|
function readBoundedSessionHeader(filePath) {
|
|
18748
19141
|
const fd = openSync(filePath, "r");
|
|
@@ -18815,8 +19208,8 @@ function parseSessionHeaderLine(line2) {
|
|
|
18815
19208
|
};
|
|
18816
19209
|
}
|
|
18817
19210
|
function mostRecentNavigatorSessionFile(sessionDir, cwd) {
|
|
18818
|
-
const absoluteSessionDir =
|
|
18819
|
-
const absoluteCwd =
|
|
19211
|
+
const absoluteSessionDir = resolve14(sessionDir);
|
|
19212
|
+
const absoluteCwd = resolve14(cwd);
|
|
18820
19213
|
let names;
|
|
18821
19214
|
try {
|
|
18822
19215
|
names = readdirSync2(absoluteSessionDir);
|
|
@@ -18829,7 +19222,7 @@ function mostRecentNavigatorSessionFile(sessionDir, cwd) {
|
|
|
18829
19222
|
const matched = [];
|
|
18830
19223
|
for (const name of names) {
|
|
18831
19224
|
if (!name.endsWith(".jsonl")) continue;
|
|
18832
|
-
const filePath =
|
|
19225
|
+
const filePath = join36(absoluteSessionDir, name);
|
|
18833
19226
|
let st;
|
|
18834
19227
|
try {
|
|
18835
19228
|
st = statSync3(filePath);
|
|
@@ -18851,7 +19244,7 @@ function mostRecentNavigatorSessionFile(sessionDir, cwd) {
|
|
|
18851
19244
|
}
|
|
18852
19245
|
if (header === void 0) continue;
|
|
18853
19246
|
if (typeof header.cwd !== "string" || header.cwd.length === 0) continue;
|
|
18854
|
-
if (
|
|
19247
|
+
if (resolve14(header.cwd) !== absoluteCwd) continue;
|
|
18855
19248
|
matched.push({ path: filePath, mtimeMs: st.mtimeMs });
|
|
18856
19249
|
}
|
|
18857
19250
|
if (matched.length === 0) return void 0;
|
|
@@ -18881,8 +19274,8 @@ function resolveNavigatorNestContinuation(sessionDir, cwd) {
|
|
|
18881
19274
|
}
|
|
18882
19275
|
}
|
|
18883
19276
|
function assertRecentFinalFileUnderSessionDir(sessionDir, recentFile) {
|
|
18884
|
-
const absoluteSessionDir =
|
|
18885
|
-
const absoluteFile =
|
|
19277
|
+
const absoluteSessionDir = resolve14(sessionDir);
|
|
19278
|
+
const absoluteFile = resolve14(recentFile);
|
|
18886
19279
|
if (absoluteFile !== absoluteSessionDir && !pathContainedIn(absoluteSessionDir, absoluteFile)) {
|
|
18887
19280
|
throw new ActivationLedgerError(
|
|
18888
19281
|
`archivist record session must be under the authorized nest (${sessionDir}): ${recentFile}`
|
|
@@ -18937,11 +19330,11 @@ function createRecordSessionOpen(options) {
|
|
|
18937
19330
|
throw new Error("Durable record ownership requires a parent session inside the ledger home");
|
|
18938
19331
|
} else {
|
|
18939
19332
|
ledgerHome = resolveActivationLedgerHomeForPath(parentFile);
|
|
18940
|
-
const parentResolved =
|
|
19333
|
+
const parentResolved = resolve14(parentFile);
|
|
18941
19334
|
if (!physicallyContainedIn(ledgerHome, parentResolved)) {
|
|
18942
19335
|
throw new Error("Durable record ownership requires a parent session inside the ledger home");
|
|
18943
19336
|
}
|
|
18944
|
-
sessionDir =
|
|
19337
|
+
sessionDir = join36(dirname18(parentResolved), options.kind);
|
|
18945
19338
|
parentSession = parentFile;
|
|
18946
19339
|
mayResumeSameNest = options.kind === WORKER_SUBMISSION_GATE_KIND;
|
|
18947
19340
|
}
|
|
@@ -18975,7 +19368,7 @@ function createRecordSessionOpen(options) {
|
|
|
18975
19368
|
if (file !== void 0 && !existsSync11(file)) {
|
|
18976
19369
|
const header = session.getHeader();
|
|
18977
19370
|
if (header !== null && header.type === "session") {
|
|
18978
|
-
|
|
19371
|
+
writeFileSync2(file, `${JSON.stringify(header)}
|
|
18979
19372
|
`, { flag: "wx" });
|
|
18980
19373
|
session.setSessionFile(file);
|
|
18981
19374
|
}
|
|
@@ -18990,8 +19383,8 @@ function createRecordSession(options) {
|
|
|
18990
19383
|
return createRecordSessionOpen(options).session;
|
|
18991
19384
|
}
|
|
18992
19385
|
function bookDirectOfficerRunPointer(options) {
|
|
18993
|
-
const nest =
|
|
18994
|
-
|
|
19386
|
+
const nest = join36(dirname18(options.parentSessionFile), "auditor-roles");
|
|
19387
|
+
mkdirSync2(nest, { recursive: true });
|
|
18995
19388
|
const pointer = {
|
|
18996
19389
|
version: 1,
|
|
18997
19390
|
kind: DIRECT_OFFICER_RUN_POINTER_KIND,
|
|
@@ -18999,8 +19392,8 @@ function bookDirectOfficerRunPointer(options) {
|
|
|
18999
19392
|
sessionFile: options.sessionFile,
|
|
19000
19393
|
...options.runDirectory !== void 0 && options.runDirectory.trim() !== "" ? { runDirectory: options.runDirectory } : {}
|
|
19001
19394
|
};
|
|
19002
|
-
|
|
19003
|
-
|
|
19395
|
+
writeFileSync2(
|
|
19396
|
+
join36(nest, `${options.officer}.pointer.json`),
|
|
19004
19397
|
`${JSON.stringify(pointer)}
|
|
19005
19398
|
`,
|
|
19006
19399
|
"utf8"
|
|
@@ -19026,7 +19419,7 @@ var init_archivist_record_entry = __esm({
|
|
|
19026
19419
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
19027
19420
|
|
|
19028
19421
|
// src/role-runtime-dependencies.ts
|
|
19029
|
-
import { readFile as
|
|
19422
|
+
import { readFile as readFile24 } from "node:fs/promises";
|
|
19030
19423
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
19031
19424
|
|
|
19032
19425
|
// src/canonical-skill-binding.ts
|
|
@@ -19100,11 +19493,11 @@ init_doctor_auditor();
|
|
|
19100
19493
|
init_doctor_evidence();
|
|
19101
19494
|
|
|
19102
19495
|
// src/navigator-attendance.ts
|
|
19103
|
-
import { createHash as
|
|
19496
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
19104
19497
|
init_navigator_invocation_identity();
|
|
19105
19498
|
init_packaged_role_registry();
|
|
19106
19499
|
init_activation_ledger_topology();
|
|
19107
|
-
import { resolve as
|
|
19500
|
+
import { resolve as resolve15 } from "node:path";
|
|
19108
19501
|
import "@earendil-works/pi-coding-agent";
|
|
19109
19502
|
import { Type as Type13 } from "typebox";
|
|
19110
19503
|
|
|
@@ -19560,11 +19953,11 @@ function navigatorSubjectKey(subjectRoot, subject, provenance = "role_input") {
|
|
|
19560
19953
|
if (provenance === "placeholder") return subjectRoot;
|
|
19561
19954
|
const normalized = subject.trim().replace(/\s+/g, " ");
|
|
19562
19955
|
if (normalized === "") return subjectRoot;
|
|
19563
|
-
return `${subjectRoot}#${
|
|
19956
|
+
return `${subjectRoot}#${createHash8("sha256").update(normalized).digest("hex").slice(0, 32)}`;
|
|
19564
19957
|
}
|
|
19565
19958
|
function navigatorSubjectKeyForInput(subjectRoot, reference, cwd = process.cwd()) {
|
|
19566
19959
|
if (issueRoot(subjectRoot) !== void 0 || !subjectRoot.includes("/.ak/work/")) return subjectRoot;
|
|
19567
|
-
const resolvedReference =
|
|
19960
|
+
const resolvedReference = resolve15(cwd, reference);
|
|
19568
19961
|
const marker = "/runs/";
|
|
19569
19962
|
if (resolvedReference.includes(marker)) {
|
|
19570
19963
|
return subjectRoot;
|
|
@@ -20075,8 +20468,8 @@ ${helpContext}
|
|
|
20075
20468
|
// src/navigator-work-context.ts
|
|
20076
20469
|
init_doctor_evidence();
|
|
20077
20470
|
init_host_contracts();
|
|
20078
|
-
import { readFile as
|
|
20079
|
-
import { resolve as
|
|
20471
|
+
import { readFile as readFile22 } from "node:fs/promises";
|
|
20472
|
+
import { resolve as resolve16 } from "node:path";
|
|
20080
20473
|
init_notary_source_run();
|
|
20081
20474
|
init_packaged_role_registry();
|
|
20082
20475
|
init_invocation();
|
|
@@ -20084,11 +20477,11 @@ function navigatorInputReference(getFlag, role) {
|
|
|
20084
20477
|
if (getFlag === void 0) return void 0;
|
|
20085
20478
|
const name = packagedRoleInputFlag(role);
|
|
20086
20479
|
const value = name === void 0 ? void 0 : getFlag(name);
|
|
20087
|
-
return typeof value === "string" && value !== "" ?
|
|
20480
|
+
return typeof value === "string" && value !== "" ? resolve16(value) : void 0;
|
|
20088
20481
|
}
|
|
20089
20482
|
async function loadNavigatorWorkContext(options) {
|
|
20090
20483
|
const reference = navigatorInputReference(options.getFlag, options.role);
|
|
20091
|
-
const input = reference === void 0 || options.role === "doctor" || options.role === "notary" ? void 0 : await
|
|
20484
|
+
const input = reference === void 0 || options.role === "doctor" || options.role === "notary" ? void 0 : await readFile22(reference, "utf8");
|
|
20092
20485
|
const subjectRoot = subjectPath(reference ?? options.context.sessionManager.getSessionDir(), options.context.cwd);
|
|
20093
20486
|
let subjectKey = reference === void 0 ? subjectRoot : navigatorSubjectKeyForInput(subjectRoot, reference, options.context.cwd);
|
|
20094
20487
|
let subject = input ?? `work subject: ${subjectKey}`;
|
|
@@ -20105,7 +20498,7 @@ async function loadNavigatorWorkContext(options) {
|
|
|
20105
20498
|
}
|
|
20106
20499
|
const publicRunDir = runDirectoryFromHostContext(options.context);
|
|
20107
20500
|
const currentSessionDir = options.context.sessionManager.getSessionDir();
|
|
20108
|
-
const isBoundPublicRun = publicRunDir !== void 0 &&
|
|
20501
|
+
const isBoundPublicRun = publicRunDir !== void 0 && resolve16(currentSessionDir) === resolve16(publicRunDir, "session");
|
|
20109
20502
|
if (options.role === "judge" && isBoundPublicRun) {
|
|
20110
20503
|
let admitted;
|
|
20111
20504
|
try {
|
|
@@ -20138,14 +20531,14 @@ async function loadNavigatorWorkContext(options) {
|
|
|
20138
20531
|
}
|
|
20139
20532
|
const workRoot = subjectRoot.includes("/.ak/work/") ? subjectRoot : void 0;
|
|
20140
20533
|
const authorityFiles = workRoot === void 0 ? [] : [
|
|
20141
|
-
|
|
20142
|
-
|
|
20143
|
-
|
|
20534
|
+
resolve16(workRoot, "authority.md"),
|
|
20535
|
+
resolve16(workRoot, "authority.txt"),
|
|
20536
|
+
resolve16(workRoot, "design-v2/owner-direction.md")
|
|
20144
20537
|
];
|
|
20145
20538
|
let authorityMaterial;
|
|
20146
20539
|
for (const path of authorityFiles) {
|
|
20147
20540
|
try {
|
|
20148
|
-
const content = await
|
|
20541
|
+
const content = await readFile22(path, "utf8");
|
|
20149
20542
|
if (content.trim() !== "") {
|
|
20150
20543
|
authorityMaterial = content;
|
|
20151
20544
|
break;
|
|
@@ -20170,7 +20563,7 @@ async function loadNavigatorWorkContext(options) {
|
|
|
20170
20563
|
init_notary_source_run();
|
|
20171
20564
|
|
|
20172
20565
|
// src/package-resources/method-skill-binding.ts
|
|
20173
|
-
import { dirname as
|
|
20566
|
+
import { dirname as dirname20 } from "node:path";
|
|
20174
20567
|
init_method_skill();
|
|
20175
20568
|
async function loadPackagedCanonicalSkillBinding(packageRoot, name) {
|
|
20176
20569
|
const material = await loadPackagedMethodSkillMaterial(packageRoot, name);
|
|
@@ -20178,7 +20571,7 @@ async function loadPackagedCanonicalSkillBinding(packageRoot, name) {
|
|
|
20178
20571
|
const snapshot = Object.freeze({
|
|
20179
20572
|
raw: material.raw,
|
|
20180
20573
|
path: material.skillPath,
|
|
20181
|
-
baseDir:
|
|
20574
|
+
baseDir: dirname20(material.skillPath),
|
|
20182
20575
|
body: material.body,
|
|
20183
20576
|
snapshotIdentity: Object.freeze({ text: material.raw })
|
|
20184
20577
|
});
|
|
@@ -20254,7 +20647,7 @@ import {
|
|
|
20254
20647
|
openSync as openSync2,
|
|
20255
20648
|
writeSync
|
|
20256
20649
|
} from "node:fs";
|
|
20257
|
-
import { dirname as
|
|
20650
|
+
import { dirname as dirname21, isAbsolute as isAbsolute10, resolve as resolve18 } from "node:path";
|
|
20258
20651
|
|
|
20259
20652
|
// src/activation-ledger-session.ts
|
|
20260
20653
|
init_activation_ledger_topology();
|
|
@@ -20262,9 +20655,9 @@ import {
|
|
|
20262
20655
|
lstatSync as lstatSync2,
|
|
20263
20656
|
realpathSync as realpathSync3,
|
|
20264
20657
|
statSync as statSync4,
|
|
20265
|
-
writeFileSync as
|
|
20658
|
+
writeFileSync as writeFileSync3
|
|
20266
20659
|
} from "node:fs";
|
|
20267
|
-
import { isAbsolute as isAbsolute9, resolve as
|
|
20660
|
+
import { isAbsolute as isAbsolute9, resolve as resolve17 } from "node:path";
|
|
20268
20661
|
var ActivationSessionFileMissingError = class extends Error {
|
|
20269
20662
|
code = "AK_ACTIVATION_SESSION_FILE_MISSING";
|
|
20270
20663
|
path;
|
|
@@ -20283,7 +20676,7 @@ function materializeDeferredSessionFile(sessionManager, resolvedFile) {
|
|
|
20283
20676
|
throw new ActivationSessionFileMissingError(resolvedFile);
|
|
20284
20677
|
}
|
|
20285
20678
|
try {
|
|
20286
|
-
|
|
20679
|
+
writeFileSync3(resolvedFile, `${JSON.stringify(header)}
|
|
20287
20680
|
`, { flag: "wx" });
|
|
20288
20681
|
} catch (error) {
|
|
20289
20682
|
if (errnoCode(error) !== "EEXIST") {
|
|
@@ -20309,7 +20702,7 @@ function durableSessionPointer(sessionManager) {
|
|
|
20309
20702
|
`Workflow role activation requires an absolute durable session file path; got relative path: ${file}`
|
|
20310
20703
|
);
|
|
20311
20704
|
}
|
|
20312
|
-
const resolvedFile =
|
|
20705
|
+
const resolvedFile = resolve17(file);
|
|
20313
20706
|
try {
|
|
20314
20707
|
lstatSync2(resolvedFile);
|
|
20315
20708
|
} catch (error) {
|
|
@@ -20401,9 +20794,9 @@ function appendActivationLedgerLine(ledgerPath, line2, options) {
|
|
|
20401
20794
|
`activation ledger home must be absolute: ${options.ledgerHome}`
|
|
20402
20795
|
);
|
|
20403
20796
|
}
|
|
20404
|
-
const resolvedLedger =
|
|
20405
|
-
const resolvedHome =
|
|
20406
|
-
const parent =
|
|
20797
|
+
const resolvedLedger = resolve18(ledgerPath);
|
|
20798
|
+
const resolvedHome = resolve18(options.ledgerHome);
|
|
20799
|
+
const parent = dirname21(resolvedLedger);
|
|
20407
20800
|
ensureRealDirectoryTree(resolvedHome, parent);
|
|
20408
20801
|
assertLedgerFileInsideHome(resolvedLedger, resolvedHome);
|
|
20409
20802
|
if (typeof constants2.O_NOFOLLOW !== "number") {
|
|
@@ -20711,27 +21104,10 @@ init_collector_evidence();
|
|
|
20711
21104
|
init_collector_github();
|
|
20712
21105
|
|
|
20713
21106
|
// src/collector-handbook.ts
|
|
20714
|
-
|
|
20715
|
-
import { join as join38, sep as sep5 } from "node:path";
|
|
20716
|
-
|
|
20717
|
-
// src/atomic-write.ts
|
|
20718
|
-
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
20719
|
-
import { rename as rename3, rm as rm3, writeFile as writeFile11 } from "node:fs/promises";
|
|
20720
|
-
import { dirname as dirname20, join as join37 } from "node:path";
|
|
20721
|
-
async function writeFileAtomically(destination, contents) {
|
|
20722
|
-
const parent = dirname20(destination);
|
|
20723
|
-
const temporary = join37(parent, `.atomic-write-${randomUUID6()}.tmp`);
|
|
20724
|
-
try {
|
|
20725
|
-
await writeFile11(temporary, contents);
|
|
20726
|
-
await rename3(temporary, destination);
|
|
20727
|
-
} catch (error) {
|
|
20728
|
-
await rm3(temporary, { force: true }).catch(() => void 0);
|
|
20729
|
-
throw error;
|
|
20730
|
-
}
|
|
20731
|
-
}
|
|
20732
|
-
|
|
20733
|
-
// src/collector-handbook.ts
|
|
21107
|
+
init_atomic_write();
|
|
20734
21108
|
init_activation_ledger_topology();
|
|
21109
|
+
import { readFile as readFile23 } from "node:fs/promises";
|
|
21110
|
+
import { join as join38, sep as sep5 } from "node:path";
|
|
20735
21111
|
|
|
20736
21112
|
// src/collector-tool-schemas.ts
|
|
20737
21113
|
init_open_tool_schema();
|
|
@@ -20874,7 +21250,7 @@ function createCollectorHandbookStore(input) {
|
|
|
20874
21250
|
ensureRealDirectoryTree(input.ledgerHome, parentDir2);
|
|
20875
21251
|
assertLedgerFileInsideHome(path, input.ledgerHome);
|
|
20876
21252
|
try {
|
|
20877
|
-
const body = await
|
|
21253
|
+
const body = await readFile23(path, "utf8");
|
|
20878
21254
|
assertHandbookBudget(body, "\u6B63\u6587");
|
|
20879
21255
|
return body;
|
|
20880
21256
|
} catch (error) {
|
|
@@ -21795,33 +22171,80 @@ var diaristOutputSchema = withInfrastructureFailureDeclaration(
|
|
|
21795
22171
|
description: "status \u4E3A escalate \u65F6\uFF1A\u8BA4\u4E0D\u51FA\u672C\u5EAD\u5BF9\u8C61\u7684\u539F\u56E0"
|
|
21796
22172
|
})
|
|
21797
22173
|
),
|
|
21798
|
-
|
|
22174
|
+
sessions: Type21.Optional(
|
|
21799
22175
|
Type21.Array(
|
|
21800
22176
|
Type21.Object(
|
|
21801
22177
|
{
|
|
21802
|
-
|
|
21803
|
-
description: "\
|
|
21804
|
-
|
|
21805
|
-
|
|
21806
|
-
|
|
21807
|
-
|
|
21808
|
-
|
|
21809
|
-
|
|
21810
|
-
|
|
21811
|
-
|
|
21812
|
-
|
|
21813
|
-
|
|
21814
|
-
|
|
21815
|
-
|
|
21816
|
-
|
|
21817
|
-
|
|
21818
|
-
|
|
21819
|
-
|
|
22178
|
+
path: Type21.Optional(
|
|
22179
|
+
Type21.String({ description: "\u4F1A\u8BDD\u5377\u7EDD\u5BF9\u6216\u53EF\u8BFB\u8DEF\u5F84" })
|
|
22180
|
+
),
|
|
22181
|
+
ranges: Type21.Optional(
|
|
22182
|
+
Type21.Array(
|
|
22183
|
+
Type21.Object(
|
|
22184
|
+
{
|
|
22185
|
+
from: Type21.Optional(
|
|
22186
|
+
Type21.Object(
|
|
22187
|
+
{
|
|
22188
|
+
id: Type21.Optional(Type21.String()),
|
|
22189
|
+
line: Type21.Optional(Type21.Unknown())
|
|
22190
|
+
},
|
|
22191
|
+
{
|
|
22192
|
+
additionalProperties: true,
|
|
22193
|
+
description: "\u8D77\u70B9\uFF1A\u539F\u751F id \u6216\u672C\u8F6E\u884C\u53F7\u4E8C\u9009\u4E00"
|
|
22194
|
+
}
|
|
22195
|
+
)
|
|
22196
|
+
),
|
|
22197
|
+
to: Type21.Optional(
|
|
22198
|
+
Type21.Object(
|
|
22199
|
+
{
|
|
22200
|
+
id: Type21.Optional(Type21.String()),
|
|
22201
|
+
line: Type21.Optional(Type21.Unknown())
|
|
22202
|
+
},
|
|
22203
|
+
{
|
|
22204
|
+
additionalProperties: true,
|
|
22205
|
+
description: "\u7EC8\u70B9\uFF1A\u539F\u751F id \u6216\u672C\u8F6E\u884C\u53F7\u4E8C\u9009\u4E00"
|
|
22206
|
+
}
|
|
22207
|
+
)
|
|
22208
|
+
)
|
|
22209
|
+
},
|
|
22210
|
+
{ additionalProperties: true, description: "\u4E00\u6BB5\u5BF9\u8BDD\u533A\u95F4" }
|
|
22211
|
+
),
|
|
22212
|
+
{ description: "\u672C\u5377\u672C\u8F6E\u5404\u533A\u95F4\uFF1B\u81F3\u5C11\u4E00\u6BB5" }
|
|
22213
|
+
)
|
|
21820
22214
|
)
|
|
21821
22215
|
},
|
|
21822
|
-
{ additionalProperties: true, description: "\u4E00\
|
|
22216
|
+
{ additionalProperties: true, description: "\u4E00\u5377\u4F1A\u8BDD\u7684\u8FB9\u754C" }
|
|
21823
22217
|
),
|
|
21824
|
-
{
|
|
22218
|
+
{
|
|
22219
|
+
description: "\u672C\u7968\u5BF9\u8BDD\u8FB9\u754C\uFF1B\u7A7A\u5217\u8868\uFF1D\u672C\u8F6E\u65E0\u5BF9\u8BDD\u53EF\u5212\u3002\u7AEF\u70B9\u65E0\u6CD5\u6307\u540D\u65F6\u8D70 reask\uFF0C\u4E0D\u4E2D\u6B62\u3002"
|
|
22220
|
+
}
|
|
22221
|
+
)
|
|
22222
|
+
),
|
|
22223
|
+
amendments: Type21.Optional(
|
|
22224
|
+
Type21.Array(
|
|
22225
|
+
Type21.Object(
|
|
22226
|
+
{
|
|
22227
|
+
s: Type21.Optional(
|
|
22228
|
+
Type21.Unknown({ description: "\u5377\u4E0B\u6807\uFF08sessions \u4F4D\u7F6E\uFF09" })
|
|
22229
|
+
),
|
|
22230
|
+
line: Type21.Optional(
|
|
22231
|
+
Type21.Unknown({ description: "\u6E90\u5377 1-based \u884C\u53F7" })
|
|
22232
|
+
),
|
|
22233
|
+
speaker: Type21.Optional(
|
|
22234
|
+
Type21.String({ description: "owner | runner" })
|
|
22235
|
+
),
|
|
22236
|
+
text: Type21.Optional(
|
|
22237
|
+
Type21.String({ description: "\u8865\u5199\u6B63\u6587\uFF08\u539F\u8BDD\uFF09" })
|
|
22238
|
+
)
|
|
22239
|
+
},
|
|
22240
|
+
{
|
|
22241
|
+
additionalProperties: true,
|
|
22242
|
+
description: "\u4E00\u6761\u574F\u884C\u8865\u5199\uFF1B\u7F3A\u5B57\u6BB5\u7684\u6210\u5458\u673A\u68B0\u8DF3\u8FC7"
|
|
22243
|
+
}
|
|
22244
|
+
),
|
|
22245
|
+
{
|
|
22246
|
+
description: "\u53EF\u9009\uFF1B\u673A\u68B0\u89E3\u6790\u4E0D\u4E86\u7684\u884C\u4EA4\u6B64\u8865\u5199\u3002\u7F3A\u672C\u5B57\u6BB5\uFF1D\u65E0\u8865\u5199\uFF0C\u4E0D\u62D2\u6536\u3002"
|
|
22247
|
+
}
|
|
21825
22248
|
)
|
|
21826
22249
|
)
|
|
21827
22250
|
})
|
|
@@ -21830,8 +22253,8 @@ var diaristOutputSchema = withInfrastructureFailureDeclaration(
|
|
|
21830
22253
|
var DIARIST_TOOL_SPEC = {
|
|
21831
22254
|
name: DIARIST_OUTPUT_TOOL_NAME,
|
|
21832
22255
|
label: "\u8D77\u5C45\u90CE\u8F93\u51FA",
|
|
21833
|
-
description: "\u8D77\u5C45\u90CE\
|
|
21834
|
-
promptSnippet: "\u8D77\u5C45\u90CE\
|
|
22256
|
+
description: "\u8D77\u5C45\u90CE\u4EA4\u672C\u7968\u5BF9\u8BDD\u8FB9\u754C\uFF08sessions\uFF09\u4E0E\u53EF\u9009\u574F\u884C\u8865\u5199\uFF08amendments\uFF09\uFF1B\u8BA4\u4E0D\u51FA\u672C\u5EAD\u5BF9\u8C61\u5219 escalate\u3002",
|
|
22257
|
+
promptSnippet: "\u8D77\u5C45\u90CE\u4EA4\u8FB9\u754C\u4E0E\u53EF\u9009\u8865\u5199",
|
|
21835
22258
|
parameters: diaristOutputSchema
|
|
21836
22259
|
};
|
|
21837
22260
|
|
|
@@ -21840,46 +22263,24 @@ init_diarist_contracts();
|
|
|
21840
22263
|
|
|
21841
22264
|
// src/diarist.ts
|
|
21842
22265
|
init_ticket_provenance();
|
|
21843
|
-
|
|
21844
|
-
|
|
21845
|
-
|
|
21846
|
-
|
|
21847
|
-
|
|
21848
|
-
|
|
21849
|
-
|
|
21850
|
-
for (const submitted of input.entries) {
|
|
21851
|
-
if (projectTicketProvenanceEntry(submitted) === void 0) {
|
|
21852
|
-
dropped += 1;
|
|
21853
|
-
}
|
|
21854
|
-
appendTicketProvenanceEntry({
|
|
21855
|
-
ticketNumber,
|
|
21856
|
-
cwd,
|
|
21857
|
-
sessionParent: input.sessionParent,
|
|
21858
|
-
...homeOpt,
|
|
21859
|
-
payload: submitted,
|
|
21860
|
-
source: "diarist"
|
|
21861
|
-
});
|
|
21862
|
-
}
|
|
21863
|
-
const volume = await readTicketProvenance(ticketNumber, cwd, input.home);
|
|
21864
|
-
const humanViewFile = writeTicketProvenanceHumanView({
|
|
21865
|
-
ticketNumber,
|
|
21866
|
-
cwd,
|
|
21867
|
-
...homeOpt,
|
|
21868
|
-
entries: volume.entries,
|
|
21869
|
-
unprojected: volume.unprojected
|
|
22266
|
+
async function commitDiaristProjection(input) {
|
|
22267
|
+
const result = await reprojectTicketProvenance({
|
|
22268
|
+
ticketNumber: input.ticketNumber,
|
|
22269
|
+
cwd: input.cwd,
|
|
22270
|
+
...input.home === void 0 ? {} : { home: input.home },
|
|
22271
|
+
sessions: input.sessions,
|
|
22272
|
+
...input.amendments === void 0 ? {} : { amendments: input.amendments }
|
|
21870
22273
|
});
|
|
21871
|
-
const appended = volume.entries.length - before.entries.length;
|
|
21872
22274
|
return {
|
|
21873
|
-
ticketNumber,
|
|
21874
|
-
|
|
21875
|
-
|
|
21876
|
-
|
|
21877
|
-
humanViewFile,
|
|
21878
|
-
collectorStatus: appended > 0 ? "ok" : input.entries.length === 0 ? "empty-selection" : "nothing-appended"
|
|
22275
|
+
ticketNumber: input.ticketNumber,
|
|
22276
|
+
volumeRecordFile: result.recordFile,
|
|
22277
|
+
lineCount: result.lines.length,
|
|
22278
|
+
unparsable: result.unparsable
|
|
21879
22279
|
};
|
|
21880
22280
|
}
|
|
21881
22281
|
|
|
21882
22282
|
// src/role-runtime.ts
|
|
22283
|
+
init_ticket_provenance();
|
|
21883
22284
|
init_invocation();
|
|
21884
22285
|
init_gatekeeper_role();
|
|
21885
22286
|
|
|
@@ -22032,9 +22433,9 @@ init_reviewer_pinned_git();
|
|
|
22032
22433
|
init_reviewer_output();
|
|
22033
22434
|
import { Type as Type23 } from "typebox";
|
|
22034
22435
|
var reviewerAmendmentsSchema = Type23.Object({
|
|
22035
|
-
standards: Type23.Optional(Type23.String({ description: "\
|
|
22036
|
-
spec: Type23.Optional(Type23.String({ description: "\
|
|
22037
|
-
}, { additionalProperties: true, description: "\
|
|
22436
|
+
standards: Type23.Optional(Type23.String({ description: "\u6807\u51C6\u8F74\u5F39\u7AE0\u6B63\u6587" })),
|
|
22437
|
+
spec: Type23.Optional(Type23.String({ description: "\u89C4\u683C\u8F74\u5F39\u7AE0\u6B63\u6587" }))
|
|
22438
|
+
}, { additionalProperties: true, description: "\u9010\u8F74\u5F39\u7AE0\u6B63\u6587\uFF1B\u65E0\u5F39\u7AE0\u7684\u8F74\u53EF\u7701\u7565\u3002" });
|
|
22038
22439
|
var REVIEWER_STATUS_DESCRIPTION = "completed | refused \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8";
|
|
22039
22440
|
var reviewerOutputVariants = Type23.Union([
|
|
22040
22441
|
Type23.Object({
|
|
@@ -22109,7 +22510,7 @@ init_submission_errors();
|
|
|
22109
22510
|
init_submission_errors();
|
|
22110
22511
|
import { execFileSync as execFileSync4 } from "node:child_process";
|
|
22111
22512
|
import { existsSync as existsSync12, lstatSync as lstatSync3, readdirSync as readdirSync3, readFileSync as readFileSync4, rmdirSync, rmSync } from "node:fs";
|
|
22112
|
-
import { resolve as
|
|
22513
|
+
import { resolve as resolve19 } from "node:path";
|
|
22113
22514
|
var WORKER_SUBMISSION_GATE_RECORD_KIND = WORKER_SUBMISSION_GATE_KIND;
|
|
22114
22515
|
var WORKER_COMMIT_BASELINE_ENTRY_TYPE = "commit-baseline";
|
|
22115
22516
|
var WORKER_COMMIT_REMINDER_BOUNCE_ENTRY_TYPE = "commit-reminder-bounce";
|
|
@@ -22158,7 +22559,7 @@ function escapeGitConfigValueRegex(value) {
|
|
|
22158
22559
|
function unsetOwnedHooksPath(file) {
|
|
22159
22560
|
const owned = [];
|
|
22160
22561
|
for (const value of tryGetAll(file, "core.hooksPath")) {
|
|
22161
|
-
if (!ownedHook(
|
|
22562
|
+
if (!ownedHook(resolve19(value, HOOK_FILE))) continue;
|
|
22162
22563
|
try {
|
|
22163
22564
|
gitFile(file, [
|
|
22164
22565
|
"--unset-all",
|
|
@@ -22173,15 +22574,15 @@ function unsetOwnedHooksPath(file) {
|
|
|
22173
22574
|
return owned;
|
|
22174
22575
|
}
|
|
22175
22576
|
function rmOwnedDir(dir) {
|
|
22176
|
-
const hookPath =
|
|
22577
|
+
const hookPath = resolve19(dir, HOOK_FILE);
|
|
22177
22578
|
if (!ownedHook(hookPath)) return;
|
|
22178
22579
|
rmSync(hookPath, { force: true });
|
|
22179
22580
|
if (existsSync12(dir) && readdirSync3(dir).length === 0) rmdirSync(dir);
|
|
22180
22581
|
}
|
|
22181
22582
|
function linkedGitDirs(commonDir) {
|
|
22182
|
-
const root =
|
|
22583
|
+
const root = resolve19(commonDir, "worktrees");
|
|
22183
22584
|
if (!existsSync12(root)) return [];
|
|
22184
|
-
return readdirSync3(root).map((name) =>
|
|
22585
|
+
return readdirSync3(root).map((name) => resolve19(root, name)).filter((dir) => lstatSync3(dir).isDirectory());
|
|
22185
22586
|
}
|
|
22186
22587
|
function uninstallPackageWorkerHooks(cwd) {
|
|
22187
22588
|
let inside;
|
|
@@ -22195,17 +22596,17 @@ function uninstallPackageWorkerHooks(cwd) {
|
|
|
22195
22596
|
const clear = (configFile) => {
|
|
22196
22597
|
for (const hooks of unsetOwnedHooksPath(configFile)) rmOwnedDir(hooks);
|
|
22197
22598
|
};
|
|
22198
|
-
clear(
|
|
22199
|
-
clear(
|
|
22200
|
-
rmOwnedDir(
|
|
22201
|
-
const legacy =
|
|
22599
|
+
clear(resolve19(commonDir, "config"));
|
|
22600
|
+
clear(resolve19(commonDir, "config.worktree"));
|
|
22601
|
+
rmOwnedDir(resolve19(commonDir, HOOKS_DIR));
|
|
22602
|
+
const legacy = resolve19(commonDir, "hooks", HOOK_FILE);
|
|
22202
22603
|
if (ownedHook(legacy)) rmSync(legacy, { force: true });
|
|
22203
22604
|
for (const gitDir of linkedGitDirs(commonDir)) {
|
|
22204
|
-
clear(
|
|
22205
|
-
rmOwnedDir(
|
|
22605
|
+
clear(resolve19(gitDir, "config.worktree"));
|
|
22606
|
+
rmOwnedDir(resolve19(gitDir, HOOKS_DIR));
|
|
22206
22607
|
}
|
|
22207
22608
|
}
|
|
22208
|
-
function
|
|
22609
|
+
function isRecord12(value) {
|
|
22209
22610
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22210
22611
|
}
|
|
22211
22612
|
function unfinishedReasonPresent(details) {
|
|
@@ -22221,7 +22622,7 @@ function readGateState(session) {
|
|
|
22221
22622
|
if (entry.type !== "custom") continue;
|
|
22222
22623
|
if (entry.customType === WORKER_COMMIT_BASELINE_ENTRY_TYPE) {
|
|
22223
22624
|
const data = entry.data;
|
|
22224
|
-
if (
|
|
22625
|
+
if (isRecord12(data) && (data.head === null || typeof data.head === "string")) {
|
|
22225
22626
|
baseline = data.head;
|
|
22226
22627
|
}
|
|
22227
22628
|
} else if (entry.customType === WORKER_COMMIT_REMINDER_BOUNCE_ENTRY_TYPE) {
|
|
@@ -23205,6 +23606,18 @@ function readDiaristRunCoordinates(ctx) {
|
|
|
23205
23606
|
...bound === void 0 ? {} : { boundTicketNumber: bound }
|
|
23206
23607
|
};
|
|
23207
23608
|
}
|
|
23609
|
+
var DIARIST_BOUNDS_REASK = "\u8FB9\u754C\u65E0\u6CD5\u4F7F\u7528\u3002\u8BF7\u91CD\u4EA4 sessions\uFF1A\u6BCF\u5377 path + ranges\uFF0C\u6BCF\u7AEF\u4EE5\u539F\u751F id \u6216\u672C\u8F6E\u884C\u53F7\u4E8C\u9009\u4E00\u6307\u540D\u3002";
|
|
23610
|
+
function diaristUnparsableReask(rows) {
|
|
23611
|
+
const payload = rows.map((row) => ({
|
|
23612
|
+
s: row.s,
|
|
23613
|
+
line: row.line,
|
|
23614
|
+
raw: row.raw
|
|
23615
|
+
}));
|
|
23616
|
+
return [
|
|
23617
|
+
"\u4E0B\u5217\u6E90\u884C\u672A\u80FD\u5F55\u5165\uFF0C\u8BF7\u7ECF amendments \u8865\u5199\uFF08\u6BCF\u6761 s + line + speaker + text\uFF09\uFF1B\u5176\u4F59\u8FB9\u754C\u53EF\u4FDD\u6301\u4E0D\u53D8\u3002",
|
|
23618
|
+
JSON.stringify(payload)
|
|
23619
|
+
].join("\n");
|
|
23620
|
+
}
|
|
23208
23621
|
function createDiaristRoleRuntime(roleHost, dependencies) {
|
|
23209
23622
|
return createFiledOfficerRuntime(
|
|
23210
23623
|
roleHost,
|
|
@@ -23222,13 +23635,33 @@ function createDiaristRoleRuntime(roleHost, dependencies) {
|
|
|
23222
23635
|
if (coords.boundTicketNumber === void 0) {
|
|
23223
23636
|
await bindTicketNumberOnRunDirectory(coords.runDirectory, ticketNumber);
|
|
23224
23637
|
}
|
|
23225
|
-
|
|
23226
|
-
|
|
23227
|
-
|
|
23228
|
-
|
|
23229
|
-
|
|
23230
|
-
|
|
23231
|
-
|
|
23638
|
+
const sessions = projectDiaristSessions(parameters);
|
|
23639
|
+
if (sessions === void 0) {
|
|
23640
|
+
throw new ParentQueueReaskError(DIARIST_BOUNDS_REASK);
|
|
23641
|
+
}
|
|
23642
|
+
const amendments = projectDiaristAmendments(parameters);
|
|
23643
|
+
let facts;
|
|
23644
|
+
try {
|
|
23645
|
+
facts = await commitDiaristProjection({
|
|
23646
|
+
ticketNumber,
|
|
23647
|
+
cwd: coords.projectRoot,
|
|
23648
|
+
home: coords.home,
|
|
23649
|
+
sessions,
|
|
23650
|
+
amendments
|
|
23651
|
+
});
|
|
23652
|
+
} catch (error) {
|
|
23653
|
+
if (error instanceof ParentQueueReaskError) throw error;
|
|
23654
|
+
if (error instanceof TicketProvenanceInputError) {
|
|
23655
|
+
throw new ParentQueueReaskError(
|
|
23656
|
+
`${DIARIST_BOUNDS_REASK}
|
|
23657
|
+
${error.message}`
|
|
23658
|
+
);
|
|
23659
|
+
}
|
|
23660
|
+
throw error;
|
|
23661
|
+
}
|
|
23662
|
+
if (facts.unparsable.length > 0) {
|
|
23663
|
+
throw new ParentQueueReaskError(diaristUnparsableReask(facts.unparsable));
|
|
23664
|
+
}
|
|
23232
23665
|
}
|
|
23233
23666
|
return parameters;
|
|
23234
23667
|
}
|
|
@@ -24140,13 +24573,13 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
24140
24573
|
packageRoot,
|
|
24141
24574
|
loadJudgeSoul: () => loadMainRoleSessionMaterials("judge"),
|
|
24142
24575
|
loadFixerSoul: () => loadMainRoleSessionMaterials("fixer"),
|
|
24143
|
-
loadFixPacket: (path) =>
|
|
24576
|
+
loadFixPacket: (path) => readFile24(path, "utf8"),
|
|
24144
24577
|
loadCoderSoul: () => loadMainRoleSessionMaterials("coder"),
|
|
24145
|
-
loadCoderTask: (path) =>
|
|
24578
|
+
loadCoderTask: (path) => readFile24(path, "utf8"),
|
|
24146
24579
|
loadReviewerSoul: () => loadMainRoleSessionMaterials("reviewer"),
|
|
24147
24580
|
createReviewerPinnedGitReader: () => createReviewerPinnedGitReader(),
|
|
24148
24581
|
loadCollectorSoul: () => loadMainRoleSessionMaterials("collector"),
|
|
24149
|
-
loadCollectorHandbookSeed: () =>
|
|
24582
|
+
loadCollectorHandbookSeed: () => readFile24(collectorHandbookSeedPath, "utf8"),
|
|
24150
24583
|
createCollectorTransport: () => createGhCollectorGitHubTransport(),
|
|
24151
24584
|
loadDoctorSoul: () => loadMainRoleSessionMaterials("doctor"),
|
|
24152
24585
|
loadDoctorCase,
|
|
@@ -24160,7 +24593,7 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
24160
24593
|
loadDiaristSoul: () => loadMainRoleSessionMaterials("diarist"),
|
|
24161
24594
|
loadNotarySourceRun: loadNotarySourceRunLocator,
|
|
24162
24595
|
loadMergerSoul: () => loadMainRoleSessionMaterials("merger"),
|
|
24163
|
-
loadMergerInput: async (path) => JSON.parse(await
|
|
24596
|
+
loadMergerInput: async (path) => JSON.parse(await readFile24(path, "utf8")),
|
|
24164
24597
|
async loadCanonicalSkillBinding(name) {
|
|
24165
24598
|
if (name === "tdd") {
|
|
24166
24599
|
return loadPackagedCanonicalSkillBinding(packageRoot, "tdd");
|
|
@@ -24186,7 +24619,7 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
24186
24619
|
authority: options.authority,
|
|
24187
24620
|
invocationId: options.invocationId,
|
|
24188
24621
|
loadSoul: () => loadMainRoleSessionMaterials("navigator"),
|
|
24189
|
-
loadRoutePlaybook: () =>
|
|
24622
|
+
loadRoutePlaybook: () => readFile24(navigatorRoutePlaybookPath, "utf8"),
|
|
24190
24623
|
loadRoleHelp: async (role) => formatNavigatorRoleHelp(role),
|
|
24191
24624
|
createSession: navigatorSessionFactory,
|
|
24192
24625
|
...options.contextError === void 0 ? {} : { contextError: options.contextError },
|
|
@@ -24198,9 +24631,9 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
24198
24631
|
// src/role-envelope.ts
|
|
24199
24632
|
init_engine_detour();
|
|
24200
24633
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
24201
|
-
import { mkdir as mkdir5, readFile as
|
|
24634
|
+
import { mkdir as mkdir5, readFile as readFile25, writeFile as writeFile12 } from "node:fs/promises";
|
|
24202
24635
|
import { createServer } from "node:net";
|
|
24203
|
-
import { basename as
|
|
24636
|
+
import { basename as basename9, dirname as dirname22, join as join40 } from "node:path";
|
|
24204
24637
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
24205
24638
|
|
|
24206
24639
|
// src/gatekeeper-pass-envelope.ts
|
|
@@ -24285,11 +24718,11 @@ function buildSkillExpansion(methodSkills, prompt) {
|
|
|
24285
24718
|
});
|
|
24286
24719
|
}
|
|
24287
24720
|
async function listen(server, path) {
|
|
24288
|
-
await new Promise((
|
|
24721
|
+
await new Promise((resolve21, reject) => {
|
|
24289
24722
|
server.once("error", reject);
|
|
24290
24723
|
server.listen(path, () => {
|
|
24291
24724
|
server.off("error", reject);
|
|
24292
|
-
|
|
24725
|
+
resolve21();
|
|
24293
24726
|
});
|
|
24294
24727
|
});
|
|
24295
24728
|
}
|
|
@@ -24327,12 +24760,12 @@ async function prepareRoleEnvelope(options) {
|
|
|
24327
24760
|
await mkdir5(request.runDirectory, { recursive: true });
|
|
24328
24761
|
for (const method of request.methods) {
|
|
24329
24762
|
if (method.kind !== "skill") continue;
|
|
24330
|
-
const name =
|
|
24331
|
-
const raw = await
|
|
24763
|
+
const name = basename9(dirname22(method.path));
|
|
24764
|
+
const raw = await readFile25(method.path, "utf8");
|
|
24332
24765
|
methodSkills.set(name, { path: method.path, body: stripSkillFrontmatter(raw).trim() });
|
|
24333
24766
|
}
|
|
24334
24767
|
let sessionFile = options.sessionFile ?? join40(request.runDirectory, "session", "session.jsonl");
|
|
24335
|
-
await mkdir5(
|
|
24768
|
+
await mkdir5(dirname22(sessionFile), { recursive: true });
|
|
24336
24769
|
if (request.continuation.kind !== "resume") {
|
|
24337
24770
|
try {
|
|
24338
24771
|
await writeFile12(
|
|
@@ -24361,7 +24794,7 @@ async function prepareRoleEnvelope(options) {
|
|
|
24361
24794
|
getLeafEntry: () => sessionEntries.at(-1),
|
|
24362
24795
|
getLeafId: () => runId,
|
|
24363
24796
|
getEntries: () => sessionEntries,
|
|
24364
|
-
getSessionDir: () =>
|
|
24797
|
+
getSessionDir: () => dirname22(sessionFile),
|
|
24365
24798
|
getSessionFile: () => sessionFile,
|
|
24366
24799
|
getHeader: () => ({ type: "session", id: runId }),
|
|
24367
24800
|
setSessionFile(path) {
|
|
@@ -24671,8 +25104,8 @@ async function prepareRoleEnvelope(options) {
|
|
|
24671
25104
|
try {
|
|
24672
25105
|
const closeAll = server.closeAllConnections;
|
|
24673
25106
|
if (typeof closeAll === "function") closeAll.call(server);
|
|
24674
|
-
await new Promise((
|
|
24675
|
-
server.close((error) => error ? reject(error) :
|
|
25107
|
+
await new Promise((resolve21, reject) => {
|
|
25108
|
+
server.close((error) => error ? reject(error) : resolve21());
|
|
24676
25109
|
});
|
|
24677
25110
|
} catch (error) {
|
|
24678
25111
|
cleanupFailures.push(error);
|
|
@@ -24736,7 +25169,7 @@ async function prepareRoleEnvelope(options) {
|
|
|
24736
25169
|
message: { role: "user", content: prompt }
|
|
24737
25170
|
});
|
|
24738
25171
|
}
|
|
24739
|
-
const methodPrompt = (await Promise.all(request.methods.map(({ path }) =>
|
|
25172
|
+
const methodPrompt = (await Promise.all(request.methods.map(({ path }) => readFile25(path, "utf8")))).join("\n\n");
|
|
24740
25173
|
const promptResults = await emit("before_agent_start", {
|
|
24741
25174
|
prompt,
|
|
24742
25175
|
systemPrompt: methodPrompt,
|
|
@@ -25061,7 +25494,7 @@ import { spawn as spawn4, spawnSync } from "node:child_process";
|
|
|
25061
25494
|
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
25062
25495
|
import { existsSync as existsSync13 } from "node:fs";
|
|
25063
25496
|
import { writeFile as writeFile13 } from "node:fs/promises";
|
|
25064
|
-
import { dirname as
|
|
25497
|
+
import { dirname as dirname23, isAbsolute as isAbsolute11, join as join42, resolve as resolve20 } from "node:path";
|
|
25065
25498
|
|
|
25066
25499
|
// src/external-host-turn-loop.ts
|
|
25067
25500
|
init_host_contracts();
|
|
@@ -25281,7 +25714,7 @@ function cwdIsGitWorkTree(cwd) {
|
|
|
25281
25714
|
let dir = cwd;
|
|
25282
25715
|
for (; ; ) {
|
|
25283
25716
|
if (existsSync13(join42(dir, ".git"))) return true;
|
|
25284
|
-
const parent =
|
|
25717
|
+
const parent = dirname23(dir);
|
|
25285
25718
|
if (parent === dir) return false;
|
|
25286
25719
|
dir = parent;
|
|
25287
25720
|
}
|
|
@@ -25309,10 +25742,10 @@ function resolveGitCommonDir(cwd) {
|
|
|
25309
25742
|
if (raw === "") {
|
|
25310
25743
|
throw new Error("git rev-parse --git-common-dir returned empty stdout");
|
|
25311
25744
|
}
|
|
25312
|
-
return isAbsolute11(raw) ? raw :
|
|
25745
|
+
return isAbsolute11(raw) ? raw : resolve20(cwd, raw);
|
|
25313
25746
|
}
|
|
25314
25747
|
function spawnHeadlessTurn(options) {
|
|
25315
|
-
return new Promise((
|
|
25748
|
+
return new Promise((resolve21, reject) => {
|
|
25316
25749
|
if (options.signal?.aborted) {
|
|
25317
25750
|
reject(hostAbortedError("headless host aborted"));
|
|
25318
25751
|
return;
|
|
@@ -25387,7 +25820,7 @@ function spawnHeadlessTurn(options) {
|
|
|
25387
25820
|
reject(stdinDeliveryError);
|
|
25388
25821
|
return;
|
|
25389
25822
|
}
|
|
25390
|
-
|
|
25823
|
+
resolve21({ code, stdout: resultStdout, stderr, timedOut });
|
|
25391
25824
|
};
|
|
25392
25825
|
const onAbort = () => {
|
|
25393
25826
|
child.kill("SIGTERM");
|