bazilion 0.26.0 → 0.27.0
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/cli.js +5 -5
- package/dist/cli.js.map +1 -1
- package/dist/daemon.js +636 -234
- package/dist/daemon.js.map +1 -1
- package/dist/web/client/assets/{ChatPane-BgW59Bvn.js → ChatPane-DOV_HJg-.js} +1 -1
- package/dist/web/client/assets/{ConfigPage-BcjKer-E.js → ConfigPage-Dfu9DzFX.js} +1 -1
- package/dist/web/client/assets/{ConfirmDialog-B5BLql5H.js → ConfirmDialog-536ziJ5P.js} +1 -1
- package/dist/web/client/assets/{FieldRow-Dr1dDiQ6.js → FieldRow-z1JqCdqn.js} +1 -1
- package/dist/web/client/assets/{ResultCard-CDLhGze2.js → ResultCard-X4nTbjYY.js} +1 -1
- package/dist/web/client/assets/{SkillFindings-BPmVzjOa.js → SkillFindings-8LX6bYf_.js} +1 -1
- package/dist/web/client/assets/{SpawnDialog-CWvaYWBr.js → SpawnDialog-DoZl-yes.js} +1 -1
- package/dist/web/client/assets/{SpawnTeamModal-DxU7QH0e.js → SpawnTeamModal-C638hEoN.js} +1 -1
- package/dist/web/client/assets/{TeamForm-Bxl3s8yF.js → TeamForm-C-WzvOl4.js} +1 -1
- package/dist/web/client/assets/{TeamPolicyEditor-B-ikYl3V.js → TeamPolicyEditor-CSKBx0oK.js} +1 -1
- package/dist/web/client/assets/{UnsavedChangesGuard-CmeIPiXp.js → UnsavedChangesGuard-GC-vzw7h.js} +1 -1
- package/dist/web/client/assets/{_id-iXED17f-.js → _id-BKLynswT.js} +1 -1
- package/dist/web/client/assets/{_id-CNN1ila9.js → _id-BYM_NORr.js} +1 -1
- package/dist/web/client/assets/{_id-B-Vo1VkF.js → _id-Cxa98a9m.js} +1 -1
- package/dist/web/client/assets/{_id-CrGDqaFa.js → _id-D4hV1U1t.js} +1 -1
- package/dist/web/client/assets/{agent-actions-CmkRSxQg.js → agent-actions-CXQCoxKO.js} +1 -1
- package/dist/web/client/assets/{agents-KnMSeucP.js → agents-BxPS1_Bp.js} +1 -1
- package/dist/web/client/assets/{agents-DwDcKOif.js → agents-GozAWW-l.js} +1 -1
- package/dist/web/client/assets/{attention-CLQIHUF6.js → attention-Cz9rZcrr.js} +1 -1
- package/dist/web/client/assets/chevron-right-CPAb1zac.js +1 -0
- package/dist/web/client/assets/{config-B483VUYj.js → config-9vv9Lipb.js} +2 -2
- package/dist/web/client/assets/{inbox-DIXsxGV8.js → inbox-DHLArXxl.js} +1 -1
- package/dist/web/client/assets/{index-CKJ3uVR4.js → index-1YXquAq8.js} +2 -2
- package/dist/web/client/assets/{learning-DDTz_N6N.js → learning-PvtXm8Ne.js} +1 -1
- package/dist/web/client/assets/{login-6S3kA9Yb.js → login-DIJpNQFo.js} +1 -1
- package/dist/web/client/assets/{mcp-Dm4DfYI9.js → mcp-pKBL0xIf.js} +1 -1
- package/dist/web/client/assets/{members-CD93Kya7.js → members-DHWsgsEs.js} +1 -1
- package/dist/web/client/assets/{memory-M28_uFOH.js → memory-CEVppPyU.js} +1 -1
- package/dist/web/client/assets/plus-BaIRdB10.js +1 -0
- package/dist/web/client/assets/{policy-IKYNTvWX.js → policy-DEh4BLSw.js} +1 -1
- package/dist/web/client/assets/{results-CGNpUJ11.js → results-DgJPjEZF.js} +1 -1
- package/dist/web/client/assets/{review-BN6V988m.js → review-BbshafTQ.js} +1 -1
- package/dist/web/client/assets/{route-DUIeAVZz.js → route-Ccb8v41z.js} +1 -1
- package/dist/web/client/assets/{route-V5VM1ufA.js → route-D1d6kCEV.js} +1 -1
- package/dist/web/client/assets/{routes-CInZFLoI.js → routes-g7V4ru7T.js} +1 -1
- package/dist/web/client/assets/{services-CeB7gfY5.js → services-B2f7e5jV.js} +1 -1
- package/dist/web/client/assets/{settings-BWonPTKi.js → settings-B6elpcYm.js} +1 -1
- package/dist/web/client/assets/{skills-CgrXwmh8.js → skills-CngE7TF8.js} +1 -1
- package/dist/web/client/assets/styles-xUnZ-ep_.css +2 -0
- package/dist/web/client/assets/{teams-D-g74z8r.js → teams-BdJZXOan.js} +1 -1
- package/dist/web/client/assets/{teams-C98Ww6Xu.js → teams-c496ISsT.js} +1 -1
- package/dist/web/client/assets/{telegram-Cc8NJ4Tc.js → telegram-B_-hK6EC.js} +1 -1
- package/dist/web/client/assets/{tokens-ZTSxCsD_.js → tokens-CKz8gx4-.js} +1 -1
- package/dist/web/client/assets/{triggers-Br8Wk4Yk.js → triggers-DCEPciGW.js} +1 -1
- package/dist/web/client/assets/{welcome-C-hJvXWG.js → welcome-D-zVOLGA.js} +1 -1
- package/dist/web/client/baziu.svg +176 -7
- package/dist/web/server/assets/{_tanstack-start-manifest_v-BUFDfU9j.js → _tanstack-start-manifest_v-B8u80HjK.js} +72 -72
- package/dist/web/server/assets/{config-C0lOmAcs.js → config-BNEgu7WG.js} +5 -6
- package/dist/web/server/assets/{config-D7Z2wgbk.js → config-C1VB28se.js} +1 -1
- package/dist/web/server/assets/{router-vAv1HkV1.js → router-BI9gmY3S.js} +2 -2
- package/dist/web/server/server.js +2 -2
- package/dist/worker.js +58 -8
- package/dist/worker.js.map +1 -1
- package/package.json +4 -5
- package/dist/web/client/assets/chevron-right-DZFmP-cr.js +0 -1
- package/dist/web/client/assets/plus-xCBcVxeD.js +0 -1
- package/dist/web/client/assets/styles-d9JiV6N4.css +0 -2
package/dist/daemon.js
CHANGED
|
@@ -177,7 +177,7 @@ async function guardedFetch(opts) {
|
|
|
177
177
|
let redirects = 0;
|
|
178
178
|
let dispatcher = null;
|
|
179
179
|
let activeResponse = null;
|
|
180
|
-
const
|
|
180
|
+
const release2 = async () => {
|
|
181
181
|
if (!activeResponse?.body?.locked) await activeResponse?.body?.cancel().catch(() => {
|
|
182
182
|
});
|
|
183
183
|
if (timeoutId) clearTimeout(timeoutId);
|
|
@@ -189,11 +189,11 @@ async function guardedFetch(opts) {
|
|
|
189
189
|
try {
|
|
190
190
|
parsed = new URL(current2);
|
|
191
191
|
} catch {
|
|
192
|
-
await
|
|
192
|
+
await release2();
|
|
193
193
|
throw new Error("Invalid URL");
|
|
194
194
|
}
|
|
195
195
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
196
|
-
await
|
|
196
|
+
await release2();
|
|
197
197
|
throw new Error("Invalid URL: must be http or https");
|
|
198
198
|
}
|
|
199
199
|
const canPin = !opts.fetchImpl;
|
|
@@ -202,7 +202,7 @@ async function guardedFetch(opts) {
|
|
|
202
202
|
try {
|
|
203
203
|
addrs = await resolveAndCheck(parsed.hostname);
|
|
204
204
|
} catch (error) {
|
|
205
|
-
await
|
|
205
|
+
await release2();
|
|
206
206
|
throw error;
|
|
207
207
|
}
|
|
208
208
|
await closeDispatcher(dispatcher);
|
|
@@ -219,7 +219,7 @@ async function guardedFetch(opts) {
|
|
|
219
219
|
res = await fetcher(parsed.toString(), init);
|
|
220
220
|
activeResponse = res;
|
|
221
221
|
} catch (err) {
|
|
222
|
-
await
|
|
222
|
+
await release2();
|
|
223
223
|
throw err;
|
|
224
224
|
}
|
|
225
225
|
if (isRedirectStatus(res.status)) {
|
|
@@ -227,23 +227,23 @@ async function guardedFetch(opts) {
|
|
|
227
227
|
});
|
|
228
228
|
const loc = res.headers.get("location");
|
|
229
229
|
if (!loc) {
|
|
230
|
-
await
|
|
230
|
+
await release2();
|
|
231
231
|
throw new Error(`Redirect ${res.status} missing Location header`);
|
|
232
232
|
}
|
|
233
233
|
redirects += 1;
|
|
234
234
|
if (redirects > maxRedirects) {
|
|
235
|
-
await
|
|
235
|
+
await release2();
|
|
236
236
|
throw new Error(`Too many redirects (> ${maxRedirects})`);
|
|
237
237
|
}
|
|
238
238
|
let next;
|
|
239
239
|
try {
|
|
240
240
|
next = new URL(loc, parsed).toString();
|
|
241
241
|
} catch {
|
|
242
|
-
await
|
|
242
|
+
await release2();
|
|
243
243
|
throw new Error("Invalid redirect Location");
|
|
244
244
|
}
|
|
245
245
|
if (visited.has(next)) {
|
|
246
|
-
await
|
|
246
|
+
await release2();
|
|
247
247
|
throw new Error("Redirect loop");
|
|
248
248
|
}
|
|
249
249
|
visited.add(next);
|
|
@@ -256,7 +256,7 @@ async function guardedFetch(opts) {
|
|
|
256
256
|
current2 = next;
|
|
257
257
|
continue;
|
|
258
258
|
}
|
|
259
|
-
return { response: res, finalUrl: parsed.toString(), release };
|
|
259
|
+
return { response: res, finalUrl: parsed.toString(), release: release2 };
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
var SsrFBlockedError, BLOCKED_HOSTNAMES;
|
|
@@ -499,28 +499,28 @@ ${stderr.slice(-2e3)}` : ""}`
|
|
|
499
499
|
});
|
|
500
500
|
return conn;
|
|
501
501
|
}
|
|
502
|
-
function getMcpConnection(server3,
|
|
502
|
+
function getMcpConnection(server3, connect3) {
|
|
503
503
|
let conn = resources().mcp.get(server3.id);
|
|
504
504
|
if (!conn) {
|
|
505
|
-
conn = open(server3,
|
|
505
|
+
conn = open(server3, connect3());
|
|
506
506
|
resources().mcp.set(server3.id, conn);
|
|
507
507
|
ensureResourceReaper();
|
|
508
508
|
}
|
|
509
509
|
conn.lastUsedAt = Date.now();
|
|
510
510
|
return conn.ready;
|
|
511
511
|
}
|
|
512
|
-
function connection(server3,
|
|
513
|
-
if (!signal) return getMcpConnection(server3,
|
|
512
|
+
function connection(server3, connect3, signal) {
|
|
513
|
+
if (!signal) return getMcpConnection(server3, connect3);
|
|
514
514
|
if (signal.aborted) return Promise.reject(new McpAbortError());
|
|
515
|
-
const ready = getMcpConnection(server3,
|
|
515
|
+
const ready = getMcpConnection(server3, connect3);
|
|
516
516
|
return new Promise((resolve8, reject2) => {
|
|
517
517
|
const abort = () => reject2(new McpAbortError());
|
|
518
518
|
signal.addEventListener("abort", abort, { once: true });
|
|
519
519
|
ready.then(resolve8, reject2).finally(() => signal.removeEventListener("abort", abort));
|
|
520
520
|
});
|
|
521
521
|
}
|
|
522
|
-
async function listMcpTools(server3,
|
|
523
|
-
const conn = await connection(server3,
|
|
522
|
+
async function listMcpTools(server3, connect3, signal) {
|
|
523
|
+
const conn = await connection(server3, connect3, signal);
|
|
524
524
|
if (conn.tools && !conn.toolsStale) return conn.tools;
|
|
525
525
|
conn.toolsStale = false;
|
|
526
526
|
conn.busy++;
|
|
@@ -679,10 +679,230 @@ var init_resources = __esm({
|
|
|
679
679
|
}
|
|
680
680
|
});
|
|
681
681
|
|
|
682
|
+
// ../daemon/src/lib/browser/ssrf.ts
|
|
683
|
+
import { lookup as dnsLookup2 } from "node:dns/promises";
|
|
684
|
+
async function browserBlockReason(rawUrl, allowPrivate) {
|
|
685
|
+
if (allowPrivate) return null;
|
|
686
|
+
let url;
|
|
687
|
+
try {
|
|
688
|
+
url = new URL(rawUrl);
|
|
689
|
+
} catch {
|
|
690
|
+
return null;
|
|
691
|
+
}
|
|
692
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
693
|
+
return SAFE_NON_HTTP_SCHEMES.has(url.protocol) ? null : `blocked URL scheme: ${url.protocol}`;
|
|
694
|
+
}
|
|
695
|
+
const host3 = url.hostname;
|
|
696
|
+
if (isBlockedHostname(host3)) return `blocked hostname: ${host3}`;
|
|
697
|
+
if (isPrivateIpAddress(host3)) return `blocked private IP literal: ${host3}`;
|
|
698
|
+
try {
|
|
699
|
+
const results = await dnsLookup2(host3, { all: true });
|
|
700
|
+
for (const r of results) {
|
|
701
|
+
if (isPrivateIpAddress(r.address)) {
|
|
702
|
+
return `${host3} resolves to private IP ${r.address}`;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
} catch {
|
|
706
|
+
return null;
|
|
707
|
+
}
|
|
708
|
+
return null;
|
|
709
|
+
}
|
|
710
|
+
var SAFE_NON_HTTP_SCHEMES;
|
|
711
|
+
var init_ssrf = __esm({
|
|
712
|
+
"../daemon/src/lib/browser/ssrf.ts"() {
|
|
713
|
+
"use strict";
|
|
714
|
+
init_web_ssrf();
|
|
715
|
+
SAFE_NON_HTTP_SCHEMES = /* @__PURE__ */ new Set(["about:", "data:", "blob:"]);
|
|
716
|
+
}
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
// ../daemon/src/lib/browser/attach.ts
|
|
720
|
+
import { readFileSync as readFileSync6 } from "node:fs";
|
|
721
|
+
import { connect as connect2 } from "node:net";
|
|
722
|
+
import { homedir as homedir2 } from "node:os";
|
|
723
|
+
import { join as join10 } from "node:path";
|
|
724
|
+
function runningBrowserDirs(platform = process.platform, home = homedir2()) {
|
|
725
|
+
if (platform === "darwin") {
|
|
726
|
+
const root2 = join10(home, "Library", "Application Support");
|
|
727
|
+
return [
|
|
728
|
+
{ name: "Google Chrome", dir: join10(root2, "Google", "Chrome") },
|
|
729
|
+
{ name: "Google Chrome Beta", dir: join10(root2, "Google", "Chrome Beta") },
|
|
730
|
+
{ name: "Google Chrome Canary", dir: join10(root2, "Google", "Chrome Canary") },
|
|
731
|
+
{ name: "Chromium", dir: join10(root2, "Chromium") }
|
|
732
|
+
];
|
|
733
|
+
}
|
|
734
|
+
const root = process.env.XDG_CONFIG_HOME || join10(home, ".config");
|
|
735
|
+
return [
|
|
736
|
+
{ name: "Google Chrome", dir: join10(root, "google-chrome") },
|
|
737
|
+
{ name: "Google Chrome Beta", dir: join10(root, "google-chrome-beta") },
|
|
738
|
+
{ name: "Google Chrome Dev", dir: join10(root, "google-chrome-unstable") },
|
|
739
|
+
{ name: "Chromium", dir: join10(root, "chromium") },
|
|
740
|
+
{ name: "Chromium", dir: join10(home, "snap", "chromium", "common", "chromium") }
|
|
741
|
+
];
|
|
742
|
+
}
|
|
743
|
+
function parseDevToolsActivePort(content) {
|
|
744
|
+
const [port2, path] = content.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
745
|
+
if (!port2 || !/^\d{1,5}$/.test(port2) || Number(port2) < 1 || Number(port2) > 65535) return null;
|
|
746
|
+
if (!path?.startsWith("/")) return null;
|
|
747
|
+
return `ws://127.0.0.1:${port2}${path}`;
|
|
748
|
+
}
|
|
749
|
+
function isListening(endpoint2) {
|
|
750
|
+
return new Promise((resolve8) => {
|
|
751
|
+
const socket = connect2({ host: "127.0.0.1", port: Number(new URL(endpoint2).port) });
|
|
752
|
+
const done = (listening) => {
|
|
753
|
+
socket.destroy();
|
|
754
|
+
resolve8(listening);
|
|
755
|
+
};
|
|
756
|
+
socket.setTimeout(1e3, () => done(false));
|
|
757
|
+
socket.once("connect", () => done(true));
|
|
758
|
+
socket.once("error", () => done(false));
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
async function findRunningBrowser(dirs = runningBrowserDirs()) {
|
|
762
|
+
let denied;
|
|
763
|
+
for (const { name, dir } of dirs) {
|
|
764
|
+
let content;
|
|
765
|
+
try {
|
|
766
|
+
content = readFileSync6(join10(dir, "DevToolsActivePort"), "utf8");
|
|
767
|
+
} catch (error) {
|
|
768
|
+
const code = error.code;
|
|
769
|
+
if (code === "EPERM" || code === "EACCES") denied = dir;
|
|
770
|
+
continue;
|
|
771
|
+
}
|
|
772
|
+
const endpoint2 = parseDevToolsActivePort(content);
|
|
773
|
+
if (endpoint2 && await isListening(endpoint2)) return { name, endpoint: endpoint2 };
|
|
774
|
+
}
|
|
775
|
+
throw new Error(
|
|
776
|
+
denied ? `Cannot read ${denied}: the system denies the daemon access to the browser's folder. On macOS, allow the terminal that runs Bazilion under System Settings > Privacy & Security > Files & Folders, or set BROWSER_ATTACH_URL.` : `No running Chrome or Chromium accepts remote debugging. ${HOW_TO_ENABLE}`
|
|
777
|
+
);
|
|
778
|
+
}
|
|
779
|
+
async function openConnection(url) {
|
|
780
|
+
const target = url ? { name: url, endpoint: url } : await findRunningBrowser();
|
|
781
|
+
const { chromium } = await import("playwright");
|
|
782
|
+
let browser;
|
|
783
|
+
try {
|
|
784
|
+
browser = await chromium.connectOverCDP(target.endpoint, {
|
|
785
|
+
timeout: CONNECT_MS,
|
|
786
|
+
...url ? {} : { isLocal: true }
|
|
787
|
+
});
|
|
788
|
+
} catch (error) {
|
|
789
|
+
const detail = (error instanceof Error ? error.message : String(error)).split("\n")[0];
|
|
790
|
+
throw new Error(
|
|
791
|
+
`Could not attach to ${target.name}: ${detail}. If the browser asks whether to allow remote debugging, allow it and try again.`
|
|
792
|
+
);
|
|
793
|
+
}
|
|
794
|
+
const context = browser.contexts()[0];
|
|
795
|
+
if (!context) {
|
|
796
|
+
await browser.close().catch(() => {
|
|
797
|
+
});
|
|
798
|
+
throw new Error(`${target.name} has no browser window to work in`);
|
|
799
|
+
}
|
|
800
|
+
return { browser, context };
|
|
801
|
+
}
|
|
802
|
+
function acquire(url) {
|
|
803
|
+
const key2 = url ?? "";
|
|
804
|
+
let shared = connections.get(key2);
|
|
805
|
+
if (!shared) {
|
|
806
|
+
const created = { opened: openConnection(url), users: 0 };
|
|
807
|
+
const drop = () => {
|
|
808
|
+
if (connections.get(key2) === created) connections.delete(key2);
|
|
809
|
+
};
|
|
810
|
+
created.opened.then(({ browser }) => browser.once("disconnected", drop), drop);
|
|
811
|
+
connections.set(key2, created);
|
|
812
|
+
shared = created;
|
|
813
|
+
}
|
|
814
|
+
shared.users++;
|
|
815
|
+
return shared;
|
|
816
|
+
}
|
|
817
|
+
async function release(url, shared) {
|
|
818
|
+
if (--shared.users > 0) return;
|
|
819
|
+
if (connections.get(url ?? "") === shared) connections.delete(url ?? "");
|
|
820
|
+
await shared.opened.then(({ browser }) => browser.close()).catch(() => {
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
async function refusePrivateRequests(page) {
|
|
824
|
+
await page.route("**/*", async (route) => {
|
|
825
|
+
try {
|
|
826
|
+
const reason = await browserBlockReason(route.request().url(), false);
|
|
827
|
+
await (reason ? route.abort("blockedbyclient") : route.continue());
|
|
828
|
+
} catch {
|
|
829
|
+
}
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
async function refuseDownloads(context, page) {
|
|
833
|
+
const cdp = await context.newCDPSession(page);
|
|
834
|
+
await cdp.send("Page.setDownloadBehavior", { behavior: "deny" });
|
|
835
|
+
}
|
|
836
|
+
async function attachBrowser(opts) {
|
|
837
|
+
const shared = acquire(opts.url);
|
|
838
|
+
let connection2;
|
|
839
|
+
try {
|
|
840
|
+
connection2 = await shared.opened;
|
|
841
|
+
} catch (error) {
|
|
842
|
+
await release(opts.url, shared);
|
|
843
|
+
throw error;
|
|
844
|
+
}
|
|
845
|
+
const { browser, context } = connection2;
|
|
846
|
+
const owned = /* @__PURE__ */ new Set();
|
|
847
|
+
const own = (page) => {
|
|
848
|
+
owned.add(page);
|
|
849
|
+
page.once("close", () => owned.delete(page));
|
|
850
|
+
page.on("popup", (popup) => void own(popup));
|
|
851
|
+
page.setDefaultNavigationTimeout(3e4);
|
|
852
|
+
page.setDefaultTimeout(1e4);
|
|
853
|
+
return Promise.all([
|
|
854
|
+
opts.allowPrivate ? void 0 : refusePrivateRequests(page),
|
|
855
|
+
refuseDownloads(context, page)
|
|
856
|
+
]).catch(() => {
|
|
857
|
+
});
|
|
858
|
+
};
|
|
859
|
+
let closed;
|
|
860
|
+
return {
|
|
861
|
+
context,
|
|
862
|
+
get running() {
|
|
863
|
+
return browser.isConnected();
|
|
864
|
+
},
|
|
865
|
+
pages: () => context.pages().filter((page) => owned.has(page)),
|
|
866
|
+
owns: (page) => page !== null && owned.has(page),
|
|
867
|
+
async newPage() {
|
|
868
|
+
const page = await context.newPage();
|
|
869
|
+
await own(page);
|
|
870
|
+
return page;
|
|
871
|
+
},
|
|
872
|
+
close() {
|
|
873
|
+
closed ??= (async () => {
|
|
874
|
+
await Promise.all([...owned].map((page) => page.close().catch(() => {
|
|
875
|
+
})));
|
|
876
|
+
await release(opts.url, shared);
|
|
877
|
+
})();
|
|
878
|
+
return closed;
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
var CONNECT_MS, HOW_TO_ENABLE, connections;
|
|
883
|
+
var init_attach = __esm({
|
|
884
|
+
"../daemon/src/lib/browser/attach.ts"() {
|
|
885
|
+
"use strict";
|
|
886
|
+
init_ssrf();
|
|
887
|
+
CONNECT_MS = 6e4;
|
|
888
|
+
HOW_TO_ENABLE = "In Chrome 144 or later, open chrome://inspect/#remote-debugging and allow remote debugging; or start the browser with --remote-debugging-port and set BROWSER_ATTACH_URL.";
|
|
889
|
+
connections = /* @__PURE__ */ new Map();
|
|
890
|
+
}
|
|
891
|
+
});
|
|
892
|
+
|
|
682
893
|
// ../daemon/src/lib/browser/executable.ts
|
|
683
894
|
import { accessSync, constants, readdirSync as readdirSync3, statSync as statSync3 } from "node:fs";
|
|
684
|
-
import { homedir as
|
|
685
|
-
import { basename as basename3, isAbsolute, join as
|
|
895
|
+
import { homedir as homedir3 } from "node:os";
|
|
896
|
+
import { basename as basename3, isAbsolute, join as join11 } from "node:path";
|
|
897
|
+
function installedBrowserPaths(platform = process.platform, home = homedir3()) {
|
|
898
|
+
if (platform !== "darwin") return LINUX_INSTALLED;
|
|
899
|
+
return ["/Applications", join11(home, "Applications")].flatMap(
|
|
900
|
+
(root) => MAC_APPS.map(({ app: app2, name }) => ({
|
|
901
|
+
path: join11(root, `${app2}.app`, "Contents", "MacOS", app2),
|
|
902
|
+
name
|
|
903
|
+
}))
|
|
904
|
+
);
|
|
905
|
+
}
|
|
686
906
|
function isExecutableFile(path) {
|
|
687
907
|
try {
|
|
688
908
|
if (!statSync3(path).isFile()) return false;
|
|
@@ -692,7 +912,10 @@ function isExecutableFile(path) {
|
|
|
692
912
|
return false;
|
|
693
913
|
}
|
|
694
914
|
}
|
|
695
|
-
function
|
|
915
|
+
function playwrightCacheDir(platform = process.platform, home = homedir3()) {
|
|
916
|
+
return process.env.PLAYWRIGHT_BROWSERS_PATH || (platform === "darwin" ? join11(home, "Library", "Caches", "ms-playwright") : join11(home, ".cache", "ms-playwright"));
|
|
917
|
+
}
|
|
918
|
+
function bundledChromium(root = playwrightCacheDir()) {
|
|
696
919
|
let entries;
|
|
697
920
|
try {
|
|
698
921
|
entries = readdirSync3(root);
|
|
@@ -701,8 +924,8 @@ function bundledChromium(root = process.env.PLAYWRIGHT_BROWSERS_PATH || join10(h
|
|
|
701
924
|
}
|
|
702
925
|
const revisions = entries.filter((entry) => /^chromium-\d+$/.test(entry)).sort((a, b) => Number(b.slice("chromium-".length)) - Number(a.slice("chromium-".length)));
|
|
703
926
|
for (const revision of revisions) {
|
|
704
|
-
for (const
|
|
705
|
-
const path =
|
|
927
|
+
for (const layout of BUNDLED_LAYOUTS) {
|
|
928
|
+
const path = join11(root, revision, ...layout);
|
|
706
929
|
if (isExecutableFile(path)) return { path, name: "Chromium (Playwright)" };
|
|
707
930
|
}
|
|
708
931
|
}
|
|
@@ -715,19 +938,16 @@ function findBrowserExecutable(configuredPath) {
|
|
|
715
938
|
}
|
|
716
939
|
return { path: configuredPath, name: basename3(configuredPath) };
|
|
717
940
|
}
|
|
718
|
-
const found =
|
|
719
|
-
if (!found)
|
|
720
|
-
throw new Error(
|
|
721
|
-
"No browser found: install Chrome, Brave, Edge or Chromium, or set BROWSER_EXECUTABLE_PATH."
|
|
722
|
-
);
|
|
723
|
-
}
|
|
941
|
+
const found = installedBrowserPaths().find((candidate) => isExecutableFile(candidate.path)) ?? bundledChromium();
|
|
942
|
+
if (!found) throw new Error(NO_BROWSER_FOUND);
|
|
724
943
|
return found;
|
|
725
944
|
}
|
|
726
|
-
var
|
|
945
|
+
var NO_BROWSER_FOUND, LINUX_INSTALLED, MAC_APPS, BUNDLED_LAYOUTS;
|
|
727
946
|
var init_executable = __esm({
|
|
728
947
|
"../daemon/src/lib/browser/executable.ts"() {
|
|
729
948
|
"use strict";
|
|
730
|
-
|
|
949
|
+
NO_BROWSER_FOUND = "No browser found: install Chrome, Brave, Edge or Chromium, or set BROWSER_EXECUTABLE_PATH.";
|
|
950
|
+
LINUX_INSTALLED = [
|
|
731
951
|
{ path: "/usr/bin/google-chrome", name: "Google Chrome" },
|
|
732
952
|
{ path: "/usr/bin/google-chrome-stable", name: "Google Chrome" },
|
|
733
953
|
{ path: "/opt/google/chrome/chrome", name: "Google Chrome" },
|
|
@@ -742,19 +962,132 @@ var init_executable = __esm({
|
|
|
742
962
|
{ path: "/usr/bin/chromium-browser", name: "Chromium" },
|
|
743
963
|
{ path: "/snap/bin/chromium", name: "Chromium" }
|
|
744
964
|
];
|
|
965
|
+
MAC_APPS = [
|
|
966
|
+
{ app: "Google Chrome", name: "Google Chrome" },
|
|
967
|
+
{ app: "Brave Browser", name: "Brave" },
|
|
968
|
+
{ app: "Microsoft Edge", name: "Microsoft Edge" },
|
|
969
|
+
{ app: "Chromium", name: "Chromium" }
|
|
970
|
+
];
|
|
971
|
+
BUNDLED_LAYOUTS = [
|
|
972
|
+
["chrome-linux64", "chrome"],
|
|
973
|
+
["chrome-linux", "chrome"],
|
|
974
|
+
...["chrome-mac-arm64", "chrome-mac-x64", "chrome-mac"].flatMap(
|
|
975
|
+
(dir) => ["Google Chrome for Testing", "Chromium"].map((app2) => [
|
|
976
|
+
dir,
|
|
977
|
+
`${app2}.app`,
|
|
978
|
+
"Contents",
|
|
979
|
+
"MacOS",
|
|
980
|
+
app2
|
|
981
|
+
])
|
|
982
|
+
)
|
|
983
|
+
];
|
|
745
984
|
}
|
|
746
985
|
});
|
|
747
986
|
|
|
748
|
-
// ../daemon/src/lib/browser/
|
|
987
|
+
// ../daemon/src/lib/browser/install.ts
|
|
749
988
|
import { spawn } from "node:child_process";
|
|
750
|
-
import {
|
|
751
|
-
import { join as
|
|
989
|
+
import { createRequire } from "node:module";
|
|
990
|
+
import { dirname as dirname3, join as join12 } from "node:path";
|
|
991
|
+
function downloadAllowed() {
|
|
992
|
+
const skip2 = process.env.PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD?.trim().toLowerCase();
|
|
993
|
+
return !skip2 || skip2 === "0" || skip2 === "false";
|
|
994
|
+
}
|
|
995
|
+
function runInstaller() {
|
|
996
|
+
return new Promise((resolve8, reject2) => {
|
|
997
|
+
const cli = join12(
|
|
998
|
+
dirname3(createRequire(import.meta.url).resolve("playwright/package.json")),
|
|
999
|
+
"cli.js"
|
|
1000
|
+
);
|
|
1001
|
+
const child = spawn(
|
|
1002
|
+
process.execPath,
|
|
1003
|
+
[cli, "install", "--no-shell", "--no-progress", "chromium"],
|
|
1004
|
+
{
|
|
1005
|
+
env: Object.fromEntries(
|
|
1006
|
+
Object.entries(process.env).filter(([name]) => INSTALLER_ENV.test(name))
|
|
1007
|
+
),
|
|
1008
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
1009
|
+
timeout: DOWNLOAD_TIMEOUT_MS
|
|
1010
|
+
}
|
|
1011
|
+
);
|
|
1012
|
+
let output = "";
|
|
1013
|
+
const keep = (chunk) => {
|
|
1014
|
+
output = (output + chunk.toString("utf8")).slice(-2e3);
|
|
1015
|
+
};
|
|
1016
|
+
child.stdout.on("data", keep);
|
|
1017
|
+
child.stderr.on("data", keep);
|
|
1018
|
+
child.once("error", reject2);
|
|
1019
|
+
child.once("exit", (code, signal) => {
|
|
1020
|
+
if (code === 0) resolve8();
|
|
1021
|
+
else reject2(new Error(output.trim() || `the installer ended with ${signal ?? code}`));
|
|
1022
|
+
});
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
function downloadChromium() {
|
|
1026
|
+
if (!download) {
|
|
1027
|
+
console.log("browser: no browser is installed, downloading Chromium (once)\u2026");
|
|
1028
|
+
const run = runInstaller().then(
|
|
1029
|
+
() => {
|
|
1030
|
+
lastError = null;
|
|
1031
|
+
console.log("browser: Chromium downloaded");
|
|
1032
|
+
},
|
|
1033
|
+
(error) => {
|
|
1034
|
+
lastError = error instanceof Error ? error.message : String(error);
|
|
1035
|
+
console.error(`browser: downloading Chromium failed: ${lastError}`);
|
|
1036
|
+
throw error;
|
|
1037
|
+
}
|
|
1038
|
+
);
|
|
1039
|
+
download = run;
|
|
1040
|
+
const clear = () => {
|
|
1041
|
+
if (download === run) download = null;
|
|
1042
|
+
};
|
|
1043
|
+
run.then(clear, clear);
|
|
1044
|
+
}
|
|
1045
|
+
return download;
|
|
1046
|
+
}
|
|
1047
|
+
async function ensureBrowserExecutable(configuredPath) {
|
|
1048
|
+
try {
|
|
1049
|
+
return findBrowserExecutable(configuredPath);
|
|
1050
|
+
} catch (error) {
|
|
1051
|
+
if (configuredPath || !downloadAllowed()) throw error;
|
|
1052
|
+
}
|
|
1053
|
+
try {
|
|
1054
|
+
await downloadChromium();
|
|
1055
|
+
} catch (error) {
|
|
1056
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
1057
|
+
throw new Error(`${NO_BROWSER_FOUND} Downloading Chromium failed: ${detail}`);
|
|
1058
|
+
}
|
|
1059
|
+
return findBrowserExecutable();
|
|
1060
|
+
}
|
|
1061
|
+
function prepareBrowser(configuredPath) {
|
|
1062
|
+
ensureBrowserExecutable(configuredPath).catch(() => {
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
function browserDownloadNote() {
|
|
1066
|
+
if (download) return "No browser is installed yet: Chromium is being downloaded.";
|
|
1067
|
+
return lastError ? `${NO_BROWSER_FOUND} Downloading Chromium failed: ${lastError}` : null;
|
|
1068
|
+
}
|
|
1069
|
+
var DOWNLOAD_TIMEOUT_MS, INSTALLER_ENV, download, lastError;
|
|
1070
|
+
var init_install = __esm({
|
|
1071
|
+
"../daemon/src/lib/browser/install.ts"() {
|
|
1072
|
+
"use strict";
|
|
1073
|
+
init_executable();
|
|
1074
|
+
DOWNLOAD_TIMEOUT_MS = 15 * 6e4;
|
|
1075
|
+
INSTALLER_ENV = /^(PATH|HOME|TMPDIR|XDG_CACHE_HOME|NODE_EXTRA_CA_CERTS|PLAYWRIGHT_.*|(HTTPS?|NO|ALL)_PROXY)$/i;
|
|
1076
|
+
download = null;
|
|
1077
|
+
lastError = null;
|
|
1078
|
+
}
|
|
1079
|
+
});
|
|
1080
|
+
|
|
1081
|
+
// ../daemon/src/lib/browser/launch.ts
|
|
1082
|
+
import { execFileSync, spawn as spawn2 } from "node:child_process";
|
|
1083
|
+
import { mkdirSync as mkdirSync5, readFileSync as readFileSync7, readlinkSync, writeFileSync as writeFileSync4 } from "node:fs";
|
|
1084
|
+
import { join as join13 } from "node:path";
|
|
752
1085
|
function launchArgs(opts) {
|
|
753
1086
|
const wayland = !opts.headless && !process.env.DISPLAY && !!process.env.WAYLAND_DISPLAY;
|
|
754
1087
|
return [
|
|
755
1088
|
// Chromium picks the port and prints the endpoint on stderr.
|
|
756
1089
|
"--remote-debugging-port=0",
|
|
757
|
-
`--user-data-dir=${
|
|
1090
|
+
`--user-data-dir=${join13(opts.dir, "user-data")}`,
|
|
758
1091
|
"--no-first-run",
|
|
759
1092
|
"--no-default-browser-check",
|
|
760
1093
|
"--disable-sync",
|
|
@@ -780,7 +1113,7 @@ function launchArgs(opts) {
|
|
|
780
1113
|
function browserEnv(opts) {
|
|
781
1114
|
const env = {
|
|
782
1115
|
PATH: process.env.PATH ?? "/usr/bin:/bin",
|
|
783
|
-
HOME:
|
|
1116
|
+
HOME: join13(opts.dir, "home"),
|
|
784
1117
|
LANG: "C.UTF-8"
|
|
785
1118
|
};
|
|
786
1119
|
if (!opts.headless) {
|
|
@@ -805,13 +1138,23 @@ function isAlive(pid) {
|
|
|
805
1138
|
return false;
|
|
806
1139
|
}
|
|
807
1140
|
}
|
|
1141
|
+
function runsOnProfile(pid, userDataDir) {
|
|
1142
|
+
const flag = `--user-data-dir=${userDataDir}`;
|
|
1143
|
+
try {
|
|
1144
|
+
return readFileSync7(`/proc/${pid}/cmdline`, "utf8").split("\0").includes(flag);
|
|
1145
|
+
} catch {
|
|
1146
|
+
const command = execFileSync("ps", ["-ww", "-o", "command=", "-p", String(pid)], {
|
|
1147
|
+
encoding: "utf8"
|
|
1148
|
+
}).trim();
|
|
1149
|
+
return command.includes(`${flag} `) || command.endsWith(flag);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
808
1152
|
async function killOrphanBrowser(dir) {
|
|
809
|
-
const userDataDir =
|
|
1153
|
+
const userDataDir = join13(dir, "user-data");
|
|
810
1154
|
let pid;
|
|
811
1155
|
try {
|
|
812
|
-
pid = Number(/-(\d+)$/.exec(readlinkSync(
|
|
813
|
-
|
|
814
|
-
if (!argv.includes(`--user-data-dir=${userDataDir}`)) return;
|
|
1156
|
+
pid = Number(/-(\d+)$/.exec(readlinkSync(join13(userDataDir, "SingletonLock")))?.[1]);
|
|
1157
|
+
if (!runsOnProfile(pid, userDataDir)) return;
|
|
815
1158
|
} catch {
|
|
816
1159
|
return;
|
|
817
1160
|
}
|
|
@@ -823,11 +1166,11 @@ async function killOrphanBrowser(dir) {
|
|
|
823
1166
|
for (let i = 0; i < 40 && isAlive(pid); i++) await sleep(50);
|
|
824
1167
|
}
|
|
825
1168
|
function skipSessionRestore(userDataDir) {
|
|
826
|
-
const dir =
|
|
827
|
-
const file =
|
|
1169
|
+
const dir = join13(userDataDir, "Default");
|
|
1170
|
+
const file = join13(dir, "Preferences");
|
|
828
1171
|
let prefs = {};
|
|
829
1172
|
try {
|
|
830
|
-
const parsed = JSON.parse(
|
|
1173
|
+
const parsed = JSON.parse(readFileSync7(file, "utf8"));
|
|
831
1174
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
832
1175
|
prefs = parsed;
|
|
833
1176
|
}
|
|
@@ -847,12 +1190,12 @@ function trackGroup(pid) {
|
|
|
847
1190
|
});
|
|
848
1191
|
}
|
|
849
1192
|
async function launchBrowser(opts) {
|
|
850
|
-
const userDataDir =
|
|
1193
|
+
const userDataDir = join13(opts.dir, "user-data");
|
|
851
1194
|
mkdirSync5(userDataDir, { recursive: true, mode: 448 });
|
|
852
|
-
mkdirSync5(
|
|
1195
|
+
mkdirSync5(join13(opts.dir, "home"), { recursive: true, mode: 448 });
|
|
853
1196
|
await killOrphanBrowser(opts.dir);
|
|
854
1197
|
skipSessionRestore(userDataDir);
|
|
855
|
-
const child =
|
|
1198
|
+
const child = spawn2(opts.executablePath, launchArgs(opts), {
|
|
856
1199
|
env: browserEnv(opts),
|
|
857
1200
|
detached: true,
|
|
858
1201
|
stdio: ["ignore", "ignore", "pipe"]
|
|
@@ -938,6 +1281,9 @@ ${stderr.trim()}` : message));
|
|
|
938
1281
|
return {
|
|
939
1282
|
context,
|
|
940
1283
|
close,
|
|
1284
|
+
pages: () => context.pages(),
|
|
1285
|
+
newPage: () => context.newPage(),
|
|
1286
|
+
owns: () => true,
|
|
941
1287
|
get running() {
|
|
942
1288
|
return running();
|
|
943
1289
|
}
|
|
@@ -1014,43 +1360,6 @@ var init_snapshot = __esm({
|
|
|
1014
1360
|
}
|
|
1015
1361
|
});
|
|
1016
1362
|
|
|
1017
|
-
// ../daemon/src/lib/browser/ssrf.ts
|
|
1018
|
-
import { lookup as dnsLookup2 } from "node:dns/promises";
|
|
1019
|
-
async function browserBlockReason(rawUrl, allowPrivate) {
|
|
1020
|
-
if (allowPrivate) return null;
|
|
1021
|
-
let url;
|
|
1022
|
-
try {
|
|
1023
|
-
url = new URL(rawUrl);
|
|
1024
|
-
} catch {
|
|
1025
|
-
return null;
|
|
1026
|
-
}
|
|
1027
|
-
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
1028
|
-
return SAFE_NON_HTTP_SCHEMES.has(url.protocol) ? null : `blocked URL scheme: ${url.protocol}`;
|
|
1029
|
-
}
|
|
1030
|
-
const host3 = url.hostname;
|
|
1031
|
-
if (isBlockedHostname(host3)) return `blocked hostname: ${host3}`;
|
|
1032
|
-
if (isPrivateIpAddress(host3)) return `blocked private IP literal: ${host3}`;
|
|
1033
|
-
try {
|
|
1034
|
-
const results = await dnsLookup2(host3, { all: true });
|
|
1035
|
-
for (const r of results) {
|
|
1036
|
-
if (isPrivateIpAddress(r.address)) {
|
|
1037
|
-
return `${host3} resolves to private IP ${r.address}`;
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
} catch {
|
|
1041
|
-
return null;
|
|
1042
|
-
}
|
|
1043
|
-
return null;
|
|
1044
|
-
}
|
|
1045
|
-
var SAFE_NON_HTTP_SCHEMES;
|
|
1046
|
-
var init_ssrf = __esm({
|
|
1047
|
-
"../daemon/src/lib/browser/ssrf.ts"() {
|
|
1048
|
-
"use strict";
|
|
1049
|
-
init_web_ssrf();
|
|
1050
|
-
SAFE_NON_HTTP_SCHEMES = /* @__PURE__ */ new Set(["about:", "data:", "blob:"]);
|
|
1051
|
-
}
|
|
1052
|
-
});
|
|
1053
|
-
|
|
1054
1363
|
// ../daemon/src/lib/browser/pool.ts
|
|
1055
1364
|
import { existsSync as existsSync10, rmSync as rmSync8 } from "node:fs";
|
|
1056
1365
|
function serialize(agentId, work) {
|
|
@@ -1071,7 +1380,14 @@ function errorMessage(error) {
|
|
|
1071
1380
|
return error instanceof Error ? error.message : String(error);
|
|
1072
1381
|
}
|
|
1073
1382
|
function configKey(config) {
|
|
1074
|
-
return `${config.headless}|${config.executablePath ?? ""}|${config.allowPrivate}`;
|
|
1383
|
+
return config.attach ? `attach|${config.attachUrl ?? ""}|${config.allowPrivate}` : `${config.headless}|${config.executablePath ?? ""}|${config.allowPrivate}`;
|
|
1384
|
+
}
|
|
1385
|
+
function requestPage(request) {
|
|
1386
|
+
try {
|
|
1387
|
+
return request.frame().page();
|
|
1388
|
+
} catch {
|
|
1389
|
+
return null;
|
|
1390
|
+
}
|
|
1075
1391
|
}
|
|
1076
1392
|
function tabId(session, page) {
|
|
1077
1393
|
let id = session.tabIds.get(page);
|
|
@@ -1087,6 +1403,8 @@ function remember(log, entry) {
|
|
|
1087
1403
|
}
|
|
1088
1404
|
function startSession(agentId, key2, browser, idleMs) {
|
|
1089
1405
|
const sessions = resources().browsers;
|
|
1406
|
+
const { context } = browser;
|
|
1407
|
+
const unlisten = [];
|
|
1090
1408
|
let closed;
|
|
1091
1409
|
const session = {
|
|
1092
1410
|
agentId,
|
|
@@ -1104,6 +1422,7 @@ function startSession(agentId, key2, browser, idleMs) {
|
|
|
1104
1422
|
close() {
|
|
1105
1423
|
if (sessions.get(agentId) === session) sessions.delete(agentId);
|
|
1106
1424
|
if (!closed) {
|
|
1425
|
+
for (const off of unlisten) off();
|
|
1107
1426
|
const done = browser.close();
|
|
1108
1427
|
closed = done;
|
|
1109
1428
|
closing.set(agentId, done);
|
|
@@ -1114,24 +1433,35 @@ function startSession(agentId, key2, browser, idleMs) {
|
|
|
1114
1433
|
return closed;
|
|
1115
1434
|
}
|
|
1116
1435
|
};
|
|
1117
|
-
const
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1436
|
+
for (const page of browser.pages()) tabId(session, page);
|
|
1437
|
+
const onPage = (page) => {
|
|
1438
|
+
if (browser.owns(page)) tabId(session, page);
|
|
1439
|
+
};
|
|
1440
|
+
const onConsole = (message) => {
|
|
1441
|
+
if (!browser.owns(message.page())) return;
|
|
1123
1442
|
remember(session.console, clip(`[${message.type()}] ${message.text()}`, CONSOLE_CHARS));
|
|
1124
|
-
}
|
|
1443
|
+
};
|
|
1125
1444
|
const entries = /* @__PURE__ */ new WeakMap();
|
|
1126
|
-
|
|
1445
|
+
const onRequest2 = (request) => {
|
|
1446
|
+
if (!browser.owns(requestPage(request))) return;
|
|
1127
1447
|
const entry = { method: request.method(), url: clip(request.url()) };
|
|
1128
1448
|
entries.set(request, entry);
|
|
1129
1449
|
remember(session.network, entry);
|
|
1130
|
-
}
|
|
1131
|
-
|
|
1450
|
+
};
|
|
1451
|
+
const onResponse = (response) => {
|
|
1132
1452
|
const entry = entries.get(response.request());
|
|
1133
1453
|
if (entry) entry.status = response.status();
|
|
1134
|
-
}
|
|
1454
|
+
};
|
|
1455
|
+
context.on("page", onPage);
|
|
1456
|
+
context.on("console", onConsole);
|
|
1457
|
+
context.on("request", onRequest2);
|
|
1458
|
+
context.on("response", onResponse);
|
|
1459
|
+
unlisten.push(
|
|
1460
|
+
() => context.off("page", onPage),
|
|
1461
|
+
() => context.off("console", onConsole),
|
|
1462
|
+
() => context.off("request", onRequest2),
|
|
1463
|
+
() => context.off("response", onResponse)
|
|
1464
|
+
);
|
|
1135
1465
|
sessions.set(agentId, session);
|
|
1136
1466
|
ensureResourceReaper();
|
|
1137
1467
|
return session;
|
|
@@ -1158,9 +1488,11 @@ async function claimSession(agentId, config, paths) {
|
|
|
1158
1488
|
}
|
|
1159
1489
|
launching++;
|
|
1160
1490
|
try {
|
|
1161
|
-
const
|
|
1162
|
-
|
|
1163
|
-
|
|
1491
|
+
const browser = config.attach ? await attachBrowser({
|
|
1492
|
+
allowPrivate: config.allowPrivate,
|
|
1493
|
+
...config.attachUrl ? { url: config.attachUrl } : {}
|
|
1494
|
+
}) : await launchBrowser({
|
|
1495
|
+
executablePath: (await ensureBrowserExecutable(config.executablePath)).path,
|
|
1164
1496
|
dir: paths.browserDir(agentId),
|
|
1165
1497
|
headless: config.headless,
|
|
1166
1498
|
...config.allowPrivate ? {} : { proxyUrl: await getSsrfProxy() }
|
|
@@ -1237,13 +1569,21 @@ function browserStatus(agentId, config, paths, enabled) {
|
|
|
1237
1569
|
running: resources().browsers.get(agentId)?.browser.running ?? false,
|
|
1238
1570
|
profilePresent: existsSync10(paths.browserDir(agentId))
|
|
1239
1571
|
};
|
|
1572
|
+
const launchError = launchErrors.get(agentId);
|
|
1573
|
+
if (config.attach) {
|
|
1574
|
+
status2.browser = {
|
|
1575
|
+
name: config.attachUrl ?? "The running Chrome or Chromium",
|
|
1576
|
+
mode: "attached"
|
|
1577
|
+
};
|
|
1578
|
+
if (launchError) status2.error = launchError;
|
|
1579
|
+
return status2;
|
|
1580
|
+
}
|
|
1240
1581
|
try {
|
|
1241
1582
|
const { name } = findBrowserExecutable(config.executablePath);
|
|
1242
1583
|
status2.browser = { name, mode: config.headless ? "headless" : "headed" };
|
|
1243
|
-
const launchError = launchErrors.get(agentId);
|
|
1244
1584
|
if (launchError) status2.error = launchError;
|
|
1245
1585
|
} catch (error) {
|
|
1246
|
-
status2.error = errorMessage(error);
|
|
1586
|
+
status2.error = (config.executablePath ? null : browserDownloadNote()) ?? launchError ?? errorMessage(error);
|
|
1247
1587
|
}
|
|
1248
1588
|
return status2;
|
|
1249
1589
|
}
|
|
@@ -1272,8 +1612,8 @@ async function checkUrl(url, config) {
|
|
|
1272
1612
|
if (reason) throw new Error(`navigation blocked: ${reason}`);
|
|
1273
1613
|
}
|
|
1274
1614
|
async function activePage(session) {
|
|
1275
|
-
const pages = session.browser.
|
|
1276
|
-
const page = pages.find((p) => tabId(session, p) === session.activeTab) ?? pages[0] ?? await session.browser.
|
|
1615
|
+
const pages = session.browser.pages();
|
|
1616
|
+
const page = pages.find((p) => tabId(session, p) === session.activeTab) ?? pages[0] ?? await session.browser.newPage();
|
|
1277
1617
|
session.activeTab = tabId(session, page);
|
|
1278
1618
|
return page;
|
|
1279
1619
|
}
|
|
@@ -1426,28 +1766,28 @@ async function runAction(session, action, args, config) {
|
|
|
1426
1766
|
}
|
|
1427
1767
|
async function tabs(session, args, config) {
|
|
1428
1768
|
const op = stringArg(args, "op");
|
|
1429
|
-
const {
|
|
1769
|
+
const { browser } = session;
|
|
1430
1770
|
if (op === "list") {
|
|
1431
|
-
const lines =
|
|
1771
|
+
const lines = browser.pages().map((page2) => {
|
|
1432
1772
|
const id2 = tabId(session, page2);
|
|
1433
1773
|
return `${id2 === session.activeTab ? "*" : " "} ${id2} ${clip(page2.url())}`;
|
|
1434
1774
|
}).join("\n");
|
|
1435
|
-
return text(lines);
|
|
1775
|
+
return text(lines || "No tabs are open.");
|
|
1436
1776
|
}
|
|
1437
1777
|
if (op === "new") {
|
|
1438
|
-
if (
|
|
1778
|
+
if (browser.pages().length >= MAX_TABS) {
|
|
1439
1779
|
throw new Error(`${MAX_TABS} tabs are already open; close one first`);
|
|
1440
1780
|
}
|
|
1441
1781
|
const url = typeof args.url === "string" && args.url ? args.url : void 0;
|
|
1442
1782
|
if (url) await checkUrl(url, config);
|
|
1443
|
-
const page2 = await
|
|
1783
|
+
const page2 = await browser.newPage();
|
|
1444
1784
|
session.activeTab = tabId(session, page2);
|
|
1445
1785
|
if (!url) return text(`Opened ${session.activeTab} (about:blank).`);
|
|
1446
1786
|
await page2.goto(url, { waitUntil: "domcontentloaded" });
|
|
1447
1787
|
return text(await freshSnapshot(session, page2));
|
|
1448
1788
|
}
|
|
1449
1789
|
const id = stringArg(args, "tabId");
|
|
1450
|
-
const page =
|
|
1790
|
+
const page = browser.pages().find((p) => tabId(session, p) === id);
|
|
1451
1791
|
if (op === "select") {
|
|
1452
1792
|
if (!page) throw new Error(`No open tab "${id}"; browser_tabs {"op":"list"} lists them.`);
|
|
1453
1793
|
await page.bringToFront();
|
|
@@ -1468,7 +1808,9 @@ var init_pool2 = __esm({
|
|
|
1468
1808
|
"../daemon/src/lib/browser/pool.ts"() {
|
|
1469
1809
|
"use strict";
|
|
1470
1810
|
init_resources();
|
|
1811
|
+
init_attach();
|
|
1471
1812
|
init_executable();
|
|
1813
|
+
init_install();
|
|
1472
1814
|
init_launch();
|
|
1473
1815
|
init_proxy();
|
|
1474
1816
|
init_snapshot();
|
|
@@ -3080,6 +3422,30 @@ function isSetupComplete(db) {
|
|
|
3080
3422
|
return listAvailableModels(db).length > 0;
|
|
3081
3423
|
}
|
|
3082
3424
|
|
|
3425
|
+
// ../daemon/src/core/curatedModels.ts
|
|
3426
|
+
function replaceCuratedModels(db, provider, models) {
|
|
3427
|
+
const before = list5(db, provider);
|
|
3428
|
+
replace(db, provider, models);
|
|
3429
|
+
const after = list5(db, provider);
|
|
3430
|
+
const removed = new Set(
|
|
3431
|
+
before.filter((model) => !after.includes(model)).map((model) => `${provider}:${model}`)
|
|
3432
|
+
);
|
|
3433
|
+
const target = after[0] ? `${provider}:${after[0]}` : listAvailableModels(db)[0]?.value;
|
|
3434
|
+
const movedTemplates = [];
|
|
3435
|
+
if (target) {
|
|
3436
|
+
for (const profile of list3(db)) {
|
|
3437
|
+
if (!removed.has(profile.defaultModel)) continue;
|
|
3438
|
+
update2(db, profile.id, {
|
|
3439
|
+
name: profile.name,
|
|
3440
|
+
defaultModel: target,
|
|
3441
|
+
skillsMode: profile.skillsMode
|
|
3442
|
+
});
|
|
3443
|
+
movedTemplates.push({ id: profile.id, name: profile.name, model: target });
|
|
3444
|
+
}
|
|
3445
|
+
}
|
|
3446
|
+
return { models: after, movedTemplates };
|
|
3447
|
+
}
|
|
3448
|
+
|
|
3083
3449
|
// ../daemon/src/core/db/client.ts
|
|
3084
3450
|
import { dirname } from "node:path";
|
|
3085
3451
|
import { backup, DatabaseSync } from "node:sqlite";
|
|
@@ -3953,7 +4319,7 @@ var PROVIDERS = [
|
|
|
3953
4319
|
hint: "Hosted open-weight models \xB7 baseten.co"
|
|
3954
4320
|
}),
|
|
3955
4321
|
apiKey("moonshotai", "Moonshot AI", "MOONSHOT_API_KEY", {
|
|
3956
|
-
hint: "Kimi K2
|
|
4322
|
+
hint: "Kimi K2 and K3 models \xB7 platform.moonshot.ai"
|
|
3957
4323
|
}),
|
|
3958
4324
|
apiKey("moonshotai-cn", "Moonshot AI (CN)", "MOONSHOT_CN_API_KEY", {
|
|
3959
4325
|
hint: "Kimi models via the China endpoint \xB7 platform.moonshot.cn",
|
|
@@ -3977,6 +4343,12 @@ var PROVIDERS = [
|
|
|
3977
4343
|
apiKey("qwen-token-plan-individual", "Qwen Token Plan (Individual)", "QWEN_TOKEN_PLAN_API_KEY", {
|
|
3978
4344
|
hint: "Individual subscription models via the international endpoint"
|
|
3979
4345
|
}),
|
|
4346
|
+
apiKey(
|
|
4347
|
+
"qwen-token-plan-individual-cn",
|
|
4348
|
+
"Qwen Token Plan (Individual, CN)",
|
|
4349
|
+
"QWEN_TOKEN_PLAN_CN_API_KEY",
|
|
4350
|
+
{ hint: "Individual subscription models via the China endpoint" }
|
|
4351
|
+
),
|
|
3980
4352
|
apiKey("xiaomi", "Xiaomi MiMo", "XIAOMI_API_KEY", {
|
|
3981
4353
|
hint: "API billing endpoint \xB7 platform.xiaomimimo.com"
|
|
3982
4354
|
}),
|
|
@@ -4311,7 +4683,7 @@ var SERVICES = [
|
|
|
4311
4683
|
displayName: "Browser Automation",
|
|
4312
4684
|
category: "service",
|
|
4313
4685
|
team: "Browser",
|
|
4314
|
-
hint:
|
|
4686
|
+
hint: 'Each Agent gets its own persistent browser profile (cookies, logins), kept across turns and Team moves and excluded from backups. Reset on the Agent page, or deleting the Agent, removes it. With "Use my running browser" on, Agents work in your own Chrome or Chromium instead.',
|
|
4315
4687
|
fields: [
|
|
4316
4688
|
{
|
|
4317
4689
|
envVar: "BROWSER_ENABLED",
|
|
@@ -4325,14 +4697,28 @@ var SERVICES = [
|
|
|
4325
4697
|
kind: "config",
|
|
4326
4698
|
label: "Browser executable (optional)",
|
|
4327
4699
|
placeholder: "/usr/bin/brave-browser",
|
|
4328
|
-
description: "Absolute path to a Chromium-family browser. When unset, Bazilion uses the first installed Chrome, Brave, Edge or Chromium
|
|
4700
|
+
description: "Absolute path to a Chromium-family browser. When unset, Bazilion uses the first installed Chrome, Brave, Edge or Chromium; when none is installed it downloads Chromium once."
|
|
4701
|
+
},
|
|
4702
|
+
{
|
|
4703
|
+
envVar: "BROWSER_ATTACH",
|
|
4704
|
+
kind: "config",
|
|
4705
|
+
label: "Use my running browser",
|
|
4706
|
+
placeholder: "false",
|
|
4707
|
+
description: "true makes Agents work in the Chrome or Chromium you already have open, with your logins, in tabs of their own. Allow it first in Chrome at chrome://inspect/#remote-debugging. Default false: each Agent gets a browser of its own."
|
|
4708
|
+
},
|
|
4709
|
+
{
|
|
4710
|
+
envVar: "BROWSER_ATTACH_URL",
|
|
4711
|
+
kind: "config",
|
|
4712
|
+
label: "Running browser address (optional)",
|
|
4713
|
+
placeholder: "http://127.0.0.1:9222",
|
|
4714
|
+
description: 'DevTools address of the browser to use when "Use my running browser" is on, for one started with --remote-debugging-port. When unset, Bazilion finds the running Chrome or Chromium itself.'
|
|
4329
4715
|
},
|
|
4330
4716
|
{
|
|
4331
4717
|
envVar: "BROWSER_HEADLESS",
|
|
4332
4718
|
kind: "config",
|
|
4333
4719
|
label: "Headless",
|
|
4334
4720
|
placeholder: "true",
|
|
4335
|
-
description: "true (default) runs the browser without a window; false opens a visible browser window on the desktop the daemon runs in."
|
|
4721
|
+
description: "true (default) runs the browser without a window; false opens a visible browser window on the desktop the daemon runs in. Not used with a running browser."
|
|
4336
4722
|
},
|
|
4337
4723
|
{
|
|
4338
4724
|
envVar: "BROWSER_ALLOW_PRIVATE_NETWORK",
|
|
@@ -5902,10 +6288,13 @@ function isBrowserEnabled(env) {
|
|
|
5902
6288
|
}
|
|
5903
6289
|
function resolveBrowserConfig(env) {
|
|
5904
6290
|
const executablePath = env.BROWSER_EXECUTABLE_PATH?.trim();
|
|
6291
|
+
const attachUrl = env.BROWSER_ATTACH_URL?.trim();
|
|
5905
6292
|
return {
|
|
5906
6293
|
headless: envBool(env.BROWSER_HEADLESS, true),
|
|
5907
6294
|
...executablePath ? { executablePath } : {},
|
|
5908
6295
|
allowPrivate: envBool(env.BROWSER_ALLOW_PRIVATE_NETWORK, false),
|
|
6296
|
+
attach: envBool(env.BROWSER_ATTACH, false),
|
|
6297
|
+
...attachUrl ? { attachUrl } : {},
|
|
5909
6298
|
idleMs: envInt(env.BROWSER_IDLE_MS, 9e5),
|
|
5910
6299
|
maxSessions: envInt(env.BROWSER_MAX_SESSIONS, 4)
|
|
5911
6300
|
};
|
|
@@ -5976,8 +6365,8 @@ agentBrowserRouter.delete("/:id/browser/profile", async (c) => {
|
|
|
5976
6365
|
|
|
5977
6366
|
// ../daemon/src/routes/agent-chat.ts
|
|
5978
6367
|
import { randomUUID as randomUUID19 } from "node:crypto";
|
|
5979
|
-
import { existsSync as existsSync16, readFileSync as
|
|
5980
|
-
import { join as
|
|
6368
|
+
import { existsSync as existsSync16, readFileSync as readFileSync10 } from "node:fs";
|
|
6369
|
+
import { join as join26 } from "node:path";
|
|
5981
6370
|
|
|
5982
6371
|
// ../daemon/src/core/repos/conversations.ts
|
|
5983
6372
|
var columns = "id, agent_id AS agentId, title, created_at AS createdAt, updated_at AS updatedAt";
|
|
@@ -6169,12 +6558,12 @@ import {
|
|
|
6169
6558
|
mkdirSync as mkdirSync6,
|
|
6170
6559
|
openSync,
|
|
6171
6560
|
readdirSync as readdirSync4,
|
|
6172
|
-
readFileSync as
|
|
6561
|
+
readFileSync as readFileSync8,
|
|
6173
6562
|
realpathSync as realpathSync2,
|
|
6174
6563
|
rmSync as rmSync9,
|
|
6175
6564
|
writeFileSync as writeFileSync5
|
|
6176
6565
|
} from "node:fs";
|
|
6177
|
-
import { dirname as
|
|
6566
|
+
import { dirname as dirname4, isAbsolute as isAbsolute2, join as join14, relative, resolve as resolve4, sep as sep2 } from "node:path";
|
|
6178
6567
|
import { createStore, extractSnippet } from "@tobilu/qmd";
|
|
6179
6568
|
|
|
6180
6569
|
// ../daemon/src/lib/native-module-error.ts
|
|
@@ -6220,7 +6609,7 @@ function getStore(dir, storeFactory) {
|
|
|
6220
6609
|
if (!p) {
|
|
6221
6610
|
p = withNativeModuleErrorBoundary(
|
|
6222
6611
|
() => storeFactory({
|
|
6223
|
-
dbPath:
|
|
6612
|
+
dbPath: join14(dir, INDEX_FILENAME),
|
|
6224
6613
|
config: {
|
|
6225
6614
|
collections: {
|
|
6226
6615
|
[COLLECTION_NAME]: { path: dir, pattern: PATTERN }
|
|
@@ -6298,7 +6687,7 @@ function inspectSafePath(root, path) {
|
|
|
6298
6687
|
let current2 = root;
|
|
6299
6688
|
const components = rel.split(sep2).filter(Boolean);
|
|
6300
6689
|
for (let index = 0; index < components.length; index += 1) {
|
|
6301
|
-
current2 =
|
|
6690
|
+
current2 = join14(current2, components[index]);
|
|
6302
6691
|
const info = lstatIfPresent(current2);
|
|
6303
6692
|
if (!info) return void 0;
|
|
6304
6693
|
if (info.isSymbolicLink()) {
|
|
@@ -6312,12 +6701,12 @@ function inspectSafePath(root, path) {
|
|
|
6312
6701
|
return lstatIfPresent(path);
|
|
6313
6702
|
}
|
|
6314
6703
|
function ensureSafeParentDirectories(root, path) {
|
|
6315
|
-
const parent =
|
|
6704
|
+
const parent = dirname4(path);
|
|
6316
6705
|
assertContained(root, parent);
|
|
6317
6706
|
const rel = relative(root, parent);
|
|
6318
6707
|
let current2 = root;
|
|
6319
6708
|
for (const component2 of rel.split(sep2).filter(Boolean)) {
|
|
6320
|
-
current2 =
|
|
6709
|
+
current2 = join14(current2, component2);
|
|
6321
6710
|
let info = lstatIfPresent(current2);
|
|
6322
6711
|
if (!info) {
|
|
6323
6712
|
mkdirSync6(current2);
|
|
@@ -6341,7 +6730,7 @@ function readSafeFile(root, path) {
|
|
|
6341
6730
|
fd = openSync(path, constants2.O_RDONLY | constants2.O_NOFOLLOW);
|
|
6342
6731
|
const stats = fstatSync(fd);
|
|
6343
6732
|
if (!stats.isFile()) throw unsafeMemoryPath(path, "memory entry is not a regular file");
|
|
6344
|
-
return { content:
|
|
6733
|
+
return { content: readFileSync8(fd, "utf8"), stats };
|
|
6345
6734
|
} catch (error) {
|
|
6346
6735
|
if (error.code === "ELOOP") {
|
|
6347
6736
|
throw unsafeMemoryPath(path, "symbolic links are not allowed");
|
|
@@ -6383,7 +6772,7 @@ function writeSafeFile(root, path, content) {
|
|
|
6383
6772
|
function assertSafeTree(root, dir = root) {
|
|
6384
6773
|
assertContained(root, realpathSync2(dir));
|
|
6385
6774
|
for (const entry of readdirSync4(dir, { withFileTypes: true })) {
|
|
6386
|
-
const full =
|
|
6775
|
+
const full = join14(dir, entry.name);
|
|
6387
6776
|
const info = lstatSync(full);
|
|
6388
6777
|
if (info.isSymbolicLink()) {
|
|
6389
6778
|
throw unsafeMemoryPath(full, "symbolic links are not allowed in memory storage");
|
|
@@ -6397,7 +6786,7 @@ function assertSafeTree(root, dir = root) {
|
|
|
6397
6786
|
}
|
|
6398
6787
|
function walkMd(root, dir, prefix, out) {
|
|
6399
6788
|
for (const entry of readdirSync4(dir, { withFileTypes: true })) {
|
|
6400
|
-
const full =
|
|
6789
|
+
const full = join14(dir, entry.name);
|
|
6401
6790
|
const info = lstatSync(full);
|
|
6402
6791
|
if (info.isSymbolicLink()) {
|
|
6403
6792
|
throw unsafeMemoryPath(full, "symbolic links are not allowed in memory storage");
|
|
@@ -6504,17 +6893,17 @@ function qmdBackend(root, options = {}) {
|
|
|
6504
6893
|
// ../daemon/src/runtime/worker/runtime.ts
|
|
6505
6894
|
import { mkdirSync as mkdirSync7, mkdtempSync as mkdtempSync2, rmSync as rmSync10 } from "node:fs";
|
|
6506
6895
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
6507
|
-
import { join as
|
|
6896
|
+
import { join as join15 } from "node:path";
|
|
6508
6897
|
var REDACTED_VALUE = "[REDACTED]";
|
|
6509
6898
|
function createMinimalWorkerScratch(parentDir = tmpdir2()) {
|
|
6510
|
-
const root = mkdtempSync2(
|
|
6899
|
+
const root = mkdtempSync2(join15(parentDir, "bazilion-worker-"));
|
|
6511
6900
|
const scratch = {
|
|
6512
6901
|
root,
|
|
6513
|
-
homeDir:
|
|
6514
|
-
tempDir:
|
|
6515
|
-
piAgentDir:
|
|
6516
|
-
reviewCwd:
|
|
6517
|
-
reviewSessionDir:
|
|
6902
|
+
homeDir: join15(root, "home"),
|
|
6903
|
+
tempDir: join15(root, "tmp"),
|
|
6904
|
+
piAgentDir: join15(root, "pi"),
|
|
6905
|
+
reviewCwd: join15(root, "review-work"),
|
|
6906
|
+
reviewSessionDir: join15(root, "review-session")
|
|
6518
6907
|
};
|
|
6519
6908
|
try {
|
|
6520
6909
|
for (const path of Object.values(scratch).slice(1)) {
|
|
@@ -6733,7 +7122,7 @@ function extractResultReferences(value) {
|
|
|
6733
7122
|
|
|
6734
7123
|
// ../daemon/src/runtime/pi/session.ts
|
|
6735
7124
|
import { existsSync as existsSync14, mkdirSync as mkdirSync10, statSync as statSync6, writeFileSync as writeFileSync7 } from "node:fs";
|
|
6736
|
-
import { basename as basename5, join as
|
|
7125
|
+
import { basename as basename5, join as join21 } from "node:path";
|
|
6737
7126
|
import {
|
|
6738
7127
|
buildSessionContext,
|
|
6739
7128
|
createAgentSession,
|
|
@@ -6837,7 +7226,7 @@ async function testProviderModel(spec) {
|
|
|
6837
7226
|
|
|
6838
7227
|
// ../daemon/src/runtime/session/prompt.ts
|
|
6839
7228
|
import { existsSync as existsSync11, readdirSync as readdirSync5 } from "node:fs";
|
|
6840
|
-
import { join as
|
|
7229
|
+
import { join as join16 } from "node:path";
|
|
6841
7230
|
|
|
6842
7231
|
// ../daemon/src/runtime/safe-files.ts
|
|
6843
7232
|
import {
|
|
@@ -6847,13 +7236,13 @@ import {
|
|
|
6847
7236
|
lstatSync as lstatSync2,
|
|
6848
7237
|
mkdirSync as mkdirSync8,
|
|
6849
7238
|
openSync as openSync2,
|
|
6850
|
-
readFileSync as
|
|
7239
|
+
readFileSync as readFileSync9,
|
|
6851
7240
|
readlinkSync as readlinkSync2,
|
|
6852
7241
|
readSync,
|
|
6853
7242
|
realpathSync as realpathSync3,
|
|
6854
7243
|
statSync as statSync4
|
|
6855
7244
|
} from "node:fs";
|
|
6856
|
-
import { dirname as
|
|
7245
|
+
import { dirname as dirname5, isAbsolute as isAbsolute3, relative as relative2, resolve as resolve5, sep as sep3 } from "node:path";
|
|
6857
7246
|
var ContainedFileError = class extends Error {
|
|
6858
7247
|
reason;
|
|
6859
7248
|
constructor(reason) {
|
|
@@ -6921,7 +7310,7 @@ function ensureContainedRealDirectory(path, root, options = {}) {
|
|
|
6921
7310
|
}
|
|
6922
7311
|
} catch (error) {
|
|
6923
7312
|
if (error.code !== "ENOENT" || !options.create) throw error;
|
|
6924
|
-
const canonicalParent = realpathSync3(
|
|
7313
|
+
const canonicalParent = realpathSync3(dirname5(requested));
|
|
6925
7314
|
if (!isContained2(canonicalRoot, canonicalParent)) throw new Error("directory escapes its root");
|
|
6926
7315
|
mkdirSync8(requested, { recursive: true, mode: 448 });
|
|
6927
7316
|
const entry = lstatSync2(requested);
|
|
@@ -6941,7 +7330,7 @@ function readRegularFileNoFollow(path) {
|
|
|
6941
7330
|
try {
|
|
6942
7331
|
fd = openSync2(path, constants3.O_RDONLY | noFollowFlag());
|
|
6943
7332
|
if (!fstatSync2(fd).isFile()) throw new Error("target is not a regular file");
|
|
6944
|
-
return
|
|
7333
|
+
return readFileSync9(fd, "utf8");
|
|
6945
7334
|
} finally {
|
|
6946
7335
|
if (fd !== void 0) closeSync2(fd);
|
|
6947
7336
|
}
|
|
@@ -6955,12 +7344,15 @@ function isContained2(root, candidate) {
|
|
|
6955
7344
|
}
|
|
6956
7345
|
|
|
6957
7346
|
// ../daemon/src/runtime/session/browser-guide.ts
|
|
6958
|
-
function browserGuideSection() {
|
|
7347
|
+
function browserGuideSection(attached = false) {
|
|
6959
7348
|
return [
|
|
6960
7349
|
"# Browser",
|
|
6961
7350
|
"",
|
|
6962
|
-
"You have a browser of your own (`browser_*` tools). Its cookies and logins persist across turns.",
|
|
7351
|
+
attached ? "The `browser_*` tools work in the user's own running browser, signed in to their accounts. You see and drive only the tabs you open; their other tabs are not yours to see." : "You have a browser of your own (`browser_*` tools). Its cookies and logins persist across turns.",
|
|
6963
7352
|
"",
|
|
7353
|
+
...attached ? [
|
|
7354
|
+
"- On every site the user is signed in to, you act as them. Post, send, buy, delete or change settings only when the user asked for exactly that; otherwise ask first."
|
|
7355
|
+
] : [],
|
|
6964
7356
|
"- Read a page with `browser_snapshot`: an accessibility tree whose elements carry refs like `[ref=e5]`. Use `browser_take_screenshot` only when the visual layout matters.",
|
|
6965
7357
|
"- Act with refs from the latest snapshot. Every action returns a fresh snapshot; take the next refs from it.",
|
|
6966
7358
|
"- A link that opens a new tab does not switch to it: list the tabs with `browser_tabs` and select the new one.",
|
|
@@ -6980,9 +7372,9 @@ function loadPromptSkills(skillsDir, attachedNames) {
|
|
|
6980
7372
|
const discovered = readdirSync5(skillsDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && attached.has(entry.name)).sort((a, b) => a.name.localeCompare(b.name));
|
|
6981
7373
|
const loaded = [];
|
|
6982
7374
|
for (const entry of discovered) {
|
|
6983
|
-
const hostDir =
|
|
7375
|
+
const hostDir = join16(skillsDir, entry.name);
|
|
6984
7376
|
try {
|
|
6985
|
-
const parsed = parseSkillContent(readRegularFileNoFollow(
|
|
7377
|
+
const parsed = parseSkillContent(readRegularFileNoFollow(join16(hostDir, "SKILL.md")));
|
|
6986
7378
|
const safeLabel = entry.name.replace(/[^A-Za-z0-9._-]/g, "_") || "skill";
|
|
6987
7379
|
loaded.push({
|
|
6988
7380
|
name: entry.name,
|
|
@@ -7001,7 +7393,7 @@ function loadHomeDocuments(agentDir2) {
|
|
|
7001
7393
|
const root = resolveRealDirectory(agentDir2);
|
|
7002
7394
|
const read2 = (file) => {
|
|
7003
7395
|
try {
|
|
7004
|
-
return readRegularFileNoFollow(
|
|
7396
|
+
return readRegularFileNoFollow(join16(root, file));
|
|
7005
7397
|
} catch (error) {
|
|
7006
7398
|
if (error.code === "ENOENT") return null;
|
|
7007
7399
|
throw new Error(`private Agent home is unsafe at ${file}`);
|
|
@@ -7106,7 +7498,10 @@ ${contextBlocks.join("\n\n")}`
|
|
|
7106
7498
|
});
|
|
7107
7499
|
}
|
|
7108
7500
|
if (options.browserGuide) {
|
|
7109
|
-
parts.push({
|
|
7501
|
+
parts.push({
|
|
7502
|
+
id: "browser-guide",
|
|
7503
|
+
text: browserGuideSection(options.browserGuide === "attached")
|
|
7504
|
+
});
|
|
7110
7505
|
}
|
|
7111
7506
|
const teamLines = [
|
|
7112
7507
|
"# Team",
|
|
@@ -7167,7 +7562,7 @@ function boundReviewedLessons(lessons, maxCharacters = 8e3) {
|
|
|
7167
7562
|
}
|
|
7168
7563
|
|
|
7169
7564
|
// ../daemon/src/runtime/shell/docker.ts
|
|
7170
|
-
import { spawn as
|
|
7565
|
+
import { spawn as spawn3 } from "node:child_process";
|
|
7171
7566
|
import { createHash as createHash3, randomUUID as randomUUID13 } from "node:crypto";
|
|
7172
7567
|
var CONTAINER_WORKSPACE = "/workspace";
|
|
7173
7568
|
var DOCKER_CALL_TIMEOUT_MS = 5e3;
|
|
@@ -7234,7 +7629,7 @@ function createDockerBashOperations(sandbox) {
|
|
|
7234
7629
|
const name = `${current2.containerPrefix}${randomUUID13().replaceAll("-", "").slice(0, 12)}`;
|
|
7235
7630
|
const args = dockerRunArgs(current2, name, command);
|
|
7236
7631
|
return new Promise((resolve8, reject2) => {
|
|
7237
|
-
const child =
|
|
7632
|
+
const child = spawn3("docker", args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
7238
7633
|
let stopped;
|
|
7239
7634
|
let settled = false;
|
|
7240
7635
|
const stop = (reason) => {
|
|
@@ -7303,7 +7698,7 @@ async function removeContainers(names) {
|
|
|
7303
7698
|
}
|
|
7304
7699
|
function docker(args) {
|
|
7305
7700
|
return new Promise((resolve8, reject2) => {
|
|
7306
|
-
const child =
|
|
7701
|
+
const child = spawn3("docker", args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
7307
7702
|
let stdout = "";
|
|
7308
7703
|
let stderr = "";
|
|
7309
7704
|
const timer = setTimeout(() => {
|
|
@@ -7333,7 +7728,7 @@ function dockerError(error) {
|
|
|
7333
7728
|
|
|
7334
7729
|
// ../daemon/src/runtime/shell/tooling.ts
|
|
7335
7730
|
import { existsSync as existsSync12, lstatSync as lstatSync3, mkdirSync as mkdirSync9, realpathSync as realpathSync4, statSync as statSync5 } from "node:fs";
|
|
7336
|
-
import { dirname as
|
|
7731
|
+
import { dirname as dirname6, isAbsolute as isAbsolute4, join as join17, relative as relative3, sep as sep4 } from "node:path";
|
|
7337
7732
|
import {
|
|
7338
7733
|
createBashToolDefinition,
|
|
7339
7734
|
createLocalBashOperations,
|
|
@@ -7655,18 +8050,18 @@ function createSessionShellTools(cwd, env, options = {}) {
|
|
|
7655
8050
|
};
|
|
7656
8051
|
const sandbox = () => {
|
|
7657
8052
|
const workspace = realpathSync4(cwd);
|
|
7658
|
-
if (turn.cwd !== "." && !statSync5(
|
|
8053
|
+
if (turn.cwd !== "." && !statSync5(join17(workspace, turn.cwd), { throwIfNoEntry: false })?.isDirectory())
|
|
7659
8054
|
throw new Error(`Working directory does not exist: ${containerWorkdir(turn.cwd)}`);
|
|
7660
|
-
mkdirSync9(
|
|
8055
|
+
mkdirSync9(join17(workspace, "memory"), { recursive: true });
|
|
7661
8056
|
return {
|
|
7662
8057
|
image: turn.image,
|
|
7663
8058
|
workspace,
|
|
7664
8059
|
workdir: containerWorkdir(turn.cwd),
|
|
7665
8060
|
readOnlyMounts: [
|
|
7666
|
-
readOnlyMount(
|
|
7667
|
-
...options.inputsDir && existsSync12(options.inputsDir) ? [readOnlyMount(options.inputsDir, SANDBOX_INPUTS_DIR,
|
|
8061
|
+
readOnlyMount(join17(workspace, "memory"), SANDBOX_MEMORY_DIR, workspace),
|
|
8062
|
+
...options.inputsDir && existsSync12(options.inputsDir) ? [readOnlyMount(options.inputsDir, SANDBOX_INPUTS_DIR, dirname6(options.inputsDir))] : [],
|
|
7668
8063
|
...(options.skillMounts ?? []).map(
|
|
7669
|
-
(mount) => readOnlyMount(mount.source, mount.target,
|
|
8064
|
+
(mount) => readOnlyMount(mount.source, mount.target, dirname6(mount.source))
|
|
7670
8065
|
)
|
|
7671
8066
|
],
|
|
7672
8067
|
containerPrefix: turn.containerPrefix
|
|
@@ -7699,13 +8094,13 @@ function readOnlyMount(source, target, root) {
|
|
|
7699
8094
|
|
|
7700
8095
|
// ../daemon/src/runtime/pi/session-file.ts
|
|
7701
8096
|
import { closeSync as closeSync3, constants as constants4, fstatSync as fstatSync3, openSync as openSync3, readSync as readSync2 } from "node:fs";
|
|
7702
|
-
import { join as
|
|
8097
|
+
import { join as join18 } from "node:path";
|
|
7703
8098
|
var MAX_SESSION_BYTES = 64 * 1024 * 1024;
|
|
7704
8099
|
var MAX_HEADER_BYTES = 64 * 1024;
|
|
7705
8100
|
function readStart(directory, id, limit) {
|
|
7706
8101
|
if (!/^[0-9a-f-]{36}$/i.test(id)) throw new Error("Invalid conversation id");
|
|
7707
8102
|
const fd = openSync3(
|
|
7708
|
-
|
|
8103
|
+
join18(directory, `${id}.jsonl`),
|
|
7709
8104
|
constants4.O_RDONLY | constants4.O_NOFOLLOW | constants4.O_NONBLOCK
|
|
7710
8105
|
);
|
|
7711
8106
|
try {
|
|
@@ -7783,7 +8178,7 @@ function askUserTool(ask) {
|
|
|
7783
8178
|
|
|
7784
8179
|
// ../daemon/src/runtime/tools/bootstrap.ts
|
|
7785
8180
|
import { existsSync as existsSync13, rmSync as rmSync11 } from "node:fs";
|
|
7786
|
-
import { join as
|
|
8181
|
+
import { join as join19 } from "node:path";
|
|
7787
8182
|
function bootstrapTool(agentDir2) {
|
|
7788
8183
|
return {
|
|
7789
8184
|
def: {
|
|
@@ -7792,7 +8187,7 @@ function bootstrapTool(agentDir2) {
|
|
|
7792
8187
|
parameters: { type: "object", properties: {} }
|
|
7793
8188
|
},
|
|
7794
8189
|
async invoke() {
|
|
7795
|
-
const path =
|
|
8190
|
+
const path = join19(agentDir2, "BOOTSTRAP.md");
|
|
7796
8191
|
if (existsSync13(path)) {
|
|
7797
8192
|
rmSync11(path);
|
|
7798
8193
|
return "BOOTSTRAP.md removed. Bootstrap is complete.";
|
|
@@ -7992,7 +8387,7 @@ import {
|
|
|
7992
8387
|
readdirSync as readdirSync6,
|
|
7993
8388
|
writeFileSync as writeFileSync6
|
|
7994
8389
|
} from "node:fs";
|
|
7995
|
-
import { join as
|
|
8390
|
+
import { join as join20 } from "node:path";
|
|
7996
8391
|
var HOME_FILES_READABLE = [
|
|
7997
8392
|
"IDENTITY.md",
|
|
7998
8393
|
"SOUL.md",
|
|
@@ -8113,7 +8508,7 @@ function resolvePrivateHomeRoot(agentDir2) {
|
|
|
8113
8508
|
}
|
|
8114
8509
|
}
|
|
8115
8510
|
function privateHomeFile(homeRoot, file) {
|
|
8116
|
-
return
|
|
8511
|
+
return join20(homeRoot, file);
|
|
8117
8512
|
}
|
|
8118
8513
|
function rejectSymlinkOrNonFile(path) {
|
|
8119
8514
|
const entry = lstatSync4(path);
|
|
@@ -8896,7 +9291,7 @@ function turnSurface(opts) {
|
|
|
8896
9291
|
const shellTools = createSessionShellTools(cwd, env, {
|
|
8897
9292
|
docker: opts.docker,
|
|
8898
9293
|
containerPrefix: homeContainerPrefix(paths.home),
|
|
8899
|
-
inputsDir:
|
|
9294
|
+
inputsDir: join21(agent.agent.dir, "uploads"),
|
|
8900
9295
|
skillMounts: promptSkills.map((skill) => ({ source: skill.hostDir, target: skill.sandboxDir })),
|
|
8901
9296
|
approvalHost: opts.bashApprovalHost
|
|
8902
9297
|
});
|
|
@@ -8919,7 +9314,7 @@ function turnSurface(opts) {
|
|
|
8919
9314
|
skills: promptSkills,
|
|
8920
9315
|
sandboxMode: shellTools.config.sandboxMode,
|
|
8921
9316
|
// The guides ride along exactly when their tools are admitted.
|
|
8922
|
-
...opts.browserHost ? { browserGuide: true } : {},
|
|
9317
|
+
...opts.browserHost ? { browserGuide: resolveBrowserConfig(env).attach ? "attached" : true } : {},
|
|
8923
9318
|
...opts.webSearchHost ? { searchGuide: true } : {}
|
|
8924
9319
|
};
|
|
8925
9320
|
return {
|
|
@@ -8937,7 +9332,7 @@ async function createBazilionSession(opts) {
|
|
|
8937
9332
|
const { agent, paths } = opts;
|
|
8938
9333
|
const { providerName, modelId } = parseModelString(agent.model);
|
|
8939
9334
|
if (!existsSync14(agent.team.path)) mkdirSync10(agent.team.path, { recursive: true });
|
|
8940
|
-
mkdirSync10(
|
|
9335
|
+
mkdirSync10(join21(paths.agentDir(agent.agent.id), "sessions"), { recursive: true });
|
|
8941
9336
|
const sessionManager = openConversation(agent, paths, opts.conversation);
|
|
8942
9337
|
const turn = turnSurface(opts);
|
|
8943
9338
|
return openPiSession({
|
|
@@ -8949,7 +9344,7 @@ async function createBazilionSession(opts) {
|
|
|
8949
9344
|
},
|
|
8950
9345
|
reasoningLevel: agent.reasoningLevel,
|
|
8951
9346
|
cwd: turn.modelCwd,
|
|
8952
|
-
piAgentDir:
|
|
9347
|
+
piAgentDir: join21(paths.home, "pi"),
|
|
8953
9348
|
sessionManager,
|
|
8954
9349
|
appendSystemPrompt: buildSystemPrompt(agent, turn.promptOptions),
|
|
8955
9350
|
agentsFiles: (opts.repositoryInstructions ?? []).map((file) => ({
|
|
@@ -9007,7 +9402,7 @@ function toPiThinkingLevel(level) {
|
|
|
9007
9402
|
}
|
|
9008
9403
|
}
|
|
9009
9404
|
function openConversation(agent, paths, target) {
|
|
9010
|
-
const sessionDir =
|
|
9405
|
+
const sessionDir = join21(paths.agentDir(agent.agent.id), "sessions");
|
|
9011
9406
|
return SessionManager.open(
|
|
9012
9407
|
explicitConversationFile(sessionDir, target),
|
|
9013
9408
|
sessionDir,
|
|
@@ -9016,13 +9411,13 @@ function openConversation(agent, paths, target) {
|
|
|
9016
9411
|
}
|
|
9017
9412
|
function loadInitialMessages(agent, paths, target) {
|
|
9018
9413
|
if (!target) return [];
|
|
9019
|
-
const entries = readSessionFile(
|
|
9414
|
+
const entries = readSessionFile(join21(paths.agentDir(agent.agent.id), "sessions"), target.id);
|
|
9020
9415
|
return buildSessionContext(entries.filter((entry) => entry.type !== "session")).messages;
|
|
9021
9416
|
}
|
|
9022
9417
|
function loadSessionMessages(agent, paths, sessionId) {
|
|
9023
9418
|
if (!/^[A-Za-z0-9._-]+$/.test(sessionId)) return [];
|
|
9024
|
-
const sessionDir =
|
|
9025
|
-
const file =
|
|
9419
|
+
const sessionDir = join21(paths.agentDir(agent.agent.id), "sessions");
|
|
9420
|
+
const file = join21(sessionDir, `${sessionId}.jsonl`);
|
|
9026
9421
|
if (!existsSync14(file) || !existsSync14(agent.team.path)) return [];
|
|
9027
9422
|
try {
|
|
9028
9423
|
return SessionManager.open(file, sessionDir).buildSessionContext().messages;
|
|
@@ -9031,7 +9426,7 @@ function loadSessionMessages(agent, paths, sessionId) {
|
|
|
9031
9426
|
}
|
|
9032
9427
|
}
|
|
9033
9428
|
function loadSessionHead(agent, paths, target) {
|
|
9034
|
-
const sessionDir =
|
|
9429
|
+
const sessionDir = join21(paths.agentDir(agent.agent.id), "sessions");
|
|
9035
9430
|
if (!existsSync14(sessionDir)) return { file: null, size: 0 };
|
|
9036
9431
|
const recent = target ? explicitConversationFile(sessionDir, target) : null;
|
|
9037
9432
|
if (!recent) return { file: null, size: 0 };
|
|
@@ -9045,7 +9440,7 @@ function loadSessionHead(agent, paths, target) {
|
|
|
9045
9440
|
function explicitConversationFile(directory, target) {
|
|
9046
9441
|
if (!target) throw new Error("Explicit conversation target is required");
|
|
9047
9442
|
readSessionHeader(directory, target.id);
|
|
9048
|
-
return
|
|
9443
|
+
return join21(directory, `${target.id}.jsonl`);
|
|
9049
9444
|
}
|
|
9050
9445
|
|
|
9051
9446
|
// ../daemon/src/runtime/providers/catalog.ts
|
|
@@ -9075,7 +9470,7 @@ async function listCatalogModels(providerName, env = process.env, signal) {
|
|
|
9075
9470
|
}
|
|
9076
9471
|
|
|
9077
9472
|
// ../daemon/src/runtime/worker/spawn.ts
|
|
9078
|
-
import { spawn as
|
|
9473
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
9079
9474
|
import { existsSync as existsSync15 } from "node:fs";
|
|
9080
9475
|
import { isAbsolute as isAbsolute6 } from "node:path";
|
|
9081
9476
|
import { fileURLToPath } from "node:url";
|
|
@@ -9162,7 +9557,7 @@ async function* runWorker(run) {
|
|
|
9162
9557
|
if (!isAbsolute6(workerEntry)) throw new Error("worker entry path must be absolute");
|
|
9163
9558
|
const serializedInput = JSON.stringify(run.input);
|
|
9164
9559
|
opts.signal?.throwIfAborted();
|
|
9165
|
-
const child =
|
|
9560
|
+
const child = spawn4(process.execPath, workerSpawnArgs(workerEntry), {
|
|
9166
9561
|
env: run.env,
|
|
9167
9562
|
detached: true,
|
|
9168
9563
|
stdio: ["pipe", "pipe", "pipe", "ipc"]
|
|
@@ -10871,7 +11266,7 @@ function mirrorTypingStop(agentId) {
|
|
|
10871
11266
|
// ../daemon/src/lib/attachments.ts
|
|
10872
11267
|
import { randomUUID as randomUUID17 } from "node:crypto";
|
|
10873
11268
|
import { closeSync as closeSync5, constants as constants6, fstatSync as fstatSync5, openSync as openSync5, writeFileSync as writeFileSync8 } from "node:fs";
|
|
10874
|
-
import { join as
|
|
11269
|
+
import { join as join22, posix as posix2 } from "node:path";
|
|
10875
11270
|
var MAX_FILE_BYTES = 25 * 1024 * 1024;
|
|
10876
11271
|
function safeName(name) {
|
|
10877
11272
|
const base = name.split(/[\\/]/).pop() ?? "file";
|
|
@@ -10883,7 +11278,7 @@ function fmtBytes(n) {
|
|
|
10883
11278
|
return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
10884
11279
|
}
|
|
10885
11280
|
function prepareInputFilesDirectory(agentDir2) {
|
|
10886
|
-
return ensureContainedRealDirectory(
|
|
11281
|
+
return ensureContainedRealDirectory(join22(agentDir2, "uploads"), agentDir2, { create: true });
|
|
10887
11282
|
}
|
|
10888
11283
|
function saveInputFiles(agentDir2, files, options = {}) {
|
|
10889
11284
|
if (!files || files.length === 0) return "";
|
|
@@ -10897,7 +11292,7 @@ function saveInputFiles(agentDir2, files, options = {}) {
|
|
|
10897
11292
|
continue;
|
|
10898
11293
|
}
|
|
10899
11294
|
const filename = `${randomUUID17().slice(0, 8)}-${safeName(label)}`;
|
|
10900
|
-
const path =
|
|
11295
|
+
const path = join22(dir, filename);
|
|
10901
11296
|
let fd;
|
|
10902
11297
|
try {
|
|
10903
11298
|
fd = openSync5(
|
|
@@ -10920,7 +11315,7 @@ function saveInputFiles(agentDir2, files, options = {}) {
|
|
|
10920
11315
|
|
|
10921
11316
|
// ../daemon/src/lib/coding-environment.ts
|
|
10922
11317
|
import { lstatSync as lstatSync5 } from "node:fs";
|
|
10923
|
-
import { join as
|
|
11318
|
+
import { join as join23 } from "node:path";
|
|
10924
11319
|
|
|
10925
11320
|
// ../daemon/src/core/coding-environment/config.ts
|
|
10926
11321
|
var CodingEnvironmentValidationError = class extends DomainError {
|
|
@@ -10977,7 +11372,7 @@ function setTeamCodingEnvironment(db, team, input, env = process.env) {
|
|
|
10977
11372
|
const environment = validateCodingEnvironment(input);
|
|
10978
11373
|
let path = team.path;
|
|
10979
11374
|
for (const part of environment.cwd === "." ? [] : environment.cwd.split("/")) {
|
|
10980
|
-
path =
|
|
11375
|
+
path = join23(path, part);
|
|
10981
11376
|
if (!lstatSync5(path, { throwIfNoEntry: false })?.isDirectory())
|
|
10982
11377
|
throw new CodingEnvironmentValidationError(
|
|
10983
11378
|
"The directory must be an existing directory inside the Team"
|
|
@@ -10998,17 +11393,17 @@ function dockerTurn(db, paths, agent, env) {
|
|
|
10998
11393
|
// ../daemon/src/lib/conversation-target.ts
|
|
10999
11394
|
import { randomUUID as randomUUID18 } from "node:crypto";
|
|
11000
11395
|
import { writeFileSync as writeFileSync9 } from "node:fs";
|
|
11001
|
-
import { join as
|
|
11396
|
+
import { join as join24 } from "node:path";
|
|
11002
11397
|
import { SessionManager as SessionManager2 } from "@earendil-works/pi-coding-agent";
|
|
11003
11398
|
function sessionsDir(paths, agentId) {
|
|
11004
|
-
return
|
|
11399
|
+
return join24(paths.agentDir(agentId), "sessions");
|
|
11005
11400
|
}
|
|
11006
11401
|
function startConversation(db, paths, agentId, title) {
|
|
11007
11402
|
const agent = resolveAgent(db, paths, agentId);
|
|
11008
11403
|
if (title !== void 0) validTitle(title);
|
|
11009
11404
|
const id = randomUUID18();
|
|
11010
11405
|
const header = SessionManager2.inMemory(agent.team.path, { id }).getHeader();
|
|
11011
|
-
writeFileSync9(
|
|
11406
|
+
writeFileSync9(join24(sessionsDir(paths, agentId), `${id}.jsonl`), `${JSON.stringify(header)}
|
|
11012
11407
|
`, {
|
|
11013
11408
|
flag: "wx",
|
|
11014
11409
|
mode: 384
|
|
@@ -11028,7 +11423,7 @@ function selectedConversationTarget(db, agentId) {
|
|
|
11028
11423
|
|
|
11029
11424
|
// ../daemon/src/lib/repository-instructions.ts
|
|
11030
11425
|
import { realpathSync as realpathSync6 } from "node:fs";
|
|
11031
|
-
import { join as
|
|
11426
|
+
import { join as join25 } from "node:path";
|
|
11032
11427
|
var MAX_FILE_BYTES2 = 128 * 1024;
|
|
11033
11428
|
var SKIPPED = {
|
|
11034
11429
|
outside: "it resolves outside the Team workspace",
|
|
@@ -11048,7 +11443,7 @@ function loadRepositoryInstructions(root, cwd = ".") {
|
|
|
11048
11443
|
for (let depth = 0; depth <= parts.length; depth++) {
|
|
11049
11444
|
const path = [...parts.slice(0, depth), "AGENTS.md"].join("/");
|
|
11050
11445
|
try {
|
|
11051
|
-
const content = readContainedFile(
|
|
11446
|
+
const content = readContainedFile(join25(realRoot, path), realRoot, MAX_FILE_BYTES2);
|
|
11052
11447
|
instructions.push({ path, content: content.toString("utf8") });
|
|
11053
11448
|
} catch (error) {
|
|
11054
11449
|
if (error instanceof ContainedFileError) {
|
|
@@ -11686,7 +12081,7 @@ agentChatRouter.post("/:id/chat/compact", async (c) => {
|
|
|
11686
12081
|
const { db, paths, authToken } = getCtx();
|
|
11687
12082
|
const resolved = resolveAgent(db, paths, id);
|
|
11688
12083
|
assertProviderReady(db, authToken, resolved.model);
|
|
11689
|
-
const memory = qmdBackend(
|
|
12084
|
+
const memory = qmdBackend(join26(resolved.team.path, "memory"));
|
|
11690
12085
|
await memory.init();
|
|
11691
12086
|
const handle12 = await createBazilionSession({
|
|
11692
12087
|
agent: resolved,
|
|
@@ -11744,9 +12139,9 @@ agentChatRouter.get(
|
|
|
11744
12139
|
const env = mergeSecretsIntoEnv(db, authToken);
|
|
11745
12140
|
const files = [];
|
|
11746
12141
|
for (const file of CONTEXT_FILE_ORDER2) {
|
|
11747
|
-
const path =
|
|
12142
|
+
const path = join26(resolved.agent.dir, file);
|
|
11748
12143
|
if (!existsSync16(path)) continue;
|
|
11749
|
-
const content =
|
|
12144
|
+
const content = readFileSync10(path, "utf8").trimEnd();
|
|
11750
12145
|
if (!content) continue;
|
|
11751
12146
|
const chars = content.length + file.length + 6;
|
|
11752
12147
|
files.push({ name: file, chars, tokens: estimateTokens2(chars) });
|
|
@@ -11759,7 +12154,7 @@ agentChatRouter.get(
|
|
|
11759
12154
|
agent: resolved,
|
|
11760
12155
|
paths,
|
|
11761
12156
|
env,
|
|
11762
|
-
memory: qmdBackend(
|
|
12157
|
+
memory: qmdBackend(join26(resolved.team.path, "memory")),
|
|
11763
12158
|
messagingHost: createDbMessagingHost(db),
|
|
11764
12159
|
userMdHost: createDbUserMdHost(db, paths),
|
|
11765
12160
|
fileSink: reportOnly,
|
|
@@ -11789,7 +12184,7 @@ agentChatRouter.get(
|
|
|
11789
12184
|
let blockChars = name.length + 2;
|
|
11790
12185
|
if (match) {
|
|
11791
12186
|
try {
|
|
11792
|
-
blockChars =
|
|
12187
|
+
blockChars = readFileSync10(match.skillFile, "utf8").length;
|
|
11793
12188
|
} catch {
|
|
11794
12189
|
}
|
|
11795
12190
|
}
|
|
@@ -11863,7 +12258,7 @@ agentChatRouter.post("/:id/chat/truncate", async (c) => {
|
|
|
11863
12258
|
});
|
|
11864
12259
|
|
|
11865
12260
|
// ../daemon/src/routes/agent-learning.ts
|
|
11866
|
-
import { join as
|
|
12261
|
+
import { join as join27 } from "node:path";
|
|
11867
12262
|
|
|
11868
12263
|
// ../daemon/src/lib/lesson-decisions.ts
|
|
11869
12264
|
var LessonProposalConflictError = class extends DomainError {
|
|
@@ -12062,7 +12457,7 @@ for (const decision of ["approve", "reject", "revoke"]) {
|
|
|
12062
12457
|
const team = teams_exports.get(db, agent.teamId, paths);
|
|
12063
12458
|
if (!team) return c.json({ error: `team not found: ${agent.teamId}` }, 404);
|
|
12064
12459
|
const proposal = await runAgentLifecycleMutation(agent.id, async () => {
|
|
12065
|
-
const memory = qmdBackend(
|
|
12460
|
+
const memory = qmdBackend(join27(team.path, "memory"));
|
|
12066
12461
|
if (decision === "approve") return approveLessonProposal(db, memory, current2.id, version);
|
|
12067
12462
|
if (decision === "reject") return rejectLessonProposal(db, current2.id, version);
|
|
12068
12463
|
return revokeLessonProposal(db, memory, current2.id, version);
|
|
@@ -12090,7 +12485,7 @@ function withEvidenceExcerpts(proposals, agent, paths) {
|
|
|
12090
12485
|
}
|
|
12091
12486
|
|
|
12092
12487
|
// ../daemon/src/routes/agents.ts
|
|
12093
|
-
import { join as
|
|
12488
|
+
import { join as join28 } from "node:path";
|
|
12094
12489
|
init_pool2();
|
|
12095
12490
|
|
|
12096
12491
|
// ../daemon/src/lib/telegram/config.ts
|
|
@@ -12365,7 +12760,7 @@ agentsRouter.get("/", (c) => {
|
|
|
12365
12760
|
const includeArchived = c.req.query("includeArchived") === "true";
|
|
12366
12761
|
const agents = agents_exports.list(getCtx().db, { includeArchived }).map((agent) => ({
|
|
12367
12762
|
...agent,
|
|
12368
|
-
identity: loadIdentityFromFile(
|
|
12763
|
+
identity: loadIdentityFromFile(join28(agent.dir, "IDENTITY.md"))
|
|
12369
12764
|
}));
|
|
12370
12765
|
return c.json(agents);
|
|
12371
12766
|
});
|
|
@@ -12499,7 +12894,7 @@ attentionRouter.delete(
|
|
|
12499
12894
|
import { deleteCookie, setCookie } from "hono/cookie";
|
|
12500
12895
|
|
|
12501
12896
|
// ../daemon/src/lib/openai-oauth-prompt.ts
|
|
12502
|
-
import { spawn as
|
|
12897
|
+
import { spawn as spawn5 } from "node:child_process";
|
|
12503
12898
|
import { createServer as createServer2 } from "node:net";
|
|
12504
12899
|
var OPENAI_CODEX_CALLBACK_PORT = 1455;
|
|
12505
12900
|
var WEB_OPENAI_LOGIN_TIMEOUT_MS = 10 * 6e4;
|
|
@@ -12521,14 +12916,17 @@ async function preflightOpenAICodexCallback(host3 = process.env.PI_OAUTH_CALLBAC
|
|
|
12521
12916
|
await new Promise((resolve8) => server3.close(() => resolve8()));
|
|
12522
12917
|
}
|
|
12523
12918
|
}
|
|
12919
|
+
function openAICodexBrowserCommand(platform = process.platform) {
|
|
12920
|
+
return platform === "darwin" ? "/usr/bin/open" : "xdg-open";
|
|
12921
|
+
}
|
|
12524
12922
|
function launchOpenAICodexBrowser(url, onFailure) {
|
|
12525
|
-
const command =
|
|
12923
|
+
const command = openAICodexBrowserCommand();
|
|
12526
12924
|
const fail2 = (detail) => onFailure(
|
|
12527
12925
|
new Error(
|
|
12528
12926
|
`Could not open the OpenAI sign-in page with ${command}: ${detail}. Run ${DEVICE_CODE_FALLBACK}.`
|
|
12529
12927
|
)
|
|
12530
12928
|
);
|
|
12531
|
-
const child =
|
|
12929
|
+
const child = spawn5(command, [url], { stdio: "ignore", detached: true });
|
|
12532
12930
|
child.once("error", (error) => fail2(error.message));
|
|
12533
12931
|
child.once("exit", (code, signal) => {
|
|
12534
12932
|
if (code !== 0) fail2(code === null ? `terminated by ${signal}` : `exited ${code}`);
|
|
@@ -12796,9 +13194,9 @@ configRouter.put("/providers/:name/models", async (c) => {
|
|
|
12796
13194
|
);
|
|
12797
13195
|
}
|
|
12798
13196
|
const { db, paths } = getCtx();
|
|
12799
|
-
|
|
13197
|
+
const saved = replaceCuratedModels(db, name, models);
|
|
12800
13198
|
ensureSetupSeeded(db, paths);
|
|
12801
|
-
return c.json(
|
|
13199
|
+
return c.json(saved);
|
|
12802
13200
|
});
|
|
12803
13201
|
configRouter.put("/fields/:envVar", async (c) => {
|
|
12804
13202
|
const envVar = c.req.param("envVar");
|
|
@@ -13122,24 +13520,24 @@ agentMessagesRouter.post("/:id/messages", async (c) => {
|
|
|
13122
13520
|
|
|
13123
13521
|
// ../daemon/src/routes/misc.ts
|
|
13124
13522
|
import { existsSync as existsSync17 } from "node:fs";
|
|
13125
|
-
import { homedir as
|
|
13126
|
-
import { join as
|
|
13523
|
+
import { homedir as homedir4 } from "node:os";
|
|
13524
|
+
import { join as join31 } from "node:path";
|
|
13127
13525
|
|
|
13128
13526
|
// ../daemon/src/lib/backup.ts
|
|
13129
13527
|
import { mkdtempSync as mkdtempSync3, rmSync as rmSync13 } from "node:fs";
|
|
13130
13528
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
13131
|
-
import { join as
|
|
13529
|
+
import { join as join30, resolve as resolve7 } from "node:path";
|
|
13132
13530
|
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
13133
13531
|
import { create as create6 } from "tar";
|
|
13134
13532
|
|
|
13135
13533
|
// ../daemon/src/lib/daemon-liveness.ts
|
|
13136
|
-
import { mkdirSync as mkdirSync11, readFileSync as
|
|
13137
|
-
import { join as
|
|
13534
|
+
import { mkdirSync as mkdirSync11, readFileSync as readFileSync11, rmSync as rmSync12, writeFileSync as writeFileSync10 } from "node:fs";
|
|
13535
|
+
import { join as join29 } from "node:path";
|
|
13138
13536
|
var DAEMON_PID_FILE = "daemon.pid";
|
|
13139
13537
|
function runningDaemonPid(home) {
|
|
13140
13538
|
let pid;
|
|
13141
13539
|
try {
|
|
13142
|
-
pid = Number.parseInt(
|
|
13540
|
+
pid = Number.parseInt(readFileSync11(join29(home, DAEMON_PID_FILE), "utf8"), 10);
|
|
13143
13541
|
} catch (error) {
|
|
13144
13542
|
if (error.code === "ENOENT") return null;
|
|
13145
13543
|
throw error;
|
|
@@ -13156,12 +13554,12 @@ function assertDaemonStopped(home) {
|
|
|
13156
13554
|
const pid = runningDaemonPid(home);
|
|
13157
13555
|
if (pid !== null) {
|
|
13158
13556
|
throw new Error(
|
|
13159
|
-
`a bazilion daemon (pid ${pid}) is running on ${home}; stop it first (if none is running, delete ${
|
|
13557
|
+
`a bazilion daemon (pid ${pid}) is running on ${home}; stop it first (if none is running, delete ${join29(home, DAEMON_PID_FILE)})`
|
|
13160
13558
|
);
|
|
13161
13559
|
}
|
|
13162
13560
|
}
|
|
13163
13561
|
function claimDaemonPidFile(home) {
|
|
13164
|
-
const path =
|
|
13562
|
+
const path = join29(home, DAEMON_PID_FILE);
|
|
13165
13563
|
const content = `${process.pid}
|
|
13166
13564
|
`;
|
|
13167
13565
|
mkdirSync11(home, { recursive: true });
|
|
@@ -13175,7 +13573,7 @@ function claimDaemonPidFile(home) {
|
|
|
13175
13573
|
}
|
|
13176
13574
|
return () => {
|
|
13177
13575
|
try {
|
|
13178
|
-
if (
|
|
13576
|
+
if (readFileSync11(path, "utf8") === content) rmSync12(path);
|
|
13179
13577
|
} catch {
|
|
13180
13578
|
}
|
|
13181
13579
|
};
|
|
@@ -13190,10 +13588,10 @@ function createBackupSnapshot(db) {
|
|
|
13190
13588
|
return snapshot2;
|
|
13191
13589
|
}
|
|
13192
13590
|
async function takeSnapshot(db) {
|
|
13193
|
-
const directory = mkdtempSync3(
|
|
13591
|
+
const directory = mkdtempSync3(join30(tmpdir3(), "bazilion-backup-"));
|
|
13194
13592
|
const cleanup = () => rmSync13(directory, { recursive: true, force: true });
|
|
13195
13593
|
try {
|
|
13196
|
-
const database =
|
|
13594
|
+
const database = join30(directory, "bazilion.snapshot");
|
|
13197
13595
|
await db.backupTo(database);
|
|
13198
13596
|
const snapshot2 = new DatabaseSync2(database, { readOnly: true });
|
|
13199
13597
|
try {
|
|
@@ -13292,7 +13690,7 @@ miscRouter.get("/health/details", async (c) => {
|
|
|
13292
13690
|
} catch {
|
|
13293
13691
|
}
|
|
13294
13692
|
}
|
|
13295
|
-
const openclawSkillsDir =
|
|
13693
|
+
const openclawSkillsDir = join31(homedir4(), ".openclaw", "skills");
|
|
13296
13694
|
const providerSection = {
|
|
13297
13695
|
// Hosted providers with credentials; local servers are reported below.
|
|
13298
13696
|
configured: PROVIDERS.filter(
|
|
@@ -13700,8 +14098,8 @@ notificationsRouter.put("/", async (c) => {
|
|
|
13700
14098
|
});
|
|
13701
14099
|
|
|
13702
14100
|
// ../daemon/src/routes/profiles.ts
|
|
13703
|
-
import { existsSync as existsSync18, readFileSync as
|
|
13704
|
-
import { join as
|
|
14101
|
+
import { existsSync as existsSync18, readFileSync as readFileSync12, writeFileSync as writeFileSync11 } from "node:fs";
|
|
14102
|
+
import { join as join32 } from "node:path";
|
|
13705
14103
|
var profilesRouter = newRouter();
|
|
13706
14104
|
profilesRouter.get("/", (c) => {
|
|
13707
14105
|
const { db } = getCtx();
|
|
@@ -13784,13 +14182,13 @@ function profileFile(c) {
|
|
|
13784
14182
|
if (!PROFILE_FILES.includes(file)) {
|
|
13785
14183
|
return c.json({ error: `unsupported file: ${file}` }, 400);
|
|
13786
14184
|
}
|
|
13787
|
-
return
|
|
14185
|
+
return join32(paths.profilesDir, id, file);
|
|
13788
14186
|
}
|
|
13789
14187
|
profilesRouter.get("/:id/files/:file", (c) => {
|
|
13790
14188
|
const path = profileFile(c);
|
|
13791
14189
|
if (typeof path !== "string") return path;
|
|
13792
14190
|
if (!existsSync18(path)) return c.json({ error: `file not present: ${c.req.param("file")}` }, 404);
|
|
13793
|
-
return c.json({ content:
|
|
14191
|
+
return c.json({ content: readFileSync12(path, "utf8") });
|
|
13794
14192
|
});
|
|
13795
14193
|
profilesRouter.put("/:id/files/:file", async (c) => {
|
|
13796
14194
|
const body = await jsonBody(c);
|
|
@@ -13924,8 +14322,8 @@ shellApprovalsRouter.post("/:id", async (c) => {
|
|
|
13924
14322
|
|
|
13925
14323
|
// ../daemon/src/routes/skills.ts
|
|
13926
14324
|
import { mkdtempSync as mkdtempSync4, rmSync as rmSync14, writeFileSync as writeFileSync12 } from "node:fs";
|
|
13927
|
-
import { homedir as
|
|
13928
|
-
import { join as
|
|
14325
|
+
import { homedir as homedir5, tmpdir as tmpdir4 } from "node:os";
|
|
14326
|
+
import { join as join33 } from "node:path";
|
|
13929
14327
|
var MAX_ZIP_BYTES = 50 * 1024 * 1024;
|
|
13930
14328
|
var skillsRouter = newRouter();
|
|
13931
14329
|
skillsRouter.get("/", (c) => {
|
|
@@ -14018,8 +14416,8 @@ async function parseImportInput(request) {
|
|
|
14018
14416
|
if (!filename.toLowerCase().endsWith(".zip")) {
|
|
14019
14417
|
throw new Error("uploaded file must be a .zip archive");
|
|
14020
14418
|
}
|
|
14021
|
-
const tmpDir = mkdtempSync4(
|
|
14022
|
-
const zipPath =
|
|
14419
|
+
const tmpDir = mkdtempSync4(join33(tmpdir4(), "bazilion-skill-upload-"));
|
|
14420
|
+
const zipPath = join33(tmpDir, filename.replace(/[^\w.-]+/g, "_"));
|
|
14023
14421
|
const buf = Buffer.from(await file.arrayBuffer());
|
|
14024
14422
|
writeFileSync12(zipPath, buf);
|
|
14025
14423
|
const forceField = form.get("force");
|
|
@@ -14035,7 +14433,7 @@ async function parseImportInput(request) {
|
|
|
14035
14433
|
const { source } = body;
|
|
14036
14434
|
if (typeof source !== "string" || !source) throw new Error("source is required");
|
|
14037
14435
|
return {
|
|
14038
|
-
source: source === "openclaw" ?
|
|
14436
|
+
source: source === "openclaw" ? join33(homedir5(), ".openclaw", "skills") : source,
|
|
14039
14437
|
force: Boolean(body.force),
|
|
14040
14438
|
tempZipPath: null,
|
|
14041
14439
|
sourceLabel: source
|
|
@@ -14105,7 +14503,7 @@ teamCodingEnvironmentRouter.put("/:id/coding-environment", async (c) => {
|
|
|
14105
14503
|
});
|
|
14106
14504
|
|
|
14107
14505
|
// ../daemon/src/routes/team-memory.ts
|
|
14108
|
-
import { join as
|
|
14506
|
+
import { join as join34 } from "node:path";
|
|
14109
14507
|
var teamMemoryRouter = newRouter();
|
|
14110
14508
|
teamMemoryRouter.onError((error, c) => {
|
|
14111
14509
|
const safe = sanitizeNativeModuleError(error, { subject: "Bazilion memory" });
|
|
@@ -14113,7 +14511,7 @@ teamMemoryRouter.onError((error, c) => {
|
|
|
14113
14511
|
return onRouteError(safe, c);
|
|
14114
14512
|
});
|
|
14115
14513
|
async function openMemory(c) {
|
|
14116
|
-
const mem = qmdBackend(
|
|
14514
|
+
const mem = qmdBackend(join34(routeTeam(c).path, "memory"));
|
|
14117
14515
|
await mem.init();
|
|
14118
14516
|
return mem;
|
|
14119
14517
|
}
|
|
@@ -14179,7 +14577,7 @@ import {
|
|
|
14179
14577
|
readSync as readSync3,
|
|
14180
14578
|
realpathSync as realpathSync7
|
|
14181
14579
|
} from "node:fs";
|
|
14182
|
-
import { join as
|
|
14580
|
+
import { join as join35 } from "node:path";
|
|
14183
14581
|
var hash = (value) => createHash6("sha256").update(value).digest("hex");
|
|
14184
14582
|
var ContextReadError = class extends Error {
|
|
14185
14583
|
code;
|
|
@@ -14217,12 +14615,12 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
14217
14615
|
this.parent = parent;
|
|
14218
14616
|
if (parent) component(registeredPath);
|
|
14219
14617
|
parent?.assertOpen();
|
|
14220
|
-
const canonicalPath = parent ?
|
|
14618
|
+
const canonicalPath = parent ? join35(parent.canonicalPath, registeredPath) : realpathSync7(registeredPath);
|
|
14221
14619
|
this.canonicalPath = canonicalPath;
|
|
14222
14620
|
let fd;
|
|
14223
14621
|
try {
|
|
14224
14622
|
fd = openSync6(
|
|
14225
|
-
parent ?
|
|
14623
|
+
parent ? join35(parent.path, registeredPath) : canonicalPath,
|
|
14226
14624
|
constants7.O_RDONLY | constants7.O_DIRECTORY | constants7.O_NOFOLLOW
|
|
14227
14625
|
);
|
|
14228
14626
|
const stat = fstatSync6(fd, { bigint: true });
|
|
@@ -14260,7 +14658,7 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
14260
14658
|
component(name);
|
|
14261
14659
|
this.assertOpen();
|
|
14262
14660
|
try {
|
|
14263
|
-
return lstatSync6(
|
|
14661
|
+
return lstatSync6(join35(this.path, name));
|
|
14264
14662
|
} catch (error) {
|
|
14265
14663
|
if (error.code === "ENOENT") return null;
|
|
14266
14664
|
throw new ContextReadError("unreadable");
|
|
@@ -14268,7 +14666,7 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
14268
14666
|
}
|
|
14269
14667
|
observe(name) {
|
|
14270
14668
|
try {
|
|
14271
|
-
return lstatSync6(
|
|
14669
|
+
return lstatSync6(join35(this.path, name), { bigint: true });
|
|
14272
14670
|
} catch (error) {
|
|
14273
14671
|
if (error.code === "ENOENT") return null;
|
|
14274
14672
|
throw new ContextReadError("unreadable");
|
|
@@ -14309,7 +14707,7 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
14309
14707
|
let fd;
|
|
14310
14708
|
try {
|
|
14311
14709
|
fd = openSync6(
|
|
14312
|
-
|
|
14710
|
+
join35(this.path, name),
|
|
14313
14711
|
constants7.O_RDONLY | constants7.O_NOFOLLOW | constants7.O_NONBLOCK
|
|
14314
14712
|
);
|
|
14315
14713
|
const before = fstatSync6(fd, { bigint: true });
|
|
@@ -14335,7 +14733,7 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
14335
14733
|
}
|
|
14336
14734
|
validate(skipGit = false, names) {
|
|
14337
14735
|
this.assertOpen();
|
|
14338
|
-
const currentPath = this.parent ?
|
|
14736
|
+
const currentPath = this.parent ? join35(this.parent.path, this.registeredPath) : realpathSync7(this.registeredPath);
|
|
14339
14737
|
const stat = lstatSync6(currentPath, { bigint: true });
|
|
14340
14738
|
if (!stat.isDirectory() || identity(stat) !== identity(this.originalIdentity))
|
|
14341
14739
|
throw new ContextReadError("root_changed");
|
|
@@ -14763,7 +15161,7 @@ async function readOrNull(captured, args) {
|
|
|
14763
15161
|
import { execFile } from "node:child_process";
|
|
14764
15162
|
import { mkdirSync as mkdirSync12, mkdtempSync as mkdtempSync5, rmSync as rmSync15, writeFileSync as writeFileSync13 } from "node:fs";
|
|
14765
15163
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
14766
|
-
import { join as
|
|
15164
|
+
import { join as join36 } from "node:path";
|
|
14767
15165
|
var INSPECTION_BUDGET_MS = 5e3;
|
|
14768
15166
|
var METADATA_BUDGET_MS = 2500;
|
|
14769
15167
|
var METADATA_BYTES = 64 * 1024 * 1024;
|
|
@@ -14792,7 +15190,7 @@ async function captureRepositoryGit(root, budgetMs = INSPECTION_BUDGET_MS) {
|
|
|
14792
15190
|
const dir = git.directory("info");
|
|
14793
15191
|
if (dir.entry("sparse-checkout")) throw new ContextReadError("unsupported_git_metadata");
|
|
14794
15192
|
}
|
|
14795
|
-
const scratch = mkdtempSync5(
|
|
15193
|
+
const scratch = mkdtempSync5(join36(tmpdir5(), "bazilion-context-git-"));
|
|
14796
15194
|
let cleaned = false;
|
|
14797
15195
|
const cleanup = () => {
|
|
14798
15196
|
if (cleaned) return;
|
|
@@ -14853,7 +15251,7 @@ async function captureRepositoryGit(root, budgetMs = INSPECTION_BUDGET_MS) {
|
|
|
14853
15251
|
if (capturedConfig) {
|
|
14854
15252
|
bytes += capturedConfig.length;
|
|
14855
15253
|
count++;
|
|
14856
|
-
const configPath =
|
|
15254
|
+
const configPath = join36(scratch, "captured-config");
|
|
14857
15255
|
writeFileSync13(configPath, capturedConfig, { mode: 384 });
|
|
14858
15256
|
const config = await rawGit([
|
|
14859
15257
|
"config",
|
|
@@ -14906,8 +15304,8 @@ objectformat = ${value}`
|
|
|
14906
15304
|
const exclude = git.directory("info").read("exclude", METADATA_READ);
|
|
14907
15305
|
if (exclude) {
|
|
14908
15306
|
bytes += exclude.length;
|
|
14909
|
-
mkdirSync12(
|
|
14910
|
-
writeFileSync13(
|
|
15307
|
+
mkdirSync12(join36(scratch, "info"), { mode: 448 });
|
|
15308
|
+
writeFileSync13(join36(scratch, "info", "exclude"), exclude, { mode: 384 });
|
|
14911
15309
|
}
|
|
14912
15310
|
}
|
|
14913
15311
|
const copy = (source, destination, depth) => {
|
|
@@ -14920,13 +15318,13 @@ objectformat = ${value}`
|
|
|
14920
15318
|
if (name === "alternates" || name === "http-alternates")
|
|
14921
15319
|
throw new ContextReadError("unsupported_git_metadata");
|
|
14922
15320
|
if (entry.isDirectory()) {
|
|
14923
|
-
mkdirSync12(
|
|
14924
|
-
copy(source.directory(name),
|
|
15321
|
+
mkdirSync12(join36(destination, name), { mode: 448 });
|
|
15322
|
+
copy(source.directory(name), join36(destination, name), depth + 1);
|
|
14925
15323
|
} else {
|
|
14926
15324
|
const content = source.read(name, METADATA_BYTES - bytes);
|
|
14927
15325
|
if (!content) throw new ContextReadError("source_changed");
|
|
14928
15326
|
bytes += content.length;
|
|
14929
|
-
writeFileSync13(
|
|
15327
|
+
writeFileSync13(join36(destination, name), content, { mode: 384 });
|
|
14930
15328
|
}
|
|
14931
15329
|
}
|
|
14932
15330
|
};
|
|
@@ -14935,16 +15333,16 @@ objectformat = ${value}`
|
|
|
14935
15333
|
if (content) {
|
|
14936
15334
|
count++;
|
|
14937
15335
|
bytes += content.length;
|
|
14938
|
-
writeFileSync13(
|
|
15336
|
+
writeFileSync13(join36(scratch, name), content, { mode: 384 });
|
|
14939
15337
|
}
|
|
14940
15338
|
}
|
|
14941
15339
|
for (const name of ["refs", "objects"]) {
|
|
14942
|
-
mkdirSync12(
|
|
14943
|
-
if (git.entry(name)) copy(git.directory(name),
|
|
15340
|
+
mkdirSync12(join36(scratch, name), { mode: 448 });
|
|
15341
|
+
if (git.entry(name)) copy(git.directory(name), join36(scratch, name), 0);
|
|
14944
15342
|
}
|
|
14945
15343
|
if (git.list().some((name) => name.startsWith("sharedindex.")))
|
|
14946
15344
|
throw new ContextReadError("unsupported_git_metadata");
|
|
14947
|
-
writeFileSync13(
|
|
15345
|
+
writeFileSync13(join36(scratch, "config"), `${configLines.join("\n")}
|
|
14948
15346
|
`, { mode: 384 });
|
|
14949
15347
|
const validate2 = () => git.validate();
|
|
14950
15348
|
validate2();
|
|
@@ -17147,6 +17545,7 @@ function createApp() {
|
|
|
17147
17545
|
}
|
|
17148
17546
|
|
|
17149
17547
|
// ../daemon/src/index.ts
|
|
17548
|
+
init_install();
|
|
17150
17549
|
init_resources();
|
|
17151
17550
|
|
|
17152
17551
|
// ../daemon/src/lib/review-provider.ts
|
|
@@ -17761,6 +18160,9 @@ var server2 = serve({ fetch: app.fetch, hostname: host2, port }, (info) => {
|
|
|
17761
18160
|
maybeStartTelegramBot(db, authToken).catch((err) => {
|
|
17762
18161
|
console.error("telegram: background start failed:", err instanceof Error ? err.message : err);
|
|
17763
18162
|
});
|
|
18163
|
+
const env = mergeSecretsIntoEnv(db, authToken);
|
|
18164
|
+
const browser = resolveBrowserConfig(env);
|
|
18165
|
+
if (isBrowserEnabled(env) && !browser.attach) prepareBrowser(browser.executablePath);
|
|
17764
18166
|
});
|
|
17765
18167
|
var shutdown = (signal) => {
|
|
17766
18168
|
if (shuttingDown) return;
|