barebrowse 0.2.2 → 0.3.1
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/.claude/skills/barebrowse/SKILL.md +107 -0
- package/CHANGELOG.md +57 -0
- package/CLAUDE.md +4 -2
- package/README.md +52 -5
- package/barebrowse.context.md +27 -8
- package/cli.js +289 -48
- package/docs/00-context/assumptions.md +38 -0
- package/docs/{blueprint.md → 00-context/system-state.md} +30 -5
- package/docs/00-context/vision.md +52 -0
- package/docs/01-product/prd.md +284 -0
- package/docs/03-logs/bug-log.md +16 -0
- package/docs/03-logs/decisions-log.md +32 -0
- package/docs/03-logs/implementation-log.md +54 -0
- package/docs/03-logs/insights.md +35 -0
- package/docs/03-logs/validation-log.md +123 -0
- package/docs/04-process/definition-of-done.md +31 -0
- package/docs/04-process/dev-workflow.md +68 -0
- package/docs/{testing.md → 04-process/testing.md} +21 -2
- package/docs/README.md +55 -0
- package/docs/archive/poc-plan.md +230 -0
- package/package.json +1 -1
- package/src/aria.js +1 -1
- package/src/daemon.js +321 -0
- package/src/session-client.js +70 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* session-client.js -- HTTP client to talk to the daemon.
|
|
3
|
+
*
|
|
4
|
+
* sendCommand() — POST a command to the running daemon
|
|
5
|
+
* readSession() — read session.json from output dir
|
|
6
|
+
* isAlive() — check if daemon is still responding
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
10
|
+
import { join, resolve } from 'node:path';
|
|
11
|
+
|
|
12
|
+
const SESSION_FILE = 'session.json';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Read session.json from the output directory.
|
|
16
|
+
* @returns {{ port: number, pid: number, startedAt: string } | null}
|
|
17
|
+
*/
|
|
18
|
+
export function readSession(outputDir) {
|
|
19
|
+
const sessionPath = join(resolve(outputDir), SESSION_FILE);
|
|
20
|
+
if (!existsSync(sessionPath)) return null;
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(readFileSync(sessionPath, 'utf8'));
|
|
23
|
+
} catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Check if the daemon is alive by hitting GET /status.
|
|
30
|
+
*/
|
|
31
|
+
export async function isAlive(outputDir) {
|
|
32
|
+
const session = readSession(outputDir);
|
|
33
|
+
if (!session) return false;
|
|
34
|
+
try {
|
|
35
|
+
const res = await fetch(`http://127.0.0.1:${session.port}/status`, {
|
|
36
|
+
signal: AbortSignal.timeout(2000),
|
|
37
|
+
});
|
|
38
|
+
return res.ok;
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Send a command to the running daemon.
|
|
46
|
+
* @returns {Promise<object>} The daemon's response
|
|
47
|
+
*/
|
|
48
|
+
export async function sendCommand(command, args, outputDir) {
|
|
49
|
+
const session = readSession(outputDir);
|
|
50
|
+
if (!session) throw new Error('No active session. Run `barebrowse open` first.');
|
|
51
|
+
|
|
52
|
+
let res;
|
|
53
|
+
try {
|
|
54
|
+
res = await fetch(`http://127.0.0.1:${session.port}/command`, {
|
|
55
|
+
method: 'POST',
|
|
56
|
+
headers: { 'Content-Type': 'application/json' },
|
|
57
|
+
body: JSON.stringify({ command, args }),
|
|
58
|
+
signal: AbortSignal.timeout(60000),
|
|
59
|
+
});
|
|
60
|
+
} catch (err) {
|
|
61
|
+
// ECONNREFUSED / ECONNRESET — daemon died
|
|
62
|
+
if (command === 'close') {
|
|
63
|
+
// Expected: daemon exited before response
|
|
64
|
+
return { ok: true };
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`Daemon not responding (pid ${session.pid}). Session may be stale.`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return res.json();
|
|
70
|
+
}
|