bazilion 0.57.1 → 0.58.1
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 +392 -92
- package/dist/cli.js.map +1 -1
- package/dist/daemon.js +674 -259
- package/dist/daemon.js.map +1 -1
- package/dist/web/client/assets/AddProviderDialog-DIxB5CRz.js +1 -0
- package/dist/web/client/assets/AgentTemplateParts-B9JD9mno.js +1 -0
- package/dist/web/client/assets/ConfirmDialog-D-Qk9p6V.js +1 -0
- package/dist/web/client/assets/ConnectionsView-Dfbn7vfB.js +1 -0
- package/dist/web/client/assets/SkillsParts-DN_JvpRU.js +1 -0
- package/dist/web/client/assets/SpawnTeamModal-Btj3My2v.js +1 -0
- package/dist/web/client/assets/TeamForm-BX_68QZQ.js +1 -0
- package/dist/web/client/assets/TeamThread-CJXudrt6.js +1 -0
- package/dist/web/client/assets/{UnsavedChangesGuard-CYz0AopL.js → UnsavedChangesGuard-B_e5_ck_.js} +1 -1
- package/dist/web/client/assets/_id-BJt13p-G.js +1 -0
- package/dist/web/client/assets/_id-DoP6Mlct.js +1 -0
- package/dist/web/client/assets/{access-BGtASxet.js → access-DnkUj0iM.js} +1 -1
- package/dist/web/client/assets/{agents-BAODfMcm.js → agents-CrfF2ZOS.js} +1 -1
- package/dist/web/client/assets/agents-Cv07gKT0.js +1 -0
- package/dist/web/client/assets/{attention-BIC0TL8d.js → attention-TQpP915m.js} +1 -1
- package/dist/web/client/assets/config-CKPln0Ng.js +1 -0
- package/dist/web/client/assets/index-Bwz8tnmS.js +14 -0
- package/dist/web/client/assets/{login-q9O7dqRe.js → login-C-FCzcQU.js} +1 -1
- package/dist/web/client/assets/manage-BSGsiEPw.js +1 -0
- package/dist/web/client/assets/mcp-DDw8SGMV.js +1 -0
- package/dist/web/client/assets/routes-C5KzZ73E.js +85 -0
- package/dist/web/client/assets/shield-alert-CO7P-cbq.js +1 -0
- package/dist/web/client/assets/{skills-VEtq-MQJ.js → skills-H_AVE6G7.js} +1 -1
- package/dist/web/client/assets/style-HG30duye.js +7 -0
- package/dist/web/client/assets/styles-DyFDuWBI.css +2 -0
- package/dist/web/client/assets/system-C7vZKVdU.js +1 -0
- package/dist/web/client/assets/teams-DcxoMrsV.js +1 -0
- package/dist/web/client/assets/teams-Dcy3Wb4u.js +1 -0
- package/dist/web/client/assets/telegram-CUw1r_J5.js +1 -0
- package/dist/web/client/assets/{tools-C0FIeAL1.js → tools-BNZxmJJk.js} +1 -1
- package/dist/web/client/assets/usage-BhqvXWtk.js +1 -0
- package/dist/web/client/assets/welcome-4H9Gvu-u.js +1 -0
- package/dist/web/server/assets/{AddProviderDialog-CpLDHOcA.js → AddProviderDialog-Bqsz5NaL.js} +1 -1
- package/dist/web/server/assets/{AgentTemplateParts-Dh9F_-T_.js → AgentTemplateParts-D97gKNdN.js} +2 -2
- package/dist/web/server/assets/{ConfirmDialog-C89B8qKM.js → ConfirmDialog-CuD5HXTw.js} +1 -1
- package/dist/web/server/assets/{ConnectionsView-DslcKQmA.js → ConnectionsView-CSf83J-v.js} +32 -10
- package/dist/web/server/assets/{Dialog-_Gt_Nt86.js → Dialog-CwAfaXpM.js} +5 -0
- package/dist/web/server/assets/{SkillsParts-CqS2B45v.js → SkillsParts-hjS9a_Ht.js} +2 -2
- package/dist/web/server/assets/{SpawnDialog-BNKj2Lup.js → SpawnDialog-BjVZl7xK.js} +19 -6
- package/dist/web/server/assets/{SpawnTeamModal-zcLxtFOO.js → SpawnTeamModal-BmBXqfFi.js} +7 -7
- package/dist/web/server/assets/{TeamForm-XFP0l2TB.js → TeamForm-B4702hBg.js} +2 -2
- package/dist/web/server/assets/{TeamThread-gYV_ToRM.js → TeamThread-BGl5z8_I.js} +40 -2
- package/dist/web/server/assets/{UnsavedChangesGuard-CB_TugFF.js → UnsavedChangesGuard-Be8EqfV_.js} +1 -1
- package/dist/web/server/assets/{_id-D4RFNqaJ.js → _id-BWtcQovD.js} +1 -1
- package/dist/web/server/assets/{_id-josYXBx3.js → _id-CKBQM7LH.js} +1 -1
- package/dist/web/server/assets/{_id-BTyd2i5U.js → _id-Cf1461pN.js} +1 -1
- package/dist/web/server/assets/{_id-517adSuB.js → _id-DBhvSxVl.js} +1 -1
- package/dist/web/server/assets/{_id-CyinHJam.js → _id-TT_ZsaSc.js} +6 -6
- package/dist/web/server/assets/{_id-BsQnL9LV.js → _id-VqiN2zRR.js} +35 -12
- package/dist/web/server/assets/{_tanstack-start-manifest_v-DIMayzEa.js → _tanstack-start-manifest_v-Df5LTm5g.js} +60 -58
- package/dist/web/server/assets/{access-BdQmjMJV.js → access-Bog7dbtP.js} +1 -1
- package/dist/web/server/assets/{access-Cc7fMMod.js → access-C5lXP5JS.js} +2 -2
- package/dist/web/server/assets/{access-B97-94Wt.js → access-bTlESGXh.js} +1 -1
- package/dist/web/server/assets/{agents-CjrkaEz8.js → agents-8XZAjHh0.js} +5 -5
- package/dist/web/server/assets/{agents-Tg3zkmQv.js → agents-BepbikC0.js} +1 -1
- package/dist/web/server/assets/{agents-BL918wVc.js → agents-CKkMouJX.js} +1 -1
- package/dist/web/server/assets/{agents-BzJFjA2i.js → agents-Co6S2Ml9.js} +1 -1
- package/dist/web/server/assets/{agents-BlUZqqJn.js → agents-DDUHE3eY.js} +17 -9
- package/dist/web/server/assets/{agents-uw32jPWx.js → agents-DnUK-7qJ.js} +1 -1
- package/dist/web/server/assets/{attention-C94WWwQe.js → attention--1dBWt0c.js} +1 -1
- package/dist/web/server/assets/{attention-2unmuO-q.js → attention-ColV2zMz.js} +1 -1
- package/dist/web/server/assets/{attention-a_OmC6L3.js → attention-n8edCJBL.js} +2 -2
- package/dist/web/server/assets/{auth-DuIqEAed.js → auth-Q5eVKoKR.js} +1 -1
- package/dist/web/server/assets/{config-BG1KOtwA.js → config-BpwsF11b.js} +1 -1
- package/dist/web/server/assets/{config-D1Li_7Yt2.js → config-Cfn1TU8w.js} +1 -1
- package/dist/web/server/assets/{config-Bhem9XER.js → config-UHRqSrh4.js} +4 -4
- package/dist/web/server/assets/{daemon-client-D-NWKQto.js → daemon-client-Dw3ut4pU.js} +1 -1
- package/dist/web/server/assets/{manage-C7ReF2ZZ.js → manage-C7ss0xG5.js} +147 -1
- package/dist/web/server/assets/{mcp-BFixpBQk.js → mcp-COn047tO.js} +1 -1
- package/dist/web/server/assets/mcp-CUoF4jIO.js +753 -0
- package/dist/web/server/assets/{mcp-Ceg9gzKE.js → mcp-DVjTaRq3.js} +1 -1
- package/dist/web/server/assets/{open-groups-C89TEK85.js → open-groups-lUX_YX9X.js} +1 -1
- package/dist/web/server/assets/{router-DizFxqh-.js → router-q3PwQgDH.js} +22 -22
- package/dist/web/server/assets/{routes-DsuaDPTO.js → routes-BgjikzXy.js} +2 -2
- package/dist/web/server/assets/{routes-CVrH9qgo.js → routes-DRtxA9c1.js} +1 -1
- package/dist/web/server/assets/{routes-D9Mw1_VV.js → routes-Do8a2liK.js} +261 -71
- package/dist/web/server/assets/{skills-BNbZ75am.js → skills-B--hjk-0.js} +1 -1
- package/dist/web/server/assets/{skills-D5rnOmKJ.js → skills-D5oN5ehC.js} +4 -4
- package/dist/web/server/assets/{skills-BWwEFc4a.js → skills-DouMCq_2.js} +1 -1
- package/dist/web/server/assets/src-ErO6nYmi.js +226 -0
- package/dist/web/server/assets/{start-2MvkBRdC.js → start-D4sx5Ovq.js} +1 -1
- package/dist/web/server/assets/style-BgFXDhAR.js +64 -0
- package/dist/web/server/assets/{system-Cr4C-YRw.js → system-4WV2pOS4.js} +1 -1
- package/dist/web/server/assets/{system-DsmXkgqn.js → system-A2Aib6JE.js} +2 -1
- package/dist/web/server/assets/{system-DT7AU0e6.js → system-DtGHi7X7.js} +31 -11
- package/dist/web/server/assets/{teams-u6m6JzuU.js → teams-BJNZ7ZsS.js} +1 -1
- package/dist/web/server/assets/{teams-Dix5XVIx.js → teams-Blfyu8ej.js} +1 -1
- package/dist/web/server/assets/{teams-DjE0swAZ.js → teams-BnsbH4YW.js} +9 -9
- package/dist/web/server/assets/{teams-Rk_RED7X.js → teams-GDzT7Tv0.js} +1 -1
- package/dist/web/server/assets/{teams-BeStcDvQ.js → teams-QVxXJfo7.js} +1 -1
- package/dist/web/server/assets/{teams-CsEBLW8-.js → teams-gzY3tOtu.js} +7 -7
- package/dist/web/server/assets/{telegram-CQpF3EHA.js → telegram-BSp9aCz6.js} +1 -1
- package/dist/web/server/assets/{telegram-DhzHgDfg.js → telegram-CIbuQ5-U.js} +1 -1
- package/dist/web/server/assets/{telegram-BjqABrl-.js → telegram-Ctj5dqvs.js} +2 -2
- package/dist/web/server/assets/{tools-DC69leH7.js → tools-BPhol5jb.js} +1 -1
- package/dist/web/server/assets/{usage-mvQegG4l.js → usage-CeiyPffw.js} +1 -1
- package/dist/web/server/assets/{usage-4zMG0sab.js → usage-Dsi2V9Wh.js} +2 -2
- package/dist/web/server/assets/{welcome-DrYbWGd_.js → welcome-A2Koo4HI.js} +3 -3
- package/dist/web/server/assets/{welcome-BuE9FRf4.js → welcome-C71pZOQ9.js} +1 -1
- package/dist/web/server/assets/{welcome-DYw35wl5.js → welcome-PxSZeoU6.js} +1 -1
- package/dist/web/server/server.js +20 -20
- package/dist/worker.js +15 -5
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
- package/dist/web/client/assets/AddProviderDialog-D8VvDmbM.js +0 -1
- package/dist/web/client/assets/AgentTemplateParts-BWorU6-F.js +0 -1
- package/dist/web/client/assets/ConfirmDialog-DrN26lN_.js +0 -1
- package/dist/web/client/assets/ConnectionsView-DcO7RJZ7.js +0 -1
- package/dist/web/client/assets/SkillsParts-BueR3HoP.js +0 -1
- package/dist/web/client/assets/SpawnTeamModal-B65eQyzu.js +0 -1
- package/dist/web/client/assets/TeamForm-BhI9FbjV.js +0 -1
- package/dist/web/client/assets/TeamThread-FPpHlVFc.js +0 -1
- package/dist/web/client/assets/_id-5mTcKU2j.js +0 -1
- package/dist/web/client/assets/_id-DKgyyyeX.js +0 -1
- package/dist/web/client/assets/agents-Bfwz3dl5.js +0 -1
- package/dist/web/client/assets/config-kMzM8kdp.js +0 -1
- package/dist/web/client/assets/index-DuLpyCSP.js +0 -14
- package/dist/web/client/assets/manage-DdCiSgG9.js +0 -1
- package/dist/web/client/assets/mcp-B3LzNtrr.js +0 -1
- package/dist/web/client/assets/routes-BDdLZEGO.js +0 -85
- package/dist/web/client/assets/style-J8ypSsCb.js +0 -7
- package/dist/web/client/assets/styles-C7NsCHeU.css +0 -2
- package/dist/web/client/assets/system-DtBBeAjO.js +0 -1
- package/dist/web/client/assets/teams-D4X9oNx8.js +0 -1
- package/dist/web/client/assets/teams-QlaY2Sxd.js +0 -1
- package/dist/web/client/assets/telegram-B7vlTQbt.js +0 -1
- package/dist/web/client/assets/usage-3mYfS5C-.js +0 -1
- package/dist/web/client/assets/welcome-CkmanVa_.js +0 -1
- package/dist/web/server/assets/mcp-BTZkDvdc.js +0 -379
- package/dist/web/server/assets/src-BeMh8Fze.js +0 -113
- package/dist/web/server/assets/style-B3l0Wtlf.js +0 -178
package/dist/daemon.js
CHANGED
|
@@ -543,6 +543,7 @@ async function listMcpTools(server3, connect3, signal) {
|
|
|
543
543
|
tools.push({
|
|
544
544
|
toolName,
|
|
545
545
|
serverId: server3.id,
|
|
546
|
+
serverName: server3.name,
|
|
546
547
|
rawName: tool.name,
|
|
547
548
|
description: tool.description ?? `MCP tool ${tool.name} from ${server3.name}`,
|
|
548
549
|
inputSchema: schema
|
|
@@ -726,7 +727,7 @@ var init_ssrf = __esm({
|
|
|
726
727
|
});
|
|
727
728
|
|
|
728
729
|
// ../daemon/src/lib/browser/attach.ts
|
|
729
|
-
import { readFileSync as
|
|
730
|
+
import { readFileSync as readFileSync7 } from "node:fs";
|
|
730
731
|
import { connect as connect2 } from "node:net";
|
|
731
732
|
import { homedir as homedir2 } from "node:os";
|
|
732
733
|
import { join as join11 } from "node:path";
|
|
@@ -750,7 +751,7 @@ function runningBrowserDirs(platform = process.platform, home = homedir2()) {
|
|
|
750
751
|
];
|
|
751
752
|
}
|
|
752
753
|
function parseDevToolsActivePort(content) {
|
|
753
|
-
const [port2, path] = content.split("\n").map((
|
|
754
|
+
const [port2, path] = content.split("\n").map((line2) => line2.trim()).filter(Boolean);
|
|
754
755
|
if (!port2 || !/^\d{1,5}$/.test(port2) || Number(port2) < 1 || Number(port2) > 65535) return null;
|
|
755
756
|
if (!path?.startsWith("/")) return null;
|
|
756
757
|
return `ws://127.0.0.1:${port2}${path}`;
|
|
@@ -772,7 +773,7 @@ async function findRunningBrowser(dirs = runningBrowserDirs()) {
|
|
|
772
773
|
for (const { name, dir } of dirs) {
|
|
773
774
|
let content;
|
|
774
775
|
try {
|
|
775
|
-
content =
|
|
776
|
+
content = readFileSync7(join11(dir, "DevToolsActivePort"), "utf8");
|
|
776
777
|
} catch (error) {
|
|
777
778
|
const code = error.code;
|
|
778
779
|
if (code === "EPERM" || code === "EACCES") denied = dir;
|
|
@@ -1089,7 +1090,7 @@ var init_install = __esm({
|
|
|
1089
1090
|
|
|
1090
1091
|
// ../daemon/src/lib/browser/launch.ts
|
|
1091
1092
|
import { execFileSync, spawn as spawn2 } from "node:child_process";
|
|
1092
|
-
import { mkdirSync as mkdirSync5, readFileSync as
|
|
1093
|
+
import { mkdirSync as mkdirSync5, readFileSync as readFileSync8, readlinkSync, writeFileSync as writeFileSync4 } from "node:fs";
|
|
1093
1094
|
import { join as join14 } from "node:path";
|
|
1094
1095
|
function launchArgs(opts) {
|
|
1095
1096
|
const wayland = !opts.headless && !process.env.DISPLAY && !!process.env.WAYLAND_DISPLAY;
|
|
@@ -1150,7 +1151,7 @@ function isAlive(pid) {
|
|
|
1150
1151
|
function runsOnProfile(pid, userDataDir) {
|
|
1151
1152
|
const flag = `--user-data-dir=${userDataDir}`;
|
|
1152
1153
|
try {
|
|
1153
|
-
return
|
|
1154
|
+
return readFileSync8(`/proc/${pid}/cmdline`, "utf8").split("\0").includes(flag);
|
|
1154
1155
|
} catch {
|
|
1155
1156
|
const command = execFileSync("ps", ["-ww", "-o", "command=", "-p", String(pid)], {
|
|
1156
1157
|
encoding: "utf8"
|
|
@@ -1179,7 +1180,7 @@ function skipSessionRestore(userDataDir) {
|
|
|
1179
1180
|
const file = join14(dir, "Preferences");
|
|
1180
1181
|
let prefs = {};
|
|
1181
1182
|
try {
|
|
1182
|
-
const parsed = JSON.parse(
|
|
1183
|
+
const parsed = JSON.parse(readFileSync8(file, "utf8"));
|
|
1183
1184
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
1184
1185
|
prefs = parsed;
|
|
1185
1186
|
}
|
|
@@ -1266,9 +1267,9 @@ ${stderr.trim()}` : message));
|
|
|
1266
1267
|
stderr = (stderr + text4).slice(-2e3);
|
|
1267
1268
|
const lines = (pending + text4).slice(-16384).split("\n");
|
|
1268
1269
|
pending = lines.pop() ?? "";
|
|
1269
|
-
for (const
|
|
1270
|
+
for (const line2 of lines) {
|
|
1270
1271
|
const match = /^DevTools listening on (ws:\/\/127\.0\.0\.1:\d+\/devtools\/browser\/[\w-]+)$/.exec(
|
|
1271
|
-
|
|
1272
|
+
line2.trim()
|
|
1272
1273
|
);
|
|
1273
1274
|
if (match?.[1]) {
|
|
1274
1275
|
clearTimeout(timer);
|
|
@@ -1325,13 +1326,13 @@ function cutAt(text4, max) {
|
|
|
1325
1326
|
function splitPages(text4, size = PAGE_CHARS) {
|
|
1326
1327
|
const pages = [];
|
|
1327
1328
|
let current2 = "";
|
|
1328
|
-
for (const
|
|
1329
|
-
if (current2 && current2.length + 1 +
|
|
1329
|
+
for (const line2 of text4.split("\n")) {
|
|
1330
|
+
if (current2 && current2.length + 1 + line2.length > size) {
|
|
1330
1331
|
pages.push(current2);
|
|
1331
1332
|
current2 = "";
|
|
1332
1333
|
}
|
|
1333
1334
|
let rest = current2 ? `${current2}
|
|
1334
|
-
${
|
|
1335
|
+
${line2}` : line2;
|
|
1335
1336
|
while (rest.length > size) {
|
|
1336
1337
|
const cut = cutAt(rest, size);
|
|
1337
1338
|
pages.push(rest.slice(0, cut));
|
|
@@ -1371,7 +1372,7 @@ var init_snapshot = __esm({
|
|
|
1371
1372
|
});
|
|
1372
1373
|
|
|
1373
1374
|
// ../daemon/src/lib/browser/pool.ts
|
|
1374
|
-
import { existsSync as
|
|
1375
|
+
import { existsSync as existsSync11, rmSync as rmSync8 } from "node:fs";
|
|
1375
1376
|
function serialize(agentId, work) {
|
|
1376
1377
|
const run = (queues.get(agentId) ?? Promise.resolve()).then(work);
|
|
1377
1378
|
const settled = run.then(
|
|
@@ -1577,7 +1578,7 @@ function browserStatus(agentId, config, paths, enabled) {
|
|
|
1577
1578
|
// A browser that crashed or whose window was closed stays registered until
|
|
1578
1579
|
// its next call or the reaper, but is not running.
|
|
1579
1580
|
running: resources().browsers.get(agentId)?.browser.running ?? false,
|
|
1580
|
-
profilePresent:
|
|
1581
|
+
profilePresent: existsSync11(paths.browserDir(agentId))
|
|
1581
1582
|
};
|
|
1582
1583
|
const launchError = launchErrors.get(agentId);
|
|
1583
1584
|
if (config.attach) {
|
|
@@ -1844,6 +1845,7 @@ import { writeSync } from "node:fs";
|
|
|
1844
1845
|
// ../../packages/api-types/src/entities.ts
|
|
1845
1846
|
var DEFAULT_TEAM_ID = "default";
|
|
1846
1847
|
var AGENT_NAME_MAX = 120;
|
|
1848
|
+
var AGENT_ROLE_MAX = 4e3;
|
|
1847
1849
|
function agentNameProblem(name) {
|
|
1848
1850
|
if (!name.trim()) return "A name cannot be empty.";
|
|
1849
1851
|
if (name.length > AGENT_NAME_MAX) return `A name is at most ${AGENT_NAME_MAX} characters.`;
|
|
@@ -1862,6 +1864,11 @@ var REASONING_LEVELS = [
|
|
|
1862
1864
|
"high",
|
|
1863
1865
|
"xhigh"
|
|
1864
1866
|
];
|
|
1867
|
+
function chosenName(agent) {
|
|
1868
|
+
const own = agent.identity?.name?.trim();
|
|
1869
|
+
if (!own || agentNameProblem(own)) return null;
|
|
1870
|
+
return own.toLowerCase() !== agent.name.trim().toLowerCase() ? own : null;
|
|
1871
|
+
}
|
|
1865
1872
|
|
|
1866
1873
|
// ../../packages/api-types/src/git-review.ts
|
|
1867
1874
|
var REVIEW_LIMITS = {
|
|
@@ -1940,6 +1947,16 @@ function isTextPreview(result) {
|
|
|
1940
1947
|
return TEXT_EXTENSIONS.has(extension);
|
|
1941
1948
|
}
|
|
1942
1949
|
|
|
1950
|
+
// ../../packages/api-types/src/team-day.ts
|
|
1951
|
+
function messageText(payload) {
|
|
1952
|
+
try {
|
|
1953
|
+
const parsed = JSON.parse(payload);
|
|
1954
|
+
if (parsed && typeof parsed.text === "string") return parsed.text;
|
|
1955
|
+
} catch {
|
|
1956
|
+
}
|
|
1957
|
+
return payload;
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1943
1960
|
// ../daemon/src/index.ts
|
|
1944
1961
|
import { serve } from "@hono/node-server";
|
|
1945
1962
|
|
|
@@ -1972,12 +1989,14 @@ __export(agents_exports, {
|
|
|
1972
1989
|
findByName: () => findByName,
|
|
1973
1990
|
findByNameInTeam: () => findByNameInTeam,
|
|
1974
1991
|
findByTelegramTopicId: () => findByTelegramTopicId,
|
|
1992
|
+
freeNameInTeam: () => freeNameInTeam,
|
|
1975
1993
|
get: () => get,
|
|
1976
1994
|
getTelegramTopicId: () => getTelegramTopicId,
|
|
1977
1995
|
insert: () => insert,
|
|
1978
1996
|
list: () => list,
|
|
1979
1997
|
listAttachedSkills: () => listAttachedSkills,
|
|
1980
1998
|
listBoundTopicsInTeam: () => listBoundTopicsInTeam,
|
|
1999
|
+
nameTakenInTeam: () => nameTakenInTeam,
|
|
1981
2000
|
remove: () => remove,
|
|
1982
2001
|
setModelOverride: () => setModelOverride,
|
|
1983
2002
|
setName: () => setName,
|
|
@@ -2101,6 +2120,18 @@ function findByName(db, name) {
|
|
|
2101
2120
|
"SELECT * FROM agents WHERE name = ? AND status != 'archived' ORDER BY created_at ASC"
|
|
2102
2121
|
).all(name).map((row) => toAgent(db, row));
|
|
2103
2122
|
}
|
|
2123
|
+
function nameTakenInTeam(db, teamId, name, exceptId) {
|
|
2124
|
+
const wanted = name.trim().toLowerCase();
|
|
2125
|
+
return db.raw.query(
|
|
2126
|
+
"SELECT id, name FROM agents WHERE team_id = ? AND status != 'archived'"
|
|
2127
|
+
).all(teamId).some((row) => row.id !== exceptId && row.name.trim().toLowerCase() === wanted);
|
|
2128
|
+
}
|
|
2129
|
+
function freeNameInTeam(db, teamId, base) {
|
|
2130
|
+
if (!nameTakenInTeam(db, teamId, base)) return base;
|
|
2131
|
+
let suffix = 2;
|
|
2132
|
+
while (nameTakenInTeam(db, teamId, `${base} ${suffix}`)) suffix++;
|
|
2133
|
+
return `${base} ${suffix}`;
|
|
2134
|
+
}
|
|
2104
2135
|
function findByNameInTeam(db, teamId, name) {
|
|
2105
2136
|
const row = db.raw.query(
|
|
2106
2137
|
"SELECT * FROM agents WHERE team_id = ? AND name = ? AND status != 'archived' LIMIT 1"
|
|
@@ -2354,6 +2385,12 @@ function moveAgent(db, paths, agentId, destinationTeamId) {
|
|
|
2354
2385
|
throw new DomainError(404, `team not found: ${destinationTeamId}`);
|
|
2355
2386
|
}
|
|
2356
2387
|
if (agent.teamId === destinationTeamId) return agent;
|
|
2388
|
+
if (nameTakenInTeam(db, destinationTeamId, agent.name)) {
|
|
2389
|
+
throw new DomainError(
|
|
2390
|
+
409,
|
|
2391
|
+
`That Team already has an Agent named ${agent.name}: rename one of them first.`
|
|
2392
|
+
);
|
|
2393
|
+
}
|
|
2357
2394
|
return db.raw.transaction(() => {
|
|
2358
2395
|
removeAgentEdges(db, agent.teamId, agent.id);
|
|
2359
2396
|
setTeam(db, agent.id, destinationTeamId);
|
|
@@ -2390,8 +2427,8 @@ function isIdentityPlaceholder(value) {
|
|
|
2390
2427
|
}
|
|
2391
2428
|
function parseIdentityMarkdown(content) {
|
|
2392
2429
|
const identity2 = {};
|
|
2393
|
-
for (const
|
|
2394
|
-
const cleaned =
|
|
2430
|
+
for (const line2 of content.split(/\r?\n/)) {
|
|
2431
|
+
const cleaned = line2.trim().replace(/^\s*-\s*/, "");
|
|
2395
2432
|
const colonIndex = cleaned.indexOf(":");
|
|
2396
2433
|
if (colonIndex === -1) continue;
|
|
2397
2434
|
const label = cleaned.slice(0, colonIndex).replace(/[*_]/g, "").trim().toLowerCase();
|
|
@@ -2620,7 +2657,7 @@ function resolveAgent(db, paths, agentId) {
|
|
|
2620
2657
|
|
|
2621
2658
|
// ../daemon/src/core/agent/spawn.ts
|
|
2622
2659
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
2623
|
-
import { mkdirSync, rmSync as rmSync2, writeFileSync } from "node:fs";
|
|
2660
|
+
import { existsSync as existsSync4, mkdirSync, readFileSync as readFileSync3, rmSync as rmSync2, writeFileSync } from "node:fs";
|
|
2624
2661
|
import { join as join6 } from "node:path";
|
|
2625
2662
|
|
|
2626
2663
|
// ../daemon/src/core/profile/load.ts
|
|
@@ -2670,10 +2707,30 @@ function discoverSkills(paths) {
|
|
|
2670
2707
|
}
|
|
2671
2708
|
|
|
2672
2709
|
// ../daemon/src/core/agent/spawn.ts
|
|
2710
|
+
function giveRole(dir, role, teamName, addedBy) {
|
|
2711
|
+
const day = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
2712
|
+
const who = addedBy ? `${addedBy.name} (Agent id ${addedBy.id}) added you to the Team ${teamName} on ${day}, when the operator asked. Report back to ${addedBy.name} unless the operator says otherwise.` : `The operator added you to the Team ${teamName} on ${day}.`;
|
|
2713
|
+
const file = join6(dir, "AGENTS.md");
|
|
2714
|
+
const rest = existsSync4(file) ? readFileSync3(file, "utf8").trim() : "";
|
|
2715
|
+
writeFileSync(
|
|
2716
|
+
file,
|
|
2717
|
+
`${["# Your role", "", role, "", who].join("\n")}
|
|
2718
|
+
${rest ? `
|
|
2719
|
+
---
|
|
2720
|
+
|
|
2721
|
+
${rest}
|
|
2722
|
+
` : ""}`
|
|
2723
|
+
);
|
|
2724
|
+
rmSync2(join6(dir, "BOOTSTRAP.md"), { force: true });
|
|
2725
|
+
}
|
|
2673
2726
|
function spawnAgent(db, paths, input) {
|
|
2674
2727
|
const givenName = input.name?.trim() || void 0;
|
|
2675
2728
|
const nameProblem = givenName === void 0 ? null : agentNameProblem(givenName);
|
|
2676
2729
|
if (nameProblem) throw new DomainError(400, nameProblem);
|
|
2730
|
+
const role = input.role?.trim() || void 0;
|
|
2731
|
+
if (role && role.length > AGENT_ROLE_MAX) {
|
|
2732
|
+
throw new DomainError(400, `A role is at most ${AGENT_ROLE_MAX} characters.`);
|
|
2733
|
+
}
|
|
2677
2734
|
const loaded = loadProfile(db, input.profileId);
|
|
2678
2735
|
const id = randomUUID3();
|
|
2679
2736
|
const dir = paths.agentDir(id);
|
|
@@ -2701,10 +2758,14 @@ function spawnAgent(db, paths, input) {
|
|
|
2701
2758
|
`spawnAgent: team "${teamId}" does not exist. Pass an explicit --team or complete first-run setup first.`
|
|
2702
2759
|
);
|
|
2703
2760
|
}
|
|
2761
|
+
if (givenName !== void 0 && nameTakenInTeam(db, team.id, givenName)) {
|
|
2762
|
+
throw new DomainError(409, `${team.name} already has an Agent named ${givenName}.`);
|
|
2763
|
+
}
|
|
2704
2764
|
const agent = insert(db, {
|
|
2705
2765
|
id,
|
|
2706
2766
|
profileId: input.profileId,
|
|
2707
|
-
name
|
|
2767
|
+
// A name given is the Agent's own; the template's is numbered when the Team has it.
|
|
2768
|
+
name: givenName ?? freeNameInTeam(db, team.id, loaded.profile.name),
|
|
2708
2769
|
modelOverride: input.modelOverride ?? null,
|
|
2709
2770
|
reasoningLevel,
|
|
2710
2771
|
status: "idle",
|
|
@@ -2712,6 +2773,7 @@ function spawnAgent(db, paths, input) {
|
|
|
2712
2773
|
});
|
|
2713
2774
|
const skills = loaded.profile.skillsMode === "all" ? discoverSkills(paths).map((s) => s.name) : loaded.defaultSkills;
|
|
2714
2775
|
for (const s of skills) attachSkill(db, id, s);
|
|
2776
|
+
if (role) giveRole(dir, role, team.name, input.addedBy);
|
|
2715
2777
|
return agent;
|
|
2716
2778
|
})();
|
|
2717
2779
|
} catch (error) {
|
|
@@ -2727,6 +2789,12 @@ function unarchiveAgent(db, id) {
|
|
|
2727
2789
|
if (agent.status !== "archived") {
|
|
2728
2790
|
throw new DomainError(400, `agent is not archived (status: ${agent.status})`);
|
|
2729
2791
|
}
|
|
2792
|
+
if (nameTakenInTeam(db, agent.teamId, agent.name, agent.id)) {
|
|
2793
|
+
throw new DomainError(
|
|
2794
|
+
409,
|
|
2795
|
+
`Its Team now has another Agent named ${agent.name}: rename one of them first.`
|
|
2796
|
+
);
|
|
2797
|
+
}
|
|
2730
2798
|
unarchive(db, agent.id);
|
|
2731
2799
|
}
|
|
2732
2800
|
|
|
@@ -3551,7 +3619,7 @@ function inTx(db, fn) {
|
|
|
3551
3619
|
}
|
|
3552
3620
|
|
|
3553
3621
|
// ../daemon/src/core/db/schema.ts
|
|
3554
|
-
import { readFileSync as
|
|
3622
|
+
import { readFileSync as readFileSync4 } from "node:fs";
|
|
3555
3623
|
var INCOMPATIBLE_DATABASE_MESSAGE = "Bazilion cannot start because this home uses an incompatible database schema. Preserve the entire Bazilion home directory as a filesystem backup first, keeping bazilion.db and auth.json together. Then perform the reset with `bazilion uninstall --yes` (from the repository root of a source checkout: `pnpm tsx apps/cli/src/index.ts uninstall --yes`) and start Bazilion again. Use `--all` only if you also want to remove installed skills.";
|
|
3556
3624
|
var IncompatibleDatabaseError = class extends Error {
|
|
3557
3625
|
constructor() {
|
|
@@ -3568,7 +3636,7 @@ function fingerprint(read2) {
|
|
|
3568
3636
|
}
|
|
3569
3637
|
var schemaSql;
|
|
3570
3638
|
function readSchemaSql() {
|
|
3571
|
-
schemaSql ??=
|
|
3639
|
+
schemaSql ??= readFileSync4(new URL("./schema.sql", import.meta.url), "utf8");
|
|
3572
3640
|
return schemaSql;
|
|
3573
3641
|
}
|
|
3574
3642
|
var canonical;
|
|
@@ -3888,7 +3956,7 @@ function createProfile(db, paths, input) {
|
|
|
3888
3956
|
}
|
|
3889
3957
|
|
|
3890
3958
|
// ../daemon/src/core/profile/delete.ts
|
|
3891
|
-
import { existsSync as
|
|
3959
|
+
import { existsSync as existsSync5, rmSync as rmSync3 } from "node:fs";
|
|
3892
3960
|
|
|
3893
3961
|
// ../daemon/src/core/repos/teamTemplates.ts
|
|
3894
3962
|
var teamTemplates_exports = {};
|
|
@@ -4104,13 +4172,13 @@ function deleteProfile(db, id) {
|
|
|
4104
4172
|
);
|
|
4105
4173
|
}
|
|
4106
4174
|
remove3(db, id);
|
|
4107
|
-
if (
|
|
4175
|
+
if (existsSync5(profile.dir)) {
|
|
4108
4176
|
rmSync3(profile.dir, { recursive: true, force: true });
|
|
4109
4177
|
}
|
|
4110
4178
|
}
|
|
4111
4179
|
|
|
4112
4180
|
// ../daemon/src/core/team/register.ts
|
|
4113
|
-
import { existsSync as
|
|
4181
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync3, rmSync as rmSync4, statSync, symlinkSync } from "node:fs";
|
|
4114
4182
|
import { resolve as resolve2 } from "node:path";
|
|
4115
4183
|
function registerTeam(db, input, paths) {
|
|
4116
4184
|
validateSlug(input.id);
|
|
@@ -4118,13 +4186,13 @@ function registerTeam(db, input, paths) {
|
|
|
4118
4186
|
throw new DomainError(400, `team already registered: ${input.id}`);
|
|
4119
4187
|
}
|
|
4120
4188
|
const slot = paths.teamDir(input.id);
|
|
4121
|
-
if (
|
|
4189
|
+
if (existsSync6(slot)) {
|
|
4122
4190
|
throw new DomainError(400, `team slot already on disk at ${slot} (move or remove it first)`);
|
|
4123
4191
|
}
|
|
4124
4192
|
mkdirSync3(paths.teamsDir, { recursive: true });
|
|
4125
4193
|
if (input.link) {
|
|
4126
4194
|
const target = resolve2(input.link);
|
|
4127
|
-
if (!
|
|
4195
|
+
if (!existsSync6(target)) {
|
|
4128
4196
|
throw new DomainError(400, `--link target does not exist: ${target}`);
|
|
4129
4197
|
}
|
|
4130
4198
|
if (!statSync(target).isDirectory()) {
|
|
@@ -5990,14 +6058,14 @@ function revokeForToken(db, tokenId) {
|
|
|
5990
6058
|
}
|
|
5991
6059
|
|
|
5992
6060
|
// ../daemon/src/core/secrets.ts
|
|
5993
|
-
import { existsSync as
|
|
6061
|
+
import { existsSync as existsSync7, readFileSync as readFileSync5 } from "node:fs";
|
|
5994
6062
|
function readAuthFile(authFile) {
|
|
5995
|
-
if (!
|
|
6063
|
+
if (!existsSync7(authFile)) {
|
|
5996
6064
|
throw new Error(
|
|
5997
6065
|
`${authFile} not found. Start the daemon (\`bazilion serve\`) \u2014 it auto-bootstraps on first run.`
|
|
5998
6066
|
);
|
|
5999
6067
|
}
|
|
6000
|
-
const raw =
|
|
6068
|
+
const raw = readFileSync5(authFile, "utf8");
|
|
6001
6069
|
const parsed = JSON.parse(raw);
|
|
6002
6070
|
if (typeof parsed.token !== "string" || !parsed.token) {
|
|
6003
6071
|
throw new Error(`${authFile} is missing the "token" field`);
|
|
@@ -6013,13 +6081,13 @@ function mergeSecretsIntoEnv(db, password, env = process.env) {
|
|
|
6013
6081
|
}
|
|
6014
6082
|
|
|
6015
6083
|
// ../daemon/src/core/skills/import.ts
|
|
6016
|
-
import { cpSync, existsSync as
|
|
6084
|
+
import { cpSync, existsSync as existsSync8, mkdtempSync, readdirSync as readdirSync2, rmSync as rmSync5, statSync as statSync2 } from "node:fs";
|
|
6017
6085
|
import { tmpdir } from "node:os";
|
|
6018
6086
|
import { basename as basename2, join as join9, resolve as resolve3, sep } from "node:path";
|
|
6019
6087
|
import AdmZip from "adm-zip";
|
|
6020
6088
|
|
|
6021
6089
|
// ../daemon/src/core/skills/parse.ts
|
|
6022
|
-
import { readFileSync as
|
|
6090
|
+
import { readFileSync as readFileSync6 } from "node:fs";
|
|
6023
6091
|
import { parse as parseYaml } from "yaml";
|
|
6024
6092
|
var FRONTMATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/;
|
|
6025
6093
|
function parseSkillContent(raw) {
|
|
@@ -6048,7 +6116,7 @@ function parseSkillContent(raw) {
|
|
|
6048
6116
|
return { frontmatter: fmObj, body, raw };
|
|
6049
6117
|
}
|
|
6050
6118
|
function parseSkillFile(path) {
|
|
6051
|
-
const raw =
|
|
6119
|
+
const raw = readFileSync6(path, "utf8");
|
|
6052
6120
|
return parseSkillContent(raw);
|
|
6053
6121
|
}
|
|
6054
6122
|
|
|
@@ -6063,25 +6131,25 @@ var RULES = [
|
|
|
6063
6131
|
code: "sensitive-reference",
|
|
6064
6132
|
severity: "danger",
|
|
6065
6133
|
message: "Mentions a sensitive path, database, auth file, or credential environment variable.",
|
|
6066
|
-
test: (
|
|
6134
|
+
test: (line2) => SENSITIVE_PATH_RE.test(line2) || SECRET_ENV_RE.test(line2)
|
|
6067
6135
|
},
|
|
6068
6136
|
{
|
|
6069
6137
|
code: "secret-exfiltration",
|
|
6070
6138
|
severity: "danger",
|
|
6071
6139
|
message: "Combines secret/env/file access with exfiltration-style language.",
|
|
6072
|
-
test: (
|
|
6140
|
+
test: (line2) => SECRET_TARGET_RE.test(line2) && EXFIL_VERB_RE.test(line2)
|
|
6073
6141
|
},
|
|
6074
6142
|
{
|
|
6075
6143
|
code: "instruction-hijack",
|
|
6076
6144
|
severity: "danger",
|
|
6077
6145
|
message: "Contains instruction-hijacking language such as ignoring prior instructions.",
|
|
6078
|
-
test: (
|
|
6146
|
+
test: (line2) => /ignore (all )?(previous|prior|system|developer|user) instructions/i.test(line2) || /override (the )?(system|developer) (prompt|instructions)/i.test(line2) || /bypass (safety|security|policy|guardrails)/i.test(line2) || /you are now (root|unrestricted|in developer mode)/i.test(line2)
|
|
6079
6147
|
},
|
|
6080
6148
|
{
|
|
6081
6149
|
code: "unicode-stealth",
|
|
6082
6150
|
severity: "warning",
|
|
6083
6151
|
message: "Contains zero-width, bidi, or byte-order characters that can hide prompt text.",
|
|
6084
|
-
test: (
|
|
6152
|
+
test: (line2) => UNICODE_STEALTH_RE.test(line2)
|
|
6085
6153
|
}
|
|
6086
6154
|
];
|
|
6087
6155
|
function addFinding(findings, seen, finding) {
|
|
@@ -6094,9 +6162,9 @@ function scanSkillContent(raw) {
|
|
|
6094
6162
|
const findings = [];
|
|
6095
6163
|
const seen = /* @__PURE__ */ new Set();
|
|
6096
6164
|
const lines = raw.split(/\r?\n/);
|
|
6097
|
-
lines.forEach((
|
|
6165
|
+
lines.forEach((line2, index) => {
|
|
6098
6166
|
for (const rule of RULES) {
|
|
6099
|
-
if (!rule.test(
|
|
6167
|
+
if (!rule.test(line2)) continue;
|
|
6100
6168
|
addFinding(findings, seen, {
|
|
6101
6169
|
code: rule.code,
|
|
6102
6170
|
severity: rule.severity,
|
|
@@ -6148,7 +6216,7 @@ function extractZipSafely(zipPath) {
|
|
|
6148
6216
|
}
|
|
6149
6217
|
function importSkills(paths, input) {
|
|
6150
6218
|
const rawSource = resolve3(input.source);
|
|
6151
|
-
if (!
|
|
6219
|
+
if (!existsSync8(rawSource)) {
|
|
6152
6220
|
throw new Error(`source does not exist: ${rawSource}`);
|
|
6153
6221
|
}
|
|
6154
6222
|
let source = rawSource;
|
|
@@ -6172,14 +6240,14 @@ function importSkills(paths, input) {
|
|
|
6172
6240
|
}
|
|
6173
6241
|
function importSkillsFromDir(paths, source, input) {
|
|
6174
6242
|
const candidates = [];
|
|
6175
|
-
if (
|
|
6243
|
+
if (existsSync8(join9(source, "SKILL.md"))) {
|
|
6176
6244
|
candidates.push({ name: basename2(source), dir: source });
|
|
6177
6245
|
} else {
|
|
6178
6246
|
const entries = readdirSync2(source, { withFileTypes: true });
|
|
6179
6247
|
for (const e of entries) {
|
|
6180
6248
|
if (!e.isDirectory()) continue;
|
|
6181
6249
|
const skillDir = join9(source, e.name);
|
|
6182
|
-
if (!
|
|
6250
|
+
if (!existsSync8(join9(skillDir, "SKILL.md"))) continue;
|
|
6183
6251
|
candidates.push({ name: e.name, dir: skillDir });
|
|
6184
6252
|
}
|
|
6185
6253
|
}
|
|
@@ -6199,7 +6267,7 @@ function importSkillsFromDir(paths, source, input) {
|
|
|
6199
6267
|
const skipped = [];
|
|
6200
6268
|
for (const c of candidates) {
|
|
6201
6269
|
const target = join9(paths.skillsDir, c.name);
|
|
6202
|
-
if (
|
|
6270
|
+
if (existsSync8(target) && !input.force) {
|
|
6203
6271
|
skipped.push({
|
|
6204
6272
|
name: c.name,
|
|
6205
6273
|
reason: "already exists (use --force to overwrite)",
|
|
@@ -6241,7 +6309,7 @@ function resolveAgentSkills(db, paths, agentId) {
|
|
|
6241
6309
|
|
|
6242
6310
|
// ../daemon/src/core/team/delete.ts
|
|
6243
6311
|
import { randomUUID as randomUUID12 } from "node:crypto";
|
|
6244
|
-
import { existsSync as
|
|
6312
|
+
import { existsSync as existsSync9, renameSync as renameSync2, rmSync as rmSync6 } from "node:fs";
|
|
6245
6313
|
function deleteTeam(db, paths, id) {
|
|
6246
6314
|
const g = get3(db, id, paths);
|
|
6247
6315
|
if (!g) throw new DomainError(404, `team not found: ${id}`);
|
|
@@ -6254,15 +6322,15 @@ function deleteTeam(db, paths, id) {
|
|
|
6254
6322
|
);
|
|
6255
6323
|
}
|
|
6256
6324
|
const stagedPath = `${g.path}.deleting-${randomUUID12()}`;
|
|
6257
|
-
const hadSlot =
|
|
6325
|
+
const hadSlot = existsSync9(g.path);
|
|
6258
6326
|
if (hadSlot) renameSync2(g.path, stagedPath);
|
|
6259
6327
|
try {
|
|
6260
6328
|
remove2(db, id);
|
|
6261
6329
|
} catch (error) {
|
|
6262
|
-
if (hadSlot &&
|
|
6330
|
+
if (hadSlot && existsSync9(stagedPath)) renameSync2(stagedPath, g.path);
|
|
6263
6331
|
throw error;
|
|
6264
6332
|
}
|
|
6265
|
-
if (hadSlot &&
|
|
6333
|
+
if (hadSlot && existsSync9(stagedPath)) {
|
|
6266
6334
|
rmSync6(stagedPath, { recursive: true, force: true });
|
|
6267
6335
|
}
|
|
6268
6336
|
}
|
|
@@ -6322,11 +6390,11 @@ function spawnTeamTemplate(db, paths, input) {
|
|
|
6322
6390
|
teamCreated = true;
|
|
6323
6391
|
}
|
|
6324
6392
|
const names = new Set(
|
|
6325
|
-
list(db, { includeArchived: true }).filter((agent) => agent.teamId === input.teamId).map((agent) => agent.name)
|
|
6393
|
+
list(db, { includeArchived: true }).filter((agent) => agent.teamId === input.teamId).map((agent) => agent.name.trim().toLowerCase())
|
|
6326
6394
|
);
|
|
6327
6395
|
for (const slot of template.slots) {
|
|
6328
6396
|
const name = uniqueName(slot.agentName, names);
|
|
6329
|
-
names.add(name);
|
|
6397
|
+
names.add(name.toLowerCase());
|
|
6330
6398
|
created.push(
|
|
6331
6399
|
spawnAgent(db, paths, {
|
|
6332
6400
|
profileId: slot.profileId,
|
|
@@ -6382,14 +6450,15 @@ function saveTeamAsTemplate(db, paths, teamId, input) {
|
|
|
6382
6450
|
});
|
|
6383
6451
|
}
|
|
6384
6452
|
function uniqueName(base, existing) {
|
|
6385
|
-
|
|
6453
|
+
const taken = (name) => existing.has(name.trim().toLowerCase());
|
|
6454
|
+
if (!taken(base)) return base;
|
|
6386
6455
|
let suffix = 2;
|
|
6387
|
-
while (
|
|
6456
|
+
while (taken(`${base}-${suffix}`)) suffix++;
|
|
6388
6457
|
return `${base}-${suffix}`;
|
|
6389
6458
|
}
|
|
6390
6459
|
|
|
6391
6460
|
// ../daemon/src/lib/ctx.ts
|
|
6392
|
-
import { chmodSync, existsSync as
|
|
6461
|
+
import { chmodSync, existsSync as existsSync10, mkdirSync as mkdirSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
6393
6462
|
var _db = null;
|
|
6394
6463
|
var _paths = null;
|
|
6395
6464
|
var _authToken = null;
|
|
@@ -6402,8 +6471,8 @@ var IncompatibleBootstrapIdentityError = class extends Error {
|
|
|
6402
6471
|
};
|
|
6403
6472
|
function bootstrap(paths) {
|
|
6404
6473
|
mkdirSync4(paths.home, { recursive: true, mode: 448 });
|
|
6405
|
-
const databaseExists =
|
|
6406
|
-
const authFileExists =
|
|
6474
|
+
const databaseExists = existsSync10(paths.db);
|
|
6475
|
+
const authFileExists = existsSync10(paths.authFile);
|
|
6407
6476
|
if (databaseExists !== authFileExists) {
|
|
6408
6477
|
throw new IncompatibleBootstrapIdentityError();
|
|
6409
6478
|
}
|
|
@@ -6877,6 +6946,7 @@ var CommandApprovalRegistry = class {
|
|
|
6877
6946
|
teamId: input.teamId,
|
|
6878
6947
|
command: input.command,
|
|
6879
6948
|
risks: input.risks,
|
|
6949
|
+
...input.tool ? { tool: input.tool } : {},
|
|
6880
6950
|
status: "pending",
|
|
6881
6951
|
createdAt: Date.now(),
|
|
6882
6952
|
expiresAt: Date.now() + this.#timeoutMs
|
|
@@ -7073,8 +7143,8 @@ function stepTarget(rawArguments) {
|
|
|
7073
7143
|
for (const key2 of TARGET_KEYS) {
|
|
7074
7144
|
const value = args[key2];
|
|
7075
7145
|
if (typeof value === "string" && value.trim()) {
|
|
7076
|
-
const
|
|
7077
|
-
return
|
|
7146
|
+
const line2 = value.trim().split("\n")[0] ?? "";
|
|
7147
|
+
return line2.length > TARGET_CHARS ? `${line2.slice(0, TARGET_CHARS - 1)}\u2026` : line2;
|
|
7078
7148
|
}
|
|
7079
7149
|
}
|
|
7080
7150
|
return null;
|
|
@@ -7239,9 +7309,12 @@ agentBrowserRouter.delete("/:id/browser/profile", async (c) => {
|
|
|
7239
7309
|
});
|
|
7240
7310
|
|
|
7241
7311
|
// ../daemon/src/routes/agent-chat.ts
|
|
7242
|
-
import { randomUUID as
|
|
7312
|
+
import { randomUUID as randomUUID20 } from "node:crypto";
|
|
7243
7313
|
import { existsSync as existsSync17, readFileSync as readFileSync11 } from "node:fs";
|
|
7244
|
-
import { join as
|
|
7314
|
+
import { join as join29 } from "node:path";
|
|
7315
|
+
|
|
7316
|
+
// ../daemon/src/lib/agent-turn.ts
|
|
7317
|
+
import { randomUUID as randomUUID19 } from "node:crypto";
|
|
7245
7318
|
|
|
7246
7319
|
// ../daemon/src/runtime/auth/openai-codex.ts
|
|
7247
7320
|
import { openaiCodexProvider } from "@earendil-works/pi-ai/providers/openai-codex";
|
|
@@ -7368,7 +7441,7 @@ import {
|
|
|
7368
7441
|
mkdirSync as mkdirSync6,
|
|
7369
7442
|
openSync,
|
|
7370
7443
|
readdirSync as readdirSync4,
|
|
7371
|
-
readFileSync as
|
|
7444
|
+
readFileSync as readFileSync9,
|
|
7372
7445
|
realpathSync as realpathSync2,
|
|
7373
7446
|
rmSync as rmSync9,
|
|
7374
7447
|
writeFileSync as writeFileSync5
|
|
@@ -7540,7 +7613,7 @@ function readSafeFile(root, path) {
|
|
|
7540
7613
|
fd = openSync(path, constants2.O_RDONLY | constants2.O_NOFOLLOW);
|
|
7541
7614
|
const stats = fstatSync(fd);
|
|
7542
7615
|
if (!stats.isFile()) throw unsafeMemoryPath(path, "memory entry is not a regular file");
|
|
7543
|
-
return { content:
|
|
7616
|
+
return { content: readFileSync9(fd, "utf8"), stats };
|
|
7544
7617
|
} catch (error) {
|
|
7545
7618
|
if (error.code === "ELOOP") {
|
|
7546
7619
|
throw unsafeMemoryPath(path, "symbolic links are not allowed");
|
|
@@ -7933,7 +8006,7 @@ function extractResultReferences(value) {
|
|
|
7933
8006
|
}
|
|
7934
8007
|
|
|
7935
8008
|
// ../daemon/src/runtime/pi/session.ts
|
|
7936
|
-
import { existsSync as
|
|
8009
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync10, statSync as statSync7, writeFileSync as writeFileSync7 } from "node:fs";
|
|
7937
8010
|
import { basename as basename5, join as join22 } from "node:path";
|
|
7938
8011
|
import {
|
|
7939
8012
|
buildSessionContext,
|
|
@@ -8037,7 +8110,7 @@ async function testProviderModel(spec) {
|
|
|
8037
8110
|
}
|
|
8038
8111
|
|
|
8039
8112
|
// ../daemon/src/runtime/session/prompt.ts
|
|
8040
|
-
import { existsSync as
|
|
8113
|
+
import { existsSync as existsSync12, readdirSync as readdirSync5 } from "node:fs";
|
|
8041
8114
|
import { join as join17 } from "node:path";
|
|
8042
8115
|
|
|
8043
8116
|
// ../daemon/src/runtime/safe-files.ts
|
|
@@ -8048,7 +8121,7 @@ import {
|
|
|
8048
8121
|
lstatSync as lstatSync2,
|
|
8049
8122
|
mkdirSync as mkdirSync8,
|
|
8050
8123
|
openSync as openSync2,
|
|
8051
|
-
readFileSync as
|
|
8124
|
+
readFileSync as readFileSync10,
|
|
8052
8125
|
readlinkSync as readlinkSync2,
|
|
8053
8126
|
readSync,
|
|
8054
8127
|
realpathSync as realpathSync3,
|
|
@@ -8142,7 +8215,7 @@ function readRegularFileNoFollow(path) {
|
|
|
8142
8215
|
try {
|
|
8143
8216
|
fd = openSync2(path, constants3.O_RDONLY | noFollowFlag());
|
|
8144
8217
|
if (!fstatSync2(fd).isFile()) throw new Error("target is not a regular file");
|
|
8145
|
-
return
|
|
8218
|
+
return readFileSync10(fd, "utf8");
|
|
8146
8219
|
} finally {
|
|
8147
8220
|
if (fd !== void 0) closeSync2(fd);
|
|
8148
8221
|
}
|
|
@@ -8181,7 +8254,7 @@ var SANDBOX_SKILLS_DIR = "/skills";
|
|
|
8181
8254
|
var MAX_LISTED_TEAMMATES = 40;
|
|
8182
8255
|
var MAX_LISTED_OUTSIDE = 20;
|
|
8183
8256
|
function loadPromptSkills(skillsDir, attachedNames) {
|
|
8184
|
-
if (!
|
|
8257
|
+
if (!existsSync12(skillsDir) || attachedNames.length === 0) return [];
|
|
8185
8258
|
const attached = new Set(attachedNames);
|
|
8186
8259
|
const discovered = readdirSync5(skillsDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && attached.has(entry.name)).sort((a, b) => a.name.localeCompare(b.name));
|
|
8187
8260
|
const loaded = [];
|
|
@@ -8302,7 +8375,7 @@ ${contextBlocks.join("\n\n")}`
|
|
|
8302
8375
|
`Runtime directory: \`${runtimeDir}\`. Resolve any relative scripts or assets mentioned by this skill from that directory.`,
|
|
8303
8376
|
"",
|
|
8304
8377
|
skill.body
|
|
8305
|
-
].filter((
|
|
8378
|
+
].filter((line2, index, lines) => line2 !== "" || lines[index - 1] !== "").join("\n").trimEnd();
|
|
8306
8379
|
});
|
|
8307
8380
|
const unavailableNote = unavailable.length > 0 ? `Attached but unavailable or invalid: ${unavailable.join(", ")}.` : "";
|
|
8308
8381
|
parts.push({
|
|
@@ -8376,8 +8449,8 @@ ${reviewedLessons.map((lesson) => `- ${lesson}`).join("\n")}`
|
|
|
8376
8449
|
}
|
|
8377
8450
|
function teammateLines(agent, options) {
|
|
8378
8451
|
const contacts = options.contacts ?? [];
|
|
8379
|
-
const
|
|
8380
|
-
const entry = (contact, team) => `- ${
|
|
8452
|
+
const line2 = (text4) => text4.replace(/[\p{Cc}\p{Cf}\u2028\u2029\s]+/gu, " ").trim();
|
|
8453
|
+
const entry = (contact, team) => `- ${line2(contact.name)}${contact.calledName ? ` (calls itself ${line2(contact.calledName)})` : ""}: id ${contact.id}${team ? "" : `, Team ${line2(contact.teamName)}`} (template ${line2(contact.template)})`;
|
|
8381
8454
|
const listed = (list13, max, team) => [
|
|
8382
8455
|
...list13.slice(0, max).map((contact) => entry(contact, team)),
|
|
8383
8456
|
...list13.length > max ? [`- and ${list13.length - max} more`] : []
|
|
@@ -8592,7 +8665,7 @@ function dockerError(error) {
|
|
|
8592
8665
|
}
|
|
8593
8666
|
|
|
8594
8667
|
// ../daemon/src/runtime/shell/tooling.ts
|
|
8595
|
-
import { existsSync as
|
|
8668
|
+
import { existsSync as existsSync13, lstatSync as lstatSync3, mkdirSync as mkdirSync9, realpathSync as realpathSync4, statSync as statSync6 } from "node:fs";
|
|
8596
8669
|
import { dirname as dirname6, isAbsolute as isAbsolute4, join as join18, relative as relative3, sep as sep4 } from "node:path";
|
|
8597
8670
|
import {
|
|
8598
8671
|
createBashToolDefinition,
|
|
@@ -8853,7 +8926,7 @@ function resolveShellSecurityConfig(env = process.env) {
|
|
|
8853
8926
|
sandboxImage: rawImage || DEFAULT_BASH_SANDBOX_IMAGE
|
|
8854
8927
|
};
|
|
8855
8928
|
}
|
|
8856
|
-
var INTERNAL_SECRET_NAME = /^(?:OPENAI_CODEX_OAUTH|TELEGRAM_BOT_TOKEN|BAZILION_TOKEN|MCP_TOKEN_.*)$/;
|
|
8929
|
+
var INTERNAL_SECRET_NAME = /^(?:OPENAI_CODEX_OAUTH|TELEGRAM_BOT_TOKEN|BAZILION_TOKEN|MCP_TOKEN_.*|MCP_ENV_.*|MCP_ASK_.*)$/;
|
|
8857
8930
|
function toolEnvironment(env, bootstrapToken) {
|
|
8858
8931
|
return Object.fromEntries(
|
|
8859
8932
|
Object.entries(env).filter(
|
|
@@ -8924,7 +8997,7 @@ function createSessionShellTools(cwd, env, options = {}) {
|
|
|
8924
8997
|
workdir: containerWorkdir(turn.cwd),
|
|
8925
8998
|
readOnlyMounts: [
|
|
8926
8999
|
readOnlyMount(join18(workspace, "memory"), SANDBOX_MEMORY_DIR, workspace),
|
|
8927
|
-
...options.inputsDir &&
|
|
9000
|
+
...options.inputsDir && existsSync13(options.inputsDir) ? [readOnlyMount(options.inputsDir, SANDBOX_INPUTS_DIR, dirname6(options.inputsDir))] : [],
|
|
8928
9001
|
...(options.skillMounts ?? []).map(
|
|
8929
9002
|
(mount) => readOnlyMount(mount.source, mount.target, dirname6(mount.source))
|
|
8930
9003
|
)
|
|
@@ -8995,7 +9068,7 @@ function readSessionText(directory, id) {
|
|
|
8995
9068
|
return text4.slice(0, text4.lastIndexOf("\n") + 1);
|
|
8996
9069
|
}
|
|
8997
9070
|
function parseSessionText(text4, id) {
|
|
8998
|
-
const entries = text4.split("\n").filter((
|
|
9071
|
+
const entries = text4.split("\n").filter((line2) => line2.trim()).map((line2) => JSON.parse(line2));
|
|
8999
9072
|
checkHeader(entries[0], id);
|
|
9000
9073
|
return entries;
|
|
9001
9074
|
}
|
|
@@ -9056,7 +9129,7 @@ function askUserTool(ask) {
|
|
|
9056
9129
|
}
|
|
9057
9130
|
|
|
9058
9131
|
// ../daemon/src/runtime/tools/bootstrap.ts
|
|
9059
|
-
import { existsSync as
|
|
9132
|
+
import { existsSync as existsSync14, rmSync as rmSync11 } from "node:fs";
|
|
9060
9133
|
import { join as join20 } from "node:path";
|
|
9061
9134
|
function bootstrapTool(agentDir2) {
|
|
9062
9135
|
return {
|
|
@@ -9067,7 +9140,7 @@ function bootstrapTool(agentDir2) {
|
|
|
9067
9140
|
},
|
|
9068
9141
|
async invoke() {
|
|
9069
9142
|
const path = join20(agentDir2, "BOOTSTRAP.md");
|
|
9070
|
-
if (
|
|
9143
|
+
if (existsSync14(path)) {
|
|
9071
9144
|
rmSync11(path);
|
|
9072
9145
|
return "BOOTSTRAP.md removed. Bootstrap is complete.";
|
|
9073
9146
|
}
|
|
@@ -9444,14 +9517,24 @@ function imageGenerateTool(host3) {
|
|
|
9444
9517
|
}
|
|
9445
9518
|
|
|
9446
9519
|
// ../daemon/src/runtime/tools/mcp.ts
|
|
9520
|
+
var SHOWN_ARGUMENTS = 4e3;
|
|
9521
|
+
function toolCallSummary(rawName, args) {
|
|
9522
|
+
const json = JSON.stringify(args, null, 2);
|
|
9523
|
+
const shown2 = json.length > SHOWN_ARGUMENTS ? `${json.slice(0, SHOWN_ARGUMENTS)}
|
|
9524
|
+
\u2026` : json;
|
|
9525
|
+
return `${rawName}
|
|
9526
|
+
${shown2}`;
|
|
9527
|
+
}
|
|
9447
9528
|
function mcpProxyTools(host3, tools) {
|
|
9448
9529
|
return tools.map((t) => ({
|
|
9449
9530
|
def: {
|
|
9450
9531
|
name: t.toolName,
|
|
9451
|
-
description: t.description
|
|
9532
|
+
description: t.ask ? `${t.description}
|
|
9533
|
+
|
|
9534
|
+
The operator approves each call of this tool before it runs.` : t.description,
|
|
9452
9535
|
parameters: t.inputSchema
|
|
9453
9536
|
},
|
|
9454
|
-
invoke: (args) => host3.invoke(t.serverId, t.rawName, args)
|
|
9537
|
+
invoke: (args, context) => host3.invoke(t.serverId, t.rawName, args, { toolCallId: context?.toolCallId })
|
|
9455
9538
|
}));
|
|
9456
9539
|
}
|
|
9457
9540
|
|
|
@@ -10257,7 +10340,7 @@ function turnSurface(opts) {
|
|
|
10257
10340
|
async function createBazilionSession(opts) {
|
|
10258
10341
|
const { agent, paths } = opts;
|
|
10259
10342
|
const { providerName, modelId } = parseModelString(agent.model);
|
|
10260
|
-
if (!
|
|
10343
|
+
if (!existsSync15(agent.team.path)) mkdirSync10(agent.team.path, { recursive: true });
|
|
10261
10344
|
mkdirSync10(join22(paths.agentDir(agent.agent.id), "sessions"), { recursive: true });
|
|
10262
10345
|
const sessionManager = openConversation(agent, paths, opts.conversation);
|
|
10263
10346
|
const turn = turnSurface(opts);
|
|
@@ -10344,7 +10427,7 @@ function loadSessionMessages(agent, paths, sessionId) {
|
|
|
10344
10427
|
if (!/^[A-Za-z0-9._-]+$/.test(sessionId)) return [];
|
|
10345
10428
|
const sessionDir = join22(paths.agentDir(agent.agent.id), "sessions");
|
|
10346
10429
|
const file = join22(sessionDir, `${sessionId}.jsonl`);
|
|
10347
|
-
if (!
|
|
10430
|
+
if (!existsSync15(file) || !existsSync15(agent.team.path)) return [];
|
|
10348
10431
|
try {
|
|
10349
10432
|
return SessionManager.open(file, sessionDir).buildSessionContext().messages;
|
|
10350
10433
|
} catch {
|
|
@@ -10353,7 +10436,7 @@ function loadSessionMessages(agent, paths, sessionId) {
|
|
|
10353
10436
|
}
|
|
10354
10437
|
function loadSessionHead(agent, paths, target) {
|
|
10355
10438
|
const sessionDir = join22(paths.agentDir(agent.agent.id), "sessions");
|
|
10356
|
-
if (!
|
|
10439
|
+
if (!existsSync15(sessionDir)) return { file: null, size: 0 };
|
|
10357
10440
|
const recent = target ? explicitConversationFile(sessionDir, target) : null;
|
|
10358
10441
|
if (!recent) return { file: null, size: 0 };
|
|
10359
10442
|
try {
|
|
@@ -10422,7 +10505,7 @@ async function listLiveModels(providerName, env = process.env, signal) {
|
|
|
10422
10505
|
|
|
10423
10506
|
// ../daemon/src/runtime/worker/spawn.ts
|
|
10424
10507
|
import { spawn as spawn4 } from "node:child_process";
|
|
10425
|
-
import { existsSync as
|
|
10508
|
+
import { existsSync as existsSync16 } from "node:fs";
|
|
10426
10509
|
import { isAbsolute as isAbsolute6 } from "node:path";
|
|
10427
10510
|
import { fileURLToPath } from "node:url";
|
|
10428
10511
|
|
|
@@ -10466,7 +10549,7 @@ var MAX_WORKER_STDERR_CHARS = 16 * 1024;
|
|
|
10466
10549
|
var MAX_WORKER_FRAME_CHARS = 40 * 1024 * 1024;
|
|
10467
10550
|
var sourceEntryPath = fileURLToPath(new URL("./entry.ts", import.meta.url));
|
|
10468
10551
|
var bundledEntryPath = fileURLToPath(new URL("./worker.js", import.meta.url));
|
|
10469
|
-
var entryPath =
|
|
10552
|
+
var entryPath = existsSync16(sourceEntryPath) ? sourceEntryPath : bundledEntryPath;
|
|
10470
10553
|
function spawnWorkerTurn(spec, opts) {
|
|
10471
10554
|
const { env, signal, diagnosticSink, workerEntryPath, ...hosts } = opts;
|
|
10472
10555
|
return runWorker({
|
|
@@ -10641,7 +10724,13 @@ var RPC_HANDLERS = {
|
|
|
10641
10724
|
userMdGet: ({ teamId }, { hosts }) => host(hosts.userMdHost, "USER.md").get(teamId),
|
|
10642
10725
|
userMdWrite: ({ teamId, content, ifMatch }, { hosts }) => host(hosts.userMdHost, "USER.md").write(teamId, content, ifMatch),
|
|
10643
10726
|
browserInvoke: ({ agentId, action, args }, { hosts }) => host(hosts.browserHost, "browser").invoke(agentId, action, args),
|
|
10644
|
-
mcpInvoke: ({ serverId, toolName, args },
|
|
10727
|
+
mcpInvoke: ({ serverId, toolName, args, toolCallId }, ctx) => host(ctx.hosts.mcpHost, "MCP").invoke(serverId, toolName, args, {
|
|
10728
|
+
...toolCallId ? { toolCallId } : {},
|
|
10729
|
+
// The call ends with the worker: an approval it waits for is cancelled with it.
|
|
10730
|
+
signal: ctx.signal,
|
|
10731
|
+
// A tool that asks first shows its approval in the chat, as a risky command does.
|
|
10732
|
+
onApproval: (approval) => ctx.pushFrame(approvalFrame(approval))
|
|
10733
|
+
}),
|
|
10645
10734
|
createAgent: (args, { hosts }) => host(hosts.teamHost, "team").createAgent(args),
|
|
10646
10735
|
refreshApiKey: async ({ providerName }, ctx) => {
|
|
10647
10736
|
const token = await refreshApiKeyForTurn(
|
|
@@ -10732,11 +10821,11 @@ async function pumpWorkerFrames(stdout, frames, secrets, stopWorker) {
|
|
|
10732
10821
|
let rest = chunk;
|
|
10733
10822
|
let newline = rest.indexOf("\n");
|
|
10734
10823
|
while (newline !== -1) {
|
|
10735
|
-
const
|
|
10824
|
+
const line2 = partial + rest.slice(0, newline);
|
|
10736
10825
|
partial = "";
|
|
10737
10826
|
rest = rest.slice(newline + 1);
|
|
10738
|
-
if (
|
|
10739
|
-
if (
|
|
10827
|
+
if (line2.length > MAX_WORKER_FRAME_CHARS) return tooLong();
|
|
10828
|
+
if (line2.trim()) frames.push(parseFrame(line2, secrets));
|
|
10740
10829
|
newline = rest.indexOf("\n");
|
|
10741
10830
|
}
|
|
10742
10831
|
partial += rest;
|
|
@@ -10752,9 +10841,9 @@ async function pumpWorkerFrames(stdout, frames, secrets, stopWorker) {
|
|
|
10752
10841
|
frames.end();
|
|
10753
10842
|
}
|
|
10754
10843
|
}
|
|
10755
|
-
function parseFrame(
|
|
10844
|
+
function parseFrame(line2, secrets) {
|
|
10756
10845
|
try {
|
|
10757
|
-
const frame = redactJsonValue(JSON.parse(
|
|
10846
|
+
const frame = redactJsonValue(JSON.parse(line2), secrets);
|
|
10758
10847
|
if (frame.kind === "fatal") return { ...frame, error: formatWorkerDiagnostic(frame.error) };
|
|
10759
10848
|
if (frame.kind === "event" && frame.event.type === "error") {
|
|
10760
10849
|
return {
|
|
@@ -10907,7 +10996,7 @@ async function responsesStream(url, headers, body, signal, fetchImpl = fetch) {
|
|
|
10907
10996
|
const streamed = [];
|
|
10908
10997
|
let completed;
|
|
10909
10998
|
for (const frame of (await readCapped(response)).replace(/\r\n?/g, "\n").split("\n\n")) {
|
|
10910
|
-
const data = frame.split("\n").filter((
|
|
10999
|
+
const data = frame.split("\n").filter((line2) => line2.startsWith("data:")).map((line2) => line2.slice(5).trimStart()).join("\n");
|
|
10911
11000
|
if (!data || data === "[DONE]") continue;
|
|
10912
11001
|
const event = JSON.parse(data);
|
|
10913
11002
|
if (["error", "response.failed", "response.incomplete"].includes(String(event.type)))
|
|
@@ -11070,17 +11159,130 @@ function createImageGenerationHost(opts) {
|
|
|
11070
11159
|
|
|
11071
11160
|
// ../daemon/src/lib/mcp/resolve.ts
|
|
11072
11161
|
init_pool();
|
|
11162
|
+
|
|
11163
|
+
// ../daemon/src/lib/mcp/settings.ts
|
|
11164
|
+
var ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
11165
|
+
var keyOf = (serverId) => serverId.replace(/-/g, "").toUpperCase();
|
|
11166
|
+
var envPrefix = (serverId) => `MCP_ENV_${keyOf(serverId)}__`;
|
|
11167
|
+
var askKey = (serverId) => `MCP_ASK_${keyOf(serverId)}`;
|
|
11168
|
+
function validEnvName(name) {
|
|
11169
|
+
return ENV_NAME.test(name);
|
|
11170
|
+
}
|
|
11171
|
+
function serverEnv(db, authToken, serverId) {
|
|
11172
|
+
const prefix = envPrefix(serverId);
|
|
11173
|
+
return Object.fromEntries(
|
|
11174
|
+
Object.entries(openSecrets(db, authToken).getAll()).filter(([key2]) => key2.startsWith(prefix)).map(([key2, value]) => [key2.slice(prefix.length), value])
|
|
11175
|
+
);
|
|
11176
|
+
}
|
|
11177
|
+
function serverEnvNames(db, authToken, serverId) {
|
|
11178
|
+
return Object.keys(serverEnv(db, authToken, serverId)).sort();
|
|
11179
|
+
}
|
|
11180
|
+
function setServerEnv(db, authToken, serverId, env) {
|
|
11181
|
+
const secrets = openSecrets(db, authToken);
|
|
11182
|
+
for (const [name, value] of Object.entries(env)) {
|
|
11183
|
+
const key2 = `${envPrefix(serverId)}${name}`;
|
|
11184
|
+
if (value === null || value === "") secrets.remove(key2);
|
|
11185
|
+
else secrets.set(key2, value);
|
|
11186
|
+
}
|
|
11187
|
+
}
|
|
11188
|
+
function askChoices(db, authToken, serverId) {
|
|
11189
|
+
const raw = openSecrets(db, authToken).get(askKey(serverId));
|
|
11190
|
+
if (raw === void 0) return {};
|
|
11191
|
+
try {
|
|
11192
|
+
const parsed = JSON.parse(raw);
|
|
11193
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
|
|
11194
|
+
return Object.fromEntries(
|
|
11195
|
+
Object.entries(parsed).filter(
|
|
11196
|
+
(entry) => typeof entry[1] === "boolean"
|
|
11197
|
+
)
|
|
11198
|
+
);
|
|
11199
|
+
} catch {
|
|
11200
|
+
return {};
|
|
11201
|
+
}
|
|
11202
|
+
}
|
|
11203
|
+
function setAskChoices(db, authToken, serverId, choices) {
|
|
11204
|
+
const secrets = openSecrets(db, authToken);
|
|
11205
|
+
if (!choices || Object.keys(choices).length === 0) secrets.remove(askKey(serverId));
|
|
11206
|
+
else secrets.set(askKey(serverId), JSON.stringify(choices));
|
|
11207
|
+
}
|
|
11208
|
+
function removeServerSettings(db, authToken, serverId) {
|
|
11209
|
+
const secrets = openSecrets(db, authToken);
|
|
11210
|
+
for (const name of serverEnvNames(db, authToken, serverId)) {
|
|
11211
|
+
secrets.remove(`${envPrefix(serverId)}${name}`);
|
|
11212
|
+
}
|
|
11213
|
+
secrets.remove(askKey(serverId));
|
|
11214
|
+
}
|
|
11215
|
+
var OUTWARD = /* @__PURE__ */ new Set([
|
|
11216
|
+
"send",
|
|
11217
|
+
"post",
|
|
11218
|
+
"publish",
|
|
11219
|
+
"reply",
|
|
11220
|
+
"forward",
|
|
11221
|
+
"share",
|
|
11222
|
+
"invite",
|
|
11223
|
+
"create",
|
|
11224
|
+
"update",
|
|
11225
|
+
"edit",
|
|
11226
|
+
"modify",
|
|
11227
|
+
"manage",
|
|
11228
|
+
"patch",
|
|
11229
|
+
"put",
|
|
11230
|
+
"insert",
|
|
11231
|
+
"upsert",
|
|
11232
|
+
"import",
|
|
11233
|
+
"append",
|
|
11234
|
+
"copy",
|
|
11235
|
+
"rename",
|
|
11236
|
+
"move",
|
|
11237
|
+
"merge",
|
|
11238
|
+
"transfer",
|
|
11239
|
+
"assign",
|
|
11240
|
+
"schedule",
|
|
11241
|
+
"draft",
|
|
11242
|
+
"format",
|
|
11243
|
+
"sort",
|
|
11244
|
+
"mark",
|
|
11245
|
+
"delete",
|
|
11246
|
+
"remove",
|
|
11247
|
+
"archive",
|
|
11248
|
+
"trash",
|
|
11249
|
+
"upload",
|
|
11250
|
+
"write",
|
|
11251
|
+
"add",
|
|
11252
|
+
"set",
|
|
11253
|
+
"cancel",
|
|
11254
|
+
"accept",
|
|
11255
|
+
"decline"
|
|
11256
|
+
]);
|
|
11257
|
+
var METHOD = /* @__PURE__ */ new Set(["post", "put", "patch"]);
|
|
11258
|
+
var READ = /* @__PURE__ */ new Set(["search", "query", "get", "list", "read", "fetch", "find", "retrieve"]);
|
|
11259
|
+
function looksOutward(toolName) {
|
|
11260
|
+
const words = toolName.replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase().split(/[-_.\s]+/);
|
|
11261
|
+
const outward = words.filter((word) => OUTWARD.has(word));
|
|
11262
|
+
if (outward.length === 0) return false;
|
|
11263
|
+
return !(outward.every((word) => METHOD.has(word)) && words.some((word) => READ.has(word)));
|
|
11264
|
+
}
|
|
11265
|
+
function toolAsks(choices, toolName) {
|
|
11266
|
+
return choices[toolName] ?? looksOutward(toolName);
|
|
11267
|
+
}
|
|
11268
|
+
|
|
11269
|
+
// ../daemon/src/lib/mcp/resolve.ts
|
|
11073
11270
|
var DISCOVERY_MS = 1e4;
|
|
11074
11271
|
function mcpTokenSecretKey(id) {
|
|
11075
11272
|
return `MCP_TOKEN_${id.replace(/-/g, "").toUpperCase()}`;
|
|
11076
11273
|
}
|
|
11077
11274
|
function mcpConnectOptions(db, authToken, server3) {
|
|
11078
11275
|
if (server3.transport === "stdio")
|
|
11079
|
-
return {
|
|
11276
|
+
return {
|
|
11277
|
+
env: {
|
|
11278
|
+
...toolEnvironment(mergeSecretsIntoEnv(db, authToken), authToken),
|
|
11279
|
+
...serverEnv(db, authToken, server3.id)
|
|
11280
|
+
}
|
|
11281
|
+
};
|
|
11080
11282
|
const token = openSecrets(db, authToken).get(mcpTokenSecretKey(server3.id));
|
|
11081
11283
|
return token ? { authToken: token } : {};
|
|
11082
11284
|
}
|
|
11083
|
-
async function resolveMcpForTurn(db, authToken, signal) {
|
|
11285
|
+
async function resolveMcpForTurn(db, authToken, signal, gate) {
|
|
11084
11286
|
const servers = mcpServers_exports.listEnabled(db);
|
|
11085
11287
|
if (servers.length === 0) return null;
|
|
11086
11288
|
const deadline = new AbortController();
|
|
@@ -11102,7 +11304,9 @@ async function resolveMcpForTurn(db, authToken, signal) {
|
|
|
11102
11304
|
console.warn(`mcp: server ${server3.name} is unavailable: ${reason}`);
|
|
11103
11305
|
continue;
|
|
11104
11306
|
}
|
|
11105
|
-
|
|
11307
|
+
const chosen = askChoices(db, authToken, server3.id);
|
|
11308
|
+
for (const listed2 of result.value) {
|
|
11309
|
+
const tool = toolAsks(chosen, listed2.rawName) ? { ...listed2, ask: true } : listed2;
|
|
11106
11310
|
if (names.has(tool.toolName)) {
|
|
11107
11311
|
console.warn(`mcp: ${tool.toolName} from server ${server3.name} repeats a name; skipped`);
|
|
11108
11312
|
continue;
|
|
@@ -11112,20 +11316,42 @@ async function resolveMcpForTurn(db, authToken, signal) {
|
|
|
11112
11316
|
}
|
|
11113
11317
|
}
|
|
11114
11318
|
const host3 = {
|
|
11115
|
-
async invoke(serverId, toolName, args) {
|
|
11116
|
-
|
|
11117
|
-
|
|
11319
|
+
async invoke(serverId, toolName, args, options) {
|
|
11320
|
+
const tool = tools.find((entry) => entry.serverId === serverId && entry.rawName === toolName);
|
|
11321
|
+
if (!tool) throw new Error(`MCP tool ${toolName} is not available in this turn`);
|
|
11118
11322
|
const server3 = mcpServers_exports.get(db, serverId);
|
|
11119
11323
|
if (!server3?.enabled) throw new Error("This MCP server has been disabled or removed");
|
|
11324
|
+
const callSignal = signal && options?.signal ? AbortSignal.any([signal, options.signal]) : options?.signal ?? signal;
|
|
11325
|
+
if (tool.ask) {
|
|
11326
|
+
if (!gate) throw new Error(`${tool.toolName} needs the operator's approval first`);
|
|
11327
|
+
const handle12 = gate({
|
|
11328
|
+
toolCallId: options?.toolCallId ?? tool.toolName,
|
|
11329
|
+
command: toolCallSummary(toolName, args),
|
|
11330
|
+
tool: `${server3.name} \xB7 ${toolName}`,
|
|
11331
|
+
...callSignal ? { signal: callSignal } : {}
|
|
11332
|
+
});
|
|
11333
|
+
options?.onApproval?.(handle12.approval);
|
|
11334
|
+
const settled = await handle12.settled;
|
|
11335
|
+
if (handle12.approval.status === "pending") options?.onApproval?.(settled);
|
|
11336
|
+
if (settled.status !== "allowed") {
|
|
11337
|
+
throw new Error(
|
|
11338
|
+
`${tool.toolName} was not approved, so nothing was sent. In a turn nobody is watching (a schedule, a teammate's message, Telegram), ask the operator in a conversation instead.`
|
|
11339
|
+
);
|
|
11340
|
+
}
|
|
11341
|
+
callSignal?.throwIfAborted();
|
|
11342
|
+
}
|
|
11120
11343
|
return callMcpTool(server3, toolName, args, {
|
|
11121
11344
|
connect: () => mcpConnectOptions(db, authToken, server3),
|
|
11122
|
-
signal
|
|
11345
|
+
...callSignal ? { signal: callSignal } : {}
|
|
11123
11346
|
});
|
|
11124
11347
|
}
|
|
11125
11348
|
};
|
|
11126
11349
|
return { tools, host: host3 };
|
|
11127
11350
|
}
|
|
11128
11351
|
|
|
11352
|
+
// ../daemon/src/lib/messaging-host.ts
|
|
11353
|
+
import { join as join23 } from "node:path";
|
|
11354
|
+
|
|
11129
11355
|
// ../daemon/src/lib/agent-loop-guard.ts
|
|
11130
11356
|
import { randomUUID as randomUUID16 } from "node:crypto";
|
|
11131
11357
|
var DEFAULT_MAX_HOPS = 8;
|
|
@@ -11279,13 +11505,20 @@ function recipientOf(db, from, ref) {
|
|
|
11279
11505
|
if (exact) return exact.id;
|
|
11280
11506
|
const sender = agents_exports.get(db, from);
|
|
11281
11507
|
if (sender) {
|
|
11282
|
-
const
|
|
11283
|
-
|
|
11284
|
-
).
|
|
11508
|
+
const key2 = wanted.toLowerCase();
|
|
11509
|
+
const team = agents_exports.list(db).filter((agent) => agent.teamId === sender.teamId);
|
|
11510
|
+
const teammates = team.filter((agent) => agent.name.trim().toLowerCase() === key2);
|
|
11285
11511
|
if (teammates.length === 1 && teammates[0]) return teammates[0].id;
|
|
11286
11512
|
if (teammates.length > 1) {
|
|
11287
11513
|
throw new Error(`send_message: more than one teammate is named "${wanted}"; use the id`);
|
|
11288
11514
|
}
|
|
11515
|
+
const calling = team.filter(
|
|
11516
|
+
(agent) => chosenName({
|
|
11517
|
+
name: agent.name,
|
|
11518
|
+
identity: loadIdentityFromFile(join23(agent.dir, "IDENTITY.md"))
|
|
11519
|
+
})?.toLowerCase() === key2
|
|
11520
|
+
);
|
|
11521
|
+
if (calling.length === 1 && calling[0]) return calling[0].id;
|
|
11289
11522
|
}
|
|
11290
11523
|
const found = agents_exports.get(db, wanted);
|
|
11291
11524
|
if (found) return found.id;
|
|
@@ -11339,8 +11572,7 @@ function createResultHost(db, agent, conversationId, signal) {
|
|
|
11339
11572
|
}
|
|
11340
11573
|
|
|
11341
11574
|
// ../daemon/src/lib/team-host.ts
|
|
11342
|
-
import {
|
|
11343
|
-
import { join as join23 } from "node:path";
|
|
11575
|
+
import { join as join24 } from "node:path";
|
|
11344
11576
|
|
|
11345
11577
|
// ../daemon/src/lib/telegram/config.ts
|
|
11346
11578
|
var BOT_TOKEN_KEY = "TELEGRAM_BOT_TOKEN";
|
|
@@ -11536,8 +11768,14 @@ function notifyDirectoryDirty() {
|
|
|
11536
11768
|
}
|
|
11537
11769
|
|
|
11538
11770
|
// ../daemon/src/lib/team-host.ts
|
|
11771
|
+
function calledName(agent) {
|
|
11772
|
+
const own = chosenName({
|
|
11773
|
+
...agent,
|
|
11774
|
+
identity: loadIdentityFromFile(join24(agent.dir, "IDENTITY.md"))
|
|
11775
|
+
});
|
|
11776
|
+
return own ? { calledName: own } : {};
|
|
11777
|
+
}
|
|
11539
11778
|
var MAX_CREATED_PER_TURN = 6;
|
|
11540
|
-
var MAX_ROLE = 4e3;
|
|
11541
11779
|
function agentContacts(db, agentId) {
|
|
11542
11780
|
const self = agents_exports.get(db, agentId);
|
|
11543
11781
|
if (!self) return [];
|
|
@@ -11548,6 +11786,8 @@ function agentContacts(db, agentId) {
|
|
|
11548
11786
|
const contacts = agents_exports.list(db).filter((agent) => agent.id !== self.id).map((agent) => ({
|
|
11549
11787
|
id: agent.id,
|
|
11550
11788
|
name: agent.name,
|
|
11789
|
+
// Only a teammate is reached by the name it gave itself (`recipientOf`).
|
|
11790
|
+
...agent.teamId === self.teamId ? calledName(agent) : {},
|
|
11551
11791
|
teamId: agent.teamId,
|
|
11552
11792
|
teamName: teams.get(agent.teamId) ?? agent.teamId,
|
|
11553
11793
|
template: templates.get(agent.profileId) ?? agent.profileId,
|
|
@@ -11557,15 +11797,6 @@ function agentContacts(db, agentId) {
|
|
|
11557
11797
|
const others = contacts.filter((contact) => contact.teamId !== self.teamId && contact.canMessage).sort((a, b) => a.teamName.localeCompare(b.teamName));
|
|
11558
11798
|
return [...own, ...others];
|
|
11559
11799
|
}
|
|
11560
|
-
function roleNote(role, creator, teamName) {
|
|
11561
|
-
return [
|
|
11562
|
-
"# Your role",
|
|
11563
|
-
"",
|
|
11564
|
-
role,
|
|
11565
|
-
"",
|
|
11566
|
-
`${creator.name} (Agent id ${creator.id}) added you to the Team ${teamName} on ${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}, when the operator asked. Report back to ${creator.name} unless the operator says otherwise.`
|
|
11567
|
-
].join("\n");
|
|
11568
|
-
}
|
|
11569
11800
|
function createDbTeamHost(db, paths, creatorId) {
|
|
11570
11801
|
let created = 0;
|
|
11571
11802
|
return {
|
|
@@ -11578,18 +11809,15 @@ function createDbTeamHost(db, paths, creatorId) {
|
|
|
11578
11809
|
const nameProblem = agentNameProblem(name);
|
|
11579
11810
|
if (nameProblem) throw new Error(`agent_create: ${nameProblem}`);
|
|
11580
11811
|
if (!role) throw new Error('agent_create: "role" is required: say what the Agent is for');
|
|
11581
|
-
if (role.length >
|
|
11582
|
-
throw new Error(`agent_create: a role is at most ${
|
|
11812
|
+
if (role.length > AGENT_ROLE_MAX) {
|
|
11813
|
+
throw new Error(`agent_create: a role is at most ${AGENT_ROLE_MAX} characters`);
|
|
11583
11814
|
}
|
|
11584
11815
|
if (created >= MAX_CREATED_PER_TURN) {
|
|
11585
11816
|
throw new Error(
|
|
11586
11817
|
`agent_create: at most ${MAX_CREATED_PER_TURN} Agents per turn; ask the operator before adding more`
|
|
11587
11818
|
);
|
|
11588
11819
|
}
|
|
11589
|
-
|
|
11590
|
-
(agent2) => agent2.teamId === creator.teamId && agent2.name.toLowerCase() === name.toLowerCase()
|
|
11591
|
-
);
|
|
11592
|
-
if (taken) {
|
|
11820
|
+
if (agents_exports.nameTakenInTeam(db, creator.teamId, name)) {
|
|
11593
11821
|
throw new Error(`agent_create: this Team already has an Agent named "${name}"`);
|
|
11594
11822
|
}
|
|
11595
11823
|
const templateId = input.template?.trim() || creator.profileId;
|
|
@@ -11605,22 +11833,13 @@ function createDbTeamHost(db, paths, creatorId) {
|
|
|
11605
11833
|
profileId: template.id,
|
|
11606
11834
|
name,
|
|
11607
11835
|
...model && model !== template.defaultModel ? { modelOverride: model } : {},
|
|
11608
|
-
teamId: creator.teamId
|
|
11836
|
+
teamId: creator.teamId,
|
|
11837
|
+
// It starts knowing its job and who to report to.
|
|
11838
|
+
role,
|
|
11839
|
+
addedBy: { id: creator.id, name: creator.name }
|
|
11609
11840
|
});
|
|
11610
11841
|
created++;
|
|
11611
|
-
const agentsFile = join23(agent.dir, "AGENTS.md");
|
|
11612
11842
|
const teamName = db.raw.query("SELECT name FROM teams WHERE id = ?").get(creator.teamId)?.name ?? creator.teamId;
|
|
11613
|
-
const rest = existsSync16(agentsFile) ? readFileSync10(agentsFile, "utf8").trim() : "";
|
|
11614
|
-
writeFileSync8(
|
|
11615
|
-
agentsFile,
|
|
11616
|
-
`${roleNote(role, creator, teamName)}
|
|
11617
|
-
${rest ? `
|
|
11618
|
-
---
|
|
11619
|
-
|
|
11620
|
-
${rest}
|
|
11621
|
-
` : ""}`
|
|
11622
|
-
);
|
|
11623
|
-
rmSync12(join23(agent.dir, "BOOTSTRAP.md"), { force: true });
|
|
11624
11843
|
const restricted = teamPolicies_exports.mode(db, creator.teamId) === "restricted";
|
|
11625
11844
|
if (restricted) {
|
|
11626
11845
|
teamPolicies_exports.insertEdges(db, creator.teamId, [
|
|
@@ -11934,7 +12153,7 @@ var COMMAND_CHARS = 1500;
|
|
|
11934
12153
|
function promptBody(agentName, approval) {
|
|
11935
12154
|
const risks = [...new Set(approval.risks.map((risk) => risk.message))].join(" ");
|
|
11936
12155
|
return [
|
|
11937
|
-
`\u26A0\uFE0F ${agentName} wants to run a command that needs your approval:`,
|
|
12156
|
+
approval.tool ? `\u26A0\uFE0F ${agentName} wants to use ${approval.tool}, which sends or changes something outside:` : `\u26A0\uFE0F ${agentName} wants to run a command that needs your approval:`,
|
|
11938
12157
|
clip2(approval.command, COMMAND_CHARS),
|
|
11939
12158
|
risks ? `Why it asks: ${clip2(risks, 500)}` : ""
|
|
11940
12159
|
].filter(Boolean).join("\n\n");
|
|
@@ -12331,8 +12550,8 @@ function mirrorTypingStop(agentId) {
|
|
|
12331
12550
|
|
|
12332
12551
|
// ../daemon/src/lib/attachments.ts
|
|
12333
12552
|
import { randomUUID as randomUUID17 } from "node:crypto";
|
|
12334
|
-
import { closeSync as closeSync5, constants as constants6, fstatSync as fstatSync5, openSync as openSync5, writeFileSync as
|
|
12335
|
-
import { join as
|
|
12553
|
+
import { closeSync as closeSync5, constants as constants6, fstatSync as fstatSync5, openSync as openSync5, writeFileSync as writeFileSync8 } from "node:fs";
|
|
12554
|
+
import { join as join25, posix as posix2 } from "node:path";
|
|
12336
12555
|
var MAX_FILE_BYTES = 25 * 1024 * 1024;
|
|
12337
12556
|
function safeName(name) {
|
|
12338
12557
|
const base = name.split(/[\\/]/).pop() ?? "file";
|
|
@@ -12344,7 +12563,7 @@ function fmtBytes(n) {
|
|
|
12344
12563
|
return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
12345
12564
|
}
|
|
12346
12565
|
function prepareInputFilesDirectory(agentDir2) {
|
|
12347
|
-
return ensureContainedRealDirectory(
|
|
12566
|
+
return ensureContainedRealDirectory(join25(agentDir2, "uploads"), agentDir2, { create: true });
|
|
12348
12567
|
}
|
|
12349
12568
|
function saveInputFiles(agentDir2, files, options = {}) {
|
|
12350
12569
|
if (!files || files.length === 0) return "";
|
|
@@ -12358,7 +12577,7 @@ function saveInputFiles(agentDir2, files, options = {}) {
|
|
|
12358
12577
|
continue;
|
|
12359
12578
|
}
|
|
12360
12579
|
const filename = `${randomUUID17().slice(0, 8)}-${safeName(label)}`;
|
|
12361
|
-
const path =
|
|
12580
|
+
const path = join25(dir, filename);
|
|
12362
12581
|
let fd;
|
|
12363
12582
|
try {
|
|
12364
12583
|
fd = openSync5(
|
|
@@ -12367,7 +12586,7 @@ function saveInputFiles(agentDir2, files, options = {}) {
|
|
|
12367
12586
|
384
|
|
12368
12587
|
);
|
|
12369
12588
|
if (!fstatSync5(fd).isFile()) throw new Error("attachment target is not a regular file");
|
|
12370
|
-
|
|
12589
|
+
writeFileSync8(fd, buf);
|
|
12371
12590
|
} finally {
|
|
12372
12591
|
if (fd !== void 0) closeSync5(fd);
|
|
12373
12592
|
}
|
|
@@ -12381,7 +12600,7 @@ function saveInputFiles(agentDir2, files, options = {}) {
|
|
|
12381
12600
|
|
|
12382
12601
|
// ../daemon/src/lib/coding-environment.ts
|
|
12383
12602
|
import { lstatSync as lstatSync5 } from "node:fs";
|
|
12384
|
-
import { join as
|
|
12603
|
+
import { join as join26 } from "node:path";
|
|
12385
12604
|
|
|
12386
12605
|
// ../daemon/src/core/coding-environment/config.ts
|
|
12387
12606
|
var CodingEnvironmentValidationError = class extends DomainError {
|
|
@@ -12438,7 +12657,7 @@ function setTeamCodingEnvironment(db, team, input, env = process.env) {
|
|
|
12438
12657
|
const environment = validateCodingEnvironment(input);
|
|
12439
12658
|
let path = team.path;
|
|
12440
12659
|
for (const part of environment.cwd === "." ? [] : environment.cwd.split("/")) {
|
|
12441
|
-
path =
|
|
12660
|
+
path = join26(path, part);
|
|
12442
12661
|
if (!lstatSync5(path, { throwIfNoEntry: false })?.isDirectory())
|
|
12443
12662
|
throw new CodingEnvironmentValidationError(
|
|
12444
12663
|
"The directory must be an existing directory inside the Team"
|
|
@@ -12458,18 +12677,18 @@ function dockerTurn(db, paths, agent, env) {
|
|
|
12458
12677
|
|
|
12459
12678
|
// ../daemon/src/lib/conversation-target.ts
|
|
12460
12679
|
import { randomUUID as randomUUID18 } from "node:crypto";
|
|
12461
|
-
import { writeFileSync as
|
|
12462
|
-
import { join as
|
|
12680
|
+
import { writeFileSync as writeFileSync9 } from "node:fs";
|
|
12681
|
+
import { join as join27 } from "node:path";
|
|
12463
12682
|
import { SessionManager as SessionManager2 } from "@earendil-works/pi-coding-agent";
|
|
12464
12683
|
function sessionsDir(paths, agentId) {
|
|
12465
|
-
return
|
|
12684
|
+
return join27(paths.agentDir(agentId), "sessions");
|
|
12466
12685
|
}
|
|
12467
12686
|
function startConversation(db, paths, agentId, title) {
|
|
12468
12687
|
const agent = resolveAgent(db, paths, agentId);
|
|
12469
12688
|
if (title !== void 0) validTitle(title);
|
|
12470
12689
|
const id = randomUUID18();
|
|
12471
12690
|
const header = SessionManager2.inMemory(agent.team.path, { id }).getHeader();
|
|
12472
|
-
|
|
12691
|
+
writeFileSync9(join27(sessionsDir(paths, agentId), `${id}.jsonl`), `${JSON.stringify(header)}
|
|
12473
12692
|
`, {
|
|
12474
12693
|
flag: "wx",
|
|
12475
12694
|
mode: 384
|
|
@@ -12493,9 +12712,9 @@ function selectConversation(db, paths, agentId, id) {
|
|
|
12493
12712
|
}
|
|
12494
12713
|
var TITLE_CHARS = 60;
|
|
12495
12714
|
function titleFromMessage(message) {
|
|
12496
|
-
const
|
|
12497
|
-
if (!
|
|
12498
|
-
const clean = Array.from(
|
|
12715
|
+
const line2 = message.split("\n").map((part) => part.replace(/\s+/g, " ").trim()).find((part) => part.length > 0);
|
|
12716
|
+
if (!line2) return null;
|
|
12717
|
+
const clean = Array.from(line2).filter((char) => char.charCodeAt(0) >= 32 && char.charCodeAt(0) !== 127).join("").trim();
|
|
12499
12718
|
if (!clean) return null;
|
|
12500
12719
|
if (clean.length <= TITLE_CHARS) return clean;
|
|
12501
12720
|
const cut = clean.slice(0, TITLE_CHARS);
|
|
@@ -12517,7 +12736,7 @@ function selectedConversationTarget(db, agentId) {
|
|
|
12517
12736
|
|
|
12518
12737
|
// ../daemon/src/lib/repository-instructions.ts
|
|
12519
12738
|
import { realpathSync as realpathSync6 } from "node:fs";
|
|
12520
|
-
import { join as
|
|
12739
|
+
import { join as join28 } from "node:path";
|
|
12521
12740
|
var MAX_FILE_BYTES2 = 128 * 1024;
|
|
12522
12741
|
var SKIPPED = {
|
|
12523
12742
|
outside: "it resolves outside the Team workspace",
|
|
@@ -12537,7 +12756,7 @@ function loadRepositoryInstructions(root, cwd = ".") {
|
|
|
12537
12756
|
for (let depth = 0; depth <= parts.length; depth++) {
|
|
12538
12757
|
const path = [...parts.slice(0, depth), "AGENTS.md"].join("/");
|
|
12539
12758
|
try {
|
|
12540
|
-
const content = readContainedFile(
|
|
12759
|
+
const content = readContainedFile(join28(realRoot, path), realRoot, MAX_FILE_BYTES2);
|
|
12541
12760
|
instructions.push({ path, content: content.toString("utf8") });
|
|
12542
12761
|
} catch (error) {
|
|
12543
12762
|
if (error instanceof ContainedFileError) {
|
|
@@ -12777,7 +12996,31 @@ async function* runAgentTurn(turn) {
|
|
|
12777
12996
|
const { db, authToken } = getCtx();
|
|
12778
12997
|
const env = toolEnvironment(mergeSecretsIntoEnv(db, authToken), authToken);
|
|
12779
12998
|
const { apiKey: apiKey2, refreshApiKey } = await resolveAgentApiKey(db, authToken, turn.agent);
|
|
12780
|
-
const mcp = await resolveMcpForTurn(
|
|
12999
|
+
const mcp = await resolveMcpForTurn(
|
|
13000
|
+
db,
|
|
13001
|
+
authToken,
|
|
13002
|
+
turn.controller.signal,
|
|
13003
|
+
(request) => commandApprovalRegistry.begin(
|
|
13004
|
+
{
|
|
13005
|
+
id: randomUUID19(),
|
|
13006
|
+
turnId: turn.request.attemptId,
|
|
13007
|
+
toolCallId: request.toolCallId,
|
|
13008
|
+
agentId,
|
|
13009
|
+
teamId: turn.agent.team.id,
|
|
13010
|
+
command: request.command,
|
|
13011
|
+
risks: [
|
|
13012
|
+
{
|
|
13013
|
+
code: "outward-action",
|
|
13014
|
+
message: "It sends or changes something outside Bazilion.",
|
|
13015
|
+
span: { start: 0, end: 0 }
|
|
13016
|
+
}
|
|
13017
|
+
],
|
|
13018
|
+
mode: turn.bashApprovalMode,
|
|
13019
|
+
tool: request.tool
|
|
13020
|
+
},
|
|
13021
|
+
request.signal ?? turn.controller.signal
|
|
13022
|
+
)
|
|
13023
|
+
);
|
|
12781
13024
|
const frames = spawnWorkerTurn(
|
|
12782
13025
|
{
|
|
12783
13026
|
kind: "agent_turn",
|
|
@@ -13116,7 +13359,7 @@ agentChatRouter.post("/:id/chat", async (c) => {
|
|
|
13116
13359
|
}
|
|
13117
13360
|
const preparedTurn = await prepareAgentTurn({
|
|
13118
13361
|
origin: "http",
|
|
13119
|
-
attemptId: c.req.header("x-request-id") ??
|
|
13362
|
+
attemptId: c.req.header("x-request-id") ?? randomUUID20(),
|
|
13120
13363
|
agentId: id,
|
|
13121
13364
|
message,
|
|
13122
13365
|
attachments,
|
|
@@ -13179,7 +13422,7 @@ agentChatRouter.post("/:id/chat/compact", async (c) => {
|
|
|
13179
13422
|
const { db, paths, authToken } = getCtx();
|
|
13180
13423
|
const resolved = resolveAgent(db, paths, id);
|
|
13181
13424
|
assertProviderReady(db, authToken, resolved.model);
|
|
13182
|
-
const memory = qmdBackend(
|
|
13425
|
+
const memory = qmdBackend(join29(resolved.team.path, "memory"));
|
|
13183
13426
|
await memory.init();
|
|
13184
13427
|
const handle12 = await createBazilionSession({
|
|
13185
13428
|
agent: resolved,
|
|
@@ -13237,7 +13480,7 @@ agentChatRouter.get(
|
|
|
13237
13480
|
const env = mergeSecretsIntoEnv(db, authToken);
|
|
13238
13481
|
const files = [];
|
|
13239
13482
|
for (const file of CONTEXT_FILE_ORDER2) {
|
|
13240
|
-
const path =
|
|
13483
|
+
const path = join29(resolved.agent.dir, file);
|
|
13241
13484
|
if (!existsSync17(path)) continue;
|
|
13242
13485
|
const content = readFileSync11(path, "utf8").trimEnd();
|
|
13243
13486
|
if (!content) continue;
|
|
@@ -13252,7 +13495,7 @@ agentChatRouter.get(
|
|
|
13252
13495
|
agent: resolved,
|
|
13253
13496
|
paths,
|
|
13254
13497
|
env,
|
|
13255
|
-
memory: qmdBackend(
|
|
13498
|
+
memory: qmdBackend(join29(resolved.team.path, "memory")),
|
|
13256
13499
|
messagingHost: createDbMessagingHost(db),
|
|
13257
13500
|
userMdHost: createDbUserMdHost(db, paths),
|
|
13258
13501
|
// As in a chat turn: the operator is there.
|
|
@@ -13359,7 +13602,7 @@ agentChatRouter.post("/:id/chat/truncate", async (c) => {
|
|
|
13359
13602
|
});
|
|
13360
13603
|
|
|
13361
13604
|
// ../daemon/src/routes/agent-learning.ts
|
|
13362
|
-
import { join as
|
|
13605
|
+
import { join as join30 } from "node:path";
|
|
13363
13606
|
|
|
13364
13607
|
// ../daemon/src/lib/lesson-decisions.ts
|
|
13365
13608
|
var LessonProposalConflictError = class extends DomainError {
|
|
@@ -13558,7 +13801,7 @@ for (const decision of ["approve", "reject", "revoke"]) {
|
|
|
13558
13801
|
const team = teams_exports.get(db, agent.teamId, paths);
|
|
13559
13802
|
if (!team) return c.json({ error: `team not found: ${agent.teamId}` }, 404);
|
|
13560
13803
|
const proposal = await runAgentLifecycleMutation(agent.id, async () => {
|
|
13561
|
-
const memory = qmdBackend(
|
|
13804
|
+
const memory = qmdBackend(join30(team.path, "memory"));
|
|
13562
13805
|
if (decision === "approve") return approveLessonProposal(db, memory, current2.id, version);
|
|
13563
13806
|
if (decision === "reject") return rejectLessonProposal(db, current2.id, version);
|
|
13564
13807
|
return revokeLessonProposal(db, memory, current2.id, version);
|
|
@@ -13586,7 +13829,7 @@ function withEvidenceExcerpts(proposals, agent, paths) {
|
|
|
13586
13829
|
}
|
|
13587
13830
|
|
|
13588
13831
|
// ../daemon/src/routes/agents.ts
|
|
13589
|
-
import { join as
|
|
13832
|
+
import { join as join31 } from "node:path";
|
|
13590
13833
|
init_pool2();
|
|
13591
13834
|
|
|
13592
13835
|
// ../daemon/src/lib/telegram/profile-emojis.ts
|
|
@@ -13682,7 +13925,7 @@ agentsRouter.get("/", (c) => {
|
|
|
13682
13925
|
const includeArchived = c.req.query("includeArchived") === "true";
|
|
13683
13926
|
const agents = agents_exports.list(getCtx().db, { includeArchived }).map((agent) => ({
|
|
13684
13927
|
...agent,
|
|
13685
|
-
identity: loadIdentityFromFile(
|
|
13928
|
+
identity: loadIdentityFromFile(join31(agent.dir, "IDENTITY.md"))
|
|
13686
13929
|
}));
|
|
13687
13930
|
return c.json(agents);
|
|
13688
13931
|
});
|
|
@@ -13701,7 +13944,8 @@ agentsRouter.post("/", async (c) => {
|
|
|
13701
13944
|
...typeof body.name === "string" && body.name ? { name: body.name } : {},
|
|
13702
13945
|
...typeof body.model === "string" && body.model ? { modelOverride: body.model } : {},
|
|
13703
13946
|
...body.reasoningLevel ? { reasoningLevel: body.reasoningLevel } : {},
|
|
13704
|
-
...typeof body.teamId === "string" && body.teamId ? { teamId: body.teamId } : {}
|
|
13947
|
+
...typeof body.teamId === "string" && body.teamId ? { teamId: body.teamId } : {},
|
|
13948
|
+
...typeof body.role === "string" && body.role.trim() ? { role: body.role } : {}
|
|
13705
13949
|
});
|
|
13706
13950
|
notifyDirectoryDirty();
|
|
13707
13951
|
return c.json({ agent }, 201);
|
|
@@ -13723,6 +13967,12 @@ agentsRouter.patch("/:id", async (c) => {
|
|
|
13723
13967
|
}
|
|
13724
13968
|
const nameProblem = typeof name === "string" ? agentNameProblem(name.trim()) : null;
|
|
13725
13969
|
if (nameProblem) return c.json({ error: nameProblem }, 400);
|
|
13970
|
+
if (typeof name === "string") {
|
|
13971
|
+
const current2 = agents_exports.get(getCtx().db, id);
|
|
13972
|
+
if (current2 && agents_exports.nameTakenInTeam(getCtx().db, current2.teamId, name, id)) {
|
|
13973
|
+
return c.json({ error: `This Team already has an Agent named ${name.trim()}.` }, 409);
|
|
13974
|
+
}
|
|
13975
|
+
}
|
|
13726
13976
|
if (telegramMirrorMode !== void 0 && telegramMirrorMode !== "minimal" && telegramMirrorMode !== "verbose") {
|
|
13727
13977
|
return c.json({ error: `invalid telegramMirrorMode: ${String(telegramMirrorMode)}` }, 400);
|
|
13728
13978
|
}
|
|
@@ -13840,7 +14090,7 @@ function waitingAttention(db) {
|
|
|
13840
14090
|
occurredAt: approval.createdAt,
|
|
13841
14091
|
updatedAt: approval.createdAt,
|
|
13842
14092
|
expiresAt: approval.expiresAt,
|
|
13843
|
-
title: `${name(entry)} wants to run a command that needs your approval`,
|
|
14093
|
+
title: approval.tool ? `${name(entry)} wants to use ${approval.tool}, which needs your approval` : `${name(entry)} wants to run a command that needs your approval`,
|
|
13844
14094
|
diagnostic: bounded(`${command.slice(0, 200)}${risks ? `: ${risks}` : ""}`, "A command"),
|
|
13845
14095
|
href: href(approval.agentId),
|
|
13846
14096
|
acknowledgeable: false,
|
|
@@ -15114,7 +15364,7 @@ configRouter.delete("/fields/:envVar", (c) => {
|
|
|
15114
15364
|
});
|
|
15115
15365
|
|
|
15116
15366
|
// ../daemon/src/lib/conversation-search.ts
|
|
15117
|
-
import { join as
|
|
15367
|
+
import { join as join32 } from "node:path";
|
|
15118
15368
|
import { buildSessionContext as buildSessionContext2 } from "@earendil-works/pi-coding-agent";
|
|
15119
15369
|
var INBOX_WAKE_PREFIX = "[[bazilion:inbox-wake]]\n";
|
|
15120
15370
|
var MAX_WORDS = 8;
|
|
@@ -15158,7 +15408,7 @@ async function searchConversations(db, paths, options) {
|
|
|
15158
15408
|
for (const row of rows) {
|
|
15159
15409
|
await new Promise((resolve9) => setImmediate(resolve9));
|
|
15160
15410
|
if (options.signal?.aborted) break;
|
|
15161
|
-
const directory =
|
|
15411
|
+
const directory = join32(paths.agentDir(row.agentId), "sessions");
|
|
15162
15412
|
let text4;
|
|
15163
15413
|
try {
|
|
15164
15414
|
text4 = readSessionText(directory, row.id);
|
|
@@ -15179,10 +15429,10 @@ async function searchConversations(db, paths, options) {
|
|
|
15179
15429
|
let nth = 0;
|
|
15180
15430
|
for (const message of messages) {
|
|
15181
15431
|
if (message.role !== "user" && message.role !== "assistant") continue;
|
|
15182
|
-
const [
|
|
15183
|
-
if (!
|
|
15432
|
+
const [shown2] = piMessagesToProviderView([message], options.secrets ?? []);
|
|
15433
|
+
if (!shown2) continue;
|
|
15184
15434
|
const content = redactExactValues(
|
|
15185
|
-
|
|
15435
|
+
shown2.content.startsWith(INBOX_WAKE_PREFIX) ? shown2.content.slice(INBOX_WAKE_PREFIX.length) : shown2.content,
|
|
15186
15436
|
options.secrets ?? []
|
|
15187
15437
|
);
|
|
15188
15438
|
const found = plainText(content).toLowerCase();
|
|
@@ -15210,7 +15460,7 @@ async function searchConversations(db, paths, options) {
|
|
|
15210
15460
|
|
|
15211
15461
|
// ../daemon/src/lib/usage.ts
|
|
15212
15462
|
import { closeSync as closeSync6, constants as constants7, fstatSync as fstatSync6, openSync as openSync6, readdirSync as readdirSync7, readSync as readSync3 } from "node:fs";
|
|
15213
|
-
import { join as
|
|
15463
|
+
import { join as join33 } from "node:path";
|
|
15214
15464
|
var CONVERSATION_FILE = /^([0-9a-f-]{36})\.jsonl$/i;
|
|
15215
15465
|
var READ_CHUNK = 1024 * 1024;
|
|
15216
15466
|
var CACHE_KEY = /* @__PURE__ */ Symbol.for("bazilion.usage.files");
|
|
@@ -15243,10 +15493,10 @@ function toRecord(usage, at, provider, model) {
|
|
|
15243
15493
|
billed: usage.cost?.totalFromProvider === true
|
|
15244
15494
|
};
|
|
15245
15495
|
}
|
|
15246
|
-
function usageOfLine(
|
|
15496
|
+
function usageOfLine(line2, file) {
|
|
15247
15497
|
let entry;
|
|
15248
15498
|
try {
|
|
15249
|
-
entry = JSON.parse(
|
|
15499
|
+
entry = JSON.parse(line2);
|
|
15250
15500
|
} catch {
|
|
15251
15501
|
return null;
|
|
15252
15502
|
}
|
|
@@ -15312,9 +15562,9 @@ function scanFile(path) {
|
|
|
15312
15562
|
pending = Buffer.from(bytes.subarray(0, length));
|
|
15313
15563
|
continue;
|
|
15314
15564
|
}
|
|
15315
|
-
for (const
|
|
15316
|
-
if (!
|
|
15317
|
-
const record = usageOfLine(
|
|
15565
|
+
for (const line2 of bytes.subarray(0, end).toString("utf8").split("\n")) {
|
|
15566
|
+
if (!line2.trim()) continue;
|
|
15567
|
+
const record = usageOfLine(line2, file);
|
|
15318
15568
|
if (record) keep(file, record);
|
|
15319
15569
|
}
|
|
15320
15570
|
pending = Buffer.from(bytes.subarray(end + 1, length));
|
|
@@ -15330,7 +15580,7 @@ function scanUsage(paths, agentIds, options = {}) {
|
|
|
15330
15580
|
let unreadable = 0;
|
|
15331
15581
|
const seen = /* @__PURE__ */ new Set();
|
|
15332
15582
|
for (const agentId of agentIds) {
|
|
15333
|
-
const directory =
|
|
15583
|
+
const directory = join33(paths.agentDir(agentId), "sessions");
|
|
15334
15584
|
let names;
|
|
15335
15585
|
try {
|
|
15336
15586
|
names = readdirSync7(directory);
|
|
@@ -15340,7 +15590,7 @@ function scanUsage(paths, agentIds, options = {}) {
|
|
|
15340
15590
|
for (const name of names) {
|
|
15341
15591
|
const id = CONVERSATION_FILE.exec(name)?.[1];
|
|
15342
15592
|
if (!id) continue;
|
|
15343
|
-
const path =
|
|
15593
|
+
const path = join33(directory, name);
|
|
15344
15594
|
seen.add(path);
|
|
15345
15595
|
try {
|
|
15346
15596
|
const totals = scanFile(path).totals;
|
|
@@ -15350,7 +15600,7 @@ function scanUsage(paths, agentIds, options = {}) {
|
|
|
15350
15600
|
}
|
|
15351
15601
|
}
|
|
15352
15602
|
}
|
|
15353
|
-
const listed = agentIds.map((id) => `${
|
|
15603
|
+
const listed = agentIds.map((id) => `${join33(paths.agentDir(id), "sessions")}/`);
|
|
15354
15604
|
for (const path of cache().keys()) {
|
|
15355
15605
|
if (seen.has(path)) continue;
|
|
15356
15606
|
if (options.everyAgent || listed.some((prefix) => path.startsWith(prefix))) cache().delete(path);
|
|
@@ -15438,13 +15688,13 @@ var bySpend = (a, b) => b.cost - a.cost || b.totalTokens - a.totalTokens;
|
|
|
15438
15688
|
function usageReport(db, paths, query) {
|
|
15439
15689
|
const plans = query.plans ?? ALWAYS_PLANS;
|
|
15440
15690
|
const agents = agentRows(db);
|
|
15441
|
-
const
|
|
15691
|
+
const shown2 = agents.filter(
|
|
15442
15692
|
(agent) => (!query.agentId || agent.id === query.agentId) && (!query.teamId || agent.team_id === query.teamId)
|
|
15443
15693
|
);
|
|
15444
15694
|
const { conversations, unreadable } = scanUsage(
|
|
15445
15695
|
paths,
|
|
15446
|
-
|
|
15447
|
-
{ everyAgent:
|
|
15696
|
+
shown2.map((agent) => agent.id),
|
|
15697
|
+
{ everyAgent: shown2.length === agents.length }
|
|
15448
15698
|
);
|
|
15449
15699
|
const to = dayOf(query.now ?? Date.now(), query.timeZone);
|
|
15450
15700
|
const from = query.days === null ? null : shiftDay(to, -(query.days - 1));
|
|
@@ -15775,6 +16025,37 @@ eventsRouter.get("/", (c) => {
|
|
|
15775
16025
|
init_pool();
|
|
15776
16026
|
var mcpRouter = newRouter();
|
|
15777
16027
|
var TRANSPORTS = /* @__PURE__ */ new Set(["stdio", "http"]);
|
|
16028
|
+
function shown(server3) {
|
|
16029
|
+
const { db, authToken } = getCtx();
|
|
16030
|
+
return {
|
|
16031
|
+
...server3,
|
|
16032
|
+
envNames: serverEnvNames(db, authToken, server3.id),
|
|
16033
|
+
ask: askChoices(db, authToken, server3.id)
|
|
16034
|
+
};
|
|
16035
|
+
}
|
|
16036
|
+
function validateSettings(input, transport) {
|
|
16037
|
+
if (input.env !== void 0) {
|
|
16038
|
+
if (transport !== "stdio")
|
|
16039
|
+
return "env is for stdio servers; an http server takes a bearer token";
|
|
16040
|
+
if (!input.env || typeof input.env !== "object" || Array.isArray(input.env))
|
|
16041
|
+
return "env must be an object of variable names to values (or null to remove one)";
|
|
16042
|
+
for (const [name, value] of Object.entries(input.env)) {
|
|
16043
|
+
if (!validEnvName(name)) return `env: ${name} is not a variable name`;
|
|
16044
|
+
if (value !== null && typeof value !== "string")
|
|
16045
|
+
return `env: ${name} must be a string or null`;
|
|
16046
|
+
}
|
|
16047
|
+
}
|
|
16048
|
+
if (input.ask !== void 0 && input.ask !== null) {
|
|
16049
|
+
if (typeof input.ask !== "object" || Array.isArray(input.ask) || !Object.values(input.ask).every((asks) => typeof asks === "boolean"))
|
|
16050
|
+
return "ask must map tool names to true (asks first) or false (never asks), or be null";
|
|
16051
|
+
}
|
|
16052
|
+
return null;
|
|
16053
|
+
}
|
|
16054
|
+
function applySettings(id, input) {
|
|
16055
|
+
const { db, authToken } = getCtx();
|
|
16056
|
+
if (input.env) setServerEnv(db, authToken, id, input.env);
|
|
16057
|
+
if (input.ask !== void 0) setAskChoices(db, authToken, id, input.ask);
|
|
16058
|
+
}
|
|
15778
16059
|
function validate(input) {
|
|
15779
16060
|
if (!input.name || !/^[a-zA-Z0-9_]+$/.test(input.name)) {
|
|
15780
16061
|
return "name is required and must match [a-zA-Z0-9_]+ (letters, digits, underscore)";
|
|
@@ -15796,12 +16077,12 @@ function validate(input) {
|
|
|
15796
16077
|
}
|
|
15797
16078
|
mcpRouter.get("/", (c) => {
|
|
15798
16079
|
const { db } = getCtx();
|
|
15799
|
-
return c.json({ servers: mcpServers_exports.list(db) });
|
|
16080
|
+
return c.json({ servers: mcpServers_exports.list(db).map(shown) });
|
|
15800
16081
|
});
|
|
15801
16082
|
mcpRouter.post("/", async (c) => {
|
|
15802
16083
|
const body = await jsonBody(c);
|
|
15803
16084
|
if (!body) return c.json({ error: "invalid JSON body" }, 400);
|
|
15804
|
-
const err = validate(body);
|
|
16085
|
+
const err = validate(body) ?? validateSettings(body, body.transport);
|
|
15805
16086
|
if (err) return c.json({ error: err }, 400);
|
|
15806
16087
|
const { db, authToken } = getCtx();
|
|
15807
16088
|
if (mcpServers_exports.getByName(db, body.name)) {
|
|
@@ -15820,13 +16101,14 @@ mcpRouter.post("/", async (c) => {
|
|
|
15820
16101
|
if (hasAuth) {
|
|
15821
16102
|
openSecrets(db, authToken).set(mcpTokenSecretKey(server3.id), body.authToken);
|
|
15822
16103
|
}
|
|
15823
|
-
|
|
16104
|
+
applySettings(server3.id, body);
|
|
16105
|
+
return c.json({ server: shown(server3) }, 201);
|
|
15824
16106
|
});
|
|
15825
16107
|
mcpRouter.get("/:id", (c) => {
|
|
15826
16108
|
const { db } = getCtx();
|
|
15827
16109
|
const server3 = mcpServers_exports.get(db, c.req.param("id"));
|
|
15828
16110
|
if (!server3) return c.json({ error: "MCP server not found" }, 404);
|
|
15829
|
-
return c.json({ server: server3 });
|
|
16111
|
+
return c.json({ server: shown(server3) });
|
|
15830
16112
|
});
|
|
15831
16113
|
mcpRouter.patch("/:id", async (c) => {
|
|
15832
16114
|
const id = c.req.param("id");
|
|
@@ -15842,7 +16124,7 @@ mcpRouter.patch("/:id", async (c) => {
|
|
|
15842
16124
|
args: body.args ?? existing.args,
|
|
15843
16125
|
url: body.url !== void 0 ? body.url : existing.url
|
|
15844
16126
|
};
|
|
15845
|
-
const err = validate(merged);
|
|
16127
|
+
const err = validate(merged) ?? validateSettings(body, merged.transport);
|
|
15846
16128
|
if (err) return c.json({ error: err }, 400);
|
|
15847
16129
|
if (merged.name !== existing.name && mcpServers_exports.getByName(db, merged.name)) {
|
|
15848
16130
|
return c.json({ error: `an MCP server named "${merged.name}" already exists` }, 409);
|
|
@@ -15865,8 +16147,10 @@ mcpRouter.patch("/:id", async (c) => {
|
|
|
15865
16147
|
enabled: body.enabled,
|
|
15866
16148
|
hasAuth
|
|
15867
16149
|
});
|
|
16150
|
+
if (!server3) return c.json({ error: "MCP server not found" }, 404);
|
|
16151
|
+
applySettings(id, body);
|
|
15868
16152
|
await closeMcpConnection(id);
|
|
15869
|
-
return c.json({ server: server3 });
|
|
16153
|
+
return c.json({ server: shown(server3) });
|
|
15870
16154
|
});
|
|
15871
16155
|
mcpRouter.delete("/:id", async (c) => {
|
|
15872
16156
|
const id = c.req.param("id");
|
|
@@ -15874,6 +16158,7 @@ mcpRouter.delete("/:id", async (c) => {
|
|
|
15874
16158
|
if (!mcpServers_exports.get(db, id)) return c.json({ error: "MCP server not found" }, 404);
|
|
15875
16159
|
await closeMcpConnection(id);
|
|
15876
16160
|
openSecrets(db, authToken).remove(mcpTokenSecretKey(id));
|
|
16161
|
+
removeServerSettings(db, authToken, id);
|
|
15877
16162
|
mcpServers_exports.remove(db, id);
|
|
15878
16163
|
return c.body(null, 204);
|
|
15879
16164
|
});
|
|
@@ -15885,7 +16170,13 @@ mcpRouter.post("/:id/test", async (c) => {
|
|
|
15885
16170
|
await closeMcpConnection(id);
|
|
15886
16171
|
try {
|
|
15887
16172
|
const tools = await listMcpTools(server3, () => mcpConnectOptions(db, authToken, server3));
|
|
15888
|
-
const
|
|
16173
|
+
const chosen = askChoices(db, authToken, server3.id);
|
|
16174
|
+
const info = tools.map((t) => ({
|
|
16175
|
+
name: t.rawName,
|
|
16176
|
+
description: t.description,
|
|
16177
|
+
asks: toolAsks(chosen, t.rawName),
|
|
16178
|
+
asksByDefault: looksOutward(t.rawName)
|
|
16179
|
+
}));
|
|
15889
16180
|
return c.json({ ok: true, tools: info });
|
|
15890
16181
|
} catch (err) {
|
|
15891
16182
|
return c.json({ ok: false, error: err instanceof Error ? err.message : String(err) }, 502);
|
|
@@ -15956,23 +16247,23 @@ agentMessagesRouter.post("/:id/messages", async (c) => {
|
|
|
15956
16247
|
// ../daemon/src/routes/misc.ts
|
|
15957
16248
|
import { existsSync as existsSync18 } from "node:fs";
|
|
15958
16249
|
import { homedir as homedir4 } from "node:os";
|
|
15959
|
-
import { join as
|
|
16250
|
+
import { join as join36 } from "node:path";
|
|
15960
16251
|
|
|
15961
16252
|
// ../daemon/src/lib/backup.ts
|
|
15962
|
-
import { mkdtempSync as mkdtempSync3, rmSync as
|
|
16253
|
+
import { mkdtempSync as mkdtempSync3, rmSync as rmSync13 } from "node:fs";
|
|
15963
16254
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
15964
|
-
import { join as
|
|
16255
|
+
import { join as join35, resolve as resolve7 } from "node:path";
|
|
15965
16256
|
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
15966
16257
|
import { create as create6 } from "tar";
|
|
15967
16258
|
|
|
15968
16259
|
// ../daemon/src/lib/daemon-liveness.ts
|
|
15969
|
-
import { mkdirSync as mkdirSync11, readFileSync as readFileSync12, rmSync as
|
|
15970
|
-
import { join as
|
|
16260
|
+
import { mkdirSync as mkdirSync11, readFileSync as readFileSync12, rmSync as rmSync12, writeFileSync as writeFileSync10 } from "node:fs";
|
|
16261
|
+
import { join as join34 } from "node:path";
|
|
15971
16262
|
var DAEMON_PID_FILE = "daemon.pid";
|
|
15972
16263
|
function runningDaemonPid(home) {
|
|
15973
16264
|
let pid;
|
|
15974
16265
|
try {
|
|
15975
|
-
pid = Number.parseInt(readFileSync12(
|
|
16266
|
+
pid = Number.parseInt(readFileSync12(join34(home, DAEMON_PID_FILE), "utf8"), 10);
|
|
15976
16267
|
} catch (error) {
|
|
15977
16268
|
if (error.code === "ENOENT") return null;
|
|
15978
16269
|
throw error;
|
|
@@ -15989,26 +16280,26 @@ function assertDaemonStopped(home) {
|
|
|
15989
16280
|
const pid = runningDaemonPid(home);
|
|
15990
16281
|
if (pid !== null) {
|
|
15991
16282
|
throw new Error(
|
|
15992
|
-
`a bazilion daemon (pid ${pid}) is running on ${home}; stop it first (if none is running, delete ${
|
|
16283
|
+
`a bazilion daemon (pid ${pid}) is running on ${home}; stop it first (if none is running, delete ${join34(home, DAEMON_PID_FILE)})`
|
|
15993
16284
|
);
|
|
15994
16285
|
}
|
|
15995
16286
|
}
|
|
15996
16287
|
function claimDaemonPidFile(home) {
|
|
15997
|
-
const path =
|
|
16288
|
+
const path = join34(home, DAEMON_PID_FILE);
|
|
15998
16289
|
const content = `${process.pid}
|
|
15999
16290
|
`;
|
|
16000
16291
|
mkdirSync11(home, { recursive: true });
|
|
16001
16292
|
try {
|
|
16002
|
-
|
|
16293
|
+
writeFileSync10(path, content, { flag: "wx", mode: 384 });
|
|
16003
16294
|
} catch (error) {
|
|
16004
16295
|
if (error.code !== "EEXIST") throw error;
|
|
16005
16296
|
assertDaemonStopped(home);
|
|
16006
|
-
|
|
16007
|
-
|
|
16297
|
+
rmSync12(path, { force: true });
|
|
16298
|
+
writeFileSync10(path, content, { flag: "wx", mode: 384 });
|
|
16008
16299
|
}
|
|
16009
16300
|
return () => {
|
|
16010
16301
|
try {
|
|
16011
|
-
if (readFileSync12(path, "utf8") === content)
|
|
16302
|
+
if (readFileSync12(path, "utf8") === content) rmSync12(path);
|
|
16012
16303
|
} catch {
|
|
16013
16304
|
}
|
|
16014
16305
|
};
|
|
@@ -16023,10 +16314,10 @@ function createBackupSnapshot(db) {
|
|
|
16023
16314
|
return snapshot3;
|
|
16024
16315
|
}
|
|
16025
16316
|
async function takeSnapshot(db) {
|
|
16026
|
-
const directory = mkdtempSync3(
|
|
16027
|
-
const cleanup = () =>
|
|
16317
|
+
const directory = mkdtempSync3(join35(tmpdir3(), "bazilion-backup-"));
|
|
16318
|
+
const cleanup = () => rmSync13(directory, { recursive: true, force: true });
|
|
16028
16319
|
try {
|
|
16029
|
-
const database =
|
|
16320
|
+
const database = join35(directory, "bazilion.snapshot");
|
|
16030
16321
|
await db.backupTo(database);
|
|
16031
16322
|
const snapshot3 = new DatabaseSync2(database, { readOnly: true });
|
|
16032
16323
|
try {
|
|
@@ -16107,14 +16398,15 @@ miscRouter.get("/health/details", async (c) => {
|
|
|
16107
16398
|
}
|
|
16108
16399
|
}
|
|
16109
16400
|
const skills = discoverSkills(paths);
|
|
16110
|
-
|
|
16401
|
+
const broken = [];
|
|
16111
16402
|
for (const s of skills) {
|
|
16112
16403
|
try {
|
|
16113
16404
|
parseSkillFile(s.skillFile);
|
|
16114
|
-
} catch {
|
|
16115
|
-
|
|
16405
|
+
} catch (error) {
|
|
16406
|
+
broken.push({ name: s.name, error: error instanceof Error ? error.message : String(error) });
|
|
16116
16407
|
}
|
|
16117
16408
|
}
|
|
16409
|
+
const parseErrors = broken.length;
|
|
16118
16410
|
let effectiveEnv2 = process.env;
|
|
16119
16411
|
let codexConnected = false;
|
|
16120
16412
|
if (pathChecks.auth && pathChecks.db) {
|
|
@@ -16125,7 +16417,7 @@ miscRouter.get("/health/details", async (c) => {
|
|
|
16125
16417
|
} catch {
|
|
16126
16418
|
}
|
|
16127
16419
|
}
|
|
16128
|
-
const openclawSkillsDir =
|
|
16420
|
+
const openclawSkillsDir = join36(homedir4(), ".openclaw", "skills");
|
|
16129
16421
|
const providerSection = {
|
|
16130
16422
|
// Hosted providers with credentials; local servers are reported below.
|
|
16131
16423
|
configured: PROVIDERS.filter(
|
|
@@ -16167,7 +16459,13 @@ miscRouter.get("/health/details", async (c) => {
|
|
|
16167
16459
|
home: paths.home,
|
|
16168
16460
|
paths: pathChecks,
|
|
16169
16461
|
database,
|
|
16170
|
-
skills: { installed: skills.length, parseErrors },
|
|
16462
|
+
skills: { installed: skills.length, parseErrors, broken },
|
|
16463
|
+
problems: [
|
|
16464
|
+
...Object.entries(pathChecks).filter(([, present]) => !present).map(([name]) => `The ${name === "db" ? "database" : name} of the home is missing.`),
|
|
16465
|
+
...database && !database.ok ? [database.error] : [],
|
|
16466
|
+
...broken.map((skill) => `The skill ${skill.name} cannot be read: ${skill.error}`),
|
|
16467
|
+
...shellSecurity.ok ? [] : [`How Agents run commands is not set right: ${shellSecurity.error}`]
|
|
16468
|
+
],
|
|
16171
16469
|
providers: providerSection,
|
|
16172
16470
|
webSearch: {
|
|
16173
16471
|
braveConfigured: Boolean(effectiveEnv2.BRAVE_API_KEY?.trim()),
|
|
@@ -16358,11 +16656,11 @@ function forgetClosed(db, openKeys) {
|
|
|
16358
16656
|
|
|
16359
16657
|
// ../daemon/src/lib/notification-message.ts
|
|
16360
16658
|
function display(value) {
|
|
16361
|
-
const
|
|
16659
|
+
const line2 = Array.from(value, (character) => {
|
|
16362
16660
|
const code = character.codePointAt(0) ?? 0;
|
|
16363
16661
|
return code < 32 || code >= 127 && code <= 159 ? " " : character;
|
|
16364
16662
|
});
|
|
16365
|
-
return htmlEscape(
|
|
16663
|
+
return htmlEscape(line2.slice(0, 80).join(""));
|
|
16366
16664
|
}
|
|
16367
16665
|
function publicOrigin(env) {
|
|
16368
16666
|
try {
|
|
@@ -16533,8 +16831,8 @@ notificationsRouter.put("/", async (c) => {
|
|
|
16533
16831
|
});
|
|
16534
16832
|
|
|
16535
16833
|
// ../daemon/src/routes/profiles.ts
|
|
16536
|
-
import { existsSync as existsSync19, readFileSync as readFileSync13, writeFileSync as
|
|
16537
|
-
import { join as
|
|
16834
|
+
import { existsSync as existsSync19, readFileSync as readFileSync13, writeFileSync as writeFileSync11 } from "node:fs";
|
|
16835
|
+
import { join as join37 } from "node:path";
|
|
16538
16836
|
var profilesRouter = newRouter();
|
|
16539
16837
|
profilesRouter.get("/", (c) => {
|
|
16540
16838
|
const { db } = getCtx();
|
|
@@ -16616,7 +16914,7 @@ function profileFile(c) {
|
|
|
16616
16914
|
if (!PROFILE_FILES.includes(file)) {
|
|
16617
16915
|
return c.json({ error: `unsupported file: ${file}` }, 400);
|
|
16618
16916
|
}
|
|
16619
|
-
return
|
|
16917
|
+
return join37(paths.profilesDir, id, file);
|
|
16620
16918
|
}
|
|
16621
16919
|
profilesRouter.get("/:id/files/:file", (c) => {
|
|
16622
16920
|
const path = profileFile(c);
|
|
@@ -16629,7 +16927,7 @@ profilesRouter.put("/:id/files/:file", async (c) => {
|
|
|
16629
16927
|
if (typeof body?.content !== "string") return c.json({ error: "content is required" }, 400);
|
|
16630
16928
|
const path = profileFile(c);
|
|
16631
16929
|
if (typeof path !== "string") return path;
|
|
16632
|
-
|
|
16930
|
+
writeFileSync11(path, body.content);
|
|
16633
16931
|
return c.body(null, 204);
|
|
16634
16932
|
});
|
|
16635
16933
|
|
|
@@ -16847,22 +17145,22 @@ resultsRouter.get("/:id/preview", (c) => {
|
|
|
16847
17145
|
try {
|
|
16848
17146
|
const bytes = read(db, result.id);
|
|
16849
17147
|
if (text4) {
|
|
16850
|
-
let
|
|
17148
|
+
let shown2;
|
|
16851
17149
|
try {
|
|
16852
|
-
|
|
17150
|
+
shown2 = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
16853
17151
|
} catch {
|
|
16854
17152
|
return c.json({ error: "This file is not text. Use Download." }, 415);
|
|
16855
17153
|
}
|
|
16856
|
-
if (
|
|
17154
|
+
if (shown2.includes("\0"))
|
|
16857
17155
|
return c.json({ error: "This file is not text. Use Download." }, 415);
|
|
16858
|
-
if (cut !== null && Buffer.byteLength(
|
|
16859
|
-
|
|
17156
|
+
if (cut !== null && Buffer.byteLength(shown2) > cut) {
|
|
17157
|
+
shown2 = Buffer.from(shown2).subarray(0, cut).toString("utf8").replace(/\uFFFD$/, "");
|
|
16860
17158
|
}
|
|
16861
17159
|
c.header("Content-Type", "text/plain; charset=utf-8");
|
|
16862
17160
|
c.header("X-Content-Type-Options", "nosniff");
|
|
16863
17161
|
c.header("Content-Security-Policy", "default-src 'none'; sandbox");
|
|
16864
17162
|
c.header("Cache-Control", "private, max-age=3600");
|
|
16865
|
-
return c.body(
|
|
17163
|
+
return c.body(shown2);
|
|
16866
17164
|
}
|
|
16867
17165
|
const magic = result.mimeType === "image/png" ? bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])) : result.mimeType === "image/jpeg" ? bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255 : result.mimeType === "image/gif" ? ["GIF87a", "GIF89a"].includes(bytes.subarray(0, 6).toString("ascii")) : result.mimeType === "image/webp" ? bytes.subarray(0, 4).toString("ascii") === "RIFF" && bytes.subarray(8, 12).toString("ascii") === "WEBP" : false;
|
|
16868
17166
|
if (image && !magic)
|
|
@@ -16899,9 +17197,9 @@ shellApprovalsRouter.post("/:id", async (c) => {
|
|
|
16899
17197
|
});
|
|
16900
17198
|
|
|
16901
17199
|
// ../daemon/src/routes/skills.ts
|
|
16902
|
-
import { mkdtempSync as mkdtempSync4, rmSync as
|
|
17200
|
+
import { mkdtempSync as mkdtempSync4, rmSync as rmSync14, writeFileSync as writeFileSync12 } from "node:fs";
|
|
16903
17201
|
import { homedir as homedir5, tmpdir as tmpdir4 } from "node:os";
|
|
16904
|
-
import { join as
|
|
17202
|
+
import { join as join38 } from "node:path";
|
|
16905
17203
|
var MAX_ZIP_BYTES = 50 * 1024 * 1024;
|
|
16906
17204
|
var skillsRouter = newRouter();
|
|
16907
17205
|
skillsRouter.get("/", (c) => {
|
|
@@ -16931,7 +17229,7 @@ skillsRouter.delete("/:name", (c) => {
|
|
|
16931
17229
|
const name = c.req.param("name");
|
|
16932
17230
|
const skill = discoverSkills(paths).find((s) => s.name === name);
|
|
16933
17231
|
if (!skill) return c.json({ error: `skill not found: ${name}` }, 404);
|
|
16934
|
-
|
|
17232
|
+
rmSync14(skill.dir, { recursive: true, force: true });
|
|
16935
17233
|
skillMeta_exports.remove(db, name);
|
|
16936
17234
|
return c.body(null, 204);
|
|
16937
17235
|
});
|
|
@@ -16968,7 +17266,7 @@ skillsRouter.post("/import", async (c) => {
|
|
|
16968
17266
|
}
|
|
16969
17267
|
return c.json({ error: err.message }, 400);
|
|
16970
17268
|
} finally {
|
|
16971
|
-
if (input.tempZipPath)
|
|
17269
|
+
if (input.tempZipPath) rmSync14(input.tempZipPath, { recursive: true, force: true });
|
|
16972
17270
|
}
|
|
16973
17271
|
});
|
|
16974
17272
|
function flattenFindings(findings) {
|
|
@@ -16994,10 +17292,10 @@ async function parseImportInput(request) {
|
|
|
16994
17292
|
if (!filename.toLowerCase().endsWith(".zip")) {
|
|
16995
17293
|
throw new Error("uploaded file must be a .zip archive");
|
|
16996
17294
|
}
|
|
16997
|
-
const tmpDir = mkdtempSync4(
|
|
16998
|
-
const zipPath =
|
|
17295
|
+
const tmpDir = mkdtempSync4(join38(tmpdir4(), "bazilion-skill-upload-"));
|
|
17296
|
+
const zipPath = join38(tmpDir, filename.replace(/[^\w.-]+/g, "_"));
|
|
16999
17297
|
const buf = Buffer.from(await file.arrayBuffer());
|
|
17000
|
-
|
|
17298
|
+
writeFileSync12(zipPath, buf);
|
|
17001
17299
|
const forceField = form.get("force");
|
|
17002
17300
|
return {
|
|
17003
17301
|
source: zipPath,
|
|
@@ -17011,7 +17309,7 @@ async function parseImportInput(request) {
|
|
|
17011
17309
|
const { source } = body;
|
|
17012
17310
|
if (typeof source !== "string" || !source) throw new Error("source is required");
|
|
17013
17311
|
return {
|
|
17014
|
-
source: source === "openclaw" ?
|
|
17312
|
+
source: source === "openclaw" ? join38(homedir5(), ".openclaw", "skills") : source,
|
|
17015
17313
|
force: Boolean(body.force),
|
|
17016
17314
|
tempZipPath: null,
|
|
17017
17315
|
sourceLabel: source
|
|
@@ -17081,7 +17379,7 @@ teamCodingEnvironmentRouter.put("/:id/coding-environment", async (c) => {
|
|
|
17081
17379
|
});
|
|
17082
17380
|
|
|
17083
17381
|
// ../daemon/src/routes/team-memory.ts
|
|
17084
|
-
import { join as
|
|
17382
|
+
import { join as join39 } from "node:path";
|
|
17085
17383
|
var teamMemoryRouter = newRouter();
|
|
17086
17384
|
teamMemoryRouter.onError((error, c) => {
|
|
17087
17385
|
const safe = sanitizeNativeModuleError(error, { subject: "Bazilion memory" });
|
|
@@ -17089,7 +17387,7 @@ teamMemoryRouter.onError((error, c) => {
|
|
|
17089
17387
|
return onRouteError(safe, c);
|
|
17090
17388
|
});
|
|
17091
17389
|
async function openMemory(c) {
|
|
17092
|
-
const mem = qmdBackend(
|
|
17390
|
+
const mem = qmdBackend(join39(routeTeam(c).path, "memory"));
|
|
17093
17391
|
await mem.init();
|
|
17094
17392
|
return mem;
|
|
17095
17393
|
}
|
|
@@ -17155,7 +17453,7 @@ import {
|
|
|
17155
17453
|
readSync as readSync4,
|
|
17156
17454
|
realpathSync as realpathSync7
|
|
17157
17455
|
} from "node:fs";
|
|
17158
|
-
import { join as
|
|
17456
|
+
import { join as join40 } from "node:path";
|
|
17159
17457
|
var hash = (value) => createHash9("sha256").update(value).digest("hex");
|
|
17160
17458
|
var ContextReadError = class extends Error {
|
|
17161
17459
|
code;
|
|
@@ -17193,12 +17491,12 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
17193
17491
|
this.parent = parent;
|
|
17194
17492
|
if (parent) component(registeredPath);
|
|
17195
17493
|
parent?.assertOpen();
|
|
17196
|
-
const canonicalPath = parent ?
|
|
17494
|
+
const canonicalPath = parent ? join40(parent.canonicalPath, registeredPath) : realpathSync7(registeredPath);
|
|
17197
17495
|
this.canonicalPath = canonicalPath;
|
|
17198
17496
|
let fd;
|
|
17199
17497
|
try {
|
|
17200
17498
|
fd = openSync7(
|
|
17201
|
-
parent ?
|
|
17499
|
+
parent ? join40(parent.path, registeredPath) : canonicalPath,
|
|
17202
17500
|
constants8.O_RDONLY | constants8.O_DIRECTORY | constants8.O_NOFOLLOW
|
|
17203
17501
|
);
|
|
17204
17502
|
const stat = fstatSync7(fd, { bigint: true });
|
|
@@ -17247,7 +17545,7 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
17247
17545
|
entry(name) {
|
|
17248
17546
|
component(name);
|
|
17249
17547
|
this.assertOpen();
|
|
17250
|
-
const path =
|
|
17548
|
+
const path = join40(this.path, name);
|
|
17251
17549
|
try {
|
|
17252
17550
|
return lstatSync6(path);
|
|
17253
17551
|
} catch (error) {
|
|
@@ -17256,7 +17554,7 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
17256
17554
|
}
|
|
17257
17555
|
}
|
|
17258
17556
|
observe(name) {
|
|
17259
|
-
const path =
|
|
17557
|
+
const path = join40(this.path, name);
|
|
17260
17558
|
try {
|
|
17261
17559
|
return lstatSync6(path, { bigint: true });
|
|
17262
17560
|
} catch (error) {
|
|
@@ -17299,7 +17597,7 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
17299
17597
|
let fd;
|
|
17300
17598
|
try {
|
|
17301
17599
|
fd = openSync7(
|
|
17302
|
-
|
|
17600
|
+
join40(this.path, name),
|
|
17303
17601
|
constants8.O_RDONLY | constants8.O_NOFOLLOW | constants8.O_NONBLOCK
|
|
17304
17602
|
);
|
|
17305
17603
|
const before = fstatSync7(fd, { bigint: true });
|
|
@@ -17326,7 +17624,7 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
17326
17624
|
}
|
|
17327
17625
|
validate(skipGit = false, names) {
|
|
17328
17626
|
this.assertOpen();
|
|
17329
|
-
const currentPath = this.parent ?
|
|
17627
|
+
const currentPath = this.parent ? join40(this.parent.path, this.registeredPath) : realpathSync7(this.registeredPath);
|
|
17330
17628
|
const stat = lstatSync6(currentPath, { bigint: true });
|
|
17331
17629
|
if (!stat.isDirectory() || identity(stat) !== identity(this.originalIdentity))
|
|
17332
17630
|
throw new ContextReadError("root_changed");
|
|
@@ -17588,7 +17886,7 @@ new file mode ${file.executable ? "100755" : "100644"}
|
|
|
17588
17886
|
+++ b/${path}
|
|
17589
17887
|
@@ -0,0 +${range} @@
|
|
17590
17888
|
`,
|
|
17591
|
-
...lines.map((
|
|
17889
|
+
...lines.map((line2) => `+${line2}
|
|
17592
17890
|
`),
|
|
17593
17891
|
finalNewline ? "" : "\\n"
|
|
17594
17892
|
].join("");
|
|
@@ -17752,9 +18050,9 @@ async function readOrNull(captured, args) {
|
|
|
17752
18050
|
|
|
17753
18051
|
// ../daemon/src/lib/git/capture.ts
|
|
17754
18052
|
import { execFile } from "node:child_process";
|
|
17755
|
-
import { mkdirSync as mkdirSync12, mkdtempSync as mkdtempSync5, rmSync as
|
|
18053
|
+
import { mkdirSync as mkdirSync12, mkdtempSync as mkdtempSync5, rmSync as rmSync15, utimesSync, writeFileSync as writeFileSync13 } from "node:fs";
|
|
17756
18054
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
17757
|
-
import { join as
|
|
18055
|
+
import { join as join41 } from "node:path";
|
|
17758
18056
|
var INSPECTION_BUDGET_MS = 5e3;
|
|
17759
18057
|
var METADATA_BUDGET_MS = 2500;
|
|
17760
18058
|
var METADATA_BYTES = 64 * 1024 * 1024;
|
|
@@ -17783,12 +18081,12 @@ async function captureRepositoryGit(root, budgetMs = INSPECTION_BUDGET_MS) {
|
|
|
17783
18081
|
const dir = git.directory("info");
|
|
17784
18082
|
if (dir.entry("sparse-checkout")) throw new ContextReadError("unsupported_git_metadata");
|
|
17785
18083
|
}
|
|
17786
|
-
const scratch = mkdtempSync5(
|
|
18084
|
+
const scratch = mkdtempSync5(join41(tmpdir5(), "bazilion-context-git-"));
|
|
17787
18085
|
let cleaned = false;
|
|
17788
18086
|
const cleanup = () => {
|
|
17789
18087
|
if (cleaned) return;
|
|
17790
18088
|
cleaned = true;
|
|
17791
|
-
|
|
18089
|
+
rmSync15(scratch, { recursive: true, force: true });
|
|
17792
18090
|
};
|
|
17793
18091
|
const checkBudget = () => {
|
|
17794
18092
|
if (Date.now() - start2 >= budgetMs) throw new ContextReadError("git_timeout");
|
|
@@ -17844,8 +18142,8 @@ async function captureRepositoryGit(root, budgetMs = INSPECTION_BUDGET_MS) {
|
|
|
17844
18142
|
if (capturedConfig) {
|
|
17845
18143
|
bytes += capturedConfig.length;
|
|
17846
18144
|
count2++;
|
|
17847
|
-
const configPath =
|
|
17848
|
-
|
|
18145
|
+
const configPath = join41(scratch, "captured-config");
|
|
18146
|
+
writeFileSync13(configPath, capturedConfig, { mode: 384 });
|
|
17849
18147
|
const config = await rawGit([
|
|
17850
18148
|
"config",
|
|
17851
18149
|
"--no-includes",
|
|
@@ -17897,8 +18195,8 @@ objectformat = ${value}`
|
|
|
17897
18195
|
const exclude = git.directory("info").read("exclude", METADATA_READ);
|
|
17898
18196
|
if (exclude) {
|
|
17899
18197
|
bytes += exclude.length;
|
|
17900
|
-
mkdirSync12(
|
|
17901
|
-
|
|
18198
|
+
mkdirSync12(join41(scratch, "info"), { mode: 448 });
|
|
18199
|
+
writeFileSync13(join41(scratch, "info", "exclude"), exclude, { mode: 384 });
|
|
17902
18200
|
}
|
|
17903
18201
|
}
|
|
17904
18202
|
const copy = (source, destination, depth) => {
|
|
@@ -17911,13 +18209,13 @@ objectformat = ${value}`
|
|
|
17911
18209
|
if (name === "alternates" || name === "http-alternates")
|
|
17912
18210
|
throw new ContextReadError("unsupported_git_metadata");
|
|
17913
18211
|
if (entry.isDirectory()) {
|
|
17914
|
-
mkdirSync12(
|
|
17915
|
-
copy(source.directory(name),
|
|
18212
|
+
mkdirSync12(join41(destination, name), { mode: 448 });
|
|
18213
|
+
copy(source.directory(name), join41(destination, name), depth + 1);
|
|
17916
18214
|
} else {
|
|
17917
18215
|
const content = source.read(name, METADATA_BYTES - bytes);
|
|
17918
18216
|
if (!content) throw new ContextReadError("source_changed");
|
|
17919
18217
|
bytes += content.length;
|
|
17920
|
-
|
|
18218
|
+
writeFileSync13(join41(destination, name), content, { mode: 384 });
|
|
17921
18219
|
}
|
|
17922
18220
|
}
|
|
17923
18221
|
};
|
|
@@ -17927,20 +18225,20 @@ objectformat = ${value}`
|
|
|
17927
18225
|
if (content) {
|
|
17928
18226
|
count2++;
|
|
17929
18227
|
bytes += content.length;
|
|
17930
|
-
|
|
18228
|
+
writeFileSync13(join41(scratch, name), content, { mode: 384 });
|
|
17931
18229
|
if (written) {
|
|
17932
18230
|
const seconds = Math.floor(written.mtimeMs / 1e3);
|
|
17933
|
-
utimesSync(
|
|
18231
|
+
utimesSync(join41(scratch, name), seconds, seconds);
|
|
17934
18232
|
}
|
|
17935
18233
|
}
|
|
17936
18234
|
}
|
|
17937
18235
|
for (const name of ["refs", "objects"]) {
|
|
17938
|
-
mkdirSync12(
|
|
17939
|
-
if (git.entry(name)) copy(git.directory(name),
|
|
18236
|
+
mkdirSync12(join41(scratch, name), { mode: 448 });
|
|
18237
|
+
if (git.entry(name)) copy(git.directory(name), join41(scratch, name), 0);
|
|
17940
18238
|
}
|
|
17941
18239
|
if (git.list().some((name) => name.startsWith("sharedindex.")))
|
|
17942
18240
|
throw new ContextReadError("unsupported_git_metadata");
|
|
17943
|
-
|
|
18241
|
+
writeFileSync13(join41(scratch, "config"), `${configLines.join("\n")}
|
|
17944
18242
|
`, { mode: 384 });
|
|
17945
18243
|
const validate2 = () => git.validate();
|
|
17946
18244
|
validate2();
|
|
@@ -17953,7 +18251,7 @@ objectformat = ${value}`
|
|
|
17953
18251
|
|
|
17954
18252
|
// ../daemon/src/lib/git-review/authors.ts
|
|
17955
18253
|
import { realpathSync as realpathSync8 } from "node:fs";
|
|
17956
|
-
import { isAbsolute as isAbsolute8, join as
|
|
18254
|
+
import { isAbsolute as isAbsolute8, join as join42, relative as relative5, resolve as resolve8, sep as sep6 } from "node:path";
|
|
17957
18255
|
var FILE_TOOLS = /* @__PURE__ */ new Set(["write", "edit"]);
|
|
17958
18256
|
var CONVERSATIONS_PER_AGENT = 5;
|
|
17959
18257
|
var SANDBOX_ROOT = "/workspace";
|
|
@@ -17978,7 +18276,7 @@ function readChangeAuthors(db, paths, team, changedPaths) {
|
|
|
17978
18276
|
}
|
|
17979
18277
|
const members = list(db, { includeArchived: true }).filter((agent) => agent.teamId === team.id);
|
|
17980
18278
|
for (const agent of members) {
|
|
17981
|
-
const directory =
|
|
18279
|
+
const directory = join42(paths.agentDir(agent.id), "sessions");
|
|
17982
18280
|
const recent = list11(db, agent.id, CONVERSATIONS_PER_AGENT, 0).conversations;
|
|
17983
18281
|
for (const conversation of recent) {
|
|
17984
18282
|
let lines;
|
|
@@ -17989,18 +18287,18 @@ function readChangeAuthors(db, paths, team, changedPaths) {
|
|
|
17989
18287
|
}
|
|
17990
18288
|
const cwd = lines[0]?.cwd ?? team.path;
|
|
17991
18289
|
const failed = /* @__PURE__ */ new Set();
|
|
17992
|
-
for (const
|
|
17993
|
-
const message =
|
|
18290
|
+
for (const line2 of lines) {
|
|
18291
|
+
const message = line2.message;
|
|
17994
18292
|
if (message?.role === "toolResult" && message.isError && message.toolCallId) {
|
|
17995
18293
|
failed.add(message.toolCallId);
|
|
17996
18294
|
}
|
|
17997
18295
|
}
|
|
17998
|
-
for (const
|
|
17999
|
-
if (
|
|
18000
|
-
if (!Array.isArray(
|
|
18001
|
-
const at = Date.parse(
|
|
18296
|
+
for (const line2 of lines) {
|
|
18297
|
+
if (line2.type !== "message" || line2.message?.role !== "assistant") continue;
|
|
18298
|
+
if (!Array.isArray(line2.message.content)) continue;
|
|
18299
|
+
const at = Date.parse(line2.timestamp ?? "");
|
|
18002
18300
|
if (!Number.isFinite(at)) continue;
|
|
18003
|
-
for (const part of
|
|
18301
|
+
for (const part of line2.message.content) {
|
|
18004
18302
|
if (part?.type !== "toolCall" || !part.name || !FILE_TOOLS.has(part.name)) continue;
|
|
18005
18303
|
if (part.id && failed.has(part.id)) continue;
|
|
18006
18304
|
const target = part.arguments?.path;
|
|
@@ -18117,7 +18415,7 @@ async function queueReviewFeedback(db, paths, teamId, request) {
|
|
|
18117
18415
|
const item = await enqueueUserInput(agent.id, { message, attachments: [] }, { db, paths });
|
|
18118
18416
|
return { message, item };
|
|
18119
18417
|
}
|
|
18120
|
-
function hunkForLine(patch,
|
|
18418
|
+
function hunkForLine(patch, line2) {
|
|
18121
18419
|
const lines = patch.split("\n");
|
|
18122
18420
|
const starts = [];
|
|
18123
18421
|
lines.forEach((text4, index) => {
|
|
@@ -18128,7 +18426,7 @@ function hunkForLine(patch, line) {
|
|
|
18128
18426
|
if (!header) continue;
|
|
18129
18427
|
const first = Number(header[1]);
|
|
18130
18428
|
const count2 = header[2] === void 0 ? 1 : Number(header[2]);
|
|
18131
|
-
if (
|
|
18429
|
+
if (line2 < first || line2 >= first + Math.max(count2, 1)) continue;
|
|
18132
18430
|
return lines.slice(start2, starts[position + 1] ?? lines.length).join("\n");
|
|
18133
18431
|
}
|
|
18134
18432
|
return null;
|
|
@@ -18269,6 +18567,115 @@ teamTemplatesRouter.post("/:id/spawn", async (c) => {
|
|
|
18269
18567
|
);
|
|
18270
18568
|
});
|
|
18271
18569
|
|
|
18570
|
+
// ../daemon/src/lib/team-day.ts
|
|
18571
|
+
import { statSync as statSync8 } from "node:fs";
|
|
18572
|
+
import { join as join43 } from "node:path";
|
|
18573
|
+
var TEAM_DAY_MAX = 200;
|
|
18574
|
+
var MESSAGES_READ = 500;
|
|
18575
|
+
var RESULTS_READ = 100;
|
|
18576
|
+
var CONVERSATION_PAGES = 10;
|
|
18577
|
+
var LINE = 240;
|
|
18578
|
+
var line = (text4) => {
|
|
18579
|
+
const flat = text4.replace(/\s+/g, " ").trim();
|
|
18580
|
+
return flat.length > LINE ? `${flat.slice(0, LINE - 1)}\u2026` : flat;
|
|
18581
|
+
};
|
|
18582
|
+
function teamDay(db, paths, teamId, since) {
|
|
18583
|
+
const everyone = list(db, { includeArchived: true });
|
|
18584
|
+
const name = new Map(everyone.map((agent) => [agent.id, agent.name]));
|
|
18585
|
+
const members = everyone.filter((agent) => agent.teamId === teamId && agent.status !== "archived");
|
|
18586
|
+
const member = new Set(members.map((agent) => agent.id));
|
|
18587
|
+
const events = [];
|
|
18588
|
+
let missed = false;
|
|
18589
|
+
const fullDay = (items, limit) => items.length >= limit && items.every((item) => item.createdAt >= since);
|
|
18590
|
+
const messages = listForTeam(db, teamId, MESSAGES_READ);
|
|
18591
|
+
if (fullDay(messages, MESSAGES_READ)) missed = true;
|
|
18592
|
+
for (const message of messages) {
|
|
18593
|
+
if (message.createdAt < since) continue;
|
|
18594
|
+
events.push({
|
|
18595
|
+
at: message.createdAt,
|
|
18596
|
+
kind: message.replyTo ? "reply" : "handoff",
|
|
18597
|
+
agentId: message.fromAgentId,
|
|
18598
|
+
agentName: name.get(message.fromAgentId) ?? message.fromAgentId,
|
|
18599
|
+
otherAgentId: message.toAgentId,
|
|
18600
|
+
otherAgentName: name.get(message.toAgentId) ?? message.toAgentId,
|
|
18601
|
+
text: line(messageText(message.payload))
|
|
18602
|
+
});
|
|
18603
|
+
}
|
|
18604
|
+
const delivered = list12(db, { teamId, limit: RESULTS_READ }).results;
|
|
18605
|
+
if (fullDay(delivered, RESULTS_READ)) missed = true;
|
|
18606
|
+
for (const result of delivered) {
|
|
18607
|
+
if (result.createdAt < since) continue;
|
|
18608
|
+
events.push({
|
|
18609
|
+
at: result.createdAt,
|
|
18610
|
+
kind: "file",
|
|
18611
|
+
agentId: result.agentId,
|
|
18612
|
+
agentName: name.get(result.agentId) ?? result.agentId,
|
|
18613
|
+
text: result.name,
|
|
18614
|
+
resultId: result.id,
|
|
18615
|
+
conversationId: result.sessionId
|
|
18616
|
+
});
|
|
18617
|
+
}
|
|
18618
|
+
for (const agent of members) {
|
|
18619
|
+
const all = [];
|
|
18620
|
+
for (let page = 0; page < CONVERSATION_PAGES; page++) {
|
|
18621
|
+
const { conversations: batch, total } = list11(db, agent.id, 100, page * 100);
|
|
18622
|
+
all.push(...batch);
|
|
18623
|
+
if (all.length >= total || batch.length === 0) break;
|
|
18624
|
+
if (page === CONVERSATION_PAGES - 1) missed = true;
|
|
18625
|
+
}
|
|
18626
|
+
for (const conversation of all) {
|
|
18627
|
+
let at;
|
|
18628
|
+
try {
|
|
18629
|
+
at = Math.floor(
|
|
18630
|
+
statSync8(join43(paths.agentDir(agent.id), "sessions", `${conversation.id}.jsonl`)).mtimeMs
|
|
18631
|
+
);
|
|
18632
|
+
} catch {
|
|
18633
|
+
continue;
|
|
18634
|
+
}
|
|
18635
|
+
if (at < since) continue;
|
|
18636
|
+
events.push({
|
|
18637
|
+
at,
|
|
18638
|
+
kind: "worked",
|
|
18639
|
+
agentId: agent.id,
|
|
18640
|
+
agentName: agent.name,
|
|
18641
|
+
text: conversation.title,
|
|
18642
|
+
conversationId: conversation.id
|
|
18643
|
+
});
|
|
18644
|
+
}
|
|
18645
|
+
}
|
|
18646
|
+
for (const question of questionRegistry.list()) {
|
|
18647
|
+
if (!member.has(question.agentId)) continue;
|
|
18648
|
+
events.push({
|
|
18649
|
+
at: question.createdAt,
|
|
18650
|
+
kind: "question",
|
|
18651
|
+
agentId: question.agentId,
|
|
18652
|
+
agentName: name.get(question.agentId) ?? question.agentId,
|
|
18653
|
+
text: line(question.question.prompt),
|
|
18654
|
+
conversationId: question.conversationId
|
|
18655
|
+
});
|
|
18656
|
+
}
|
|
18657
|
+
for (const approval of commandApprovalRegistry.list()) {
|
|
18658
|
+
if (!member.has(approval.agentId)) continue;
|
|
18659
|
+
events.push({
|
|
18660
|
+
at: approval.createdAt,
|
|
18661
|
+
kind: "approval",
|
|
18662
|
+
agentId: approval.agentId,
|
|
18663
|
+
agentName: name.get(approval.agentId) ?? approval.agentId,
|
|
18664
|
+
text: line(approval.command)
|
|
18665
|
+
});
|
|
18666
|
+
}
|
|
18667
|
+
events.sort((a, b) => b.at - a.at);
|
|
18668
|
+
return {
|
|
18669
|
+
teamId,
|
|
18670
|
+
since,
|
|
18671
|
+
events: events.slice(0, TEAM_DAY_MAX),
|
|
18672
|
+
truncated: missed || events.length > TEAM_DAY_MAX
|
|
18673
|
+
};
|
|
18674
|
+
}
|
|
18675
|
+
function startOfToday(now = /* @__PURE__ */ new Date()) {
|
|
18676
|
+
return new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime();
|
|
18677
|
+
}
|
|
18678
|
+
|
|
18272
18679
|
// ../daemon/src/routes/teams.ts
|
|
18273
18680
|
var teamsRouter = newRouter();
|
|
18274
18681
|
teamsRouter.get("/", (c) => {
|
|
@@ -18283,6 +18690,13 @@ teamsRouter.post("/", async (c) => {
|
|
|
18283
18690
|
return c.json(team, 201);
|
|
18284
18691
|
});
|
|
18285
18692
|
teamsRouter.get("/:id", (c) => c.json(routeTeam(c)));
|
|
18693
|
+
teamsRouter.get("/:id/today", (c) => {
|
|
18694
|
+
const raw = c.req.query("since");
|
|
18695
|
+
const since = raw === void 0 ? startOfToday() : Number(raw);
|
|
18696
|
+
if (!Number.isSafeInteger(since) || since < 0) return c.json({ error: "Invalid since" }, 400);
|
|
18697
|
+
const { db, paths } = getCtx();
|
|
18698
|
+
return c.json(teamDay(db, paths, routeTeam(c).id, since));
|
|
18699
|
+
});
|
|
18286
18700
|
teamsRouter.delete("/:id", (c) => {
|
|
18287
18701
|
const { db, paths } = getCtx();
|
|
18288
18702
|
deleteTeam(db, paths, routeTeam(c).id);
|
|
@@ -18746,7 +19160,7 @@ function namePrompt(profile) {
|
|
|
18746
19160
|
Reply with a name for the new agent, or <code>-</code> to auto-name.`;
|
|
18747
19161
|
}
|
|
18748
19162
|
async function spawnAndBind(ctx, profile, rawName, teamSlug = null) {
|
|
18749
|
-
const requestedName = rawName === "-" ? autoName(ctx, profile) : rawName;
|
|
19163
|
+
const requestedName = rawName === "-" ? autoName(ctx, profile, teamSlug ?? "default") : rawName;
|
|
18750
19164
|
let agent;
|
|
18751
19165
|
try {
|
|
18752
19166
|
agent = spawnAgent(ctx.db, ctx.paths, {
|
|
@@ -18785,9 +19199,10 @@ Run <code>/talk ${htmlEscape(agent.name)}</code> after fixing the underlying iss
|
|
|
18785
19199
|
}
|
|
18786
19200
|
};
|
|
18787
19201
|
}
|
|
18788
|
-
function autoName(ctx, profile) {
|
|
18789
|
-
|
|
18790
|
-
|
|
19202
|
+
function autoName(ctx, profile, teamId) {
|
|
19203
|
+
let n = agents_exports.countByProfile(ctx.db, profile.id) + 1;
|
|
19204
|
+
while (agents_exports.nameTakenInTeam(ctx.db, teamId, `${profile.id}-${n}`)) n++;
|
|
19205
|
+
return `${profile.id}-${n}`;
|
|
18791
19206
|
}
|
|
18792
19207
|
|
|
18793
19208
|
// ../daemon/src/lib/telegram/commands/spawn-team.ts
|