@beatos/bridge-runner 0.1.0 → 0.1.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/README.md CHANGED
@@ -205,8 +205,8 @@ Every field:
205
205
  | `maxRunsPerDay` | number | `8` | How many runs this computer starts per day. |
206
206
  | `billing` | `subscription` or `metered` | `subscription` | `subscription`: a Claude plan, runs report $0. `metered`: an API key, runs report the cost. |
207
207
  | `pollSeconds` | number | `30` | How often the runner checks BeatOS. |
208
- | `taskRoot` | string | `~/.beatos-runner/tasks` | Where each task's files go. |
209
- | `worktreeRoot` | string | `~/.beatos-runner/worktrees` | Where git projects get their work copies. |
208
+ | `taskRoot` | string | `~/beatos-runner-work/tasks` | Where each task's files go (`TAREA.md`, rules, your answers). Use a full path (`~` is not expanded). The agent must read and write here, so it must be outside `~/.beatos-runner` and outside `protectPaths`. |
209
+ | `worktreeRoot` | string | `~/beatos-runner-work/worktrees` | Where git projects get their work copies. Same rule as `taskRoot`. |
210
210
  | `claudePath` | string | found by itself | The Claude Code program. `BEATOS_RUNNER_CLAUDE` also sets it. |
211
211
  | `ghUser` | string | none | The GitHub CLI account the runner uses to push and open pull requests. |
212
212
  | `protectPaths` | string array | `[]` | More folders the agent may not read or change. See the next section. |
@@ -272,7 +272,7 @@ How to check it works:
272
272
  | `exclude` | Never takes tasks from this project. |
273
273
 
274
274
  A task from a project that is not listed works in a scratch folder in
275
- `~/.beatos-runner/tasks/<TASK>`.
275
+ `~/beatos-runner-work/tasks/<TASK>`.
276
276
 
277
277
  ## The key
278
278
 
@@ -304,7 +304,10 @@ These rules are in the code. No setting turns them off.
304
304
 
305
305
  ## Files and logs
306
306
 
307
- Everything is in `~/.beatos-runner` (or `BEATOS_RUNNER_HOME`):
307
+ The runner uses two folders in your home folder.
308
+
309
+ `~/.beatos-runner` (or `BEATOS_RUNNER_HOME`): the runner's own files. The
310
+ agent can never read or change this folder.
308
311
 
309
312
  | File or folder | What |
310
313
  | --- | --- |
@@ -312,9 +315,20 @@ Everything is in `~/.beatos-runner` (or `BEATOS_RUNNER_HOME`):
312
315
  | `config.json` | Your settings. |
313
316
  | `state.json` | Open runs and today's count. |
314
317
  | `outbox/` | Events saved before they are sent, so nothing is lost offline. |
318
+ | `runner.lock` | Present while the runner runs. |
319
+
320
+ `~/beatos-runner-work` (next to the runner folder): where the agent works.
321
+ Change it with `taskRoot` and `worktreeRoot`.
322
+
323
+ | Folder | What |
324
+ | --- | --- |
315
325
  | `tasks/<TASK>/` | Each task's brief (`TAREA.md`), rules and your answers. |
316
326
  | `worktrees/` | Work copies of git projects. |
317
- | `runner.lock` | Present while the runner runs. |
327
+
328
+ At start, the runner checks that the agent may read and write both work
329
+ folders. If a deny rule covers one of them (for example a `taskRoot` inside
330
+ `~/.beatos-runner` or inside a `protectPaths` entry), it does not start and
331
+ says which rule blocks it.
318
332
 
319
333
  Logs go to the terminal, with the prefix `[bridge-runner]`. To keep them in a
320
334
  file:
@@ -346,20 +360,22 @@ Your key and settings stay. Stop the runner (Ctrl+C) before you update.
346
360
 
347
361
  1. In Bridge, Runners: **Revoke key** on the computer's card, then **Remove**.
348
362
  2. Stop the runner (Ctrl+C).
349
- 3. Delete the runner folder:
363
+ 3. Delete the runner folder and the work folder:
350
364
 
351
365
  macOS and Linux:
352
366
 
353
367
  ```bash
354
- rm -rf ~/.beatos-runner
368
+ rm -rf ~/.beatos-runner ~/beatos-runner-work
355
369
  ```
356
370
 
357
371
  Windows (PowerShell):
358
372
 
359
373
  ```powershell
360
- Remove-Item -Recurse -Force $HOME\.beatos-runner
374
+ Remove-Item -Recurse -Force $HOME\.beatos-runner, $HOME\beatos-runner-work
361
375
  ```
362
376
 
377
+ If you set `taskRoot` or `worktreeRoot`, delete those folders too.
378
+
363
379
  4. Optional: clear the npx copy with `npm cache clean --force`.
364
380
 
365
381
  ## Troubleshooting
@@ -374,6 +390,8 @@ Your key and settings stay. Stop the runner (Ctrl+C) before you update.
374
390
  | "no agent key" | Pair this computer first, or set `BEATOS_RUNNER_KEY`. |
375
391
  | "no agent set" | Pair this computer first, or set `agentName` in `config.json`. |
376
392
  | "another runner is already running" | One runner per computer. Close the other terminal. If none runs, delete `~/.beatos-runner/runner.lock`. |
393
+ | A run says it cannot read `TAREA.md` (runner 0.1.0) | Update to 0.1.1 or newer (`npx @beatos/bridge-runner@latest`). In 0.1.0 the task folder was inside `~/.beatos-runner`, which the agent may not read. On 0.1.0, set full paths in `config.json`, like `"taskRoot": "/home/you/beatos-runner-work/tasks"` and `"worktreeRoot": "/home/you/beatos-runner-work/worktrees"` (Windows: `"C:/Users/you/beatos-runner-work/tasks"`). |
394
+ | "taskRoot ... is blocked for the agent by" | The task or work folder is under a denied path. Move `taskRoot` and `worktreeRoot` outside `~/.beatos-runner` and outside `protectPaths`, or remove the default lines from `config.json`. |
377
395
  | "the runner key was refused" | The key was revoked. Pair again with a new code. |
378
396
  | The card says offline | Start the runner and keep the terminal open. Check the internet connection. A sleeping computer is offline. |
379
397
  | No tasks are picked up | Check: the task is delegated to **Local AI**; the runner is not paused; the daily limit (`maxRunsPerDay`) is not reached; the task's project is not `exclude`; the task has no machine target for another computer; the task is not blocked or waiting. |
package/dist/config.js CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import { existsSync, readdirSync, readFileSync } from "node:fs";
8
8
  import { homedir, hostname } from "node:os";
9
- import { join } from "node:path";
9
+ import { dirname, join } from "node:path";
10
10
  /**
11
11
  * The real Claude Code executable. On Windows the npm `claude.cmd` shim cannot
12
12
  * be spawned without a shell and mangles multi-line arguments, so look for
@@ -36,6 +36,15 @@ export function findClaude(env = process.env, platform = process.platform, home
36
36
  export function defaultStateDir() {
37
37
  return join(homedir(), ".beatos-runner");
38
38
  }
39
+ /**
40
+ * Where the agent works: task briefs and git work copies. It sits NEXT TO
41
+ * the state folder (~/beatos-runner-work), never inside it: the state folder
42
+ * holds the key and is denied to every agent session, so a task inside it
43
+ * could not read its own TAREA.md (0.1.0 bug).
44
+ */
45
+ export function defaultWorkDir(stateDir) {
46
+ return join(dirname(stateDir), "beatos-runner-work");
47
+ }
39
48
  export function loadConfig(env = process.env) {
40
49
  const stateDir = env.BEATOS_RUNNER_HOME || defaultStateDir();
41
50
  const file = env.BEATOS_RUNNER_CONFIG || join(stateDir, "config.json");
@@ -55,8 +64,8 @@ export function loadConfig(env = process.env) {
55
64
  billing: raw.billing === "metered" ? "metered" : "subscription",
56
65
  pollSeconds: raw.pollSeconds ?? 30,
57
66
  stateDir,
58
- taskRoot: raw.taskRoot ?? join(stateDir, "tasks"),
59
- worktreeRoot: raw.worktreeRoot ?? join(stateDir, "worktrees"),
67
+ taskRoot: raw.taskRoot ?? join(defaultWorkDir(stateDir), "tasks"),
68
+ worktreeRoot: raw.worktreeRoot ?? join(defaultWorkDir(stateDir), "worktrees"),
60
69
  claudePath: raw.claudePath ?? findClaude(env),
61
70
  ghUser: raw.ghUser,
62
71
  protectPaths: Array.isArray(raw.protectPaths) ? raw.protectPaths.filter((p) => typeof p === "string") : [],
package/dist/main.js CHANGED
@@ -22,6 +22,7 @@ import { BeatosApi } from "./api.js";
22
22
  import { runClaude } from "./claude.js";
23
23
  import { loadConfig, loadKey } from "./config.js";
24
24
  import { pair } from "./pair.js";
25
+ import { agentPathProblems } from "./safety.js";
25
26
  import { makeClaudeExec, Runner, RUNNER_VERSION } from "./runner.js";
26
27
  import { Workspace } from "./workspace.js";
27
28
  const USAGE = `BeatOS Bridge runner ${RUNNER_VERSION}
@@ -89,6 +90,17 @@ async function main() {
89
90
  console.error("[bridge-runner] no agent set: connect this computer first with npx @beatos/bridge-runner pair <CODE> (or set agentName in ~/.beatos-runner/config.json)");
90
91
  return 2;
91
92
  }
93
+ // The agent must read and write these; a deny rule over them blocks every task.
94
+ const problems = agentPathProblems([
95
+ { label: "taskRoot", path: cfg.taskRoot },
96
+ { label: "worktreeRoot", path: cfg.worktreeRoot },
97
+ ], { protectPaths: cfg.protectPaths, stateDir: cfg.stateDir });
98
+ if (problems.length > 0) {
99
+ for (const p of problems)
100
+ console.error(`[bridge-runner] ${p.label} ${p.path} is blocked for the agent by: ${p.rule}`);
101
+ console.error("[bridge-runner] the agent could not read its own task there. Move it: set taskRoot and worktreeRoot in config.json to a folder outside ~/.beatos-runner and outside protectPaths (default: ~/beatos-runner-work).");
102
+ return 2;
103
+ }
92
104
  const lock = takeLock(cfg.stateDir);
93
105
  if (!lock) {
94
106
  console.error("[bridge-runner] another runner is already running on this computer");
package/dist/runner.js CHANGED
@@ -31,7 +31,7 @@ import { classifyError, retryDelaySeconds, sessionUsage, } from "./claude.js";
31
31
  import { Outbox } from "./outbox.js";
32
32
  import { decideAction } from "./policy.js";
33
33
  import { claudeArgs, sessionSettings, agentEnv } from "./safety.js";
34
- export const RUNNER_VERSION = "0.1.0";
34
+ export const RUNNER_VERSION = "0.1.1";
35
35
  /** A model name from Bridge goes into argv: plain names only. */
36
36
  const MODEL_RE = /^[A-Za-z0-9._-]{1,64}$/;
37
37
  const CLAIM_REFRESH_MS = 5 * 60_000;
@@ -491,7 +491,7 @@ export class Runner {
491
491
  place: rec.place,
492
492
  model: rec.model ?? this.d.cfg.model,
493
493
  rulesFile: join(rec.place.brief, "REGLAS.md"),
494
- settings: sessionSettings(rec.place, undefined, this.d.cfg.protectPaths),
494
+ settings: sessionSettings(rec.place, undefined, this.d.cfg.protectPaths, this.d.cfg.stateDir),
495
495
  prompt,
496
496
  ...(resume && rec.sessionId ? { resumeSessionId: rec.sessionId } : {}),
497
497
  });
package/dist/safety.js CHANGED
@@ -153,7 +153,7 @@ export function pathForms(tool, path) {
153
153
  rules.push(`${tool}(//${drive[1].toLowerCase()}/${drive[2]}/**)`);
154
154
  return rules;
155
155
  }
156
- export function denyRules(place, home = homedir(), protectPaths = []) {
156
+ export function denyRules(place, home = homedir(), protectPaths = [], stateDir) {
157
157
  const rules = [...ALWAYS_DENY, ...LOCAL_DENY];
158
158
  for (const rel of [...SECRET_PATHS, ...protectPaths])
159
159
  for (const tool of ["Read", "Edit", "Write"])
@@ -165,14 +165,76 @@ export function denyRules(place, home = homedir(), protectPaths = []) {
165
165
  for (const tool of ["Edit", "Write", "MultiEdit", "NotebookEdit"])
166
166
  rules.push(...pathForms(tool, place.projectPath));
167
167
  }
168
+ // The runner's own folder (key, config, outbox) also when BEATOS_RUNNER_HOME moves it.
169
+ if (stateDir)
170
+ for (const tool of ["Read", "Edit", "Write"])
171
+ rules.push(...pathForms(tool, stateDir));
168
172
  return rules;
169
173
  }
174
+ /** A home-relative deny glob as a regex over a home-relative posix path. */
175
+ function globRegex(glob, caseless) {
176
+ let re = "";
177
+ for (let i = 0; i < glob.length; i++) {
178
+ const c = glob[i];
179
+ if (c === "*" && glob[i + 1] === "*") {
180
+ i++;
181
+ if (glob[i + 1] === "/") {
182
+ i++;
183
+ re += "(?:.*/)?";
184
+ }
185
+ else
186
+ re += ".*";
187
+ }
188
+ else if (c === "*")
189
+ re += "[^/]*";
190
+ else
191
+ re += c.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
192
+ }
193
+ return new RegExp(`^${re}$`, caseless ? "i" : "");
194
+ }
195
+ const posixPath = (p) => p.replace(/\\/g, "/").replace(/\/+$/, "");
196
+ /**
197
+ * Checks the folders the agent works in (task briefs, git work copies)
198
+ * against every deny rule a session gets. A folder under a denied path
199
+ * would block every task, so the runner refuses to start instead.
200
+ */
201
+ export function agentPathProblems(folders, opts = {}) {
202
+ const caseless = (opts.platform ?? process.platform) === "win32";
203
+ const norm = (p) => (caseless ? posixPath(p).toLowerCase() : posixPath(p));
204
+ const home = norm(opts.home ?? homedir());
205
+ const homeRules = [
206
+ ...[...SECRET_PATHS, ...(opts.protectPaths ?? [])].map((g) => ({ g, rule: `~/${g} (no read, edit or write)` })),
207
+ ...CONTROL_PATHS.map((g) => ({ g, rule: `~/${g} (no edit or write)` })),
208
+ ];
209
+ const bashParts = ALWAYS_DENY.map((r) => /^Bash\(\*(.+)\*\)$/.exec(r)?.[1]).filter((x) => Boolean(x) && !x.includes("*") && !x.includes(" "));
210
+ const out = [];
211
+ for (const { label, path } of folders) {
212
+ const abs = norm(path);
213
+ const probe = `${abs}/TAREA.md`;
214
+ const add = (rule) => out.push({ label, path, rule });
215
+ if (opts.stateDir) {
216
+ const state = norm(opts.stateDir);
217
+ if (abs === state || abs.startsWith(`${state}/`))
218
+ add(`${opts.stateDir} (the runner's own folder)`);
219
+ }
220
+ if (probe.startsWith(`${home}/`)) {
221
+ const rel = probe.slice(home.length + 1);
222
+ for (const { g, rule } of homeRules)
223
+ if (globRegex(g, caseless).test(rel))
224
+ add(rule);
225
+ }
226
+ for (const part of bashParts)
227
+ if (abs.includes(caseless ? part.toLowerCase() : part))
228
+ add(`shell commands that mention ${part}`);
229
+ }
230
+ return out;
231
+ }
170
232
  /** The --settings every agent session starts with. */
171
- export function sessionSettings(place, home = homedir(), protectPaths = []) {
233
+ export function sessionSettings(place, home = homedir(), protectPaths = [], stateDir) {
172
234
  return {
173
235
  disableAllHooks: true,
174
236
  worktree: { bgIsolation: "none" },
175
- permissions: { deny: denyRules(place, home, protectPaths) },
237
+ permissions: { deny: denyRules(place, home, protectPaths, stateDir) },
176
238
  };
177
239
  }
178
240
  /** Everything but names that look like secrets (the runner's own key included). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beatos/bridge-runner",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "description": "BeatOS Bridge runner: a small program on your own computer that takes BeatOS tasks for your agent and works them with Claude Code. It only dials out to beatos.app.",
6
6
  "license": "MIT",