pi-fabric 0.131.1 → 0.131.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/activity/store.d.ts.map +1 -1
- package/dist/actors/global-registry.d.ts.map +1 -1
- package/dist/actors/manager.d.ts.map +1 -1
- package/dist/agents/manager.d.ts.map +1 -1
- package/dist/agents/request.d.ts.map +1 -1
- package/dist/agents/transports/herdr-core-socket.d.ts +13 -0
- package/dist/agents/transports/herdr-core-socket.d.ts.map +1 -0
- package/dist/agents/transports/herdr-core-transport.d.ts +10 -0
- package/dist/agents/transports/herdr-core-transport.d.ts.map +1 -0
- package/dist/agents.js +1 -1
- package/dist/audit/details.d.ts +2 -0
- package/dist/audit/details.d.ts.map +1 -1
- package/dist/chunks/{chunk-3PKZSIRA.js → chunk-ASOJYFKU.js} +8 -4
- package/dist/chunks/chunk-ASOJYFKU.js.map +7 -0
- package/dist/chunks/{chunk-5BOTHX47.js → chunk-HKGHRPX7.js} +3 -3
- package/dist/chunks/chunk-HKGHRPX7.js.map +7 -0
- package/dist/chunks/{chunk-7CIES6X2.js → chunk-HRVYXRWZ.js} +2 -2
- package/dist/chunks/chunk-HRVYXRWZ.js.map +7 -0
- package/dist/chunks/{chunk-36XQFTEN.js → chunk-L6H46CPY.js} +2 -2
- package/dist/chunks/{chunk-4KX6BIPL.js → chunk-LRSZFYUC.js} +2 -2
- package/dist/chunks/chunk-LRSZFYUC.js.map +7 -0
- package/dist/chunks/{chunk-UFMYN5TA.js → chunk-MX53BRAC.js} +2 -2
- package/dist/chunks/{chunk-IOGDTIGN.js → chunk-QYBALDEM.js} +2 -2
- package/dist/chunks/{chunk-WWTGWGH7.js → chunk-RKJPBTBB.js} +22 -6
- package/dist/chunks/chunk-RKJPBTBB.js.map +7 -0
- package/dist/chunks/{chunk-W3N72XYK.js → chunk-SQRDHUD2.js} +70 -38
- package/dist/chunks/chunk-SQRDHUD2.js.map +7 -0
- package/dist/chunks/{chunk-YHFWMAQ5.js → chunk-TEMKDJJY.js} +151 -52
- package/dist/chunks/chunk-TEMKDJJY.js.map +7 -0
- package/dist/chunks/{chunk-ZFWICFNJ.js → chunk-UTPA2PBN.js} +6 -3
- package/dist/chunks/chunk-UTPA2PBN.js.map +7 -0
- package/dist/chunks/{chunk-VNWQIGQL.js → chunk-VGRUWTMG.js} +415 -252
- package/dist/chunks/chunk-VGRUWTMG.js.map +7 -0
- package/dist/chunks/{chunk-X7QETPBC.js → chunk-ZHROHNEE.js} +1 -1
- package/dist/commands/fabric-handler.js +1 -1
- package/dist/compaction/claim-events.js +1 -1
- package/dist/components/configuration.js +2 -2
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/core/call-presentation.d.ts +14 -0
- package/dist/core/call-presentation.d.ts.map +1 -0
- package/dist/core/shell-inbox.d.ts.map +1 -1
- package/dist/durable/agent.d.ts.map +1 -1
- package/dist/durable/worker-host.js +1 -1
- package/dist/durable-extension.d.ts +1 -1
- package/dist/durable-extension.js +1 -1
- package/dist/durable-extension.js.map +1 -1
- package/dist/durable-host.js +1 -1
- package/dist/durable.d.ts.map +1 -1
- package/dist/durable.js +5 -4
- package/dist/durable.js.map +2 -2
- package/dist/extension-bootstrap.js +5 -5
- package/dist/fabric-exec-tool.d.ts.map +1 -1
- package/dist/fabric-runtime-state.js +48 -31
- package/dist/fabric-runtime-state.js.map +2 -2
- package/dist/index.js +5 -5
- package/dist/jev.js +1 -1
- package/dist/providers/agents-provider.d.ts.map +1 -1
- package/dist/providers/jev-provider.js +1 -1
- package/dist/residency/host.js +3 -3
- package/dist/residency/pi-entry.js +3 -3
- package/dist/runtime/core-override-guest-types.js +2 -2
- package/dist/runtime/guest-types.d.ts +1 -1
- package/dist/runtime/guest-types.d.ts.map +1 -1
- package/dist/runtime/guest-types.js +1 -1
- package/dist/runtime/monty-runtime.js +1 -1
- package/dist/runtime/typescript-kernel.js +2 -2
- package/dist/topology/participant-directory.d.ts.map +1 -1
- package/dist/type-error-guidance.js +1 -1
- package/dist/ui/dashboard-model.d.ts.map +1 -1
- package/dist/ui/dashboard.js +6 -3
- package/dist/ui/dashboard.js.map +2 -2
- package/dist/ui/fabric-render.d.ts +1 -0
- package/dist/ui/fabric-render.d.ts.map +1 -1
- package/dist/ui/settings-values.d.ts +1 -1
- package/dist/ui/settings-values.d.ts.map +1 -1
- package/dist/ui/settings.js +2 -2
- package/dist/ui/settings.js.map +2 -2
- package/dist/ui/widget.d.ts +8 -4
- package/dist/ui/widget.d.ts.map +1 -1
- package/docs/agents.md +4 -1
- package/docs/background-tasks.md +24 -12
- package/docs/configuration.md +2 -0
- package/docs/interface.md +3 -1
- package/package.json +9 -9
- package/skillsets/typescript/fabric-exec/references/agents.md +1 -1
- package/dist/chunks/chunk-3PKZSIRA.js.map +0 -7
- package/dist/chunks/chunk-4KX6BIPL.js.map +0 -7
- package/dist/chunks/chunk-5BOTHX47.js.map +0 -7
- package/dist/chunks/chunk-7CIES6X2.js.map +0 -7
- package/dist/chunks/chunk-VNWQIGQL.js.map +0 -7
- package/dist/chunks/chunk-W3N72XYK.js.map +0 -7
- package/dist/chunks/chunk-WWTGWGH7.js.map +0 -7
- package/dist/chunks/chunk-YHFWMAQ5.js.map +0 -7
- package/dist/chunks/chunk-ZFWICFNJ.js.map +0 -7
- /package/dist/chunks/{chunk-36XQFTEN.js.map → chunk-L6H46CPY.js.map} +0 -0
- /package/dist/chunks/{chunk-UFMYN5TA.js.map → chunk-MX53BRAC.js.map} +0 -0
- /package/dist/chunks/{chunk-IOGDTIGN.js.map → chunk-QYBALDEM.js.map} +0 -0
- /package/dist/chunks/{chunk-X7QETPBC.js.map → chunk-ZHROHNEE.js.map} +0 -0
|
@@ -56,7 +56,7 @@ import {
|
|
|
56
56
|
DEFAULT_FABRIC_CONFIG,
|
|
57
57
|
MAX_AGENT_TIMEOUT_MS,
|
|
58
58
|
MIN_AGENT_TIMEOUT_MS
|
|
59
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-LRSZFYUC.js";
|
|
60
60
|
import {
|
|
61
61
|
readJsonlPage
|
|
62
62
|
} from "./chunk-CGPK5WHX.js";
|
|
@@ -304,10 +304,10 @@ function appendBudgetLedger(file, entry) {
|
|
|
304
304
|
}
|
|
305
305
|
|
|
306
306
|
// src/agents/manager.ts
|
|
307
|
-
import { randomUUID as
|
|
308
|
-
import
|
|
307
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
308
|
+
import fs13 from "node:fs";
|
|
309
309
|
import os3 from "node:os";
|
|
310
|
-
import
|
|
310
|
+
import path14 from "node:path";
|
|
311
311
|
import { fileURLToPath } from "node:url";
|
|
312
312
|
|
|
313
313
|
// src/agents/hosted-run.ts
|
|
@@ -971,6 +971,11 @@ var adoptedWorkerHandle = (pid, id, probes = {}) => ({
|
|
|
971
971
|
}
|
|
972
972
|
});
|
|
973
973
|
|
|
974
|
+
// src/agents/transports/herdr-core-transport.ts
|
|
975
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
976
|
+
import path5 from "node:path";
|
|
977
|
+
import fs5 from "node:fs/promises";
|
|
978
|
+
|
|
974
979
|
// src/agents/constants.ts
|
|
975
980
|
var AGENT_STATUS_POLL_INTERVAL_MS = 250;
|
|
976
981
|
var EXTERNAL_TRANSPORT_LIVENESS_POLL_INTERVAL_MS = 2e3;
|
|
@@ -979,6 +984,162 @@ var AGENT_STARTUP_RETRY_BASE_DELAY_MS = 500;
|
|
|
979
984
|
var AGENT_RESUME_MAX_ATTEMPTS = 3;
|
|
980
985
|
var AGENT_RESUME_RETRY_BASE_DELAY_MS = 1e3;
|
|
981
986
|
|
|
987
|
+
// src/agents/transports/herdr-core-socket.ts
|
|
988
|
+
import net from "node:net";
|
|
989
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
990
|
+
var HerdrCoreRpcError = class extends Error {
|
|
991
|
+
constructor(code, message2, kind) {
|
|
992
|
+
super(`Herdr Core API: ${code}: ${message2}`);
|
|
993
|
+
this.code = code;
|
|
994
|
+
this.kind = kind;
|
|
995
|
+
this.name = "HerdrCoreRpcError";
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
var herdrCoreEndpoint = (socket, platform = process.platform) => platform === "win32" && !socket.startsWith("\\\\.\\pipe\\") ? `\\\\.\\pipe\\${socket}` : socket;
|
|
999
|
+
var herdrCoreSocketRequest = (socketPath, method, params, options = {}) => new Promise((resolve, reject) => {
|
|
1000
|
+
const id = `pi-fabric:${randomUUID3()}`;
|
|
1001
|
+
const socket = net.createConnection(herdrCoreEndpoint(socketPath));
|
|
1002
|
+
const chunks = [];
|
|
1003
|
+
let bytes = 0;
|
|
1004
|
+
let settled = false;
|
|
1005
|
+
const finish = (error, result) => {
|
|
1006
|
+
if (settled) return;
|
|
1007
|
+
settled = true;
|
|
1008
|
+
clearTimeout(timer);
|
|
1009
|
+
socket.destroy();
|
|
1010
|
+
if (error) reject(error);
|
|
1011
|
+
else resolve(result);
|
|
1012
|
+
};
|
|
1013
|
+
const timer = setTimeout(() => finish(new Error("Herdr Core API request timed out")), options.timeoutMs ?? 5e3);
|
|
1014
|
+
timer.unref?.();
|
|
1015
|
+
socket.on("connect", () => socket.write(`${JSON.stringify({ jsonrpc: "2.0", id, method, params })}
|
|
1016
|
+
`));
|
|
1017
|
+
socket.on("data", (chunk) => {
|
|
1018
|
+
const newline = chunk.indexOf(10);
|
|
1019
|
+
const captured = newline < 0 ? chunk : chunk.subarray(0, newline);
|
|
1020
|
+
bytes += captured.length;
|
|
1021
|
+
if (bytes > (options.maxResponseBytes ?? 1024 * 1024)) {
|
|
1022
|
+
finish(new Error("Herdr Core API response exceeds byte limit"));
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
chunks.push(captured);
|
|
1026
|
+
if (newline < 0) return;
|
|
1027
|
+
try {
|
|
1028
|
+
const value = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
1029
|
+
if (!value || value.jsonrpc !== "2.0" || value.id !== id || Object.hasOwn(value, "result") === Object.hasOwn(value, "error")) {
|
|
1030
|
+
throw new Error("uncorrelated or invalid JSON-RPC envelope");
|
|
1031
|
+
}
|
|
1032
|
+
if (Object.hasOwn(value, "error")) {
|
|
1033
|
+
const error = value.error;
|
|
1034
|
+
if (!error || !Number.isInteger(error.code) || typeof error.message !== "string") {
|
|
1035
|
+
throw new Error("invalid JSON-RPC error");
|
|
1036
|
+
}
|
|
1037
|
+
finish(new HerdrCoreRpcError(
|
|
1038
|
+
error.code,
|
|
1039
|
+
error.message,
|
|
1040
|
+
typeof error.data?.kind === "string" ? error.data.kind : void 0
|
|
1041
|
+
));
|
|
1042
|
+
} else finish(void 0, value.result);
|
|
1043
|
+
} catch (error) {
|
|
1044
|
+
finish(new Error(`Invalid Herdr Core API response: ${error instanceof Error ? error.message : String(error)}`));
|
|
1045
|
+
}
|
|
1046
|
+
});
|
|
1047
|
+
socket.on("error", (error) => finish(error));
|
|
1048
|
+
socket.on("end", () => finish(new Error("Herdr Core API closed without a complete response")));
|
|
1049
|
+
socket.on("close", () => finish(new Error("Herdr Core API socket closed")));
|
|
1050
|
+
});
|
|
1051
|
+
|
|
1052
|
+
// src/agents/transports/herdr-core-transport.ts
|
|
1053
|
+
var missing = (error) => error instanceof HerdrCoreRpcError && error.kind === "not_found";
|
|
1054
|
+
var terminal = (value) => {
|
|
1055
|
+
const result = value;
|
|
1056
|
+
if (!result || typeof result.address !== "string" || !/^t[0-9a-z]+$/.test(result.address) || result.state !== "live" && result.state !== "finished") {
|
|
1057
|
+
throw new Error("Herdr Core returned an invalid terminal");
|
|
1058
|
+
}
|
|
1059
|
+
return { address: result.address, state: result.state };
|
|
1060
|
+
};
|
|
1061
|
+
var HerdrCoreTransport = class {
|
|
1062
|
+
constructor(environment = process.env) {
|
|
1063
|
+
this.environment = environment;
|
|
1064
|
+
}
|
|
1065
|
+
kind = "herdr-core";
|
|
1066
|
+
async available() {
|
|
1067
|
+
if (!this.environment.HC_TERMINAL_ID || !this.environment.HC_TERMINAL_SOCKET) return false;
|
|
1068
|
+
try {
|
|
1069
|
+
const hello = await this.#request("hello", { generation: 1, framed: false });
|
|
1070
|
+
return hello?.generation === 1 && hello.framed === false && Array.isArray(hello.methods) && ["terminal.run", "terminal.get", "terminal.kill"].every((method) => hello.methods.includes(method));
|
|
1071
|
+
} catch {
|
|
1072
|
+
return false;
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
async launch(request) {
|
|
1076
|
+
const caller = this.environment.HC_TERMINAL_ID;
|
|
1077
|
+
if (!caller) throw new Error("Herdr Core transport requires HC_TERMINAL_ID");
|
|
1078
|
+
const argv = await scriptSpawnArgs(request.workerPath, request.workerArguments);
|
|
1079
|
+
if (!path5.isAbsolute(argv[0])) {
|
|
1080
|
+
const names = process.platform === "win32" && !path5.extname(argv[0]) ? [argv[0], ...(this.environment.PATHEXT ?? ".EXE;.CMD;.BAT").split(";").map((ext) => argv[0] + ext)] : [argv[0]];
|
|
1081
|
+
let resolved;
|
|
1082
|
+
for (const directory of (this.environment.PATH ?? "").split(path5.delimiter).filter(Boolean)) {
|
|
1083
|
+
for (const name of names) {
|
|
1084
|
+
const candidate = path5.resolve(directory.replace(/^"|"$/g, ""), name);
|
|
1085
|
+
try {
|
|
1086
|
+
if ((await fs5.stat(candidate)).isFile()) {
|
|
1087
|
+
await fs5.access(candidate, process.platform === "win32" ? fs5.constants.F_OK : fs5.constants.X_OK);
|
|
1088
|
+
resolved = candidate;
|
|
1089
|
+
break;
|
|
1090
|
+
}
|
|
1091
|
+
} catch {
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
if (resolved) break;
|
|
1095
|
+
}
|
|
1096
|
+
if (!resolved) throw new Error("Herdr Core could not resolve an absolute worker runtime");
|
|
1097
|
+
argv[0] = resolved;
|
|
1098
|
+
}
|
|
1099
|
+
const prefix = request.name.toLowerCase().replace(/[^a-z0-9_-]+/g, "-").slice(0, 7) || "agent";
|
|
1100
|
+
const child = terminal(await this.#request("terminal.run", {
|
|
1101
|
+
argv,
|
|
1102
|
+
cwd: request.cwd,
|
|
1103
|
+
name: `${prefix}-${randomUUID4().replaceAll("-", "").slice(0, 24)}`,
|
|
1104
|
+
caller,
|
|
1105
|
+
parent: caller,
|
|
1106
|
+
no_notify: true,
|
|
1107
|
+
wait: false,
|
|
1108
|
+
keep: false,
|
|
1109
|
+
outlive_parent: false
|
|
1110
|
+
}));
|
|
1111
|
+
const params = { terminal: child.address, caller };
|
|
1112
|
+
return {
|
|
1113
|
+
kind: this.kind,
|
|
1114
|
+
sessionId: child.address,
|
|
1115
|
+
attachCommand: `hc attach ${child.address}`,
|
|
1116
|
+
livenessPollIntervalMs: EXTERNAL_TRANSPORT_LIVENESS_POLL_INTERVAL_MS,
|
|
1117
|
+
isAlive: async () => {
|
|
1118
|
+
try {
|
|
1119
|
+
const current = terminal(await this.#request("terminal.get", params));
|
|
1120
|
+
if (current.address !== child.address) throw new Error("Herdr Core terminal address changed");
|
|
1121
|
+
return current.state === "live";
|
|
1122
|
+
} catch (error) {
|
|
1123
|
+
if (missing(error)) return false;
|
|
1124
|
+
throw error;
|
|
1125
|
+
}
|
|
1126
|
+
},
|
|
1127
|
+
stop: async () => {
|
|
1128
|
+
try {
|
|
1129
|
+
await this.#request("terminal.kill", params);
|
|
1130
|
+
} catch (error) {
|
|
1131
|
+
if (!missing(error)) throw error;
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
};
|
|
1135
|
+
}
|
|
1136
|
+
#request(method, params) {
|
|
1137
|
+
const socket = this.environment.HC_TERMINAL_SOCKET;
|
|
1138
|
+
if (!socket) return Promise.reject(new Error("Herdr Core transport requires HC_TERMINAL_SOCKET"));
|
|
1139
|
+
return herdrCoreSocketRequest(socket, method, params);
|
|
1140
|
+
}
|
|
1141
|
+
};
|
|
1142
|
+
|
|
982
1143
|
// src/agents/transports/herdr-transport.ts
|
|
983
1144
|
var HerdrTransport = class {
|
|
984
1145
|
constructor(environment = process.env) {
|
|
@@ -1201,16 +1362,16 @@ var TmuxTransport = class {
|
|
|
1201
1362
|
};
|
|
1202
1363
|
|
|
1203
1364
|
// src/agents/worktree-manager.ts
|
|
1204
|
-
import
|
|
1205
|
-
import
|
|
1365
|
+
import fs9 from "node:fs";
|
|
1366
|
+
import path9 from "node:path";
|
|
1206
1367
|
|
|
1207
1368
|
// src/agents/clone-first-worktree.ts
|
|
1208
|
-
import
|
|
1209
|
-
import
|
|
1369
|
+
import fs8 from "node:fs";
|
|
1370
|
+
import path8 from "node:path";
|
|
1210
1371
|
|
|
1211
1372
|
// src/agents/cow-clone.ts
|
|
1212
|
-
import
|
|
1213
|
-
import
|
|
1373
|
+
import fs6 from "node:fs";
|
|
1374
|
+
import path6 from "node:path";
|
|
1214
1375
|
var CLONE_SKIP_PREFIXES = [".git", ".pi/fabric/worktrees"];
|
|
1215
1376
|
var CowUnavailableError = class extends Error {
|
|
1216
1377
|
constructor(message2, options) {
|
|
@@ -1226,11 +1387,11 @@ var isCowUnavailable = (error) => {
|
|
|
1226
1387
|
};
|
|
1227
1388
|
var cloneEntry = async (from, to) => {
|
|
1228
1389
|
try {
|
|
1229
|
-
await
|
|
1390
|
+
await fs6.promises.cp(from, to, {
|
|
1230
1391
|
recursive: true,
|
|
1231
1392
|
verbatimSymlinks: true,
|
|
1232
1393
|
force: false,
|
|
1233
|
-
mode:
|
|
1394
|
+
mode: fs6.constants.COPYFILE_FICLONE_FORCE
|
|
1234
1395
|
});
|
|
1235
1396
|
} catch (error) {
|
|
1236
1397
|
if (isCowUnavailable(error)) {
|
|
@@ -1250,13 +1411,13 @@ var hasNestedSkip = (rel, prefixes) => {
|
|
|
1250
1411
|
return prefixes.some((prefix) => prefix.startsWith(`${value}/`));
|
|
1251
1412
|
};
|
|
1252
1413
|
var cloneLevel = async (source, dest, relBase, prefixes) => {
|
|
1253
|
-
await
|
|
1254
|
-
const entries = await
|
|
1414
|
+
await fs6.promises.mkdir(dest, { recursive: true });
|
|
1415
|
+
const entries = await fs6.promises.readdir(source, { withFileTypes: true });
|
|
1255
1416
|
for (const entry of entries) {
|
|
1256
1417
|
const rel = relBase ? `${relBase}/${entry.name}` : entry.name;
|
|
1257
1418
|
if (skipped(rel, prefixes)) continue;
|
|
1258
|
-
const from =
|
|
1259
|
-
const to =
|
|
1419
|
+
const from = path6.join(source, entry.name);
|
|
1420
|
+
const to = path6.join(dest, entry.name);
|
|
1260
1421
|
if (entry.isDirectory() && !entry.isSymbolicLink() && hasNestedSkip(rel, prefixes)) {
|
|
1261
1422
|
await cloneLevel(from, to, rel, prefixes);
|
|
1262
1423
|
continue;
|
|
@@ -1266,20 +1427,20 @@ var cloneLevel = async (source, dest, relBase, prefixes) => {
|
|
|
1266
1427
|
}
|
|
1267
1428
|
};
|
|
1268
1429
|
var cloneTree = async (source, dest, prefixes = CLONE_SKIP_PREFIXES) => {
|
|
1269
|
-
await
|
|
1270
|
-
const [realSource, realDest] = await Promise.all([
|
|
1271
|
-
const relativeDest =
|
|
1430
|
+
await fs6.promises.mkdir(dest, { recursive: true });
|
|
1431
|
+
const [realSource, realDest] = await Promise.all([fs6.promises.realpath(source), fs6.promises.realpath(dest)]);
|
|
1432
|
+
const relativeDest = path6.relative(realSource, realDest);
|
|
1272
1433
|
if (!relativeDest) throw new Error("Cannot clone a tree into itself");
|
|
1273
|
-
const inside = relativeDest !== ".." && !relativeDest.startsWith(`..${
|
|
1434
|
+
const inside = relativeDest !== ".." && !relativeDest.startsWith(`..${path6.sep}`) && !path6.isAbsolute(relativeDest);
|
|
1274
1435
|
await cloneLevel(realSource, realDest, "", inside ? [...prefixes, posixRel(relativeDest)] : prefixes);
|
|
1275
1436
|
};
|
|
1276
1437
|
|
|
1277
1438
|
// src/agents/worktree-paths.ts
|
|
1278
|
-
import
|
|
1279
|
-
import
|
|
1439
|
+
import fs7 from "node:fs";
|
|
1440
|
+
import path7 from "node:path";
|
|
1280
1441
|
var FABRIC_WORKTREE_SEGMENTS = [".pi", "fabric", "worktrees"];
|
|
1281
1442
|
var FABRIC_WORKTREE_EXCLUDE = ".pi/fabric/worktrees/";
|
|
1282
|
-
var fabricWorktreePath = (gitRoot, id) =>
|
|
1443
|
+
var fabricWorktreePath = (gitRoot, id) => path7.join(gitRoot, ...FABRIC_WORKTREE_SEGMENTS, id);
|
|
1283
1444
|
var isFabricWorktreePath = (worktree, id) => {
|
|
1284
1445
|
const parts = worktree.split(/[\\/]/).filter(Boolean);
|
|
1285
1446
|
return parts.length >= 4 && parts.at(-1) === id && parts.at(-2) === "worktrees" && parts.at(-3) === "fabric" && parts.at(-4) === ".pi";
|
|
@@ -1289,11 +1450,11 @@ var ensureWorktreeExclude = async (gitRoot) => {
|
|
|
1289
1450
|
cwd: gitRoot,
|
|
1290
1451
|
timeoutMs: 1e4
|
|
1291
1452
|
});
|
|
1292
|
-
const excludePath =
|
|
1293
|
-
|
|
1453
|
+
const excludePath = path7.resolve(gitRoot, located.stdout.trim());
|
|
1454
|
+
fs7.mkdirSync(path7.dirname(excludePath), { recursive: true });
|
|
1294
1455
|
let current = "";
|
|
1295
1456
|
try {
|
|
1296
|
-
current =
|
|
1457
|
+
current = fs7.readFileSync(excludePath, "utf8");
|
|
1297
1458
|
} catch (error) {
|
|
1298
1459
|
const code = error instanceof Error && "code" in error ? error.code : void 0;
|
|
1299
1460
|
if (code !== "ENOENT") throw error;
|
|
@@ -1301,7 +1462,7 @@ var ensureWorktreeExclude = async (gitRoot) => {
|
|
|
1301
1462
|
const lines = current.split(/\r?\n/);
|
|
1302
1463
|
if (lines.some((line) => line.trim() === FABRIC_WORKTREE_EXCLUDE)) return;
|
|
1303
1464
|
const prefix = current.length === 0 || current.endsWith("\n") ? "" : "\n";
|
|
1304
|
-
|
|
1465
|
+
fs7.appendFileSync(excludePath, `${prefix}${FABRIC_WORKTREE_EXCLUDE}
|
|
1305
1466
|
`);
|
|
1306
1467
|
};
|
|
1307
1468
|
|
|
@@ -1312,10 +1473,10 @@ var worktreeRollbackError = (gitRoot, worktree, branch, error, cleanupError) =>
|
|
|
1312
1473
|
};
|
|
1313
1474
|
var addCloneFirstWorktree = async (options) => {
|
|
1314
1475
|
const dest = options.dest;
|
|
1315
|
-
if (isFabricWorktreePath(dest,
|
|
1476
|
+
if (isFabricWorktreePath(dest, path8.basename(dest))) {
|
|
1316
1477
|
await ensureWorktreeExclude(options.gitRoot);
|
|
1317
1478
|
}
|
|
1318
|
-
|
|
1479
|
+
fs8.mkdirSync(path8.dirname(dest), { recursive: true });
|
|
1319
1480
|
const args = ["worktree", "add", "--no-checkout"];
|
|
1320
1481
|
if (options.quiet) args.push("-q");
|
|
1321
1482
|
if (options.detach) args.push("--detach");
|
|
@@ -1349,7 +1510,7 @@ var removeWorktree = async (gitRoot, worktree, branch) => {
|
|
|
1349
1510
|
try {
|
|
1350
1511
|
await executeFile("git", ["worktree", "remove", "--force", worktree], { cwd: gitRoot, timeoutMs: 6e4 });
|
|
1351
1512
|
} catch (error) {
|
|
1352
|
-
if (
|
|
1513
|
+
if (fs8.existsSync(worktree)) failure = error;
|
|
1353
1514
|
else await executeFile("git", ["worktree", "prune"], { cwd: gitRoot, timeoutMs: 3e4 }).catch(() => void 0);
|
|
1354
1515
|
}
|
|
1355
1516
|
if (branch) {
|
|
@@ -1373,9 +1534,9 @@ var SETUP_TIMEOUT_MS = 10 * 6e4;
|
|
|
1373
1534
|
var SETUP_OUTPUT_TAIL_CHARS = 2e3;
|
|
1374
1535
|
var countLines = (file) => {
|
|
1375
1536
|
try {
|
|
1376
|
-
const stat =
|
|
1537
|
+
const stat = fs9.statSync(file);
|
|
1377
1538
|
if (!stat.isFile() || stat.size > MAX_COUNTED_BYTES) return 0;
|
|
1378
|
-
const content =
|
|
1539
|
+
const content = fs9.readFileSync(file);
|
|
1379
1540
|
if (content.length === 0 || content.includes(0)) return 0;
|
|
1380
1541
|
let lines = 0;
|
|
1381
1542
|
for (const byte of content) if (byte === 10) lines++;
|
|
@@ -1386,8 +1547,8 @@ var countLines = (file) => {
|
|
|
1386
1547
|
};
|
|
1387
1548
|
var safeLabel = (value) => value.toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 30) || "agent";
|
|
1388
1549
|
var isInside2 = (root, target) => {
|
|
1389
|
-
const relative =
|
|
1390
|
-
return relative === "" || relative !== ".." && !relative.startsWith(`..${
|
|
1550
|
+
const relative = path9.relative(root, target);
|
|
1551
|
+
return relative === "" || relative !== ".." && !relative.startsWith(`..${path9.sep}`) && !path9.isAbsolute(relative);
|
|
1391
1552
|
};
|
|
1392
1553
|
var worktreePrefixParts = (prefix) => {
|
|
1393
1554
|
const parts = prefix.split(/[\\/]+/).filter(Boolean);
|
|
@@ -1405,7 +1566,7 @@ var WorktreeManager = class {
|
|
|
1405
1566
|
]);
|
|
1406
1567
|
const output = root.stdout.trim();
|
|
1407
1568
|
if (!output) throw new Error("Git did not return a worktree root");
|
|
1408
|
-
gitRoot =
|
|
1569
|
+
gitRoot = fs9.realpathSync(output);
|
|
1409
1570
|
sourcePrefix = prefix2.stdout.trim();
|
|
1410
1571
|
} catch (error) {
|
|
1411
1572
|
const failure = error;
|
|
@@ -1422,7 +1583,7 @@ var WorktreeManager = class {
|
|
|
1422
1583
|
});
|
|
1423
1584
|
let canonicalWorktreePath;
|
|
1424
1585
|
try {
|
|
1425
|
-
canonicalWorktreePath =
|
|
1586
|
+
canonicalWorktreePath = fs9.realpathSync(worktreePath);
|
|
1426
1587
|
} catch (error) {
|
|
1427
1588
|
try {
|
|
1428
1589
|
await removeWorktree(gitRoot, worktreePath, branch);
|
|
@@ -1435,10 +1596,10 @@ var WorktreeManager = class {
|
|
|
1435
1596
|
const prefix = preserveSourceSubdirectory ? worktreePrefixParts(sourcePrefix) : void 0;
|
|
1436
1597
|
let effectiveCwd = canonicalWorktreePath;
|
|
1437
1598
|
if (prefix && prefix.length > 0) {
|
|
1438
|
-
const candidate =
|
|
1599
|
+
const candidate = path9.resolve(canonicalWorktreePath, ...prefix);
|
|
1439
1600
|
try {
|
|
1440
|
-
const canonicalCandidate =
|
|
1441
|
-
if (
|
|
1601
|
+
const canonicalCandidate = fs9.realpathSync(candidate);
|
|
1602
|
+
if (fs9.statSync(canonicalCandidate).isDirectory() && isInside2(canonicalWorktreePath, canonicalCandidate)) {
|
|
1442
1603
|
effectiveCwd = canonicalCandidate;
|
|
1443
1604
|
}
|
|
1444
1605
|
} catch {
|
|
@@ -1477,7 +1638,7 @@ ${tail}` : ""}`);
|
|
|
1477
1638
|
...lease.baseRef ? { baseRef: lease.baseRef } : {},
|
|
1478
1639
|
changedFiles: [],
|
|
1479
1640
|
diffstat: { files: 0, insertions: 0, deletions: 0 },
|
|
1480
|
-
kept:
|
|
1641
|
+
kept: fs9.existsSync(lease.path)
|
|
1481
1642
|
};
|
|
1482
1643
|
if (!result.kept) return result;
|
|
1483
1644
|
try {
|
|
@@ -1497,7 +1658,7 @@ ${tail}` : ""}`);
|
|
|
1497
1658
|
for (const file of untracked.stdout.split("\n")) {
|
|
1498
1659
|
if (!file || files.has(file)) continue;
|
|
1499
1660
|
files.add(file);
|
|
1500
|
-
if (files.size <= MAX_CHANGED_FILES) result.diffstat.insertions += countLines(
|
|
1661
|
+
if (files.size <= MAX_CHANGED_FILES) result.diffstat.insertions += countLines(path9.join(lease.path, file));
|
|
1501
1662
|
}
|
|
1502
1663
|
result.diffstat.files = files.size;
|
|
1503
1664
|
result.changedFiles = [...files].sort().slice(0, MAX_CHANGED_FILES);
|
|
@@ -1516,9 +1677,9 @@ ${tail}` : ""}`);
|
|
|
1516
1677
|
};
|
|
1517
1678
|
|
|
1518
1679
|
// src/agents/handoff.ts
|
|
1519
|
-
import { randomUUID as
|
|
1520
|
-
import
|
|
1521
|
-
import
|
|
1680
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
1681
|
+
import fs10 from "node:fs";
|
|
1682
|
+
import path10 from "node:path";
|
|
1522
1683
|
|
|
1523
1684
|
// src/core/host-sdk-runtime.ts
|
|
1524
1685
|
var PiCodingAgent = await loadHostSdk();
|
|
@@ -1729,8 +1890,8 @@ var materializeBranch = (seed, cwd, directory, options = {}) => {
|
|
|
1729
1890
|
if (!seed.sourceBranch) {
|
|
1730
1891
|
throw new Error("In-memory trajectory handoff is missing its source branch");
|
|
1731
1892
|
}
|
|
1732
|
-
const id =
|
|
1733
|
-
const sessionFile =
|
|
1893
|
+
const id = randomUUID5();
|
|
1894
|
+
const sessionFile = path10.join(directory, `handoff-${id}.jsonl`);
|
|
1734
1895
|
const header = {
|
|
1735
1896
|
type: "session",
|
|
1736
1897
|
version: PiCodingAgent.CURRENT_SESSION_VERSION,
|
|
@@ -1740,7 +1901,7 @@ var materializeBranch = (seed, cwd, directory, options = {}) => {
|
|
|
1740
1901
|
...seed.sourceSessionFile ? { parentSession: seed.sourceSessionFile } : {}
|
|
1741
1902
|
};
|
|
1742
1903
|
const entries = options.workerRole ? withWorkerRoot(seed.sourceBranch) : seed.sourceBranch;
|
|
1743
|
-
|
|
1904
|
+
fs10.writeFileSync(
|
|
1744
1905
|
sessionFile,
|
|
1745
1906
|
`${[header, ...entries].map((entry) => JSON.stringify(entry)).join("\n")}
|
|
1746
1907
|
`,
|
|
@@ -1749,13 +1910,13 @@ var materializeBranch = (seed, cwd, directory, options = {}) => {
|
|
|
1749
1910
|
return PiCodingAgent.SessionManager.open(sessionFile, directory, cwd);
|
|
1750
1911
|
};
|
|
1751
1912
|
var insertWorkerRoot = (sessionFile) => {
|
|
1752
|
-
if (!
|
|
1913
|
+
if (!fs10.existsSync(sessionFile)) {
|
|
1753
1914
|
throw new Error("Trajectory handoff session file was not written, so the worker role cannot be placed at its root");
|
|
1754
1915
|
}
|
|
1755
|
-
const [headerLine, ...entryLines] =
|
|
1916
|
+
const [headerLine, ...entryLines] = fs10.readFileSync(sessionFile, "utf8").split("\n").filter((line) => line.length > 0);
|
|
1756
1917
|
const entries = entryLines.map((line) => JSON.parse(line));
|
|
1757
1918
|
const placed = withWorkerRoot(entries);
|
|
1758
|
-
|
|
1919
|
+
fs10.writeFileSync(
|
|
1759
1920
|
sessionFile,
|
|
1760
1921
|
`${[headerLine, ...placed.map((entry) => JSON.stringify(entry))].join("\n")}
|
|
1761
1922
|
`,
|
|
@@ -1798,7 +1959,7 @@ var synchronizeSourceSettings = (session, seed) => {
|
|
|
1798
1959
|
}
|
|
1799
1960
|
};
|
|
1800
1961
|
var writeHandoffSession = (seed, cwd, directory, transfer, compaction, compactionBudget, options = {}) => {
|
|
1801
|
-
|
|
1962
|
+
fs10.mkdirSync(directory, { recursive: true, mode: 448 });
|
|
1802
1963
|
const policy = transfer ? thinkingTransferPolicy(transfer) : "preserved";
|
|
1803
1964
|
let session;
|
|
1804
1965
|
const viaPiBranch = Boolean(seed.sourceSessionFile) && (!transfer || policy === "preserved");
|
|
@@ -1874,11 +2035,11 @@ var writeHandoffSession = (seed, cwd, directory, transfer, compaction, compactio
|
|
|
1874
2035
|
const sessionFile = session.getSessionFile();
|
|
1875
2036
|
if (!sessionFile) throw new Error("Trajectory handoff did not produce a Pi session file");
|
|
1876
2037
|
if (options.workerRole && viaPiBranch) insertWorkerRoot(sessionFile);
|
|
1877
|
-
|
|
2038
|
+
fs10.chmodSync(sessionFile, 384);
|
|
1878
2039
|
return sessionFile;
|
|
1879
2040
|
};
|
|
1880
2041
|
var writeForkSession = (seed, cwd, directory, transfer, options = {}) => {
|
|
1881
|
-
|
|
2042
|
+
fs10.mkdirSync(directory, { recursive: true, mode: 448 });
|
|
1882
2043
|
const policy = transfer ? thinkingTransferPolicy(transfer) : "preserved";
|
|
1883
2044
|
const raw = structuredClone(seed.sourceBranch);
|
|
1884
2045
|
const digest = policy === "stripped" && transfer ? buildThinkingDigest(raw, transfer) : void 0;
|
|
@@ -1902,13 +2063,13 @@ var writeForkSession = (seed, cwd, directory, transfer, options = {}) => {
|
|
|
1902
2063
|
});
|
|
1903
2064
|
const sessionFile = session.getSessionFile();
|
|
1904
2065
|
if (!sessionFile) throw new Error("Branch seed did not produce a Pi session file");
|
|
1905
|
-
|
|
2066
|
+
fs10.chmodSync(sessionFile, 384);
|
|
1906
2067
|
return sessionFile;
|
|
1907
2068
|
};
|
|
1908
2069
|
|
|
1909
2070
|
// src/agents/child-env.ts
|
|
1910
|
-
import
|
|
1911
|
-
import
|
|
2071
|
+
import fs11 from "node:fs";
|
|
2072
|
+
import path11 from "node:path";
|
|
1912
2073
|
var MAX_WRITABLE_ROOTS = 32;
|
|
1913
2074
|
var MAX_ROOT_CHARS = 4096;
|
|
1914
2075
|
var readAgentLineage = (raw = process.env.PI_FABRIC_LINEAGE) => {
|
|
@@ -1939,12 +2100,12 @@ var checkWritePolicyRequest = (request) => {
|
|
|
1939
2100
|
};
|
|
1940
2101
|
var nearestExisting = (target) => {
|
|
1941
2102
|
let current = target;
|
|
1942
|
-
while (!
|
|
1943
|
-
const parent =
|
|
2103
|
+
while (!fs11.existsSync(current)) {
|
|
2104
|
+
const parent = path11.dirname(current);
|
|
1944
2105
|
if (parent === current) break;
|
|
1945
2106
|
current = parent;
|
|
1946
2107
|
}
|
|
1947
|
-
return
|
|
2108
|
+
return path11.join(fs11.realpathSync(current), path11.relative(current, target));
|
|
1948
2109
|
};
|
|
1949
2110
|
var resolveChildWritePolicy = (request, parent, cwd) => {
|
|
1950
2111
|
if (!requestsWritePolicy(request)) return parent;
|
|
@@ -1957,21 +2118,21 @@ var resolveChildWritePolicy = (request, parent, cwd) => {
|
|
|
1957
2118
|
throw new Error('A shell-confined agent cannot launch a child with shell: "unconfined"');
|
|
1958
2119
|
}
|
|
1959
2120
|
if (readOnly) return { readOnly, writableRoots: [], shell };
|
|
1960
|
-
const realCwd =
|
|
2121
|
+
const realCwd = fs11.realpathSync(cwd);
|
|
1961
2122
|
const within = (target) => !parent || parent.writableRoots.some((root) => isInside(root, target));
|
|
1962
2123
|
const roots = request.writableRoots ?? (parent ? parent.writableRoots : [cwd]);
|
|
1963
2124
|
const resolved = /* @__PURE__ */ new Set();
|
|
1964
2125
|
for (const root of roots) {
|
|
1965
|
-
const absolute =
|
|
1966
|
-
if (!
|
|
2126
|
+
const absolute = path11.resolve(cwd, root);
|
|
2127
|
+
if (!fs11.existsSync(absolute)) {
|
|
1967
2128
|
const target = nearestExisting(absolute);
|
|
1968
2129
|
if (!isInside(cwd, absolute) || !isInside(realCwd, target) || !within(target)) {
|
|
1969
2130
|
throw new Error(`Writable root must exist or be creatable inside the agent cwd: ${root}`);
|
|
1970
2131
|
}
|
|
1971
|
-
|
|
2132
|
+
fs11.mkdirSync(absolute, { recursive: true });
|
|
1972
2133
|
}
|
|
1973
|
-
const real =
|
|
1974
|
-
if (!
|
|
2134
|
+
const real = fs11.realpathSync(absolute);
|
|
2135
|
+
if (!fs11.statSync(real).isDirectory()) throw new Error(`Writable root is not a directory: ${root}`);
|
|
1975
2136
|
if (!within(real)) throw new Error(`Writable root is outside the caller's writable roots: ${root}`);
|
|
1976
2137
|
resolved.add(real);
|
|
1977
2138
|
}
|
|
@@ -2012,17 +2173,17 @@ var budgetAdmits = (spent, limit) => {
|
|
|
2012
2173
|
};
|
|
2013
2174
|
|
|
2014
2175
|
// src/storage/retention.ts
|
|
2015
|
-
import
|
|
2016
|
-
import
|
|
2176
|
+
import fs12 from "node:fs";
|
|
2177
|
+
import path12 from "node:path";
|
|
2017
2178
|
var RUN_ROOT_OWNER_FILE = ".fabric-owner.json";
|
|
2018
2179
|
var TERMINAL_STATUSES = /* @__PURE__ */ new Set(["completed", "failed", "stopped", "timed_out"]);
|
|
2019
2180
|
var RUN_ROOT_HEARTBEAT_TTL_MS = 45 * 60 * 1e3;
|
|
2020
|
-
var ownerPath = (root) =>
|
|
2181
|
+
var ownerPath = (root) => path12.join(root, RUN_ROOT_OWNER_FILE);
|
|
2021
2182
|
var readJson = (file) => {
|
|
2022
2183
|
try {
|
|
2023
2184
|
const stat = ownedStat(file);
|
|
2024
2185
|
if (!stat?.isFile() || stat.size > 1024 * 1024) return;
|
|
2025
|
-
return JSON.parse(
|
|
2186
|
+
return JSON.parse(fs12.readFileSync(file, "utf8"));
|
|
2026
2187
|
} catch {
|
|
2027
2188
|
return;
|
|
2028
2189
|
}
|
|
@@ -2030,9 +2191,9 @@ var readJson = (file) => {
|
|
|
2030
2191
|
var time = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
2031
2192
|
var validOwner = (owner) => !!owner && Number.isSafeInteger(owner.pid) && owner.pid > 0 && time(owner.startedAt) && time(owner.heartbeatAt) && (owner.closedAt === void 0 || time(owner.closedAt)) && (owner.orphanedAt === void 0 || time(owner.orphanedAt)) && (owner.childrenStopped === void 0 || typeof owner.childrenStopped === "boolean");
|
|
2032
2193
|
var writeOwner = (root, owner) => {
|
|
2033
|
-
if (
|
|
2194
|
+
if (fs12.existsSync(root) && !ownedStat(root)?.isDirectory()) throw new Error("Unsafe Fabric run root");
|
|
2034
2195
|
const file = ownerPath(root);
|
|
2035
|
-
if (
|
|
2196
|
+
if (fs12.existsSync(file)) {
|
|
2036
2197
|
const existing = readJson(file);
|
|
2037
2198
|
if (!validOwner(existing) || existing.pid !== owner.pid) throw new Error("Unsafe Fabric run owner marker");
|
|
2038
2199
|
}
|
|
@@ -2079,21 +2240,21 @@ var DURABLE_KEY = /^(?:initial|[0-9a-f]{64})$/;
|
|
|
2079
2240
|
var DURABLE_LEASE_FILES = /* @__PURE__ */ new Set(["lease.sqlite", "lease.sqlite-journal"]);
|
|
2080
2241
|
var DURABLE_STORE_FILE = /^(?:main|(?:doc|task)-(?:0|[1-9]\d*))\.jsonl(?:\.reclaim)?$/;
|
|
2081
2242
|
var FABRIC_JOURNAL_FILE = /^[0-9a-f]{32}\.jsonl$/;
|
|
2082
|
-
var onlyOwnedFiles = (directory, allowed) =>
|
|
2243
|
+
var onlyOwnedFiles = (directory, allowed) => fs12.readdirSync(directory).every((name) => allowed(name) && ownedStat(path12.join(directory, name))?.isFile() === true);
|
|
2083
2244
|
var DURABLE_SESSION_FILE = "session.jsonl";
|
|
2084
2245
|
var DURABLE_SESSION_TEMP = /^tmp-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\.jsonl$/;
|
|
2085
2246
|
var DURABLE_SESSION_SIDECAR = /^session\.jsonl\.[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
2086
2247
|
var safeDurableSessionFolder = (directory) => {
|
|
2087
2248
|
const uid = process.getuid?.();
|
|
2088
2249
|
const stats = /* @__PURE__ */ new Map();
|
|
2089
|
-
for (const name of
|
|
2250
|
+
for (const name of fs12.readdirSync(directory)) {
|
|
2090
2251
|
if (DURABLE_SESSION_SIDECAR.test(name)) {
|
|
2091
|
-
const sidecar =
|
|
2252
|
+
const sidecar = fs12.lstatSync(path12.join(directory, name));
|
|
2092
2253
|
if (!sidecar.isFile() || uid !== void 0 && sidecar.uid !== uid || sidecar.nlink !== 1) return false;
|
|
2093
2254
|
continue;
|
|
2094
2255
|
}
|
|
2095
2256
|
if (name !== DURABLE_SESSION_FILE && !DURABLE_SESSION_TEMP.test(name)) return false;
|
|
2096
|
-
const stat =
|
|
2257
|
+
const stat = fs12.lstatSync(path12.join(directory, name));
|
|
2097
2258
|
if (!stat.isFile() || uid !== void 0 && stat.uid !== uid || stat.nlink > 2) return false;
|
|
2098
2259
|
stats.set(name, stat);
|
|
2099
2260
|
}
|
|
@@ -2104,11 +2265,11 @@ var safeDurableSessionFolder = (directory) => {
|
|
|
2104
2265
|
const [temporary] = temporaries;
|
|
2105
2266
|
return stats.size === 2 && session !== void 0 && temporaries.length === 1 && temporary !== void 0 && session.nlink === 2 && temporary[1].nlink === 2 && session.dev === temporary[1].dev && session.ino === temporary[1].ino;
|
|
2106
2267
|
};
|
|
2107
|
-
var safeDurableTree = (directory) =>
|
|
2108
|
-
const conversation =
|
|
2268
|
+
var safeDurableTree = (directory) => fs12.readdirSync(directory).every((key) => {
|
|
2269
|
+
const conversation = path12.join(directory, key);
|
|
2109
2270
|
if (!DURABLE_KEY.test(key) || !ownedStat(conversation)?.isDirectory()) return false;
|
|
2110
|
-
return
|
|
2111
|
-
const file =
|
|
2271
|
+
return fs12.readdirSync(conversation).every((name) => {
|
|
2272
|
+
const file = path12.join(conversation, name);
|
|
2112
2273
|
if (name === "store") return ownedStat(file)?.isDirectory() === true && onlyOwnedFiles(file, (child) => DURABLE_STORE_FILE.test(child));
|
|
2113
2274
|
if (name === "fabric-journal") return ownedStat(file)?.isDirectory() === true && onlyOwnedFiles(file, (child) => FABRIC_JOURNAL_FILE.test(child));
|
|
2114
2275
|
return DURABLE_LEASE_FILES.has(name) && ownedStat(file)?.isFile() === true;
|
|
@@ -2116,25 +2277,25 @@ var safeDurableTree = (directory) => fs11.readdirSync(directory).every((key) =>
|
|
|
2116
2277
|
});
|
|
2117
2278
|
var ownedTree = (directory, depth) => {
|
|
2118
2279
|
if (depth > 32) return false;
|
|
2119
|
-
return
|
|
2120
|
-
const stat = ownedStat(
|
|
2280
|
+
return fs12.readdirSync(directory).every((name) => {
|
|
2281
|
+
const stat = ownedStat(path12.join(directory, name));
|
|
2121
2282
|
if (!stat || name.startsWith("hosted.json")) return false;
|
|
2122
|
-
return stat.isFile() || stat.isDirectory() && ownedTree(
|
|
2283
|
+
return stat.isFile() || stat.isDirectory() && ownedTree(path12.join(directory, name), depth + 1);
|
|
2123
2284
|
});
|
|
2124
2285
|
};
|
|
2125
2286
|
var safeRunTree = (root, childrenStopped, owner, depth = 0, anyContents = false) => {
|
|
2126
2287
|
if (depth > 32 || !ownedStat(root)?.isDirectory()) return false;
|
|
2127
|
-
const record = readJson(
|
|
2288
|
+
const record = readJson(path12.join(root, "status.json"));
|
|
2128
2289
|
const pid = record?.transport === "process" && typeof record.sessionId === "string" && /^\d+$/.test(record.sessionId) ? Number(record.sessionId) : void 0;
|
|
2129
2290
|
if (pid !== void 0 && childAlive(owner, pid)) return false;
|
|
2130
|
-
const
|
|
2131
|
-
if (!
|
|
2291
|
+
const terminal2 = !!record?.status && TERMINAL_STATUSES.has(record.status);
|
|
2292
|
+
if (!terminal2) {
|
|
2132
2293
|
if (!childrenStopped && pid === void 0) return false;
|
|
2133
|
-
if (!ownedStat(
|
|
2294
|
+
if (!ownedStat(path12.join(root, "task.txt"))?.isFile()) return false;
|
|
2134
2295
|
}
|
|
2135
2296
|
try {
|
|
2136
|
-
for (const name of
|
|
2137
|
-
const file =
|
|
2297
|
+
for (const name of fs12.readdirSync(root)) {
|
|
2298
|
+
const file = path12.join(root, name);
|
|
2138
2299
|
const stat = ownedStat(file);
|
|
2139
2300
|
if (!stat) return false;
|
|
2140
2301
|
if (stat.isFile() && (runFiles.has(name) || name === OVERSIZED_EVENT_FILE || STATUS_TEMP_FILE.test(name))) continue;
|
|
@@ -2147,7 +2308,7 @@ var safeRunTree = (root, childrenStopped, owner, depth = 0, anyContents = false)
|
|
|
2147
2308
|
continue;
|
|
2148
2309
|
}
|
|
2149
2310
|
if (stat.isDirectory() && name === "handoff-session") {
|
|
2150
|
-
if (
|
|
2311
|
+
if (fs12.readdirSync(file).some((child) => !child.endsWith(".jsonl") || !ownedStat(path12.join(file, child))?.isFile())) return false;
|
|
2151
2312
|
continue;
|
|
2152
2313
|
}
|
|
2153
2314
|
if (stat.isDirectory() && name === "durable-session") {
|
|
@@ -2159,7 +2320,7 @@ var safeRunTree = (root, childrenStopped, owner, depth = 0, anyContents = false)
|
|
|
2159
2320
|
continue;
|
|
2160
2321
|
}
|
|
2161
2322
|
if (stat.isDirectory() && name === "nested") {
|
|
2162
|
-
for (const child of
|
|
2323
|
+
for (const child of fs12.readdirSync(file)) if (!safeRunTree(path12.join(file, child), false, owner, depth + 1, anyContents)) return false;
|
|
2163
2324
|
continue;
|
|
2164
2325
|
}
|
|
2165
2326
|
return false;
|
|
@@ -2171,7 +2332,7 @@ var safeRunTree = (root, childrenStopped, owner, depth = 0, anyContents = false)
|
|
|
2171
2332
|
};
|
|
2172
2333
|
var safeRootContents = (root, childrenStopped, owner, anyContents = false) => {
|
|
2173
2334
|
try {
|
|
2174
|
-
return
|
|
2335
|
+
return fs12.readdirSync(root).every((name) => name === RUN_ROOT_OWNER_FILE || safeRunTree(path12.join(root, name), childrenStopped, owner, 0, anyContents));
|
|
2175
2336
|
} catch {
|
|
2176
2337
|
return false;
|
|
2177
2338
|
}
|
|
@@ -2184,8 +2345,8 @@ var canRemoveManagedRunRoot = (root) => {
|
|
|
2184
2345
|
var removeEmptyRunRoot = (root) => {
|
|
2185
2346
|
try {
|
|
2186
2347
|
if (!ownedStat(root)?.isDirectory() || !validOwner(readJson(ownerPath(root)))) return false;
|
|
2187
|
-
if (
|
|
2188
|
-
|
|
2348
|
+
if (fs12.readdirSync(root).some((name) => name !== RUN_ROOT_OWNER_FILE)) return false;
|
|
2349
|
+
fs12.rmSync(root, { recursive: true, force: true });
|
|
2189
2350
|
return true;
|
|
2190
2351
|
} catch {
|
|
2191
2352
|
return false;
|
|
@@ -2195,21 +2356,21 @@ var pruneClosedRunRoot = (root, owner, orphanMs, oneShotMs, now) => {
|
|
|
2195
2356
|
const removed = [];
|
|
2196
2357
|
let entries;
|
|
2197
2358
|
try {
|
|
2198
|
-
entries =
|
|
2359
|
+
entries = fs12.readdirSync(root, { withFileTypes: true });
|
|
2199
2360
|
} catch {
|
|
2200
2361
|
return removed;
|
|
2201
2362
|
}
|
|
2202
2363
|
for (const entry of entries) {
|
|
2203
2364
|
if (!entry.isDirectory()) continue;
|
|
2204
|
-
const directory =
|
|
2365
|
+
const directory = path12.join(root, entry.name);
|
|
2205
2366
|
if (!safeRunTree(directory, owner.childrenStopped === true, owner)) continue;
|
|
2206
|
-
const record = readJson(
|
|
2207
|
-
const
|
|
2208
|
-
const reference =
|
|
2209
|
-
const retention =
|
|
2367
|
+
const record = readJson(path12.join(directory, "status.json"));
|
|
2368
|
+
const terminal2 = !!record?.status && TERMINAL_STATUSES.has(record.status);
|
|
2369
|
+
const reference = terminal2 ? recordAgeReference(record, ownedStat(directory)?.mtimeMs ?? now) : owner.closedAt;
|
|
2370
|
+
const retention = terminal2 && !record?.actorId ? oneShotMs : orphanMs;
|
|
2210
2371
|
if (now - reference < retention) continue;
|
|
2211
2372
|
try {
|
|
2212
|
-
|
|
2373
|
+
fs12.rmSync(directory, { recursive: true, force: true });
|
|
2213
2374
|
removed.push(directory);
|
|
2214
2375
|
} catch {
|
|
2215
2376
|
}
|
|
@@ -2221,14 +2382,14 @@ var sweepTempRunRoots = (options) => {
|
|
|
2221
2382
|
const result = { removedRoots: [], removedRuns: [] };
|
|
2222
2383
|
let entries;
|
|
2223
2384
|
try {
|
|
2224
|
-
entries =
|
|
2385
|
+
entries = fs12.readdirSync(options.tempRoot, { withFileTypes: true });
|
|
2225
2386
|
} catch {
|
|
2226
2387
|
return result;
|
|
2227
2388
|
}
|
|
2228
2389
|
for (const entry of entries) {
|
|
2229
2390
|
if (!entry.isDirectory() || !/^pi-fabric-runs-[A-Za-z0-9_-]+$/.test(entry.name)) continue;
|
|
2230
|
-
const root =
|
|
2231
|
-
if (options.currentRoot &&
|
|
2391
|
+
const root = path12.join(options.tempRoot, entry.name);
|
|
2392
|
+
if (options.currentRoot && path12.resolve(root) === path12.resolve(options.currentRoot)) continue;
|
|
2232
2393
|
if (!ownedStat(root)?.isDirectory()) continue;
|
|
2233
2394
|
const owner = readJson(ownerPath(root));
|
|
2234
2395
|
if (!validOwner(owner)) continue;
|
|
@@ -2247,7 +2408,7 @@ var sweepTempRunRoots = (options) => {
|
|
|
2247
2408
|
}
|
|
2248
2409
|
if (now - owner.orphanedAt < options.orphanedTempRunRetentionMs || !safeRootContents(root, false, owner, true)) continue;
|
|
2249
2410
|
try {
|
|
2250
|
-
|
|
2411
|
+
fs12.rmSync(root, { recursive: true, force: true });
|
|
2251
2412
|
result.removedRoots.push(root);
|
|
2252
2413
|
} catch {
|
|
2253
2414
|
}
|
|
@@ -2260,18 +2421,18 @@ var pruneActorRunArchives = (options) => {
|
|
|
2260
2421
|
if (!ownedStat(options.runsDirectory)?.isDirectory()) return removed;
|
|
2261
2422
|
let entries;
|
|
2262
2423
|
try {
|
|
2263
|
-
entries =
|
|
2424
|
+
entries = fs12.readdirSync(options.runsDirectory, { withFileTypes: true });
|
|
2264
2425
|
} catch {
|
|
2265
2426
|
return removed;
|
|
2266
2427
|
}
|
|
2267
2428
|
for (const entry of entries) {
|
|
2268
2429
|
if (!entry.isDirectory() || entry.name === options.latestRunId) continue;
|
|
2269
|
-
const directory =
|
|
2270
|
-
const record = readJson(
|
|
2430
|
+
const directory = path12.join(options.runsDirectory, entry.name);
|
|
2431
|
+
const record = readJson(path12.join(directory, "status.json"));
|
|
2271
2432
|
if (!record?.status || !TERMINAL_STATUSES.has(record.status) || !safeRunTree(directory, false)) continue;
|
|
2272
2433
|
if (now - recordAgeReference(record, ownedStat(directory)?.mtimeMs ?? now) < options.retentionMs) continue;
|
|
2273
2434
|
try {
|
|
2274
|
-
|
|
2435
|
+
fs12.rmSync(directory, { recursive: true, force: true });
|
|
2275
2436
|
removed.push(directory);
|
|
2276
2437
|
} catch {
|
|
2277
2438
|
}
|
|
@@ -2281,21 +2442,21 @@ var pruneActorRunArchives = (options) => {
|
|
|
2281
2442
|
|
|
2282
2443
|
// src/agents/session-export.ts
|
|
2283
2444
|
import os2 from "node:os";
|
|
2284
|
-
import
|
|
2445
|
+
import path13 from "node:path";
|
|
2285
2446
|
var SESSION_EXPORT_ENV = "PI_FABRIC_AGENT_DIR";
|
|
2286
|
-
var expandHome = (value) => value === "~" ? os2.homedir() : value.startsWith("~/") || value.startsWith(`~${
|
|
2447
|
+
var expandHome = (value) => value === "~" ? os2.homedir() : value.startsWith("~/") || value.startsWith(`~${path13.win32.sep}`) ? path13.join(os2.homedir(), value.slice(2)) : value;
|
|
2287
2448
|
var encodeSessionExportCwd = (cwd) => {
|
|
2288
|
-
const absolute =
|
|
2449
|
+
const absolute = path13.isAbsolute(cwd) || path13.win32.isAbsolute(cwd) ? cwd : path13.resolve(cwd);
|
|
2289
2450
|
return `--${absolute.replace(/^[/\\]/, "").replace(/[/\\:]/g, "-")}--`;
|
|
2290
2451
|
};
|
|
2291
2452
|
var resolveSessionExportDir = (config) => {
|
|
2292
2453
|
if (!config.sessionExport) return void 0;
|
|
2293
|
-
const raw = process.env[SESSION_EXPORT_ENV]?.trim() || config.sessionExportDir.trim() ||
|
|
2454
|
+
const raw = process.env[SESSION_EXPORT_ENV]?.trim() || config.sessionExportDir.trim() || path13.join(os2.homedir(), ".pi", "agent");
|
|
2294
2455
|
return expandHome(raw);
|
|
2295
2456
|
};
|
|
2296
2457
|
var sessionExportFileFor = (root, cwd, runId, at) => {
|
|
2297
2458
|
const fileTimestamp = at.toISOString().replace(/[:.]/g, "-");
|
|
2298
|
-
return
|
|
2459
|
+
return path13.join(
|
|
2299
2460
|
root,
|
|
2300
2461
|
"sessions",
|
|
2301
2462
|
".fabric",
|
|
@@ -2336,11 +2497,11 @@ var resolveAgentCwd = (parentCwd, requestedCwd) => {
|
|
|
2336
2497
|
if (typeof requested !== "string" || requested.trim().length === 0) {
|
|
2337
2498
|
throw new Error(`Invalid Fabric agent cwd ${JSON.stringify(requested)}: path must not be empty`);
|
|
2338
2499
|
}
|
|
2339
|
-
const candidate =
|
|
2500
|
+
const candidate = path14.isAbsolute(requested) ? requested : path14.resolve(parentCwd, requested);
|
|
2340
2501
|
try {
|
|
2341
|
-
const canonical =
|
|
2342
|
-
|
|
2343
|
-
if (!
|
|
2502
|
+
const canonical = fs13.realpathSync(candidate);
|
|
2503
|
+
fs13.accessSync(canonical, fs13.constants.R_OK | fs13.constants.X_OK);
|
|
2504
|
+
if (!fs13.statSync(canonical).isDirectory()) {
|
|
2344
2505
|
throw new Error("path is not a directory");
|
|
2345
2506
|
}
|
|
2346
2507
|
return canonical;
|
|
@@ -2374,7 +2535,7 @@ var queuedResult = (entry, status, error) => {
|
|
|
2374
2535
|
};
|
|
2375
2536
|
var fileSize = (filePath) => {
|
|
2376
2537
|
try {
|
|
2377
|
-
return
|
|
2538
|
+
return fs13.statSync(filePath).size;
|
|
2378
2539
|
} catch {
|
|
2379
2540
|
return 0;
|
|
2380
2541
|
}
|
|
@@ -2425,7 +2586,7 @@ var runName = (request) => safeName(request.name ?? request.task.split("\n", 1)[
|
|
|
2425
2586
|
var safeName = (value) => value.replace(/[\r\n\t]+/g, " ").trim().slice(0, MAX_NAME_LENGTH) || "Fabric agent";
|
|
2426
2587
|
var readRecord = (filePath) => {
|
|
2427
2588
|
try {
|
|
2428
|
-
const parsed = JSON.parse(
|
|
2589
|
+
const parsed = JSON.parse(fs13.readFileSync(filePath, "utf8"));
|
|
2429
2590
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return void 0;
|
|
2430
2591
|
const record = parsed;
|
|
2431
2592
|
return { ...record, runner: isFabricRunnerId(record.runner) ? record.runner : "pi" };
|
|
@@ -2477,24 +2638,24 @@ var reconcileNestedAgents = (records, owner) => records.map((record) => {
|
|
|
2477
2638
|
});
|
|
2478
2639
|
var readNestedAgents = (runDirectory, depth = 0) => {
|
|
2479
2640
|
if (depth >= 8) return [];
|
|
2480
|
-
const nestedRoot =
|
|
2641
|
+
const nestedRoot = path14.join(runDirectory, "nested");
|
|
2481
2642
|
let entries;
|
|
2482
2643
|
try {
|
|
2483
|
-
entries =
|
|
2644
|
+
entries = fs13.readdirSync(nestedRoot);
|
|
2484
2645
|
} catch {
|
|
2485
2646
|
return [];
|
|
2486
2647
|
}
|
|
2487
2648
|
const agents = [];
|
|
2488
2649
|
for (const entry of entries.slice(0, 200)) {
|
|
2489
|
-
const runDirectory2 =
|
|
2490
|
-
const record = readRecord(
|
|
2650
|
+
const runDirectory2 = path14.join(nestedRoot, entry);
|
|
2651
|
+
const record = readRecord(path14.join(runDirectory2, "status.json"));
|
|
2491
2652
|
if (!record) continue;
|
|
2492
2653
|
const nestedAgents = readNestedAgents(runDirectory2, depth + 1);
|
|
2493
2654
|
const { logFile: _logFile, nestedAgents: _nestedAgents, ...safeRecord } = record;
|
|
2494
2655
|
agents.push(
|
|
2495
2656
|
compactUiRecord({
|
|
2496
2657
|
...safeRecord,
|
|
2497
|
-
logFile:
|
|
2658
|
+
logFile: path14.join(runDirectory2, "events.jsonl"),
|
|
2498
2659
|
...nestedAgents.length > 0 ? { nestedAgents } : {}
|
|
2499
2660
|
})
|
|
2500
2661
|
);
|
|
@@ -2502,7 +2663,7 @@ var readNestedAgents = (runDirectory, depth = 0) => {
|
|
|
2502
2663
|
return agents;
|
|
2503
2664
|
};
|
|
2504
2665
|
var summarizeRunLog = (runDirectory, lines) => {
|
|
2505
|
-
const page = readJsonlPage(
|
|
2666
|
+
const page = readJsonlPage(path14.join(runDirectory, "events.jsonl"), lines);
|
|
2506
2667
|
const summary = [];
|
|
2507
2668
|
for (const entry of page.lines) {
|
|
2508
2669
|
const parsed = entry.parsed;
|
|
@@ -2555,8 +2716,8 @@ var AgentManager = class {
|
|
|
2555
2716
|
this.config = config;
|
|
2556
2717
|
this.#semaphore = new AgentAdmission(config.maxConcurrent, Infinity, config.maxDepth);
|
|
2557
2718
|
this.#managedTempRoot = options.runRoot === void 0 && process.env.PI_FABRIC_RUN_ROOT === void 0;
|
|
2558
|
-
this.#runRoot = options.runRoot ?? process.env.PI_FABRIC_RUN_ROOT ??
|
|
2559
|
-
this.#parentOwnedRunRoot = options.runRoot === void 0 && this.#parentLineage?.worker === true && this.#parentLineage.depth > 0 &&
|
|
2719
|
+
this.#runRoot = options.runRoot ?? process.env.PI_FABRIC_RUN_ROOT ?? fs13.mkdtempSync(path14.join(os3.tmpdir(), "pi-fabric-runs-"));
|
|
2720
|
+
this.#parentOwnedRunRoot = options.runRoot === void 0 && this.#parentLineage?.worker === true && this.#parentLineage.depth > 0 && path14.basename(this.#runRoot) === "nested" && path14.basename(path14.dirname(this.#runRoot)) === this.#parentLineage.runId;
|
|
2560
2721
|
this.#retention = options.retention ?? DEFAULT_FABRIC_CONFIG.retention;
|
|
2561
2722
|
this.#workerPath = options.workerPath ?? fileURLToPath(new URL("../worker.js", import.meta.url));
|
|
2562
2723
|
this.#fabricExtensionPath = options.fabricExtensionPath ?? fileURLToPath(new URL("../index.js", import.meta.url));
|
|
@@ -2593,7 +2754,8 @@ var AgentManager = class {
|
|
|
2593
2754
|
new TmuxTransport(),
|
|
2594
2755
|
new ScreenTransport(),
|
|
2595
2756
|
new LocaltermTransport(),
|
|
2596
|
-
new HerdrTransport()
|
|
2757
|
+
new HerdrTransport(),
|
|
2758
|
+
new HerdrCoreTransport()
|
|
2597
2759
|
];
|
|
2598
2760
|
this.#transports = new Map(adapters.map((adapter) => [adapter.kind, adapter]));
|
|
2599
2761
|
if (this.#managedTempRoot) {
|
|
@@ -2770,7 +2932,7 @@ var AgentManager = class {
|
|
|
2770
2932
|
if (request.residency === "durable") {
|
|
2771
2933
|
return Promise.reject(new Error('queue: true is not supported with residency: "durable"'));
|
|
2772
2934
|
}
|
|
2773
|
-
const id =
|
|
2935
|
+
const id = randomUUID6().replaceAll("-", "");
|
|
2774
2936
|
const control = new AbortController();
|
|
2775
2937
|
return new Promise((resolve, reject) => {
|
|
2776
2938
|
let entry;
|
|
@@ -2953,28 +3115,28 @@ var AgentManager = class {
|
|
|
2953
3115
|
release();
|
|
2954
3116
|
throw error;
|
|
2955
3117
|
}
|
|
2956
|
-
const id = queued?.id ??
|
|
3118
|
+
const id = queued?.id ?? randomUUID6().replaceAll("-", "");
|
|
2957
3119
|
const name = runName(request);
|
|
2958
|
-
const runDirectory =
|
|
3120
|
+
const runDirectory = path14.join(this.#runRoot, id);
|
|
2959
3121
|
const durableSession = runner === "pi-durable" && this.config.durableWorkerSession === true;
|
|
2960
|
-
const taskFile =
|
|
2961
|
-
const statusFile =
|
|
2962
|
-
const lifecycleFile =
|
|
2963
|
-
const logFile =
|
|
2964
|
-
const steerFile =
|
|
2965
|
-
const schemaFile = request.schema ?
|
|
2966
|
-
const imagesFile = request.images && request.images.length > 0 ?
|
|
3122
|
+
const taskFile = path14.join(runDirectory, "task.txt");
|
|
3123
|
+
const statusFile = path14.join(runDirectory, "status.json");
|
|
3124
|
+
const lifecycleFile = path14.join(runDirectory, "lifecycle.jsonl");
|
|
3125
|
+
const logFile = path14.join(runDirectory, "events.jsonl");
|
|
3126
|
+
const steerFile = path14.join(runDirectory, "steer.jsonl");
|
|
3127
|
+
const schemaFile = request.schema ? path14.join(runDirectory, "schema.json") : void 0;
|
|
3128
|
+
const imagesFile = request.images && request.images.length > 0 ? path14.join(runDirectory, "images.json") : void 0;
|
|
2967
3129
|
try {
|
|
2968
|
-
|
|
2969
|
-
|
|
3130
|
+
fs13.mkdirSync(runDirectory, durableSession ? { recursive: true, mode: 448 } : { recursive: true });
|
|
3131
|
+
fs13.writeFileSync(taskFile, request.task, { encoding: "utf8", mode: 384 });
|
|
2970
3132
|
if (imagesFile) {
|
|
2971
|
-
|
|
3133
|
+
fs13.writeFileSync(imagesFile, JSON.stringify(request.images), {
|
|
2972
3134
|
encoding: "utf8",
|
|
2973
3135
|
mode: 384
|
|
2974
3136
|
});
|
|
2975
3137
|
}
|
|
2976
3138
|
if (schemaFile) {
|
|
2977
|
-
|
|
3139
|
+
fs13.writeFileSync(schemaFile, JSON.stringify(request.schema, null, 2), {
|
|
2978
3140
|
encoding: "utf8",
|
|
2979
3141
|
mode: 384
|
|
2980
3142
|
});
|
|
@@ -3022,10 +3184,10 @@ var AgentManager = class {
|
|
|
3022
3184
|
const seedOptions = durableSession ? { workerRole: true } : {};
|
|
3023
3185
|
const handoffBudget = request.sessionSeed && request.handoffCompact ? await this.#resolveHandoffCompactionBudget?.(model, agentCwd) : void 0;
|
|
3024
3186
|
admissionSignal.throwIfAborted();
|
|
3025
|
-
const sessionFile = request.forkSeed ? writeForkSession(request.forkSeed, agentCwd,
|
|
3187
|
+
const sessionFile = request.forkSeed ? writeForkSession(request.forkSeed, agentCwd, path14.join(runDirectory, "fork-session"), request.thinkingTransfer, seedOptions) : request.sessionSeed ? writeHandoffSession(
|
|
3026
3188
|
request.sessionSeed,
|
|
3027
3189
|
agentCwd,
|
|
3028
|
-
|
|
3190
|
+
path14.join(runDirectory, "handoff-session"),
|
|
3029
3191
|
request.thinkingTransfer,
|
|
3030
3192
|
request.handoffCompact,
|
|
3031
3193
|
handoffBudget,
|
|
@@ -3161,7 +3323,7 @@ var AgentManager = class {
|
|
|
3161
3323
|
...this.#identityId ? ["--owner-identity-id", this.#identityId] : [],
|
|
3162
3324
|
...request.runnerSessionId ? ["--runner-session-id", request.runnerSessionId] : [],
|
|
3163
3325
|
"--run-root",
|
|
3164
|
-
|
|
3326
|
+
path14.join(runDirectory, "nested"),
|
|
3165
3327
|
"--steer-file",
|
|
3166
3328
|
steerFile,
|
|
3167
3329
|
...this.config.childQuestions === "route" && capabilities2.questions ? [
|
|
@@ -3313,7 +3475,7 @@ var AgentManager = class {
|
|
|
3313
3475
|
const hosted = await HostedRun.prepare(
|
|
3314
3476
|
adapter,
|
|
3315
3477
|
{ ...context, idempotencyKey: context.id },
|
|
3316
|
-
{ ...launch.files, stateFile:
|
|
3478
|
+
{ ...launch.files, stateFile: path14.join(context.runDirectory, HOSTED_STATE_FILE) },
|
|
3317
3479
|
record,
|
|
3318
3480
|
this.#hostedHooks(() => managed, launch.request.holdQuestions === true)
|
|
3319
3481
|
);
|
|
@@ -3400,17 +3562,17 @@ var AgentManager = class {
|
|
|
3400
3562
|
async recoverHostedRuns() {
|
|
3401
3563
|
let entries;
|
|
3402
3564
|
try {
|
|
3403
|
-
entries =
|
|
3565
|
+
entries = fs13.readdirSync(this.#runRoot);
|
|
3404
3566
|
} catch {
|
|
3405
3567
|
return [];
|
|
3406
3568
|
}
|
|
3407
3569
|
const recovered = [];
|
|
3408
3570
|
for (const entry of entries) {
|
|
3409
3571
|
if (this.#closing || this.#runs.has(entry) || !/^[0-9a-f]{32}$/.test(entry)) continue;
|
|
3410
|
-
const runDirectory =
|
|
3411
|
-
const statusFile =
|
|
3572
|
+
const runDirectory = path14.join(this.#runRoot, entry);
|
|
3573
|
+
const statusFile = path14.join(runDirectory, "status.json");
|
|
3412
3574
|
const record = readRecord(statusFile);
|
|
3413
|
-
const state = readHostedRunState(
|
|
3575
|
+
const state = readHostedRunState(path14.join(runDirectory, HOSTED_STATE_FILE));
|
|
3414
3576
|
if (!record?.hosted || !state || record.id !== entry || state.context.id !== entry || terminalStatuses.has(record.status)) {
|
|
3415
3577
|
continue;
|
|
3416
3578
|
}
|
|
@@ -3442,9 +3604,9 @@ var AgentManager = class {
|
|
|
3442
3604
|
state,
|
|
3443
3605
|
{
|
|
3444
3606
|
statusFile,
|
|
3445
|
-
lifecycleFile:
|
|
3446
|
-
logFile:
|
|
3447
|
-
stateFile:
|
|
3607
|
+
lifecycleFile: path14.join(runDirectory, "lifecycle.jsonl"),
|
|
3608
|
+
logFile: path14.join(runDirectory, "events.jsonl"),
|
|
3609
|
+
stateFile: path14.join(runDirectory, HOSTED_STATE_FILE)
|
|
3448
3610
|
},
|
|
3449
3611
|
record,
|
|
3450
3612
|
this.#hostedHooks(() => managed, state.holdQuestions === true)
|
|
@@ -3524,16 +3686,16 @@ var AgentManager = class {
|
|
|
3524
3686
|
async recoverWorkerRuns() {
|
|
3525
3687
|
let entries;
|
|
3526
3688
|
try {
|
|
3527
|
-
entries =
|
|
3689
|
+
entries = fs13.readdirSync(this.#runRoot);
|
|
3528
3690
|
} catch {
|
|
3529
3691
|
return [];
|
|
3530
3692
|
}
|
|
3531
3693
|
const recovered = [];
|
|
3532
3694
|
for (const entry of entries) {
|
|
3533
3695
|
if (this.#closing || this.#runs.has(entry) || !/^[0-9a-f]{32}$/.test(entry)) continue;
|
|
3534
|
-
const runDirectory =
|
|
3696
|
+
const runDirectory = path14.join(this.#runRoot, entry);
|
|
3535
3697
|
const recovery = readWorkerRecovery(runDirectory);
|
|
3536
|
-
const statusFile =
|
|
3698
|
+
const statusFile = path14.join(runDirectory, "status.json");
|
|
3537
3699
|
const record = readRecord(statusFile);
|
|
3538
3700
|
if (!recovery || recovery.id !== entry) {
|
|
3539
3701
|
if (!hasWorkerRecovery(runDirectory)) continue;
|
|
@@ -3621,7 +3783,7 @@ var AgentManager = class {
|
|
|
3621
3783
|
indeterminate(`Fabric cannot verify whether worker process ${recovery.pid} is still running`);
|
|
3622
3784
|
continue;
|
|
3623
3785
|
}
|
|
3624
|
-
if (liveness === "dead" && !
|
|
3786
|
+
if (liveness === "dead" && !fs13.existsSync(authority.launch.workerPath)) {
|
|
3625
3787
|
indeterminate(`The worker entry ${recovery.launch.workerPath} no longer exists`);
|
|
3626
3788
|
continue;
|
|
3627
3789
|
}
|
|
@@ -3646,9 +3808,9 @@ var AgentManager = class {
|
|
|
3646
3808
|
residency: "durable",
|
|
3647
3809
|
cwd: record.cwd,
|
|
3648
3810
|
statusFile,
|
|
3649
|
-
lifecycleFile:
|
|
3811
|
+
lifecycleFile: path14.join(runDirectory, "lifecycle.jsonl"),
|
|
3650
3812
|
// Events before this point reached the previous host's ledger.
|
|
3651
|
-
lifecycleOffset: fileSize(
|
|
3813
|
+
lifecycleOffset: fileSize(path14.join(runDirectory, "lifecycle.jsonl")),
|
|
3652
3814
|
lifecycleRemainder: Buffer.alloc(0),
|
|
3653
3815
|
runDirectory,
|
|
3654
3816
|
transport: adoptedWorkerHandle(authority.pid, entry),
|
|
@@ -3907,9 +4069,9 @@ var AgentManager = class {
|
|
|
3907
4069
|
await this.#stopWorkerRunner(managed);
|
|
3908
4070
|
await managed.transport.stop();
|
|
3909
4071
|
await this.#waitForTransportExit(managed);
|
|
3910
|
-
const
|
|
3911
|
-
const record =
|
|
3912
|
-
if (!
|
|
4072
|
+
const terminal2 = readRecord(managed.statusFile);
|
|
4073
|
+
const record = terminal2 && terminalStatuses.has(terminal2.status) ? this.#withTransportMetadata(terminal2, managed) : failedRecord(managed, "stopped", "Agent stopped");
|
|
4074
|
+
if (!terminal2 || !terminalStatuses.has(terminal2.status)) writeRecord(managed.statusFile, record);
|
|
3913
4075
|
await this.#captureWorktree(managed);
|
|
3914
4076
|
this.#settle(managed, record);
|
|
3915
4077
|
return record;
|
|
@@ -3933,15 +4095,15 @@ var AgentManager = class {
|
|
|
3933
4095
|
this.#runs.delete(id);
|
|
3934
4096
|
this.#pruneRetainedUiRecords();
|
|
3935
4097
|
this.#invalidateUiList();
|
|
3936
|
-
return { cleaned: cleaned || !
|
|
4098
|
+
return { cleaned: cleaned || !fs13.existsSync(managed.runDirectory) };
|
|
3937
4099
|
}
|
|
3938
4100
|
readLog(id, opts = {}) {
|
|
3939
4101
|
const managed = this.#requireRun(id);
|
|
3940
4102
|
const runDirectory = managed.runDirectory;
|
|
3941
|
-
const logFile =
|
|
4103
|
+
const logFile = path14.join(runDirectory, "events.jsonl");
|
|
3942
4104
|
const lines = Math.max(1, Math.min(opts.lines ?? 200, 5e3));
|
|
3943
4105
|
const page = readJsonlPage(logFile, lines, opts.before);
|
|
3944
|
-
const statusRecord = readRecord(
|
|
4106
|
+
const statusRecord = readRecord(path14.join(runDirectory, "status.json"));
|
|
3945
4107
|
return {
|
|
3946
4108
|
id,
|
|
3947
4109
|
runDirectory,
|
|
@@ -4016,10 +4178,10 @@ var AgentManager = class {
|
|
|
4016
4178
|
`Fabric agent ${id} already finished (${record.status}); steering has no target`
|
|
4017
4179
|
);
|
|
4018
4180
|
}
|
|
4019
|
-
const steerFile =
|
|
4020
|
-
const messageId =
|
|
4181
|
+
const steerFile = path14.join(managed.runDirectory, "steer.jsonl");
|
|
4182
|
+
const messageId = randomUUID6();
|
|
4021
4183
|
const line = JSON.stringify({ ...entry, id: messageId, ts: Date.now() }) + "\n";
|
|
4022
|
-
|
|
4184
|
+
fs13.appendFileSync(steerFile, line, { encoding: "utf8", mode: 384 });
|
|
4023
4185
|
return { queued: true, messageId };
|
|
4024
4186
|
}
|
|
4025
4187
|
close() {
|
|
@@ -4072,7 +4234,7 @@ var AgentManager = class {
|
|
|
4072
4234
|
removeEmptyRunRoot(this.#runRoot);
|
|
4073
4235
|
}
|
|
4074
4236
|
if (storageSafe && this.#budgetOwned && this.#budget) {
|
|
4075
|
-
await removeTree(
|
|
4237
|
+
await removeTree(path14.dirname(this.#budget.file)).catch(() => void 0);
|
|
4076
4238
|
}
|
|
4077
4239
|
}
|
|
4078
4240
|
if (this.#budgetOwned) clearOwnedBudgetEnv();
|
|
@@ -4114,7 +4276,7 @@ var AgentManager = class {
|
|
|
4114
4276
|
});
|
|
4115
4277
|
for (const managed of expired) {
|
|
4116
4278
|
await removeTree(managed.runDirectory).catch(() => void 0);
|
|
4117
|
-
if (!
|
|
4279
|
+
if (!fs13.existsSync(managed.runDirectory)) this.#runs.delete(managed.id);
|
|
4118
4280
|
}
|
|
4119
4281
|
if (expired.length > 0) {
|
|
4120
4282
|
this.#pruneRetainedUiRecords();
|
|
@@ -4218,7 +4380,7 @@ var AgentManager = class {
|
|
|
4218
4380
|
);
|
|
4219
4381
|
}
|
|
4220
4382
|
if (resume) {
|
|
4221
|
-
|
|
4383
|
+
fs13.writeFileSync(path14.join(managed.runDirectory, "task.txt"), resume.task, {
|
|
4222
4384
|
encoding: "utf8",
|
|
4223
4385
|
mode: 384
|
|
4224
4386
|
});
|
|
@@ -4241,10 +4403,10 @@ var AgentManager = class {
|
|
|
4241
4403
|
}
|
|
4242
4404
|
this.#drainLifecycle(managed);
|
|
4243
4405
|
if (managed.settled || this.#closing || managed.stopRequested) return false;
|
|
4244
|
-
|
|
4406
|
+
fs13.rmSync(managed.statusFile, { force: true });
|
|
4245
4407
|
managed.lifecycleOffset = 0;
|
|
4246
4408
|
managed.lifecycleRemainder = Buffer.alloc(0);
|
|
4247
|
-
|
|
4409
|
+
fs13.rmSync(managed.lifecycleFile, { force: true });
|
|
4248
4410
|
managed.transport = await this.#launchTransport(managed.adapter, managed.launch);
|
|
4249
4411
|
this.#unregisteredTransports.delete(managed.transport);
|
|
4250
4412
|
if (managed.workerRecovery) this.#persistWorkerRecovery(managed);
|
|
@@ -4423,7 +4585,7 @@ var AgentManager = class {
|
|
|
4423
4585
|
managed.questions?.abort(new Error("Agent run settled"));
|
|
4424
4586
|
managed.hosted?.close();
|
|
4425
4587
|
try {
|
|
4426
|
-
|
|
4588
|
+
fs13.rmSync(path14.join(managed.runDirectory, "images.json"), { force: true });
|
|
4427
4589
|
} catch {
|
|
4428
4590
|
}
|
|
4429
4591
|
this.#emitLifecycle(managed, `run.${result.status}`, result.finishedAt ?? Date.now(), {
|
|
@@ -4458,7 +4620,7 @@ var AgentManager = class {
|
|
|
4458
4620
|
#drainLifecycle(managed) {
|
|
4459
4621
|
let content;
|
|
4460
4622
|
try {
|
|
4461
|
-
content =
|
|
4623
|
+
content = fs13.readFileSync(managed.lifecycleFile);
|
|
4462
4624
|
} catch {
|
|
4463
4625
|
return;
|
|
4464
4626
|
}
|
|
@@ -4511,9 +4673,9 @@ var AgentManager = class {
|
|
|
4511
4673
|
const requestId = question.requestId;
|
|
4512
4674
|
const steer = (command) => {
|
|
4513
4675
|
try {
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
`${JSON.stringify({ ...command, id:
|
|
4676
|
+
fs13.appendFileSync(
|
|
4677
|
+
path14.join(managed.runDirectory, "steer.jsonl"),
|
|
4678
|
+
`${JSON.stringify({ ...command, id: randomUUID6(), ts: Date.now() })}
|
|
4517
4679
|
`,
|
|
4518
4680
|
{ encoding: "utf8", mode: 384 }
|
|
4519
4681
|
);
|
|
@@ -4660,7 +4822,7 @@ var AgentManager = class {
|
|
|
4660
4822
|
}
|
|
4661
4823
|
return adapter;
|
|
4662
4824
|
}
|
|
4663
|
-
for (const kind of ["herdr", "localterm", "tmux", "screen", "process"]) {
|
|
4825
|
+
for (const kind of ["herdr-core", "herdr", "localterm", "tmux", "screen", "process"]) {
|
|
4664
4826
|
const adapter = this.#transports.get(kind);
|
|
4665
4827
|
if (adapter && await adapter.available()) return adapter;
|
|
4666
4828
|
}
|
|
@@ -4728,7 +4890,7 @@ var AgentManager = class {
|
|
|
4728
4890
|
// directories. Terminal-owner reconciliation prevents cached active ghosts.
|
|
4729
4891
|
#nestedAgents(managed, force = false) {
|
|
4730
4892
|
const now = Date.now();
|
|
4731
|
-
const needsInitialDiscovery = managed.nestedSnapshot === void 0 &&
|
|
4893
|
+
const needsInitialDiscovery = managed.nestedSnapshot === void 0 && fs13.existsSync(path14.join(managed.runDirectory, "nested"));
|
|
4732
4894
|
if (!force && !needsInitialDiscovery && managed.nestedSnapshotAt !== void 0 && now - managed.nestedSnapshotAt < NESTED_SNAPSHOT_POLL_MS) {
|
|
4733
4895
|
return managed.nestedSnapshot ? structuredClone(managed.nestedSnapshot) : [];
|
|
4734
4896
|
}
|
|
@@ -4756,7 +4918,7 @@ var AgentManager = class {
|
|
|
4756
4918
|
runner: managed.runner,
|
|
4757
4919
|
...managed.kernel ? { kernel: managed.kernel } : {},
|
|
4758
4920
|
...managed.residency === "durable" ? { residency: "durable" } : {},
|
|
4759
|
-
logFile:
|
|
4921
|
+
logFile: path14.join(managed.runDirectory, "events.jsonl"),
|
|
4760
4922
|
...nestedAgents.length > 0 ? { nestedAgents } : {},
|
|
4761
4923
|
...budget ? { budget } : {},
|
|
4762
4924
|
...model ? { model } : {},
|
|
@@ -4812,15 +4974,15 @@ var actorDeliveryNotice = (delivery, triggerTurn) => {
|
|
|
4812
4974
|
};
|
|
4813
4975
|
|
|
4814
4976
|
// src/actors/directory.ts
|
|
4815
|
-
import
|
|
4977
|
+
import fs20 from "node:fs";
|
|
4816
4978
|
|
|
4817
4979
|
// src/actors/manager.ts
|
|
4818
|
-
import { randomUUID as
|
|
4819
|
-
import
|
|
4980
|
+
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
4981
|
+
import fs19 from "node:fs";
|
|
4820
4982
|
|
|
4821
4983
|
// src/actors/mesh-monitor.ts
|
|
4822
|
-
import
|
|
4823
|
-
import
|
|
4984
|
+
import fs14 from "node:fs";
|
|
4985
|
+
import path15 from "node:path";
|
|
4824
4986
|
var MESH_WATCH_RECONCILE_MS = 2e3;
|
|
4825
4987
|
var ActorMeshMonitor = class {
|
|
4826
4988
|
constructor(mesh, config, callbacks) {
|
|
@@ -4847,8 +5009,8 @@ var ActorMeshMonitor = class {
|
|
|
4847
5009
|
return;
|
|
4848
5010
|
}
|
|
4849
5011
|
try {
|
|
4850
|
-
const watcher =
|
|
4851
|
-
const name = filename == null ? void 0 :
|
|
5012
|
+
const watcher = fs14.watch(this.mesh.root, { persistent: false }, (_event, filename) => {
|
|
5013
|
+
const name = filename == null ? void 0 : path15.basename(filename.toString());
|
|
4852
5014
|
if (name !== void 0 && name !== "events.jsonl" && name !== "schedules.json") return;
|
|
4853
5015
|
this.schedule();
|
|
4854
5016
|
});
|
|
@@ -4940,7 +5102,7 @@ var ActorMeshMonitor = class {
|
|
|
4940
5102
|
#readCursor() {
|
|
4941
5103
|
if (!this.callbacks.cursorPath) return void 0;
|
|
4942
5104
|
try {
|
|
4943
|
-
const value = JSON.parse(
|
|
5105
|
+
const value = JSON.parse(fs14.readFileSync(this.callbacks.cursorPath, "utf8"));
|
|
4944
5106
|
return value.format === 1 && typeof value.cursor === "number" && value.cursor >= 0 ? value.cursor : void 0;
|
|
4945
5107
|
} catch {
|
|
4946
5108
|
return void 0;
|
|
@@ -4957,11 +5119,11 @@ var ActorMeshMonitor = class {
|
|
|
4957
5119
|
|
|
4958
5120
|
// src/actors/manager.ts
|
|
4959
5121
|
import os4 from "node:os";
|
|
4960
|
-
import
|
|
5122
|
+
import path19 from "node:path";
|
|
4961
5123
|
|
|
4962
5124
|
// src/actors/log-store.ts
|
|
4963
|
-
import
|
|
4964
|
-
import
|
|
5125
|
+
import fs15 from "node:fs";
|
|
5126
|
+
import path16 from "node:path";
|
|
4965
5127
|
var ACTOR_MESSAGE_HISTORY_LIMIT = 100;
|
|
4966
5128
|
var ACTOR_MESSAGE_ENVELOPE_BYTES = 4096;
|
|
4967
5129
|
var ACTOR_TRUNCATION_SUFFIX = "\n[actor message truncated]";
|
|
@@ -5019,17 +5181,17 @@ var ActorLogStore = class {
|
|
|
5019
5181
|
this.retention = retention;
|
|
5020
5182
|
}
|
|
5021
5183
|
async retainRun(actor, runId, runDirectory) {
|
|
5022
|
-
if (!runDirectory || !
|
|
5023
|
-
const dest =
|
|
5024
|
-
|
|
5184
|
+
if (!runDirectory || !fs15.existsSync(runDirectory)) return;
|
|
5185
|
+
const dest = path16.join(path16.dirname(actor.sessionFile), "runs", runId);
|
|
5186
|
+
fs15.mkdirSync(dest, { recursive: true, mode: 448 });
|
|
5025
5187
|
for (const file of ["events.jsonl", "status.json", "task.txt"]) {
|
|
5026
|
-
const src =
|
|
5027
|
-
if (
|
|
5188
|
+
const src = path16.join(runDirectory, file);
|
|
5189
|
+
if (fs15.existsSync(src)) fs15.copyFileSync(src, path16.join(dest, file));
|
|
5028
5190
|
}
|
|
5029
|
-
const nested =
|
|
5030
|
-
if (
|
|
5191
|
+
const nested = path16.join(runDirectory, "nested");
|
|
5192
|
+
if (fs15.existsSync(nested)) {
|
|
5031
5193
|
try {
|
|
5032
|
-
|
|
5194
|
+
fs15.cpSync(nested, path16.join(dest, "nested"), { recursive: true });
|
|
5033
5195
|
} catch {
|
|
5034
5196
|
}
|
|
5035
5197
|
}
|
|
@@ -5037,16 +5199,16 @@ var ActorLogStore = class {
|
|
|
5037
5199
|
}
|
|
5038
5200
|
pruneRuns(actor, now = Date.now()) {
|
|
5039
5201
|
pruneActorRunArchives({
|
|
5040
|
-
runsDirectory:
|
|
5202
|
+
runsDirectory: path16.join(path16.dirname(actor.sessionFile), "runs"),
|
|
5041
5203
|
...actor.lastRunId ? { latestRunId: actor.lastRunId } : {},
|
|
5042
5204
|
retentionMs: this.retention.actorRunArchiveMs,
|
|
5043
5205
|
now
|
|
5044
5206
|
});
|
|
5045
5207
|
}
|
|
5046
5208
|
retainedRunIds(actor) {
|
|
5047
|
-
const runsDir =
|
|
5209
|
+
const runsDir = path16.join(path16.dirname(actor.sessionFile), "runs");
|
|
5048
5210
|
try {
|
|
5049
|
-
return
|
|
5211
|
+
return fs15.readdirSync(runsDir).sort();
|
|
5050
5212
|
} catch {
|
|
5051
5213
|
return [];
|
|
5052
5214
|
}
|
|
@@ -5195,12 +5357,12 @@ var evaluateActorValidWhile = async (source, facts) => {
|
|
|
5195
5357
|
};
|
|
5196
5358
|
|
|
5197
5359
|
// src/actors/binding-store.ts
|
|
5198
|
-
import { createHash, randomUUID as
|
|
5199
|
-
import
|
|
5200
|
-
import
|
|
5360
|
+
import { createHash, randomUUID as randomUUID7 } from "node:crypto";
|
|
5361
|
+
import fs17 from "node:fs";
|
|
5362
|
+
import path17 from "node:path";
|
|
5201
5363
|
|
|
5202
5364
|
// src/actors/store-read.ts
|
|
5203
|
-
import
|
|
5365
|
+
import fs16 from "node:fs";
|
|
5204
5366
|
var ActorStoreReadError = class extends Error {
|
|
5205
5367
|
filePath;
|
|
5206
5368
|
constructor(filePath, detail, options) {
|
|
@@ -5212,7 +5374,7 @@ var ActorStoreReadError = class extends Error {
|
|
|
5212
5374
|
var readStoreJson = (filePath) => {
|
|
5213
5375
|
let text;
|
|
5214
5376
|
try {
|
|
5215
|
-
text =
|
|
5377
|
+
text = fs16.readFileSync(filePath, "utf8");
|
|
5216
5378
|
} catch (error) {
|
|
5217
5379
|
if (error?.code === "ENOENT") return void 0;
|
|
5218
5380
|
throw new ActorStoreReadError(
|
|
@@ -5241,7 +5403,7 @@ var delay2 = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
5241
5403
|
var ActorBindingStore = class {
|
|
5242
5404
|
constructor(sessionId, root) {
|
|
5243
5405
|
this.sessionId = sessionId;
|
|
5244
|
-
this.filePath = root ?
|
|
5406
|
+
this.filePath = root ? path17.join(root, "bindings", bindingFileName(sessionId)) : void 0;
|
|
5245
5407
|
this.#sync(true);
|
|
5246
5408
|
}
|
|
5247
5409
|
#bindings = /* @__PURE__ */ new Map();
|
|
@@ -5374,7 +5536,7 @@ var ActorBindingStore = class {
|
|
|
5374
5536
|
#currentFingerprint() {
|
|
5375
5537
|
if (!this.filePath) return void 0;
|
|
5376
5538
|
try {
|
|
5377
|
-
const stat =
|
|
5539
|
+
const stat = fs17.statSync(this.filePath);
|
|
5378
5540
|
return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeMs}`;
|
|
5379
5541
|
} catch {
|
|
5380
5542
|
return void 0;
|
|
@@ -5384,7 +5546,7 @@ var ActorBindingStore = class {
|
|
|
5384
5546
|
if (!this.filePath) return operation();
|
|
5385
5547
|
const lockPath = `${this.filePath}.lock`;
|
|
5386
5548
|
const deadline = Date.now() + BINDING_LOCK_TIMEOUT_MS;
|
|
5387
|
-
const token =
|
|
5549
|
+
const token = randomUUID7();
|
|
5388
5550
|
const processAlive2 = (pid) => {
|
|
5389
5551
|
if (!Number.isSafeInteger(pid) || pid <= 0) return false;
|
|
5390
5552
|
try {
|
|
@@ -5394,7 +5556,7 @@ var ActorBindingStore = class {
|
|
|
5394
5556
|
return false;
|
|
5395
5557
|
}
|
|
5396
5558
|
};
|
|
5397
|
-
|
|
5559
|
+
fs17.mkdirSync(path17.dirname(this.filePath), { recursive: true, mode: 448 });
|
|
5398
5560
|
while (!tryAcquireShortLock(lockPath, formatShortLockOwner(token))) {
|
|
5399
5561
|
if (reapStaleShortLock(lockPath, { staleMs: BINDING_STALE_LOCK_MS, legacyAlive: processAlive2 })) continue;
|
|
5400
5562
|
if (Date.now() >= deadline) {
|
|
@@ -5411,9 +5573,9 @@ var ActorBindingStore = class {
|
|
|
5411
5573
|
};
|
|
5412
5574
|
|
|
5413
5575
|
// src/actors/registry-store.ts
|
|
5414
|
-
import { randomUUID as
|
|
5415
|
-
import
|
|
5416
|
-
import
|
|
5576
|
+
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
5577
|
+
import fs18 from "node:fs";
|
|
5578
|
+
import path18 from "node:path";
|
|
5417
5579
|
import { setTimeout as delay3 } from "node:timers/promises";
|
|
5418
5580
|
var ACTOR_REGISTRY_LOCK_TIMEOUT_MS = 5e3;
|
|
5419
5581
|
var ACTOR_REGISTRY_STALE_LOCK_MS = 3e4;
|
|
@@ -5424,7 +5586,7 @@ var ActorRegistryStore = class {
|
|
|
5424
5586
|
#actorRoot;
|
|
5425
5587
|
constructor(actorRoot) {
|
|
5426
5588
|
this.#actorRoot = actorRoot;
|
|
5427
|
-
this.#registryPath =
|
|
5589
|
+
this.#registryPath = path18.join(actorRoot, "actors.json");
|
|
5428
5590
|
}
|
|
5429
5591
|
/**
|
|
5430
5592
|
* Every entry in actors.json, including entries without a valid identity, so
|
|
@@ -5448,7 +5610,7 @@ var ActorRegistryStore = class {
|
|
|
5448
5610
|
async withLock(operation, signal) {
|
|
5449
5611
|
const lockPath = `${this.#registryPath}.lock`;
|
|
5450
5612
|
const deadline = Date.now() + ACTOR_REGISTRY_LOCK_TIMEOUT_MS;
|
|
5451
|
-
const token =
|
|
5613
|
+
const token = randomUUID8();
|
|
5452
5614
|
const processAlive2 = (pid) => {
|
|
5453
5615
|
if (!Number.isSafeInteger(pid) || pid <= 0) return false;
|
|
5454
5616
|
try {
|
|
@@ -5458,7 +5620,7 @@ var ActorRegistryStore = class {
|
|
|
5458
5620
|
return false;
|
|
5459
5621
|
}
|
|
5460
5622
|
};
|
|
5461
|
-
|
|
5623
|
+
fs18.mkdirSync(this.#actorRoot, { recursive: true, mode: 448 });
|
|
5462
5624
|
signal?.throwIfAborted();
|
|
5463
5625
|
while (!tryAcquireShortLock(lockPath, formatShortLockOwner(token))) {
|
|
5464
5626
|
if (reapStaleShortLock(lockPath, { staleMs: ACTOR_REGISTRY_STALE_LOCK_MS, legacyAlive: processAlive2 })) continue;
|
|
@@ -5477,14 +5639,14 @@ var ActorRegistryStore = class {
|
|
|
5477
5639
|
}
|
|
5478
5640
|
fingerprint() {
|
|
5479
5641
|
try {
|
|
5480
|
-
const stat =
|
|
5642
|
+
const stat = fs18.statSync(this.#registryPath);
|
|
5481
5643
|
return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeMs}`;
|
|
5482
5644
|
} catch {
|
|
5483
5645
|
return void 0;
|
|
5484
5646
|
}
|
|
5485
5647
|
}
|
|
5486
5648
|
read() {
|
|
5487
|
-
return JSON.parse(
|
|
5649
|
+
return JSON.parse(fs18.readFileSync(this.#registryPath, "utf8"));
|
|
5488
5650
|
}
|
|
5489
5651
|
/** Call within withLock for read-modify-write operations. */
|
|
5490
5652
|
write(actors) {
|
|
@@ -5522,7 +5684,7 @@ var normalizeCapabilityRequirements = (requirements = []) => {
|
|
|
5522
5684
|
};
|
|
5523
5685
|
var readRunRecord = (filePath) => {
|
|
5524
5686
|
try {
|
|
5525
|
-
const parsed = JSON.parse(
|
|
5687
|
+
const parsed = JSON.parse(fs19.readFileSync(filePath, "utf8"));
|
|
5526
5688
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return void 0;
|
|
5527
5689
|
return parsed;
|
|
5528
5690
|
} catch {
|
|
@@ -5572,7 +5734,7 @@ var ActorManager = class {
|
|
|
5572
5734
|
this.meshConfig = meshConfig;
|
|
5573
5735
|
this.agents = agents;
|
|
5574
5736
|
this.onDeliver = onDeliver;
|
|
5575
|
-
this.#actorRoot = options.actorRoot ??
|
|
5737
|
+
this.#actorRoot = options.actorRoot ?? fs19.mkdtempSync(path19.join(os4.tmpdir(), "pi-fabric-actors-"));
|
|
5576
5738
|
this.#actorScope = options.actorScope ?? meshConfig.actorScope;
|
|
5577
5739
|
this.#persistent = options.persistent ?? false;
|
|
5578
5740
|
this.#mainAgent = options.mainAgent;
|
|
@@ -5744,8 +5906,8 @@ var ActorManager = class {
|
|
|
5744
5906
|
throw new Error("This Fabric host cannot commit actor capability requirements");
|
|
5745
5907
|
}
|
|
5746
5908
|
const principalScope = launchScope(void 0, request.principalScope);
|
|
5747
|
-
const id =
|
|
5748
|
-
const actorDirectory =
|
|
5909
|
+
const id = randomUUID9().replaceAll("-", "");
|
|
5910
|
+
const actorDirectory = path19.join(this.#actorRoot, id);
|
|
5749
5911
|
const actor = {
|
|
5750
5912
|
id,
|
|
5751
5913
|
name,
|
|
@@ -5772,14 +5934,14 @@ var ActorManager = class {
|
|
|
5772
5934
|
...request.validWhile ? { validWhile: structuredClone(request.validWhile) } : {},
|
|
5773
5935
|
...principalScope ? { principalScope } : {},
|
|
5774
5936
|
latestActivationSequence: 0,
|
|
5775
|
-
sessionFile:
|
|
5937
|
+
sessionFile: path19.join(actorDirectory, "session.jsonl"),
|
|
5776
5938
|
queue: [],
|
|
5777
5939
|
draining: false,
|
|
5778
5940
|
messages: [],
|
|
5779
5941
|
createdAt: Date.now(),
|
|
5780
5942
|
updatedAt: Date.now()
|
|
5781
5943
|
};
|
|
5782
|
-
|
|
5944
|
+
fs19.mkdirSync(actorDirectory, { recursive: true, mode: 448 });
|
|
5783
5945
|
this.#actors.set(id, actor);
|
|
5784
5946
|
this.#locallyCreated.add(id);
|
|
5785
5947
|
this.#ownership.set(id, true);
|
|
@@ -6109,17 +6271,17 @@ var ActorManager = class {
|
|
|
6109
6271
|
const type = opts.type ?? "session";
|
|
6110
6272
|
const lines = Math.max(1, Math.min(opts.lines ?? 200, 5e3));
|
|
6111
6273
|
const sessionFile = actor.sessionFile;
|
|
6112
|
-
const logDir =
|
|
6274
|
+
const logDir = path19.join(path19.dirname(sessionFile), "runs");
|
|
6113
6275
|
const sessionPage = type === "run" ? { lines: [], hasMore: false } : readJsonlPage(sessionFile, lines, opts.before);
|
|
6114
6276
|
const session = sessionPage.lines;
|
|
6115
6277
|
let run;
|
|
6116
6278
|
if (type !== "session") {
|
|
6117
6279
|
const targetRunId = opts.runId ?? actor.lastRunId;
|
|
6118
6280
|
if (targetRunId) {
|
|
6119
|
-
const runPath =
|
|
6120
|
-
if (
|
|
6121
|
-
const statusRecord = readRunRecord(
|
|
6122
|
-
const eventsFile =
|
|
6281
|
+
const runPath = path19.join(logDir, targetRunId);
|
|
6282
|
+
if (fs19.existsSync(runPath)) {
|
|
6283
|
+
const statusRecord = readRunRecord(path19.join(runPath, "status.json"));
|
|
6284
|
+
const eventsFile = path19.join(runPath, "events.jsonl");
|
|
6123
6285
|
const page = readJsonlPage(eventsFile, lines, opts.before);
|
|
6124
6286
|
run = {
|
|
6125
6287
|
runId: targetRunId,
|
|
@@ -6322,7 +6484,7 @@ var ActorManager = class {
|
|
|
6322
6484
|
await this.#bindings.delete(actor.id);
|
|
6323
6485
|
this.#actors.delete(actor.id);
|
|
6324
6486
|
this.#emitChange();
|
|
6325
|
-
|
|
6487
|
+
fs19.rmSync(path19.dirname(actor.sessionFile), { recursive: true, force: true });
|
|
6326
6488
|
await this.#saveActors(/* @__PURE__ */ new Set([actor.id]));
|
|
6327
6489
|
await this.mesh.delete({ key: this.#presenceKey(actor.id) }).catch(() => ({ deleted: false }));
|
|
6328
6490
|
if (retainedRunId) await this.agents.cleanup(retainedRunId).catch(() => ({ cleaned: false }));
|
|
@@ -6363,7 +6525,7 @@ var ActorManager = class {
|
|
|
6363
6525
|
await Promise.allSettled(
|
|
6364
6526
|
[...this.#actors.values()].map((actor) => actor.drain ?? Promise.resolve())
|
|
6365
6527
|
);
|
|
6366
|
-
|
|
6528
|
+
fs19.rmSync(this.#actorRoot, { recursive: true, force: true });
|
|
6367
6529
|
}
|
|
6368
6530
|
#enqueue(actor, source, payload, options = {}) {
|
|
6369
6531
|
const canManage = options.ownershipChecked ? this.#canManageCached(actor.id) : this.#canManage(actor.id);
|
|
@@ -6406,7 +6568,7 @@ var ActorManager = class {
|
|
|
6406
6568
|
`Fabric actor queue limit reached for ${actor.name} (${this.meshConfig.actorQueueLimit})`
|
|
6407
6569
|
);
|
|
6408
6570
|
}
|
|
6409
|
-
const itemId =
|
|
6571
|
+
const itemId = randomUUID9();
|
|
6410
6572
|
const item = {
|
|
6411
6573
|
id: itemId,
|
|
6412
6574
|
source,
|
|
@@ -6526,7 +6688,7 @@ var ActorManager = class {
|
|
|
6526
6688
|
if (actor.responseMode === "directive") {
|
|
6527
6689
|
const reason = result.error || `Actor run ${result.status}`;
|
|
6528
6690
|
const silent = {
|
|
6529
|
-
id:
|
|
6691
|
+
id: randomUUID9(),
|
|
6530
6692
|
actorId: actor.id,
|
|
6531
6693
|
actorName: actor.name,
|
|
6532
6694
|
direction: "out",
|
|
@@ -6592,7 +6754,7 @@ var ActorManager = class {
|
|
|
6592
6754
|
}
|
|
6593
6755
|
actor.lastError = message2;
|
|
6594
6756
|
const failed = {
|
|
6595
|
-
id:
|
|
6757
|
+
id: randomUUID9(),
|
|
6596
6758
|
actorId: actor.id,
|
|
6597
6759
|
actorName: actor.name,
|
|
6598
6760
|
direction: "out",
|
|
@@ -6684,7 +6846,7 @@ var ActorManager = class {
|
|
|
6684
6846
|
if (actor.responseMode === "directive") {
|
|
6685
6847
|
const directive = asDirective(result);
|
|
6686
6848
|
return {
|
|
6687
|
-
id:
|
|
6849
|
+
id: randomUUID9(),
|
|
6688
6850
|
actorId: actor.id,
|
|
6689
6851
|
actorName: actor.name,
|
|
6690
6852
|
direction: "out",
|
|
@@ -6698,7 +6860,7 @@ var ActorManager = class {
|
|
|
6698
6860
|
};
|
|
6699
6861
|
}
|
|
6700
6862
|
return {
|
|
6701
|
-
id:
|
|
6863
|
+
id: randomUUID9(),
|
|
6702
6864
|
actorId: actor.id,
|
|
6703
6865
|
actorName: actor.name,
|
|
6704
6866
|
direction: "out",
|
|
@@ -6753,7 +6915,7 @@ var ActorManager = class {
|
|
|
6753
6915
|
}
|
|
6754
6916
|
#recordStale(actor, item, reason = "validWhile returned false", runId, usage) {
|
|
6755
6917
|
const message2 = {
|
|
6756
|
-
id:
|
|
6918
|
+
id: randomUUID9(),
|
|
6757
6919
|
actorId: actor.id,
|
|
6758
6920
|
actorName: actor.name,
|
|
6759
6921
|
direction: "out",
|
|
@@ -7027,7 +7189,7 @@ var ActorManager = class {
|
|
|
7027
7189
|
...typeof record.model === "string" ? { model: record.model } : {},
|
|
7028
7190
|
...isFabricThinking(record.thinking) ? { thinking: record.thinking } : {},
|
|
7029
7191
|
...Array.isArray(record.tools) ? { tools: record.tools.filter((tool) => typeof tool === "string") } : {},
|
|
7030
|
-
...record.transport === "auto" || record.transport === "process" || record.transport === "tmux" || record.transport === "screen" || record.transport === "localterm" || record.transport === "herdr" ? { transport: record.transport } : {},
|
|
7192
|
+
...record.transport === "auto" || record.transport === "process" || record.transport === "tmux" || record.transport === "screen" || record.transport === "localterm" || record.transport === "herdr" || record.transport === "herdr-core" ? { transport: record.transport } : {},
|
|
7031
7193
|
...typeof record.timeoutMs === "number" ? { timeoutMs: record.timeoutMs } : {},
|
|
7032
7194
|
...typeof record.extensions === "boolean" ? { extensions: record.extensions } : {},
|
|
7033
7195
|
requirements,
|
|
@@ -7035,7 +7197,7 @@ var ActorManager = class {
|
|
|
7035
7197
|
...record.validWhile?.version === 1 && typeof record.validWhile.source === "string" ? { validWhile: record.validWhile } : {},
|
|
7036
7198
|
...principalScope ? { principalScope } : {},
|
|
7037
7199
|
latestActivationSequence: 0,
|
|
7038
|
-
sessionFile:
|
|
7200
|
+
sessionFile: path19.join(this.#actorRoot, record.id, "session.jsonl"),
|
|
7039
7201
|
queue: [],
|
|
7040
7202
|
draining: false,
|
|
7041
7203
|
messages: [],
|
|
@@ -7140,7 +7302,7 @@ var ActorManager = class {
|
|
|
7140
7302
|
...actor.lastRunId ? { lastRunId: actor.lastRunId } : {},
|
|
7141
7303
|
...actor.lastError ? { lastError: actor.lastError } : {},
|
|
7142
7304
|
sessionFile: actor.sessionFile,
|
|
7143
|
-
logDir:
|
|
7305
|
+
logDir: path19.join(path19.dirname(actor.sessionFile), "runs")
|
|
7144
7306
|
};
|
|
7145
7307
|
}
|
|
7146
7308
|
validateDirectMessage(message2, data) {
|
|
@@ -7347,10 +7509,10 @@ var ActorDirectory = class extends ActorManager {
|
|
|
7347
7509
|
delete options.actorRoot;
|
|
7348
7510
|
delete options.meshCursorPath;
|
|
7349
7511
|
const cursorPaths = meshCursorPath ? { project: `${meshCursorPath}.project`, session: `${meshCursorPath}.session` } : void 0;
|
|
7350
|
-
if (meshCursorPath &&
|
|
7512
|
+
if (meshCursorPath && fs20.existsSync(meshCursorPath)) {
|
|
7351
7513
|
for (const cursorPath of Object.values(cursorPaths)) {
|
|
7352
7514
|
try {
|
|
7353
|
-
if (!
|
|
7515
|
+
if (!fs20.existsSync(cursorPath)) fs20.copyFileSync(meshCursorPath, cursorPath);
|
|
7354
7516
|
} catch {
|
|
7355
7517
|
}
|
|
7356
7518
|
}
|
|
@@ -7522,7 +7684,7 @@ var ActorDirectory = class extends ActorManager {
|
|
|
7522
7684
|
};
|
|
7523
7685
|
|
|
7524
7686
|
// src/lifecycle/broker.ts
|
|
7525
|
-
import { randomUUID as
|
|
7687
|
+
import { randomUUID as randomUUID10 } from "node:crypto";
|
|
7526
7688
|
var subscriptionKey = (id) => FABRIC_LIFECYCLE_SUBSCRIPTION_PREFIX + id;
|
|
7527
7689
|
var LifecycleBroker = class {
|
|
7528
7690
|
constructor(mesh, identity, participants, options, deliver) {
|
|
@@ -7601,7 +7763,7 @@ var LifecycleBroker = class {
|
|
|
7601
7763
|
const now = Date.now();
|
|
7602
7764
|
const subscription = {
|
|
7603
7765
|
format: 1,
|
|
7604
|
-
id:
|
|
7766
|
+
id: randomUUID10().replaceAll("-", ""),
|
|
7605
7767
|
from,
|
|
7606
7768
|
events,
|
|
7607
7769
|
to,
|
|
@@ -7771,7 +7933,7 @@ var LifecycleBroker = class {
|
|
|
7771
7933
|
};
|
|
7772
7934
|
|
|
7773
7935
|
// src/topology/control-plane.ts
|
|
7774
|
-
import { createHash as createHash2, randomUUID as
|
|
7936
|
+
import { createHash as createHash2, randomUUID as randomUUID11 } from "node:crypto";
|
|
7775
7937
|
var CONTROL_TOPIC = "fabric.control.command";
|
|
7776
7938
|
var ACK_TOPIC = "fabric.control.ack";
|
|
7777
7939
|
var CONTROL_SEEN_PREFIX = "topology/control-seen/";
|
|
@@ -7819,7 +7981,7 @@ var FabricControlPlane = class {
|
|
|
7819
7981
|
#activeHandlers = /* @__PURE__ */ new Set();
|
|
7820
7982
|
#pollMs;
|
|
7821
7983
|
#ackTimeoutMs;
|
|
7822
|
-
#incarnation =
|
|
7984
|
+
#incarnation = randomUUID11();
|
|
7823
7985
|
#offset;
|
|
7824
7986
|
#lastSequence;
|
|
7825
7987
|
#timer;
|
|
@@ -7881,7 +8043,7 @@ var FabricControlPlane = class {
|
|
|
7881
8043
|
this.#pollMs * 4,
|
|
7882
8044
|
Math.min(MAX_CONTROL_TIMEOUT_MS, Math.floor(options.timeoutMs ?? this.#ackTimeoutMs))
|
|
7883
8045
|
);
|
|
7884
|
-
const commandId =
|
|
8046
|
+
const commandId = randomUUID11();
|
|
7885
8047
|
const requestedAt = Date.now();
|
|
7886
8048
|
let pendingRequest;
|
|
7887
8049
|
const acceptance = new Promise((resolve, reject) => {
|
|
@@ -7975,7 +8137,7 @@ var FabricControlPlane = class {
|
|
|
7975
8137
|
to: pending.ownerHostId,
|
|
7976
8138
|
data: {
|
|
7977
8139
|
version: 1,
|
|
7978
|
-
commandId:
|
|
8140
|
+
commandId: randomUUID11(),
|
|
7979
8141
|
targetId: pending.targetId,
|
|
7980
8142
|
operation: "cancel",
|
|
7981
8143
|
cancelCommandId: commandId,
|
|
@@ -8275,7 +8437,8 @@ var transports = /* @__PURE__ */ new Set([
|
|
|
8275
8437
|
"tmux",
|
|
8276
8438
|
"screen",
|
|
8277
8439
|
"localterm",
|
|
8278
|
-
"herdr"
|
|
8440
|
+
"herdr",
|
|
8441
|
+
"herdr-core"
|
|
8279
8442
|
]);
|
|
8280
8443
|
var capabilities = /* @__PURE__ */ new Set([
|
|
8281
8444
|
"steer",
|
|
@@ -9015,4 +9178,4 @@ export {
|
|
|
9015
9178
|
agentParticipantRecords,
|
|
9016
9179
|
actorParticipantRecord
|
|
9017
9180
|
};
|
|
9018
|
-
//# sourceMappingURL=chunk-
|
|
9181
|
+
//# sourceMappingURL=chunk-VGRUWTMG.js.map
|