vibebook.dev 1.6.18 → 1.6.21
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 +64 -20
- package/package.json +2 -2
package/cli.mjs
CHANGED
|
@@ -5,9 +5,9 @@ import { execFileSync, execSync, spawn } from "node:child_process";
|
|
|
5
5
|
import { createHash, randomBytes } from "node:crypto";
|
|
6
6
|
import { appendFileSync, chmodSync, closeSync, existsSync, fstatSync, mkdirSync, openSync, readdirSync, readFileSync, readSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { createServer } from "node:http";
|
|
8
|
-
import { homedir, tmpdir } from "node:os";
|
|
8
|
+
import { homedir, hostname, tmpdir } from "node:os";
|
|
9
9
|
import { basename, dirname, join } from "node:path";
|
|
10
|
-
var VERSION = "1.6.
|
|
10
|
+
var VERSION = "1.6.21";
|
|
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");
|
|
@@ -592,28 +592,43 @@ function herdrServer(appMode = false) {
|
|
|
592
592
|
}).on("error", (e) => process.stderr.write(`vibebook herdr: botão "ir pro Claude" desligado (${e.message})
|
|
593
593
|
`)).listen(port, "127.0.0.1");
|
|
594
594
|
}
|
|
595
|
+
var MACHINE = join(HOME, "machine.json");
|
|
596
|
+
function machineId() {
|
|
597
|
+
const m = readJson(MACHINE, {});
|
|
598
|
+
if (m.id && /^m_[a-f0-9]{32}$/.test(m.id))
|
|
599
|
+
return m.id;
|
|
600
|
+
const id = `m_${randomBytes(16).toString("hex")}`;
|
|
601
|
+
writePrivate(MACHINE, { id });
|
|
602
|
+
return id;
|
|
603
|
+
}
|
|
604
|
+
var sessionAgent = (session) => `s_${createHash("sha256").update(`claude-code:${session}`).digest("hex").slice(0, 32)}`;
|
|
595
605
|
var roomsCache = null;
|
|
596
|
-
async function claudeRooms(agent, tools) {
|
|
606
|
+
async function claudeRooms(agent, tools, kind = "herdr", managed = []) {
|
|
597
607
|
const port = await ensureHub().catch(() => null);
|
|
598
608
|
let gen = -1;
|
|
599
609
|
if (port)
|
|
600
610
|
try {
|
|
601
611
|
gen = (await (await fetch(`http://127.0.0.1:${port}/wait?book=agents&since=-1`)).json()).agents ?? -1;
|
|
602
612
|
} catch {}
|
|
603
|
-
|
|
613
|
+
const key = [...managed].sort().join(",");
|
|
614
|
+
if (roomsCache && gen >= 0 && roomsCache.gen === gen && roomsCache.key === key && Date.now() - roomsCache.at < 5 * 60000)
|
|
604
615
|
return roomsCache.res;
|
|
605
|
-
const
|
|
606
|
-
|
|
616
|
+
const takes = !!tools.find((t) => t.name === "claude_rooms")?.inputSchema.properties?.machine;
|
|
617
|
+
const args = takes ? { machine: { id: machineId(), name: hostname().replace(/\.local$/, ""), kind }, agents: managed.slice(0, 50) } : {};
|
|
618
|
+
const res = await callTool("claude_rooms", args, agent, tools);
|
|
619
|
+
roomsCache = { gen, at: Date.now(), key, res };
|
|
607
620
|
return res;
|
|
608
621
|
}
|
|
609
622
|
async function herdrSync(agent, tools) {
|
|
610
|
-
const res = await claudeRooms(agent, tools);
|
|
611
|
-
const rooms = JSON.parse(res.content[0]?.text ?? "{}").rooms ?? [];
|
|
612
|
-
const deaf = new Set(rooms.filter((r) => r.on && r.listening === false).map((r) => r.room_id));
|
|
613
623
|
const map = readJson(HERDR, {});
|
|
614
624
|
const wsList = herdr("workspace", "list").workspaces;
|
|
615
625
|
const live = new Set(wsList.map((w) => w.workspace_id));
|
|
616
626
|
const panes = herdr("pane", "list").panes;
|
|
627
|
+
const mapped = new Set(Object.values(map).map((e) => e.workspace).filter(Boolean));
|
|
628
|
+
const managed = panes.filter((p) => p.agent === "claude" && mapped.has(p.workspace_id) && p.agent_session?.value).map((p) => sessionAgent(p.agent_session.value));
|
|
629
|
+
const res = await claudeRooms(agent, tools, "herdr", managed);
|
|
630
|
+
const rooms = JSON.parse(res.content[0]?.text ?? "{}").rooms ?? [];
|
|
631
|
+
const deaf = new Set(rooms.filter((r) => r.on && r.listening === false).map((r) => r.room_id));
|
|
617
632
|
const on = new Map(rooms.filter((r) => r.on).map((r) => [r.room_id, r.title]));
|
|
618
633
|
const log = (m) => process.stdout.write(`${new Date().toLocaleTimeString()} ${m}
|
|
619
634
|
`);
|
|
@@ -736,15 +751,18 @@ async function herdrSync(agent, tools) {
|
|
|
736
751
|
log(`${title}: Claude aberto em ${e.folder}, esperando você confirmar no herdr (${String(err.stderr ?? err).match(/"message":"([^"]+)"/)?.[1] ?? "não ficou pronto"})`);
|
|
737
752
|
}
|
|
738
753
|
}
|
|
754
|
+
const listed = new Set(rooms.map((r) => r.room_id));
|
|
739
755
|
for (const [room, e] of Object.entries(map)) {
|
|
740
756
|
if (on.has(room) || !e.workspace)
|
|
741
757
|
continue;
|
|
758
|
+
const p = panes.find((x) => x.workspace_id === e.workspace && x.agent === "claude");
|
|
759
|
+
if (p?.agent_session?.value)
|
|
760
|
+
e.session = p.agent_session.value;
|
|
761
|
+
if (listed.has(room) && live.has(e.workspace))
|
|
762
|
+
continue;
|
|
742
763
|
if (live.has(e.workspace)) {
|
|
743
|
-
const p = panes.find((x) => x.workspace_id === e.workspace && x.agent === "claude");
|
|
744
|
-
if (p?.agent_session?.value)
|
|
745
|
-
e.session = p.agent_session.value;
|
|
746
764
|
herdr("workspace", "close", e.workspace);
|
|
747
|
-
log(`${
|
|
765
|
+
log(`${room}: a sala saiu da sua lista, fechei a aba (a conversa fica pra retomar)`);
|
|
748
766
|
}
|
|
749
767
|
delete e.workspace;
|
|
750
768
|
}
|
|
@@ -760,7 +778,7 @@ var happ = (...args) => {
|
|
|
760
778
|
};
|
|
761
779
|
var appClaude = (sp) => sp.tabs.flatMap((t) => t.terminals).find((t) => /claude/i.test(t.app ?? ""));
|
|
762
780
|
async function herdrAppSync(agent, tools) {
|
|
763
|
-
const res = await claudeRooms(agent, tools);
|
|
781
|
+
const res = await claudeRooms(agent, tools, "herdr-app");
|
|
764
782
|
const rooms = JSON.parse(res.content[0]?.text ?? "{}").rooms ?? [];
|
|
765
783
|
const deaf = new Set(rooms.filter((r) => r.on && r.listening === false).map((r) => r.room_id));
|
|
766
784
|
const map = readJson(HERDR_APP, {});
|
|
@@ -813,12 +831,15 @@ async function herdrAppSync(agent, tools) {
|
|
|
813
831
|
e.prompted_at = Date.now();
|
|
814
832
|
log(`${title}: abri um Claude em ${e.folder}`);
|
|
815
833
|
}
|
|
834
|
+
const listedApp = new Set(rooms.map((r) => r.room_id));
|
|
816
835
|
for (const [room, e] of Object.entries(map)) {
|
|
817
836
|
if (on.has(room) || !e.space)
|
|
818
837
|
continue;
|
|
838
|
+
if (listedApp.has(room) && live.has(e.space))
|
|
839
|
+
continue;
|
|
819
840
|
if (live.has(e.space)) {
|
|
820
841
|
happ("do", "space.close", "--id", e.space, "--confirmed", "true");
|
|
821
|
-
log(`${
|
|
842
|
+
log(`${room}: a sala saiu da sua lista, fechei o space`);
|
|
822
843
|
}
|
|
823
844
|
delete e.space;
|
|
824
845
|
}
|
|
@@ -901,6 +922,24 @@ var HELP = `vibebook ${VERSION}: your vibebook rooms from the terminal (for you
|
|
|
901
922
|
vibebook update install the latest version
|
|
902
923
|
|
|
903
924
|
Options: --model "Claude Opus 5.5" (or VIBEBOOK_MODEL) names the agent in the room; --origin for a local server.`;
|
|
925
|
+
function hubNotice(raw) {
|
|
926
|
+
let m;
|
|
927
|
+
try {
|
|
928
|
+
m = JSON.parse(raw);
|
|
929
|
+
} catch {
|
|
930
|
+
return null;
|
|
931
|
+
}
|
|
932
|
+
if (!m || typeof m !== "object" || Array.isArray(m))
|
|
933
|
+
return null;
|
|
934
|
+
const o = m;
|
|
935
|
+
if (o.jsonrpc === "2.0") {
|
|
936
|
+
if (typeof o.method !== "string" || "id" in o)
|
|
937
|
+
return null;
|
|
938
|
+
const params = o.params && typeof o.params === "object" && !Array.isArray(o.params) ? o.params : {};
|
|
939
|
+
return { ...params, t: o.method };
|
|
940
|
+
}
|
|
941
|
+
return typeof o.t === "string" ? o : null;
|
|
942
|
+
}
|
|
904
943
|
var HUB = join(HOME, "hub.json");
|
|
905
944
|
var hubPort = () => {
|
|
906
945
|
const h = readJson(HUB, null);
|
|
@@ -994,7 +1033,7 @@ async function hub() {
|
|
|
994
1033
|
let sock = null, ping;
|
|
995
1034
|
const connect = async () => {
|
|
996
1035
|
const s = await session();
|
|
997
|
-
const ws = new WebSocket(`${s.origin.replace(/^http/, "ws")}/mcp`, { headers: { authorization: `Bearer ${s.access_token}` } });
|
|
1036
|
+
const ws = new WebSocket(`${s.origin.replace(/^http/, "ws")}/mcp?wire=jsonrpc`, { headers: { authorization: `Bearer ${s.access_token}` } });
|
|
998
1037
|
sock = ws;
|
|
999
1038
|
let closed = false;
|
|
1000
1039
|
const again = () => {
|
|
@@ -1017,8 +1056,10 @@ async function hub() {
|
|
|
1017
1056
|
};
|
|
1018
1057
|
ws.onmessage = (e) => {
|
|
1019
1058
|
try {
|
|
1020
|
-
const m =
|
|
1021
|
-
if (m
|
|
1059
|
+
const m = hubNotice(String(e.data));
|
|
1060
|
+
if (!m)
|
|
1061
|
+
return;
|
|
1062
|
+
if (m.t === "me" && typeof m.book === "string" && m.book)
|
|
1022
1063
|
bump(m.book);
|
|
1023
1064
|
if (m.t === "agents")
|
|
1024
1065
|
bumpAgents();
|
|
@@ -1207,8 +1248,11 @@ async function main() {
|
|
|
1207
1248
|
happ("ls");
|
|
1208
1249
|
else
|
|
1209
1250
|
execFileSync("herdr", ["status"], { stdio: "ignore" });
|
|
1210
|
-
} catch {
|
|
1211
|
-
|
|
1251
|
+
} catch (e) {
|
|
1252
|
+
if (appMode)
|
|
1253
|
+
return die("Herdr (the desktop app) isn't open, or herdr-app isn't installed (https://herdr.dev)");
|
|
1254
|
+
return die(e.code === "ENOENT" ? `herdr isn't installed. It's the terminal your room Claudes open in. Set everything up with one line:
|
|
1255
|
+
curl -fsSL https://vibebook.dev/setup.sh | sh` : 'herdr isn\'t open. Run `herdr` in a terminal: with the vibebook plugin (herdr plugin install decocms/chat/herdr-plugin) its "vibebook" tab runs this for you.');
|
|
1212
1256
|
}
|
|
1213
1257
|
const lock = join(HOME, "herdr.pid");
|
|
1214
1258
|
const other = Number(existsSync(lock) ? readFileSync(lock, "utf8") : 0);
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vibebook.dev",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.21",
|
|
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" },
|
|
7
7
|
"files": ["cli.mjs"],
|
|
8
8
|
"engines": { "node": ">=18" },
|
|
9
9
|
"homepage": "https://vibebook.dev",
|
|
10
|
-
"repository": { "type": "git", "url": "git+https://github.com/
|
|
10
|
+
"repository": { "type": "git", "url": "git+https://github.com/decocms/chat.git", "directory": "cli" },
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"keywords": ["vibebook", "claude", "agents", "cli"]
|
|
13
13
|
}
|