@akagilnc/pi-workflow-roles 0.1.4929 → 0.1.4949
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acp-host/production-host.js +9180 -9080
- package/dist/headless-host/production-host.js +9178 -9078
- package/dist/migrate-book-topology.js +74 -27
- package/dist/public-cli/countersign-run.js +4 -0
- package/dist/public-cli/instruction-seat-run.js +18 -2
- package/dist/public-cli/invocation.js +40 -3
- package/dist/public-cli/main.js +567 -467
- package/dist/sitian-appender.js +38 -1
- package/dist/ticket-provenance-contracts.js +1 -1
- package/dist/ticket-provenance.js +28 -10
- package/package.json +1 -1
- package/souls/coder-output-guide.md +1 -0
- package/souls/fixer-output-guide.md +1 -0
- package/souls/quality-law.md +2 -0
- package/src/book-topology-record-class-migrators.ts +1 -1
- package/src/diarist-contracts.ts +1 -1
- package/src/diarist.ts +4 -2
- package/src/public-cli/countersign-run.ts +5 -0
- package/src/public-cli/instruction-seat-run.ts +16 -1
- package/src/public-cli/invocation.ts +44 -3
- package/src/role-runtime.ts +23 -22
- package/src/sitian-appender.ts +39 -1
- package/src/sitian-contracts.ts +2 -0
- package/src/ticket-provenance-contracts.ts +2 -2
- package/src/ticket-provenance.ts +36 -10
package/dist/public-cli/main.js
CHANGED
|
@@ -840,7 +840,7 @@ async function listPullRequestNumbersByCommit(runner, input) {
|
|
|
840
840
|
function createGhApiRunner(options = {}) {
|
|
841
841
|
const spawnImpl = options.spawnImpl ?? spawn;
|
|
842
842
|
return async (args, runOptions = {}) => {
|
|
843
|
-
return await new Promise((
|
|
843
|
+
return await new Promise((resolve12, reject) => {
|
|
844
844
|
const signal = runOptions.signal;
|
|
845
845
|
if (signal?.aborted) {
|
|
846
846
|
reject(signal.reason ?? new Error("aborted"));
|
|
@@ -913,11 +913,11 @@ function createGhApiRunner(options = {}) {
|
|
|
913
913
|
const value = line2.slice(idx + 1).trim();
|
|
914
914
|
headers[name] = value;
|
|
915
915
|
}
|
|
916
|
-
|
|
916
|
+
resolve12({ status, headers, bodyText });
|
|
917
917
|
return;
|
|
918
918
|
}
|
|
919
919
|
if (code === 0) {
|
|
920
|
-
|
|
920
|
+
resolve12({ status: 200, headers: {}, bodyText: stdout });
|
|
921
921
|
return;
|
|
922
922
|
}
|
|
923
923
|
const failure = new Error(
|
|
@@ -17082,6 +17082,36 @@ function sealTornTail(recordFile) {
|
|
|
17082
17082
|
appendFileSync(recordFile, "\n", "utf8");
|
|
17083
17083
|
}
|
|
17084
17084
|
}
|
|
17085
|
+
function appendSitianRecordBlock(input, block) {
|
|
17086
|
+
if (block === "") return;
|
|
17087
|
+
try {
|
|
17088
|
+
const { sessionDir, recordFile, ledgerHome } = resolveSitianRecordPath(input);
|
|
17089
|
+
ensureRealDirectoryTree(ledgerHome, sessionDir);
|
|
17090
|
+
appendFileSync(recordFile, "", "utf8");
|
|
17091
|
+
sealTornTail(recordFile);
|
|
17092
|
+
const identityOf = (line2) => {
|
|
17093
|
+
try {
|
|
17094
|
+
const row = JSON.parse(line2);
|
|
17095
|
+
return isRecord2(row) && typeof row.identity === "string" ? row.identity : void 0;
|
|
17096
|
+
} catch {
|
|
17097
|
+
return void 0;
|
|
17098
|
+
}
|
|
17099
|
+
};
|
|
17100
|
+
const identities = new Set(readFileSync2(recordFile, "utf8").split("\n").map(identityOf).filter((id) => id !== void 0));
|
|
17101
|
+
for (const line2 of block.match(/[^\n]*\n|[^\n]+$/g) ?? []) {
|
|
17102
|
+
const identity = identityOf(line2);
|
|
17103
|
+
if (identity !== void 0 && identities.has(identity)) continue;
|
|
17104
|
+
appendFileSync(recordFile, line2, "utf8");
|
|
17105
|
+
if (identity !== void 0) identities.add(identity);
|
|
17106
|
+
}
|
|
17107
|
+
} catch (error) {
|
|
17108
|
+
if (error instanceof SitianInfrastructureError) throw error;
|
|
17109
|
+
throw new SitianInfrastructureError(
|
|
17110
|
+
`Sitian appender persistence failure: ${errorText(error)}`,
|
|
17111
|
+
{ cause: error }
|
|
17112
|
+
);
|
|
17113
|
+
}
|
|
17114
|
+
}
|
|
17085
17115
|
function findIdentityPointer(recordFile, identity, kind, level) {
|
|
17086
17116
|
if (!existsSync3(recordFile)) return void 0;
|
|
17087
17117
|
const text = readFileSync2(recordFile, "utf8");
|
|
@@ -17205,6 +17235,9 @@ function resolveSitianRecordPathInLedger(input, ledgerHome) {
|
|
|
17205
17235
|
);
|
|
17206
17236
|
sessionDir = paths.sessionDir;
|
|
17207
17237
|
recordFile = paths.recordFile;
|
|
17238
|
+
} else if (category === "ticket-provenance" && input.runDirectory !== void 0) {
|
|
17239
|
+
sessionDir = input.runDirectory;
|
|
17240
|
+
recordFile = join9(sessionDir, SITIAN_RECORDS_LEAF);
|
|
17208
17241
|
} else {
|
|
17209
17242
|
if (input.sessionParent === void 0 || input.sessionParent.length === 0 || !physicallyContainedIn(ledgerHome, input.sessionParent)) {
|
|
17210
17243
|
throw new Error("Sitian record ownership requires a parent session inside the ledger home");
|
|
@@ -17212,6 +17245,9 @@ function resolveSitianRecordPathInLedger(input, ledgerHome) {
|
|
|
17212
17245
|
sessionDir = join9(dirname5(input.sessionParent), category);
|
|
17213
17246
|
recordFile = join9(sessionDir, SITIAN_RECORDS_LEAF);
|
|
17214
17247
|
}
|
|
17248
|
+
if (!physicallyContainedIn(ledgerHome, sessionDir)) {
|
|
17249
|
+
throw new Error("Sitian record ownership requires a directory inside the ledger home");
|
|
17250
|
+
}
|
|
17215
17251
|
return { sessionDir, recordFile, ledgerHome };
|
|
17216
17252
|
}
|
|
17217
17253
|
function projectTicketRecordsPathShape() {
|
|
@@ -17223,7 +17259,7 @@ function projectTicketRecordsPathShape() {
|
|
|
17223
17259
|
return recordFile.replace(/\\/g, "/");
|
|
17224
17260
|
}
|
|
17225
17261
|
function resolveSitianRecordPath(input) {
|
|
17226
|
-
const ledgerHome = input.home !== void 0 && input.home.length > 0 ? resolveActivationLedgerHome(input.home) : resolveActivationLedgerHomeForPath(input.sessionParent);
|
|
17262
|
+
const ledgerHome = input.home !== void 0 && input.home.length > 0 ? resolveActivationLedgerHome(input.home) : resolveActivationLedgerHomeForPath(input.runDirectory ?? input.sessionParent);
|
|
17227
17263
|
return resolveSitianRecordPathInLedger(input, ledgerHome);
|
|
17228
17264
|
}
|
|
17229
17265
|
function appendSitianRecord(input) {
|
|
@@ -18590,6 +18626,261 @@ var init_merger_git_state = __esm({
|
|
|
18590
18626
|
}
|
|
18591
18627
|
});
|
|
18592
18628
|
|
|
18629
|
+
// src/ledger-session-read.ts
|
|
18630
|
+
import { readFile as readFile9 } from "node:fs/promises";
|
|
18631
|
+
function isRecord5(value) {
|
|
18632
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18633
|
+
}
|
|
18634
|
+
async function readLedgerSessionJsonlLines(path) {
|
|
18635
|
+
const text = await readFile9(path, "utf8");
|
|
18636
|
+
const lines = text.split("\n");
|
|
18637
|
+
const out = [];
|
|
18638
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
18639
|
+
const raw = lines[index];
|
|
18640
|
+
if (!raw.trim()) continue;
|
|
18641
|
+
const lineNumber = index + 1;
|
|
18642
|
+
let row;
|
|
18643
|
+
try {
|
|
18644
|
+
row = JSON.parse(raw);
|
|
18645
|
+
} catch (error) {
|
|
18646
|
+
if (!(error instanceof SyntaxError)) throw error;
|
|
18647
|
+
const completedByTerminator = index < lines.length - 1;
|
|
18648
|
+
if (!completedByTerminator) break;
|
|
18649
|
+
out.push({
|
|
18650
|
+
line: lineNumber,
|
|
18651
|
+
raw,
|
|
18652
|
+
error: `malformed JSONL record in ${path} at line ${lineNumber}: ${error.message}`
|
|
18653
|
+
});
|
|
18654
|
+
continue;
|
|
18655
|
+
}
|
|
18656
|
+
if (!isRecord5(row)) {
|
|
18657
|
+
const kind = row === null ? "null" : Array.isArray(row) ? "array" : typeof row;
|
|
18658
|
+
out.push({
|
|
18659
|
+
line: lineNumber,
|
|
18660
|
+
raw,
|
|
18661
|
+
error: `complete non-object JSONL record in ${path} at line ${lineNumber}: expected object, got ${kind}`
|
|
18662
|
+
});
|
|
18663
|
+
continue;
|
|
18664
|
+
}
|
|
18665
|
+
out.push({ line: lineNumber, raw, row });
|
|
18666
|
+
}
|
|
18667
|
+
return out;
|
|
18668
|
+
}
|
|
18669
|
+
async function readLedgerSessionJsonl(path) {
|
|
18670
|
+
const rows = [];
|
|
18671
|
+
for (const line2 of await readLedgerSessionJsonlLines(path)) {
|
|
18672
|
+
if (line2.row === void 0) {
|
|
18673
|
+
throw new LedgerSessionJsonlError(line2.error ?? `unreadable JSONL record in ${path} at line ${line2.line}`, {
|
|
18674
|
+
path,
|
|
18675
|
+
line: line2.line,
|
|
18676
|
+
prefixRows: rows
|
|
18677
|
+
});
|
|
18678
|
+
}
|
|
18679
|
+
rows.push(line2.row);
|
|
18680
|
+
}
|
|
18681
|
+
return rows;
|
|
18682
|
+
}
|
|
18683
|
+
function extractSessionTimestampSpan(rows) {
|
|
18684
|
+
let startedAt;
|
|
18685
|
+
let endedAt;
|
|
18686
|
+
for (const row of rows) {
|
|
18687
|
+
if (typeof row.timestamp !== "string" || !row.timestamp) continue;
|
|
18688
|
+
if (startedAt === void 0) startedAt = row.timestamp;
|
|
18689
|
+
endedAt = row.timestamp;
|
|
18690
|
+
}
|
|
18691
|
+
return {
|
|
18692
|
+
...startedAt !== void 0 ? { startedAt } : {},
|
|
18693
|
+
...endedAt !== void 0 ? { endedAt } : {}
|
|
18694
|
+
};
|
|
18695
|
+
}
|
|
18696
|
+
function extractSessionModelSequence(rows) {
|
|
18697
|
+
const seen = /* @__PURE__ */ new Set();
|
|
18698
|
+
const ordered = [];
|
|
18699
|
+
const push = (raw) => {
|
|
18700
|
+
const model = raw.trim();
|
|
18701
|
+
if (model === "" || seen.has(model)) return;
|
|
18702
|
+
seen.add(model);
|
|
18703
|
+
ordered.push(model);
|
|
18704
|
+
};
|
|
18705
|
+
for (const row of rows) {
|
|
18706
|
+
if (row.type === "model_change" && typeof row.modelId === "string") {
|
|
18707
|
+
push(row.modelId);
|
|
18708
|
+
}
|
|
18709
|
+
const message = isRecord5(row.message) ? row.message : void 0;
|
|
18710
|
+
if (message?.role === "assistant" && typeof message.model === "string") {
|
|
18711
|
+
push(message.model);
|
|
18712
|
+
}
|
|
18713
|
+
}
|
|
18714
|
+
return ordered;
|
|
18715
|
+
}
|
|
18716
|
+
function bashCommandFirstLine(command) {
|
|
18717
|
+
const match = /^[^\r\n]*/.exec(command);
|
|
18718
|
+
return match?.[0] ?? "";
|
|
18719
|
+
}
|
|
18720
|
+
function extractSessionToolIntervals(rows) {
|
|
18721
|
+
const order = [];
|
|
18722
|
+
const openById = /* @__PURE__ */ new Map();
|
|
18723
|
+
for (const row of rows) {
|
|
18724
|
+
const rowTimestamp = typeof row.timestamp === "string" ? row.timestamp : void 0;
|
|
18725
|
+
const message = isRecord5(row.message) ? row.message : void 0;
|
|
18726
|
+
if (message?.role === "assistant" && Array.isArray(message.content)) {
|
|
18727
|
+
const callTimestamp = typeof message.timestamp === "string" && message.timestamp ? message.timestamp : rowTimestamp;
|
|
18728
|
+
for (const part of message.content) {
|
|
18729
|
+
if (!isRecord5(part) || part.type !== "toolCall") continue;
|
|
18730
|
+
if (typeof part.id !== "string" || part.id.length === 0) {
|
|
18731
|
+
throw new Error("toolCall frame missing string id");
|
|
18732
|
+
}
|
|
18733
|
+
if (typeof part.name !== "string" || part.name.length === 0) {
|
|
18734
|
+
throw new Error(`toolCall ${part.id} missing string name`);
|
|
18735
|
+
}
|
|
18736
|
+
if (callTimestamp === void 0 || callTimestamp.length === 0) {
|
|
18737
|
+
throw new Error(`toolCall ${part.id} missing timestamp`);
|
|
18738
|
+
}
|
|
18739
|
+
if (openById.has(part.id)) {
|
|
18740
|
+
throw new Error(`duplicate toolCall id ${part.id}`);
|
|
18741
|
+
}
|
|
18742
|
+
const args = isRecord5(part.arguments) ? part.arguments : void 0;
|
|
18743
|
+
const command = part.name === "bash" && args !== void 0 && typeof args.command === "string" ? bashCommandFirstLine(args.command) : void 0;
|
|
18744
|
+
const interval = {
|
|
18745
|
+
toolCallId: part.id,
|
|
18746
|
+
toolName: part.name,
|
|
18747
|
+
startedAt: callTimestamp,
|
|
18748
|
+
...command !== void 0 ? { command } : {}
|
|
18749
|
+
};
|
|
18750
|
+
order.push(interval);
|
|
18751
|
+
openById.set(part.id, interval);
|
|
18752
|
+
}
|
|
18753
|
+
}
|
|
18754
|
+
if (message?.role === "toolResult") {
|
|
18755
|
+
if (typeof message.toolCallId !== "string" || message.toolCallId.length === 0) {
|
|
18756
|
+
throw new Error("toolResult frame missing string toolCallId");
|
|
18757
|
+
}
|
|
18758
|
+
const resultTimestamp = typeof message.timestamp === "string" && message.timestamp ? message.timestamp : rowTimestamp;
|
|
18759
|
+
if (resultTimestamp === void 0 || resultTimestamp.length === 0) {
|
|
18760
|
+
throw new Error(`toolResult ${message.toolCallId} missing timestamp`);
|
|
18761
|
+
}
|
|
18762
|
+
const open4 = openById.get(message.toolCallId);
|
|
18763
|
+
if (open4 === void 0) {
|
|
18764
|
+
const toolName = typeof message.toolName === "string" && message.toolName.length > 0 ? message.toolName : "unknown";
|
|
18765
|
+
order.push({
|
|
18766
|
+
toolCallId: message.toolCallId,
|
|
18767
|
+
toolName,
|
|
18768
|
+
startedAt: resultTimestamp,
|
|
18769
|
+
endedAt: resultTimestamp
|
|
18770
|
+
});
|
|
18771
|
+
continue;
|
|
18772
|
+
}
|
|
18773
|
+
if (open4.endedAt !== void 0) {
|
|
18774
|
+
throw new Error(`duplicate toolResult for toolCallId ${message.toolCallId}`);
|
|
18775
|
+
}
|
|
18776
|
+
open4.endedAt = resultTimestamp;
|
|
18777
|
+
}
|
|
18778
|
+
}
|
|
18779
|
+
return order.map((interval) => {
|
|
18780
|
+
const base = {
|
|
18781
|
+
toolCallId: interval.toolCallId,
|
|
18782
|
+
toolName: interval.toolName,
|
|
18783
|
+
startedAt: interval.startedAt,
|
|
18784
|
+
...interval.command !== void 0 ? { command: interval.command } : {}
|
|
18785
|
+
};
|
|
18786
|
+
return interval.endedAt === void 0 ? base : { ...base, endedAt: interval.endedAt };
|
|
18787
|
+
});
|
|
18788
|
+
}
|
|
18789
|
+
function intervalRowsAroundAnchor(rows, anchorIndex, isBindingRow) {
|
|
18790
|
+
let start = 0;
|
|
18791
|
+
for (let i = anchorIndex; i >= 0; i -= 1) {
|
|
18792
|
+
if (isBindingRow(rows[i])) {
|
|
18793
|
+
start = i;
|
|
18794
|
+
break;
|
|
18795
|
+
}
|
|
18796
|
+
}
|
|
18797
|
+
let end = rows.length;
|
|
18798
|
+
for (let i = Math.max(anchorIndex, start) + 1; i < rows.length; i += 1) {
|
|
18799
|
+
if (isBindingRow(rows[i])) {
|
|
18800
|
+
end = i;
|
|
18801
|
+
break;
|
|
18802
|
+
}
|
|
18803
|
+
}
|
|
18804
|
+
return { rows: rows.slice(start, end), closed: end < rows.length };
|
|
18805
|
+
}
|
|
18806
|
+
var LedgerSessionJsonlError;
|
|
18807
|
+
var init_ledger_session_read = __esm({
|
|
18808
|
+
"src/ledger-session-read.ts"() {
|
|
18809
|
+
"use strict";
|
|
18810
|
+
LedgerSessionJsonlError = class extends Error {
|
|
18811
|
+
path;
|
|
18812
|
+
line;
|
|
18813
|
+
prefixRows;
|
|
18814
|
+
constructor(message, init) {
|
|
18815
|
+
super(message);
|
|
18816
|
+
this.name = "LedgerSessionJsonlError";
|
|
18817
|
+
this.path = init.path;
|
|
18818
|
+
this.line = init.line;
|
|
18819
|
+
this.prefixRows = init.prefixRows;
|
|
18820
|
+
}
|
|
18821
|
+
};
|
|
18822
|
+
}
|
|
18823
|
+
});
|
|
18824
|
+
|
|
18825
|
+
// src/session-dialogue.ts
|
|
18826
|
+
var init_session_dialogue = __esm({
|
|
18827
|
+
"src/session-dialogue.ts"() {
|
|
18828
|
+
"use strict";
|
|
18829
|
+
}
|
|
18830
|
+
});
|
|
18831
|
+
|
|
18832
|
+
// src/ticket-provenance.ts
|
|
18833
|
+
import { readFile as readFile10, unlink } from "node:fs/promises";
|
|
18834
|
+
import { basename as basename5, dirname as dirname9, join as join13, resolve as resolve6 } from "node:path";
|
|
18835
|
+
function ticketProvenanceSubject(ticketNumber) {
|
|
18836
|
+
if (!isSafePositiveTicketNumber(ticketNumber)) {
|
|
18837
|
+
throw new Error(
|
|
18838
|
+
`ticket-provenance subject requires a positive ticket number, got ${String(ticketNumber)}`
|
|
18839
|
+
);
|
|
18840
|
+
}
|
|
18841
|
+
return String(ticketNumber);
|
|
18842
|
+
}
|
|
18843
|
+
function ticketProvenanceRecordInput(ticketNumber, cwd, home, runDirectory) {
|
|
18844
|
+
return {
|
|
18845
|
+
level: "event",
|
|
18846
|
+
kind: TICKET_PROVENANCE_KIND,
|
|
18847
|
+
...ticketNumber === null ? {} : { subject: ticketProvenanceSubject(ticketNumber) },
|
|
18848
|
+
...runDirectory === void 0 ? {} : { runDirectory },
|
|
18849
|
+
cwd,
|
|
18850
|
+
...home === void 0 ? {} : { home }
|
|
18851
|
+
};
|
|
18852
|
+
}
|
|
18853
|
+
function resolveTicketProvenanceVolume(ticketNumber, cwd, home) {
|
|
18854
|
+
const path = resolveSitianRecordPath(
|
|
18855
|
+
ticketProvenanceRecordInput(ticketNumber, cwd, home)
|
|
18856
|
+
);
|
|
18857
|
+
return { recordFile: path.recordFile, volumeDir: path.sessionDir };
|
|
18858
|
+
}
|
|
18859
|
+
async function rehomeUnboundTicketProvenance(runDirectory, ticketNumber, cwd, home) {
|
|
18860
|
+
const source = join13(runDirectory, "records.jsonl");
|
|
18861
|
+
let content;
|
|
18862
|
+
try {
|
|
18863
|
+
content = await readFile10(source, "utf8");
|
|
18864
|
+
} catch (error) {
|
|
18865
|
+
if (errnoCode(error) === "ENOENT") return;
|
|
18866
|
+
throw error;
|
|
18867
|
+
}
|
|
18868
|
+
appendSitianRecordBlock(ticketProvenanceRecordInput(ticketNumber, cwd, home), content);
|
|
18869
|
+
await unlink(source);
|
|
18870
|
+
}
|
|
18871
|
+
var init_ticket_provenance = __esm({
|
|
18872
|
+
"src/ticket-provenance.ts"() {
|
|
18873
|
+
"use strict";
|
|
18874
|
+
init_activation_ledger_git();
|
|
18875
|
+
init_activation_ledger_topology();
|
|
18876
|
+
init_ledger_session_read();
|
|
18877
|
+
init_run_ticket_number();
|
|
18878
|
+
init_session_dialogue();
|
|
18879
|
+
init_sitian_facade();
|
|
18880
|
+
init_ticket_provenance_contracts();
|
|
18881
|
+
}
|
|
18882
|
+
});
|
|
18883
|
+
|
|
18593
18884
|
// src/uuidv7.ts
|
|
18594
18885
|
import { randomBytes } from "node:crypto";
|
|
18595
18886
|
function isUuidV7(value) {
|
|
@@ -18616,14 +18907,14 @@ var init_uuidv7 = __esm({
|
|
|
18616
18907
|
});
|
|
18617
18908
|
|
|
18618
18909
|
// src/typed-provider-http.ts
|
|
18619
|
-
import { readFile as
|
|
18620
|
-
import { join as
|
|
18910
|
+
import { readFile as readFile11, unlink as unlink2, writeFile as writeFile2 } from "node:fs/promises";
|
|
18911
|
+
import { join as join14 } from "node:path";
|
|
18621
18912
|
function typedProviderHttpPath(runDirectory) {
|
|
18622
|
-
return
|
|
18913
|
+
return join14(runDirectory, TYPED_HTTP_FILE);
|
|
18623
18914
|
}
|
|
18624
18915
|
async function clearTypedProviderHttpObservation(runDirectory) {
|
|
18625
18916
|
try {
|
|
18626
|
-
await
|
|
18917
|
+
await unlink2(typedProviderHttpPath(runDirectory));
|
|
18627
18918
|
} catch (error) {
|
|
18628
18919
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
18629
18920
|
return;
|
|
@@ -18634,7 +18925,7 @@ async function clearTypedProviderHttpObservation(runDirectory) {
|
|
|
18634
18925
|
async function readLatestTypedProviderHttpObservation(runDirectory) {
|
|
18635
18926
|
let text;
|
|
18636
18927
|
try {
|
|
18637
|
-
text = await
|
|
18928
|
+
text = await readFile11(typedProviderHttpPath(runDirectory), "utf8");
|
|
18638
18929
|
} catch (error) {
|
|
18639
18930
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
18640
18931
|
return void 0;
|
|
@@ -18663,8 +18954,8 @@ var init_typed_provider_http = __esm({
|
|
|
18663
18954
|
});
|
|
18664
18955
|
|
|
18665
18956
|
// src/public-cli/run-lifecycle.ts
|
|
18666
|
-
import { chmod, lstat as lstat2, open, readdir as readdir4, readFile as
|
|
18667
|
-
import { basename as
|
|
18957
|
+
import { chmod, lstat as lstat2, open, readdir as readdir4, readFile as readFile12, unlink as unlink3, writeFile as writeFile3 } from "node:fs/promises";
|
|
18958
|
+
import { basename as basename6, join as join15 } from "node:path";
|
|
18668
18959
|
function buildAutoResumeContinuationPrompt(options) {
|
|
18669
18960
|
return appendEngineSessionMaterial(
|
|
18670
18961
|
[RESUME_TRANSPORT_ENVELOPE],
|
|
@@ -18690,7 +18981,7 @@ function renderResumeCommand(runId) {
|
|
|
18690
18981
|
async function writeRoleRunState(runDirectory, record4) {
|
|
18691
18982
|
const payload = { ...record4, runDirectory };
|
|
18692
18983
|
await writeFile3(
|
|
18693
|
-
|
|
18984
|
+
join15(runDirectory, RUN_STATE_FILE),
|
|
18694
18985
|
`${JSON.stringify(payload, null, 2)}
|
|
18695
18986
|
`,
|
|
18696
18987
|
"utf8"
|
|
@@ -18740,7 +19031,7 @@ function parseCurrentCourtState(raw) {
|
|
|
18740
19031
|
async function readRoleRunStateDisk(runDirectory) {
|
|
18741
19032
|
let raw;
|
|
18742
19033
|
try {
|
|
18743
|
-
raw = JSON.parse(await
|
|
19034
|
+
raw = JSON.parse(await readFile12(join15(runDirectory, RUN_STATE_FILE), "utf8"));
|
|
18744
19035
|
} catch (error) {
|
|
18745
19036
|
if (errorCodeOf2(error) === "ENOENT") return void 0;
|
|
18746
19037
|
throw error;
|
|
@@ -18818,7 +19109,7 @@ async function writeRoleRunStateDisk(runDirectory, disk) {
|
|
|
18818
19109
|
...disk.currentCourt === void 0 ? {} : { currentCourt: disk.currentCourt }
|
|
18819
19110
|
};
|
|
18820
19111
|
await writeFile3(
|
|
18821
|
-
|
|
19112
|
+
join15(runDirectory, RUN_STATE_FILE),
|
|
18822
19113
|
`${JSON.stringify(payload, null, 2)}
|
|
18823
19114
|
`,
|
|
18824
19115
|
"utf8"
|
|
@@ -18987,7 +19278,7 @@ function isProcessAlive(pid) {
|
|
|
18987
19278
|
async function autopsyWriterLock(lockPath) {
|
|
18988
19279
|
let content;
|
|
18989
19280
|
try {
|
|
18990
|
-
content = await
|
|
19281
|
+
content = await readFile12(lockPath, "utf8");
|
|
18991
19282
|
} catch (error) {
|
|
18992
19283
|
if (errorCodeOf2(error) === "ENOENT") return { verdict: "absent" };
|
|
18993
19284
|
return { verdict: "unknown", reason: "unreadable", readFailure: error };
|
|
@@ -19018,7 +19309,7 @@ async function reclaimStaleWriterLock(lockPath, runDirectory) {
|
|
|
19018
19309
|
const current = await autopsyWriterLock(lockPath);
|
|
19019
19310
|
if (current.verdict !== "dead") return { reclaimed: false };
|
|
19020
19311
|
try {
|
|
19021
|
-
await
|
|
19312
|
+
await unlink3(lockPath);
|
|
19022
19313
|
return { reclaimed: true };
|
|
19023
19314
|
} catch (error) {
|
|
19024
19315
|
if (errorCodeOf2(error) === "ENOENT") return { reclaimed: false };
|
|
@@ -19034,7 +19325,7 @@ async function createWriterLease(lockPath, runDirectory, reportCleanupFailure) {
|
|
|
19034
19325
|
`, "utf8");
|
|
19035
19326
|
} catch (error) {
|
|
19036
19327
|
await handle.close().catch(() => void 0);
|
|
19037
|
-
await
|
|
19328
|
+
await unlink3(lockPath).catch(() => void 0);
|
|
19038
19329
|
throw error;
|
|
19039
19330
|
}
|
|
19040
19331
|
let released = false;
|
|
@@ -19046,19 +19337,19 @@ async function createWriterLease(lockPath, runDirectory, reportCleanupFailure) {
|
|
|
19046
19337
|
},
|
|
19047
19338
|
relocate(nextRunDirectory) {
|
|
19048
19339
|
currentRunDirectory = nextRunDirectory;
|
|
19049
|
-
currentLockPath =
|
|
19340
|
+
currentLockPath = join15(nextRunDirectory, WRITER_LOCK_FILE);
|
|
19050
19341
|
},
|
|
19051
19342
|
async release() {
|
|
19052
19343
|
if (released) return;
|
|
19053
19344
|
released = true;
|
|
19054
19345
|
await handle.close().catch(() => void 0);
|
|
19055
19346
|
try {
|
|
19056
|
-
await
|
|
19347
|
+
await unlink3(currentLockPath);
|
|
19057
19348
|
} catch (error) {
|
|
19058
19349
|
if (errorCodeOf2(error) === "EACCES") {
|
|
19059
19350
|
try {
|
|
19060
19351
|
await chmod(currentRunDirectory, 493);
|
|
19061
|
-
await
|
|
19352
|
+
await unlink3(currentLockPath);
|
|
19062
19353
|
} catch (retryError) {
|
|
19063
19354
|
reportCleanupFailure(retryError, currentLockPath);
|
|
19064
19355
|
}
|
|
@@ -19085,10 +19376,10 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
|
|
|
19085
19376
|
};
|
|
19086
19377
|
const reportReadFailure = (error) => {
|
|
19087
19378
|
reportDiagnostic(
|
|
19088
|
-
`writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${
|
|
19379
|
+
`writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${join15(runDirectory, WRITER_LOCK_FILE)}: ${describeErrorIdentity(error)}`
|
|
19089
19380
|
);
|
|
19090
19381
|
};
|
|
19091
|
-
const lockPath =
|
|
19382
|
+
const lockPath = join15(runDirectory, WRITER_LOCK_FILE);
|
|
19092
19383
|
let lastAutopsy = { verdict: "absent" };
|
|
19093
19384
|
let lastReclaimFailure;
|
|
19094
19385
|
for (let reclaimsLeft = WRITER_LEASE_RECLAIM_ROUNDS; ; reclaimsLeft -= 1) {
|
|
@@ -19143,7 +19434,7 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
|
|
|
19143
19434
|
async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole) {
|
|
19144
19435
|
if (runId.trim() === "") return void 0;
|
|
19145
19436
|
const ledgerHome = resolveActivationLedgerHome(home);
|
|
19146
|
-
const booksRoot =
|
|
19437
|
+
const booksRoot = join15(ledgerHome, "books");
|
|
19147
19438
|
let bookKeys;
|
|
19148
19439
|
try {
|
|
19149
19440
|
bookKeys = await readdir4(booksRoot);
|
|
@@ -19163,7 +19454,7 @@ async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole) {
|
|
|
19163
19454
|
throw error;
|
|
19164
19455
|
}
|
|
19165
19456
|
for (const runDirectory of runDirectories) {
|
|
19166
|
-
const entry =
|
|
19457
|
+
const entry = basename6(runDirectory);
|
|
19167
19458
|
if (onlyRole === void 0 && (entry === `${runId}@judge` || entry.startsWith(`${runId}@`)) || entry === `${runId}@${onlyRole}`) {
|
|
19168
19459
|
matches.push(runDirectory);
|
|
19169
19460
|
}
|
|
@@ -19184,7 +19475,7 @@ async function readRunParentPath(runDirectory) {
|
|
|
19184
19475
|
let raw;
|
|
19185
19476
|
try {
|
|
19186
19477
|
raw = JSON.parse(
|
|
19187
|
-
await
|
|
19478
|
+
await readFile12(join15(runDirectory, "admitted-request.json"), "utf8")
|
|
19188
19479
|
);
|
|
19189
19480
|
} catch (error) {
|
|
19190
19481
|
if (errorCodeOf2(error) === "ENOENT") return void 0;
|
|
@@ -19205,7 +19496,7 @@ async function readRunParentPath(runDirectory) {
|
|
|
19205
19496
|
async function runHasFormedSessionPrincipal(runDirectory) {
|
|
19206
19497
|
const disk = await readRoleRunStateDisk(runDirectory);
|
|
19207
19498
|
if (disk === void 0) return false;
|
|
19208
|
-
const sessionFile = typeof disk.principalWire.sessionFile === "string" && disk.principalWire.sessionFile.trim() !== "" ? disk.principalWire.sessionFile :
|
|
19499
|
+
const sessionFile = typeof disk.principalWire.sessionFile === "string" && disk.principalWire.sessionFile.trim() !== "" ? disk.principalWire.sessionFile : join15(disk.principalWire.sessionDirectory, "session.jsonl");
|
|
19209
19500
|
try {
|
|
19210
19501
|
const stat2 = await lstat2(sessionFile);
|
|
19211
19502
|
return stat2.isFile() && !stat2.isSymbolicLink();
|
|
@@ -19223,7 +19514,7 @@ async function findLatestRunIdForSeatTicket(input) {
|
|
|
19223
19514
|
let runDirectories;
|
|
19224
19515
|
try {
|
|
19225
19516
|
runDirectories = await listBookRunDirectories(
|
|
19226
|
-
input.ticketNumber === void 0 ? bookDir :
|
|
19517
|
+
input.ticketNumber === void 0 ? bookDir : join15(bookDir, String(input.ticketNumber))
|
|
19227
19518
|
);
|
|
19228
19519
|
} catch (error) {
|
|
19229
19520
|
if (errorCodeOf2(error) === "ENOENT") return void 0;
|
|
@@ -19232,7 +19523,7 @@ async function findLatestRunIdForSeatTicket(input) {
|
|
|
19232
19523
|
const suffix = `@${input.role}`;
|
|
19233
19524
|
let best;
|
|
19234
19525
|
for (const runDirectory of runDirectories) {
|
|
19235
|
-
const entry =
|
|
19526
|
+
const entry = basename6(runDirectory);
|
|
19236
19527
|
if (!entry.endsWith(suffix)) continue;
|
|
19237
19528
|
const runId = entry.slice(0, entry.length - suffix.length);
|
|
19238
19529
|
if (runId.length === 0) continue;
|
|
@@ -19350,7 +19641,7 @@ async function loadResumableRunRecord(home, runId, authority) {
|
|
|
19350
19641
|
let sourceRun;
|
|
19351
19642
|
try {
|
|
19352
19643
|
const raw = JSON.parse(
|
|
19353
|
-
await
|
|
19644
|
+
await readFile12(run.admittedRequestPath, "utf8")
|
|
19354
19645
|
);
|
|
19355
19646
|
if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
|
|
19356
19647
|
const record4 = raw;
|
|
@@ -19473,7 +19764,7 @@ async function loadResumableRunRecord(home, runId, authority) {
|
|
|
19473
19764
|
let model;
|
|
19474
19765
|
try {
|
|
19475
19766
|
const invocationRaw = JSON.parse(
|
|
19476
|
-
await
|
|
19767
|
+
await readFile12(join15(run.runDirectory, "invocation.json"), "utf8")
|
|
19477
19768
|
);
|
|
19478
19769
|
if (invocationRaw !== null && typeof invocationRaw === "object" && !Array.isArray(invocationRaw)) {
|
|
19479
19770
|
const rec = invocationRaw;
|
|
@@ -19512,7 +19803,7 @@ async function loadResumableRunRecord(home, runId, authority) {
|
|
|
19512
19803
|
} else if (mergedSet.tickets !== void 0) {
|
|
19513
19804
|
courtTicketNumbers = mergedSet.tickets;
|
|
19514
19805
|
}
|
|
19515
|
-
const sourceRunLeaf =
|
|
19806
|
+
const sourceRunLeaf = basename6(sourceRunPath ?? "").split("@");
|
|
19516
19807
|
const referencedRunId = sourceRun?.runId ?? sourceRunLeaf[0];
|
|
19517
19808
|
const referencedRole = sourceRun?.role ?? sourceRunLeaf[1];
|
|
19518
19809
|
if (referencedRunId !== void 0 && referencedRunId !== "") {
|
|
@@ -19857,7 +20148,7 @@ var init_run_lifecycle = __esm({
|
|
|
19857
20148
|
});
|
|
19858
20149
|
|
|
19859
20150
|
// src/notary-source-run.ts
|
|
19860
|
-
import { dirname as
|
|
20151
|
+
import { dirname as dirname10, isAbsolute as isAbsolute6, join as join16, resolve as resolve7, basename as basename7 } from "node:path";
|
|
19861
20152
|
import { lstat as lstat3, realpath as realpath3 } from "node:fs/promises";
|
|
19862
20153
|
function parseRunDirectoryName(name) {
|
|
19863
20154
|
const match = RUN_DIR_NAME.exec(name);
|
|
@@ -19888,10 +20179,10 @@ async function requireRunDirectory(candidate, display) {
|
|
|
19888
20179
|
`notary --source-run must be a run directory: ${display}`
|
|
19889
20180
|
);
|
|
19890
20181
|
}
|
|
19891
|
-
const identity = parseRunDirectoryName(
|
|
20182
|
+
const identity = parseRunDirectoryName(basename7(real));
|
|
19892
20183
|
if (identity === void 0) {
|
|
19893
20184
|
throw new NotarySourceRunError(
|
|
19894
|
-
`notary --source-run must be named <runId>@<role>: ${
|
|
20185
|
+
`notary --source-run must be named <runId>@<role>: ${basename7(real)}`
|
|
19895
20186
|
);
|
|
19896
20187
|
}
|
|
19897
20188
|
return real;
|
|
@@ -19904,16 +20195,16 @@ async function resolveNotarySourceRunLocator(options) {
|
|
|
19904
20195
|
const ledgerHome = resolveActivationLedgerHome(options.home);
|
|
19905
20196
|
const bookKey = resolveBookKeyFromGit(options.projectRoot);
|
|
19906
20197
|
const bookDirectory = activationBookDirectory(ledgerHome, bookKey);
|
|
19907
|
-
const bookRunsRoot =
|
|
20198
|
+
const bookRunsRoot = join16(bookDirectory, "runs");
|
|
19908
20199
|
let candidate;
|
|
19909
20200
|
const bare = parseRunDirectoryName(raw);
|
|
19910
20201
|
if (bare !== void 0 && !raw.includes("/") && !raw.includes("\\")) {
|
|
19911
|
-
candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ??
|
|
20202
|
+
candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ?? join16(bookRunsRoot, `${bare.runId}@${bare.role}`);
|
|
19912
20203
|
} else {
|
|
19913
|
-
candidate = isAbsolute6(raw) ? raw :
|
|
19914
|
-
const identity2 = parseRunDirectoryName(
|
|
19915
|
-
const subjectDirectory =
|
|
19916
|
-
const isLegacyUnboundLocator = identity2 !== void 0 &&
|
|
20204
|
+
candidate = isAbsolute6(raw) ? raw : resolve7(options.projectRoot, raw);
|
|
20205
|
+
const identity2 = parseRunDirectoryName(basename7(candidate));
|
|
20206
|
+
const subjectDirectory = dirname10(dirname10(candidate));
|
|
20207
|
+
const isLegacyUnboundLocator = identity2 !== void 0 && basename7(dirname10(candidate)) === "runs" && basename7(subjectDirectory) === "unbound" && resolve7(dirname10(subjectDirectory)) === resolve7(bookDirectory);
|
|
19917
20208
|
if (isLegacyUnboundLocator) {
|
|
19918
20209
|
candidate = await findRunDirectoryById(
|
|
19919
20210
|
options.home,
|
|
@@ -19924,11 +20215,11 @@ async function resolveNotarySourceRunLocator(options) {
|
|
|
19924
20215
|
}
|
|
19925
20216
|
}
|
|
19926
20217
|
const real = await requireRunDirectory(candidate, raw);
|
|
19927
|
-
const identity = parseRunDirectoryName(
|
|
20218
|
+
const identity = parseRunDirectoryName(basename7(real));
|
|
19928
20219
|
const bookIdentity = physicalPathIdentity(bookDirectory);
|
|
19929
|
-
const parentIdentity = physicalPathIdentity(
|
|
19930
|
-
const subjectBookIdentity = physicalPathIdentity(
|
|
19931
|
-
if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(
|
|
20220
|
+
const parentIdentity = physicalPathIdentity(dirname10(real));
|
|
20221
|
+
const subjectBookIdentity = physicalPathIdentity(dirname10(dirname10(dirname10(real))));
|
|
20222
|
+
if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(basename7(dirname10(real)) === "runs" && subjectBookIdentity === bookIdentity)) {
|
|
19932
20223
|
throw new NotarySourceRunError(
|
|
19933
20224
|
"notary --source-run must resolve to a retained run under the project machine-ledger book"
|
|
19934
20225
|
);
|
|
@@ -21032,14 +21323,14 @@ import { existsSync as existsSync5 } from "node:fs";
|
|
|
21032
21323
|
import {
|
|
21033
21324
|
lstat as lstat4,
|
|
21034
21325
|
mkdtemp,
|
|
21035
|
-
readFile as
|
|
21326
|
+
readFile as readFile13,
|
|
21036
21327
|
realpath as realpath4,
|
|
21037
21328
|
rename,
|
|
21038
21329
|
rm,
|
|
21039
21330
|
writeFile as writeFile4
|
|
21040
21331
|
} from "node:fs/promises";
|
|
21041
21332
|
import { tmpdir } from "node:os";
|
|
21042
|
-
import { basename as
|
|
21333
|
+
import { basename as basename8, dirname as dirname11, isAbsolute as isAbsolute7, join as join17, resolve as resolve8, sep as sep4 } from "node:path";
|
|
21043
21334
|
function issueAdmissionPlacement(authority, request) {
|
|
21044
21335
|
const ledgerHome = resolveActivationLedgerHome(request.home);
|
|
21045
21336
|
const bookKey = resolveBookKeyFromGit(request.cwd);
|
|
@@ -21093,15 +21384,15 @@ async function writeRoleInvocationLedger(source, role, effectiveModel) {
|
|
|
21093
21384
|
...effectiveModelLedgerFields(effectiveModel)
|
|
21094
21385
|
};
|
|
21095
21386
|
await writeFile4(
|
|
21096
|
-
|
|
21387
|
+
join17(source.runDirectory, "invocation.json"),
|
|
21097
21388
|
`${JSON.stringify(identity, null, 2)}
|
|
21098
21389
|
`,
|
|
21099
21390
|
"utf8"
|
|
21100
21391
|
);
|
|
21101
21392
|
}
|
|
21102
21393
|
async function recordEffectiveInvocationModel(runDirectory, model, engine, host, engineModel) {
|
|
21103
|
-
const ledgerPath =
|
|
21104
|
-
const current = JSON.parse(await
|
|
21394
|
+
const ledgerPath = join17(runDirectory, "invocation.json");
|
|
21395
|
+
const current = JSON.parse(await readFile13(ledgerPath, "utf8"));
|
|
21105
21396
|
const next = { ...current };
|
|
21106
21397
|
if (model !== void 0) {
|
|
21107
21398
|
next.provider = model.provider;
|
|
@@ -21133,8 +21424,8 @@ async function recordEffectiveInvocationModel(runDirectory, model, engine, host,
|
|
|
21133
21424
|
);
|
|
21134
21425
|
}
|
|
21135
21426
|
async function mergeInvocationIdentityPage(runDirectory, fields) {
|
|
21136
|
-
const ledgerPath =
|
|
21137
|
-
const current = JSON.parse(await
|
|
21427
|
+
const ledgerPath = join17(runDirectory, "invocation.json");
|
|
21428
|
+
const current = JSON.parse(await readFile13(ledgerPath, "utf8"));
|
|
21138
21429
|
await writeFile4(
|
|
21139
21430
|
ledgerPath,
|
|
21140
21431
|
`${JSON.stringify({
|
|
@@ -21150,7 +21441,7 @@ async function persistAdmittedSourceRunPath(admitted, sourceRunPath) {
|
|
|
21150
21441
|
throw new Error("persistAdmittedSourceRunPath requires a non-empty sourceRunPath");
|
|
21151
21442
|
}
|
|
21152
21443
|
const admittedPath = admitted.admittedRequestPath;
|
|
21153
|
-
const current = JSON.parse(await
|
|
21444
|
+
const current = JSON.parse(await readFile13(admittedPath, "utf8"));
|
|
21154
21445
|
if (typeof current.sourceRunPath === "string") {
|
|
21155
21446
|
if (current.sourceRunPath === sourceRunPath) return;
|
|
21156
21447
|
throw new Error(
|
|
@@ -21176,7 +21467,7 @@ async function bindAdmittedTicketNumber(admitted, ticketNumber) {
|
|
|
21176
21467
|
}
|
|
21177
21468
|
async function recordAdmittedCorrelation(admitted, correlationId) {
|
|
21178
21469
|
const current = JSON.parse(
|
|
21179
|
-
await
|
|
21470
|
+
await readFile13(admitted.admittedRequestPath, "utf8")
|
|
21180
21471
|
);
|
|
21181
21472
|
const prior = [
|
|
21182
21473
|
...Array.isArray(current.correlationIds) ? current.correlationIds.filter(
|
|
@@ -21224,7 +21515,7 @@ async function bindCourtTicketNumbersOnAdmitted(admitted, courtTicketNumbers) {
|
|
|
21224
21515
|
}
|
|
21225
21516
|
const frozen = Object.freeze([...projected]);
|
|
21226
21517
|
const admittedPath = admitted.admittedRequestPath;
|
|
21227
|
-
const current = JSON.parse(await
|
|
21518
|
+
const current = JSON.parse(await readFile13(admittedPath, "utf8"));
|
|
21228
21519
|
await writeFile4(
|
|
21229
21520
|
admittedPath,
|
|
21230
21521
|
`${JSON.stringify({ ...current, courtTicketNumbers: frozen }, null, 2)}
|
|
@@ -21246,8 +21537,31 @@ async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
|
|
|
21246
21537
|
runId: admitted.runId,
|
|
21247
21538
|
role: admitted.role
|
|
21248
21539
|
});
|
|
21249
|
-
ensureRoleRunDirectory(ledgerHome,
|
|
21540
|
+
ensureRoleRunDirectory(ledgerHome, dirname11(target.runDirectory));
|
|
21250
21541
|
const principal = authority.seal(target);
|
|
21542
|
+
if (admitted.role !== "diarist") {
|
|
21543
|
+
const parentPage = JSON.parse(await readFile13(admitted.admittedRequestPath, "utf8"));
|
|
21544
|
+
const childRunIds = parentPage.childDiaristRunIds;
|
|
21545
|
+
for (const childRunId of Array.isArray(childRunIds) ? childRunIds : []) {
|
|
21546
|
+
if (typeof childRunId !== "string") continue;
|
|
21547
|
+
const childDirectory = join17(dirname11(oldRunDirectory), `${childRunId}@diarist`);
|
|
21548
|
+
const childTarget = roleRunPlacement(ledgerHome, {
|
|
21549
|
+
bookKey: admitted.bookKey,
|
|
21550
|
+
subject: { ticketNumber: admitted.ticketNumber },
|
|
21551
|
+
runId: childRunId,
|
|
21552
|
+
role: "diarist"
|
|
21553
|
+
});
|
|
21554
|
+
authority.seal(childTarget);
|
|
21555
|
+
if (!existsSync5(childDirectory) && existsSync5(childTarget.runDirectory)) continue;
|
|
21556
|
+
await bindTicketNumberOnRunDirectory(childDirectory, admitted.ticketNumber);
|
|
21557
|
+
await rehomeUnboundTicketProvenance(childDirectory, admitted.ticketNumber, admitted.projectRoot, homeFromRunDirectory(oldRunDirectory));
|
|
21558
|
+
ensureRoleRunDirectory(ledgerHome, dirname11(childTarget.runDirectory));
|
|
21559
|
+
await rename(childDirectory, childTarget.runDirectory);
|
|
21560
|
+
}
|
|
21561
|
+
}
|
|
21562
|
+
if (admitted.role === "diarist") {
|
|
21563
|
+
await rehomeUnboundTicketProvenance(oldRunDirectory, admitted.ticketNumber, admitted.projectRoot, homeFromRunDirectory(oldRunDirectory));
|
|
21564
|
+
}
|
|
21251
21565
|
await rename(oldRunDirectory, target.runDirectory);
|
|
21252
21566
|
heldLease?.relocate(target.runDirectory);
|
|
21253
21567
|
const admittedRecord = admitted;
|
|
@@ -21275,14 +21589,21 @@ async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
|
|
|
21275
21589
|
admitted.principal = principal;
|
|
21276
21590
|
return { oldRunDirectory, newRunDirectory: target.runDirectory };
|
|
21277
21591
|
}
|
|
21592
|
+
async function recordChildDiaristRun(parent, childRunId) {
|
|
21593
|
+
const page = JSON.parse(await readFile13(parent.admittedRequestPath, "utf8"));
|
|
21594
|
+
const existing = Array.isArray(page.childDiaristRunIds) ? page.childDiaristRunIds.filter((runId) => typeof runId === "string") : [];
|
|
21595
|
+
const childDiaristRunIds = existing.includes(childRunId) ? existing : [...existing, childRunId];
|
|
21596
|
+
await writeFile4(parent.admittedRequestPath, `${JSON.stringify({ ...page, childDiaristRunIds }, null, 2)}
|
|
21597
|
+
`, "utf8");
|
|
21598
|
+
}
|
|
21278
21599
|
async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
|
|
21279
21600
|
requireSafePositiveTicketNumber(
|
|
21280
21601
|
ticketNumber,
|
|
21281
21602
|
"bindTicketNumberOnRunDirectory"
|
|
21282
21603
|
);
|
|
21283
|
-
const admittedPath =
|
|
21284
|
-
const invocationPath =
|
|
21285
|
-
const admitted = JSON.parse(await
|
|
21604
|
+
const admittedPath = join17(runDirectory, "admitted-request.json");
|
|
21605
|
+
const invocationPath = join17(runDirectory, "invocation.json");
|
|
21606
|
+
const admitted = JSON.parse(await readFile13(admittedPath, "utf8"));
|
|
21286
21607
|
const existing = admitted.ticketNumber;
|
|
21287
21608
|
if (typeof existing === "number") {
|
|
21288
21609
|
if (existing === ticketNumber) return;
|
|
@@ -21292,7 +21613,7 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
|
|
|
21292
21613
|
}
|
|
21293
21614
|
if (existsSync5(invocationPath)) {
|
|
21294
21615
|
const invocation = JSON.parse(
|
|
21295
|
-
await
|
|
21616
|
+
await readFile13(invocationPath, "utf8")
|
|
21296
21617
|
);
|
|
21297
21618
|
if (typeof invocation.ticketNumber === "number" && invocation.ticketNumber !== ticketNumber) {
|
|
21298
21619
|
throw new Error(
|
|
@@ -21317,7 +21638,7 @@ async function recordLaunchedPiIdentity(runDirectory, identity) {
|
|
|
21317
21638
|
async function observeLaunchedRolePackageIdentity(packageRoot2, selectedRoleEntry) {
|
|
21318
21639
|
const rolePackageRoot = packageRoot2;
|
|
21319
21640
|
const raw = JSON.parse(
|
|
21320
|
-
await
|
|
21641
|
+
await readFile13(join17(rolePackageRoot, "package.json"), "utf8")
|
|
21321
21642
|
);
|
|
21322
21643
|
if (typeof raw.version !== "string" || raw.version.trim() === "") {
|
|
21323
21644
|
throw new Error(
|
|
@@ -21588,7 +21909,7 @@ function requireAuthorityRef(value) {
|
|
|
21588
21909
|
});
|
|
21589
21910
|
}
|
|
21590
21911
|
async function readRegularFileAttachment(sourcePath) {
|
|
21591
|
-
const absolute = isAbsolute7(sourcePath) ? sourcePath :
|
|
21912
|
+
const absolute = isAbsolute7(sourcePath) ? sourcePath : resolve8(sourcePath);
|
|
21592
21913
|
let st;
|
|
21593
21914
|
try {
|
|
21594
21915
|
st = await lstat4(absolute);
|
|
@@ -21604,7 +21925,7 @@ async function readRegularFileAttachment(sourcePath) {
|
|
|
21604
21925
|
);
|
|
21605
21926
|
}
|
|
21606
21927
|
try {
|
|
21607
|
-
return { absolute, bytes: await
|
|
21928
|
+
return { absolute, bytes: await readFile13(absolute) };
|
|
21608
21929
|
} catch (error) {
|
|
21609
21930
|
throw new CliUsageError(
|
|
21610
21931
|
`attachment is not a readable regular file: ${sourcePath}`,
|
|
@@ -21617,13 +21938,13 @@ async function removePreparedAttachmentDirectory(stagingDirectory) {
|
|
|
21617
21938
|
}
|
|
21618
21939
|
async function withPreparedAttachments(attachmentPaths, use) {
|
|
21619
21940
|
if (attachmentPaths.length === 0) return await use([]);
|
|
21620
|
-
const stagingDirectory = await mkdtemp(
|
|
21941
|
+
const stagingDirectory = await mkdtemp(join17(tmpdir(), "ak-role-attachments-"));
|
|
21621
21942
|
const prepared = [];
|
|
21622
21943
|
let result;
|
|
21623
21944
|
try {
|
|
21624
21945
|
for (let index = 0; index < attachmentPaths.length; index += 1) {
|
|
21625
21946
|
const { absolute, bytes } = await readRegularFileAttachment(attachmentPaths[index]);
|
|
21626
|
-
const snapshotPath =
|
|
21947
|
+
const snapshotPath = join17(stagingDirectory, String(index).padStart(6, "0"));
|
|
21627
21948
|
await writeFile4(snapshotPath, bytes);
|
|
21628
21949
|
prepared.push({ absolute, snapshotPath });
|
|
21629
21950
|
}
|
|
@@ -21644,9 +21965,9 @@ async function withPreparedAttachments(attachmentPaths, use) {
|
|
|
21644
21965
|
return result;
|
|
21645
21966
|
}
|
|
21646
21967
|
async function freezeAttachmentBytes(provenancePath, bytes, destinationDir, index) {
|
|
21647
|
-
const frozenPath =
|
|
21968
|
+
const frozenPath = join17(
|
|
21648
21969
|
destinationDir,
|
|
21649
|
-
`${String(index).padStart(2, "0")}-${
|
|
21970
|
+
`${String(index).padStart(2, "0")}-${basename8(provenancePath)}`
|
|
21650
21971
|
);
|
|
21651
21972
|
await writeFile4(frozenPath, bytes);
|
|
21652
21973
|
return {
|
|
@@ -21660,7 +21981,7 @@ async function freezeAttachmentBytes(provenancePath, bytes, destinationDir, inde
|
|
|
21660
21981
|
async function freezePreparedAttachment(prepared, destinationDir, index) {
|
|
21661
21982
|
return freezeAttachmentBytes(
|
|
21662
21983
|
prepared.absolute,
|
|
21663
|
-
await
|
|
21984
|
+
await readFile13(prepared.snapshotPath),
|
|
21664
21985
|
destinationDir,
|
|
21665
21986
|
index
|
|
21666
21987
|
);
|
|
@@ -21687,14 +22008,14 @@ async function freezeAttachments(attachmentPaths, attachmentsDirectory) {
|
|
|
21687
22008
|
async function freezeAttachmentsIntoRun(attachmentPaths, runDirectory, summonsKey = `s-${Date.now().toString(36)}`) {
|
|
21688
22009
|
if (attachmentPaths.length === 0) return [];
|
|
21689
22010
|
const ledgerHome = resolveActivationLedgerHome(homeFromRunDirectory(runDirectory));
|
|
21690
|
-
const attachmentsDirectory =
|
|
22011
|
+
const attachmentsDirectory = join17(runDirectory, "attachments", summonsKey);
|
|
21691
22012
|
ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
|
|
21692
22013
|
return freezeAttachments(attachmentPaths, attachmentsDirectory);
|
|
21693
22014
|
}
|
|
21694
22015
|
async function freezePreparedAttachmentsIntoRun(prepared, runDirectory, summonsKey) {
|
|
21695
22016
|
if (prepared.length === 0) return [];
|
|
21696
22017
|
const ledgerHome = resolveActivationLedgerHome(homeFromRunDirectory(runDirectory));
|
|
21697
|
-
const attachmentsDirectory = summonsKey === void 0 ?
|
|
22018
|
+
const attachmentsDirectory = summonsKey === void 0 ? join17(runDirectory, "attachments") : join17(runDirectory, "attachments", summonsKey);
|
|
21698
22019
|
ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
|
|
21699
22020
|
const attachments = [];
|
|
21700
22021
|
for (let index = 0; index < prepared.length; index += 1) {
|
|
@@ -21771,7 +22092,7 @@ async function admitPublicRole(role, parsed, env, override) {
|
|
|
21771
22092
|
attachmentPaths,
|
|
21772
22093
|
...project,
|
|
21773
22094
|
placedFields: async (placed) => {
|
|
21774
|
-
const taskPath =
|
|
22095
|
+
const taskPath = join17(placed.runDirectory, "task.md");
|
|
21775
22096
|
await writeFile4(taskPath, instruction, "utf8");
|
|
21776
22097
|
return { phase, taskPath };
|
|
21777
22098
|
}
|
|
@@ -21791,9 +22112,9 @@ async function admitPublicRole(role, parsed, env, override) {
|
|
|
21791
22112
|
let prerequisites = Object.freeze([]);
|
|
21792
22113
|
let prerequisitesSource;
|
|
21793
22114
|
if (parsed.prerequisitesPath !== void 0) {
|
|
21794
|
-
const absolutePrereq = isAbsolute7(parsed.prerequisitesPath) ? parsed.prerequisitesPath :
|
|
22115
|
+
const absolutePrereq = isAbsolute7(parsed.prerequisitesPath) ? parsed.prerequisitesPath : resolve8(parsed.prerequisitesPath);
|
|
21795
22116
|
try {
|
|
21796
|
-
prerequisitesSource = await
|
|
22117
|
+
prerequisitesSource = await readFile13(absolutePrereq, "utf8");
|
|
21797
22118
|
} catch (error) {
|
|
21798
22119
|
throw new CliUsageError(
|
|
21799
22120
|
`fixer prerequisites path is unreadable: ${parsed.prerequisitesPath}`,
|
|
@@ -21817,7 +22138,7 @@ async function admitPublicRole(role, parsed, env, override) {
|
|
|
21817
22138
|
placedFields: async (placed) => {
|
|
21818
22139
|
let prerequisitesPath;
|
|
21819
22140
|
if (prerequisitesSource !== void 0) {
|
|
21820
|
-
prerequisitesPath =
|
|
22141
|
+
prerequisitesPath = join17(placed.runDirectory, "prerequisites.json");
|
|
21821
22142
|
await writeFile4(
|
|
21822
22143
|
prerequisitesPath,
|
|
21823
22144
|
`${JSON.stringify(prerequisites, null, 2)}
|
|
@@ -21825,7 +22146,7 @@ async function admitPublicRole(role, parsed, env, override) {
|
|
|
21825
22146
|
"utf8"
|
|
21826
22147
|
);
|
|
21827
22148
|
}
|
|
21828
|
-
const packetPath =
|
|
22149
|
+
const packetPath = join17(placed.runDirectory, "fix-packet.md");
|
|
21829
22150
|
await writeFile4(packetPath, instruction, "utf8");
|
|
21830
22151
|
return {
|
|
21831
22152
|
phase,
|
|
@@ -21849,7 +22170,7 @@ async function admitPublicRole(role, parsed, env, override) {
|
|
|
21849
22170
|
throw new CliUsageError(detail, { cause: error });
|
|
21850
22171
|
}
|
|
21851
22172
|
}
|
|
21852
|
-
const projectRoot =
|
|
22173
|
+
const projectRoot = resolve8(parsed.project ?? shared.cwd);
|
|
21853
22174
|
let repository;
|
|
21854
22175
|
if (parsed.repo !== void 0) {
|
|
21855
22176
|
try {
|
|
@@ -21889,7 +22210,7 @@ async function admitPublicRole(role, parsed, env, override) {
|
|
|
21889
22210
|
const prNumber = target.kind === "bound" ? target.prNumber : void 0;
|
|
21890
22211
|
let requestManifestPath;
|
|
21891
22212
|
if (manifestCanonicalJson !== void 0) {
|
|
21892
|
-
requestManifestPath =
|
|
22213
|
+
requestManifestPath = join17(placed.runDirectory, "request-manifest.json");
|
|
21893
22214
|
await writeFile4(requestManifestPath, manifestCanonicalJson, "utf8");
|
|
21894
22215
|
}
|
|
21895
22216
|
return {
|
|
@@ -21972,7 +22293,7 @@ async function admitPublicRole(role, parsed, env, override) {
|
|
|
21972
22293
|
if (parsed.project !== void 0) {
|
|
21973
22294
|
requireOptionPath("--project", parsed.project);
|
|
21974
22295
|
}
|
|
21975
|
-
const projectRoot =
|
|
22296
|
+
const projectRoot = resolve8(parsed.project ?? shared.cwd);
|
|
21976
22297
|
let sourceRun;
|
|
21977
22298
|
try {
|
|
21978
22299
|
sourceRun = await resolveNotarySourceRunLocator({
|
|
@@ -22049,7 +22370,7 @@ async function admitPublicRole(role, parsed, env, override) {
|
|
|
22049
22370
|
if (instruction.trim() === "") {
|
|
22050
22371
|
throw new CliUsageError("merger requires a nonblank task instruction");
|
|
22051
22372
|
}
|
|
22052
|
-
const projectRoot =
|
|
22373
|
+
const projectRoot = resolve8(parsed.project ?? shared.cwd);
|
|
22053
22374
|
const derived = await deriveMergerEnvelopeFromActiveMerge(
|
|
22054
22375
|
projectRoot,
|
|
22055
22376
|
createProductionMergerGitState(projectRoot)
|
|
@@ -22080,7 +22401,7 @@ async function admitPublicRole(role, parsed, env, override) {
|
|
|
22080
22401
|
resolutionScope: [...derived.resolutionScope],
|
|
22081
22402
|
authorizedChecks: []
|
|
22082
22403
|
});
|
|
22083
|
-
const mergerInputPath =
|
|
22404
|
+
const mergerInputPath = join17(placed.runDirectory, "merger-input.json");
|
|
22084
22405
|
await writeFile4(
|
|
22085
22406
|
mergerInputPath,
|
|
22086
22407
|
`${JSON.stringify(mergerInput, null, 2)}
|
|
@@ -22110,7 +22431,7 @@ async function placeRoleAdmission(options) {
|
|
|
22110
22431
|
if (options.project !== void 0) {
|
|
22111
22432
|
requireOptionPath("--project", options.project);
|
|
22112
22433
|
}
|
|
22113
|
-
const projectRoot =
|
|
22434
|
+
const projectRoot = resolve8(options.project ?? options.cwd);
|
|
22114
22435
|
const runId = options.runId ?? (options.createRunId ?? uuidv7)();
|
|
22115
22436
|
const ticketFields = ticketAdmissionFields(options.assertedTicketNumber);
|
|
22116
22437
|
const {
|
|
@@ -22154,7 +22475,7 @@ function persistedAttachmentRefs(attachments) {
|
|
|
22154
22475
|
}));
|
|
22155
22476
|
}
|
|
22156
22477
|
async function persistPlacedAdmission(admitted, placed, model) {
|
|
22157
|
-
const admittedRequestPath =
|
|
22478
|
+
const admittedRequestPath = join17(placed.runDirectory, "admitted-request.json");
|
|
22158
22479
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
22159
22480
|
sessionDirectory: placed.sessionDirectory,
|
|
22160
22481
|
sessionFile: placed.sessionFile
|
|
@@ -22207,7 +22528,7 @@ async function admitStandardMaterialInvocation(role, options) {
|
|
|
22207
22528
|
attachments: persistedAttachmentRefs(placed.attachments),
|
|
22208
22529
|
...placed.ticketFields
|
|
22209
22530
|
};
|
|
22210
|
-
const admittedRequestPath = defer ?
|
|
22531
|
+
const admittedRequestPath = defer ? join17(placed.runDirectory, "admitted-request.json") : await persistPlacedAdmission(admitted, placed, options.model);
|
|
22211
22532
|
return {
|
|
22212
22533
|
role,
|
|
22213
22534
|
runId: placed.runId,
|
|
@@ -22282,7 +22603,7 @@ async function materializeCountersignInvocation(admitted, options) {
|
|
|
22282
22603
|
});
|
|
22283
22604
|
const placement = placed;
|
|
22284
22605
|
admitted.runDirectory = placement.runDirectory;
|
|
22285
|
-
admitted.admittedRequestPath =
|
|
22606
|
+
admitted.admittedRequestPath = join17(
|
|
22286
22607
|
placement.runDirectory,
|
|
22287
22608
|
"admitted-request.json"
|
|
22288
22609
|
);
|
|
@@ -22378,7 +22699,7 @@ function parseDoctorIssueNumber(raw) {
|
|
|
22378
22699
|
}
|
|
22379
22700
|
async function resolveDoctorCaseRunsPath(options) {
|
|
22380
22701
|
const ledgerHome = resolveActivationLedgerHome(options.home);
|
|
22381
|
-
const defaultRuns =
|
|
22702
|
+
const defaultRuns = join17(
|
|
22382
22703
|
activationBookDirectory(ledgerHome, options.bookKey),
|
|
22383
22704
|
String(options.issueNumber),
|
|
22384
22705
|
"runs"
|
|
@@ -22395,7 +22716,7 @@ async function resolveDoctorCaseRunsPath(options) {
|
|
|
22395
22716
|
"doctor --runs must be a project-relative path"
|
|
22396
22717
|
);
|
|
22397
22718
|
}
|
|
22398
|
-
const resolved =
|
|
22719
|
+
const resolved = resolve8(options.projectRoot, raw);
|
|
22399
22720
|
if (resolved !== options.projectRoot && !pathContainedIn(options.projectRoot, resolved)) {
|
|
22400
22721
|
throw new CliUsageError(
|
|
22401
22722
|
"doctor --runs escapes the project root"
|
|
@@ -22472,11 +22793,11 @@ function parseAnalystCohortIssueToken(raw, flag) {
|
|
|
22472
22793
|
`${flag} requires a comma-separated list of N or book:N`
|
|
22473
22794
|
);
|
|
22474
22795
|
}
|
|
22475
|
-
const
|
|
22476
|
-
if (
|
|
22477
|
-
const rhs = trimmed.slice(
|
|
22796
|
+
const sep6 = trimmed.lastIndexOf(":");
|
|
22797
|
+
if (sep6 > 0) {
|
|
22798
|
+
const rhs = trimmed.slice(sep6 + 1);
|
|
22478
22799
|
if (ANALYST_TICKET_NUMBER_PATTERN.test(rhs)) {
|
|
22479
|
-
const bookKey = trimmed.slice(0,
|
|
22800
|
+
const bookKey = trimmed.slice(0, sep6);
|
|
22480
22801
|
if (bookKey.trim() === "") {
|
|
22481
22802
|
throw new CliUsageError(
|
|
22482
22803
|
`${flag} book:N requires a non-empty book key, got ${raw}`
|
|
@@ -22686,6 +23007,7 @@ var init_invocation = __esm({
|
|
|
22686
23007
|
init_merger_git_state();
|
|
22687
23008
|
init_merger_contracts();
|
|
22688
23009
|
init_sha256();
|
|
23010
|
+
init_ticket_provenance();
|
|
22689
23011
|
init_uuidv7();
|
|
22690
23012
|
init_notary_contracts();
|
|
22691
23013
|
init_notary_source_run();
|
|
@@ -22700,15 +23022,15 @@ var init_invocation = __esm({
|
|
|
22700
23022
|
|
|
22701
23023
|
// src/public-cli/load-production-acp-host.ts
|
|
22702
23024
|
import { existsSync as existsSync6 } from "node:fs";
|
|
22703
|
-
import { join as
|
|
23025
|
+
import { join as join18 } from "node:path";
|
|
22704
23026
|
import { pathToFileURL } from "node:url";
|
|
22705
23027
|
async function loadProductionAcpHostFactory(packageRoot2, host) {
|
|
22706
23028
|
const description = lookupHostDescription(host);
|
|
22707
23029
|
if (description === void 0) {
|
|
22708
23030
|
throw new Error(`unregistered host: ${host}`);
|
|
22709
23031
|
}
|
|
22710
|
-
const built =
|
|
22711
|
-
const source =
|
|
23032
|
+
const built = join18(packageRoot2, "dist/acp-host/production-host.js");
|
|
23033
|
+
const source = join18(packageRoot2, "src/acp-host/production-host.ts");
|
|
22712
23034
|
const target = existsSync6(built) ? built : source;
|
|
22713
23035
|
const href = pathToFileURL(target).href;
|
|
22714
23036
|
const mod = await import(href);
|
|
@@ -22724,15 +23046,15 @@ var init_load_production_acp_host = __esm({
|
|
|
22724
23046
|
|
|
22725
23047
|
// src/public-cli/load-production-headless-host.ts
|
|
22726
23048
|
import { existsSync as existsSync7 } from "node:fs";
|
|
22727
|
-
import { join as
|
|
23049
|
+
import { join as join19 } from "node:path";
|
|
22728
23050
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
22729
23051
|
async function loadProductionHeadlessHostFactory(packageRoot2, host) {
|
|
22730
23052
|
const description = lookupHeadlessHostDescription(host);
|
|
22731
23053
|
if (description === void 0) {
|
|
22732
23054
|
throw new Error(`unregistered headless host: ${host}`);
|
|
22733
23055
|
}
|
|
22734
|
-
const built =
|
|
22735
|
-
const source =
|
|
23056
|
+
const built = join19(packageRoot2, "dist/headless-host/production-host.js");
|
|
23057
|
+
const source = join19(packageRoot2, "src/headless-host/production-host.ts");
|
|
22736
23058
|
const target = existsSync7(built) ? built : source;
|
|
22737
23059
|
const href = pathToFileURL2(target).href;
|
|
22738
23060
|
const mod = await import(href);
|
|
@@ -22859,8 +23181,8 @@ var init_role_turn_host_resolution = __esm({
|
|
|
22859
23181
|
|
|
22860
23182
|
// src/package-resources/method-skill.ts
|
|
22861
23183
|
import { createHash as createHash4 } from "node:crypto";
|
|
22862
|
-
import { readFile as
|
|
22863
|
-
import { join as
|
|
23184
|
+
import { readFile as readFile14, realpath as realpath5 } from "node:fs/promises";
|
|
23185
|
+
import { join as join20 } from "node:path";
|
|
22864
23186
|
function gitBlobOid(bytes) {
|
|
22865
23187
|
const body = typeof bytes === "string" ? Buffer.from(bytes, "utf8") : Buffer.from(bytes);
|
|
22866
23188
|
const header = Buffer.from(`blob ${body.byteLength}\0`, "utf8");
|
|
@@ -22877,16 +23199,16 @@ function packagedMethodSkillRelativeDirectory(name) {
|
|
|
22877
23199
|
return `${METHOD_SKILL_RELATIVE_ROOT}/${name}`;
|
|
22878
23200
|
}
|
|
22879
23201
|
function resolvePackagedMethodSkillRoot(packageRoot2, name) {
|
|
22880
|
-
return
|
|
23202
|
+
return join20(packageRoot2, packagedMethodSkillRelativeDirectory(name));
|
|
22881
23203
|
}
|
|
22882
23204
|
function resolvePackagedMethodSkillPath(packageRoot2, name) {
|
|
22883
|
-
return
|
|
23205
|
+
return join20(resolvePackagedMethodSkillRoot(packageRoot2, name), "SKILL.md");
|
|
22884
23206
|
}
|
|
22885
|
-
function
|
|
23207
|
+
function isRecord6(value) {
|
|
22886
23208
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22887
23209
|
}
|
|
22888
23210
|
function parseProvenance(raw, expectedName) {
|
|
22889
|
-
if (!
|
|
23211
|
+
if (!isRecord6(raw)) {
|
|
22890
23212
|
throw new Error(`Packaged method provenance must be an object for ${expectedName}`);
|
|
22891
23213
|
}
|
|
22892
23214
|
if (raw.name !== expectedName) {
|
|
@@ -22900,7 +23222,7 @@ function parseProvenance(raw, expectedName) {
|
|
|
22900
23222
|
if (typeof raw.packageAdaptation !== "string" || raw.packageAdaptation.trim() === "") {
|
|
22901
23223
|
throw new Error(`Packaged method provenance packageAdaptation must be nonblank`);
|
|
22902
23224
|
}
|
|
22903
|
-
if (!
|
|
23225
|
+
if (!isRecord6(raw.upstream)) {
|
|
22904
23226
|
throw new Error(`Packaged method provenance upstream must be an object`);
|
|
22905
23227
|
}
|
|
22906
23228
|
const upstream = raw.upstream;
|
|
@@ -22927,12 +23249,12 @@ function parseProvenance(raw, expectedName) {
|
|
|
22927
23249
|
`Packaged method provenance upstream must include nonblank tag or version`
|
|
22928
23250
|
);
|
|
22929
23251
|
}
|
|
22930
|
-
if (!
|
|
23252
|
+
if (!isRecord6(raw.files)) {
|
|
22931
23253
|
throw new Error(`Packaged method provenance files must be an object`);
|
|
22932
23254
|
}
|
|
22933
23255
|
const files = {};
|
|
22934
23256
|
for (const [rel, entry] of Object.entries(raw.files)) {
|
|
22935
|
-
if (!
|
|
23257
|
+
if (!isRecord6(entry)) {
|
|
22936
23258
|
throw new Error(`Packaged method provenance file entry must be an object: ${rel}`);
|
|
22937
23259
|
}
|
|
22938
23260
|
if (typeof entry.sha256 !== "string" || !SHA256_RE.test(entry.sha256)) {
|
|
@@ -22974,11 +23296,11 @@ function parseProvenance(raw, expectedName) {
|
|
|
22974
23296
|
}
|
|
22975
23297
|
async function loadPackagedMethodSkillMaterial(packageRoot2, name) {
|
|
22976
23298
|
const rootDirectory = resolvePackagedMethodSkillRoot(packageRoot2, name);
|
|
22977
|
-
const skillPathConfigured =
|
|
22978
|
-
const provenancePath =
|
|
23299
|
+
const skillPathConfigured = join20(rootDirectory, "SKILL.md");
|
|
23300
|
+
const provenancePath = join20(rootDirectory, "provenance.json");
|
|
22979
23301
|
let provenanceRaw;
|
|
22980
23302
|
try {
|
|
22981
|
-
provenanceRaw = await
|
|
23303
|
+
provenanceRaw = await readFile14(provenancePath, "utf8");
|
|
22982
23304
|
} catch (error) {
|
|
22983
23305
|
throw new PackagedMethodSkillUnavailableError(name, provenancePath, error);
|
|
22984
23306
|
}
|
|
@@ -22992,10 +23314,10 @@ async function loadPackagedMethodSkillMaterial(packageRoot2, name) {
|
|
|
22992
23314
|
}
|
|
22993
23315
|
const provenance = parseProvenance(provenanceJson, name);
|
|
22994
23316
|
for (const [rel, expected] of Object.entries(provenance.files)) {
|
|
22995
|
-
const absolute =
|
|
23317
|
+
const absolute = join20(rootDirectory, rel);
|
|
22996
23318
|
let bytes;
|
|
22997
23319
|
try {
|
|
22998
|
-
bytes = await
|
|
23320
|
+
bytes = await readFile14(absolute);
|
|
22999
23321
|
} catch (error) {
|
|
23000
23322
|
throw new PackagedMethodSkillUnavailableError(name, absolute, error);
|
|
23001
23323
|
}
|
|
@@ -23011,7 +23333,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot2, name) {
|
|
|
23011
23333
|
let raw;
|
|
23012
23334
|
try {
|
|
23013
23335
|
skillPath = await realpath5(skillPathConfigured);
|
|
23014
|
-
raw = await
|
|
23336
|
+
raw = await readFile14(skillPath, "utf8");
|
|
23015
23337
|
} catch (error) {
|
|
23016
23338
|
throw new PackagedMethodSkillUnavailableError(name, skillPathConfigured, error);
|
|
23017
23339
|
}
|
|
@@ -23096,23 +23418,23 @@ var init_method_skill = __esm({
|
|
|
23096
23418
|
|
|
23097
23419
|
// src/session-opening-materials.ts
|
|
23098
23420
|
import { existsSync as existsSync8 } from "node:fs";
|
|
23099
|
-
import { readFile as
|
|
23100
|
-
import { dirname as
|
|
23421
|
+
import { readFile as readFile15 } from "node:fs/promises";
|
|
23422
|
+
import { dirname as dirname12, join as join21 } from "node:path";
|
|
23101
23423
|
import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "node:url";
|
|
23102
23424
|
function resolvePackageRootDir(moduleUrl = import.meta.url) {
|
|
23103
|
-
let dir =
|
|
23425
|
+
let dir = dirname12(fileURLToPath(moduleUrl));
|
|
23104
23426
|
for (let i = 0; i < 8; i += 1) {
|
|
23105
|
-
if (existsSync8(
|
|
23427
|
+
if (existsSync8(join21(dir, "package.json")) && existsSync8(join21(dir, "souls"))) {
|
|
23106
23428
|
return dir;
|
|
23107
23429
|
}
|
|
23108
|
-
const parent =
|
|
23430
|
+
const parent = dirname12(dir);
|
|
23109
23431
|
if (parent === dir) break;
|
|
23110
23432
|
dir = parent;
|
|
23111
23433
|
}
|
|
23112
23434
|
return fileURLToPath(new URL("..", moduleUrl));
|
|
23113
23435
|
}
|
|
23114
23436
|
async function readPackageMaterial(relativePath) {
|
|
23115
|
-
return
|
|
23437
|
+
return readFile15(fileURLToPath(new URL(relativePath, packageRootUrl)), "utf8");
|
|
23116
23438
|
}
|
|
23117
23439
|
async function joinPackageMaterials(relativePaths) {
|
|
23118
23440
|
const chunks = [];
|
|
@@ -23220,14 +23542,14 @@ var init_audit_escalation = __esm({
|
|
|
23220
23542
|
});
|
|
23221
23543
|
|
|
23222
23544
|
// src/submission-ledger.ts
|
|
23223
|
-
import { join as
|
|
23545
|
+
import { join as join22 } from "node:path";
|
|
23224
23546
|
async function submissionRecordFile(cwd, runId, scope) {
|
|
23225
23547
|
const ledgerHome = resolveActivationLedgerHome(scope.home);
|
|
23226
23548
|
let sessionParent = scope.sessionParent;
|
|
23227
23549
|
if (sessionParent === void 0) {
|
|
23228
23550
|
const discoveredRun = await findRunDirectoryById(scope.home, runId);
|
|
23229
23551
|
if (discoveredRun === void 0) return void 0;
|
|
23230
|
-
sessionParent =
|
|
23552
|
+
sessionParent = join22(discoveredRun, "session", "session.jsonl");
|
|
23231
23553
|
}
|
|
23232
23554
|
return resolveSitianRecordPathInLedger({
|
|
23233
23555
|
level: "event",
|
|
@@ -23413,17 +23735,17 @@ var init_submission_ledger = __esm({
|
|
|
23413
23735
|
});
|
|
23414
23736
|
|
|
23415
23737
|
// src/session-identity.ts
|
|
23416
|
-
import { mkdir as mkdir2, readFile as
|
|
23417
|
-
import { dirname as
|
|
23738
|
+
import { mkdir as mkdir2, readFile as readFile16, rename as rename2, writeFile as writeFile5 } from "node:fs/promises";
|
|
23739
|
+
import { dirname as dirname13, join as join23 } from "node:path";
|
|
23418
23740
|
function createSessionIdentityAuthority(authority, sessionBindingFile) {
|
|
23419
|
-
const bindingPath = (principal) =>
|
|
23741
|
+
const bindingPath = (principal) => join23(authority.decode(principal).sessionDirectory, sessionBindingFile);
|
|
23420
23742
|
return {
|
|
23421
23743
|
resolveSessionFile(principal) {
|
|
23422
23744
|
return authority.decode(principal).sessionFile;
|
|
23423
23745
|
},
|
|
23424
23746
|
async load(principal) {
|
|
23425
23747
|
try {
|
|
23426
|
-
const value = JSON.parse(await
|
|
23748
|
+
const value = JSON.parse(await readFile16(bindingPath(principal), "utf8"));
|
|
23427
23749
|
if (typeof value !== "object" || value === null || typeof value.sessionId !== "string") {
|
|
23428
23750
|
throw new Error("durable session binding is invalid");
|
|
23429
23751
|
}
|
|
@@ -23435,7 +23757,7 @@ function createSessionIdentityAuthority(authority, sessionBindingFile) {
|
|
|
23435
23757
|
},
|
|
23436
23758
|
async bind(principal, sessionId) {
|
|
23437
23759
|
const target = bindingPath(principal);
|
|
23438
|
-
await mkdir2(
|
|
23760
|
+
await mkdir2(dirname13(target), { recursive: true });
|
|
23439
23761
|
const temporary = `${target}.${process.pid}.tmp`;
|
|
23440
23762
|
await writeFile5(temporary, `${JSON.stringify({ sessionId })}
|
|
23441
23763
|
`, { encoding: "utf8", mode: 384 });
|
|
@@ -23467,250 +23789,10 @@ var init_session_identity = __esm({
|
|
|
23467
23789
|
}
|
|
23468
23790
|
});
|
|
23469
23791
|
|
|
23470
|
-
// src/ledger-session-read.ts
|
|
23471
|
-
import { readFile as readFile15 } from "node:fs/promises";
|
|
23472
|
-
function isRecord6(value) {
|
|
23473
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23474
|
-
}
|
|
23475
|
-
async function readLedgerSessionJsonlLines(path) {
|
|
23476
|
-
const text = await readFile15(path, "utf8");
|
|
23477
|
-
const lines = text.split("\n");
|
|
23478
|
-
const out = [];
|
|
23479
|
-
for (let index = 0; index < lines.length; index += 1) {
|
|
23480
|
-
const raw = lines[index];
|
|
23481
|
-
if (!raw.trim()) continue;
|
|
23482
|
-
const lineNumber = index + 1;
|
|
23483
|
-
let row;
|
|
23484
|
-
try {
|
|
23485
|
-
row = JSON.parse(raw);
|
|
23486
|
-
} catch (error) {
|
|
23487
|
-
if (!(error instanceof SyntaxError)) throw error;
|
|
23488
|
-
const completedByTerminator = index < lines.length - 1;
|
|
23489
|
-
if (!completedByTerminator) break;
|
|
23490
|
-
out.push({
|
|
23491
|
-
line: lineNumber,
|
|
23492
|
-
raw,
|
|
23493
|
-
error: `malformed JSONL record in ${path} at line ${lineNumber}: ${error.message}`
|
|
23494
|
-
});
|
|
23495
|
-
continue;
|
|
23496
|
-
}
|
|
23497
|
-
if (!isRecord6(row)) {
|
|
23498
|
-
const kind = row === null ? "null" : Array.isArray(row) ? "array" : typeof row;
|
|
23499
|
-
out.push({
|
|
23500
|
-
line: lineNumber,
|
|
23501
|
-
raw,
|
|
23502
|
-
error: `complete non-object JSONL record in ${path} at line ${lineNumber}: expected object, got ${kind}`
|
|
23503
|
-
});
|
|
23504
|
-
continue;
|
|
23505
|
-
}
|
|
23506
|
-
out.push({ line: lineNumber, raw, row });
|
|
23507
|
-
}
|
|
23508
|
-
return out;
|
|
23509
|
-
}
|
|
23510
|
-
async function readLedgerSessionJsonl(path) {
|
|
23511
|
-
const rows = [];
|
|
23512
|
-
for (const line2 of await readLedgerSessionJsonlLines(path)) {
|
|
23513
|
-
if (line2.row === void 0) {
|
|
23514
|
-
throw new LedgerSessionJsonlError(line2.error ?? `unreadable JSONL record in ${path} at line ${line2.line}`, {
|
|
23515
|
-
path,
|
|
23516
|
-
line: line2.line,
|
|
23517
|
-
prefixRows: rows
|
|
23518
|
-
});
|
|
23519
|
-
}
|
|
23520
|
-
rows.push(line2.row);
|
|
23521
|
-
}
|
|
23522
|
-
return rows;
|
|
23523
|
-
}
|
|
23524
|
-
function extractSessionTimestampSpan(rows) {
|
|
23525
|
-
let startedAt;
|
|
23526
|
-
let endedAt;
|
|
23527
|
-
for (const row of rows) {
|
|
23528
|
-
if (typeof row.timestamp !== "string" || !row.timestamp) continue;
|
|
23529
|
-
if (startedAt === void 0) startedAt = row.timestamp;
|
|
23530
|
-
endedAt = row.timestamp;
|
|
23531
|
-
}
|
|
23532
|
-
return {
|
|
23533
|
-
...startedAt !== void 0 ? { startedAt } : {},
|
|
23534
|
-
...endedAt !== void 0 ? { endedAt } : {}
|
|
23535
|
-
};
|
|
23536
|
-
}
|
|
23537
|
-
function extractSessionModelSequence(rows) {
|
|
23538
|
-
const seen = /* @__PURE__ */ new Set();
|
|
23539
|
-
const ordered = [];
|
|
23540
|
-
const push = (raw) => {
|
|
23541
|
-
const model = raw.trim();
|
|
23542
|
-
if (model === "" || seen.has(model)) return;
|
|
23543
|
-
seen.add(model);
|
|
23544
|
-
ordered.push(model);
|
|
23545
|
-
};
|
|
23546
|
-
for (const row of rows) {
|
|
23547
|
-
if (row.type === "model_change" && typeof row.modelId === "string") {
|
|
23548
|
-
push(row.modelId);
|
|
23549
|
-
}
|
|
23550
|
-
const message = isRecord6(row.message) ? row.message : void 0;
|
|
23551
|
-
if (message?.role === "assistant" && typeof message.model === "string") {
|
|
23552
|
-
push(message.model);
|
|
23553
|
-
}
|
|
23554
|
-
}
|
|
23555
|
-
return ordered;
|
|
23556
|
-
}
|
|
23557
|
-
function bashCommandFirstLine(command) {
|
|
23558
|
-
const match = /^[^\r\n]*/.exec(command);
|
|
23559
|
-
return match?.[0] ?? "";
|
|
23560
|
-
}
|
|
23561
|
-
function extractSessionToolIntervals(rows) {
|
|
23562
|
-
const order = [];
|
|
23563
|
-
const openById = /* @__PURE__ */ new Map();
|
|
23564
|
-
for (const row of rows) {
|
|
23565
|
-
const rowTimestamp = typeof row.timestamp === "string" ? row.timestamp : void 0;
|
|
23566
|
-
const message = isRecord6(row.message) ? row.message : void 0;
|
|
23567
|
-
if (message?.role === "assistant" && Array.isArray(message.content)) {
|
|
23568
|
-
const callTimestamp = typeof message.timestamp === "string" && message.timestamp ? message.timestamp : rowTimestamp;
|
|
23569
|
-
for (const part of message.content) {
|
|
23570
|
-
if (!isRecord6(part) || part.type !== "toolCall") continue;
|
|
23571
|
-
if (typeof part.id !== "string" || part.id.length === 0) {
|
|
23572
|
-
throw new Error("toolCall frame missing string id");
|
|
23573
|
-
}
|
|
23574
|
-
if (typeof part.name !== "string" || part.name.length === 0) {
|
|
23575
|
-
throw new Error(`toolCall ${part.id} missing string name`);
|
|
23576
|
-
}
|
|
23577
|
-
if (callTimestamp === void 0 || callTimestamp.length === 0) {
|
|
23578
|
-
throw new Error(`toolCall ${part.id} missing timestamp`);
|
|
23579
|
-
}
|
|
23580
|
-
if (openById.has(part.id)) {
|
|
23581
|
-
throw new Error(`duplicate toolCall id ${part.id}`);
|
|
23582
|
-
}
|
|
23583
|
-
const args = isRecord6(part.arguments) ? part.arguments : void 0;
|
|
23584
|
-
const command = part.name === "bash" && args !== void 0 && typeof args.command === "string" ? bashCommandFirstLine(args.command) : void 0;
|
|
23585
|
-
const interval = {
|
|
23586
|
-
toolCallId: part.id,
|
|
23587
|
-
toolName: part.name,
|
|
23588
|
-
startedAt: callTimestamp,
|
|
23589
|
-
...command !== void 0 ? { command } : {}
|
|
23590
|
-
};
|
|
23591
|
-
order.push(interval);
|
|
23592
|
-
openById.set(part.id, interval);
|
|
23593
|
-
}
|
|
23594
|
-
}
|
|
23595
|
-
if (message?.role === "toolResult") {
|
|
23596
|
-
if (typeof message.toolCallId !== "string" || message.toolCallId.length === 0) {
|
|
23597
|
-
throw new Error("toolResult frame missing string toolCallId");
|
|
23598
|
-
}
|
|
23599
|
-
const resultTimestamp = typeof message.timestamp === "string" && message.timestamp ? message.timestamp : rowTimestamp;
|
|
23600
|
-
if (resultTimestamp === void 0 || resultTimestamp.length === 0) {
|
|
23601
|
-
throw new Error(`toolResult ${message.toolCallId} missing timestamp`);
|
|
23602
|
-
}
|
|
23603
|
-
const open4 = openById.get(message.toolCallId);
|
|
23604
|
-
if (open4 === void 0) {
|
|
23605
|
-
const toolName = typeof message.toolName === "string" && message.toolName.length > 0 ? message.toolName : "unknown";
|
|
23606
|
-
order.push({
|
|
23607
|
-
toolCallId: message.toolCallId,
|
|
23608
|
-
toolName,
|
|
23609
|
-
startedAt: resultTimestamp,
|
|
23610
|
-
endedAt: resultTimestamp
|
|
23611
|
-
});
|
|
23612
|
-
continue;
|
|
23613
|
-
}
|
|
23614
|
-
if (open4.endedAt !== void 0) {
|
|
23615
|
-
throw new Error(`duplicate toolResult for toolCallId ${message.toolCallId}`);
|
|
23616
|
-
}
|
|
23617
|
-
open4.endedAt = resultTimestamp;
|
|
23618
|
-
}
|
|
23619
|
-
}
|
|
23620
|
-
return order.map((interval) => {
|
|
23621
|
-
const base = {
|
|
23622
|
-
toolCallId: interval.toolCallId,
|
|
23623
|
-
toolName: interval.toolName,
|
|
23624
|
-
startedAt: interval.startedAt,
|
|
23625
|
-
...interval.command !== void 0 ? { command: interval.command } : {}
|
|
23626
|
-
};
|
|
23627
|
-
return interval.endedAt === void 0 ? base : { ...base, endedAt: interval.endedAt };
|
|
23628
|
-
});
|
|
23629
|
-
}
|
|
23630
|
-
function intervalRowsAroundAnchor(rows, anchorIndex, isBindingRow) {
|
|
23631
|
-
let start = 0;
|
|
23632
|
-
for (let i = anchorIndex; i >= 0; i -= 1) {
|
|
23633
|
-
if (isBindingRow(rows[i])) {
|
|
23634
|
-
start = i;
|
|
23635
|
-
break;
|
|
23636
|
-
}
|
|
23637
|
-
}
|
|
23638
|
-
let end = rows.length;
|
|
23639
|
-
for (let i = Math.max(anchorIndex, start) + 1; i < rows.length; i += 1) {
|
|
23640
|
-
if (isBindingRow(rows[i])) {
|
|
23641
|
-
end = i;
|
|
23642
|
-
break;
|
|
23643
|
-
}
|
|
23644
|
-
}
|
|
23645
|
-
return { rows: rows.slice(start, end), closed: end < rows.length };
|
|
23646
|
-
}
|
|
23647
|
-
var LedgerSessionJsonlError;
|
|
23648
|
-
var init_ledger_session_read = __esm({
|
|
23649
|
-
"src/ledger-session-read.ts"() {
|
|
23650
|
-
"use strict";
|
|
23651
|
-
LedgerSessionJsonlError = class extends Error {
|
|
23652
|
-
path;
|
|
23653
|
-
line;
|
|
23654
|
-
prefixRows;
|
|
23655
|
-
constructor(message, init) {
|
|
23656
|
-
super(message);
|
|
23657
|
-
this.name = "LedgerSessionJsonlError";
|
|
23658
|
-
this.path = init.path;
|
|
23659
|
-
this.line = init.line;
|
|
23660
|
-
this.prefixRows = init.prefixRows;
|
|
23661
|
-
}
|
|
23662
|
-
};
|
|
23663
|
-
}
|
|
23664
|
-
});
|
|
23665
|
-
|
|
23666
|
-
// src/session-dialogue.ts
|
|
23667
|
-
var init_session_dialogue = __esm({
|
|
23668
|
-
"src/session-dialogue.ts"() {
|
|
23669
|
-
"use strict";
|
|
23670
|
-
}
|
|
23671
|
-
});
|
|
23672
|
-
|
|
23673
|
-
// src/ticket-provenance.ts
|
|
23674
|
-
function ticketProvenanceSubject(ticketNumber) {
|
|
23675
|
-
if (!isSafePositiveTicketNumber(ticketNumber)) {
|
|
23676
|
-
throw new Error(
|
|
23677
|
-
`ticket-provenance subject requires a positive ticket number, got ${String(ticketNumber)}`
|
|
23678
|
-
);
|
|
23679
|
-
}
|
|
23680
|
-
return String(ticketNumber);
|
|
23681
|
-
}
|
|
23682
|
-
function ticketProvenanceRecordInput(ticketNumber, cwd, home) {
|
|
23683
|
-
return {
|
|
23684
|
-
level: "event",
|
|
23685
|
-
kind: TICKET_PROVENANCE_KIND,
|
|
23686
|
-
subject: ticketProvenanceSubject(ticketNumber),
|
|
23687
|
-
cwd,
|
|
23688
|
-
...home === void 0 ? {} : { home }
|
|
23689
|
-
};
|
|
23690
|
-
}
|
|
23691
|
-
function resolveTicketProvenanceVolume(ticketNumber, cwd, home) {
|
|
23692
|
-
const path = resolveSitianRecordPath(
|
|
23693
|
-
ticketProvenanceRecordInput(ticketNumber, cwd, home)
|
|
23694
|
-
);
|
|
23695
|
-
return { recordFile: path.recordFile, volumeDir: path.sessionDir };
|
|
23696
|
-
}
|
|
23697
|
-
var init_ticket_provenance = __esm({
|
|
23698
|
-
"src/ticket-provenance.ts"() {
|
|
23699
|
-
"use strict";
|
|
23700
|
-
init_activation_ledger_git();
|
|
23701
|
-
init_activation_ledger_topology();
|
|
23702
|
-
init_ledger_session_read();
|
|
23703
|
-
init_run_ticket_number();
|
|
23704
|
-
init_session_dialogue();
|
|
23705
|
-
init_sitian_facade();
|
|
23706
|
-
init_ticket_provenance_contracts();
|
|
23707
|
-
}
|
|
23708
|
-
});
|
|
23709
|
-
|
|
23710
23792
|
// src/public-cli/case-dossier-delivery.ts
|
|
23711
|
-
import { mkdtemp as mkdtemp2, readFile as
|
|
23793
|
+
import { mkdtemp as mkdtemp2, readFile as readFile17, rm as rm2, writeFile as writeFile6 } from "node:fs/promises";
|
|
23712
23794
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
23713
|
-
import { join as
|
|
23795
|
+
import { join as join24 } from "node:path";
|
|
23714
23796
|
async function projectCaseDossierPointerSection(input) {
|
|
23715
23797
|
if (input.ticketNumber === void 0) {
|
|
23716
23798
|
return [
|
|
@@ -23737,9 +23819,9 @@ async function deliverCaseDossierAsAttachment(input) {
|
|
|
23737
23819
|
projectRoot: input.projectRoot,
|
|
23738
23820
|
home: input.home
|
|
23739
23821
|
});
|
|
23740
|
-
const stagingDir = await mkdtemp2(
|
|
23822
|
+
const stagingDir = await mkdtemp2(join24(tmpdir2(), "ak-case-dossier-"));
|
|
23741
23823
|
try {
|
|
23742
|
-
const stagingPath =
|
|
23824
|
+
const stagingPath = join24(stagingDir, CASE_DOSSIER_ATTACH_FILE);
|
|
23743
23825
|
await writeFile6(stagingPath, `${section}
|
|
23744
23826
|
`, "utf8");
|
|
23745
23827
|
return await freezeAttachmentsIntoRun(
|
|
@@ -23768,7 +23850,7 @@ var init_case_dossier_delivery = __esm({
|
|
|
23768
23850
|
// src/engine-detour-usage.ts
|
|
23769
23851
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
23770
23852
|
import { readFileSync as readFileSync3 } from "node:fs";
|
|
23771
|
-
import { dirname as
|
|
23853
|
+
import { dirname as dirname14, join as join25 } from "node:path";
|
|
23772
23854
|
function isRecord7(value) {
|
|
23773
23855
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23774
23856
|
}
|
|
@@ -23852,7 +23934,7 @@ function projectEngineDetourToolUsageForPublicTerminal(usage, options) {
|
|
|
23852
23934
|
function readInvocationRecord(runDirectory) {
|
|
23853
23935
|
try {
|
|
23854
23936
|
const raw = JSON.parse(
|
|
23855
|
-
readFileSync3(
|
|
23937
|
+
readFileSync3(join25(runDirectory, "invocation.json"), "utf8")
|
|
23856
23938
|
);
|
|
23857
23939
|
return isRecord7(raw) ? raw : void 0;
|
|
23858
23940
|
} catch (error) {
|
|
@@ -23882,10 +23964,10 @@ function withEngineDetourToolUsageFact(outcome, usage) {
|
|
|
23882
23964
|
};
|
|
23883
23965
|
}
|
|
23884
23966
|
function runDirectoryFromSessionDirectory(sessionDirectory) {
|
|
23885
|
-
return
|
|
23967
|
+
return dirname14(sessionDirectory);
|
|
23886
23968
|
}
|
|
23887
23969
|
function sessionFileFromSessionDirectory(sessionDirectory) {
|
|
23888
|
-
return
|
|
23970
|
+
return join25(sessionDirectory, "session.jsonl");
|
|
23889
23971
|
}
|
|
23890
23972
|
function mintEngineDetourInvocationScope(input) {
|
|
23891
23973
|
const engine = input.effectiveEngine?.trim();
|
|
@@ -23915,7 +23997,7 @@ var init_engine_detour_usage = __esm({
|
|
|
23915
23997
|
|
|
23916
23998
|
// src/host-transition-prior-native.ts
|
|
23917
23999
|
import { access as access3, readdir as readdir5 } from "node:fs/promises";
|
|
23918
|
-
import { dirname as
|
|
24000
|
+
import { dirname as dirname15, join as join26 } from "node:path";
|
|
23919
24001
|
function isEnoent2(error) {
|
|
23920
24002
|
return typeof error === "object" && error !== null && error.code === "ENOENT";
|
|
23921
24003
|
}
|
|
@@ -23929,7 +24011,7 @@ async function listPiNativeRecordPaths(sessionFile) {
|
|
|
23929
24011
|
}
|
|
23930
24012
|
}
|
|
23931
24013
|
async function listSitianRecordPaths(sessionParent) {
|
|
23932
|
-
const sessionRoot =
|
|
24014
|
+
const sessionRoot = dirname15(sessionParent);
|
|
23933
24015
|
let entries;
|
|
23934
24016
|
try {
|
|
23935
24017
|
entries = await readdir5(sessionRoot, { withFileTypes: true });
|
|
@@ -23940,7 +24022,7 @@ async function listSitianRecordPaths(sessionParent) {
|
|
|
23940
24022
|
const recordPaths = [];
|
|
23941
24023
|
for (const entry of entries) {
|
|
23942
24024
|
if (!entry.isDirectory()) continue;
|
|
23943
|
-
const recordFile =
|
|
24025
|
+
const recordFile = join26(sessionRoot, entry.name, "records.jsonl");
|
|
23944
24026
|
try {
|
|
23945
24027
|
await access3(recordFile);
|
|
23946
24028
|
recordPaths.push(recordFile);
|
|
@@ -24025,7 +24107,7 @@ var init_process_cancel = __esm({
|
|
|
24025
24107
|
|
|
24026
24108
|
// src/analyst-gate-cycles-read.ts
|
|
24027
24109
|
import { readdir as readdir6 } from "node:fs/promises";
|
|
24028
|
-
import { join as
|
|
24110
|
+
import { join as join27 } from "node:path";
|
|
24029
24111
|
function isRecord8(value) {
|
|
24030
24112
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24031
24113
|
}
|
|
@@ -24240,10 +24322,10 @@ function pairGateRounds(volumes) {
|
|
|
24240
24322
|
return rounds.sort((a, b) => a.officerStartedAt.localeCompare(b.officerStartedAt)).map((round, index) => ({ ...round, roundIndex: index + 1 }));
|
|
24241
24323
|
}
|
|
24242
24324
|
async function resolveOfficerSessionFromPointerFile(pointerPath) {
|
|
24243
|
-
const { readFile:
|
|
24325
|
+
const { readFile: readFile23 } = await import("node:fs/promises");
|
|
24244
24326
|
let raw;
|
|
24245
24327
|
try {
|
|
24246
|
-
raw = JSON.parse(await
|
|
24328
|
+
raw = JSON.parse(await readFile23(pointerPath, "utf8"));
|
|
24247
24329
|
} catch (error) {
|
|
24248
24330
|
throw new Error(
|
|
24249
24331
|
`direct officer run pointer unreadable in ${pointerPath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
@@ -24275,7 +24357,7 @@ async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory, opti
|
|
|
24275
24357
|
throw error;
|
|
24276
24358
|
}
|
|
24277
24359
|
for (const name of names) {
|
|
24278
|
-
const path =
|
|
24360
|
+
const path = join27(directory, name);
|
|
24279
24361
|
const fromPointer = name.endsWith(".pointer.json");
|
|
24280
24362
|
const sessionPath = fromPointer ? await resolveOfficerSessionFromPointerFile(path) : path;
|
|
24281
24363
|
if (sessionPath === void 0) continue;
|
|
@@ -24604,15 +24686,15 @@ __export(settlement_exports, {
|
|
|
24604
24686
|
withSubmissions: () => withSubmissions
|
|
24605
24687
|
});
|
|
24606
24688
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
24607
|
-
import { appendFile as appendFile2, readFile as
|
|
24608
|
-
import { dirname as
|
|
24689
|
+
import { appendFile as appendFile2, readFile as readFile18, readdir as readdir7, rm as rm3, writeFile as writeFile7 } from "node:fs/promises";
|
|
24690
|
+
import { dirname as dirname16, join as join28 } from "node:path";
|
|
24609
24691
|
function sealedLedgerHome(admitted) {
|
|
24610
24692
|
return homeFromRunDirectory(admitted.runDirectory);
|
|
24611
24693
|
}
|
|
24612
24694
|
function ledgerReadScope(admitted, scope) {
|
|
24613
24695
|
return {
|
|
24614
24696
|
home: sealedLedgerHome(admitted),
|
|
24615
|
-
sessionParent:
|
|
24697
|
+
sessionParent: join28(admitted.runDirectory, "session", "session.jsonl"),
|
|
24616
24698
|
...scope?.courtAttemptId === void 0 || scope.courtAttemptId.length === 0 ? {} : { attemptId: scope.courtAttemptId }
|
|
24617
24699
|
};
|
|
24618
24700
|
}
|
|
@@ -24752,7 +24834,7 @@ function presentControlledFailure(failure, io) {
|
|
|
24752
24834
|
}
|
|
24753
24835
|
async function inspectJudgeSession(sessionFile) {
|
|
24754
24836
|
try {
|
|
24755
|
-
await
|
|
24837
|
+
await readFile18(sessionFile, "utf8");
|
|
24756
24838
|
return { state: "present" };
|
|
24757
24839
|
} catch (error) {
|
|
24758
24840
|
if (isMissingPathError4(error)) return { state: "missing" };
|
|
@@ -24992,7 +25074,7 @@ function sessionReadFailure(error, fallbackMessage) {
|
|
|
24992
25074
|
return failed;
|
|
24993
25075
|
}
|
|
24994
25076
|
async function readBoundSessionEntries(sessionFile) {
|
|
24995
|
-
const text = await
|
|
25077
|
+
const text = await readFile18(sessionFile, "utf8");
|
|
24996
25078
|
const entries = [];
|
|
24997
25079
|
for (const line2 of text.trim().split("\n").filter(Boolean)) {
|
|
24998
25080
|
try {
|
|
@@ -25053,7 +25135,7 @@ async function readSitianRetainedAuditorProviderStop(sessionFile) {
|
|
|
25053
25135
|
kind: "auditor",
|
|
25054
25136
|
sessionParent: sessionFile,
|
|
25055
25137
|
// Path is driven by sessionParent when under ledger home; cwd is a fallback only.
|
|
25056
|
-
cwd:
|
|
25138
|
+
cwd: dirname16(sessionFile)
|
|
25057
25139
|
});
|
|
25058
25140
|
const { records } = await readSitianRecords(recordFile);
|
|
25059
25141
|
for (let i = records.length - 1; i >= 0; i -= 1) {
|
|
@@ -25088,7 +25170,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
25088
25170
|
}
|
|
25089
25171
|
const parentId = parentEntries.find((entry) => entry.type === "session")?.id;
|
|
25090
25172
|
if (parentId === void 0) return void 0;
|
|
25091
|
-
const childDirectories = [
|
|
25173
|
+
const childDirectories = [join28(dirname16(sessionFile), "auditor-roles")];
|
|
25092
25174
|
const valid = [];
|
|
25093
25175
|
let sawAnyDirectory = false;
|
|
25094
25176
|
for (const childDirectory of childDirectories) {
|
|
@@ -25103,7 +25185,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
25103
25185
|
for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
|
|
25104
25186
|
let entries;
|
|
25105
25187
|
try {
|
|
25106
|
-
entries = await readBoundSessionEntries(
|
|
25188
|
+
entries = await readBoundSessionEntries(join28(childDirectory, file));
|
|
25107
25189
|
} catch (error) {
|
|
25108
25190
|
throw sessionReadFailure(error, "failed to read discovered auditor session");
|
|
25109
25191
|
}
|
|
@@ -25615,8 +25697,8 @@ function projectTerminalGateFact(rounds) {
|
|
|
25615
25697
|
};
|
|
25616
25698
|
}
|
|
25617
25699
|
async function extractGateFactFromSessionDirectory(sessionDirectory, options = {}) {
|
|
25618
|
-
const directories = [
|
|
25619
|
-
const parentSessionFile = options.parentSessionFile ??
|
|
25700
|
+
const directories = [join28(sessionDirectory, "auditor-roles")];
|
|
25701
|
+
const parentSessionFile = options.parentSessionFile ?? join28(sessionDirectory, "session.jsonl");
|
|
25620
25702
|
const rounds = await readAnalystGateCyclesFromAuditorRoles(directories, {
|
|
25621
25703
|
parentSessionFile
|
|
25622
25704
|
});
|
|
@@ -25754,10 +25836,10 @@ async function removeFaceIfPresent(path) {
|
|
|
25754
25836
|
async function clearOppositeTerminalArtifactFace(runDirectory) {
|
|
25755
25837
|
const artifactsDir = roleRunArtifactsDirectory(runDirectory);
|
|
25756
25838
|
for (const file of RUN_TERMINAL_ARTIFACT_FILES) {
|
|
25757
|
-
await removeFaceIfPresent(
|
|
25839
|
+
await removeFaceIfPresent(join28(artifactsDir, file));
|
|
25758
25840
|
}
|
|
25759
25841
|
for (const relative3 of RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS) {
|
|
25760
|
-
await removeFaceIfPresent(
|
|
25842
|
+
await removeFaceIfPresent(join28(runDirectory, relative3));
|
|
25761
25843
|
}
|
|
25762
25844
|
for (const path of await listSeamOwnedUniqueErrorFacePaths(runDirectory)) {
|
|
25763
25845
|
await removeFaceIfPresent(path);
|
|
@@ -25786,8 +25868,8 @@ async function publishAcceptedTerminalArtifacts(admitted, roleOutcome, coordinat
|
|
|
25786
25868
|
roleOutcome
|
|
25787
25869
|
);
|
|
25788
25870
|
const artifactsDir = await ensureTerminalArtifactFace(admitted.runDirectory);
|
|
25789
|
-
const reportPath =
|
|
25790
|
-
const evidencePath =
|
|
25871
|
+
const reportPath = join28(artifactsDir, "report.json");
|
|
25872
|
+
const evidencePath = join28(artifactsDir, "evidence.json");
|
|
25791
25873
|
await writeFile7(
|
|
25792
25874
|
reportPath,
|
|
25793
25875
|
`${JSON.stringify(bodies.report, null, 2)}
|
|
@@ -26222,7 +26304,7 @@ function publicationAttemptFromError(path, error) {
|
|
|
26222
26304
|
}
|
|
26223
26305
|
function uniqueFailureFallbackDirs(runDirectory, baseDir) {
|
|
26224
26306
|
const dirs = [];
|
|
26225
|
-
for (const dir of [baseDir, runDirectory,
|
|
26307
|
+
for (const dir of [baseDir, runDirectory, dirname16(runDirectory)]) {
|
|
26226
26308
|
if (!dirs.includes(dir)) dirs.push(dir);
|
|
26227
26309
|
}
|
|
26228
26310
|
return dirs;
|
|
@@ -26244,7 +26326,7 @@ async function writeFailureJsonRetainingCause(preferredCandidates, uniqueFallbac
|
|
|
26244
26326
|
const candidates = [
|
|
26245
26327
|
...preferredCandidates,
|
|
26246
26328
|
// One unique name per fallback dir — collisions on fixed names cannot exhaust this.
|
|
26247
|
-
...uniqueFallbackDirs.map((dir) =>
|
|
26329
|
+
...uniqueFallbackDirs.map((dir) => join28(dir, `${stem}.${randomUUID4()}.json`))
|
|
26248
26330
|
];
|
|
26249
26331
|
for (let i = 0; i < candidates.length; i += 1) {
|
|
26250
26332
|
const path = candidates[i];
|
|
@@ -26305,20 +26387,20 @@ async function publishFailureArtifacts(admitted, failure, authority) {
|
|
|
26305
26387
|
baseDir
|
|
26306
26388
|
);
|
|
26307
26389
|
const errorCandidates = underArtifacts ? [
|
|
26308
|
-
|
|
26309
|
-
|
|
26310
|
-
|
|
26390
|
+
join28(baseDir, "error.json"),
|
|
26391
|
+
join28(baseDir, "error.settlement.json"),
|
|
26392
|
+
join28(admitted.runDirectory, "error.settlement.json")
|
|
26311
26393
|
] : [
|
|
26312
|
-
|
|
26313
|
-
|
|
26394
|
+
join28(baseDir, "error.settlement.json"),
|
|
26395
|
+
join28(baseDir, "error.json")
|
|
26314
26396
|
];
|
|
26315
26397
|
const evidenceCandidates = underArtifacts ? [
|
|
26316
|
-
|
|
26317
|
-
|
|
26318
|
-
|
|
26398
|
+
join28(baseDir, "evidence.json"),
|
|
26399
|
+
join28(baseDir, "evidence.settlement.json"),
|
|
26400
|
+
join28(admitted.runDirectory, "evidence.settlement.json")
|
|
26319
26401
|
] : [
|
|
26320
|
-
|
|
26321
|
-
|
|
26402
|
+
join28(baseDir, "evidence.settlement.json"),
|
|
26403
|
+
join28(baseDir, "evidence.json")
|
|
26322
26404
|
];
|
|
26323
26405
|
const errorPayloadBase = {
|
|
26324
26406
|
kind: "error",
|
|
@@ -26494,10 +26576,10 @@ function presentFailureTerminal(terminal, io) {
|
|
|
26494
26576
|
}
|
|
26495
26577
|
function defaultNavigatorGraceSleep() {
|
|
26496
26578
|
let timer;
|
|
26497
|
-
const sleep2 = ((ms) => new Promise((
|
|
26579
|
+
const sleep2 = ((ms) => new Promise((resolve12) => {
|
|
26498
26580
|
timer = setTimeout(() => {
|
|
26499
26581
|
timer = void 0;
|
|
26500
|
-
|
|
26582
|
+
resolve12();
|
|
26501
26583
|
}, ms);
|
|
26502
26584
|
}));
|
|
26503
26585
|
sleep2.cancel = () => {
|
|
@@ -26509,7 +26591,7 @@ function defaultNavigatorGraceSleep() {
|
|
|
26509
26591
|
return sleep2;
|
|
26510
26592
|
}
|
|
26511
26593
|
function raceNavigatorGrace(work, graceMs = NAVIGATOR_POST_ROLE_GRACE_MS, sleep2 = defaultNavigatorGraceSleep()) {
|
|
26512
|
-
return new Promise((
|
|
26594
|
+
return new Promise((resolve12, reject) => {
|
|
26513
26595
|
let settled = false;
|
|
26514
26596
|
const finish = (action) => {
|
|
26515
26597
|
if (settled) return;
|
|
@@ -26518,11 +26600,11 @@ function raceNavigatorGrace(work, graceMs = NAVIGATOR_POST_ROLE_GRACE_MS, sleep2
|
|
|
26518
26600
|
action();
|
|
26519
26601
|
};
|
|
26520
26602
|
void work.then(
|
|
26521
|
-
(value) => finish(() =>
|
|
26603
|
+
(value) => finish(() => resolve12({ status: "done", value })),
|
|
26522
26604
|
(error) => finish(() => reject(error))
|
|
26523
26605
|
);
|
|
26524
26606
|
void sleep2(graceMs).then(() => {
|
|
26525
|
-
finish(() =>
|
|
26607
|
+
finish(() => resolve12({ status: "timeout" }));
|
|
26526
26608
|
});
|
|
26527
26609
|
});
|
|
26528
26610
|
}
|
|
@@ -26600,7 +26682,7 @@ var init_settlement = __esm({
|
|
|
26600
26682
|
import { constants as fsConstants2 } from "node:fs";
|
|
26601
26683
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
26602
26684
|
import { lstat as lstat6, mkdir as mkdir3, open as open2 } from "node:fs/promises";
|
|
26603
|
-
import { join as
|
|
26685
|
+
import { join as join29 } from "node:path";
|
|
26604
26686
|
async function persistReturnedRunState(admitted, authority, options) {
|
|
26605
26687
|
if (options?.lawful === true) {
|
|
26606
26688
|
await markRunTerminal(admitted.runDirectory);
|
|
@@ -26671,7 +26753,7 @@ function jsonSafeReplacer() {
|
|
|
26671
26753
|
};
|
|
26672
26754
|
}
|
|
26673
26755
|
async function writeHardenedArtifactFile(artifactsDir, namePrefix, payload) {
|
|
26674
|
-
const filePath =
|
|
26756
|
+
const filePath = join29(artifactsDir, `${namePrefix}-${randomUUID5()}.json`);
|
|
26675
26757
|
const body = `${JSON.stringify(payload, jsonSafeReplacer(), 2)}
|
|
26676
26758
|
`;
|
|
26677
26759
|
const noFollowFlag = typeof fsConstants2.O_NOFOLLOW === "number" ? fsConstants2.O_NOFOLLOW : 0;
|
|
@@ -26960,7 +27042,7 @@ var init_auto_resume = __esm({
|
|
|
26960
27042
|
// src/public-cli/post-admission.ts
|
|
26961
27043
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
26962
27044
|
import { writeFile as writeFile8 } from "node:fs/promises";
|
|
26963
|
-
import { isAbsolute as isAbsolute8, join as
|
|
27045
|
+
import { isAbsolute as isAbsolute8, join as join30, resolve as resolve9 } from "node:path";
|
|
26964
27046
|
function describeCaughtError(error) {
|
|
26965
27047
|
if (error instanceof Error) {
|
|
26966
27048
|
const code = error.code;
|
|
@@ -27050,7 +27132,7 @@ async function recordBestEffortPostDispatchDiagnostic(admitted, env, diagnostic,
|
|
|
27050
27132
|
try {
|
|
27051
27133
|
const artifactsDir = await ensureRealArtifactsDirectory(admitted.runDirectory);
|
|
27052
27134
|
await writeFile8(
|
|
27053
|
-
|
|
27135
|
+
join30(artifactsDir, `post-admission-diagnostic-${randomUUID6()}.json`),
|
|
27054
27136
|
`${JSON.stringify({ version: 1, ...payload }, null, 2)}
|
|
27055
27137
|
`,
|
|
27056
27138
|
{ encoding: "utf8", flag: "wx" }
|
|
@@ -27215,7 +27297,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
27215
27297
|
const rows = await readRecordedSubmissionRows(
|
|
27216
27298
|
admitted.projectRoot,
|
|
27217
27299
|
admitted.runId,
|
|
27218
|
-
{ home: homeFromRunDirectory(admitted.runDirectory), sessionParent:
|
|
27300
|
+
{ home: homeFromRunDirectory(admitted.runDirectory), sessionParent: join30(admitted.runDirectory, "session", "session.jsonl") }
|
|
27219
27301
|
);
|
|
27220
27302
|
const asserted = rows.filter((row) => row.kind === "accepted" && row.role === admitted.role).map((row) => row.accepted).find((payload) => {
|
|
27221
27303
|
if (payload === null || typeof payload !== "object" || Array.isArray(payload)) return false;
|
|
@@ -27370,7 +27452,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
27370
27452
|
let stderrLogWriteFailure;
|
|
27371
27453
|
try {
|
|
27372
27454
|
await writeFile8(
|
|
27373
|
-
|
|
27455
|
+
join30(admitted.runDirectory, "stderr.log"),
|
|
27374
27456
|
result.stderr,
|
|
27375
27457
|
"utf8"
|
|
27376
27458
|
);
|
|
@@ -27646,8 +27728,8 @@ async function dispatchAfterWriterLease(input) {
|
|
|
27646
27728
|
}
|
|
27647
27729
|
}
|
|
27648
27730
|
function isAlreadyFrozenSummonsAttachment(runDirectory, attachmentPath) {
|
|
27649
|
-
const absolute = isAbsolute8(attachmentPath) ? attachmentPath :
|
|
27650
|
-
return pathContainedIn(
|
|
27731
|
+
const absolute = isAbsolute8(attachmentPath) ? attachmentPath : resolve9(attachmentPath);
|
|
27732
|
+
return pathContainedIn(join30(runDirectory, "attachments"), absolute);
|
|
27651
27733
|
}
|
|
27652
27734
|
async function prepareSummonsResumeMaterials(runDirectory, summons) {
|
|
27653
27735
|
if (summons === void 0) return void 0;
|
|
@@ -28078,7 +28160,7 @@ __export(public_role_summons_exports, {
|
|
|
28078
28160
|
import { execFile as execFile3 } from "node:child_process";
|
|
28079
28161
|
import { existsSync as existsSync9 } from "node:fs";
|
|
28080
28162
|
import { realpath as realpath6 } from "node:fs/promises";
|
|
28081
|
-
import { join as
|
|
28163
|
+
import { join as join31 } from "node:path";
|
|
28082
28164
|
import { promisify as promisify3 } from "node:util";
|
|
28083
28165
|
function createCapturingIo() {
|
|
28084
28166
|
const chunks = [];
|
|
@@ -28102,7 +28184,7 @@ function parentDir(path) {
|
|
|
28102
28184
|
function walkPackageRoot(start) {
|
|
28103
28185
|
let dir = start;
|
|
28104
28186
|
for (let i = 0; i < 12; i += 1) {
|
|
28105
|
-
if (existsSync9(
|
|
28187
|
+
if (existsSync9(join31(dir, "package.json")) && existsSync9(join31(dir, "souls"))) {
|
|
28106
28188
|
return dir;
|
|
28107
28189
|
}
|
|
28108
28190
|
const parent = parentDir(dir);
|
|
@@ -28218,7 +28300,7 @@ async function createSummonEnv(options, afterHost) {
|
|
|
28218
28300
|
async function summonPublicRole(options) {
|
|
28219
28301
|
const packageRoot2 = resolveSummonsPackageRoot(options.packageRoot);
|
|
28220
28302
|
const home = await resolveSummonHome(options);
|
|
28221
|
-
const agentDir = options.agentDir ?? process.env.PI_CODING_AGENT_DIR ??
|
|
28303
|
+
const agentDir = options.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? join31(home, ".pi", "agent");
|
|
28222
28304
|
const {
|
|
28223
28305
|
loadCredentialProviders: loadCredentialProviders2,
|
|
28224
28306
|
loadPublicCliConfig: loadPublicCliConfig2,
|
|
@@ -28682,13 +28764,15 @@ async function invokeCourtDiarist(input, env, io) {
|
|
|
28682
28764
|
identity: {
|
|
28683
28765
|
kind: "escalate",
|
|
28684
28766
|
diagnostic: courtDiaristEscalateDiagnostic(roleOutcome, submissions)
|
|
28685
|
-
}
|
|
28767
|
+
},
|
|
28768
|
+
...result.admitted === void 0 ? {} : { admitted: result.admitted }
|
|
28686
28769
|
};
|
|
28687
28770
|
}
|
|
28688
28771
|
if (result.exitCode !== 0) {
|
|
28689
28772
|
const diagnostic = roleOutcome?.kind === "failure" ? roleOutcome.diagnostic : result.stderr?.trim() || `exit ${result.exitCode}`;
|
|
28690
28773
|
return {
|
|
28691
28774
|
identity: { kind: "unbound" },
|
|
28775
|
+
...result.admitted === void 0 ? {} : { admitted: result.admitted },
|
|
28692
28776
|
failedWithoutEscalate: {
|
|
28693
28777
|
diagnostic: `court diarist station failed for ${input.failureLabel}: ${diagnostic}`
|
|
28694
28778
|
}
|
|
@@ -28706,11 +28790,13 @@ async function invokeCourtDiarist(input, env, io) {
|
|
|
28706
28790
|
kind: "ticket",
|
|
28707
28791
|
ticketNumber: asserted,
|
|
28708
28792
|
...courtTicketNumbers === void 0 ? {} : { courtTicketNumbers }
|
|
28709
|
-
}
|
|
28793
|
+
},
|
|
28794
|
+
...result.admitted === void 0 ? {} : { admitted: result.admitted }
|
|
28710
28795
|
};
|
|
28711
28796
|
}
|
|
28712
28797
|
return {
|
|
28713
|
-
identity: { kind: "unbound" }
|
|
28798
|
+
identity: { kind: "unbound" },
|
|
28799
|
+
...result.admitted === void 0 ? {} : { admitted: result.admitted }
|
|
28714
28800
|
};
|
|
28715
28801
|
}
|
|
28716
28802
|
async function runCountersignCourtDiaristStation(admitted, env, io) {
|
|
@@ -28770,7 +28856,7 @@ __export(instruction_seat_run_exports, {
|
|
|
28770
28856
|
runPublicInstructionSeat: () => runPublicInstructionSeat,
|
|
28771
28857
|
runPublicInstructionSeatResume: () => runPublicInstructionSeatResume
|
|
28772
28858
|
});
|
|
28773
|
-
import { resolve as
|
|
28859
|
+
import { resolve as resolve10, sep as sep5 } from "node:path";
|
|
28774
28860
|
function roleRecord(role) {
|
|
28775
28861
|
const record4 = packagedRoleMetadata(role);
|
|
28776
28862
|
if (record4 === void 0) {
|
|
@@ -28931,7 +29017,7 @@ async function runOmittedLensBatch(argv2, parsed, env, io) {
|
|
|
28931
29017
|
const children = await summonParallelReviewerLenses2({
|
|
28932
29018
|
argv: argv2,
|
|
28933
29019
|
cwd: env.cwd,
|
|
28934
|
-
projectRoot:
|
|
29020
|
+
projectRoot: resolve10(parsed.project ?? env.cwd),
|
|
28935
29021
|
baseRevision: parsed.baseRevision ?? "",
|
|
28936
29022
|
home: env.home,
|
|
28937
29023
|
agentDir: env.agentDir,
|
|
@@ -28989,7 +29075,7 @@ async function runCountersignBody(parsed, env, io) {
|
|
|
28989
29075
|
const resumeInstruction = env.reviewReask ?? env.gateReviewInstruction ?? parsed.instruction ?? "";
|
|
28990
29076
|
const resumed = await tryResumeSameTicketSeatRun({
|
|
28991
29077
|
home: env.home,
|
|
28992
|
-
projectRoot:
|
|
29078
|
+
projectRoot: resolve10(parsed.project ?? env.cwd),
|
|
28993
29079
|
role: "countersign",
|
|
28994
29080
|
parentRunPath: gateParentRunPath,
|
|
28995
29081
|
...env.boundTicketNumber === void 0 ? {} : { ticketNumber: env.boundTicketNumber },
|
|
@@ -29029,6 +29115,7 @@ async function runCountersignBody(parsed, env, io) {
|
|
|
29029
29115
|
let typedTicket;
|
|
29030
29116
|
let typedCourtTicketNumbers;
|
|
29031
29117
|
let identityDiaristRan = false;
|
|
29118
|
+
let unboundDiaristRunId;
|
|
29032
29119
|
if (env.runCourtDiaristStation === void 0) {
|
|
29033
29120
|
let outcome;
|
|
29034
29121
|
try {
|
|
@@ -29051,11 +29138,15 @@ async function runCountersignBody(parsed, env, io) {
|
|
|
29051
29138
|
}, seatAdapters(admitted, env), env.principalAuthority, io);
|
|
29052
29139
|
}
|
|
29053
29140
|
identityDiaristRan = true;
|
|
29141
|
+
if (outcome.admitted?.runDirectory.includes(`${sep5}unbound${sep5}runs${sep5}`)) {
|
|
29142
|
+
unboundDiaristRunId = outcome.admitted.runId;
|
|
29143
|
+
}
|
|
29054
29144
|
if (outcome.identity.kind === "escalate" || outcome.failedWithoutEscalate !== void 0) {
|
|
29055
29145
|
const diagnostic = outcome.identity.kind === "escalate" ? outcome.identity.diagnostic : outcome.failedWithoutEscalate?.diagnostic ?? "";
|
|
29056
29146
|
await materializeAdmission(
|
|
29057
29147
|
isSafePositiveTicketNumber(env.boundTicketNumber) ? env.boundTicketNumber : void 0
|
|
29058
29148
|
);
|
|
29149
|
+
if (unboundDiaristRunId !== void 0) await recordChildDiaristRun(admitted, unboundDiaristRunId);
|
|
29059
29150
|
await markRunAdmitted(admitted, env.principalAuthority);
|
|
29060
29151
|
return await presentControlledFailure2(admitted, {
|
|
29061
29152
|
timedOut: false,
|
|
@@ -29073,6 +29164,9 @@ async function runCountersignBody(parsed, env, io) {
|
|
|
29073
29164
|
}
|
|
29074
29165
|
await materializeAdmission(typedTicket);
|
|
29075
29166
|
await markRunAdmitted(admitted, env.principalAuthority);
|
|
29167
|
+
if (unboundDiaristRunId !== void 0) {
|
|
29168
|
+
await recordChildDiaristRun(admitted, unboundDiaristRunId);
|
|
29169
|
+
}
|
|
29076
29170
|
if (gateParentRunPath !== void 0) {
|
|
29077
29171
|
await persistAdmittedSourceRunPath(admitted, gateParentRunPath);
|
|
29078
29172
|
admitted = { ...admitted, sourceRunPath: gateParentRunPath };
|
|
@@ -29317,6 +29411,9 @@ async function runPublicInstructionSeat(argv2, env, io, role, parseArgv2) {
|
|
|
29317
29411
|
...env.signal === void 0 ? {} : { signal: env.signal },
|
|
29318
29412
|
...env.hostAdapters === void 0 ? {} : { hostAdapters: env.hostAdapters }
|
|
29319
29413
|
}, io);
|
|
29414
|
+
if (outcome.admitted?.runDirectory.includes(`${sep5}unbound${sep5}runs${sep5}`)) {
|
|
29415
|
+
await recordChildDiaristRun(admitted, outcome.admitted.runId);
|
|
29416
|
+
}
|
|
29320
29417
|
if (outcome.identity.kind === "escalate" || outcome.failedWithoutEscalate !== void 0) {
|
|
29321
29418
|
const diagnostic = outcome.identity.kind === "escalate" ? outcome.identity.diagnostic : outcome.failedWithoutEscalate?.diagnostic ?? "";
|
|
29322
29419
|
return await presentControlledFailure2(admitted, {
|
|
@@ -29328,6 +29425,9 @@ async function runPublicInstructionSeat(argv2, env, io, role, parseArgv2) {
|
|
|
29328
29425
|
}
|
|
29329
29426
|
if (outcome.identity.kind === "ticket") {
|
|
29330
29427
|
try {
|
|
29428
|
+
if (outcome.admitted === void 0) throw new Error("court diarist ticket has no admitted run");
|
|
29429
|
+
await bindAdmittedTicketNumber(outcome.admitted, outcome.identity.ticketNumber);
|
|
29430
|
+
await relocateAdmittedRunToTicket(outcome.admitted, env.principalAuthority);
|
|
29331
29431
|
await bindAdmittedTicketNumber(admitted, outcome.identity.ticketNumber);
|
|
29332
29432
|
await relocateAdmittedRunToTicket(admitted, env.principalAuthority);
|
|
29333
29433
|
} catch (error) {
|
|
@@ -29459,10 +29559,10 @@ var init_analyst_book_key = __esm({
|
|
|
29459
29559
|
// src/atomic-write.ts
|
|
29460
29560
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
29461
29561
|
import { rename as rename3, rm as rm4, writeFile as writeFile9 } from "node:fs/promises";
|
|
29462
|
-
import { dirname as
|
|
29562
|
+
import { dirname as dirname17, join as join32 } from "node:path";
|
|
29463
29563
|
async function writeFileAtomically(destination, contents) {
|
|
29464
|
-
const parent =
|
|
29465
|
-
const temporary =
|
|
29564
|
+
const parent = dirname17(destination);
|
|
29565
|
+
const temporary = join32(parent, `.atomic-write-${randomUUID7()}.tmp`);
|
|
29466
29566
|
try {
|
|
29467
29567
|
await writeFile9(temporary, contents);
|
|
29468
29568
|
await rename3(temporary, destination);
|
|
@@ -29478,17 +29578,17 @@ var init_atomic_write = __esm({
|
|
|
29478
29578
|
});
|
|
29479
29579
|
|
|
29480
29580
|
// src/analyst-index.ts
|
|
29481
|
-
import { open as open3, readFile as
|
|
29482
|
-
import { dirname as
|
|
29581
|
+
import { open as open3, readFile as readFile19, unlink as unlink5 } from "node:fs/promises";
|
|
29582
|
+
import { dirname as dirname18, join as join33 } from "node:path";
|
|
29483
29583
|
function sleep(ms) {
|
|
29484
|
-
return new Promise((
|
|
29485
|
-
setTimeout(
|
|
29584
|
+
return new Promise((resolve12) => {
|
|
29585
|
+
setTimeout(resolve12, ms);
|
|
29486
29586
|
});
|
|
29487
29587
|
}
|
|
29488
29588
|
async function withAnalystLibraryIndexLock(ledgerHome, fn) {
|
|
29489
29589
|
const indexPath = analystLibraryIndexPath(ledgerHome);
|
|
29490
|
-
ensureRealDirectoryTree(ledgerHome,
|
|
29491
|
-
const lockPath =
|
|
29590
|
+
ensureRealDirectoryTree(ledgerHome, dirname18(indexPath));
|
|
29591
|
+
const lockPath = join33(dirname18(indexPath), LIBRARY_INDEX_LOCK_NAME);
|
|
29492
29592
|
assertLedgerFileInsideHome(lockPath, ledgerHome);
|
|
29493
29593
|
const startedAt = Date.now();
|
|
29494
29594
|
while (true) {
|
|
@@ -29500,7 +29600,7 @@ async function withAnalystLibraryIndexLock(ledgerHome, fn) {
|
|
|
29500
29600
|
return await fn();
|
|
29501
29601
|
} finally {
|
|
29502
29602
|
await handle.close().catch(() => void 0);
|
|
29503
|
-
await
|
|
29603
|
+
await unlink5(lockPath).catch(() => void 0);
|
|
29504
29604
|
}
|
|
29505
29605
|
} catch (error) {
|
|
29506
29606
|
const code = error instanceof Error && "code" in error ? error.code : void 0;
|
|
@@ -29515,7 +29615,7 @@ async function withAnalystLibraryIndexLock(ledgerHome, fn) {
|
|
|
29515
29615
|
}
|
|
29516
29616
|
}
|
|
29517
29617
|
function analystLibraryIndexPath(ledgerHome) {
|
|
29518
|
-
return
|
|
29618
|
+
return join33(ledgerHome, "analyst", "library-index.json");
|
|
29519
29619
|
}
|
|
29520
29620
|
function rowFromIssueMetricsPage(page) {
|
|
29521
29621
|
return {
|
|
@@ -29606,7 +29706,7 @@ async function readAnalystLibraryIndexPage(ledgerHome) {
|
|
|
29606
29706
|
const path = analystLibraryIndexPath(ledgerHome);
|
|
29607
29707
|
let raw;
|
|
29608
29708
|
try {
|
|
29609
|
-
raw = await
|
|
29709
|
+
raw = await readFile19(path, "utf8");
|
|
29610
29710
|
} catch (error) {
|
|
29611
29711
|
if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
|
|
29612
29712
|
return void 0;
|
|
@@ -29624,7 +29724,7 @@ async function readAnalystLibraryIndexPage(ledgerHome) {
|
|
|
29624
29724
|
}
|
|
29625
29725
|
async function writeAnalystLibraryIndexPage(ledgerHome, page) {
|
|
29626
29726
|
const path = analystLibraryIndexPath(ledgerHome);
|
|
29627
|
-
ensureRealDirectoryTree(ledgerHome,
|
|
29727
|
+
ensureRealDirectoryTree(ledgerHome, dirname18(path));
|
|
29628
29728
|
assertLedgerFileInsideHome(path, ledgerHome);
|
|
29629
29729
|
await writeFileAtomically(path, `${JSON.stringify(page, null, 2)}
|
|
29630
29730
|
`);
|
|
@@ -29810,8 +29910,8 @@ var init_analyst_cohort = __esm({
|
|
|
29810
29910
|
});
|
|
29811
29911
|
|
|
29812
29912
|
// src/analyst-ledger.ts
|
|
29813
|
-
import { readdir as readdir8, readFile as
|
|
29814
|
-
import { basename as
|
|
29913
|
+
import { readdir as readdir8, readFile as readFile20 } from "node:fs/promises";
|
|
29914
|
+
import { basename as basename9, join as join34 } from "node:path";
|
|
29815
29915
|
function isMissingPathError6(error) {
|
|
29816
29916
|
return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
|
|
29817
29917
|
}
|
|
@@ -29824,7 +29924,7 @@ function isRecord12(value) {
|
|
|
29824
29924
|
async function readExistingRunLifecycleState(runDirectory) {
|
|
29825
29925
|
try {
|
|
29826
29926
|
const raw = JSON.parse(
|
|
29827
|
-
await
|
|
29927
|
+
await readFile20(join34(runDirectory, "run-state.json"), "utf8")
|
|
29828
29928
|
);
|
|
29829
29929
|
if (!isRecord12(raw) || typeof raw.state !== "string") return void 0;
|
|
29830
29930
|
return raw.state;
|
|
@@ -29848,7 +29948,7 @@ function ghostLeaseCheckFromAutopsy(autopsy) {
|
|
|
29848
29948
|
}
|
|
29849
29949
|
}
|
|
29850
29950
|
async function classifyGhostCandidate(input) {
|
|
29851
|
-
const autopsy = await autopsyWriterLock(
|
|
29951
|
+
const autopsy = await autopsyWriterLock(join34(input.runDirectory, "writer.lock"));
|
|
29852
29952
|
const leaseCheck = ghostLeaseCheckFromAutopsy(autopsy);
|
|
29853
29953
|
if (leaseCheck === void 0) return { kind: "live" };
|
|
29854
29954
|
return {
|
|
@@ -29884,7 +29984,7 @@ async function listLedgerBookNames(booksRoot) {
|
|
|
29884
29984
|
async function readInvocationScopeFields(runDirectory) {
|
|
29885
29985
|
let raw;
|
|
29886
29986
|
try {
|
|
29887
|
-
raw = await
|
|
29987
|
+
raw = await readFile20(join34(runDirectory, "invocation.json"), "utf8");
|
|
29888
29988
|
} catch (error) {
|
|
29889
29989
|
if (isMissingPathError6(error)) return void 0;
|
|
29890
29990
|
throw error;
|
|
@@ -29917,7 +30017,7 @@ function decideIssueScope(input) {
|
|
|
29917
30017
|
}
|
|
29918
30018
|
async function resolveSessionFile(runDirectory) {
|
|
29919
30019
|
try {
|
|
29920
|
-
const raw = await
|
|
30020
|
+
const raw = await readFile20(join34(runDirectory, "invocation.json"), "utf8");
|
|
29921
30021
|
const parsed = JSON.parse(raw);
|
|
29922
30022
|
if (isRecord12(parsed) && typeof parsed.sessionFile === "string" && parsed.sessionFile.trim() !== "") {
|
|
29923
30023
|
return parsed.sessionFile;
|
|
@@ -29925,7 +30025,7 @@ async function resolveSessionFile(runDirectory) {
|
|
|
29925
30025
|
} catch (error) {
|
|
29926
30026
|
if (!isMissingPathError6(error)) throw error;
|
|
29927
30027
|
}
|
|
29928
|
-
return
|
|
30028
|
+
return join34(runDirectory, "session", "session.jsonl");
|
|
29929
30029
|
}
|
|
29930
30030
|
function attributeSessionRowsForRun(input) {
|
|
29931
30031
|
if (pathContainedIn(input.runDirectory, input.sessionFile)) {
|
|
@@ -30111,9 +30211,9 @@ async function classifyScopedRun(input) {
|
|
|
30111
30211
|
}
|
|
30112
30212
|
let gateCycles;
|
|
30113
30213
|
try {
|
|
30114
|
-
const parentSessionFile =
|
|
30214
|
+
const parentSessionFile = join34(input.runDirectory, "session", "session.jsonl");
|
|
30115
30215
|
gateCycles = await readAnalystGateCyclesFromAuditorRoles(
|
|
30116
|
-
|
|
30216
|
+
join34(input.runDirectory, "session", "auditor-roles"),
|
|
30117
30217
|
{ parentSessionFile }
|
|
30118
30218
|
);
|
|
30119
30219
|
} catch (error) {
|
|
@@ -30148,7 +30248,7 @@ async function classifyScopedRun(input) {
|
|
|
30148
30248
|
async function scanAnalystIssueRuns(input) {
|
|
30149
30249
|
const ledgerHome = resolveActivationLedgerHome(input.home);
|
|
30150
30250
|
const scopeTicketNumber = input.ticketNumber;
|
|
30151
|
-
const booksRoot =
|
|
30251
|
+
const booksRoot = join34(ledgerHome, "books");
|
|
30152
30252
|
let wholeBook = false;
|
|
30153
30253
|
let scopeRootIdentity;
|
|
30154
30254
|
let bookNames;
|
|
@@ -30181,7 +30281,7 @@ async function scanAnalystIssueRuns(input) {
|
|
|
30181
30281
|
const ghostLegs = [];
|
|
30182
30282
|
const scopeConflicts = [];
|
|
30183
30283
|
for (const book of bookNames) {
|
|
30184
|
-
const bookDir =
|
|
30284
|
+
const bookDir = join34(booksRoot, book);
|
|
30185
30285
|
let runDirectories;
|
|
30186
30286
|
try {
|
|
30187
30287
|
runDirectories = await listBookRunDirectories(bookDir);
|
|
@@ -30190,7 +30290,7 @@ async function scanAnalystIssueRuns(input) {
|
|
|
30190
30290
|
throw error;
|
|
30191
30291
|
}
|
|
30192
30292
|
for (const runDirectory of runDirectories) {
|
|
30193
|
-
const runName =
|
|
30293
|
+
const runName = basename9(runDirectory);
|
|
30194
30294
|
const parsed = parseRunDirectoryName2(runName);
|
|
30195
30295
|
if (parsed === void 0) continue;
|
|
30196
30296
|
let scopeFields;
|
|
@@ -31058,7 +31158,7 @@ var init_analyst_metric_family = __esm({
|
|
|
31058
31158
|
|
|
31059
31159
|
// src/analyst-page.ts
|
|
31060
31160
|
import { createHash as createHash5 } from "node:crypto";
|
|
31061
|
-
import { dirname as
|
|
31161
|
+
import { dirname as dirname19, join as join35 } from "node:path";
|
|
31062
31162
|
function analystIssuePageKey(address) {
|
|
31063
31163
|
const parts = ["book", address.bookKey];
|
|
31064
31164
|
if (address.issueNumber !== void 0) {
|
|
@@ -31069,7 +31169,7 @@ function analystIssuePageKey(address) {
|
|
|
31069
31169
|
return createHash5("sha256").update(parts.join("\0")).digest("hex").slice(0, 32);
|
|
31070
31170
|
}
|
|
31071
31171
|
function analystIssuePagePath(ledgerHome, address) {
|
|
31072
|
-
return
|
|
31172
|
+
return join35(ledgerHome, "analyst", "issues", `${analystIssuePageKey(address)}.json`);
|
|
31073
31173
|
}
|
|
31074
31174
|
function analystIssuePageAddressFromPage(page) {
|
|
31075
31175
|
return {
|
|
@@ -31188,7 +31288,7 @@ async function buildAnalystIssueMetricsPage(input) {
|
|
|
31188
31288
|
}
|
|
31189
31289
|
async function writeAnalystIssueMetricsPage(ledgerHome, page) {
|
|
31190
31290
|
const path = analystIssuePagePath(ledgerHome, analystIssuePageAddressFromPage(page));
|
|
31191
|
-
ensureRealDirectoryTree(ledgerHome,
|
|
31291
|
+
ensureRealDirectoryTree(ledgerHome, dirname19(path));
|
|
31192
31292
|
assertLedgerFileInsideHome(path, ledgerHome);
|
|
31193
31293
|
await writeFileAtomically(path, `${JSON.stringify(page, null, 2)}
|
|
31194
31294
|
`);
|
|
@@ -31205,7 +31305,7 @@ var init_analyst_page = __esm({
|
|
|
31205
31305
|
});
|
|
31206
31306
|
|
|
31207
31307
|
// src/analyst-entry.ts
|
|
31208
|
-
import { readFile as
|
|
31308
|
+
import { readFile as readFile21 } from "node:fs/promises";
|
|
31209
31309
|
function isMissingPathError7(error) {
|
|
31210
31310
|
return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
|
|
31211
31311
|
}
|
|
@@ -31235,7 +31335,7 @@ async function readOrComputeAnalystIssuePage(input, options) {
|
|
|
31235
31335
|
...issueNumber === void 0 && input.bookKey === void 0 ? { scopeRootIdentity: projectRoot } : {}
|
|
31236
31336
|
});
|
|
31237
31337
|
try {
|
|
31238
|
-
const raw = await
|
|
31338
|
+
const raw = await readFile21(pagePath, "utf8");
|
|
31239
31339
|
const page = JSON.parse(raw);
|
|
31240
31340
|
if (cachedPageMatchesRequestedScope(page, { bookKey, ...input })) {
|
|
31241
31341
|
const ghostScan = await scanAnalystIssueRuns({
|
|
@@ -31336,7 +31436,7 @@ async function runAnalystModelGroupsMode(input, home) {
|
|
|
31336
31436
|
scopeRootIdentity: projectRoot
|
|
31337
31437
|
});
|
|
31338
31438
|
try {
|
|
31339
|
-
const raw = await
|
|
31439
|
+
const raw = await readFile21(pagePath, "utf8");
|
|
31340
31440
|
JSON.parse(raw);
|
|
31341
31441
|
} catch (error) {
|
|
31342
31442
|
if (!isMissingPathError7(error)) {
|
|
@@ -31435,8 +31535,8 @@ var init_analyst_entry = __esm({
|
|
|
31435
31535
|
});
|
|
31436
31536
|
|
|
31437
31537
|
// src/public-cli/analyst-run.ts
|
|
31438
|
-
import { readFile as
|
|
31439
|
-
import { isAbsolute as isAbsolute10, resolve as
|
|
31538
|
+
import { readFile as readFile22 } from "node:fs/promises";
|
|
31539
|
+
import { isAbsolute as isAbsolute10, resolve as resolve11 } from "node:path";
|
|
31440
31540
|
function resolveAnalystIssueBookKeyFromCwd(cwd = process.cwd()) {
|
|
31441
31541
|
try {
|
|
31442
31542
|
return resolveBookKeyFromGit(cwd);
|
|
@@ -31485,10 +31585,10 @@ async function buildAnalystSweepModeInputFromAttachmentPaths(attachmentPaths) {
|
|
|
31485
31585
|
);
|
|
31486
31586
|
}
|
|
31487
31587
|
const sourcePath = attachmentPaths[0];
|
|
31488
|
-
const absolute = isAbsolute10(sourcePath) ? sourcePath :
|
|
31588
|
+
const absolute = isAbsolute10(sourcePath) ? sourcePath : resolve11(sourcePath);
|
|
31489
31589
|
let bytes;
|
|
31490
31590
|
try {
|
|
31491
|
-
bytes = await
|
|
31591
|
+
bytes = await readFile22(absolute);
|
|
31492
31592
|
} catch (error) {
|
|
31493
31593
|
throw new CliUsageError(
|
|
31494
31594
|
`analyst sweep attachment is not a readable regular file: ${sourcePath}`,
|
|
@@ -31609,7 +31709,7 @@ __export(cli_exports, {
|
|
|
31609
31709
|
runAkRole: () => runAkRole
|
|
31610
31710
|
});
|
|
31611
31711
|
import { realpath as realpath7 } from "node:fs/promises";
|
|
31612
|
-
import { join as
|
|
31712
|
+
import { join as join36 } from "node:path";
|
|
31613
31713
|
function publicSeatArgv(owner) {
|
|
31614
31714
|
return {
|
|
31615
31715
|
parse: (args) => parsePublicSeatArgv(owner, args),
|
|
@@ -31748,7 +31848,7 @@ function resolveHome(env) {
|
|
|
31748
31848
|
return env.home ?? packageMachineHome();
|
|
31749
31849
|
}
|
|
31750
31850
|
function resolveAgentDir(env, home) {
|
|
31751
|
-
return env.agentDir ?? process.env.PI_CODING_AGENT_DIR ??
|
|
31851
|
+
return env.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? join36(home, ".pi", "agent");
|
|
31752
31852
|
}
|
|
31753
31853
|
function parseThinking(value) {
|
|
31754
31854
|
return value;
|
|
@@ -32462,7 +32562,7 @@ var init_cli = __esm({
|
|
|
32462
32562
|
|
|
32463
32563
|
// src/public-cli/main.ts
|
|
32464
32564
|
import { existsSync as existsSync10 } from "node:fs";
|
|
32465
|
-
import { dirname as
|
|
32565
|
+
import { dirname as dirname20, join as join37 } from "node:path";
|
|
32466
32566
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
32467
32567
|
|
|
32468
32568
|
// src/public-cli/host-pi-runtime.ts
|
|
@@ -32549,10 +32649,10 @@ function linkPackage(packageRoot2, name, targetDir) {
|
|
|
32549
32649
|
}
|
|
32550
32650
|
|
|
32551
32651
|
// src/public-cli/main.ts
|
|
32552
|
-
var here =
|
|
32652
|
+
var here = dirname20(fileURLToPath2(import.meta.url));
|
|
32553
32653
|
function resolvePackageRoot(binDir) {
|
|
32554
|
-
const canonical =
|
|
32555
|
-
if (existsSync10(
|
|
32654
|
+
const canonical = join37(binDir, "..", "..");
|
|
32655
|
+
if (existsSync10(join37(canonical, "package.json"))) {
|
|
32556
32656
|
return canonical;
|
|
32557
32657
|
}
|
|
32558
32658
|
return binDir;
|