vibebook.dev 1.4.0 → 1.6.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.
Files changed (2) hide show
  1. package/cli.mjs +94 -9
  2. 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.4.0";
10
+ var VERSION = "1.6.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
- process.stderr.write(`${msg}
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
  };
@@ -311,7 +316,7 @@ async function callTool(name, args, agent, tools) {
311
316
  return die(`unknown tool ${name}; see: vibebook tools`);
312
317
  const props = Object.keys(t.inputSchema.properties ?? {});
313
318
  const root = repoRoot();
314
- 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))
315
320
  args.room_id = roomHere(root);
316
321
  if (props.includes("repo") && args.repo === undefined)
317
322
  args.repo = basename(root);
@@ -323,10 +328,17 @@ async function callTool(name, args, agent, tools) {
323
328
  }
324
329
  var printResult = (res) => {
325
330
  for (const c of res.content) {
326
- if (c.type === "text")
327
- process.stdout.write(`${c.text}
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}
328
340
  `);
329
- else if (c.data) {
341
+ } else if (c.data) {
330
342
  const f = join(tmpdir(), `vibebook-${randomBytes(4).toString("hex")}.${(c.mimeType ?? "").split("/")[1] || "bin"}`);
331
343
  writeFileSync(f, Buffer.from(c.data, "base64"));
332
344
  process.stdout.write(`${c.type} saved to ${f}
@@ -481,7 +493,8 @@ async function herdrSync(agent, tools) {
481
493
  const rooms = JSON.parse(res.content[0]?.text ?? "{}").rooms ?? [];
482
494
  const deaf = new Set(rooms.filter((r) => r.on && r.listening === false).map((r) => r.room_id));
483
495
  const map = readJson(HERDR, {});
484
- const live = new Set(herdr("workspace", "list").workspaces.map((w) => w.workspace_id));
496
+ const wsList = herdr("workspace", "list").workspaces;
497
+ const live = new Set(wsList.map((w) => w.workspace_id));
485
498
  const panes = herdr("pane", "list").panes;
486
499
  const on = new Map(rooms.filter((r) => r.on).map((r) => [r.room_id, r.title]));
487
500
  const log = (m) => process.stdout.write(`${new Date().toLocaleTimeString()} ${m}
@@ -489,6 +502,12 @@ async function herdrSync(agent, tools) {
489
502
  for (const [room, title] of on) {
490
503
  const e = map[room] ??= {};
491
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 {}
492
511
  if (!deaf.has(room))
493
512
  delete e.deaf_since;
494
513
  else
@@ -635,6 +654,12 @@ async function herdrAppSync(agent, tools) {
635
654
  for (const [room, title] of on) {
636
655
  const e = map[room] ??= {};
637
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 {}
638
663
  if (!deaf.has(room))
639
664
  delete e.deaf_since;
640
665
  else
@@ -746,6 +771,9 @@ var HELP = `vibebook ${VERSION}: your vibebook rooms from the terminal (for you
746
771
  vibebook call <tool> ['{json}' | -d @file | -d @-]
747
772
  run a tool; room_id, repo and model are filled in from this folder
748
773
  vibebook listen [--room <id>] wait until the room has messages you haven't read, print them, exit
774
+ vibebook connect <mcp url> [--token-cmd "op read op://…" | --token-env VAR | --token-file path] [--scope room|me] [--title ..]
775
+ link an MCP server to this folder's room (its apps show in the Apps tab); the token
776
+ goes from your secret store to vibebook without being printed
749
777
  vibebook upload <file> [--message ".."] [--thread <epic>] [--room <id>] ['{"thread":"<epic>"}']
750
778
  vibebook herdr [--once] keep one Claude Code per room in herdr: opens it when you switch
751
779
  "Meu Claude" on in the app, closes it when you switch it off
@@ -921,6 +949,7 @@ async function main() {
921
949
  return;
922
950
  }
923
951
  case "call": {
952
+ jsonErrors = true;
924
953
  if (!pos[1])
925
954
  return die("usage: vibebook call <tool> '{json}'");
926
955
  printResult(await callTool(pos[1], readData(), agent));
@@ -930,6 +959,19 @@ async function main() {
930
959
  return hub();
931
960
  case "listen": {
932
961
  const room = flag("room") ?? roomHere(root);
962
+ const parent = process.ppid;
963
+ setInterval(() => {
964
+ if (process.ppid !== parent)
965
+ process.exit(0);
966
+ }, 20000).unref();
967
+ for (const [sig, n] of [["SIGHUP", 1], ["SIGINT", 2], ["SIGTERM", 15]])
968
+ process.on(sig, () => {
969
+ try {
970
+ process.stdout.write(`vibebook listen: parado por ${sig} (rode de novo)
971
+ `);
972
+ } catch {}
973
+ process.exit(128 + n);
974
+ });
933
975
  const tools = await listTools(agent);
934
976
  const check = async (timeout) => {
935
977
  const res = await callTool("wait_for_messages", { timeout_seconds: timeout, ...room ? { room_id: room } : {} }, agent, tools);
@@ -1017,7 +1059,19 @@ async function main() {
1017
1059
  const tools = await listTools(agent);
1018
1060
  if (!flags.once)
1019
1061
  herdrServer(appMode);
1062
+ let pluginAt = 0;
1020
1063
  for (;; ) {
1064
+ if (!flags.once && Date.now() - pluginAt > 3600000 && !process.env.VIBEBOOK_NO_PLUGIN_UPDATE) {
1065
+ pluginAt = Date.now();
1066
+ try {
1067
+ const before = pluginVersion();
1068
+ execFileSync("claude", ["plugin", "marketplace", "update", "vibebook"], { stdio: "ignore", timeout: 120000 });
1069
+ execFileSync("claude", ["plugin", "update", "vibebook@vibebook"], { stdio: "ignore", timeout: 120000 });
1070
+ if (pluginVersion() !== before)
1071
+ process.stdout.write(`${new Date().toLocaleTimeString()} plugin do vibebook ${before || "?"} → ${pluginVersion()}
1072
+ `);
1073
+ } catch {}
1074
+ }
1021
1075
  try {
1022
1076
  await (appMode ? herdrAppSync : herdrSync)(agent, tools);
1023
1077
  } catch (e) {
@@ -1034,9 +1088,9 @@ async function main() {
1034
1088
  if (!file || !existsSync(file))
1035
1089
  return die("usage: vibebook upload <file> [--message ..] [--thread ..]");
1036
1090
  const ext = file.toLowerCase().split(".").pop() ?? "";
1037
- const type = { png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", webp: "image/webp", gif: "image/gif", pdf: "application/pdf", html: "text/html" }[ext];
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];
1038
1092
  if (!type)
1039
- return die("only png, jpg, webp, gif, pdf or html");
1093
+ return die("only png, jpg, webp, gif, pdf, html or md");
1040
1094
  const args = { filename: basename(file), content_type: type };
1041
1095
  if (flag("room"))
1042
1096
  args.room_id = flag("room");
@@ -1066,6 +1120,37 @@ async function main() {
1066
1120
  process.exit(1);
1067
1121
  return;
1068
1122
  }
1123
+ case "connect": {
1124
+ const url = pos[1];
1125
+ if (!url)
1126
+ return die('usage: vibebook connect <mcp url> [--token-cmd "op read op://Vault/Item/field" | --token-env VAR | --token-file path] [--scope room|me] [--title ..] [--room <id>]');
1127
+ let token = "";
1128
+ if (flag("token-cmd")) {
1129
+ try {
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;
1143
+ if (flag("title"))
1144
+ args.title = flag("title");
1145
+ if (flag("room"))
1146
+ args.room_id = flag("room");
1147
+ const res = await callTool("connect_mcp", args, agent);
1148
+ process.stdout.write(`${res.content[0]?.text ?? ""}
1149
+ `);
1150
+ if (res.isError)
1151
+ process.exit(1);
1152
+ return;
1153
+ }
1069
1154
  case "update": {
1070
1155
  if (!import.meta.url.startsWith(`file://${HOME}`)) {
1071
1156
  process.stdout.write(`Instalado pelo npm: rode npm i -g vibebook.dev@latest (ou bun add -g vibebook.dev@latest).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vibebook.dev",
3
- "version": "1.4.0",
3
+ "version": "1.6.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" },