viberealm 0.0.0-stage → 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BinaryBears LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,44 @@
1
- # Temporary Holding Version
1
+ # viberealm
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The installer for [VibeRealm](https://viberealm.dev) — a pixel-art social plaza
4
+ you hang out in while your AI coding agent works.
5
+
6
+ This package registers a small hook with the coding agents on your machine
7
+ (Claude Code, OpenAI Codex, Google Antigravity). The hook tells VibeRealm three
8
+ things: your agent started working, it finished, or it needs your input. While
9
+ it works, your builder in the plaza shows a little bot circling it, and you get
10
+ a macOS notification inviting you in.
11
+
12
+ **The hook never sends code, prompts, file names or file contents.** It only
13
+ reports agent status.
14
+
15
+ ## Install
16
+
17
+ ```
18
+ npx viberealm init --handle <your-handle>
19
+ ```
20
+
21
+ Then add the private hook key shown in the game (player card → "Connect agent")
22
+ to `~/.viberealm/config.json` as `"hookToken"`.
23
+
24
+ Full instructions for you or your agent: https://viberealm.dev/install.md
25
+
26
+ ## What it changes
27
+
28
+ Depending on which agents you have installed:
29
+
30
+ - `~/.claude/settings.json`
31
+ - `~/.codex/hooks.json`
32
+ - `~/.gemini/config/hooks.json`
33
+ - `~/.viberealm/` (new folder: hook script + config)
34
+
35
+ ## Uninstall
36
+
37
+ Delete the entries mentioning `viberealm/hook.mjs` from the config files above,
38
+ then delete `~/.viberealm/`.
39
+
40
+ ## Requirements
41
+
42
+ macOS or Linux, Node.js 18+. Desktop notifications are macOS-only for now.
43
+
44
+ Part of the VibeRealm project: https://github.com/BinaryBearsLLC/viberealm
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env node
2
+ import fs from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
+ const home = os.homedir();
9
+ const configDir = path.join(home, ".viberealm");
10
+ const hookDest = path.join(configDir, "hook.mjs");
11
+ const configPath = path.join(configDir, "config.json");
12
+
13
+ function readJsonSafe(filePath) {
14
+ if (!fs.existsSync(filePath)) return {};
15
+ try {
16
+ return JSON.parse(fs.readFileSync(filePath, "utf8"));
17
+ } catch (err) {
18
+ console.error(`[VibeRealm] Refusing to overwrite invalid JSON in ${filePath}: ${err.message}`);
19
+ return null;
20
+ }
21
+ }
22
+
23
+ function writeJsonSafe(filePath, obj) {
24
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
25
+ fs.writeFileSync(filePath, JSON.stringify(obj, null, 2) + "\n", "utf8");
26
+ }
27
+
28
+ function parseArgs(argv) {
29
+ const args = { cmd: argv[2] ?? "init", handle: os.userInfo().username, serverUrl: "https://viberealm.dev" };
30
+ for (let i = 3; i < argv.length; i++) {
31
+ if (argv[i] === "--handle" && argv[i + 1]) args.handle = argv[++i];
32
+ if (argv[i] === "--server" && argv[i + 1]) args.serverUrl = argv[++i];
33
+ }
34
+ return args;
35
+ }
36
+
37
+ function installClaudeHook(hookCmd) {
38
+ const settingsPath = path.join(home, ".claude", "settings.json");
39
+ if (!fs.existsSync(path.join(home, ".claude"))) return false;
40
+ const cfg = readJsonSafe(settingsPath);
41
+ if (!cfg) return false;
42
+ cfg.hooks = cfg.hooks || {};
43
+
44
+ const events = [
45
+ ["UserPromptSubmit", `${hookCmd} claude working`],
46
+ ["Stop", `${hookCmd} claude idle`],
47
+ ["Notification", `${hookCmd} claude needs_input`],
48
+ ];
49
+
50
+ for (const [ev, command] of events) {
51
+ // Remove legacy prototype entries that were mistakenly written as top-level event keys.
52
+ if (Array.isArray(cfg[ev])) {
53
+ cfg[ev] = cfg[ev].filter((entry) => !JSON.stringify(entry).includes("viberealm/hook.mjs"));
54
+ if (cfg[ev].length === 0) delete cfg[ev];
55
+ }
56
+ cfg.hooks[ev] = Array.isArray(cfg.hooks[ev]) ? cfg.hooks[ev] : [];
57
+ const already = cfg.hooks[ev].some((entry) => JSON.stringify(entry).includes("viberealm/hook.mjs"));
58
+ if (!already) {
59
+ cfg.hooks[ev].push({
60
+ matcher: "",
61
+ hooks: [{ type: "command", command }],
62
+ });
63
+ }
64
+ }
65
+ writeJsonSafe(settingsPath, cfg);
66
+ return true;
67
+ }
68
+
69
+ function installCodexHook(hookCmd) {
70
+ const codexDir = path.join(home, ".codex");
71
+ if (!fs.existsSync(codexDir)) return false;
72
+ const hooksPath = path.join(codexDir, "hooks.json");
73
+ const cfg = readJsonSafe(hooksPath);
74
+ if (!cfg) return false;
75
+ cfg.hooks = cfg.hooks || {};
76
+ const events = [
77
+ ["UserPromptSubmit", `${hookCmd} codex working`],
78
+ ["Stop", `${hookCmd} codex idle`],
79
+ ["PermissionRequest", `${hookCmd} codex needs_input`],
80
+ ];
81
+ for (const [ev, command] of events) {
82
+ cfg.hooks[ev] = Array.isArray(cfg.hooks[ev]) ? cfg.hooks[ev] : [];
83
+ const already = cfg.hooks[ev].some((entry) => JSON.stringify(entry).includes("viberealm/hook.mjs"));
84
+ if (!already) {
85
+ cfg.hooks[ev].push({
86
+ hooks: [{ type: "command", command }],
87
+ });
88
+ }
89
+ }
90
+ writeJsonSafe(hooksPath, cfg);
91
+ return true;
92
+ }
93
+
94
+ function installAntigravityHook(hookCmd) {
95
+ const geminiDir = path.join(home, ".gemini");
96
+ if (!fs.existsSync(geminiDir)) return false;
97
+ const hooksPath = path.join(geminiDir, "config", "hooks.json");
98
+ const cfg = readJsonSafe(hooksPath);
99
+ if (!cfg) return false;
100
+ cfg["viberealm-plaza"] = {
101
+ enabled: true,
102
+ PreInvocation: [{ type: "command", command: `${hookCmd} antigravity working` }],
103
+ PostInvocation: [{ type: "command", command: `${hookCmd} antigravity idle` }],
104
+ };
105
+ writeJsonSafe(hooksPath, cfg);
106
+ return true;
107
+ }
108
+
109
+ const args = parseArgs(process.argv);
110
+
111
+ if (args.cmd !== "init") {
112
+ console.log("Usage: npx viberealm init --handle <github_handle> [--server https://viberealm.dev]");
113
+ process.exit(0);
114
+ }
115
+
116
+ fs.mkdirSync(configDir, { recursive: true });
117
+ const templateSrc = path.join(__dirname, "..", "src", "hook-template.mjs");
118
+ fs.copyFileSync(templateSrc, hookDest);
119
+ fs.chmodSync(hookDest, 0o755);
120
+
121
+ writeJsonSafe(configPath, {
122
+ handle: args.handle,
123
+ serverUrl: args.serverUrl,
124
+ notifyOnStart: true,
125
+ });
126
+
127
+ const hookCmd = `node "${hookDest}"`;
128
+ const installed = [];
129
+ if (installClaudeHook(hookCmd)) installed.push("Claude Code (~/.claude/settings.json)");
130
+ if (installCodexHook(hookCmd)) installed.push("OpenAI Codex (~/.codex/hooks.json)");
131
+ if (installAntigravityHook(hookCmd)) installed.push("Google Antigravity (~/.gemini/config/hooks.json)");
132
+
133
+ console.log(`\nVibeRealm hook installed at ${hookDest}`);
134
+ console.log(`Handle: @${args.handle} | Server: ${args.serverUrl}`);
135
+ if (installed.length > 0) {
136
+ console.log("Registered hooks for:\n - " + installed.join("\n - "));
137
+ } else {
138
+ console.log("No local Claude Code / Codex / Antigravity config folders found yet.");
139
+ console.log(`Run this manually in any hook: ${hookCmd} claude working`);
140
+ }
141
+ console.log("\nDone! Next time you submit a prompt, you'll get a macOS popup to hop into VibeRealm.");
package/package.json CHANGED
@@ -1,6 +1,33 @@
1
1
  {
2
2
  "name": "viberealm",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Install VibeRealm macOS hooks for Claude Code, OpenAI Codex, and Google Antigravity",
5
+ "type": "module",
6
+ "bin": {
7
+ "viberealm": "bin/viberealm.mjs"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "src"
12
+ ],
13
+ "engines": {
14
+ "node": ">=18"
15
+ },
16
+ "license": "MIT",
17
+ "author": "BinaryBears LLC",
18
+ "homepage": "https://viberealm.dev",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/BinaryBearsLLC/viberealm.git",
22
+ "directory": "packages/cli"
23
+ },
24
+ "keywords": [
25
+ "viberealm",
26
+ "claude-code",
27
+ "codex",
28
+ "antigravity",
29
+ "ai-agents",
30
+ "hooks"
31
+ ],
32
+ "bugs": "https://github.com/BinaryBearsLLC/viberealm/issues"
33
+ }
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env node
2
+ // Installed to ~/.viberealm/hook.mjs by `npx viberealm init`
3
+ // Fires on Claude Code / Codex / Antigravity lifecycle hooks with zero LLM token overhead.
4
+ import { execFile } from "node:child_process";
5
+ import fs from "node:fs";
6
+ import os from "node:os";
7
+ import path from "node:path";
8
+
9
+ const [, , toolArg = "claude", statusArg = "working"] = process.argv;
10
+ const configPath = path.join(os.homedir(), ".viberealm", "config.json");
11
+
12
+ let cfg = { handle: os.userInfo().username, serverUrl: "https://viberealm.dev", notifyOnStart: true };
13
+ try {
14
+ cfg = { ...cfg, ...JSON.parse(fs.readFileSync(configPath, "utf8")) };
15
+ } catch {
16
+ // use defaults
17
+ }
18
+
19
+ const serverUrl = cfg.serverUrl.replace(/\/$/, "");
20
+
21
+ // Claude Code / Codex lifecycle hooks pipe a JSON payload on stdin that carries
22
+ // session_id — the identity that lets the server tell concurrent sessions apart,
23
+ // so one session finishing no longer falsely reports everyone idle.
24
+ let sessionId = "";
25
+ try {
26
+ const input = fs.readFileSync(0, "utf8");
27
+ const payload = JSON.parse(input);
28
+ sessionId = payload.session_id ?? payload.sessionId ?? "";
29
+ } catch {
30
+ // no stdin payload (manual invocation) — fall back to the parent process
31
+ sessionId = `ppid-${process.ppid}`;
32
+ }
33
+
34
+ // 1. Notify VibeRealm server asynchronously (never block the coding agent!)
35
+ fetch(`${serverUrl}/api/hook/event`, {
36
+ method: "POST",
37
+ headers: { "Content-Type": "application/json" },
38
+ body: JSON.stringify({
39
+ handle: cfg.handle,
40
+ activeTool: toolArg,
41
+ status: statusArg,
42
+ activeAgents: statusArg === "working" ? 1 : 0,
43
+ sessionId,
44
+ // hookToken comes from ~/.viberealm/config.json — copy it from your in-game
45
+ // player card. Without it the server rejects events for your handle.
46
+ hookToken: cfg.hookToken,
47
+ }),
48
+ signal: AbortSignal.timeout(2500),
49
+ }).catch(() => {});
50
+
51
+ // 2. On macOS, show native popup when agent starts working so user can hop into the plaza in 1 click
52
+ if (process.platform === "darwin" && statusArg === "working" && cfg.notifyOnStart) {
53
+ const title = "VibeRealm";
54
+ const subtitle = `${toolArg.toUpperCase()} agent is running`;
55
+ const msg = "Want to hop into the plaza while it works?";
56
+
57
+ // Prefer terminal-notifier (supports click-to-open URL), fallback to built-in osascript
58
+ execFile(
59
+ "terminal-notifier",
60
+ ["-title", title, "-subtitle", subtitle, "-message", msg, "-open", serverUrl, "-group", "viberealm"],
61
+ (err) => {
62
+ if (err) {
63
+ const script = `display notification "${msg}" with title "${title}" subtitle "${subtitle}"`;
64
+ execFile("osascript", ["-e", script], () => {});
65
+ }
66
+ }
67
+ );
68
+ }