vibebook.dev 1.0.1 → 1.1.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 +171 -3
- package/package.json +1 -1
package/cli.mjs
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// cli/vibebook.ts
|
|
4
|
-
import { execSync, spawn } from "node:child_process";
|
|
4
|
+
import { execFileSync, execSync, spawn } from "node:child_process";
|
|
5
5
|
import { createHash, randomBytes } from "node:crypto";
|
|
6
|
-
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { appendFileSync, chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
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.0
|
|
10
|
+
var VERSION = "1.1.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
|
+
var HERDR = join(HOME, "herdr.json");
|
|
15
16
|
var die = (msg, code = 1) => {
|
|
16
17
|
process.stderr.write(`${msg}
|
|
17
18
|
`);
|
|
@@ -224,6 +225,152 @@ function readData() {
|
|
|
224
225
|
return die(`arguments must be a JSON object, e.g. '{"room_id":"abc"}' (or -d @file.json, -d @-)`);
|
|
225
226
|
}
|
|
226
227
|
}
|
|
228
|
+
var herdr = (...args) => JSON.parse(execFileSync("herdr", args, { stdio: ["ignore", "pipe", "pipe"] }).toString()).result;
|
|
229
|
+
var PROJECTS = join(homedir(), "Projects");
|
|
230
|
+
var slug = (t) => t.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 40) || "sala";
|
|
231
|
+
function roomFolder(room, title) {
|
|
232
|
+
const look = (dir, depth) => {
|
|
233
|
+
let names = [];
|
|
234
|
+
try {
|
|
235
|
+
names = readdirSync(dir);
|
|
236
|
+
} catch {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (names.includes(".vibebook")) {
|
|
240
|
+
try {
|
|
241
|
+
if (linkedRoom(dir) === room)
|
|
242
|
+
return dir;
|
|
243
|
+
} catch {}
|
|
244
|
+
}
|
|
245
|
+
if (depth === 0)
|
|
246
|
+
return;
|
|
247
|
+
for (const n of names)
|
|
248
|
+
if (!n.startsWith(".") && n !== "node_modules" && n !== "_archive") {
|
|
249
|
+
const f = look(join(dir, n), depth - 1);
|
|
250
|
+
if (f)
|
|
251
|
+
return f;
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
return look(PROJECTS, 2) ?? join(PROJECTS, slug(title));
|
|
255
|
+
}
|
|
256
|
+
function linkFolder(folder, room) {
|
|
257
|
+
mkdirSync(folder, { recursive: true });
|
|
258
|
+
const f = join(folder, ".vibebook");
|
|
259
|
+
try {
|
|
260
|
+
if (linkedRoom(folder) === room)
|
|
261
|
+
return;
|
|
262
|
+
} catch {}
|
|
263
|
+
writeFileSync(f, `room_id=${room}
|
|
264
|
+
`);
|
|
265
|
+
const exclude = join(folder, ".git", "info", "exclude");
|
|
266
|
+
if (existsSync(exclude) && !readFileSync(exclude, "utf8").split(`
|
|
267
|
+
`).includes(".vibebook"))
|
|
268
|
+
appendFileSync(exclude, `
|
|
269
|
+
.vibebook
|
|
270
|
+
`);
|
|
271
|
+
}
|
|
272
|
+
async function herdrSync(agent, tools) {
|
|
273
|
+
const res = await callTool("claude_rooms", {}, agent, tools);
|
|
274
|
+
const rooms = JSON.parse(res.content[0]?.text ?? "{}").rooms ?? [];
|
|
275
|
+
const map = readJson(HERDR, {});
|
|
276
|
+
const live = new Set(herdr("workspace", "list").workspaces.map((w) => w.workspace_id));
|
|
277
|
+
const panes = herdr("pane", "list").panes;
|
|
278
|
+
const on = new Map(rooms.filter((r) => r.on).map((r) => [r.room_id, r.title]));
|
|
279
|
+
const log = (m) => process.stdout.write(`${new Date().toLocaleTimeString()} ${m}
|
|
280
|
+
`);
|
|
281
|
+
for (const [room, title] of on) {
|
|
282
|
+
const e = map[room] ??= {};
|
|
283
|
+
if (e.workspace && live.has(e.workspace))
|
|
284
|
+
continue;
|
|
285
|
+
e.folder ??= roomFolder(room, title);
|
|
286
|
+
linkFolder(e.folder, room);
|
|
287
|
+
const there = panes.find((p) => p.agent === "claude" && (p.cwd === e.folder || p.foreground_cwd === e.folder));
|
|
288
|
+
if (there) {
|
|
289
|
+
e.workspace = there.workspace_id;
|
|
290
|
+
try {
|
|
291
|
+
herdr("workspace", "rename", there.workspace_id, title.slice(0, 40));
|
|
292
|
+
} catch {}
|
|
293
|
+
log(`${title}: adotei o Claude que já estava em ${e.folder}`);
|
|
294
|
+
if (there.agent_status === "idle" || there.agent_status === "done")
|
|
295
|
+
try {
|
|
296
|
+
herdr("agent", "prompt", there.pane_id, "/vibebook:listen");
|
|
297
|
+
} catch {}
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
const w = herdr("workspace", "create", "--cwd", e.folder, "--label", title.slice(0, 40), "--no-focus");
|
|
301
|
+
e.workspace = w.workspace.workspace_id;
|
|
302
|
+
const args = ["agent", "start", `vb-${room}`, "--kind", "claude", "--pane", w.root_pane.pane_id, "--timeout", "60000", "--"];
|
|
303
|
+
if (e.session)
|
|
304
|
+
args.push("--resume", e.session);
|
|
305
|
+
writePrivate(HERDR, map);
|
|
306
|
+
try {
|
|
307
|
+
herdr(...args, "/vibebook:listen");
|
|
308
|
+
log(`${title}: abri um Claude em ${e.folder}${e.session ? " (retomando a conversa)" : ""}`);
|
|
309
|
+
} catch (err) {
|
|
310
|
+
log(`${title}: Claude aberto em ${e.folder}, esperando você confirmar no herdr (${String(err.stderr ?? err).match(/"message":"([^"]+)"/)?.[1] ?? "não ficou pronto"})`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
for (const [room, e] of Object.entries(map)) {
|
|
314
|
+
if (on.has(room) || !e.workspace)
|
|
315
|
+
continue;
|
|
316
|
+
if (live.has(e.workspace)) {
|
|
317
|
+
const p = panes.find((x) => x.workspace_id === e.workspace && x.agent === "claude");
|
|
318
|
+
if (p?.agent_session?.value)
|
|
319
|
+
e.session = p.agent_session.value;
|
|
320
|
+
herdr("workspace", "close", e.workspace);
|
|
321
|
+
log(`${rooms.find((r) => r.room_id === room)?.title ?? room}: Claude desligado, fechei a aba (a conversa fica pra retomar)`);
|
|
322
|
+
}
|
|
323
|
+
delete e.workspace;
|
|
324
|
+
}
|
|
325
|
+
writePrivate(HERDR, map);
|
|
326
|
+
herdrOrder([...on.keys()], map);
|
|
327
|
+
}
|
|
328
|
+
function herdrOrder(order, map) {
|
|
329
|
+
const list = herdr("workspace", "list").workspaces;
|
|
330
|
+
const ours = new Map(order.filter((r) => map[r]?.workspace).map((r) => [map[r].workspace, r]));
|
|
331
|
+
const current = list.filter((w) => ours.has(w.workspace_id)).map((w) => w.workspace_id);
|
|
332
|
+
const desired = order.map((r) => map[r]?.workspace).filter((w) => !!w && current.includes(w));
|
|
333
|
+
let i = 0;
|
|
334
|
+
while (i < desired.length && current[i] === desired[i])
|
|
335
|
+
i++;
|
|
336
|
+
if (i === desired.length)
|
|
337
|
+
return;
|
|
338
|
+
const focused = list.find((w) => w.focused)?.workspace_id;
|
|
339
|
+
let refocus;
|
|
340
|
+
const tabs = herdr("tab", "list").tabs;
|
|
341
|
+
for (const ws of desired.slice(i)) {
|
|
342
|
+
const room = ours.get(ws);
|
|
343
|
+
const panes = herdr("pane", "list").panes.filter((p) => p.workspace_id === ws);
|
|
344
|
+
let newWs;
|
|
345
|
+
const newTab = new Map;
|
|
346
|
+
for (const p of panes) {
|
|
347
|
+
const tabLabel = tabs.find((t) => t.tab_id === p.tab_id)?.label ?? "1";
|
|
348
|
+
let r;
|
|
349
|
+
if (!newWs)
|
|
350
|
+
r = herdr("pane", "move", p.pane_id, "--new-workspace", "--label", list.find((w) => w.workspace_id === ws)?.label ?? room, "--tab-label", tabLabel);
|
|
351
|
+
else if (newTab.has(p.tab_id))
|
|
352
|
+
r = herdr("pane", "move", p.pane_id, "--tab", newTab.get(p.tab_id), "--split", "right", "--no-focus");
|
|
353
|
+
else
|
|
354
|
+
r = herdr("pane", "move", p.pane_id, "--new-tab", "--workspace", newWs, "--label", tabLabel, "--no-focus");
|
|
355
|
+
const moved = r.move_result.pane;
|
|
356
|
+
newWs = moved.workspace_id;
|
|
357
|
+
newTab.set(p.tab_id, moved.tab_id);
|
|
358
|
+
}
|
|
359
|
+
if (newWs) {
|
|
360
|
+
map[room].workspace = newWs;
|
|
361
|
+
if (ws === focused)
|
|
362
|
+
refocus = newWs;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
writePrivate(HERDR, map);
|
|
366
|
+
const back = refocus ?? focused;
|
|
367
|
+
if (back)
|
|
368
|
+
try {
|
|
369
|
+
herdr("workspace", "focus", back);
|
|
370
|
+
} catch {}
|
|
371
|
+
process.stdout.write(`${new Date().toLocaleTimeString()} reordenei ${desired.length - i} workspace(s) na ordem das salas
|
|
372
|
+
`);
|
|
373
|
+
}
|
|
227
374
|
var HELP = `vibebook ${VERSION}: your vibebook rooms from the terminal (for you and your Claude).
|
|
228
375
|
|
|
229
376
|
vibebook login connect this machine (opens the browser; once per machine)
|
|
@@ -235,6 +382,8 @@ var HELP = `vibebook ${VERSION}: your vibebook rooms from the terminal (for you
|
|
|
235
382
|
run a tool; room_id, repo and model are filled in from this folder
|
|
236
383
|
vibebook listen [--room <id>] wait until the room has messages you haven't read, print them, exit
|
|
237
384
|
vibebook upload <file> [--message ".."] [--thread <epic>] [--room <id>]
|
|
385
|
+
vibebook herdr [--once] keep one Claude Code per room in herdr: opens it when you switch
|
|
386
|
+
"Meu Claude" on in the app, closes it when you switch it off
|
|
238
387
|
vibebook update install the latest version
|
|
239
388
|
|
|
240
389
|
Options: --model "Claude Opus 5.5" (or VIBEBOOK_MODEL) names the agent in the room; --origin for a local server.`;
|
|
@@ -301,6 +450,25 @@ async function main() {
|
|
|
301
450
|
}
|
|
302
451
|
}
|
|
303
452
|
}
|
|
453
|
+
case "herdr": {
|
|
454
|
+
try {
|
|
455
|
+
execFileSync("herdr", ["status"], { stdio: "ignore" });
|
|
456
|
+
} catch {
|
|
457
|
+
return die("herdr not found or not running (https://herdr.dev)");
|
|
458
|
+
}
|
|
459
|
+
const tools = await listTools(agent);
|
|
460
|
+
for (;; ) {
|
|
461
|
+
try {
|
|
462
|
+
await herdrSync(agent, tools);
|
|
463
|
+
} catch (e) {
|
|
464
|
+
process.stderr.write(`vibebook herdr: ${String(e?.message ?? e)}
|
|
465
|
+
`);
|
|
466
|
+
}
|
|
467
|
+
if (flags.once)
|
|
468
|
+
return;
|
|
469
|
+
await new Promise((r) => setTimeout(r, 15000));
|
|
470
|
+
}
|
|
471
|
+
}
|
|
304
472
|
case "upload": {
|
|
305
473
|
const file = pos[1];
|
|
306
474
|
if (!file || !existsSync(file))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vibebook.dev",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.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" },
|