frizz-server 0.15.34 → 0.15.35
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/dev-child.js +929 -312
- package/package.json +1 -1
- package/web-dist/assets/{abnfDiagram-VRR7QNED-CFaAYE1a.js → abnfDiagram-VRR7QNED-D129srQj.js} +1 -1
- package/web-dist/assets/{arc-H59Ve1JE.js → arc-lZudOQfd.js} +1 -1
- package/web-dist/assets/architecture-TIHT7OUA-CA5ec0Gm.js +1 -0
- package/web-dist/assets/{architectureDiagram-ZJ3FMSHR-B0ntL95X.js → architectureDiagram-ZJ3FMSHR-CrtK2py-.js} +1 -1
- package/web-dist/assets/{blockDiagram-677ZJIJ3-CtRsk161.js → blockDiagram-677ZJIJ3-Cr7MSTZQ.js} +1 -1
- package/web-dist/assets/{c4Diagram-LMCZKHZV-B02WWGeI.js → c4Diagram-LMCZKHZV-CNCtP_VP.js} +1 -1
- package/web-dist/assets/channel-BVTiuco4.js +1 -0
- package/web-dist/assets/{chunk-32BRIVSS-DGsOWAPF.js → chunk-32BRIVSS-DUIgVT9q.js} +1 -1
- package/web-dist/assets/{chunk-52WLFC77-DPcFO2S4.js → chunk-52WLFC77-ll0wxrGo.js} +1 -1
- package/web-dist/assets/{chunk-C7G6YPKG-BVCX2DYY.js → chunk-C7G6YPKG-C7nZQ7PD.js} +1 -1
- package/web-dist/assets/{chunk-EX3LRPZG-CKoCIAj8.js → chunk-EX3LRPZG-H1Md81EP.js} +1 -1
- package/web-dist/assets/{chunk-FWX5IMBZ-CUw3oZSE.js → chunk-FWX5IMBZ-Dp2I8ck_.js} +2 -2
- package/web-dist/assets/{chunk-HOUHSVGY-Drt6IAdB.js → chunk-HOUHSVGY-D26eCze_.js} +1 -1
- package/web-dist/assets/{chunk-ICXQ74PX-CdLRBMoI.js → chunk-ICXQ74PX-Da4scpSO.js} +1 -1
- package/web-dist/assets/{chunk-MOJQB5TN-CJeEJtO8.js → chunk-MOJQB5TN-DkPSKSSy.js} +1 -1
- package/web-dist/assets/{chunk-OGEWGWER-DQ4Tm4aQ.js → chunk-OGEWGWER-B6i3Jran.js} +1 -1
- package/web-dist/assets/{chunk-PUDLZKDR-be9yrGGa.js → chunk-PUDLZKDR-v-Plka6E.js} +1 -1
- package/web-dist/assets/{chunk-Q4XR5HBZ-Kma0zISV.js → chunk-Q4XR5HBZ-6_YVJ7i9.js} +1 -1
- package/web-dist/assets/{chunk-RYQCIY6F-DU4Nd3-9.js → chunk-RYQCIY6F-D0ZjBw8D.js} +1 -1
- package/web-dist/assets/{chunk-V7JOEXUC-B-BWV-U3.js → chunk-V7JOEXUC-CCy2fibM.js} +1 -1
- package/web-dist/assets/{chunk-VAUOI2AC-D_nBmjle.js → chunk-VAUOI2AC-DtsKL0xS.js} +1 -1
- package/web-dist/assets/{chunk-VR4S4FIN-DeyNQWWd.js → chunk-VR4S4FIN-BZFI-yXe.js} +1 -1
- package/web-dist/assets/{chunk-WYO6CB5R-Dz3AXG32.js → chunk-WYO6CB5R-BvJbL3sv.js} +1 -1
- package/web-dist/assets/{chunk-XXDRQBXY-DdxDU3jE.js → chunk-XXDRQBXY-C_M3xhvd.js} +1 -1
- package/web-dist/assets/{chunk-ZGVPDNZ5-BoUQUdRC.js → chunk-ZGVPDNZ5-C8RyBdFb.js} +1 -1
- package/web-dist/assets/classDiagram-OUVF2IWQ-9CrZWFBB.js +1 -0
- package/web-dist/assets/classDiagram-v2-EOCWNBFH-9CrZWFBB.js +1 -0
- package/web-dist/assets/{cose-bilkent-JH36ORCC-CROUkmyY.js → cose-bilkent-JH36ORCC-DGSLJpi2.js} +1 -1
- package/web-dist/assets/{cynefin-VYW2F7L2-BP7uFRVf.js → cynefin-VYW2F7L2-B0dqUUva.js} +1 -1
- package/web-dist/assets/{cynefinDiagram-TSTJHNR4-MHbxpbqh.js → cynefinDiagram-TSTJHNR4-C6-pVgHN.js} +1 -1
- package/web-dist/assets/{dagre-VKFMJZFB-BobHYWM0.js → dagre-VKFMJZFB-BPhBZDn_.js} +1 -1
- package/web-dist/assets/{diagram-FQU43EPY-BzQyYg74.js → diagram-FQU43EPY-Dx0GRxRd.js} +1 -1
- package/web-dist/assets/{diagram-G47NLZAW-C84J5-0I.js → diagram-G47NLZAW-tRnsp5NZ.js} +1 -1
- package/web-dist/assets/{diagram-NH7WQ7WH-CD0VPXnL.js → diagram-NH7WQ7WH-brRG4YP3.js} +1 -1
- package/web-dist/assets/{diagram-OA4YK3LP-DJZf0CpF.js → diagram-OA4YK3LP-HPCPq5vN.js} +1 -1
- package/web-dist/assets/{diagram-WEI45ONY-mBb7-sIf.js → diagram-WEI45ONY-DBIDlkOn.js} +1 -1
- package/web-dist/assets/{dist-B_lpiD0M.js → dist-QrxGAEfI.js} +1 -1
- package/web-dist/assets/{ebnfDiagram-CCIWWBDH-B6yIFQ2s.js → ebnfDiagram-CCIWWBDH-DPpG2nEr.js} +1 -1
- package/web-dist/assets/{erDiagram-Q63AITRT-AZeMhESY.js → erDiagram-Q63AITRT-B03KTREu.js} +1 -1
- package/web-dist/assets/eventmodeling-45OFAUF4-D4WnFJFn.js +1 -0
- package/web-dist/assets/flowDiagram-23GEKE2U-Db_Yi3kp.js +1 -0
- package/web-dist/assets/{ganttDiagram-NO4QXBWP-g3WnNJN4.js → ganttDiagram-NO4QXBWP-IHjbBNTs.js} +1 -1
- package/web-dist/assets/{gitGraph-TEB2WS4Q-CcuRL4Bo.js → gitGraph-TEB2WS4Q-BJwmP2d4.js} +1 -1
- package/web-dist/assets/{gitGraphDiagram-IHSO6WYX-ufdCG-3_.js → gitGraphDiagram-IHSO6WYX-C8pGIJ9F.js} +1 -1
- package/web-dist/assets/{index-CUibhd_n.js → index-6SDsPnCe.js} +115 -115
- package/web-dist/assets/index-BbpuV6k_.css +2 -0
- package/web-dist/assets/{info-DKCQHKI2-jw1e4zDx.js → info-DKCQHKI2-BVcPA0uT.js} +1 -1
- package/web-dist/assets/{infoDiagram-FWYZ7A6U-B6Qw_wFZ.js → infoDiagram-FWYZ7A6U-DvqztdKA.js} +1 -1
- package/web-dist/assets/{ishikawaDiagram-FXEZZL3T-Drh50tWs.js → ishikawaDiagram-FXEZZL3T-DyhVzZBU.js} +1 -1
- package/web-dist/assets/{journeyDiagram-5HDEW3XC-BP-DYvU-.js → journeyDiagram-5HDEW3XC-ZEKauv5n.js} +1 -1
- package/web-dist/assets/{kanban-definition-HUTT4EX6-D3xpEevb.js → kanban-definition-HUTT4EX6-CepyK851.js} +1 -1
- package/web-dist/assets/{line-D_Y12TIr.js → line-wQ98gODj.js} +1 -1
- package/web-dist/assets/{linear-CLfxkXN2.js → linear-C2rtjUR9.js} +1 -1
- package/web-dist/assets/{mermaid-parser.core-ClsUfbZZ.js → mermaid-parser.core-Ci-cUDXV.js} +3 -3
- package/web-dist/assets/{mermaid.core-yL3u6LSI.js → mermaid.core-D26PB2uv.js} +3 -3
- package/web-dist/assets/{mindmap-definition-LN4V7U3C-DqHDZg3y.js → mindmap-definition-LN4V7U3C-pQ423WTQ.js} +1 -1
- package/web-dist/assets/{packet-7NZHBO7P-B8guUQZ5.js → packet-7NZHBO7P-m5EZAdVa.js} +1 -1
- package/web-dist/assets/{pegDiagram-2B236MQR-D2mc5pqT.js → pegDiagram-2B236MQR-CmQauXMc.js} +1 -1
- package/web-dist/assets/{pie-RZYD4A2V-CRdt5SrU.js → pie-RZYD4A2V-DsCjC6Aw.js} +1 -1
- package/web-dist/assets/{pieDiagram-ENE6RG2P-BZZz5Ldk.js → pieDiagram-ENE6RG2P-DAnWnktJ.js} +1 -1
- package/web-dist/assets/{quadrantDiagram-ABIIQ3AL-B5GoIki7.js → quadrantDiagram-ABIIQ3AL-yV-55X6h.js} +1 -1
- package/web-dist/assets/{radar-I7S5WNFK-DZVbkilW.js → radar-I7S5WNFK-DmYrhbGZ.js} +1 -1
- package/web-dist/assets/{railroad-3IZDKUUU-Cr8jhig0.js → railroad-3IZDKUUU-1Af5LHVH.js} +1 -1
- package/web-dist/assets/railroad-abnf-AHOZXSZD-q1VO-5_s.js +1 -0
- package/web-dist/assets/railroad-ebnf-EBAXGLYW-H0RP0IGY.js +1 -0
- package/web-dist/assets/railroad-peg-LSFZ7HO6-P2_YWa6e.js +1 -0
- package/web-dist/assets/{railroadDiagram-RFXS5EU6-H59shyyz.js → railroadDiagram-RFXS5EU6-CL490ICY.js} +1 -1
- package/web-dist/assets/{requirementDiagram-TGXJPOKE-RtSre_B7.js → requirementDiagram-TGXJPOKE-D4V2V4M4.js} +1 -1
- package/web-dist/assets/{sankeyDiagram-HTMAVEWB-B7sRCf_S.js → sankeyDiagram-HTMAVEWB-DboOdoog.js} +1 -1
- package/web-dist/assets/{sequenceDiagram-DBY2YBRQ-CZFvlC9p.js → sequenceDiagram-DBY2YBRQ-B9imFSyN.js} +1 -1
- package/web-dist/assets/{src-4qa8RxUx.js → src-bXz5F_73.js} +1 -1
- package/web-dist/assets/{stateDiagram-2N3HPSRC-CJG2eOvi.js → stateDiagram-2N3HPSRC-9fBbVPbS.js} +1 -1
- package/web-dist/assets/stateDiagram-v2-6OUMAXLB-D3NihPE7.js +1 -0
- package/web-dist/assets/{swimlanes-5IMT3BWC-DzJ8HN_9.js → swimlanes-5IMT3BWC-NuoWaLoT.js} +1 -1
- package/web-dist/assets/swimlanesDiagram-G3AALYLV-i7_yBzZ9.js +8 -0
- package/web-dist/assets/{timeline-definition-FHXFAJF6-BLJZ9NLD.js → timeline-definition-FHXFAJF6-CFTpt9PD.js} +1 -1
- package/web-dist/assets/{treeView-QDETBFTQ-CNVshWOh.js → treeView-QDETBFTQ-DMVW9992.js} +1 -1
- package/web-dist/assets/{treemap-6X3UGDF4-_wlaX-no.js → treemap-6X3UGDF4-DnVjneTc.js} +1 -1
- package/web-dist/assets/{vennDiagram-L72KCM5P-y8OAbS4z.js → vennDiagram-L72KCM5P-CRxeJqHm.js} +1 -1
- package/web-dist/assets/{wardley-OPB4EBWU-DY4-knrx.js → wardley-OPB4EBWU-j2g5ErAe.js} +1 -1
- package/web-dist/assets/{wardleyDiagram-EHGQE667-DqJUB6jl.js → wardleyDiagram-EHGQE667-Cwy2dkRh.js} +1 -1
- package/web-dist/assets/{xychartDiagram-FW5EYKEG-BE7k8bUK.js → xychartDiagram-FW5EYKEG-D0talZt6.js} +1 -1
- package/web-dist/index.html +2 -2
- package/web-dist/assets/architecture-TIHT7OUA-CD4mgFrC.js +0 -1
- package/web-dist/assets/channel-CEC6f2u8.js +0 -1
- package/web-dist/assets/classDiagram-OUVF2IWQ-GAwjPxTk.js +0 -1
- package/web-dist/assets/classDiagram-v2-EOCWNBFH-GAwjPxTk.js +0 -1
- package/web-dist/assets/eventmodeling-45OFAUF4-DBJ3QWbN.js +0 -1
- package/web-dist/assets/flowDiagram-23GEKE2U-CMBu0KXr.js +0 -1
- package/web-dist/assets/index-IvdpjBO_.css +0 -2
- package/web-dist/assets/railroad-abnf-AHOZXSZD-Ct9VX0SS.js +0 -1
- package/web-dist/assets/railroad-ebnf-EBAXGLYW-C-MlhbSs.js +0 -1
- package/web-dist/assets/railroad-peg-LSFZ7HO6-DtfCi0rH.js +0 -1
- package/web-dist/assets/stateDiagram-v2-6OUMAXLB-BUjDakil.js +0 -1
- package/web-dist/assets/swimlanesDiagram-G3AALYLV-Bfwe-6lb.js +0 -8
package/dist/dev-child.js
CHANGED
|
@@ -8717,14 +8717,14 @@ function isValidJWT(jwt, alg) {
|
|
|
8717
8717
|
if (!header)
|
|
8718
8718
|
return false;
|
|
8719
8719
|
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
8720
|
-
const
|
|
8721
|
-
if (typeof
|
|
8720
|
+
const decoded2 = JSON.parse(atob(base64));
|
|
8721
|
+
if (typeof decoded2 !== "object" || decoded2 === null)
|
|
8722
8722
|
return false;
|
|
8723
|
-
if ("typ" in
|
|
8723
|
+
if ("typ" in decoded2 && decoded2?.typ !== "JWT")
|
|
8724
8724
|
return false;
|
|
8725
|
-
if (!
|
|
8725
|
+
if (!decoded2.alg)
|
|
8726
8726
|
return false;
|
|
8727
|
-
if (alg &&
|
|
8727
|
+
if (alg && decoded2.alg !== alg)
|
|
8728
8728
|
return false;
|
|
8729
8729
|
return true;
|
|
8730
8730
|
} catch {
|
|
@@ -14293,6 +14293,7 @@ function timerPromptMessage(prompt, fireAt) {
|
|
|
14293
14293
|
}
|
|
14294
14294
|
function limitResumeSteer(window) {
|
|
14295
14295
|
const which = window === "weekly" ? "weekly usage limit" : window === "session" ? "session usage limit" : window === "model" ? "model usage limit" : "usage limit";
|
|
14296
|
+
if (window === "unknown") return "\u23F3 Capacity is available again after the usage limit that interrupted you. Continue exactly where you left off.";
|
|
14296
14297
|
return `\u23F3 The ${which} that interrupted you has reset. Continue exactly where you left off.`;
|
|
14297
14298
|
}
|
|
14298
14299
|
function limitModelSwitchSteer(capped, to) {
|
|
@@ -16144,8 +16145,20 @@ ${ANSWER_CONTINUATION_INDENT}`);
|
|
|
16144
16145
|
planType: external_exports.string().optional(),
|
|
16145
16146
|
// "pro" / "max" / etc. when the source reports it
|
|
16146
16147
|
windows: external_exports.array(QuotaWindow),
|
|
16147
|
-
detail: external_exports.string().optional()
|
|
16148
|
+
detail: external_exports.string().optional(),
|
|
16148
16149
|
// why unavailable, or an extra note
|
|
16150
|
+
// Recovery evidence from a LIVE Codex read only. Rollout quota has no account identity or freshness
|
|
16151
|
+
// guarantee and must never wake a failed thread. accountKey is a hash, not a credential/account id.
|
|
16152
|
+
codexRecovery: external_exports.object({
|
|
16153
|
+
observedAt: external_exports.number(),
|
|
16154
|
+
// request start, unix milliseconds (not the later cache/read time)
|
|
16155
|
+
accountKey: external_exports.string().optional(),
|
|
16156
|
+
creditsAvailable: external_exports.boolean().optional(),
|
|
16157
|
+
ordinaryUsageAllowed: external_exports.boolean().nullable().optional(),
|
|
16158
|
+
// null is explicitly unavailable
|
|
16159
|
+
blocked: external_exports.boolean().optional()
|
|
16160
|
+
// explicit workspace/spend-control denial beats apparent headroom
|
|
16161
|
+
}).optional()
|
|
16149
16162
|
});
|
|
16150
16163
|
QuotaSnapshot = external_exports.object({
|
|
16151
16164
|
claude: ProviderQuota,
|
|
@@ -17267,12 +17280,15 @@ ${DISPATCH_TASK_BANNER}
|
|
|
17267
17280
|
/** The directory is gone — moved or deleted. The card stays so it can be reopened or forgotten. */
|
|
17268
17281
|
stale: external_exports.boolean(),
|
|
17269
17282
|
/**
|
|
17270
|
-
*
|
|
17283
|
+
* A hash of the icon's bytes; for a project with no icon, when it was last scanned. Absent if it
|
|
17284
|
+
* never has been.
|
|
17271
17285
|
*
|
|
17272
17286
|
* Carried purely so the client can hang it off the `/_frizz/project-icon` URL: the icon bytes are
|
|
17273
17287
|
* cached hard (a rail of forty squares is forty requests, and none of them should recur), which
|
|
17274
17288
|
* means a newly uploaded icon would otherwise stay invisible behind the cached old one. A changed
|
|
17275
17289
|
* version is a changed URL, so the swap is immediate without weakening the caching for everyone.
|
|
17290
|
+
* It is the HASH, not the scan time, because a rescan restamps the time every ten minutes whether
|
|
17291
|
+
* or not the picture changed, and every restamp was a fresh download of every icon.
|
|
17276
17292
|
*
|
|
17277
17293
|
* Deliberately NOT "does this project have an icon". Answering that for a project nobody has
|
|
17278
17294
|
* scanned yet would mean scanning it, and this list is one file read on purpose.
|
|
@@ -17319,6 +17335,7 @@ ${DISPATCH_TASK_BANNER}
|
|
|
17319
17335
|
});
|
|
17320
17336
|
|
|
17321
17337
|
// packages/server/src/project-registry.ts
|
|
17338
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
17322
17339
|
import { closeSync as closeSync3, existsSync as existsSync3, fsyncSync as fsyncSync3, mkdirSync as mkdirSync3, openSync as openSync3, readFileSync as readFileSync4, readdirSync, realpathSync as realpathSync3, renameSync as renameSync3, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
17323
17340
|
import { homedir as homedir4 } from "node:os";
|
|
17324
17341
|
import { basename, dirname as dirname4, join as join5 } from "node:path";
|
|
@@ -17550,10 +17567,30 @@ function updateEntry(id, apply, home) {
|
|
|
17550
17567
|
return entry;
|
|
17551
17568
|
}
|
|
17552
17569
|
function setProjectIcon(id, path3, home = homedir4()) {
|
|
17570
|
+
const hash = iconFileHash(path3);
|
|
17553
17571
|
return updateEntry(id, (entry) => {
|
|
17554
17572
|
entry.icon = path3;
|
|
17555
17573
|
entry.iconSource = "custom";
|
|
17556
17574
|
entry.iconScannedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
17575
|
+
if (hash) entry.iconHash = hash;
|
|
17576
|
+
else delete entry.iconHash;
|
|
17577
|
+
}, home);
|
|
17578
|
+
}
|
|
17579
|
+
function iconContentHash(bytes) {
|
|
17580
|
+
return createHash4("sha256").update(bytes).digest("hex").slice(0, 16);
|
|
17581
|
+
}
|
|
17582
|
+
function iconFileHash(path3) {
|
|
17583
|
+
try {
|
|
17584
|
+
return iconContentHash(readFileSync4(path3));
|
|
17585
|
+
} catch {
|
|
17586
|
+
return void 0;
|
|
17587
|
+
}
|
|
17588
|
+
}
|
|
17589
|
+
function recordProjectIconHash(id, path3, hash, home = homedir4()) {
|
|
17590
|
+
const entry = readRegistry(home).projects.find((p) => p.id === id);
|
|
17591
|
+
if (!entry || entry.icon !== path3 || entry.iconHash === hash) return;
|
|
17592
|
+
updateEntry(id, (target) => {
|
|
17593
|
+
target.iconHash = hash;
|
|
17557
17594
|
}, home);
|
|
17558
17595
|
}
|
|
17559
17596
|
function clearProjectIcon(id, home = homedir4()) {
|
|
@@ -17561,6 +17598,7 @@ function clearProjectIcon(id, home = homedir4()) {
|
|
|
17561
17598
|
delete entry.icon;
|
|
17562
17599
|
delete entry.iconSource;
|
|
17563
17600
|
delete entry.iconScannedAt;
|
|
17601
|
+
delete entry.iconHash;
|
|
17564
17602
|
}, home);
|
|
17565
17603
|
}
|
|
17566
17604
|
function resolveProjectIcon(id, detect, options = {}) {
|
|
@@ -17578,6 +17616,7 @@ function resolveProjectIcon(id, detect, options = {}) {
|
|
|
17578
17616
|
}
|
|
17579
17617
|
if (!existsSync3(entry.path)) return void 0;
|
|
17580
17618
|
const found = detect(entry.path);
|
|
17619
|
+
const hash = found ? iconFileHash(found) : void 0;
|
|
17581
17620
|
updateEntry(id, (target) => {
|
|
17582
17621
|
if (found) {
|
|
17583
17622
|
target.icon = found;
|
|
@@ -17586,6 +17625,8 @@ function resolveProjectIcon(id, detect, options = {}) {
|
|
|
17586
17625
|
delete target.icon;
|
|
17587
17626
|
delete target.iconSource;
|
|
17588
17627
|
}
|
|
17628
|
+
if (hash) target.iconHash = hash;
|
|
17629
|
+
else delete target.iconHash;
|
|
17589
17630
|
target.iconScannedAt = new Date(now()).toISOString();
|
|
17590
17631
|
target.iconScanVersion = version;
|
|
17591
17632
|
}, home);
|
|
@@ -17899,9 +17940,9 @@ async function attachLinkedPrs(repo, items) {
|
|
|
17899
17940
|
const chunks = [];
|
|
17900
17941
|
for (let i = 0; i < numbers.length; i += LINKED_PR_CHUNK) chunks.push(numbers.slice(i, i + LINKED_PR_CHUNK));
|
|
17901
17942
|
const results = await Promise.all(
|
|
17902
|
-
chunks.map(async (
|
|
17943
|
+
chunks.map(async (chunk2) => {
|
|
17903
17944
|
try {
|
|
17904
|
-
return parseLinkedPrJson(await gh(["api", "graphql", "-f", `query=${linkedPrQuery(
|
|
17945
|
+
return parseLinkedPrJson(await gh(["api", "graphql", "-f", `query=${linkedPrQuery(chunk2)}`, "-F", `owner=${owner}`, "-F", `name=${name}`]));
|
|
17905
17946
|
} catch {
|
|
17906
17947
|
return /* @__PURE__ */ new Map();
|
|
17907
17948
|
}
|
|
@@ -18237,7 +18278,7 @@ var init_project = __esm({
|
|
|
18237
18278
|
});
|
|
18238
18279
|
|
|
18239
18280
|
// packages/server/src/project-launch.ts
|
|
18240
|
-
import { createHash as
|
|
18281
|
+
import { createHash as createHash5, randomUUID as randomUUID5 } from "node:crypto";
|
|
18241
18282
|
import {
|
|
18242
18283
|
closeSync as closeSync4,
|
|
18243
18284
|
fsyncSync as fsyncSync4,
|
|
@@ -18445,7 +18486,7 @@ function sameProjectIdentity(record, target) {
|
|
|
18445
18486
|
}
|
|
18446
18487
|
function projectLaunchTokenProof(target, token) {
|
|
18447
18488
|
if (!UUID_RE.test(token)) throw new Error("invalid Frizz project launch owner token");
|
|
18448
|
-
return
|
|
18489
|
+
return createHash5("sha256").update("frizz-project-launch-v2\0").update(target.projectId).update("\0").update(target.projectDir).update("\0").update(token).digest("hex");
|
|
18449
18490
|
}
|
|
18450
18491
|
function removeStatusesForToken(stateDir, token) {
|
|
18451
18492
|
for (const name of ["dev-supervisor.lock", "server.lock"]) {
|
|
@@ -19406,7 +19447,7 @@ var init_local_image = __esm({
|
|
|
19406
19447
|
|
|
19407
19448
|
// packages/server/src/audit.ts
|
|
19408
19449
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
19409
|
-
import { createHash as
|
|
19450
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
19410
19451
|
import { appendFileSync as appendFileSync2, chmodSync as chmodSync2, mkdirSync as mkdirSync8 } from "node:fs";
|
|
19411
19452
|
import { dirname as dirname7, join as join10 } from "node:path";
|
|
19412
19453
|
function bounded(value) {
|
|
@@ -19443,7 +19484,7 @@ function currentRequestOrigin() {
|
|
|
19443
19484
|
return requestOrigin.getStore() ?? { via: "internal" };
|
|
19444
19485
|
}
|
|
19445
19486
|
function textDigest(text2) {
|
|
19446
|
-
return { chars: text2.length, sha256:
|
|
19487
|
+
return { chars: text2.length, sha256: createHash6("sha256").update(text2).digest("hex") };
|
|
19447
19488
|
}
|
|
19448
19489
|
function auditLogPathForStateDir(stateDir) {
|
|
19449
19490
|
return join10(dirname7(serverAddressPathForStateDir(stateDir)), "logs", "audit.jsonl");
|
|
@@ -24682,6 +24723,33 @@ var init_usage_limit = __esm({
|
|
|
24682
24723
|
}
|
|
24683
24724
|
});
|
|
24684
24725
|
|
|
24726
|
+
// packages/server/src/backend/codex-usage-limit.ts
|
|
24727
|
+
function codexLimitFault(error, at2) {
|
|
24728
|
+
if (error.retrying || !at2 || !Number.isFinite(Date.parse(at2))) return void 0;
|
|
24729
|
+
if (error.code !== "usage_limit_exceeded" && error.code !== "rate_limit_exceeded") return void 0;
|
|
24730
|
+
return {
|
|
24731
|
+
window: "unknown",
|
|
24732
|
+
at: at2,
|
|
24733
|
+
codex: /\bworkspace is out of credits\b/i.test(error.message) ? "credits" : "usage"
|
|
24734
|
+
};
|
|
24735
|
+
}
|
|
24736
|
+
function codexLimitRecovery(fault, quota, nowMs) {
|
|
24737
|
+
const live2 = quota?.codexRecovery;
|
|
24738
|
+
const faultAt = Date.parse(fault.at);
|
|
24739
|
+
if (!fault.codex || !Number.isFinite(faultAt) || quota?.status !== "ok" || !live2 || !Number.isFinite(live2.observedAt) || live2.observedAt <= faultAt || live2.observedAt > nowMs || nowMs - live2.observedAt > 6e4) return void 0;
|
|
24740
|
+
if (live2.blocked) return "blocked";
|
|
24741
|
+
const credits = live2.creditsAvailable === true;
|
|
24742
|
+
const headroom = quota.windows.length > 0 && quota.windows.every((w) => Number.isFinite(w.usedPercent) && w.usedPercent >= 0 && w.usedPercent <= 85);
|
|
24743
|
+
const included = live2.ordinaryUsageAllowed === true || fault.codex !== "credits" && live2.ordinaryUsageAllowed === void 0 && headroom;
|
|
24744
|
+
if (!credits && !included) return "blocked";
|
|
24745
|
+
return { key: live2.accountKey ?? "unidentified-codex-account" };
|
|
24746
|
+
}
|
|
24747
|
+
var init_codex_usage_limit = __esm({
|
|
24748
|
+
"packages/server/src/backend/codex-usage-limit.ts"() {
|
|
24749
|
+
"use strict";
|
|
24750
|
+
}
|
|
24751
|
+
});
|
|
24752
|
+
|
|
24685
24753
|
// packages/server/src/backend/claude-agent-sdk-protocol.ts
|
|
24686
24754
|
function hasUndeliverableInputText(value) {
|
|
24687
24755
|
for (const character of value) {
|
|
@@ -24997,7 +25065,7 @@ var init_ipc_path = __esm({
|
|
|
24997
25065
|
|
|
24998
25066
|
// packages/server/src/backend/claude-broker-host.ts
|
|
24999
25067
|
import { spawn } from "node:child_process";
|
|
25000
|
-
import { createHash as
|
|
25068
|
+
import { createHash as createHash7, randomUUID as randomUUID8 } from "node:crypto";
|
|
25001
25069
|
import { accessSync, constants as fsConstants, mkdirSync as mkdirSync13, readFileSync as readFileSync12, readdirSync as readdirSync5, statSync as statSync8, unlinkSync, writeFileSync as writeFileSync10 } from "node:fs";
|
|
25002
25070
|
import { delimiter, dirname as dirname11, isAbsolute as isAbsolute4, join as join20 } from "node:path";
|
|
25003
25071
|
function windowsShimTarget(shimPath) {
|
|
@@ -25050,7 +25118,7 @@ function resolveClaudeExecutableAbsolute(bin, env = process.env) {
|
|
|
25050
25118
|
throw new Error(`Claude session broker: could not resolve '${candidate}' to an absolute executable path on PATH (the SDK requires one)`);
|
|
25051
25119
|
}
|
|
25052
25120
|
function claudeBrokerSocketPath(stateDir, sessionId) {
|
|
25053
|
-
const key =
|
|
25121
|
+
const key = createHash7("sha256").update(stateDir).update("\0").update(sessionId).digest("hex").slice(0, 16);
|
|
25054
25122
|
return frizzIpcPath(`frizz-claude-${key}`);
|
|
25055
25123
|
}
|
|
25056
25124
|
function claudeBrokerRecordPath(stateDir, sessionId) {
|
|
@@ -25059,7 +25127,7 @@ function claudeBrokerRecordPath(stateDir, sessionId) {
|
|
|
25059
25127
|
function claudeBrokerRecordName(sessionId) {
|
|
25060
25128
|
let name = recordNames.get(sessionId);
|
|
25061
25129
|
if (name === void 0) {
|
|
25062
|
-
name = `${
|
|
25130
|
+
name = `${createHash7("sha256").update(sessionId).digest("hex").slice(0, 16)}.json`;
|
|
25063
25131
|
recordNames.set(sessionId, name);
|
|
25064
25132
|
}
|
|
25065
25133
|
return name;
|
|
@@ -25100,7 +25168,7 @@ function brokerLivenessSnapshot(stateDir) {
|
|
|
25100
25168
|
});
|
|
25101
25169
|
}
|
|
25102
25170
|
function claudeBrokerRetirementPath(stateDir, sessionId) {
|
|
25103
|
-
const key =
|
|
25171
|
+
const key = createHash7("sha256").update(sessionId).digest("hex").slice(0, 16);
|
|
25104
25172
|
return join20(stateDir, "claude-broker", `${key}.retired`);
|
|
25105
25173
|
}
|
|
25106
25174
|
function markBrokerRetired(stateDir, sessionId, reason, generation) {
|
|
@@ -26191,12 +26259,12 @@ var init_completion_relay = __esm({
|
|
|
26191
26259
|
});
|
|
26192
26260
|
|
|
26193
26261
|
// packages/server/src/tail-cache.ts
|
|
26194
|
-
import { createHash as
|
|
26262
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
26195
26263
|
import { closeSync as closeSync9, openSync as openSync10, readFileSync as readFileSync13, readSync as readSync3, statSync as statSync10 } from "node:fs";
|
|
26196
26264
|
import { join as join21 } from "node:path";
|
|
26197
26265
|
function foldSchemaDigest(dir = import.meta.dirname) {
|
|
26198
26266
|
if (foldSchemaMemo) return foldSchemaMemo;
|
|
26199
|
-
const hash =
|
|
26267
|
+
const hash = createHash8("sha256").update("frizz-tail-state-v1\0");
|
|
26200
26268
|
let read = 0;
|
|
26201
26269
|
for (const name of FOLD_SOURCES) {
|
|
26202
26270
|
try {
|
|
@@ -26239,7 +26307,7 @@ function measureFence(path3, offset) {
|
|
|
26239
26307
|
const tail = Buffer.allocUnsafe(window);
|
|
26240
26308
|
const tailRead = readSync3(fd, tail, 0, window, offset - window);
|
|
26241
26309
|
if (headRead !== window || tailRead !== window) return null;
|
|
26242
|
-
const contentDigest =
|
|
26310
|
+
const contentDigest = createHash8("sha256").update(String(offset)).update("\0").update(head).update("\0").update(tail).digest("hex").slice(0, 32);
|
|
26243
26311
|
return {
|
|
26244
26312
|
offset,
|
|
26245
26313
|
size: stat2.size,
|
|
@@ -26450,7 +26518,7 @@ var init_json_value = __esm({
|
|
|
26450
26518
|
// packages/server/src/tailer.ts
|
|
26451
26519
|
import { statSync as statSync11, openSync as openSync11, readSync as readSync4, closeSync as closeSync10, readdirSync as readdirSync6, realpathSync as realpathSync6, mkdirSync as mkdirSync14, writeFileSync as writeFileSync11, readFileSync as readFileSync14, existsSync as existsSync7 } from "node:fs";
|
|
26452
26520
|
import { execFile as execFile2 } from "node:child_process";
|
|
26453
|
-
import { createHash as
|
|
26521
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
26454
26522
|
import { promisify as promisify2 } from "node:util";
|
|
26455
26523
|
import { basename as basename4, join as join22, win32 } from "node:path";
|
|
26456
26524
|
import { homedir as homedir7 } from "node:os";
|
|
@@ -27209,7 +27277,7 @@ function trackCompletions(state, rec) {
|
|
|
27209
27277
|
const monitorTimedOut = isMonitorTimeoutEvent(block);
|
|
27210
27278
|
const terminal = status === "completed" || status === "failed" || status === "killed" ? status : status === "stopped" || monitorTimedOut ? "killed" : void 0;
|
|
27211
27279
|
if (!terminal) continue;
|
|
27212
|
-
const fingerprint =
|
|
27280
|
+
const fingerprint = createHash9("sha1").update(block).digest("hex").slice(0, 16);
|
|
27213
27281
|
const repeatOf = /* @__PURE__ */ new Set();
|
|
27214
27282
|
for (const id of blockTaskIds(block)) {
|
|
27215
27283
|
if (state.foldedTerminals?.get(id) === fingerprint) repeatOf.add(id);
|
|
@@ -27475,6 +27543,7 @@ function applyEvent(state, ev2) {
|
|
|
27475
27543
|
state.turn = "idle";
|
|
27476
27544
|
state.apiFault = true;
|
|
27477
27545
|
state.providerError = ev2.error;
|
|
27546
|
+
state.limitFault = codexLimitFault(ev2.error, ev2.at);
|
|
27478
27547
|
state.lastAssistant = ev2.error.message;
|
|
27479
27548
|
state.lastAssistantLine = firstTextLine(ev2.error.message);
|
|
27480
27549
|
state.lastFence = void 0;
|
|
@@ -27493,6 +27562,7 @@ function applyEvent(state, ev2) {
|
|
|
27493
27562
|
if (ev2.finalText !== void 0 || ev2.successful) {
|
|
27494
27563
|
state.apiFault = void 0;
|
|
27495
27564
|
state.providerError = void 0;
|
|
27565
|
+
state.limitFault = void 0;
|
|
27496
27566
|
}
|
|
27497
27567
|
if (ev2.finalText !== void 0) {
|
|
27498
27568
|
applyFinalText(state, ev2.finalText);
|
|
@@ -27504,6 +27574,7 @@ function applyEvent(state, ev2) {
|
|
|
27504
27574
|
state.sawRecords = true;
|
|
27505
27575
|
state.apiFault = void 0;
|
|
27506
27576
|
state.providerError = void 0;
|
|
27577
|
+
state.limitFault = void 0;
|
|
27507
27578
|
if (ev2.final) {
|
|
27508
27579
|
if (typeof ev2.at === "string") state.lastAssistantAt = ev2.at;
|
|
27509
27580
|
applyFinalText(state, ev2.text);
|
|
@@ -27519,6 +27590,7 @@ function applyEvent(state, ev2) {
|
|
|
27519
27590
|
break;
|
|
27520
27591
|
case "user-message":
|
|
27521
27592
|
state.sawRecords = true;
|
|
27593
|
+
state.limitFault = void 0;
|
|
27522
27594
|
state.turn = "in-flight";
|
|
27523
27595
|
state.lastAssistantAllDone = false;
|
|
27524
27596
|
state.lastFence = void 0;
|
|
@@ -28446,16 +28518,16 @@ ${ask}`;
|
|
|
28446
28518
|
if (row?.backend === "codex") return false;
|
|
28447
28519
|
const current = measureFence(entry.path, entry.offset);
|
|
28448
28520
|
if (!current || !fenceMatches(entry, current)) return false;
|
|
28449
|
-
const
|
|
28450
|
-
if (!
|
|
28451
|
-
if (
|
|
28521
|
+
const decoded2 = decodeTailState(entry.state);
|
|
28522
|
+
if (!decoded2) return false;
|
|
28523
|
+
if (decoded2.offset !== entry.offset || typeof decoded2.partial !== "string") return false;
|
|
28452
28524
|
for (const field2 of ["subAgents", "retiredSubAgents", "queuedReports", "retiredShells"]) {
|
|
28453
|
-
if (!(
|
|
28525
|
+
if (!(decoded2[field2] instanceof Map)) return false;
|
|
28454
28526
|
}
|
|
28455
|
-
if (!(
|
|
28456
|
-
if (!(
|
|
28527
|
+
if (!(decoded2.deliveredReports instanceof Set)) return false;
|
|
28528
|
+
if (!(decoded2.ownedToolUseIds instanceof Set)) return false;
|
|
28457
28529
|
const target = state;
|
|
28458
|
-
for (const [key2, value] of Object.entries(
|
|
28530
|
+
for (const [key2, value] of Object.entries(decoded2)) {
|
|
28459
28531
|
if (UNRESTORED_TAIL_FIELDS.has(key2)) continue;
|
|
28460
28532
|
target[key2] = value;
|
|
28461
28533
|
}
|
|
@@ -29193,6 +29265,7 @@ var init_tailer = __esm({
|
|
|
29193
29265
|
init_subagent_profile();
|
|
29194
29266
|
init_claude_runtime_ingest();
|
|
29195
29267
|
init_usage_limit();
|
|
29268
|
+
init_codex_usage_limit();
|
|
29196
29269
|
init_claude_broker_diagnostics();
|
|
29197
29270
|
init_claude_broker_host();
|
|
29198
29271
|
init_delivery_ledger();
|
|
@@ -30009,19 +30082,19 @@ function searchPath2(env) {
|
|
|
30009
30082
|
function vendoredNativeBeside(launcherJs, arch, access) {
|
|
30010
30083
|
const triple = WINDOWS_TRIPLE[arch];
|
|
30011
30084
|
if (!triple) return void 0;
|
|
30012
|
-
const { dirname: dirname32, join:
|
|
30085
|
+
const { dirname: dirname32, join: join61 } = win322;
|
|
30013
30086
|
const pkgRoot = dirname32(dirname32(launcherJs));
|
|
30014
30087
|
const platformPkg = `codex-win32-${arch}`;
|
|
30015
30088
|
const vendorRoots = [
|
|
30016
|
-
|
|
30089
|
+
join61(pkgRoot, "node_modules", "@openai", platformPkg, "vendor"),
|
|
30017
30090
|
// nested under the package
|
|
30018
|
-
|
|
30091
|
+
join61(dirname32(pkgRoot), platformPkg, "vendor"),
|
|
30019
30092
|
// hoisted beside it: <prefix>\node_modules\@openai\<pkg>
|
|
30020
|
-
|
|
30093
|
+
join61(pkgRoot, "vendor")
|
|
30021
30094
|
// the pre-platform-package layout, binaries inside @openai/codex itself
|
|
30022
30095
|
];
|
|
30023
30096
|
for (const root of vendorRoots) {
|
|
30024
|
-
const exe2 =
|
|
30097
|
+
const exe2 = join61(root, triple, "bin", "codex.exe");
|
|
30025
30098
|
if (access(exe2, "exists")) return exe2;
|
|
30026
30099
|
}
|
|
30027
30100
|
return void 0;
|
|
@@ -30078,14 +30151,14 @@ var init_codex_executable = __esm({
|
|
|
30078
30151
|
});
|
|
30079
30152
|
|
|
30080
30153
|
// packages/server/src/backend/claude-quota-observed.ts
|
|
30081
|
-
import { createHash as
|
|
30154
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
30082
30155
|
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
30083
30156
|
import { join as join24 } from "node:path";
|
|
30084
30157
|
function finite(value) {
|
|
30085
30158
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
30086
30159
|
}
|
|
30087
30160
|
function observedQuotaPath(cacheDir, configDir) {
|
|
30088
|
-
const profile =
|
|
30161
|
+
const profile = createHash10("sha256").update(configDir).digest("hex").slice(0, 12);
|
|
30089
30162
|
return join24(cacheDir, `claude-observed-${profile}.json`);
|
|
30090
30163
|
}
|
|
30091
30164
|
function live(window, now) {
|
|
@@ -30126,7 +30199,7 @@ var init_claude_quota_observed = __esm({
|
|
|
30126
30199
|
// packages/server/src/backend/claude-quota.ts
|
|
30127
30200
|
import { join as join25 } from "node:path";
|
|
30128
30201
|
import { homedir as homedir9, platform } from "node:os";
|
|
30129
|
-
import { createHash as
|
|
30202
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
30130
30203
|
import { mkdir as mkdir2, readFile as readFile2, rename as rename2, rm as rm2, stat, writeFile as writeFile2 } from "node:fs/promises";
|
|
30131
30204
|
import { execFile as execFile3 } from "node:child_process";
|
|
30132
30205
|
import { promisify as promisify3 } from "node:util";
|
|
@@ -30275,11 +30348,11 @@ async function resolveConfiguredRoute(configDir, env = process.env) {
|
|
|
30275
30348
|
return {
|
|
30276
30349
|
url,
|
|
30277
30350
|
headers: credential,
|
|
30278
|
-
fingerprint:
|
|
30351
|
+
fingerprint: createHash11("sha256").update(JSON.stringify([url, credential])).digest("hex").slice(0, 16)
|
|
30279
30352
|
};
|
|
30280
30353
|
}
|
|
30281
30354
|
function cachePaths(cacheDir, configDir) {
|
|
30282
|
-
const profile =
|
|
30355
|
+
const profile = createHash11("sha256").update(configDir).digest("hex").slice(0, 12);
|
|
30283
30356
|
return {
|
|
30284
30357
|
data: join25(cacheDir, `claude-${profile}.json`),
|
|
30285
30358
|
lock: join25(cacheDir, `claude-${profile}.lock`)
|
|
@@ -31500,14 +31573,14 @@ var require_permessage_deflate = __commonJS({
|
|
|
31500
31573
|
}
|
|
31501
31574
|
};
|
|
31502
31575
|
module.exports = PerMessageDeflate2;
|
|
31503
|
-
function deflateOnData(
|
|
31504
|
-
this[kBuffers].push(
|
|
31505
|
-
this[kTotalLength] +=
|
|
31576
|
+
function deflateOnData(chunk2) {
|
|
31577
|
+
this[kBuffers].push(chunk2);
|
|
31578
|
+
this[kTotalLength] += chunk2.length;
|
|
31506
31579
|
}
|
|
31507
|
-
function inflateOnData(
|
|
31508
|
-
this[kTotalLength] +=
|
|
31580
|
+
function inflateOnData(chunk2) {
|
|
31581
|
+
this[kTotalLength] += chunk2.length;
|
|
31509
31582
|
if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
|
|
31510
|
-
this[kBuffers].push(
|
|
31583
|
+
this[kBuffers].push(chunk2);
|
|
31511
31584
|
return;
|
|
31512
31585
|
}
|
|
31513
31586
|
this[kError] = new RangeError("Max payload size exceeded");
|
|
@@ -31807,7 +31880,7 @@ var require_receiver = __commonJS({
|
|
|
31807
31880
|
* @param {Function} cb Callback
|
|
31808
31881
|
* @private
|
|
31809
31882
|
*/
|
|
31810
|
-
_write(
|
|
31883
|
+
_write(chunk2, encoding, cb) {
|
|
31811
31884
|
if (this._opcode === 8 && this._state == GET_INFO) return cb();
|
|
31812
31885
|
if (this._maxBufferedChunks > 0 && this._buffers.length >= this._maxBufferedChunks) {
|
|
31813
31886
|
cb(
|
|
@@ -31821,8 +31894,8 @@ var require_receiver = __commonJS({
|
|
|
31821
31894
|
);
|
|
31822
31895
|
return;
|
|
31823
31896
|
}
|
|
31824
|
-
this._bufferedBytes +=
|
|
31825
|
-
this._buffers.push(
|
|
31897
|
+
this._bufferedBytes += chunk2.length;
|
|
31898
|
+
this._buffers.push(chunk2);
|
|
31826
31899
|
this.startLoop(cb);
|
|
31827
31900
|
}
|
|
31828
31901
|
/**
|
|
@@ -33245,7 +33318,7 @@ var require_websocket = __commonJS({
|
|
|
33245
33318
|
var http = __require("http");
|
|
33246
33319
|
var net2 = __require("net");
|
|
33247
33320
|
var tls = __require("tls");
|
|
33248
|
-
var { randomBytes: randomBytes3, createHash:
|
|
33321
|
+
var { randomBytes: randomBytes3, createHash: createHash24 } = __require("crypto");
|
|
33249
33322
|
var { Duplex, Readable: Readable3 } = __require("stream");
|
|
33250
33323
|
var { URL: URL2 } = __require("url");
|
|
33251
33324
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
@@ -33913,7 +33986,7 @@ var require_websocket = __commonJS({
|
|
|
33913
33986
|
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
33914
33987
|
return;
|
|
33915
33988
|
}
|
|
33916
|
-
const digest =
|
|
33989
|
+
const digest = createHash24("sha1").update(key + GUID).digest("base64");
|
|
33917
33990
|
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
33918
33991
|
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
33919
33992
|
return;
|
|
@@ -34096,8 +34169,8 @@ var require_websocket = __commonJS({
|
|
|
34096
34169
|
this.removeListener("end", socketOnEnd);
|
|
34097
34170
|
websocket._readyState = WebSocket3.CLOSING;
|
|
34098
34171
|
if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && this._readableState.length !== 0) {
|
|
34099
|
-
const
|
|
34100
|
-
websocket._receiver.write(
|
|
34172
|
+
const chunk2 = this.read(this._readableState.length);
|
|
34173
|
+
websocket._receiver.write(chunk2);
|
|
34101
34174
|
}
|
|
34102
34175
|
websocket._receiver.end();
|
|
34103
34176
|
this[kWebSocket] = void 0;
|
|
@@ -34109,8 +34182,8 @@ var require_websocket = __commonJS({
|
|
|
34109
34182
|
websocket._receiver.on("finish", receiverOnFinish);
|
|
34110
34183
|
}
|
|
34111
34184
|
}
|
|
34112
|
-
function socketOnData(
|
|
34113
|
-
if (!this[kWebSocket]._receiver.write(
|
|
34185
|
+
function socketOnData(chunk2) {
|
|
34186
|
+
if (!this[kWebSocket]._receiver.write(chunk2)) {
|
|
34114
34187
|
this.pause();
|
|
34115
34188
|
}
|
|
34116
34189
|
}
|
|
@@ -34213,14 +34286,14 @@ var require_stream = __commonJS({
|
|
|
34213
34286
|
duplex._read = function() {
|
|
34214
34287
|
if (ws2.isPaused) ws2.resume();
|
|
34215
34288
|
};
|
|
34216
|
-
duplex._write = function(
|
|
34289
|
+
duplex._write = function(chunk2, encoding, callback) {
|
|
34217
34290
|
if (ws2.readyState === ws2.CONNECTING) {
|
|
34218
34291
|
ws2.once("open", function open() {
|
|
34219
|
-
duplex._write(
|
|
34292
|
+
duplex._write(chunk2, encoding, callback);
|
|
34220
34293
|
});
|
|
34221
34294
|
return;
|
|
34222
34295
|
}
|
|
34223
|
-
ws2.send(
|
|
34296
|
+
ws2.send(chunk2, callback);
|
|
34224
34297
|
};
|
|
34225
34298
|
duplex.on("end", duplexOnEnd);
|
|
34226
34299
|
duplex.on("error", duplexOnError);
|
|
@@ -34282,7 +34355,7 @@ var require_websocket_server = __commonJS({
|
|
|
34282
34355
|
var EventEmitter = __require("events");
|
|
34283
34356
|
var http = __require("http");
|
|
34284
34357
|
var { Duplex } = __require("stream");
|
|
34285
|
-
var { createHash:
|
|
34358
|
+
var { createHash: createHash24 } = __require("crypto");
|
|
34286
34359
|
var extension2 = require_extension();
|
|
34287
34360
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
34288
34361
|
var subprotocol2 = require_subprotocol();
|
|
@@ -34589,7 +34662,7 @@ var require_websocket_server = __commonJS({
|
|
|
34589
34662
|
);
|
|
34590
34663
|
}
|
|
34591
34664
|
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
34592
|
-
const digest =
|
|
34665
|
+
const digest = createHash24("sha1").update(key + GUID).digest("base64");
|
|
34593
34666
|
const headers = [
|
|
34594
34667
|
"HTTP/1.1 101 Switching Protocols",
|
|
34595
34668
|
"Upgrade: websocket",
|
|
@@ -34758,7 +34831,7 @@ var init_codex_mcp = __esm({
|
|
|
34758
34831
|
import { spawn as spawn2 } from "node:child_process";
|
|
34759
34832
|
import { connect } from "node:net";
|
|
34760
34833
|
import { Agent as HttpAgent } from "node:http";
|
|
34761
|
-
import { createHash as
|
|
34834
|
+
import { createHash as createHash12, randomUUID as randomUUID9 } from "node:crypto";
|
|
34762
34835
|
import { existsSync as existsSync8, mkdirSync as mkdirSync15, readFileSync as readFileSync18, unlinkSync as unlinkSync2, writeFileSync as writeFileSync12 } from "node:fs";
|
|
34763
34836
|
import { join as join27 } from "node:path";
|
|
34764
34837
|
import { PassThrough, Writable } from "node:stream";
|
|
@@ -34770,7 +34843,7 @@ function nativeRecordPath(stateDir, projectId) {
|
|
|
34770
34843
|
return join27(nativeDir(stateDir), `${projectId}.json`);
|
|
34771
34844
|
}
|
|
34772
34845
|
function nativeListenSocketPath(stateDir, projectId) {
|
|
34773
|
-
const key =
|
|
34846
|
+
const key = createHash12("sha256").update(stateDir).update("\0").update(projectId).digest("hex").slice(0, 16);
|
|
34774
34847
|
return frizzIpcPath(`frizz-codex-native-${key}`);
|
|
34775
34848
|
}
|
|
34776
34849
|
function pidAlive2(pid) {
|
|
@@ -34876,8 +34949,8 @@ function attach(record, timeoutMs) {
|
|
|
34876
34949
|
const decoder = new StringDecoder("utf8");
|
|
34877
34950
|
let outbound = "";
|
|
34878
34951
|
const stdin = new Writable({
|
|
34879
|
-
write(
|
|
34880
|
-
outbound += decoder.write(
|
|
34952
|
+
write(chunk2, _encoding, callback) {
|
|
34953
|
+
outbound += decoder.write(chunk2);
|
|
34881
34954
|
for (; ; ) {
|
|
34882
34955
|
const index = outbound.indexOf("\n");
|
|
34883
34956
|
if (index < 0) break;
|
|
@@ -35038,7 +35111,7 @@ var init_codex_app_server_native = __esm({
|
|
|
35038
35111
|
// packages/server/src/backend/codex-app-server-host.ts
|
|
35039
35112
|
import { spawn as spawn3 } from "node:child_process";
|
|
35040
35113
|
import { createConnection } from "node:net";
|
|
35041
|
-
import { createHash as
|
|
35114
|
+
import { createHash as createHash13, randomUUID as randomUUID10 } from "node:crypto";
|
|
35042
35115
|
import { existsSync as existsSync9, mkdirSync as mkdirSync16, readFileSync as readFileSync19, unlinkSync as unlinkSync3 } from "node:fs";
|
|
35043
35116
|
import { join as join28 } from "node:path";
|
|
35044
35117
|
import { PassThrough as PassThrough2, Writable as Writable2 } from "node:stream";
|
|
@@ -35050,7 +35123,7 @@ function recordPath(stateDir, projectId) {
|
|
|
35050
35123
|
return join28(daemonDir(stateDir), `${projectId}.json`);
|
|
35051
35124
|
}
|
|
35052
35125
|
function codexAppServerSocketPath(stateDir, projectId) {
|
|
35053
|
-
const key =
|
|
35126
|
+
const key = createHash13("sha256").update(stateDir).update("\0").update(projectId).digest("hex").slice(0, 16);
|
|
35054
35127
|
return frizzIpcPath(`frizz-codex-${key}`);
|
|
35055
35128
|
}
|
|
35056
35129
|
function pidAlive3(pid) {
|
|
@@ -35207,8 +35280,8 @@ function attach2(record, timeoutMs) {
|
|
|
35207
35280
|
}, timeoutMs);
|
|
35208
35281
|
timer.unref?.();
|
|
35209
35282
|
const stdin = new Writable2({
|
|
35210
|
-
write(
|
|
35211
|
-
socket.write(
|
|
35283
|
+
write(chunk2, _encoding, callback) {
|
|
35284
|
+
socket.write(chunk2, (error) => callback(error ?? null));
|
|
35212
35285
|
}
|
|
35213
35286
|
});
|
|
35214
35287
|
const handle = {
|
|
@@ -35229,8 +35302,8 @@ function attach2(record, timeoutMs) {
|
|
|
35229
35302
|
};
|
|
35230
35303
|
const decoder = new StringDecoder2("utf8");
|
|
35231
35304
|
let buffer = "";
|
|
35232
|
-
socket.on("data", (
|
|
35233
|
-
buffer += decoder.write(
|
|
35305
|
+
socket.on("data", (chunk2) => {
|
|
35306
|
+
buffer += decoder.write(chunk2);
|
|
35234
35307
|
for (; ; ) {
|
|
35235
35308
|
const index = buffer.indexOf("\n");
|
|
35236
35309
|
if (index < 0) break;
|
|
@@ -35419,7 +35492,7 @@ var init_codex_execution_health = __esm({
|
|
|
35419
35492
|
});
|
|
35420
35493
|
|
|
35421
35494
|
// packages/server/src/backend/codex-app-server.ts
|
|
35422
|
-
import { createHash as
|
|
35495
|
+
import { createHash as createHash14, randomUUID as randomUUID11 } from "node:crypto";
|
|
35423
35496
|
import { existsSync as existsSync10 } from "node:fs";
|
|
35424
35497
|
import { StringDecoder as StringDecoder3 } from "node:string_decoder";
|
|
35425
35498
|
function selectCodexHostKind(flagValue, platform3, hasSpawn) {
|
|
@@ -35767,7 +35840,7 @@ function canonicalJson2(value) {
|
|
|
35767
35840
|
return JSON.stringify(normalize2(value));
|
|
35768
35841
|
}
|
|
35769
35842
|
function logicalRequestId(method, parts) {
|
|
35770
|
-
const digest =
|
|
35843
|
+
const digest = createHash14("sha256").update(JSON.stringify([method, ...parts])).digest("hex");
|
|
35771
35844
|
return `codex-${digest}`;
|
|
35772
35845
|
}
|
|
35773
35846
|
function requestFingerprint(value) {
|
|
@@ -35777,7 +35850,7 @@ function requestFingerprint(value) {
|
|
|
35777
35850
|
delete record.startedAtMs;
|
|
35778
35851
|
delete record.autoResolutionMs;
|
|
35779
35852
|
}
|
|
35780
|
-
return
|
|
35853
|
+
return createHash14("sha256").update(canonicalJson2(normalized)).digest("hex");
|
|
35781
35854
|
}
|
|
35782
35855
|
function decision(id, semantic, label) {
|
|
35783
35856
|
return { id, semantic, label };
|
|
@@ -36362,12 +36435,12 @@ var init_codex_app_server = __esm({
|
|
|
36362
36435
|
this.onNotification = onNotification;
|
|
36363
36436
|
this.onClosed = onClosed;
|
|
36364
36437
|
this.diagnostic = diagnostic;
|
|
36365
|
-
child.stdout.on("data", (
|
|
36438
|
+
child.stdout.on("data", (chunk2) => this.consume(chunk2));
|
|
36366
36439
|
child.stdout.on("end", () => this.fail("protocol", new Error("Codex app-server stdout ended")));
|
|
36367
36440
|
child.stdout.on("error", () => this.fail("protocol", new Error("Codex app-server stdout failed")));
|
|
36368
36441
|
child.stdin.on("error", () => this.fail("error", new Error("Codex app-server stdin failed")));
|
|
36369
|
-
child.stderr.on("data", (
|
|
36370
|
-
const size = Buffer.byteLength(
|
|
36442
|
+
child.stderr.on("data", (chunk2) => {
|
|
36443
|
+
const size = Buffer.byteLength(chunk2);
|
|
36371
36444
|
this.stderrBytes = Math.min(MAX_STDERR_BYTES + 1, this.stderrBytes + size);
|
|
36372
36445
|
if (!this.stderrReported) {
|
|
36373
36446
|
this.stderrReported = true;
|
|
@@ -36430,9 +36503,9 @@ var init_codex_app_server = __esm({
|
|
|
36430
36503
|
if (!this.draining) return Promise.resolve();
|
|
36431
36504
|
return new Promise((resolve14) => this.idleWaiters.add(resolve14));
|
|
36432
36505
|
}
|
|
36433
|
-
consume(
|
|
36506
|
+
consume(chunk2) {
|
|
36434
36507
|
if (this.closed) return;
|
|
36435
|
-
this.buffer += typeof
|
|
36508
|
+
this.buffer += typeof chunk2 === "string" ? chunk2 : this.decoder.write(chunk2);
|
|
36436
36509
|
while (true) {
|
|
36437
36510
|
const newline = this.buffer.indexOf("\n");
|
|
36438
36511
|
if (newline < 0) {
|
|
@@ -38940,6 +39013,7 @@ var init_codex_app_server = __esm({
|
|
|
38940
39013
|
import { join as join29 } from "node:path";
|
|
38941
39014
|
import { readdirSync as readdirSync8, statSync as statSync14, openSync as openSync13, readSync as readSync6, fstatSync, closeSync as closeSync12 } from "node:fs";
|
|
38942
39015
|
import { spawn as spawn4 } from "node:child_process";
|
|
39016
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
38943
39017
|
function sessionsDir2(codexHome) {
|
|
38944
39018
|
return join29(codexHome, "sessions");
|
|
38945
39019
|
}
|
|
@@ -39053,18 +39127,32 @@ function toLiveWindow(raw2) {
|
|
|
39053
39127
|
const w = raw2;
|
|
39054
39128
|
return makeWindow(num(w.usedPercent), num(w.windowDurationMins), num(w.resetsAt));
|
|
39055
39129
|
}
|
|
39056
|
-
function parseCodexQuotaFromRateLimits(result) {
|
|
39130
|
+
function parseCodexQuotaFromRateLimits(result, observedAt = Date.now()) {
|
|
39057
39131
|
if (!result || typeof result !== "object") return void 0;
|
|
39058
39132
|
const rl2 = result.rateLimits;
|
|
39059
39133
|
if (!rl2 || typeof rl2 !== "object") return void 0;
|
|
39060
39134
|
const r = rl2;
|
|
39135
|
+
const allowed = result.ordinaryUsageAllowed;
|
|
39136
|
+
const ordinaryUsageAllowed = !("ordinaryUsageAllowed" in result) ? void 0 : typeof allowed === "boolean" ? allowed : null;
|
|
39061
39137
|
const windows = [toLiveWindow(r.primary), toLiveWindow(r.secondary)].filter((x4) => x4 !== void 0);
|
|
39062
|
-
|
|
39138
|
+
const credits = r.credits && typeof r.credits === "object" ? r.credits : void 0;
|
|
39139
|
+
const creditsAvailable = credits?.unlimited === true || credits?.hasCredits === true ? true : credits?.unlimited === false && credits?.hasCredits === false ? false : void 0;
|
|
39140
|
+
const reached = r.rateLimitReachedType;
|
|
39141
|
+
const individual = r.individualLimit && typeof r.individualLimit === "object" ? r.individualLimit : void 0;
|
|
39142
|
+
const blocked = r.spendControlReached === true || typeof reached === "string" && reached !== "rate_limit_reached" || typeof individual?.remainingPercent === "number" && individual.remainingPercent <= 0;
|
|
39143
|
+
if (windows.length === 0 && creditsAvailable === void 0 && ordinaryUsageAllowed !== true) return void 0;
|
|
39063
39144
|
const planType = typeof r.planType === "string" ? r.planType : void 0;
|
|
39064
|
-
return { status: "ok", planType, windows
|
|
39145
|
+
return { status: "ok", planType, windows, codexRecovery: {
|
|
39146
|
+
observedAt,
|
|
39147
|
+
creditsAvailable,
|
|
39148
|
+
...ordinaryUsageAllowed !== void 0 ? { ordinaryUsageAllowed } : {},
|
|
39149
|
+
...blocked ? { blocked: true } : {}
|
|
39150
|
+
} };
|
|
39065
39151
|
}
|
|
39066
39152
|
function queryCodexRateLimits(codexHome = defaultCodexHome(), codexBin = "codex", timeoutMs = 12e3) {
|
|
39067
39153
|
return new Promise((resolve14) => {
|
|
39154
|
+
const observedAt = Date.now();
|
|
39155
|
+
const accountId = readCodexAccountId(codexHome);
|
|
39068
39156
|
let child;
|
|
39069
39157
|
try {
|
|
39070
39158
|
const codex = resolveCodexExecutable(codexBin);
|
|
@@ -39101,8 +39189,8 @@ function queryCodexRateLimits(codexHome = defaultCodexHome(), codexBin = "codex"
|
|
|
39101
39189
|
child.on("exit", () => finish(void 0));
|
|
39102
39190
|
child.stdin?.on("error", () => finish(void 0));
|
|
39103
39191
|
let buf = "";
|
|
39104
|
-
child.stdout?.on("data", (
|
|
39105
|
-
buf +=
|
|
39192
|
+
child.stdout?.on("data", (chunk2) => {
|
|
39193
|
+
buf += chunk2.toString("utf8");
|
|
39106
39194
|
if (buf.length > 4 * 1024 * 1024) buf = buf.slice(-64 * 1024);
|
|
39107
39195
|
let nl2;
|
|
39108
39196
|
while ((nl2 = buf.indexOf("\n")) >= 0) {
|
|
@@ -39119,7 +39207,13 @@ function queryCodexRateLimits(codexHome = defaultCodexHome(), codexBin = "codex"
|
|
|
39119
39207
|
send({ jsonrpc: "2.0", method: "initialized" });
|
|
39120
39208
|
send({ jsonrpc: "2.0", id: 2, method: "account/rateLimits/read", params: {} });
|
|
39121
39209
|
} else if (msg.id === 2) {
|
|
39122
|
-
|
|
39210
|
+
const quota = parseCodexQuotaFromRateLimits(msg.result, observedAt);
|
|
39211
|
+
if (quota) {
|
|
39212
|
+
const reported = msg.result && typeof msg.result === "object" ? msg.result.accountId : void 0;
|
|
39213
|
+
if (readCodexAccountId(codexHome) !== accountId || accountId && typeof reported === "string" && reported !== accountId) delete quota.codexRecovery;
|
|
39214
|
+
else if (accountId) quota.codexRecovery.accountKey = createHash15("sha256").update(accountId).digest("hex");
|
|
39215
|
+
}
|
|
39216
|
+
finish(quota);
|
|
39123
39217
|
}
|
|
39124
39218
|
}
|
|
39125
39219
|
});
|
|
@@ -39537,7 +39631,7 @@ function readQuestionFences(storage, input) {
|
|
|
39537
39631
|
for (const id of assembled.refs) {
|
|
39538
39632
|
const row = index.get(id);
|
|
39539
39633
|
if (!row) {
|
|
39540
|
-
fault(id, `\`id: ${id}\` alone references a question, and no question of yours uses that id \u2014 to ask
|
|
39634
|
+
fault(id, `\`id: ${id}\` alone references a question, and no question of yours uses that id, so the human was never asked it and no answer is coming \u2014 \`frizzctl activity\` lists the questions you have open; to ask this one, write the whole fence, with a \`kind:\` and a \`question:\``);
|
|
39541
39635
|
} else if (!settledBefore(row)) ref(row);
|
|
39542
39636
|
else if (row.state === "answered") continue;
|
|
39543
39637
|
else if (row.state === "withdrawn") {
|
|
@@ -39581,7 +39675,7 @@ ${b.read.id.toLowerCase()}`)) continue;
|
|
|
39581
39675
|
return open.filter((q5) => q5.asked_at > restFrom || named.has(q5.id));
|
|
39582
39676
|
}
|
|
39583
39677
|
function questionFenceCorrection(faults, opts = {}) {
|
|
39584
|
-
const asks = faults.some((f) => f.faults.some((x4) => !/
|
|
39678
|
+
const asks = faults.some((f) => f.faults.some((x4) => !/nothing left to reference/.test(x4)));
|
|
39585
39679
|
const lines = [
|
|
39586
39680
|
`${QUESTION_FENCE_CORRECTION_LEAD}could not register, so ${asks ? "the human has NOT been asked" : "it placed nothing"}:`,
|
|
39587
39681
|
"",
|
|
@@ -39593,6 +39687,7 @@ function questionFenceCorrection(faults, opts = {}) {
|
|
|
39593
39687
|
"`description:`, `recommended: true` and an indented `detail: |` block. Anything else the human needs",
|
|
39594
39688
|
"goes below a `---` line as markdown. A fence with `id:` alone references a question you already asked."
|
|
39595
39689
|
];
|
|
39690
|
+
if (opts.typedPast) lines.push("", QUESTION_FENCE_TYPED_PAST_HINT);
|
|
39596
39691
|
if (opts.closedOnDone) lines.push("", QUESTION_FENCE_UNDER_DONE_HINT);
|
|
39597
39692
|
return lines.join("\n");
|
|
39598
39693
|
}
|
|
@@ -39647,13 +39742,14 @@ function createQuestionRegistrar(deps) {
|
|
|
39647
39742
|
}
|
|
39648
39743
|
};
|
|
39649
39744
|
}
|
|
39650
|
-
var QUESTION_FENCES_REGISTER_FROM, REGISTER_FROM_MS, bare, SETTLED_WORD, QUESTION_FENCE_UNDER_DONE_HINT;
|
|
39745
|
+
var QUESTION_FENCES_REGISTER_FROM, REGISTER_FROM_MS, QUESTION_FAULTS_OUTLIVE_HUMAN_FROM, bare, SETTLED_WORD, QUESTION_FENCE_TYPED_PAST_HINT, QUESTION_FENCE_UNDER_DONE_HINT;
|
|
39651
39746
|
var init_question_fences = __esm({
|
|
39652
39747
|
"packages/server/src/question-fences.ts"() {
|
|
39653
39748
|
"use strict";
|
|
39654
39749
|
init_src();
|
|
39655
39750
|
QUESTION_FENCES_REGISTER_FROM = "2026-10-13T20:00:00Z";
|
|
39656
39751
|
REGISTER_FROM_MS = Date.parse(QUESTION_FENCES_REGISTER_FROM);
|
|
39752
|
+
QUESTION_FAULTS_OUTLIVE_HUMAN_FROM = "2026-10-21T22:00:00Z";
|
|
39657
39753
|
bare = (q5) => JSON.stringify({ ...q5, options: q5.options?.map(({ followUps: _followUps, ...o }) => o) });
|
|
39658
39754
|
SETTLED_WORD = {
|
|
39659
39755
|
open: "open",
|
|
@@ -39661,6 +39757,7 @@ var init_question_fences = __esm({
|
|
|
39661
39757
|
withdrawn: "withdrawn",
|
|
39662
39758
|
dismissed: "dismissed by the human"
|
|
39663
39759
|
};
|
|
39760
|
+
QUESTION_FENCE_TYPED_PAST_HINT = "The human has written to you since the message that carried this fence; if what they wrote already settles it, there is nothing to ask again.";
|
|
39664
39761
|
QUESTION_FENCE_UNDER_DONE_HINT = "This rest also closed on a ```done fence, and a done fence cannot stand beside a question once it registers: the message that carries the fixed fence carries no ```done fence, and the sign-off as done comes once the question is answered.";
|
|
39665
39762
|
}
|
|
39666
39763
|
});
|
|
@@ -40438,7 +40535,7 @@ var init_worker_plugin_dir = __esm({
|
|
|
40438
40535
|
});
|
|
40439
40536
|
|
|
40440
40537
|
// packages/server/src/stable-plugin-path.ts
|
|
40441
|
-
import { createHash as
|
|
40538
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
40442
40539
|
import { cpSync, lstatSync as lstatSync4, mkdirSync as mkdirSync17, readFileSync as readFileSync22, readdirSync as readdirSync9, readlinkSync, realpathSync as realpathSync9, renameSync as renameSync7, rmSync as rmSync10, statSync as statSync16, symlinkSync as symlinkSync2 } from "node:fs";
|
|
40443
40540
|
import { homedir as homedir13 } from "node:os";
|
|
40444
40541
|
import { dirname as dirname15, isAbsolute as isAbsolute7, join as join34, resolve as resolve7 } from "node:path";
|
|
@@ -40533,7 +40630,7 @@ function pluginFiles(root) {
|
|
|
40533
40630
|
return files;
|
|
40534
40631
|
}
|
|
40535
40632
|
function pluginContentDigest(dir, siblings = []) {
|
|
40536
|
-
const hash =
|
|
40633
|
+
const hash = createHash16("sha256");
|
|
40537
40634
|
const roots = [[dir, ""], ...siblings.map((s) => [join34(dirname15(dir), s), `../${s}/`])];
|
|
40538
40635
|
for (const [root, prefix] of roots) {
|
|
40539
40636
|
for (const rel of pluginFiles(root)) hash.update(prefix + rel).update("\0").update(readFileSync22(join34(root, rel))).update("\0");
|
|
@@ -41093,7 +41190,17 @@ HTML page carrying every candidate, linked in your message as \`[name](file:///a
|
|
|
41093
41190
|
screenshot it, judge the screenshots, or put them in a lightbox or a question option in its place: the
|
|
41094
41191
|
human reads the real page in their own browser faster and better than any picture of it (maintainer
|
|
41095
41192
|
2026-10-06: *"you should always just generate an artifact or an HTML page or whatever and just link me
|
|
41096
|
-
to it. You don't need to take screenshots; that just made it harder for me to gauge"*)
|
|
41193
|
+
to it. You don't need to take screenshots; that just made it harder for me to gauge"*).
|
|
41194
|
+
|
|
41195
|
+
**SELF-CONTAINED MEANS THE ONE FILE, AND NOTHING BESIDE IT.** Every image, stylesheet, font and
|
|
41196
|
+
script the page uses goes INSIDE it: a screenshot as a \`data:\` URI, never a relative \`src\` to a
|
|
41197
|
+
file in the same folder. The browser that opens the link may be allowed that one file and nothing
|
|
41198
|
+
else. On macOS a browser denied the folder the page sits in (Documents, Desktop and Downloads each
|
|
41199
|
+
need the human's permission) is still handed the page it was asked to open, and refused every file
|
|
41200
|
+
beside it, so each image draws as a broken icon. Your own headless browser cannot catch this, since
|
|
41201
|
+
it inherits your terminal's folder access: check the page COPIED ALONE into an empty directory
|
|
41202
|
+
before you link it (maintainer 2026-10-21, after galleries of screenshots reached them as broken
|
|
41203
|
+
images: *"You keep making this mistake"*).`;
|
|
41097
41204
|
MARKDOWN_COMPONENTS = `## Markdown that Frizz draws as more than text
|
|
41098
41205
|
|
|
41099
41206
|
Each of these is drawn wherever your Markdown is: a message, the body of \`frizzctl done\`, a
|
|
@@ -42069,8 +42176,8 @@ function connectClaudeBroker(socketPath, handlers, options = {}) {
|
|
|
42069
42176
|
}
|
|
42070
42177
|
pendingInputs.clear();
|
|
42071
42178
|
};
|
|
42072
|
-
const onData = (
|
|
42073
|
-
buf +=
|
|
42179
|
+
const onData = (chunk2) => {
|
|
42180
|
+
buf += chunk2;
|
|
42074
42181
|
for (let nl2 = buf.indexOf("\n"); nl2 >= 0; nl2 = buf.indexOf("\n")) {
|
|
42075
42182
|
const line = buf.slice(0, nl2);
|
|
42076
42183
|
buf = buf.slice(nl2 + 1);
|
|
@@ -43042,7 +43149,7 @@ var init_claude_agent_broker_bridge = __esm({
|
|
|
43042
43149
|
// packages/server/src/dispatch.ts
|
|
43043
43150
|
import { closeSync as closeSync14, constants as constants3, existsSync as existsSync13, fstatSync as fstatSync3, lstatSync as lstatSync5, openSync as openSync15, readFileSync as readFileSync23, realpathSync as realpathSync10, statSync as statSync18, writeFileSync as writeFileSync13, mkdirSync as mkdirSync18, rmSync as rmSync11 } from "node:fs";
|
|
43044
43151
|
import { basename as basename7, join as join36, dirname as dirname16 } from "node:path";
|
|
43045
|
-
import { createHash as
|
|
43152
|
+
import { createHash as createHash17, randomUUID as randomUUID14 } from "node:crypto";
|
|
43046
43153
|
function fallbackTitle(prompt) {
|
|
43047
43154
|
const firstLine2 = prompt.trim().split("\n", 1)[0].trim();
|
|
43048
43155
|
let allWords = firstLine2.split(/\s+/).filter(Boolean);
|
|
@@ -43111,7 +43218,7 @@ function resolveLegacyThreadFile(projectDir, value) {
|
|
|
43111
43218
|
size: after.size,
|
|
43112
43219
|
mtimeMs: after.mtimeMs,
|
|
43113
43220
|
ctimeMs: after.ctimeMs,
|
|
43114
|
-
digest:
|
|
43221
|
+
digest: createHash17("sha256").update(contents).digest("hex")
|
|
43115
43222
|
};
|
|
43116
43223
|
} catch {
|
|
43117
43224
|
return null;
|
|
@@ -44348,6 +44455,7 @@ function resolveRecurringPrompt(row) {
|
|
|
44348
44455
|
function resolveLimitPause(row, tele, nowMs) {
|
|
44349
44456
|
const fault = tele?.limitFault;
|
|
44350
44457
|
if (!fault) return void 0;
|
|
44458
|
+
if (fault.codex) return void 0;
|
|
44351
44459
|
const at2 = Date.parse(fault.at);
|
|
44352
44460
|
const stale = limitPauseIsStale(fault.window, at2, nowMs);
|
|
44353
44461
|
const resumesAtMs = fault.resetClock && Number.isFinite(at2) ? textResetInstant({ window: fault.window, resetClock: fault.resetClock }, at2) : void 0;
|
|
@@ -45968,16 +46076,16 @@ function createGithubReviewFetcher(deps = {}) {
|
|
|
45968
46076
|
}
|
|
45969
46077
|
const entries2 = [...batch.values()];
|
|
45970
46078
|
for (let offset = 0; offset < entries2.length; offset += MAX_REFS_PER_REQUEST) {
|
|
45971
|
-
const
|
|
46079
|
+
const chunk2 = entries2.slice(offset, offset + MAX_REFS_PER_REQUEST);
|
|
45972
46080
|
if (offset > 0 && now() < rateLimitBlockedUntilMs) {
|
|
45973
|
-
for (const entry of
|
|
46081
|
+
for (const entry of chunk2) for (const resolve14 of entry.resolve) resolve14({ status: "deferred" });
|
|
45974
46082
|
continue;
|
|
45975
46083
|
}
|
|
45976
46084
|
let results;
|
|
45977
46085
|
try {
|
|
45978
|
-
results = await fetchChunk(
|
|
46086
|
+
results = await fetchChunk(chunk2.map((entry) => entry.ref));
|
|
45979
46087
|
} catch (error) {
|
|
45980
|
-
results = new Map(
|
|
46088
|
+
results = new Map(chunk2.map((entry) => [
|
|
45981
46089
|
refKey(entry.ref),
|
|
45982
46090
|
{
|
|
45983
46091
|
status: "error",
|
|
@@ -45985,7 +46093,7 @@ function createGithubReviewFetcher(deps = {}) {
|
|
|
45985
46093
|
}
|
|
45986
46094
|
]));
|
|
45987
46095
|
}
|
|
45988
|
-
for (const entry of
|
|
46096
|
+
for (const entry of chunk2) {
|
|
45989
46097
|
const result = results.get(refKey(entry.ref)) ?? {
|
|
45990
46098
|
status: "error",
|
|
45991
46099
|
failure: { kind: "shape", message: `No GitHub result for ${refKey(entry.ref)}` }
|
|
@@ -46156,7 +46264,7 @@ var init_pr_watch_noise = __esm({
|
|
|
46156
46264
|
// packages/server/src/scheduler.ts
|
|
46157
46265
|
import { execFile as execFile8 } from "node:child_process";
|
|
46158
46266
|
import { promisify as promisify7 } from "node:util";
|
|
46159
|
-
import { createHash as
|
|
46267
|
+
import { createHash as createHash18, randomUUID as randomUUID15 } from "node:crypto";
|
|
46160
46268
|
function failureSignature(rollup) {
|
|
46161
46269
|
const ids = [];
|
|
46162
46270
|
for (const c of Array.isArray(rollup) ? rollup : []) {
|
|
@@ -46166,7 +46274,7 @@ function failureSignature(rollup) {
|
|
|
46166
46274
|
ids.push(`${label}@${c.detailsUrl ?? c.targetUrl ?? c.completedAt ?? ""}`);
|
|
46167
46275
|
}
|
|
46168
46276
|
if (ids.length === 0) return "";
|
|
46169
|
-
return
|
|
46277
|
+
return createHash18("sha1").update(ids.sort().join("\n")).digest("hex").slice(0, 12);
|
|
46170
46278
|
}
|
|
46171
46279
|
function ghPrViewArgs(ref) {
|
|
46172
46280
|
return ["pr", "view", String(ref.number), "--repo", `${ref.owner}/${ref.repo}`, "--json", "state,mergedAt,statusCheckRollup,headRefOid,mergeable,reviewDecision"];
|
|
@@ -46278,7 +46386,7 @@ function githubWatchStatus(pr, polledAt) {
|
|
|
46278
46386
|
};
|
|
46279
46387
|
}
|
|
46280
46388
|
function wakeDeliveryId(slug, sessionId, fenceId) {
|
|
46281
|
-
return
|
|
46389
|
+
return createHash18("sha256").update(slug).update("\0").update(sessionId).update("\0").update(fenceId).digest("hex");
|
|
46282
46390
|
}
|
|
46283
46391
|
function limitFenceId(fault) {
|
|
46284
46392
|
return `${LIMIT_FENCE_PREFIX}${fault.at}`;
|
|
@@ -46293,7 +46401,7 @@ function isReportFenceId(fenceId) {
|
|
|
46293
46401
|
return fenceId.startsWith(`${REPORT_FENCE_PREFIX}:`);
|
|
46294
46402
|
}
|
|
46295
46403
|
function snoozeFenceId(until, prompt) {
|
|
46296
|
-
const digest =
|
|
46404
|
+
const digest = createHash18("sha256").update(prompt).digest("hex").slice(0, 16);
|
|
46297
46405
|
return `${SNOOZE_FENCE_PREFIX}:${until}:${digest}`;
|
|
46298
46406
|
}
|
|
46299
46407
|
function isSnoozeFenceId(fenceId) {
|
|
@@ -46433,7 +46541,7 @@ function isCommandWatchFenceId(fenceId) {
|
|
|
46433
46541
|
return fenceId.startsWith(`${COMMAND_WATCH_FENCE_PREFIX}:`) || fenceId.startsWith(`${COMMAND_WATCH_EXPIRED_FENCE_PREFIX}:`) || fenceId.startsWith(`${COMMAND_WATCH_CANCELLED_FENCE_PREFIX}:`);
|
|
46434
46542
|
}
|
|
46435
46543
|
function questionAnswerFenceId(ids) {
|
|
46436
|
-
return `${QUESTION_ANSWER_FENCE_PREFIX}:${
|
|
46544
|
+
return `${QUESTION_ANSWER_FENCE_PREFIX}:${createHash18("sha256").update([...ids].sort().join(",")).digest("hex").slice(0, 16)}`;
|
|
46437
46545
|
}
|
|
46438
46546
|
function isQuestionAnswerFenceId(fenceId) {
|
|
46439
46547
|
return fenceId.startsWith(`${QUESTION_ANSWER_FENCE_PREFIX}:`);
|
|
@@ -46607,11 +46715,29 @@ function createScheduler(deps) {
|
|
|
46607
46715
|
function retryDelay(attempts) {
|
|
46608
46716
|
return Math.min(retryMaxMs, retryBaseMs * 2 ** Math.max(0, Math.min(30, attempts - 1)));
|
|
46609
46717
|
}
|
|
46718
|
+
function limitTelemetry(row) {
|
|
46719
|
+
const tele = deps.tailer.get(row.slug);
|
|
46720
|
+
const live2 = row.backend === "codex" ? deps.codexTurnLiveness?.(row.slug, row.session_id) : void 0;
|
|
46721
|
+
if (live2?.bridgeTurn) return tele ? { ...tele, turn: "in-flight" } : void 0;
|
|
46722
|
+
const error = live2?.providerError;
|
|
46723
|
+
if (!error || error.retrying || !error.at || tele?.lastActivityAt && error.at < tele.lastActivityAt) return tele;
|
|
46724
|
+
const same2 = tele?.providerError?.message === error.message && tele?.providerError?.code === error.code;
|
|
46725
|
+
const at2 = same2 ? tele?.providerError?.at ?? error.at : error.at;
|
|
46726
|
+
return {
|
|
46727
|
+
subAgents: [],
|
|
46728
|
+
bgShells: [],
|
|
46729
|
+
...tele,
|
|
46730
|
+
turn: "idle",
|
|
46731
|
+
permPrompt: false,
|
|
46732
|
+
pendingQuestion: false,
|
|
46733
|
+
limitFault: codexLimitFault(error, at2)
|
|
46734
|
+
};
|
|
46735
|
+
}
|
|
46610
46736
|
function deliveryContext(item) {
|
|
46611
46737
|
const row = deps.storage.getSession(item.slug);
|
|
46612
46738
|
if (!row || row.session_id !== item.sessionId) return "superseded";
|
|
46613
46739
|
if (row.state === "archived" || row.archived === 1) return "superseded";
|
|
46614
|
-
const tele = deps.tailer.get(item.slug);
|
|
46740
|
+
const tele = isLimitFenceId(item.fenceId) ? limitTelemetry(row) : deps.tailer.get(item.slug);
|
|
46615
46741
|
if (!tele) return "unknown";
|
|
46616
46742
|
if (tele.lastUserText?.includes(wakeDeliveryToken(item.id))) return "confirmed";
|
|
46617
46743
|
if (isLimitFenceId(item.fenceId)) {
|
|
@@ -46754,10 +46880,14 @@ function createScheduler(deps) {
|
|
|
46754
46880
|
const out = [];
|
|
46755
46881
|
for (const row of deps.storage.allSessions()) {
|
|
46756
46882
|
if (row.state === "archived" || row.archived === 1) continue;
|
|
46757
|
-
const tele =
|
|
46883
|
+
const tele = limitTelemetry(row);
|
|
46758
46884
|
const fault = tele?.limitFault;
|
|
46885
|
+
const spent = spentCodexResume.get(row.slug);
|
|
46886
|
+
if (!fault && spent && !tele?.apiFault && Date.parse(tele?.lastAssistantAt ?? "") > spent.at) {
|
|
46887
|
+
spentCodexResume.delete(row.slug);
|
|
46888
|
+
}
|
|
46759
46889
|
if (!fault || tele?.turn !== "idle") continue;
|
|
46760
|
-
if (limitPauseIsStale(fault.window, Date.parse(fault.at), nowMs)) continue;
|
|
46890
|
+
if (limitPauseIsStale(fault.codex ? "weekly" : fault.window, Date.parse(fault.at), nowMs)) continue;
|
|
46761
46891
|
out.push({
|
|
46762
46892
|
slug: row.slug,
|
|
46763
46893
|
sessionId: row.session_id,
|
|
@@ -46768,9 +46898,21 @@ function createScheduler(deps) {
|
|
|
46768
46898
|
return out;
|
|
46769
46899
|
}
|
|
46770
46900
|
const spentEarlyResume = /* @__PURE__ */ new Map();
|
|
46901
|
+
const spentCodexResume = /* @__PURE__ */ new Map();
|
|
46771
46902
|
function limitRecovered(c, quota, nowMs) {
|
|
46772
46903
|
const faultAtMs = Date.parse(c.fault.at);
|
|
46773
46904
|
const provider = quota?.[c.backend];
|
|
46905
|
+
if (c.backend === "codex") {
|
|
46906
|
+
if (!Number.isFinite(faultAtMs) || nowMs - faultAtMs < LIMIT_HEADROOM_MIN_FAULT_AGE_MS) return void 0;
|
|
46907
|
+
const recovery = codexLimitRecovery(c.fault, provider, nowMs);
|
|
46908
|
+
if (recovery === "blocked") {
|
|
46909
|
+
spentCodexResume.delete(c.slug);
|
|
46910
|
+
return false;
|
|
46911
|
+
}
|
|
46912
|
+
if (!recovery || spentCodexResume.get(c.slug)?.key === recovery.key) return void 0;
|
|
46913
|
+
spentCodexResume.set(c.slug, { key: recovery.key, at: nowMs });
|
|
46914
|
+
return true;
|
|
46915
|
+
}
|
|
46774
46916
|
if (provider?.status === "ok" && Number.isFinite(faultAtMs) && nowMs - faultAtMs >= LIMIT_HEADROOM_MIN_FAULT_AGE_MS) {
|
|
46775
46917
|
const key = quotaWindowKeyFor(c.fault.window);
|
|
46776
46918
|
const w = key ? provider.windows.find((x4) => x4.key === key) : c.fault.window === "model" ? scopedQuotaWindow(provider.windows, c.fault.model) : void 0;
|
|
@@ -46824,7 +46966,7 @@ function createScheduler(deps) {
|
|
|
46824
46966
|
const deliveryId = wakeDeliveryId(c.slug, c.sessionId, fenceId);
|
|
46825
46967
|
if (outbox.get(deliveryId)) continue;
|
|
46826
46968
|
const fallback = modelFallbackFor(c);
|
|
46827
|
-
if (!fallback && limitRecovered(c, quota,
|
|
46969
|
+
if (!fallback && limitRecovered(c, quota, now()) !== true) continue;
|
|
46828
46970
|
if (fallback) deps.storage.setProfile(c.slug, fallback.model, fallback.effort);
|
|
46829
46971
|
const item = outbox.enqueue({
|
|
46830
46972
|
id: deliveryId,
|
|
@@ -46833,7 +46975,7 @@ function createScheduler(deps) {
|
|
|
46833
46975
|
fenceId,
|
|
46834
46976
|
hintKey: fallback ? `${LIMIT_HINT_PREFIX}model-switch` : `${LIMIT_HINT_PREFIX}${c.fault.window}`,
|
|
46835
46977
|
message: fallback ? limitModelSwitchSteer(fallback.capped, fallback.label) : limitResumeSteer(c.fault.window),
|
|
46836
|
-
reason: fallback ? `${fallback.capped} limit \u2014 restarting on ${fallback.label} (interrupted ${c.fault.at})` : `${c.fault.window} usage limit reset (interrupted ${c.fault.at})`
|
|
46978
|
+
reason: fallback ? `${fallback.capped} limit \u2014 restarting on ${fallback.label} (interrupted ${c.fault.at})` : c.backend === "codex" ? `Codex capacity recovered (interrupted ${c.fault.at})` : `${c.fault.window} usage limit reset (interrupted ${c.fault.at})`
|
|
46837
46979
|
}, nowMs).delivery;
|
|
46838
46980
|
log3(`waker: queued ${c.slug} \u2014 ${item.reason}`);
|
|
46839
46981
|
checkpoint("after-enqueue", item);
|
|
@@ -46975,7 +47117,12 @@ ${wakeTimeHeader(now(), spokeAt)}`;
|
|
|
46975
47117
|
if (tele.lastUserAt && Date.parse(spokeAt) <= Date.parse(tele.lastUserAt)) continue;
|
|
46976
47118
|
if (tele.authFault || tele.apiFault) continue;
|
|
46977
47119
|
const instant2 = (at2) => at2 ? Date.parse(at2) : Number.NEGATIVE_INFINITY;
|
|
46978
|
-
const
|
|
47120
|
+
const humanAt = instant2(tele.restFromAt ?? tele.lastUserAt);
|
|
47121
|
+
const correctedAt = instant2(tele.questionCorrectedAt);
|
|
47122
|
+
const untold = (at2) => {
|
|
47123
|
+
const atMs = Date.parse(at2);
|
|
47124
|
+
return atMs > correctedAt && (atMs >= FAULTS_OUTLIVE_HUMAN_FROM_MS || atMs > humanAt);
|
|
47125
|
+
};
|
|
46979
47126
|
const rows = deps.storage.listThreadQuestions(row.slug);
|
|
46980
47127
|
const fixedAfter = (id, at2) => {
|
|
46981
47128
|
if (!id) return false;
|
|
@@ -46984,8 +47131,9 @@ ${wakeTimeHeader(now(), spokeAt)}`;
|
|
|
46984
47131
|
const fixedByRef = sync.refs.some((r) => Date.parse(r.at) > atMs && rows.some((q5) => q5.id === r.rowId && q5.handle === id));
|
|
46985
47132
|
return fixedByRow || fixedByRef;
|
|
46986
47133
|
};
|
|
46987
|
-
const faults = sync.faults.filter((f) =>
|
|
47134
|
+
const faults = sync.faults.filter((f) => untold(f.at) && !fixedAfter(f.id, f.at));
|
|
46988
47135
|
if (faults.length === 0) continue;
|
|
47136
|
+
const typedPast = faults.some((f) => Date.parse(f.at) < humanAt);
|
|
46989
47137
|
if (faults.some((f) => Date.parse(f.at) > instant2(tele.lastUserAt))) questionFaultRests.set(row.slug, spokeAt);
|
|
46990
47138
|
if (parkCapSpent(row, spokeAt) || !correctionAllowedSinceHuman(row.slug, QUESTION_FENCE_CAUSE, tele)) continue;
|
|
46991
47139
|
const fenceId = parkFenceId(QUESTION_FENCE_CAUSE, spokeAt);
|
|
@@ -46993,9 +47141,9 @@ ${wakeTimeHeader(now(), spokeAt)}`;
|
|
|
46993
47141
|
if (outbox.get(deliveryId)) continue;
|
|
46994
47142
|
const underDone = correctionAllowedSinceHuman(row.slug, DONE_OVER_QUESTION_CAUSE, tele) ? questionsUnderDoneFence(row, tele, rows) : [];
|
|
46995
47143
|
const closedOnDone = underDone.length === 0 && tele.lastFence?.kind === "done";
|
|
46996
|
-
const correction = underDone.length > 0 ? `${questionFenceCorrection(faults)}
|
|
47144
|
+
const correction = underDone.length > 0 ? `${questionFenceCorrection(faults, { typedPast })}
|
|
46997
47145
|
|
|
46998
|
-
Separately, your \`\`\`done fence ${doneOverOpenQuestionsBody(underDone)}` : questionFenceCorrection(faults, { closedOnDone });
|
|
47146
|
+
Separately, your \`\`\`done fence ${doneOverOpenQuestionsBody(underDone)}` : questionFenceCorrection(faults, { closedOnDone, typedPast });
|
|
46999
47147
|
const item = outbox.enqueue({
|
|
47000
47148
|
id: deliveryId,
|
|
47001
47149
|
slug: row.slug,
|
|
@@ -48199,6 +48347,7 @@ ${clock}`;
|
|
|
48199
48347
|
const adopted = [];
|
|
48200
48348
|
for (const sibling of outbox.pendingFor(carrier.slug, carrier.sessionId)) {
|
|
48201
48349
|
if (sibling.id === carrier.id || isQuestionAnswerFenceId(sibling.fenceId)) continue;
|
|
48350
|
+
if (isLimitFenceId(sibling.fenceId) && deps.storage.getSession(sibling.slug)?.backend === "codex") continue;
|
|
48202
48351
|
const context = deliveryContext(sibling);
|
|
48203
48352
|
if (context === "confirmed") {
|
|
48204
48353
|
outbox.confirm(sibling.id, now());
|
|
@@ -48249,7 +48398,18 @@ ${wakeTimeHeader(now(), spokeAt)}`;
|
|
|
48249
48398
|
settleSnooze(item);
|
|
48250
48399
|
continue;
|
|
48251
48400
|
}
|
|
48252
|
-
|
|
48401
|
+
let codexCapacity = true;
|
|
48402
|
+
const row = deps.storage.getSession(item.slug);
|
|
48403
|
+
if (isLimitFenceId(item.fenceId) && row?.backend === "codex") {
|
|
48404
|
+
const fault = limitTelemetry(row)?.limitFault;
|
|
48405
|
+
try {
|
|
48406
|
+
const recovery = fault && codexLimitRecovery(fault, (await deps.readQuota?.())?.codex, now());
|
|
48407
|
+
codexCapacity = !!recovery && recovery !== "blocked";
|
|
48408
|
+
} catch {
|
|
48409
|
+
codexCapacity = false;
|
|
48410
|
+
}
|
|
48411
|
+
}
|
|
48412
|
+
if (!codexCapacity || !isDeliverableNow(item, deliveryContext(item), claimedAt)) {
|
|
48253
48413
|
const deferredAt = now();
|
|
48254
48414
|
outbox.deferFailure(
|
|
48255
48415
|
item.id,
|
|
@@ -48445,13 +48605,14 @@ ${wakeTimeHeader(now(), spokeAt)}`;
|
|
|
48445
48605
|
commandRunsIdle
|
|
48446
48606
|
};
|
|
48447
48607
|
}
|
|
48448
|
-
var execFileAsync5, OFF_MERGE_PATHS, LIMIT_FENCE_PREFIX, LIMIT_HINT_PREFIX, LIMIT_RESUME_GRACE_MS, LIMIT_RESUME_HEADROOM_PERCENT, LIMIT_HEADROOM_MIN_FAULT_AGE_MS, REPORT_FENCE_PREFIX, REPORT_HINT_PREFIX, SNOOZE_FENCE_PREFIX, SNOOZE_HINT_PREFIX, HEARTBEAT_FENCE_PREFIX, HEARTBEAT_HINT_PREFIX, STOP_HOOK_FENCE_PREFIX, STOP_HOOK_HINT_KEY, COMPACT_FENCE_PREFIX, COMPACT_HINT_KEY, TIMER_FENCE_PREFIX, TIMER_HINT_PREFIX, SHELL_FENCE_PREFIX, INTERRUPT_ENDED_FENCE_PREFIX, PR_WATCH_FENCE_PREFIX, PR_WATCH_EXPIRED_FENCE_PREFIX, OWN_WATCH_EXPIRED_FENCE_PREFIX, COMMAND_WATCH_FENCE_PREFIX, COMMAND_WATCH_EXPIRED_FENCE_PREFIX, COMMAND_WATCH_CANCELLED_FENCE_PREFIX, QUESTION_ANSWER_FENCE_PREFIX, ANSWER_REOFFER_BACKOFF_MS, CONTEXT_SUPERSEDED, PR_WATCH_POLL_MS, PR_WATCH_GONE_MS, PR_STATUS_FALLBACK_LIMIT, SIGNOFF_FENCE_PREFIX, SIGNOFF_HINT_KEY, SIGNOFF_NUDGE_MAX, PARK_BUMP_MAX, SIGNOFF_NUDGE_SETTING, PARK_FENCE_PREFIX, QUESTION_FENCE_CAUSE, DONE_OVER_QUESTION_CAUSE, DONE_GATE_FROM_MS, GITHUB_STATUS_CAP, REVIEW_SEEN_CAP, REVIEW_STEER_CAP, AWAITING_KEY_OF, MID_TURN_HOLD_MAX_MS, WAKE_HOLD_DEFERRAL;
|
|
48608
|
+
var execFileAsync5, OFF_MERGE_PATHS, LIMIT_FENCE_PREFIX, LIMIT_HINT_PREFIX, LIMIT_RESUME_GRACE_MS, LIMIT_RESUME_HEADROOM_PERCENT, LIMIT_HEADROOM_MIN_FAULT_AGE_MS, REPORT_FENCE_PREFIX, REPORT_HINT_PREFIX, SNOOZE_FENCE_PREFIX, SNOOZE_HINT_PREFIX, HEARTBEAT_FENCE_PREFIX, HEARTBEAT_HINT_PREFIX, STOP_HOOK_FENCE_PREFIX, STOP_HOOK_HINT_KEY, COMPACT_FENCE_PREFIX, COMPACT_HINT_KEY, TIMER_FENCE_PREFIX, TIMER_HINT_PREFIX, SHELL_FENCE_PREFIX, INTERRUPT_ENDED_FENCE_PREFIX, PR_WATCH_FENCE_PREFIX, PR_WATCH_EXPIRED_FENCE_PREFIX, OWN_WATCH_EXPIRED_FENCE_PREFIX, COMMAND_WATCH_FENCE_PREFIX, COMMAND_WATCH_EXPIRED_FENCE_PREFIX, COMMAND_WATCH_CANCELLED_FENCE_PREFIX, QUESTION_ANSWER_FENCE_PREFIX, ANSWER_REOFFER_BACKOFF_MS, CONTEXT_SUPERSEDED, PR_WATCH_POLL_MS, PR_WATCH_GONE_MS, PR_STATUS_FALLBACK_LIMIT, SIGNOFF_FENCE_PREFIX, SIGNOFF_HINT_KEY, SIGNOFF_NUDGE_MAX, PARK_BUMP_MAX, SIGNOFF_NUDGE_SETTING, PARK_FENCE_PREFIX, QUESTION_FENCE_CAUSE, DONE_OVER_QUESTION_CAUSE, DONE_GATE_FROM_MS, FAULTS_OUTLIVE_HUMAN_FROM_MS, GITHUB_STATUS_CAP, REVIEW_SEEN_CAP, REVIEW_STEER_CAP, AWAITING_KEY_OF, MID_TURN_HOLD_MAX_MS, WAKE_HOLD_DEFERRAL;
|
|
48449
48609
|
var init_scheduler = __esm({
|
|
48450
48610
|
"packages/server/src/scheduler.ts"() {
|
|
48451
48611
|
"use strict";
|
|
48452
48612
|
init_src();
|
|
48453
48613
|
init_question_fences();
|
|
48454
48614
|
init_awaiting();
|
|
48615
|
+
init_codex_usage_limit();
|
|
48455
48616
|
init_usage_limit();
|
|
48456
48617
|
init_thread_profiles();
|
|
48457
48618
|
init_wake_store();
|
|
@@ -48504,6 +48665,7 @@ var init_scheduler = __esm({
|
|
|
48504
48665
|
QUESTION_FENCE_CAUSE = "question-fence";
|
|
48505
48666
|
DONE_OVER_QUESTION_CAUSE = "done-open-question";
|
|
48506
48667
|
DONE_GATE_FROM_MS = Date.parse(QUESTION_FENCES_REGISTER_FROM);
|
|
48668
|
+
FAULTS_OUTLIVE_HUMAN_FROM_MS = Date.parse(QUESTION_FAULTS_OUTLIVE_HUMAN_FROM);
|
|
48507
48669
|
GITHUB_STATUS_CAP = 200;
|
|
48508
48670
|
REVIEW_SEEN_CAP = 300;
|
|
48509
48671
|
REVIEW_STEER_CAP = 10;
|
|
@@ -49164,8 +49326,8 @@ var init_acp_rpc = __esm({
|
|
|
49164
49326
|
});
|
|
49165
49327
|
});
|
|
49166
49328
|
process2.stdin?.on("error", (err) => this.settleClosed(`stdin: ${err.message}`));
|
|
49167
|
-
process2.stdout?.on("data", (
|
|
49168
|
-
this.buffer += typeof
|
|
49329
|
+
process2.stdout?.on("data", (chunk2) => {
|
|
49330
|
+
this.buffer += typeof chunk2 === "string" ? chunk2 : this.decoder.write(chunk2);
|
|
49169
49331
|
let nl2;
|
|
49170
49332
|
while ((nl2 = this.buffer.indexOf("\n")) >= 0) {
|
|
49171
49333
|
const line = this.buffer.slice(0, nl2);
|
|
@@ -49182,8 +49344,8 @@ var init_acp_rpc = __esm({
|
|
|
49182
49344
|
this.overflowing = true;
|
|
49183
49345
|
}
|
|
49184
49346
|
});
|
|
49185
|
-
process2.stderr?.on("data", (
|
|
49186
|
-
const text2 = String(
|
|
49347
|
+
process2.stderr?.on("data", (chunk2) => {
|
|
49348
|
+
const text2 = String(chunk2);
|
|
49187
49349
|
for (const line of text2.split("\n")) {
|
|
49188
49350
|
if (!line.trim()) continue;
|
|
49189
49351
|
this.stderrTail.push(line.slice(0, 2e3));
|
|
@@ -49337,7 +49499,7 @@ var init_acp_rpc = __esm({
|
|
|
49337
49499
|
// packages/server/src/backend/acp-host.ts
|
|
49338
49500
|
import { spawn as spawn7 } from "node:child_process";
|
|
49339
49501
|
import { createConnection as createConnection2 } from "node:net";
|
|
49340
|
-
import { createHash as
|
|
49502
|
+
import { createHash as createHash19, randomUUID as randomUUID16 } from "node:crypto";
|
|
49341
49503
|
import { existsSync as existsSync16, mkdirSync as mkdirSync21, readFileSync as readFileSync26, readdirSync as readdirSync10, unlinkSync as unlinkSync4 } from "node:fs";
|
|
49342
49504
|
import { join as join41 } from "node:path";
|
|
49343
49505
|
import { PassThrough as PassThrough3, Writable as Writable3 } from "node:stream";
|
|
@@ -49349,7 +49511,7 @@ function acpDaemonRecordPath(stateDir, sessionId) {
|
|
|
49349
49511
|
return join41(daemonDir2(stateDir), `${sessionId}.json`);
|
|
49350
49512
|
}
|
|
49351
49513
|
function acpDaemonSocketPath(stateDir, sessionId) {
|
|
49352
|
-
const key =
|
|
49514
|
+
const key = createHash19("sha256").update(stateDir).update("\0").update(sessionId).digest("hex").slice(0, 16);
|
|
49353
49515
|
return frizzIpcPath(`frizz-acp-${key}`);
|
|
49354
49516
|
}
|
|
49355
49517
|
function pidAlive4(pid) {
|
|
@@ -49485,8 +49647,8 @@ function attach3(record, timeoutMs) {
|
|
|
49485
49647
|
}, timeoutMs);
|
|
49486
49648
|
timer.unref?.();
|
|
49487
49649
|
const stdin = new Writable3({
|
|
49488
|
-
write(
|
|
49489
|
-
socket.write(
|
|
49650
|
+
write(chunk2, _encoding, callback) {
|
|
49651
|
+
socket.write(chunk2, (error) => callback(error ?? null));
|
|
49490
49652
|
},
|
|
49491
49653
|
// The bridge's `close()` ends stdin as the protocol's teardown. On a daemon attachment that is a
|
|
49492
49654
|
// DETACH: the socket closes, the agent keeps running.
|
|
@@ -49520,8 +49682,8 @@ function attach3(record, timeoutMs) {
|
|
|
49520
49682
|
};
|
|
49521
49683
|
const decoder = new StringDecoder5("utf8");
|
|
49522
49684
|
let buffer = "";
|
|
49523
|
-
socket.on("data", (
|
|
49524
|
-
buffer += decoder.write(
|
|
49685
|
+
socket.on("data", (chunk2) => {
|
|
49686
|
+
buffer += decoder.write(chunk2);
|
|
49525
49687
|
for (; ; ) {
|
|
49526
49688
|
const index = buffer.indexOf("\n");
|
|
49527
49689
|
if (index < 0) break;
|
|
@@ -79091,9 +79253,9 @@ function runWatchCommand(spec) {
|
|
|
79091
79253
|
return new Promise((resolve14) => {
|
|
79092
79254
|
const chunks = [];
|
|
79093
79255
|
let held = 0;
|
|
79094
|
-
const keep = (
|
|
79095
|
-
chunks.push(
|
|
79096
|
-
held +=
|
|
79256
|
+
const keep = (chunk2) => {
|
|
79257
|
+
chunks.push(chunk2);
|
|
79258
|
+
held += chunk2.length;
|
|
79097
79259
|
while (held - chunks[0].length >= COMMAND_WATCH_OUTPUT_MAX_BYTES && chunks.length > 1) held -= chunks.shift().length;
|
|
79098
79260
|
};
|
|
79099
79261
|
let settled = false;
|
|
@@ -79653,13 +79815,13 @@ async function enumerateProcs(exec = defaultExec, opts = {}) {
|
|
|
79653
79815
|
return rows;
|
|
79654
79816
|
}
|
|
79655
79817
|
const records = [];
|
|
79656
|
-
for (const
|
|
79657
|
-
const record =
|
|
79818
|
+
for (const chunk2 of text2.split(/\n(?=[ \t]*\d+ )/)) {
|
|
79819
|
+
const record = chunk2.replace(/^[ \t]+/, "");
|
|
79658
79820
|
const pid = Number(record.match(/^(\d+) /)?.[1]);
|
|
79659
79821
|
const argv = byPid.get(pid)?.command;
|
|
79660
79822
|
if (argv !== void 0 && record.startsWith(`${pid} ${argv}`)) records.push(record);
|
|
79661
79823
|
else if (records.length) records[records.length - 1] += `
|
|
79662
|
-
${
|
|
79824
|
+
${chunk2}`;
|
|
79663
79825
|
}
|
|
79664
79826
|
for (const rec of records) {
|
|
79665
79827
|
const pid = Number(rec.slice(0, rec.indexOf(" ")));
|
|
@@ -79840,12 +80002,12 @@ var init_orphan_reaper = __esm({
|
|
|
79840
80002
|
});
|
|
79841
80003
|
|
|
79842
80004
|
// packages/server/src/backend/lazy-mcp-host.ts
|
|
79843
|
-
import { createHash as
|
|
80005
|
+
import { createHash as createHash20, randomBytes as randomBytes2 } from "node:crypto";
|
|
79844
80006
|
import { mkdirSync as mkdirSync24, readFileSync as readFileSync30, renameSync as renameSync12, writeFileSync as writeFileSync15 } from "node:fs";
|
|
79845
80007
|
import { join as join46 } from "node:path";
|
|
79846
80008
|
function lazyMcpCacheKey(server, cwd) {
|
|
79847
80009
|
const identity = JSON.stringify({ command: server.command, args: server.args ?? [], env: server.env ?? {}, cwd });
|
|
79848
|
-
return
|
|
80010
|
+
return createHash20("sha256").update(identity).digest("hex").slice(0, 32);
|
|
79849
80011
|
}
|
|
79850
80012
|
function lazyMcpCachedToolCount(server, cwd, cacheDir) {
|
|
79851
80013
|
try {
|
|
@@ -80745,6 +80907,7 @@ function createContextUnchecked(opts, resources) {
|
|
|
80745
80907
|
// so consulting it per tick costs a live request only every few minutes. Read through the resolved
|
|
80746
80908
|
// runtimes, as the quota RPC does: a bare call would start whatever `codex` is first on PATH.
|
|
80747
80909
|
readQuota: () => readQuota({ claudeBin: opts.claudeBin, codexBin: opts.codexBin }),
|
|
80910
|
+
codexTurnLiveness: (slug, sessionId) => codexAppServer?.turnLiveness(slug, sessionId),
|
|
80748
80911
|
// The only runtime that can answer is the broker: its daemon record is on disk while the daemon
|
|
80749
80912
|
// lives and is unlinked when it dies (liveBrokerRecords checks the pid), so "did the process that
|
|
80750
80913
|
// took this wake survive" is one directory read. Codex and any row whose session moved on answer
|
|
@@ -81365,15 +81528,15 @@ var init_request = __esm({
|
|
|
81365
81528
|
return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
|
|
81366
81529
|
}
|
|
81367
81530
|
#getAllDecodedParams() {
|
|
81368
|
-
const
|
|
81531
|
+
const decoded2 = {};
|
|
81369
81532
|
const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
|
|
81370
81533
|
for (const key of keys) {
|
|
81371
81534
|
const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
81372
81535
|
if (value !== void 0) {
|
|
81373
|
-
|
|
81536
|
+
decoded2[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
|
|
81374
81537
|
}
|
|
81375
81538
|
}
|
|
81376
|
-
return
|
|
81539
|
+
return decoded2;
|
|
81377
81540
|
}
|
|
81378
81541
|
#getParamValue(paramKey) {
|
|
81379
81542
|
return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
|
|
@@ -84053,7 +84216,7 @@ var init_bash_background = __esm({
|
|
|
84053
84216
|
|
|
84054
84217
|
// packages/server/src/transcript.ts
|
|
84055
84218
|
import { closeSync as closeSync16, existsSync as existsSync20, fstatSync as fstatSync4, mkdirSync as mkdirSync25, openSync as openSync17, readdirSync as readdirSync13, readFileSync as readFileSync33, readSync as readSync9, renameSync as renameSync13, statSync as statSync21, unlinkSync as unlinkSync7, writeFileSync as writeFileSync17 } from "node:fs";
|
|
84056
|
-
import { createHash as
|
|
84219
|
+
import { createHash as createHash21 } from "node:crypto";
|
|
84057
84220
|
import { StringDecoder as StringDecoder6 } from "node:string_decoder";
|
|
84058
84221
|
import { join as join48 } from "node:path";
|
|
84059
84222
|
import { homedir as homedir19 } from "node:os";
|
|
@@ -84584,9 +84747,9 @@ ${block.text}` : block.text;
|
|
|
84584
84747
|
processLine(text2, at2);
|
|
84585
84748
|
return true;
|
|
84586
84749
|
}
|
|
84587
|
-
function ingest(
|
|
84588
|
-
if (!
|
|
84589
|
-
const data = buffer +
|
|
84750
|
+
function ingest(chunk2) {
|
|
84751
|
+
if (!chunk2) return;
|
|
84752
|
+
const data = buffer + chunk2;
|
|
84590
84753
|
buffer = "";
|
|
84591
84754
|
let pos = offset;
|
|
84592
84755
|
const lastNl = data.lastIndexOf("\n");
|
|
@@ -84741,7 +84904,7 @@ function persistDataUrlImage(dataUrl, idKey) {
|
|
|
84741
84904
|
function persistBase64Image(mediaType, data, idKey) {
|
|
84742
84905
|
const ext = IMAGE_MEDIA_EXT[typeof mediaType === "string" ? mediaType.toLowerCase() : ""];
|
|
84743
84906
|
if (!ext || !data) return void 0;
|
|
84744
|
-
const name =
|
|
84907
|
+
const name = createHash21("sha256").update(idKey).digest("hex").slice(0, 32);
|
|
84745
84908
|
const path3 = join48(SCREENSHOT_CACHE_DIR, `${name}.${ext}`);
|
|
84746
84909
|
try {
|
|
84747
84910
|
if (existsSync20(path3)) return path3;
|
|
@@ -84763,7 +84926,7 @@ function persistSentFile(srcPath, idKey) {
|
|
|
84763
84926
|
if (!ATTACHMENT_IMAGE_EXTENSIONS.includes(ext)) return void 0;
|
|
84764
84927
|
const outExt = ext === "jpeg" ? "jpg" : ext;
|
|
84765
84928
|
try {
|
|
84766
|
-
const name =
|
|
84929
|
+
const name = createHash21("sha256").update(idKey).digest("hex").slice(0, 32);
|
|
84767
84930
|
const dest = join48(SCREENSHOT_CACHE_DIR, `${name}.${outExt}`);
|
|
84768
84931
|
if (existsSync20(dest)) return dest;
|
|
84769
84932
|
const size = statSync21(srcPath).size;
|
|
@@ -85155,9 +85318,9 @@ function ingestBounded(entry, to, read) {
|
|
|
85155
85318
|
while (entry.bytesRead < to) {
|
|
85156
85319
|
const buf = read(entry.bytesRead, Math.min(TRANSCRIPT_DECODE_WINDOW, to - entry.bytesRead));
|
|
85157
85320
|
if (buf.length === 0) break;
|
|
85158
|
-
const
|
|
85321
|
+
const chunk2 = entry.decoder.write(buf);
|
|
85159
85322
|
entry.bytesRead += buf.length;
|
|
85160
|
-
if (
|
|
85323
|
+
if (chunk2) entry.fold.ingest(chunk2);
|
|
85161
85324
|
}
|
|
85162
85325
|
}
|
|
85163
85326
|
function readAppendedBytes(fd, from, to) {
|
|
@@ -85569,7 +85732,7 @@ function latestTranscriptWindow(messages, start = latestWindowStart(messages)) {
|
|
|
85569
85732
|
);
|
|
85570
85733
|
if (tools.length === 0) continue;
|
|
85571
85734
|
pinned.push({
|
|
85572
|
-
sourceId: `pinned-bg:${
|
|
85735
|
+
sourceId: `pinned-bg:${createHash21("sha256").update(message.sourceId).digest("base64url").slice(0, 24)}`,
|
|
85573
85736
|
pinnedFromSourceId: message.sourceId,
|
|
85574
85737
|
role: "assistant",
|
|
85575
85738
|
text: "",
|
|
@@ -86365,7 +86528,7 @@ function fixedSnapshot(source) {
|
|
|
86365
86528
|
};
|
|
86366
86529
|
let allBytes;
|
|
86367
86530
|
const fileKey = `${before.dev}:${before.ino}:${Math.trunc(before.birthtimeMs)}`;
|
|
86368
|
-
const transcriptKey =
|
|
86531
|
+
const transcriptKey = createHash21("sha256").update(`${source.slug}\0${source.sessionId}\0${source.nativeId}\0${source.backend}\0${source.runtimeGeneration}\0${fileKey}`).digest("base64url").slice(0, 32);
|
|
86369
86532
|
let rawText;
|
|
86370
86533
|
return {
|
|
86371
86534
|
...source,
|
|
@@ -86398,7 +86561,7 @@ function projectSnapshot(snapshot) {
|
|
|
86398
86561
|
return retireStaleQueuedBubbles([...entry.fold.allMessages()]);
|
|
86399
86562
|
}
|
|
86400
86563
|
function digestPrefix(snapshot, length) {
|
|
86401
|
-
const hash =
|
|
86564
|
+
const hash = createHash21("sha256");
|
|
86402
86565
|
hashRange(hash, snapshot, 0, length);
|
|
86403
86566
|
return hash.digest("base64url");
|
|
86404
86567
|
}
|
|
@@ -86420,7 +86583,7 @@ function fullDigest(snapshot) {
|
|
|
86420
86583
|
fullDigestCache.set(key, entry);
|
|
86421
86584
|
return entry.digest;
|
|
86422
86585
|
}
|
|
86423
|
-
if (!entry || entry.bytes > snapshot.size) entry = { hash:
|
|
86586
|
+
if (!entry || entry.bytes > snapshot.size) entry = { hash: createHash21("sha256"), bytes: 0, digest: "" };
|
|
86424
86587
|
entry.bytes = hashRange(entry.hash, snapshot, entry.bytes, snapshot.size);
|
|
86425
86588
|
entry.digest = entry.hash.copy().digest("base64url");
|
|
86426
86589
|
fullDigestCache.set(key, entry);
|
|
@@ -86498,7 +86661,7 @@ function emptyTranscriptPage(source) {
|
|
|
86498
86661
|
beforeCursor: null,
|
|
86499
86662
|
hasEarlier: false,
|
|
86500
86663
|
reachedTurnBoundary: true,
|
|
86501
|
-
transcriptKey:
|
|
86664
|
+
transcriptKey: createHash21("sha256").update(keySeed).digest("base64url").slice(0, 32),
|
|
86502
86665
|
editedFiles: []
|
|
86503
86666
|
};
|
|
86504
86667
|
}
|
|
@@ -86645,7 +86808,7 @@ function projectTranscriptPageAgentLifecycles(page, lookup, peerLookup, sessionP
|
|
|
86645
86808
|
}
|
|
86646
86809
|
function readTranscriptFile(absPath) {
|
|
86647
86810
|
try {
|
|
86648
|
-
const pathKey =
|
|
86811
|
+
const pathKey = createHash21("sha256").update(absPath).digest("base64url").slice(0, 16);
|
|
86649
86812
|
return parseTranscript(readFileSync33(absPath, "utf8"), `claude-file:${pathKey}`);
|
|
86650
86813
|
} catch {
|
|
86651
86814
|
return [];
|
|
@@ -87067,11 +87230,11 @@ function createGithubHovercardService(deps = {}) {
|
|
|
87067
87230
|
if (wanted.length > 0) {
|
|
87068
87231
|
const chunks = [];
|
|
87069
87232
|
for (let i = 0; i < wanted.length; i += MAX_REFS_PER_QUERY) chunks.push(wanted.slice(i, i + MAX_REFS_PER_QUERY));
|
|
87070
|
-
const runs = chunks.map((
|
|
87071
|
-
const run3 = fetchChunk(
|
|
87072
|
-
for (const ref of
|
|
87233
|
+
const runs = chunks.map((chunk2) => {
|
|
87234
|
+
const run3 = fetchChunk(chunk2);
|
|
87235
|
+
for (const ref of chunk2) inflight.set(ref.key, run3);
|
|
87073
87236
|
return run3.finally(() => {
|
|
87074
|
-
for (const ref of
|
|
87237
|
+
for (const ref of chunk2) if (inflight.get(ref.key) === run3) inflight.delete(ref.key);
|
|
87075
87238
|
});
|
|
87076
87239
|
});
|
|
87077
87240
|
const settled = await Promise.allSettled([...runs, ...joins]);
|
|
@@ -87310,15 +87473,15 @@ function gif(head) {
|
|
|
87310
87473
|
function webp(head) {
|
|
87311
87474
|
if (head.length < 30) return void 0;
|
|
87312
87475
|
if (head.toString("ascii", 0, 4) !== "RIFF" || head.toString("ascii", 8, 12) !== "WEBP") return void 0;
|
|
87313
|
-
const
|
|
87314
|
-
if (
|
|
87476
|
+
const chunk2 = head.toString("ascii", 12, 16);
|
|
87477
|
+
if (chunk2 === "VP8 ") {
|
|
87315
87478
|
return { width: head.readUInt16LE(26) & 16383, height: head.readUInt16LE(28) & 16383, scalable: false };
|
|
87316
87479
|
}
|
|
87317
|
-
if (
|
|
87480
|
+
if (chunk2 === "VP8L") {
|
|
87318
87481
|
const bits = head.readUInt32LE(21);
|
|
87319
87482
|
return { width: (bits & 16383) + 1, height: (bits >> 14 & 16383) + 1, scalable: false };
|
|
87320
87483
|
}
|
|
87321
|
-
if (
|
|
87484
|
+
if (chunk2 === "VP8X") {
|
|
87322
87485
|
const read24 = (at2) => head[at2] | head[at2 + 1] << 8 | head[at2 + 2] << 16;
|
|
87323
87486
|
return { width: read24(24) + 1, height: read24(27) + 1, scalable: false };
|
|
87324
87487
|
}
|
|
@@ -87415,10 +87578,443 @@ var init_image_header = __esm({
|
|
|
87415
87578
|
}
|
|
87416
87579
|
});
|
|
87417
87580
|
|
|
87418
|
-
// packages/server/src/
|
|
87419
|
-
import {
|
|
87581
|
+
// packages/server/src/raster.ts
|
|
87582
|
+
import { deflateSync, inflateSync } from "node:zlib";
|
|
87583
|
+
function decodeRaster(bytes) {
|
|
87584
|
+
try {
|
|
87585
|
+
const buffer = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
87586
|
+
if (buffer.subarray(0, 8).equals(PNG_SIGNATURE)) return decodePng(buffer);
|
|
87587
|
+
if (buffer.length >= 6 && buffer.readUInt16LE(0) === 0 && buffer.readUInt16LE(2) === 1) return decodeIco(buffer);
|
|
87588
|
+
return void 0;
|
|
87589
|
+
} catch {
|
|
87590
|
+
return void 0;
|
|
87591
|
+
}
|
|
87592
|
+
}
|
|
87593
|
+
function rasterDimensions(bytes) {
|
|
87594
|
+
const buffer = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
87595
|
+
if (buffer.length >= 24 && buffer.subarray(0, 8).equals(PNG_SIGNATURE)) {
|
|
87596
|
+
return { width: buffer.readUInt32BE(16), height: buffer.readUInt32BE(20) };
|
|
87597
|
+
}
|
|
87598
|
+
if (buffer.length < 22 || buffer.readUInt16LE(0) !== 0 || buffer.readUInt16LE(2) !== 1) return void 0;
|
|
87599
|
+
let best;
|
|
87600
|
+
for (let i = 0; i < buffer.readUInt16LE(4) && 6 + i * 16 + 16 <= buffer.length; i++) {
|
|
87601
|
+
const width = buffer[6 + i * 16] || 256;
|
|
87602
|
+
const height = buffer[7 + i * 16] || 256;
|
|
87603
|
+
if (!best || width * height > best.width * best.height) best = { width, height };
|
|
87604
|
+
}
|
|
87605
|
+
return best;
|
|
87606
|
+
}
|
|
87607
|
+
function decodePng(buffer) {
|
|
87608
|
+
let at2 = 8;
|
|
87609
|
+
let width = 0;
|
|
87610
|
+
let height = 0;
|
|
87611
|
+
let depth = 0;
|
|
87612
|
+
let colorType = 0;
|
|
87613
|
+
let interlace = 0;
|
|
87614
|
+
let palette;
|
|
87615
|
+
let transparency;
|
|
87616
|
+
const data = [];
|
|
87617
|
+
while (at2 + 8 <= buffer.length) {
|
|
87618
|
+
const length = buffer.readUInt32BE(at2);
|
|
87619
|
+
const type = buffer.toString("latin1", at2 + 4, at2 + 8);
|
|
87620
|
+
const body = buffer.subarray(at2 + 8, at2 + 8 + length);
|
|
87621
|
+
if (body.length !== length) return void 0;
|
|
87622
|
+
if (type === "IHDR") {
|
|
87623
|
+
width = body.readUInt32BE(0);
|
|
87624
|
+
height = body.readUInt32BE(4);
|
|
87625
|
+
depth = body[8];
|
|
87626
|
+
colorType = body[9];
|
|
87627
|
+
interlace = body[12];
|
|
87628
|
+
} else if (type === "PLTE") palette = body;
|
|
87629
|
+
else if (type === "tRNS") transparency = body;
|
|
87630
|
+
else if (type === "IDAT") data.push(body);
|
|
87631
|
+
else if (type === "IEND") break;
|
|
87632
|
+
at2 += 12 + length;
|
|
87633
|
+
}
|
|
87634
|
+
const channels = CHANNELS[colorType];
|
|
87635
|
+
if (!channels || width === 0 || height === 0 || width * height > MAX_DECODE_PIXELS || data.length === 0) return void 0;
|
|
87636
|
+
if (colorType === 3 && !palette) return void 0;
|
|
87637
|
+
const raw2 = inflateSync(Buffer.concat(data));
|
|
87638
|
+
const rgba = new Uint8Array(width * height * 4);
|
|
87639
|
+
const bitsPerPixel = channels * depth;
|
|
87640
|
+
const filterStride = Math.max(1, bitsPerPixel >> 3);
|
|
87641
|
+
let offset = 0;
|
|
87642
|
+
const passes = interlace === 1 ? ADAM7 : [[0, 0, 1, 1]];
|
|
87643
|
+
for (const [x02, y02, dx2, dy2] of passes) {
|
|
87644
|
+
const passWidth = Math.ceil((width - x02) / dx2);
|
|
87645
|
+
const passHeight = Math.ceil((height - y02) / dy2);
|
|
87646
|
+
if (passWidth <= 0 || passHeight <= 0) continue;
|
|
87647
|
+
const rowBytes = Math.ceil(passWidth * bitsPerPixel / 8);
|
|
87648
|
+
let previous = new Uint8Array(rowBytes);
|
|
87649
|
+
for (let row = 0; row < passHeight; row++) {
|
|
87650
|
+
const filter = raw2[offset];
|
|
87651
|
+
const line = raw2.subarray(offset + 1, offset + 1 + rowBytes);
|
|
87652
|
+
if (filter === void 0 || line.length !== rowBytes) return void 0;
|
|
87653
|
+
const current = new Uint8Array(line);
|
|
87654
|
+
unfilter(filter, current, previous, filterStride);
|
|
87655
|
+
offset += 1 + rowBytes;
|
|
87656
|
+
for (let column = 0; column < passWidth; column++) {
|
|
87657
|
+
const target = ((y02 + row * dy2) * width + x02 + column * dx2) * 4;
|
|
87658
|
+
writePixel(rgba, target, current, column, colorType, depth, palette, transparency);
|
|
87659
|
+
}
|
|
87660
|
+
previous = current;
|
|
87661
|
+
}
|
|
87662
|
+
}
|
|
87663
|
+
return { width, height, rgba };
|
|
87664
|
+
}
|
|
87665
|
+
function unfilter(filter, line, above, stride) {
|
|
87666
|
+
const n = line.length;
|
|
87667
|
+
switch (filter) {
|
|
87668
|
+
case 0:
|
|
87669
|
+
return;
|
|
87670
|
+
case 1:
|
|
87671
|
+
for (let i = stride; i < n; i++) line[i] = line[i] + line[i - stride] & 255;
|
|
87672
|
+
return;
|
|
87673
|
+
case 2:
|
|
87674
|
+
for (let i = 0; i < n; i++) line[i] = line[i] + above[i] & 255;
|
|
87675
|
+
return;
|
|
87676
|
+
case 3:
|
|
87677
|
+
for (let i = 0; i < n; i++) line[i] = line[i] + ((i >= stride ? line[i - stride] : 0) + above[i] >> 1) & 255;
|
|
87678
|
+
return;
|
|
87679
|
+
case 4:
|
|
87680
|
+
for (let i = 0; i < n; i++) {
|
|
87681
|
+
const left = i >= stride ? line[i - stride] : 0;
|
|
87682
|
+
const upperLeft = i >= stride ? above[i - stride] : 0;
|
|
87683
|
+
line[i] = line[i] + paeth(left, above[i], upperLeft) & 255;
|
|
87684
|
+
}
|
|
87685
|
+
return;
|
|
87686
|
+
default:
|
|
87687
|
+
throw new Error(`unknown PNG filter ${filter}`);
|
|
87688
|
+
}
|
|
87689
|
+
}
|
|
87690
|
+
function paeth(a, b, c) {
|
|
87691
|
+
const p = a + b - c;
|
|
87692
|
+
const pa2 = Math.abs(p - a);
|
|
87693
|
+
const pb = Math.abs(p - b);
|
|
87694
|
+
const pc2 = Math.abs(p - c);
|
|
87695
|
+
return pa2 <= pb && pa2 <= pc2 ? a : pb <= pc2 ? b : c;
|
|
87696
|
+
}
|
|
87697
|
+
function sample(line, index, depth) {
|
|
87698
|
+
if (depth === 8) return line[index];
|
|
87699
|
+
if (depth === 16) return line[index * 2] << 8 | line[index * 2 + 1];
|
|
87700
|
+
const perByte = 8 / depth;
|
|
87701
|
+
const byte = line[Math.floor(index / perByte)];
|
|
87702
|
+
const shift = 8 - depth * (index % perByte + 1);
|
|
87703
|
+
return byte >> shift & (1 << depth) - 1;
|
|
87704
|
+
}
|
|
87705
|
+
function writePixel(out, at2, line, column, colorType, depth, palette, transparency) {
|
|
87706
|
+
const max = (1 << depth) - 1;
|
|
87707
|
+
const to8 = (value) => depth === 16 ? value >> 8 : depth === 8 ? value : Math.round(value * 255 / max);
|
|
87708
|
+
if (colorType === 3) {
|
|
87709
|
+
const index = sample(line, column, depth);
|
|
87710
|
+
out[at2] = palette[index * 3] ?? 0;
|
|
87711
|
+
out[at2 + 1] = palette[index * 3 + 1] ?? 0;
|
|
87712
|
+
out[at2 + 2] = palette[index * 3 + 2] ?? 0;
|
|
87713
|
+
out[at2 + 3] = transparency && index < transparency.length ? transparency[index] : 255;
|
|
87714
|
+
return;
|
|
87715
|
+
}
|
|
87716
|
+
if (colorType === 0 || colorType === 4) {
|
|
87717
|
+
const grey = sample(line, column * (colorType === 4 ? 2 : 1), depth);
|
|
87718
|
+
out[at2] = out[at2 + 1] = out[at2 + 2] = to8(grey);
|
|
87719
|
+
if (colorType === 4) out[at2 + 3] = to8(sample(line, column * 2 + 1, depth));
|
|
87720
|
+
else out[at2 + 3] = transparency && transparency.length >= 2 && transparency.readUInt16BE(0) === grey ? 0 : 255;
|
|
87721
|
+
return;
|
|
87722
|
+
}
|
|
87723
|
+
const per = colorType === 6 ? 4 : 3;
|
|
87724
|
+
const r = sample(line, column * per, depth);
|
|
87725
|
+
const g = sample(line, column * per + 1, depth);
|
|
87726
|
+
const b = sample(line, column * per + 2, depth);
|
|
87727
|
+
out[at2] = to8(r);
|
|
87728
|
+
out[at2 + 1] = to8(g);
|
|
87729
|
+
out[at2 + 2] = to8(b);
|
|
87730
|
+
if (colorType === 6) out[at2 + 3] = to8(sample(line, column * 4 + 3, depth));
|
|
87731
|
+
else {
|
|
87732
|
+
const keyed = transparency && transparency.length >= 6 && transparency.readUInt16BE(0) === r && transparency.readUInt16BE(2) === g && transparency.readUInt16BE(4) === b;
|
|
87733
|
+
out[at2 + 3] = keyed ? 0 : 255;
|
|
87734
|
+
}
|
|
87735
|
+
}
|
|
87736
|
+
function decodeIco(buffer) {
|
|
87737
|
+
const count = buffer.readUInt16LE(4);
|
|
87738
|
+
let best;
|
|
87739
|
+
for (let i = 0; i < count; i++) {
|
|
87740
|
+
const at2 = 6 + i * 16;
|
|
87741
|
+
if (at2 + 16 > buffer.length) break;
|
|
87742
|
+
const area = (buffer[at2] || 256) * (buffer[at2 + 1] || 256);
|
|
87743
|
+
const bits = buffer.readUInt16LE(at2 + 6);
|
|
87744
|
+
if (!best || area > best.area || area === best.area && bits > best.bits) {
|
|
87745
|
+
best = { area, bits, size: buffer.readUInt32LE(at2 + 8), offset: buffer.readUInt32LE(at2 + 12) };
|
|
87746
|
+
}
|
|
87747
|
+
}
|
|
87748
|
+
if (!best) return void 0;
|
|
87749
|
+
const entry = buffer.subarray(best.offset, best.offset + best.size);
|
|
87750
|
+
if (entry.subarray(0, 8).equals(PNG_SIGNATURE)) return decodePng(entry);
|
|
87751
|
+
return decodeIcoBitmap(entry);
|
|
87752
|
+
}
|
|
87753
|
+
function decodeIcoBitmap(entry) {
|
|
87754
|
+
const headerSize = entry.readUInt32LE(0);
|
|
87755
|
+
const width = entry.readInt32LE(4);
|
|
87756
|
+
const height = entry.readInt32LE(8) / 2;
|
|
87757
|
+
const bits = entry.readUInt16LE(14);
|
|
87758
|
+
const compression = entry.readUInt32LE(16);
|
|
87759
|
+
if (width <= 0 || height <= 0 || width * height > MAX_DECODE_PIXELS || ![1, 4, 8, 24, 32].includes(bits)) return void 0;
|
|
87760
|
+
if (compression !== 0 && !(compression === 3 && bits === 32)) return void 0;
|
|
87761
|
+
const colorsUsed = entry.readUInt32LE(32);
|
|
87762
|
+
const paletteEntries = bits <= 8 ? colorsUsed || 1 << bits : 0;
|
|
87763
|
+
const paletteAt = headerSize + (compression === 3 && headerSize === 40 ? 12 : 0);
|
|
87764
|
+
const pixelsAt = paletteAt + paletteEntries * 4;
|
|
87765
|
+
const stride = Math.ceil(width * bits / 32) * 4;
|
|
87766
|
+
const maskAt = pixelsAt + stride * height;
|
|
87767
|
+
const maskStride = Math.ceil(width / 32) * 4;
|
|
87768
|
+
const hasMask = entry.length >= maskAt + maskStride * height;
|
|
87769
|
+
if (entry.length < maskAt) return void 0;
|
|
87770
|
+
const rgba = new Uint8Array(width * height * 4);
|
|
87771
|
+
let anyAlpha = false;
|
|
87772
|
+
for (let y = 0; y < height; y++) {
|
|
87773
|
+
const row = pixelsAt + (height - 1 - y) * stride;
|
|
87774
|
+
for (let x4 = 0; x4 < width; x4++) {
|
|
87775
|
+
const out = (y * width + x4) * 4;
|
|
87776
|
+
if (bits === 32 || bits === 24) {
|
|
87777
|
+
const at2 = row + x4 * (bits / 8);
|
|
87778
|
+
rgba[out] = entry[at2 + 2];
|
|
87779
|
+
rgba[out + 1] = entry[at2 + 1];
|
|
87780
|
+
rgba[out + 2] = entry[at2];
|
|
87781
|
+
rgba[out + 3] = bits === 32 ? entry[at2 + 3] : 255;
|
|
87782
|
+
if (bits === 32 && entry[at2 + 3] > 0) anyAlpha = true;
|
|
87783
|
+
} else {
|
|
87784
|
+
const index = sample(entry.subarray(row, row + stride), x4, bits);
|
|
87785
|
+
const color = paletteAt + index * 4;
|
|
87786
|
+
rgba[out] = entry[color + 2] ?? 0;
|
|
87787
|
+
rgba[out + 1] = entry[color + 1] ?? 0;
|
|
87788
|
+
rgba[out + 2] = entry[color] ?? 0;
|
|
87789
|
+
rgba[out + 3] = 255;
|
|
87790
|
+
}
|
|
87791
|
+
}
|
|
87792
|
+
}
|
|
87793
|
+
if (!anyAlpha && hasMask) {
|
|
87794
|
+
for (let y = 0; y < height; y++) {
|
|
87795
|
+
const row = maskAt + (height - 1 - y) * maskStride;
|
|
87796
|
+
for (let x4 = 0; x4 < width; x4++) {
|
|
87797
|
+
const transparent = entry[row + (x4 >> 3)] >> 7 - (x4 & 7) & 1;
|
|
87798
|
+
rgba[(y * width + x4) * 4 + 3] = transparent ? 0 : 255;
|
|
87799
|
+
}
|
|
87800
|
+
}
|
|
87801
|
+
}
|
|
87802
|
+
return { width, height, rgba };
|
|
87803
|
+
}
|
|
87804
|
+
function toSrgb8(linear) {
|
|
87805
|
+
const c = linear <= 31308e-7 ? linear * 12.92 : 1.055 * linear ** (1 / 2.4) - 0.055;
|
|
87806
|
+
return Math.max(0, Math.min(255, Math.round(c * 255)));
|
|
87807
|
+
}
|
|
87808
|
+
function coverage(source, target) {
|
|
87809
|
+
const scale = source / target;
|
|
87810
|
+
return Array.from({ length: target }, (_, i) => {
|
|
87811
|
+
const from = i * scale;
|
|
87812
|
+
const to = Math.min(source, (i + 1) * scale);
|
|
87813
|
+
const start = Math.floor(from);
|
|
87814
|
+
const end = Math.ceil(to);
|
|
87815
|
+
const weights = new Float32Array(end - start);
|
|
87816
|
+
for (let j4 = start; j4 < end; j4++) weights[j4 - start] = (Math.min(to, j4 + 1) - Math.max(from, j4)) / scale;
|
|
87817
|
+
return { start, weights };
|
|
87818
|
+
});
|
|
87819
|
+
}
|
|
87820
|
+
function resizeToFit(image, size) {
|
|
87821
|
+
const longest = Math.max(image.width, image.height);
|
|
87822
|
+
if (longest <= size) return image;
|
|
87823
|
+
const width = Math.max(1, Math.round(image.width * size / longest));
|
|
87824
|
+
const height = Math.max(1, Math.round(image.height * size / longest));
|
|
87825
|
+
const columns = coverage(image.width, width);
|
|
87826
|
+
const rows = coverage(image.height, height);
|
|
87827
|
+
const band = new Float32Array(width * image.height * 4);
|
|
87828
|
+
const src = image.rgba;
|
|
87829
|
+
for (let y = 0; y < image.height; y++) {
|
|
87830
|
+
for (let x4 = 0; x4 < width; x4++) {
|
|
87831
|
+
const { start, weights } = columns[x4];
|
|
87832
|
+
let r = 0, g = 0, b = 0, a = 0;
|
|
87833
|
+
for (let k4 = 0; k4 < weights.length; k4++) {
|
|
87834
|
+
const at2 = (y * image.width + start + k4) * 4;
|
|
87835
|
+
const alpha = src[at2 + 3] / 255 * weights[k4];
|
|
87836
|
+
r += TO_LINEAR[src[at2]] * alpha;
|
|
87837
|
+
g += TO_LINEAR[src[at2 + 1]] * alpha;
|
|
87838
|
+
b += TO_LINEAR[src[at2 + 2]] * alpha;
|
|
87839
|
+
a += alpha;
|
|
87840
|
+
}
|
|
87841
|
+
const out = (y * width + x4) * 4;
|
|
87842
|
+
band[out] = r;
|
|
87843
|
+
band[out + 1] = g;
|
|
87844
|
+
band[out + 2] = b;
|
|
87845
|
+
band[out + 3] = a;
|
|
87846
|
+
}
|
|
87847
|
+
}
|
|
87848
|
+
const rgba = new Uint8Array(width * height * 4);
|
|
87849
|
+
for (let y = 0; y < height; y++) {
|
|
87850
|
+
const { start, weights } = rows[y];
|
|
87851
|
+
for (let x4 = 0; x4 < width; x4++) {
|
|
87852
|
+
let r = 0, g = 0, b = 0, a = 0;
|
|
87853
|
+
for (let k4 = 0; k4 < weights.length; k4++) {
|
|
87854
|
+
const at2 = ((start + k4) * width + x4) * 4;
|
|
87855
|
+
const weight = weights[k4];
|
|
87856
|
+
r += band[at2] * weight;
|
|
87857
|
+
g += band[at2 + 1] * weight;
|
|
87858
|
+
b += band[at2 + 2] * weight;
|
|
87859
|
+
a += band[at2 + 3] * weight;
|
|
87860
|
+
}
|
|
87861
|
+
const out = (y * width + x4) * 4;
|
|
87862
|
+
if (a > 0) {
|
|
87863
|
+
rgba[out] = toSrgb8(r / a);
|
|
87864
|
+
rgba[out + 1] = toSrgb8(g / a);
|
|
87865
|
+
rgba[out + 2] = toSrgb8(b / a);
|
|
87866
|
+
}
|
|
87867
|
+
rgba[out + 3] = Math.max(0, Math.min(255, Math.round(a * 255)));
|
|
87868
|
+
}
|
|
87869
|
+
}
|
|
87870
|
+
return { width, height, rgba };
|
|
87871
|
+
}
|
|
87872
|
+
function crc32(bytes) {
|
|
87873
|
+
let c = 4294967295;
|
|
87874
|
+
for (let i = 0; i < bytes.length; i++) c = CRC_TABLE[(c ^ bytes[i]) & 255] ^ c >>> 8;
|
|
87875
|
+
return (c ^ 4294967295) >>> 0;
|
|
87876
|
+
}
|
|
87877
|
+
function chunk(type, body) {
|
|
87878
|
+
const out = Buffer.alloc(12 + body.length);
|
|
87879
|
+
out.writeUInt32BE(body.length, 0);
|
|
87880
|
+
out.write(type, 4, "latin1");
|
|
87881
|
+
out.set(body, 8);
|
|
87882
|
+
out.writeUInt32BE(crc32(out.subarray(4, 8 + body.length)), 8 + body.length);
|
|
87883
|
+
return out;
|
|
87884
|
+
}
|
|
87885
|
+
function encodePng(image) {
|
|
87886
|
+
const { width, height, rgba } = image;
|
|
87887
|
+
const rowBytes = width * 4;
|
|
87888
|
+
const filtered = Buffer.alloc((rowBytes + 1) * height);
|
|
87889
|
+
const candidate = new Uint8Array(rowBytes);
|
|
87890
|
+
const best = new Uint8Array(rowBytes);
|
|
87891
|
+
for (let y = 0; y < height; y++) {
|
|
87892
|
+
const line = rgba.subarray(y * rowBytes, (y + 1) * rowBytes);
|
|
87893
|
+
const above = y > 0 ? rgba.subarray((y - 1) * rowBytes, y * rowBytes) : new Uint8Array(rowBytes);
|
|
87894
|
+
let bestFilter = 0;
|
|
87895
|
+
let bestScore = Infinity;
|
|
87896
|
+
for (let filter = 0; filter < 5; filter++) {
|
|
87897
|
+
let score = 0;
|
|
87898
|
+
for (let i = 0; i < rowBytes; i++) {
|
|
87899
|
+
const left = i >= 4 ? line[i - 4] : 0;
|
|
87900
|
+
const up2 = above[i];
|
|
87901
|
+
const upperLeft = i >= 4 ? above[i - 4] : 0;
|
|
87902
|
+
const predictor = filter === 0 ? 0 : filter === 1 ? left : filter === 2 ? up2 : filter === 3 ? left + up2 >> 1 : paeth(left, up2, upperLeft);
|
|
87903
|
+
const value = line[i] - predictor & 255;
|
|
87904
|
+
candidate[i] = value;
|
|
87905
|
+
score += value < 128 ? value : 256 - value;
|
|
87906
|
+
}
|
|
87907
|
+
if (score < bestScore) {
|
|
87908
|
+
bestScore = score;
|
|
87909
|
+
bestFilter = filter;
|
|
87910
|
+
best.set(candidate);
|
|
87911
|
+
}
|
|
87912
|
+
}
|
|
87913
|
+
const at2 = y * (rowBytes + 1);
|
|
87914
|
+
filtered[at2] = bestFilter;
|
|
87915
|
+
filtered.set(best, at2 + 1);
|
|
87916
|
+
}
|
|
87917
|
+
const header = Buffer.alloc(13);
|
|
87918
|
+
header.writeUInt32BE(width, 0);
|
|
87919
|
+
header.writeUInt32BE(height, 4);
|
|
87920
|
+
header[8] = 8;
|
|
87921
|
+
header[9] = 6;
|
|
87922
|
+
return Buffer.concat([
|
|
87923
|
+
PNG_SIGNATURE,
|
|
87924
|
+
chunk("IHDR", header),
|
|
87925
|
+
chunk("IDAT", deflateSync(filtered, { level: 9 })),
|
|
87926
|
+
chunk("IEND", new Uint8Array(0))
|
|
87927
|
+
]);
|
|
87928
|
+
}
|
|
87929
|
+
var MAX_DECODE_PIXELS, PNG_SIGNATURE, CHANNELS, ADAM7, TO_LINEAR, CRC_TABLE;
|
|
87930
|
+
var init_raster = __esm({
|
|
87931
|
+
"packages/server/src/raster.ts"() {
|
|
87932
|
+
"use strict";
|
|
87933
|
+
MAX_DECODE_PIXELS = 4096 * 4096;
|
|
87934
|
+
PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
|
|
87935
|
+
CHANNELS = { 0: 1, 2: 3, 3: 1, 4: 2, 6: 4 };
|
|
87936
|
+
ADAM7 = [
|
|
87937
|
+
[0, 0, 8, 8],
|
|
87938
|
+
[4, 0, 8, 8],
|
|
87939
|
+
[0, 4, 4, 8],
|
|
87940
|
+
[2, 0, 4, 4],
|
|
87941
|
+
[0, 2, 2, 4],
|
|
87942
|
+
[1, 0, 2, 2],
|
|
87943
|
+
[0, 1, 1, 2]
|
|
87944
|
+
];
|
|
87945
|
+
TO_LINEAR = Float32Array.from({ length: 256 }, (_, i) => {
|
|
87946
|
+
const c = i / 255;
|
|
87947
|
+
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
87948
|
+
});
|
|
87949
|
+
CRC_TABLE = Uint32Array.from({ length: 256 }, (_, n) => {
|
|
87950
|
+
let c = n;
|
|
87951
|
+
for (let k4 = 0; k4 < 8; k4++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
87952
|
+
return c >>> 0;
|
|
87953
|
+
});
|
|
87954
|
+
}
|
|
87955
|
+
});
|
|
87956
|
+
|
|
87957
|
+
// packages/server/src/icon-renditions.ts
|
|
87958
|
+
import { mkdirSync as mkdirSync26, readdirSync as readdirSync14, readFileSync as readFileSync35, renameSync as renameSync14, rmSync as rmSync14, writeFileSync as writeFileSync18 } from "node:fs";
|
|
87420
87959
|
import { homedir as homedir20 } from "node:os";
|
|
87421
|
-
import {
|
|
87960
|
+
import { join as join49 } from "node:path";
|
|
87961
|
+
function iconRenditionDir(id, home = homedir20()) {
|
|
87962
|
+
return join49(frizzPaths({ home }).cache, "project-icons", id);
|
|
87963
|
+
}
|
|
87964
|
+
function renditionName(hash, size) {
|
|
87965
|
+
return `${hash}-${size}.v${RENDITION_VERSION}.png`;
|
|
87966
|
+
}
|
|
87967
|
+
function masterFor(hash, bytes) {
|
|
87968
|
+
const kept = decoded.get(hash);
|
|
87969
|
+
if (kept) return kept;
|
|
87970
|
+
const image = decodeRaster(bytes);
|
|
87971
|
+
if (!image) return void 0;
|
|
87972
|
+
const master = resizeToFit(image, DECODED_MAX_PX);
|
|
87973
|
+
decoded.set(hash, master);
|
|
87974
|
+
if (decoded.size > DECODED_KEPT) decoded.delete(decoded.keys().next().value);
|
|
87975
|
+
return master;
|
|
87976
|
+
}
|
|
87977
|
+
function projectIconRendition(id, bytes, hash, size, options = {}) {
|
|
87978
|
+
if (!Number.isInteger(size) || size < 1 || size > MAX_RENDITION_PX) return void 0;
|
|
87979
|
+
const dimensions = rasterDimensions(bytes);
|
|
87980
|
+
if (!dimensions || Math.max(dimensions.width, dimensions.height) <= size) return void 0;
|
|
87981
|
+
const dir = iconRenditionDir(id, options.home);
|
|
87982
|
+
const file = join49(dir, renditionName(hash, size));
|
|
87983
|
+
try {
|
|
87984
|
+
return readFileSync35(file);
|
|
87985
|
+
} catch {
|
|
87986
|
+
}
|
|
87987
|
+
const master = masterFor(hash, bytes);
|
|
87988
|
+
if (!master) return void 0;
|
|
87989
|
+
const png2 = encodePng(resizeToFit(master, size));
|
|
87990
|
+
try {
|
|
87991
|
+
mkdirSync26(dir, { recursive: true });
|
|
87992
|
+
for (const name of readdirSync14(dir)) if (!name.startsWith(`${hash}-`)) rmSync14(join49(dir, name), { force: true });
|
|
87993
|
+
const partial = `${file}.${process.pid}.tmp`;
|
|
87994
|
+
writeFileSync18(partial, png2);
|
|
87995
|
+
renameSync14(partial, file);
|
|
87996
|
+
} catch {
|
|
87997
|
+
}
|
|
87998
|
+
return png2;
|
|
87999
|
+
}
|
|
88000
|
+
var RENDITION_VERSION, MAX_RENDITION_PX, decoded, DECODED_KEPT, DECODED_MAX_PX;
|
|
88001
|
+
var init_icon_renditions = __esm({
|
|
88002
|
+
"packages/server/src/icon-renditions.ts"() {
|
|
88003
|
+
"use strict";
|
|
88004
|
+
init_frizz_paths();
|
|
88005
|
+
init_raster();
|
|
88006
|
+
RENDITION_VERSION = 1;
|
|
88007
|
+
MAX_RENDITION_PX = 256;
|
|
88008
|
+
decoded = /* @__PURE__ */ new Map();
|
|
88009
|
+
DECODED_KEPT = 8;
|
|
88010
|
+
DECODED_MAX_PX = 1024;
|
|
88011
|
+
}
|
|
88012
|
+
});
|
|
88013
|
+
|
|
88014
|
+
// packages/server/src/project-icon.ts
|
|
88015
|
+
import { readFileSync as readFileSync36, readdirSync as readdirSync15, realpathSync as realpathSync15, statSync as statSync24 } from "node:fs";
|
|
88016
|
+
import { homedir as homedir21 } from "node:os";
|
|
88017
|
+
import { basename as basename10, dirname as dirname23, extname as extname3, join as join50, relative as relative2, sep as sep4 } from "node:path";
|
|
87422
88018
|
function normalizeStem(stem) {
|
|
87423
88019
|
const sized = stem.toLowerCase().replace(/[@-]\d+(\.\d+)?x(\d+)?$/u, "").replace(/[-_]\d{2,4}$/u, "");
|
|
87424
88020
|
const themed = sized.replace(VARIANT_SUFFIX, "");
|
|
@@ -87439,11 +88035,11 @@ function sizeScore(dimensions) {
|
|
|
87439
88035
|
return Math.max(0, Math.min(40, Math.round(Math.log2(edge / 24) * 8)));
|
|
87440
88036
|
}
|
|
87441
88037
|
function under(root, relativeDirectory) {
|
|
87442
|
-
return relativeDirectory ?
|
|
88038
|
+
return relativeDirectory ? join50(root, relativeDirectory) : root;
|
|
87443
88039
|
}
|
|
87444
88040
|
function listFiles(directory) {
|
|
87445
88041
|
try {
|
|
87446
|
-
return
|
|
88042
|
+
return readdirSync15(directory, { withFileTypes: true }).filter((entry) => entry.isFile() || entry.isSymbolicLink()).map((entry) => entry.name);
|
|
87447
88043
|
} catch {
|
|
87448
88044
|
return [];
|
|
87449
88045
|
}
|
|
@@ -87452,7 +88048,7 @@ function iconDirectories(root) {
|
|
|
87452
88048
|
let children2;
|
|
87453
88049
|
try {
|
|
87454
88050
|
children2 = new Set(
|
|
87455
|
-
|
|
88051
|
+
readdirSync15(root, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name)
|
|
87456
88052
|
);
|
|
87457
88053
|
} catch {
|
|
87458
88054
|
return [root];
|
|
@@ -87461,19 +88057,19 @@ function iconDirectories(root) {
|
|
|
87461
88057
|
for (const asset of ASSET_DIRECTORIES) directories.push(under(root, asset));
|
|
87462
88058
|
for (const host of HOST_DIRECTORIES) {
|
|
87463
88059
|
if (!children2.has(host)) continue;
|
|
87464
|
-
for (const asset of ASSET_DIRECTORIES) directories.push(under(
|
|
88060
|
+
for (const asset of ASSET_DIRECTORIES) directories.push(under(join50(root, host), asset));
|
|
87465
88061
|
}
|
|
87466
88062
|
for (const extra of EXTRA_DIRECTORIES) directories.push(under(root, extra));
|
|
87467
88063
|
for (const container of WORKSPACE_CONTAINERS) {
|
|
87468
88064
|
if (!children2.has(container)) continue;
|
|
87469
88065
|
let members;
|
|
87470
88066
|
try {
|
|
87471
|
-
members =
|
|
88067
|
+
members = readdirSync15(join50(root, container), { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => entry.name);
|
|
87472
88068
|
} catch {
|
|
87473
88069
|
continue;
|
|
87474
88070
|
}
|
|
87475
88071
|
for (const member of members) {
|
|
87476
|
-
for (const asset of ASSET_DIRECTORIES) directories.push(under(
|
|
88072
|
+
for (const asset of ASSET_DIRECTORIES) directories.push(under(join50(root, container, member), asset));
|
|
87477
88073
|
}
|
|
87478
88074
|
}
|
|
87479
88075
|
return [...new Set(directories)];
|
|
@@ -87481,13 +88077,13 @@ function iconDirectories(root) {
|
|
|
87481
88077
|
function manifestIcons(manifestPath) {
|
|
87482
88078
|
let parsed;
|
|
87483
88079
|
try {
|
|
87484
|
-
parsed = JSON.parse(
|
|
88080
|
+
parsed = JSON.parse(readFileSync36(manifestPath, "utf8"));
|
|
87485
88081
|
} catch {
|
|
87486
88082
|
return [];
|
|
87487
88083
|
}
|
|
87488
88084
|
if (!Array.isArray(parsed?.icons)) return [];
|
|
87489
88085
|
const directory = dirname23(manifestPath);
|
|
87490
|
-
return parsed.icons.map((icon) => typeof icon?.src === "string" ? icon.src : void 0).filter((src) => !!src && !/^(https?:)?\/\//u.test(src) && !src.startsWith("data:")).map((src) =>
|
|
88086
|
+
return parsed.icons.map((icon) => typeof icon?.src === "string" ? icon.src : void 0).filter((src) => !!src && !/^(https?:)?\/\//u.test(src) && !src.startsWith("data:")).map((src) => join50(directory, src.replace(/[?#].*$/u, "").replace(/^\//u, "")));
|
|
87491
88087
|
}
|
|
87492
88088
|
function projectIconCandidates(root) {
|
|
87493
88089
|
const projectStem = normalizeStem(basename10(root)).normalized;
|
|
@@ -87506,7 +88102,7 @@ function projectIconCandidates(root) {
|
|
|
87506
88102
|
for (const name of listFiles(directory)) {
|
|
87507
88103
|
const extension2 = extname3(name).toLowerCase();
|
|
87508
88104
|
if (MANIFEST_NAMES.includes(name.toLowerCase())) {
|
|
87509
|
-
for (const icon of manifestIcons(
|
|
88105
|
+
for (const icon of manifestIcons(join50(directory, name))) {
|
|
87510
88106
|
if (MEASURABLE_IMAGE_EXTENSIONS.has(extname3(icon).toLowerCase())) {
|
|
87511
88107
|
fromManifest.add(icon);
|
|
87512
88108
|
files.push({ path: icon, directory: dirname23(icon) });
|
|
@@ -87517,7 +88113,7 @@ function projectIconCandidates(root) {
|
|
|
87517
88113
|
if (!MEASURABLE_IMAGE_EXTENSIONS.has(extension2)) continue;
|
|
87518
88114
|
const stem = name.slice(0, name.length - extension2.length);
|
|
87519
88115
|
if (normalizeStem(stem).normalized === "favicon") iconHomes.add(directory);
|
|
87520
|
-
files.push({ path:
|
|
88116
|
+
files.push({ path: join50(directory, name), directory });
|
|
87521
88117
|
if (files.length >= MAX_CANDIDATES) break;
|
|
87522
88118
|
}
|
|
87523
88119
|
}
|
|
@@ -87560,7 +88156,7 @@ function iconMediaType(path3) {
|
|
|
87560
88156
|
}
|
|
87561
88157
|
function resolveProjectIconResponse(id, options = {}) {
|
|
87562
88158
|
if (!id) return { status: 400 };
|
|
87563
|
-
const home = options.home ??
|
|
88159
|
+
const home = options.home ?? homedir21();
|
|
87564
88160
|
const entry = readRegistry(home).projects.find((project) => project.id === id);
|
|
87565
88161
|
if (!entry) return { status: 404 };
|
|
87566
88162
|
const path3 = resolveProjectIcon(id, (root) => detectProjectIcon(root)?.path, { home });
|
|
@@ -87582,11 +88178,19 @@ function resolveProjectIconResponse(id, options = {}) {
|
|
|
87582
88178
|
}
|
|
87583
88179
|
});
|
|
87584
88180
|
if (!roots.some((root) => real === root || real.startsWith(root + sep4))) return { status: 404 };
|
|
88181
|
+
let body;
|
|
87585
88182
|
try {
|
|
87586
|
-
|
|
88183
|
+
body = readFileSync36(real);
|
|
87587
88184
|
} catch {
|
|
87588
88185
|
return { status: 404 };
|
|
87589
88186
|
}
|
|
88187
|
+
const hash = iconContentHash(body);
|
|
88188
|
+
if (entry.iconHash !== hash) recordProjectIconHash(id, path3, hash, home);
|
|
88189
|
+
const rendition = options.size ? projectIconRendition(id, body, hash, options.size, { home }) : void 0;
|
|
88190
|
+
if (rendition) {
|
|
88191
|
+
return { status: 200, contentType: "image/png", body: rendition, hash, etag: `W/"${hash}-${options.size}.v${RENDITION_VERSION}"` };
|
|
88192
|
+
}
|
|
88193
|
+
return { status: 200, contentType, body, hash, etag: `W/"${hash}"` };
|
|
87590
88194
|
}
|
|
87591
88195
|
var MAX_CANDIDATES, HOST_DIRECTORIES, BRAND_KIT_DIRECTORIES, ASSET_DIRECTORIES, EXTRA_DIRECTORIES, WORKSPACE_CONTAINERS, MANIFEST_NAMES, NAME_SCORES, COLOURLESS_SVG_PENALTY, GENERATED_DIRECTORIES, NEVER_AN_ICON, MIN_ASPECT, MAX_ASPECT, MIN_EDGE, VARIANT_SUFFIX, SQUARE_SUFFIX, FORMAT_SCORES, MEDIA_TYPES;
|
|
87592
88196
|
var init_project_icon = __esm({
|
|
@@ -87595,6 +88199,7 @@ var init_project_icon = __esm({
|
|
|
87595
88199
|
init_image_header();
|
|
87596
88200
|
init_frizz_paths();
|
|
87597
88201
|
init_project_registry();
|
|
88202
|
+
init_icon_renditions();
|
|
87598
88203
|
MAX_CANDIDATES = 400;
|
|
87599
88204
|
HOST_DIRECTORIES = [
|
|
87600
88205
|
"site",
|
|
@@ -87731,8 +88336,8 @@ function openPanel(kind, command = panelCommand(kind)) {
|
|
|
87731
88336
|
}
|
|
87732
88337
|
});
|
|
87733
88338
|
child.stderr.setEncoding("utf8");
|
|
87734
|
-
child.stderr.on("data", (
|
|
87735
|
-
stderr +=
|
|
88339
|
+
child.stderr.on("data", (chunk2) => {
|
|
88340
|
+
stderr += chunk2;
|
|
87736
88341
|
});
|
|
87737
88342
|
child.stdin.on("error", () => {
|
|
87738
88343
|
});
|
|
@@ -87940,12 +88545,12 @@ function run(argv) {
|
|
|
87940
88545
|
});
|
|
87941
88546
|
|
|
87942
88547
|
// packages/server/src/router.ts
|
|
87943
|
-
import { readFileSync as
|
|
87944
|
-
import { join as
|
|
88548
|
+
import { readFileSync as readFileSync37, statSync as statSync25 } from "node:fs";
|
|
88549
|
+
import { join as join51, resolve as resolve11 } from "node:path";
|
|
87945
88550
|
import { randomUUID as randomUUID20 } from "node:crypto";
|
|
87946
88551
|
import { basename as basename11, dirname as dirname24 } from "node:path";
|
|
87947
|
-
import { existsSync as existsSync21, mkdirSync as
|
|
87948
|
-
import { homedir as
|
|
88552
|
+
import { existsSync as existsSync21, mkdirSync as mkdirSync27, rmSync as rmSync15, writeFileSync as writeFileSync19 } from "node:fs";
|
|
88553
|
+
import { homedir as homedir22 } from "node:os";
|
|
87949
88554
|
function validateGithubDispatchProfile(input, codexModels) {
|
|
87950
88555
|
if (input.backend === "acp") return;
|
|
87951
88556
|
if (input.effort === void 0) throw new Error(`Unsupported ${input.backend} model/effort pair: ${input.model} / (no effort)`);
|
|
@@ -88101,7 +88706,10 @@ function projectCard(entry, stale) {
|
|
|
88101
88706
|
path: entry.path,
|
|
88102
88707
|
lastOpenedAt: entry.lastOpenedAt,
|
|
88103
88708
|
stale,
|
|
88104
|
-
|
|
88709
|
+
// The picture's own hash where it is known, so the URL changes when the picture does and never
|
|
88710
|
+
// otherwise. A miss has no hash, and takes the scan time: an old miss must be a NEW url, because
|
|
88711
|
+
// the request for it is what runs the rescan (see iconStatus below).
|
|
88712
|
+
iconVersion: entry.iconHash ?? entry.iconScannedAt,
|
|
88105
88713
|
// `iconScannedAt` alone cannot answer this: it is stamped whenever a scan RAN, found or not. See
|
|
88106
88714
|
// ProjectCard.iconStatus for why the never-scanned case has to stay distinguishable.
|
|
88107
88715
|
//
|
|
@@ -88115,10 +88723,10 @@ function projectCard(entry, stale) {
|
|
|
88115
88723
|
iconIsCustom: entry.iconSource === "custom" ? true : void 0
|
|
88116
88724
|
};
|
|
88117
88725
|
}
|
|
88118
|
-
function addProjectAtPath(input, home =
|
|
88726
|
+
function addProjectAtPath(input, home = homedir22()) {
|
|
88119
88727
|
const typed = input.trim();
|
|
88120
88728
|
if (!typed) throw new Error("Enter a folder path.");
|
|
88121
|
-
const expanded = typed === "~" || typed.startsWith("~/") ?
|
|
88729
|
+
const expanded = typed === "~" || typed.startsWith("~/") ? join51(home, typed.slice(1)) : typed;
|
|
88122
88730
|
const absolute = resolve11(expanded);
|
|
88123
88731
|
let stats;
|
|
88124
88732
|
try {
|
|
@@ -88150,15 +88758,15 @@ function storeProjectIcon(id, name, bytes) {
|
|
|
88150
88758
|
if (!entry) throw new Error("No such project.");
|
|
88151
88759
|
if (bytes.length === 0) throw new Error("That file is empty.");
|
|
88152
88760
|
const path3 = customIconPath(id, `.${extension2}`);
|
|
88153
|
-
|
|
88154
|
-
|
|
88761
|
+
mkdirSync27(dirname24(path3), { recursive: true });
|
|
88762
|
+
writeFileSync19(path3, bytes);
|
|
88155
88763
|
if (!imageDimensions(path3)) {
|
|
88156
|
-
|
|
88764
|
+
rmSync15(path3, { force: true });
|
|
88157
88765
|
throw new Error("That file does not look like an image Frizz can draw.");
|
|
88158
88766
|
}
|
|
88159
88767
|
for (const stale of PROJECT_ICON_EXTENSIONS) {
|
|
88160
88768
|
const other = customIconPath(id, `.${stale}`);
|
|
88161
|
-
if (other !== path3)
|
|
88769
|
+
if (other !== path3) rmSync15(other, { force: true });
|
|
88162
88770
|
}
|
|
88163
88771
|
const updated = setProjectIcon(id, path3);
|
|
88164
88772
|
if (!updated) throw new Error("No such project.");
|
|
@@ -88172,7 +88780,7 @@ function iconPicker(id) {
|
|
|
88172
88780
|
function setProjectIconFromFile(id, file) {
|
|
88173
88781
|
let bytes;
|
|
88174
88782
|
try {
|
|
88175
|
-
bytes =
|
|
88783
|
+
bytes = readFileSync37(file);
|
|
88176
88784
|
} catch {
|
|
88177
88785
|
throw new Error("That file could not be read.");
|
|
88178
88786
|
}
|
|
@@ -88205,7 +88813,7 @@ function mergeSubAgentSteers(messages, steers) {
|
|
|
88205
88813
|
return merged2;
|
|
88206
88814
|
}
|
|
88207
88815
|
function createRouter(ctx) {
|
|
88208
|
-
const frizzDir =
|
|
88816
|
+
const frizzDir = join51(ctx.project.dir, ".frizz");
|
|
88209
88817
|
const openRoots = openableFileRoots(ctx.project);
|
|
88210
88818
|
const thisProject = { id: ctx.project.id, dir: ctx.project.dir };
|
|
88211
88819
|
const audit = (action, base, run3, onResult) => audited(ctx.audit, action, base, run3, { onResult, servedBy: ctx.project.id });
|
|
@@ -90915,7 +91523,7 @@ Say which way you went and why in your write-up, so the human can course-correct
|
|
|
90915
91523
|
output: ProjectCard,
|
|
90916
91524
|
handler: async ({ input }) => {
|
|
90917
91525
|
for (const extension2 of PROJECT_ICON_EXTENSIONS) {
|
|
90918
|
-
|
|
91526
|
+
rmSync15(customIconPath(input.id, `.${extension2}`), { force: true });
|
|
90919
91527
|
}
|
|
90920
91528
|
if (!clearProjectIcon(input.id)) throw new Error("No such project.");
|
|
90921
91529
|
resolveProjectIcon(input.id, (root) => detectProjectIcon(root)?.path);
|
|
@@ -91265,11 +91873,11 @@ var init_compression = __esm({
|
|
|
91265
91873
|
});
|
|
91266
91874
|
|
|
91267
91875
|
// packages/server/src/local-visualization.ts
|
|
91268
|
-
import { readdirSync as
|
|
91269
|
-
import { join as
|
|
91876
|
+
import { readdirSync as readdirSync16, readFileSync as readFileSync38, realpathSync as realpathSync16, statSync as statSync26 } from "node:fs";
|
|
91877
|
+
import { join as join52, sep as sep5 } from "node:path";
|
|
91270
91878
|
function children(path3, pattern) {
|
|
91271
91879
|
try {
|
|
91272
|
-
return
|
|
91880
|
+
return readdirSync16(path3, { withFileTypes: true }).filter((entry) => entry.isDirectory() && pattern.test(entry.name)).map((entry) => entry.name).sort().reverse();
|
|
91273
91881
|
} catch {
|
|
91274
91882
|
return [];
|
|
91275
91883
|
}
|
|
@@ -91278,7 +91886,7 @@ function isUnder2(path3, root) {
|
|
|
91278
91886
|
return path3 === root || path3.startsWith(root.endsWith(sep5) ? root : root + sep5);
|
|
91279
91887
|
}
|
|
91280
91888
|
function resolveFragment(projectDir, sessionId, file) {
|
|
91281
|
-
const base =
|
|
91889
|
+
const base = join52(projectDir, ".codex", "visualizations");
|
|
91282
91890
|
let projectReal;
|
|
91283
91891
|
let baseReal;
|
|
91284
91892
|
try {
|
|
@@ -91289,12 +91897,12 @@ function resolveFragment(projectDir, sessionId, file) {
|
|
|
91289
91897
|
}
|
|
91290
91898
|
if (!isUnder2(baseReal, projectReal)) return null;
|
|
91291
91899
|
for (const year of children(base, YEAR_PART)) {
|
|
91292
|
-
const yearDir =
|
|
91900
|
+
const yearDir = join52(base, year);
|
|
91293
91901
|
for (const month of children(yearDir, DATE_PART)) {
|
|
91294
|
-
const monthDir =
|
|
91902
|
+
const monthDir = join52(yearDir, month);
|
|
91295
91903
|
for (const day of children(monthDir, DATE_PART)) {
|
|
91296
|
-
const sessionRoot =
|
|
91297
|
-
const candidate =
|
|
91904
|
+
const sessionRoot = join52(baseReal, year, month, day, sessionId);
|
|
91905
|
+
const candidate = join52(monthDir, day, sessionId, file);
|
|
91298
91906
|
try {
|
|
91299
91907
|
const real = realpathSync16(candidate);
|
|
91300
91908
|
if (isUnder2(real, sessionRoot) && statSync26(real).isFile()) return real;
|
|
@@ -91384,7 +91992,7 @@ function resolveLocalVisualization(projectDir, sessionId, file) {
|
|
|
91384
91992
|
try {
|
|
91385
91993
|
const size = statSync26(path3).size;
|
|
91386
91994
|
if (size > MAX_FRAGMENT_BYTES) return { status: 413 };
|
|
91387
|
-
fragment =
|
|
91995
|
+
fragment = readFileSync38(path3, "utf8");
|
|
91388
91996
|
} catch {
|
|
91389
91997
|
return { status: 404 };
|
|
91390
91998
|
}
|
|
@@ -91427,9 +92035,9 @@ var init_local_visualization = __esm({
|
|
|
91427
92035
|
|
|
91428
92036
|
// packages/server/src/launch-routing.ts
|
|
91429
92037
|
import { realpathSync as realpathSync17 } from "node:fs";
|
|
91430
|
-
import { homedir as
|
|
92038
|
+
import { homedir as homedir23 } from "node:os";
|
|
91431
92039
|
import { isAbsolute as isAbsolute11 } from "node:path";
|
|
91432
|
-
function classifyLaunch(dir, home =
|
|
92040
|
+
function classifyLaunch(dir, home = homedir23()) {
|
|
91433
92041
|
const candidate = realpathSync17(discoverProjectRoot(dir, home));
|
|
91434
92042
|
const refused = isHomeDirectory(candidate, home);
|
|
91435
92043
|
if (!refused && (isExistingProjectRoot(candidate) || findByPath(candidate, home) !== void 0)) {
|
|
@@ -91440,7 +92048,7 @@ function classifyLaunch(dir, home = homedir22()) {
|
|
|
91440
92048
|
function offerPath(directory) {
|
|
91441
92049
|
return `/?add=${encodeURIComponent(directory)}`;
|
|
91442
92050
|
}
|
|
91443
|
-
function routeLaunch(dir, open, home =
|
|
92051
|
+
function routeLaunch(dir, open, home = homedir23()) {
|
|
91444
92052
|
const launch = classifyLaunch(dir, home);
|
|
91445
92053
|
if (launch.kind === "grid") return { path: "/" };
|
|
91446
92054
|
if (launch.kind === "offer") return { path: offerPath(launch.directory) };
|
|
@@ -91476,8 +92084,8 @@ var init_launch_routing = __esm({
|
|
|
91476
92084
|
});
|
|
91477
92085
|
|
|
91478
92086
|
// packages/server/src/project-serving.ts
|
|
91479
|
-
import { readFileSync as
|
|
91480
|
-
import { isAbsolute as isAbsolute12, join as
|
|
92087
|
+
import { readFileSync as readFileSync39, renameSync as renameSync15, writeFileSync as writeFileSync20 } from "node:fs";
|
|
92088
|
+
import { isAbsolute as isAbsolute12, join as join53 } from "node:path";
|
|
91481
92089
|
function parse3(value) {
|
|
91482
92090
|
if (!value || typeof value !== "object") return null;
|
|
91483
92091
|
const record = value;
|
|
@@ -91495,17 +92103,17 @@ function parse3(value) {
|
|
|
91495
92103
|
}
|
|
91496
92104
|
function readProjectServing(stateDir) {
|
|
91497
92105
|
try {
|
|
91498
|
-
return parse3(JSON.parse(
|
|
92106
|
+
return parse3(JSON.parse(readFileSync39(join53(stateDir, PROJECT_SERVING_FILE), "utf8")));
|
|
91499
92107
|
} catch {
|
|
91500
92108
|
return null;
|
|
91501
92109
|
}
|
|
91502
92110
|
}
|
|
91503
92111
|
function writeRecord(stateDir, record) {
|
|
91504
|
-
const path3 =
|
|
92112
|
+
const path3 = join53(stateDir, PROJECT_SERVING_FILE);
|
|
91505
92113
|
const partial = `${path3}.${process.pid}.tmp`;
|
|
91506
|
-
|
|
92114
|
+
writeFileSync20(partial, `${JSON.stringify(record)}
|
|
91507
92115
|
`, { mode: 384 });
|
|
91508
|
-
|
|
92116
|
+
renameSync15(partial, path3);
|
|
91509
92117
|
}
|
|
91510
92118
|
function servingRecordElsewhere(stateDir, projectId, adapter = defaultProcessPlatformAdapter) {
|
|
91511
92119
|
const record = readProjectServing(stateDir);
|
|
@@ -91573,9 +92181,9 @@ var init_project_serving = __esm({
|
|
|
91573
92181
|
});
|
|
91574
92182
|
|
|
91575
92183
|
// packages/server/src/app.ts
|
|
91576
|
-
import { createReadStream as createReadStream2, mkdirSync as
|
|
92184
|
+
import { createReadStream as createReadStream2, mkdirSync as mkdirSync28, writeFileSync as writeFileSync21 } from "node:fs";
|
|
91577
92185
|
import { Readable } from "node:stream";
|
|
91578
|
-
import { join as
|
|
92186
|
+
import { join as join54 } from "node:path";
|
|
91579
92187
|
import { randomUUID as randomUUID21 } from "node:crypto";
|
|
91580
92188
|
function attachmentFileName(name) {
|
|
91581
92189
|
let clean = (name.split(/[\\/]/).pop() ?? "").replace(/\s/g, " ").replace(/[\u0000-\u001f\u007f`]/g, "-").trim();
|
|
@@ -91700,16 +92308,25 @@ function createApp(ctx, options = {}) {
|
|
|
91700
92308
|
return c.body(Readable.toWeb(stream2), 200, headers);
|
|
91701
92309
|
});
|
|
91702
92310
|
app.get(frizzRoute("/project-icon"), (c) => {
|
|
91703
|
-
const
|
|
92311
|
+
const size = Number(c.req.query("s")) || void 0;
|
|
92312
|
+
const r = resolveProjectIconResponse(c.req.query("id"), { size });
|
|
91704
92313
|
if (r.status !== 200) return c.text(String(r.status), r.status);
|
|
91705
|
-
|
|
92314
|
+
const headers = {
|
|
91706
92315
|
"content-type": r.contentType,
|
|
91707
|
-
"cache-control": "private, max-age=300",
|
|
92316
|
+
"cache-control": c.req.query("v") === r.hash ? "private, max-age=300, stale-while-revalidate=2592000" : "private, no-cache",
|
|
92317
|
+
etag: r.etag,
|
|
91708
92318
|
// An SVG icon is a file out of somebody's repository. It renders through <img>, where scripting
|
|
91709
92319
|
// is already off; this makes that unconditional rather than a property of how it is embedded.
|
|
91710
92320
|
"content-security-policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox",
|
|
91711
92321
|
"x-content-type-options": "nosniff"
|
|
91712
|
-
}
|
|
92322
|
+
};
|
|
92323
|
+
const known = (c.req.header("if-none-match") ?? "").split(",").map((tag) => tag.trim().replace(/^W\//u, ""));
|
|
92324
|
+
if (known.includes(r.etag.replace(/^W\//u, "")) || known.includes("*")) return c.body(null, 304, headers);
|
|
92325
|
+
const encoding = r.contentType === "image/svg+xml" ? negotiateEncoding(c.req.header("accept-encoding")) : null;
|
|
92326
|
+
if (encoding && r.body.byteLength >= MIN_COMPRESS_BYTES) {
|
|
92327
|
+
return c.body(compress(r.body, encoding), 200, { ...headers, "content-encoding": encoding, vary: "Accept-Encoding" });
|
|
92328
|
+
}
|
|
92329
|
+
return c.body(Uint8Array.from(r.body), 200, headers);
|
|
91713
92330
|
});
|
|
91714
92331
|
app.get(frizzRoute("/local-visualization"), (c) => {
|
|
91715
92332
|
const row = ctx.storage.getSession(c.req.query("slug") ?? "");
|
|
@@ -91732,10 +92349,10 @@ function createApp(ctx, options = {}) {
|
|
|
91732
92349
|
if (!isAllowedAttachmentName(name)) return c.json({ error: "unsupported file type" }, 400);
|
|
91733
92350
|
if (typeof body.data !== "string" || body.data.length > ATTACHMENT_MAX_BASE64_CHARS) return c.json({ error: "bad payload" }, 400);
|
|
91734
92351
|
const buf = Buffer.from(body.data, "base64");
|
|
91735
|
-
const dir =
|
|
91736
|
-
|
|
91737
|
-
const path3 =
|
|
91738
|
-
|
|
92352
|
+
const dir = join54(ctx.project.stateDir, "attachments", `${Date.now()}-${randomUUID21().slice(0, 8)}`);
|
|
92353
|
+
mkdirSync28(dir, { recursive: true });
|
|
92354
|
+
const path3 = join54(dir, attachmentFileName(name));
|
|
92355
|
+
writeFileSync21(path3, buf);
|
|
91739
92356
|
return c.json({ path: path3 });
|
|
91740
92357
|
});
|
|
91741
92358
|
app.get(
|
|
@@ -91798,7 +92415,7 @@ var init_app = __esm({
|
|
|
91798
92415
|
});
|
|
91799
92416
|
|
|
91800
92417
|
// packages/server/src/app-socket.ts
|
|
91801
|
-
import { createHash as
|
|
92418
|
+
import { createHash as createHash22 } from "node:crypto";
|
|
91802
92419
|
function isWsPath(url) {
|
|
91803
92420
|
return (url ?? "").split("?")[0] === WS_PATH;
|
|
91804
92421
|
}
|
|
@@ -92002,7 +92619,7 @@ function createAppSocketServer(deps) {
|
|
|
92002
92619
|
sendEncoded(ws2, frame, false);
|
|
92003
92620
|
}
|
|
92004
92621
|
function frameSignature(frame) {
|
|
92005
|
-
return
|
|
92622
|
+
return createHash22("sha256").update(frame.text).digest("base64url");
|
|
92006
92623
|
}
|
|
92007
92624
|
const globalReadTimes = [];
|
|
92008
92625
|
const originReadTimes = /* @__PURE__ */ new Map();
|
|
@@ -92395,14 +93012,14 @@ function createAppSocketServer(deps) {
|
|
|
92395
93012
|
closeSocket(ws2, 1003, "text frames required");
|
|
92396
93013
|
return;
|
|
92397
93014
|
}
|
|
92398
|
-
let
|
|
93015
|
+
let decoded2;
|
|
92399
93016
|
try {
|
|
92400
|
-
|
|
93017
|
+
decoded2 = JSON.parse(raw2.toString());
|
|
92401
93018
|
} catch {
|
|
92402
93019
|
closeSocket(ws2, 1008, "invalid message");
|
|
92403
93020
|
return;
|
|
92404
93021
|
}
|
|
92405
|
-
const parsed = SocketClientMsg.safeParse(
|
|
93022
|
+
const parsed = SocketClientMsg.safeParse(decoded2);
|
|
92406
93023
|
if (!parsed.success) {
|
|
92407
93024
|
closeSocket(ws2, 1008, "invalid message");
|
|
92408
93025
|
return;
|
|
@@ -92733,10 +93350,10 @@ var init_local_file_watch = __esm({
|
|
|
92733
93350
|
});
|
|
92734
93351
|
|
|
92735
93352
|
// packages/server/src/boot-progress.ts
|
|
92736
|
-
import { mkdirSync as
|
|
92737
|
-
import { basename as basename13, dirname as dirname26, join as
|
|
93353
|
+
import { mkdirSync as mkdirSync29, readFileSync as readFileSync40, renameSync as renameSync16, rmSync as rmSync16, writeFileSync as writeFileSync22 } from "node:fs";
|
|
93354
|
+
import { basename as basename13, dirname as dirname26, join as join55 } from "node:path";
|
|
92738
93355
|
function bootProgressPath(stateDir) {
|
|
92739
|
-
return
|
|
93356
|
+
return join55(stateDir, BOOT_PROGRESS_NAME);
|
|
92740
93357
|
}
|
|
92741
93358
|
function createBootProgressPublisher(stateDir, minIntervalMs = 200) {
|
|
92742
93359
|
if (!stateDir) {
|
|
@@ -92756,18 +93373,18 @@ function createBootProgressPublisher(stateDir, minIntervalMs = 200) {
|
|
|
92756
93373
|
lastAt = now;
|
|
92757
93374
|
step++;
|
|
92758
93375
|
try {
|
|
92759
|
-
|
|
92760
|
-
const temp =
|
|
92761
|
-
|
|
93376
|
+
mkdirSync29(dirname26(path3), { recursive: true, mode: 448 });
|
|
93377
|
+
const temp = join55(dirname26(path3), `.${basename13(path3)}.${process.pid}.tmp`);
|
|
93378
|
+
writeFileSync22(temp, `${JSON.stringify({ pid: process.pid, step, phase, at: new Date(now).toISOString() })}
|
|
92762
93379
|
`, "utf8");
|
|
92763
|
-
|
|
93380
|
+
renameSync16(temp, path3);
|
|
92764
93381
|
} catch {
|
|
92765
93382
|
}
|
|
92766
93383
|
};
|
|
92767
93384
|
return Object.assign(write, {
|
|
92768
93385
|
done: () => {
|
|
92769
93386
|
try {
|
|
92770
|
-
|
|
93387
|
+
rmSync16(path3, { force: true });
|
|
92771
93388
|
} catch {
|
|
92772
93389
|
}
|
|
92773
93390
|
}
|
|
@@ -92783,12 +93400,12 @@ var init_boot_progress = __esm({
|
|
|
92783
93400
|
});
|
|
92784
93401
|
|
|
92785
93402
|
// packages/server/src/runtime-lease.ts
|
|
92786
|
-
import { existsSync as existsSync22, mkdirSync as
|
|
92787
|
-
import { dirname as dirname27, join as
|
|
93403
|
+
import { existsSync as existsSync22, mkdirSync as mkdirSync30, readdirSync as readdirSync17, readFileSync as readFileSync41, unlinkSync as unlinkSync8, writeFileSync as writeFileSync23 } from "node:fs";
|
|
93404
|
+
import { dirname as dirname27, join as join56 } from "node:path";
|
|
92788
93405
|
function runtimeVersionDir(bin) {
|
|
92789
93406
|
let dir = dirname27(bin);
|
|
92790
93407
|
for (let step = 0; step < MAX_ASCENT; step++) {
|
|
92791
|
-
if (existsSync22(
|
|
93408
|
+
if (existsSync22(join56(dir, PROVISIONED_MARKER))) return dir;
|
|
92792
93409
|
const parent = dirname27(dir);
|
|
92793
93410
|
if (parent === dir) return void 0;
|
|
92794
93411
|
dir = parent;
|
|
@@ -92807,11 +93424,11 @@ function leaseRuntime(bin, role) {
|
|
|
92807
93424
|
const versionDir = runtimeVersionDir(bin);
|
|
92808
93425
|
if (!versionDir) return () => {
|
|
92809
93426
|
};
|
|
92810
|
-
const path3 =
|
|
93427
|
+
const path3 = join56(versionDir, LEASES_DIR, `${process.pid}.json`);
|
|
92811
93428
|
try {
|
|
92812
|
-
|
|
93429
|
+
mkdirSync30(dirname27(path3), { recursive: true });
|
|
92813
93430
|
const lease = { pid: process.pid, role, bin, at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
92814
|
-
|
|
93431
|
+
writeFileSync23(path3, JSON.stringify(lease));
|
|
92815
93432
|
} catch {
|
|
92816
93433
|
return () => {
|
|
92817
93434
|
};
|
|
@@ -92824,20 +93441,20 @@ function leaseRuntime(bin, role) {
|
|
|
92824
93441
|
};
|
|
92825
93442
|
}
|
|
92826
93443
|
function liveRuntimeLeases(versionDir) {
|
|
92827
|
-
const dir =
|
|
93444
|
+
const dir = join56(versionDir, LEASES_DIR);
|
|
92828
93445
|
let names;
|
|
92829
93446
|
try {
|
|
92830
|
-
names =
|
|
93447
|
+
names = readdirSync17(dir);
|
|
92831
93448
|
} catch {
|
|
92832
93449
|
return [];
|
|
92833
93450
|
}
|
|
92834
93451
|
const live2 = [];
|
|
92835
93452
|
for (const name of names) {
|
|
92836
93453
|
if (!name.endsWith(".json")) continue;
|
|
92837
|
-
const path3 =
|
|
93454
|
+
const path3 = join56(dir, name);
|
|
92838
93455
|
let lease;
|
|
92839
93456
|
try {
|
|
92840
|
-
lease = JSON.parse(
|
|
93457
|
+
lease = JSON.parse(readFileSync41(path3, "utf8"));
|
|
92841
93458
|
} catch {
|
|
92842
93459
|
continue;
|
|
92843
93460
|
}
|
|
@@ -92864,29 +93481,29 @@ var init_runtime_lease = __esm({
|
|
|
92864
93481
|
});
|
|
92865
93482
|
|
|
92866
93483
|
// packages/server/src/runtimes.ts
|
|
92867
|
-
import { createHash as
|
|
93484
|
+
import { createHash as createHash23 } from "node:crypto";
|
|
92868
93485
|
import {
|
|
92869
93486
|
chmodSync as chmodSync5,
|
|
92870
93487
|
closeSync as closeSync19,
|
|
92871
93488
|
existsSync as existsSync23,
|
|
92872
|
-
mkdirSync as
|
|
93489
|
+
mkdirSync as mkdirSync31,
|
|
92873
93490
|
openSync as openSync20,
|
|
92874
|
-
readFileSync as
|
|
92875
|
-
readdirSync as
|
|
92876
|
-
renameSync as
|
|
92877
|
-
rmSync as
|
|
93491
|
+
readFileSync as readFileSync42,
|
|
93492
|
+
readdirSync as readdirSync18,
|
|
93493
|
+
renameSync as renameSync17,
|
|
93494
|
+
rmSync as rmSync17,
|
|
92878
93495
|
statSync as statSync28,
|
|
92879
|
-
writeFileSync as
|
|
93496
|
+
writeFileSync as writeFileSync24,
|
|
92880
93497
|
writeSync as writeSync3
|
|
92881
93498
|
} from "node:fs";
|
|
92882
|
-
import { dirname as dirname28, isAbsolute as isAbsolute13, join as
|
|
93499
|
+
import { dirname as dirname28, isAbsolute as isAbsolute13, join as join57, normalize, relative as relative3, sep as sep6 } from "node:path";
|
|
92883
93500
|
import { Readable as Readable2, Transform, Writable as Writable4 } from "node:stream";
|
|
92884
93501
|
import { pipeline } from "node:stream/promises";
|
|
92885
93502
|
import { createGunzip } from "node:zlib";
|
|
92886
93503
|
function runtimesRoot(env = process.env) {
|
|
92887
93504
|
const override = env[RUNTIMES_DIR_ENV];
|
|
92888
93505
|
if (override && isAbsolute13(override)) return override;
|
|
92889
|
-
return
|
|
93506
|
+
return join57(frizzRoots().cache, "runtimes");
|
|
92890
93507
|
}
|
|
92891
93508
|
function isMusl() {
|
|
92892
93509
|
if (process.platform !== "linux") return false;
|
|
@@ -92903,15 +93520,15 @@ function runtimeCoordinates(backend, platform3 = process.platform, arch = proces
|
|
|
92903
93520
|
return { pkg: "@openai/codex", packageVersion: `${CODEX_VERSION}-${platform3}-${arch}`, label: CODEX_VERSION, binary: `codex${exe2}` };
|
|
92904
93521
|
}
|
|
92905
93522
|
function provisionedBinary(backend, root, label) {
|
|
92906
|
-
const dir =
|
|
93523
|
+
const dir = join57(root, backend, label);
|
|
92907
93524
|
let marker;
|
|
92908
93525
|
try {
|
|
92909
|
-
marker = JSON.parse(
|
|
93526
|
+
marker = JSON.parse(readFileSync42(join57(dir, MARKER), "utf8"));
|
|
92910
93527
|
} catch {
|
|
92911
93528
|
return void 0;
|
|
92912
93529
|
}
|
|
92913
93530
|
if (typeof marker.binary !== "string" || marker.label !== label) return void 0;
|
|
92914
|
-
const bin =
|
|
93531
|
+
const bin = join57(dir, marker.binary);
|
|
92915
93532
|
return existsSync23(bin) ? bin : void 0;
|
|
92916
93533
|
}
|
|
92917
93534
|
function octal(buffer, offset, length) {
|
|
@@ -92926,25 +93543,25 @@ function safeEntryPath(dest, name) {
|
|
|
92926
93543
|
if (parts.length < 2) return void 0;
|
|
92927
93544
|
const rel = normalize(parts.slice(1).join(sep6));
|
|
92928
93545
|
if (isAbsolute13(rel) || rel === ".." || rel.startsWith(`..${sep6}`)) return void 0;
|
|
92929
|
-
const full =
|
|
93546
|
+
const full = join57(dest, rel);
|
|
92930
93547
|
const back = relative3(dest, full);
|
|
92931
93548
|
if (back.startsWith("..") || isAbsolute13(back)) return void 0;
|
|
92932
93549
|
return full;
|
|
92933
93550
|
}
|
|
92934
93551
|
function locateBinary(dir, backend, binary) {
|
|
92935
93552
|
if (backend === "claude") {
|
|
92936
|
-
const direct =
|
|
93553
|
+
const direct = join57(dir, binary);
|
|
92937
93554
|
return existsSync23(direct) ? direct : void 0;
|
|
92938
93555
|
}
|
|
92939
|
-
const vendor =
|
|
93556
|
+
const vendor = join57(dir, "vendor");
|
|
92940
93557
|
let triples;
|
|
92941
93558
|
try {
|
|
92942
|
-
triples =
|
|
93559
|
+
triples = readdirSync18(vendor);
|
|
92943
93560
|
} catch {
|
|
92944
93561
|
return void 0;
|
|
92945
93562
|
}
|
|
92946
93563
|
for (const triple of triples) {
|
|
92947
|
-
const candidate =
|
|
93564
|
+
const candidate = join57(vendor, triple, "bin", binary);
|
|
92948
93565
|
if (existsSync23(candidate)) return candidate;
|
|
92949
93566
|
}
|
|
92950
93567
|
return void 0;
|
|
@@ -92960,12 +93577,12 @@ async function provisionRuntime(backend, options) {
|
|
|
92960
93577
|
const registry = options.registry ?? REGISTRY;
|
|
92961
93578
|
const progress = options.onProgress ?? (() => {
|
|
92962
93579
|
});
|
|
92963
|
-
const backendDir =
|
|
92964
|
-
const finalDir =
|
|
92965
|
-
const partial =
|
|
92966
|
-
|
|
92967
|
-
|
|
92968
|
-
|
|
93580
|
+
const backendDir = join57(root, backend);
|
|
93581
|
+
const finalDir = join57(backendDir, coordinates.label);
|
|
93582
|
+
const partial = join57(backendDir, `.partial-${coordinates.label}-${process.pid}`);
|
|
93583
|
+
mkdirSync31(backendDir, { recursive: true });
|
|
93584
|
+
rmSync17(partial, { recursive: true, force: true });
|
|
93585
|
+
mkdirSync31(partial);
|
|
92969
93586
|
try {
|
|
92970
93587
|
const manifestUrl = `${registry}/${coordinates.pkg.replace("/", "%2F")}/${coordinates.packageVersion}`;
|
|
92971
93588
|
progress(`resolving ${coordinates.pkg}@${coordinates.packageVersion}`);
|
|
@@ -92978,19 +93595,19 @@ async function provisionRuntime(backend, options) {
|
|
|
92978
93595
|
const response = await fetchImpl(tarball);
|
|
92979
93596
|
if (!response.ok || !response.body) throw new Error(`tarball download answered ${response.status}`);
|
|
92980
93597
|
const total = Number(response.headers.get("content-length") ?? 0);
|
|
92981
|
-
const hash =
|
|
93598
|
+
const hash = createHash23("sha512");
|
|
92982
93599
|
let seen = 0;
|
|
92983
93600
|
let lastReport = 0;
|
|
92984
93601
|
const hasher = new Transform({
|
|
92985
|
-
transform(
|
|
92986
|
-
hash.update(
|
|
92987
|
-
seen +=
|
|
93602
|
+
transform(chunk2, _encoding, callback) {
|
|
93603
|
+
hash.update(chunk2);
|
|
93604
|
+
seen += chunk2.length;
|
|
92988
93605
|
const now = Date.now();
|
|
92989
93606
|
if (now - lastReport > 500) {
|
|
92990
93607
|
lastReport = now;
|
|
92991
93608
|
progress(total > 0 ? `downloading ${describeBytes(total)}, ${Math.min(99, Math.floor(seen / total * 100))}%` : `downloading, ${describeBytes(seen)} so far`);
|
|
92992
93609
|
}
|
|
92993
|
-
callback(null,
|
|
93610
|
+
callback(null, chunk2);
|
|
92994
93611
|
}
|
|
92995
93612
|
});
|
|
92996
93613
|
progress(total > 0 ? `downloading ${describeBytes(total)}` : "downloading");
|
|
@@ -93009,9 +93626,9 @@ async function provisionRuntime(backend, options) {
|
|
|
93009
93626
|
binary: relative3(partial, bin),
|
|
93010
93627
|
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
93011
93628
|
};
|
|
93012
|
-
|
|
93629
|
+
writeFileSync24(join57(partial, MARKER), `${JSON.stringify(marker, null, 2)}
|
|
93013
93630
|
`, "utf8");
|
|
93014
|
-
const rename3 = options.rename ??
|
|
93631
|
+
const rename3 = options.rename ?? renameSync17;
|
|
93015
93632
|
try {
|
|
93016
93633
|
for (let attempt = 1; ; attempt++) {
|
|
93017
93634
|
try {
|
|
@@ -93025,29 +93642,29 @@ async function provisionRuntime(backend, options) {
|
|
|
93025
93642
|
} catch (err) {
|
|
93026
93643
|
const theirs = provisionedBinary(backend, root, coordinates.label);
|
|
93027
93644
|
if (!theirs) throw err;
|
|
93028
|
-
|
|
93645
|
+
rmSync17(partial, { recursive: true, force: true });
|
|
93029
93646
|
return { bin: theirs, label: coordinates.label, fetched: false };
|
|
93030
93647
|
}
|
|
93031
93648
|
progress("ready");
|
|
93032
|
-
return { bin:
|
|
93649
|
+
return { bin: join57(finalDir, marker.binary), label: coordinates.label, fetched: true };
|
|
93033
93650
|
} catch (err) {
|
|
93034
|
-
|
|
93651
|
+
rmSync17(partial, { recursive: true, force: true });
|
|
93035
93652
|
throw err;
|
|
93036
93653
|
}
|
|
93037
93654
|
}
|
|
93038
93655
|
function sweepRuntimes(backend, root, keepLabel, now = Date.now(), deps = {}) {
|
|
93039
93656
|
const rm4 = deps.rm ?? defaultSweepRm;
|
|
93040
|
-
const backendDir =
|
|
93657
|
+
const backendDir = join57(root, backend);
|
|
93041
93658
|
let entries2;
|
|
93042
93659
|
try {
|
|
93043
|
-
entries2 =
|
|
93660
|
+
entries2 = readdirSync18(backendDir);
|
|
93044
93661
|
} catch {
|
|
93045
93662
|
return { removed: [], kept: [] };
|
|
93046
93663
|
}
|
|
93047
93664
|
const sweep = { removed: [], kept: [] };
|
|
93048
93665
|
for (const entry of entries2) {
|
|
93049
93666
|
if (entry === keepLabel) continue;
|
|
93050
|
-
const full =
|
|
93667
|
+
const full = join57(backendDir, entry);
|
|
93051
93668
|
if (entry.startsWith(".partial-")) {
|
|
93052
93669
|
try {
|
|
93053
93670
|
if (now - statSync28(full).mtimeMs < 24 * 60 * 60 * 1e3) continue;
|
|
@@ -93164,9 +93781,9 @@ var init_runtimes = __esm({
|
|
|
93164
93781
|
paxBuffer;
|
|
93165
93782
|
nameBuffer;
|
|
93166
93783
|
written = [];
|
|
93167
|
-
_write(
|
|
93784
|
+
_write(chunk2, _encoding, callback) {
|
|
93168
93785
|
try {
|
|
93169
|
-
this.consume(
|
|
93786
|
+
this.consume(chunk2);
|
|
93170
93787
|
callback();
|
|
93171
93788
|
} catch (err) {
|
|
93172
93789
|
callback(err instanceof Error ? err : new Error(String(err)));
|
|
@@ -93177,8 +93794,8 @@ var init_runtimes = __esm({
|
|
|
93177
93794
|
this.fd = void 0;
|
|
93178
93795
|
callback(this.remaining > 0 ? new Error("tarball ended inside a file entry") : null);
|
|
93179
93796
|
}
|
|
93180
|
-
consume(
|
|
93181
|
-
let data = this.pending.length ? Buffer.concat([this.pending,
|
|
93797
|
+
consume(chunk2) {
|
|
93798
|
+
let data = this.pending.length ? Buffer.concat([this.pending, chunk2]) : chunk2;
|
|
93182
93799
|
this.pending = Buffer.alloc(0);
|
|
93183
93800
|
for (; ; ) {
|
|
93184
93801
|
if (this.remaining > 0) {
|
|
@@ -93230,7 +93847,7 @@ var init_runtimes = __esm({
|
|
|
93230
93847
|
return;
|
|
93231
93848
|
case "5": {
|
|
93232
93849
|
const dir = safeEntryPath(this.dest, name);
|
|
93233
|
-
if (dir)
|
|
93850
|
+
if (dir) mkdirSync31(dir, { recursive: true });
|
|
93234
93851
|
return;
|
|
93235
93852
|
}
|
|
93236
93853
|
case "0":
|
|
@@ -93238,7 +93855,7 @@ var init_runtimes = __esm({
|
|
|
93238
93855
|
case "7": {
|
|
93239
93856
|
const file = safeEntryPath(this.dest, name);
|
|
93240
93857
|
if (!file) return;
|
|
93241
|
-
|
|
93858
|
+
mkdirSync31(dirname28(file), { recursive: true });
|
|
93242
93859
|
this.fd = openSync20(file, "w", octal(header, 100, 8) & 511 || 420);
|
|
93243
93860
|
this.written.push(file);
|
|
93244
93861
|
return;
|
|
@@ -93282,7 +93899,7 @@ var init_runtimes = __esm({
|
|
|
93282
93899
|
RENAME_RETRY_DELAY_MS = 200;
|
|
93283
93900
|
TRANSIENT_HANDLE_CODES = /* @__PURE__ */ new Set(["EPERM", "EBUSY", "EACCES", "ENOTEMPTY"]);
|
|
93284
93901
|
errorCode4 = (err) => err?.code;
|
|
93285
|
-
defaultSweepRm = (path3) =>
|
|
93902
|
+
defaultSweepRm = (path3) => rmSync17(path3, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
93286
93903
|
}
|
|
93287
93904
|
});
|
|
93288
93905
|
|
|
@@ -93825,18 +94442,18 @@ var init_legacy_project_db = __esm({
|
|
|
93825
94442
|
});
|
|
93826
94443
|
|
|
93827
94444
|
// packages/server/src/frizz-db.ts
|
|
93828
|
-
import { existsSync as existsSync24, mkdirSync as
|
|
93829
|
-
import { basename as basename14, dirname as dirname29, join as
|
|
94445
|
+
import { existsSync as existsSync24, mkdirSync as mkdirSync32, readdirSync as readdirSync19, renameSync as renameSync18, statSync as statSync29 } from "node:fs";
|
|
94446
|
+
import { basename as basename14, dirname as dirname29, join as join58 } from "node:path";
|
|
93830
94447
|
function frizzDatabaseLocation(options) {
|
|
93831
94448
|
if (options.stateDir !== void 0) {
|
|
93832
94449
|
const projectsDir = dirname29(options.stateDir);
|
|
93833
94450
|
if (basename14(projectsDir) === "projects") {
|
|
93834
|
-
return { path: options.path ??
|
|
94451
|
+
return { path: options.path ?? join58(dirname29(projectsDir), "ui.db"), projectsDir };
|
|
93835
94452
|
}
|
|
93836
|
-
return { path: options.path ??
|
|
94453
|
+
return { path: options.path ?? join58(options.stateDir, "ui.db"), projectsDir: void 0 };
|
|
93837
94454
|
}
|
|
93838
94455
|
const data = options.home ? frizzPaths({ home: options.home }).data : frizzRoots().data;
|
|
93839
|
-
return { path: options.path ??
|
|
94456
|
+
return { path: options.path ?? join58(data, "ui.db"), projectsDir: join58(data, "projects") };
|
|
93840
94457
|
}
|
|
93841
94458
|
function ensureFrizzSchema(db) {
|
|
93842
94459
|
db.exec(`
|
|
@@ -93855,7 +94472,7 @@ function ensureFrizzSchema(db) {
|
|
|
93855
94472
|
}
|
|
93856
94473
|
function openFrizzDatabase(options = {}) {
|
|
93857
94474
|
const { path: path3, projectsDir } = frizzDatabaseLocation(options);
|
|
93858
|
-
|
|
94475
|
+
mkdirSync32(dirname29(path3), { recursive: true });
|
|
93859
94476
|
const db = new sqlite_default(path3);
|
|
93860
94477
|
db.pragma("busy_timeout = 5000");
|
|
93861
94478
|
db.pragma("journal_mode = WAL");
|
|
@@ -93867,10 +94484,10 @@ function openFrizzDatabase(options = {}) {
|
|
|
93867
94484
|
);
|
|
93868
94485
|
for (const projectId of retiredLegacyProjectIds(projectsDir)) {
|
|
93869
94486
|
if (alreadyImported.has(projectId)) continue;
|
|
93870
|
-
const dir =
|
|
94487
|
+
const dir = join58(projectsDir, projectId);
|
|
93871
94488
|
try {
|
|
93872
|
-
|
|
93873
|
-
db.prepare("INSERT INTO imported_project (project_id, source, rows, imported_at) VALUES (?, ?, 0, ?)").run(projectId,
|
|
94489
|
+
renameSync18(join58(dir, "ui.db.imported"), join58(dir, "ui.db"));
|
|
94490
|
+
db.prepare("INSERT INTO imported_project (project_id, source, rows, imported_at) VALUES (?, ?, 0, ?)").run(projectId, join58(dir, "ui.db"), (/* @__PURE__ */ new Date()).toISOString());
|
|
93874
94491
|
alreadyImported.add(projectId);
|
|
93875
94492
|
log.info("frizz-db", `${projectId}: restored ui.db.imported to ui.db and recorded it as imported`);
|
|
93876
94493
|
} catch (error) {
|
|
@@ -93880,7 +94497,7 @@ function openFrizzDatabase(options = {}) {
|
|
|
93880
94497
|
}
|
|
93881
94498
|
for (const projectId of legacyProjectIds(projectsDir)) {
|
|
93882
94499
|
if (alreadyImported.has(projectId)) continue;
|
|
93883
|
-
const legacyPath =
|
|
94500
|
+
const legacyPath = join58(projectsDir, projectId, "ui.db");
|
|
93884
94501
|
try {
|
|
93885
94502
|
const rows = importLegacyProject(db, projectId, legacyPath);
|
|
93886
94503
|
imported.push({ projectId, rows });
|
|
@@ -93911,9 +94528,9 @@ function openFrizzDatabase(options = {}) {
|
|
|
93911
94528
|
}
|
|
93912
94529
|
function projectIdsWithFile(projectsDir, file) {
|
|
93913
94530
|
if (!existsSync24(projectsDir)) return [];
|
|
93914
|
-
return
|
|
94531
|
+
return readdirSync19(projectsDir).filter((name) => {
|
|
93915
94532
|
try {
|
|
93916
|
-
return statSync29(
|
|
94533
|
+
return statSync29(join58(projectsDir, name, file)).isFile();
|
|
93917
94534
|
} catch {
|
|
93918
94535
|
return false;
|
|
93919
94536
|
}
|
|
@@ -93923,7 +94540,7 @@ function legacyProjectIds(projectsDir) {
|
|
|
93923
94540
|
return projectIdsWithFile(projectsDir, "ui.db");
|
|
93924
94541
|
}
|
|
93925
94542
|
function retiredLegacyProjectIds(projectsDir) {
|
|
93926
|
-
return projectIdsWithFile(projectsDir, "ui.db.imported").filter((id) => !existsSync24(
|
|
94543
|
+
return projectIdsWithFile(projectsDir, "ui.db.imported").filter((id) => !existsSync24(join58(projectsDir, id, "ui.db")));
|
|
93927
94544
|
}
|
|
93928
94545
|
function tableColumns(db, schema, table) {
|
|
93929
94546
|
return db.prepare(`PRAGMA ${schema}.table_info(${table})`).all().map((c) => c.name);
|
|
@@ -94102,8 +94719,8 @@ var init_projects_changed = __esm({
|
|
|
94102
94719
|
});
|
|
94103
94720
|
|
|
94104
94721
|
// packages/server/src/project-teardown.ts
|
|
94105
|
-
import { rmSync as
|
|
94106
|
-
import { homedir as
|
|
94722
|
+
import { rmSync as rmSync18 } from "node:fs";
|
|
94723
|
+
import { homedir as homedir24 } from "node:os";
|
|
94107
94724
|
import { dirname as dirname30, resolve as resolve12 } from "node:path";
|
|
94108
94725
|
async function stopProjectWorkers(ctx) {
|
|
94109
94726
|
let stopped = 0;
|
|
@@ -94119,7 +94736,7 @@ async function stopProjectWorkers(ctx) {
|
|
|
94119
94736
|
}
|
|
94120
94737
|
return stopped;
|
|
94121
94738
|
}
|
|
94122
|
-
function deleteProjectState(projectId, home =
|
|
94739
|
+
function deleteProjectState(projectId, home = homedir24()) {
|
|
94123
94740
|
const target = projectStateDir(projectId, home);
|
|
94124
94741
|
if (!/^[\w.-]+$/u.test(projectId) || projectId === "." || projectId === "..") {
|
|
94125
94742
|
throw new Error(`Refusing to delete state for a malformed project id: ${projectId}`);
|
|
@@ -94127,7 +94744,7 @@ function deleteProjectState(projectId, home = homedir23()) {
|
|
|
94127
94744
|
if (dirname30(resolve12(target)) !== resolve12(dirname30(projectStateDir("x", home)))) {
|
|
94128
94745
|
throw new Error(`Refusing to delete ${target} \u2014 it is not a project state directory`);
|
|
94129
94746
|
}
|
|
94130
|
-
|
|
94747
|
+
rmSync18(target, { recursive: true, force: true });
|
|
94131
94748
|
}
|
|
94132
94749
|
var init_project_teardown = __esm({
|
|
94133
94750
|
"packages/server/src/project-teardown.ts"() {
|
|
@@ -94153,11 +94770,11 @@ __export(index_exports, {
|
|
|
94153
94770
|
unknownProjectPage: () => unknownProjectPage
|
|
94154
94771
|
});
|
|
94155
94772
|
import { createServer } from "node:http";
|
|
94156
|
-
import { readFileSync as
|
|
94157
|
-
import { dirname as dirname31, join as
|
|
94773
|
+
import { readFileSync as readFileSync43, existsSync as existsSync25, statSync as statSync30 } from "node:fs";
|
|
94774
|
+
import { dirname as dirname31, join as join59, resolve as resolve13, extname as extname4, posix as posix2, sep as sep7 } from "node:path";
|
|
94158
94775
|
function readServerAddressHolder(path3) {
|
|
94159
94776
|
try {
|
|
94160
|
-
const value = JSON.parse(
|
|
94777
|
+
const value = JSON.parse(readFileSync43(path3, "utf8"));
|
|
94161
94778
|
if (typeof value?.pid !== "number") return void 0;
|
|
94162
94779
|
return { pid: value.pid, port: typeof value.port === "number" ? value.port : -1 };
|
|
94163
94780
|
} catch {
|
|
@@ -94285,12 +94902,12 @@ function staticIsFresh(req, etag, mtimeMs) {
|
|
|
94285
94902
|
}
|
|
94286
94903
|
function serveStatic(distDir, req, res) {
|
|
94287
94904
|
const rel = posix2.normalize((req.url ?? "/").split("?")[0].replace(/\\/g, "/")).replace(/^(\.\.[/\\])+/, "");
|
|
94288
|
-
let file =
|
|
94289
|
-
if (!file.startsWith(distDir + sep7)) file =
|
|
94290
|
-
if (!existsSync25(file)) file =
|
|
94905
|
+
let file = join59(distDir, rel === "/" ? "index.html" : rel);
|
|
94906
|
+
if (!file.startsWith(distDir + sep7)) file = join59(distDir, "index.html");
|
|
94907
|
+
if (!existsSync25(file)) file = join59(distDir, "index.html");
|
|
94291
94908
|
try {
|
|
94292
94909
|
const stats = statSync30(file);
|
|
94293
|
-
const cacheControl = file.startsWith(
|
|
94910
|
+
const cacheControl = file.startsWith(join59(distDir, "assets") + sep7) ? STATIC_CACHE_IMMUTABLE : STATIC_CACHE_REVALIDATE;
|
|
94294
94911
|
const etag = `"${stats.size.toString(16)}-${Math.trunc(stats.mtimeMs).toString(16)}"`;
|
|
94295
94912
|
const headers = {
|
|
94296
94913
|
"content-type": MIME[extname4(file)] ?? "application/octet-stream",
|
|
@@ -94306,7 +94923,7 @@ function serveStatic(distDir, req, res) {
|
|
|
94306
94923
|
res.end();
|
|
94307
94924
|
return;
|
|
94308
94925
|
}
|
|
94309
|
-
let body =
|
|
94926
|
+
let body = readFileSync43(file);
|
|
94310
94927
|
const accept = req.headers["accept-encoding"];
|
|
94311
94928
|
const encoding = negotiateEncoding(Array.isArray(accept) ? accept.join(",") : accept);
|
|
94312
94929
|
if (encoding && shouldCompress(new Headers({ "content-type": headers["content-type"] }), body.byteLength)) {
|
|
@@ -94717,7 +95334,7 @@ async function startServer(opts = {}) {
|
|
|
94717
95334
|
}
|
|
94718
95335
|
statusPath = serverLockPathFor(ctx.project);
|
|
94719
95336
|
const webRoot = resolve13(import.meta.dirname, "..", "..", "web");
|
|
94720
|
-
const distDir = opts.webDistDir ? resolve13(opts.webDistDir) :
|
|
95337
|
+
const distDir = opts.webDistDir ? resolve13(opts.webDistDir) : join59(webRoot, "dist");
|
|
94721
95338
|
startupPhase = "Vite";
|
|
94722
95339
|
if (opts.dev) {
|
|
94723
95340
|
try {
|
|
@@ -94795,7 +95412,7 @@ async function startServer(opts = {}) {
|
|
|
94795
95412
|
if (vite) {
|
|
94796
95413
|
vite.middlewares(req, res, () => {
|
|
94797
95414
|
try {
|
|
94798
|
-
const html =
|
|
95415
|
+
const html = readFileSync43(join59(webRoot, "index.html"), "utf8");
|
|
94799
95416
|
void vite.transformIndexHtml(url, html).then((out) => {
|
|
94800
95417
|
res.writeHead(200, { "content-type": "text/html" });
|
|
94801
95418
|
res.end(out);
|
|
@@ -95006,7 +95623,7 @@ var init_index = __esm({
|
|
|
95006
95623
|
}
|
|
95007
95624
|
};
|
|
95008
95625
|
isApiUrl = (url) => url === FRIZZ_ROUTE_PREFIX || url.startsWith(`${FRIZZ_ROUTE_PREFIX}/`);
|
|
95009
|
-
serverLockPathFor = (project) =>
|
|
95626
|
+
serverLockPathFor = (project) => join59(project.stateDir, "server.lock");
|
|
95010
95627
|
MIME = {
|
|
95011
95628
|
".html": "text/html",
|
|
95012
95629
|
".js": "text/javascript",
|
|
@@ -95031,7 +95648,7 @@ init_shutdown();
|
|
|
95031
95648
|
init_logging();
|
|
95032
95649
|
init_access_codes();
|
|
95033
95650
|
import { existsSync as existsSync26 } from "node:fs";
|
|
95034
|
-
import { join as
|
|
95651
|
+
import { join as join60 } from "node:path";
|
|
95035
95652
|
|
|
95036
95653
|
// packages/server/src/session-epoch-child.ts
|
|
95037
95654
|
init_access_codes();
|
|
@@ -95351,7 +95968,7 @@ try {
|
|
|
95351
95968
|
];
|
|
95352
95969
|
if (!existsSync26(stableWebDist)) throw new Error("stable artifact launch is missing its verified web directory");
|
|
95353
95970
|
for (const [name, directory, requiredFile] of required) {
|
|
95354
|
-
if (!directory || !existsSync26(
|
|
95971
|
+
if (!directory || !existsSync26(join60(directory, requiredFile)))
|
|
95355
95972
|
throw new Error(`stable artifact launch is missing verified ${name}`);
|
|
95356
95973
|
}
|
|
95357
95974
|
}
|