@akagilnc/pi-workflow-roles 0.1.5303 → 0.1.5312
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/description.js +0 -11
- package/dist/acp-host/production-host.js +577 -604
- package/dist/analyst-ledger.js +16 -1
- package/dist/analyst-metric-families/acceptance-success-rework.js +16 -15
- package/dist/analyst-metric-families/b2-frame-buckets-actions.js +3 -8
- package/dist/analyst-metric-families/gate-cycles.js +2 -8
- package/dist/analyst-metric-families/leg-wall-clock.js +4 -13
- package/dist/analyst-metric-families/round-timeline.js +1 -4
- package/dist/analyst-model-groups.js +1 -7
- package/dist/analyst-page.js +4 -13
- package/dist/headless-host/description.js +0 -11
- package/dist/headless-host/production-host.js +679 -718
- package/dist/host-descriptions.js +13 -0
- package/dist/prepared-role-turn.js +4 -0
- package/dist/public-cli/machine-method-skills.js +5 -5
- package/dist/public-cli/main.js +291 -313
- package/package.json +1 -1
- package/src/acp-host/description.ts +2 -12
- package/src/acp-host/production-host.ts +3 -2
- package/src/acp-host/role-turn-host.ts +7 -42
- package/src/analyst-ledger.ts +20 -1
- package/src/analyst-metric-families/acceptance-success-rework.ts +5 -15
- package/src/analyst-metric-families/b2-frame-buckets-actions.ts +3 -7
- package/src/analyst-metric-families/gate-cycles.ts +2 -8
- package/src/analyst-metric-families/leg-wall-clock.ts +4 -16
- package/src/analyst-metric-families/round-timeline.ts +1 -5
- package/src/analyst-model-groups.ts +1 -10
- package/src/analyst-page.ts +4 -16
- package/src/external-host-turn-loop.ts +36 -16
- package/src/headless-host/description.ts +3 -18
- package/src/headless-host/production-host.ts +3 -2
- package/src/headless-host/role-turn-host.ts +10 -68
- package/src/host-descriptions.ts +18 -0
- package/src/prepared-role-turn.ts +8 -0
- package/src/public-cli/machine-method-skills.ts +5 -5
|
@@ -13,6 +13,109 @@ var __export = (target, all) => {
|
|
|
13
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
// src/host-descriptions.ts
|
|
17
|
+
import { join } from "node:path";
|
|
18
|
+
function resolveHostBinary(description, operatorHome) {
|
|
19
|
+
return join(operatorHome, ...description.binaryFromHome);
|
|
20
|
+
}
|
|
21
|
+
function lookupHostDescription(host) {
|
|
22
|
+
return Object.hasOwn(HOST_DESCRIPTIONS, host) ? HOST_DESCRIPTIONS[host] : void 0;
|
|
23
|
+
}
|
|
24
|
+
function lookupHeadlessHostDescription(host) {
|
|
25
|
+
return Object.hasOwn(HEADLESS_HOST_DESCRIPTIONS, host) ? HEADLESS_HOST_DESCRIPTIONS[host] : void 0;
|
|
26
|
+
}
|
|
27
|
+
function lookupHostFamily(host) {
|
|
28
|
+
if (lookupHostDescription(host) !== void 0) return "acp";
|
|
29
|
+
if (lookupHeadlessHostDescription(host) !== void 0) return "headless";
|
|
30
|
+
return void 0;
|
|
31
|
+
}
|
|
32
|
+
function packagedExternalHostNames() {
|
|
33
|
+
return [...Object.keys(HOST_DESCRIPTIONS), ...Object.keys(HEADLESS_HOST_DESCRIPTIONS)];
|
|
34
|
+
}
|
|
35
|
+
function assertRegisteredHostName(host) {
|
|
36
|
+
if (host === DEFAULT_ROLE_TURN_HOST || lookupHostFamily(host) !== void 0) {
|
|
37
|
+
return host;
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`unregistered host: ${host}`);
|
|
40
|
+
}
|
|
41
|
+
var DEFAULT_ROLE_TURN_HOST, HOST_DESCRIPTIONS, HEADLESS_HOST_DESCRIPTIONS;
|
|
42
|
+
var init_host_descriptions = __esm({
|
|
43
|
+
"src/host-descriptions.ts"() {
|
|
44
|
+
"use strict";
|
|
45
|
+
DEFAULT_ROLE_TURN_HOST = "pi";
|
|
46
|
+
HOST_DESCRIPTIONS = Object.freeze({
|
|
47
|
+
/** Operator home `~/.grok`, native session/load resume, `agent [--model X] stdio`. */
|
|
48
|
+
"grok-build": Object.freeze({
|
|
49
|
+
binaryFromHome: Object.freeze([".grok", "bin", "grok"]),
|
|
50
|
+
argv: Object.freeze({
|
|
51
|
+
prefix: Object.freeze(["agent"]),
|
|
52
|
+
suffix: Object.freeze(["stdio"]),
|
|
53
|
+
modelFlag: "--model"
|
|
54
|
+
}),
|
|
55
|
+
modelPassing: "argv",
|
|
56
|
+
sessionBindingFile: "grok-acp-session.json"
|
|
57
|
+
}),
|
|
58
|
+
/**
|
|
59
|
+
* Operator home `~/.hermes`, native session/load resume, `acp` subcommand.
|
|
60
|
+
* Model arrives as an ACP `session/set_model` RPC with modelId `provider:model`
|
|
61
|
+
* (seat table provider + model concatenated). Reasoning is the global
|
|
62
|
+
* `--reasoning` flag before `acp`. Soul is the seat profile SOUL.md symlink
|
|
63
|
+
* (`hermes -p ak-<role> …`); package `souls/<role>.md` is the sole source.
|
|
64
|
+
*/
|
|
65
|
+
"hermes": Object.freeze({
|
|
66
|
+
binaryFromHome: Object.freeze([".local", "bin", "hermes"]),
|
|
67
|
+
argv: Object.freeze({
|
|
68
|
+
prefix: Object.freeze(["acp"]),
|
|
69
|
+
suffix: Object.freeze([]),
|
|
70
|
+
thinkingFlag: "--reasoning"
|
|
71
|
+
}),
|
|
72
|
+
modelPassing: "set_model",
|
|
73
|
+
sessionBindingFile: "hermes-acp-session.json",
|
|
74
|
+
seatProfileSoul: Object.freeze({
|
|
75
|
+
flag: "-p",
|
|
76
|
+
namePrefix: "ak-",
|
|
77
|
+
profilesRootFromHome: Object.freeze([".hermes", "profiles"]),
|
|
78
|
+
soulFileName: "SOUL.md"
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
});
|
|
82
|
+
HEADLESS_HOST_DESCRIPTIONS = Object.freeze({
|
|
83
|
+
"claude": Object.freeze({
|
|
84
|
+
protocol: "claude-print",
|
|
85
|
+
binaryFromHome: Object.freeze([".local", "bin", "claude"]),
|
|
86
|
+
sessionBindingFile: "claude-headless-session.json",
|
|
87
|
+
fixedArgs: Object.freeze([
|
|
88
|
+
// Live NDJSON events → sitian host-session records (#811); last line is the result receipt.
|
|
89
|
+
"--output-format",
|
|
90
|
+
"stream-json",
|
|
91
|
+
// Intermediate assistant/tool/system events require verbose with stream-json.
|
|
92
|
+
"--verbose",
|
|
93
|
+
"--permission-mode",
|
|
94
|
+
"bypassPermissions"
|
|
95
|
+
]),
|
|
96
|
+
promptFlag: "-p",
|
|
97
|
+
modelFlag: "--model",
|
|
98
|
+
effortFlag: "--effort",
|
|
99
|
+
// File path keeps large role envelopes off ARG_MAX.
|
|
100
|
+
systemPromptFlag: "--system-prompt-file",
|
|
101
|
+
jsonSchemaFlag: "--json-schema",
|
|
102
|
+
mcpConfigFlag: "--mcp-config",
|
|
103
|
+
sessionIdFlag: "--session-id",
|
|
104
|
+
resumeFlag: "--resume"
|
|
105
|
+
}),
|
|
106
|
+
/**
|
|
107
|
+
* Codex headless (#646). Binary under operator home; auth stays in CODEX_HOME.
|
|
108
|
+
* Argv/parse/schema-close are codex-exec helpers — not Claude flag mapping.
|
|
109
|
+
*/
|
|
110
|
+
"codex": Object.freeze({
|
|
111
|
+
protocol: "codex-exec",
|
|
112
|
+
binaryFromHome: Object.freeze([".local", "bin", "codex"]),
|
|
113
|
+
sessionBindingFile: "codex-headless-session.json"
|
|
114
|
+
})
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
16
119
|
// src/sha256.ts
|
|
17
120
|
import { createHash } from "node:crypto";
|
|
18
121
|
function sha256Hex(bytes) {
|
|
@@ -789,7 +892,7 @@ __export(run_ticket_number_exports, {
|
|
|
789
892
|
requireSafePositiveTicketNumber: () => requireSafePositiveTicketNumber
|
|
790
893
|
});
|
|
791
894
|
import { readFile } from "node:fs/promises";
|
|
792
|
-
import { join } from "node:path";
|
|
895
|
+
import { join as join2 } from "node:path";
|
|
793
896
|
function isEnoent(error) {
|
|
794
897
|
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
795
898
|
}
|
|
@@ -829,7 +932,7 @@ async function readJsonObject(path) {
|
|
|
829
932
|
}
|
|
830
933
|
}
|
|
831
934
|
async function readBoardPageTicketNumber(runDirectory, page) {
|
|
832
|
-
const record4 = await readJsonObject(
|
|
935
|
+
const record4 = await readJsonObject(join2(runDirectory, page));
|
|
833
936
|
if (record4 === void 0) return void 0;
|
|
834
937
|
return ticketFromRecord(record4);
|
|
835
938
|
}
|
|
@@ -838,7 +941,7 @@ async function readBoardTicketNumber(runDirectory) {
|
|
|
838
941
|
}
|
|
839
942
|
async function readMigrationDerivedTicketNumber(runDirectory) {
|
|
840
943
|
const record4 = await readJsonObject(
|
|
841
|
-
|
|
944
|
+
join2(runDirectory, MIGRATION_TICKET_DERIVATION_PAGE)
|
|
842
945
|
);
|
|
843
946
|
if (record4 === void 0) return void 0;
|
|
844
947
|
if (record4.derivation !== "worktree-path-basename") return void 0;
|
|
@@ -2004,7 +2107,7 @@ import {
|
|
|
2004
2107
|
statSync
|
|
2005
2108
|
} from "node:fs";
|
|
2006
2109
|
import { userInfo } from "node:os";
|
|
2007
|
-
import { basename, dirname as dirname2, isAbsolute, join as
|
|
2110
|
+
import { basename, dirname as dirname2, isAbsolute, join as join3, relative as relative2, resolve as resolve2, sep as sep2 } from "node:path";
|
|
2008
2111
|
function packageMachineHome() {
|
|
2009
2112
|
return resolve2(userInfo().homedir);
|
|
2010
2113
|
}
|
|
@@ -2044,7 +2147,7 @@ function resolveActivationLedgerHomeForPath(path) {
|
|
|
2044
2147
|
return resolveActivationLedgerHome();
|
|
2045
2148
|
}
|
|
2046
2149
|
function activationBookDirectory(ledgerHome, bookKey) {
|
|
2047
|
-
return
|
|
2150
|
+
return join3(ledgerHome, "books", bookKey);
|
|
2048
2151
|
}
|
|
2049
2152
|
function pathContainedIn(root, candidate) {
|
|
2050
2153
|
const rel = relative2(root, candidate);
|
|
@@ -2057,7 +2160,7 @@ function physicalPathIdentity(path) {
|
|
|
2057
2160
|
while (true) {
|
|
2058
2161
|
try {
|
|
2059
2162
|
const real = realpathSync(cursor);
|
|
2060
|
-
return missing.length === 0 ? real :
|
|
2163
|
+
return missing.length === 0 ? real : join3(real, ...missing);
|
|
2061
2164
|
} catch (error) {
|
|
2062
2165
|
if (errnoCode(error) !== "ENOENT") {
|
|
2063
2166
|
return absolute;
|
|
@@ -2157,7 +2260,7 @@ function ensureRealDirectoryTree(root, targetDir) {
|
|
|
2157
2260
|
if (part === "..") {
|
|
2158
2261
|
throw new ActivationLedgerError(`activation ledger path contains '..': ${absoluteTarget}`);
|
|
2159
2262
|
}
|
|
2160
|
-
lexicalCursor =
|
|
2263
|
+
lexicalCursor = join3(lexicalCursor, part);
|
|
2161
2264
|
let st;
|
|
2162
2265
|
try {
|
|
2163
2266
|
st = lstatSync(lexicalCursor);
|
|
@@ -2572,7 +2675,7 @@ var init_sitian_contracts = __esm({
|
|
|
2572
2675
|
// src/sitian-appender.ts
|
|
2573
2676
|
import { randomUUID } from "node:crypto";
|
|
2574
2677
|
import { appendFileSync } from "node:fs";
|
|
2575
|
-
import { dirname as dirname4, join as
|
|
2678
|
+
import { dirname as dirname4, join as join4 } from "node:path";
|
|
2576
2679
|
function appendSitianRecordBlock(input, block) {
|
|
2577
2680
|
if (block === "") return;
|
|
2578
2681
|
try {
|
|
@@ -2594,8 +2697,8 @@ function resolveSitianVolumeCategory(kind) {
|
|
|
2594
2697
|
return kind;
|
|
2595
2698
|
}
|
|
2596
2699
|
function ticketProvenanceUnderBookPaths(ledgerHome, bookKey, ticketId) {
|
|
2597
|
-
const sessionDir =
|
|
2598
|
-
return { sessionDir, recordFile:
|
|
2700
|
+
const sessionDir = join4(activationBookDirectory(ledgerHome, bookKey), ticketId);
|
|
2701
|
+
return { sessionDir, recordFile: join4(sessionDir, SITIAN_RECORDS_LEAF) };
|
|
2599
2702
|
}
|
|
2600
2703
|
function resolveSitianRecordPathInLedger(input, ledgerHome) {
|
|
2601
2704
|
const category = resolveSitianVolumeCategory(input.kind);
|
|
@@ -2612,13 +2715,13 @@ function resolveSitianRecordPathInLedger(input, ledgerHome) {
|
|
|
2612
2715
|
recordFile = paths.recordFile;
|
|
2613
2716
|
} else if (category === "ticket-provenance" && input.runDirectory !== void 0) {
|
|
2614
2717
|
sessionDir = input.runDirectory;
|
|
2615
|
-
recordFile =
|
|
2718
|
+
recordFile = join4(sessionDir, SITIAN_RECORDS_LEAF);
|
|
2616
2719
|
} else {
|
|
2617
2720
|
if (input.sessionParent === void 0 || input.sessionParent.length === 0 || !physicallyContainedIn(ledgerHome, input.sessionParent)) {
|
|
2618
2721
|
throw new Error("Sitian record ownership requires a parent session inside the ledger home");
|
|
2619
2722
|
}
|
|
2620
|
-
sessionDir =
|
|
2621
|
-
recordFile =
|
|
2723
|
+
sessionDir = join4(dirname4(input.sessionParent), category);
|
|
2724
|
+
recordFile = join4(sessionDir, SITIAN_RECORDS_LEAF);
|
|
2622
2725
|
}
|
|
2623
2726
|
if (!physicallyContainedIn(ledgerHome, sessionDir)) {
|
|
2624
2727
|
throw new Error("Sitian record ownership requires a directory inside the ledger home");
|
|
@@ -2745,108 +2848,9 @@ var init_sitian_facade = __esm({
|
|
|
2745
2848
|
}
|
|
2746
2849
|
});
|
|
2747
2850
|
|
|
2748
|
-
// src/host-descriptions.ts
|
|
2749
|
-
function lookupHostDescription(host) {
|
|
2750
|
-
return Object.hasOwn(HOST_DESCRIPTIONS, host) ? HOST_DESCRIPTIONS[host] : void 0;
|
|
2751
|
-
}
|
|
2752
|
-
function lookupHeadlessHostDescription(host) {
|
|
2753
|
-
return Object.hasOwn(HEADLESS_HOST_DESCRIPTIONS, host) ? HEADLESS_HOST_DESCRIPTIONS[host] : void 0;
|
|
2754
|
-
}
|
|
2755
|
-
function lookupHostFamily(host) {
|
|
2756
|
-
if (lookupHostDescription(host) !== void 0) return "acp";
|
|
2757
|
-
if (lookupHeadlessHostDescription(host) !== void 0) return "headless";
|
|
2758
|
-
return void 0;
|
|
2759
|
-
}
|
|
2760
|
-
function packagedExternalHostNames() {
|
|
2761
|
-
return [...Object.keys(HOST_DESCRIPTIONS), ...Object.keys(HEADLESS_HOST_DESCRIPTIONS)];
|
|
2762
|
-
}
|
|
2763
|
-
function assertRegisteredHostName(host) {
|
|
2764
|
-
if (host === DEFAULT_ROLE_TURN_HOST || lookupHostFamily(host) !== void 0) {
|
|
2765
|
-
return host;
|
|
2766
|
-
}
|
|
2767
|
-
throw new Error(`unregistered host: ${host}`);
|
|
2768
|
-
}
|
|
2769
|
-
var DEFAULT_ROLE_TURN_HOST, HOST_DESCRIPTIONS, HEADLESS_HOST_DESCRIPTIONS;
|
|
2770
|
-
var init_host_descriptions = __esm({
|
|
2771
|
-
"src/host-descriptions.ts"() {
|
|
2772
|
-
"use strict";
|
|
2773
|
-
DEFAULT_ROLE_TURN_HOST = "pi";
|
|
2774
|
-
HOST_DESCRIPTIONS = Object.freeze({
|
|
2775
|
-
/** Operator home `~/.grok`, native session/load resume, `agent [--model X] stdio`. */
|
|
2776
|
-
"grok-build": Object.freeze({
|
|
2777
|
-
binaryFromHome: Object.freeze([".grok", "bin", "grok"]),
|
|
2778
|
-
argv: Object.freeze({
|
|
2779
|
-
prefix: Object.freeze(["agent"]),
|
|
2780
|
-
suffix: Object.freeze(["stdio"]),
|
|
2781
|
-
modelFlag: "--model"
|
|
2782
|
-
}),
|
|
2783
|
-
modelPassing: "argv",
|
|
2784
|
-
sessionBindingFile: "grok-acp-session.json"
|
|
2785
|
-
}),
|
|
2786
|
-
/**
|
|
2787
|
-
* Operator home `~/.hermes`, native session/load resume, `acp` subcommand.
|
|
2788
|
-
* Model arrives as an ACP `session/set_model` RPC with modelId `provider:model`
|
|
2789
|
-
* (seat table provider + model concatenated). Reasoning is the global
|
|
2790
|
-
* `--reasoning` flag before `acp`. Soul is the seat profile SOUL.md symlink
|
|
2791
|
-
* (`hermes -p ak-<role> …`); package `souls/<role>.md` is the sole source.
|
|
2792
|
-
*/
|
|
2793
|
-
"hermes": Object.freeze({
|
|
2794
|
-
binaryFromHome: Object.freeze([".local", "bin", "hermes"]),
|
|
2795
|
-
argv: Object.freeze({
|
|
2796
|
-
prefix: Object.freeze(["acp"]),
|
|
2797
|
-
suffix: Object.freeze([]),
|
|
2798
|
-
thinkingFlag: "--reasoning"
|
|
2799
|
-
}),
|
|
2800
|
-
modelPassing: "set_model",
|
|
2801
|
-
sessionBindingFile: "hermes-acp-session.json",
|
|
2802
|
-
seatProfileSoul: Object.freeze({
|
|
2803
|
-
flag: "-p",
|
|
2804
|
-
namePrefix: "ak-",
|
|
2805
|
-
profilesRootFromHome: Object.freeze([".hermes", "profiles"]),
|
|
2806
|
-
soulFileName: "SOUL.md"
|
|
2807
|
-
})
|
|
2808
|
-
})
|
|
2809
|
-
});
|
|
2810
|
-
HEADLESS_HOST_DESCRIPTIONS = Object.freeze({
|
|
2811
|
-
"claude": Object.freeze({
|
|
2812
|
-
protocol: "claude-print",
|
|
2813
|
-
binaryFromHome: Object.freeze([".local", "bin", "claude"]),
|
|
2814
|
-
sessionBindingFile: "claude-headless-session.json",
|
|
2815
|
-
fixedArgs: Object.freeze([
|
|
2816
|
-
// Live NDJSON events → sitian host-session records (#811); last line is the result receipt.
|
|
2817
|
-
"--output-format",
|
|
2818
|
-
"stream-json",
|
|
2819
|
-
// Intermediate assistant/tool/system events require verbose with stream-json.
|
|
2820
|
-
"--verbose",
|
|
2821
|
-
"--permission-mode",
|
|
2822
|
-
"bypassPermissions"
|
|
2823
|
-
]),
|
|
2824
|
-
promptFlag: "-p",
|
|
2825
|
-
modelFlag: "--model",
|
|
2826
|
-
effortFlag: "--effort",
|
|
2827
|
-
// File path keeps large role envelopes off ARG_MAX.
|
|
2828
|
-
systemPromptFlag: "--system-prompt-file",
|
|
2829
|
-
jsonSchemaFlag: "--json-schema",
|
|
2830
|
-
mcpConfigFlag: "--mcp-config",
|
|
2831
|
-
sessionIdFlag: "--session-id",
|
|
2832
|
-
resumeFlag: "--resume"
|
|
2833
|
-
}),
|
|
2834
|
-
/**
|
|
2835
|
-
* Codex headless (#646). Binary under operator home; auth stays in CODEX_HOME.
|
|
2836
|
-
* Argv/parse/schema-close are codex-exec helpers — not Claude flag mapping.
|
|
2837
|
-
*/
|
|
2838
|
-
"codex": Object.freeze({
|
|
2839
|
-
protocol: "codex-exec",
|
|
2840
|
-
binaryFromHome: Object.freeze([".local", "bin", "codex"]),
|
|
2841
|
-
sessionBindingFile: "codex-headless-session.json"
|
|
2842
|
-
})
|
|
2843
|
-
});
|
|
2844
|
-
}
|
|
2845
|
-
});
|
|
2846
|
-
|
|
2847
2851
|
// src/package-resources/engine-material.ts
|
|
2848
2852
|
import { existsSync as existsSync2, readdirSync } from "node:fs";
|
|
2849
|
-
import { join as
|
|
2853
|
+
import { join as join5 } from "node:path";
|
|
2850
2854
|
function pickEngineAxis(source) {
|
|
2851
2855
|
return {
|
|
2852
2856
|
...source.engine === void 0 ? {} : { engine: source.engine },
|
|
@@ -2867,11 +2871,11 @@ function isEngineNameSyntax(name) {
|
|
|
2867
2871
|
return true;
|
|
2868
2872
|
}
|
|
2869
2873
|
function resolveEngineMaterialDirectory(packageRoot) {
|
|
2870
|
-
return
|
|
2874
|
+
return join5(packageRoot, ENGINE_MATERIAL_RELATIVE_ROOT);
|
|
2871
2875
|
}
|
|
2872
2876
|
function resolveEngineMaterialPath(packageRoot, name) {
|
|
2873
2877
|
const legal = assertLegalEngineName(name);
|
|
2874
|
-
return
|
|
2878
|
+
return join5(resolveEngineMaterialDirectory(packageRoot), `${legal}.md`);
|
|
2875
2879
|
}
|
|
2876
2880
|
function assertLegalEngineName(name) {
|
|
2877
2881
|
if (!isEngineNameSyntax(name)) {
|
|
@@ -3050,7 +3054,7 @@ __export(config_exports, {
|
|
|
3050
3054
|
validatePublicCliConfigAxes: () => validatePublicCliConfigAxes
|
|
3051
3055
|
});
|
|
3052
3056
|
import { mkdir, readFile as readFile4, writeFile } from "node:fs/promises";
|
|
3053
|
-
import { dirname as dirname5, join as
|
|
3057
|
+
import { dirname as dirname5, join as join6 } from "node:path";
|
|
3054
3058
|
function isGateOfficerSeat(value) {
|
|
3055
3059
|
return packagedProvinceConfig(value);
|
|
3056
3060
|
}
|
|
@@ -3058,7 +3062,7 @@ function publicCliConfigPath(home) {
|
|
|
3058
3062
|
if (typeof home !== "string" || home.trim() === "") {
|
|
3059
3063
|
throw new Error("home must be explicitly provided");
|
|
3060
3064
|
}
|
|
3061
|
-
return
|
|
3065
|
+
return join6(home, ".ak-roles", "public-cli.json");
|
|
3062
3066
|
}
|
|
3063
3067
|
async function loadPublicCliConfig(home) {
|
|
3064
3068
|
const path = publicCliConfigPath(home);
|
|
@@ -3521,7 +3525,7 @@ function credentialProvidersFromAuthData(data) {
|
|
|
3521
3525
|
}
|
|
3522
3526
|
async function loadCredentialProviders(agentDir) {
|
|
3523
3527
|
try {
|
|
3524
|
-
const raw = await readFile4(
|
|
3528
|
+
const raw = await readFile4(join6(agentDir, "auth.json"), "utf8");
|
|
3525
3529
|
return credentialProvidersFromAuthData(JSON.parse(raw));
|
|
3526
3530
|
} catch (error) {
|
|
3527
3531
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
@@ -3599,10 +3603,10 @@ var init_cli_errors = __esm({
|
|
|
3599
3603
|
// src/atomic-write.ts
|
|
3600
3604
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
3601
3605
|
import { rename, rm, writeFile as writeFile2 } from "node:fs/promises";
|
|
3602
|
-
import { dirname as dirname6, join as
|
|
3606
|
+
import { dirname as dirname6, join as join7 } from "node:path";
|
|
3603
3607
|
async function writeFileAtomically(destination, contents) {
|
|
3604
3608
|
const parent = dirname6(destination);
|
|
3605
|
-
const temporary =
|
|
3609
|
+
const temporary = join7(parent, `.atomic-write-${randomUUID2()}.tmp`);
|
|
3606
3610
|
try {
|
|
3607
3611
|
await writeFile2(temporary, contents);
|
|
3608
3612
|
await rename(temporary, destination);
|
|
@@ -3619,7 +3623,7 @@ var init_atomic_write = __esm({
|
|
|
3619
3623
|
|
|
3620
3624
|
// src/role-run-placement.ts
|
|
3621
3625
|
import { readdir as readdir2 } from "node:fs/promises";
|
|
3622
|
-
import { join as
|
|
3626
|
+
import { join as join9 } from "node:path";
|
|
3623
3627
|
function isMissingPathError2(error) {
|
|
3624
3628
|
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
3625
3629
|
}
|
|
@@ -3636,13 +3640,13 @@ async function listBookRunDirectories(bookDir) {
|
|
|
3636
3640
|
}
|
|
3637
3641
|
for (const entry of entries) {
|
|
3638
3642
|
if (!entry.isDirectory()) continue;
|
|
3639
|
-
const runDir =
|
|
3643
|
+
const runDir = join9(runsDir, entry.name);
|
|
3640
3644
|
if (seen.has(runDir)) continue;
|
|
3641
3645
|
seen.add(runDir);
|
|
3642
3646
|
out.push(runDir);
|
|
3643
3647
|
}
|
|
3644
3648
|
};
|
|
3645
|
-
await collect(
|
|
3649
|
+
await collect(join9(bookDir, "runs"));
|
|
3646
3650
|
let subjects;
|
|
3647
3651
|
try {
|
|
3648
3652
|
subjects = await readdir2(bookDir, { withFileTypes: true });
|
|
@@ -3652,7 +3656,7 @@ async function listBookRunDirectories(bookDir) {
|
|
|
3652
3656
|
}
|
|
3653
3657
|
for (const subject of subjects) {
|
|
3654
3658
|
if (!subject.isDirectory() || subject.name === "runs") continue;
|
|
3655
|
-
await collect(
|
|
3659
|
+
await collect(join9(bookDir, subject.name, "runs"));
|
|
3656
3660
|
}
|
|
3657
3661
|
return out.sort();
|
|
3658
3662
|
}
|
|
@@ -3661,23 +3665,23 @@ function roleRunPlacement(ledgerHome, input) {
|
|
|
3661
3665
|
input.subject.ticketNumber,
|
|
3662
3666
|
"roleRunPlacement subject.ticketNumber"
|
|
3663
3667
|
)) : "unbound";
|
|
3664
|
-
const runDirectory =
|
|
3668
|
+
const runDirectory = join9(
|
|
3665
3669
|
activationBookDirectory(ledgerHome, input.bookKey),
|
|
3666
3670
|
subjectDirectory,
|
|
3667
3671
|
"runs",
|
|
3668
3672
|
`${input.runId}@${input.role}`
|
|
3669
3673
|
);
|
|
3670
|
-
const sessionDirectory =
|
|
3674
|
+
const sessionDirectory = join9(runDirectory, "session");
|
|
3671
3675
|
return {
|
|
3672
3676
|
runDirectory,
|
|
3673
3677
|
sessionDirectory,
|
|
3674
|
-
sessionFile:
|
|
3678
|
+
sessionFile: join9(sessionDirectory, "session.jsonl"),
|
|
3675
3679
|
artifactsDirectory: roleRunArtifactsDirectory(runDirectory),
|
|
3676
|
-
attachmentsDirectory:
|
|
3680
|
+
attachmentsDirectory: join9(runDirectory, "attachments")
|
|
3677
3681
|
};
|
|
3678
3682
|
}
|
|
3679
3683
|
function roleRunArtifactsDirectory(runDirectory) {
|
|
3680
|
-
return
|
|
3684
|
+
return join9(runDirectory, "artifacts");
|
|
3681
3685
|
}
|
|
3682
3686
|
function ensureRoleRunDirectory(ledgerHome, directory) {
|
|
3683
3687
|
return ensureRealDirectoryTree(ledgerHome, directory);
|
|
@@ -3704,7 +3708,7 @@ __export(durable_principal_exports, {
|
|
|
3704
3708
|
issuePiDurablePrincipalCoordinates: () => issuePiDurablePrincipalCoordinates,
|
|
3705
3709
|
piDurablePrincipalAuthority: () => piDurablePrincipalAuthority
|
|
3706
3710
|
});
|
|
3707
|
-
import { join as
|
|
3711
|
+
import { join as join10 } from "node:path";
|
|
3708
3712
|
function encode(coordinates) {
|
|
3709
3713
|
return coordinates;
|
|
3710
3714
|
}
|
|
@@ -3754,7 +3758,7 @@ var init_durable_principal = __esm({
|
|
|
3754
3758
|
}
|
|
3755
3759
|
return {
|
|
3756
3760
|
sessionDirectory: record4.sessionDirectory,
|
|
3757
|
-
sessionFile: typeof record4.sessionFile === "string" && record4.sessionFile.trim() !== "" ? record4.sessionFile :
|
|
3761
|
+
sessionFile: typeof record4.sessionFile === "string" && record4.sessionFile.trim() !== "" ? record4.sessionFile : join10(record4.sessionDirectory, "session.jsonl")
|
|
3758
3762
|
};
|
|
3759
3763
|
}
|
|
3760
3764
|
};
|
|
@@ -3763,9 +3767,9 @@ var init_durable_principal = __esm({
|
|
|
3763
3767
|
|
|
3764
3768
|
// src/typed-provider-http.ts
|
|
3765
3769
|
import { readFile as readFile6, unlink, writeFile as writeFile3 } from "node:fs/promises";
|
|
3766
|
-
import { join as
|
|
3770
|
+
import { join as join11 } from "node:path";
|
|
3767
3771
|
function typedProviderHttpPath(runDirectory) {
|
|
3768
|
-
return
|
|
3772
|
+
return join11(runDirectory, TYPED_HTTP_FILE);
|
|
3769
3773
|
}
|
|
3770
3774
|
async function clearTypedProviderHttpObservation(runDirectory) {
|
|
3771
3775
|
try {
|
|
@@ -3909,7 +3913,7 @@ __export(auditor_dossier_tool_exports, {
|
|
|
3909
3913
|
auditorRunDirectory: () => auditorRunDirectory,
|
|
3910
3914
|
createAuditorDossierTool: () => createAuditorDossierTool
|
|
3911
3915
|
});
|
|
3912
|
-
import { dirname as dirname8, join as
|
|
3916
|
+
import { dirname as dirname8, join as join12, resolve as resolve6 } from "node:path";
|
|
3913
3917
|
import { Type as Type11 } from "typebox";
|
|
3914
3918
|
function auditorRunDirectory(context) {
|
|
3915
3919
|
const sessionFile = context.sessionManager?.getSessionFile?.();
|
|
@@ -3932,9 +3936,9 @@ function createAuditorDossierTool(runDirectory) {
|
|
|
3932
3936
|
}
|
|
3933
3937
|
const details = {
|
|
3934
3938
|
runDirectory,
|
|
3935
|
-
admittedRequest:
|
|
3936
|
-
parentSessionCandidate:
|
|
3937
|
-
attachments:
|
|
3939
|
+
admittedRequest: join12(runDirectory, "admitted-request.json"),
|
|
3940
|
+
parentSessionCandidate: join12(runDirectory, "session", "session.jsonl"),
|
|
3941
|
+
attachments: join12(runDirectory, "attachments"),
|
|
3938
3942
|
artifacts: roleRunArtifactsDirectory(runDirectory)
|
|
3939
3943
|
};
|
|
3940
3944
|
return {
|
|
@@ -3964,7 +3968,7 @@ __export(run_terminal_artifacts_exports, {
|
|
|
3964
3968
|
runIdFromRunDirectory: () => runIdFromRunDirectory
|
|
3965
3969
|
});
|
|
3966
3970
|
import { readdir as readdir3, readFile as readFile8 } from "node:fs/promises";
|
|
3967
|
-
import { basename as basename4, dirname as dirname9, join as
|
|
3971
|
+
import { basename as basename4, dirname as dirname9, join as join13 } from "node:path";
|
|
3968
3972
|
function isMissingPathError3(error) {
|
|
3969
3973
|
return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
|
|
3970
3974
|
}
|
|
@@ -4039,7 +4043,7 @@ async function listUniqueErrorFallbackPaths(directories) {
|
|
|
4039
4043
|
}
|
|
4040
4044
|
for (const name of names.sort((a, b) => a.localeCompare(b))) {
|
|
4041
4045
|
if (!UNIQUE_ERROR_FALLBACK_NAME.test(name)) continue;
|
|
4042
|
-
found.push(
|
|
4046
|
+
found.push(join13(dir, name));
|
|
4043
4047
|
}
|
|
4044
4048
|
}
|
|
4045
4049
|
return found;
|
|
@@ -4085,11 +4089,11 @@ async function readRunTerminalArtifact(runDirectory) {
|
|
|
4085
4089
|
unreadable.push(read);
|
|
4086
4090
|
};
|
|
4087
4091
|
for (const file of RUN_TERMINAL_ARTIFACT_FILES) {
|
|
4088
|
-
consider(await readTerminalArtifactAtPath(
|
|
4092
|
+
consider(await readTerminalArtifactAtPath(join13(artifactsDir, file), file));
|
|
4089
4093
|
}
|
|
4090
4094
|
for (const relative3 of RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS) {
|
|
4091
4095
|
consider(
|
|
4092
|
-
await readTerminalArtifactAtPath(
|
|
4096
|
+
await readTerminalArtifactAtPath(join13(runDirectory, relative3), "error.json")
|
|
4093
4097
|
);
|
|
4094
4098
|
}
|
|
4095
4099
|
for (const path of await listSeamOwnedUniqueErrorFacePaths(runDirectory)) {
|
|
@@ -4438,7 +4442,7 @@ __export(session_assistant_usage_exports, {
|
|
|
4438
4442
|
sessionFileFromPublicSummon: () => sessionFileFromPublicSummon,
|
|
4439
4443
|
usageFromPublicSummon: () => usageFromPublicSummon
|
|
4440
4444
|
});
|
|
4441
|
-
import { join as
|
|
4445
|
+
import { join as join14 } from "node:path";
|
|
4442
4446
|
async function readAssistantUsageFromSessionFile(sessionFile) {
|
|
4443
4447
|
const { readFile: readFile25 } = await import("node:fs/promises");
|
|
4444
4448
|
let text;
|
|
@@ -4508,7 +4512,7 @@ async function readAssistantUsageFromSessionFile(sessionFile) {
|
|
|
4508
4512
|
}
|
|
4509
4513
|
function sessionFileFromPublicSummon(summoned) {
|
|
4510
4514
|
if (typeof summoned.runDirectory === "string" && summoned.runDirectory.trim() !== "") {
|
|
4511
|
-
return
|
|
4515
|
+
return join14(summoned.runDirectory, "session", "session.jsonl");
|
|
4512
4516
|
}
|
|
4513
4517
|
const fromArtifacts = summoned.terminal?.artifacts?.map((a) => a.path).find((p) => typeof p === "string" && p.endsWith("session.jsonl"));
|
|
4514
4518
|
if (fromArtifacts !== void 0) return fromArtifacts;
|
|
@@ -4517,7 +4521,7 @@ function sessionFileFromPublicSummon(summoned) {
|
|
|
4517
4521
|
const facts = outcome.decisiveFacts;
|
|
4518
4522
|
const pointer = facts?.runPointer;
|
|
4519
4523
|
if (typeof pointer === "string" && pointer.trim() !== "") {
|
|
4520
|
-
return
|
|
4524
|
+
return join14(pointer, "session", "session.jsonl");
|
|
4521
4525
|
}
|
|
4522
4526
|
return void 0;
|
|
4523
4527
|
}
|
|
@@ -4536,7 +4540,7 @@ var init_session_assistant_usage = __esm({
|
|
|
4536
4540
|
import { spawn } from "node:child_process";
|
|
4537
4541
|
import { mkdtemp, rm as rm2, writeFile as writeFile4 } from "node:fs/promises";
|
|
4538
4542
|
import { tmpdir } from "node:os";
|
|
4539
|
-
import { join as
|
|
4543
|
+
import { join as join15 } from "node:path";
|
|
4540
4544
|
function normalizeEngineName(engine) {
|
|
4541
4545
|
if (engine === void 0) return void 0;
|
|
4542
4546
|
const trimmed = engine.trim();
|
|
@@ -4637,8 +4641,8 @@ async function runEngineDetourOnce(input) {
|
|
|
4637
4641
|
if (input.stagedPrompt === void 0) {
|
|
4638
4642
|
return spawnEngineDetourOnce(input);
|
|
4639
4643
|
}
|
|
4640
|
-
const stagingDir = await mkdtemp(
|
|
4641
|
-
const stagedPath =
|
|
4644
|
+
const stagingDir = await mkdtemp(join15(tmpdir(), "ak-engine-detour-"));
|
|
4645
|
+
const stagedPath = join15(stagingDir, "prompt.txt");
|
|
4642
4646
|
let result;
|
|
4643
4647
|
let runError;
|
|
4644
4648
|
try {
|
|
@@ -4772,12 +4776,12 @@ __export(role_turn_host_exports, {
|
|
|
4772
4776
|
import { execFile, spawn as spawn2 } from "node:child_process";
|
|
4773
4777
|
import { constants } from "node:fs";
|
|
4774
4778
|
import { access, appendFile, readFile as readFile9, realpath as realpath2 } from "node:fs/promises";
|
|
4775
|
-
import { delimiter, dirname as dirname10, isAbsolute as isAbsolute3, join as
|
|
4779
|
+
import { delimiter, dirname as dirname10, isAbsolute as isAbsolute3, join as join16, resolve as resolve7 } from "node:path";
|
|
4776
4780
|
import { platform } from "node:process";
|
|
4777
4781
|
import { promisify } from "node:util";
|
|
4778
4782
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
4779
4783
|
function resolveInternalRoleEntrypoint(packageRoot) {
|
|
4780
|
-
return
|
|
4784
|
+
return join16(packageRoot, INTERNAL_ROLE_ENTRYPOINT_RELATIVE2);
|
|
4781
4785
|
}
|
|
4782
4786
|
function buildExplicitInternalActivationArgs(selectedRoleEntry, extraArgs = []) {
|
|
4783
4787
|
return ["--no-extensions", "-e", selectedRoleEntry, ...extraArgs];
|
|
@@ -5536,13 +5540,13 @@ var init_session_dialogue = __esm({
|
|
|
5536
5540
|
|
|
5537
5541
|
// src/ticket-provenance.ts
|
|
5538
5542
|
import { readFile as readFile12, unlink as unlink2 } from "node:fs/promises";
|
|
5539
|
-
import { basename as basename5, dirname as dirname11, join as
|
|
5543
|
+
import { basename as basename5, dirname as dirname11, join as join17, resolve as resolve9 } from "node:path";
|
|
5540
5544
|
function dialogueSessionSourceRoots(home) {
|
|
5541
5545
|
const machineHome = typeof home === "string" && home.trim() !== "" ? home : packageMachineHome();
|
|
5542
5546
|
return [
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5547
|
+
join17(machineHome, ".claude", "projects"),
|
|
5548
|
+
join17(machineHome, ".codex", "sessions"),
|
|
5549
|
+
join17(machineHome, ".pi", "agent", "sessions")
|
|
5546
5550
|
];
|
|
5547
5551
|
}
|
|
5548
5552
|
function isLedgerRoleSessionFile(absolute, home) {
|
|
@@ -5580,7 +5584,7 @@ function ticketProvenanceRecordInput(ticketNumber, cwd, home, runDirectory) {
|
|
|
5580
5584
|
};
|
|
5581
5585
|
}
|
|
5582
5586
|
async function rehomeUnboundTicketProvenance(runDirectory, ticketNumber, cwd, home) {
|
|
5583
|
-
const source =
|
|
5587
|
+
const source = join17(runDirectory, "records.jsonl");
|
|
5584
5588
|
let content;
|
|
5585
5589
|
try {
|
|
5586
5590
|
content = await readFile12(source, "utf8");
|
|
@@ -5765,7 +5769,7 @@ var init_ticket_provenance = __esm({
|
|
|
5765
5769
|
});
|
|
5766
5770
|
|
|
5767
5771
|
// src/notary-source-run.ts
|
|
5768
|
-
import { dirname as dirname12, isAbsolute as isAbsolute5, join as
|
|
5772
|
+
import { dirname as dirname12, isAbsolute as isAbsolute5, join as join18, resolve as resolve10, basename as basename6 } from "node:path";
|
|
5769
5773
|
import { lstat, realpath as realpath3 } from "node:fs/promises";
|
|
5770
5774
|
async function readRetainedIdentity(runDirectory) {
|
|
5771
5775
|
try {
|
|
@@ -5822,11 +5826,11 @@ async function resolveNotarySourceRunLocator(options) {
|
|
|
5822
5826
|
const ledgerHome = resolveActivationLedgerHome(options.home);
|
|
5823
5827
|
const bookKey = resolveBookKeyFromGit(options.projectRoot);
|
|
5824
5828
|
const bookDirectory = activationBookDirectory(ledgerHome, bookKey);
|
|
5825
|
-
const bookRunsRoot =
|
|
5829
|
+
const bookRunsRoot = join18(bookDirectory, "runs");
|
|
5826
5830
|
let candidate;
|
|
5827
5831
|
const bare = parseRunDirectoryName(raw);
|
|
5828
5832
|
if (bare !== void 0 && !raw.includes("/") && !raw.includes("\\")) {
|
|
5829
|
-
candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ??
|
|
5833
|
+
candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ?? join18(bookRunsRoot, `${bare.runId}@${bare.role}`);
|
|
5830
5834
|
} else {
|
|
5831
5835
|
candidate = isAbsolute5(raw) ? raw : resolve10(options.projectRoot, raw);
|
|
5832
5836
|
const identity2 = parseRunDirectoryName(basename6(candidate));
|
|
@@ -6967,7 +6971,7 @@ import {
|
|
|
6967
6971
|
writeFile as writeFile5
|
|
6968
6972
|
} from "node:fs/promises";
|
|
6969
6973
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
6970
|
-
import { basename as basename7, dirname as dirname13, isAbsolute as isAbsolute6, join as
|
|
6974
|
+
import { basename as basename7, dirname as dirname13, isAbsolute as isAbsolute6, join as join19, resolve as resolve11, sep as sep3 } from "node:path";
|
|
6971
6975
|
function issueAdmissionPlacement(authority, request) {
|
|
6972
6976
|
const ledgerHome = resolveActivationLedgerHome(request.home);
|
|
6973
6977
|
const bookKey = resolveBookKeyFromGit(request.cwd);
|
|
@@ -7021,14 +7025,14 @@ async function writeRoleInvocationLedger(source, role, effectiveModel) {
|
|
|
7021
7025
|
...effectiveModelLedgerFields(effectiveModel)
|
|
7022
7026
|
};
|
|
7023
7027
|
await writeFile5(
|
|
7024
|
-
|
|
7028
|
+
join19(source.runDirectory, "invocation.json"),
|
|
7025
7029
|
`${JSON.stringify(identity, null, 2)}
|
|
7026
7030
|
`,
|
|
7027
7031
|
"utf8"
|
|
7028
7032
|
);
|
|
7029
7033
|
}
|
|
7030
7034
|
async function recordEffectiveInvocationModel(runDirectory, model, engine, host, engineModel) {
|
|
7031
|
-
const ledgerPath =
|
|
7035
|
+
const ledgerPath = join19(runDirectory, "invocation.json");
|
|
7032
7036
|
const current = JSON.parse(await readFile13(ledgerPath, "utf8"));
|
|
7033
7037
|
const next = { ...current };
|
|
7034
7038
|
if (model !== void 0) {
|
|
@@ -7061,7 +7065,7 @@ async function recordEffectiveInvocationModel(runDirectory, model, engine, host,
|
|
|
7061
7065
|
);
|
|
7062
7066
|
}
|
|
7063
7067
|
async function mergeInvocationIdentityPage(runDirectory, fields) {
|
|
7064
|
-
const ledgerPath =
|
|
7068
|
+
const ledgerPath = join19(runDirectory, "invocation.json");
|
|
7065
7069
|
const current = JSON.parse(await readFile13(ledgerPath, "utf8"));
|
|
7066
7070
|
await writeFile5(
|
|
7067
7071
|
ledgerPath,
|
|
@@ -7144,7 +7148,7 @@ async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
|
|
|
7144
7148
|
const childRunIds = parentPage.childDiaristRunIds;
|
|
7145
7149
|
for (const childRunId of Array.isArray(childRunIds) ? childRunIds : []) {
|
|
7146
7150
|
if (typeof childRunId !== "string") continue;
|
|
7147
|
-
const childDirectory =
|
|
7151
|
+
const childDirectory = join19(dirname13(oldRunDirectory), `${childRunId}@diarist`);
|
|
7148
7152
|
if (!existsSync4(childDirectory)) continue;
|
|
7149
7153
|
const childTarget = roleRunPlacement(ledgerHome, {
|
|
7150
7154
|
bookKey: admitted.bookKey,
|
|
@@ -7201,7 +7205,7 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
|
|
|
7201
7205
|
ticketNumber,
|
|
7202
7206
|
"bindTicketNumberOnRunDirectory"
|
|
7203
7207
|
);
|
|
7204
|
-
const admittedPath =
|
|
7208
|
+
const admittedPath = join19(runDirectory, "admitted-request.json");
|
|
7205
7209
|
const admitted = JSON.parse(await readFile13(admittedPath, "utf8"));
|
|
7206
7210
|
if (admitted.ticketNumber === ticketNumber) return;
|
|
7207
7211
|
await writeFile5(
|
|
@@ -7221,7 +7225,7 @@ async function recordLaunchedPiIdentity(runDirectory, identity) {
|
|
|
7221
7225
|
async function observeLaunchedRolePackageIdentity(packageRoot, selectedRoleEntry) {
|
|
7222
7226
|
const rolePackageRoot = packageRoot;
|
|
7223
7227
|
const raw = JSON.parse(
|
|
7224
|
-
await readFile13(
|
|
7228
|
+
await readFile13(join19(rolePackageRoot, "package.json"), "utf8")
|
|
7225
7229
|
);
|
|
7226
7230
|
if (typeof raw.version !== "string" || raw.version.trim() === "") {
|
|
7227
7231
|
throw new Error(
|
|
@@ -7509,13 +7513,13 @@ async function removePreparedAttachmentDirectory(stagingDirectory) {
|
|
|
7509
7513
|
}
|
|
7510
7514
|
async function withPreparedAttachments(attachmentPaths, use) {
|
|
7511
7515
|
if (attachmentPaths.length === 0) return await use([]);
|
|
7512
|
-
const stagingDirectory = await mkdtemp2(
|
|
7516
|
+
const stagingDirectory = await mkdtemp2(join19(tmpdir2(), "ak-role-attachments-"));
|
|
7513
7517
|
const prepared = [];
|
|
7514
7518
|
let result;
|
|
7515
7519
|
try {
|
|
7516
7520
|
for (let index = 0; index < attachmentPaths.length; index += 1) {
|
|
7517
7521
|
const { absolute, bytes } = await readRegularFileAttachment(attachmentPaths[index]);
|
|
7518
|
-
const snapshotPath =
|
|
7522
|
+
const snapshotPath = join19(stagingDirectory, String(index).padStart(6, "0"));
|
|
7519
7523
|
await writeFile5(snapshotPath, bytes);
|
|
7520
7524
|
prepared.push({ absolute, snapshotPath });
|
|
7521
7525
|
}
|
|
@@ -7536,7 +7540,7 @@ async function withPreparedAttachments(attachmentPaths, use) {
|
|
|
7536
7540
|
return result;
|
|
7537
7541
|
}
|
|
7538
7542
|
async function freezeAttachmentBytes(provenancePath, bytes, destinationDir, index) {
|
|
7539
|
-
const frozenPath =
|
|
7543
|
+
const frozenPath = join19(
|
|
7540
7544
|
destinationDir,
|
|
7541
7545
|
`${String(index).padStart(2, "0")}-${basename7(provenancePath)}`
|
|
7542
7546
|
);
|
|
@@ -7579,14 +7583,14 @@ async function freezeAttachments(attachmentPaths, attachmentsDirectory) {
|
|
|
7579
7583
|
async function freezeAttachmentsIntoRun(attachmentPaths, runDirectory, summonsKey = `s-${Date.now().toString(36)}`) {
|
|
7580
7584
|
if (attachmentPaths.length === 0) return [];
|
|
7581
7585
|
const ledgerHome = resolveActivationLedgerHome(homeFromRunDirectory(runDirectory));
|
|
7582
|
-
const attachmentsDirectory =
|
|
7586
|
+
const attachmentsDirectory = join19(runDirectory, "attachments", summonsKey);
|
|
7583
7587
|
ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
|
|
7584
7588
|
return freezeAttachments(attachmentPaths, attachmentsDirectory);
|
|
7585
7589
|
}
|
|
7586
7590
|
async function freezePreparedAttachmentsIntoRun(prepared, runDirectory, summonsKey) {
|
|
7587
7591
|
if (prepared.length === 0) return [];
|
|
7588
7592
|
const ledgerHome = resolveActivationLedgerHome(homeFromRunDirectory(runDirectory));
|
|
7589
|
-
const attachmentsDirectory = summonsKey === void 0 ?
|
|
7593
|
+
const attachmentsDirectory = summonsKey === void 0 ? join19(runDirectory, "attachments") : join19(runDirectory, "attachments", summonsKey);
|
|
7590
7594
|
ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
|
|
7591
7595
|
const attachments = [];
|
|
7592
7596
|
for (let index = 0; index < prepared.length; index += 1) {
|
|
@@ -7663,7 +7667,7 @@ async function admitPublicRole(role, parsed, env, override) {
|
|
|
7663
7667
|
attachmentPaths,
|
|
7664
7668
|
...project,
|
|
7665
7669
|
placedFields: async (placed) => {
|
|
7666
|
-
const taskPath =
|
|
7670
|
+
const taskPath = join19(placed.runDirectory, "task.md");
|
|
7667
7671
|
await writeFile5(taskPath, instruction, "utf8");
|
|
7668
7672
|
return { phase, taskPath };
|
|
7669
7673
|
}
|
|
@@ -7709,7 +7713,7 @@ async function admitPublicRole(role, parsed, env, override) {
|
|
|
7709
7713
|
placedFields: async (placed) => {
|
|
7710
7714
|
let prerequisitesPath;
|
|
7711
7715
|
if (prerequisitesSource !== void 0) {
|
|
7712
|
-
prerequisitesPath =
|
|
7716
|
+
prerequisitesPath = join19(placed.runDirectory, "prerequisites.json");
|
|
7713
7717
|
await writeFile5(
|
|
7714
7718
|
prerequisitesPath,
|
|
7715
7719
|
`${JSON.stringify(prerequisites, null, 2)}
|
|
@@ -7717,7 +7721,7 @@ async function admitPublicRole(role, parsed, env, override) {
|
|
|
7717
7721
|
"utf8"
|
|
7718
7722
|
);
|
|
7719
7723
|
}
|
|
7720
|
-
const packetPath =
|
|
7724
|
+
const packetPath = join19(placed.runDirectory, "fix-packet.md");
|
|
7721
7725
|
await writeFile5(packetPath, instruction, "utf8");
|
|
7722
7726
|
return {
|
|
7723
7727
|
phase,
|
|
@@ -7775,7 +7779,7 @@ async function admitPublicRole(role, parsed, env, override) {
|
|
|
7775
7779
|
placedFields: async (placed) => {
|
|
7776
7780
|
let requestManifestPath;
|
|
7777
7781
|
if (manifestCanonicalJson !== void 0) {
|
|
7778
|
-
requestManifestPath =
|
|
7782
|
+
requestManifestPath = join19(placed.runDirectory, "request-manifest.json");
|
|
7779
7783
|
await writeFile5(requestManifestPath, manifestCanonicalJson, "utf8");
|
|
7780
7784
|
}
|
|
7781
7785
|
return {
|
|
@@ -7965,7 +7969,7 @@ async function admitPublicRole(role, parsed, env, override) {
|
|
|
7965
7969
|
resolutionScope: [...derived.resolutionScope],
|
|
7966
7970
|
authorizedChecks: []
|
|
7967
7971
|
});
|
|
7968
|
-
const mergerInputPath =
|
|
7972
|
+
const mergerInputPath = join19(placed.runDirectory, "merger-input.json");
|
|
7969
7973
|
await writeFile5(
|
|
7970
7974
|
mergerInputPath,
|
|
7971
7975
|
`${JSON.stringify(mergerInput, null, 2)}
|
|
@@ -8039,7 +8043,7 @@ function persistedAttachmentRefs(attachments) {
|
|
|
8039
8043
|
}));
|
|
8040
8044
|
}
|
|
8041
8045
|
async function persistPlacedAdmission(admitted, placed, model) {
|
|
8042
|
-
const admittedRequestPath =
|
|
8046
|
+
const admittedRequestPath = join19(placed.runDirectory, "admitted-request.json");
|
|
8043
8047
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
8044
8048
|
sessionDirectory: placed.sessionDirectory,
|
|
8045
8049
|
sessionFile: placed.sessionFile
|
|
@@ -8092,7 +8096,7 @@ async function admitStandardMaterialInvocation(role, options) {
|
|
|
8092
8096
|
attachments: persistedAttachmentRefs(placed.attachments),
|
|
8093
8097
|
...placed.ticketFields
|
|
8094
8098
|
};
|
|
8095
|
-
const admittedRequestPath = defer ?
|
|
8099
|
+
const admittedRequestPath = defer ? join19(placed.runDirectory, "admitted-request.json") : await persistPlacedAdmission(admitted, placed, options.model);
|
|
8096
8100
|
return {
|
|
8097
8101
|
role,
|
|
8098
8102
|
runId: placed.runId,
|
|
@@ -8170,7 +8174,7 @@ async function materializeCountersignInvocation(admitted, options) {
|
|
|
8170
8174
|
});
|
|
8171
8175
|
const placement = placed;
|
|
8172
8176
|
admitted.runDirectory = placement.runDirectory;
|
|
8173
|
-
admitted.admittedRequestPath =
|
|
8177
|
+
admitted.admittedRequestPath = join19(
|
|
8174
8178
|
placement.runDirectory,
|
|
8175
8179
|
"admitted-request.json"
|
|
8176
8180
|
);
|
|
@@ -8197,7 +8201,7 @@ async function materializeCountersignInvocation(admitted, options) {
|
|
|
8197
8201
|
async function loadAdmittedJudgeRequest(runDirectory) {
|
|
8198
8202
|
try {
|
|
8199
8203
|
const raw = JSON.parse(
|
|
8200
|
-
await readFile13(
|
|
8204
|
+
await readFile13(join19(runDirectory, "admitted-request.json"), "utf8")
|
|
8201
8205
|
);
|
|
8202
8206
|
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return void 0;
|
|
8203
8207
|
const record4 = raw;
|
|
@@ -8286,7 +8290,7 @@ function parseDoctorIssueNumber(raw) {
|
|
|
8286
8290
|
}
|
|
8287
8291
|
async function resolveDoctorCaseRunsPath(options) {
|
|
8288
8292
|
const ledgerHome = resolveActivationLedgerHome(options.home);
|
|
8289
|
-
const defaultRuns =
|
|
8293
|
+
const defaultRuns = join19(
|
|
8290
8294
|
activationBookDirectory(ledgerHome, options.bookKey),
|
|
8291
8295
|
String(options.issueNumber),
|
|
8292
8296
|
"runs"
|
|
@@ -8607,15 +8611,15 @@ var init_invocation = __esm({
|
|
|
8607
8611
|
|
|
8608
8612
|
// src/public-cli/load-production-acp-host.ts
|
|
8609
8613
|
import { existsSync as existsSync5 } from "node:fs";
|
|
8610
|
-
import { join as
|
|
8614
|
+
import { join as join20 } from "node:path";
|
|
8611
8615
|
import { pathToFileURL } from "node:url";
|
|
8612
8616
|
async function loadProductionAcpHostFactory(packageRoot, host) {
|
|
8613
8617
|
const description = lookupHostDescription(host);
|
|
8614
8618
|
if (description === void 0) {
|
|
8615
8619
|
throw new Error(`unregistered host: ${host}`);
|
|
8616
8620
|
}
|
|
8617
|
-
const built =
|
|
8618
|
-
const source =
|
|
8621
|
+
const built = join20(packageRoot, "dist/acp-host/production-host.js");
|
|
8622
|
+
const source = join20(packageRoot, "src/acp-host/production-host.ts");
|
|
8619
8623
|
const target = existsSync5(built) ? built : source;
|
|
8620
8624
|
const href = pathToFileURL(target).href;
|
|
8621
8625
|
const mod = await import(href);
|
|
@@ -8631,15 +8635,15 @@ var init_load_production_acp_host = __esm({
|
|
|
8631
8635
|
|
|
8632
8636
|
// src/public-cli/load-production-headless-host.ts
|
|
8633
8637
|
import { existsSync as existsSync6 } from "node:fs";
|
|
8634
|
-
import { join as
|
|
8638
|
+
import { join as join21 } from "node:path";
|
|
8635
8639
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
8636
8640
|
async function loadProductionHeadlessHostFactory(packageRoot, host) {
|
|
8637
8641
|
const description = lookupHeadlessHostDescription(host);
|
|
8638
8642
|
if (description === void 0) {
|
|
8639
8643
|
throw new Error(`unregistered headless host: ${host}`);
|
|
8640
8644
|
}
|
|
8641
|
-
const built =
|
|
8642
|
-
const source =
|
|
8645
|
+
const built = join21(packageRoot, "dist/headless-host/production-host.js");
|
|
8646
|
+
const source = join21(packageRoot, "src/headless-host/production-host.ts");
|
|
8643
8647
|
const target = existsSync6(built) ? built : source;
|
|
8644
8648
|
const href = pathToFileURL2(target).href;
|
|
8645
8649
|
const mod = await import(href);
|
|
@@ -8693,8 +8697,8 @@ __export(role_turn_host_resolution_exports, {
|
|
|
8693
8697
|
resolveRoleTurnHost: () => resolveRoleTurnHost,
|
|
8694
8698
|
selectRoleTurnHost: () => selectRoleTurnHost
|
|
8695
8699
|
});
|
|
8696
|
-
function formatHostSelectionFailure(
|
|
8697
|
-
return `${
|
|
8700
|
+
function formatHostSelectionFailure(failure) {
|
|
8701
|
+
return `${failure.kind}: ${failure.host}; seat=${failure.seat}; model=${failure.model}; registered: ${failure.registeredHosts.join(", ")}`;
|
|
8698
8702
|
}
|
|
8699
8703
|
function composeRoleTurnHostAdapters(env, principalAuthority) {
|
|
8700
8704
|
const piHost = env.roleTurnHost ?? createPiRoleTurnHost({
|
|
@@ -8754,9 +8758,9 @@ var init_role_turn_host_resolution = __esm({
|
|
|
8754
8758
|
init_invocation();
|
|
8755
8759
|
init_load_production_external_host();
|
|
8756
8760
|
HostSelectionError = class extends Error {
|
|
8757
|
-
constructor(
|
|
8758
|
-
super(formatHostSelectionFailure(
|
|
8759
|
-
this.failure =
|
|
8761
|
+
constructor(failure) {
|
|
8762
|
+
super(formatHostSelectionFailure(failure));
|
|
8763
|
+
this.failure = failure;
|
|
8760
8764
|
this.name = "HostSelectionError";
|
|
8761
8765
|
}
|
|
8762
8766
|
failure;
|
|
@@ -8778,15 +8782,15 @@ __export(host_providers_exports, {
|
|
|
8778
8782
|
renderHostProvidersTable: () => renderHostProvidersTable
|
|
8779
8783
|
});
|
|
8780
8784
|
import { readFileSync } from "node:fs";
|
|
8781
|
-
import { join as
|
|
8785
|
+
import { join as join22 } from "node:path";
|
|
8782
8786
|
function hostProvidersPath(home) {
|
|
8783
8787
|
if (typeof home !== "string" || home.trim() === "") {
|
|
8784
8788
|
throw new Error("home must be explicitly provided");
|
|
8785
8789
|
}
|
|
8786
|
-
return
|
|
8790
|
+
return join22(home, ".ak-roles", "host-providers.json");
|
|
8787
8791
|
}
|
|
8788
8792
|
function hermesProviderModelsCachePath(home) {
|
|
8789
|
-
return
|
|
8793
|
+
return join22(home, ".hermes", "provider_models_cache.json");
|
|
8790
8794
|
}
|
|
8791
8795
|
function parseHostProvidersTable(value) {
|
|
8792
8796
|
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
@@ -8942,7 +8946,7 @@ var init_host_providers = __esm({
|
|
|
8942
8946
|
|
|
8943
8947
|
// src/analyst-gate-cycles-read.ts
|
|
8944
8948
|
import { readdir as readdir4 } from "node:fs/promises";
|
|
8945
|
-
import { join as
|
|
8949
|
+
import { join as join23 } from "node:path";
|
|
8946
8950
|
function isRecord6(value) {
|
|
8947
8951
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8948
8952
|
}
|
|
@@ -9193,7 +9197,7 @@ async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory, opti
|
|
|
9193
9197
|
throw error;
|
|
9194
9198
|
}
|
|
9195
9199
|
for (const name of names) {
|
|
9196
|
-
const path =
|
|
9200
|
+
const path = join23(directory, name);
|
|
9197
9201
|
const fromPointer = name.endsWith(".pointer.json");
|
|
9198
9202
|
const pointer = fromPointer ? await resolveOfficerSessionFromPointerFile(path) : void 0;
|
|
9199
9203
|
const sessionPath = pointer?.sessionFile ?? path;
|
|
@@ -9235,7 +9239,7 @@ var init_analyst_gate_cycles_read = __esm({
|
|
|
9235
9239
|
});
|
|
9236
9240
|
|
|
9237
9241
|
// src/submission-ledger.ts
|
|
9238
|
-
import { join as
|
|
9242
|
+
import { join as join24 } from "node:path";
|
|
9239
9243
|
function runIdentity(context) {
|
|
9240
9244
|
const directory = runDirectoryFromHostContext(context);
|
|
9241
9245
|
if (directory !== void 0) {
|
|
@@ -9257,7 +9261,7 @@ async function submissionRecordFile(cwd, runId, scope) {
|
|
|
9257
9261
|
if (sessionParent === void 0) {
|
|
9258
9262
|
const discoveredRun = await findRunDirectoryById(scope.home, runId);
|
|
9259
9263
|
if (discoveredRun === void 0) return void 0;
|
|
9260
|
-
sessionParent =
|
|
9264
|
+
sessionParent = join24(discoveredRun, "session", "session.jsonl");
|
|
9261
9265
|
}
|
|
9262
9266
|
return resolveSitianRecordPathInLedger({
|
|
9263
9267
|
level: "event",
|
|
@@ -9450,12 +9454,12 @@ async function restoreState(cwd, runId, scope) {
|
|
|
9450
9454
|
}
|
|
9451
9455
|
function sessionParentFromHostContext(context) {
|
|
9452
9456
|
const runDirectory = runDirectoryFromHostContext(context);
|
|
9453
|
-
if (runDirectory !== void 0) return
|
|
9457
|
+
if (runDirectory !== void 0) return join24(runDirectory, "session", "session.jsonl");
|
|
9454
9458
|
const sessionFile = context.sessionManager.getSessionFile?.();
|
|
9455
9459
|
if (typeof sessionFile === "string" && sessionFile.length > 0) return sessionFile;
|
|
9456
9460
|
const sessionDir = context.sessionManager.getSessionDir?.();
|
|
9457
9461
|
if (typeof sessionDir === "string" && sessionDir.length > 0) {
|
|
9458
|
-
return
|
|
9462
|
+
return join24(sessionDir, "session.jsonl");
|
|
9459
9463
|
}
|
|
9460
9464
|
return void 0;
|
|
9461
9465
|
}
|
|
@@ -9643,12 +9647,12 @@ var init_audit_escalation = __esm({
|
|
|
9643
9647
|
// src/session-opening-materials.ts
|
|
9644
9648
|
import { existsSync as existsSync7 } from "node:fs";
|
|
9645
9649
|
import { readFile as readFile14 } from "node:fs/promises";
|
|
9646
|
-
import { dirname as dirname14, join as
|
|
9650
|
+
import { dirname as dirname14, join as join25 } from "node:path";
|
|
9647
9651
|
import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "node:url";
|
|
9648
9652
|
function resolvePackageRootDir(moduleUrl = import.meta.url) {
|
|
9649
9653
|
let dir = dirname14(fileURLToPath(moduleUrl));
|
|
9650
9654
|
for (let i = 0; i < 8; i += 1) {
|
|
9651
|
-
if (existsSync7(
|
|
9655
|
+
if (existsSync7(join25(dir, "package.json")) && existsSync7(join25(dir, "souls"))) {
|
|
9652
9656
|
return dir;
|
|
9653
9657
|
}
|
|
9654
9658
|
const parent = dirname14(dir);
|
|
@@ -9717,7 +9721,7 @@ __export(auditor_soul_exports, {
|
|
|
9717
9721
|
resolveAuditorSubject: () => resolveAuditorSubject
|
|
9718
9722
|
});
|
|
9719
9723
|
import { readFile as readFile15 } from "node:fs/promises";
|
|
9720
|
-
import { basename as basename8, join as
|
|
9724
|
+
import { basename as basename8, join as join26 } from "node:path";
|
|
9721
9725
|
function auditorSoulRelativePath(role) {
|
|
9722
9726
|
return `souls/${role}-auditor.md`;
|
|
9723
9727
|
}
|
|
@@ -9759,7 +9763,7 @@ function subjectFromSourceDirectory(sourceRunDirectory) {
|
|
|
9759
9763
|
async function readAuditorResumeBinding(runDirectory) {
|
|
9760
9764
|
let raw;
|
|
9761
9765
|
try {
|
|
9762
|
-
raw = JSON.parse(await readFile15(
|
|
9766
|
+
raw = JSON.parse(await readFile15(join26(runDirectory, "admitted-request.json"), "utf8"));
|
|
9763
9767
|
} catch (error) {
|
|
9764
9768
|
if (error.code === "ENOENT") return void 0;
|
|
9765
9769
|
throw error;
|
|
@@ -9872,7 +9876,7 @@ var init_serialize_thrown_value = __esm({
|
|
|
9872
9876
|
// src/engine-detour-usage.ts
|
|
9873
9877
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
9874
9878
|
import { readFileSync as readFileSync2 } from "node:fs";
|
|
9875
|
-
import { dirname as dirname15, join as
|
|
9879
|
+
import { dirname as dirname15, join as join27 } from "node:path";
|
|
9876
9880
|
function engineDetourStdoutByteLength(stdout) {
|
|
9877
9881
|
return Buffer.byteLength(stdout, "utf8");
|
|
9878
9882
|
}
|
|
@@ -10009,7 +10013,7 @@ function projectEngineDetourToolUsageForPublicTerminal(usage, options) {
|
|
|
10009
10013
|
function readInvocationRecord(runDirectory) {
|
|
10010
10014
|
try {
|
|
10011
10015
|
const raw = JSON.parse(
|
|
10012
|
-
readFileSync2(
|
|
10016
|
+
readFileSync2(join27(runDirectory, "invocation.json"), "utf8")
|
|
10013
10017
|
);
|
|
10014
10018
|
return isRecord7(raw) ? raw : void 0;
|
|
10015
10019
|
} catch (error) {
|
|
@@ -10037,7 +10041,7 @@ function runDirectoryFromSessionDirectory(sessionDirectory) {
|
|
|
10037
10041
|
return dirname15(sessionDirectory);
|
|
10038
10042
|
}
|
|
10039
10043
|
function sessionFileFromSessionDirectory(sessionDirectory) {
|
|
10040
|
-
return
|
|
10044
|
+
return join27(sessionDirectory, "session.jsonl");
|
|
10041
10045
|
}
|
|
10042
10046
|
function mintEngineDetourInvocationScope(input) {
|
|
10043
10047
|
const engine = input.effectiveEngine?.trim();
|
|
@@ -10282,14 +10286,14 @@ __export(settlement_exports, {
|
|
|
10282
10286
|
});
|
|
10283
10287
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
10284
10288
|
import { appendFile as appendFile2, readFile as readFile16, readdir as readdir5, rm as rm4, writeFile as writeFile6 } from "node:fs/promises";
|
|
10285
|
-
import { dirname as dirname16, join as
|
|
10289
|
+
import { dirname as dirname16, join as join28 } from "node:path";
|
|
10286
10290
|
function sealedLedgerHome(admitted) {
|
|
10287
10291
|
return homeFromRunDirectory(admitted.runDirectory);
|
|
10288
10292
|
}
|
|
10289
10293
|
function ledgerReadScope(admitted, scope) {
|
|
10290
10294
|
return {
|
|
10291
10295
|
home: sealedLedgerHome(admitted),
|
|
10292
|
-
sessionParent:
|
|
10296
|
+
sessionParent: join28(admitted.runDirectory, "session", "session.jsonl"),
|
|
10293
10297
|
...scope?.courtAttemptId === void 0 || scope.courtAttemptId.length === 0 ? {} : { attemptId: scope.courtAttemptId }
|
|
10294
10298
|
};
|
|
10295
10299
|
}
|
|
@@ -10421,8 +10425,8 @@ function formatCliDiagnostic(message) {
|
|
|
10421
10425
|
return `ak-role: ${message}
|
|
10422
10426
|
`;
|
|
10423
10427
|
}
|
|
10424
|
-
function formatFailureStderrDiagnostic(
|
|
10425
|
-
const text =
|
|
10428
|
+
function formatFailureStderrDiagnostic(failure) {
|
|
10429
|
+
const text = failure.diagnostic.trim().length > 0 ? failure.diagnostic : "failure";
|
|
10426
10430
|
return formatCliDiagnostic(text);
|
|
10427
10431
|
}
|
|
10428
10432
|
function formatErrorCauseDetail(cause) {
|
|
@@ -10447,10 +10451,10 @@ function presentStructuralRejection(error, io) {
|
|
|
10447
10451
|
}
|
|
10448
10452
|
io.stderr(formatCliDiagnostic(message));
|
|
10449
10453
|
}
|
|
10450
|
-
function presentControlledFailure(
|
|
10451
|
-
io.stdout(`${JSON.stringify(
|
|
10454
|
+
function presentControlledFailure(failure, io) {
|
|
10455
|
+
io.stdout(`${JSON.stringify(failure, null, 2)}
|
|
10452
10456
|
`);
|
|
10453
|
-
io.stderr(formatFailureStderrDiagnostic(
|
|
10457
|
+
io.stderr(formatFailureStderrDiagnostic(failure));
|
|
10454
10458
|
}
|
|
10455
10459
|
async function inspectJudgeSession(sessionFile) {
|
|
10456
10460
|
try {
|
|
@@ -10553,14 +10557,14 @@ function classifyThrownFailure(error) {
|
|
|
10553
10557
|
}
|
|
10554
10558
|
};
|
|
10555
10559
|
}
|
|
10556
|
-
function withKnownDetails(
|
|
10557
|
-
if (knownDetails === void 0) return
|
|
10560
|
+
function withKnownDetails(failure, knownDetails) {
|
|
10561
|
+
if (knownDetails === void 0) return failure;
|
|
10558
10562
|
const { timedOut: _knownTimedOut, ...rest } = knownDetails;
|
|
10559
10563
|
return {
|
|
10560
|
-
...
|
|
10564
|
+
...failure,
|
|
10561
10565
|
details: {
|
|
10562
10566
|
...rest,
|
|
10563
|
-
...
|
|
10567
|
+
...failure.details ?? {}
|
|
10564
10568
|
}
|
|
10565
10569
|
};
|
|
10566
10570
|
}
|
|
@@ -10653,13 +10657,13 @@ function classifyPostAdmissionFailure(input) {
|
|
|
10653
10657
|
input.knownDetails
|
|
10654
10658
|
);
|
|
10655
10659
|
}
|
|
10656
|
-
function explicitInternalKnownFailureClassificationInput(
|
|
10657
|
-
if (
|
|
10660
|
+
function explicitInternalKnownFailureClassificationInput(failure) {
|
|
10661
|
+
if (failure === void 0) return {};
|
|
10658
10662
|
return {
|
|
10659
|
-
...
|
|
10660
|
-
...
|
|
10661
|
-
...
|
|
10662
|
-
...
|
|
10663
|
+
...failure.cause === void 0 ? {} : { knownCause: failure.cause },
|
|
10664
|
+
...failure.identity === void 0 ? {} : { knownIdentity: failure.identity },
|
|
10665
|
+
...failure.diagnostic === void 0 ? {} : { knownDiagnostic: failure.diagnostic },
|
|
10666
|
+
...failure.details === void 0 ? {} : { knownDetails: failure.details }
|
|
10663
10667
|
};
|
|
10664
10668
|
}
|
|
10665
10669
|
function isMissingPathError4(error) {
|
|
@@ -10790,7 +10794,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
10790
10794
|
}
|
|
10791
10795
|
const parentId = parentEntries.find((entry) => entry.type === "session")?.id;
|
|
10792
10796
|
if (parentId === void 0) return void 0;
|
|
10793
|
-
const childDirectories = [
|
|
10797
|
+
const childDirectories = [join28(dirname16(sessionFile), "auditor-roles")];
|
|
10794
10798
|
const valid = [];
|
|
10795
10799
|
let sawAnyDirectory = false;
|
|
10796
10800
|
for (const childDirectory of childDirectories) {
|
|
@@ -10805,7 +10809,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
10805
10809
|
for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
|
|
10806
10810
|
let entries;
|
|
10807
10811
|
try {
|
|
10808
|
-
entries = await readBoundSessionEntries(
|
|
10812
|
+
entries = await readBoundSessionEntries(join28(childDirectory, file));
|
|
10809
10813
|
} catch (error) {
|
|
10810
10814
|
throw sessionReadFailure(error, "failed to read discovered auditor session");
|
|
10811
10815
|
}
|
|
@@ -10850,19 +10854,19 @@ function complianceFailureFromAuditorVolumes(volumes) {
|
|
|
10850
10854
|
const entry = entries[i];
|
|
10851
10855
|
if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !isRecord10(entry.data)) continue;
|
|
10852
10856
|
const parent = isRecord10(entry.data.parent) ? entry.data.parent : void 0;
|
|
10853
|
-
const
|
|
10857
|
+
const failure = isRecord10(entry.data.failure) ? entry.data.failure : void 0;
|
|
10854
10858
|
if (parent?.sessionId !== parentId || parent.sessionFile !== sessionFile || parent.attemptEntryId !== attemptEntryId) continue;
|
|
10855
|
-
if (
|
|
10856
|
-
const identity = isRecord10(
|
|
10857
|
-
const typedCause =
|
|
10859
|
+
if (failure === void 0) continue;
|
|
10860
|
+
const identity = isRecord10(failure.identity) ? failure.identity : void 0;
|
|
10861
|
+
const typedCause = failure.cause === "provider" || failure.cause === "activation" || failure.cause === "session" || failure.cause === "output" || failure.cause === "timeout" ? failure.cause : void 0;
|
|
10858
10862
|
return {
|
|
10859
10863
|
...typedCause === void 0 ? {} : { cause: typedCause },
|
|
10860
10864
|
...identity === void 0 ? {} : { identity: {
|
|
10861
10865
|
...typeof identity.name === "string" ? { name: identity.name } : {},
|
|
10862
10866
|
...typeof identity.code === "string" || typeof identity.code === "number" ? { code: identity.code } : {}
|
|
10863
10867
|
} },
|
|
10864
|
-
...typeof
|
|
10865
|
-
...isRecord10(
|
|
10868
|
+
...typeof failure.diagnostic === "string" ? { diagnostic: failure.diagnostic } : {},
|
|
10869
|
+
...isRecord10(failure.details) ? { details: failure.details } : {}
|
|
10866
10870
|
};
|
|
10867
10871
|
}
|
|
10868
10872
|
}
|
|
@@ -10934,11 +10938,11 @@ async function resolveAuditedRunnerFailureResolution(input) {
|
|
|
10934
10938
|
const auditorCompliance = await readBoundAuditorComplianceFailure(input.sessionFile);
|
|
10935
10939
|
if (auditorCompliance !== void 0) return resolutionOf(auditorCompliance);
|
|
10936
10940
|
} catch (error) {
|
|
10937
|
-
const
|
|
10941
|
+
const failure = sessionReadFailure(error, "failed to recover bound auditor failure");
|
|
10938
10942
|
return resolutionOf({
|
|
10939
10943
|
cause: "session",
|
|
10940
|
-
identity: thrownIdentity(
|
|
10941
|
-
diagnostic:
|
|
10944
|
+
identity: thrownIdentity(failure),
|
|
10945
|
+
diagnostic: failure.message || failure.name
|
|
10942
10946
|
});
|
|
10943
10947
|
}
|
|
10944
10948
|
try {
|
|
@@ -10948,11 +10952,11 @@ async function resolveAuditedRunnerFailureResolution(input) {
|
|
|
10948
10952
|
if (terminatingFailure !== void 0) return resolutionOf(terminatingFailure);
|
|
10949
10953
|
} catch (error) {
|
|
10950
10954
|
if (!isMissingPathError4(error)) {
|
|
10951
|
-
const
|
|
10955
|
+
const failure = sessionReadFailure(error, "failed to recover typed terminating-tool failure");
|
|
10952
10956
|
return resolutionOf({
|
|
10953
10957
|
cause: "session",
|
|
10954
|
-
identity: thrownIdentity(
|
|
10955
|
-
diagnostic:
|
|
10958
|
+
identity: thrownIdentity(failure),
|
|
10959
|
+
diagnostic: failure.message || failure.name
|
|
10956
10960
|
});
|
|
10957
10961
|
}
|
|
10958
10962
|
}
|
|
@@ -10960,11 +10964,11 @@ async function resolveAuditedRunnerFailureResolution(input) {
|
|
|
10960
10964
|
const auditorStop = await readBoundAuditorProviderStopFallback(input.sessionFile);
|
|
10961
10965
|
if (auditorStop !== void 0) return resolutionOf(auditorStop);
|
|
10962
10966
|
} catch (error) {
|
|
10963
|
-
const
|
|
10967
|
+
const failure = sessionReadFailure(error, "failed to recover bound auditor provider stop");
|
|
10964
10968
|
return resolutionOf({
|
|
10965
10969
|
cause: "session",
|
|
10966
|
-
identity: thrownIdentity(
|
|
10967
|
-
diagnostic:
|
|
10970
|
+
identity: thrownIdentity(failure),
|
|
10971
|
+
diagnostic: failure.message || failure.name
|
|
10968
10972
|
});
|
|
10969
10973
|
}
|
|
10970
10974
|
const parentStop = await readSessionProviderStop(input.sessionFile);
|
|
@@ -10973,12 +10977,12 @@ async function resolveAuditedRunnerFailureResolution(input) {
|
|
|
10973
10977
|
try {
|
|
10974
10978
|
httpObservation = await readLatestTypedProviderHttpObservation(input.runDirectory);
|
|
10975
10979
|
} catch (error) {
|
|
10976
|
-
const
|
|
10980
|
+
const failure = error instanceof Error ? error : new Error(String(error));
|
|
10977
10981
|
return resolutionOf(
|
|
10978
10982
|
{
|
|
10979
10983
|
cause: "session",
|
|
10980
|
-
identity: thrownIdentity(
|
|
10981
|
-
diagnostic:
|
|
10984
|
+
identity: thrownIdentity(failure),
|
|
10985
|
+
diagnostic: failure.message || failure.name
|
|
10982
10986
|
},
|
|
10983
10987
|
{ settled: true }
|
|
10984
10988
|
);
|
|
@@ -11029,12 +11033,12 @@ async function resolveControlledFailureResumeObservation(input) {
|
|
|
11029
11033
|
const typedHttp429 = await readTypedHttp429Observation(input.runDirectory);
|
|
11030
11034
|
return typedHttp429 === void 0 ? {} : { typedHttp429 };
|
|
11031
11035
|
} catch (error) {
|
|
11032
|
-
const
|
|
11036
|
+
const failure = error instanceof Error ? error : new Error(String(error));
|
|
11033
11037
|
return {
|
|
11034
11038
|
observationReadFailure: {
|
|
11035
11039
|
cause: "session",
|
|
11036
|
-
identity: thrownIdentity(
|
|
11037
|
-
diagnostic:
|
|
11040
|
+
identity: thrownIdentity(failure),
|
|
11041
|
+
diagnostic: failure.message || failure.name
|
|
11038
11042
|
}
|
|
11039
11043
|
};
|
|
11040
11044
|
}
|
|
@@ -11114,11 +11118,11 @@ async function readEngineDetourInfrastructureFailure(sessionFile) {
|
|
|
11114
11118
|
ENGINE_DETOUR_INFRASTRUCTURE_FAILURE_SPEC
|
|
11115
11119
|
);
|
|
11116
11120
|
}
|
|
11117
|
-
function knownFailureFromControlled(
|
|
11121
|
+
function knownFailureFromControlled(failure) {
|
|
11118
11122
|
return {
|
|
11119
|
-
...
|
|
11120
|
-
diagnostic:
|
|
11121
|
-
...
|
|
11123
|
+
...failure.cause === void 0 ? {} : { cause: failure.cause },
|
|
11124
|
+
diagnostic: failure.diagnostic,
|
|
11125
|
+
...failure.identity === void 0 ? {} : { identity: failure.identity }
|
|
11122
11126
|
};
|
|
11123
11127
|
}
|
|
11124
11128
|
function seatKnownFailureResolver(role) {
|
|
@@ -11281,8 +11285,8 @@ function projectTerminalGateFact(rounds) {
|
|
|
11281
11285
|
};
|
|
11282
11286
|
}
|
|
11283
11287
|
async function extractGateFactFromSessionDirectory(sessionDirectory, options = {}) {
|
|
11284
|
-
const directories = [
|
|
11285
|
-
const parentSessionFile = options.parentSessionFile ??
|
|
11288
|
+
const directories = [join28(sessionDirectory, "auditor-roles")];
|
|
11289
|
+
const parentSessionFile = options.parentSessionFile ?? join28(sessionDirectory, "session.jsonl");
|
|
11286
11290
|
const rounds = await readAnalystGateCyclesFromAuditorRoles(directories, {
|
|
11287
11291
|
parentSessionFile
|
|
11288
11292
|
});
|
|
@@ -11394,10 +11398,10 @@ async function removeFaceIfPresent(path) {
|
|
|
11394
11398
|
async function clearOppositeTerminalArtifactFace(runDirectory) {
|
|
11395
11399
|
const artifactsDir = roleRunArtifactsDirectory(runDirectory);
|
|
11396
11400
|
for (const file of RUN_TERMINAL_ARTIFACT_FILES) {
|
|
11397
|
-
await removeFaceIfPresent(
|
|
11401
|
+
await removeFaceIfPresent(join28(artifactsDir, file));
|
|
11398
11402
|
}
|
|
11399
11403
|
for (const relative3 of RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS) {
|
|
11400
|
-
await removeFaceIfPresent(
|
|
11404
|
+
await removeFaceIfPresent(join28(runDirectory, relative3));
|
|
11401
11405
|
}
|
|
11402
11406
|
for (const path of await listSeamOwnedUniqueErrorFacePaths(runDirectory)) {
|
|
11403
11407
|
await removeFaceIfPresent(path);
|
|
@@ -11426,8 +11430,8 @@ async function publishAcceptedTerminalArtifacts(admitted, roleOutcome, coordinat
|
|
|
11426
11430
|
roleOutcome
|
|
11427
11431
|
);
|
|
11428
11432
|
const artifactsDir = await ensureTerminalArtifactFace(admitted.runDirectory);
|
|
11429
|
-
const reportPath =
|
|
11430
|
-
const evidencePath =
|
|
11433
|
+
const reportPath = join28(artifactsDir, "report.json");
|
|
11434
|
+
const evidencePath = join28(artifactsDir, "evidence.json");
|
|
11431
11435
|
await writeFile6(
|
|
11432
11436
|
reportPath,
|
|
11433
11437
|
`${JSON.stringify(bodies.report, null, 2)}
|
|
@@ -11836,7 +11840,7 @@ async function writeFailureJsonRetainingCause(preferredCandidates, uniqueFallbac
|
|
|
11836
11840
|
const candidates = [
|
|
11837
11841
|
...preferredCandidates,
|
|
11838
11842
|
// One unique name per fallback dir — collisions on fixed names cannot exhaust this.
|
|
11839
|
-
...uniqueFallbackDirs.map((dir) =>
|
|
11843
|
+
...uniqueFallbackDirs.map((dir) => join28(dir, `${stem}.${randomUUID5()}.json`))
|
|
11840
11844
|
];
|
|
11841
11845
|
for (let i = 0; i < candidates.length; i += 1) {
|
|
11842
11846
|
const path = candidates[i];
|
|
@@ -11866,7 +11870,7 @@ async function writeFailureJsonRetainingCause(preferredCandidates, uniqueFallbac
|
|
|
11866
11870
|
error.publicationAttempts = issues;
|
|
11867
11871
|
throw error;
|
|
11868
11872
|
}
|
|
11869
|
-
async function publishFailureArtifacts(admitted,
|
|
11873
|
+
async function publishFailureArtifacts(admitted, failure, authority, onErrorPublished) {
|
|
11870
11874
|
const { sessionDirectory, sessionFile } = coordinatesFromAdmitted(authority, admitted);
|
|
11871
11875
|
const { baseDir, attempt: baseAttempt } = await resolveFailureArtifactsBase(
|
|
11872
11876
|
admitted.runDirectory
|
|
@@ -11886,7 +11890,7 @@ async function publishFailureArtifacts(admitted, failure2, authority, onErrorPub
|
|
|
11886
11890
|
await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile }, {
|
|
11887
11891
|
kind: "failure",
|
|
11888
11892
|
role: admitted.role,
|
|
11889
|
-
...
|
|
11893
|
+
...failure
|
|
11890
11894
|
});
|
|
11891
11895
|
} catch (error) {
|
|
11892
11896
|
priorIssues.push(publicationAttemptFromError(sessionFile, error));
|
|
@@ -11897,29 +11901,29 @@ async function publishFailureArtifacts(admitted, failure2, authority, onErrorPub
|
|
|
11897
11901
|
baseDir
|
|
11898
11902
|
);
|
|
11899
11903
|
const errorCandidates = underArtifacts ? [
|
|
11900
|
-
|
|
11901
|
-
|
|
11902
|
-
|
|
11904
|
+
join28(baseDir, "error.json"),
|
|
11905
|
+
join28(baseDir, "error.settlement.json"),
|
|
11906
|
+
join28(admitted.runDirectory, "error.settlement.json")
|
|
11903
11907
|
] : [
|
|
11904
|
-
|
|
11905
|
-
|
|
11908
|
+
join28(baseDir, "error.settlement.json"),
|
|
11909
|
+
join28(baseDir, "error.json")
|
|
11906
11910
|
];
|
|
11907
11911
|
const evidenceCandidates = underArtifacts ? [
|
|
11908
|
-
|
|
11909
|
-
|
|
11910
|
-
|
|
11912
|
+
join28(baseDir, "evidence.json"),
|
|
11913
|
+
join28(baseDir, "evidence.settlement.json"),
|
|
11914
|
+
join28(admitted.runDirectory, "evidence.settlement.json")
|
|
11911
11915
|
] : [
|
|
11912
|
-
|
|
11913
|
-
|
|
11916
|
+
join28(baseDir, "evidence.settlement.json"),
|
|
11917
|
+
join28(baseDir, "evidence.json")
|
|
11914
11918
|
];
|
|
11915
11919
|
const errorPayloadBase = {
|
|
11916
11920
|
kind: "error",
|
|
11917
11921
|
role: admitted.role,
|
|
11918
11922
|
runId: admitted.runId,
|
|
11919
|
-
...
|
|
11920
|
-
diagnostic:
|
|
11921
|
-
...
|
|
11922
|
-
...
|
|
11923
|
+
...failure.cause === void 0 ? {} : { cause: failure.cause },
|
|
11924
|
+
diagnostic: failure.diagnostic,
|
|
11925
|
+
...failure.identity === void 0 ? {} : { identity: failure.identity },
|
|
11926
|
+
...failure.details === void 0 ? {} : { details: failure.details }
|
|
11923
11927
|
};
|
|
11924
11928
|
const errorWrite = await writeFailureJsonRetainingCause(
|
|
11925
11929
|
errorCandidates,
|
|
@@ -11940,7 +11944,7 @@ async function publishFailureArtifacts(admitted, failure2, authority, onErrorPub
|
|
|
11940
11944
|
sha256: a.sha256,
|
|
11941
11945
|
byteLength: a.byteLength
|
|
11942
11946
|
})),
|
|
11943
|
-
...
|
|
11947
|
+
...failure.cause === void 0 ? {} : { failureCause: failure.cause }
|
|
11944
11948
|
};
|
|
11945
11949
|
const evidenceWrite = await writeFailureJsonRetainingCause(
|
|
11946
11950
|
evidenceCandidates,
|
|
@@ -11955,10 +11959,10 @@ async function publishFailureArtifacts(admitted, failure2, authority, onErrorPub
|
|
|
11955
11959
|
{ kind: "evidence", path: evidenceWrite.path }
|
|
11956
11960
|
];
|
|
11957
11961
|
}
|
|
11958
|
-
async function settleFailureTerminalResult(admitted,
|
|
11962
|
+
async function settleFailureTerminalResult(admitted, failure, authority, options = {}) {
|
|
11959
11963
|
const coordinates = coordinatesFromAdmitted(authority, admitted);
|
|
11960
11964
|
const { sessionDirectory, sessionFile } = coordinates;
|
|
11961
|
-
if (
|
|
11965
|
+
if (failure.cause === "output") {
|
|
11962
11966
|
const entries = await readBoundSessionEntries(sessionFile).catch(() => void 0);
|
|
11963
11967
|
if (entries !== void 0) {
|
|
11964
11968
|
let attemptStart = 0;
|
|
@@ -12000,27 +12004,27 @@ async function settleFailureTerminalResult(admitted, failure2, authority, option
|
|
|
12000
12004
|
}
|
|
12001
12005
|
}
|
|
12002
12006
|
const navigator = await extractNavigatorFactFromAdmittedSession(sessionFile);
|
|
12003
|
-
const artifacts = await publishFailureArtifacts(admitted,
|
|
12007
|
+
const artifacts = await publishFailureArtifacts(admitted, failure, authority, options.onErrorPublished);
|
|
12004
12008
|
const errorPath = artifacts.find((artifact) => artifact.kind === "error")?.path;
|
|
12005
12009
|
const decisiveFacts = {
|
|
12006
|
-
...
|
|
12007
|
-
diagnostic:
|
|
12010
|
+
...failure.cause === void 0 ? {} : { cause: failure.cause },
|
|
12011
|
+
diagnostic: failure.diagnostic
|
|
12008
12012
|
};
|
|
12009
|
-
if (
|
|
12010
|
-
decisiveFacts.errorName =
|
|
12013
|
+
if (failure.identity?.name !== void 0) {
|
|
12014
|
+
decisiveFacts.errorName = failure.identity.name;
|
|
12011
12015
|
}
|
|
12012
|
-
if (
|
|
12013
|
-
decisiveFacts.errorCode =
|
|
12016
|
+
if (failure.identity?.code !== void 0) {
|
|
12017
|
+
decisiveFacts.errorCode = failure.identity.code;
|
|
12014
12018
|
}
|
|
12015
|
-
if (
|
|
12016
|
-
decisiveFacts.secondaryEvidence =
|
|
12019
|
+
if (failure.details !== void 0) {
|
|
12020
|
+
decisiveFacts.secondaryEvidence = failure.details;
|
|
12017
12021
|
}
|
|
12018
12022
|
if (options.resume !== void 0) {
|
|
12019
12023
|
const roleOutcome2 = {
|
|
12020
12024
|
kind: "failure",
|
|
12021
12025
|
role: admitted.role,
|
|
12022
|
-
...
|
|
12023
|
-
diagnostic:
|
|
12026
|
+
...failure.cause === void 0 ? {} : { cause: failure.cause },
|
|
12027
|
+
diagnostic: failure.diagnostic,
|
|
12024
12028
|
decisiveFacts
|
|
12025
12029
|
};
|
|
12026
12030
|
const terminal = await withOptionalGateProjection(
|
|
@@ -12039,8 +12043,8 @@ async function settleFailureTerminalResult(admitted, failure2, authority, option
|
|
|
12039
12043
|
const roleOutcome = {
|
|
12040
12044
|
kind: "failure",
|
|
12041
12045
|
role: admitted.role,
|
|
12042
|
-
...
|
|
12043
|
-
diagnostic:
|
|
12046
|
+
...failure.cause === void 0 ? {} : { cause: failure.cause },
|
|
12047
|
+
diagnostic: failure.diagnostic,
|
|
12044
12048
|
decisiveFacts
|
|
12045
12049
|
};
|
|
12046
12050
|
return withOptionalGateProjection(
|
|
@@ -12054,8 +12058,8 @@ async function settleFailureTerminalResult(admitted, failure2, authority, option
|
|
|
12054
12058
|
detourGateContext(admitted, options)
|
|
12055
12059
|
);
|
|
12056
12060
|
}
|
|
12057
|
-
async function settleJudgeFailureTerminalResult(admitted,
|
|
12058
|
-
return settleFailureTerminalResult(admitted,
|
|
12061
|
+
async function settleJudgeFailureTerminalResult(admitted, failure, authority, options = {}) {
|
|
12062
|
+
return settleFailureTerminalResult(admitted, failure, authority, options);
|
|
12059
12063
|
}
|
|
12060
12064
|
function presentFailureTerminal(terminal, io) {
|
|
12061
12065
|
if (terminal.roleOutcome.kind !== "failure" && terminal.roleOutcome.kind !== "no_receipt") {
|
|
@@ -12165,9 +12169,9 @@ var init_settlement = __esm({
|
|
|
12165
12169
|
|
|
12166
12170
|
// src/archivist-record-pointer.ts
|
|
12167
12171
|
import { mkdirSync as mkdirSync2, writeFileSync } from "node:fs";
|
|
12168
|
-
import { dirname as dirname17, join as
|
|
12172
|
+
import { dirname as dirname17, join as join29 } from "node:path";
|
|
12169
12173
|
function bookDirectOfficerRunPointer(options) {
|
|
12170
|
-
const nest =
|
|
12174
|
+
const nest = join29(dirname17(options.parentSessionFile), "auditor-roles");
|
|
12171
12175
|
mkdirSync2(nest, { recursive: true });
|
|
12172
12176
|
const pointer = {
|
|
12173
12177
|
version: 1,
|
|
@@ -12177,7 +12181,7 @@ function bookDirectOfficerRunPointer(options) {
|
|
|
12177
12181
|
...options.runDirectory !== void 0 && options.runDirectory.trim() !== "" ? { runDirectory: options.runDirectory } : {}
|
|
12178
12182
|
};
|
|
12179
12183
|
writeFileSync(
|
|
12180
|
-
|
|
12184
|
+
join29(nest, `${options.officer}.pointer.json`),
|
|
12181
12185
|
`${JSON.stringify(pointer)}
|
|
12182
12186
|
`,
|
|
12183
12187
|
"utf8"
|
|
@@ -12406,11 +12410,11 @@ async function requireSubmissionGate(options) {
|
|
|
12406
12410
|
continue;
|
|
12407
12411
|
}
|
|
12408
12412
|
if (gatekeeper.status === "transport_failure") {
|
|
12409
|
-
const
|
|
12413
|
+
const failure = Object.assign(new Error(gatekeeper.reason), {
|
|
12410
12414
|
name: "GatekeeperTransportFailure",
|
|
12411
12415
|
...gatekeeper.submission === void 0 ? {} : { submission: gatekeeper.submission }
|
|
12412
12416
|
});
|
|
12413
|
-
options.hostActions.failInfrastructure(
|
|
12417
|
+
options.hostActions.failInfrastructure(failure, options.context, options.toolCallId);
|
|
12414
12418
|
}
|
|
12415
12419
|
if (gatekeeper.status === "escalate") {
|
|
12416
12420
|
return {
|
|
@@ -12436,9 +12440,9 @@ var init_submission_gate = __esm({
|
|
|
12436
12440
|
|
|
12437
12441
|
// src/session-identity.ts
|
|
12438
12442
|
import { mkdir as mkdir2, readFile as readFile17, rename as rename3, writeFile as writeFile7 } from "node:fs/promises";
|
|
12439
|
-
import { dirname as dirname18, join as
|
|
12443
|
+
import { dirname as dirname18, join as join30 } from "node:path";
|
|
12440
12444
|
function createSessionIdentityAuthority(authority, sessionBindingFile) {
|
|
12441
|
-
const bindingPath = (principal) =>
|
|
12445
|
+
const bindingPath = (principal) => join30(authority.decode(principal).sessionDirectory, sessionBindingFile);
|
|
12442
12446
|
return {
|
|
12443
12447
|
resolveSessionFile(principal) {
|
|
12444
12448
|
return authority.decode(principal).sessionFile;
|
|
@@ -12516,7 +12520,7 @@ import {
|
|
|
12516
12520
|
statSync as statSync3
|
|
12517
12521
|
} from "node:fs";
|
|
12518
12522
|
import { homedir } from "node:os";
|
|
12519
|
-
import { dirname as dirname19, join as
|
|
12523
|
+
import { dirname as dirname19, join as join31 } from "node:path";
|
|
12520
12524
|
function declareHostSessionFailure(error) {
|
|
12521
12525
|
const message = error instanceof Error ? error.stack || error.message : String(error);
|
|
12522
12526
|
process.stderr.write(`[host-session] Dossier record failure: ${message}
|
|
@@ -12541,7 +12545,7 @@ function findCodexRollout(sessionsDir, sessionId) {
|
|
|
12541
12545
|
return;
|
|
12542
12546
|
}
|
|
12543
12547
|
for (const entry of entries) {
|
|
12544
|
-
const fullPath =
|
|
12548
|
+
const fullPath = join31(dir, entry.name);
|
|
12545
12549
|
if (entry.isDirectory()) {
|
|
12546
12550
|
scan(fullPath, depth + 1);
|
|
12547
12551
|
} else if (entry.isFile() && entry.name.endsWith(".jsonl") && entry.name.includes(sessionId)) {
|
|
@@ -12565,25 +12569,25 @@ function sanitizeClaudeCwd(cwd) {
|
|
|
12565
12569
|
function resolveNativeSessionPath(options) {
|
|
12566
12570
|
const home = options.home || homedir();
|
|
12567
12571
|
if (options.host === "claude") {
|
|
12568
|
-
const configDir = process.env.CLAUDE_CONFIG_DIR ||
|
|
12572
|
+
const configDir = process.env.CLAUDE_CONFIG_DIR || join31(home, ".claude");
|
|
12569
12573
|
const sanitizedCwd = sanitizeClaudeCwd(options.cwd);
|
|
12570
|
-
return
|
|
12574
|
+
return join31(configDir, "projects", sanitizedCwd, `${options.sessionId}.jsonl`);
|
|
12571
12575
|
}
|
|
12572
12576
|
if (options.host === "codex") {
|
|
12573
12577
|
return findCodexRollout(codexSessionsDirectory(home), options.sessionId);
|
|
12574
12578
|
}
|
|
12575
12579
|
if (options.host === "grok-build") {
|
|
12576
|
-
const grokHome = process.env.GROK_HOME ||
|
|
12577
|
-
return
|
|
12580
|
+
const grokHome = process.env.GROK_HOME || join31(home, ".grok");
|
|
12581
|
+
return join31(grokHome, "sessions", encodeURIComponent(options.cwd), options.sessionId);
|
|
12578
12582
|
}
|
|
12579
12583
|
return void 0;
|
|
12580
12584
|
}
|
|
12581
12585
|
function codexSessionsDirectory(home) {
|
|
12582
|
-
return
|
|
12586
|
+
return join31(process.env.CODEX_HOME || join31(home || homedir(), ".codex"), "sessions");
|
|
12583
12587
|
}
|
|
12584
12588
|
function recordRunStart(runDirectory) {
|
|
12585
12589
|
try {
|
|
12586
|
-
appendFileSync2(
|
|
12590
|
+
appendFileSync2(join31(runDirectory, ".run-starts"), "\n");
|
|
12587
12591
|
} catch (error) {
|
|
12588
12592
|
declareHostSessionFailure(error);
|
|
12589
12593
|
}
|
|
@@ -12607,12 +12611,12 @@ function resolveHostDossierLandingPath(options) {
|
|
|
12607
12611
|
} catch {
|
|
12608
12612
|
}
|
|
12609
12613
|
}
|
|
12610
|
-
const startsPath =
|
|
12614
|
+
const startsPath = join31(dirname19(options.sessionDirectory), ".run-starts");
|
|
12611
12615
|
let starts = 0;
|
|
12612
12616
|
if (existsSync9(startsPath)) starts = readFileSync3(startsPath, "utf8").length;
|
|
12613
12617
|
const ordinal = Math.max(maxOrdinal + 1, starts, options.continuation.kind === "resume" ? 2 : 1);
|
|
12614
12618
|
const baseName = `${options.host}-${sanitizedModel}-${ordinal}`;
|
|
12615
|
-
const landingPath = options.host === "grok-build" ?
|
|
12619
|
+
const landingPath = options.host === "grok-build" ? join31(options.sessionDirectory, baseName) : join31(options.sessionDirectory, `${baseName}.jsonl`);
|
|
12616
12620
|
return { landingPath, ordinal, sanitizedModel };
|
|
12617
12621
|
}
|
|
12618
12622
|
function recordNativeSessionPointer(options) {
|
|
@@ -12645,18 +12649,18 @@ function copyFileCloneOrFallback(src, dest) {
|
|
|
12645
12649
|
copyFileSync(src, dest);
|
|
12646
12650
|
}
|
|
12647
12651
|
function copyGrokDossier(srcDir, destDir) {
|
|
12648
|
-
const chatHistorySrc =
|
|
12652
|
+
const chatHistorySrc = join31(srcDir, "chat_history.jsonl");
|
|
12649
12653
|
if (!existsSync9(chatHistorySrc)) {
|
|
12650
12654
|
throw new Error(`Grok native chat_history.jsonl missing at ${chatHistorySrc}`);
|
|
12651
12655
|
}
|
|
12652
12656
|
mkdirSync3(destDir, { recursive: true });
|
|
12653
|
-
const chatHistoryDest =
|
|
12657
|
+
const chatHistoryDest = join31(destDir, "chat_history.jsonl");
|
|
12654
12658
|
copyFileCloneOrFallback(chatHistorySrc, chatHistoryDest);
|
|
12655
|
-
const usageSrc =
|
|
12659
|
+
const usageSrc = join31(srcDir, "usage.json");
|
|
12656
12660
|
if (!existsSync9(usageSrc)) {
|
|
12657
12661
|
throw new Error(`Grok native usage.json missing at ${usageSrc}`);
|
|
12658
12662
|
}
|
|
12659
|
-
copyFileCloneOrFallback(usageSrc,
|
|
12663
|
+
copyFileCloneOrFallback(usageSrc, join31(destDir, "usage.json"));
|
|
12660
12664
|
}
|
|
12661
12665
|
function copyAndRecordHostDossier(options) {
|
|
12662
12666
|
if (options.host === "pi" || options.host === "hermes") {
|
|
@@ -12731,7 +12735,7 @@ function copyAndRecordHostDossier(options) {
|
|
|
12731
12735
|
}
|
|
12732
12736
|
try {
|
|
12733
12737
|
mkdirSync3(options.sessionDirectory, { recursive: true });
|
|
12734
|
-
closeSync(openSync(
|
|
12738
|
+
closeSync(openSync(join31(options.sessionDirectory, `${options.host}-${sanitizedModel}-${ordinal}.failed`), "a"));
|
|
12735
12739
|
} catch {
|
|
12736
12740
|
}
|
|
12737
12741
|
sitianReportSafe({
|
|
@@ -12765,7 +12769,7 @@ var init_host_session_record = __esm({
|
|
|
12765
12769
|
import { constants as fsConstants2 } from "node:fs";
|
|
12766
12770
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
12767
12771
|
import { lstat as lstat4, mkdir as mkdir3, open } from "node:fs/promises";
|
|
12768
|
-
import { join as
|
|
12772
|
+
import { join as join32 } from "node:path";
|
|
12769
12773
|
async function persistReturnedRunState(admitted, options) {
|
|
12770
12774
|
if (options?.lawful === true) {
|
|
12771
12775
|
await markRunTerminal(admitted.runDirectory);
|
|
@@ -12834,7 +12838,7 @@ function jsonSafeReplacer() {
|
|
|
12834
12838
|
};
|
|
12835
12839
|
}
|
|
12836
12840
|
async function writeHardenedArtifactFile(artifactsDir, namePrefix, payload) {
|
|
12837
|
-
const filePath =
|
|
12841
|
+
const filePath = join32(artifactsDir, `${namePrefix}-${randomUUID6()}.json`);
|
|
12838
12842
|
const body = `${JSON.stringify(payload, jsonSafeReplacer(), 2)}
|
|
12839
12843
|
`;
|
|
12840
12844
|
const noFollowFlag = typeof fsConstants2.O_NOFOLLOW === "number" ? fsConstants2.O_NOFOLLOW : 0;
|
|
@@ -13089,7 +13093,7 @@ var init_auto_resume = __esm({
|
|
|
13089
13093
|
// src/public-cli/post-admission.ts
|
|
13090
13094
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
13091
13095
|
import { writeFile as writeFile8 } from "node:fs/promises";
|
|
13092
|
-
import { isAbsolute as isAbsolute7, join as
|
|
13096
|
+
import { isAbsolute as isAbsolute7, join as join33, resolve as resolve13 } from "node:path";
|
|
13093
13097
|
function describeCaughtError(error) {
|
|
13094
13098
|
if (error instanceof Error) {
|
|
13095
13099
|
const code = error.code;
|
|
@@ -13185,7 +13189,7 @@ async function recordBestEffortPostDispatchDiagnostic(admitted, env, diagnostic,
|
|
|
13185
13189
|
try {
|
|
13186
13190
|
const artifactsDir = await ensureRealArtifactsDirectory(admitted.runDirectory);
|
|
13187
13191
|
await writeFile8(
|
|
13188
|
-
|
|
13192
|
+
join33(artifactsDir, `post-admission-diagnostic-${randomUUID7()}.json`),
|
|
13189
13193
|
`${JSON.stringify({ version: 1, ...payload }, null, 2)}
|
|
13190
13194
|
`,
|
|
13191
13195
|
{ encoding: "utf8", flag: "wx" }
|
|
@@ -13214,7 +13218,7 @@ async function presentControlledFailure2(admitted, failureInput, adapters, autho
|
|
|
13214
13218
|
const knownFailure = failureInput.knownFailure ?? resumeObservation.observationReadFailure;
|
|
13215
13219
|
const session = !hasThrown && !failureInput.timedOut && knownFailure === void 0 && failureInput.knownCause === void 0 && admitted.principal !== void 0 ? await inspectJudgeSession(authority.decode(admitted.principal).sessionFile) : void 0;
|
|
13216
13220
|
const fromKnownFailure = explicitInternalKnownFailureClassificationInput(knownFailure);
|
|
13217
|
-
const
|
|
13221
|
+
const failure = classifyPostAdmissionFailure({
|
|
13218
13222
|
timedOut: failureInput.timedOut,
|
|
13219
13223
|
code: failureInput.code,
|
|
13220
13224
|
stderr: failureInput.stderr,
|
|
@@ -13233,7 +13237,7 @@ async function presentControlledFailure2(admitted, failureInput, adapters, autho
|
|
|
13233
13237
|
let publishedErrorPath;
|
|
13234
13238
|
let terminal;
|
|
13235
13239
|
try {
|
|
13236
|
-
const settled = await settleFailureTerminalResult(admitted,
|
|
13240
|
+
const settled = await settleFailureTerminalResult(admitted, failure, authority, {
|
|
13237
13241
|
...resumable ? { resume: { command: renderResumeCommand(admitted.runId) } } : {},
|
|
13238
13242
|
...failureInput.invocationScopeId === void 0 || failureInput.invocationScopeId.length === 0 ? {} : { invocationScopeId: failureInput.invocationScopeId },
|
|
13239
13243
|
onErrorPublished: (path) => {
|
|
@@ -13326,7 +13330,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
13326
13330
|
const rows = await readRecordedSubmissionRows(
|
|
13327
13331
|
admitted.projectRoot,
|
|
13328
13332
|
admitted.runId,
|
|
13329
|
-
{ home: homeFromRunDirectory(admitted.runDirectory), sessionParent:
|
|
13333
|
+
{ home: homeFromRunDirectory(admitted.runDirectory), sessionParent: join33(admitted.runDirectory, "session", "session.jsonl") }
|
|
13330
13334
|
);
|
|
13331
13335
|
let ticketNumber;
|
|
13332
13336
|
for (const row of rows) {
|
|
@@ -13453,7 +13457,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
13453
13457
|
let stderrLogWriteFailure;
|
|
13454
13458
|
try {
|
|
13455
13459
|
await writeFile8(
|
|
13456
|
-
|
|
13460
|
+
join33(admitted.runDirectory, "stderr.log"),
|
|
13457
13461
|
result.stderr,
|
|
13458
13462
|
"utf8"
|
|
13459
13463
|
);
|
|
@@ -13732,7 +13736,7 @@ async function dispatchAfterWriterLease(input) {
|
|
|
13732
13736
|
}
|
|
13733
13737
|
function isAlreadyFrozenSummonsAttachment(runDirectory, attachmentPath) {
|
|
13734
13738
|
const absolute = isAbsolute7(attachmentPath) ? attachmentPath : resolve13(attachmentPath);
|
|
13735
|
-
return pathContainedIn(
|
|
13739
|
+
return pathContainedIn(join33(runDirectory, "attachments"), absolute);
|
|
13736
13740
|
}
|
|
13737
13741
|
async function prepareSummonsResumeMaterials(runDirectory, summons) {
|
|
13738
13742
|
if (summons === void 0) return void 0;
|
|
@@ -13914,10 +13918,10 @@ async function runPostAdmissionSeatResume(input) {
|
|
|
13914
13918
|
await presentResumeFailurePointer(
|
|
13915
13919
|
input.io,
|
|
13916
13920
|
error,
|
|
13917
|
-
(
|
|
13921
|
+
(failure) => writeResumeDiagnosticFile(
|
|
13918
13922
|
loaded.admitted.runDirectory,
|
|
13919
13923
|
loaded.admitted.runId,
|
|
13920
|
-
|
|
13924
|
+
failure,
|
|
13921
13925
|
loaded.admitted.role
|
|
13922
13926
|
)
|
|
13923
13927
|
);
|
|
@@ -13940,7 +13944,7 @@ async function pointExistingRunFailure(home, runId, authority, io, thrown) {
|
|
|
13940
13944
|
await presentResumeFailurePointer(
|
|
13941
13945
|
io,
|
|
13942
13946
|
thrown,
|
|
13943
|
-
(
|
|
13947
|
+
(failure) => writeResumeDiagnosticFile(runDirectory, runId, failure)
|
|
13944
13948
|
);
|
|
13945
13949
|
return true;
|
|
13946
13950
|
}
|
|
@@ -13948,7 +13952,7 @@ async function pointExistingRunFailure(home, runId, authority, io, thrown) {
|
|
|
13948
13952
|
await presentResumeFailurePointer(
|
|
13949
13953
|
io,
|
|
13950
13954
|
thrown,
|
|
13951
|
-
(
|
|
13955
|
+
(failure) => writeResumeDiagnosticFile(runDirectory, runId, failure, record4.role)
|
|
13952
13956
|
);
|
|
13953
13957
|
return true;
|
|
13954
13958
|
}
|
|
@@ -13964,14 +13968,14 @@ function showResumeErrorPointer(io, exitCode, terminal) {
|
|
|
13964
13968
|
if (publishedError !== void 0) writeResumeFailurePointer(io, publishedError);
|
|
13965
13969
|
}
|
|
13966
13970
|
async function presentResumeFailurePointer(io, thrown, publish) {
|
|
13967
|
-
const
|
|
13971
|
+
const failure = classifyPostAdmissionFailure({
|
|
13968
13972
|
timedOut: false,
|
|
13969
13973
|
code: null,
|
|
13970
13974
|
stderr: "",
|
|
13971
13975
|
thrown
|
|
13972
13976
|
});
|
|
13973
13977
|
try {
|
|
13974
|
-
writeResumeFailurePointer(io, await publish(
|
|
13978
|
+
writeResumeFailurePointer(io, await publish(failure));
|
|
13975
13979
|
} catch (publishError) {
|
|
13976
13980
|
const cause = {
|
|
13977
13981
|
publishError: formatErrorCauseDetail(publishError)
|
|
@@ -13985,18 +13989,18 @@ async function presentResumeFailurePointer(io, thrown, publish) {
|
|
|
13985
13989
|
}, io);
|
|
13986
13990
|
}
|
|
13987
13991
|
}
|
|
13988
|
-
async function writeResumeDiagnosticFile(runDirectory, runId,
|
|
13992
|
+
async function writeResumeDiagnosticFile(runDirectory, runId, failure, role) {
|
|
13989
13993
|
const dir = await ensureRealArtifactsDirectory(runDirectory);
|
|
13990
|
-
const path =
|
|
13994
|
+
const path = join33(dir, `resume-diagnostic-${randomUUID7()}.json`);
|
|
13991
13995
|
await writeFile8(
|
|
13992
13996
|
path,
|
|
13993
13997
|
`${JSON.stringify({
|
|
13994
13998
|
runId,
|
|
13995
13999
|
...role === void 0 ? {} : { role },
|
|
13996
|
-
diagnostic:
|
|
13997
|
-
...
|
|
13998
|
-
...
|
|
13999
|
-
...
|
|
14000
|
+
diagnostic: failure.diagnostic,
|
|
14001
|
+
...failure.cause === void 0 ? {} : { cause: failure.cause },
|
|
14002
|
+
...failure.identity === void 0 ? {} : { identity: failure.identity },
|
|
14003
|
+
...failure.details === void 0 ? {} : { details: failure.details }
|
|
14000
14004
|
}, null, 2)}
|
|
14001
14005
|
`,
|
|
14002
14006
|
{ encoding: "utf8", flag: "wx" }
|
|
@@ -14156,16 +14160,16 @@ var init_seat_ticket_binding = __esm({
|
|
|
14156
14160
|
// src/public-cli/machine-method-skills.ts
|
|
14157
14161
|
import { accessSync, constants as constants2, statSync as statSync4 } from "node:fs";
|
|
14158
14162
|
import { lstat as lstat5, mkdir as mkdir4, symlink } from "node:fs/promises";
|
|
14159
|
-
import { join as
|
|
14163
|
+
import { join as join34 } from "node:path";
|
|
14160
14164
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
14161
14165
|
function skillRoot(home) {
|
|
14162
|
-
return
|
|
14166
|
+
return join34(home, ".agents/skills");
|
|
14163
14167
|
}
|
|
14164
14168
|
function installedMethodSkillPath(home, name) {
|
|
14165
14169
|
return installedSkillPath(skillRoot(home), name);
|
|
14166
14170
|
}
|
|
14167
14171
|
function installedSkillPath(root, name) {
|
|
14168
|
-
const path =
|
|
14172
|
+
const path = join34(root, name, "SKILL.md");
|
|
14169
14173
|
try {
|
|
14170
14174
|
if (!statSync4(path).isFile()) return void 0;
|
|
14171
14175
|
accessSync(path, constants2.R_OK);
|
|
@@ -14178,9 +14182,9 @@ function installedSkillPath(root, name) {
|
|
|
14178
14182
|
}
|
|
14179
14183
|
function linkedSkillRoot(home, host) {
|
|
14180
14184
|
if (host === "claude" || host === "claude-code") {
|
|
14181
|
-
return
|
|
14185
|
+
return join34(process.env.CLAUDE_CONFIG_DIR?.trim() || join34(home, ".claude"), "skills");
|
|
14182
14186
|
}
|
|
14183
|
-
if (host === "hermes") return
|
|
14187
|
+
if (host === "hermes") return join34(home, ".hermes/skills");
|
|
14184
14188
|
return void 0;
|
|
14185
14189
|
}
|
|
14186
14190
|
async function occupied(path) {
|
|
@@ -14237,7 +14241,7 @@ async function runMachineSkillSetup(home, stdout) {
|
|
|
14237
14241
|
const missingBySource = /* @__PURE__ */ new Map();
|
|
14238
14242
|
let unsourced = false;
|
|
14239
14243
|
for (const name of packagedMethodSkillNames()) {
|
|
14240
|
-
const path =
|
|
14244
|
+
const path = join34(canonical, name);
|
|
14241
14245
|
if (await occupied(path)) {
|
|
14242
14246
|
warnOccupied(path, stdout);
|
|
14243
14247
|
continue;
|
|
@@ -14259,17 +14263,17 @@ async function runMachineSkillSetup(home, stdout) {
|
|
|
14259
14263
|
if (unsourced) return 1;
|
|
14260
14264
|
for (const host of ["claude-code", "hermes"]) {
|
|
14261
14265
|
const root = linkedSkillRoot(home, host);
|
|
14262
|
-
const
|
|
14266
|
+
const description = host === "claude-code" ? HEADLESS_HOST_DESCRIPTIONS.claude : HOST_DESCRIPTIONS.hermes;
|
|
14263
14267
|
try {
|
|
14264
|
-
accessSync(
|
|
14268
|
+
accessSync(resolveHostBinary(description, home), constants2.X_OK);
|
|
14265
14269
|
} catch (error) {
|
|
14266
14270
|
if (["ENOENT", "ENOTDIR", "EACCES"].includes(error.code ?? "")) continue;
|
|
14267
14271
|
throw error;
|
|
14268
14272
|
}
|
|
14269
14273
|
for (const name of packagedMethodSkillNames()) {
|
|
14270
|
-
const target =
|
|
14274
|
+
const target = join34(canonical, name);
|
|
14271
14275
|
if (installedMethodSkillPath(home, name) === void 0) continue;
|
|
14272
|
-
const link =
|
|
14276
|
+
const link = join34(root, name);
|
|
14273
14277
|
if (await occupied(link)) {
|
|
14274
14278
|
warnOccupied(link, stdout);
|
|
14275
14279
|
continue;
|
|
@@ -15477,7 +15481,7 @@ var init_analyst_book_key = __esm({
|
|
|
15477
15481
|
|
|
15478
15482
|
// src/analyst-index.ts
|
|
15479
15483
|
import { open as open2, readFile as readFile18, unlink as unlink4 } from "node:fs/promises";
|
|
15480
|
-
import { dirname as dirname21, join as
|
|
15484
|
+
import { dirname as dirname21, join as join35 } from "node:path";
|
|
15481
15485
|
function sleep(ms) {
|
|
15482
15486
|
return new Promise((resolve22) => {
|
|
15483
15487
|
setTimeout(resolve22, ms);
|
|
@@ -15486,7 +15490,7 @@ function sleep(ms) {
|
|
|
15486
15490
|
async function withAnalystLibraryIndexLock(ledgerHome, fn) {
|
|
15487
15491
|
const indexPath = analystLibraryIndexPath(ledgerHome);
|
|
15488
15492
|
ensureRealDirectoryTree(ledgerHome, dirname21(indexPath));
|
|
15489
|
-
const lockPath =
|
|
15493
|
+
const lockPath = join35(dirname21(indexPath), LIBRARY_INDEX_LOCK_NAME);
|
|
15490
15494
|
assertLedgerFileInsideHome(lockPath, ledgerHome);
|
|
15491
15495
|
const startedAt = Date.now();
|
|
15492
15496
|
while (true) {
|
|
@@ -15513,7 +15517,7 @@ async function withAnalystLibraryIndexLock(ledgerHome, fn) {
|
|
|
15513
15517
|
}
|
|
15514
15518
|
}
|
|
15515
15519
|
function analystLibraryIndexPath(ledgerHome) {
|
|
15516
|
-
return
|
|
15520
|
+
return join35(ledgerHome, "analyst", "library-index.json");
|
|
15517
15521
|
}
|
|
15518
15522
|
function rowFromIssueMetricsPage(page) {
|
|
15519
15523
|
return {
|
|
@@ -15809,7 +15813,7 @@ var init_analyst_cohort = __esm({
|
|
|
15809
15813
|
|
|
15810
15814
|
// src/analyst-ledger.ts
|
|
15811
15815
|
import { readdir as readdir6, readFile as readFile19 } from "node:fs/promises";
|
|
15812
|
-
import { basename as basename9, join as
|
|
15816
|
+
import { basename as basename9, join as join36 } from "node:path";
|
|
15813
15817
|
function isMissingPathError6(error) {
|
|
15814
15818
|
return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
|
|
15815
15819
|
}
|
|
@@ -15838,7 +15842,7 @@ function ghostLeaseCheckFromAutopsy(autopsy) {
|
|
|
15838
15842
|
}
|
|
15839
15843
|
}
|
|
15840
15844
|
async function classifyGhostCandidate(input) {
|
|
15841
|
-
const autopsy = await autopsyWriterLock(
|
|
15845
|
+
const autopsy = await autopsyWriterLock(join36(input.runDirectory, "writer.lock"));
|
|
15842
15846
|
const leaseCheck = ghostLeaseCheckFromAutopsy(autopsy);
|
|
15843
15847
|
if (leaseCheck === void 0) return { kind: "live" };
|
|
15844
15848
|
return {
|
|
@@ -15867,7 +15871,7 @@ async function listLedgerBookNames(booksRoot) {
|
|
|
15867
15871
|
async function readInvocationScopeFields(runDirectory) {
|
|
15868
15872
|
let raw;
|
|
15869
15873
|
try {
|
|
15870
|
-
raw = await readFile19(
|
|
15874
|
+
raw = await readFile19(join36(runDirectory, "invocation.json"), "utf8");
|
|
15871
15875
|
} catch (error) {
|
|
15872
15876
|
if (isMissingPathError6(error)) return void 0;
|
|
15873
15877
|
throw error;
|
|
@@ -15900,7 +15904,7 @@ function decideIssueScope(input) {
|
|
|
15900
15904
|
}
|
|
15901
15905
|
async function resolveSessionFile(runDirectory) {
|
|
15902
15906
|
try {
|
|
15903
|
-
const raw = await readFile19(
|
|
15907
|
+
const raw = await readFile19(join36(runDirectory, "invocation.json"), "utf8");
|
|
15904
15908
|
const parsed = JSON.parse(raw);
|
|
15905
15909
|
if (isRecord12(parsed) && typeof parsed.sessionFile === "string" && parsed.sessionFile.trim() !== "") {
|
|
15906
15910
|
return parsed.sessionFile;
|
|
@@ -15908,7 +15912,7 @@ async function resolveSessionFile(runDirectory) {
|
|
|
15908
15912
|
} catch (error) {
|
|
15909
15913
|
if (!isMissingPathError6(error)) throw error;
|
|
15910
15914
|
}
|
|
15911
|
-
return
|
|
15915
|
+
return join36(runDirectory, "session", "session.jsonl");
|
|
15912
15916
|
}
|
|
15913
15917
|
function attributeSessionRowsForRun(input) {
|
|
15914
15918
|
if (pathContainedIn(input.runDirectory, input.sessionFile)) {
|
|
@@ -15958,11 +15962,21 @@ function admitFrameSpanFromRows(rows) {
|
|
|
15958
15962
|
}
|
|
15959
15963
|
return {
|
|
15960
15964
|
models,
|
|
15961
|
-
frameSpan: { startedAt: span.startedAt, endedAt: span.endedAt },
|
|
15965
|
+
frameSpan: { startedAt: span.startedAt, endedAt: span.endedAt, wallMs: endedMs - startedMs },
|
|
15962
15966
|
partialFirstFrameAt: { status: "present", at: span.startedAt },
|
|
15963
15967
|
partialLastFrameAt: { status: "present", at: span.endedAt }
|
|
15964
15968
|
};
|
|
15965
15969
|
}
|
|
15970
|
+
function sumAnalystRunWallMs(runs) {
|
|
15971
|
+
let total = 0;
|
|
15972
|
+
for (const run of runs) total += run.frameSpan.wallMs;
|
|
15973
|
+
return total;
|
|
15974
|
+
}
|
|
15975
|
+
function compareAnalystLegs(a, b) {
|
|
15976
|
+
if (a.book !== b.book) return a.book.localeCompare(b.book);
|
|
15977
|
+
if (a.role !== b.role) return a.role.localeCompare(b.role);
|
|
15978
|
+
return a.runId.localeCompare(b.runId);
|
|
15979
|
+
}
|
|
15966
15980
|
async function classifyScopedRun(input) {
|
|
15967
15981
|
const missingSources = [];
|
|
15968
15982
|
const reasons = [];
|
|
@@ -16100,9 +16114,9 @@ async function classifyScopedRun(input) {
|
|
|
16100
16114
|
}
|
|
16101
16115
|
let gateCycles;
|
|
16102
16116
|
try {
|
|
16103
|
-
const parentSessionFile =
|
|
16117
|
+
const parentSessionFile = join36(input.runDirectory, "session", "session.jsonl");
|
|
16104
16118
|
gateCycles = await readAnalystGateCyclesFromAuditorRoles(
|
|
16105
|
-
|
|
16119
|
+
join36(input.runDirectory, "session", "auditor-roles"),
|
|
16106
16120
|
{ parentSessionFile }
|
|
16107
16121
|
);
|
|
16108
16122
|
} catch (error) {
|
|
@@ -16137,7 +16151,7 @@ async function classifyScopedRun(input) {
|
|
|
16137
16151
|
async function scanAnalystIssueRuns(input) {
|
|
16138
16152
|
const ledgerHome = resolveActivationLedgerHome(input.home);
|
|
16139
16153
|
const scopeTicketNumber = input.ticketNumber;
|
|
16140
|
-
const booksRoot =
|
|
16154
|
+
const booksRoot = join36(ledgerHome, "books");
|
|
16141
16155
|
let wholeBook = false;
|
|
16142
16156
|
let scopeRootIdentity;
|
|
16143
16157
|
let bookNames;
|
|
@@ -16170,7 +16184,7 @@ async function scanAnalystIssueRuns(input) {
|
|
|
16170
16184
|
const ghostLegs = [];
|
|
16171
16185
|
const scopeConflicts = [];
|
|
16172
16186
|
for (const book of bookNames) {
|
|
16173
|
-
const bookDir =
|
|
16187
|
+
const bookDir = join36(booksRoot, book);
|
|
16174
16188
|
let runDirectories;
|
|
16175
16189
|
try {
|
|
16176
16190
|
runDirectories = await listBookRunDirectories(bookDir);
|
|
@@ -16243,9 +16257,6 @@ var init_analyst_ledger = __esm({
|
|
|
16243
16257
|
function isRecord13(value) {
|
|
16244
16258
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16245
16259
|
}
|
|
16246
|
-
function wallMsFromSpan(span) {
|
|
16247
|
-
return Date.parse(span.endedAt) - Date.parse(span.startedAt);
|
|
16248
|
-
}
|
|
16249
16260
|
function findCollectorGroups(body) {
|
|
16250
16261
|
if (Array.isArray(body.groups)) return body.groups;
|
|
16251
16262
|
const receipt = body.receipt;
|
|
@@ -16354,7 +16365,7 @@ function projectLegs(runs) {
|
|
|
16354
16365
|
book: run.book,
|
|
16355
16366
|
role: run.role,
|
|
16356
16367
|
startedAt: run.frameSpan.startedAt,
|
|
16357
|
-
wallMs:
|
|
16368
|
+
wallMs: run.frameSpan.wallMs,
|
|
16358
16369
|
terminalLabel: mapped.terminalLabel,
|
|
16359
16370
|
accepted: mapped.accepted,
|
|
16360
16371
|
success: mapped.success,
|
|
@@ -16364,11 +16375,7 @@ function projectLegs(runs) {
|
|
|
16364
16375
|
rework: ordinal >= 2
|
|
16365
16376
|
});
|
|
16366
16377
|
}
|
|
16367
|
-
return legs.sort(
|
|
16368
|
-
if (a.book !== b.book) return a.book.localeCompare(b.book);
|
|
16369
|
-
if (a.role !== b.role) return a.role.localeCompare(b.role);
|
|
16370
|
-
return a.runId.localeCompare(b.runId);
|
|
16371
|
-
});
|
|
16378
|
+
return legs.sort(compareAnalystLegs);
|
|
16372
16379
|
}
|
|
16373
16380
|
function aggregateByRole(legs) {
|
|
16374
16381
|
const roles = [...new Set(legs.map((leg) => leg.role))].sort((a, b) => a.localeCompare(b));
|
|
@@ -16412,12 +16419,10 @@ function aggregateByRole(legs) {
|
|
|
16412
16419
|
};
|
|
16413
16420
|
});
|
|
16414
16421
|
}
|
|
16415
|
-
function reworkLens(legs) {
|
|
16422
|
+
function reworkLens(legs, totalWallMs) {
|
|
16416
16423
|
let reworkWallMs = 0;
|
|
16417
|
-
let totalWallMs = 0;
|
|
16418
16424
|
let reworkLegCount = 0;
|
|
16419
16425
|
for (const leg of legs) {
|
|
16420
|
-
totalWallMs += leg.wallMs;
|
|
16421
16426
|
if (leg.rework) {
|
|
16422
16427
|
reworkWallMs += leg.wallMs;
|
|
16423
16428
|
reworkLegCount += 1;
|
|
@@ -16438,13 +16443,14 @@ function buildAcceptanceSuccessReworkSection(runs) {
|
|
|
16438
16443
|
kind: "analyst-acceptance-success-rework",
|
|
16439
16444
|
legs,
|
|
16440
16445
|
byRole: aggregateByRole(legs),
|
|
16441
|
-
rework: reworkLens(legs)
|
|
16446
|
+
rework: reworkLens(legs, sumAnalystRunWallMs(runs))
|
|
16442
16447
|
};
|
|
16443
16448
|
}
|
|
16444
16449
|
var WORKER_ROLES, ACCEPTED_STATUS, SUCCESS_STATUS, acceptanceSuccessReworkFamily, acceptance_success_rework_default;
|
|
16445
16450
|
var init_acceptance_success_rework = __esm({
|
|
16446
16451
|
"src/analyst-metric-families/acceptance-success-rework.ts"() {
|
|
16447
16452
|
"use strict";
|
|
16453
|
+
init_analyst_ledger();
|
|
16448
16454
|
init_analyst_median();
|
|
16449
16455
|
init_packaged_role_registry();
|
|
16450
16456
|
WORKER_ROLES = /* @__PURE__ */ new Set(["coder", "fixer"]);
|
|
@@ -16477,127 +16483,16 @@ var init_acceptance_success_rework = __esm({
|
|
|
16477
16483
|
}
|
|
16478
16484
|
});
|
|
16479
16485
|
|
|
16480
|
-
// src/analyst-
|
|
16481
|
-
function
|
|
16482
|
-
|
|
16483
|
-
if (
|
|
16484
|
-
|
|
16485
|
-
}
|
|
16486
|
-
|
|
16487
|
-
if (denominator === 0) return void 0;
|
|
16488
|
-
return numerator / denominator;
|
|
16489
|
-
}
|
|
16490
|
-
function displayNameFor(rawGroupKey, combinationMapping) {
|
|
16491
|
-
if (combinationMapping === void 0) return rawGroupKey;
|
|
16492
|
-
const aliased = combinationMapping[rawGroupKey];
|
|
16493
|
-
return aliased === void 0 ? rawGroupKey : aliased;
|
|
16486
|
+
// src/analyst-metric-families/b2-frame-buckets-actions.ts
|
|
16487
|
+
function timestampMs(iso) {
|
|
16488
|
+
const ms = Date.parse(iso);
|
|
16489
|
+
if (!Number.isFinite(ms)) {
|
|
16490
|
+
throw new Error(`unparseable timestamp: ${iso}`);
|
|
16491
|
+
}
|
|
16492
|
+
return ms;
|
|
16494
16493
|
}
|
|
16495
|
-
function
|
|
16496
|
-
return
|
|
16497
|
-
if (a.book !== b.book) return a.book.localeCompare(b.book);
|
|
16498
|
-
return a.runId.localeCompare(b.runId);
|
|
16499
|
-
});
|
|
16500
|
-
}
|
|
16501
|
-
function modelIdentityAbsentEntry(run) {
|
|
16502
|
-
return {
|
|
16503
|
-
runId: run.runId,
|
|
16504
|
-
book: run.book,
|
|
16505
|
-
missingSources: ["session-model"],
|
|
16506
|
-
reason: "session has no usable model identity",
|
|
16507
|
-
firstFrameAt: { status: "present", at: run.frameSpan.startedAt },
|
|
16508
|
-
// Readable legs already admitted a full span — retain end edge for lastActivityAt.
|
|
16509
|
-
lastFrameAt: { status: "present", at: run.frameSpan.endedAt }
|
|
16510
|
-
};
|
|
16511
|
-
}
|
|
16512
|
-
function buildAnalystModelGroupsPage(input) {
|
|
16513
|
-
const groupedRuns = [];
|
|
16514
|
-
const modelAbsent = [];
|
|
16515
|
-
for (const run of input.runs) {
|
|
16516
|
-
const rawGroupKey = analystModelGroupKey(run.models);
|
|
16517
|
-
if (rawGroupKey === void 0) {
|
|
16518
|
-
modelAbsent.push(modelIdentityAbsentEntry(run));
|
|
16519
|
-
} else {
|
|
16520
|
-
groupedRuns.push({ run, rawGroupKey });
|
|
16521
|
-
}
|
|
16522
|
-
}
|
|
16523
|
-
const acceptance = buildAcceptanceSuccessReworkSection(
|
|
16524
|
-
groupedRuns.map(({ run }) => run)
|
|
16525
|
-
);
|
|
16526
|
-
const legByRunId = new Map(
|
|
16527
|
-
(acceptance?.legs ?? []).map((leg) => [leg.runId, leg])
|
|
16528
|
-
);
|
|
16529
|
-
const byRaw = /* @__PURE__ */ new Map();
|
|
16530
|
-
for (const { run, rawGroupKey } of groupedRuns) {
|
|
16531
|
-
const leg = legByRunId.get(run.runId);
|
|
16532
|
-
if (leg === void 0) {
|
|
16533
|
-
throw new Error(
|
|
16534
|
-
`analyst model-groups: missing acceptance projection for run ${run.runId}`
|
|
16535
|
-
);
|
|
16536
|
-
}
|
|
16537
|
-
let acc = byRaw.get(rawGroupKey);
|
|
16538
|
-
if (acc === void 0) {
|
|
16539
|
-
acc = {
|
|
16540
|
-
acceptedCount: 0,
|
|
16541
|
-
successCount: 0,
|
|
16542
|
-
successEligibleCount: 0,
|
|
16543
|
-
noReceiptCount: 0,
|
|
16544
|
-
walls: []
|
|
16545
|
-
};
|
|
16546
|
-
byRaw.set(rawGroupKey, acc);
|
|
16547
|
-
}
|
|
16548
|
-
if (leg.accepted) acc.acceptedCount += 1;
|
|
16549
|
-
if (leg.success) acc.successCount += 1;
|
|
16550
|
-
if (leg.successEligible) acc.successEligibleCount += 1;
|
|
16551
|
-
if (leg.noReceipt) acc.noReceiptCount += 1;
|
|
16552
|
-
acc.walls.push(leg.wallMs);
|
|
16553
|
-
}
|
|
16554
|
-
const rawKeys = [...byRaw.keys()].sort((a, b) => a.localeCompare(b));
|
|
16555
|
-
const groups = rawKeys.map((rawGroupKey) => {
|
|
16556
|
-
const acc = byRaw.get(rawGroupKey);
|
|
16557
|
-
const legCount = acc.walls.length;
|
|
16558
|
-
return {
|
|
16559
|
-
rawGroupKey,
|
|
16560
|
-
displayName: displayNameFor(rawGroupKey, input.combinationMapping),
|
|
16561
|
-
legCount,
|
|
16562
|
-
acceptedCount: acc.acceptedCount,
|
|
16563
|
-
acceptanceRate: rate(acc.acceptedCount, legCount),
|
|
16564
|
-
successCount: acc.successCount,
|
|
16565
|
-
successEligibleCount: acc.successEligibleCount,
|
|
16566
|
-
successRate: rate(acc.successCount, acc.successEligibleCount),
|
|
16567
|
-
noReceiptCount: acc.noReceiptCount,
|
|
16568
|
-
noReceiptRate: rate(acc.noReceiptCount, legCount),
|
|
16569
|
-
wallClockMedianMs: medianNumber(acc.walls)
|
|
16570
|
-
};
|
|
16571
|
-
});
|
|
16572
|
-
const unreadable = sortUnreadable([...input.unreadable, ...modelAbsent]);
|
|
16573
|
-
return {
|
|
16574
|
-
kind: "analyst-model-groups",
|
|
16575
|
-
mode: "model-groups",
|
|
16576
|
-
projectRoots: [...input.projectRoots].sort((a, b) => a.localeCompare(b)),
|
|
16577
|
-
groups,
|
|
16578
|
-
legCount: groupedRuns.length,
|
|
16579
|
-
unreadableCount: unreadable.length,
|
|
16580
|
-
unreadable
|
|
16581
|
-
};
|
|
16582
|
-
}
|
|
16583
|
-
var init_analyst_model_groups = __esm({
|
|
16584
|
-
"src/analyst-model-groups.ts"() {
|
|
16585
|
-
"use strict";
|
|
16586
|
-
init_acceptance_success_rework();
|
|
16587
|
-
init_analyst_median();
|
|
16588
|
-
}
|
|
16589
|
-
});
|
|
16590
|
-
|
|
16591
|
-
// src/analyst-metric-families/b2-frame-buckets-actions.ts
|
|
16592
|
-
function timestampMs(iso) {
|
|
16593
|
-
const ms = Date.parse(iso);
|
|
16594
|
-
if (!Number.isFinite(ms)) {
|
|
16595
|
-
throw new Error(`unparseable timestamp: ${iso}`);
|
|
16596
|
-
}
|
|
16597
|
-
return ms;
|
|
16598
|
-
}
|
|
16599
|
-
function toIso(ms) {
|
|
16600
|
-
return new Date(ms).toISOString();
|
|
16494
|
+
function toIso(ms) {
|
|
16495
|
+
return new Date(ms).toISOString();
|
|
16601
16496
|
}
|
|
16602
16497
|
function closedTools(intervals) {
|
|
16603
16498
|
const out = [];
|
|
@@ -16710,7 +16605,7 @@ function sortActionsDescending(actions) {
|
|
|
16710
16605
|
function computeAnalystB2RunMetrics(facts) {
|
|
16711
16606
|
const frameStartMs = timestampMs(facts.frameSpan.startedAt);
|
|
16712
16607
|
const frameEndMs = timestampMs(facts.frameSpan.endedAt);
|
|
16713
|
-
const wallMs =
|
|
16608
|
+
const wallMs = facts.frameSpan.wallMs;
|
|
16714
16609
|
const tools = clipToolsToFrame(closedTools(facts.toolIntervals), frameStartMs, frameEndMs);
|
|
16715
16610
|
const toolUnion = mergeUnion(tools);
|
|
16716
16611
|
const toolBucketMs = toolUnion.reduce(
|
|
@@ -16740,15 +16635,12 @@ var init_b2_frame_buckets_actions = __esm({
|
|
|
16740
16635
|
"src/analyst-metric-families/b2-frame-buckets-actions.ts"() {
|
|
16741
16636
|
"use strict";
|
|
16742
16637
|
init_analyst_median();
|
|
16638
|
+
init_analyst_ledger();
|
|
16743
16639
|
b2FrameBucketsActionsFamily = {
|
|
16744
16640
|
id: "b2-frame-buckets-actions",
|
|
16745
16641
|
contribute(input) {
|
|
16746
16642
|
if (input.runs.length === 0) return void 0;
|
|
16747
|
-
const runs = [...input.runs].map(computeAnalystB2RunMetrics).sort(
|
|
16748
|
-
if (a.book !== b.book) return a.book.localeCompare(b.book);
|
|
16749
|
-
if (a.role !== b.role) return a.role.localeCompare(b.role);
|
|
16750
|
-
return a.runId.localeCompare(b.runId);
|
|
16751
|
-
});
|
|
16643
|
+
const runs = [...input.runs].map(computeAnalystB2RunMetrics).sort(compareAnalystLegs);
|
|
16752
16644
|
const section = {
|
|
16753
16645
|
kind: "analyst-b2-frame-buckets-actions",
|
|
16754
16646
|
runs
|
|
@@ -16781,11 +16673,6 @@ function projectLeg(facts) {
|
|
|
16781
16673
|
rounds
|
|
16782
16674
|
};
|
|
16783
16675
|
}
|
|
16784
|
-
function compareLegs(a, b) {
|
|
16785
|
-
if (a.book !== b.book) return a.book.localeCompare(b.book);
|
|
16786
|
-
if (a.role !== b.role) return a.role.localeCompare(b.role);
|
|
16787
|
-
return a.runId.localeCompare(b.runId);
|
|
16788
|
-
}
|
|
16789
16676
|
function emptyAccum() {
|
|
16790
16677
|
return { rounds: 0, bounceCount: 0, passCount: 0, wallSum: 0 };
|
|
16791
16678
|
}
|
|
@@ -16821,11 +16708,12 @@ var gateCyclesFamily, gate_cycles_default;
|
|
|
16821
16708
|
var init_gate_cycles = __esm({
|
|
16822
16709
|
"src/analyst-metric-families/gate-cycles.ts"() {
|
|
16823
16710
|
"use strict";
|
|
16711
|
+
init_analyst_ledger();
|
|
16824
16712
|
gateCyclesFamily = {
|
|
16825
16713
|
id: "gate-cycles",
|
|
16826
16714
|
contribute(input) {
|
|
16827
16715
|
if (input.runs.length === 0) return void 0;
|
|
16828
|
-
const legs = input.runs.map(projectLeg).sort(
|
|
16716
|
+
const legs = input.runs.map(projectLeg).sort(compareAnalystLegs);
|
|
16829
16717
|
const section = {
|
|
16830
16718
|
kind: "analyst-gate-cycles",
|
|
16831
16719
|
legs,
|
|
@@ -16839,28 +16727,24 @@ var init_gate_cycles = __esm({
|
|
|
16839
16727
|
});
|
|
16840
16728
|
|
|
16841
16729
|
// src/analyst-metric-families/leg-wall-clock.ts
|
|
16842
|
-
function frameSpanWallMs(span) {
|
|
16843
|
-
return Date.parse(span.endedAt) - Date.parse(span.startedAt);
|
|
16844
|
-
}
|
|
16845
16730
|
function projectEntry(facts) {
|
|
16846
16731
|
return {
|
|
16847
16732
|
runId: facts.runId,
|
|
16848
16733
|
book: facts.book,
|
|
16849
16734
|
role: facts.role,
|
|
16850
|
-
wallMs:
|
|
16735
|
+
wallMs: facts.frameSpan.wallMs
|
|
16851
16736
|
};
|
|
16852
16737
|
}
|
|
16853
16738
|
function compareRankingDesc(a, b) {
|
|
16854
16739
|
if (b.wallMs !== a.wallMs) return b.wallMs - a.wallMs;
|
|
16855
|
-
|
|
16856
|
-
if (a.role !== b.role) return a.role.localeCompare(b.role);
|
|
16857
|
-
return a.runId.localeCompare(b.runId);
|
|
16740
|
+
return compareAnalystLegs(a, b);
|
|
16858
16741
|
}
|
|
16859
16742
|
var legWallClockFamily, leg_wall_clock_default;
|
|
16860
16743
|
var init_leg_wall_clock = __esm({
|
|
16861
16744
|
"src/analyst-metric-families/leg-wall-clock.ts"() {
|
|
16862
16745
|
"use strict";
|
|
16863
16746
|
init_analyst_median();
|
|
16747
|
+
init_analyst_ledger();
|
|
16864
16748
|
legWallClockFamily = {
|
|
16865
16749
|
id: "leg-wall-clock",
|
|
16866
16750
|
contribute(input) {
|
|
@@ -16873,13 +16757,11 @@ var init_leg_wall_clock = __esm({
|
|
|
16873
16757
|
if (medianWallMs === void 0) {
|
|
16874
16758
|
return void 0;
|
|
16875
16759
|
}
|
|
16876
|
-
let totalElapsedMs = 0;
|
|
16877
|
-
for (const wallMs of walls) totalElapsedMs += wallMs;
|
|
16878
16760
|
const section = {
|
|
16879
16761
|
kind: "analyst-leg-wall-clock",
|
|
16880
16762
|
ranking,
|
|
16881
16763
|
medianWallMs,
|
|
16882
|
-
totalElapsedMs
|
|
16764
|
+
totalElapsedMs: sumAnalystRunWallMs(input.runs)
|
|
16883
16765
|
};
|
|
16884
16766
|
return { legWallClock: section };
|
|
16885
16767
|
}
|
|
@@ -16892,9 +16774,6 @@ var init_leg_wall_clock = __esm({
|
|
|
16892
16774
|
function isRecord14(value) {
|
|
16893
16775
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16894
16776
|
}
|
|
16895
|
-
function wallMsFromSpan2(startedAt, endedAt) {
|
|
16896
|
-
return Date.parse(endedAt) - Date.parse(startedAt);
|
|
16897
|
-
}
|
|
16898
16777
|
function readClassCount(body) {
|
|
16899
16778
|
if (!isRecord14(body.outcome)) return void 0;
|
|
16900
16779
|
if (!isRecord14(body.outcome.decisiveFacts)) return void 0;
|
|
@@ -16931,7 +16810,7 @@ function projectRunRow(facts) {
|
|
|
16931
16810
|
role: facts.role,
|
|
16932
16811
|
startedAt,
|
|
16933
16812
|
endedAt,
|
|
16934
|
-
wallMs:
|
|
16813
|
+
wallMs: facts.frameSpan.wallMs,
|
|
16935
16814
|
terminal: projectTerminal(facts)
|
|
16936
16815
|
};
|
|
16937
16816
|
}
|
|
@@ -17042,7 +16921,7 @@ var init_analyst_metric_family = __esm({
|
|
|
17042
16921
|
|
|
17043
16922
|
// src/analyst-page.ts
|
|
17044
16923
|
import { createHash as createHash3 } from "node:crypto";
|
|
17045
|
-
import { dirname as dirname22, join as
|
|
16924
|
+
import { dirname as dirname22, join as join37 } from "node:path";
|
|
17046
16925
|
function analystIssuePageKey(address) {
|
|
17047
16926
|
const parts = ["book", address.bookKey];
|
|
17048
16927
|
if (address.issueNumber !== void 0) {
|
|
@@ -17053,7 +16932,7 @@ function analystIssuePageKey(address) {
|
|
|
17053
16932
|
return createHash3("sha256").update(parts.join("\0")).digest("hex").slice(0, 32);
|
|
17054
16933
|
}
|
|
17055
16934
|
function analystIssuePagePath(ledgerHome, address) {
|
|
17056
|
-
return
|
|
16935
|
+
return join37(ledgerHome, "analyst", "issues", `${analystIssuePageKey(address)}.json`);
|
|
17057
16936
|
}
|
|
17058
16937
|
function analystIssuePageAddressFromPage(page) {
|
|
17059
16938
|
return {
|
|
@@ -17063,13 +16942,9 @@ function analystIssuePageAddressFromPage(page) {
|
|
|
17063
16942
|
};
|
|
17064
16943
|
}
|
|
17065
16944
|
function sortLegs(legs) {
|
|
17066
|
-
return [...legs].sort(
|
|
17067
|
-
if (a.book !== b.book) return a.book.localeCompare(b.book);
|
|
17068
|
-
if (a.role !== b.role) return a.role.localeCompare(b.role);
|
|
17069
|
-
return a.runId.localeCompare(b.runId);
|
|
17070
|
-
});
|
|
16945
|
+
return [...legs].sort(compareAnalystLegs);
|
|
17071
16946
|
}
|
|
17072
|
-
function
|
|
16947
|
+
function sortUnreadable(unreadable) {
|
|
17073
16948
|
return [...unreadable].sort((a, b) => {
|
|
17074
16949
|
if (a.book !== b.book) return a.book.localeCompare(b.book);
|
|
17075
16950
|
return a.runId.localeCompare(b.runId);
|
|
@@ -17105,14 +16980,10 @@ function computeAnalystMsPerKLines(totalElapsedMs, changedLines) {
|
|
|
17105
16980
|
value: totalElapsedMs / (changedLines.value / 1e3)
|
|
17106
16981
|
};
|
|
17107
16982
|
}
|
|
17108
|
-
function frameSpanWallMs2(span) {
|
|
17109
|
-
return Date.parse(span.endedAt) - Date.parse(span.startedAt);
|
|
17110
|
-
}
|
|
17111
16983
|
function summarizeAnalystRunEfficiency(runs, unreadable = []) {
|
|
17112
|
-
|
|
16984
|
+
const totalElapsedMs = sumAnalystRunWallMs(runs);
|
|
17113
16985
|
let latestEndedAt;
|
|
17114
16986
|
for (const run of runs) {
|
|
17115
|
-
totalElapsedMs += frameSpanWallMs2(run.frameSpan);
|
|
17116
16987
|
const endedAt = run.frameSpan.endedAt;
|
|
17117
16988
|
if (latestEndedAt === void 0 || endedAt > latestEndedAt) {
|
|
17118
16989
|
latestEndedAt = endedAt;
|
|
@@ -17137,7 +17008,7 @@ async function buildAnalystIssueMetricsPage(input) {
|
|
|
17137
17008
|
role: run.role
|
|
17138
17009
|
}))
|
|
17139
17010
|
);
|
|
17140
|
-
const unreadable =
|
|
17011
|
+
const unreadable = sortUnreadable(input.unreadable);
|
|
17141
17012
|
const scopeConflicts = sortScopeConflicts(input.scopeConflicts ?? []);
|
|
17142
17013
|
const projectRoot = physicalPathIdentity(input.projectRoot);
|
|
17143
17014
|
const { totalElapsedMs, lastActivityAt } = summarizeAnalystRunEfficiency(
|
|
@@ -17183,11 +17054,118 @@ var init_analyst_page = __esm({
|
|
|
17183
17054
|
"use strict";
|
|
17184
17055
|
init_atomic_write();
|
|
17185
17056
|
init_activation_ledger_topology();
|
|
17057
|
+
init_analyst_ledger();
|
|
17186
17058
|
init_analyst_metric_families();
|
|
17187
17059
|
init_analyst_metric_family();
|
|
17188
17060
|
}
|
|
17189
17061
|
});
|
|
17190
17062
|
|
|
17063
|
+
// src/analyst-model-groups.ts
|
|
17064
|
+
function analystModelGroupKey(models) {
|
|
17065
|
+
if (models.length === 0) return void 0;
|
|
17066
|
+
if (models.length === 1) return models[0];
|
|
17067
|
+
return `mixed:${models.join("+")}`;
|
|
17068
|
+
}
|
|
17069
|
+
function rate(numerator, denominator) {
|
|
17070
|
+
if (denominator === 0) return void 0;
|
|
17071
|
+
return numerator / denominator;
|
|
17072
|
+
}
|
|
17073
|
+
function displayNameFor(rawGroupKey, combinationMapping) {
|
|
17074
|
+
if (combinationMapping === void 0) return rawGroupKey;
|
|
17075
|
+
const aliased = combinationMapping[rawGroupKey];
|
|
17076
|
+
return aliased === void 0 ? rawGroupKey : aliased;
|
|
17077
|
+
}
|
|
17078
|
+
function modelIdentityAbsentEntry(run) {
|
|
17079
|
+
return {
|
|
17080
|
+
runId: run.runId,
|
|
17081
|
+
book: run.book,
|
|
17082
|
+
missingSources: ["session-model"],
|
|
17083
|
+
reason: "session has no usable model identity",
|
|
17084
|
+
firstFrameAt: { status: "present", at: run.frameSpan.startedAt },
|
|
17085
|
+
// Readable legs already admitted a full span — retain end edge for lastActivityAt.
|
|
17086
|
+
lastFrameAt: { status: "present", at: run.frameSpan.endedAt }
|
|
17087
|
+
};
|
|
17088
|
+
}
|
|
17089
|
+
function buildAnalystModelGroupsPage(input) {
|
|
17090
|
+
const groupedRuns = [];
|
|
17091
|
+
const modelAbsent = [];
|
|
17092
|
+
for (const run of input.runs) {
|
|
17093
|
+
const rawGroupKey = analystModelGroupKey(run.models);
|
|
17094
|
+
if (rawGroupKey === void 0) {
|
|
17095
|
+
modelAbsent.push(modelIdentityAbsentEntry(run));
|
|
17096
|
+
} else {
|
|
17097
|
+
groupedRuns.push({ run, rawGroupKey });
|
|
17098
|
+
}
|
|
17099
|
+
}
|
|
17100
|
+
const acceptance = buildAcceptanceSuccessReworkSection(
|
|
17101
|
+
groupedRuns.map(({ run }) => run)
|
|
17102
|
+
);
|
|
17103
|
+
const legByRunId = new Map(
|
|
17104
|
+
(acceptance?.legs ?? []).map((leg) => [leg.runId, leg])
|
|
17105
|
+
);
|
|
17106
|
+
const byRaw = /* @__PURE__ */ new Map();
|
|
17107
|
+
for (const { run, rawGroupKey } of groupedRuns) {
|
|
17108
|
+
const leg = legByRunId.get(run.runId);
|
|
17109
|
+
if (leg === void 0) {
|
|
17110
|
+
throw new Error(
|
|
17111
|
+
`analyst model-groups: missing acceptance projection for run ${run.runId}`
|
|
17112
|
+
);
|
|
17113
|
+
}
|
|
17114
|
+
let acc = byRaw.get(rawGroupKey);
|
|
17115
|
+
if (acc === void 0) {
|
|
17116
|
+
acc = {
|
|
17117
|
+
acceptedCount: 0,
|
|
17118
|
+
successCount: 0,
|
|
17119
|
+
successEligibleCount: 0,
|
|
17120
|
+
noReceiptCount: 0,
|
|
17121
|
+
walls: []
|
|
17122
|
+
};
|
|
17123
|
+
byRaw.set(rawGroupKey, acc);
|
|
17124
|
+
}
|
|
17125
|
+
if (leg.accepted) acc.acceptedCount += 1;
|
|
17126
|
+
if (leg.success) acc.successCount += 1;
|
|
17127
|
+
if (leg.successEligible) acc.successEligibleCount += 1;
|
|
17128
|
+
if (leg.noReceipt) acc.noReceiptCount += 1;
|
|
17129
|
+
acc.walls.push(leg.wallMs);
|
|
17130
|
+
}
|
|
17131
|
+
const rawKeys = [...byRaw.keys()].sort((a, b) => a.localeCompare(b));
|
|
17132
|
+
const groups = rawKeys.map((rawGroupKey) => {
|
|
17133
|
+
const acc = byRaw.get(rawGroupKey);
|
|
17134
|
+
const legCount = acc.walls.length;
|
|
17135
|
+
return {
|
|
17136
|
+
rawGroupKey,
|
|
17137
|
+
displayName: displayNameFor(rawGroupKey, input.combinationMapping),
|
|
17138
|
+
legCount,
|
|
17139
|
+
acceptedCount: acc.acceptedCount,
|
|
17140
|
+
acceptanceRate: rate(acc.acceptedCount, legCount),
|
|
17141
|
+
successCount: acc.successCount,
|
|
17142
|
+
successEligibleCount: acc.successEligibleCount,
|
|
17143
|
+
successRate: rate(acc.successCount, acc.successEligibleCount),
|
|
17144
|
+
noReceiptCount: acc.noReceiptCount,
|
|
17145
|
+
noReceiptRate: rate(acc.noReceiptCount, legCount),
|
|
17146
|
+
wallClockMedianMs: medianNumber(acc.walls)
|
|
17147
|
+
};
|
|
17148
|
+
});
|
|
17149
|
+
const unreadable = sortUnreadable([...input.unreadable, ...modelAbsent]);
|
|
17150
|
+
return {
|
|
17151
|
+
kind: "analyst-model-groups",
|
|
17152
|
+
mode: "model-groups",
|
|
17153
|
+
projectRoots: [...input.projectRoots].sort((a, b) => a.localeCompare(b)),
|
|
17154
|
+
groups,
|
|
17155
|
+
legCount: groupedRuns.length,
|
|
17156
|
+
unreadableCount: unreadable.length,
|
|
17157
|
+
unreadable
|
|
17158
|
+
};
|
|
17159
|
+
}
|
|
17160
|
+
var init_analyst_model_groups = __esm({
|
|
17161
|
+
"src/analyst-model-groups.ts"() {
|
|
17162
|
+
"use strict";
|
|
17163
|
+
init_acceptance_success_rework();
|
|
17164
|
+
init_analyst_median();
|
|
17165
|
+
init_analyst_page();
|
|
17166
|
+
}
|
|
17167
|
+
});
|
|
17168
|
+
|
|
17191
17169
|
// src/analyst-entry.ts
|
|
17192
17170
|
import { readFile as readFile20 } from "node:fs/promises";
|
|
17193
17171
|
import { Type as Type12 } from "typebox";
|
|
@@ -17593,7 +17571,7 @@ __export(cli_exports, {
|
|
|
17593
17571
|
runAkRole: () => runAkRole
|
|
17594
17572
|
});
|
|
17595
17573
|
import { realpath as realpath5 } from "node:fs/promises";
|
|
17596
|
-
import { join as
|
|
17574
|
+
import { join as join38 } from "node:path";
|
|
17597
17575
|
function publicSeatArgv(owner) {
|
|
17598
17576
|
return {
|
|
17599
17577
|
parse: (args) => parsePublicSeatArgv(owner, args),
|
|
@@ -17732,7 +17710,7 @@ function resolveHome(env) {
|
|
|
17732
17710
|
return env.home ?? packageMachineHome();
|
|
17733
17711
|
}
|
|
17734
17712
|
function resolveAgentDir(env, home) {
|
|
17735
|
-
return env.agentDir ?? process.env.PI_CODING_AGENT_DIR ??
|
|
17713
|
+
return env.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? join38(home, ".pi", "agent");
|
|
17736
17714
|
}
|
|
17737
17715
|
function parseThinking(value) {
|
|
17738
17716
|
return value;
|
|
@@ -18504,7 +18482,7 @@ __export(public_role_summons_exports, {
|
|
|
18504
18482
|
import { execFile as execFile3 } from "node:child_process";
|
|
18505
18483
|
import { existsSync as existsSync10 } from "node:fs";
|
|
18506
18484
|
import { realpath as realpath6 } from "node:fs/promises";
|
|
18507
|
-
import { join as
|
|
18485
|
+
import { join as join39 } from "node:path";
|
|
18508
18486
|
import { promisify as promisify3 } from "node:util";
|
|
18509
18487
|
function createCapturingIo() {
|
|
18510
18488
|
const chunks = [];
|
|
@@ -18528,7 +18506,7 @@ function parentDir(path) {
|
|
|
18528
18506
|
function walkPackageRoot(start) {
|
|
18529
18507
|
let dir = start;
|
|
18530
18508
|
for (let i = 0; i < 12; i += 1) {
|
|
18531
|
-
if (existsSync10(
|
|
18509
|
+
if (existsSync10(join39(dir, "package.json")) && existsSync10(join39(dir, "souls"))) {
|
|
18532
18510
|
return dir;
|
|
18533
18511
|
}
|
|
18534
18512
|
const parent = parentDir(dir);
|
|
@@ -18578,8 +18556,8 @@ function projectSeatHost2(seat) {
|
|
|
18578
18556
|
function hostSelectionFailureFromUnknown(error) {
|
|
18579
18557
|
if (typeof error !== "object" || error === null) return void 0;
|
|
18580
18558
|
if (error.name !== "HostSelectionError") return void 0;
|
|
18581
|
-
const
|
|
18582
|
-
return
|
|
18559
|
+
const failure = error.failure;
|
|
18560
|
+
return failure;
|
|
18583
18561
|
}
|
|
18584
18562
|
async function createSummonEnv(options, afterHost) {
|
|
18585
18563
|
const [
|
|
@@ -18644,7 +18622,7 @@ async function createSummonEnv(options, afterHost) {
|
|
|
18644
18622
|
async function summonPublicRole(options) {
|
|
18645
18623
|
const packageRoot = resolveSummonsPackageRoot(options.packageRoot);
|
|
18646
18624
|
const home = await resolveSummonHome(options);
|
|
18647
|
-
const agentDir = options.agentDir ?? process.env.PI_CODING_AGENT_DIR ??
|
|
18625
|
+
const agentDir = options.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? join39(home, ".pi", "agent");
|
|
18648
18626
|
const {
|
|
18649
18627
|
loadCredentialProviders: loadCredentialProviders2,
|
|
18650
18628
|
loadPublicCliConfig: loadPublicCliConfig2,
|
|
@@ -18712,10 +18690,10 @@ async function summonPublicRole(options) {
|
|
|
18712
18690
|
}
|
|
18713
18691
|
};
|
|
18714
18692
|
} catch (error) {
|
|
18715
|
-
const
|
|
18716
|
-
if (
|
|
18693
|
+
const failure = hostSelectionFailureFromUnknown(error);
|
|
18694
|
+
if (failure !== void 0) {
|
|
18717
18695
|
const { formatHostSelectionFailure: formatHostSelectionFailure2 } = await Promise.resolve().then(() => (init_role_turn_host_resolution(), role_turn_host_resolution_exports));
|
|
18718
|
-
return { ok: false, exitCode: 1, stderr: formatHostSelectionFailure2(
|
|
18696
|
+
return { ok: false, exitCode: 1, stderr: formatHostSelectionFailure2(failure) };
|
|
18719
18697
|
}
|
|
18720
18698
|
const { CliUsageError: CliUsageError2 } = await Promise.resolve().then(() => (init_cli_errors(), cli_errors_exports));
|
|
18721
18699
|
if (error instanceof CliUsageError2) {
|
|
@@ -18811,8 +18789,8 @@ async function summonParallelReviewerLenses(options) {
|
|
|
18811
18789
|
stderr: describeFailure(error)
|
|
18812
18790
|
});
|
|
18813
18791
|
const dualFailure = (error) => {
|
|
18814
|
-
const
|
|
18815
|
-
return { completeness:
|
|
18792
|
+
const failure = failedResult(error);
|
|
18793
|
+
return { completeness: failure, correctness: failure };
|
|
18816
18794
|
};
|
|
18817
18795
|
let sourceProjectRoot;
|
|
18818
18796
|
let targetCommit;
|
|
@@ -19152,7 +19130,7 @@ var init_compliance_transport = __esm({
|
|
|
19152
19130
|
});
|
|
19153
19131
|
|
|
19154
19132
|
// src/role-run-relocation.ts
|
|
19155
|
-
import { join as
|
|
19133
|
+
import { join as join40, sep as sep5 } from "node:path";
|
|
19156
19134
|
function rewriteRunDirectoryPathValue(value, oldRunDirectory, newRunDirectory) {
|
|
19157
19135
|
if (typeof value !== "string") return value;
|
|
19158
19136
|
if (value === oldRunDirectory) return newRunDirectory;
|
|
@@ -19280,7 +19258,7 @@ __export(run_lifecycle_exports, {
|
|
|
19280
19258
|
writeRoleRunState: () => writeRoleRunState
|
|
19281
19259
|
});
|
|
19282
19260
|
import { chmod, lstat as lstat6, open as open3, readdir as readdir7, readFile as readFile22, unlink as unlink5, writeFile as writeFile9 } from "node:fs/promises";
|
|
19283
|
-
import { basename as basename10, join as
|
|
19261
|
+
import { basename as basename10, join as join41 } from "node:path";
|
|
19284
19262
|
function buildAutoResumeContinuationPrompt(options) {
|
|
19285
19263
|
return appendEngineSessionMaterial(
|
|
19286
19264
|
[RESUME_TRANSPORT_ENVELOPE],
|
|
@@ -19306,7 +19284,7 @@ function renderResumeCommand(runId) {
|
|
|
19306
19284
|
async function writeRoleRunState(runDirectory, record4) {
|
|
19307
19285
|
const payload = { ...record4, runDirectory };
|
|
19308
19286
|
await writeFile9(
|
|
19309
|
-
|
|
19287
|
+
join41(runDirectory, RUN_STATE_FILE),
|
|
19310
19288
|
`${JSON.stringify(payload, null, 2)}
|
|
19311
19289
|
`,
|
|
19312
19290
|
"utf8"
|
|
@@ -19356,7 +19334,7 @@ function parseCurrentCourtState(raw) {
|
|
|
19356
19334
|
async function readRoleRunStateRaw(runDirectory) {
|
|
19357
19335
|
let raw;
|
|
19358
19336
|
try {
|
|
19359
|
-
raw = JSON.parse(await readFile22(
|
|
19337
|
+
raw = JSON.parse(await readFile22(join41(runDirectory, RUN_STATE_FILE), "utf8"));
|
|
19360
19338
|
} catch (error) {
|
|
19361
19339
|
if (errorCodeOf(error) === "ENOENT") return void 0;
|
|
19362
19340
|
throw error;
|
|
@@ -19450,7 +19428,7 @@ async function writeRoleRunStateDisk(runDirectory, disk) {
|
|
|
19450
19428
|
...disk.currentCourt === void 0 ? {} : { currentCourt: disk.currentCourt }
|
|
19451
19429
|
};
|
|
19452
19430
|
await writeFile9(
|
|
19453
|
-
|
|
19431
|
+
join41(runDirectory, RUN_STATE_FILE),
|
|
19454
19432
|
`${JSON.stringify(payload, null, 2)}
|
|
19455
19433
|
`,
|
|
19456
19434
|
"utf8"
|
|
@@ -19673,7 +19651,7 @@ async function createWriterLease(lockPath, runDirectory, reportCleanupFailure) {
|
|
|
19673
19651
|
},
|
|
19674
19652
|
relocate(nextRunDirectory) {
|
|
19675
19653
|
currentRunDirectory = nextRunDirectory;
|
|
19676
|
-
currentLockPath =
|
|
19654
|
+
currentLockPath = join41(nextRunDirectory, WRITER_LOCK_FILE);
|
|
19677
19655
|
},
|
|
19678
19656
|
async release() {
|
|
19679
19657
|
if (released) return;
|
|
@@ -19712,10 +19690,10 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
|
|
|
19712
19690
|
};
|
|
19713
19691
|
const reportReadFailure = (error) => {
|
|
19714
19692
|
reportDiagnostic(
|
|
19715
|
-
`writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${
|
|
19693
|
+
`writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${join41(runDirectory, WRITER_LOCK_FILE)}: ${describeErrorIdentity(error)}`
|
|
19716
19694
|
);
|
|
19717
19695
|
};
|
|
19718
|
-
const lockPath =
|
|
19696
|
+
const lockPath = join41(runDirectory, WRITER_LOCK_FILE);
|
|
19719
19697
|
let lastAutopsy = { verdict: "absent" };
|
|
19720
19698
|
let lastReclaimFailure;
|
|
19721
19699
|
for (let reclaimsLeft = WRITER_LEASE_RECLAIM_ROUNDS; ; reclaimsLeft -= 1) {
|
|
@@ -19770,7 +19748,7 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
|
|
|
19770
19748
|
async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole) {
|
|
19771
19749
|
if (runId.trim() === "") return void 0;
|
|
19772
19750
|
const ledgerHome = resolveActivationLedgerHome(home);
|
|
19773
|
-
const booksRoot =
|
|
19751
|
+
const booksRoot = join41(ledgerHome, "books");
|
|
19774
19752
|
let bookKeys;
|
|
19775
19753
|
try {
|
|
19776
19754
|
bookKeys = await readdir7(booksRoot);
|
|
@@ -19811,7 +19789,7 @@ async function readRunParentPath(runDirectory) {
|
|
|
19811
19789
|
let raw;
|
|
19812
19790
|
try {
|
|
19813
19791
|
raw = JSON.parse(
|
|
19814
|
-
await readFile22(
|
|
19792
|
+
await readFile22(join41(runDirectory, "admitted-request.json"), "utf8")
|
|
19815
19793
|
);
|
|
19816
19794
|
} catch (error) {
|
|
19817
19795
|
if (errorCodeOf(error) === "ENOENT") return void 0;
|
|
@@ -19832,7 +19810,7 @@ async function readRunParentPath(runDirectory) {
|
|
|
19832
19810
|
async function runHasFormedSessionPrincipal(runDirectory) {
|
|
19833
19811
|
const disk = await readRoleRunStateDisk(runDirectory);
|
|
19834
19812
|
if (disk === void 0) return false;
|
|
19835
|
-
const sessionFile = typeof disk.principalWire.sessionFile === "string" && disk.principalWire.sessionFile.trim() !== "" ? disk.principalWire.sessionFile :
|
|
19813
|
+
const sessionFile = typeof disk.principalWire.sessionFile === "string" && disk.principalWire.sessionFile.trim() !== "" ? disk.principalWire.sessionFile : join41(disk.principalWire.sessionDirectory, "session.jsonl");
|
|
19836
19814
|
try {
|
|
19837
19815
|
const stat2 = await lstat6(sessionFile);
|
|
19838
19816
|
return stat2.isFile() && !stat2.isSymbolicLink();
|
|
@@ -19850,7 +19828,7 @@ async function findLatestRunIdForSeatTicket(input) {
|
|
|
19850
19828
|
let runDirectories;
|
|
19851
19829
|
try {
|
|
19852
19830
|
runDirectories = await listBookRunDirectories(
|
|
19853
|
-
input.ticketNumber === void 0 ? bookDir :
|
|
19831
|
+
input.ticketNumber === void 0 ? bookDir : join41(bookDir, String(input.ticketNumber))
|
|
19854
19832
|
);
|
|
19855
19833
|
} catch (error) {
|
|
19856
19834
|
if (errorCodeOf(error) === "ENOENT") return void 0;
|
|
@@ -20048,7 +20026,7 @@ async function loadResumableRunRecord(home, runId, authority) {
|
|
|
20048
20026
|
let model;
|
|
20049
20027
|
try {
|
|
20050
20028
|
const invocationRaw = JSON.parse(
|
|
20051
|
-
await readFile22(
|
|
20029
|
+
await readFile22(join41(run.runDirectory, "invocation.json"), "utf8")
|
|
20052
20030
|
);
|
|
20053
20031
|
if (invocationRaw !== null && typeof invocationRaw === "object" && !Array.isArray(invocationRaw)) {
|
|
20054
20032
|
const rec = invocationRaw;
|
|
@@ -20417,7 +20395,7 @@ var init_run_lifecycle = __esm({
|
|
|
20417
20395
|
|
|
20418
20396
|
// src/archivist-record-topology.ts
|
|
20419
20397
|
import { createHash as createHash4 } from "node:crypto";
|
|
20420
|
-
import { join as
|
|
20398
|
+
import { join as join42 } from "node:path";
|
|
20421
20399
|
function resolveNavigatorWorkSubjectPlacement(input) {
|
|
20422
20400
|
let ledgerHome;
|
|
20423
20401
|
if (input.parentSessionFile !== void 0 && input.parentSessionFile.length > 0) {
|
|
@@ -20430,7 +20408,7 @@ function resolveNavigatorWorkSubjectPlacement(input) {
|
|
|
20430
20408
|
const digest = createHash4("sha256").update(input.subject).digest("hex").slice(0, 32);
|
|
20431
20409
|
return {
|
|
20432
20410
|
ledgerHome,
|
|
20433
|
-
sessionDir:
|
|
20411
|
+
sessionDir: join42(
|
|
20434
20412
|
activationBookDirectory(ledgerHome, resolveBookKeyFromGit(input.cwd)),
|
|
20435
20413
|
NAVIGATOR_RECORD_KIND,
|
|
20436
20414
|
digest
|
|
@@ -20502,10 +20480,10 @@ import {
|
|
|
20502
20480
|
statSync as statSync6,
|
|
20503
20481
|
writeFileSync as writeFileSync2
|
|
20504
20482
|
} from "node:fs";
|
|
20505
|
-
import { dirname as dirname23, resolve as resolve16, join as
|
|
20483
|
+
import { dirname as dirname23, resolve as resolve16, join as join43 } from "node:path";
|
|
20506
20484
|
import { StringDecoder } from "node:string_decoder";
|
|
20507
20485
|
function readCurrentSession(sessionDir) {
|
|
20508
|
-
const ledger =
|
|
20486
|
+
const ledger = join43(sessionDir, CURRENT_SESSION_LEDGER);
|
|
20509
20487
|
try {
|
|
20510
20488
|
const value = JSON.parse(readFileSync4(ledger, "utf8"));
|
|
20511
20489
|
if (typeof value !== "object" || value === null || typeof value.sessionFile !== "string" || value.sessionFile.length === 0) {
|
|
@@ -20520,7 +20498,7 @@ function readCurrentSession(sessionDir) {
|
|
|
20520
20498
|
}
|
|
20521
20499
|
}
|
|
20522
20500
|
function writeCurrentSession(sessionDir, sessionFile) {
|
|
20523
|
-
const ledger =
|
|
20501
|
+
const ledger = join43(sessionDir, CURRENT_SESSION_LEDGER);
|
|
20524
20502
|
try {
|
|
20525
20503
|
writeFileSync2(ledger, `${JSON.stringify({ sessionFile })}
|
|
20526
20504
|
`, { flag: "wx" });
|
|
@@ -20536,7 +20514,7 @@ function isCurrentSessionClaimRace(error) {
|
|
|
20536
20514
|
return errnoCode(error.cause) === "EEXIST";
|
|
20537
20515
|
}
|
|
20538
20516
|
function currentSessionLedgerPath(sessionDir) {
|
|
20539
|
-
return
|
|
20517
|
+
return join43(sessionDir, CURRENT_SESSION_LEDGER);
|
|
20540
20518
|
}
|
|
20541
20519
|
function readBoundedSessionHeader(filePath) {
|
|
20542
20520
|
const fd = openSync2(filePath, "r");
|
|
@@ -20623,7 +20601,7 @@ function mostRecentNavigatorSessionFile(sessionDir, cwd) {
|
|
|
20623
20601
|
const matched = [];
|
|
20624
20602
|
for (const name of names) {
|
|
20625
20603
|
if (!name.endsWith(".jsonl")) continue;
|
|
20626
|
-
const filePath =
|
|
20604
|
+
const filePath = join43(absoluteSessionDir, name);
|
|
20627
20605
|
let st;
|
|
20628
20606
|
try {
|
|
20629
20607
|
st = statSync6(filePath);
|
|
@@ -20735,7 +20713,7 @@ function createRecordSessionOpen(options, host = piRecordSessionHost) {
|
|
|
20735
20713
|
if (!physicallyContainedIn(ledgerHome, parentResolved)) {
|
|
20736
20714
|
throw new Error("Durable record ownership requires a parent session inside the ledger home");
|
|
20737
20715
|
}
|
|
20738
|
-
sessionDir =
|
|
20716
|
+
sessionDir = join43(dirname23(parentResolved), options.kind);
|
|
20739
20717
|
parentSession = parentFile;
|
|
20740
20718
|
mayResumeSameNest = options.kind === WORKER_SUBMISSION_GATE_KIND;
|
|
20741
20719
|
}
|
|
@@ -20798,6 +20776,7 @@ var init_archivist_record_entry = __esm({
|
|
|
20798
20776
|
});
|
|
20799
20777
|
|
|
20800
20778
|
// src/headless-host/production-host.ts
|
|
20779
|
+
init_host_descriptions();
|
|
20801
20780
|
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
20802
20781
|
|
|
20803
20782
|
// src/role-runtime-dependencies.ts
|
|
@@ -21011,10 +20990,10 @@ init_packaged_role_registry();
|
|
|
21011
20990
|
init_atomic_write();
|
|
21012
20991
|
import { existsSync as existsSync3, realpathSync as realpathSync2 } from "node:fs";
|
|
21013
20992
|
import { readFile as readFile5 } from "node:fs/promises";
|
|
21014
|
-
import { basename as basename3, dirname as dirname7, join as
|
|
20993
|
+
import { basename as basename3, dirname as dirname7, join as join8, resolve as resolve5 } from "node:path";
|
|
21015
20994
|
var NAVIGATOR_WORK_CONTEXT_BASENAME = "work-context.json";
|
|
21016
20995
|
function navigatorWorkContextFile(sessionDir) {
|
|
21017
|
-
return
|
|
20996
|
+
return join8(sessionDir, NAVIGATOR_WORK_CONTEXT_BASENAME);
|
|
21018
20997
|
}
|
|
21019
20998
|
function isNavigatorWorkContextFile(path) {
|
|
21020
20999
|
const resolved = resolve5(path);
|
|
@@ -21431,12 +21410,12 @@ function createNavigatorAttendance(options) {
|
|
|
21431
21410
|
return { ...options.context, signal };
|
|
21432
21411
|
};
|
|
21433
21412
|
const unavailable = (invocationId, reason) => {
|
|
21434
|
-
const
|
|
21413
|
+
const failure = reason instanceof NavigatorUnavailableError ? reason : navigatorUnavailableError("unknown", reason);
|
|
21435
21414
|
return {
|
|
21436
21415
|
disposition: "unavailable",
|
|
21437
|
-
unavailableReason:
|
|
21438
|
-
unavailableSource:
|
|
21439
|
-
unavailableCause:
|
|
21416
|
+
unavailableReason: failure.message,
|
|
21417
|
+
unavailableSource: failure.unavailableSource,
|
|
21418
|
+
unavailableCause: failure.unavailableCause
|
|
21440
21419
|
};
|
|
21441
21420
|
};
|
|
21442
21421
|
let prepareBoundSettlement;
|
|
@@ -21873,7 +21852,7 @@ init_sitian_facade();
|
|
|
21873
21852
|
init_submission_ledger();
|
|
21874
21853
|
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
21875
21854
|
import { readFileSync as readFileSync6, writeSync as writeSync2 } from "node:fs";
|
|
21876
|
-
import { join as
|
|
21855
|
+
import { join as join45 } from "node:path";
|
|
21877
21856
|
import { Value as Value4 } from "typebox/value";
|
|
21878
21857
|
|
|
21879
21858
|
// src/activation-trace.ts
|
|
@@ -23829,7 +23808,7 @@ function readDiaristTicketAssertion(submitted) {
|
|
|
23829
23808
|
function readRoleRunCoordinates(ctx, label) {
|
|
23830
23809
|
const runDirectory = runDirectoryFromHostContext(ctx);
|
|
23831
23810
|
if (runDirectory === void 0) throw new Error(`${label} requires AK_ROLE_RUN_DIR`);
|
|
23832
|
-
const admittedPath =
|
|
23811
|
+
const admittedPath = join45(runDirectory, "admitted-request.json");
|
|
23833
23812
|
const admitted = JSON.parse(readFileSync6(admittedPath, "utf8"));
|
|
23834
23813
|
if (typeof admitted.projectRoot !== "string" || admitted.projectRoot.trim() === "") {
|
|
23835
23814
|
throw new Error(`${label} admitted-request missing projectRoot (${admittedPath})`);
|
|
@@ -24758,7 +24737,7 @@ init_packaged_role_registry();
|
|
|
24758
24737
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
24759
24738
|
import { appendFile as appendFile3, mkdir as mkdir5, writeFile as writeFile10 } from "node:fs/promises";
|
|
24760
24739
|
import { createServer } from "node:net";
|
|
24761
|
-
import { dirname as dirname25, join as
|
|
24740
|
+
import { dirname as dirname25, join as join46 } from "node:path";
|
|
24762
24741
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
24763
24742
|
init_role_activation_flags();
|
|
24764
24743
|
init_submission_correctable_error();
|
|
@@ -24804,7 +24783,7 @@ async function prepareRoleEnvelope(options) {
|
|
|
24804
24783
|
const hostAbort = new AbortController();
|
|
24805
24784
|
const runId = request.runDirectory.split("/").filter(Boolean).at(-1) ?? randomUUID9();
|
|
24806
24785
|
await mkdir5(request.runDirectory, { recursive: true });
|
|
24807
|
-
let sessionFile = options.sessionFile ??
|
|
24786
|
+
let sessionFile = options.sessionFile ?? join46(request.runDirectory, "session", "session.jsonl");
|
|
24808
24787
|
await mkdir5(dirname25(sessionFile), { recursive: true });
|
|
24809
24788
|
if (request.continuation.kind !== "resume") {
|
|
24810
24789
|
try {
|
|
@@ -25323,17 +25302,129 @@ async function prepareRoleEnvelope(options) {
|
|
|
25323
25302
|
// src/headless-host/production-host.ts
|
|
25324
25303
|
init_session_identity();
|
|
25325
25304
|
|
|
25305
|
+
// src/headless-host/role-turn-host.ts
|
|
25306
|
+
import { spawn as spawn3, spawnSync as spawnSync3 } from "node:child_process";
|
|
25307
|
+
import { randomUUID as randomUUID10 } from "node:crypto";
|
|
25308
|
+
import { existsSync as existsSync15 } from "node:fs";
|
|
25309
|
+
import { writeFile as writeFile11 } from "node:fs/promises";
|
|
25310
|
+
import { dirname as dirname26, isAbsolute as isAbsolute12, join as join47, resolve as resolve21 } from "node:path";
|
|
25311
|
+
|
|
25312
|
+
// src/external-host-turn-loop.ts
|
|
25313
|
+
var EXTERNAL_ROLE_TURN_ROUND_LIMIT = 8;
|
|
25314
|
+
function mergeRoleTurnAbortSignals(prepared, request) {
|
|
25315
|
+
if (request === void 0) return prepared;
|
|
25316
|
+
if (prepared === void 0) return request;
|
|
25317
|
+
return AbortSignal.any([prepared, request]);
|
|
25318
|
+
}
|
|
25319
|
+
function isHostAbortedError(error) {
|
|
25320
|
+
return typeof error === "object" && error !== null && error.code === "host-aborted";
|
|
25321
|
+
}
|
|
25322
|
+
function hostAbortedError(message = "host aborted") {
|
|
25323
|
+
return Object.assign(new Error(message), { code: "host-aborted" });
|
|
25324
|
+
}
|
|
25325
|
+
function externalHostFailure(cause, name, code, details, diagnostic) {
|
|
25326
|
+
return asFailure({
|
|
25327
|
+
cause,
|
|
25328
|
+
identity: { name, code },
|
|
25329
|
+
...diagnostic === void 0 ? {} : { diagnostic },
|
|
25330
|
+
...details === void 0 ? {} : { details }
|
|
25331
|
+
});
|
|
25332
|
+
}
|
|
25333
|
+
function withExternalHostCleanupFailure(outcome, cleanupError, name) {
|
|
25334
|
+
const message = cleanupError instanceof Error ? cleanupError.message : String(cleanupError);
|
|
25335
|
+
if (outcome.knownFailure === void 0) {
|
|
25336
|
+
return externalHostFailure("session", name, "dispose-failed", { cleanupError: message }, message);
|
|
25337
|
+
}
|
|
25338
|
+
return {
|
|
25339
|
+
...outcome,
|
|
25340
|
+
knownFailure: {
|
|
25341
|
+
...outcome.knownFailure,
|
|
25342
|
+
details: { ...outcome.knownFailure.details ?? {}, cleanupError: message }
|
|
25343
|
+
}
|
|
25344
|
+
};
|
|
25345
|
+
}
|
|
25346
|
+
function asFailure(knownFailure, stderr = "") {
|
|
25347
|
+
return { code: null, stderr, timedOut: false, knownFailure };
|
|
25348
|
+
}
|
|
25349
|
+
async function settleHostAborted(prepared, sessionId) {
|
|
25350
|
+
const closure = await prepared.closeRound();
|
|
25351
|
+
if ("failure" in closure) return asFailure(closure.failure);
|
|
25352
|
+
return asFailure({
|
|
25353
|
+
cause: "session",
|
|
25354
|
+
identity: { name: "HostAborted", code: "host-aborted" },
|
|
25355
|
+
...sessionId === void 0 ? {} : { details: { sessionId } }
|
|
25356
|
+
});
|
|
25357
|
+
}
|
|
25358
|
+
async function driveExternalRoleTurnRounds(prepared, request, driver) {
|
|
25359
|
+
let prompt = prepared.prompt;
|
|
25360
|
+
const abortSignal = mergeRoleTurnAbortSignals(prepared.abortSignal, request.signal);
|
|
25361
|
+
let stderr = "";
|
|
25362
|
+
for (let attempt = 0; attempt < EXTERNAL_ROLE_TURN_ROUND_LIMIT; attempt += 1) {
|
|
25363
|
+
if (abortSignal?.aborted) return settleHostAborted(prepared, driver.currentSessionId());
|
|
25364
|
+
let round;
|
|
25365
|
+
try {
|
|
25366
|
+
round = await driver.runRound({ prompt, abortSignal, attempt });
|
|
25367
|
+
} catch (error) {
|
|
25368
|
+
if (isHostAbortedError(error)) return settleHostAborted(prepared, driver.currentSessionId());
|
|
25369
|
+
throw error;
|
|
25370
|
+
}
|
|
25371
|
+
if (round.status === "terminal") {
|
|
25372
|
+
const result = round.result;
|
|
25373
|
+
const combined = `${stderr}${result.stderr}`;
|
|
25374
|
+
return combined === result.stderr ? result : { ...result, stderr: combined };
|
|
25375
|
+
}
|
|
25376
|
+
if (round.stderr !== void 0 && round.stderr.length > 0) stderr += round.stderr;
|
|
25377
|
+
const closure = await prepared.closeRound();
|
|
25378
|
+
if (closure.accepted) {
|
|
25379
|
+
await driver.afterAccepted?.();
|
|
25380
|
+
return { code: 0, stderr, timedOut: false };
|
|
25381
|
+
}
|
|
25382
|
+
if ("failure" in closure) return asFailure(closure.failure, stderr);
|
|
25383
|
+
prompt = closure.retry.message;
|
|
25384
|
+
driver.afterRetry?.();
|
|
25385
|
+
}
|
|
25386
|
+
return asFailure({
|
|
25387
|
+
cause: "output",
|
|
25388
|
+
identity: { name: driver.roundLimitName, code: "round-retry-limit" },
|
|
25389
|
+
...driver.currentSessionId() === void 0 ? {} : { details: { sessionId: driver.currentSessionId() } }
|
|
25390
|
+
});
|
|
25391
|
+
}
|
|
25392
|
+
function createSerializedRoleTurnHost(execute) {
|
|
25393
|
+
let serial = Promise.resolve();
|
|
25394
|
+
return {
|
|
25395
|
+
executeTurn(request) {
|
|
25396
|
+
const execution = serial.then(() => execute(request));
|
|
25397
|
+
serial = execution.then(() => void 0, () => void 0);
|
|
25398
|
+
return execution;
|
|
25399
|
+
}
|
|
25400
|
+
};
|
|
25401
|
+
}
|
|
25402
|
+
|
|
25403
|
+
// src/agent-start-materials.ts
|
|
25404
|
+
function renderAgentStartMaterials(body, materials) {
|
|
25405
|
+
if (materials.length === 0) return body;
|
|
25406
|
+
return [body, ...materials.map((material) => JSON.stringify(material))].join("\n\n");
|
|
25407
|
+
}
|
|
25408
|
+
|
|
25409
|
+
// src/prepared-role-turn.ts
|
|
25410
|
+
function renderSystemPromptOverride(authority) {
|
|
25411
|
+
return renderAgentStartMaterials(authority.body, authority.materials);
|
|
25412
|
+
}
|
|
25413
|
+
async function resolveBoundHostSessionId(request, identity) {
|
|
25414
|
+
const explicit = request.continuation.kind === "resume" ? request.continuation.hostSessionId : void 0;
|
|
25415
|
+
return explicit !== void 0 && explicit !== "" ? explicit : identity.load(request.principal);
|
|
25416
|
+
}
|
|
25417
|
+
|
|
25418
|
+
// src/headless-host/role-turn-host.ts
|
|
25419
|
+
init_host_session_record();
|
|
25420
|
+
|
|
25326
25421
|
// src/headless-host/description.ts
|
|
25327
|
-
import { join as join46 } from "node:path";
|
|
25328
25422
|
function isClaudePrintDescription(description) {
|
|
25329
25423
|
return description.protocol === "claude-print";
|
|
25330
25424
|
}
|
|
25331
25425
|
function isCodexExecDescription(description) {
|
|
25332
25426
|
return description.protocol === "codex-exec";
|
|
25333
25427
|
}
|
|
25334
|
-
function resolveHeadlessBinary(description, operatorHome) {
|
|
25335
|
-
return join46(operatorHome, ...description.binaryFromHome);
|
|
25336
|
-
}
|
|
25337
25428
|
function headlessTurnArgs(options) {
|
|
25338
25429
|
const { description } = options;
|
|
25339
25430
|
const args = [
|
|
@@ -25592,109 +25683,7 @@ function headlessMcpConfigDocument(mcpServers) {
|
|
|
25592
25683
|
}
|
|
25593
25684
|
|
|
25594
25685
|
// src/headless-host/role-turn-host.ts
|
|
25595
|
-
import { spawn as spawn3, spawnSync as spawnSync3 } from "node:child_process";
|
|
25596
|
-
import { randomUUID as randomUUID10 } from "node:crypto";
|
|
25597
|
-
import { existsSync as existsSync15 } from "node:fs";
|
|
25598
|
-
import { writeFile as writeFile11 } from "node:fs/promises";
|
|
25599
|
-
import { dirname as dirname26, isAbsolute as isAbsolute12, join as join47, resolve as resolve21 } from "node:path";
|
|
25600
|
-
|
|
25601
|
-
// src/external-host-turn-loop.ts
|
|
25602
|
-
var EXTERNAL_ROLE_TURN_ROUND_LIMIT = 8;
|
|
25603
|
-
function mergeRoleTurnAbortSignals(prepared, request) {
|
|
25604
|
-
if (request === void 0) return prepared;
|
|
25605
|
-
if (prepared === void 0) return request;
|
|
25606
|
-
return AbortSignal.any([prepared, request]);
|
|
25607
|
-
}
|
|
25608
|
-
function isHostAbortedError(error) {
|
|
25609
|
-
return typeof error === "object" && error !== null && error.code === "host-aborted";
|
|
25610
|
-
}
|
|
25611
|
-
function hostAbortedError(message = "host aborted") {
|
|
25612
|
-
return Object.assign(new Error(message), { code: "host-aborted" });
|
|
25613
|
-
}
|
|
25614
|
-
function asFailure(knownFailure, stderr = "") {
|
|
25615
|
-
return { code: null, stderr, timedOut: false, knownFailure };
|
|
25616
|
-
}
|
|
25617
|
-
async function settleHostAborted(prepared, sessionId) {
|
|
25618
|
-
const closure = await prepared.closeRound();
|
|
25619
|
-
if ("failure" in closure) return asFailure(closure.failure);
|
|
25620
|
-
return asFailure({
|
|
25621
|
-
cause: "session",
|
|
25622
|
-
identity: { name: "HostAborted", code: "host-aborted" },
|
|
25623
|
-
...sessionId === void 0 ? {} : { details: { sessionId } }
|
|
25624
|
-
});
|
|
25625
|
-
}
|
|
25626
|
-
async function driveExternalRoleTurnRounds(prepared, request, driver) {
|
|
25627
|
-
let prompt = prepared.prompt;
|
|
25628
|
-
const abortSignal = mergeRoleTurnAbortSignals(prepared.abortSignal, request.signal);
|
|
25629
|
-
let stderr = "";
|
|
25630
|
-
for (let attempt = 0; attempt < EXTERNAL_ROLE_TURN_ROUND_LIMIT; attempt += 1) {
|
|
25631
|
-
if (abortSignal?.aborted) return settleHostAborted(prepared, driver.currentSessionId());
|
|
25632
|
-
let round;
|
|
25633
|
-
try {
|
|
25634
|
-
round = await driver.runRound({ prompt, abortSignal, attempt });
|
|
25635
|
-
} catch (error) {
|
|
25636
|
-
if (isHostAbortedError(error)) return settleHostAborted(prepared, driver.currentSessionId());
|
|
25637
|
-
throw error;
|
|
25638
|
-
}
|
|
25639
|
-
if (round.status === "terminal") {
|
|
25640
|
-
const result = round.result;
|
|
25641
|
-
const combined = `${stderr}${result.stderr}`;
|
|
25642
|
-
return combined === result.stderr ? result : { ...result, stderr: combined };
|
|
25643
|
-
}
|
|
25644
|
-
if (round.stderr !== void 0 && round.stderr.length > 0) stderr += round.stderr;
|
|
25645
|
-
const closure = await prepared.closeRound();
|
|
25646
|
-
if (closure.accepted) {
|
|
25647
|
-
await driver.afterAccepted?.();
|
|
25648
|
-
return { code: 0, stderr, timedOut: false };
|
|
25649
|
-
}
|
|
25650
|
-
if ("failure" in closure) return asFailure(closure.failure, stderr);
|
|
25651
|
-
prompt = closure.retry.message;
|
|
25652
|
-
driver.afterRetry?.();
|
|
25653
|
-
}
|
|
25654
|
-
return asFailure({
|
|
25655
|
-
cause: "output",
|
|
25656
|
-
identity: { name: driver.roundLimitName, code: "round-retry-limit" },
|
|
25657
|
-
...driver.currentSessionId() === void 0 ? {} : { details: { sessionId: driver.currentSessionId() } }
|
|
25658
|
-
});
|
|
25659
|
-
}
|
|
25660
|
-
function createSerializedRoleTurnHost(execute) {
|
|
25661
|
-
let serial = Promise.resolve();
|
|
25662
|
-
return {
|
|
25663
|
-
executeTurn(request) {
|
|
25664
|
-
const execution = serial.then(() => execute(request));
|
|
25665
|
-
serial = execution.then(() => void 0, () => void 0);
|
|
25666
|
-
return execution;
|
|
25667
|
-
}
|
|
25668
|
-
};
|
|
25669
|
-
}
|
|
25670
|
-
|
|
25671
|
-
// src/agent-start-materials.ts
|
|
25672
|
-
function renderAgentStartMaterials(body, materials) {
|
|
25673
|
-
if (materials.length === 0) return body;
|
|
25674
|
-
return [body, ...materials.map((material) => JSON.stringify(material))].join("\n\n");
|
|
25675
|
-
}
|
|
25676
|
-
|
|
25677
|
-
// src/prepared-role-turn.ts
|
|
25678
|
-
function renderSystemPromptOverride(authority) {
|
|
25679
|
-
return renderAgentStartMaterials(authority.body, authority.materials);
|
|
25680
|
-
}
|
|
25681
|
-
|
|
25682
|
-
// src/headless-host/role-turn-host.ts
|
|
25683
|
-
init_host_session_record();
|
|
25684
25686
|
init_navigator_output();
|
|
25685
|
-
function failure(cause, name, code, details, diagnostic) {
|
|
25686
|
-
return {
|
|
25687
|
-
code: null,
|
|
25688
|
-
stderr: "",
|
|
25689
|
-
timedOut: false,
|
|
25690
|
-
knownFailure: {
|
|
25691
|
-
cause,
|
|
25692
|
-
identity: { name, code },
|
|
25693
|
-
...diagnostic === void 0 ? {} : { diagnostic },
|
|
25694
|
-
...details === void 0 ? {} : { details }
|
|
25695
|
-
}
|
|
25696
|
-
};
|
|
25697
|
-
}
|
|
25698
25687
|
function isHeadlessResultCandidate(value) {
|
|
25699
25688
|
if (!isPlainObject2(value)) return false;
|
|
25700
25689
|
const record4 = value;
|
|
@@ -25704,25 +25693,11 @@ function parseHeadlessCliStdout(stdout) {
|
|
|
25704
25693
|
const trimmed = stdout.trim();
|
|
25705
25694
|
if (trimmed === "") return void 0;
|
|
25706
25695
|
try {
|
|
25707
|
-
const
|
|
25708
|
-
|
|
25696
|
+
const value = JSON.parse(trimmed);
|
|
25697
|
+
return isHeadlessResultCandidate(value) ? value : void 0;
|
|
25709
25698
|
} catch {
|
|
25699
|
+
return void 0;
|
|
25710
25700
|
}
|
|
25711
|
-
let last;
|
|
25712
|
-
for (const line2 of trimmed.split("\n")) {
|
|
25713
|
-
const text = line2.trim();
|
|
25714
|
-
if (text === "") continue;
|
|
25715
|
-
try {
|
|
25716
|
-
const value = JSON.parse(text);
|
|
25717
|
-
if (!isPlainObject2(value)) continue;
|
|
25718
|
-
const record4 = value;
|
|
25719
|
-
if (record4.type === "result" || record4.structured_output !== void 0) {
|
|
25720
|
-
last = record4;
|
|
25721
|
-
}
|
|
25722
|
-
} catch {
|
|
25723
|
-
}
|
|
25724
|
-
}
|
|
25725
|
-
return last;
|
|
25726
25701
|
}
|
|
25727
25702
|
function resultCandidateText(line2) {
|
|
25728
25703
|
const text = line2.trim();
|
|
@@ -25929,19 +25904,6 @@ function spawnHeadlessTurn(options) {
|
|
|
25929
25904
|
}
|
|
25930
25905
|
});
|
|
25931
25906
|
}
|
|
25932
|
-
function withCleanupFailure(outcome, cleanupError) {
|
|
25933
|
-
const message = cleanupError instanceof Error ? cleanupError.message : String(cleanupError);
|
|
25934
|
-
if (outcome.knownFailure === void 0) {
|
|
25935
|
-
return failure("session", "HeadlessDisposeFailure", "dispose-failed", { cleanupError: message }, message);
|
|
25936
|
-
}
|
|
25937
|
-
return {
|
|
25938
|
-
...outcome,
|
|
25939
|
-
knownFailure: {
|
|
25940
|
-
...outcome.knownFailure,
|
|
25941
|
-
details: { ...outcome.knownFailure.details ?? {}, cleanupError: message }
|
|
25942
|
-
}
|
|
25943
|
-
};
|
|
25944
|
-
}
|
|
25945
25907
|
function terminalFromSpawned(spawned, knownFailure) {
|
|
25946
25908
|
return {
|
|
25947
25909
|
status: "terminal",
|
|
@@ -25988,12 +25950,11 @@ function createHeadlessRoleTurnHost(config) {
|
|
|
25988
25950
|
const prepared = await config.prepare(request);
|
|
25989
25951
|
const systemPrompt = renderSystemPromptOverride(prepared.systemPrompt);
|
|
25990
25952
|
const codex = isCodexExecDescription(config.description);
|
|
25991
|
-
let outcome =
|
|
25953
|
+
let outcome = externalHostFailure("session", "HeadlessNoOutcome", "no-outcome");
|
|
25992
25954
|
try {
|
|
25993
|
-
|
|
25994
|
-
let sessionId = explicitHostSessionId !== void 0 && explicitHostSessionId !== "" ? explicitHostSessionId : await config.sessionIdentity.load(request.principal);
|
|
25955
|
+
let sessionId = await resolveBoundHostSessionId(request, config.sessionIdentity);
|
|
25995
25956
|
if (request.continuation.kind === "resume" && (sessionId === void 0 || sessionId === "")) {
|
|
25996
|
-
outcome =
|
|
25957
|
+
outcome = externalHostFailure(
|
|
25997
25958
|
"session",
|
|
25998
25959
|
"HeadlessSessionFailure",
|
|
25999
25960
|
"session-id-missing",
|
|
@@ -26062,7 +26023,7 @@ function createHeadlessRoleTurnHost(config) {
|
|
|
26062
26023
|
const message = error instanceof Error ? error.message : String(error);
|
|
26063
26024
|
return {
|
|
26064
26025
|
status: "terminal",
|
|
26065
|
-
result:
|
|
26026
|
+
result: externalHostFailure("session", "HeadlessArgvFailure", "argv-failed", { diagnostic: message }, message)
|
|
26066
26027
|
};
|
|
26067
26028
|
}
|
|
26068
26029
|
const codexObserver = codex ? createCodexExecTurnObserver() : void 0;
|
|
@@ -26133,7 +26094,7 @@ function createHeadlessRoleTurnHost(config) {
|
|
|
26133
26094
|
if (observedHostFailure !== void 0) {
|
|
26134
26095
|
return {
|
|
26135
26096
|
status: "terminal",
|
|
26136
|
-
result:
|
|
26097
|
+
result: externalHostFailure("output", "HeadlessCliError", "codex-turn-failed", {
|
|
26137
26098
|
diagnostic: observedHostFailure,
|
|
26138
26099
|
sessionRecordDiagnostic: message,
|
|
26139
26100
|
sessionId
|
|
@@ -26142,7 +26103,7 @@ function createHeadlessRoleTurnHost(config) {
|
|
|
26142
26103
|
}
|
|
26143
26104
|
return {
|
|
26144
26105
|
status: "terminal",
|
|
26145
|
-
result:
|
|
26106
|
+
result: externalHostFailure("activation", "HeadlessSpawnFailure", "spawn-failed", {
|
|
26146
26107
|
diagnostic: message,
|
|
26147
26108
|
binary: config.binary
|
|
26148
26109
|
}, message)
|
|
@@ -26298,7 +26259,7 @@ function createHeadlessRoleTurnHost(config) {
|
|
|
26298
26259
|
try {
|
|
26299
26260
|
await prepared.dispose?.();
|
|
26300
26261
|
} catch (cleanupError) {
|
|
26301
|
-
outcome =
|
|
26262
|
+
outcome = withExternalHostCleanupFailure(outcome, cleanupError, "HeadlessDisposeFailure");
|
|
26302
26263
|
}
|
|
26303
26264
|
}
|
|
26304
26265
|
return outcome;
|
|
@@ -26317,7 +26278,7 @@ function createProductionHeadlessRoleTurnHost(options) {
|
|
|
26317
26278
|
description,
|
|
26318
26279
|
hostName,
|
|
26319
26280
|
sessionIdentity,
|
|
26320
|
-
binary:
|
|
26281
|
+
binary: resolveHostBinary(description, operatorHome),
|
|
26321
26282
|
env: {
|
|
26322
26283
|
...process.env,
|
|
26323
26284
|
AK_PACKAGE_ROOT: packageRoot
|