vibebook.dev 1.6.0 → 1.6.5
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/cli.mjs +126 -31
- package/package.json +1 -1
package/cli.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { appendFileSync, chmodSync, closeSync, existsSync, fstatSync, mkdirSync,
|
|
|
7
7
|
import { createServer } from "node:http";
|
|
8
8
|
import { homedir, tmpdir } from "node:os";
|
|
9
9
|
import { basename, dirname, join } from "node:path";
|
|
10
|
-
var VERSION = "1.6.
|
|
10
|
+
var VERSION = "1.6.5";
|
|
11
11
|
var HOME = process.env.VIBEBOOK_HOME || join(homedir(), ".vibebook");
|
|
12
12
|
var SESSION = join(HOME, "session.json");
|
|
13
13
|
var AGENTS = join(HOME, "agents.json");
|
|
@@ -281,10 +281,70 @@ var sessionStatus = (sid) => {
|
|
|
281
281
|
const s = readJson(join(STATUS, `${sid}.json`), null);
|
|
282
282
|
return s && Date.now() - s.at < 6 * 3600000 ? s : undefined;
|
|
283
283
|
};
|
|
284
|
+
function codexContext() {
|
|
285
|
+
try {
|
|
286
|
+
const root = join(homedir(), ".codex", "sessions");
|
|
287
|
+
if (!existsSync(root))
|
|
288
|
+
return {};
|
|
289
|
+
const day = (d) => {
|
|
290
|
+
const t = new Date(Date.now() - d * 86400000);
|
|
291
|
+
return join(root, String(t.getFullYear()), String(t.getMonth() + 1).padStart(2, "0"), String(t.getDate()).padStart(2, "0"));
|
|
292
|
+
};
|
|
293
|
+
const files = [day(0), day(1)].filter((d) => existsSync(d)).flatMap((d) => readdirSync(d).filter((f) => f.endsWith(".jsonl")).map((f) => join(d, f))).map((f) => ({ f, m: statSync(f).mtimeMs })).filter((x) => Date.now() - x.m < 15 * 60000).sort((a, b) => b.m - a.m).slice(0, 10);
|
|
294
|
+
const cwd = process.cwd();
|
|
295
|
+
const read = (f, from, n) => {
|
|
296
|
+
const fd = openSync(f, "r");
|
|
297
|
+
const size = fstatSync(fd).size;
|
|
298
|
+
const k = Math.min(size, n);
|
|
299
|
+
const buf = Buffer.alloc(k);
|
|
300
|
+
readSync(fd, buf, 0, k, from === "head" ? 0 : size - k);
|
|
301
|
+
closeSync(fd);
|
|
302
|
+
return buf.toString("utf8");
|
|
303
|
+
};
|
|
304
|
+
for (const { f } of files) {
|
|
305
|
+
let meta;
|
|
306
|
+
try {
|
|
307
|
+
meta = JSON.parse(read(f, "head", 1 << 20).split(`
|
|
308
|
+
`)[0]);
|
|
309
|
+
} catch {
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
const dir = String(meta?.payload?.cwd ?? "");
|
|
313
|
+
if (!dir || cwd !== dir && !cwd.startsWith(dir + "/"))
|
|
314
|
+
continue;
|
|
315
|
+
const lines = read(f, "tail", 2 << 20).split(`
|
|
316
|
+
`);
|
|
317
|
+
for (let i = lines.length - 1;i >= 0; i--) {
|
|
318
|
+
if (!lines[i].includes('"token_count"'))
|
|
319
|
+
continue;
|
|
320
|
+
let p;
|
|
321
|
+
try {
|
|
322
|
+
p = JSON.parse(lines[i])?.payload;
|
|
323
|
+
} catch {
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
const u = p?.info?.last_token_usage, w = Number(p?.info?.model_context_window);
|
|
327
|
+
if (!u || !w)
|
|
328
|
+
continue;
|
|
329
|
+
const h = { "x-vibebook-context": `${Number(u.input_tokens) || 0}/${w}` };
|
|
330
|
+
const limits = {};
|
|
331
|
+
for (const [k, l] of [["five_hour", p.rate_limits?.primary], ["seven_day", p.rate_limits?.secondary]])
|
|
332
|
+
if (typeof l?.used_percent === "number")
|
|
333
|
+
limits[k] = { p: Math.round(l.used_percent), r: Number(l.resets_at) || 0 };
|
|
334
|
+
if (Object.keys(limits).length)
|
|
335
|
+
h["x-vibebook-limits"] = JSON.stringify(limits);
|
|
336
|
+
return h;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
} catch {}
|
|
340
|
+
return {};
|
|
341
|
+
}
|
|
284
342
|
var myContext = () => {
|
|
285
343
|
const sid = process.env.CLAUDE_CODE_SESSION_ID;
|
|
286
|
-
|
|
287
|
-
|
|
344
|
+
if (!sid)
|
|
345
|
+
return codexContext();
|
|
346
|
+
const c = sessionContext(sid);
|
|
347
|
+
if (!c)
|
|
288
348
|
return {};
|
|
289
349
|
const st = sessionStatus(sid);
|
|
290
350
|
const h = { "x-vibebook-context": `${c.tokens}/${st?.window ?? c.window}` };
|
|
@@ -323,6 +383,9 @@ async function callTool(name, args, agent, tools) {
|
|
|
323
383
|
const model = flag("model") ?? process.env.VIBEBOOK_MODEL;
|
|
324
384
|
if (props.includes("model") && args.model === undefined && model)
|
|
325
385
|
args.model = model;
|
|
386
|
+
const host = hostApp();
|
|
387
|
+
if (host && typeof args.model === "string" && !args.model.toLowerCase().includes(host.toLowerCase()))
|
|
388
|
+
args.model = `${host} · ${args.model}`.slice(0, 40);
|
|
326
389
|
const res = await rpc("tools/call", { name, arguments: args }, agent);
|
|
327
390
|
return res;
|
|
328
391
|
}
|
|
@@ -420,6 +483,26 @@ function linkFolder(folder, room) {
|
|
|
420
483
|
.vibebook
|
|
421
484
|
`);
|
|
422
485
|
}
|
|
486
|
+
var hostAppMemo;
|
|
487
|
+
function hostApp() {
|
|
488
|
+
if (hostAppMemo !== undefined)
|
|
489
|
+
return hostAppMemo;
|
|
490
|
+
hostAppMemo = null;
|
|
491
|
+
if (process.platform !== "darwin" && process.platform !== "linux")
|
|
492
|
+
return null;
|
|
493
|
+
try {
|
|
494
|
+
let p = String(process.ppid);
|
|
495
|
+
for (let i = 0;i < 15 && p && p !== "1" && p !== "0"; i++) {
|
|
496
|
+
const [ppid, ...cmd] = execFileSync("ps", ["-o", "ppid=,comm=", "-p", p]).toString().trim().split(/\s+/);
|
|
497
|
+
const name = cmd.join(" ").match(/([^/]+)\.app\/Contents\//)?.[1] ?? cmd.join(" ").split("/").pop() ?? "";
|
|
498
|
+
const hit = /^(Antigravity|agy|Cursor|Windsurf)$/i.exec(name);
|
|
499
|
+
if (hit)
|
|
500
|
+
return hostAppMemo = /^agy$/i.test(hit[1]) ? "Antigravity" : hit[1][0].toUpperCase() + hit[1].slice(1).toLowerCase();
|
|
501
|
+
p = ppid;
|
|
502
|
+
}
|
|
503
|
+
} catch {}
|
|
504
|
+
return null;
|
|
505
|
+
}
|
|
423
506
|
function terminalApp() {
|
|
424
507
|
try {
|
|
425
508
|
for (const pid of execFileSync("pgrep", ["-x", "herdr"]).toString().split(/\s+/).filter(Boolean)) {
|
|
@@ -488,8 +571,22 @@ function herdrServer(appMode = false) {
|
|
|
488
571
|
}).on("error", (e) => process.stderr.write(`vibebook herdr: botão "ir pro Claude" desligado (${e.message})
|
|
489
572
|
`)).listen(port, "127.0.0.1");
|
|
490
573
|
}
|
|
491
|
-
|
|
574
|
+
var roomsCache = null;
|
|
575
|
+
async function claudeRooms(agent, tools) {
|
|
576
|
+
const port = await ensureHub().catch(() => null);
|
|
577
|
+
let gen = -1;
|
|
578
|
+
if (port)
|
|
579
|
+
try {
|
|
580
|
+
gen = (await (await fetch(`http://127.0.0.1:${port}/wait?book=agents&since=-1`)).json()).agents ?? -1;
|
|
581
|
+
} catch {}
|
|
582
|
+
if (roomsCache && gen >= 0 && roomsCache.gen === gen && Date.now() - roomsCache.at < 5 * 60000)
|
|
583
|
+
return roomsCache.res;
|
|
492
584
|
const res = await callTool("claude_rooms", {}, agent, tools);
|
|
585
|
+
roomsCache = { gen, at: Date.now(), res };
|
|
586
|
+
return res;
|
|
587
|
+
}
|
|
588
|
+
async function herdrSync(agent, tools) {
|
|
589
|
+
const res = await claudeRooms(agent, tools);
|
|
493
590
|
const rooms = JSON.parse(res.content[0]?.text ?? "{}").rooms ?? [];
|
|
494
591
|
const deaf = new Set(rooms.filter((r) => r.on && r.listening === false).map((r) => r.room_id));
|
|
495
592
|
const map = readJson(HERDR, {});
|
|
@@ -642,7 +739,7 @@ var happ = (...args) => {
|
|
|
642
739
|
};
|
|
643
740
|
var appClaude = (sp) => sp.tabs.flatMap((t) => t.terminals).find((t) => /claude/i.test(t.app ?? ""));
|
|
644
741
|
async function herdrAppSync(agent, tools) {
|
|
645
|
-
const res = await
|
|
742
|
+
const res = await claudeRooms(agent, tools);
|
|
646
743
|
const rooms = JSON.parse(res.content[0]?.text ?? "{}").rooms ?? [];
|
|
647
744
|
const deaf = new Set(rooms.filter((r) => r.on && r.listening === false).map((r) => r.room_id));
|
|
648
745
|
const map = readJson(HERDR_APP, {});
|
|
@@ -771,9 +868,9 @@ var HELP = `vibebook ${VERSION}: your vibebook rooms from the terminal (for you
|
|
|
771
868
|
vibebook call <tool> ['{json}' | -d @file | -d @-]
|
|
772
869
|
run a tool; room_id, repo and model are filled in from this folder
|
|
773
870
|
vibebook listen [--room <id>] wait until the room has messages you haven't read, print them, exit
|
|
774
|
-
vibebook connect <mcp url> [--
|
|
775
|
-
link an MCP server to this folder's room (its apps show in the Apps tab);
|
|
776
|
-
|
|
871
|
+
vibebook connect <mcp url> [--scope me|room] [--title ..]
|
|
872
|
+
link an MCP server to this folder's room (its apps show in the Apps tab); no token:
|
|
873
|
+
a server that needs a login has each person sign in from the Apps tab
|
|
777
874
|
vibebook upload <file> [--message ".."] [--thread <epic>] [--room <id>] ['{"thread":"<epic>"}']
|
|
778
875
|
vibebook herdr [--once] keep one Claude Code per room in herdr: opens it when you switch
|
|
779
876
|
"Meu Claude" on in the app, closes it when you switch it off
|
|
@@ -811,10 +908,18 @@ async function ensureHub() {
|
|
|
811
908
|
async function hub() {
|
|
812
909
|
if (hubPort())
|
|
813
910
|
return;
|
|
814
|
-
let gen = 0, allGen = 0, lastUse = Date.now(), backoff = 1000;
|
|
911
|
+
let gen = 0, allGen = 0, agentsGen = 0, lastUse = Date.now(), backoff = 1000;
|
|
815
912
|
const books = new Map;
|
|
816
913
|
const waiters = new Set;
|
|
817
|
-
const seen = (book) => book === "*" ? gen : Math.max(books.get(book) ?? 0, allGen);
|
|
914
|
+
const seen = (book) => book === "agents" ? agentsGen : book === "*" ? gen : Math.max(books.get(book) ?? 0, allGen);
|
|
915
|
+
const bumpAgents = () => {
|
|
916
|
+
agentsGen = ++gen;
|
|
917
|
+
for (const w of [...waiters])
|
|
918
|
+
if (w.book === "agents") {
|
|
919
|
+
waiters.delete(w);
|
|
920
|
+
w.done();
|
|
921
|
+
}
|
|
922
|
+
};
|
|
818
923
|
const bump = (book) => {
|
|
819
924
|
gen++;
|
|
820
925
|
if (book)
|
|
@@ -822,7 +927,7 @@ async function hub() {
|
|
|
822
927
|
else
|
|
823
928
|
allGen = gen;
|
|
824
929
|
for (const w of [...waiters])
|
|
825
|
-
if (!book || w.book === "*" || w.book === book) {
|
|
930
|
+
if (w.book !== "agents" && (!book || w.book === "*" || w.book === book)) {
|
|
826
931
|
waiters.delete(w);
|
|
827
932
|
w.done();
|
|
828
933
|
}
|
|
@@ -833,7 +938,7 @@ async function hub() {
|
|
|
833
938
|
const book = u.searchParams.get("book") || "*", since = Number(u.searchParams.get("since") ?? -1);
|
|
834
939
|
const answer = (timeout = false) => {
|
|
835
940
|
res.writeHead(200, { "content-type": "application/json" });
|
|
836
|
-
res.end(JSON.stringify({ gen, timeout }));
|
|
941
|
+
res.end(JSON.stringify({ gen, agents: agentsGen, timeout }));
|
|
837
942
|
};
|
|
838
943
|
if (seen(book) > since)
|
|
839
944
|
return answer();
|
|
@@ -882,6 +987,7 @@ async function hub() {
|
|
|
882
987
|
ws.onopen = () => {
|
|
883
988
|
backoff = 1000;
|
|
884
989
|
bump();
|
|
990
|
+
bumpAgents();
|
|
885
991
|
ping = setInterval(() => {
|
|
886
992
|
try {
|
|
887
993
|
ws.send("ping");
|
|
@@ -893,6 +999,8 @@ async function hub() {
|
|
|
893
999
|
const m = JSON.parse(String(e.data));
|
|
894
1000
|
if (m.t === "me" && m.book)
|
|
895
1001
|
bump(m.book);
|
|
1002
|
+
if (m.t === "agents")
|
|
1003
|
+
bumpAgents();
|
|
896
1004
|
} catch {}
|
|
897
1005
|
};
|
|
898
1006
|
ws.onclose = again;
|
|
@@ -1088,9 +1196,9 @@ async function main() {
|
|
|
1088
1196
|
if (!file || !existsSync(file))
|
|
1089
1197
|
return die("usage: vibebook upload <file> [--message ..] [--thread ..]");
|
|
1090
1198
|
const ext = file.toLowerCase().split(".").pop() ?? "";
|
|
1091
|
-
const type = { png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", webp: "image/webp", gif: "image/gif", pdf: "application/pdf", html: "text/html", md: "text/markdown" }[ext];
|
|
1199
|
+
const type = { png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", webp: "image/webp", gif: "image/gif", pdf: "application/pdf", html: "text/html", md: "text/markdown", txt: "text/plain", csv: "text/csv", m4a: "audio/x-m4a", mp3: "audio/mpeg", wav: "audio/wav", aac: "audio/aac", ogg: "audio/ogg", opus: "audio/ogg", webm: "audio/webm", flac: "audio/flac" }[ext];
|
|
1092
1200
|
if (!type)
|
|
1093
|
-
return die("only png, jpg, webp, gif, pdf, html or
|
|
1201
|
+
return die("only png, jpg, webp, gif, pdf, html, md or audio (m4a, mp3, wav, aac, ogg, webm, flac)");
|
|
1094
1202
|
const args = { filename: basename(file), content_type: type };
|
|
1095
1203
|
if (flag("room"))
|
|
1096
1204
|
args.room_id = flag("room");
|
|
@@ -1123,23 +1231,10 @@ async function main() {
|
|
|
1123
1231
|
case "connect": {
|
|
1124
1232
|
const url = pos[1];
|
|
1125
1233
|
if (!url)
|
|
1126
|
-
return die(
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
token = execSync(flag("token-cmd"), { stdio: ["inherit", "pipe", "inherit"] }).toString().trim();
|
|
1131
|
-
} catch {
|
|
1132
|
-
return die("--token-cmd failed (nothing was sent)");
|
|
1133
|
-
}
|
|
1134
|
-
} else if (flag("token-env"))
|
|
1135
|
-
token = process.env[flag("token-env")] ?? "";
|
|
1136
|
-
else if (flag("token-file"))
|
|
1137
|
-
token = existsSync(flag("token-file")) ? readFileSync(flag("token-file"), "utf8").trim() : "";
|
|
1138
|
-
if ((flag("token-cmd") || flag("token-env") || flag("token-file")) && !token)
|
|
1139
|
-
return die("the token came back empty (nothing was sent)");
|
|
1140
|
-
const args = { url, scope: flag("scope") === "me" ? "me" : "room" };
|
|
1141
|
-
if (token)
|
|
1142
|
-
args.token = token;
|
|
1234
|
+
return die("usage: vibebook connect <mcp url> [--scope room|me] [--title ..] [--room <id>]");
|
|
1235
|
+
if (flag("token-cmd") || flag("token-env") || flag("token-file"))
|
|
1236
|
+
return die("vibebook no longer takes MCP tokens: connect the URL, then each person signs in from the Apps tab (Entrar em <host>). Nothing was sent.");
|
|
1237
|
+
const args = { url, scope: flag("scope") === "room" ? "room" : "me" };
|
|
1143
1238
|
if (flag("title"))
|
|
1144
1239
|
args.title = flag("title");
|
|
1145
1240
|
if (flag("room"))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vibebook.dev",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.5",
|
|
4
4
|
"description": "vibebook CLI: your vibebook rooms from the terminal, for you and your Claude. One login per machine; room tools discovered at run time.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": { "vibebook": "cli.mjs" },
|