@beatos/bridge-runner 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/dist/safety.js ADDED
@@ -0,0 +1,201 @@
1
+ /**
2
+ * The box every agent session runs in (BEA-85). Ported from the older local
3
+ * dispatcher (advisor review 2026-10-04) without loosening anything, plus the
4
+ * Bridge v1 rules:
5
+ * - never skip permissions (Paperclip's adapter defaults to TRUE; we never
6
+ * pass --dangerously-skip-permissions, and a test fails if we ever do);
7
+ * - browser level 1 by default: --no-chrome AND a deny rule for the user's
8
+ * Chrome (a resume takes no flags, the rule still holds);
9
+ * - no MCP servers (--strict-mcp-config with an empty config);
10
+ * - no push, no gh, no deploy, no databases, no new packages, no secrets.
11
+ */
12
+ import { homedir } from "node:os";
13
+ export const ALWAYS_DENY = [
14
+ "PowerShell",
15
+ "AskUserQuestion",
16
+ "SendMessage",
17
+ "Workflow",
18
+ "Artifact",
19
+ "ArtifactComments",
20
+ "ArtifactData",
21
+ "EnterWorktree",
22
+ "ExitWorktree",
23
+ "RemoteTrigger",
24
+ "CronCreate",
25
+ "ScheduleWakeup",
26
+ "PushNotification",
27
+ "SendUserFile",
28
+ // The user's own Chrome, with every site they are logged in to. --strict-mcp-config
29
+ // does not turn it off (DAN-249, 2026-10-05), so it is denied by name too.
30
+ "mcp__claude-in-chrome",
31
+ // git and GitHub: the runner pushes, the agent only commits in its own clone
32
+ "Bash(git push*)",
33
+ "Bash(git -C *)",
34
+ "Bash(git remote*)",
35
+ "Bash(git config*)",
36
+ "Bash(git clone*)",
37
+ "Bash(git worktree*)",
38
+ "Bash(git update-ref*)",
39
+ "Bash(git branch -D*)",
40
+ "Bash(git branch -f*)",
41
+ "Bash(git branch --force*)",
42
+ "Bash(*git-credential*)",
43
+ "Bash(*.git/hooks*)",
44
+ "Bash(*.git/config*)",
45
+ "Bash(gh *)",
46
+ "Bash(*gh.exe*)",
47
+ // deploys, publishing, databases, other machines
48
+ "Bash(gcloud*)",
49
+ "Bash(vercel*)",
50
+ "Bash(npx vercel*)",
51
+ "Bash(netlify*)",
52
+ "Bash(wrangler*)",
53
+ "Bash(npx wrangler*)",
54
+ "Bash(fly *)",
55
+ "Bash(flyctl*)",
56
+ "Bash(kubectl*)",
57
+ "Bash(terraform*)",
58
+ "Bash(docker push*)",
59
+ "Bash(firebase deploy*)",
60
+ "Bash(npm publish*)",
61
+ "Bash(pnpm publish*)",
62
+ "Bash(yarn publish*)",
63
+ "Bash(psql*)",
64
+ "Bash(*drizzle-kit push*)",
65
+ "Bash(*drizzle-kit migrate*)",
66
+ "Bash(*db:push*)",
67
+ "Bash(*db:migrate*)",
68
+ "Bash(*apply-*-prod*)",
69
+ "Bash(ssh *)",
70
+ "Bash(scp *)",
71
+ "Bash(rsync *)",
72
+ // new packages run their install scripts as the user: only the lockfile's packages
73
+ "Bash(npm install *)",
74
+ "Bash(npm i *)",
75
+ "Bash(pnpm add*)",
76
+ "Bash(yarn add*)",
77
+ "Bash(pip install*)",
78
+ "Bash(uv pip install*)",
79
+ "Bash(uv add*)",
80
+ "Bash(uvx*)",
81
+ "Bash(pipx*)",
82
+ "Bash(npx -y*)",
83
+ "Bash(npx --yes*)",
84
+ "Bash(bunx*)",
85
+ "Bash(winget*)",
86
+ "Bash(choco*)",
87
+ "Bash(scoop*)",
88
+ // secrets in files
89
+ "Bash(*.env*)",
90
+ "Bash(*credentials*)",
91
+ "Bash(*CREDENTIALS*)",
92
+ "Bash(*.ssh*)",
93
+ "Bash(*.claude.json*)",
94
+ "Bash(*hosts.yml*)",
95
+ "Bash(*token.txt*)",
96
+ "Bash(*.pem*)",
97
+ "Bash(*.npmrc*)",
98
+ "Bash(*.beatos-runner*)",
99
+ // local voice servers, other agents, the machine
100
+ "Bash(*localhost:31337*)",
101
+ "Bash(*127.0.0.1:31337*)",
102
+ "Bash(*localhost:8888*)",
103
+ "Bash(*127.0.0.1:8888*)",
104
+ "Bash(claude *)",
105
+ "Bash(*claude.exe*)",
106
+ "Bash(schtasks*)",
107
+ "Bash(reg *)",
108
+ "Bash(setx*)",
109
+ "Bash(shutdown*)",
110
+ ];
111
+ /** Under the home folder. Secrets: no Read, Edit or Write. */
112
+ export const SECRET_PATHS = [
113
+ ".claude/**/.env",
114
+ ".claude/**/CREDENTIALS/**",
115
+ ".claude/.credentials.json",
116
+ ".claude.json",
117
+ ".ssh/**",
118
+ ".aws/**",
119
+ ".docker/**",
120
+ ".npmrc",
121
+ ".git-credentials",
122
+ ".config/gh/**",
123
+ "AppData/Roaming/GitHub CLI/**",
124
+ ".beatos-runner/**",
125
+ "projects/**/*.pem",
126
+ "projects/**/.env*",
127
+ ];
128
+ /** Under the home folder. Control plane: no Edit or Write. */
129
+ export const CONTROL_PATHS = [".claude/**"];
130
+ /** Relative to the session's working folder: its own clone's .git and Claude settings. */
131
+ export const LOCAL_DENY = [
132
+ "Read(**/.env*)",
133
+ "Edit(**/.git/**)",
134
+ "Write(**/.git/**)",
135
+ "Edit(**/.claude/**)",
136
+ "Write(**/.claude/**)",
137
+ ];
138
+ const SECRET_ENV = /KEY|TOKEN|SECRET|PASS|CRED|AUTH/i;
139
+ /** A home-relative path rule in both forms Claude Code matches on Windows. */
140
+ export function homeForms(tool, rel, home = homedir()) {
141
+ const h = home.replace(/\\/g, "/");
142
+ const rules = [`${tool}(~/${rel})`];
143
+ const drive = /^([A-Za-z]):\/(.*)$/.exec(h);
144
+ if (drive)
145
+ rules.push(`${tool}(//${drive[1].toLowerCase()}/${drive[2]}/${rel})`);
146
+ return rules;
147
+ }
148
+ export function pathForms(tool, path) {
149
+ const posix = path.replace(/\\/g, "/").replace(/\/+$/, "");
150
+ const rules = [`${tool}(${posix}/**)`];
151
+ const drive = /^([A-Za-z]):\/(.*)$/.exec(posix);
152
+ if (drive)
153
+ rules.push(`${tool}(//${drive[1].toLowerCase()}/${drive[2]}/**)`);
154
+ return rules;
155
+ }
156
+ export function denyRules(place, home = homedir(), protectPaths = []) {
157
+ const rules = [...ALWAYS_DENY, ...LOCAL_DENY];
158
+ for (const rel of [...SECRET_PATHS, ...protectPaths])
159
+ for (const tool of ["Read", "Edit", "Write"])
160
+ rules.push(...homeForms(tool, rel, home));
161
+ for (const rel of CONTROL_PATHS)
162
+ for (const tool of ["Edit", "Write", "MultiEdit", "NotebookEdit"])
163
+ rules.push(...homeForms(tool, rel, home));
164
+ if ((place.mode === "git" || place.mode === "folder") && place.projectPath) {
165
+ for (const tool of ["Edit", "Write", "MultiEdit", "NotebookEdit"])
166
+ rules.push(...pathForms(tool, place.projectPath));
167
+ }
168
+ return rules;
169
+ }
170
+ /** The --settings every agent session starts with. */
171
+ export function sessionSettings(place, home = homedir(), protectPaths = []) {
172
+ return {
173
+ disableAllHooks: true,
174
+ worktree: { bgIsolation: "none" },
175
+ permissions: { deny: denyRules(place, home, protectPaths) },
176
+ };
177
+ }
178
+ /** Everything but names that look like secrets (the runner's own key included). */
179
+ export function agentEnv(env = process.env) {
180
+ const out = {};
181
+ for (const [k, v] of Object.entries(env))
182
+ if (v !== undefined && !SECRET_ENV.test(k))
183
+ out[k] = v;
184
+ return out;
185
+ }
186
+ /**
187
+ * argv for `claude -p` in stream-json mode. Task text never travels in argv
188
+ * (it arrives broken on Windows): the prompt is ASCII and points at files.
189
+ */
190
+ export function claudeArgs(i) {
191
+ if (!/^[\x20-\x7e]*$/.test(i.prompt))
192
+ throw new Error("prompt must be printable ASCII");
193
+ const argv = ["-p", "--output-format", "stream-json", "--verbose", "--model", i.model];
194
+ if (i.resumeSessionId)
195
+ argv.push("--resume", i.resumeSessionId);
196
+ argv.push("--permission-mode", "auto", "--settings", JSON.stringify(i.settings), "--strict-mcp-config", "--mcp-config", '{"mcpServers":{}}', "--no-chrome", "--append-system-prompt-file", i.rulesFile);
197
+ if (i.place.addDirs.length > 0)
198
+ argv.push("--add-dir", ...i.place.addDirs);
199
+ argv.push("--", i.prompt); // --add-dir and --mcp-config take many values and would eat the prompt
200
+ return argv;
201
+ }
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Where one task's session works (BEA-85), ported from the older local dispatcher.
3
+ * - git: a separate local clone with its own .git, push URL "no_push",
4
+ * on branch local-ai/<CODE>. The agent only commits there. With
5
+ * pushPr the RUNNER (never the agent) pushes and opens the PR.
6
+ * - folder: the project folder is read only; the agent writes in its task folder.
7
+ * - none: only the task folder.
8
+ * Merge and deploy always stay with the human.
9
+ */
10
+ import { execFileSync } from "node:child_process";
11
+ import { existsSync, mkdirSync } from "node:fs";
12
+ import { basename, join } from "node:path";
13
+ import { agentEnv } from "./safety.js";
14
+ export const realGit = (cwd, ...args) => execFileSync("git", ["-C", cwd, ...args], {
15
+ encoding: "utf8",
16
+ timeout: 300_000,
17
+ windowsHide: true,
18
+ }).trim();
19
+ export const realGh = (args, env) => execFileSync("gh", args, { encoding: "utf8", timeout: 120_000, env, windowsHide: true }).trim();
20
+ export function githubRepo(url) {
21
+ const m = /github\.com[/:]([^/]+\/[^/.]+?)(?:\.git)?\/?$/.exec(url.trim());
22
+ return m ? m[1] : null;
23
+ }
24
+ export class Workspace {
25
+ cfg;
26
+ git;
27
+ gh;
28
+ constructor(cfg, git = realGit, gh = realGh) {
29
+ this.cfg = cfg;
30
+ this.git = git;
31
+ this.gh = gh;
32
+ }
33
+ prepare(code, project) {
34
+ const brief = join(this.cfg.taskRoot, code);
35
+ mkdirSync(brief, { recursive: true });
36
+ const place = {
37
+ cwd: brief,
38
+ brief,
39
+ mode: "none",
40
+ projectPath: "",
41
+ branch: "",
42
+ base: "",
43
+ pushPr: false,
44
+ addDirs: [],
45
+ };
46
+ if (project?.mode === "git" && project.path) {
47
+ const cwd = join(this.cfg.worktreeRoot, `${basename(project.path)}-${code}`);
48
+ const branch = `local-ai/${code}`;
49
+ const base = this.baseBranch(project.path);
50
+ if (!existsSync(join(cwd, ".git")))
51
+ this.clone(project.path, cwd, branch, base);
52
+ return {
53
+ ...place,
54
+ cwd,
55
+ mode: "git",
56
+ projectPath: project.path,
57
+ branch,
58
+ base,
59
+ pushPr: Boolean(project.pushPr),
60
+ addDirs: [brief],
61
+ };
62
+ }
63
+ if (project?.mode === "folder" && project.path) {
64
+ return { ...place, mode: "folder", projectPath: project.path, addDirs: [project.path] };
65
+ }
66
+ return place;
67
+ }
68
+ clone(repo, cwd, branch, base) {
69
+ mkdirSync(this.cfg.worktreeRoot, { recursive: true });
70
+ const url = this.git(repo, "remote", "get-url", "origin");
71
+ this.git(this.cfg.worktreeRoot, "clone", "--local", "--no-checkout", "--quiet", repo, cwd);
72
+ this.git(cwd, "remote", "set-url", "origin", url);
73
+ this.git(cwd, "remote", "set-url", "--push", "origin", "no_push");
74
+ try {
75
+ this.git(cwd, "fetch", "origin", "--quiet", "--prune");
76
+ }
77
+ catch {
78
+ // offline: start from the local copy of the base branch
79
+ }
80
+ const start = this.hasRef(cwd, `refs/remotes/origin/${branch}`)
81
+ ? `origin/${branch}`
82
+ : `origin/${base}`;
83
+ this.git(cwd, "checkout", "--quiet", "-b", branch, start);
84
+ }
85
+ hasRef(repo, ref) {
86
+ try {
87
+ this.git(repo, "rev-parse", "--verify", "--quiet", ref);
88
+ return true;
89
+ }
90
+ catch {
91
+ return false;
92
+ }
93
+ }
94
+ baseBranch(repo) {
95
+ try {
96
+ const head = this.git(repo, "symbolic-ref", "--short", "refs/remotes/origin/HEAD");
97
+ return head.includes("/") ? head.split("/").slice(1).join("/") : "main";
98
+ }
99
+ catch {
100
+ return "main";
101
+ }
102
+ }
103
+ /** Push the agent's branch and open (or find) its PR. Runs in the runner, never in the agent. */
104
+ publish(place, title, body) {
105
+ const out = {
106
+ pushed: false,
107
+ pr: "",
108
+ dirty: Boolean(this.git(place.cwd, "status", "--porcelain")),
109
+ };
110
+ if (["", "0"].includes(this.git(place.cwd, "rev-list", "--count", `origin/${place.base}..${place.branch}`)))
111
+ return out;
112
+ const url = this.git(place.cwd, "remote", "get-url", "origin"); // the fetch URL; push URL is no_push
113
+ this.git(place.cwd, "push", "--no-verify", "--quiet", url, `${place.branch}:refs/heads/${place.branch}`);
114
+ out.pushed = true;
115
+ const repo = githubRepo(url);
116
+ if (!repo)
117
+ return out;
118
+ const env = { ...agentEnv(), ...(this.cfg.ghUser ? { GH_TOKEN: this.ghToken() } : {}) };
119
+ const existing = this.gh([
120
+ "pr",
121
+ "list",
122
+ "--repo",
123
+ repo,
124
+ "--head",
125
+ place.branch,
126
+ "--state",
127
+ "open",
128
+ "--json",
129
+ "url",
130
+ "--jq",
131
+ ".[0].url",
132
+ ], env);
133
+ out.pr =
134
+ existing ||
135
+ this.gh([
136
+ "pr",
137
+ "create",
138
+ "--repo",
139
+ repo,
140
+ "--base",
141
+ place.base,
142
+ "--head",
143
+ place.branch,
144
+ "--title",
145
+ title,
146
+ "--body",
147
+ body,
148
+ ], env)
149
+ .split("\n")
150
+ .pop() ||
151
+ "";
152
+ return out;
153
+ }
154
+ ghToken() {
155
+ return execFileSync("gh", ["auth", "token", "--user", this.cfg.ghUser], {
156
+ encoding: "utf8",
157
+ timeout: 60_000,
158
+ windowsHide: true,
159
+ }).trim();
160
+ }
161
+ }
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
2
  "name": "@beatos/bridge-runner",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "type": "module",
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
+ "license": "MIT",
7
+ "homepage": "https://github.com/Gordon-Web-Studio/beatos-bridge-runner#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/Gordon-Web-Studio/beatos-bridge-runner.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/Gordon-Web-Studio/beatos-bridge-runner/issues"
14
+ },
15
+ "keywords": [
16
+ "beatos",
17
+ "bridge",
18
+ "runner",
19
+ "claude-code"
20
+ ],
21
+ "bin": {
22
+ "beatos-runner": "dist/main.js"
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "README.md",
27
+ "LICENSE"
28
+ ],
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "scripts": {
33
+ "start": "node --experimental-strip-types --disable-warning=ExperimentalWarning src/main.ts",
34
+ "build": "node scripts/build.mjs",
35
+ "prepublishOnly": "npm run build && npm test",
36
+ "lint": "eslint .",
37
+ "typecheck": "tsc --noEmit",
38
+ "test": "vitest run",
39
+ "test:coverage": "vitest run --coverage",
40
+ "pack:check": "npm pack --dry-run"
41
+ },
42
+ "devDependencies": {
43
+ "@eslint/js": "^9.39.5",
44
+ "@types/node": "^22",
45
+ "@vitest/coverage-v8": "^4.1.6",
46
+ "eslint": "^9.39.5",
47
+ "typescript": "^5",
48
+ "typescript-eslint": "^8.71.2",
49
+ "vitest": "^4.1.6"
50
+ },
51
+ "engines": {
52
+ "node": ">=22.6"
53
+ },
54
+ "packageManager": "pnpm@11.9.0"
55
+ }