vibebook.dev 1.6.18 → 1.6.19
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 +36 -15
- 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.19";
|
|
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
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vibebook.dev",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.19",
|
|
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
|
}
|