@e4779/pi-fabric 0.92.17-fork.3 → 0.92.28-fork.5
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/actors/host-event-payload.d.ts.map +1 -1
- package/dist/agents/budget-ledger.d.ts.map +1 -1
- package/dist/agents/handoff-continuation.d.ts +4 -0
- package/dist/agents/handoff-continuation.d.ts.map +1 -0
- package/dist/agents/manager.d.ts.map +1 -1
- package/dist/agents/request.d.ts +4 -0
- package/dist/agents/request.d.ts.map +1 -1
- package/dist/agents.js +5 -4
- package/dist/agents.js.map +1 -1
- package/dist/chunks/{chunk-GXNR6NRU.js → chunk-2IAVP4O2.js} +2 -2
- package/dist/chunks/{chunk-TPLMVELH.js → chunk-77PDIBK2.js} +15 -4
- package/dist/chunks/{chunk-TPLMVELH.js.map → chunk-77PDIBK2.js.map} +2 -2
- package/dist/chunks/chunk-7TX532EG.js +134 -0
- package/dist/chunks/chunk-7TX532EG.js.map +7 -0
- package/dist/chunks/chunk-BJOJX2UW.js +59 -0
- package/dist/chunks/chunk-BJOJX2UW.js.map +7 -0
- package/dist/chunks/{chunk-2PZWDVJB.js → chunk-BYOGRJME.js} +13 -4
- package/dist/chunks/chunk-BYOGRJME.js.map +7 -0
- package/dist/chunks/{chunk-RERA6YWA.js → chunk-CIODQX77.js} +12 -4
- package/dist/chunks/chunk-CIODQX77.js.map +7 -0
- package/dist/chunks/{chunk-OP2KTYQB.js → chunk-D6YSBP3R.js} +4 -4
- package/dist/chunks/chunk-EDL4JDW7.js +184 -0
- package/dist/chunks/chunk-EDL4JDW7.js.map +7 -0
- package/dist/chunks/{chunk-WVH324VF.js → chunk-FAMBJFFF.js} +1 -1
- package/dist/chunks/{chunk-WVH324VF.js.map → chunk-FAMBJFFF.js.map} +1 -1
- package/dist/chunks/{chunk-UDFDF7IY.js → chunk-G7UJLM33.js} +148 -251
- package/dist/chunks/chunk-G7UJLM33.js.map +7 -0
- package/dist/chunks/{chunk-RNOPHITP.js → chunk-H6DDV6E2.js} +180 -24
- package/dist/chunks/chunk-H6DDV6E2.js.map +7 -0
- package/dist/chunks/{chunk-ARLYAW2A.js → chunk-IR3PIHJM.js} +2 -1
- package/dist/chunks/chunk-IR3PIHJM.js.map +7 -0
- package/dist/chunks/{chunk-VRZNFNPB.js → chunk-IYQ5MNCW.js} +20 -17
- package/dist/chunks/chunk-IYQ5MNCW.js.map +7 -0
- package/dist/chunks/chunk-JNMTTJMQ.js +50 -0
- package/dist/chunks/chunk-JNMTTJMQ.js.map +7 -0
- package/dist/chunks/{chunk-CPSW2GW4.js → chunk-JOEFBOFN.js} +11 -7
- package/dist/chunks/chunk-JOEFBOFN.js.map +7 -0
- package/dist/chunks/chunk-KI277YNS.js +218 -0
- package/dist/chunks/chunk-KI277YNS.js.map +7 -0
- package/dist/chunks/{chunk-Y7KNRAFL.js → chunk-M3ZNZ6EZ.js} +28 -3
- package/dist/chunks/chunk-M3ZNZ6EZ.js.map +7 -0
- package/dist/chunks/{chunk-2DMJ7MEI.js → chunk-M7W57BRC.js} +172 -141
- package/dist/chunks/chunk-M7W57BRC.js.map +7 -0
- package/dist/chunks/{chunk-U6CTHPZC.js → chunk-MQG5QKGI.js} +2 -2
- package/dist/chunks/{chunk-CI56CW53.js → chunk-NPHCGLGH.js} +16 -10
- package/dist/chunks/chunk-NPHCGLGH.js.map +7 -0
- package/dist/chunks/{chunk-4SSMGBF4.js → chunk-QLV2IZ3F.js} +6 -7
- package/dist/chunks/chunk-QLV2IZ3F.js.map +7 -0
- package/dist/chunks/{chunk-PH7ZJ27F.js → chunk-RAEGNBRA.js} +210 -118
- package/dist/chunks/chunk-RAEGNBRA.js.map +7 -0
- package/dist/chunks/chunk-RAO6TQFP.js +187 -0
- package/dist/chunks/chunk-RAO6TQFP.js.map +7 -0
- package/dist/chunks/{chunk-ZZ4LHQYJ.js → chunk-RTXZHKMS.js} +22 -13
- package/dist/chunks/chunk-RTXZHKMS.js.map +7 -0
- package/dist/chunks/{chunk-BOTRGFQQ.js → chunk-RWDKJ24D.js} +26 -19
- package/dist/chunks/chunk-RWDKJ24D.js.map +7 -0
- package/dist/chunks/{chunk-2UQV52II.js → chunk-RZKN534S.js} +6 -6
- package/dist/chunks/{chunk-656HWVFU.js → chunk-SZUXWOO7.js} +5 -3
- package/dist/chunks/chunk-SZUXWOO7.js.map +7 -0
- package/dist/chunks/{chunk-YK5AZ7CZ.js → chunk-ULLIZPBH.js} +7 -7
- package/dist/chunks/{chunk-UTR3I23Z.js → chunk-W63E3WEO.js} +2 -2
- package/dist/chunks/{chunk-32BNQ75J.js → chunk-WG24VI7K.js} +56 -2
- package/dist/chunks/{chunk-32BNQ75J.js.map → chunk-WG24VI7K.js.map} +2 -2
- package/dist/chunks/{chunk-3MEHEH6B.js → chunk-X3OD47CL.js} +12 -2
- package/dist/chunks/chunk-X3OD47CL.js.map +7 -0
- package/dist/chunks/{chunk-4JETKRFE.js → chunk-ZHJNWM6A.js} +2 -2
- package/dist/compaction/hook.js +2 -2
- package/dist/components/configuration.d.ts +42 -0
- package/dist/components/configuration.d.ts.map +1 -0
- package/dist/components/configuration.js +18 -0
- package/dist/components/configuration.js.map +7 -0
- package/dist/components/control.d.ts +76 -0
- package/dist/components/control.d.ts.map +1 -0
- package/dist/components/loader.d.ts +12 -0
- package/dist/components/loader.d.ts.map +1 -1
- package/dist/components/supervisor.d.ts.map +1 -1
- package/dist/components/types.d.ts +2 -0
- package/dist/components/types.d.ts.map +1 -1
- package/dist/components/validation.d.ts +6 -0
- package/dist/components/validation.d.ts.map +1 -0
- package/dist/config.d.ts +4 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/core/action-registry.d.ts +1 -0
- package/dist/core/action-registry.d.ts.map +1 -1
- package/dist/core/action-registry.js +3 -3
- package/dist/core/auto-approval-classifier.d.ts.map +1 -1
- package/dist/core/media-sanitize.d.ts +45 -0
- package/dist/core/media-sanitize.d.ts.map +1 -0
- package/dist/core/model-resolution.d.ts +20 -3
- package/dist/core/model-resolution.d.ts.map +1 -1
- package/dist/core/shell-jobs.d.ts +7 -1
- package/dist/core/shell-jobs.d.ts.map +1 -1
- package/dist/entropy/compiler.d.ts +8 -0
- package/dist/entropy/compiler.d.ts.map +1 -1
- package/dist/entropy/index.js +9 -1
- package/dist/entropy/meter.d.ts +10 -0
- package/dist/entropy/meter.d.ts.map +1 -1
- package/dist/entropy/pool.d.ts +5 -0
- package/dist/entropy/pool.d.ts.map +1 -1
- package/dist/entropy/sessions.d.ts +12 -1
- package/dist/entropy/sessions.d.ts.map +1 -1
- package/dist/execution-service.d.ts +3 -1
- package/dist/execution-service.d.ts.map +1 -1
- package/dist/fabric-exec-tool.d.ts.map +1 -1
- package/dist/fabric-runtime-state.d.ts.map +1 -1
- package/dist/fabric-runtime-state.js +424 -65
- package/dist/fabric-runtime-state.js.map +4 -4
- package/dist/fabric-state.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +130 -51
- package/dist/index.js.map +3 -3
- package/dist/jev/browser.d.ts.map +1 -1
- package/dist/jev/browser.js +2 -2
- package/dist/jev/config.d.ts +2 -0
- package/dist/jev/config.d.ts.map +1 -1
- package/dist/jev/model-key.d.ts +6 -0
- package/dist/jev/model-key.d.ts.map +1 -0
- package/dist/jev/observation.js +3 -2
- package/dist/jev.js +8 -7
- package/dist/memory/file-worker.d.ts +15 -0
- package/dist/memory/file-worker.d.ts.map +1 -0
- package/dist/memory/file-worker.js +44 -0
- package/dist/memory/file-worker.js.map +7 -0
- package/dist/memory/worker-provider.d.ts +24 -0
- package/dist/memory/worker-provider.d.ts.map +1 -0
- package/dist/memory/worker-provider.js +18 -0
- package/dist/memory/worker-provider.js.map +7 -0
- package/dist/output-budget.d.ts.map +1 -1
- package/dist/prewalk/arm.d.ts.map +1 -1
- package/dist/prewalk/handoff.d.ts.map +1 -1
- package/dist/protocol.d.ts +1 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +1 -1
- package/dist/providers/agents-actions.d.ts.map +1 -1
- package/dist/providers/captured-tools-provider.d.ts.map +1 -1
- package/dist/providers/components-provider.d.ts +5 -3
- package/dist/providers/components-provider.d.ts.map +1 -1
- package/dist/providers/jev-provider.js +7 -6
- package/dist/residency/actor-client.d.ts +2 -2
- package/dist/residency/actor-client.d.ts.map +1 -1
- package/dist/residency/actor-client.js +2 -2
- package/dist/residency/client.d.ts.map +1 -1
- package/dist/residency/host.js +11 -9
- package/dist/residency/pi-entry.js +11 -9
- package/dist/residency/pi-entry.js.map +1 -1
- package/dist/residency/protocol.d.ts +11 -2
- package/dist/residency/protocol.d.ts.map +1 -1
- 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 +4 -2
- package/dist/runtime/monty-runtime.js.map +1 -1
- package/dist/runtime/node-process-runtime.d.ts.map +1 -1
- package/dist/runtime/node-process-runtime.js +2 -2
- package/dist/runtime/quickjs-runtime.d.ts.map +1 -1
- package/dist/runtime/quickjs-runtime.js +1 -1
- package/dist/runtime/typescript-kernel.js +6 -6
- package/dist/runtime-state-builtins.d.ts.map +1 -1
- package/dist/schema/policy.d.ts.map +1 -1
- package/dist/speculation/stream-tap.d.ts.map +1 -1
- package/dist/storage/retention.d.ts +3 -1
- package/dist/storage/retention.d.ts.map +1 -1
- package/dist/storage/scratch.d.ts +33 -0
- package/dist/storage/scratch.d.ts.map +1 -0
- package/dist/ui/code-preview-shell.d.ts.map +1 -1
- package/dist/ui/controller.d.ts.map +1 -1
- package/dist/ui/conversation-chrome.js +2 -2
- package/dist/ui/conversation-native-reader.js +4 -2
- package/dist/ui/conversation-native-reader.js.map +2 -2
- package/dist/ui/conversation.js +3 -3
- package/dist/ui/dashboard-presentation.d.ts.map +1 -1
- package/dist/ui/dashboard.js +13 -9
- package/dist/ui/dashboard.js.map +2 -2
- package/dist/ui/fabric-code-parser.d.ts.map +1 -1
- package/dist/ui/format.d.ts +1 -0
- package/dist/ui/format.d.ts.map +1 -1
- package/dist/ui/highlight.d.ts.map +1 -1
- package/dist/ui/settings-rpc.d.ts.map +1 -1
- package/dist/ui/settings-sections-execution.d.ts.map +1 -1
- package/dist/ui/settings-submenus.d.ts +12 -4
- package/dist/ui/settings-submenus.d.ts.map +1 -1
- package/dist/ui/settings.js +79 -31
- package/dist/ui/settings.js.map +2 -2
- package/dist/ui/shiki-catalog.d.ts +3 -0
- package/dist/ui/shiki-catalog.d.ts.map +1 -0
- package/dist/ui/structured.d.ts.map +1 -1
- package/dist/ui/tool-call-timing.d.ts.map +1 -1
- package/dist/ui/widget.d.ts +12 -1
- package/dist/ui/widget.d.ts.map +1 -1
- package/dist/worker/model-control.d.ts.map +1 -1
- package/dist/worker/model-control.js +0 -1
- package/dist/worker/model-control.js.map +2 -2
- package/dist/worker.js +14 -12
- package/dist/worker.js.map +2 -2
- package/docs/agents.md +7 -3
- package/docs/architecture.md +1 -1
- package/docs/components.md +30 -1
- package/docs/configuration.md +24 -10
- package/docs/entropy.md +17 -1
- package/docs/jev.md +68 -3
- package/docs/memory-recall.md +21 -0
- package/package.json +5 -2
- package/skillsets/python/fabric-exec/references/agents.md +2 -0
- package/skillsets/python/fabric-jev/SKILL.md +1 -1
- package/skillsets/typescript/fabric-exec/SKILL.md +5 -1
- package/skillsets/typescript/fabric-exec/references/agents.md +4 -0
- package/skillsets/typescript/fabric-jev/SKILL.md +1 -1
- package/dist/chunks/chunk-2DMJ7MEI.js.map +0 -7
- package/dist/chunks/chunk-2PZWDVJB.js.map +0 -7
- package/dist/chunks/chunk-3MEHEH6B.js.map +0 -7
- package/dist/chunks/chunk-4SSMGBF4.js.map +0 -7
- package/dist/chunks/chunk-656HWVFU.js.map +0 -7
- package/dist/chunks/chunk-ARLYAW2A.js.map +0 -7
- package/dist/chunks/chunk-BOTRGFQQ.js.map +0 -7
- package/dist/chunks/chunk-CI56CW53.js.map +0 -7
- package/dist/chunks/chunk-CPSW2GW4.js.map +0 -7
- package/dist/chunks/chunk-PH7ZJ27F.js.map +0 -7
- package/dist/chunks/chunk-RERA6YWA.js.map +0 -7
- package/dist/chunks/chunk-RNOPHITP.js.map +0 -7
- package/dist/chunks/chunk-TSRKCXNI.js +0 -17
- package/dist/chunks/chunk-TSRKCXNI.js.map +0 -7
- package/dist/chunks/chunk-UDFDF7IY.js.map +0 -7
- package/dist/chunks/chunk-VRZNFNPB.js.map +0 -7
- package/dist/chunks/chunk-Y7KNRAFL.js.map +0 -7
- package/dist/chunks/chunk-ZZ4LHQYJ.js.map +0 -7
- /package/dist/chunks/{chunk-GXNR6NRU.js.map → chunk-2IAVP4O2.js.map} +0 -0
- /package/dist/chunks/{chunk-OP2KTYQB.js.map → chunk-D6YSBP3R.js.map} +0 -0
- /package/dist/chunks/{chunk-U6CTHPZC.js.map → chunk-MQG5QKGI.js.map} +0 -0
- /package/dist/chunks/{chunk-2UQV52II.js.map → chunk-RZKN534S.js.map} +0 -0
- /package/dist/chunks/{chunk-YK5AZ7CZ.js.map → chunk-ULLIZPBH.js.map} +0 -0
- /package/dist/chunks/{chunk-UTR3I23Z.js.map → chunk-W63E3WEO.js.map} +0 -0
- /package/dist/chunks/{chunk-4JETKRFE.js.map → chunk-ZHJNWM6A.js.map} +0 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// src/storage/scratch.ts
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
var SCRATCH_OWNER_FILE = ".fabric-scratch.json";
|
|
6
|
+
var SCRATCH_MAX_AGE_MS = 24 * 60 * 60 * 1e3;
|
|
7
|
+
var SCRATCH_RECENT_MS = 60 * 60 * 1e3;
|
|
8
|
+
var SCRATCH_ORPHAN_GRACE_MS = 6 * 60 * 60 * 1e3;
|
|
9
|
+
var SCRATCH_MAX_BYTES = 128 * 1024 * 1024;
|
|
10
|
+
var SCRATCH_MAX_ITEMS = 256;
|
|
11
|
+
var prefixes = {
|
|
12
|
+
output: "pi-fabric-output-",
|
|
13
|
+
shell: "pi-fabric-shell-",
|
|
14
|
+
checkpoint: "pi-native-reader-"
|
|
15
|
+
};
|
|
16
|
+
var contents = {
|
|
17
|
+
output: /* @__PURE__ */ new Set(["output.txt"]),
|
|
18
|
+
shell: /* @__PURE__ */ new Set(["output.log", "child.pid"]),
|
|
19
|
+
checkpoint: /* @__PURE__ */ new Set(["checkpoint", "pending"])
|
|
20
|
+
};
|
|
21
|
+
var timestamp = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
22
|
+
var processAlive = (pid) => {
|
|
23
|
+
if (!Number.isSafeInteger(pid) || pid <= 0) return true;
|
|
24
|
+
try {
|
|
25
|
+
process.kill(pid, 0);
|
|
26
|
+
return true;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
return error.code !== "ESRCH";
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var ownedStat = (file) => {
|
|
32
|
+
try {
|
|
33
|
+
const stat = fs.lstatSync(file);
|
|
34
|
+
if (stat.isSymbolicLink() || stat.isFile() && stat.nlink !== 1 || process.getuid && stat.uid !== process.getuid()) return;
|
|
35
|
+
return stat;
|
|
36
|
+
} catch {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var readOwner = (directory) => {
|
|
41
|
+
try {
|
|
42
|
+
const file = path.join(directory, SCRATCH_OWNER_FILE);
|
|
43
|
+
const stat = ownedStat(file);
|
|
44
|
+
if (!stat?.isFile() || stat.size > 4096) return;
|
|
45
|
+
const owner = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
46
|
+
if (!owner || owner.app !== "pi-fabric-scratch" || owner.version !== 1 || !Object.hasOwn(prefixes, owner.kind) || !Number.isSafeInteger(owner.pid) || owner.pid <= 0 || !timestamp(owner.createdAt) || owner.closedAt !== void 0 && !timestamp(owner.closedAt) || owner.orphanedAt !== void 0 && !timestamp(owner.orphanedAt)) return;
|
|
47
|
+
const suffix = path.basename(directory).slice(prefixes[owner.kind].length);
|
|
48
|
+
if (!path.basename(directory).startsWith(prefixes[owner.kind]) || !/^[A-Za-z0-9]{6}$/.test(suffix)) return;
|
|
49
|
+
return owner;
|
|
50
|
+
} catch {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var createScratch = (kind, tempRoot = os.tmpdir()) => {
|
|
55
|
+
const directory = fs.mkdtempSync(path.join(tempRoot, prefixes[kind]));
|
|
56
|
+
try {
|
|
57
|
+
fs.chmodSync(directory, 448);
|
|
58
|
+
fs.writeFileSync(path.join(directory, SCRATCH_OWNER_FILE), JSON.stringify({
|
|
59
|
+
app: "pi-fabric-scratch",
|
|
60
|
+
version: 1,
|
|
61
|
+
kind,
|
|
62
|
+
pid: process.pid,
|
|
63
|
+
createdAt: Date.now()
|
|
64
|
+
}), { mode: 384, flag: "wx" });
|
|
65
|
+
} catch (error) {
|
|
66
|
+
fs.rmSync(directory, { recursive: true, force: true });
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
scheduleScratchSweep(tempRoot);
|
|
70
|
+
return directory;
|
|
71
|
+
};
|
|
72
|
+
var closeScratch = (directory) => {
|
|
73
|
+
try {
|
|
74
|
+
if (!ownedStat(directory)?.isDirectory()) return;
|
|
75
|
+
const owner = readOwner(directory);
|
|
76
|
+
if (!owner || owner.pid !== process.pid) return;
|
|
77
|
+
fs.writeFileSync(path.join(directory, SCRATCH_OWNER_FILE), JSON.stringify({ ...owner, closedAt: Date.now() }), { mode: 384 });
|
|
78
|
+
scheduleScratchSweep(path.dirname(directory));
|
|
79
|
+
} catch {
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var unchanged = (before, after) => !!after && before.dev === after.dev && before.ino === after.ino && before.uid === after.uid && before.mode === after.mode && before.nlink === after.nlink && before.size === after.size && before.mtimeMs === after.mtimeMs && before.ctimeMs === after.ctimeMs;
|
|
83
|
+
var sweepScratch = async (options) => {
|
|
84
|
+
const result = { eligible: [], removed: [], orphaned: [] };
|
|
85
|
+
const now = options.now ?? Date.now();
|
|
86
|
+
const candidates = [];
|
|
87
|
+
let entries;
|
|
88
|
+
try {
|
|
89
|
+
entries = await fs.promises.readdir(options.tempRoot, { withFileTypes: true });
|
|
90
|
+
} catch {
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
let totalBytes = 0;
|
|
94
|
+
let totalItems = 0;
|
|
95
|
+
for (const entry of entries) {
|
|
96
|
+
if (!entry.isDirectory() || !Object.values(prefixes).some((prefix) => entry.name.startsWith(prefix))) continue;
|
|
97
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
98
|
+
const directory = path.join(options.tempRoot, entry.name);
|
|
99
|
+
try {
|
|
100
|
+
const root = ownedStat(directory);
|
|
101
|
+
if (!root?.isDirectory()) continue;
|
|
102
|
+
const owner = readOwner(directory);
|
|
103
|
+
if (!owner) continue;
|
|
104
|
+
let bytes = 0;
|
|
105
|
+
const files = /* @__PURE__ */ new Map();
|
|
106
|
+
let safe = true;
|
|
107
|
+
for (const name of await fs.promises.readdir(directory)) {
|
|
108
|
+
const stat = ownedStat(path.join(directory, name));
|
|
109
|
+
if (!stat?.isFile() || name !== SCRATCH_OWNER_FILE && !contents[owner.kind].has(name)) {
|
|
110
|
+
safe = false;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
files.set(name, stat);
|
|
114
|
+
bytes += stat.size;
|
|
115
|
+
}
|
|
116
|
+
if (!safe) continue;
|
|
117
|
+
const cache = owner.kind !== "checkpoint";
|
|
118
|
+
if (cache) {
|
|
119
|
+
totalBytes += bytes;
|
|
120
|
+
totalItems++;
|
|
121
|
+
}
|
|
122
|
+
let childPid;
|
|
123
|
+
if (owner.kind === "shell" && files.has("child.pid")) {
|
|
124
|
+
childPid = Number(fs.readFileSync(path.join(directory, "child.pid"), "utf8").trim());
|
|
125
|
+
if (processAlive(childPid)) continue;
|
|
126
|
+
}
|
|
127
|
+
if (owner.closedAt === void 0) {
|
|
128
|
+
if (processAlive(owner.pid)) continue;
|
|
129
|
+
if (owner.orphanedAt === void 0) {
|
|
130
|
+
result.orphaned.push(directory);
|
|
131
|
+
if (!options.dryRun) await fs.promises.writeFile(path.join(directory, SCRATCH_OWNER_FILE), JSON.stringify({ ...owner, orphanedAt: now }), { mode: 384 });
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (now - owner.orphanedAt < (options.orphanGraceMs ?? SCRATCH_ORPHAN_GRACE_MS)) continue;
|
|
135
|
+
}
|
|
136
|
+
const age = now - (owner.closedAt ?? owner.orphanedAt ?? owner.createdAt);
|
|
137
|
+
candidates.push({ directory, root, files, owner, ...childPid === void 0 ? {} : { childPid }, age, bytes, cache, expired: owner.closedAt === void 0 || age >= (options.maxAgeMs ?? SCRATCH_MAX_AGE_MS) });
|
|
138
|
+
} catch {
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
candidates.sort((a, b) => b.age - a.age);
|
|
142
|
+
for (const candidate of candidates) {
|
|
143
|
+
const pressure = candidate.cache && (totalBytes > (options.maxBytes ?? SCRATCH_MAX_BYTES) || totalItems > (options.maxItems ?? SCRATCH_MAX_ITEMS));
|
|
144
|
+
if (!candidate.expired && !(pressure && candidate.age >= (options.recentMs ?? SCRATCH_RECENT_MS))) continue;
|
|
145
|
+
result.eligible.push(candidate.directory);
|
|
146
|
+
if (options.dryRun) {
|
|
147
|
+
if (candidate.cache) {
|
|
148
|
+
totalBytes -= candidate.bytes;
|
|
149
|
+
totalItems--;
|
|
150
|
+
}
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
if (!unchanged(candidate.root, ownedStat(candidate.directory))) continue;
|
|
155
|
+
const names = await fs.promises.readdir(candidate.directory);
|
|
156
|
+
if (names.length !== candidate.files.size || names.some((name) => !candidate.files.has(name))) continue;
|
|
157
|
+
if ([...candidate.files].some(([name, stat]) => !unchanged(stat, ownedStat(path.join(candidate.directory, name))))) continue;
|
|
158
|
+
if (candidate.owner.closedAt === void 0 && processAlive(candidate.owner.pid)) continue;
|
|
159
|
+
if (candidate.childPid !== void 0 && processAlive(candidate.childPid)) continue;
|
|
160
|
+
await fs.promises.rm(candidate.directory, { recursive: true, force: true });
|
|
161
|
+
result.removed.push(candidate.directory);
|
|
162
|
+
if (candidate.cache) {
|
|
163
|
+
totalBytes -= candidate.bytes;
|
|
164
|
+
totalItems--;
|
|
165
|
+
}
|
|
166
|
+
} catch {
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
};
|
|
171
|
+
var pending = /* @__PURE__ */ new Map();
|
|
172
|
+
var lastSweep = /* @__PURE__ */ new Map();
|
|
173
|
+
var scheduleScratchSweep = (tempRoot = os.tmpdir()) => {
|
|
174
|
+
if (pending.has(tempRoot) || Date.now() - (lastSweep.get(tempRoot) ?? 0) < 6e4) return;
|
|
175
|
+
lastSweep.set(tempRoot, Date.now());
|
|
176
|
+
if (lastSweep.size > 8) lastSweep.delete(lastSweep.keys().next().value);
|
|
177
|
+
const task = new Promise((resolve) => setImmediate(resolve)).then(() => sweepScratch({ tempRoot })).catch(() => void 0).finally(() => pending.delete(tempRoot));
|
|
178
|
+
pending.set(tempRoot, task);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export {
|
|
182
|
+
processAlive,
|
|
183
|
+
ownedStat,
|
|
184
|
+
createScratch,
|
|
185
|
+
closeScratch
|
|
186
|
+
};
|
|
187
|
+
//# sourceMappingURL=chunk-RAO6TQFP.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/storage/scratch.ts"],
|
|
4
|
+
"sourcesContent": ["import fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\nexport const SCRATCH_OWNER_FILE = \".fabric-scratch.json\";\nexport const SCRATCH_MAX_AGE_MS = 24 * 60 * 60 * 1_000;\nexport const SCRATCH_RECENT_MS = 60 * 60 * 1_000;\nexport const SCRATCH_ORPHAN_GRACE_MS = 6 * 60 * 60 * 1_000;\nexport const SCRATCH_MAX_BYTES = 128 * 1024 * 1024;\nexport const SCRATCH_MAX_ITEMS = 256;\ntype ScratchKind = \"output\" | \"shell\" | \"checkpoint\";\nconst prefixes: Record<ScratchKind, string> = {\n output: \"pi-fabric-output-\", shell: \"pi-fabric-shell-\", checkpoint: \"pi-native-reader-\",\n};\nconst contents: Record<ScratchKind, Set<string>> = {\n output: new Set([\"output.txt\"]), shell: new Set([\"output.log\", \"child.pid\"]),\n checkpoint: new Set([\"checkpoint\", \"pending\"]),\n};\ninterface Owner {\n app: \"pi-fabric-scratch\";\n version: 1;\n kind: ScratchKind;\n pid: number;\n createdAt: number;\n closedAt?: number;\n orphanedAt?: number;\n}\nconst timestamp = (value: unknown): value is number => typeof value === \"number\" && Number.isFinite(value) && value >= 0;\nexport const processAlive = (pid: number): boolean => {\n if (!Number.isSafeInteger(pid) || pid <= 0) return true; // uncertainty is not death\n try { process.kill(pid, 0); return true; }\n catch (error) { return (error as NodeJS.ErrnoException).code !== \"ESRCH\"; }\n};\nexport const ownedStat = (file: string): fs.Stats | undefined => {\n try {\n const stat = fs.lstatSync(file);\n if (stat.isSymbolicLink() || (stat.isFile() && stat.nlink !== 1) || (process.getuid && stat.uid !== process.getuid())) return;\n return stat;\n } catch { return; }\n};\nconst readOwner = (directory: string): Owner | undefined => {\n try {\n const file = path.join(directory, SCRATCH_OWNER_FILE);\n const stat = ownedStat(file);\n if (!stat?.isFile() || stat.size > 4096) return;\n const owner = JSON.parse(fs.readFileSync(file, \"utf8\")) as Owner;\n if (!owner || owner.app !== \"pi-fabric-scratch\" || owner.version !== 1 ||\n !Object.hasOwn(prefixes, owner.kind) || !Number.isSafeInteger(owner.pid) || owner.pid <= 0 ||\n !timestamp(owner.createdAt) || (owner.closedAt !== undefined && !timestamp(owner.closedAt)) ||\n (owner.orphanedAt !== undefined && !timestamp(owner.orphanedAt))) return;\n const suffix = path.basename(directory).slice(prefixes[owner.kind].length);\n if (!path.basename(directory).startsWith(prefixes[owner.kind]) || !/^[A-Za-z0-9]{6}$/.test(suffix)) return;\n return owner;\n } catch { return; }\n};\n\nexport const createScratch = (kind: ScratchKind, tempRoot = os.tmpdir()): string => {\n const directory = fs.mkdtempSync(path.join(tempRoot, prefixes[kind]));\n try {\n fs.chmodSync(directory, 0o700);\n fs.writeFileSync(path.join(directory, SCRATCH_OWNER_FILE), JSON.stringify({\n app: \"pi-fabric-scratch\", version: 1, kind, pid: process.pid, createdAt: Date.now(),\n } satisfies Owner), { mode: 0o600, flag: \"wx\" });\n } catch (error) {\n fs.rmSync(directory, { recursive: true, force: true });\n throw error;\n }\n scheduleScratchSweep(tempRoot);\n return directory;\n};\n\n/** Only used on directories this process allocated, never on caller-owned roots. */\nexport const closeScratch = (directory: string): void => {\n try {\n if (!ownedStat(directory)?.isDirectory()) return;\n const owner = readOwner(directory);\n if (!owner || owner.pid !== process.pid) return;\n fs.writeFileSync(path.join(directory, SCRATCH_OWNER_FILE), JSON.stringify({ ...owner, closedAt: Date.now() }), { mode: 0o600 });\n scheduleScratchSweep(path.dirname(directory));\n } catch { /* housekeeping must not fail the operation */ }\n};\n\nexport interface ScratchSweepOptions {\n tempRoot: string;\n now?: number;\n dryRun?: boolean;\n maxAgeMs?: number;\n recentMs?: number;\n orphanGraceMs?: number;\n maxBytes?: number;\n maxItems?: number;\n}\nexport interface ScratchSweepResult {\n eligible: string[];\n removed: string[];\n orphaned: string[];\n}\n\nconst unchanged = (before: fs.Stats, after: fs.Stats | undefined): boolean => !!after\n && before.dev === after.dev && before.ino === after.ino && before.uid === after.uid\n && before.mode === after.mode && before.nlink === after.nlink && before.size === after.size\n && before.mtimeMs === after.mtimeMs && before.ctimeMs === after.ctimeMs;\n\n/** No legacy prefix-only deletion. Unknown files, symlinks and malformed markers veto cleanup. */\nexport const sweepScratch = async (options: ScratchSweepOptions): Promise<ScratchSweepResult> => {\n const result: ScratchSweepResult = { eligible: [], removed: [], orphaned: [] };\n const now = options.now ?? Date.now();\n const candidates: { directory: string; root: fs.Stats; files: Map<string, fs.Stats>; owner: Owner; childPid?: number; age: number; bytes: number; cache: boolean; expired: boolean }[] = [];\n let entries: fs.Dirent[];\n try { entries = await fs.promises.readdir(options.tempRoot, { withFileTypes: true }); }\n catch { return result; }\n let totalBytes = 0;\n let totalItems = 0;\n for (const entry of entries) {\n if (!entry.isDirectory() || !Object.values(prefixes).some((prefix) => entry.name.startsWith(prefix))) continue;\n // Yield between roots; no scan in registration or idle lifecycle hooks.\n await new Promise<void>((resolve) => setImmediate(resolve));\n const directory = path.join(options.tempRoot, entry.name);\n try {\n const root = ownedStat(directory);\n if (!root?.isDirectory()) continue;\n const owner = readOwner(directory);\n if (!owner) continue;\n let bytes = 0;\n const files = new Map<string, fs.Stats>();\n let safe = true;\n for (const name of await fs.promises.readdir(directory)) {\n const stat = ownedStat(path.join(directory, name));\n if (!stat?.isFile() || (name !== SCRATCH_OWNER_FILE && !contents[owner.kind].has(name))) { safe = false; break; }\n files.set(name, stat);\n bytes += stat.size;\n }\n if (!safe) continue;\n const cache = owner.kind !== \"checkpoint\";\n if (cache) { totalBytes += bytes; totalItems++; }\n let childPid: number | undefined;\n if (owner.kind === \"shell\" && files.has(\"child.pid\")) {\n childPid = Number(fs.readFileSync(path.join(directory, \"child.pid\"), \"utf8\").trim());\n if (processAlive(childPid)) continue;\n }\n if (owner.closedAt === undefined) {\n if (processAlive(owner.pid)) continue;\n if (owner.orphanedAt === undefined) {\n result.orphaned.push(directory);\n if (!options.dryRun) await fs.promises.writeFile(path.join(directory, SCRATCH_OWNER_FILE), JSON.stringify({ ...owner, orphanedAt: now }), { mode: 0o600 });\n continue;\n }\n if (now - owner.orphanedAt < (options.orphanGraceMs ?? SCRATCH_ORPHAN_GRACE_MS)) continue;\n }\n const age = now - (owner.closedAt ?? owner.orphanedAt ?? owner.createdAt);\n candidates.push({ directory, root, files, owner, ...(childPid === undefined ? {} : { childPid }), age, bytes, cache, expired: owner.closedAt === undefined || age >= (options.maxAgeMs ?? SCRATCH_MAX_AGE_MS) });\n } catch { /* disappearing or inaccessible artifacts are not cleanup authority */ }\n }\n candidates.sort((a, b) => b.age - a.age);\n for (const candidate of candidates) {\n const pressure = candidate.cache && (totalBytes > (options.maxBytes ?? SCRATCH_MAX_BYTES) || totalItems > (options.maxItems ?? SCRATCH_MAX_ITEMS));\n if (!candidate.expired && !(pressure && candidate.age >= (options.recentMs ?? SCRATCH_RECENT_MS))) continue;\n result.eligible.push(candidate.directory);\n if (options.dryRun) {\n if (candidate.cache) { totalBytes -= candidate.bytes; totalItems--; }\n continue;\n }\n try {\n // Recheck identity, contents and liveness, not merely that a directory exists.\n if (!unchanged(candidate.root, ownedStat(candidate.directory))) continue;\n const names = await fs.promises.readdir(candidate.directory);\n if (names.length !== candidate.files.size || names.some(name => !candidate.files.has(name))) continue;\n if ([...candidate.files].some(([name, stat]) => !unchanged(stat, ownedStat(path.join(candidate.directory, name))))) continue;\n if (candidate.owner.closedAt === undefined && processAlive(candidate.owner.pid)) continue;\n if (candidate.childPid !== undefined && processAlive(candidate.childPid)) continue;\n await fs.promises.rm(candidate.directory, { recursive: true, force: true });\n result.removed.push(candidate.directory);\n if (candidate.cache) { totalBytes -= candidate.bytes; totalItems--; }\n } catch { /* best effort */ }\n }\n return result;\n};\n\nconst pending = new Map<string, Promise<unknown>>();\nconst lastSweep = new Map<string, number>();\nexport const scheduleScratchSweep = (tempRoot = os.tmpdir()): void => {\n if (pending.has(tempRoot) || Date.now() - (lastSweep.get(tempRoot) ?? 0) < 60_000) return;\n lastSweep.set(tempRoot, Date.now());\n if (lastSweep.size > 8) lastSweep.delete(lastSweep.keys().next().value!);\n const task = new Promise<void>((resolve) => setImmediate(resolve))\n .then(() => sweepScratch({ tempRoot })).catch(() => undefined)\n .finally(() => pending.delete(tempRoot));\n pending.set(tempRoot, task);\n};\n"],
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BAAc,UAAU;AAAO;AAAA,MAAc;AAAA,IACtE,QAAQ;AAAA,IAAoB;AAAA,EAC9B;AACA,SAAO;AACT;AAEA,IAAM,UAAU,oBAAI,IAA8B;AAClD,IAAM,YAAY,oBAAI,IAAoB;AACnC,IAAM,uBAAuB,CAAC,WAAW,GAAG,OAAO,MAAY;AACpE,MAAI,QAAQ,IAAI,QAAQ,KAAK,KAAK,IAAI,KAAK,UAAU,IAAI,QAAQ,KAAK,KAAK,IAAQ;AACnF,YAAU,IAAI,UAAU,KAAK,IAAI,CAAC;AAClC,MAAI,UAAU,OAAO,EAAG,WAAU,OAAO,UAAU,KAAK,EAAE,KAAK,EAAE,KAAM;AACvE,QAAM,OAAO,IAAI,QAAc,CAAC,YAAY,aAAa,OAAO,CAAC,EAC9D,KAAK,MAAM,aAAa,EAAE,SAAS,CAAC,CAAC,EAAE,MAAM,MAAM,MAAS,EAC5D,QAAQ,MAAM,QAAQ,OAAO,QAAQ,CAAC;AACzC,UAAQ,IAAI,UAAU,IAAI;AAC5B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -5,8 +5,17 @@ import {
|
|
|
5
5
|
// src/ui/highlight.ts
|
|
6
6
|
import { readFileSync, statSync } from "node:fs";
|
|
7
7
|
import { basename, extname } from "node:path";
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
|
|
9
|
+
// src/ui/shiki-catalog.ts
|
|
10
|
+
import { createRequire } from "node:module";
|
|
11
|
+
var require2 = createRequire(import.meta.url);
|
|
12
|
+
var languages;
|
|
13
|
+
var themeTypes;
|
|
14
|
+
var shikiLanguages = () => languages ??= require2("shiki/langs").bundledLanguages;
|
|
15
|
+
var shikiThemeType = (id) => {
|
|
16
|
+
themeTypes ??= new Map(require2("shiki/themes").bundledThemesInfo.map((theme) => [theme.id, theme.type]));
|
|
17
|
+
return themeTypes.get(id);
|
|
18
|
+
};
|
|
10
19
|
|
|
11
20
|
// src/ui/shiki-theme.ts
|
|
12
21
|
var THEME_IMPORTS = {
|
|
@@ -220,7 +229,6 @@ var EXTENSION_ALIASES = /* @__PURE__ */ new Map([
|
|
|
220
229
|
[".prisma", "prisma"],
|
|
221
230
|
[".dockerfile", "dockerfile"]
|
|
222
231
|
]);
|
|
223
|
-
var THEME_TYPE = new Map(bundledThemesInfo.map((theme) => [theme.id, theme.type]));
|
|
224
232
|
var LOW_CONTRAST_FALLBACK = "\x1B[38;2;139;148;158m";
|
|
225
233
|
var highlighter;
|
|
226
234
|
var readyTheme;
|
|
@@ -324,22 +332,22 @@ function observePiTheme(theme) {
|
|
|
324
332
|
const variant = classifyPiTheme(theme);
|
|
325
333
|
if (variant) syncEffectiveTheme(themePreference, variant);
|
|
326
334
|
}
|
|
327
|
-
var effectiveShikiThemeIsLight = () =>
|
|
335
|
+
var effectiveShikiThemeIsLight = () => shikiThemeType(currentTheme) === "light";
|
|
328
336
|
var observedThemeVariant = () => observedVariant;
|
|
329
337
|
function languageFromPath(filePath) {
|
|
330
338
|
if (!filePath) return void 0;
|
|
331
339
|
const name = basename(filePath).toLowerCase();
|
|
332
340
|
if (name.startsWith(".env")) {
|
|
333
341
|
const candidate = "dotenv";
|
|
334
|
-
return candidate in
|
|
342
|
+
return candidate in shikiLanguages() ? candidate : void 0;
|
|
335
343
|
}
|
|
336
344
|
if (name === "dockerfile" || name.startsWith("dockerfile.")) {
|
|
337
|
-
return "dockerfile" in
|
|
345
|
+
return "dockerfile" in shikiLanguages() ? "dockerfile" : void 0;
|
|
338
346
|
}
|
|
339
347
|
const exact = EXACT_BASENAMES.get(name);
|
|
340
|
-
if (exact && exact in
|
|
348
|
+
if (exact && exact in shikiLanguages()) return exact;
|
|
341
349
|
const byExt = EXTENSION_ALIASES.get(extname(name));
|
|
342
|
-
return byExt && byExt in
|
|
350
|
+
return byExt && byExt in shikiLanguages() ? byExt : void 0;
|
|
343
351
|
}
|
|
344
352
|
function configureHighlighting(themePreferenceValue, syntaxEnabled = true) {
|
|
345
353
|
const preference = themePreferenceValue.trim() || "auto";
|
|
@@ -446,7 +454,7 @@ var isLowContrastFg = (params) => {
|
|
|
446
454
|
return luminance < 72;
|
|
447
455
|
};
|
|
448
456
|
var normalizeContrast = (ansi) => {
|
|
449
|
-
if (
|
|
457
|
+
if (shikiThemeType(currentTheme) === "light") return ansi;
|
|
450
458
|
return ansi.replace(
|
|
451
459
|
/\x1b\[([0-9;]*)m/g,
|
|
452
460
|
(seq, params) => isLowContrastFg(params) ? LOW_CONTRAST_FALLBACK : seq
|
|
@@ -514,7 +522,7 @@ function highlightCode(text, lang, invalidate) {
|
|
|
514
522
|
return null;
|
|
515
523
|
}
|
|
516
524
|
const shikiLang = normalizeLanguage(lang);
|
|
517
|
-
if (!(shikiLang in
|
|
525
|
+
if (!(shikiLang in shikiLanguages())) return null;
|
|
518
526
|
const cacheKey = `${currentTheme}\0${shikiLang}\0${text.length}\0${hashString(text)}`;
|
|
519
527
|
const cached = renderCache.get(cacheKey);
|
|
520
528
|
if (cached) {
|
|
@@ -654,7 +662,7 @@ function highlightFileLines(filePath, lang, from, to, invalidate) {
|
|
|
654
662
|
return null;
|
|
655
663
|
}
|
|
656
664
|
const shikiLang = normalizeLanguage(lang);
|
|
657
|
-
if (!(shikiLang in
|
|
665
|
+
if (!(shikiLang in shikiLanguages())) return null;
|
|
658
666
|
if (!loadedLanguages.has(shikiLang)) {
|
|
659
667
|
requestLanguageLoad(shikiLang, invalidate);
|
|
660
668
|
return null;
|
|
@@ -714,7 +722,7 @@ function highlightSourceLines(cacheKey, sourceLines, lang, from, to, invalidate)
|
|
|
714
722
|
return null;
|
|
715
723
|
}
|
|
716
724
|
const shikiLang = normalizeLanguage(lang);
|
|
717
|
-
if (!(shikiLang in
|
|
725
|
+
if (!(shikiLang in shikiLanguages())) return null;
|
|
718
726
|
if (!loadedLanguages.has(shikiLang)) {
|
|
719
727
|
requestLanguageLoad(shikiLang, invalidate);
|
|
720
728
|
return null;
|
|
@@ -764,6 +772,7 @@ var fileHighlightRange = (entry, from, to, invalidate) => {
|
|
|
764
772
|
};
|
|
765
773
|
|
|
766
774
|
export {
|
|
775
|
+
shikiLanguages,
|
|
767
776
|
ansi256ToRgb,
|
|
768
777
|
observePiTheme,
|
|
769
778
|
effectiveShikiThemeIsLight,
|
|
@@ -774,4 +783,4 @@ export {
|
|
|
774
783
|
highlightFileLines,
|
|
775
784
|
highlightSourceLines
|
|
776
785
|
};
|
|
777
|
-
//# sourceMappingURL=chunk-
|
|
786
|
+
//# sourceMappingURL=chunk-RTXZHKMS.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/ui/highlight.ts", "../../src/ui/shiki-catalog.ts", "../../src/ui/shiki-theme.ts", "../../src/ui/shiki-language.ts"],
|
|
4
|
+
"sourcesContent": ["import { readFileSync, statSync } from \"node:fs\";\nimport { basename, extname } from \"node:path\";\nimport { shikiLanguages, shikiThemeType } from \"./shiki-catalog.js\";\nimport type { GrammarState, Highlighter } from \"shiki\";\nimport { resolveShikiTheme, type ShikiThemeVariant } from \"./code-preview.js\";\nimport { resolveShikiThemeObject } from \"./shiki-theme.js\";\nimport { resolveShikiLanguageObjects } from \"./shiki-language.js\";\n\nconst configuredMaxHighlightChars = Number.parseInt(\n process.env.CODE_PREVIEW_MAX_HIGHLIGHT_CHARS ?? \"\",\n 10,\n);\nconst MAX_HIGHLIGHT_CHARS =\n Number.isFinite(configuredMaxHighlightChars) && configuredMaxHighlightChars > 0\n ? configuredMaxHighlightChars\n : 80_000;\nconst configuredFileHighlightMaxSourceChars = Number.parseInt(\n process.env.CODE_PREVIEW_FILE_HIGHLIGHT_MAX_CHARS ?? \"\",\n 10,\n);\n// Files larger than this never enter full-file tokenization; their previews\n// fall back to per-run tokenization. Bounds worst-case background work.\nconst FILE_HIGHLIGHT_MAX_SOURCE_CHARS =\n Number.isFinite(configuredFileHighlightMaxSourceChars) &&\n configuredFileHighlightMaxSourceChars > 0\n ? configuredFileHighlightMaxSourceChars\n : 200_000;\n// One background slice covers ~5-10ms of shiki work on heavy grammars\n// (measured ~106ms for a 1.3k-line TS file), keeping each event-loop tick\n// well under one frame.\nconst FILE_HIGHLIGHT_TICK_LINE_BUDGET = 96;\nconst FILE_HIGHLIGHT_TICK_CHAR_BUDGET = 16_000;\nconst FILE_HIGHLIGHT_ENTRY_LIMIT = 24;\nconst FILE_HIGHLIGHT_CHAR_LIMIT = 4_000_000;\nconst CACHE_LIMIT = 192;\nconst CACHE_CHAR_LIMIT = 4_000_000;\nconst PRELOADED_LANGUAGES = [\n \"bash\",\n \"typescript\",\n \"tsx\",\n \"javascript\",\n \"jsx\",\n \"json\",\n \"markdown\",\n \"yaml\",\n \"toml\",\n \"css\",\n] as const;\n\nconst LANGUAGE_ALIASES = new Map<string, string>([\n [\"sh\", \"bash\"],\n [\"shell\", \"bash\"],\n [\"zsh\", \"bash\"],\n [\"ts\", \"typescript\"],\n [\"js\", \"javascript\"],\n [\"md\", \"markdown\"],\n [\"yml\", \"yaml\"],\n [\"py\", \"python\"],\n [\"rs\", \"rust\"],\n [\"rb\", \"ruby\"],\n [\"cs\", \"csharp\"],\n [\"fs\", \"fsharp\"],\n [\"ps1\", \"powershell\"],\n]);\n\nconst EXACT_BASENAMES = new Map<string, string>([\n [\"dockerfile\", \"dockerfile\"],\n [\"makefile\", \"makefile\"],\n [\"gnumakefile\", \"makefile\"],\n [\"justfile\", \"makefile\"],\n [\"procfile\", \"shellscript\"],\n [\"gemfile\", \"ruby\"],\n [\"rakefile\", \"ruby\"],\n [\"cargo.lock\", \"toml\"],\n [\"package-lock.json\", \"json\"],\n [\"composer.lock\", \"json\"],\n [\"pnpm-lock.yaml\", \"yaml\"],\n [\"pnpm-lock.yml\", \"yaml\"],\n [\"yarn.lock\", \"yaml\"],\n]);\n\nconst EXTENSION_ALIASES = new Map<string, string>([\n [\".ts\", \"typescript\"],\n [\".tsx\", \"tsx\"],\n [\".js\", \"javascript\"],\n [\".jsx\", \"jsx\"],\n [\".mjs\", \"javascript\"],\n [\".cjs\", \"javascript\"],\n [\".json\", \"json\"],\n [\".md\", \"markdown\"],\n [\".markdown\", \"markdown\"],\n [\".yml\", \"yaml\"],\n [\".yaml\", \"yaml\"],\n [\".toml\", \"toml\"],\n [\".sh\", \"bash\"],\n [\".bash\", \"bash\"],\n [\".zsh\", \"bash\"],\n [\".css\", \"css\"],\n [\".html\", \"html\"],\n [\".htm\", \"html\"],\n [\".py\", \"python\"],\n [\".rs\", \"rust\"],\n [\".go\", \"go\"],\n [\".rb\", \"ruby\"],\n [\".php\", \"php\"],\n [\".sql\", \"sql\"],\n [\".xml\", \"xml\"],\n [\".svg\", \"xml\"],\n [\".vue\", \"vue\"],\n [\".svelte\", \"svelte\"],\n [\".c\", \"c\"],\n [\".h\", \"c\"],\n [\".cpp\", \"cpp\"],\n [\".cc\", \"cpp\"],\n [\".hpp\", \"cpp\"],\n [\".java\", \"java\"],\n [\".kt\", \"kotlin\"],\n [\".swift\", \"swift\"],\n [\".lua\", \"lua\"],\n [\".r\", \"r\"],\n [\".scala\", \"scala\"],\n [\".clj\", \"clojure\"],\n [\".ex\", \"elixir\"],\n [\".exs\", \"elixir\"],\n [\".erl\", \"erlang\"],\n [\".hs\", \"haskell\"],\n [\".ml\", \"ocaml\"],\n [\".fs\", \"fsharp\"],\n [\".fsx\", \"fsharp\"],\n [\".cs\", \"csharp\"],\n [\".ps1\", \"powershell\"],\n [\".graphql\", \"graphql\"],\n [\".prisma\", \"prisma\"],\n [\".dockerfile\", \"dockerfile\"],\n]);\n\nconst LOW_CONTRAST_FALLBACK = \"\\x1b[38;2;139;148;158m\";\n\nlet highlighter: Highlighter | undefined;\nlet readyTheme: string | undefined;\nlet initializingTheme: string | undefined;\nlet initVersion = 0;\nlet highlighterGeneration = 0;\nlet themePreference = \"auto\";\nlet observedVariant: ShikiThemeVariant = \"dark\";\nlet currentTheme = resolveShikiTheme(themePreference, observedVariant);\nlet enabled = true;\nconst loadedLanguages = new Set<string>();\nconst pendingLanguages = new Set<string>();\nconst languageLoadCallbacks = new Map<string, Set<() => void>>();\nconst highlighterReadyCallbacks = new Set<() => void>();\nconst renderCache = new Map<string, { value: string[]; size: number }>();\nlet renderCacheChars = 0;\n\nconst hashString = (value: string): number => {\n let hash = 5381;\n for (let index = 0; index < value.length; index++) {\n hash = ((hash << 5) + hash + value.charCodeAt(index)) | 0;\n }\n return hash;\n};\n\nconst escapeControlChars = (text: string): string =>\n text\n .replace(/\\x1b/g, \"\u241B\")\n .replace(/\\r/g, \"\u240D\")\n .replace(/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f-\\x9f]/g, \"\uFFFD\");\n\nconst normalizeLanguage = (language: string): string => {\n const normalized = language.toLowerCase();\n return LANGUAGE_ALIASES.get(normalized) ?? normalized;\n};\n\ninterface Rgb {\n r: number;\n g: number;\n b: number;\n}\n\nconst ANSI_16_RGB: readonly Rgb[] = [\n { r: 0, g: 0, b: 0 },\n { r: 205, g: 49, b: 49 },\n { r: 13, g: 161, b: 13 },\n { r: 229, g: 165, b: 10 },\n { r: 36, g: 114, b: 200 },\n { r: 188, g: 63, b: 188 },\n { r: 17, g: 168, b: 205 },\n { r: 229, g: 229, b: 229 },\n { r: 102, g: 102, b: 102 },\n { r: 241, g: 76, b: 76 },\n { r: 35, g: 209, b: 139 },\n { r: 245, g: 245, b: 67 },\n { r: 59, g: 142, b: 234 },\n { r: 214, g: 112, b: 214 },\n { r: 41, g: 184, b: 219 },\n { r: 255, g: 255, b: 255 },\n];\n\nexport const ansi256ToRgb = (index: number): Rgb => {\n if (index < 16) return ANSI_16_RGB[Math.max(0, index)] ?? { r: 0, g: 0, b: 0 };\n if (index < 232) {\n const cube = index - 16;\n const channel = (value: number): number => (value === 0 ? 0 : 55 + 40 * value);\n return {\n r: channel(Math.floor(cube / 36)),\n g: channel(Math.floor((cube % 36) / 6)),\n b: channel(cube % 6),\n };\n }\n const gray = 8 + 10 * (Math.min(index, 255) - 232);\n return { r: gray, g: gray, b: gray };\n};\n\nconst parseAnsiBgColor = (sequence: string): Rgb | undefined => {\n const truecolor = sequence.match(/\\x1b\\[4?8;2;(\\d+);(\\d+);(\\d+)m/);\n if (truecolor) {\n return { r: Number(truecolor[1]), g: Number(truecolor[2]), b: Number(truecolor[3]) };\n }\n const indexed = sequence.match(/\\x1b\\[4?8;5;(\\d+)m/);\n if (indexed) return ansi256ToRgb(Number(indexed[1]));\n return undefined;\n};\n\nconst relativeLuminance = ({ r, g, b }: Rgb): number =>\n (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255;\n\n/** Minimal structural view of Pi's active theme, as handed to renderers. */\nexport interface PiThemeLike {\n name?: string;\n getBgAnsi?(color: \"userMessageBg\"): string;\n}\n\n/**\n * Classify Pi's active theme as a light or dark variant. Named built-ins are\n * matched directly, custom themes fall back to the luminance of Pi's message\n * background color, and as a last resort COLORFGBG provides a terminal hint.\n */\nexport const classifyPiTheme = (\n theme: PiThemeLike | undefined,\n env: NodeJS.ProcessEnv = process.env,\n): ShikiThemeVariant | undefined => {\n const name = theme?.name?.trim().toLowerCase();\n if (name === \"light\") return \"light\";\n if (name === \"dark\") return \"dark\";\n const background = theme?.getBgAnsi\n ? parseAnsiBgColor(theme.getBgAnsi(\"userMessageBg\"))\n : undefined;\n if (background) return relativeLuminance(background) >= 0.5 ? \"light\" : \"dark\";\n const colorFgBg = env.COLORFGBG;\n if (colorFgBg) {\n const index = colorFgBg\n .split(\";\")\n .map((part) => Number.parseInt(part, 10))\n .filter((part) => Number.isInteger(part) && part >= 0 && part <= 255)\n .at(-1);\n if (index !== undefined) {\n return relativeLuminance(ansi256ToRgb(index)) >= 0.5 ? \"light\" : \"dark\";\n }\n }\n return undefined;\n};\n\nconst syncEffectiveTheme = (preference: string, variant: ShikiThemeVariant): boolean => {\n themePreference = preference;\n observedVariant = variant;\n const effective = resolveShikiTheme(preference, variant);\n if (effective === currentTheme) return false;\n currentTheme = effective;\n renderCache.clear();\n renderCacheChars = 0;\n resetFileHighlighting();\n if (enabled && (highlighter || initializingTheme)) {\n void initHighlighting(effective, true);\n }\n return true;\n};\n\n/**\n * Adopt the variant of the pi theme instance handed to a renderer. When the\n * configured preference follows the variant (\"auto\" or a \"light/dark\" pair),\n * the effective shiki theme swaps as Pi auto-switches.\n */\nexport function observePiTheme(theme: PiThemeLike | undefined): void {\n const variant = classifyPiTheme(theme);\n if (variant) syncEffectiveTheme(themePreference, variant);\n}\n\n/** The shiki theme currently used for rendering (after variant resolution). */\nexport const effectiveShikiTheme = (): string => currentTheme;\n\n/** Whether the effective shiki theme is a light theme. */\nexport const effectiveShikiThemeIsLight = (): boolean =>\n shikiThemeType(currentTheme) === \"light\";\n\n/** Pi's most recently observed theme variant. */\nexport const observedThemeVariant = (): ShikiThemeVariant => observedVariant;\n\n/** Resolve a shiki language id from a file path, or undefined if unsupported. */\nexport function languageFromPath(filePath: string | undefined): string | undefined {\n if (!filePath) return undefined;\n const name = basename(filePath).toLowerCase();\n if (name.startsWith(\".env\")) {\n const candidate = \"dotenv\";\n return candidate in shikiLanguages() ? candidate : undefined;\n }\n if (name === \"dockerfile\" || name.startsWith(\"dockerfile.\")) {\n return \"dockerfile\" in shikiLanguages() ? \"dockerfile\" : undefined;\n }\n const exact = EXACT_BASENAMES.get(name);\n if (exact && exact in shikiLanguages()) return exact;\n const byExt = EXTENSION_ALIASES.get(extname(name));\n return byExt && byExt in shikiLanguages() ? byExt : undefined;\n}\n\n/** Configure highlighting without loading Shiki until the first code preview needs it. */\nexport function configureHighlighting(themePreferenceValue: string, syntaxEnabled = true): void {\n const preference = themePreferenceValue.trim() || \"auto\";\n const wasEnabled = enabled;\n enabled = syntaxEnabled;\n if (!enabled) {\n themePreference = preference;\n currentTheme = resolveShikiTheme(preference, observedVariant);\n initVersion++;\n initializingTheme = undefined;\n highlighter?.dispose();\n highlighter = undefined;\n readyTheme = undefined;\n highlighterGeneration++;\n loadedLanguages.clear();\n pendingLanguages.clear();\n languageLoadCallbacks.clear();\n highlighterReadyCallbacks.clear();\n renderCache.clear();\n renderCacheChars = 0;\n resetFileHighlighting();\n return;\n }\n const themeChanged = syncEffectiveTheme(preference, observedVariant);\n // syncEffectiveTheme already rebuilds eagerly on a real theme swap and\n // highlightCode's requestInit lazily covers a never-initialized highlighter;\n // the only remaining case that needs an explicit init is re-enabling after\n // a disable disposed the highlighter. Rebuilding unconditionally here cost\n // a full 10-grammar shiki init (~80-260ms of main-thread work) on every\n // /fabric settings save even when nothing display-related had changed.\n if (!themeChanged && !wasEnabled && !highlighter && !initializingTheme) {\n void initHighlighting(currentTheme, syntaxEnabled);\n }\n}\n\n/** Initialize (or reinitialize) the shared shiki highlighter. Fire-and-forget safe. */\nexport async function initHighlighting(theme: string, syntaxEnabled = true): Promise<void> {\n currentTheme = theme;\n enabled = syntaxEnabled;\n if (!enabled) return;\n const version = ++initVersion;\n initializingTheme = theme;\n try {\n const { createHighlighter } = await import(\"shiki\");\n // Resolve the theme object from pi-fabric's own module graph and hand\n // createHighlighter the *object*, not a bare id string. Shiki's internal\n // lazy `import(\"@shikijs/themes/<id>)` for string ids cannot be resolved\n // inside Pi's extension host (issue #46); passing the object sidesteps it.\n const themeObject = await resolveShikiThemeObject(theme);\n if (!themeObject) {\n throw new Error(`Unknown shiki theme: ${theme}`);\n }\n const next = await createHighlighter({\n themes: [themeObject],\n langs: await resolveShikiLanguageObjects(PRELOADED_LANGUAGES),\n });\n if (version !== initVersion) {\n next.dispose();\n return;\n }\n highlighter?.dispose();\n highlighter = next;\n resetFileHighlighting();\n readyTheme = theme;\n initializingTheme = undefined;\n highlighterGeneration++;\n loadedLanguages.clear();\n for (const lang of PRELOADED_LANGUAGES) loadedLanguages.add(lang);\n notifyReady();\n } catch (error) {\n if (version !== initVersion) return;\n initializingTheme = undefined;\n console.warn(\"[pi-fabric] Shiki failed to initialize; previews will be plain text.\", error);\n highlighter?.dispose();\n highlighter = undefined;\n readyTheme = undefined;\n highlighterGeneration++;\n loadedLanguages.clear();\n highlighterReadyCallbacks.clear();\n }\n}\n\nconst shouldSkipHighlight = (text: string): boolean => text.length > MAX_HIGHLIGHT_CHARS;\n\nconst ansiFg = (hex: string): string => {\n const clean = hex.replace(/^#/, \"\").slice(0, 6);\n const n = Number.parseInt(clean, 16);\n return Number.isFinite(n)\n ? `\\x1b[38;2;${(n >> 16) & 255};${(n >> 8) & 255};${n & 255}m`\n : \"\";\n};\n\nconst ansiFromToken = (token: { content: string; color?: string; fontStyle?: number }): string => {\n let open = token.color ? ansiFg(token.color) : \"\";\n let close = token.color ? \"\\x1b[39m\" : \"\";\n const fontStyle = token.fontStyle ?? 0;\n if (fontStyle & 2) {\n open += \"\\x1b[1m\";\n close = \"\\x1b[22m\" + close;\n }\n if (fontStyle & 1) {\n open += \"\\x1b[3m\";\n close = \"\\x1b[23m\" + close;\n }\n if (fontStyle & 4) {\n open += \"\\x1b[4m\";\n close = \"\\x1b[24m\" + close;\n }\n return open + escapeControlChars(token.content) + close;\n};\n\nconst isLowContrastFg = (params: string): boolean => {\n if (params === \"30\" || params === \"90\" || params === \"38;5;0\" || params === \"38;5;8\") return true;\n if (!params.startsWith(\"38;2;\")) return false;\n const parts = params.split(\";\").map(Number);\n const r = parts[2];\n const g = parts[3];\n const b = parts[4];\n if (r === undefined || g === undefined || b === undefined) return false;\n if (!Number.isFinite(r) || !Number.isFinite(g) || !Number.isFinite(b)) return false;\n const luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b;\n return luminance < 72;\n};\n\nconst normalizeContrast = (ansi: string): string => {\n if (shikiThemeType(currentTheme) === \"light\") return ansi;\n return ansi.replace(/\\x1b\\[([0-9;]*)m/g, (seq, params: string) =>\n isLowContrastFg(params) ? LOW_CONTRAST_FALLBACK : seq,\n );\n};\n\nconst cacheRendered = (key: string, value: string[]): void => {\n const size = value.reduce((total, line) => total + line.length, 0);\n renderCache.set(key, { value, size });\n renderCacheChars += size;\n while (renderCache.size > CACHE_LIMIT || renderCacheChars > CACHE_CHAR_LIMIT) {\n const first = renderCache.keys().next().value;\n if (first === undefined) break;\n const cached = renderCache.get(first);\n if (cached) renderCacheChars -= cached.size;\n renderCache.delete(first);\n }\n};\n\nconst requestInit = (invalidate?: () => void): void => {\n if (invalidate) highlighterReadyCallbacks.add(invalidate);\n if (initializingTheme === currentTheme) return;\n void initHighlighting(currentTheme, enabled);\n};\n\nconst notifyReady = (): void => {\n const callbacks = [...highlighterReadyCallbacks];\n highlighterReadyCallbacks.clear();\n for (const callback of callbacks) {\n try {\n callback();\n } catch {\n // A stale invalidate callback is harmless.\n }\n }\n};\n\nconst requestLanguageLoad = (lang: string, invalidate?: () => void): void => {\n if (invalidate) {\n const callbacks = languageLoadCallbacks.get(lang) ?? new Set();\n callbacks.add(invalidate);\n languageLoadCallbacks.set(lang, callbacks);\n }\n if (pendingLanguages.has(lang)) return;\n const instance = highlighter;\n if (!instance) return;\n pendingLanguages.add(lang);\n const generation = highlighterGeneration;\n void instance\n .loadLanguage(lang as never)\n .then(() => {\n if (generation !== highlighterGeneration) return;\n loadedLanguages.add(lang);\n const callbacks = languageLoadCallbacks.get(lang);\n languageLoadCallbacks.delete(lang);\n for (const callback of callbacks ?? []) {\n try {\n callback();\n } catch {\n // Stale invalidate; ignore.\n }\n }\n })\n .catch(() => {\n if (generation === highlighterGeneration) languageLoadCallbacks.delete(lang);\n })\n .finally(() => {\n if (generation === highlighterGeneration) pendingLanguages.delete(lang);\n });\n};\n\n/**\n * Highlight `text` as `lang`, returning per-line truecolor ANSI strings that match\n * pi-code-previews' rendering (same shiki theme + token conversion). Returns null\n * when highlighting is disabled, the language is unsupported, the highlighter is\n * not yet ready, or the content is too large. Pass `invalidate` to request a\n * re-render once the highlighter/language becomes ready.\n */\nexport function highlightCode(\n text: string,\n lang: string,\n invalidate?: () => void,\n): string[] | null {\n if (!enabled || !lang || shouldSkipHighlight(text)) return null;\n // A variant flip restarts initialization with the new theme; while it is in\n // flight the old highlighter cannot serve the current theme. Register the\n // invalidate so the preview repaints once the swap completes.\n if (!highlighter || readyTheme !== currentTheme) {\n requestInit(invalidate);\n return null;\n }\n const shikiLang = normalizeLanguage(lang);\n if (!(shikiLang in shikiLanguages())) return null;\n const cacheKey = `${currentTheme}\\0${shikiLang}\\0${text.length}\\0${hashString(text)}`;\n const cached = renderCache.get(cacheKey);\n if (cached) {\n renderCache.delete(cacheKey);\n renderCache.set(cacheKey, cached);\n return cached.value;\n }\n if (!loadedLanguages.has(shikiLang)) {\n requestLanguageLoad(shikiLang, invalidate);\n return null;\n }\n try {\n const tokens = highlighter.codeToTokensBase(text, {\n lang: shikiLang as never,\n theme: currentTheme as never,\n });\n const rendered = tokens.map((line) =>\n normalizeContrast(line.map(ansiFromToken).join(\"\")),\n );\n cacheRendered(cacheKey, rendered);\n return rendered;\n } catch {\n return null;\n }\n}\n\ninterface FileHighlightWaiter {\n to: number;\n invalidate: () => void;\n}\n\ninterface FileHighlightEntry {\n highlighter: Highlighter;\n lang: string;\n // Present only for disk-backed entries; virtual documents omit both.\n mtimeMs?: number;\n size?: number;\n sourceLines: string[];\n lines: string[];\n state: GrammarState | undefined;\n target: number;\n waiters: FileHighlightWaiter[];\n stale: boolean;\n chars: number;\n}\n\nexport interface FileHighlightLine {\n raw: string;\n ansi: string;\n}\n\nconst fileHighlightCache = new Map<string, FileHighlightEntry>();\nlet fileHighlightChars = 0;\nconst fileHighlightQueue: FileHighlightEntry[] = [];\nlet fileHighlightQueueScheduled = false;\n\nconst expandFileLineTabs = (text: string): string => text.replace(/\\t/g, \" \");\n\nconst dropFileHighlightEntry = (key: string, entry: FileHighlightEntry): void => {\n if (fileHighlightCache.get(key) !== entry) return;\n entry.stale = true;\n entry.waiters = [];\n fileHighlightCache.delete(key);\n fileHighlightChars -= entry.chars;\n};\n\nconst evictFileHighlightCache = (): void => {\n while (\n fileHighlightCache.size > FILE_HIGHLIGHT_ENTRY_LIMIT ||\n fileHighlightChars > FILE_HIGHLIGHT_CHAR_LIMIT\n ) {\n const oldestKey = fileHighlightCache.keys().next().value;\n if (oldestKey === undefined) break;\n const oldest = fileHighlightCache.get(oldestKey);\n if (oldest) dropFileHighlightEntry(oldestKey, oldest);\n else fileHighlightCache.delete(oldestKey);\n }\n};\n\nconst resetFileHighlighting = (): void => {\n for (const [, entry] of fileHighlightCache) {\n entry.stale = true;\n entry.waiters = [];\n }\n fileHighlightCache.clear();\n fileHighlightQueue.length = 0;\n fileHighlightChars = 0;\n};\n\nconst fireSatisfiedWaiters = (entry: FileHighlightEntry): void => {\n const covered = entry.lines.length;\n const ready = new Set<() => void>();\n const remaining: FileHighlightWaiter[] = [];\n for (const waiter of entry.waiters) {\n if (waiter.to <= covered) ready.add(waiter.invalidate);\n else remaining.push(waiter);\n }\n entry.waiters = remaining;\n if (ready.size === 0) return;\n queueMicrotask(() => {\n for (const invalidate of ready) {\n try {\n invalidate();\n } catch {\n // A stale invalidate callback is harmless.\n }\n }\n });\n};\n\nconst advanceFileHighlight = (entry: FileHighlightEntry): void => {\n const instance = highlighter;\n if (!instance || readyTheme !== currentTheme || instance !== entry.highlighter) {\n entry.stale = true;\n return;\n }\n const start = entry.lines.length;\n const hardEnd = Math.min(entry.target, entry.sourceLines.length);\n let end = start;\n let chars = 0;\n const maxEnd = Math.min(start + FILE_HIGHLIGHT_TICK_LINE_BUDGET, hardEnd);\n while (end < maxEnd && chars <= FILE_HIGHLIGHT_TICK_CHAR_BUDGET) {\n chars += (entry.sourceLines[end]?.length ?? 0) + 1;\n end++;\n }\n if (end <= start) return;\n try {\n const tokens = instance.codeToTokensBase(entry.sourceLines.slice(start, end).join(\"\\n\"), {\n lang: entry.lang as never,\n theme: currentTheme as never,\n ...(entry.state ? { grammarState: entry.state } : {}),\n });\n const rendered = tokens.map((line) =>\n normalizeContrast(line.map(ansiFromToken).join(\"\")),\n );\n entry.state = instance.getLastGrammarState(tokens as never);\n entry.lines.push(...rendered);\n const delta = rendered.reduce((total, line) => total + line.length, 0);\n entry.chars += delta;\n fileHighlightChars += delta;\n } catch {\n entry.stale = true;\n }\n};\n\nconst pumpFileHighlightQueue = (): void => {\n fileHighlightQueueScheduled = false;\n let entry = fileHighlightQueue.shift();\n while (\n entry !== undefined &&\n (entry.stale ||\n entry.highlighter !== highlighter ||\n entry.lines.length >= Math.min(entry.target, entry.sourceLines.length))\n ) {\n if (entry.waiters.length > 0) fireSatisfiedWaiters(entry);\n entry = fileHighlightQueue.shift();\n }\n if (!entry) return;\n advanceFileHighlight(entry);\n if (!entry.stale) {\n fireSatisfiedWaiters(entry);\n // Coverage only progresses while something on screen waits for it; an\n // entry with no waiters parks so idle state never burns CPU.\n if (entry.waiters.length > 0) fileHighlightQueue.push(entry);\n }\n if (fileHighlightQueue.length > 0) {\n fileHighlightQueueScheduled = true;\n setImmediate(pumpFileHighlightQueue);\n }\n};\n\nconst scheduleFileHighlight = (entry: FileHighlightEntry): void => {\n if (!fileHighlightQueue.includes(entry)) fileHighlightQueue.push(entry);\n if (fileHighlightQueueScheduled) return;\n fileHighlightQueueScheduled = true;\n setImmediate(pumpFileHighlightQueue);\n};\n\n/**\n * Highlight a line range of an on-disk file with full grammar state, returning\n * per-line { raw, ansi } entries for 0-based [from, to). `raw` is the\n * tab-expanded source line so callers can verify the rendered content still\n * matches the file. Returns null while coverage has not reached `to` (or when\n * the file is unusable); passing `invalidate` repaints as soon as the range is\n * covered and pumps bounded background tokenization \u2014 parked shiki\n * GrammarState, one ~5-10ms slice per event-loop tick, work only while\n * waiters exist.\n */\nexport function highlightFileLines(\n filePath: string,\n lang: string,\n from: number,\n to: number,\n invalidate?: () => void,\n): FileHighlightLine[] | null {\n if (!enabled || !lang || !filePath || to <= from || from < 0) return null;\n if (!highlighter || readyTheme !== currentTheme) {\n requestInit(invalidate);\n return null;\n }\n const shikiLang = normalizeLanguage(lang);\n if (!(shikiLang in shikiLanguages())) return null;\n if (!loadedLanguages.has(shikiLang)) {\n requestLanguageLoad(shikiLang, invalidate);\n return null;\n }\n let stat;\n try {\n stat = statSync(filePath);\n } catch {\n return null;\n }\n if (!stat.isFile() || stat.size > FILE_HIGHLIGHT_MAX_SOURCE_CHARS) return null;\n const key = `${currentTheme}\\0${shikiLang}\\0${filePath}`;\n let entry = fileHighlightCache.get(key);\n if (entry && (entry.mtimeMs !== stat.mtimeMs || entry.size !== stat.size)) {\n dropFileHighlightEntry(key, entry);\n entry = undefined;\n }\n if (!entry) {\n let text: string;\n try {\n text = readFileSync(filePath, \"utf8\");\n } catch {\n return null;\n }\n if (text.includes(\"\\0\")) return null;\n const sourceLines = text\n .replace(/\\r\\n?/g, \"\\n\")\n .split(\"\\n\")\n .map(expandFileLineTabs);\n entry = {\n highlighter,\n lang: shikiLang,\n mtimeMs: stat.mtimeMs,\n size: stat.size,\n sourceLines,\n lines: [],\n state: undefined,\n target: 0,\n waiters: [],\n stale: false,\n chars: sourceLines.reduce((total, line) => total + line.length, 0),\n };\n fileHighlightCache.set(key, entry);\n fileHighlightChars += entry.chars;\n evictFileHighlightCache();\n if (entry.stale) {\n // Evicted immediately by the char budget; treat as unusable.\n entry.waiters = [];\n return null;\n }\n } else {\n fileHighlightCache.delete(key);\n fileHighlightCache.set(key, entry);\n }\n return fileHighlightRange(entry, from, to, invalidate);\n}\n\n/**\n * Highlight a line range of an in-memory document with full grammar state.\n * Shares the disk-backed pump, cache, and budgets; the caller supplies the\n * cache identity via `cacheKey` (already namespaced by theme + language) and\n * the tab-expanded source lines. Returns null while coverage has not reached\n * `to`; passing `invalidate` repaints as soon as the range is covered.\n */\nexport function highlightSourceLines(\n cacheKey: string,\n sourceLines: string[],\n lang: string,\n from: number,\n to: number,\n invalidate?: () => void,\n): FileHighlightLine[] | null {\n if (!enabled || !lang || !cacheKey || to <= from || from < 0) return null;\n if (!highlighter || readyTheme !== currentTheme) {\n requestInit(invalidate);\n return null;\n }\n const shikiLang = normalizeLanguage(lang);\n if (!(shikiLang in shikiLanguages())) return null;\n if (!loadedLanguages.has(shikiLang)) {\n requestLanguageLoad(shikiLang, invalidate);\n return null;\n }\n let entry = fileHighlightCache.get(cacheKey);\n if (!entry) {\n entry = {\n highlighter,\n lang: shikiLang,\n sourceLines,\n lines: [],\n state: undefined,\n target: 0,\n waiters: [],\n stale: false,\n chars: sourceLines.reduce((total, line) => total + line.length, 0),\n };\n fileHighlightCache.set(cacheKey, entry);\n fileHighlightChars += entry.chars;\n evictFileHighlightCache();\n if (entry.stale) {\n entry.waiters = [];\n return null;\n }\n } else {\n fileHighlightCache.delete(cacheKey);\n fileHighlightCache.set(cacheKey, entry);\n }\n return fileHighlightRange(entry, from, to, invalidate);\n}\n\nconst fileHighlightRange = (\n entry: FileHighlightEntry,\n from: number,\n to: number,\n invalidate?: () => void,\n): FileHighlightLine[] | null => {\n const total = entry.sourceLines.length;\n if (from >= total) return null;\n const clampedTo = Math.max(Math.min(to, total), Math.min(from, total));\n entry.target = Math.max(entry.target, clampedTo);\n if (invalidate && entry.lines.length < clampedTo) {\n entry.waiters = entry.waiters.filter((waiter) => waiter.invalidate !== invalidate);\n entry.waiters.push({ to: clampedTo, invalidate });\n scheduleFileHighlight(entry);\n }\n // Coverage past EOF: serve the existing lines rather than wait forever on a\n // target that can never be reached.\n if (entry.lines.length < clampedTo) return null;\n const out: FileHighlightLine[] = [];\n for (let index = from; index < Math.min(to, total); index++) {\n out.push({ raw: entry.sourceLines[index] ?? \"\", ansi: entry.lines[index] ?? \"\" });\n }\n return out;\n};\n", "import { createRequire } from \"node:module\";\n\n// Render callbacks are synchronous. Resolve optional catalogs on the first\n// preview, not while loading the extension (even metadata has a static graph).\nconst require = createRequire(import.meta.url);\nlet languages: typeof import(\"shiki/langs\")[\"bundledLanguages\"] | undefined;\nlet themeTypes: Map<string, \"light\" | \"dark\"> | undefined;\n\nexport const shikiLanguages = (): typeof import(\"shiki/langs\")[\"bundledLanguages\"] =>\n languages ??= (require(\"shiki/langs\") as typeof import(\"shiki/langs\")).bundledLanguages;\n\nexport const shikiThemeType = (id: string): \"light\" | \"dark\" | undefined => {\n themeTypes ??= new Map((require(\"shiki/themes\") as typeof import(\"shiki/themes\")).bundledThemesInfo.map(theme => [theme.id, theme.type]));\n return themeTypes.get(id);\n};\n", "import type { ThemeRegistration } from \"shiki\";\n\n// Theme resolution for issue #46.\n//\n// Pi's extension host cannot resolve shiki's internal lazy\n// `import(\"@shikijs/themes/<id>)` (triggered when createHighlighter is handed\n// a bare theme *id string*), so previews fell back to plain text. We resolve\n// each theme object from pi-fabric's own module graph with static imports and\n// hand createHighlighter the *object*, so shiki never performs that\n// host-fragile subpath import at runtime.\n//\n// Each entry is a static dynamic import so the module is only fetched when a\n// theme is actually selected, and so vitest can intercept it.\n\nconst THEME_IMPORTS = {\n \"andromeeda\": () => import(\"@shikijs/themes/andromeeda\"),\n \"aurora-x\": () => import(\"@shikijs/themes/aurora-x\"),\n \"ayu-dark\": () => import(\"@shikijs/themes/ayu-dark\"),\n \"ayu-light\": () => import(\"@shikijs/themes/ayu-light\"),\n \"ayu-mirage\": () => import(\"@shikijs/themes/ayu-mirage\"),\n \"catppuccin-frappe\": () => import(\"@shikijs/themes/catppuccin-frappe\"),\n \"catppuccin-latte\": () => import(\"@shikijs/themes/catppuccin-latte\"),\n \"catppuccin-macchiato\": () => import(\"@shikijs/themes/catppuccin-macchiato\"),\n \"catppuccin-mocha\": () => import(\"@shikijs/themes/catppuccin-mocha\"),\n \"dark-plus\": () => import(\"@shikijs/themes/dark-plus\"),\n \"dracula\": () => import(\"@shikijs/themes/dracula\"),\n \"dracula-soft\": () => import(\"@shikijs/themes/dracula-soft\"),\n \"everforest-dark\": () => import(\"@shikijs/themes/everforest-dark\"),\n \"everforest-light\": () => import(\"@shikijs/themes/everforest-light\"),\n \"github-dark\": () => import(\"@shikijs/themes/github-dark\"),\n \"github-dark-default\": () => import(\"@shikijs/themes/github-dark-default\"),\n \"github-dark-dimmed\": () => import(\"@shikijs/themes/github-dark-dimmed\"),\n \"github-dark-high-contrast\": () =>\n import(\"@shikijs/themes/github-dark-high-contrast\"),\n \"github-light\": () => import(\"@shikijs/themes/github-light\"),\n \"github-light-default\": () => import(\"@shikijs/themes/github-light-default\"),\n \"github-light-high-contrast\": () =>\n import(\"@shikijs/themes/github-light-high-contrast\"),\n \"gruvbox-dark-hard\": () => import(\"@shikijs/themes/gruvbox-dark-hard\"),\n \"gruvbox-dark-medium\": () => import(\"@shikijs/themes/gruvbox-dark-medium\"),\n \"gruvbox-dark-soft\": () => import(\"@shikijs/themes/gruvbox-dark-soft\"),\n \"gruvbox-light-hard\": () => import(\"@shikijs/themes/gruvbox-light-hard\"),\n \"gruvbox-light-medium\": () => import(\"@shikijs/themes/gruvbox-light-medium\"),\n \"gruvbox-light-soft\": () => import(\"@shikijs/themes/gruvbox-light-soft\"),\n \"horizon\": () => import(\"@shikijs/themes/horizon\"),\n \"horizon-bright\": () => import(\"@shikijs/themes/horizon-bright\"),\n \"houston\": () => import(\"@shikijs/themes/houston\"),\n \"kanagawa-dragon\": () => import(\"@shikijs/themes/kanagawa-dragon\"),\n \"kanagawa-lotus\": () => import(\"@shikijs/themes/kanagawa-lotus\"),\n \"kanagawa-wave\": () => import(\"@shikijs/themes/kanagawa-wave\"),\n \"laserwave\": () => import(\"@shikijs/themes/laserwave\"),\n \"light-plus\": () => import(\"@shikijs/themes/light-plus\"),\n \"material-theme\": () => import(\"@shikijs/themes/material-theme\"),\n \"material-theme-darker\": () => import(\"@shikijs/themes/material-theme-darker\"),\n \"material-theme-lighter\": () => import(\"@shikijs/themes/material-theme-lighter\"),\n \"material-theme-ocean\": () => import(\"@shikijs/themes/material-theme-ocean\"),\n \"material-theme-palenight\": () =>\n import(\"@shikijs/themes/material-theme-palenight\"),\n \"min-dark\": () => import(\"@shikijs/themes/min-dark\"),\n \"min-light\": () => import(\"@shikijs/themes/min-light\"),\n \"monokai\": () => import(\"@shikijs/themes/monokai\"),\n \"night-owl\": () => import(\"@shikijs/themes/night-owl\"),\n \"night-owl-light\": () => import(\"@shikijs/themes/night-owl-light\"),\n \"nord\": () => import(\"@shikijs/themes/nord\"),\n \"one-dark-pro\": () => import(\"@shikijs/themes/one-dark-pro\"),\n \"one-light\": () => import(\"@shikijs/themes/one-light\"),\n \"plastic\": () => import(\"@shikijs/themes/plastic\"),\n \"poimandres\": () => import(\"@shikijs/themes/poimandres\"),\n \"red\": () => import(\"@shikijs/themes/red\"),\n \"rose-pine\": () => import(\"@shikijs/themes/rose-pine\"),\n \"rose-pine-dawn\": () => import(\"@shikijs/themes/rose-pine-dawn\"),\n \"rose-pine-moon\": () => import(\"@shikijs/themes/rose-pine-moon\"),\n \"slack-dark\": () => import(\"@shikijs/themes/slack-dark\"),\n \"slack-ochin\": () => import(\"@shikijs/themes/slack-ochin\"),\n \"snazzy-light\": () => import(\"@shikijs/themes/snazzy-light\"),\n \"solarized-dark\": () => import(\"@shikijs/themes/solarized-dark\"),\n \"solarized-light\": () => import(\"@shikijs/themes/solarized-light\"),\n \"synthwave-84\": () => import(\"@shikijs/themes/synthwave-84\"),\n \"tokyo-night\": () => import(\"@shikijs/themes/tokyo-night\"),\n \"vesper\": () => import(\"@shikijs/themes/vesper\"),\n \"vitesse-black\": () => import(\"@shikijs/themes/vitesse-black\"),\n \"vitesse-dark\": () => import(\"@shikijs/themes/vitesse-dark\"),\n \"vitesse-light\": () => import(\"@shikijs/themes/vitesse-light\"),\n} as const satisfies Record<string, () => Promise<{ default: ThemeRegistration }>>;\n\n/**\n * Resolve a shiki theme id to its loaded theme object. Returns undefined when\n * the id is not a bundled shiki theme, so callers can fall back gracefully.\n */\nexport async function resolveShikiThemeObject(\n themeId: string,\n): Promise<ThemeRegistration | undefined> {\n const loader = THEME_IMPORTS[themeId as keyof typeof THEME_IMPORTS];\n if (!loader) return undefined;\n const mod = await loader();\n return mod.default;\n}\n", "import type { LanguageRegistration } from \"shiki\";\n\n// Resolve bundled language grammars through pi-fabric's dependency graph.\n// Shiki's own lazy imports are not resolvable from Pi's jiti extension host.\nconst LANGUAGE_IMPORTS = {\n bash: () => import(\"@shikijs/langs/shellscript\"),\n typescript: () => import(\"@shikijs/langs/typescript\"),\n tsx: () => import(\"@shikijs/langs/tsx\"),\n javascript: () => import(\"@shikijs/langs/javascript\"),\n jsx: () => import(\"@shikijs/langs/jsx\"),\n json: () => import(\"@shikijs/langs/json\"),\n markdown: () => import(\"@shikijs/langs/markdown\"),\n yaml: () => import(\"@shikijs/langs/yaml\"),\n toml: () => import(\"@shikijs/langs/toml\"),\n css: () => import(\"@shikijs/langs/css\"),\n} as const satisfies Record<\n string,\n () => Promise<{ default: LanguageRegistration[] }>\n>;\n\n/**\n * Resolve the language registrations used during highlighter initialization.\n * Passing objects prevents Shiki from issuing host-fragile lazy imports.\n */\nexport async function resolveShikiLanguageObjects(\n languageIds: readonly string[],\n): Promise<LanguageRegistration[]> {\n const modules = await Promise.all(\n languageIds.map(async (languageId) => {\n const loader = LANGUAGE_IMPORTS[languageId as keyof typeof LANGUAGE_IMPORTS];\n if (!loader) throw new Error(`Unsupported preloaded Shiki language: ${languageId}`);\n return loader();\n }),\n );\n return modules.flatMap((module) => module.default);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AAAA,SAAS,cAAc,gBAAgB;AACvC,SAAS,UAAU,eAAe;;;ACDlC,SAAS,qBAAqB;AAI9B,IAAMA,WAAU,cAAc,YAAY,GAAG;AAC7C,IAAI;AACJ,IAAI;AAEG,IAAM,iBAAiB,MAC5B,cAAeA,SAAQ,aAAa,EAAmC;AAElE,IAAM,iBAAiB,CAAC,OAA6C;AAC1E,iBAAe,IAAI,IAAKA,SAAQ,cAAc,EAAoC,kBAAkB,IAAI,WAAS,CAAC,MAAM,IAAI,MAAM,IAAI,CAAC,CAAC;AACxI,SAAO,WAAW,IAAI,EAAE;AAC1B;;;ACAA,IAAM,gBAAgB;AAAA,EACpB,cAAc,MAAM,OAAO,4BAA4B;AAAA,EACvD,YAAY,MAAM,OAAO,0BAA0B;AAAA,EACnD,YAAY,MAAM,OAAO,0BAA0B;AAAA,EACnD,aAAa,MAAM,OAAO,2BAA2B;AAAA,EACrD,cAAc,MAAM,OAAO,4BAA4B;A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ot,
|
|
5
|
+
sleepUnlessAborted
|
|
6
|
+
} from "./chunk-JNMTTJMQ.js";
|
|
5
7
|
import {
|
|
6
8
|
writeJsonAtomic
|
|
7
9
|
} from "./chunk-KAD7UWT2.js";
|
|
@@ -12,7 +14,6 @@ import fs from "node:fs";
|
|
|
12
14
|
import path from "node:path";
|
|
13
15
|
var COMMAND_TIMEOUT_MS = 3e4;
|
|
14
16
|
var STATUS_POLL_MS = 100;
|
|
15
|
-
var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
16
17
|
var readJson = (filePath) => {
|
|
17
18
|
try {
|
|
18
19
|
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
@@ -38,7 +39,7 @@ var ResidentActorClient = class _ResidentActorClient {
|
|
|
38
39
|
if (!rootId || !meshRoot) return void 0;
|
|
39
40
|
return new _ResidentActorClient(meshRoot, rootId);
|
|
40
41
|
}
|
|
41
|
-
async createActor(request) {
|
|
42
|
+
async createActor(request, signal) {
|
|
42
43
|
const response = await this.#send({
|
|
43
44
|
format: RESIDENT_HOST_FORMAT,
|
|
44
45
|
operation: "createActor",
|
|
@@ -46,11 +47,11 @@ var ResidentActorClient = class _ResidentActorClient {
|
|
|
46
47
|
rootId: this.#rootId,
|
|
47
48
|
request,
|
|
48
49
|
createdAt: Date.now()
|
|
49
|
-
});
|
|
50
|
+
}, signal);
|
|
50
51
|
if (!response.actor) throw new Error("Resident host returned no actor from createActor");
|
|
51
52
|
return response.actor;
|
|
52
53
|
}
|
|
53
|
-
async removeActor(id) {
|
|
54
|
+
async removeActor(id, signal) {
|
|
54
55
|
await this.#send({
|
|
55
56
|
format: RESIDENT_HOST_FORMAT,
|
|
56
57
|
operation: "removeActor",
|
|
@@ -58,30 +59,36 @@ var ResidentActorClient = class _ResidentActorClient {
|
|
|
58
59
|
rootId: this.#rootId,
|
|
59
60
|
id,
|
|
60
61
|
createdAt: Date.now()
|
|
61
|
-
});
|
|
62
|
+
}, signal);
|
|
62
63
|
return { removed: true };
|
|
63
64
|
}
|
|
64
|
-
async #send(command) {
|
|
65
|
+
async #send(command, signal) {
|
|
65
66
|
fs.mkdirSync(this.#requestsPath, { recursive: true });
|
|
66
67
|
writeJsonAtomic(path.join(this.#requestsPath, `${command.requestId}.json`), command);
|
|
67
68
|
const responsePath = path.join(this.#responsesPath, `${command.requestId}.json`);
|
|
68
69
|
const deadline = Date.now() + COMMAND_TIMEOUT_MS;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
|
|
70
|
+
try {
|
|
71
|
+
while (Date.now() < deadline) {
|
|
72
|
+
if (signal?.aborted) throw new Error("Resident host actor request was aborted");
|
|
73
|
+
const response = readJson(responsePath);
|
|
74
|
+
if (response?.format === RESIDENT_HOST_FORMAT && response.requestId === command.requestId) {
|
|
75
|
+
fs.rmSync(responsePath, { force: true });
|
|
76
|
+
if (!response.ok) throw new Error(response.error ?? "Resident host rejected actor request");
|
|
77
|
+
return response;
|
|
78
|
+
}
|
|
79
|
+
const owner = readJson(this.#ownerPath);
|
|
80
|
+
if (!owner?.pid) throw new Error("Root resident host exited during actor request");
|
|
81
|
+
await sleepUnlessAborted(STATUS_POLL_MS, signal).catch(() => void 0);
|
|
75
82
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
83
|
+
throw new Error("Timed out waiting for resident host actor response");
|
|
84
|
+
} catch (error) {
|
|
85
|
+
abandonResidentRequest(this.#requestsPath, this.#responsesPath, command.requestId);
|
|
86
|
+
throw error;
|
|
79
87
|
}
|
|
80
|
-
throw new Error("Timed out waiting for resident host actor response");
|
|
81
88
|
}
|
|
82
89
|
};
|
|
83
90
|
|
|
84
91
|
export {
|
|
85
92
|
ResidentActorClient
|
|
86
93
|
};
|
|
87
|
-
//# sourceMappingURL=chunk-
|
|
94
|
+
//# sourceMappingURL=chunk-RWDKJ24D.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/residency/actor-client.ts"],
|
|
4
|
+
"sourcesContent": ["import { randomUUID } from \"node:crypto\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { writeJsonAtomic } from \"../core/atomic-write.js\";\nimport type { FabricActorInfo, FabricActorRequest } from \"../actors/types.js\";\nimport {\n abandonResidentRequest,\n RESIDENT_HOST_FORMAT,\n residentRoot,\n sleepUnlessAborted,\n type ResidentCommand,\n type ResidentCommandResponse,\n} from \"./protocol.js\";\n\nconst COMMAND_TIMEOUT_MS = 30_000;\nconst STATUS_POLL_MS = 100;\n\nconst readJson = <T>(filePath: string): T | undefined => {\n try {\n return JSON.parse(fs.readFileSync(filePath, \"utf8\")) as T;\n } catch {\n return undefined;\n }\n};\n\n/**\n * Durable actor lifecycle proxy for nested Fabric runtimes.\n * Communication remains on the Fabric control plane; only authoritative\n * registry mutations are routed through the root resident host.\n */\nexport class ResidentActorClient {\n readonly #rootId: string;\n readonly #requestsPath: string;\n readonly #responsesPath: string;\n readonly #ownerPath: string;\n\n constructor(meshRoot: string, rootId: string) {\n this.#rootId = rootId;\n const residencyDir = residentRoot(meshRoot, rootId);\n this.#requestsPath = path.join(residencyDir, \"requests\");\n this.#responsesPath = path.join(residencyDir, \"responses\");\n this.#ownerPath = path.join(residencyDir, \"owner.json\");\n }\n\n static fromEnv(): ResidentActorClient | undefined {\n const rootId = process.env.PI_FABRIC_MAIN_AGENT_ID;\n const meshRoot = process.env.PI_FABRIC_MESH_ROOT;\n if (!rootId || !meshRoot) return undefined;\n return new ResidentActorClient(meshRoot, rootId);\n }\n\n async createActor(request: FabricActorRequest, signal?: AbortSignal): Promise<FabricActorInfo> {\n const response = await this.#send({\n format: RESIDENT_HOST_FORMAT,\n operation: \"createActor\",\n requestId: randomUUID(),\n rootId: this.#rootId,\n request,\n createdAt: Date.now(),\n }, signal);\n if (!response.actor) throw new Error(\"Resident host returned no actor from createActor\");\n return response.actor;\n }\n\n async removeActor(id: string, signal?: AbortSignal): Promise<{ removed: true }> {\n await this.#send({\n format: RESIDENT_HOST_FORMAT,\n operation: \"removeActor\",\n requestId: randomUUID(),\n rootId: this.#rootId,\n id,\n createdAt: Date.now(),\n }, signal);\n return { removed: true };\n }\n\n async #send(command: ResidentCommand, signal?: AbortSignal): Promise<ResidentCommandResponse> {\n fs.mkdirSync(this.#requestsPath, { recursive: true });\n writeJsonAtomic(path.join(this.#requestsPath, `${command.requestId}.json`), command);\n const responsePath = path.join(this.#responsesPath, `${command.requestId}.json`);\n const deadline = Date.now() + COMMAND_TIMEOUT_MS;\n try {\n while (Date.now() < deadline) {\n if (signal?.aborted) throw new Error(\"Resident host actor request was aborted\");\n const response = readJson<ResidentCommandResponse>(responsePath);\n if (response?.format === RESIDENT_HOST_FORMAT && response.requestId === command.requestId) {\n fs.rmSync(responsePath, { force: true });\n if (!response.ok) throw new Error(response.error ?? \"Resident host rejected actor request\");\n return response;\n }\n const owner = readJson<{ pid?: number }>(this.#ownerPath);\n if (!owner?.pid) throw new Error(\"Root resident host exited during actor request\");\n await sleepUnlessAborted(STATUS_POLL_MS, signal).catch(() => undefined);\n }\n throw new Error(\"Timed out waiting for resident host actor response\");\n } catch (error) {\n abandonResidentRequest(this.#requestsPath, this.#responsesPath, command.requestId);\n throw error;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAAA,SAAS,kBAAkB;AAC3B,OAAO,QAAQ;AACf,OAAO,UAAU;AAYjB,IAAM,qBAAqB;AAC3B,IAAM,iBAAiB;AAEvB,IAAM,WAAW,CAAI,aAAoC;AACvD,MAAI;AACF,WAAO,KAAK,MAAM,GAAG,aAAa,UAAU,MAAM,CAAC;AAAA,EACrD,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAOO,IAAM,sBAAN,MAAM,qBAAoB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,UAAkB,QAAgB;AAC5C,SAAK,UAAU;AACf,UA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UAAU;AAC5B,YAAI,QAAQ,QAAS,OAAM,IAAI,MAAM,yCAAyC;AAC9E,cAAM,WAAW,SAAkC,YAAY;AAC/D,YAAI,UAAU,WAAW,wBAAwB,SAAS,cAAc,QAAQ,WAAW;AACzF,aAAG,OAAO,cAAc,EAAE,OAAO,KAAK,CAAC;AACvC,cAAI,CAAC,SAAS,GAAI,OAAM,IAAI,MAAM,SAAS,SAAS,sCAAsC;AAC1F,iBAAO;AAAA,QACT;AACA,cAAM,QAAQ,SAA2B,KAAK,UAAU;AACxD,YAAI,CAAC,OAAO,IAAK,OAAM,IAAI,MAAM,gDAAgD;AACjF,cAAM,mBAAmB,gBAAgB,MAAM,EAAE,MAAM,MAAM,MAAS;AAAA,MACxE;AACA,YAAM,IAAI,MAAM,oDAAoD;AAAA,IACtE,SAAS,OAAO;AACd,6BAAuB,KAAK,eAAe,KAAK,gBAAgB,QAAQ,SAAS;AACjF,YAAM;AAAA,IACR;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
checkObserve,
|
|
7
7
|
jevObserveSchema
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-D6YSBP3R.js";
|
|
9
9
|
import {
|
|
10
10
|
checkSchema,
|
|
11
11
|
checkValue,
|
|
@@ -16,13 +16,13 @@ import {
|
|
|
16
16
|
ApprovalController,
|
|
17
17
|
FabricAutoApprovalClassifier,
|
|
18
18
|
FabricSessionApprovals
|
|
19
|
-
} from "./chunk-
|
|
20
|
-
import {
|
|
21
|
-
validationMessage
|
|
22
|
-
} from "./chunk-PSNXUZMY.js";
|
|
19
|
+
} from "./chunk-NPHCGLGH.js";
|
|
23
20
|
import {
|
|
24
21
|
runAbortable
|
|
25
22
|
} from "./chunk-7TB7NXSL.js";
|
|
23
|
+
import {
|
|
24
|
+
validationMessage
|
|
25
|
+
} from "./chunk-PSNXUZMY.js";
|
|
26
26
|
|
|
27
27
|
// src/providers/jev-provider.ts
|
|
28
28
|
import { Type } from "typebox";
|
|
@@ -437,4 +437,4 @@ export {
|
|
|
437
437
|
JEV_ACTION_DESCRIPTORS,
|
|
438
438
|
JevProvider
|
|
439
439
|
};
|
|
440
|
-
//# sourceMappingURL=chunk-
|
|
440
|
+
//# sourceMappingURL=chunk-RZKN534S.js.map
|