vibebook.dev 1.2.0 → 1.5.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/cli.mjs +341 -28
- package/package.json +1 -1
package/cli.mjs
CHANGED
|
@@ -7,14 +7,19 @@ 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.
|
|
10
|
+
var VERSION = "1.5.0";
|
|
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");
|
|
14
14
|
var DEFAULT_ORIGIN = "https://vibebook.dev";
|
|
15
15
|
var HERDR = join(HOME, "herdr.json");
|
|
16
|
+
var jsonErrors = false;
|
|
16
17
|
var die = (msg, code = 1) => {
|
|
17
|
-
|
|
18
|
+
if (jsonErrors)
|
|
19
|
+
process.stdout.write(`${JSON.stringify({ ok: false, error: msg })}
|
|
20
|
+
`);
|
|
21
|
+
else
|
|
22
|
+
process.stderr.write(`${msg}
|
|
18
23
|
`);
|
|
19
24
|
process.exit(code);
|
|
20
25
|
};
|
|
@@ -92,10 +97,31 @@ function openBrowser(url) {
|
|
|
92
97
|
spawn(cmd, args, { stdio: "ignore", detached: true }).unref();
|
|
93
98
|
} catch {}
|
|
94
99
|
}
|
|
95
|
-
async function
|
|
100
|
+
async function loginFromFile(path) {
|
|
101
|
+
const f = readJson(path, null);
|
|
102
|
+
if (!f?.code)
|
|
103
|
+
return die(`no login in ${path}`);
|
|
104
|
+
try {
|
|
105
|
+
rmSync(path);
|
|
106
|
+
} catch {}
|
|
107
|
+
await finishLogin(f.origin, f.redirect, f.verifier, "", "", async () => "", { client_id: f.client_id, code: f.code });
|
|
108
|
+
return f.origin;
|
|
109
|
+
}
|
|
110
|
+
async function login(origin, paste = false) {
|
|
96
111
|
const verifier = b64url(randomBytes(32));
|
|
97
112
|
const challenge = b64url(createHash("sha256").update(verifier).digest());
|
|
98
113
|
const state = b64url(randomBytes(16));
|
|
114
|
+
if (paste)
|
|
115
|
+
return finishLogin(origin, `${origin}/oauth/code`, verifier, challenge, state, async (url) => {
|
|
116
|
+
process.stderr.write(`Abra este link no navegador, autorize e cole aqui o código que aparecer:
|
|
117
|
+
|
|
118
|
+
${url}
|
|
119
|
+
|
|
120
|
+
Código: `);
|
|
121
|
+
const line = await new Promise((res) => process.stdin.once("data", (d) => res(String(d))));
|
|
122
|
+
process.stdin.pause();
|
|
123
|
+
return line.trim();
|
|
124
|
+
});
|
|
99
125
|
let resolveCode;
|
|
100
126
|
let rejectCode;
|
|
101
127
|
const got = new Promise((res, rej) => (resolveCode = res, rejectCode = rej));
|
|
@@ -113,7 +139,18 @@ async function login(origin) {
|
|
|
113
139
|
});
|
|
114
140
|
await new Promise((r) => server.listen(0, "127.0.0.1", r));
|
|
115
141
|
const port = server.address().port;
|
|
116
|
-
|
|
142
|
+
return finishLogin(origin, `http://127.0.0.1:${port}/callback`, verifier, challenge, state, async (url) => {
|
|
143
|
+
process.stderr.write(`Abrindo o navegador para conectar. Se não abrir, acesse:
|
|
144
|
+
${url}
|
|
145
|
+
`);
|
|
146
|
+
openBrowser(url);
|
|
147
|
+
const timer = setTimeout(() => rejectCode(new Error("timed out after 5 minutes")), 5 * 60000);
|
|
148
|
+
return got.finally(() => (clearTimeout(timer), server.close()));
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
async function finishLogin(origin, redirect, verifier, challenge, state, getCode, preset) {
|
|
152
|
+
if (preset)
|
|
153
|
+
return exchange(origin, redirect, verifier, preset.client_id, preset.code);
|
|
117
154
|
const reg = await fetch(`${origin}/oauth/register`, {
|
|
118
155
|
method: "POST",
|
|
119
156
|
headers: { "content-type": "application/json" },
|
|
@@ -123,12 +160,12 @@ async function login(origin) {
|
|
|
123
160
|
die(`could not register with ${origin}: ${reg.status} ${await reg.text()}`);
|
|
124
161
|
const { client_id } = await reg.json();
|
|
125
162
|
const url = `${origin}/authorize?${new URLSearchParams({ response_type: "code", client_id, redirect_uri: redirect, code_challenge: challenge, code_challenge_method: "S256", state, scope: "rooms offline_access", resource: `${origin}/mcp` })}`;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
163
|
+
const code = await getCode(url);
|
|
164
|
+
if (!code)
|
|
165
|
+
die("no code");
|
|
166
|
+
return exchange(origin, redirect, verifier, client_id, code);
|
|
167
|
+
}
|
|
168
|
+
async function exchange(origin, redirect, verifier, client_id, code) {
|
|
132
169
|
const tok = await fetch(`${origin}/oauth/token`, {
|
|
133
170
|
method: "POST",
|
|
134
171
|
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
@@ -279,7 +316,7 @@ async function callTool(name, args, agent, tools) {
|
|
|
279
316
|
return die(`unknown tool ${name}; see: vibebook tools`);
|
|
280
317
|
const props = Object.keys(t.inputSchema.properties ?? {});
|
|
281
318
|
const root = repoRoot();
|
|
282
|
-
if (props.includes("room_id") && args.room_id === undefined && roomHere(root))
|
|
319
|
+
if (props.includes("room_id") && args.room_id === undefined && name !== "search" && roomHere(root))
|
|
283
320
|
args.room_id = roomHere(root);
|
|
284
321
|
if (props.includes("repo") && args.repo === undefined)
|
|
285
322
|
args.repo = basename(root);
|
|
@@ -291,10 +328,17 @@ async function callTool(name, args, agent, tools) {
|
|
|
291
328
|
}
|
|
292
329
|
var printResult = (res) => {
|
|
293
330
|
for (const c of res.content) {
|
|
294
|
-
if (c.type === "text")
|
|
295
|
-
|
|
331
|
+
if (c.type === "text") {
|
|
332
|
+
let text = c.text ?? "";
|
|
333
|
+
if (res.isError)
|
|
334
|
+
try {
|
|
335
|
+
JSON.parse(text);
|
|
336
|
+
} catch {
|
|
337
|
+
text = JSON.stringify({ ok: false, error: text });
|
|
338
|
+
}
|
|
339
|
+
process.stdout.write(`${text}
|
|
296
340
|
`);
|
|
297
|
-
else if (c.data) {
|
|
341
|
+
} else if (c.data) {
|
|
298
342
|
const f = join(tmpdir(), `vibebook-${randomBytes(4).toString("hex")}.${(c.mimeType ?? "").split("/")[1] || "bin"}`);
|
|
299
343
|
writeFileSync(f, Buffer.from(c.data, "base64"));
|
|
300
344
|
process.stdout.write(`${c.type} saved to ${f}
|
|
@@ -319,10 +363,22 @@ function readData() {
|
|
|
319
363
|
}
|
|
320
364
|
}
|
|
321
365
|
var COMPACT_AT = Number(process.env.VIBEBOOK_COMPACT_AT) || 0.75;
|
|
366
|
+
function pluginVersion() {
|
|
367
|
+
try {
|
|
368
|
+
const j = JSON.parse(readFileSync(join(homedir(), ".claude", "plugins", "installed_plugins.json"), "utf8"));
|
|
369
|
+
return String((j.plugins ?? j)["vibebook@vibebook"]?.[0]?.version ?? "");
|
|
370
|
+
} catch {
|
|
371
|
+
return "";
|
|
372
|
+
}
|
|
373
|
+
}
|
|
322
374
|
var herdr = (...args) => JSON.parse(execFileSync("herdr", args, { stdio: ["ignore", "pipe", "pipe"] }).toString()).result;
|
|
323
375
|
var PROJECTS = join(homedir(), "Projects");
|
|
324
376
|
var LISTEN_PROMPT = 'Ouça a sala do vibebook desta pasta: rode `vibebook listen --model "<seu modelo>"` em background (Bash run_in_background); quando ele sair, `vibebook call read_room`, aja nas mensagens from_your_human e volte a ouvir. (Com o plugin, é o /vibebook:listen.)';
|
|
325
|
-
var
|
|
377
|
+
var STOP = new Set("a o as os e de da do das dos para pra pro com em no na nos nas um uma por que the of for with and to in on at my our".split(" "));
|
|
378
|
+
var slug = (t) => {
|
|
379
|
+
const words = t.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
|
|
380
|
+
return (words.filter((w) => !STOP.has(w)).slice(0, 3).join("-") || words.slice(0, 3).join("-")).slice(0, 32) || "sala";
|
|
381
|
+
};
|
|
326
382
|
function roomFolder(room, title) {
|
|
327
383
|
const look = (dir, depth) => {
|
|
328
384
|
let names = [];
|
|
@@ -437,7 +493,8 @@ async function herdrSync(agent, tools) {
|
|
|
437
493
|
const rooms = JSON.parse(res.content[0]?.text ?? "{}").rooms ?? [];
|
|
438
494
|
const deaf = new Set(rooms.filter((r) => r.on && r.listening === false).map((r) => r.room_id));
|
|
439
495
|
const map = readJson(HERDR, {});
|
|
440
|
-
const
|
|
496
|
+
const wsList = herdr("workspace", "list").workspaces;
|
|
497
|
+
const live = new Set(wsList.map((w) => w.workspace_id));
|
|
441
498
|
const panes = herdr("pane", "list").panes;
|
|
442
499
|
const on = new Map(rooms.filter((r) => r.on).map((r) => [r.room_id, r.title]));
|
|
443
500
|
const log = (m) => process.stdout.write(`${new Date().toLocaleTimeString()} ${m}
|
|
@@ -445,12 +502,63 @@ async function herdrSync(agent, tools) {
|
|
|
445
502
|
for (const [room, title] of on) {
|
|
446
503
|
const e = map[room] ??= {};
|
|
447
504
|
if (e.workspace && live.has(e.workspace)) {
|
|
505
|
+
const label = wsList.find((w2) => w2.workspace_id === e.workspace)?.label;
|
|
506
|
+
if (label !== undefined && label !== title.slice(0, 40))
|
|
507
|
+
try {
|
|
508
|
+
herdr("workspace", "rename", e.workspace, title.slice(0, 40));
|
|
509
|
+
log(`${label} → ${title}: renomeei a aba`);
|
|
510
|
+
} catch {}
|
|
448
511
|
if (!deaf.has(room))
|
|
449
512
|
delete e.deaf_since;
|
|
450
513
|
else
|
|
451
514
|
e.deaf_since ??= Date.now();
|
|
452
515
|
if (e.listening && e.deaf_since && Date.now() - e.deaf_since > 3 * 60000 && Date.now() - (e.prompted_at ?? 0) > 5 * 60000)
|
|
453
516
|
e.listening = false;
|
|
517
|
+
const inWs = panes.filter((x) => x.workspace_id === e.workspace);
|
|
518
|
+
if (inWs.length && !inWs.some((x) => x.agent === "claude") && Date.now() - (e.prompted_at ?? 0) > 2 * 60000) {
|
|
519
|
+
e.prompted_at = Date.now();
|
|
520
|
+
e.listening = true;
|
|
521
|
+
e.plugin_v = pluginVersion();
|
|
522
|
+
const updating = !!e.restarting_at;
|
|
523
|
+
delete e.deaf_since;
|
|
524
|
+
delete e.restarting_at;
|
|
525
|
+
writePrivate(HERDR, map);
|
|
526
|
+
if (updating)
|
|
527
|
+
log(`${title}: reabrindo o Claude com o plugin ${e.plugin_v} (mesma conversa)`);
|
|
528
|
+
try {
|
|
529
|
+
herdr("agent", "start", `vb-${room}`, "--kind", "claude", "--pane", inWs[0].pane_id, "--timeout", "15000", "--", ...e.session ? ["--resume", e.session] : [], "/vibebook:listen");
|
|
530
|
+
log(`${title}: o Claude tinha fechado, abri outro em ${e.folder ?? "sua pasta"}`);
|
|
531
|
+
} catch (err) {
|
|
532
|
+
const m = err.message;
|
|
533
|
+
log(/timed out waiting for agent startup/.test(m) ? `${title}: o Claude tinha fechado, abrindo outro (demorou pra subir)` : `${title}: o Claude tinha fechado e não consegui abrir outro (${m.slice(0, 120)})`);
|
|
534
|
+
}
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
537
|
+
const pv = pluginVersion();
|
|
538
|
+
const live0 = inWs.find((x) => x.agent === "claude");
|
|
539
|
+
if (e.restarting_at && live0 && live0.agent_status === "blocked") {
|
|
540
|
+
try {
|
|
541
|
+
const shown = execFileSync("herdr", ["pane", "read", live0.pane_id, "--source", "visible", "--lines", "15"], { stdio: ["ignore", "pipe", "pipe"] }).toString();
|
|
542
|
+
if (/Background work is running/.test(shown))
|
|
543
|
+
herdr("agent", "send-keys", live0.pane_id, "Enter");
|
|
544
|
+
} catch {}
|
|
545
|
+
}
|
|
546
|
+
if (e.restarting_at && live0 && Date.now() - e.restarting_at > 5 * 60000) {
|
|
547
|
+
delete e.restarting_at;
|
|
548
|
+
e.plugin_v = pv;
|
|
549
|
+
log(`${title}: não consegui reabrir o Claude pra atualizar o plugin; fica pra quando ele reabrir`);
|
|
550
|
+
}
|
|
551
|
+
if (pv && live0 && e.plugin_v !== pv && !e.restarting_at && (live0.agent_status === "idle" || live0.agent_status === "done") && live0.agent_session?.value) {
|
|
552
|
+
e.session = live0.agent_session.value;
|
|
553
|
+
e.restarting_at = Date.now();
|
|
554
|
+
e.prompted_at = 0;
|
|
555
|
+
writePrivate(HERDR, map);
|
|
556
|
+
try {
|
|
557
|
+
herdr("agent", "prompt", live0.pane_id, "/exit");
|
|
558
|
+
log(`${title}: plugin do vibebook atualizado (${e.plugin_v ?? "?"} → ${pv}); fechei o Claude livre pra reabrir com a mesma conversa`);
|
|
559
|
+
} catch {}
|
|
560
|
+
continue;
|
|
561
|
+
}
|
|
454
562
|
const cp = panes.find((x) => x.workspace_id === e.workspace && x.agent === "claude");
|
|
455
563
|
const cs = cp?.agent_session?.value;
|
|
456
564
|
const cx0 = cs ? sessionContext(cs) : undefined;
|
|
@@ -500,6 +608,7 @@ async function herdrSync(agent, tools) {
|
|
|
500
608
|
if (e.session)
|
|
501
609
|
args.push("--resume", e.session);
|
|
502
610
|
e.listening = true;
|
|
611
|
+
e.plugin_v = pluginVersion();
|
|
503
612
|
e.prompted_at = Date.now();
|
|
504
613
|
writePrivate(HERDR, map);
|
|
505
614
|
try {
|
|
@@ -545,6 +654,12 @@ async function herdrAppSync(agent, tools) {
|
|
|
545
654
|
for (const [room, title] of on) {
|
|
546
655
|
const e = map[room] ??= {};
|
|
547
656
|
if (e.space && live.has(e.space)) {
|
|
657
|
+
const name = spaces.find((x) => x.id === e.space)?.name;
|
|
658
|
+
if (name !== undefined && name !== title.slice(0, 40))
|
|
659
|
+
try {
|
|
660
|
+
happ("do", "space.rename", "--id", e.space, "--name", title.slice(0, 40));
|
|
661
|
+
log(`${name} → ${title}: renomeei o space`);
|
|
662
|
+
} catch {}
|
|
548
663
|
if (!deaf.has(room))
|
|
549
664
|
delete e.deaf_since;
|
|
550
665
|
else
|
|
@@ -656,7 +771,7 @@ var HELP = `vibebook ${VERSION}: your vibebook rooms from the terminal (for you
|
|
|
656
771
|
vibebook call <tool> ['{json}' | -d @file | -d @-]
|
|
657
772
|
run a tool; room_id, repo and model are filled in from this folder
|
|
658
773
|
vibebook listen [--room <id>] wait until the room has messages you haven't read, print them, exit
|
|
659
|
-
vibebook upload <file> [--message ".."] [--thread <epic>] [--room <id>]
|
|
774
|
+
vibebook upload <file> [--message ".."] [--thread <epic>] [--room <id>] ['{"thread":"<epic>"}']
|
|
660
775
|
vibebook herdr [--once] keep one Claude Code per room in herdr: opens it when you switch
|
|
661
776
|
"Meu Claude" on in the app, closes it when you switch it off
|
|
662
777
|
vibebook herdr --app the same in the Herdr desktop app: one space per room (not with the terminal one)
|
|
@@ -665,6 +780,123 @@ var HELP = `vibebook ${VERSION}: your vibebook rooms from the terminal (for you
|
|
|
665
780
|
vibebook update install the latest version
|
|
666
781
|
|
|
667
782
|
Options: --model "Claude Opus 5.5" (or VIBEBOOK_MODEL) names the agent in the room; --origin for a local server.`;
|
|
783
|
+
var HUB = join(HOME, "hub.json");
|
|
784
|
+
var hubPort = () => {
|
|
785
|
+
const h = readJson(HUB, null);
|
|
786
|
+
if (!h)
|
|
787
|
+
return null;
|
|
788
|
+
try {
|
|
789
|
+
process.kill(h.pid, 0);
|
|
790
|
+
return h.port;
|
|
791
|
+
} catch {
|
|
792
|
+
return null;
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
async function ensureHub() {
|
|
796
|
+
if (typeof WebSocket === "undefined" || process.env.VIBEBOOK_NO_HUB)
|
|
797
|
+
return null;
|
|
798
|
+
let port = hubPort();
|
|
799
|
+
if (port)
|
|
800
|
+
return port;
|
|
801
|
+
spawn(process.execPath, [process.argv[1], "hub"], { detached: true, stdio: "ignore", env: process.env }).unref();
|
|
802
|
+
for (let i = 0;i < 50 && !port; i++) {
|
|
803
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
804
|
+
port = hubPort();
|
|
805
|
+
}
|
|
806
|
+
return port;
|
|
807
|
+
}
|
|
808
|
+
async function hub() {
|
|
809
|
+
if (hubPort())
|
|
810
|
+
return;
|
|
811
|
+
let gen = 0, allGen = 0, lastUse = Date.now(), backoff = 1000;
|
|
812
|
+
const books = new Map;
|
|
813
|
+
const waiters = new Set;
|
|
814
|
+
const seen = (book) => book === "*" ? gen : Math.max(books.get(book) ?? 0, allGen);
|
|
815
|
+
const bump = (book) => {
|
|
816
|
+
gen++;
|
|
817
|
+
if (book)
|
|
818
|
+
books.set(book, gen);
|
|
819
|
+
else
|
|
820
|
+
allGen = gen;
|
|
821
|
+
for (const w of [...waiters])
|
|
822
|
+
if (!book || w.book === "*" || w.book === book) {
|
|
823
|
+
waiters.delete(w);
|
|
824
|
+
w.done();
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
const server = createServer((req, res) => {
|
|
828
|
+
lastUse = Date.now();
|
|
829
|
+
const u = new URL(req.url ?? "/", "http://hub");
|
|
830
|
+
const book = u.searchParams.get("book") || "*", since = Number(u.searchParams.get("since") ?? -1);
|
|
831
|
+
const answer = (timeout = false) => {
|
|
832
|
+
res.writeHead(200, { "content-type": "application/json" });
|
|
833
|
+
res.end(JSON.stringify({ gen, timeout }));
|
|
834
|
+
};
|
|
835
|
+
if (seen(book) > since)
|
|
836
|
+
return answer();
|
|
837
|
+
const w = { book, done: () => {
|
|
838
|
+
clearTimeout(timer);
|
|
839
|
+
answer();
|
|
840
|
+
} };
|
|
841
|
+
const timer = setTimeout(() => {
|
|
842
|
+
waiters.delete(w);
|
|
843
|
+
answer(true);
|
|
844
|
+
}, 50000);
|
|
845
|
+
waiters.add(w);
|
|
846
|
+
req.on("close", () => {
|
|
847
|
+
if (waiters.delete(w))
|
|
848
|
+
clearTimeout(timer);
|
|
849
|
+
});
|
|
850
|
+
});
|
|
851
|
+
await new Promise((r) => server.listen(0, "127.0.0.1", r));
|
|
852
|
+
writePrivate(HUB, { pid: process.pid, port: server.address().port });
|
|
853
|
+
const quit = () => {
|
|
854
|
+
try {
|
|
855
|
+
if (readJson(HUB, null)?.pid === process.pid)
|
|
856
|
+
unlinkSync(HUB);
|
|
857
|
+
} catch {}
|
|
858
|
+
process.exit(0);
|
|
859
|
+
};
|
|
860
|
+
process.on("SIGTERM", quit).on("SIGINT", quit);
|
|
861
|
+
setInterval(() => {
|
|
862
|
+
if (!waiters.size && Date.now() - lastUse > 15 * 60000)
|
|
863
|
+
quit();
|
|
864
|
+
}, 60000);
|
|
865
|
+
let sock = null, ping;
|
|
866
|
+
const connect = async () => {
|
|
867
|
+
const s = await session();
|
|
868
|
+
const ws = new WebSocket(`${s.origin.replace(/^http/, "ws")}/mcp`, { headers: { authorization: `Bearer ${s.access_token}` } });
|
|
869
|
+
sock = ws;
|
|
870
|
+
let closed = false;
|
|
871
|
+
const again = () => {
|
|
872
|
+
if (closed)
|
|
873
|
+
return;
|
|
874
|
+
closed = true;
|
|
875
|
+
clearInterval(ping);
|
|
876
|
+
setTimeout(() => connect().catch(again), backoff);
|
|
877
|
+
backoff = Math.min(backoff * 2, 60000);
|
|
878
|
+
};
|
|
879
|
+
ws.onopen = () => {
|
|
880
|
+
backoff = 1000;
|
|
881
|
+
bump();
|
|
882
|
+
ping = setInterval(() => {
|
|
883
|
+
try {
|
|
884
|
+
ws.send("ping");
|
|
885
|
+
} catch {}
|
|
886
|
+
}, 45000);
|
|
887
|
+
};
|
|
888
|
+
ws.onmessage = (e) => {
|
|
889
|
+
try {
|
|
890
|
+
const m = JSON.parse(String(e.data));
|
|
891
|
+
if (m.t === "me" && m.book)
|
|
892
|
+
bump(m.book);
|
|
893
|
+
} catch {}
|
|
894
|
+
};
|
|
895
|
+
ws.onclose = again;
|
|
896
|
+
ws.onerror = again;
|
|
897
|
+
};
|
|
898
|
+
await connect().catch(() => setTimeout(() => connect().catch(() => {}), backoff));
|
|
899
|
+
}
|
|
668
900
|
async function main() {
|
|
669
901
|
const cmd = flags.version ? "version" : pos[0];
|
|
670
902
|
if (cmd === "statusline")
|
|
@@ -674,7 +906,14 @@ async function main() {
|
|
|
674
906
|
switch (cmd) {
|
|
675
907
|
case "login": {
|
|
676
908
|
const origin = (flag("origin") ?? DEFAULT_ORIGIN).replace(/\/$/, "");
|
|
677
|
-
|
|
909
|
+
const file = flag("code-file");
|
|
910
|
+
if (file) {
|
|
911
|
+
const o = await loginFromFile(file);
|
|
912
|
+
process.stdout.write(`Conectado a ${o}.
|
|
913
|
+
`);
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
await login(origin, !!flags.paste);
|
|
678
917
|
process.stdout.write(`Conectado a ${origin}. Toda sessão do Claude nesta máquina usa este login.
|
|
679
918
|
`);
|
|
680
919
|
return;
|
|
@@ -707,25 +946,76 @@ async function main() {
|
|
|
707
946
|
return;
|
|
708
947
|
}
|
|
709
948
|
case "call": {
|
|
949
|
+
jsonErrors = true;
|
|
710
950
|
if (!pos[1])
|
|
711
951
|
return die("usage: vibebook call <tool> '{json}'");
|
|
712
952
|
printResult(await callTool(pos[1], readData(), agent));
|
|
713
953
|
return;
|
|
714
954
|
}
|
|
955
|
+
case "hub":
|
|
956
|
+
return hub();
|
|
715
957
|
case "listen": {
|
|
716
958
|
const room = flag("room") ?? roomHere(root);
|
|
959
|
+
const parent = process.ppid;
|
|
960
|
+
setInterval(() => {
|
|
961
|
+
if (process.ppid !== parent)
|
|
962
|
+
process.exit(0);
|
|
963
|
+
}, 20000).unref();
|
|
964
|
+
for (const [sig, n] of [["SIGHUP", 1], ["SIGINT", 2], ["SIGTERM", 15]])
|
|
965
|
+
process.on(sig, () => {
|
|
966
|
+
try {
|
|
967
|
+
process.stdout.write(`vibebook listen: parado por ${sig} (rode de novo)
|
|
968
|
+
`);
|
|
969
|
+
} catch {}
|
|
970
|
+
process.exit(128 + n);
|
|
971
|
+
});
|
|
717
972
|
const tools = await listTools(agent);
|
|
973
|
+
const check = async (timeout) => {
|
|
974
|
+
const res = await callTool("wait_for_messages", { timeout_seconds: timeout, ...room ? { room_id: room } : {} }, agent, tools);
|
|
975
|
+
const out = JSON.parse(res.content[0]?.text ?? "{}");
|
|
976
|
+
if (out.stalled?.length) {
|
|
977
|
+
const one = (t) => (t ?? "").replace(/[\p{Cc}"`]/gu, " ").replace(/\s+/g, " ").trim().slice(0, 80);
|
|
978
|
+
process.stdout.write(`vibebook: tarefas suas paradas (${out.stalled.length}). ${(out.next ?? "").replace(/[\p{Cc}`]/gu, " ").slice(0, 700)}
|
|
979
|
+
`);
|
|
980
|
+
for (const s of out.stalled)
|
|
981
|
+
process.stdout.write(`- room_id=${s.room_id} épico "${one(s.epic)}": ${one(s.task)} (${s.status})
|
|
982
|
+
`);
|
|
983
|
+
return true;
|
|
984
|
+
}
|
|
985
|
+
if (out.new?.length) {
|
|
986
|
+
const title = (t) => (t ?? "").replace(/[\p{Cc}"`]/gu, " ").replace(/\s+/g, " ").trim().slice(0, 60);
|
|
987
|
+
for (const r of out.new)
|
|
988
|
+
process.stdout.write(`vibebook: ${r.new_messages} nova(s) em "${title(r.title)}" room_id=${r.room_id}
|
|
989
|
+
`);
|
|
990
|
+
return true;
|
|
991
|
+
}
|
|
992
|
+
return false;
|
|
993
|
+
};
|
|
994
|
+
const port = await ensureHub();
|
|
995
|
+
if (port) {
|
|
996
|
+
const wait = async (since) => await (await fetch(`http://127.0.0.1:${port}/wait?book=${room ?? "*"}&since=${since}`)).json();
|
|
997
|
+
try {
|
|
998
|
+
let since = (await wait(-1)).gen, last = 0, woke = true;
|
|
999
|
+
for (;; ) {
|
|
1000
|
+
if (woke || Date.now() - last > 10 * 60000) {
|
|
1001
|
+
try {
|
|
1002
|
+
if (await check(0))
|
|
1003
|
+
return;
|
|
1004
|
+
} catch {
|
|
1005
|
+
await new Promise((r2) => setTimeout(r2, 15000));
|
|
1006
|
+
}
|
|
1007
|
+
last = Date.now();
|
|
1008
|
+
}
|
|
1009
|
+
const r = await wait(since);
|
|
1010
|
+
woke = !r.timeout && r.gen > since;
|
|
1011
|
+
since = r.gen;
|
|
1012
|
+
}
|
|
1013
|
+
} catch {}
|
|
1014
|
+
}
|
|
718
1015
|
for (;; ) {
|
|
719
1016
|
try {
|
|
720
|
-
|
|
721
|
-
const out = JSON.parse(res.content[0]?.text ?? "{}");
|
|
722
|
-
if (out.new?.length) {
|
|
723
|
-
const title = (t) => (t ?? "").replace(/[\p{Cc}"`]/gu, " ").replace(/\s+/g, " ").trim().slice(0, 60);
|
|
724
|
-
for (const r of out.new)
|
|
725
|
-
process.stdout.write(`vibebook: ${r.new_messages} nova(s) em "${title(r.title)}" room_id=${r.room_id}
|
|
726
|
-
`);
|
|
1017
|
+
if (await check(50))
|
|
727
1018
|
return;
|
|
728
|
-
}
|
|
729
1019
|
} catch (e) {
|
|
730
1020
|
await new Promise((r) => setTimeout(r, 15000));
|
|
731
1021
|
}
|
|
@@ -766,7 +1056,19 @@ async function main() {
|
|
|
766
1056
|
const tools = await listTools(agent);
|
|
767
1057
|
if (!flags.once)
|
|
768
1058
|
herdrServer(appMode);
|
|
1059
|
+
let pluginAt = 0;
|
|
769
1060
|
for (;; ) {
|
|
1061
|
+
if (!flags.once && Date.now() - pluginAt > 3600000 && !process.env.VIBEBOOK_NO_PLUGIN_UPDATE) {
|
|
1062
|
+
pluginAt = Date.now();
|
|
1063
|
+
try {
|
|
1064
|
+
const before = pluginVersion();
|
|
1065
|
+
execFileSync("claude", ["plugin", "marketplace", "update", "vibebook"], { stdio: "ignore", timeout: 120000 });
|
|
1066
|
+
execFileSync("claude", ["plugin", "update", "vibebook@vibebook"], { stdio: "ignore", timeout: 120000 });
|
|
1067
|
+
if (pluginVersion() !== before)
|
|
1068
|
+
process.stdout.write(`${new Date().toLocaleTimeString()} plugin do vibebook ${before || "?"} → ${pluginVersion()}
|
|
1069
|
+
`);
|
|
1070
|
+
} catch {}
|
|
1071
|
+
}
|
|
770
1072
|
try {
|
|
771
1073
|
await (appMode ? herdrAppSync : herdrSync)(agent, tools);
|
|
772
1074
|
} catch (e) {
|
|
@@ -783,9 +1085,9 @@ async function main() {
|
|
|
783
1085
|
if (!file || !existsSync(file))
|
|
784
1086
|
return die("usage: vibebook upload <file> [--message ..] [--thread ..]");
|
|
785
1087
|
const ext = file.toLowerCase().split(".").pop() ?? "";
|
|
786
|
-
const type = { png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", webp: "image/webp", gif: "image/gif", pdf: "application/pdf", html: "text/html" }[ext];
|
|
1088
|
+
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];
|
|
787
1089
|
if (!type)
|
|
788
|
-
return die("only png, jpg, webp, gif, pdf or
|
|
1090
|
+
return die("only png, jpg, webp, gif, pdf, html or md");
|
|
789
1091
|
const args = { filename: basename(file), content_type: type };
|
|
790
1092
|
if (flag("room"))
|
|
791
1093
|
args.room_id = flag("room");
|
|
@@ -793,6 +1095,17 @@ async function main() {
|
|
|
793
1095
|
args.message = flag("message");
|
|
794
1096
|
if (flag("thread"))
|
|
795
1097
|
args.thread = flag("thread");
|
|
1098
|
+
if (pos[2]) {
|
|
1099
|
+
let j;
|
|
1100
|
+
try {
|
|
1101
|
+
j = JSON.parse(pos[2]);
|
|
1102
|
+
} catch {
|
|
1103
|
+
return die(`not JSON: ${pos[2]}`);
|
|
1104
|
+
}
|
|
1105
|
+
for (const k of ["thread", "message", "room_id"])
|
|
1106
|
+
if (j[k] != null)
|
|
1107
|
+
args[k] = j[k];
|
|
1108
|
+
}
|
|
796
1109
|
const res = await callTool("upload_link", args, agent);
|
|
797
1110
|
const link = JSON.parse(res.content[0]?.text ?? "{}");
|
|
798
1111
|
if (!link.url)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vibebook.dev",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
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" },
|