bazilion 0.26.1 → 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 +1 -2
- package/dist/cli.js.map +1 -1
- package/dist/daemon.js +599 -230
- package/dist/daemon.js.map +1 -1
- package/dist/worker.js +51 -7
- package/dist/worker.js.map +1 -1
- package/package.json +1 -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();
|
|
@@ -4341,7 +4683,7 @@ var SERVICES = [
|
|
|
4341
4683
|
displayName: "Browser Automation",
|
|
4342
4684
|
category: "service",
|
|
4343
4685
|
team: "Browser",
|
|
4344
|
-
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.',
|
|
4345
4687
|
fields: [
|
|
4346
4688
|
{
|
|
4347
4689
|
envVar: "BROWSER_ENABLED",
|
|
@@ -4355,14 +4697,28 @@ var SERVICES = [
|
|
|
4355
4697
|
kind: "config",
|
|
4356
4698
|
label: "Browser executable (optional)",
|
|
4357
4699
|
placeholder: "/usr/bin/brave-browser",
|
|
4358
|
-
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.'
|
|
4359
4715
|
},
|
|
4360
4716
|
{
|
|
4361
4717
|
envVar: "BROWSER_HEADLESS",
|
|
4362
4718
|
kind: "config",
|
|
4363
4719
|
label: "Headless",
|
|
4364
4720
|
placeholder: "true",
|
|
4365
|
-
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."
|
|
4366
4722
|
},
|
|
4367
4723
|
{
|
|
4368
4724
|
envVar: "BROWSER_ALLOW_PRIVATE_NETWORK",
|
|
@@ -5932,10 +6288,13 @@ function isBrowserEnabled(env) {
|
|
|
5932
6288
|
}
|
|
5933
6289
|
function resolveBrowserConfig(env) {
|
|
5934
6290
|
const executablePath = env.BROWSER_EXECUTABLE_PATH?.trim();
|
|
6291
|
+
const attachUrl = env.BROWSER_ATTACH_URL?.trim();
|
|
5935
6292
|
return {
|
|
5936
6293
|
headless: envBool(env.BROWSER_HEADLESS, true),
|
|
5937
6294
|
...executablePath ? { executablePath } : {},
|
|
5938
6295
|
allowPrivate: envBool(env.BROWSER_ALLOW_PRIVATE_NETWORK, false),
|
|
6296
|
+
attach: envBool(env.BROWSER_ATTACH, false),
|
|
6297
|
+
...attachUrl ? { attachUrl } : {},
|
|
5939
6298
|
idleMs: envInt(env.BROWSER_IDLE_MS, 9e5),
|
|
5940
6299
|
maxSessions: envInt(env.BROWSER_MAX_SESSIONS, 4)
|
|
5941
6300
|
};
|
|
@@ -6006,8 +6365,8 @@ agentBrowserRouter.delete("/:id/browser/profile", async (c) => {
|
|
|
6006
6365
|
|
|
6007
6366
|
// ../daemon/src/routes/agent-chat.ts
|
|
6008
6367
|
import { randomUUID as randomUUID19 } from "node:crypto";
|
|
6009
|
-
import { existsSync as existsSync16, readFileSync as
|
|
6010
|
-
import { join as
|
|
6368
|
+
import { existsSync as existsSync16, readFileSync as readFileSync10 } from "node:fs";
|
|
6369
|
+
import { join as join26 } from "node:path";
|
|
6011
6370
|
|
|
6012
6371
|
// ../daemon/src/core/repos/conversations.ts
|
|
6013
6372
|
var columns = "id, agent_id AS agentId, title, created_at AS createdAt, updated_at AS updatedAt";
|
|
@@ -6199,12 +6558,12 @@ import {
|
|
|
6199
6558
|
mkdirSync as mkdirSync6,
|
|
6200
6559
|
openSync,
|
|
6201
6560
|
readdirSync as readdirSync4,
|
|
6202
|
-
readFileSync as
|
|
6561
|
+
readFileSync as readFileSync8,
|
|
6203
6562
|
realpathSync as realpathSync2,
|
|
6204
6563
|
rmSync as rmSync9,
|
|
6205
6564
|
writeFileSync as writeFileSync5
|
|
6206
6565
|
} from "node:fs";
|
|
6207
|
-
import { dirname as
|
|
6566
|
+
import { dirname as dirname4, isAbsolute as isAbsolute2, join as join14, relative, resolve as resolve4, sep as sep2 } from "node:path";
|
|
6208
6567
|
import { createStore, extractSnippet } from "@tobilu/qmd";
|
|
6209
6568
|
|
|
6210
6569
|
// ../daemon/src/lib/native-module-error.ts
|
|
@@ -6250,7 +6609,7 @@ function getStore(dir, storeFactory) {
|
|
|
6250
6609
|
if (!p) {
|
|
6251
6610
|
p = withNativeModuleErrorBoundary(
|
|
6252
6611
|
() => storeFactory({
|
|
6253
|
-
dbPath:
|
|
6612
|
+
dbPath: join14(dir, INDEX_FILENAME),
|
|
6254
6613
|
config: {
|
|
6255
6614
|
collections: {
|
|
6256
6615
|
[COLLECTION_NAME]: { path: dir, pattern: PATTERN }
|
|
@@ -6328,7 +6687,7 @@ function inspectSafePath(root, path) {
|
|
|
6328
6687
|
let current2 = root;
|
|
6329
6688
|
const components = rel.split(sep2).filter(Boolean);
|
|
6330
6689
|
for (let index = 0; index < components.length; index += 1) {
|
|
6331
|
-
current2 =
|
|
6690
|
+
current2 = join14(current2, components[index]);
|
|
6332
6691
|
const info = lstatIfPresent(current2);
|
|
6333
6692
|
if (!info) return void 0;
|
|
6334
6693
|
if (info.isSymbolicLink()) {
|
|
@@ -6342,12 +6701,12 @@ function inspectSafePath(root, path) {
|
|
|
6342
6701
|
return lstatIfPresent(path);
|
|
6343
6702
|
}
|
|
6344
6703
|
function ensureSafeParentDirectories(root, path) {
|
|
6345
|
-
const parent =
|
|
6704
|
+
const parent = dirname4(path);
|
|
6346
6705
|
assertContained(root, parent);
|
|
6347
6706
|
const rel = relative(root, parent);
|
|
6348
6707
|
let current2 = root;
|
|
6349
6708
|
for (const component2 of rel.split(sep2).filter(Boolean)) {
|
|
6350
|
-
current2 =
|
|
6709
|
+
current2 = join14(current2, component2);
|
|
6351
6710
|
let info = lstatIfPresent(current2);
|
|
6352
6711
|
if (!info) {
|
|
6353
6712
|
mkdirSync6(current2);
|
|
@@ -6371,7 +6730,7 @@ function readSafeFile(root, path) {
|
|
|
6371
6730
|
fd = openSync(path, constants2.O_RDONLY | constants2.O_NOFOLLOW);
|
|
6372
6731
|
const stats = fstatSync(fd);
|
|
6373
6732
|
if (!stats.isFile()) throw unsafeMemoryPath(path, "memory entry is not a regular file");
|
|
6374
|
-
return { content:
|
|
6733
|
+
return { content: readFileSync8(fd, "utf8"), stats };
|
|
6375
6734
|
} catch (error) {
|
|
6376
6735
|
if (error.code === "ELOOP") {
|
|
6377
6736
|
throw unsafeMemoryPath(path, "symbolic links are not allowed");
|
|
@@ -6413,7 +6772,7 @@ function writeSafeFile(root, path, content) {
|
|
|
6413
6772
|
function assertSafeTree(root, dir = root) {
|
|
6414
6773
|
assertContained(root, realpathSync2(dir));
|
|
6415
6774
|
for (const entry of readdirSync4(dir, { withFileTypes: true })) {
|
|
6416
|
-
const full =
|
|
6775
|
+
const full = join14(dir, entry.name);
|
|
6417
6776
|
const info = lstatSync(full);
|
|
6418
6777
|
if (info.isSymbolicLink()) {
|
|
6419
6778
|
throw unsafeMemoryPath(full, "symbolic links are not allowed in memory storage");
|
|
@@ -6427,7 +6786,7 @@ function assertSafeTree(root, dir = root) {
|
|
|
6427
6786
|
}
|
|
6428
6787
|
function walkMd(root, dir, prefix, out) {
|
|
6429
6788
|
for (const entry of readdirSync4(dir, { withFileTypes: true })) {
|
|
6430
|
-
const full =
|
|
6789
|
+
const full = join14(dir, entry.name);
|
|
6431
6790
|
const info = lstatSync(full);
|
|
6432
6791
|
if (info.isSymbolicLink()) {
|
|
6433
6792
|
throw unsafeMemoryPath(full, "symbolic links are not allowed in memory storage");
|
|
@@ -6534,17 +6893,17 @@ function qmdBackend(root, options = {}) {
|
|
|
6534
6893
|
// ../daemon/src/runtime/worker/runtime.ts
|
|
6535
6894
|
import { mkdirSync as mkdirSync7, mkdtempSync as mkdtempSync2, rmSync as rmSync10 } from "node:fs";
|
|
6536
6895
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
6537
|
-
import { join as
|
|
6896
|
+
import { join as join15 } from "node:path";
|
|
6538
6897
|
var REDACTED_VALUE = "[REDACTED]";
|
|
6539
6898
|
function createMinimalWorkerScratch(parentDir = tmpdir2()) {
|
|
6540
|
-
const root = mkdtempSync2(
|
|
6899
|
+
const root = mkdtempSync2(join15(parentDir, "bazilion-worker-"));
|
|
6541
6900
|
const scratch = {
|
|
6542
6901
|
root,
|
|
6543
|
-
homeDir:
|
|
6544
|
-
tempDir:
|
|
6545
|
-
piAgentDir:
|
|
6546
|
-
reviewCwd:
|
|
6547
|
-
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")
|
|
6548
6907
|
};
|
|
6549
6908
|
try {
|
|
6550
6909
|
for (const path of Object.values(scratch).slice(1)) {
|
|
@@ -6763,7 +7122,7 @@ function extractResultReferences(value) {
|
|
|
6763
7122
|
|
|
6764
7123
|
// ../daemon/src/runtime/pi/session.ts
|
|
6765
7124
|
import { existsSync as existsSync14, mkdirSync as mkdirSync10, statSync as statSync6, writeFileSync as writeFileSync7 } from "node:fs";
|
|
6766
|
-
import { basename as basename5, join as
|
|
7125
|
+
import { basename as basename5, join as join21 } from "node:path";
|
|
6767
7126
|
import {
|
|
6768
7127
|
buildSessionContext,
|
|
6769
7128
|
createAgentSession,
|
|
@@ -6867,7 +7226,7 @@ async function testProviderModel(spec) {
|
|
|
6867
7226
|
|
|
6868
7227
|
// ../daemon/src/runtime/session/prompt.ts
|
|
6869
7228
|
import { existsSync as existsSync11, readdirSync as readdirSync5 } from "node:fs";
|
|
6870
|
-
import { join as
|
|
7229
|
+
import { join as join16 } from "node:path";
|
|
6871
7230
|
|
|
6872
7231
|
// ../daemon/src/runtime/safe-files.ts
|
|
6873
7232
|
import {
|
|
@@ -6877,13 +7236,13 @@ import {
|
|
|
6877
7236
|
lstatSync as lstatSync2,
|
|
6878
7237
|
mkdirSync as mkdirSync8,
|
|
6879
7238
|
openSync as openSync2,
|
|
6880
|
-
readFileSync as
|
|
7239
|
+
readFileSync as readFileSync9,
|
|
6881
7240
|
readlinkSync as readlinkSync2,
|
|
6882
7241
|
readSync,
|
|
6883
7242
|
realpathSync as realpathSync3,
|
|
6884
7243
|
statSync as statSync4
|
|
6885
7244
|
} from "node:fs";
|
|
6886
|
-
import { dirname as
|
|
7245
|
+
import { dirname as dirname5, isAbsolute as isAbsolute3, relative as relative2, resolve as resolve5, sep as sep3 } from "node:path";
|
|
6887
7246
|
var ContainedFileError = class extends Error {
|
|
6888
7247
|
reason;
|
|
6889
7248
|
constructor(reason) {
|
|
@@ -6951,7 +7310,7 @@ function ensureContainedRealDirectory(path, root, options = {}) {
|
|
|
6951
7310
|
}
|
|
6952
7311
|
} catch (error) {
|
|
6953
7312
|
if (error.code !== "ENOENT" || !options.create) throw error;
|
|
6954
|
-
const canonicalParent = realpathSync3(
|
|
7313
|
+
const canonicalParent = realpathSync3(dirname5(requested));
|
|
6955
7314
|
if (!isContained2(canonicalRoot, canonicalParent)) throw new Error("directory escapes its root");
|
|
6956
7315
|
mkdirSync8(requested, { recursive: true, mode: 448 });
|
|
6957
7316
|
const entry = lstatSync2(requested);
|
|
@@ -6971,7 +7330,7 @@ function readRegularFileNoFollow(path) {
|
|
|
6971
7330
|
try {
|
|
6972
7331
|
fd = openSync2(path, constants3.O_RDONLY | noFollowFlag());
|
|
6973
7332
|
if (!fstatSync2(fd).isFile()) throw new Error("target is not a regular file");
|
|
6974
|
-
return
|
|
7333
|
+
return readFileSync9(fd, "utf8");
|
|
6975
7334
|
} finally {
|
|
6976
7335
|
if (fd !== void 0) closeSync2(fd);
|
|
6977
7336
|
}
|
|
@@ -6985,12 +7344,15 @@ function isContained2(root, candidate) {
|
|
|
6985
7344
|
}
|
|
6986
7345
|
|
|
6987
7346
|
// ../daemon/src/runtime/session/browser-guide.ts
|
|
6988
|
-
function browserGuideSection() {
|
|
7347
|
+
function browserGuideSection(attached = false) {
|
|
6989
7348
|
return [
|
|
6990
7349
|
"# Browser",
|
|
6991
7350
|
"",
|
|
6992
|
-
"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.",
|
|
6993
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
|
+
] : [],
|
|
6994
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.",
|
|
6995
7357
|
"- Act with refs from the latest snapshot. Every action returns a fresh snapshot; take the next refs from it.",
|
|
6996
7358
|
"- A link that opens a new tab does not switch to it: list the tabs with `browser_tabs` and select the new one.",
|
|
@@ -7010,9 +7372,9 @@ function loadPromptSkills(skillsDir, attachedNames) {
|
|
|
7010
7372
|
const discovered = readdirSync5(skillsDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && attached.has(entry.name)).sort((a, b) => a.name.localeCompare(b.name));
|
|
7011
7373
|
const loaded = [];
|
|
7012
7374
|
for (const entry of discovered) {
|
|
7013
|
-
const hostDir =
|
|
7375
|
+
const hostDir = join16(skillsDir, entry.name);
|
|
7014
7376
|
try {
|
|
7015
|
-
const parsed = parseSkillContent(readRegularFileNoFollow(
|
|
7377
|
+
const parsed = parseSkillContent(readRegularFileNoFollow(join16(hostDir, "SKILL.md")));
|
|
7016
7378
|
const safeLabel = entry.name.replace(/[^A-Za-z0-9._-]/g, "_") || "skill";
|
|
7017
7379
|
loaded.push({
|
|
7018
7380
|
name: entry.name,
|
|
@@ -7031,7 +7393,7 @@ function loadHomeDocuments(agentDir2) {
|
|
|
7031
7393
|
const root = resolveRealDirectory(agentDir2);
|
|
7032
7394
|
const read2 = (file) => {
|
|
7033
7395
|
try {
|
|
7034
|
-
return readRegularFileNoFollow(
|
|
7396
|
+
return readRegularFileNoFollow(join16(root, file));
|
|
7035
7397
|
} catch (error) {
|
|
7036
7398
|
if (error.code === "ENOENT") return null;
|
|
7037
7399
|
throw new Error(`private Agent home is unsafe at ${file}`);
|
|
@@ -7136,7 +7498,10 @@ ${contextBlocks.join("\n\n")}`
|
|
|
7136
7498
|
});
|
|
7137
7499
|
}
|
|
7138
7500
|
if (options.browserGuide) {
|
|
7139
|
-
parts.push({
|
|
7501
|
+
parts.push({
|
|
7502
|
+
id: "browser-guide",
|
|
7503
|
+
text: browserGuideSection(options.browserGuide === "attached")
|
|
7504
|
+
});
|
|
7140
7505
|
}
|
|
7141
7506
|
const teamLines = [
|
|
7142
7507
|
"# Team",
|
|
@@ -7197,7 +7562,7 @@ function boundReviewedLessons(lessons, maxCharacters = 8e3) {
|
|
|
7197
7562
|
}
|
|
7198
7563
|
|
|
7199
7564
|
// ../daemon/src/runtime/shell/docker.ts
|
|
7200
|
-
import { spawn as
|
|
7565
|
+
import { spawn as spawn3 } from "node:child_process";
|
|
7201
7566
|
import { createHash as createHash3, randomUUID as randomUUID13 } from "node:crypto";
|
|
7202
7567
|
var CONTAINER_WORKSPACE = "/workspace";
|
|
7203
7568
|
var DOCKER_CALL_TIMEOUT_MS = 5e3;
|
|
@@ -7264,7 +7629,7 @@ function createDockerBashOperations(sandbox) {
|
|
|
7264
7629
|
const name = `${current2.containerPrefix}${randomUUID13().replaceAll("-", "").slice(0, 12)}`;
|
|
7265
7630
|
const args = dockerRunArgs(current2, name, command);
|
|
7266
7631
|
return new Promise((resolve8, reject2) => {
|
|
7267
|
-
const child =
|
|
7632
|
+
const child = spawn3("docker", args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
7268
7633
|
let stopped;
|
|
7269
7634
|
let settled = false;
|
|
7270
7635
|
const stop = (reason) => {
|
|
@@ -7333,7 +7698,7 @@ async function removeContainers(names) {
|
|
|
7333
7698
|
}
|
|
7334
7699
|
function docker(args) {
|
|
7335
7700
|
return new Promise((resolve8, reject2) => {
|
|
7336
|
-
const child =
|
|
7701
|
+
const child = spawn3("docker", args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
7337
7702
|
let stdout = "";
|
|
7338
7703
|
let stderr = "";
|
|
7339
7704
|
const timer = setTimeout(() => {
|
|
@@ -7363,7 +7728,7 @@ function dockerError(error) {
|
|
|
7363
7728
|
|
|
7364
7729
|
// ../daemon/src/runtime/shell/tooling.ts
|
|
7365
7730
|
import { existsSync as existsSync12, lstatSync as lstatSync3, mkdirSync as mkdirSync9, realpathSync as realpathSync4, statSync as statSync5 } from "node:fs";
|
|
7366
|
-
import { dirname as
|
|
7731
|
+
import { dirname as dirname6, isAbsolute as isAbsolute4, join as join17, relative as relative3, sep as sep4 } from "node:path";
|
|
7367
7732
|
import {
|
|
7368
7733
|
createBashToolDefinition,
|
|
7369
7734
|
createLocalBashOperations,
|
|
@@ -7685,18 +8050,18 @@ function createSessionShellTools(cwd, env, options = {}) {
|
|
|
7685
8050
|
};
|
|
7686
8051
|
const sandbox = () => {
|
|
7687
8052
|
const workspace = realpathSync4(cwd);
|
|
7688
|
-
if (turn.cwd !== "." && !statSync5(
|
|
8053
|
+
if (turn.cwd !== "." && !statSync5(join17(workspace, turn.cwd), { throwIfNoEntry: false })?.isDirectory())
|
|
7689
8054
|
throw new Error(`Working directory does not exist: ${containerWorkdir(turn.cwd)}`);
|
|
7690
|
-
mkdirSync9(
|
|
8055
|
+
mkdirSync9(join17(workspace, "memory"), { recursive: true });
|
|
7691
8056
|
return {
|
|
7692
8057
|
image: turn.image,
|
|
7693
8058
|
workspace,
|
|
7694
8059
|
workdir: containerWorkdir(turn.cwd),
|
|
7695
8060
|
readOnlyMounts: [
|
|
7696
|
-
readOnlyMount(
|
|
7697
|
-
...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))] : [],
|
|
7698
8063
|
...(options.skillMounts ?? []).map(
|
|
7699
|
-
(mount) => readOnlyMount(mount.source, mount.target,
|
|
8064
|
+
(mount) => readOnlyMount(mount.source, mount.target, dirname6(mount.source))
|
|
7700
8065
|
)
|
|
7701
8066
|
],
|
|
7702
8067
|
containerPrefix: turn.containerPrefix
|
|
@@ -7729,13 +8094,13 @@ function readOnlyMount(source, target, root) {
|
|
|
7729
8094
|
|
|
7730
8095
|
// ../daemon/src/runtime/pi/session-file.ts
|
|
7731
8096
|
import { closeSync as closeSync3, constants as constants4, fstatSync as fstatSync3, openSync as openSync3, readSync as readSync2 } from "node:fs";
|
|
7732
|
-
import { join as
|
|
8097
|
+
import { join as join18 } from "node:path";
|
|
7733
8098
|
var MAX_SESSION_BYTES = 64 * 1024 * 1024;
|
|
7734
8099
|
var MAX_HEADER_BYTES = 64 * 1024;
|
|
7735
8100
|
function readStart(directory, id, limit) {
|
|
7736
8101
|
if (!/^[0-9a-f-]{36}$/i.test(id)) throw new Error("Invalid conversation id");
|
|
7737
8102
|
const fd = openSync3(
|
|
7738
|
-
|
|
8103
|
+
join18(directory, `${id}.jsonl`),
|
|
7739
8104
|
constants4.O_RDONLY | constants4.O_NOFOLLOW | constants4.O_NONBLOCK
|
|
7740
8105
|
);
|
|
7741
8106
|
try {
|
|
@@ -7813,7 +8178,7 @@ function askUserTool(ask) {
|
|
|
7813
8178
|
|
|
7814
8179
|
// ../daemon/src/runtime/tools/bootstrap.ts
|
|
7815
8180
|
import { existsSync as existsSync13, rmSync as rmSync11 } from "node:fs";
|
|
7816
|
-
import { join as
|
|
8181
|
+
import { join as join19 } from "node:path";
|
|
7817
8182
|
function bootstrapTool(agentDir2) {
|
|
7818
8183
|
return {
|
|
7819
8184
|
def: {
|
|
@@ -7822,7 +8187,7 @@ function bootstrapTool(agentDir2) {
|
|
|
7822
8187
|
parameters: { type: "object", properties: {} }
|
|
7823
8188
|
},
|
|
7824
8189
|
async invoke() {
|
|
7825
|
-
const path =
|
|
8190
|
+
const path = join19(agentDir2, "BOOTSTRAP.md");
|
|
7826
8191
|
if (existsSync13(path)) {
|
|
7827
8192
|
rmSync11(path);
|
|
7828
8193
|
return "BOOTSTRAP.md removed. Bootstrap is complete.";
|
|
@@ -8022,7 +8387,7 @@ import {
|
|
|
8022
8387
|
readdirSync as readdirSync6,
|
|
8023
8388
|
writeFileSync as writeFileSync6
|
|
8024
8389
|
} from "node:fs";
|
|
8025
|
-
import { join as
|
|
8390
|
+
import { join as join20 } from "node:path";
|
|
8026
8391
|
var HOME_FILES_READABLE = [
|
|
8027
8392
|
"IDENTITY.md",
|
|
8028
8393
|
"SOUL.md",
|
|
@@ -8143,7 +8508,7 @@ function resolvePrivateHomeRoot(agentDir2) {
|
|
|
8143
8508
|
}
|
|
8144
8509
|
}
|
|
8145
8510
|
function privateHomeFile(homeRoot, file) {
|
|
8146
|
-
return
|
|
8511
|
+
return join20(homeRoot, file);
|
|
8147
8512
|
}
|
|
8148
8513
|
function rejectSymlinkOrNonFile(path) {
|
|
8149
8514
|
const entry = lstatSync4(path);
|
|
@@ -8926,7 +9291,7 @@ function turnSurface(opts) {
|
|
|
8926
9291
|
const shellTools = createSessionShellTools(cwd, env, {
|
|
8927
9292
|
docker: opts.docker,
|
|
8928
9293
|
containerPrefix: homeContainerPrefix(paths.home),
|
|
8929
|
-
inputsDir:
|
|
9294
|
+
inputsDir: join21(agent.agent.dir, "uploads"),
|
|
8930
9295
|
skillMounts: promptSkills.map((skill) => ({ source: skill.hostDir, target: skill.sandboxDir })),
|
|
8931
9296
|
approvalHost: opts.bashApprovalHost
|
|
8932
9297
|
});
|
|
@@ -8949,7 +9314,7 @@ function turnSurface(opts) {
|
|
|
8949
9314
|
skills: promptSkills,
|
|
8950
9315
|
sandboxMode: shellTools.config.sandboxMode,
|
|
8951
9316
|
// The guides ride along exactly when their tools are admitted.
|
|
8952
|
-
...opts.browserHost ? { browserGuide: true } : {},
|
|
9317
|
+
...opts.browserHost ? { browserGuide: resolveBrowserConfig(env).attach ? "attached" : true } : {},
|
|
8953
9318
|
...opts.webSearchHost ? { searchGuide: true } : {}
|
|
8954
9319
|
};
|
|
8955
9320
|
return {
|
|
@@ -8967,7 +9332,7 @@ async function createBazilionSession(opts) {
|
|
|
8967
9332
|
const { agent, paths } = opts;
|
|
8968
9333
|
const { providerName, modelId } = parseModelString(agent.model);
|
|
8969
9334
|
if (!existsSync14(agent.team.path)) mkdirSync10(agent.team.path, { recursive: true });
|
|
8970
|
-
mkdirSync10(
|
|
9335
|
+
mkdirSync10(join21(paths.agentDir(agent.agent.id), "sessions"), { recursive: true });
|
|
8971
9336
|
const sessionManager = openConversation(agent, paths, opts.conversation);
|
|
8972
9337
|
const turn = turnSurface(opts);
|
|
8973
9338
|
return openPiSession({
|
|
@@ -8979,7 +9344,7 @@ async function createBazilionSession(opts) {
|
|
|
8979
9344
|
},
|
|
8980
9345
|
reasoningLevel: agent.reasoningLevel,
|
|
8981
9346
|
cwd: turn.modelCwd,
|
|
8982
|
-
piAgentDir:
|
|
9347
|
+
piAgentDir: join21(paths.home, "pi"),
|
|
8983
9348
|
sessionManager,
|
|
8984
9349
|
appendSystemPrompt: buildSystemPrompt(agent, turn.promptOptions),
|
|
8985
9350
|
agentsFiles: (opts.repositoryInstructions ?? []).map((file) => ({
|
|
@@ -9037,7 +9402,7 @@ function toPiThinkingLevel(level) {
|
|
|
9037
9402
|
}
|
|
9038
9403
|
}
|
|
9039
9404
|
function openConversation(agent, paths, target) {
|
|
9040
|
-
const sessionDir =
|
|
9405
|
+
const sessionDir = join21(paths.agentDir(agent.agent.id), "sessions");
|
|
9041
9406
|
return SessionManager.open(
|
|
9042
9407
|
explicitConversationFile(sessionDir, target),
|
|
9043
9408
|
sessionDir,
|
|
@@ -9046,13 +9411,13 @@ function openConversation(agent, paths, target) {
|
|
|
9046
9411
|
}
|
|
9047
9412
|
function loadInitialMessages(agent, paths, target) {
|
|
9048
9413
|
if (!target) return [];
|
|
9049
|
-
const entries = readSessionFile(
|
|
9414
|
+
const entries = readSessionFile(join21(paths.agentDir(agent.agent.id), "sessions"), target.id);
|
|
9050
9415
|
return buildSessionContext(entries.filter((entry) => entry.type !== "session")).messages;
|
|
9051
9416
|
}
|
|
9052
9417
|
function loadSessionMessages(agent, paths, sessionId) {
|
|
9053
9418
|
if (!/^[A-Za-z0-9._-]+$/.test(sessionId)) return [];
|
|
9054
|
-
const sessionDir =
|
|
9055
|
-
const file =
|
|
9419
|
+
const sessionDir = join21(paths.agentDir(agent.agent.id), "sessions");
|
|
9420
|
+
const file = join21(sessionDir, `${sessionId}.jsonl`);
|
|
9056
9421
|
if (!existsSync14(file) || !existsSync14(agent.team.path)) return [];
|
|
9057
9422
|
try {
|
|
9058
9423
|
return SessionManager.open(file, sessionDir).buildSessionContext().messages;
|
|
@@ -9061,7 +9426,7 @@ function loadSessionMessages(agent, paths, sessionId) {
|
|
|
9061
9426
|
}
|
|
9062
9427
|
}
|
|
9063
9428
|
function loadSessionHead(agent, paths, target) {
|
|
9064
|
-
const sessionDir =
|
|
9429
|
+
const sessionDir = join21(paths.agentDir(agent.agent.id), "sessions");
|
|
9065
9430
|
if (!existsSync14(sessionDir)) return { file: null, size: 0 };
|
|
9066
9431
|
const recent = target ? explicitConversationFile(sessionDir, target) : null;
|
|
9067
9432
|
if (!recent) return { file: null, size: 0 };
|
|
@@ -9075,7 +9440,7 @@ function loadSessionHead(agent, paths, target) {
|
|
|
9075
9440
|
function explicitConversationFile(directory, target) {
|
|
9076
9441
|
if (!target) throw new Error("Explicit conversation target is required");
|
|
9077
9442
|
readSessionHeader(directory, target.id);
|
|
9078
|
-
return
|
|
9443
|
+
return join21(directory, `${target.id}.jsonl`);
|
|
9079
9444
|
}
|
|
9080
9445
|
|
|
9081
9446
|
// ../daemon/src/runtime/providers/catalog.ts
|
|
@@ -9105,7 +9470,7 @@ async function listCatalogModels(providerName, env = process.env, signal) {
|
|
|
9105
9470
|
}
|
|
9106
9471
|
|
|
9107
9472
|
// ../daemon/src/runtime/worker/spawn.ts
|
|
9108
|
-
import { spawn as
|
|
9473
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
9109
9474
|
import { existsSync as existsSync15 } from "node:fs";
|
|
9110
9475
|
import { isAbsolute as isAbsolute6 } from "node:path";
|
|
9111
9476
|
import { fileURLToPath } from "node:url";
|
|
@@ -9192,7 +9557,7 @@ async function* runWorker(run) {
|
|
|
9192
9557
|
if (!isAbsolute6(workerEntry)) throw new Error("worker entry path must be absolute");
|
|
9193
9558
|
const serializedInput = JSON.stringify(run.input);
|
|
9194
9559
|
opts.signal?.throwIfAborted();
|
|
9195
|
-
const child =
|
|
9560
|
+
const child = spawn4(process.execPath, workerSpawnArgs(workerEntry), {
|
|
9196
9561
|
env: run.env,
|
|
9197
9562
|
detached: true,
|
|
9198
9563
|
stdio: ["pipe", "pipe", "pipe", "ipc"]
|
|
@@ -10901,7 +11266,7 @@ function mirrorTypingStop(agentId) {
|
|
|
10901
11266
|
// ../daemon/src/lib/attachments.ts
|
|
10902
11267
|
import { randomUUID as randomUUID17 } from "node:crypto";
|
|
10903
11268
|
import { closeSync as closeSync5, constants as constants6, fstatSync as fstatSync5, openSync as openSync5, writeFileSync as writeFileSync8 } from "node:fs";
|
|
10904
|
-
import { join as
|
|
11269
|
+
import { join as join22, posix as posix2 } from "node:path";
|
|
10905
11270
|
var MAX_FILE_BYTES = 25 * 1024 * 1024;
|
|
10906
11271
|
function safeName(name) {
|
|
10907
11272
|
const base = name.split(/[\\/]/).pop() ?? "file";
|
|
@@ -10913,7 +11278,7 @@ function fmtBytes(n) {
|
|
|
10913
11278
|
return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
10914
11279
|
}
|
|
10915
11280
|
function prepareInputFilesDirectory(agentDir2) {
|
|
10916
|
-
return ensureContainedRealDirectory(
|
|
11281
|
+
return ensureContainedRealDirectory(join22(agentDir2, "uploads"), agentDir2, { create: true });
|
|
10917
11282
|
}
|
|
10918
11283
|
function saveInputFiles(agentDir2, files, options = {}) {
|
|
10919
11284
|
if (!files || files.length === 0) return "";
|
|
@@ -10927,7 +11292,7 @@ function saveInputFiles(agentDir2, files, options = {}) {
|
|
|
10927
11292
|
continue;
|
|
10928
11293
|
}
|
|
10929
11294
|
const filename = `${randomUUID17().slice(0, 8)}-${safeName(label)}`;
|
|
10930
|
-
const path =
|
|
11295
|
+
const path = join22(dir, filename);
|
|
10931
11296
|
let fd;
|
|
10932
11297
|
try {
|
|
10933
11298
|
fd = openSync5(
|
|
@@ -10950,7 +11315,7 @@ function saveInputFiles(agentDir2, files, options = {}) {
|
|
|
10950
11315
|
|
|
10951
11316
|
// ../daemon/src/lib/coding-environment.ts
|
|
10952
11317
|
import { lstatSync as lstatSync5 } from "node:fs";
|
|
10953
|
-
import { join as
|
|
11318
|
+
import { join as join23 } from "node:path";
|
|
10954
11319
|
|
|
10955
11320
|
// ../daemon/src/core/coding-environment/config.ts
|
|
10956
11321
|
var CodingEnvironmentValidationError = class extends DomainError {
|
|
@@ -11007,7 +11372,7 @@ function setTeamCodingEnvironment(db, team, input, env = process.env) {
|
|
|
11007
11372
|
const environment = validateCodingEnvironment(input);
|
|
11008
11373
|
let path = team.path;
|
|
11009
11374
|
for (const part of environment.cwd === "." ? [] : environment.cwd.split("/")) {
|
|
11010
|
-
path =
|
|
11375
|
+
path = join23(path, part);
|
|
11011
11376
|
if (!lstatSync5(path, { throwIfNoEntry: false })?.isDirectory())
|
|
11012
11377
|
throw new CodingEnvironmentValidationError(
|
|
11013
11378
|
"The directory must be an existing directory inside the Team"
|
|
@@ -11028,17 +11393,17 @@ function dockerTurn(db, paths, agent, env) {
|
|
|
11028
11393
|
// ../daemon/src/lib/conversation-target.ts
|
|
11029
11394
|
import { randomUUID as randomUUID18 } from "node:crypto";
|
|
11030
11395
|
import { writeFileSync as writeFileSync9 } from "node:fs";
|
|
11031
|
-
import { join as
|
|
11396
|
+
import { join as join24 } from "node:path";
|
|
11032
11397
|
import { SessionManager as SessionManager2 } from "@earendil-works/pi-coding-agent";
|
|
11033
11398
|
function sessionsDir(paths, agentId) {
|
|
11034
|
-
return
|
|
11399
|
+
return join24(paths.agentDir(agentId), "sessions");
|
|
11035
11400
|
}
|
|
11036
11401
|
function startConversation(db, paths, agentId, title) {
|
|
11037
11402
|
const agent = resolveAgent(db, paths, agentId);
|
|
11038
11403
|
if (title !== void 0) validTitle(title);
|
|
11039
11404
|
const id = randomUUID18();
|
|
11040
11405
|
const header = SessionManager2.inMemory(agent.team.path, { id }).getHeader();
|
|
11041
|
-
writeFileSync9(
|
|
11406
|
+
writeFileSync9(join24(sessionsDir(paths, agentId), `${id}.jsonl`), `${JSON.stringify(header)}
|
|
11042
11407
|
`, {
|
|
11043
11408
|
flag: "wx",
|
|
11044
11409
|
mode: 384
|
|
@@ -11058,7 +11423,7 @@ function selectedConversationTarget(db, agentId) {
|
|
|
11058
11423
|
|
|
11059
11424
|
// ../daemon/src/lib/repository-instructions.ts
|
|
11060
11425
|
import { realpathSync as realpathSync6 } from "node:fs";
|
|
11061
|
-
import { join as
|
|
11426
|
+
import { join as join25 } from "node:path";
|
|
11062
11427
|
var MAX_FILE_BYTES2 = 128 * 1024;
|
|
11063
11428
|
var SKIPPED = {
|
|
11064
11429
|
outside: "it resolves outside the Team workspace",
|
|
@@ -11078,7 +11443,7 @@ function loadRepositoryInstructions(root, cwd = ".") {
|
|
|
11078
11443
|
for (let depth = 0; depth <= parts.length; depth++) {
|
|
11079
11444
|
const path = [...parts.slice(0, depth), "AGENTS.md"].join("/");
|
|
11080
11445
|
try {
|
|
11081
|
-
const content = readContainedFile(
|
|
11446
|
+
const content = readContainedFile(join25(realRoot, path), realRoot, MAX_FILE_BYTES2);
|
|
11082
11447
|
instructions.push({ path, content: content.toString("utf8") });
|
|
11083
11448
|
} catch (error) {
|
|
11084
11449
|
if (error instanceof ContainedFileError) {
|
|
@@ -11716,7 +12081,7 @@ agentChatRouter.post("/:id/chat/compact", async (c) => {
|
|
|
11716
12081
|
const { db, paths, authToken } = getCtx();
|
|
11717
12082
|
const resolved = resolveAgent(db, paths, id);
|
|
11718
12083
|
assertProviderReady(db, authToken, resolved.model);
|
|
11719
|
-
const memory = qmdBackend(
|
|
12084
|
+
const memory = qmdBackend(join26(resolved.team.path, "memory"));
|
|
11720
12085
|
await memory.init();
|
|
11721
12086
|
const handle12 = await createBazilionSession({
|
|
11722
12087
|
agent: resolved,
|
|
@@ -11774,9 +12139,9 @@ agentChatRouter.get(
|
|
|
11774
12139
|
const env = mergeSecretsIntoEnv(db, authToken);
|
|
11775
12140
|
const files = [];
|
|
11776
12141
|
for (const file of CONTEXT_FILE_ORDER2) {
|
|
11777
|
-
const path =
|
|
12142
|
+
const path = join26(resolved.agent.dir, file);
|
|
11778
12143
|
if (!existsSync16(path)) continue;
|
|
11779
|
-
const content =
|
|
12144
|
+
const content = readFileSync10(path, "utf8").trimEnd();
|
|
11780
12145
|
if (!content) continue;
|
|
11781
12146
|
const chars = content.length + file.length + 6;
|
|
11782
12147
|
files.push({ name: file, chars, tokens: estimateTokens2(chars) });
|
|
@@ -11789,7 +12154,7 @@ agentChatRouter.get(
|
|
|
11789
12154
|
agent: resolved,
|
|
11790
12155
|
paths,
|
|
11791
12156
|
env,
|
|
11792
|
-
memory: qmdBackend(
|
|
12157
|
+
memory: qmdBackend(join26(resolved.team.path, "memory")),
|
|
11793
12158
|
messagingHost: createDbMessagingHost(db),
|
|
11794
12159
|
userMdHost: createDbUserMdHost(db, paths),
|
|
11795
12160
|
fileSink: reportOnly,
|
|
@@ -11819,7 +12184,7 @@ agentChatRouter.get(
|
|
|
11819
12184
|
let blockChars = name.length + 2;
|
|
11820
12185
|
if (match) {
|
|
11821
12186
|
try {
|
|
11822
|
-
blockChars =
|
|
12187
|
+
blockChars = readFileSync10(match.skillFile, "utf8").length;
|
|
11823
12188
|
} catch {
|
|
11824
12189
|
}
|
|
11825
12190
|
}
|
|
@@ -11893,7 +12258,7 @@ agentChatRouter.post("/:id/chat/truncate", async (c) => {
|
|
|
11893
12258
|
});
|
|
11894
12259
|
|
|
11895
12260
|
// ../daemon/src/routes/agent-learning.ts
|
|
11896
|
-
import { join as
|
|
12261
|
+
import { join as join27 } from "node:path";
|
|
11897
12262
|
|
|
11898
12263
|
// ../daemon/src/lib/lesson-decisions.ts
|
|
11899
12264
|
var LessonProposalConflictError = class extends DomainError {
|
|
@@ -12092,7 +12457,7 @@ for (const decision of ["approve", "reject", "revoke"]) {
|
|
|
12092
12457
|
const team = teams_exports.get(db, agent.teamId, paths);
|
|
12093
12458
|
if (!team) return c.json({ error: `team not found: ${agent.teamId}` }, 404);
|
|
12094
12459
|
const proposal = await runAgentLifecycleMutation(agent.id, async () => {
|
|
12095
|
-
const memory = qmdBackend(
|
|
12460
|
+
const memory = qmdBackend(join27(team.path, "memory"));
|
|
12096
12461
|
if (decision === "approve") return approveLessonProposal(db, memory, current2.id, version);
|
|
12097
12462
|
if (decision === "reject") return rejectLessonProposal(db, current2.id, version);
|
|
12098
12463
|
return revokeLessonProposal(db, memory, current2.id, version);
|
|
@@ -12120,7 +12485,7 @@ function withEvidenceExcerpts(proposals, agent, paths) {
|
|
|
12120
12485
|
}
|
|
12121
12486
|
|
|
12122
12487
|
// ../daemon/src/routes/agents.ts
|
|
12123
|
-
import { join as
|
|
12488
|
+
import { join as join28 } from "node:path";
|
|
12124
12489
|
init_pool2();
|
|
12125
12490
|
|
|
12126
12491
|
// ../daemon/src/lib/telegram/config.ts
|
|
@@ -12395,7 +12760,7 @@ agentsRouter.get("/", (c) => {
|
|
|
12395
12760
|
const includeArchived = c.req.query("includeArchived") === "true";
|
|
12396
12761
|
const agents = agents_exports.list(getCtx().db, { includeArchived }).map((agent) => ({
|
|
12397
12762
|
...agent,
|
|
12398
|
-
identity: loadIdentityFromFile(
|
|
12763
|
+
identity: loadIdentityFromFile(join28(agent.dir, "IDENTITY.md"))
|
|
12399
12764
|
}));
|
|
12400
12765
|
return c.json(agents);
|
|
12401
12766
|
});
|
|
@@ -12529,7 +12894,7 @@ attentionRouter.delete(
|
|
|
12529
12894
|
import { deleteCookie, setCookie } from "hono/cookie";
|
|
12530
12895
|
|
|
12531
12896
|
// ../daemon/src/lib/openai-oauth-prompt.ts
|
|
12532
|
-
import { spawn as
|
|
12897
|
+
import { spawn as spawn5 } from "node:child_process";
|
|
12533
12898
|
import { createServer as createServer2 } from "node:net";
|
|
12534
12899
|
var OPENAI_CODEX_CALLBACK_PORT = 1455;
|
|
12535
12900
|
var WEB_OPENAI_LOGIN_TIMEOUT_MS = 10 * 6e4;
|
|
@@ -12561,7 +12926,7 @@ function launchOpenAICodexBrowser(url, onFailure) {
|
|
|
12561
12926
|
`Could not open the OpenAI sign-in page with ${command}: ${detail}. Run ${DEVICE_CODE_FALLBACK}.`
|
|
12562
12927
|
)
|
|
12563
12928
|
);
|
|
12564
|
-
const child =
|
|
12929
|
+
const child = spawn5(command, [url], { stdio: "ignore", detached: true });
|
|
12565
12930
|
child.once("error", (error) => fail2(error.message));
|
|
12566
12931
|
child.once("exit", (code, signal) => {
|
|
12567
12932
|
if (code !== 0) fail2(code === null ? `terminated by ${signal}` : `exited ${code}`);
|
|
@@ -13155,24 +13520,24 @@ agentMessagesRouter.post("/:id/messages", async (c) => {
|
|
|
13155
13520
|
|
|
13156
13521
|
// ../daemon/src/routes/misc.ts
|
|
13157
13522
|
import { existsSync as existsSync17 } from "node:fs";
|
|
13158
|
-
import { homedir as
|
|
13159
|
-
import { join as
|
|
13523
|
+
import { homedir as homedir4 } from "node:os";
|
|
13524
|
+
import { join as join31 } from "node:path";
|
|
13160
13525
|
|
|
13161
13526
|
// ../daemon/src/lib/backup.ts
|
|
13162
13527
|
import { mkdtempSync as mkdtempSync3, rmSync as rmSync13 } from "node:fs";
|
|
13163
13528
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
13164
|
-
import { join as
|
|
13529
|
+
import { join as join30, resolve as resolve7 } from "node:path";
|
|
13165
13530
|
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
13166
13531
|
import { create as create6 } from "tar";
|
|
13167
13532
|
|
|
13168
13533
|
// ../daemon/src/lib/daemon-liveness.ts
|
|
13169
|
-
import { mkdirSync as mkdirSync11, readFileSync as
|
|
13170
|
-
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";
|
|
13171
13536
|
var DAEMON_PID_FILE = "daemon.pid";
|
|
13172
13537
|
function runningDaemonPid(home) {
|
|
13173
13538
|
let pid;
|
|
13174
13539
|
try {
|
|
13175
|
-
pid = Number.parseInt(
|
|
13540
|
+
pid = Number.parseInt(readFileSync11(join29(home, DAEMON_PID_FILE), "utf8"), 10);
|
|
13176
13541
|
} catch (error) {
|
|
13177
13542
|
if (error.code === "ENOENT") return null;
|
|
13178
13543
|
throw error;
|
|
@@ -13189,12 +13554,12 @@ function assertDaemonStopped(home) {
|
|
|
13189
13554
|
const pid = runningDaemonPid(home);
|
|
13190
13555
|
if (pid !== null) {
|
|
13191
13556
|
throw new Error(
|
|
13192
|
-
`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)})`
|
|
13193
13558
|
);
|
|
13194
13559
|
}
|
|
13195
13560
|
}
|
|
13196
13561
|
function claimDaemonPidFile(home) {
|
|
13197
|
-
const path =
|
|
13562
|
+
const path = join29(home, DAEMON_PID_FILE);
|
|
13198
13563
|
const content = `${process.pid}
|
|
13199
13564
|
`;
|
|
13200
13565
|
mkdirSync11(home, { recursive: true });
|
|
@@ -13208,7 +13573,7 @@ function claimDaemonPidFile(home) {
|
|
|
13208
13573
|
}
|
|
13209
13574
|
return () => {
|
|
13210
13575
|
try {
|
|
13211
|
-
if (
|
|
13576
|
+
if (readFileSync11(path, "utf8") === content) rmSync12(path);
|
|
13212
13577
|
} catch {
|
|
13213
13578
|
}
|
|
13214
13579
|
};
|
|
@@ -13223,10 +13588,10 @@ function createBackupSnapshot(db) {
|
|
|
13223
13588
|
return snapshot2;
|
|
13224
13589
|
}
|
|
13225
13590
|
async function takeSnapshot(db) {
|
|
13226
|
-
const directory = mkdtempSync3(
|
|
13591
|
+
const directory = mkdtempSync3(join30(tmpdir3(), "bazilion-backup-"));
|
|
13227
13592
|
const cleanup = () => rmSync13(directory, { recursive: true, force: true });
|
|
13228
13593
|
try {
|
|
13229
|
-
const database =
|
|
13594
|
+
const database = join30(directory, "bazilion.snapshot");
|
|
13230
13595
|
await db.backupTo(database);
|
|
13231
13596
|
const snapshot2 = new DatabaseSync2(database, { readOnly: true });
|
|
13232
13597
|
try {
|
|
@@ -13325,7 +13690,7 @@ miscRouter.get("/health/details", async (c) => {
|
|
|
13325
13690
|
} catch {
|
|
13326
13691
|
}
|
|
13327
13692
|
}
|
|
13328
|
-
const openclawSkillsDir =
|
|
13693
|
+
const openclawSkillsDir = join31(homedir4(), ".openclaw", "skills");
|
|
13329
13694
|
const providerSection = {
|
|
13330
13695
|
// Hosted providers with credentials; local servers are reported below.
|
|
13331
13696
|
configured: PROVIDERS.filter(
|
|
@@ -13733,8 +14098,8 @@ notificationsRouter.put("/", async (c) => {
|
|
|
13733
14098
|
});
|
|
13734
14099
|
|
|
13735
14100
|
// ../daemon/src/routes/profiles.ts
|
|
13736
|
-
import { existsSync as existsSync18, readFileSync as
|
|
13737
|
-
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";
|
|
13738
14103
|
var profilesRouter = newRouter();
|
|
13739
14104
|
profilesRouter.get("/", (c) => {
|
|
13740
14105
|
const { db } = getCtx();
|
|
@@ -13817,13 +14182,13 @@ function profileFile(c) {
|
|
|
13817
14182
|
if (!PROFILE_FILES.includes(file)) {
|
|
13818
14183
|
return c.json({ error: `unsupported file: ${file}` }, 400);
|
|
13819
14184
|
}
|
|
13820
|
-
return
|
|
14185
|
+
return join32(paths.profilesDir, id, file);
|
|
13821
14186
|
}
|
|
13822
14187
|
profilesRouter.get("/:id/files/:file", (c) => {
|
|
13823
14188
|
const path = profileFile(c);
|
|
13824
14189
|
if (typeof path !== "string") return path;
|
|
13825
14190
|
if (!existsSync18(path)) return c.json({ error: `file not present: ${c.req.param("file")}` }, 404);
|
|
13826
|
-
return c.json({ content:
|
|
14191
|
+
return c.json({ content: readFileSync12(path, "utf8") });
|
|
13827
14192
|
});
|
|
13828
14193
|
profilesRouter.put("/:id/files/:file", async (c) => {
|
|
13829
14194
|
const body = await jsonBody(c);
|
|
@@ -13957,8 +14322,8 @@ shellApprovalsRouter.post("/:id", async (c) => {
|
|
|
13957
14322
|
|
|
13958
14323
|
// ../daemon/src/routes/skills.ts
|
|
13959
14324
|
import { mkdtempSync as mkdtempSync4, rmSync as rmSync14, writeFileSync as writeFileSync12 } from "node:fs";
|
|
13960
|
-
import { homedir as
|
|
13961
|
-
import { join as
|
|
14325
|
+
import { homedir as homedir5, tmpdir as tmpdir4 } from "node:os";
|
|
14326
|
+
import { join as join33 } from "node:path";
|
|
13962
14327
|
var MAX_ZIP_BYTES = 50 * 1024 * 1024;
|
|
13963
14328
|
var skillsRouter = newRouter();
|
|
13964
14329
|
skillsRouter.get("/", (c) => {
|
|
@@ -14051,8 +14416,8 @@ async function parseImportInput(request) {
|
|
|
14051
14416
|
if (!filename.toLowerCase().endsWith(".zip")) {
|
|
14052
14417
|
throw new Error("uploaded file must be a .zip archive");
|
|
14053
14418
|
}
|
|
14054
|
-
const tmpDir = mkdtempSync4(
|
|
14055
|
-
const zipPath =
|
|
14419
|
+
const tmpDir = mkdtempSync4(join33(tmpdir4(), "bazilion-skill-upload-"));
|
|
14420
|
+
const zipPath = join33(tmpDir, filename.replace(/[^\w.-]+/g, "_"));
|
|
14056
14421
|
const buf = Buffer.from(await file.arrayBuffer());
|
|
14057
14422
|
writeFileSync12(zipPath, buf);
|
|
14058
14423
|
const forceField = form.get("force");
|
|
@@ -14068,7 +14433,7 @@ async function parseImportInput(request) {
|
|
|
14068
14433
|
const { source } = body;
|
|
14069
14434
|
if (typeof source !== "string" || !source) throw new Error("source is required");
|
|
14070
14435
|
return {
|
|
14071
|
-
source: source === "openclaw" ?
|
|
14436
|
+
source: source === "openclaw" ? join33(homedir5(), ".openclaw", "skills") : source,
|
|
14072
14437
|
force: Boolean(body.force),
|
|
14073
14438
|
tempZipPath: null,
|
|
14074
14439
|
sourceLabel: source
|
|
@@ -14138,7 +14503,7 @@ teamCodingEnvironmentRouter.put("/:id/coding-environment", async (c) => {
|
|
|
14138
14503
|
});
|
|
14139
14504
|
|
|
14140
14505
|
// ../daemon/src/routes/team-memory.ts
|
|
14141
|
-
import { join as
|
|
14506
|
+
import { join as join34 } from "node:path";
|
|
14142
14507
|
var teamMemoryRouter = newRouter();
|
|
14143
14508
|
teamMemoryRouter.onError((error, c) => {
|
|
14144
14509
|
const safe = sanitizeNativeModuleError(error, { subject: "Bazilion memory" });
|
|
@@ -14146,7 +14511,7 @@ teamMemoryRouter.onError((error, c) => {
|
|
|
14146
14511
|
return onRouteError(safe, c);
|
|
14147
14512
|
});
|
|
14148
14513
|
async function openMemory(c) {
|
|
14149
|
-
const mem = qmdBackend(
|
|
14514
|
+
const mem = qmdBackend(join34(routeTeam(c).path, "memory"));
|
|
14150
14515
|
await mem.init();
|
|
14151
14516
|
return mem;
|
|
14152
14517
|
}
|
|
@@ -14212,7 +14577,7 @@ import {
|
|
|
14212
14577
|
readSync as readSync3,
|
|
14213
14578
|
realpathSync as realpathSync7
|
|
14214
14579
|
} from "node:fs";
|
|
14215
|
-
import { join as
|
|
14580
|
+
import { join as join35 } from "node:path";
|
|
14216
14581
|
var hash = (value) => createHash6("sha256").update(value).digest("hex");
|
|
14217
14582
|
var ContextReadError = class extends Error {
|
|
14218
14583
|
code;
|
|
@@ -14250,12 +14615,12 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
14250
14615
|
this.parent = parent;
|
|
14251
14616
|
if (parent) component(registeredPath);
|
|
14252
14617
|
parent?.assertOpen();
|
|
14253
|
-
const canonicalPath = parent ?
|
|
14618
|
+
const canonicalPath = parent ? join35(parent.canonicalPath, registeredPath) : realpathSync7(registeredPath);
|
|
14254
14619
|
this.canonicalPath = canonicalPath;
|
|
14255
14620
|
let fd;
|
|
14256
14621
|
try {
|
|
14257
14622
|
fd = openSync6(
|
|
14258
|
-
parent ?
|
|
14623
|
+
parent ? join35(parent.path, registeredPath) : canonicalPath,
|
|
14259
14624
|
constants7.O_RDONLY | constants7.O_DIRECTORY | constants7.O_NOFOLLOW
|
|
14260
14625
|
);
|
|
14261
14626
|
const stat = fstatSync6(fd, { bigint: true });
|
|
@@ -14293,7 +14658,7 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
14293
14658
|
component(name);
|
|
14294
14659
|
this.assertOpen();
|
|
14295
14660
|
try {
|
|
14296
|
-
return lstatSync6(
|
|
14661
|
+
return lstatSync6(join35(this.path, name));
|
|
14297
14662
|
} catch (error) {
|
|
14298
14663
|
if (error.code === "ENOENT") return null;
|
|
14299
14664
|
throw new ContextReadError("unreadable");
|
|
@@ -14301,7 +14666,7 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
14301
14666
|
}
|
|
14302
14667
|
observe(name) {
|
|
14303
14668
|
try {
|
|
14304
|
-
return lstatSync6(
|
|
14669
|
+
return lstatSync6(join35(this.path, name), { bigint: true });
|
|
14305
14670
|
} catch (error) {
|
|
14306
14671
|
if (error.code === "ENOENT") return null;
|
|
14307
14672
|
throw new ContextReadError("unreadable");
|
|
@@ -14342,7 +14707,7 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
14342
14707
|
let fd;
|
|
14343
14708
|
try {
|
|
14344
14709
|
fd = openSync6(
|
|
14345
|
-
|
|
14710
|
+
join35(this.path, name),
|
|
14346
14711
|
constants7.O_RDONLY | constants7.O_NOFOLLOW | constants7.O_NONBLOCK
|
|
14347
14712
|
);
|
|
14348
14713
|
const before = fstatSync6(fd, { bigint: true });
|
|
@@ -14368,7 +14733,7 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
14368
14733
|
}
|
|
14369
14734
|
validate(skipGit = false, names) {
|
|
14370
14735
|
this.assertOpen();
|
|
14371
|
-
const currentPath = this.parent ?
|
|
14736
|
+
const currentPath = this.parent ? join35(this.parent.path, this.registeredPath) : realpathSync7(this.registeredPath);
|
|
14372
14737
|
const stat = lstatSync6(currentPath, { bigint: true });
|
|
14373
14738
|
if (!stat.isDirectory() || identity(stat) !== identity(this.originalIdentity))
|
|
14374
14739
|
throw new ContextReadError("root_changed");
|
|
@@ -14796,7 +15161,7 @@ async function readOrNull(captured, args) {
|
|
|
14796
15161
|
import { execFile } from "node:child_process";
|
|
14797
15162
|
import { mkdirSync as mkdirSync12, mkdtempSync as mkdtempSync5, rmSync as rmSync15, writeFileSync as writeFileSync13 } from "node:fs";
|
|
14798
15163
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
14799
|
-
import { join as
|
|
15164
|
+
import { join as join36 } from "node:path";
|
|
14800
15165
|
var INSPECTION_BUDGET_MS = 5e3;
|
|
14801
15166
|
var METADATA_BUDGET_MS = 2500;
|
|
14802
15167
|
var METADATA_BYTES = 64 * 1024 * 1024;
|
|
@@ -14825,7 +15190,7 @@ async function captureRepositoryGit(root, budgetMs = INSPECTION_BUDGET_MS) {
|
|
|
14825
15190
|
const dir = git.directory("info");
|
|
14826
15191
|
if (dir.entry("sparse-checkout")) throw new ContextReadError("unsupported_git_metadata");
|
|
14827
15192
|
}
|
|
14828
|
-
const scratch = mkdtempSync5(
|
|
15193
|
+
const scratch = mkdtempSync5(join36(tmpdir5(), "bazilion-context-git-"));
|
|
14829
15194
|
let cleaned = false;
|
|
14830
15195
|
const cleanup = () => {
|
|
14831
15196
|
if (cleaned) return;
|
|
@@ -14886,7 +15251,7 @@ async function captureRepositoryGit(root, budgetMs = INSPECTION_BUDGET_MS) {
|
|
|
14886
15251
|
if (capturedConfig) {
|
|
14887
15252
|
bytes += capturedConfig.length;
|
|
14888
15253
|
count++;
|
|
14889
|
-
const configPath =
|
|
15254
|
+
const configPath = join36(scratch, "captured-config");
|
|
14890
15255
|
writeFileSync13(configPath, capturedConfig, { mode: 384 });
|
|
14891
15256
|
const config = await rawGit([
|
|
14892
15257
|
"config",
|
|
@@ -14939,8 +15304,8 @@ objectformat = ${value}`
|
|
|
14939
15304
|
const exclude = git.directory("info").read("exclude", METADATA_READ);
|
|
14940
15305
|
if (exclude) {
|
|
14941
15306
|
bytes += exclude.length;
|
|
14942
|
-
mkdirSync12(
|
|
14943
|
-
writeFileSync13(
|
|
15307
|
+
mkdirSync12(join36(scratch, "info"), { mode: 448 });
|
|
15308
|
+
writeFileSync13(join36(scratch, "info", "exclude"), exclude, { mode: 384 });
|
|
14944
15309
|
}
|
|
14945
15310
|
}
|
|
14946
15311
|
const copy = (source, destination, depth) => {
|
|
@@ -14953,13 +15318,13 @@ objectformat = ${value}`
|
|
|
14953
15318
|
if (name === "alternates" || name === "http-alternates")
|
|
14954
15319
|
throw new ContextReadError("unsupported_git_metadata");
|
|
14955
15320
|
if (entry.isDirectory()) {
|
|
14956
|
-
mkdirSync12(
|
|
14957
|
-
copy(source.directory(name),
|
|
15321
|
+
mkdirSync12(join36(destination, name), { mode: 448 });
|
|
15322
|
+
copy(source.directory(name), join36(destination, name), depth + 1);
|
|
14958
15323
|
} else {
|
|
14959
15324
|
const content = source.read(name, METADATA_BYTES - bytes);
|
|
14960
15325
|
if (!content) throw new ContextReadError("source_changed");
|
|
14961
15326
|
bytes += content.length;
|
|
14962
|
-
writeFileSync13(
|
|
15327
|
+
writeFileSync13(join36(destination, name), content, { mode: 384 });
|
|
14963
15328
|
}
|
|
14964
15329
|
}
|
|
14965
15330
|
};
|
|
@@ -14968,16 +15333,16 @@ objectformat = ${value}`
|
|
|
14968
15333
|
if (content) {
|
|
14969
15334
|
count++;
|
|
14970
15335
|
bytes += content.length;
|
|
14971
|
-
writeFileSync13(
|
|
15336
|
+
writeFileSync13(join36(scratch, name), content, { mode: 384 });
|
|
14972
15337
|
}
|
|
14973
15338
|
}
|
|
14974
15339
|
for (const name of ["refs", "objects"]) {
|
|
14975
|
-
mkdirSync12(
|
|
14976
|
-
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);
|
|
14977
15342
|
}
|
|
14978
15343
|
if (git.list().some((name) => name.startsWith("sharedindex.")))
|
|
14979
15344
|
throw new ContextReadError("unsupported_git_metadata");
|
|
14980
|
-
writeFileSync13(
|
|
15345
|
+
writeFileSync13(join36(scratch, "config"), `${configLines.join("\n")}
|
|
14981
15346
|
`, { mode: 384 });
|
|
14982
15347
|
const validate2 = () => git.validate();
|
|
14983
15348
|
validate2();
|
|
@@ -17180,6 +17545,7 @@ function createApp() {
|
|
|
17180
17545
|
}
|
|
17181
17546
|
|
|
17182
17547
|
// ../daemon/src/index.ts
|
|
17548
|
+
init_install();
|
|
17183
17549
|
init_resources();
|
|
17184
17550
|
|
|
17185
17551
|
// ../daemon/src/lib/review-provider.ts
|
|
@@ -17794,6 +18160,9 @@ var server2 = serve({ fetch: app.fetch, hostname: host2, port }, (info) => {
|
|
|
17794
18160
|
maybeStartTelegramBot(db, authToken).catch((err) => {
|
|
17795
18161
|
console.error("telegram: background start failed:", err instanceof Error ? err.message : err);
|
|
17796
18162
|
});
|
|
18163
|
+
const env = mergeSecretsIntoEnv(db, authToken);
|
|
18164
|
+
const browser = resolveBrowserConfig(env);
|
|
18165
|
+
if (isBrowserEnabled(env) && !browser.attach) prepareBrowser(browser.executablePath);
|
|
17797
18166
|
});
|
|
17798
18167
|
var shutdown = (signal) => {
|
|
17799
18168
|
if (shuttingDown) return;
|