@beatos/bridge-runner 0.4.0 → 0.5.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 +30 -1
- package/dist/api.js +14 -2
- package/dist/config.js +6 -1
- package/dist/folders.js +211 -0
- package/dist/main.js +2 -0
- package/dist/runner.js +62 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -185,6 +185,7 @@ Full example:
|
|
|
185
185
|
"pollSeconds": 30,
|
|
186
186
|
"ghUser": "your-github-user",
|
|
187
187
|
"protectPaths": ["projects/my-secrets/**", "Documents/taxes/**"],
|
|
188
|
+
"folderRoots": ["~/projects", "/home/you/code"],
|
|
188
189
|
"projects": {
|
|
189
190
|
"<beatos project id>": { "name": "My app", "mode": "git", "path": "/home/you/code/my-app", "pushPr": true },
|
|
190
191
|
"<another project id>": { "mode": "folder", "path": "/home/you/notes" },
|
|
@@ -213,7 +214,8 @@ Every field:
|
|
|
213
214
|
| `claudePath` | string | found by itself | The Claude Code program. `BEATOS_RUNNER_CLAUDE` also sets it. |
|
|
214
215
|
| `ghUser` | string | none | The GitHub CLI account the runner uses to push and open pull requests. |
|
|
215
216
|
| `protectPaths` | string array | `[]` | More folders the agent may not read or change. See the next section. |
|
|
216
|
-
| `
|
|
217
|
+
| `folderRoots` | string array | `["~/projects"]` | Where the runner looks for folders to offer on beatos.app. Full paths; `~` is expanded here. Only the direct child folders of each root are listed. Roots that do not exist are skipped. See [Connect folders from beatos.app](#connect-folders-from-beatosapp). |
|
|
218
|
+
| `projects` | object | `{}` | Where the agent works for each BeatOS project. See [Projects](#projects-where-the-agent-works). Wins over a folder picked on beatos.app. |
|
|
217
219
|
|
|
218
220
|
## Protect your private folders (protectPaths)
|
|
219
221
|
|
|
@@ -277,6 +279,33 @@ How to check it works:
|
|
|
277
279
|
A task from a project that is not listed works in a scratch folder in
|
|
278
280
|
`~/beatos-runner-work/tasks/<TASK>`.
|
|
279
281
|
|
|
282
|
+
### Connect folders from beatos.app
|
|
283
|
+
|
|
284
|
+
Runner 0.5.0 and newer: you do not have to edit `config.json` to connect a
|
|
285
|
+
project to a folder.
|
|
286
|
+
|
|
287
|
+
1. The runner lists the folders in its roots (`folderRoots`, default
|
|
288
|
+
`~/projects`) and sends the list to beatos.app: the name, the path
|
|
289
|
+
(`~/...` under your home folder) and if the folder has a `.git`. Never file
|
|
290
|
+
contents. Hidden folders, folders under a denied path (the secret folders,
|
|
291
|
+
`protectPaths`, `~/.beatos-runner`) and the runner's work folders are not
|
|
292
|
+
in the list. At most 300 folders.
|
|
293
|
+
2. In Bridge, Runners, click the runner. Under "Project folders", pick the
|
|
294
|
+
folder for each project and the mode: "Read only" (`folder`), "Git copy"
|
|
295
|
+
(`git`) or "Never take tasks" (`exclude`). Save.
|
|
296
|
+
3. The runner uses the pick on the next task of that project.
|
|
297
|
+
|
|
298
|
+
Rules:
|
|
299
|
+
|
|
300
|
+
- A project set in `config.json` wins. Bridge shows it as set on this computer.
|
|
301
|
+
- The runner uses a pick only when it listed that folder itself in its last
|
|
302
|
+
scan, the folder is still there (a real folder, not a link) and it is not
|
|
303
|
+
under a denied path. Otherwise it ignores the pick and writes one log line.
|
|
304
|
+
beatos.app can never send the agent to another folder.
|
|
305
|
+
- A pick from beatos.app never pushes: `pushPr` is set only in `config.json`.
|
|
306
|
+
- To offer folders from another place, add it to `folderRoots` and restart the
|
|
307
|
+
runner.
|
|
308
|
+
|
|
280
309
|
## Project context and memory
|
|
281
310
|
|
|
282
311
|
Runner 0.3.0 and newer read the task's project from beatos.app at the start of
|
package/dist/api.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BeatOS REST client for the runner (BEA-85). Every call carries the runner's
|
|
3
|
+
* agent key (Bearer) and x-agent-client, so BeatOS stamps the agent on claims,
|
|
4
|
+
* comments and runs. The key is never printed, logged or put in an error.
|
|
5
|
+
*/
|
|
6
|
+
import { parseProjectFolders } from "./folders.js";
|
|
1
7
|
export class ApiError extends Error {
|
|
2
8
|
status;
|
|
3
9
|
code;
|
|
@@ -173,8 +179,14 @@ export class BeatosApi {
|
|
|
173
179
|
warn("project context not available (bad reply), using the brief without it");
|
|
174
180
|
return ctx;
|
|
175
181
|
}
|
|
176
|
-
heartbeat(body) {
|
|
177
|
-
|
|
182
|
+
async heartbeat(body) {
|
|
183
|
+
const r = await this.call("POST", "/api/v1/bridge/runner/heartbeat", body);
|
|
184
|
+
const { folders, project_folders, ...rest } = r;
|
|
185
|
+
return {
|
|
186
|
+
...rest,
|
|
187
|
+
...(isObj(folders) ? { folders: { send: folders.send === true } } : {}),
|
|
188
|
+
project_folders: parseProjectFolders(project_folders),
|
|
189
|
+
};
|
|
178
190
|
}
|
|
179
191
|
createRun(body) {
|
|
180
192
|
return this.call("POST", "/api/v1/bridge/runner/runs", body);
|
package/dist/config.js
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
8
8
|
import { homedir, hostname } from "node:os";
|
|
9
|
-
import { dirname, join } from "node:path";
|
|
9
|
+
import { dirname, isAbsolute, join } from "node:path";
|
|
10
|
+
import { expandHome } from "./folders.js";
|
|
10
11
|
/**
|
|
11
12
|
* The real Claude Code executable. On Windows the npm `claude.cmd` shim cannot
|
|
12
13
|
* be spawned without a shell and mangles multi-line arguments, so look for
|
|
@@ -69,6 +70,10 @@ export function loadConfig(env = process.env) {
|
|
|
69
70
|
claudePath: raw.claudePath ?? findClaude(env),
|
|
70
71
|
ghUser: raw.ghUser,
|
|
71
72
|
protectPaths: Array.isArray(raw.protectPaths) ? raw.protectPaths.filter((p) => typeof p === "string") : [],
|
|
73
|
+
folderRoots: (Array.isArray(raw.folderRoots) ? raw.folderRoots : ["~/projects"])
|
|
74
|
+
.filter((p) => typeof p === "string")
|
|
75
|
+
.map((p) => expandHome(p))
|
|
76
|
+
.filter((p) => isAbsolute(p)),
|
|
72
77
|
projects: raw.projects ?? {},
|
|
73
78
|
};
|
|
74
79
|
}
|
package/dist/folders.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project folders from beatos.app (BEA-96 slice 3): connect a BeatOS project to
|
|
3
|
+
* a folder on this computer without editing config.json.
|
|
4
|
+
*
|
|
5
|
+
* The runner lists the direct child folders of its roots (folderRoots in
|
|
6
|
+
* config.json, default ~/projects) and sends that list. The owner picks a
|
|
7
|
+
* folder per project on beatos.app, and the heartbeat reply carries the picks.
|
|
8
|
+
*
|
|
9
|
+
* Rules that never change:
|
|
10
|
+
* - roots come only from config.json on this computer;
|
|
11
|
+
* - a pick from beatos.app is used only when its path is one the runner
|
|
12
|
+
* listed in its last scan (exact match, the runner's own full path is used,
|
|
13
|
+
* never the text from the server), the folder is still a real folder (not a
|
|
14
|
+
* link), and it is not under a denied path (checked again at use time);
|
|
15
|
+
* - config.json wins for a project it sets;
|
|
16
|
+
* - pushPr from beatos.app is always false;
|
|
17
|
+
* - names, paths and "has .git" only: never file contents.
|
|
18
|
+
*/
|
|
19
|
+
import { existsSync, lstatSync, readdirSync } from "node:fs";
|
|
20
|
+
import { homedir } from "node:os";
|
|
21
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
22
|
+
import { agentPathProblems } from "./safety.js";
|
|
23
|
+
export const FOLDERS_MAX = 300;
|
|
24
|
+
const NAME_MAX = 200;
|
|
25
|
+
const PATH_MAX = 500;
|
|
26
|
+
const MAPPINGS_MAX = 500;
|
|
27
|
+
const posix = (p) => p.replace(/\\/g, "/").replace(/\/+$/, "");
|
|
28
|
+
const caseless = (platform) => platform === "win32";
|
|
29
|
+
/** "~" and "~/x" in a config root become the home folder; other paths stay as they are. */
|
|
30
|
+
export function expandHome(p, home = homedir()) {
|
|
31
|
+
if (p === "~")
|
|
32
|
+
return home;
|
|
33
|
+
if (p.startsWith("~/") || p.startsWith("~\\"))
|
|
34
|
+
return join(home, p.slice(2));
|
|
35
|
+
return p;
|
|
36
|
+
}
|
|
37
|
+
/** "~/projects/x" for a path under home, else the full path with forward slashes. */
|
|
38
|
+
export function displayPath(abs, home = homedir(), platform = process.platform) {
|
|
39
|
+
const a = posix(abs);
|
|
40
|
+
const h = posix(home);
|
|
41
|
+
const eq = (x, y) => (caseless(platform) ? x.toLowerCase() === y.toLowerCase() : x === y);
|
|
42
|
+
if (eq(a, h))
|
|
43
|
+
return "~";
|
|
44
|
+
if (a.length > h.length && eq(a.slice(0, h.length + 1), `${h}/`))
|
|
45
|
+
return `~/${a.slice(h.length + 1)}`;
|
|
46
|
+
return a;
|
|
47
|
+
}
|
|
48
|
+
/** True when a is b or inside it. */
|
|
49
|
+
function within(a, b, platform) {
|
|
50
|
+
const x = caseless(platform) ? posix(a).toLowerCase() : posix(a);
|
|
51
|
+
const y = caseless(platform) ? posix(b).toLowerCase() : posix(b);
|
|
52
|
+
return x === y || x.startsWith(`${y}/`);
|
|
53
|
+
}
|
|
54
|
+
/** The same deny rules a session gets: secret paths, protectPaths, the state folder. */
|
|
55
|
+
export function deniedFolder(abs, cfg, home = homedir(), platform = process.platform) {
|
|
56
|
+
return (agentPathProblems([{ label: "folder", path: abs }], {
|
|
57
|
+
home,
|
|
58
|
+
protectPaths: cfg.protectPaths,
|
|
59
|
+
stateDir: cfg.stateDir,
|
|
60
|
+
platform,
|
|
61
|
+
}).length > 0);
|
|
62
|
+
}
|
|
63
|
+
/** A real folder, not a link or a junction. */
|
|
64
|
+
function realDir(p) {
|
|
65
|
+
try {
|
|
66
|
+
return lstatSync(p).isDirectory();
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function childDirs(p) {
|
|
73
|
+
try {
|
|
74
|
+
return readdirSync(p, { withFileTypes: true })
|
|
75
|
+
.filter((d) => d.isDirectory() && !d.isSymbolicLink())
|
|
76
|
+
.map((d) => d.name)
|
|
77
|
+
.sort();
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** Lists the folders the runner may offer. Never reads a file. */
|
|
84
|
+
export function scanFolders(cfg, home = homedir(), platform = process.platform) {
|
|
85
|
+
const roots = [];
|
|
86
|
+
const items = [];
|
|
87
|
+
const paths = new Map();
|
|
88
|
+
const workDirs = [cfg.taskRoot, cfg.worktreeRoot, cfg.stateDir];
|
|
89
|
+
for (const raw of cfg.folderRoots) {
|
|
90
|
+
if (!isAbsolute(raw))
|
|
91
|
+
continue;
|
|
92
|
+
const root = resolve(raw);
|
|
93
|
+
if (!realDir(root))
|
|
94
|
+
continue;
|
|
95
|
+
const shownRoot = displayPath(root, home, platform);
|
|
96
|
+
if (roots.includes(shownRoot))
|
|
97
|
+
continue;
|
|
98
|
+
roots.push(shownRoot);
|
|
99
|
+
for (const name of childDirs(root)) {
|
|
100
|
+
if (items.length >= FOLDERS_MAX)
|
|
101
|
+
break;
|
|
102
|
+
if (name.startsWith(".") || name.length > NAME_MAX)
|
|
103
|
+
continue;
|
|
104
|
+
const abs = join(root, name);
|
|
105
|
+
const shown = displayPath(abs, home, platform);
|
|
106
|
+
if (shown.length > PATH_MAX || paths.has(shown))
|
|
107
|
+
continue;
|
|
108
|
+
// The runner's own work and state folders, and any folder that holds one.
|
|
109
|
+
if (workDirs.some((w) => within(abs, w, platform) || within(w, abs, platform)))
|
|
110
|
+
continue;
|
|
111
|
+
if (deniedFolder(abs, cfg, home, platform))
|
|
112
|
+
continue;
|
|
113
|
+
paths.set(shown, abs);
|
|
114
|
+
items.push({ name, path: shown, git: existsSync(join(abs, ".git")) });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
report: { version: 1, roots, items, config_projects: Object.keys(cfg.projects) },
|
|
119
|
+
paths,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const PROJECT_ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
123
|
+
/** A control character (a new line could fake a log line). */
|
|
124
|
+
const hasControl = (s) => [...s].some((c) => c.charCodeAt(0) < 32 || c.charCodeAt(0) === 127);
|
|
125
|
+
/** The picks in a heartbeat reply, bad items dropped; undefined when the server sent none (older server). */
|
|
126
|
+
export function parseProjectFolders(raw) {
|
|
127
|
+
if (!Array.isArray(raw))
|
|
128
|
+
return undefined;
|
|
129
|
+
const out = [];
|
|
130
|
+
const seen = new Set();
|
|
131
|
+
for (const m of raw) {
|
|
132
|
+
if (out.length >= MAPPINGS_MAX)
|
|
133
|
+
break;
|
|
134
|
+
if (typeof m !== "object" || m === null)
|
|
135
|
+
continue;
|
|
136
|
+
const { project_id: id, path, mode } = m;
|
|
137
|
+
if (typeof id !== "string" || !PROJECT_ID.test(id) || seen.has(id))
|
|
138
|
+
continue;
|
|
139
|
+
if (mode === "exclude") {
|
|
140
|
+
seen.add(id);
|
|
141
|
+
out.push({ project_id: id, path: null, mode });
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (mode !== "folder" && mode !== "git")
|
|
145
|
+
continue;
|
|
146
|
+
if (typeof path !== "string" || !path || path.length > PATH_MAX || hasControl(path))
|
|
147
|
+
continue;
|
|
148
|
+
seen.add(id);
|
|
149
|
+
out.push({ project_id: id, path, mode });
|
|
150
|
+
}
|
|
151
|
+
return out;
|
|
152
|
+
}
|
|
153
|
+
/** The runner's view of project folders: the last scan, the picks, and the merge with config.json. */
|
|
154
|
+
export class ProjectFolders {
|
|
155
|
+
cfg;
|
|
156
|
+
home;
|
|
157
|
+
platform;
|
|
158
|
+
log;
|
|
159
|
+
paths = new Map();
|
|
160
|
+
web = new Map();
|
|
161
|
+
/** The last line logged per project, so a tick does not repeat it. */
|
|
162
|
+
said = new Map();
|
|
163
|
+
constructor(opts) {
|
|
164
|
+
this.cfg = opts.cfg;
|
|
165
|
+
this.home = opts.home ?? homedir();
|
|
166
|
+
this.platform = opts.platform ?? process.platform;
|
|
167
|
+
this.log = opts.log ?? (() => undefined);
|
|
168
|
+
}
|
|
169
|
+
scan() {
|
|
170
|
+
const s = scanFolders(this.cfg, this.home, this.platform);
|
|
171
|
+
this.paths = s.paths;
|
|
172
|
+
return s.report;
|
|
173
|
+
}
|
|
174
|
+
/** undefined = an older server: config.json only. */
|
|
175
|
+
setWeb(list) {
|
|
176
|
+
this.web = new Map((list ?? []).map((m) => [m.project_id, m]));
|
|
177
|
+
}
|
|
178
|
+
say(id, msg) {
|
|
179
|
+
if (this.said.get(id) === msg)
|
|
180
|
+
return;
|
|
181
|
+
this.said.set(id, msg);
|
|
182
|
+
this.log(msg);
|
|
183
|
+
}
|
|
184
|
+
ignore(id, why) {
|
|
185
|
+
this.say(id, `project ${id}: folder from beatos.app ignored (${why})`);
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
projectFor(id) {
|
|
189
|
+
const local = this.cfg.projects[id];
|
|
190
|
+
if (local)
|
|
191
|
+
return local;
|
|
192
|
+
const m = this.web.get(id);
|
|
193
|
+
if (!m)
|
|
194
|
+
return undefined;
|
|
195
|
+
if (m.mode === "exclude") {
|
|
196
|
+
this.say(id, `project ${id}: never takes tasks (set on beatos.app)`);
|
|
197
|
+
return { mode: "exclude" };
|
|
198
|
+
}
|
|
199
|
+
const shown = m.path ?? "";
|
|
200
|
+
// The runner's own path from its scan: the server's text is only a key.
|
|
201
|
+
const abs = this.paths.get(shown);
|
|
202
|
+
if (!abs)
|
|
203
|
+
return this.ignore(id, `${shown} is not in the last folder list`);
|
|
204
|
+
if (!realDir(abs))
|
|
205
|
+
return this.ignore(id, `${shown} is gone`);
|
|
206
|
+
if (deniedFolder(abs, this.cfg, this.home, this.platform))
|
|
207
|
+
return this.ignore(id, `${shown} is under a denied path`);
|
|
208
|
+
this.say(id, `project ${id}: folder from beatos.app (${shown}, ${m.mode})`);
|
|
209
|
+
return { mode: m.mode, path: abs, pushPr: false };
|
|
210
|
+
}
|
|
211
|
+
}
|
package/dist/main.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* mid-session continues the same session, and every saved event is sent, on
|
|
17
17
|
* the next start.
|
|
18
18
|
*/
|
|
19
|
+
import { ProjectFolders } from "./folders.js";
|
|
19
20
|
import { scanInventory } from "./inventory.js";
|
|
20
21
|
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, rmSync, writeFileSync, } from "node:fs";
|
|
21
22
|
import { join } from "node:path";
|
|
@@ -114,6 +115,7 @@ async function main() {
|
|
|
114
115
|
workspace: new Workspace(cfg),
|
|
115
116
|
claude: makeClaudeExec(cfg, runClaude),
|
|
116
117
|
inventory: () => scanInventory(),
|
|
118
|
+
folders: new ProjectFolders({ cfg, log: (m) => console.log(`[bridge-runner] ${m}`) }),
|
|
117
119
|
});
|
|
118
120
|
console.log(`[bridge-runner] ${cfg.runnerName} -> ${cfg.beatosUrl} as ${cfg.agentName}, every ${cfg.pollSeconds}s`);
|
|
119
121
|
let stop = false;
|
package/dist/runner.js
CHANGED
|
@@ -25,6 +25,9 @@
|
|
|
25
25
|
* from BeatOS go into TAREA.md, and the agent's APRENDIDO lines ride on the
|
|
26
26
|
* finish event as proposed facts for the next runs. Slice 2: up to 5 Vault
|
|
27
27
|
* notes (linked to the project, then found by the task title) go in too.
|
|
28
|
+
* Slice 3: the owner connects projects to folders on beatos.app; the runner
|
|
29
|
+
* lists the folders of its own roots and uses a pick only when it listed that
|
|
30
|
+
* folder itself (folders.ts). config.json still wins.
|
|
28
31
|
*/
|
|
29
32
|
import { createHash } from "node:crypto";
|
|
30
33
|
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
@@ -36,7 +39,7 @@ import { classifyError, retryDelaySeconds, sessionUsage, } from "./claude.js";
|
|
|
36
39
|
import { Outbox } from "./outbox.js";
|
|
37
40
|
import { decideAction } from "./policy.js";
|
|
38
41
|
import { claudeArgs, sessionSettings, agentEnv } from "./safety.js";
|
|
39
|
-
export const RUNNER_VERSION = "0.
|
|
42
|
+
export const RUNNER_VERSION = "0.5.0";
|
|
40
43
|
/** A model name from Bridge goes into argv: plain names only. */
|
|
41
44
|
const MODEL_RE = /^[A-Za-z0-9._-]{1,64}$/;
|
|
42
45
|
const CLAIM_REFRESH_MS = 5 * 60_000;
|
|
@@ -62,6 +65,12 @@ export class Runner {
|
|
|
62
65
|
runnerStatus = "active";
|
|
63
66
|
/** No new inventory read before this time (1 h after a send, 10 min after a failure). */
|
|
64
67
|
inventoryRetryAt = 0;
|
|
68
|
+
/** Folders: rescan at most every 10 min, send again at most once an hour when asked, 10 min after a failure. */
|
|
69
|
+
folderScanAt = 0;
|
|
70
|
+
folderAskAt = 0;
|
|
71
|
+
folderRetryAt = 0;
|
|
72
|
+
folderReport = null;
|
|
73
|
+
folderSentHash = "";
|
|
65
74
|
constructor(deps) {
|
|
66
75
|
this.d = deps;
|
|
67
76
|
mkdirSync(deps.cfg.stateDir, { recursive: true });
|
|
@@ -158,8 +167,58 @@ export class Runner {
|
|
|
158
167
|
this.stopLive("revoked");
|
|
159
168
|
if (r.status !== "revoked" && r.inventory?.enabled && r.inventory.send)
|
|
160
169
|
await this.sendInventory();
|
|
170
|
+
if (r.status !== "revoked")
|
|
171
|
+
await this.folderStep(r);
|
|
161
172
|
return true;
|
|
162
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Project folders (BEA-96 slice 3): take the owner's picks from the reply,
|
|
176
|
+
* rescan the roots now and then, and send the list in one more heartbeat
|
|
177
|
+
* when the server asks or the list changed. Never fails the tick.
|
|
178
|
+
*/
|
|
179
|
+
async folderStep(r) {
|
|
180
|
+
const f = this.d.folders;
|
|
181
|
+
if (!f)
|
|
182
|
+
return;
|
|
183
|
+
f.setWeb(r.project_folders);
|
|
184
|
+
if (!r.folders)
|
|
185
|
+
return; // an older server
|
|
186
|
+
const now = this.now();
|
|
187
|
+
if (!this.folderReport || now >= this.folderScanAt) {
|
|
188
|
+
try {
|
|
189
|
+
this.folderReport = f.scan();
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
this.log(`could not list the project folders (${err.message})`);
|
|
193
|
+
}
|
|
194
|
+
this.folderScanAt = now + 10 * 60 * 1000;
|
|
195
|
+
}
|
|
196
|
+
const report = this.folderReport;
|
|
197
|
+
if (!report || now < this.folderRetryAt)
|
|
198
|
+
return;
|
|
199
|
+
const hash = sha256Hex(JSON.stringify(report));
|
|
200
|
+
const changed = hash !== this.folderSentHash;
|
|
201
|
+
if (!changed && !(r.folders.send && now >= this.folderAskAt))
|
|
202
|
+
return;
|
|
203
|
+
try {
|
|
204
|
+
const again = await this.d.api.heartbeat({ ...this.heartbeatBody(), folders: report });
|
|
205
|
+
if (again.project_folders !== undefined)
|
|
206
|
+
f.setWeb(again.project_folders);
|
|
207
|
+
this.folderSentHash = hash;
|
|
208
|
+
this.folderAskAt = now + 60 * 60 * 1000;
|
|
209
|
+
this.log(`sent the project folder list (${report.items.length} folders, names and paths only)`);
|
|
210
|
+
}
|
|
211
|
+
catch (err) {
|
|
212
|
+
this.folderRetryAt = now + 10 * 60 * 1000;
|
|
213
|
+
this.log(`could not send the project folder list (${err.message})`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/** config.json first, then the owner's pick on beatos.app (checked in folders.ts). */
|
|
217
|
+
projectFor(projectId) {
|
|
218
|
+
if (!projectId)
|
|
219
|
+
return undefined;
|
|
220
|
+
return this.d.folders ? this.d.folders.projectFor(projectId) : this.d.cfg.projects[projectId];
|
|
221
|
+
}
|
|
163
222
|
/**
|
|
164
223
|
* The owner turned on "What is on this computer" and the server wants a
|
|
165
224
|
* fresh list (first time, or 6 hours old): read it and send it in one more
|
|
@@ -409,8 +468,7 @@ export class Runner {
|
|
|
409
468
|
return false;
|
|
410
469
|
if (Object.values(this.state.runs).some((r) => r.taskId === task.id && r.phase !== "done"))
|
|
411
470
|
return false;
|
|
412
|
-
|
|
413
|
-
return project?.mode !== "exclude";
|
|
471
|
+
return this.projectFor(task.projectId)?.mode !== "exclude";
|
|
414
472
|
}
|
|
415
473
|
async startNew() {
|
|
416
474
|
if (this.runsLeft() <= 0 || !this.state.runnerId)
|
|
@@ -429,7 +487,7 @@ export class Runner {
|
|
|
429
487
|
return;
|
|
430
488
|
}
|
|
431
489
|
const code = taskCode(task);
|
|
432
|
-
const project =
|
|
490
|
+
const project = this.projectFor(task.projectId);
|
|
433
491
|
const context = await this.taskContext(task);
|
|
434
492
|
let place;
|
|
435
493
|
let setup;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beatos/bridge-runner",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
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",
|