@beatos/bridge-runner 0.8.0 → 0.9.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/README.md +130 -2
- package/dist/api.js +50 -1
- package/dist/claude.js +7 -1
- package/dist/config.js +13 -0
- package/dist/folders.js +6 -2
- package/dist/main.js +26 -4
- package/dist/outbox.js +31 -0
- package/dist/read-wall.js +151 -0
- package/dist/runner.js +42 -6
- package/dist/safety.js +79 -0
- package/dist/sessions-engine.js +971 -0
- package/dist/sessions-scan.js +608 -0
- package/dist/video-vault.js +51 -9
- package/package.json +1 -1
package/dist/runner.js
CHANGED
|
@@ -44,12 +44,13 @@ import { ApiError, } from "./api.js";
|
|
|
44
44
|
import { answerText, parseAgentReply } from "./agent-reply.js";
|
|
45
45
|
import { briefText, CONTINUE_PROMPT, REPLY_PROMPT, RETRY_PROMPT, rulesText, START_PROMPT, } from "./brief.js";
|
|
46
46
|
import { classifyError, retryDelaySeconds, sessionUsage, } from "./claude.js";
|
|
47
|
+
import { parseSessionsConfig } from "./config.js";
|
|
47
48
|
import { Outbox } from "./outbox.js";
|
|
48
49
|
import { decideAction } from "./policy.js";
|
|
49
50
|
import { claudeArgs, comprehensionArgs, sessionSettings, agentEnv } from "./safety.js";
|
|
50
51
|
import { processVideos, realVideoFs } from "./video.js";
|
|
51
|
-
import {
|
|
52
|
-
export const RUNNER_VERSION = "0.
|
|
52
|
+
import { comprehensionLanguage, comprehensionPrompt, comprehensionTaskText, TASK_TEXT_FILE, useSavedVideos, VAULT_LIMITS, } from "./video-vault.js";
|
|
53
|
+
export const RUNNER_VERSION = "0.9.0";
|
|
53
54
|
/** A model name from Bridge goes into argv: plain names only. */
|
|
54
55
|
const MODEL_RE = /^[A-Za-z0-9._-]{1,64}$/;
|
|
55
56
|
const CLAIM_REFRESH_MS = 5 * 60_000;
|
|
@@ -169,6 +170,7 @@ export class Runner {
|
|
|
169
170
|
}
|
|
170
171
|
this.runnerStatus = "revoked";
|
|
171
172
|
this.stopLive("revoked");
|
|
173
|
+
this.d.sessions?.update({ runnerId: this.state.runnerId, enabled: false });
|
|
172
174
|
return false;
|
|
173
175
|
}
|
|
174
176
|
throw err;
|
|
@@ -181,8 +183,29 @@ export class Runner {
|
|
|
181
183
|
await this.sendInventory();
|
|
182
184
|
if (r.status !== "revoked")
|
|
183
185
|
await this.folderStep(r);
|
|
186
|
+
this.sessionsStep(r);
|
|
184
187
|
return true;
|
|
185
188
|
}
|
|
189
|
+
/** The sessions switch and the folder scan go to the engine; a paused or revoked runner is off. */
|
|
190
|
+
sessionsStep(r) {
|
|
191
|
+
const s = this.d.sessions;
|
|
192
|
+
if (!s)
|
|
193
|
+
return;
|
|
194
|
+
try {
|
|
195
|
+
s.update({
|
|
196
|
+
runnerId: r.runner_id,
|
|
197
|
+
enabled: r.status === "active" && r.sessions?.enabled === true,
|
|
198
|
+
...(r.sessions ? { pollMs: r.sessions.poll_ms } : {}),
|
|
199
|
+
...(this.d.folders ? { folders: this.d.folders.shownPaths() } : {}),
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
catch (err) {
|
|
203
|
+
this.log(`sessions: update failed (${err.name})`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
sessionsAccess() {
|
|
207
|
+
return parseSessionsConfig(this.d.cfg.sessions).access;
|
|
208
|
+
}
|
|
186
209
|
/**
|
|
187
210
|
* Project folders (BEA-96 slice 3): take the owner's picks from the reply,
|
|
188
211
|
* rescan the roots now and then, and send the list in one more heartbeat
|
|
@@ -266,6 +289,8 @@ export class Runner {
|
|
|
266
289
|
// Usage screen (BEA-87): the cap and how runs are paid on this computer.
|
|
267
290
|
max_runs_per_day: this.d.cfg.maxRunsPerDay,
|
|
268
291
|
billing: this.d.cfg.billing,
|
|
292
|
+
// Sessions in Bridge (BEA-107): the access set in config.json; "off" when off.
|
|
293
|
+
sessions: { access: this.sessionsAccess(), protocol: 1 },
|
|
269
294
|
},
|
|
270
295
|
max_concurrent: 1,
|
|
271
296
|
};
|
|
@@ -808,7 +833,7 @@ export class Runner {
|
|
|
808
833
|
const done = await processVideos(items, brief, this.d.cfg.video, {
|
|
809
834
|
...this.d.video,
|
|
810
835
|
log,
|
|
811
|
-
comprehend: (dir) => this.comprehend(dir),
|
|
836
|
+
comprehend: (dir) => this.comprehend(dir, task),
|
|
812
837
|
save: { api: this.d.api, taskId: task.id },
|
|
813
838
|
});
|
|
814
839
|
out = out.map((f, i) => done.get(i) ?? f);
|
|
@@ -826,9 +851,20 @@ export class Runner {
|
|
|
826
851
|
/**
|
|
827
852
|
* The comprension of a processed video (slice 8): one short Claude session
|
|
828
853
|
* with the same CLI and login as a run, Read as its only tool, in the
|
|
829
|
-
* video's folder, 5 minutes at most.
|
|
854
|
+
* video's folder, 5 minutes at most. Slice 10: it writes in the language
|
|
855
|
+
* of the task, whose text goes in a file next to VIDEO.md (the prompt stays
|
|
856
|
+
* ASCII), unless config.json forces a language.
|
|
830
857
|
*/
|
|
831
|
-
async comprehend(dir) {
|
|
858
|
+
async comprehend(dir, task) {
|
|
859
|
+
const language = comprehensionLanguage(this.d.cfg.video.comprehensionLanguage);
|
|
860
|
+
if (language === "task") {
|
|
861
|
+
try {
|
|
862
|
+
(this.d.video?.fs ?? realVideoFs).writeText(join(dir, TASK_TEXT_FILE), comprehensionTaskText(task.title, task.description));
|
|
863
|
+
}
|
|
864
|
+
catch (err) {
|
|
865
|
+
return { ok: false, why: `task text not written (${err.name})` };
|
|
866
|
+
}
|
|
867
|
+
}
|
|
832
868
|
const place = {
|
|
833
869
|
cwd: dir,
|
|
834
870
|
brief: dir,
|
|
@@ -842,7 +878,7 @@ export class Runner {
|
|
|
842
878
|
const args = comprehensionArgs({
|
|
843
879
|
model: this.d.cfg.model,
|
|
844
880
|
settings: sessionSettings(place, undefined, this.d.cfg.protectPaths, this.d.cfg.stateDir),
|
|
845
|
-
prompt:
|
|
881
|
+
prompt: comprehensionPrompt(language),
|
|
846
882
|
});
|
|
847
883
|
const r = await this.d.claude(args, dir, () => undefined, () => undefined, new AbortController().signal, VAULT_LIMITS.comprehensionMs);
|
|
848
884
|
if (r.timedOut)
|
package/dist/safety.js
CHANGED
|
@@ -296,6 +296,85 @@ export function claudeArgs(i) {
|
|
|
296
296
|
argv.push("--", i.prompt); // --add-dir and --mcp-config take many values and would eat the prompt
|
|
297
297
|
return argv;
|
|
298
298
|
}
|
|
299
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
300
|
+
const CHAT_MODEL_RE = /^[A-Za-z0-9._-]{1,64}$/;
|
|
301
|
+
/** The only tools of a read-only chat session (BEA-107). */
|
|
302
|
+
export const READ_TOOLS = "Read,Grep,Glob";
|
|
303
|
+
/**
|
|
304
|
+
* On Windows a file or folder also opens by its 8.3 short name
|
|
305
|
+
* (C:/Users/me/DOCUME~1 for Documents, ENV~1 for .env). A deny rule sees the
|
|
306
|
+
* path as it was written, so every rule by long name could be passed that
|
|
307
|
+
* way. Checked on Claude Code 2.1.319 with a real read session: it read a
|
|
308
|
+
* walled folder by BEATOS~2/SPIKE-~3 and its own .env as ENV~1; with these
|
|
309
|
+
* rules both are denied. A short name always has "~" and a digit, so every
|
|
310
|
+
* such name is denied on the drives given (one rule set per drive letter). A
|
|
311
|
+
* real long name with "~1" in it is refused too: the safe side.
|
|
312
|
+
*/
|
|
313
|
+
export function shortNameRules(paths) {
|
|
314
|
+
const rules = [];
|
|
315
|
+
const seen = new Set();
|
|
316
|
+
for (const p of paths) {
|
|
317
|
+
const d = /^([A-Za-z]):/.exec(p);
|
|
318
|
+
if (!d)
|
|
319
|
+
continue;
|
|
320
|
+
const letter = d[1].toUpperCase();
|
|
321
|
+
if (seen.has(letter))
|
|
322
|
+
continue;
|
|
323
|
+
seen.add(letter);
|
|
324
|
+
for (const glob of ["**/*~[0-9]*", "**/*~[0-9]*/**"]) {
|
|
325
|
+
rules.push(`Read(${letter}:/${glob})`, `Read(//${letter.toLowerCase()}/${glob})`);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return rules;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* More deny rules for every chat turn (read and work; task runs do not
|
|
332
|
+
* change): key and .env files anywhere under the session's root (the cwd can
|
|
333
|
+
* be below it, and the root can be outside ~/projects), other sessions'
|
|
334
|
+
* transcripts and the live registry, and every Windows short name on the
|
|
335
|
+
* root's drive and the home drive (shortNameRules). Work also gets Bash
|
|
336
|
+
* patterns for the transcripts and the registry.
|
|
337
|
+
*/
|
|
338
|
+
export function chatDenyRules(root, access, home = homedir()) {
|
|
339
|
+
const rules = [];
|
|
340
|
+
for (const f of PROJECT_SECRET_FILES)
|
|
341
|
+
rules.push(...pathForms("Read", root, `**/${f}`));
|
|
342
|
+
for (const rel of [".claude/projects/**", ".claude/sessions/**"])
|
|
343
|
+
rules.push(...homeForms("Read", rel, home));
|
|
344
|
+
rules.push(...shortNameRules([root, home]));
|
|
345
|
+
if (access === "work")
|
|
346
|
+
rules.push("Bash(*.claude/projects*)", "Bash(*.claude\\projects*)", "Bash(*.claude/sessions*)", "Bash(*.claude\\sessions*)");
|
|
347
|
+
return rules;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* argv for one chat turn of a Bridge session (BEA-107). The user's text goes
|
|
351
|
+
* by stdin, never argv. read: Read, Grep and Glob are the only tools there
|
|
352
|
+
* are, anything else is denied without asking. work: the same auto mode and
|
|
353
|
+
* deny rules as a task run. Never --dangerously-skip-permissions.
|
|
354
|
+
*/
|
|
355
|
+
export function chatArgs(i) {
|
|
356
|
+
if (i.access !== "read" && i.access !== "work")
|
|
357
|
+
throw new Error("sessions are off");
|
|
358
|
+
if (!CHAT_MODEL_RE.test(i.model))
|
|
359
|
+
throw new Error("bad model name");
|
|
360
|
+
if (i.resumeSessionId !== undefined && !UUID_RE.test(i.resumeSessionId))
|
|
361
|
+
throw new Error("bad session id");
|
|
362
|
+
if (i.fork && !i.resumeSessionId)
|
|
363
|
+
throw new Error("a copy needs the session it copies");
|
|
364
|
+
const argv = ["-p", "--output-format", "stream-json", "--verbose", "--model", i.model];
|
|
365
|
+
if (i.resumeSessionId)
|
|
366
|
+
argv.push("--resume", i.resumeSessionId);
|
|
367
|
+
if (i.fork)
|
|
368
|
+
argv.push("--fork-session");
|
|
369
|
+
if (i.access === "read")
|
|
370
|
+
argv.push("--tools", READ_TOOLS, "--allowedTools", READ_TOOLS, "--permission-mode", "dontAsk");
|
|
371
|
+
else
|
|
372
|
+
argv.push("--permission-mode", "auto");
|
|
373
|
+
if (!i.settingsFile || i.settingsFile.trim().startsWith("{"))
|
|
374
|
+
throw new Error("chat settings go in a file");
|
|
375
|
+
argv.push("--settings", i.settingsFile, "--strict-mcp-config", "--mcp-config", '{"mcpServers":{}}', "--no-chrome", "--append-system-prompt-file", i.rulesFile);
|
|
376
|
+
return argv;
|
|
377
|
+
}
|
|
299
378
|
/**
|
|
300
379
|
* argv for the short "comprension" session of a processed video (BEA-96
|
|
301
380
|
* slice 8): the same CLI and login as a run, but Read is the only tool there
|