@bulletproof-sh/ctrl-daemon 0.0.2 → 0.0.3
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/README.md +74 -0
- package/bin/ctrl-daemon.js +1 -1
- package/dist/index.js +77 -7
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# @bulletproof-sh/ctrl-daemon
|
|
2
|
+
|
|
3
|
+
WebSocket daemon for [Ctrl / Cubicles](https://bulletproof.sh) — watches Claude Code sessions on disk and broadcasts live agent state to connected web clients.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- [Bun](https://bun.sh) — required at runtime (`curl -fsSL https://bun.sh/install | bash`)
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
# Watch all Claude Code projects (default)
|
|
13
|
+
npx @bulletproof-sh/ctrl-daemon
|
|
14
|
+
|
|
15
|
+
# Watch a single project directory
|
|
16
|
+
npx @bulletproof-sh/ctrl-daemon --project-dir /path/to/your/project
|
|
17
|
+
|
|
18
|
+
# Custom port / host
|
|
19
|
+
npx @bulletproof-sh/ctrl-daemon --port 3001 --host 127.0.0.1
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Options
|
|
23
|
+
|
|
24
|
+
| Flag | Default | Description |
|
|
25
|
+
|---|---|---|
|
|
26
|
+
| `--port <number>` | `3001` | Port to listen on |
|
|
27
|
+
| `--host <address>` | `0.0.0.0` | Host/address to bind to |
|
|
28
|
+
| `--project-dir <path>` | — | Watch a single project; omit to watch all projects |
|
|
29
|
+
| `--help`, `-h` | — | Print usage |
|
|
30
|
+
|
|
31
|
+
Without `--project-dir`, the daemon scans `~/.claude/projects/` and watches every session it finds there.
|
|
32
|
+
|
|
33
|
+
## WebSocket API
|
|
34
|
+
|
|
35
|
+
Connect to `ws://localhost:3001/ws`. The daemon broadcasts JSON messages whenever agent state changes — the same message format used by the VS Code extension's internal webview protocol.
|
|
36
|
+
|
|
37
|
+
The [Ctrl web app](https://ctrl.bulletproof.sh) connects here by default. You can change the URL in the app's Settings modal or by setting `VITE_DAEMON_WS_URL` at build time.
|
|
38
|
+
|
|
39
|
+
## Environment Variables
|
|
40
|
+
|
|
41
|
+
| Variable | Description |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `VITE_PUBLIC_POSTHOG_KEY` | PostHog API key for analytics (optional) |
|
|
44
|
+
| `VITE_PUBLIC_POSTHOG_HOST` | PostHog host (default: `https://us.i.posthog.com`) |
|
|
45
|
+
| `CLAUDE_HOME` | Override the Claude home directory (default: `~/.claude`) |
|
|
46
|
+
|
|
47
|
+
Analytics are disabled when `VITE_PUBLIC_POSTHOG_KEY` is not set. Crash reports use PostHog Error Tracking (free feature).
|
|
48
|
+
|
|
49
|
+
## Auto-update
|
|
50
|
+
|
|
51
|
+
On startup the daemon checks npm for a newer version and prints a notice if one is available:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
[ctrl-daemon] Update available: v0.0.2 → v0.0.3
|
|
55
|
+
Run: npm install -g @bulletproof-sh/ctrl-daemon@latest
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The check is non-blocking and fails silently if the registry is unreachable.
|
|
59
|
+
|
|
60
|
+
> **Note:** If you're running via `npx`, you already get the latest version on every invocation — no manual update needed.
|
|
61
|
+
|
|
62
|
+
## Development
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
bun install
|
|
66
|
+
bun run dev # watch mode
|
|
67
|
+
bun run build # compile to dist/
|
|
68
|
+
bun run check # biome lint + format
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
MIT
|
|
74
|
+
|
package/bin/ctrl-daemon.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { execFileSync } from "node:child_process";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
3
|
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
5
|
|
|
6
6
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
7
|
const entry = join(__dirname, "..", "dist", "index.js");
|
package/dist/index.js
CHANGED
|
@@ -4204,8 +4204,14 @@ class PostHog extends PostHogBackendClient {
|
|
|
4204
4204
|
}
|
|
4205
4205
|
|
|
4206
4206
|
// src/analytics.ts
|
|
4207
|
-
var
|
|
4208
|
-
|
|
4207
|
+
var systemInfo = {
|
|
4208
|
+
os_platform: os.platform(),
|
|
4209
|
+
os_arch: os.arch(),
|
|
4210
|
+
os_release: os.release(),
|
|
4211
|
+
node_version: process.version
|
|
4212
|
+
};
|
|
4213
|
+
var POSTHOG_API_KEY = process.env.VITE_PUBLIC_POSTHOG_KEY ?? "phc_V3aPfuu7VEWm1u4CEYLIFr8Ksk8nR7qyZzGn8HotO8U";
|
|
4214
|
+
var POSTHOG_HOST = process.env.VITE_PUBLIC_POSTHOG_HOST ?? "https://a.bulletproof.sh";
|
|
4209
4215
|
var client = null;
|
|
4210
4216
|
var distinctId = os.hostname();
|
|
4211
4217
|
function initAnalytics() {
|
|
@@ -4215,6 +4221,7 @@ function initAnalytics() {
|
|
|
4215
4221
|
client.on("error", (err) => {
|
|
4216
4222
|
console.error("[ctrl-daemon] PostHog error:", err);
|
|
4217
4223
|
});
|
|
4224
|
+
console.log("[ctrl-daemon] Analytics enabled");
|
|
4218
4225
|
}
|
|
4219
4226
|
function trackEvent(event, properties) {
|
|
4220
4227
|
if (!client)
|
|
@@ -4824,6 +4831,67 @@ function createServer({ port, host, agents }) {
|
|
|
4824
4831
|
};
|
|
4825
4832
|
}
|
|
4826
4833
|
|
|
4834
|
+
// src/updater.ts
|
|
4835
|
+
var PACKAGE_NAME = "@bulletproof-sh/ctrl-daemon";
|
|
4836
|
+
var NPM_REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE_NAME}/latest`;
|
|
4837
|
+
var UPDATE_CHECK_TIMEOUT_MS = 5000;
|
|
4838
|
+
function parseSemver(version2) {
|
|
4839
|
+
const match = version2.match(/^(\d+)\.(\d+)\.(\d+)/);
|
|
4840
|
+
if (!match)
|
|
4841
|
+
return null;
|
|
4842
|
+
return [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
4843
|
+
}
|
|
4844
|
+
function isNewer(current, next) {
|
|
4845
|
+
const a = parseSemver(current);
|
|
4846
|
+
const b = parseSemver(next);
|
|
4847
|
+
if (!a || !b)
|
|
4848
|
+
return false;
|
|
4849
|
+
for (let i = 0;i < 3; i++) {
|
|
4850
|
+
if (b[i] > a[i])
|
|
4851
|
+
return true;
|
|
4852
|
+
if (b[i] < a[i])
|
|
4853
|
+
return false;
|
|
4854
|
+
}
|
|
4855
|
+
return false;
|
|
4856
|
+
}
|
|
4857
|
+
async function getCurrentVersion() {
|
|
4858
|
+
try {
|
|
4859
|
+
const pkgFile = Bun.file(new URL("../package.json", import.meta.url));
|
|
4860
|
+
const pkg = await pkgFile.json();
|
|
4861
|
+
return pkg.version ?? null;
|
|
4862
|
+
} catch {
|
|
4863
|
+
return null;
|
|
4864
|
+
}
|
|
4865
|
+
}
|
|
4866
|
+
async function getLatestVersion() {
|
|
4867
|
+
try {
|
|
4868
|
+
const controller = new AbortController;
|
|
4869
|
+
const timeout = setTimeout(() => controller.abort(), UPDATE_CHECK_TIMEOUT_MS);
|
|
4870
|
+
const res = await fetch(NPM_REGISTRY_URL, { signal: controller.signal });
|
|
4871
|
+
clearTimeout(timeout);
|
|
4872
|
+
if (!res.ok)
|
|
4873
|
+
return null;
|
|
4874
|
+
const data = await res.json();
|
|
4875
|
+
return data.version ?? null;
|
|
4876
|
+
} catch {
|
|
4877
|
+
return null;
|
|
4878
|
+
}
|
|
4879
|
+
}
|
|
4880
|
+
async function checkForUpdate() {
|
|
4881
|
+
const [current, latest] = await Promise.all([
|
|
4882
|
+
getCurrentVersion(),
|
|
4883
|
+
getLatestVersion()
|
|
4884
|
+
]);
|
|
4885
|
+
if (!current || !latest)
|
|
4886
|
+
return;
|
|
4887
|
+
if (!isNewer(current, latest))
|
|
4888
|
+
return;
|
|
4889
|
+
console.log(`
|
|
4890
|
+
[ctrl-daemon] Update available: v${current} \u2192 v${latest}
|
|
4891
|
+
` + ` Run: npx ${PACKAGE_NAME}@latest
|
|
4892
|
+
`);
|
|
4893
|
+
}
|
|
4894
|
+
|
|
4827
4895
|
// src/index.ts
|
|
4828
4896
|
function printUsage() {
|
|
4829
4897
|
console.log(`Usage: ctrl-daemon [options]
|
|
@@ -4860,18 +4928,19 @@ function resolveProjectsRoot(claudeHome) {
|
|
|
4860
4928
|
const home = claudeHome || path3.join(process.env.HOME || "~", ".claude");
|
|
4861
4929
|
return path3.join(home, "projects");
|
|
4862
4930
|
}
|
|
4863
|
-
function main() {
|
|
4931
|
+
async function main() {
|
|
4864
4932
|
initAnalytics();
|
|
4933
|
+
const [version2] = await Promise.all([getCurrentVersion(), checkForUpdate()]);
|
|
4865
4934
|
process.on("uncaughtException", async (err) => {
|
|
4866
4935
|
console.error("[ctrl-daemon] Uncaught exception:", err);
|
|
4867
|
-
trackException(err);
|
|
4936
|
+
trackException(err, { ...systemInfo, crash_type: "uncaughtException" });
|
|
4868
4937
|
await shutdownAnalytics();
|
|
4869
4938
|
process.exit(1);
|
|
4870
4939
|
});
|
|
4871
4940
|
process.on("unhandledRejection", async (reason) => {
|
|
4872
4941
|
const err = reason instanceof Error ? reason : new Error(String(reason));
|
|
4873
4942
|
console.error("[ctrl-daemon] Unhandled rejection:", err);
|
|
4874
|
-
trackException(err);
|
|
4943
|
+
trackException(err, { ...systemInfo, crash_type: "unhandledRejection" });
|
|
4875
4944
|
await shutdownAnalytics();
|
|
4876
4945
|
process.exit(1);
|
|
4877
4946
|
});
|
|
@@ -4895,10 +4964,11 @@ function main() {
|
|
|
4895
4964
|
const permissionTimers = new Map;
|
|
4896
4965
|
const server = createServer({ port, host, agents });
|
|
4897
4966
|
trackEvent("daemon_started", {
|
|
4898
|
-
|
|
4967
|
+
version: version2 ?? "unknown",
|
|
4899
4968
|
port,
|
|
4900
4969
|
host,
|
|
4901
|
-
mode: projectDir ? "single" : "all"
|
|
4970
|
+
mode: projectDir ? "single" : "all",
|
|
4971
|
+
...systemInfo
|
|
4902
4972
|
});
|
|
4903
4973
|
const scanAll = !projectDir;
|
|
4904
4974
|
const scanner = startProjectScanner(scanDirs[0], scanAll, agents, fileWatchers, pollingTimers, waitingTimers, permissionTimers, server.broadcast);
|