bazilion 0.56.0 → 0.57.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +2 -1
- package/dist/cli.js.map +1 -1
- package/dist/daemon.js +599 -318
- package/dist/daemon.js.map +1 -1
- package/dist/web/client/assets/AddProviderDialog-DwUu2FGE.js +1 -0
- package/dist/web/client/assets/AgentTemplateParts-C3BasVck.js +1 -0
- package/dist/web/client/assets/{ConfigPage-Ch-DSJUO.js → ConfigPage-DFmHgEaL.js} +1 -1
- package/dist/web/client/assets/ConfirmDialog-BCOfW63x.js +1 -0
- package/dist/web/client/assets/ConnectionsView-BbpY5YbI.js +1 -0
- package/dist/web/client/assets/{ManagePage-kd7iWYEL.js → ManagePage-BzyMHGqs.js} +1 -1
- package/dist/web/client/assets/SectionTabs-C8H_LunZ.js +1 -0
- package/dist/web/client/assets/SkillsParts-DoygBgF2.js +1 -0
- package/dist/web/client/assets/SpawnTeamModal-BVf4yN9X.js +1 -0
- package/dist/web/client/assets/TeamForm-Bfb5hVUX.js +1 -0
- package/dist/web/client/assets/TeamThread-BFmaBj82.js +1 -0
- package/dist/web/client/assets/{UnsavedChangesGuard-vQBdMl8h.js → UnsavedChangesGuard-BUsIHSxO.js} +1 -1
- package/dist/web/client/assets/{_id-C6SADaiD.js → _id-BRD3kxrX.js} +1 -1
- package/dist/web/client/assets/{_id-CC9r0qsr.js → _id-BapVoTMJ.js} +1 -1
- package/dist/web/client/assets/{access-BbQFbTPh.js → access-CqcKius1.js} +1 -1
- package/dist/web/client/assets/agents-BC_ITk28.js +1 -0
- package/dist/web/client/assets/{agents-BXwzmHu8.js → agents-DQ8nQnD6.js} +1 -1
- package/dist/web/client/assets/{attention-BMrZJ9ui.js → attention-BnCihfi0.js} +1 -1
- package/dist/web/client/assets/config-DYS8bkQl.js +1 -0
- package/dist/web/client/assets/{es2015-D1pnOGPG.js → es2015-DZDOQ3kj.js} +11 -11
- package/dist/web/client/assets/{index-B-N6NIX4.js → index-CxXsZzDC.js} +3 -3
- package/dist/web/client/assets/{login-DM3q-V4R.js → login-DFVsVP0s.js} +1 -1
- package/dist/web/client/assets/{manage-R57MUzsY.js → manage-CpXaObuS.js} +1 -1
- package/dist/web/client/assets/{mcp-CSHrVH1t.js → mcp-DslGDHmN.js} +1 -1
- package/dist/web/client/assets/{parts-68zf8Fgw.js → parts-C104qEuC.js} +1 -1
- package/dist/web/client/assets/routes-D1wFPm0n.js +85 -0
- package/dist/web/client/assets/{skills-CPZftp9O.js → skills-DmIo3vN3.js} +1 -1
- package/dist/web/client/assets/style-CqkCFvvz.js +7 -0
- package/dist/web/client/assets/styles-C7NsCHeU.css +2 -0
- package/dist/web/client/assets/{system-Dd2P9eqE.js → system-CUW9JZ9c.js} +1 -1
- package/dist/web/client/assets/teams-DJzYsuh9.js +1 -0
- package/dist/web/client/assets/teams-DrhG8KiS.js +1 -0
- package/dist/web/client/assets/telegram-Bk_kg8hb.js +1 -0
- package/dist/web/client/assets/{tools-DqNXLMpc.js → tools-z9Ixmuu2.js} +1 -1
- package/dist/web/client/assets/{usage-BC_TStVj.js → usage-DGe3x1m7.js} +1 -1
- package/dist/web/client/assets/use-resource-qjIkNQDY.js +1 -0
- package/dist/web/client/assets/{welcome-g8wtn_or.js → welcome-DDKqxHkF.js} +1 -1
- package/dist/web/server/assets/{AddProviderDialog-DtkjBMv4.js → AddProviderDialog-CpLDHOcA.js} +4 -4
- package/dist/web/server/assets/{AgentTemplateParts-CxWyovvM.js → AgentTemplateParts-Dh9F_-T_.js} +5 -5
- package/dist/web/server/assets/{ConfigPage-usZi48Zr.js → ConfigPage-CrxctbtN.js} +2 -2
- package/dist/web/server/assets/{ConfirmDialog-DAcSBHkT.js → ConfirmDialog-C89B8qKM.js} +1 -1
- package/dist/web/server/assets/{ConnectionsView-Dy6uYSRI.js → ConnectionsView-DslcKQmA.js} +5 -5
- package/dist/web/server/assets/{Dialog-DTeF-nOZ.js → Dialog-_Gt_Nt86.js} +2 -2
- package/dist/web/server/assets/{ManagePage-Dy1EdovO.js → ManagePage-DGYNJ6XG.js} +2 -2
- package/dist/web/server/assets/{ModelMenu-D-hTgYOO.js → ModelMenu-DEJoYASj.js} +13 -1
- package/dist/web/server/assets/{SectionTabs-BVrMn76H.js → SectionTabs--vMBvaUz.js} +7 -1
- package/dist/web/server/assets/{SkillsParts-Cw05b3al.js → SkillsParts-CqS2B45v.js} +5 -5
- package/dist/web/server/assets/{SpawnDialog-BAE8W91z.js → SpawnDialog-BNKj2Lup.js} +10 -8
- package/dist/web/server/assets/{SpawnTeamModal-CgBY0HuN.js → SpawnTeamModal-zcLxtFOO.js} +4 -4
- package/dist/web/server/assets/{TeamForm-JyO5xJXX.js → TeamForm-XFP0l2TB.js} +9 -7
- package/dist/web/server/assets/{TeamThread-5o48EbXL.js → TeamThread-gYV_ToRM.js} +8 -9
- package/dist/web/server/assets/{UnsavedChangesGuard-CJQGu45L.js → UnsavedChangesGuard-CB_TugFF.js} +1 -1
- package/dist/web/server/assets/{_id-BNvm89oJ.js → _id-517adSuB.js} +1 -1
- package/dist/web/server/assets/{_id-BpumuCYL.js → _id-BTyd2i5U.js} +1 -1
- package/dist/web/server/assets/{_id-BE_RSvuN.js → _id-BsQnL9LV.js} +9 -9
- package/dist/web/server/assets/{_id-BfjTS4JO.js → _id-CyinHJam.js} +11 -11
- package/dist/web/server/assets/{_id-BW6sVrvw.js → _id-D4RFNqaJ.js} +2 -2
- package/dist/web/server/assets/{_id-C54t_nX6.js → _id-josYXBx3.js} +1 -1
- package/dist/web/server/assets/{_tanstack-start-manifest_v-BPwQX_5b.js → _tanstack-start-manifest_v-w2xn07aY.js} +78 -78
- package/dist/web/server/assets/{access-BhAMfi7U.js → access-B97-94Wt.js} +1 -1
- package/dist/web/server/assets/{access-DEyq3uP_.js → access-BdQmjMJV.js} +1 -1
- package/dist/web/server/assets/{access-6FWih7nC.js → access-Cc7fMMod.js} +5 -5
- package/dist/web/server/assets/{agents-ncyhVx-T.js → agents-BL918wVc.js} +1 -1
- package/dist/web/server/assets/{agents-BXuglv4G.js → agents-BlUZqqJn.js} +10 -10
- package/dist/web/server/assets/{agents-3hBjrd8B.js → agents-BzJFjA2i.js} +2 -2
- package/dist/web/server/assets/{agents-KJcDMj0Y.js → agents-CjrkaEz8.js} +9 -9
- package/dist/web/server/assets/{agents-rTDlRZa5.js → agents-Tg3zkmQv.js} +2 -2
- package/dist/web/server/assets/{agents-DhenbitX.js → agents-uw32jPWx.js} +1 -1
- package/dist/web/server/assets/{attention-X0U6ZmiA.js → attention-2unmuO-q.js} +1 -1
- package/dist/web/server/assets/{attention-CDdOCOio.js → attention-C94WWwQe.js} +1 -1
- package/dist/web/server/assets/{attention-DM__BzWY.js → attention-a_OmC6L3.js} +6 -6
- package/dist/web/server/assets/{auth-BexhV8Yq.js → auth-DuIqEAed.js} +1 -1
- package/dist/web/server/assets/{config-Cld8Q8N7.js → config-BG1KOtwA.js} +1 -1
- package/dist/web/server/assets/{config-DpgYAXQ3.js → config-Bhem9XER.js} +8 -8
- package/dist/web/server/assets/{config-Cx5ri2DL2.js → config-D1Li_7Yt2.js} +1 -1
- package/dist/web/server/assets/{daemon-client-RxAllljf.js → daemon-client-D-NWKQto.js} +1 -1
- package/dist/web/server/assets/{form-BEjeiSy3.js → form-Bwsyt9OY.js} +2 -2
- package/dist/web/server/assets/{manage-C6ucNYZW.js → manage-C7ReF2ZZ.js} +1 -1
- package/dist/web/server/assets/{mcp-DwCzj7eO.js → mcp-BFixpBQk.js} +1 -1
- package/dist/web/server/assets/{mcp-BXnWQOwM.js → mcp-BTZkDvdc.js} +5 -5
- package/dist/web/server/assets/{mcp-C8VLspco.js → mcp-Ceg9gzKE.js} +1 -1
- package/dist/web/server/assets/{open-groups-BMGYUTtY.js → open-groups-C89TEK85.js} +1 -1
- package/dist/web/server/assets/{parts-k9M-atPa.js → parts-B0wbj_yK.js} +1 -1
- package/dist/web/server/assets/{router-BttfLktO.js → router-Ci_9VxDk.js} +83 -51
- package/dist/web/server/assets/{routes-A7UcreVX.js → routes-CVrH9qgo.js} +1 -1
- package/dist/web/server/assets/{routes-B9jw-MJ8.js → routes-D9Mw1_VV.js} +297 -101
- package/dist/web/server/assets/{routes-BX2FV8rS.js → routes-DsuaDPTO.js} +2 -2
- package/dist/web/server/assets/{skills-Cd5Cfdaz.js → skills-BNbZ75am.js} +1 -1
- package/dist/web/server/assets/{skills-y3GsyKce.js → skills-BWwEFc4a.js} +1 -1
- package/dist/web/server/assets/{skills-BVAH93cd.js → skills-D5rnOmKJ.js} +7 -7
- package/dist/web/server/assets/{src-vrZVrV9u.js → src-BeMh8Fze.js} +11 -1
- package/dist/web/server/assets/{start-Dl8gQ-95.js → start-2MvkBRdC.js} +1 -1
- package/dist/web/server/assets/{style-BQ3H9I7Y.js → style-B3l0Wtlf.js} +1 -1
- package/dist/web/server/assets/{system-BJPKqM6b.js → system-Cr4C-YRw.js} +1 -1
- package/dist/web/server/assets/{system-C7mejQSc.js → system-DT7AU0e6.js} +3 -3
- package/dist/web/server/assets/{system-LsLcuVzY.js → system-DsmXkgqn.js} +1 -1
- package/dist/web/server/assets/{teams-CiX8LUQo.js → teams-BeStcDvQ.js} +1 -1
- package/dist/web/server/assets/{teams-B6gbflsZ.js → teams-CsEBLW8-.js} +11 -9
- package/dist/web/server/assets/{teams-D-XdIkCr.js → teams-Dix5XVIx.js} +1 -1
- package/dist/web/server/assets/{teams-C7kXMNgc.js → teams-DjE0swAZ.js} +8 -8
- package/dist/web/server/assets/{teams-CeLLd2Mf.js → teams-Rk_RED7X.js} +1 -1
- package/dist/web/server/assets/{teams-CPXoTggb.js → teams-u6m6JzuU.js} +1 -1
- package/dist/web/server/assets/{telegram-D8_V7_sW.js → telegram-BjqABrl-.js} +7 -7
- package/dist/web/server/assets/{telegram-D7TW3LNZ.js → telegram-CQpF3EHA.js} +1 -1
- package/dist/web/server/assets/{telegram-DA2dwLID.js → telegram-DhzHgDfg.js} +1 -1
- package/dist/web/server/assets/{tools-D1BBVkRh.js → tools-DC69leH7.js} +1 -1
- package/dist/web/server/assets/{tools-CluiJywK.js → tools-Dn6RnOFu.js} +1 -1
- package/dist/web/server/assets/{tools-CckcG9Jl.js → tools-x_DQTQtE.js} +5 -5
- package/dist/web/server/assets/{usage-PNNb3pPj.js → usage-4zMG0sab.js} +4 -4
- package/dist/web/server/assets/{usage-CrYyvPgf.js → usage-mvQegG4l.js} +1 -1
- package/dist/web/server/assets/{use-resource-BUA9qGGY.js → use-resource-BjN1uJoL.js} +9 -1
- package/dist/web/server/assets/{welcome-CwzLt6Rp.js → welcome-BuE9FRf4.js} +1 -1
- package/dist/web/server/assets/{welcome-CUTYf8UG.js → welcome-DYw35wl5.js} +1 -1
- package/dist/web/server/assets/{welcome-CYhh3iUU.js → welcome-DrYbWGd_.js} +5 -5
- package/dist/web/server/server.js +20 -20
- package/dist/worker.js +116 -12
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
- package/dist/web/client/assets/AddProviderDialog-DZ9mXFdq.js +0 -1
- package/dist/web/client/assets/AgentTemplateParts-BfG3a-ri.js +0 -1
- package/dist/web/client/assets/ConfirmDialog-B_jXAPmh.js +0 -1
- package/dist/web/client/assets/ConnectionsView-D1Liebtf.js +0 -1
- package/dist/web/client/assets/SectionTabs-Dc0bNn-J.js +0 -1
- package/dist/web/client/assets/SkillsParts-C5T7sYDA.js +0 -1
- package/dist/web/client/assets/SpawnTeamModal-DatFF4f_.js +0 -1
- package/dist/web/client/assets/TeamForm-l-N_PYeE.js +0 -1
- package/dist/web/client/assets/TeamThread-BWmIQiAh.js +0 -1
- package/dist/web/client/assets/agents-BtETzVIY.js +0 -1
- package/dist/web/client/assets/config-B2ZDYo52.js +0 -1
- package/dist/web/client/assets/routes-DOoeKVwr.js +0 -85
- package/dist/web/client/assets/style-Bm9QsFpy.js +0 -7
- package/dist/web/client/assets/styles-B-kTTvCo.css +0 -2
- package/dist/web/client/assets/teams-7FEpSZg1.js +0 -1
- package/dist/web/client/assets/teams-ClirFbDV.js +0 -1
- package/dist/web/client/assets/telegram-BJnT5THs.js +0 -1
- package/dist/web/client/assets/use-resource-Bn0Sx7r6.js +0 -1
package/dist/daemon.js
CHANGED
|
@@ -1843,6 +1843,15 @@ import { writeSync } from "node:fs";
|
|
|
1843
1843
|
|
|
1844
1844
|
// ../../packages/api-types/src/entities.ts
|
|
1845
1845
|
var DEFAULT_TEAM_ID = "default";
|
|
1846
|
+
var AGENT_NAME_MAX = 120;
|
|
1847
|
+
function agentNameProblem(name) {
|
|
1848
|
+
if (!name.trim()) return "A name cannot be empty.";
|
|
1849
|
+
if (name.length > AGENT_NAME_MAX) return `A name is at most ${AGENT_NAME_MAX} characters.`;
|
|
1850
|
+
if (/[\p{Cc}\p{Cf}\u2028\u2029]/u.test(name)) {
|
|
1851
|
+
return "A name is one line of text, without control characters.";
|
|
1852
|
+
}
|
|
1853
|
+
return null;
|
|
1854
|
+
}
|
|
1846
1855
|
var DEFAULT_PROFILE_ID = "default";
|
|
1847
1856
|
var OUTSIDE_TEAM = "outside";
|
|
1848
1857
|
var REASONING_LEVELS = [
|
|
@@ -2662,6 +2671,9 @@ function discoverSkills(paths) {
|
|
|
2662
2671
|
|
|
2663
2672
|
// ../daemon/src/core/agent/spawn.ts
|
|
2664
2673
|
function spawnAgent(db, paths, input) {
|
|
2674
|
+
const givenName = input.name?.trim() || void 0;
|
|
2675
|
+
const nameProblem = givenName === void 0 ? null : agentNameProblem(givenName);
|
|
2676
|
+
if (nameProblem) throw new DomainError(400, nameProblem);
|
|
2665
2677
|
const loaded = loadProfile(db, input.profileId);
|
|
2666
2678
|
const id = randomUUID3();
|
|
2667
2679
|
const dir = paths.agentDir(id);
|
|
@@ -2692,7 +2704,7 @@ function spawnAgent(db, paths, input) {
|
|
|
2692
2704
|
const agent = insert(db, {
|
|
2693
2705
|
id,
|
|
2694
2706
|
profileId: input.profileId,
|
|
2695
|
-
name:
|
|
2707
|
+
name: givenName ?? loaded.profile.name,
|
|
2696
2708
|
modelOverride: input.modelOverride ?? null,
|
|
2697
2709
|
reasoningLevel,
|
|
2698
2710
|
status: "idle",
|
|
@@ -6547,6 +6559,7 @@ async function authMiddleware(c, next) {
|
|
|
6547
6559
|
}
|
|
6548
6560
|
|
|
6549
6561
|
// ../daemon/src/lib/activity.ts
|
|
6562
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
6550
6563
|
import { statSync as statSync3 } from "node:fs";
|
|
6551
6564
|
import { join as join10 } from "node:path";
|
|
6552
6565
|
|
|
@@ -7085,6 +7098,22 @@ function lastActivityAt(db, paths, agentId) {
|
|
|
7085
7098
|
return null;
|
|
7086
7099
|
}
|
|
7087
7100
|
}
|
|
7101
|
+
var ROSTER_QUERIES = [
|
|
7102
|
+
"SELECT id, name, policy_mode, telegram_icon_color, telegram_topic_name_format FROM teams ORDER BY id",
|
|
7103
|
+
`SELECT id, profile_id, name, model_override, status, reasoning_level, review_enabled,
|
|
7104
|
+
review_every_n_turns, review_model, review_reasoning_level, team_id, telegram_icon_emoji,
|
|
7105
|
+
telegram_mirror_mode FROM agents ORDER BY id`,
|
|
7106
|
+
"SELECT id, name, updated_at FROM profiles ORDER BY id",
|
|
7107
|
+
"SELECT id, name, updated_at FROM team_templates ORDER BY id"
|
|
7108
|
+
];
|
|
7109
|
+
function rosterRevision(db) {
|
|
7110
|
+
const hash2 = createHash5("sha256");
|
|
7111
|
+
for (const sql of ROSTER_QUERIES) {
|
|
7112
|
+
hash2.update(JSON.stringify(db.raw.query(sql).all()));
|
|
7113
|
+
hash2.update("\n");
|
|
7114
|
+
}
|
|
7115
|
+
return hash2.digest("hex").slice(0, 16);
|
|
7116
|
+
}
|
|
7088
7117
|
function readActivity(db, paths) {
|
|
7089
7118
|
const saved = summaryByAgent(db);
|
|
7090
7119
|
const questions = questionRegistry.list();
|
|
@@ -7156,7 +7185,10 @@ async function jsonBody(c) {
|
|
|
7156
7185
|
var activityRouter = newRouter();
|
|
7157
7186
|
activityRouter.get("/", (c) => {
|
|
7158
7187
|
const { db, paths } = getCtx();
|
|
7159
|
-
return c.json({
|
|
7188
|
+
return c.json({
|
|
7189
|
+
agents: readActivity(db, paths),
|
|
7190
|
+
roster: rosterRevision(db)
|
|
7191
|
+
});
|
|
7160
7192
|
});
|
|
7161
7193
|
|
|
7162
7194
|
// ../daemon/src/lib/browser/config.ts
|
|
@@ -7208,8 +7240,8 @@ agentBrowserRouter.delete("/:id/browser/profile", async (c) => {
|
|
|
7208
7240
|
|
|
7209
7241
|
// ../daemon/src/routes/agent-chat.ts
|
|
7210
7242
|
import { randomUUID as randomUUID19 } from "node:crypto";
|
|
7211
|
-
import { existsSync as
|
|
7212
|
-
import { join as
|
|
7243
|
+
import { existsSync as existsSync17, readFileSync as readFileSync11 } from "node:fs";
|
|
7244
|
+
import { join as join28 } from "node:path";
|
|
7213
7245
|
|
|
7214
7246
|
// ../daemon/src/runtime/auth/openai-codex.ts
|
|
7215
7247
|
import { openaiCodexProvider } from "@earendil-works/pi-ai/providers/openai-codex";
|
|
@@ -7451,11 +7483,11 @@ function assertRootUnchanged(root, canonicalRoot) {
|
|
|
7451
7483
|
function safeKey(root, key2) {
|
|
7452
7484
|
const segments = key2.split(/[\\/]/);
|
|
7453
7485
|
if (key2.length === 0 || key2.includes("\0") || isAbsolute2(key2) || /^[A-Za-z]:[\\/]/.test(key2) || key2.startsWith("\\\\") || segments.includes("..")) {
|
|
7454
|
-
throw new
|
|
7486
|
+
throw new DomainError(400, `unsafe memory key: ${key2}`);
|
|
7455
7487
|
}
|
|
7456
|
-
if (!key2.endsWith(".md")) throw new
|
|
7488
|
+
if (!key2.endsWith(".md")) throw new DomainError(400, `memory keys end in .md: ${key2}`);
|
|
7457
7489
|
const candidate = resolve4(root, key2);
|
|
7458
|
-
if (candidate === root) throw new
|
|
7490
|
+
if (candidate === root) throw new DomainError(400, `unsafe memory key: ${key2}`);
|
|
7459
7491
|
assertContained(root, candidate);
|
|
7460
7492
|
return candidate;
|
|
7461
7493
|
}
|
|
@@ -7866,6 +7898,8 @@ function piMessagesToProviderView(messages, secrets = []) {
|
|
|
7866
7898
|
const toolCalls = extractAssistantToolCalls(am);
|
|
7867
7899
|
const msg = { role: "assistant", content: text4 };
|
|
7868
7900
|
if (toolCalls.length > 0) msg.toolCalls = toolCalls;
|
|
7901
|
+
if (am.stopReason === "aborted") msg.stopped = "cancelled";
|
|
7902
|
+
else if (am.stopReason === "error") msg.stopped = "failed";
|
|
7869
7903
|
out.push(msg);
|
|
7870
7904
|
break;
|
|
7871
7905
|
}
|
|
@@ -8144,6 +8178,8 @@ function browserGuideSection(attached = false) {
|
|
|
8144
8178
|
|
|
8145
8179
|
// ../daemon/src/runtime/session/prompt.ts
|
|
8146
8180
|
var SANDBOX_SKILLS_DIR = "/skills";
|
|
8181
|
+
var MAX_LISTED_TEAMMATES = 40;
|
|
8182
|
+
var MAX_LISTED_OUTSIDE = 20;
|
|
8147
8183
|
function loadPromptSkills(skillsDir, attachedNames) {
|
|
8148
8184
|
if (!existsSync11(skillsDir) || attachedNames.length === 0) return [];
|
|
8149
8185
|
const attached = new Set(attachedNames);
|
|
@@ -8208,7 +8244,16 @@ ${contextBlocks.join("\n\n")}`
|
|
|
8208
8244
|
});
|
|
8209
8245
|
}
|
|
8210
8246
|
const bootstrap2 = homeDocuments["BOOTSTRAP.md"]?.trimEnd();
|
|
8211
|
-
if (bootstrap2) {
|
|
8247
|
+
if (bootstrap2 && options.withOperator === false) {
|
|
8248
|
+
parts.push({
|
|
8249
|
+
id: "first-run",
|
|
8250
|
+
text: [
|
|
8251
|
+
"# First-Run Ritual",
|
|
8252
|
+
"",
|
|
8253
|
+
"You have not had your first conversation with the human yet; it waits until they talk to you. This turn was not started by them (a teammate wrote to you, or a schedule fired), so nobody is here to answer its questions: do not greet the human or ask who you are. Do the work this turn asks for, with what you know."
|
|
8254
|
+
].join("\n")
|
|
8255
|
+
});
|
|
8256
|
+
} else if (bootstrap2) {
|
|
8212
8257
|
parts.push({
|
|
8213
8258
|
id: "first-run",
|
|
8214
8259
|
text: [
|
|
@@ -8220,6 +8265,9 @@ ${contextBlocks.join("\n\n")}`
|
|
|
8220
8265
|
"- Your first reply is ONLY a greeting + ONE question. No tool calls. Wait for the human to answer.",
|
|
8221
8266
|
"- Each subsequent turn: at most one new question. Wait between turns.",
|
|
8222
8267
|
"- Only after the ritual is complete (you have enough to write IDENTITY.md): call `home_write` once, then `bootstrap_done`.",
|
|
8268
|
+
...agent.team.userMd.trim() ? [
|
|
8269
|
+
"- The Team's USER.md (under About the User) already says some things about the human: do not ask what it answers."
|
|
8270
|
+
] : [],
|
|
8223
8271
|
"",
|
|
8224
8272
|
"## BOOTSTRAP.md",
|
|
8225
8273
|
"",
|
|
@@ -8290,6 +8338,7 @@ ${contextBlocks.join("\n\n")}`
|
|
|
8290
8338
|
"",
|
|
8291
8339
|
"An `AGENTS.md` file in the workspace holds repository instructions that govern its own directory and everything below it. The ones from the workspace root down to your working directory are already in your project instructions; read any other `AGENTS.md` on the path to files you edit."
|
|
8292
8340
|
];
|
|
8341
|
+
teamLines.push("", ...teammateLines(agent, options));
|
|
8293
8342
|
parts.push({ id: "team", text: teamLines.join("\n") });
|
|
8294
8343
|
if (agent.team.userMd.trim()) {
|
|
8295
8344
|
parts.push({
|
|
@@ -8325,6 +8374,44 @@ ${reviewedLessons.map((lesson) => `- ${lesson}`).join("\n")}`
|
|
|
8325
8374
|
});
|
|
8326
8375
|
return parts;
|
|
8327
8376
|
}
|
|
8377
|
+
function teammateLines(agent, options) {
|
|
8378
|
+
const contacts = options.contacts ?? [];
|
|
8379
|
+
const line = (text4) => text4.replace(/[\p{Cc}\p{Cf}\u2028\u2029\s]+/gu, " ").trim();
|
|
8380
|
+
const entry = (contact, team) => `- ${line(contact.name)}: id ${contact.id}${team ? "" : `, Team ${line(contact.teamName)}`} (template ${line(contact.template)})`;
|
|
8381
|
+
const listed = (list13, max, team) => [
|
|
8382
|
+
...list13.slice(0, max).map((contact) => entry(contact, team)),
|
|
8383
|
+
...list13.length > max ? [`- and ${list13.length - max} more`] : []
|
|
8384
|
+
];
|
|
8385
|
+
const teammates = contacts.filter((contact) => contact.teamId === agent.team.id);
|
|
8386
|
+
const reachable = teammates.filter((contact) => contact.canMessage);
|
|
8387
|
+
const unreachable = teammates.filter((contact) => !contact.canMessage);
|
|
8388
|
+
const outside = contacts.filter((contact) => contact.teamId !== agent.team.id);
|
|
8389
|
+
const create7 = options.canCreateAgents ? " When the human asks you to add teammates, create them with `agent_create`." : "";
|
|
8390
|
+
const lines = ["## Your teammates", ""];
|
|
8391
|
+
if (teammates.length === 0) {
|
|
8392
|
+
lines.push(`You are the only Agent in this Team so far.${create7}`);
|
|
8393
|
+
} else {
|
|
8394
|
+
lines.push(
|
|
8395
|
+
`Message an Agent with \`send_message\`: put its id (or its exact name) in \`to\`. These are current; do not ask the human for ids.${create7}`
|
|
8396
|
+
);
|
|
8397
|
+
if (reachable.length > 0) lines.push("", ...listed(reachable, MAX_LISTED_TEAMMATES, true));
|
|
8398
|
+
if (unreachable.length > 0) {
|
|
8399
|
+
lines.push(
|
|
8400
|
+
"",
|
|
8401
|
+
"In this restricted Team you have no connection to these teammates, so you cannot message them; the human can connect you in the Team's Connections view:",
|
|
8402
|
+
...listed(unreachable, MAX_LISTED_TEAMMATES, true)
|
|
8403
|
+
);
|
|
8404
|
+
}
|
|
8405
|
+
}
|
|
8406
|
+
if (outside.length > 0) {
|
|
8407
|
+
lines.push(
|
|
8408
|
+
"",
|
|
8409
|
+
"Team Policy also lets you message these Agents of other Teams:",
|
|
8410
|
+
...listed(outside, MAX_LISTED_OUTSIDE, false)
|
|
8411
|
+
);
|
|
8412
|
+
}
|
|
8413
|
+
return lines;
|
|
8414
|
+
}
|
|
8328
8415
|
function boundReviewedLessons(lessons, maxCharacters = 8e3) {
|
|
8329
8416
|
const selected = [];
|
|
8330
8417
|
let used = 0;
|
|
@@ -8341,7 +8428,7 @@ function boundReviewedLessons(lessons, maxCharacters = 8e3) {
|
|
|
8341
8428
|
|
|
8342
8429
|
// ../daemon/src/runtime/shell/docker.ts
|
|
8343
8430
|
import { spawn as spawn3 } from "node:child_process";
|
|
8344
|
-
import { createHash as
|
|
8431
|
+
import { createHash as createHash6, randomUUID as randomUUID15 } from "node:crypto";
|
|
8345
8432
|
var CONTAINER_WORKSPACE = "/workspace";
|
|
8346
8433
|
var DOCKER_CALL_TIMEOUT_MS = 5e3;
|
|
8347
8434
|
var MAX_TIMER_MS = 2147483647;
|
|
@@ -8448,7 +8535,7 @@ async function checkDockerImage(image) {
|
|
|
8448
8535
|
}
|
|
8449
8536
|
}
|
|
8450
8537
|
function homeContainerPrefix(home) {
|
|
8451
|
-
return `bazilion-${
|
|
8538
|
+
return `bazilion-${createHash6("sha256").update(home).digest("hex").slice(0, 12)}-`;
|
|
8452
8539
|
}
|
|
8453
8540
|
function turnContainerPrefix(home) {
|
|
8454
8541
|
return `${homeContainerPrefix(home)}${randomUUID15().replaceAll("-", "").slice(0, 12)}-`;
|
|
@@ -9463,11 +9550,11 @@ function messagingTools(host3, fromAgentId) {
|
|
|
9463
9550
|
{
|
|
9464
9551
|
def: {
|
|
9465
9552
|
name: "send_message",
|
|
9466
|
-
description:
|
|
9553
|
+
description: 'Send a message to another agent: `to` is its id, or its exact name (your teammates are listed in your instructions). Use this ONLY for things the recipient needs to ACT on: delegating a task, asking a peer for information you cannot get yourself, escalating a decision. Do NOT use it for status updates or to announce changes to team-shared resources \u2014 USER.md and the team memory backend both propagate to every agent in the team automatically on their next turn, so messages like "I updated USER.md" or "I wrote a new memory note" are pure noise and will trigger an inbox-wake loop on the recipient.',
|
|
9467
9554
|
parameters: {
|
|
9468
9555
|
type: "object",
|
|
9469
9556
|
properties: {
|
|
9470
|
-
to: { type: "string", description: "Recipient
|
|
9557
|
+
to: { type: "string", description: "Recipient Agent id, or its exact name" },
|
|
9471
9558
|
text: { type: "string", description: "Message text" },
|
|
9472
9559
|
reply_to: {
|
|
9473
9560
|
type: "string",
|
|
@@ -9482,9 +9569,6 @@ function messagingTools(host3, fromAgentId) {
|
|
|
9482
9569
|
const text4 = String(args.text ?? "");
|
|
9483
9570
|
if (!to) throw new Error('send_message: "to" is required');
|
|
9484
9571
|
if (!text4) throw new Error('send_message: "text" is required');
|
|
9485
|
-
if (!await host3.agentExists(to)) {
|
|
9486
|
-
throw new Error(`send_message: agent not found: ${to}`);
|
|
9487
|
-
}
|
|
9488
9572
|
const replyTo = typeof args.reply_to === "string" ? args.reply_to : null;
|
|
9489
9573
|
const { messageId } = await host3.sendMessage({
|
|
9490
9574
|
from: fromAgentId,
|
|
@@ -9567,6 +9651,51 @@ function messagingTools(host3, fromAgentId) {
|
|
|
9567
9651
|
];
|
|
9568
9652
|
}
|
|
9569
9653
|
|
|
9654
|
+
// ../daemon/src/runtime/tools/team.ts
|
|
9655
|
+
function agentCreateTool(host3) {
|
|
9656
|
+
return {
|
|
9657
|
+
def: {
|
|
9658
|
+
name: "agent_create",
|
|
9659
|
+
description: "Add a new Agent to your Team, when the operator asks you to (to build a team, or to hand part of the work to a specialist). It joins your Team, shares its workspace and memory, and starts knowing its role and that you made it: give it a clear name and say what it is for. It uses your model and Agent template unless you name others. In a restricted Team it is connected with you both ways. Message it afterwards with send_message, by the id this returns. Do not create Agents the operator did not ask for, or several for one job.",
|
|
9660
|
+
parameters: {
|
|
9661
|
+
type: "object",
|
|
9662
|
+
properties: {
|
|
9663
|
+
name: {
|
|
9664
|
+
type: "string",
|
|
9665
|
+
description: 'Its name, unique in your Team, e.g. "Lead Researcher"'
|
|
9666
|
+
},
|
|
9667
|
+
role: {
|
|
9668
|
+
type: "string",
|
|
9669
|
+
description: "What it is for and how it should work, in a few sentences: its job, what it delivers and to whom, and its limits"
|
|
9670
|
+
},
|
|
9671
|
+
template: {
|
|
9672
|
+
type: "string",
|
|
9673
|
+
description: "Optional: an Agent template id (default: your own)"
|
|
9674
|
+
},
|
|
9675
|
+
model: {
|
|
9676
|
+
type: "string",
|
|
9677
|
+
description: 'Optional: a model as "provider:model" (default: your own model)'
|
|
9678
|
+
}
|
|
9679
|
+
},
|
|
9680
|
+
required: ["name", "role"]
|
|
9681
|
+
}
|
|
9682
|
+
},
|
|
9683
|
+
async invoke(args) {
|
|
9684
|
+
const created = await host3.createAgent({
|
|
9685
|
+
name: String(args.name ?? ""),
|
|
9686
|
+
role: String(args.role ?? ""),
|
|
9687
|
+
...typeof args.template === "string" && args.template ? { template: args.template } : {},
|
|
9688
|
+
...typeof args.model === "string" && args.model ? { model: args.model } : {}
|
|
9689
|
+
});
|
|
9690
|
+
return [
|
|
9691
|
+
`Created ${created.name} (id ${created.id}) in ${created.teamName}, from the template ${created.template}, on ${created.model}.`,
|
|
9692
|
+
created.connected ? "It is connected with you both ways." : "",
|
|
9693
|
+
"Brief it with send_message to that id."
|
|
9694
|
+
].filter(Boolean).join(" ");
|
|
9695
|
+
}
|
|
9696
|
+
};
|
|
9697
|
+
}
|
|
9698
|
+
|
|
9570
9699
|
// ../daemon/src/runtime/tools/user-md.ts
|
|
9571
9700
|
function userMdTools(host3, teamId) {
|
|
9572
9701
|
return [
|
|
@@ -10016,6 +10145,7 @@ function createBazilionCustomTools(opts) {
|
|
|
10016
10145
|
if (opts.fileSink) handlers.push(deliverFileTool(opts.agent.team.path, opts.fileSink));
|
|
10017
10146
|
if (opts.imageGenerationHost) handlers.push(imageGenerateTool(opts.imageGenerationHost));
|
|
10018
10147
|
if (opts.askUser) handlers.push(askUserTool(opts.askUser));
|
|
10148
|
+
if (opts.teamHost) handlers.push(agentCreateTool(opts.teamHost));
|
|
10019
10149
|
return handlers.map(ourToolToPiTool);
|
|
10020
10150
|
}
|
|
10021
10151
|
|
|
@@ -10100,6 +10230,7 @@ function turnSurface(opts) {
|
|
|
10100
10230
|
imageGenerationHost: opts.imageGenerationHost,
|
|
10101
10231
|
webSearchHost: opts.webSearchHost,
|
|
10102
10232
|
askUser: opts.askUser,
|
|
10233
|
+
teamHost: opts.teamHost,
|
|
10103
10234
|
env
|
|
10104
10235
|
});
|
|
10105
10236
|
const promptOptions = {
|
|
@@ -10107,7 +10238,10 @@ function turnSurface(opts) {
|
|
|
10107
10238
|
sandboxMode: shellTools.config.sandboxMode,
|
|
10108
10239
|
// The guides ride along exactly when their tools are admitted.
|
|
10109
10240
|
...opts.browserHost ? { browserGuide: resolveBrowserConfig(env).attach ? "attached" : true } : {},
|
|
10110
|
-
...opts.webSearchHost ? { searchGuide: true } : {}
|
|
10241
|
+
...opts.webSearchHost ? { searchGuide: true } : {},
|
|
10242
|
+
contacts: opts.contacts ?? [],
|
|
10243
|
+
canCreateAgents: opts.teamHost !== void 0,
|
|
10244
|
+
withOperator: opts.withOperator ?? true
|
|
10111
10245
|
};
|
|
10112
10246
|
return {
|
|
10113
10247
|
cwd,
|
|
@@ -10497,7 +10631,6 @@ var RPC_HANDLERS = {
|
|
|
10497
10631
|
publishResult: (args, { hosts }) => host(hosts.resultHost, "result").publish(args),
|
|
10498
10632
|
generateImages: (args, { hosts }) => host(hosts.imageGenerationHost, "image generation").generate(args),
|
|
10499
10633
|
webSearch: (args, { hosts }) => host(hosts.webSearchHost, "web search").search(args),
|
|
10500
|
-
agentExists: ({ agentId }, { hosts }) => host(hosts.messagingHost, "messaging").agentExists(agentId),
|
|
10501
10634
|
sendMessage: (args, { hosts }) => host(hosts.messagingHost, "messaging").sendMessage(args),
|
|
10502
10635
|
listInbox: ({ agentId, unreadOnly }, { hosts }) => host(hosts.messagingHost, "messaging").listInbox(agentId, { unreadOnly }),
|
|
10503
10636
|
markRead: async ({ messageId }, { hosts }) => {
|
|
@@ -10509,6 +10642,7 @@ var RPC_HANDLERS = {
|
|
|
10509
10642
|
userMdWrite: ({ teamId, content, ifMatch }, { hosts }) => host(hosts.userMdHost, "USER.md").write(teamId, content, ifMatch),
|
|
10510
10643
|
browserInvoke: ({ agentId, action, args }, { hosts }) => host(hosts.browserHost, "browser").invoke(agentId, action, args),
|
|
10511
10644
|
mcpInvoke: ({ serverId, toolName, args }, { hosts }) => host(hosts.mcpHost, "MCP").invoke(serverId, toolName, args),
|
|
10645
|
+
createAgent: (args, { hosts }) => host(hosts.teamHost, "team").createAgent(args),
|
|
10512
10646
|
refreshApiKey: async ({ providerName }, ctx) => {
|
|
10513
10647
|
const token = await refreshApiKeyForTurn(
|
|
10514
10648
|
providerName,
|
|
@@ -11139,13 +11273,30 @@ function sendAgentMessage(db, input) {
|
|
|
11139
11273
|
}
|
|
11140
11274
|
|
|
11141
11275
|
// ../daemon/src/lib/messaging-host.ts
|
|
11276
|
+
function recipientOf(db, from, ref) {
|
|
11277
|
+
const wanted = ref.trim();
|
|
11278
|
+
const exact = db.raw.query("SELECT id FROM agents WHERE id = ?").get(wanted);
|
|
11279
|
+
if (exact) return exact.id;
|
|
11280
|
+
const sender = agents_exports.get(db, from);
|
|
11281
|
+
if (sender) {
|
|
11282
|
+
const teammates = db.raw.query(
|
|
11283
|
+
"SELECT id FROM agents WHERE team_id = ? AND lower(name) = lower(?) AND status != 'archived' LIMIT 2"
|
|
11284
|
+
).all(sender.teamId, wanted);
|
|
11285
|
+
if (teammates.length === 1 && teammates[0]) return teammates[0].id;
|
|
11286
|
+
if (teammates.length > 1) {
|
|
11287
|
+
throw new Error(`send_message: more than one teammate is named "${wanted}"; use the id`);
|
|
11288
|
+
}
|
|
11289
|
+
}
|
|
11290
|
+
const found = agents_exports.get(db, wanted);
|
|
11291
|
+
if (found) return found.id;
|
|
11292
|
+
throw new Error(
|
|
11293
|
+
`send_message: no Agent "${wanted}". Use an id or an exact name from your teammates list.`
|
|
11294
|
+
);
|
|
11295
|
+
}
|
|
11142
11296
|
function createDbMessagingHost(db, opts = {}) {
|
|
11143
11297
|
return {
|
|
11144
|
-
agentExists(agentId) {
|
|
11145
|
-
return agents_exports.get(db, agentId) !== null;
|
|
11146
|
-
},
|
|
11147
11298
|
sendMessage(input) {
|
|
11148
|
-
const to =
|
|
11299
|
+
const to = recipientOf(db, input.from, input.to);
|
|
11149
11300
|
const m = sendAgentMessage(db, {
|
|
11150
11301
|
...input,
|
|
11151
11302
|
to,
|
|
@@ -11187,8 +11338,42 @@ function createResultHost(db, agent, conversationId, signal) {
|
|
|
11187
11338
|
};
|
|
11188
11339
|
}
|
|
11189
11340
|
|
|
11190
|
-
// ../daemon/src/lib/
|
|
11191
|
-
import {
|
|
11341
|
+
// ../daemon/src/lib/team-host.ts
|
|
11342
|
+
import { existsSync as existsSync16, readFileSync as readFileSync10, rmSync as rmSync12, writeFileSync as writeFileSync8 } from "node:fs";
|
|
11343
|
+
import { join as join23 } from "node:path";
|
|
11344
|
+
|
|
11345
|
+
// ../daemon/src/lib/telegram/config.ts
|
|
11346
|
+
var BOT_TOKEN_KEY = "TELEGRAM_BOT_TOKEN";
|
|
11347
|
+
var CHAT_ID_KEY = "TELEGRAM_CHAT_ID";
|
|
11348
|
+
var LAST_UPDATE_KEY = "TELEGRAM_LAST_UPDATE_ID";
|
|
11349
|
+
var SERVICE_TOPIC_KEY = "TELEGRAM_SERVICE_TOPIC_ID";
|
|
11350
|
+
var DIRECTORY_MESSAGE_KEY = "TELEGRAM_DIRECTORY_MESSAGE_ID";
|
|
11351
|
+
var MIGRATED_CHAT_KEY = "TELEGRAM_MIGRATED_CHAT_ID";
|
|
11352
|
+
function readConfigNumber(db, key2) {
|
|
11353
|
+
const raw = openConfig(db).get(key2) ?? "";
|
|
11354
|
+
if (!raw) return null;
|
|
11355
|
+
const value = Number(raw);
|
|
11356
|
+
return Number.isFinite(value) ? value : null;
|
|
11357
|
+
}
|
|
11358
|
+
function readServiceTopicId(db) {
|
|
11359
|
+
return readConfigNumber(db, SERVICE_TOPIC_KEY);
|
|
11360
|
+
}
|
|
11361
|
+
function readCreds(db, authToken) {
|
|
11362
|
+
const botToken = openSecrets(db, authToken).get(BOT_TOKEN_KEY) ?? "";
|
|
11363
|
+
const chatId2 = readConfigNumber(db, CHAT_ID_KEY);
|
|
11364
|
+
return botToken && chatId2 !== null ? { botToken, chatId: chatId2 } : null;
|
|
11365
|
+
}
|
|
11366
|
+
function redactToken(text4, botToken) {
|
|
11367
|
+
return (botToken ? text4.replaceAll(botToken, "[redacted]") : text4).replace(
|
|
11368
|
+
/bot\d+:[A-Za-z0-9_-]+/g,
|
|
11369
|
+
"bot[redacted]"
|
|
11370
|
+
);
|
|
11371
|
+
}
|
|
11372
|
+
|
|
11373
|
+
// ../daemon/src/lib/telegram/html.ts
|
|
11374
|
+
function htmlEscape(s) {
|
|
11375
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
11376
|
+
}
|
|
11192
11377
|
|
|
11193
11378
|
// ../daemon/src/lib/telegram/live.ts
|
|
11194
11379
|
var current = null;
|
|
@@ -11199,15 +11384,270 @@ function setTelegramLive(live) {
|
|
|
11199
11384
|
current = live;
|
|
11200
11385
|
}
|
|
11201
11386
|
|
|
11202
|
-
// ../daemon/src/lib/telegram/
|
|
11203
|
-
|
|
11387
|
+
// ../daemon/src/lib/telegram/naming.ts
|
|
11388
|
+
var TEAM_COLORS = [
|
|
11389
|
+
7322096,
|
|
11390
|
+
// light blue / cyan
|
|
11391
|
+
16766590,
|
|
11392
|
+
// orange
|
|
11393
|
+
13338331,
|
|
11394
|
+
// purple / lavender
|
|
11395
|
+
9367192,
|
|
11396
|
+
// green
|
|
11397
|
+
16749490
|
|
11398
|
+
// pink / rose
|
|
11399
|
+
];
|
|
11400
|
+
var TOPIC_NAME_TOKENS = ["{agent.name}", "{team.name}", "{team.slug}"];
|
|
11401
|
+
function topicNameFor(agent, team) {
|
|
11402
|
+
const fmt = team.telegramTopicNameFormat ?? null;
|
|
11403
|
+
if (fmt) {
|
|
11404
|
+
return renderTopicNameFormat(fmt, {
|
|
11405
|
+
agentName: agent.name,
|
|
11406
|
+
teamName: team.name ?? team.id,
|
|
11407
|
+
teamSlug: team.id
|
|
11408
|
+
});
|
|
11409
|
+
}
|
|
11410
|
+
if (team.id === DEFAULT_TEAM_ID) return agent.name;
|
|
11411
|
+
return `${team.id} \u203A ${agent.name}`;
|
|
11412
|
+
}
|
|
11413
|
+
function renderTopicNameFormat(fmt, vals) {
|
|
11414
|
+
return fmt.replaceAll("{agent.name}", vals.agentName).replaceAll("{team.name}", vals.teamName).replaceAll("{team.slug}", vals.teamSlug);
|
|
11415
|
+
}
|
|
11416
|
+
function validateTopicNameFormat(fmt) {
|
|
11417
|
+
if (fmt.trim().length === 0) return "Format cannot be empty.";
|
|
11418
|
+
const used = fmt.match(/\{[^}]*\}/g) ?? [];
|
|
11419
|
+
for (const token of used) {
|
|
11420
|
+
if (!TOPIC_NAME_TOKENS.includes(token)) {
|
|
11421
|
+
return `Unknown token ${token}. Allowed tokens: ${TOPIC_NAME_TOKENS.join(", ")}.`;
|
|
11422
|
+
}
|
|
11423
|
+
}
|
|
11424
|
+
if (!fmt.includes("{agent.name}")) {
|
|
11425
|
+
return "Format must include {agent.name} so each agent gets a distinct topic name.";
|
|
11426
|
+
}
|
|
11427
|
+
return null;
|
|
11428
|
+
}
|
|
11429
|
+
function allocateTeamColor(db, teamId) {
|
|
11430
|
+
const existing = teams_exports.getTelegramIconColor(db, teamId);
|
|
11431
|
+
if (existing !== null) return existing;
|
|
11432
|
+
const idx = teams_exports.countAllocatedColors(db) % TEAM_COLORS.length;
|
|
11433
|
+
const color = TEAM_COLORS[idx] ?? 7322096;
|
|
11434
|
+
teams_exports.setTelegramIconColor(db, teamId, color);
|
|
11435
|
+
return color;
|
|
11436
|
+
}
|
|
11437
|
+
function topicDeepLink(chatId2, topicId) {
|
|
11438
|
+
const absStr = String(Math.abs(chatId2));
|
|
11439
|
+
const shortId = absStr.startsWith("100") ? absStr.slice(3) : absStr;
|
|
11440
|
+
return `https://t.me/c/${shortId}/${topicId}`;
|
|
11441
|
+
}
|
|
11204
11442
|
|
|
11205
|
-
// ../daemon/src/lib/telegram/
|
|
11206
|
-
function
|
|
11207
|
-
|
|
11443
|
+
// ../daemon/src/lib/telegram/directory.ts
|
|
11444
|
+
function agentListLines(db, paths, chatId2) {
|
|
11445
|
+
const agents = agents_exports.list(db);
|
|
11446
|
+
const lines = [];
|
|
11447
|
+
for (const team of teams_exports.list(db, paths)) {
|
|
11448
|
+
const members = agents.filter((agent) => agent.teamId === team.id);
|
|
11449
|
+
if (members.length === 0) continue;
|
|
11450
|
+
lines.push("", `<b>${htmlEscape(team.id)}</b>`);
|
|
11451
|
+
for (const agent of members) {
|
|
11452
|
+
const label = ` \u2022 <code>${htmlEscape(agent.name)}</code>`;
|
|
11453
|
+
lines.push(
|
|
11454
|
+
agent.telegramTopicId === null ? `${label} <i>(unbound)</i>` : `${label} \u2192 <a href="${topicDeepLink(chatId2, agent.telegramTopicId)}">open</a>`
|
|
11455
|
+
);
|
|
11456
|
+
}
|
|
11457
|
+
}
|
|
11458
|
+
return lines;
|
|
11459
|
+
}
|
|
11460
|
+
function buildDirectoryBody(db, paths, chatId2) {
|
|
11461
|
+
if (agents_exports.list(db).length === 0) {
|
|
11462
|
+
return [
|
|
11463
|
+
"\u{1F44B} <b>bazilion is online</b>",
|
|
11464
|
+
"",
|
|
11465
|
+
"No agents yet \u2014 run /spawn in this topic to create one.",
|
|
11466
|
+
"See /help for the command list."
|
|
11467
|
+
].join("\n");
|
|
11468
|
+
}
|
|
11469
|
+
return [
|
|
11470
|
+
"\u{1F6DF} <b>Available agents</b>",
|
|
11471
|
+
...agentListLines(db, paths, chatId2),
|
|
11472
|
+
"",
|
|
11473
|
+
"Run /help for commands."
|
|
11474
|
+
].join("\n");
|
|
11475
|
+
}
|
|
11476
|
+
async function refreshDirectoryMessage(deps) {
|
|
11477
|
+
const serviceTopicId = readServiceTopicId(deps.db);
|
|
11478
|
+
if (serviceTopicId === null) return;
|
|
11479
|
+
const body = buildDirectoryBody(deps.db, deps.paths, deps.chatId);
|
|
11480
|
+
const messageId = readConfigNumber(deps.db, DIRECTORY_MESSAGE_KEY);
|
|
11481
|
+
if (messageId !== null) {
|
|
11482
|
+
try {
|
|
11483
|
+
await deps.api.editMessageText(deps.chatId, messageId, body, {
|
|
11484
|
+
parse_mode: "HTML",
|
|
11485
|
+
disable_web_page_preview: true
|
|
11486
|
+
});
|
|
11487
|
+
return;
|
|
11488
|
+
} catch (e) {
|
|
11489
|
+
if (isNotModifiedError(e)) return;
|
|
11490
|
+
if (!isMessageGoneError(e)) throw e;
|
|
11491
|
+
console.warn(
|
|
11492
|
+
"telegram directory: pinned message gone, recreating \u2014",
|
|
11493
|
+
e instanceof Error ? e.message : String(e)
|
|
11494
|
+
);
|
|
11495
|
+
}
|
|
11496
|
+
}
|
|
11497
|
+
const sent = await deps.api.sendMessage(deps.chatId, body, {
|
|
11498
|
+
message_thread_id: serviceTopicId,
|
|
11499
|
+
parse_mode: "HTML",
|
|
11500
|
+
disable_web_page_preview: true
|
|
11501
|
+
});
|
|
11502
|
+
openConfig(deps.db).set(DIRECTORY_MESSAGE_KEY, String(sent.message_id));
|
|
11503
|
+
try {
|
|
11504
|
+
await deps.api.pinChatMessage(deps.chatId, sent.message_id, { disable_notification: true });
|
|
11505
|
+
} catch (e) {
|
|
11506
|
+
console.warn(
|
|
11507
|
+
"telegram directory: pin failed (continuing):",
|
|
11508
|
+
e instanceof Error ? e.message : String(e)
|
|
11509
|
+
);
|
|
11510
|
+
}
|
|
11511
|
+
}
|
|
11512
|
+
function isMessageGoneError(e) {
|
|
11513
|
+
if (!(e instanceof Error)) return false;
|
|
11514
|
+
const msg = e.message.toLowerCase();
|
|
11515
|
+
return msg.includes("message to edit not found") || msg.includes("message_id_invalid") || msg.includes("message can");
|
|
11516
|
+
}
|
|
11517
|
+
function isNotModifiedError(e) {
|
|
11518
|
+
if (!(e instanceof Error)) return false;
|
|
11519
|
+
return e.message.toLowerCase().includes("message is not modified");
|
|
11520
|
+
}
|
|
11521
|
+
var refreshScheduled = false;
|
|
11522
|
+
function notifyDirectoryDirty() {
|
|
11523
|
+
if (refreshScheduled) return;
|
|
11524
|
+
refreshScheduled = true;
|
|
11525
|
+
setImmediate(() => {
|
|
11526
|
+
refreshScheduled = false;
|
|
11527
|
+
const live = telegramLive();
|
|
11528
|
+
if (!live) return;
|
|
11529
|
+
refreshDirectoryMessage({ ...live, api: live.api }).catch(
|
|
11530
|
+
(e) => console.warn(
|
|
11531
|
+
"telegram directory: scheduled refresh failed \u2014",
|
|
11532
|
+
e instanceof Error ? e.message : String(e)
|
|
11533
|
+
)
|
|
11534
|
+
);
|
|
11535
|
+
});
|
|
11208
11536
|
}
|
|
11209
11537
|
|
|
11538
|
+
// ../daemon/src/lib/team-host.ts
|
|
11539
|
+
var MAX_CREATED_PER_TURN = 6;
|
|
11540
|
+
var MAX_ROLE = 4e3;
|
|
11541
|
+
function agentContacts(db, agentId) {
|
|
11542
|
+
const self = agents_exports.get(db, agentId);
|
|
11543
|
+
if (!self) return [];
|
|
11544
|
+
const teams = new Map(
|
|
11545
|
+
db.raw.query("SELECT id, name FROM teams").all().map((team) => [team.id, team.name])
|
|
11546
|
+
);
|
|
11547
|
+
const templates = new Map(profiles_exports.list(db).map((profile) => [profile.id, profile.name]));
|
|
11548
|
+
const contacts = agents_exports.list(db).filter((agent) => agent.id !== self.id).map((agent) => ({
|
|
11549
|
+
id: agent.id,
|
|
11550
|
+
name: agent.name,
|
|
11551
|
+
teamId: agent.teamId,
|
|
11552
|
+
teamName: teams.get(agent.teamId) ?? agent.teamId,
|
|
11553
|
+
template: templates.get(agent.profileId) ?? agent.profileId,
|
|
11554
|
+
canMessage: mayMessage(db, self.id, agent.id).allowed
|
|
11555
|
+
}));
|
|
11556
|
+
const own = contacts.filter((contact) => contact.teamId === self.teamId);
|
|
11557
|
+
const others = contacts.filter((contact) => contact.teamId !== self.teamId && contact.canMessage).sort((a, b) => a.teamName.localeCompare(b.teamName));
|
|
11558
|
+
return [...own, ...others];
|
|
11559
|
+
}
|
|
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
|
+
function createDbTeamHost(db, paths, creatorId) {
|
|
11570
|
+
let created = 0;
|
|
11571
|
+
return {
|
|
11572
|
+
createAgent(input) {
|
|
11573
|
+
const creator = agents_exports.get(db, creatorId);
|
|
11574
|
+
if (!creator) throw new Error("agent_create: your own Agent record is gone");
|
|
11575
|
+
const name = String(input.name ?? "").trim();
|
|
11576
|
+
const role = String(input.role ?? "").trim();
|
|
11577
|
+
if (!name) throw new Error('agent_create: "name" is required');
|
|
11578
|
+
const nameProblem = agentNameProblem(name);
|
|
11579
|
+
if (nameProblem) throw new Error(`agent_create: ${nameProblem}`);
|
|
11580
|
+
if (!role) throw new Error('agent_create: "role" is required: say what the Agent is for');
|
|
11581
|
+
if (role.length > MAX_ROLE) {
|
|
11582
|
+
throw new Error(`agent_create: a role is at most ${MAX_ROLE} characters`);
|
|
11583
|
+
}
|
|
11584
|
+
if (created >= MAX_CREATED_PER_TURN) {
|
|
11585
|
+
throw new Error(
|
|
11586
|
+
`agent_create: at most ${MAX_CREATED_PER_TURN} Agents per turn; ask the operator before adding more`
|
|
11587
|
+
);
|
|
11588
|
+
}
|
|
11589
|
+
const taken = agents_exports.list(db).some(
|
|
11590
|
+
(agent2) => agent2.teamId === creator.teamId && agent2.name.toLowerCase() === name.toLowerCase()
|
|
11591
|
+
);
|
|
11592
|
+
if (taken) {
|
|
11593
|
+
throw new Error(`agent_create: this Team already has an Agent named "${name}"`);
|
|
11594
|
+
}
|
|
11595
|
+
const templateId = input.template?.trim() || creator.profileId;
|
|
11596
|
+
const template = profiles_exports.get(db, templateId);
|
|
11597
|
+
if (!template) {
|
|
11598
|
+
const known = profiles_exports.list(db).map((profile) => `${profile.id} (${profile.name})`).join(", ");
|
|
11599
|
+
throw new Error(`agent_create: no Agent template "${templateId}". Templates: ${known}`);
|
|
11600
|
+
}
|
|
11601
|
+
const creatorTemplate = profiles_exports.get(db, creator.profileId);
|
|
11602
|
+
const model = input.model?.trim() || creator.modelOverride || creatorTemplate?.defaultModel || "";
|
|
11603
|
+
if (model) parseModelString(model);
|
|
11604
|
+
const agent = spawnAgent(db, paths, {
|
|
11605
|
+
profileId: template.id,
|
|
11606
|
+
name,
|
|
11607
|
+
...model && model !== template.defaultModel ? { modelOverride: model } : {},
|
|
11608
|
+
teamId: creator.teamId
|
|
11609
|
+
});
|
|
11610
|
+
created++;
|
|
11611
|
+
const agentsFile = join23(agent.dir, "AGENTS.md");
|
|
11612
|
+
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
|
+
const restricted = teamPolicies_exports.mode(db, creator.teamId) === "restricted";
|
|
11625
|
+
if (restricted) {
|
|
11626
|
+
teamPolicies_exports.insertEdges(db, creator.teamId, [
|
|
11627
|
+
{ from: creator.id, to: agent.id },
|
|
11628
|
+
{ from: agent.id, to: creator.id }
|
|
11629
|
+
]);
|
|
11630
|
+
}
|
|
11631
|
+
notifyDirectoryDirty();
|
|
11632
|
+
signalLiveChange();
|
|
11633
|
+
return {
|
|
11634
|
+
id: agent.id,
|
|
11635
|
+
name: agent.name,
|
|
11636
|
+
teamId: creator.teamId,
|
|
11637
|
+
teamName,
|
|
11638
|
+
template: template.name,
|
|
11639
|
+
model: model || template.defaultModel,
|
|
11640
|
+
connected: restricted
|
|
11641
|
+
};
|
|
11642
|
+
}
|
|
11643
|
+
};
|
|
11644
|
+
}
|
|
11645
|
+
|
|
11646
|
+
// ../daemon/src/lib/telegram/mirror.ts
|
|
11647
|
+
import { InputFile } from "grammy";
|
|
11648
|
+
|
|
11210
11649
|
// ../daemon/src/lib/telegram/markdown.ts
|
|
11650
|
+
import { marked } from "marked";
|
|
11211
11651
|
var TELEGRAM_SAFE_BUDGET = 3900;
|
|
11212
11652
|
function clip2(text4, limit) {
|
|
11213
11653
|
return text4.length <= limit ? text4 : `${text4.slice(0, limit - 1)}\u2026`;
|
|
@@ -11891,8 +12331,8 @@ function mirrorTypingStop(agentId) {
|
|
|
11891
12331
|
|
|
11892
12332
|
// ../daemon/src/lib/attachments.ts
|
|
11893
12333
|
import { randomUUID as randomUUID17 } from "node:crypto";
|
|
11894
|
-
import { closeSync as closeSync5, constants as constants6, fstatSync as fstatSync5, openSync as openSync5, writeFileSync as
|
|
11895
|
-
import { join as
|
|
12334
|
+
import { closeSync as closeSync5, constants as constants6, fstatSync as fstatSync5, openSync as openSync5, writeFileSync as writeFileSync9 } from "node:fs";
|
|
12335
|
+
import { join as join24, posix as posix2 } from "node:path";
|
|
11896
12336
|
var MAX_FILE_BYTES = 25 * 1024 * 1024;
|
|
11897
12337
|
function safeName(name) {
|
|
11898
12338
|
const base = name.split(/[\\/]/).pop() ?? "file";
|
|
@@ -11904,7 +12344,7 @@ function fmtBytes(n) {
|
|
|
11904
12344
|
return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
11905
12345
|
}
|
|
11906
12346
|
function prepareInputFilesDirectory(agentDir2) {
|
|
11907
|
-
return ensureContainedRealDirectory(
|
|
12347
|
+
return ensureContainedRealDirectory(join24(agentDir2, "uploads"), agentDir2, { create: true });
|
|
11908
12348
|
}
|
|
11909
12349
|
function saveInputFiles(agentDir2, files, options = {}) {
|
|
11910
12350
|
if (!files || files.length === 0) return "";
|
|
@@ -11918,7 +12358,7 @@ function saveInputFiles(agentDir2, files, options = {}) {
|
|
|
11918
12358
|
continue;
|
|
11919
12359
|
}
|
|
11920
12360
|
const filename = `${randomUUID17().slice(0, 8)}-${safeName(label)}`;
|
|
11921
|
-
const path =
|
|
12361
|
+
const path = join24(dir, filename);
|
|
11922
12362
|
let fd;
|
|
11923
12363
|
try {
|
|
11924
12364
|
fd = openSync5(
|
|
@@ -11927,7 +12367,7 @@ function saveInputFiles(agentDir2, files, options = {}) {
|
|
|
11927
12367
|
384
|
|
11928
12368
|
);
|
|
11929
12369
|
if (!fstatSync5(fd).isFile()) throw new Error("attachment target is not a regular file");
|
|
11930
|
-
|
|
12370
|
+
writeFileSync9(fd, buf);
|
|
11931
12371
|
} finally {
|
|
11932
12372
|
if (fd !== void 0) closeSync5(fd);
|
|
11933
12373
|
}
|
|
@@ -11941,7 +12381,7 @@ function saveInputFiles(agentDir2, files, options = {}) {
|
|
|
11941
12381
|
|
|
11942
12382
|
// ../daemon/src/lib/coding-environment.ts
|
|
11943
12383
|
import { lstatSync as lstatSync5 } from "node:fs";
|
|
11944
|
-
import { join as
|
|
12384
|
+
import { join as join25 } from "node:path";
|
|
11945
12385
|
|
|
11946
12386
|
// ../daemon/src/core/coding-environment/config.ts
|
|
11947
12387
|
var CodingEnvironmentValidationError = class extends DomainError {
|
|
@@ -11998,7 +12438,7 @@ function setTeamCodingEnvironment(db, team, input, env = process.env) {
|
|
|
11998
12438
|
const environment = validateCodingEnvironment(input);
|
|
11999
12439
|
let path = team.path;
|
|
12000
12440
|
for (const part of environment.cwd === "." ? [] : environment.cwd.split("/")) {
|
|
12001
|
-
path =
|
|
12441
|
+
path = join25(path, part);
|
|
12002
12442
|
if (!lstatSync5(path, { throwIfNoEntry: false })?.isDirectory())
|
|
12003
12443
|
throw new CodingEnvironmentValidationError(
|
|
12004
12444
|
"The directory must be an existing directory inside the Team"
|
|
@@ -12018,18 +12458,18 @@ function dockerTurn(db, paths, agent, env) {
|
|
|
12018
12458
|
|
|
12019
12459
|
// ../daemon/src/lib/conversation-target.ts
|
|
12020
12460
|
import { randomUUID as randomUUID18 } from "node:crypto";
|
|
12021
|
-
import { writeFileSync as
|
|
12022
|
-
import { join as
|
|
12461
|
+
import { writeFileSync as writeFileSync10 } from "node:fs";
|
|
12462
|
+
import { join as join26 } from "node:path";
|
|
12023
12463
|
import { SessionManager as SessionManager2 } from "@earendil-works/pi-coding-agent";
|
|
12024
12464
|
function sessionsDir(paths, agentId) {
|
|
12025
|
-
return
|
|
12465
|
+
return join26(paths.agentDir(agentId), "sessions");
|
|
12026
12466
|
}
|
|
12027
12467
|
function startConversation(db, paths, agentId, title) {
|
|
12028
12468
|
const agent = resolveAgent(db, paths, agentId);
|
|
12029
12469
|
if (title !== void 0) validTitle(title);
|
|
12030
12470
|
const id = randomUUID18();
|
|
12031
12471
|
const header = SessionManager2.inMemory(agent.team.path, { id }).getHeader();
|
|
12032
|
-
|
|
12472
|
+
writeFileSync10(join26(sessionsDir(paths, agentId), `${id}.jsonl`), `${JSON.stringify(header)}
|
|
12033
12473
|
`, {
|
|
12034
12474
|
flag: "wx",
|
|
12035
12475
|
mode: 384
|
|
@@ -12077,7 +12517,7 @@ function selectedConversationTarget(db, agentId) {
|
|
|
12077
12517
|
|
|
12078
12518
|
// ../daemon/src/lib/repository-instructions.ts
|
|
12079
12519
|
import { realpathSync as realpathSync6 } from "node:fs";
|
|
12080
|
-
import { join as
|
|
12520
|
+
import { join as join27 } from "node:path";
|
|
12081
12521
|
var MAX_FILE_BYTES2 = 128 * 1024;
|
|
12082
12522
|
var SKIPPED = {
|
|
12083
12523
|
outside: "it resolves outside the Team workspace",
|
|
@@ -12097,7 +12537,7 @@ function loadRepositoryInstructions(root, cwd = ".") {
|
|
|
12097
12537
|
for (let depth = 0; depth <= parts.length; depth++) {
|
|
12098
12538
|
const path = [...parts.slice(0, depth), "AGENTS.md"].join("/");
|
|
12099
12539
|
try {
|
|
12100
|
-
const content = readContainedFile(
|
|
12540
|
+
const content = readContainedFile(join27(realRoot, path), realRoot, MAX_FILE_BYTES2);
|
|
12101
12541
|
instructions.push({ path, content: content.toString("utf8") });
|
|
12102
12542
|
} catch (error) {
|
|
12103
12543
|
if (error instanceof ContainedFileError) {
|
|
@@ -12165,10 +12605,10 @@ function releasePreparedAgentTurn(turn) {
|
|
|
12165
12605
|
}
|
|
12166
12606
|
|
|
12167
12607
|
// ../daemon/src/lib/user-md-host.ts
|
|
12168
|
-
import { createHash as
|
|
12608
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
12169
12609
|
var USER_MD_MAX_BYTES = 12e3;
|
|
12170
12610
|
function computeEtag(content) {
|
|
12171
|
-
return
|
|
12611
|
+
return createHash7("sha256").update(content, "utf8").digest("hex").slice(0, 16);
|
|
12172
12612
|
}
|
|
12173
12613
|
function createDbUserMdHost(db, paths) {
|
|
12174
12614
|
return {
|
|
@@ -12350,7 +12790,9 @@ async function* runAgentTurn(turn) {
|
|
|
12350
12790
|
repositoryInstructions: turn.repositoryInstructions,
|
|
12351
12791
|
mcpTools: mcp?.tools,
|
|
12352
12792
|
turnId: turn.request.attemptId,
|
|
12353
|
-
bashApprovalMode: turn.bashApprovalMode
|
|
12793
|
+
bashApprovalMode: turn.bashApprovalMode,
|
|
12794
|
+
contacts: agentContacts(db, agentId),
|
|
12795
|
+
withOperator: withOperator(turn)
|
|
12354
12796
|
},
|
|
12355
12797
|
{
|
|
12356
12798
|
env,
|
|
@@ -12389,6 +12831,9 @@ async function* runAgentTurn(turn) {
|
|
|
12389
12831
|
releasePreparedAgentTurn(turn);
|
|
12390
12832
|
}
|
|
12391
12833
|
}
|
|
12834
|
+
function withOperator(turn) {
|
|
12835
|
+
return turn.request.origin === "http" || turn.request.origin === "telegram";
|
|
12836
|
+
}
|
|
12392
12837
|
function turnHosts(turn, env) {
|
|
12393
12838
|
const { db, paths, authToken } = getCtx();
|
|
12394
12839
|
const { agent, conversation } = turn;
|
|
@@ -12430,6 +12875,8 @@ function turnHosts(turn, env) {
|
|
|
12430
12875
|
codexToken: () => loadAccessToken(db, authToken),
|
|
12431
12876
|
signal
|
|
12432
12877
|
}) : void 0,
|
|
12878
|
+
// Agents add teammates when the operator asks, never from a schedule or a teammate's message.
|
|
12879
|
+
teamHost: withOperator(turn) ? createDbTeamHost(db, paths, agent.agent.id) : void 0,
|
|
12433
12880
|
// Bound to this turn's Agent: the worker cannot drive another Agent's browser.
|
|
12434
12881
|
browserHost: isBrowserEnabled(env) ? createBrowserHost(resolveBrowserConfig(env), { paths, agentId: agent.agent.id, signal }) : void 0
|
|
12435
12882
|
};
|
|
@@ -12732,7 +13179,7 @@ agentChatRouter.post("/:id/chat/compact", async (c) => {
|
|
|
12732
13179
|
const { db, paths, authToken } = getCtx();
|
|
12733
13180
|
const resolved = resolveAgent(db, paths, id);
|
|
12734
13181
|
assertProviderReady(db, authToken, resolved.model);
|
|
12735
|
-
const memory = qmdBackend(
|
|
13182
|
+
const memory = qmdBackend(join28(resolved.team.path, "memory"));
|
|
12736
13183
|
await memory.init();
|
|
12737
13184
|
const handle12 = await createBazilionSession({
|
|
12738
13185
|
agent: resolved,
|
|
@@ -12790,9 +13237,9 @@ agentChatRouter.get(
|
|
|
12790
13237
|
const env = mergeSecretsIntoEnv(db, authToken);
|
|
12791
13238
|
const files = [];
|
|
12792
13239
|
for (const file of CONTEXT_FILE_ORDER2) {
|
|
12793
|
-
const path =
|
|
12794
|
-
if (!
|
|
12795
|
-
const content =
|
|
13240
|
+
const path = join28(resolved.agent.dir, file);
|
|
13241
|
+
if (!existsSync17(path)) continue;
|
|
13242
|
+
const content = readFileSync11(path, "utf8").trimEnd();
|
|
12796
13243
|
if (!content) continue;
|
|
12797
13244
|
const chars = content.length + file.length + 6;
|
|
12798
13245
|
files.push({ name: file, chars, tokens: estimateTokens2(chars) });
|
|
@@ -12805,9 +13252,12 @@ agentChatRouter.get(
|
|
|
12805
13252
|
agent: resolved,
|
|
12806
13253
|
paths,
|
|
12807
13254
|
env,
|
|
12808
|
-
memory: qmdBackend(
|
|
13255
|
+
memory: qmdBackend(join28(resolved.team.path, "memory")),
|
|
12809
13256
|
messagingHost: createDbMessagingHost(db),
|
|
12810
13257
|
userMdHost: createDbUserMdHost(db, paths),
|
|
13258
|
+
// As in a chat turn: the operator is there.
|
|
13259
|
+
teamHost: { createAgent: reportOnly },
|
|
13260
|
+
contacts: agentContacts(db, resolved.agent.id),
|
|
12811
13261
|
fileSink: reportOnly,
|
|
12812
13262
|
...isBrowserEnabled(env) ? { browserHost: { invoke: reportOnly } } : {},
|
|
12813
13263
|
...searchRoute(env, resolved.model, codexConnected).backend ? { webSearchHost: { search: reportOnly } } : {},
|
|
@@ -12835,7 +13285,7 @@ agentChatRouter.get(
|
|
|
12835
13285
|
let blockChars = name.length + 2;
|
|
12836
13286
|
if (match) {
|
|
12837
13287
|
try {
|
|
12838
|
-
blockChars =
|
|
13288
|
+
blockChars = readFileSync11(match.skillFile, "utf8").length;
|
|
12839
13289
|
} catch {
|
|
12840
13290
|
}
|
|
12841
13291
|
}
|
|
@@ -12909,7 +13359,7 @@ agentChatRouter.post("/:id/chat/truncate", async (c) => {
|
|
|
12909
13359
|
});
|
|
12910
13360
|
|
|
12911
13361
|
// ../daemon/src/routes/agent-learning.ts
|
|
12912
|
-
import { join as
|
|
13362
|
+
import { join as join29 } from "node:path";
|
|
12913
13363
|
|
|
12914
13364
|
// ../daemon/src/lib/lesson-decisions.ts
|
|
12915
13365
|
var LessonProposalConflictError = class extends DomainError {
|
|
@@ -13108,7 +13558,7 @@ for (const decision of ["approve", "reject", "revoke"]) {
|
|
|
13108
13558
|
const team = teams_exports.get(db, agent.teamId, paths);
|
|
13109
13559
|
if (!team) return c.json({ error: `team not found: ${agent.teamId}` }, 404);
|
|
13110
13560
|
const proposal = await runAgentLifecycleMutation(agent.id, async () => {
|
|
13111
|
-
const memory = qmdBackend(
|
|
13561
|
+
const memory = qmdBackend(join29(team.path, "memory"));
|
|
13112
13562
|
if (decision === "approve") return approveLessonProposal(db, memory, current2.id, version);
|
|
13113
13563
|
if (decision === "reject") return rejectLessonProposal(db, current2.id, version);
|
|
13114
13564
|
return revokeLessonProposal(db, memory, current2.id, version);
|
|
@@ -13136,188 +13586,9 @@ function withEvidenceExcerpts(proposals, agent, paths) {
|
|
|
13136
13586
|
}
|
|
13137
13587
|
|
|
13138
13588
|
// ../daemon/src/routes/agents.ts
|
|
13139
|
-
import { join as
|
|
13589
|
+
import { join as join30 } from "node:path";
|
|
13140
13590
|
init_pool2();
|
|
13141
13591
|
|
|
13142
|
-
// ../daemon/src/lib/telegram/config.ts
|
|
13143
|
-
var BOT_TOKEN_KEY = "TELEGRAM_BOT_TOKEN";
|
|
13144
|
-
var CHAT_ID_KEY = "TELEGRAM_CHAT_ID";
|
|
13145
|
-
var LAST_UPDATE_KEY = "TELEGRAM_LAST_UPDATE_ID";
|
|
13146
|
-
var SERVICE_TOPIC_KEY = "TELEGRAM_SERVICE_TOPIC_ID";
|
|
13147
|
-
var DIRECTORY_MESSAGE_KEY = "TELEGRAM_DIRECTORY_MESSAGE_ID";
|
|
13148
|
-
var MIGRATED_CHAT_KEY = "TELEGRAM_MIGRATED_CHAT_ID";
|
|
13149
|
-
function readConfigNumber(db, key2) {
|
|
13150
|
-
const raw = openConfig(db).get(key2) ?? "";
|
|
13151
|
-
if (!raw) return null;
|
|
13152
|
-
const value = Number(raw);
|
|
13153
|
-
return Number.isFinite(value) ? value : null;
|
|
13154
|
-
}
|
|
13155
|
-
function readServiceTopicId(db) {
|
|
13156
|
-
return readConfigNumber(db, SERVICE_TOPIC_KEY);
|
|
13157
|
-
}
|
|
13158
|
-
function readCreds(db, authToken) {
|
|
13159
|
-
const botToken = openSecrets(db, authToken).get(BOT_TOKEN_KEY) ?? "";
|
|
13160
|
-
const chatId2 = readConfigNumber(db, CHAT_ID_KEY);
|
|
13161
|
-
return botToken && chatId2 !== null ? { botToken, chatId: chatId2 } : null;
|
|
13162
|
-
}
|
|
13163
|
-
function redactToken(text4, botToken) {
|
|
13164
|
-
return (botToken ? text4.replaceAll(botToken, "[redacted]") : text4).replace(
|
|
13165
|
-
/bot\d+:[A-Za-z0-9_-]+/g,
|
|
13166
|
-
"bot[redacted]"
|
|
13167
|
-
);
|
|
13168
|
-
}
|
|
13169
|
-
|
|
13170
|
-
// ../daemon/src/lib/telegram/naming.ts
|
|
13171
|
-
var TEAM_COLORS = [
|
|
13172
|
-
7322096,
|
|
13173
|
-
// light blue / cyan
|
|
13174
|
-
16766590,
|
|
13175
|
-
// orange
|
|
13176
|
-
13338331,
|
|
13177
|
-
// purple / lavender
|
|
13178
|
-
9367192,
|
|
13179
|
-
// green
|
|
13180
|
-
16749490
|
|
13181
|
-
// pink / rose
|
|
13182
|
-
];
|
|
13183
|
-
var TOPIC_NAME_TOKENS = ["{agent.name}", "{team.name}", "{team.slug}"];
|
|
13184
|
-
function topicNameFor(agent, team) {
|
|
13185
|
-
const fmt = team.telegramTopicNameFormat ?? null;
|
|
13186
|
-
if (fmt) {
|
|
13187
|
-
return renderTopicNameFormat(fmt, {
|
|
13188
|
-
agentName: agent.name,
|
|
13189
|
-
teamName: team.name ?? team.id,
|
|
13190
|
-
teamSlug: team.id
|
|
13191
|
-
});
|
|
13192
|
-
}
|
|
13193
|
-
if (team.id === DEFAULT_TEAM_ID) return agent.name;
|
|
13194
|
-
return `${team.id} \u203A ${agent.name}`;
|
|
13195
|
-
}
|
|
13196
|
-
function renderTopicNameFormat(fmt, vals) {
|
|
13197
|
-
return fmt.replaceAll("{agent.name}", vals.agentName).replaceAll("{team.name}", vals.teamName).replaceAll("{team.slug}", vals.teamSlug);
|
|
13198
|
-
}
|
|
13199
|
-
function validateTopicNameFormat(fmt) {
|
|
13200
|
-
if (fmt.trim().length === 0) return "Format cannot be empty.";
|
|
13201
|
-
const used = fmt.match(/\{[^}]*\}/g) ?? [];
|
|
13202
|
-
for (const token of used) {
|
|
13203
|
-
if (!TOPIC_NAME_TOKENS.includes(token)) {
|
|
13204
|
-
return `Unknown token ${token}. Allowed tokens: ${TOPIC_NAME_TOKENS.join(", ")}.`;
|
|
13205
|
-
}
|
|
13206
|
-
}
|
|
13207
|
-
if (!fmt.includes("{agent.name}")) {
|
|
13208
|
-
return "Format must include {agent.name} so each agent gets a distinct topic name.";
|
|
13209
|
-
}
|
|
13210
|
-
return null;
|
|
13211
|
-
}
|
|
13212
|
-
function allocateTeamColor(db, teamId) {
|
|
13213
|
-
const existing = teams_exports.getTelegramIconColor(db, teamId);
|
|
13214
|
-
if (existing !== null) return existing;
|
|
13215
|
-
const idx = teams_exports.countAllocatedColors(db) % TEAM_COLORS.length;
|
|
13216
|
-
const color = TEAM_COLORS[idx] ?? 7322096;
|
|
13217
|
-
teams_exports.setTelegramIconColor(db, teamId, color);
|
|
13218
|
-
return color;
|
|
13219
|
-
}
|
|
13220
|
-
function topicDeepLink(chatId2, topicId) {
|
|
13221
|
-
const absStr = String(Math.abs(chatId2));
|
|
13222
|
-
const shortId = absStr.startsWith("100") ? absStr.slice(3) : absStr;
|
|
13223
|
-
return `https://t.me/c/${shortId}/${topicId}`;
|
|
13224
|
-
}
|
|
13225
|
-
|
|
13226
|
-
// ../daemon/src/lib/telegram/directory.ts
|
|
13227
|
-
function agentListLines(db, paths, chatId2) {
|
|
13228
|
-
const agents = agents_exports.list(db);
|
|
13229
|
-
const lines = [];
|
|
13230
|
-
for (const team of teams_exports.list(db, paths)) {
|
|
13231
|
-
const members = agents.filter((agent) => agent.teamId === team.id);
|
|
13232
|
-
if (members.length === 0) continue;
|
|
13233
|
-
lines.push("", `<b>${htmlEscape(team.id)}</b>`);
|
|
13234
|
-
for (const agent of members) {
|
|
13235
|
-
const label = ` \u2022 <code>${htmlEscape(agent.name)}</code>`;
|
|
13236
|
-
lines.push(
|
|
13237
|
-
agent.telegramTopicId === null ? `${label} <i>(unbound)</i>` : `${label} \u2192 <a href="${topicDeepLink(chatId2, agent.telegramTopicId)}">open</a>`
|
|
13238
|
-
);
|
|
13239
|
-
}
|
|
13240
|
-
}
|
|
13241
|
-
return lines;
|
|
13242
|
-
}
|
|
13243
|
-
function buildDirectoryBody(db, paths, chatId2) {
|
|
13244
|
-
if (agents_exports.list(db).length === 0) {
|
|
13245
|
-
return [
|
|
13246
|
-
"\u{1F44B} <b>bazilion is online</b>",
|
|
13247
|
-
"",
|
|
13248
|
-
"No agents yet \u2014 run /spawn in this topic to create one.",
|
|
13249
|
-
"See /help for the command list."
|
|
13250
|
-
].join("\n");
|
|
13251
|
-
}
|
|
13252
|
-
return [
|
|
13253
|
-
"\u{1F6DF} <b>Available agents</b>",
|
|
13254
|
-
...agentListLines(db, paths, chatId2),
|
|
13255
|
-
"",
|
|
13256
|
-
"Run /help for commands."
|
|
13257
|
-
].join("\n");
|
|
13258
|
-
}
|
|
13259
|
-
async function refreshDirectoryMessage(deps) {
|
|
13260
|
-
const serviceTopicId = readServiceTopicId(deps.db);
|
|
13261
|
-
if (serviceTopicId === null) return;
|
|
13262
|
-
const body = buildDirectoryBody(deps.db, deps.paths, deps.chatId);
|
|
13263
|
-
const messageId = readConfigNumber(deps.db, DIRECTORY_MESSAGE_KEY);
|
|
13264
|
-
if (messageId !== null) {
|
|
13265
|
-
try {
|
|
13266
|
-
await deps.api.editMessageText(deps.chatId, messageId, body, {
|
|
13267
|
-
parse_mode: "HTML",
|
|
13268
|
-
disable_web_page_preview: true
|
|
13269
|
-
});
|
|
13270
|
-
return;
|
|
13271
|
-
} catch (e) {
|
|
13272
|
-
if (isNotModifiedError(e)) return;
|
|
13273
|
-
if (!isMessageGoneError(e)) throw e;
|
|
13274
|
-
console.warn(
|
|
13275
|
-
"telegram directory: pinned message gone, recreating \u2014",
|
|
13276
|
-
e instanceof Error ? e.message : String(e)
|
|
13277
|
-
);
|
|
13278
|
-
}
|
|
13279
|
-
}
|
|
13280
|
-
const sent = await deps.api.sendMessage(deps.chatId, body, {
|
|
13281
|
-
message_thread_id: serviceTopicId,
|
|
13282
|
-
parse_mode: "HTML",
|
|
13283
|
-
disable_web_page_preview: true
|
|
13284
|
-
});
|
|
13285
|
-
openConfig(deps.db).set(DIRECTORY_MESSAGE_KEY, String(sent.message_id));
|
|
13286
|
-
try {
|
|
13287
|
-
await deps.api.pinChatMessage(deps.chatId, sent.message_id, { disable_notification: true });
|
|
13288
|
-
} catch (e) {
|
|
13289
|
-
console.warn(
|
|
13290
|
-
"telegram directory: pin failed (continuing):",
|
|
13291
|
-
e instanceof Error ? e.message : String(e)
|
|
13292
|
-
);
|
|
13293
|
-
}
|
|
13294
|
-
}
|
|
13295
|
-
function isMessageGoneError(e) {
|
|
13296
|
-
if (!(e instanceof Error)) return false;
|
|
13297
|
-
const msg = e.message.toLowerCase();
|
|
13298
|
-
return msg.includes("message to edit not found") || msg.includes("message_id_invalid") || msg.includes("message can");
|
|
13299
|
-
}
|
|
13300
|
-
function isNotModifiedError(e) {
|
|
13301
|
-
if (!(e instanceof Error)) return false;
|
|
13302
|
-
return e.message.toLowerCase().includes("message is not modified");
|
|
13303
|
-
}
|
|
13304
|
-
var refreshScheduled = false;
|
|
13305
|
-
function notifyDirectoryDirty() {
|
|
13306
|
-
if (refreshScheduled) return;
|
|
13307
|
-
refreshScheduled = true;
|
|
13308
|
-
setImmediate(() => {
|
|
13309
|
-
refreshScheduled = false;
|
|
13310
|
-
const live = telegramLive();
|
|
13311
|
-
if (!live) return;
|
|
13312
|
-
refreshDirectoryMessage({ ...live, api: live.api }).catch(
|
|
13313
|
-
(e) => console.warn(
|
|
13314
|
-
"telegram directory: scheduled refresh failed \u2014",
|
|
13315
|
-
e instanceof Error ? e.message : String(e)
|
|
13316
|
-
)
|
|
13317
|
-
);
|
|
13318
|
-
});
|
|
13319
|
-
}
|
|
13320
|
-
|
|
13321
13592
|
// ../daemon/src/lib/telegram/profile-emojis.ts
|
|
13322
13593
|
var BUILTIN_PROFILE_EMOJI = {
|
|
13323
13594
|
researcher: "\u{1F4DA}",
|
|
@@ -13411,7 +13682,7 @@ agentsRouter.get("/", (c) => {
|
|
|
13411
13682
|
const includeArchived = c.req.query("includeArchived") === "true";
|
|
13412
13683
|
const agents = agents_exports.list(getCtx().db, { includeArchived }).map((agent) => ({
|
|
13413
13684
|
...agent,
|
|
13414
|
-
identity: loadIdentityFromFile(
|
|
13685
|
+
identity: loadIdentityFromFile(join30(agent.dir, "IDENTITY.md"))
|
|
13415
13686
|
}));
|
|
13416
13687
|
return c.json(agents);
|
|
13417
13688
|
});
|
|
@@ -13450,6 +13721,8 @@ agentsRouter.patch("/:id", async (c) => {
|
|
|
13450
13721
|
400
|
|
13451
13722
|
);
|
|
13452
13723
|
}
|
|
13724
|
+
const nameProblem = typeof name === "string" ? agentNameProblem(name.trim()) : null;
|
|
13725
|
+
if (nameProblem) return c.json({ error: nameProblem }, 400);
|
|
13453
13726
|
if (telegramMirrorMode !== void 0 && telegramMirrorMode !== "minimal" && telegramMirrorMode !== "verbose") {
|
|
13454
13727
|
return c.json({ error: `invalid telegramMirrorMode: ${String(telegramMirrorMode)}` }, 400);
|
|
13455
13728
|
}
|
|
@@ -14841,7 +15114,7 @@ configRouter.delete("/fields/:envVar", (c) => {
|
|
|
14841
15114
|
});
|
|
14842
15115
|
|
|
14843
15116
|
// ../daemon/src/lib/conversation-search.ts
|
|
14844
|
-
import { join as
|
|
15117
|
+
import { join as join31 } from "node:path";
|
|
14845
15118
|
import { buildSessionContext as buildSessionContext2 } from "@earendil-works/pi-coding-agent";
|
|
14846
15119
|
var INBOX_WAKE_PREFIX = "[[bazilion:inbox-wake]]\n";
|
|
14847
15120
|
var MAX_WORDS = 8;
|
|
@@ -14885,7 +15158,7 @@ async function searchConversations(db, paths, options) {
|
|
|
14885
15158
|
for (const row of rows) {
|
|
14886
15159
|
await new Promise((resolve9) => setImmediate(resolve9));
|
|
14887
15160
|
if (options.signal?.aborted) break;
|
|
14888
|
-
const directory =
|
|
15161
|
+
const directory = join31(paths.agentDir(row.agentId), "sessions");
|
|
14889
15162
|
let text4;
|
|
14890
15163
|
try {
|
|
14891
15164
|
text4 = readSessionText(directory, row.id);
|
|
@@ -14937,7 +15210,7 @@ async function searchConversations(db, paths, options) {
|
|
|
14937
15210
|
|
|
14938
15211
|
// ../daemon/src/lib/usage.ts
|
|
14939
15212
|
import { closeSync as closeSync6, constants as constants7, fstatSync as fstatSync6, openSync as openSync6, readdirSync as readdirSync7, readSync as readSync3 } from "node:fs";
|
|
14940
|
-
import { join as
|
|
15213
|
+
import { join as join32 } from "node:path";
|
|
14941
15214
|
var CONVERSATION_FILE = /^([0-9a-f-]{36})\.jsonl$/i;
|
|
14942
15215
|
var READ_CHUNK = 1024 * 1024;
|
|
14943
15216
|
var CACHE_KEY = /* @__PURE__ */ Symbol.for("bazilion.usage.files");
|
|
@@ -15057,7 +15330,7 @@ function scanUsage(paths, agentIds, options = {}) {
|
|
|
15057
15330
|
let unreadable = 0;
|
|
15058
15331
|
const seen = /* @__PURE__ */ new Set();
|
|
15059
15332
|
for (const agentId of agentIds) {
|
|
15060
|
-
const directory =
|
|
15333
|
+
const directory = join32(paths.agentDir(agentId), "sessions");
|
|
15061
15334
|
let names;
|
|
15062
15335
|
try {
|
|
15063
15336
|
names = readdirSync7(directory);
|
|
@@ -15067,7 +15340,7 @@ function scanUsage(paths, agentIds, options = {}) {
|
|
|
15067
15340
|
for (const name of names) {
|
|
15068
15341
|
const id = CONVERSATION_FILE.exec(name)?.[1];
|
|
15069
15342
|
if (!id) continue;
|
|
15070
|
-
const path =
|
|
15343
|
+
const path = join32(directory, name);
|
|
15071
15344
|
seen.add(path);
|
|
15072
15345
|
try {
|
|
15073
15346
|
const totals = scanFile(path).totals;
|
|
@@ -15077,7 +15350,7 @@ function scanUsage(paths, agentIds, options = {}) {
|
|
|
15077
15350
|
}
|
|
15078
15351
|
}
|
|
15079
15352
|
}
|
|
15080
|
-
const listed = agentIds.map((id) => `${
|
|
15353
|
+
const listed = agentIds.map((id) => `${join32(paths.agentDir(id), "sessions")}/`);
|
|
15081
15354
|
for (const path of cache().keys()) {
|
|
15082
15355
|
if (seen.has(path)) continue;
|
|
15083
15356
|
if (options.everyAgent || listed.some((prefix) => path.startsWith(prefix))) cache().delete(path);
|
|
@@ -15373,19 +15646,19 @@ conversationsRouter.patch("/:agentId/conversations/:id", async (c) => {
|
|
|
15373
15646
|
import { streamSSE } from "hono/streaming";
|
|
15374
15647
|
|
|
15375
15648
|
// ../daemon/src/lib/live.ts
|
|
15376
|
-
import { createHash as
|
|
15649
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
15377
15650
|
var CHECK_MS = 1e3;
|
|
15378
15651
|
var ATTENTION_EVERY = 5;
|
|
15379
15652
|
var SETTLE_MS = 25;
|
|
15380
15653
|
function readLiveActivity() {
|
|
15381
15654
|
const { db, paths } = getCtx();
|
|
15382
|
-
return { type: "activity", agents: readActivity(db, paths) };
|
|
15655
|
+
return { type: "activity", agents: readActivity(db, paths), roster: rosterRevision(db) };
|
|
15383
15656
|
}
|
|
15384
15657
|
function readLiveAttention() {
|
|
15385
15658
|
const { db } = getCtx();
|
|
15386
15659
|
const waiting = waitingAttention(db);
|
|
15387
15660
|
const all = projectAttention(db, { state: "all", limit: 1e5 }, waiting);
|
|
15388
|
-
const revision =
|
|
15661
|
+
const revision = createHash8("sha256").update(
|
|
15389
15662
|
all.items.map((item) => `${item.key}|${item.updatedAt}|${item.acknowledgedAt ?? ""}`).join("\n")
|
|
15390
15663
|
).update(JSON.stringify(all.degraded)).digest("hex").slice(0, 16);
|
|
15391
15664
|
return {
|
|
@@ -15681,25 +15954,25 @@ agentMessagesRouter.post("/:id/messages", async (c) => {
|
|
|
15681
15954
|
});
|
|
15682
15955
|
|
|
15683
15956
|
// ../daemon/src/routes/misc.ts
|
|
15684
|
-
import { existsSync as
|
|
15957
|
+
import { existsSync as existsSync18 } from "node:fs";
|
|
15685
15958
|
import { homedir as homedir4 } from "node:os";
|
|
15686
|
-
import { join as
|
|
15959
|
+
import { join as join35 } from "node:path";
|
|
15687
15960
|
|
|
15688
15961
|
// ../daemon/src/lib/backup.ts
|
|
15689
|
-
import { mkdtempSync as mkdtempSync3, rmSync as
|
|
15962
|
+
import { mkdtempSync as mkdtempSync3, rmSync as rmSync14 } from "node:fs";
|
|
15690
15963
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
15691
|
-
import { join as
|
|
15964
|
+
import { join as join34, resolve as resolve7 } from "node:path";
|
|
15692
15965
|
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
15693
15966
|
import { create as create6 } from "tar";
|
|
15694
15967
|
|
|
15695
15968
|
// ../daemon/src/lib/daemon-liveness.ts
|
|
15696
|
-
import { mkdirSync as mkdirSync11, readFileSync as
|
|
15697
|
-
import { join as
|
|
15969
|
+
import { mkdirSync as mkdirSync11, readFileSync as readFileSync12, rmSync as rmSync13, writeFileSync as writeFileSync11 } from "node:fs";
|
|
15970
|
+
import { join as join33 } from "node:path";
|
|
15698
15971
|
var DAEMON_PID_FILE = "daemon.pid";
|
|
15699
15972
|
function runningDaemonPid(home) {
|
|
15700
15973
|
let pid;
|
|
15701
15974
|
try {
|
|
15702
|
-
pid = Number.parseInt(
|
|
15975
|
+
pid = Number.parseInt(readFileSync12(join33(home, DAEMON_PID_FILE), "utf8"), 10);
|
|
15703
15976
|
} catch (error) {
|
|
15704
15977
|
if (error.code === "ENOENT") return null;
|
|
15705
15978
|
throw error;
|
|
@@ -15716,26 +15989,26 @@ function assertDaemonStopped(home) {
|
|
|
15716
15989
|
const pid = runningDaemonPid(home);
|
|
15717
15990
|
if (pid !== null) {
|
|
15718
15991
|
throw new Error(
|
|
15719
|
-
`a bazilion daemon (pid ${pid}) is running on ${home}; stop it first (if none is running, delete ${
|
|
15992
|
+
`a bazilion daemon (pid ${pid}) is running on ${home}; stop it first (if none is running, delete ${join33(home, DAEMON_PID_FILE)})`
|
|
15720
15993
|
);
|
|
15721
15994
|
}
|
|
15722
15995
|
}
|
|
15723
15996
|
function claimDaemonPidFile(home) {
|
|
15724
|
-
const path =
|
|
15997
|
+
const path = join33(home, DAEMON_PID_FILE);
|
|
15725
15998
|
const content = `${process.pid}
|
|
15726
15999
|
`;
|
|
15727
16000
|
mkdirSync11(home, { recursive: true });
|
|
15728
16001
|
try {
|
|
15729
|
-
|
|
16002
|
+
writeFileSync11(path, content, { flag: "wx", mode: 384 });
|
|
15730
16003
|
} catch (error) {
|
|
15731
16004
|
if (error.code !== "EEXIST") throw error;
|
|
15732
16005
|
assertDaemonStopped(home);
|
|
15733
|
-
|
|
15734
|
-
|
|
16006
|
+
rmSync13(path, { force: true });
|
|
16007
|
+
writeFileSync11(path, content, { flag: "wx", mode: 384 });
|
|
15735
16008
|
}
|
|
15736
16009
|
return () => {
|
|
15737
16010
|
try {
|
|
15738
|
-
if (
|
|
16011
|
+
if (readFileSync12(path, "utf8") === content) rmSync13(path);
|
|
15739
16012
|
} catch {
|
|
15740
16013
|
}
|
|
15741
16014
|
};
|
|
@@ -15750,10 +16023,10 @@ function createBackupSnapshot(db) {
|
|
|
15750
16023
|
return snapshot3;
|
|
15751
16024
|
}
|
|
15752
16025
|
async function takeSnapshot(db) {
|
|
15753
|
-
const directory = mkdtempSync3(
|
|
15754
|
-
const cleanup = () =>
|
|
16026
|
+
const directory = mkdtempSync3(join34(tmpdir3(), "bazilion-backup-"));
|
|
16027
|
+
const cleanup = () => rmSync14(directory, { recursive: true, force: true });
|
|
15755
16028
|
try {
|
|
15756
|
-
const database =
|
|
16029
|
+
const database = join34(directory, "bazilion.snapshot");
|
|
15757
16030
|
await db.backupTo(database);
|
|
15758
16031
|
const snapshot3 = new DatabaseSync2(database, { readOnly: true });
|
|
15759
16032
|
try {
|
|
@@ -15801,12 +16074,12 @@ miscRouter.get("/health", (c) => {
|
|
|
15801
16074
|
miscRouter.get("/health/details", async (c) => {
|
|
15802
16075
|
const { paths } = getCtx();
|
|
15803
16076
|
const pathChecks = {
|
|
15804
|
-
home:
|
|
15805
|
-
db:
|
|
15806
|
-
auth:
|
|
15807
|
-
profiles:
|
|
15808
|
-
agents:
|
|
15809
|
-
skills:
|
|
16077
|
+
home: existsSync18(paths.home),
|
|
16078
|
+
db: existsSync18(paths.db),
|
|
16079
|
+
auth: existsSync18(paths.authFile),
|
|
16080
|
+
profiles: existsSync18(paths.profilesDir),
|
|
16081
|
+
agents: existsSync18(paths.agentsDir),
|
|
16082
|
+
skills: existsSync18(paths.skillsDir)
|
|
15810
16083
|
};
|
|
15811
16084
|
let database = null;
|
|
15812
16085
|
const triggersSection = { active: 0, disabled: 0 };
|
|
@@ -15852,7 +16125,7 @@ miscRouter.get("/health/details", async (c) => {
|
|
|
15852
16125
|
} catch {
|
|
15853
16126
|
}
|
|
15854
16127
|
}
|
|
15855
|
-
const openclawSkillsDir =
|
|
16128
|
+
const openclawSkillsDir = join35(homedir4(), ".openclaw", "skills");
|
|
15856
16129
|
const providerSection = {
|
|
15857
16130
|
// Hosted providers with credentials; local servers are reported below.
|
|
15858
16131
|
configured: PROVIDERS.filter(
|
|
@@ -15902,7 +16175,7 @@ miscRouter.get("/health/details", async (c) => {
|
|
|
15902
16175
|
},
|
|
15903
16176
|
openclaw: {
|
|
15904
16177
|
path: openclawSkillsDir,
|
|
15905
|
-
exists:
|
|
16178
|
+
exists: existsSync18(openclawSkillsDir)
|
|
15906
16179
|
},
|
|
15907
16180
|
triggers: triggersSection,
|
|
15908
16181
|
tokens: tokensSection,
|
|
@@ -15929,7 +16202,7 @@ function publicShellSecurityError(error) {
|
|
|
15929
16202
|
}
|
|
15930
16203
|
miscRouter.get("/backup", async (c) => {
|
|
15931
16204
|
const { db, paths } = getCtx();
|
|
15932
|
-
if (!
|
|
16205
|
+
if (!existsSync18(paths.home)) {
|
|
15933
16206
|
return c.json({ error: `bazilion home not found at ${paths.home}` }, 404);
|
|
15934
16207
|
}
|
|
15935
16208
|
let snapshot3;
|
|
@@ -16260,8 +16533,8 @@ notificationsRouter.put("/", async (c) => {
|
|
|
16260
16533
|
});
|
|
16261
16534
|
|
|
16262
16535
|
// ../daemon/src/routes/profiles.ts
|
|
16263
|
-
import { existsSync as
|
|
16264
|
-
import { join as
|
|
16536
|
+
import { existsSync as existsSync19, readFileSync as readFileSync13, writeFileSync as writeFileSync12 } from "node:fs";
|
|
16537
|
+
import { join as join36 } from "node:path";
|
|
16265
16538
|
var profilesRouter = newRouter();
|
|
16266
16539
|
profilesRouter.get("/", (c) => {
|
|
16267
16540
|
const { db } = getCtx();
|
|
@@ -16343,20 +16616,20 @@ function profileFile(c) {
|
|
|
16343
16616
|
if (!PROFILE_FILES.includes(file)) {
|
|
16344
16617
|
return c.json({ error: `unsupported file: ${file}` }, 400);
|
|
16345
16618
|
}
|
|
16346
|
-
return
|
|
16619
|
+
return join36(paths.profilesDir, id, file);
|
|
16347
16620
|
}
|
|
16348
16621
|
profilesRouter.get("/:id/files/:file", (c) => {
|
|
16349
16622
|
const path = profileFile(c);
|
|
16350
16623
|
if (typeof path !== "string") return path;
|
|
16351
|
-
if (!
|
|
16352
|
-
return c.json({ content:
|
|
16624
|
+
if (!existsSync19(path)) return c.json({ error: `file not present: ${c.req.param("file")}` }, 404);
|
|
16625
|
+
return c.json({ content: readFileSync13(path, "utf8") });
|
|
16353
16626
|
});
|
|
16354
16627
|
profilesRouter.put("/:id/files/:file", async (c) => {
|
|
16355
16628
|
const body = await jsonBody(c);
|
|
16356
16629
|
if (typeof body?.content !== "string") return c.json({ error: "content is required" }, 400);
|
|
16357
16630
|
const path = profileFile(c);
|
|
16358
16631
|
if (typeof path !== "string") return path;
|
|
16359
|
-
|
|
16632
|
+
writeFileSync12(path, body.content);
|
|
16360
16633
|
return c.body(null, 204);
|
|
16361
16634
|
});
|
|
16362
16635
|
|
|
@@ -16626,9 +16899,9 @@ shellApprovalsRouter.post("/:id", async (c) => {
|
|
|
16626
16899
|
});
|
|
16627
16900
|
|
|
16628
16901
|
// ../daemon/src/routes/skills.ts
|
|
16629
|
-
import { mkdtempSync as mkdtempSync4, rmSync as
|
|
16902
|
+
import { mkdtempSync as mkdtempSync4, rmSync as rmSync15, writeFileSync as writeFileSync13 } from "node:fs";
|
|
16630
16903
|
import { homedir as homedir5, tmpdir as tmpdir4 } from "node:os";
|
|
16631
|
-
import { join as
|
|
16904
|
+
import { join as join37 } from "node:path";
|
|
16632
16905
|
var MAX_ZIP_BYTES = 50 * 1024 * 1024;
|
|
16633
16906
|
var skillsRouter = newRouter();
|
|
16634
16907
|
skillsRouter.get("/", (c) => {
|
|
@@ -16658,7 +16931,7 @@ skillsRouter.delete("/:name", (c) => {
|
|
|
16658
16931
|
const name = c.req.param("name");
|
|
16659
16932
|
const skill = discoverSkills(paths).find((s) => s.name === name);
|
|
16660
16933
|
if (!skill) return c.json({ error: `skill not found: ${name}` }, 404);
|
|
16661
|
-
|
|
16934
|
+
rmSync15(skill.dir, { recursive: true, force: true });
|
|
16662
16935
|
skillMeta_exports.remove(db, name);
|
|
16663
16936
|
return c.body(null, 204);
|
|
16664
16937
|
});
|
|
@@ -16695,7 +16968,7 @@ skillsRouter.post("/import", async (c) => {
|
|
|
16695
16968
|
}
|
|
16696
16969
|
return c.json({ error: err.message }, 400);
|
|
16697
16970
|
} finally {
|
|
16698
|
-
if (input.tempZipPath)
|
|
16971
|
+
if (input.tempZipPath) rmSync15(input.tempZipPath, { recursive: true, force: true });
|
|
16699
16972
|
}
|
|
16700
16973
|
});
|
|
16701
16974
|
function flattenFindings(findings) {
|
|
@@ -16721,10 +16994,10 @@ async function parseImportInput(request) {
|
|
|
16721
16994
|
if (!filename.toLowerCase().endsWith(".zip")) {
|
|
16722
16995
|
throw new Error("uploaded file must be a .zip archive");
|
|
16723
16996
|
}
|
|
16724
|
-
const tmpDir = mkdtempSync4(
|
|
16725
|
-
const zipPath =
|
|
16997
|
+
const tmpDir = mkdtempSync4(join37(tmpdir4(), "bazilion-skill-upload-"));
|
|
16998
|
+
const zipPath = join37(tmpDir, filename.replace(/[^\w.-]+/g, "_"));
|
|
16726
16999
|
const buf = Buffer.from(await file.arrayBuffer());
|
|
16727
|
-
|
|
17000
|
+
writeFileSync13(zipPath, buf);
|
|
16728
17001
|
const forceField = form.get("force");
|
|
16729
17002
|
return {
|
|
16730
17003
|
source: zipPath,
|
|
@@ -16738,7 +17011,7 @@ async function parseImportInput(request) {
|
|
|
16738
17011
|
const { source } = body;
|
|
16739
17012
|
if (typeof source !== "string" || !source) throw new Error("source is required");
|
|
16740
17013
|
return {
|
|
16741
|
-
source: source === "openclaw" ?
|
|
17014
|
+
source: source === "openclaw" ? join37(homedir5(), ".openclaw", "skills") : source,
|
|
16742
17015
|
force: Boolean(body.force),
|
|
16743
17016
|
tempZipPath: null,
|
|
16744
17017
|
sourceLabel: source
|
|
@@ -16808,7 +17081,7 @@ teamCodingEnvironmentRouter.put("/:id/coding-environment", async (c) => {
|
|
|
16808
17081
|
});
|
|
16809
17082
|
|
|
16810
17083
|
// ../daemon/src/routes/team-memory.ts
|
|
16811
|
-
import { join as
|
|
17084
|
+
import { join as join38 } from "node:path";
|
|
16812
17085
|
var teamMemoryRouter = newRouter();
|
|
16813
17086
|
teamMemoryRouter.onError((error, c) => {
|
|
16814
17087
|
const safe = sanitizeNativeModuleError(error, { subject: "Bazilion memory" });
|
|
@@ -16816,7 +17089,7 @@ teamMemoryRouter.onError((error, c) => {
|
|
|
16816
17089
|
return onRouteError(safe, c);
|
|
16817
17090
|
});
|
|
16818
17091
|
async function openMemory(c) {
|
|
16819
|
-
const mem = qmdBackend(
|
|
17092
|
+
const mem = qmdBackend(join38(routeTeam(c).path, "memory"));
|
|
16820
17093
|
await mem.init();
|
|
16821
17094
|
return mem;
|
|
16822
17095
|
}
|
|
@@ -16871,7 +17144,7 @@ teamPolicyRouter.post("/:id/policy/save-as-template", async (c) => {
|
|
|
16871
17144
|
});
|
|
16872
17145
|
|
|
16873
17146
|
// ../daemon/src/lib/git/context-directory.ts
|
|
16874
|
-
import { createHash as
|
|
17147
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
16875
17148
|
import {
|
|
16876
17149
|
closeSync as closeSync7,
|
|
16877
17150
|
constants as constants8,
|
|
@@ -16882,8 +17155,8 @@ import {
|
|
|
16882
17155
|
readSync as readSync4,
|
|
16883
17156
|
realpathSync as realpathSync7
|
|
16884
17157
|
} from "node:fs";
|
|
16885
|
-
import { join as
|
|
16886
|
-
var hash = (value) =>
|
|
17158
|
+
import { join as join39 } from "node:path";
|
|
17159
|
+
var hash = (value) => createHash9("sha256").update(value).digest("hex");
|
|
16887
17160
|
var ContextReadError = class extends Error {
|
|
16888
17161
|
code;
|
|
16889
17162
|
constructor(code) {
|
|
@@ -16920,12 +17193,12 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
16920
17193
|
this.parent = parent;
|
|
16921
17194
|
if (parent) component(registeredPath);
|
|
16922
17195
|
parent?.assertOpen();
|
|
16923
|
-
const canonicalPath = parent ?
|
|
17196
|
+
const canonicalPath = parent ? join39(parent.canonicalPath, registeredPath) : realpathSync7(registeredPath);
|
|
16924
17197
|
this.canonicalPath = canonicalPath;
|
|
16925
17198
|
let fd;
|
|
16926
17199
|
try {
|
|
16927
17200
|
fd = openSync7(
|
|
16928
|
-
parent ?
|
|
17201
|
+
parent ? join39(parent.path, registeredPath) : canonicalPath,
|
|
16929
17202
|
constants8.O_RDONLY | constants8.O_DIRECTORY | constants8.O_NOFOLLOW
|
|
16930
17203
|
);
|
|
16931
17204
|
const stat = fstatSync7(fd, { bigint: true });
|
|
@@ -16974,7 +17247,7 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
16974
17247
|
entry(name) {
|
|
16975
17248
|
component(name);
|
|
16976
17249
|
this.assertOpen();
|
|
16977
|
-
const path =
|
|
17250
|
+
const path = join39(this.path, name);
|
|
16978
17251
|
try {
|
|
16979
17252
|
return lstatSync6(path);
|
|
16980
17253
|
} catch (error) {
|
|
@@ -16983,7 +17256,7 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
16983
17256
|
}
|
|
16984
17257
|
}
|
|
16985
17258
|
observe(name) {
|
|
16986
|
-
const path =
|
|
17259
|
+
const path = join39(this.path, name);
|
|
16987
17260
|
try {
|
|
16988
17261
|
return lstatSync6(path, { bigint: true });
|
|
16989
17262
|
} catch (error) {
|
|
@@ -17026,7 +17299,7 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
17026
17299
|
let fd;
|
|
17027
17300
|
try {
|
|
17028
17301
|
fd = openSync7(
|
|
17029
|
-
|
|
17302
|
+
join39(this.path, name),
|
|
17030
17303
|
constants8.O_RDONLY | constants8.O_NOFOLLOW | constants8.O_NONBLOCK
|
|
17031
17304
|
);
|
|
17032
17305
|
const before = fstatSync7(fd, { bigint: true });
|
|
@@ -17053,7 +17326,7 @@ var ContextDirectory = class _ContextDirectory {
|
|
|
17053
17326
|
}
|
|
17054
17327
|
validate(skipGit = false, names) {
|
|
17055
17328
|
this.assertOpen();
|
|
17056
|
-
const currentPath = this.parent ?
|
|
17329
|
+
const currentPath = this.parent ? join39(this.parent.path, this.registeredPath) : realpathSync7(this.registeredPath);
|
|
17057
17330
|
const stat = lstatSync6(currentPath, { bigint: true });
|
|
17058
17331
|
if (!stat.isDirectory() || identity(stat) !== identity(this.originalIdentity))
|
|
17059
17332
|
throw new ContextReadError("root_changed");
|
|
@@ -17479,9 +17752,9 @@ async function readOrNull(captured, args) {
|
|
|
17479
17752
|
|
|
17480
17753
|
// ../daemon/src/lib/git/capture.ts
|
|
17481
17754
|
import { execFile } from "node:child_process";
|
|
17482
|
-
import { mkdirSync as mkdirSync12, mkdtempSync as mkdtempSync5, rmSync as
|
|
17755
|
+
import { mkdirSync as mkdirSync12, mkdtempSync as mkdtempSync5, rmSync as rmSync16, utimesSync, writeFileSync as writeFileSync14 } from "node:fs";
|
|
17483
17756
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
17484
|
-
import { join as
|
|
17757
|
+
import { join as join40 } from "node:path";
|
|
17485
17758
|
var INSPECTION_BUDGET_MS = 5e3;
|
|
17486
17759
|
var METADATA_BUDGET_MS = 2500;
|
|
17487
17760
|
var METADATA_BYTES = 64 * 1024 * 1024;
|
|
@@ -17510,12 +17783,12 @@ async function captureRepositoryGit(root, budgetMs = INSPECTION_BUDGET_MS) {
|
|
|
17510
17783
|
const dir = git.directory("info");
|
|
17511
17784
|
if (dir.entry("sparse-checkout")) throw new ContextReadError("unsupported_git_metadata");
|
|
17512
17785
|
}
|
|
17513
|
-
const scratch = mkdtempSync5(
|
|
17786
|
+
const scratch = mkdtempSync5(join40(tmpdir5(), "bazilion-context-git-"));
|
|
17514
17787
|
let cleaned = false;
|
|
17515
17788
|
const cleanup = () => {
|
|
17516
17789
|
if (cleaned) return;
|
|
17517
17790
|
cleaned = true;
|
|
17518
|
-
|
|
17791
|
+
rmSync16(scratch, { recursive: true, force: true });
|
|
17519
17792
|
};
|
|
17520
17793
|
const checkBudget = () => {
|
|
17521
17794
|
if (Date.now() - start2 >= budgetMs) throw new ContextReadError("git_timeout");
|
|
@@ -17571,8 +17844,8 @@ async function captureRepositoryGit(root, budgetMs = INSPECTION_BUDGET_MS) {
|
|
|
17571
17844
|
if (capturedConfig) {
|
|
17572
17845
|
bytes += capturedConfig.length;
|
|
17573
17846
|
count2++;
|
|
17574
|
-
const configPath =
|
|
17575
|
-
|
|
17847
|
+
const configPath = join40(scratch, "captured-config");
|
|
17848
|
+
writeFileSync14(configPath, capturedConfig, { mode: 384 });
|
|
17576
17849
|
const config = await rawGit([
|
|
17577
17850
|
"config",
|
|
17578
17851
|
"--no-includes",
|
|
@@ -17624,8 +17897,8 @@ objectformat = ${value}`
|
|
|
17624
17897
|
const exclude = git.directory("info").read("exclude", METADATA_READ);
|
|
17625
17898
|
if (exclude) {
|
|
17626
17899
|
bytes += exclude.length;
|
|
17627
|
-
mkdirSync12(
|
|
17628
|
-
|
|
17900
|
+
mkdirSync12(join40(scratch, "info"), { mode: 448 });
|
|
17901
|
+
writeFileSync14(join40(scratch, "info", "exclude"), exclude, { mode: 384 });
|
|
17629
17902
|
}
|
|
17630
17903
|
}
|
|
17631
17904
|
const copy = (source, destination, depth) => {
|
|
@@ -17638,13 +17911,13 @@ objectformat = ${value}`
|
|
|
17638
17911
|
if (name === "alternates" || name === "http-alternates")
|
|
17639
17912
|
throw new ContextReadError("unsupported_git_metadata");
|
|
17640
17913
|
if (entry.isDirectory()) {
|
|
17641
|
-
mkdirSync12(
|
|
17642
|
-
copy(source.directory(name),
|
|
17914
|
+
mkdirSync12(join40(destination, name), { mode: 448 });
|
|
17915
|
+
copy(source.directory(name), join40(destination, name), depth + 1);
|
|
17643
17916
|
} else {
|
|
17644
17917
|
const content = source.read(name, METADATA_BYTES - bytes);
|
|
17645
17918
|
if (!content) throw new ContextReadError("source_changed");
|
|
17646
17919
|
bytes += content.length;
|
|
17647
|
-
|
|
17920
|
+
writeFileSync14(join40(destination, name), content, { mode: 384 });
|
|
17648
17921
|
}
|
|
17649
17922
|
}
|
|
17650
17923
|
};
|
|
@@ -17654,20 +17927,20 @@ objectformat = ${value}`
|
|
|
17654
17927
|
if (content) {
|
|
17655
17928
|
count2++;
|
|
17656
17929
|
bytes += content.length;
|
|
17657
|
-
|
|
17930
|
+
writeFileSync14(join40(scratch, name), content, { mode: 384 });
|
|
17658
17931
|
if (written) {
|
|
17659
17932
|
const seconds = Math.floor(written.mtimeMs / 1e3);
|
|
17660
|
-
utimesSync(
|
|
17933
|
+
utimesSync(join40(scratch, name), seconds, seconds);
|
|
17661
17934
|
}
|
|
17662
17935
|
}
|
|
17663
17936
|
}
|
|
17664
17937
|
for (const name of ["refs", "objects"]) {
|
|
17665
|
-
mkdirSync12(
|
|
17666
|
-
if (git.entry(name)) copy(git.directory(name),
|
|
17938
|
+
mkdirSync12(join40(scratch, name), { mode: 448 });
|
|
17939
|
+
if (git.entry(name)) copy(git.directory(name), join40(scratch, name), 0);
|
|
17667
17940
|
}
|
|
17668
17941
|
if (git.list().some((name) => name.startsWith("sharedindex.")))
|
|
17669
17942
|
throw new ContextReadError("unsupported_git_metadata");
|
|
17670
|
-
|
|
17943
|
+
writeFileSync14(join40(scratch, "config"), `${configLines.join("\n")}
|
|
17671
17944
|
`, { mode: 384 });
|
|
17672
17945
|
const validate2 = () => git.validate();
|
|
17673
17946
|
validate2();
|
|
@@ -17680,7 +17953,7 @@ objectformat = ${value}`
|
|
|
17680
17953
|
|
|
17681
17954
|
// ../daemon/src/lib/git-review/authors.ts
|
|
17682
17955
|
import { realpathSync as realpathSync8 } from "node:fs";
|
|
17683
|
-
import { isAbsolute as isAbsolute8, join as
|
|
17956
|
+
import { isAbsolute as isAbsolute8, join as join41, relative as relative5, resolve as resolve8, sep as sep6 } from "node:path";
|
|
17684
17957
|
var FILE_TOOLS = /* @__PURE__ */ new Set(["write", "edit"]);
|
|
17685
17958
|
var CONVERSATIONS_PER_AGENT = 5;
|
|
17686
17959
|
var SANDBOX_ROOT = "/workspace";
|
|
@@ -17705,7 +17978,7 @@ function readChangeAuthors(db, paths, team, changedPaths) {
|
|
|
17705
17978
|
}
|
|
17706
17979
|
const members = list(db, { includeArchived: true }).filter((agent) => agent.teamId === team.id);
|
|
17707
17980
|
for (const agent of members) {
|
|
17708
|
-
const directory =
|
|
17981
|
+
const directory = join41(paths.agentDir(agent.id), "sessions");
|
|
17709
17982
|
const recent = list11(db, agent.id, CONVERSATIONS_PER_AGENT, 0).conversations;
|
|
17710
17983
|
for (const conversation of recent) {
|
|
17711
17984
|
let lines;
|
|
@@ -17751,8 +18024,10 @@ function readChangeAuthors(db, paths, team, changedPaths) {
|
|
|
17751
18024
|
|
|
17752
18025
|
// ../daemon/src/lib/git-review/service.ts
|
|
17753
18026
|
var ReviewUnavailableError = class extends DomainError {
|
|
17754
|
-
|
|
17755
|
-
|
|
18027
|
+
reason;
|
|
18028
|
+
constructor(reason, message) {
|
|
18029
|
+
super(409, message, reason);
|
|
18030
|
+
this.reason = reason;
|
|
17756
18031
|
}
|
|
17757
18032
|
};
|
|
17758
18033
|
function requireTeam(db, paths, teamId) {
|
|
@@ -17795,12 +18070,18 @@ async function withRepository(teamDir, fn) {
|
|
|
17795
18070
|
}
|
|
17796
18071
|
async function readTeamReview(db, paths, teamId, input = {}) {
|
|
17797
18072
|
const team = requireTeam(db, paths, teamId);
|
|
17798
|
-
|
|
17799
|
-
|
|
17800
|
-
|
|
17801
|
-
|
|
17802
|
-
|
|
17803
|
-
|
|
18073
|
+
let changes;
|
|
18074
|
+
try {
|
|
18075
|
+
changes = await withRepository(team.path, async (captured) => {
|
|
18076
|
+
const base = await resolveComparisonBase(captured, input.base ?? "HEAD");
|
|
18077
|
+
const identity2 = await readRepositoryIdentity(captured);
|
|
18078
|
+
const listed = await listChanges(captured, base, identity2, input.limits);
|
|
18079
|
+
return input.patches ? attachPatches(captured, listed, input.limits, input.patchPath) : listed;
|
|
18080
|
+
});
|
|
18081
|
+
} catch (error) {
|
|
18082
|
+
if (!(error instanceof ReviewUnavailableError)) throw error;
|
|
18083
|
+
return { teamId: team.id, unavailable: { code: error.reason, message: error.message } };
|
|
18084
|
+
}
|
|
17804
18085
|
if (!input.authors) return { teamId: team.id, changes };
|
|
17805
18086
|
const changedPaths = changes.changes.map((change) => change.path);
|
|
17806
18087
|
return {
|