@ulm0/gonogo 0.1.1 → 0.2.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 +5 -11
- package/dist/client/assets/index-DxUnpGbS.js +52 -0
- package/dist/client/assets/index-tpcmltjw.css +1 -0
- package/dist/client/index.html +2 -2
- package/dist/server/audited.js +156 -0
- package/dist/server/blackbox.js +261 -0
- package/dist/server/board.js +123 -0
- package/dist/server/cleanroom.js +7 -51
- package/dist/server/clearance.js +158 -0
- package/dist/server/cli.js +229 -28
- package/dist/server/constants.js +54 -3
- package/dist/server/hangar.js +311 -0
- package/dist/server/home.js +41 -2
- package/dist/server/hub.js +280 -29
- package/dist/server/launcher.js +25 -13
- package/dist/server/logchart.js +58 -0
- package/dist/server/massbudget.js +169 -0
- package/dist/server/mcp.js +73 -2
- package/dist/server/migrate.js +7 -3
- package/dist/server/missionlog.js +2 -0
- package/dist/server/missions.js +310 -0
- package/dist/server/models.js +73 -0
- package/dist/server/phone.js +122 -0
- package/dist/server/phonetag.js +47 -0
- package/dist/server/prices.js +112 -0
- package/dist/server/propellant.js +243 -16
- package/dist/server/providers.js +123 -9
- package/dist/server/recorder.js +176 -0
- package/dist/server/relay.js +53 -7
- package/dist/server/relaykinds.js +11 -1
- package/dist/server/relief.js +226 -0
- package/dist/server/remotecontrol.js +15 -0
- package/dist/server/rollout.js +172 -0
- package/dist/server/tasks.js +44 -8
- package/dist/server/telemetry.js +110 -0
- package/dist/server/uplinks.js +7 -0
- package/dist/server/web.js +310 -10
- package/dist/server/worktree.js +137 -0
- package/dist/shared/fuel.js +8 -0
- package/dist/shared/livery.js +1 -1
- package/dist/shared/positions.js +1 -1
- package/dist/shared/prices.js +75 -0
- package/dist/shared/protocol.js +61 -15
- package/package.json +1 -1
- package/dist/client/assets/index-B6MsSoeo.css +0 -1
- package/dist/client/assets/index-DRtiRh1Y.js +0 -31
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hangar (docs/hangar-spec.md): the files of one agent's folder, or of its Clean Room worktree, for the Director's browser.
|
|
3
|
+
* List a folder, read a text file, save one the Director opened (refused when it changed on disk since), make a new one. No
|
|
4
|
+
* delete, no rename. Every path is a relative one that is resolved with realpath and kept inside the root; `.git` and gonogo's
|
|
5
|
+
* own folder are never reachable. The agent runs as the same user, so this guards the browser's requests, not the agent.
|
|
6
|
+
* shortcut: a folder swapped for a link between the realpath and the open escapes the check (only the last name is opened with
|
|
7
|
+
* O_NOFOLLOW); whoever can swap it can write the file itself. Close it with openat if the agent is ever not the owner's user.
|
|
8
|
+
*/
|
|
9
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
10
|
+
import { constants as fs } from 'node:fs';
|
|
11
|
+
import { access, lstat, open, opendir, realpath, rename, unlink } from 'node:fs/promises';
|
|
12
|
+
import { isAbsolute, join, relative, sep } from 'node:path';
|
|
13
|
+
import { CLEAN_ROOM_DIR, HANGAR_FILE_MAX_BYTES, WORKTREE_DIR } from '../shared/protocol.js';
|
|
14
|
+
import { HubError } from './hub.js';
|
|
15
|
+
/** A save body: the text, in the worst case a `\u0000` escape for each byte, plus the path and the etag. */
|
|
16
|
+
export const HANGAR_BODY_MAX_BYTES = 6 * HANGAR_FILE_MAX_BYTES + 8192;
|
|
17
|
+
/** A folder shows this many entries and says there are more. */
|
|
18
|
+
export const HANGAR_LIST_MAX = 2000;
|
|
19
|
+
const PATH_MAX_CHARS = 1024;
|
|
20
|
+
const ETAG_MAX_CHARS = 64;
|
|
21
|
+
/** git's own test for a binary file: a NUL in the first 8000 bytes. */
|
|
22
|
+
const SNIFF_BYTES = 8000;
|
|
23
|
+
const bad = (message, field) => new HubError('bad_request', message, field);
|
|
24
|
+
const forbidden = (message) => new HubError('forbidden', message, 'path');
|
|
25
|
+
/** `child` is `parent` or below it. */
|
|
26
|
+
export function inside(parent, child) {
|
|
27
|
+
const r = relative(parent, child);
|
|
28
|
+
return r === '' || (r !== '..' && !r.startsWith(`..${sep}`) && !isAbsolute(r));
|
|
29
|
+
}
|
|
30
|
+
/** A name that a file system may take for `.git`: other case, a zero-width or ignorable character in it (HFS+ ignores those). */
|
|
31
|
+
export function isGitName(segment) {
|
|
32
|
+
return segment.normalize('NFKC').replace(/[---]/g, '').toLowerCase() === '.git';
|
|
33
|
+
}
|
|
34
|
+
/** The segments of a relative path from the browser. Anything that could leave the root, or reach `.git`, is refused here. */
|
|
35
|
+
export function pathParts(raw, field = 'path') {
|
|
36
|
+
if (typeof raw !== 'string')
|
|
37
|
+
throw bad(`${field} must be a string`, field);
|
|
38
|
+
if (raw.length > PATH_MAX_CHARS)
|
|
39
|
+
throw bad(`${field} is longer than ${PATH_MAX_CHARS} characters`, field);
|
|
40
|
+
if (raw.includes('\0'))
|
|
41
|
+
throw bad(`${field} has a NUL character`, field);
|
|
42
|
+
if (raw.startsWith('/'))
|
|
43
|
+
throw forbidden('the path must be relative to the agent\'s folder');
|
|
44
|
+
const parts = raw.split('/').filter((p) => p !== '' && p !== '.');
|
|
45
|
+
if (parts.includes('..'))
|
|
46
|
+
throw forbidden('a path cannot go up with ..');
|
|
47
|
+
if (parts.some(isGitName))
|
|
48
|
+
throw forbidden('.git is not reachable');
|
|
49
|
+
return parts;
|
|
50
|
+
}
|
|
51
|
+
/** Turns what a file system call said into an answer; anything else is the server's own fault and goes up as it is. */
|
|
52
|
+
function fsError(e) {
|
|
53
|
+
const code = e?.code;
|
|
54
|
+
if (code === 'ENOENT')
|
|
55
|
+
return new HubError('not_found', 'no such file or folder', 'path');
|
|
56
|
+
if (code === 'ENOTDIR')
|
|
57
|
+
return bad('a part of the path is not a folder', 'path');
|
|
58
|
+
if (code === 'EISDIR')
|
|
59
|
+
return bad('that is a folder', 'path');
|
|
60
|
+
if (code === 'EEXIST')
|
|
61
|
+
return new HubError('conflict', 'a file with that name exists', 'path');
|
|
62
|
+
if (code === 'EACCES' || code === 'EPERM')
|
|
63
|
+
return forbidden('permission denied');
|
|
64
|
+
if (code === 'ELOOP')
|
|
65
|
+
return forbidden('a symbolic link is not followed there');
|
|
66
|
+
if (code === 'ENAMETOOLONG')
|
|
67
|
+
return bad('a name in the path is too long', 'path');
|
|
68
|
+
return e;
|
|
69
|
+
}
|
|
70
|
+
const etagOf = (bytes) => createHash('sha256').update(bytes).digest('hex').slice(0, 32);
|
|
71
|
+
/** At most `max` bytes from the start; a file that grows while it is read cannot make this large. */
|
|
72
|
+
async function readUpTo(handle, max) {
|
|
73
|
+
const buffer = Buffer.alloc(max);
|
|
74
|
+
let size = 0;
|
|
75
|
+
while (size < max) {
|
|
76
|
+
const { bytesRead } = await handle.read(buffer, size, max - size, size);
|
|
77
|
+
if (bytesRead === 0)
|
|
78
|
+
break;
|
|
79
|
+
size += bytesRead;
|
|
80
|
+
}
|
|
81
|
+
return buffer.subarray(0, size);
|
|
82
|
+
}
|
|
83
|
+
async function writeAll(handle, bytes) {
|
|
84
|
+
let at = 0;
|
|
85
|
+
while (at < bytes.length)
|
|
86
|
+
at += (await handle.write(bytes, at, bytes.length - at, at)).bytesWritten;
|
|
87
|
+
}
|
|
88
|
+
/** Text the editor may hold: valid UTF-8 without a NUL. A byte order mark stays in the text, so a save writes it back. */
|
|
89
|
+
function decode(bytes) {
|
|
90
|
+
if (bytes.subarray(0, SNIFF_BYTES).includes(0))
|
|
91
|
+
throw new HubError('unsupported', 'a binary file: the editor opens text only', 'path');
|
|
92
|
+
try {
|
|
93
|
+
return new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
throw new HubError('unsupported', 'not valid UTF-8: the editor opens text only', 'path');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function textOf(input, required) {
|
|
100
|
+
const { text } = input;
|
|
101
|
+
if (text === undefined && !required)
|
|
102
|
+
return Buffer.alloc(0);
|
|
103
|
+
if (typeof text !== 'string')
|
|
104
|
+
throw bad('text must be a string', 'text');
|
|
105
|
+
if (text.includes('\0'))
|
|
106
|
+
throw bad('text has a NUL character: the editor holds text only', 'text');
|
|
107
|
+
const bytes = Buffer.from(text, 'utf8');
|
|
108
|
+
if (bytes.length > HANGAR_FILE_MAX_BYTES)
|
|
109
|
+
throw new HubError('too_large', `the file would be ${bytes.length} bytes; the limit is ${HANGAR_FILE_MAX_BYTES}`, 'text');
|
|
110
|
+
return bytes;
|
|
111
|
+
}
|
|
112
|
+
const isInput = (x) => typeof x === 'object' && x !== null && !Array.isArray(x);
|
|
113
|
+
/** Where an agent's files are: its Clean Room's worktree, else its folder. The home folder is resolved too, to keep gonogo's own state out of reach. */
|
|
114
|
+
export function createRoots(deps) {
|
|
115
|
+
return async (name) => {
|
|
116
|
+
const place = deps.agent(name);
|
|
117
|
+
if (place === null)
|
|
118
|
+
throw new HubError('not_found', 'unknown agent');
|
|
119
|
+
const wanted = place.cleanRoom ? join(deps.home, CLEAN_ROOM_DIR, name) : place.worktree === true ? join(deps.home, WORKTREE_DIR, name) : place.dir;
|
|
120
|
+
try {
|
|
121
|
+
return { root: await realpath(wanted), home: await realpath(deps.home) };
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
if (e.code === 'ENOENT') {
|
|
125
|
+
throw new HubError('not_found', place.cleanRoom ? 'the Clean Room has no worktree yet: start the agent once' : place.worktree === true ? 'the worktree is not made yet: start the agent once' : 'the agent\'s folder is gone');
|
|
126
|
+
}
|
|
127
|
+
throw e;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
export function createHangar(roots) {
|
|
132
|
+
/** Saves of one file run one after the other: two browsers saving with the same etag at once would both pass the check, and the first text would be lost. */
|
|
133
|
+
const saving = new Map();
|
|
134
|
+
async function serial(key, work) {
|
|
135
|
+
const run = (saving.get(key) ?? Promise.resolve()).then(work);
|
|
136
|
+
const tail = run.then(() => undefined, () => undefined);
|
|
137
|
+
saving.set(key, tail);
|
|
138
|
+
try {
|
|
139
|
+
return await run;
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
if (saving.get(key) === tail)
|
|
143
|
+
saving.delete(key);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/** gonogo's home is out of reach, except the Clean Room worktrees below it (an agent's own files). */
|
|
147
|
+
const ownState = (at, real) => inside(at.home, real) && !inside(join(at.home, CLEAN_ROOM_DIR), real) && !inside(join(at.home, WORKTREE_DIR), real);
|
|
148
|
+
const guard = (at, real) => {
|
|
149
|
+
if (!inside(at.root, real))
|
|
150
|
+
throw forbidden('that path leads outside the agent\'s folder');
|
|
151
|
+
if (relative(at.root, real).split(sep).some(isGitName))
|
|
152
|
+
throw forbidden('.git is not reachable');
|
|
153
|
+
if (ownState(at, real))
|
|
154
|
+
throw forbidden('that is gonogo\'s own folder');
|
|
155
|
+
};
|
|
156
|
+
async function resolveIn(at, parts) {
|
|
157
|
+
let real;
|
|
158
|
+
try {
|
|
159
|
+
real = await realpath(join(at.root, ...parts));
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
throw fsError(e);
|
|
163
|
+
}
|
|
164
|
+
guard(at, real);
|
|
165
|
+
return real;
|
|
166
|
+
}
|
|
167
|
+
/** Opens without following a link in the last name and without waiting on a pipe; what is opened must be a regular file. */
|
|
168
|
+
async function openFile(real, flags) {
|
|
169
|
+
let handle;
|
|
170
|
+
try {
|
|
171
|
+
handle = await open(real, flags | fs.O_NOFOLLOW | fs.O_NONBLOCK);
|
|
172
|
+
}
|
|
173
|
+
catch (e) {
|
|
174
|
+
throw fsError(e);
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
const info = await handle.stat();
|
|
178
|
+
if (!info.isFile())
|
|
179
|
+
throw new HubError('unsupported', 'not a regular file', 'path');
|
|
180
|
+
return { handle, info };
|
|
181
|
+
}
|
|
182
|
+
catch (e) {
|
|
183
|
+
await handle.close();
|
|
184
|
+
throw e;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/** The file `real` takes `bytes` when it still has the etag `etag`: written whole beside it, then renamed over it. */
|
|
188
|
+
async function replace(real, leaf, bytes, etag) {
|
|
189
|
+
const { handle, info } = await openFile(real, fs.O_RDONLY);
|
|
190
|
+
let temp = null;
|
|
191
|
+
try {
|
|
192
|
+
// the file is replaced by a new one, which a read-only file must not allow
|
|
193
|
+
await access(real, fs.W_OK).catch((e) => {
|
|
194
|
+
throw fsError(e);
|
|
195
|
+
});
|
|
196
|
+
const now = info.size > HANGAR_FILE_MAX_BYTES ? null : await readUpTo(handle, HANGAR_FILE_MAX_BYTES + 1);
|
|
197
|
+
if (now === null || etagOf(now) !== etag)
|
|
198
|
+
throw new HubError('conflict', 'the file changed on disk since you opened it: nothing was saved', 'etag');
|
|
199
|
+
// Written whole beside the file and renamed over it, so that a full disk or a crash leaves the old file.
|
|
200
|
+
temp = join(real, '..', `.${leaf}.gonogo-${randomBytes(4).toString('hex')}.tmp`);
|
|
201
|
+
const out = await open(temp, 'wx', 0o600).catch((e) => {
|
|
202
|
+
temp = null;
|
|
203
|
+
throw fsError(e);
|
|
204
|
+
});
|
|
205
|
+
try {
|
|
206
|
+
await writeAll(out, bytes);
|
|
207
|
+
await out.chmod(info.mode & 0o7777);
|
|
208
|
+
}
|
|
209
|
+
finally {
|
|
210
|
+
await out.close();
|
|
211
|
+
}
|
|
212
|
+
// shortcut: a write by another process between this check and the rename is lost; take a lock file when two writers matter
|
|
213
|
+
const after = await lstat(real);
|
|
214
|
+
if (after.mtimeMs !== info.mtimeMs || after.size !== info.size)
|
|
215
|
+
throw new HubError('conflict', 'the file changed on disk while it was saved: nothing was saved', 'etag');
|
|
216
|
+
await rename(temp, real);
|
|
217
|
+
temp = null;
|
|
218
|
+
}
|
|
219
|
+
finally {
|
|
220
|
+
await handle.close();
|
|
221
|
+
if (temp !== null)
|
|
222
|
+
await unlink(temp).catch(() => undefined);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const filePath = (raw) => {
|
|
226
|
+
const parts = pathParts(raw);
|
|
227
|
+
if (parts.length === 0)
|
|
228
|
+
throw bad('path must name a file', 'path');
|
|
229
|
+
return parts;
|
|
230
|
+
};
|
|
231
|
+
return {
|
|
232
|
+
async list(name, raw) {
|
|
233
|
+
const parts = pathParts(raw ?? '');
|
|
234
|
+
const at = await roots(name);
|
|
235
|
+
const dir = await resolveIn(at, parts);
|
|
236
|
+
const entries = [];
|
|
237
|
+
let truncated = false;
|
|
238
|
+
try {
|
|
239
|
+
// shortcut: past the limit the entries are the first the disk gave, not the first by name; sort a whole folder when one needs it
|
|
240
|
+
for await (const item of await opendir(dir)) {
|
|
241
|
+
if (isGitName(item.name) || ownState(at, join(dir, item.name)))
|
|
242
|
+
continue;
|
|
243
|
+
if (entries.length >= HANGAR_LIST_MAX) {
|
|
244
|
+
truncated = true;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
const kind = item.isDirectory() ? 'dir' : item.isSymbolicLink() ? 'link' : item.isFile() ? 'file' : null;
|
|
248
|
+
if (kind !== null)
|
|
249
|
+
entries.push({ name: item.name, kind, size: kind === 'file' ? (await lstat(join(dir, item.name)).catch(() => null))?.size ?? 0 : 0 });
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
catch (e) {
|
|
253
|
+
throw fsError(e);
|
|
254
|
+
}
|
|
255
|
+
entries.sort((a, b) => (a.kind === 'dir' ? 0 : 1) - (b.kind === 'dir' ? 0 : 1) || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
256
|
+
return { path: parts.join('/'), entries, truncated };
|
|
257
|
+
},
|
|
258
|
+
async read(name, raw) {
|
|
259
|
+
const parts = filePath(raw);
|
|
260
|
+
const real = await resolveIn(await roots(name), parts);
|
|
261
|
+
const { handle, info } = await openFile(real, fs.O_RDONLY);
|
|
262
|
+
try {
|
|
263
|
+
if (info.size > HANGAR_FILE_MAX_BYTES)
|
|
264
|
+
throw new HubError('too_large', `the file has ${info.size} bytes; the editor opens at most ${HANGAR_FILE_MAX_BYTES}`, 'path');
|
|
265
|
+
const bytes = await readUpTo(handle, HANGAR_FILE_MAX_BYTES + 1);
|
|
266
|
+
if (bytes.length > HANGAR_FILE_MAX_BYTES)
|
|
267
|
+
throw new HubError('too_large', `the file is larger than ${HANGAR_FILE_MAX_BYTES} bytes`, 'path');
|
|
268
|
+
return { path: parts.join('/'), text: decode(bytes), size: bytes.length, etag: etagOf(bytes) };
|
|
269
|
+
}
|
|
270
|
+
finally {
|
|
271
|
+
await handle.close();
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
async save(name, input) {
|
|
275
|
+
if (!isInput(input))
|
|
276
|
+
throw bad('the body must be an object');
|
|
277
|
+
const parts = filePath(input.path);
|
|
278
|
+
const { etag } = input;
|
|
279
|
+
if (typeof etag !== 'string' || etag === '' || etag.length > ETAG_MAX_CHARS)
|
|
280
|
+
throw bad('etag must be the one the file was read with', 'etag');
|
|
281
|
+
const bytes = textOf(input, true);
|
|
282
|
+
const real = await resolveIn(await roots(name), parts);
|
|
283
|
+
await serial(real, () => replace(real, parts[parts.length - 1] ?? 'file', bytes, etag));
|
|
284
|
+
return { path: parts.join('/'), size: bytes.length, etag: etagOf(bytes) };
|
|
285
|
+
},
|
|
286
|
+
async create(name, input) {
|
|
287
|
+
if (!isInput(input))
|
|
288
|
+
throw bad('the body must be an object');
|
|
289
|
+
const parts = filePath(input.path);
|
|
290
|
+
const bytes = textOf(input, false);
|
|
291
|
+
const at = await roots(name);
|
|
292
|
+
const folder = await resolveIn(at, parts.slice(0, -1));
|
|
293
|
+
const leaf = parts[parts.length - 1] ?? '';
|
|
294
|
+
let handle;
|
|
295
|
+
try {
|
|
296
|
+
// O_EXCL: the name must be new, and a link by that name is never followed.
|
|
297
|
+
handle = await open(join(folder, leaf), 'wx', 0o644);
|
|
298
|
+
}
|
|
299
|
+
catch (e) {
|
|
300
|
+
throw fsError(e);
|
|
301
|
+
}
|
|
302
|
+
try {
|
|
303
|
+
await writeAll(handle, bytes);
|
|
304
|
+
}
|
|
305
|
+
finally {
|
|
306
|
+
await handle.close();
|
|
307
|
+
}
|
|
308
|
+
return { path: parts.join('/'), size: bytes.length, etag: etagOf(bytes) };
|
|
309
|
+
},
|
|
310
|
+
};
|
|
311
|
+
}
|
package/dist/server/home.js
CHANGED
|
@@ -3,12 +3,16 @@ import { chmodSync, closeSync, fstatSync, mkdirSync, openSync, readFileSync, rea
|
|
|
3
3
|
import { appendFile, rename, unlink, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { join, resolve } from 'node:path';
|
|
5
5
|
import { POSITION_IDS } from '../shared/positions.js';
|
|
6
|
-
import { ACTIVITY_STATUSES, PERMISSION_MODES, PROVIDERS, RESERVED_NAMES } from '../shared/protocol.js';
|
|
6
|
+
import { ACTIVITY_STATUSES, KEYS_MAX, MODEL_PATTERN, PERMISSION_MODES, PROVIDERS, providerInfo, RESERVED_NAMES } from '../shared/protocol.js';
|
|
7
7
|
import { AGENT_NAME_PATTERN, AGENTS_DIR, AGENTS_FILE, BROWSER_TOKEN_FILE, COMMAND_MAX_CHARS, DIR_MODE, FILE_MODE, LOCK_FILE, MESSAGES_FILE, MESSAGES_ROTATE_BYTES, MESSAGES_ROTATED_FILE, MESSAGES_TAIL_BYTES, TOKEN_BYTES, nullLogger, } from './constants.js';
|
|
8
8
|
import { readCustomCommand } from './command.js';
|
|
9
9
|
import { migrateHome } from './migrate.js';
|
|
10
10
|
import { parseCleanRoom } from './cleanroom.js';
|
|
11
|
+
import { parseWorktree } from './worktree.js';
|
|
12
|
+
import { parseRemoteControl } from './remotecontrol.js';
|
|
13
|
+
import { keyNameProblem } from './clearance.js';
|
|
11
14
|
import { parsePayload, payloadRefusal } from './payload.js';
|
|
15
|
+
const MODEL_RE = new RegExp(MODEL_PATTERN);
|
|
12
16
|
const NAME_RE = new RegExp(AGENT_NAME_PATTERN);
|
|
13
17
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
14
18
|
const TOKEN_RE = /^[0-9a-f]{64}$/i;
|
|
@@ -150,7 +154,7 @@ function parseAgent(a) {
|
|
|
150
154
|
if (typeof createdAt !== 'number' || !Number.isFinite(createdAt))
|
|
151
155
|
return `${name}: createdAt must be a number`;
|
|
152
156
|
const record = { name, role, dir, mode, sessionId, desk, boss, createdAt };
|
|
153
|
-
const { position, provider, command, payload, cleanRoom } = a;
|
|
157
|
+
const { position, provider, command, payload, cleanRoom, worktree, remoteControl } = a;
|
|
154
158
|
if (position !== undefined) {
|
|
155
159
|
if (typeof position !== 'string' || !POSITION_IDS.includes(position))
|
|
156
160
|
return `${name}: unknown position`;
|
|
@@ -195,6 +199,41 @@ function parseAgent(a) {
|
|
|
195
199
|
return `${name}: ${checked.error}`;
|
|
196
200
|
record.cleanRoom = checked.cleanRoom;
|
|
197
201
|
}
|
|
202
|
+
if (worktree !== undefined) {
|
|
203
|
+
const checked = parseWorktree(worktree);
|
|
204
|
+
if (!checked.ok)
|
|
205
|
+
return `${name}: ${checked.error}`;
|
|
206
|
+
if (cleanRoom !== undefined)
|
|
207
|
+
return `${name}: a Clean Room agent has a worktree already`;
|
|
208
|
+
record.worktree = checked.worktree;
|
|
209
|
+
}
|
|
210
|
+
if (remoteControl !== undefined) {
|
|
211
|
+
const checked = parseRemoteControl(remoteControl, record.provider, record.cleanRoom !== undefined);
|
|
212
|
+
if (!checked.ok)
|
|
213
|
+
return `${name}: ${checked.error}`;
|
|
214
|
+
record.remoteControl = checked.remoteControl;
|
|
215
|
+
}
|
|
216
|
+
const { model, keys } = a;
|
|
217
|
+
if (model !== undefined) {
|
|
218
|
+
if (typeof model !== 'string' || !MODEL_RE.test(model))
|
|
219
|
+
return `${name}: model is not a usable name`;
|
|
220
|
+
if (providerInfo(record.provider).model === null)
|
|
221
|
+
return `${name}: ${providerInfo(record.provider).label} takes no model setting`;
|
|
222
|
+
record.model = model;
|
|
223
|
+
}
|
|
224
|
+
if (keys !== undefined) {
|
|
225
|
+
if (!isRecord(keys) || Object.keys(keys).length > KEYS_MAX)
|
|
226
|
+
return `${name}: keys must be an object of at most ${KEYS_MAX} names`;
|
|
227
|
+
const names = {};
|
|
228
|
+
// shortcut: a name that a later gonogo reserves makes the roster unusable here (the start stops and names the agent); delete it from `keys` to go on
|
|
229
|
+
for (const [key, at] of Object.entries(keys)) {
|
|
230
|
+
if (keyNameProblem(key) !== null || typeof at !== 'number' || !Number.isFinite(at))
|
|
231
|
+
return `${name}: keys holds a name or a time that is not usable`;
|
|
232
|
+
names[key] = at;
|
|
233
|
+
}
|
|
234
|
+
if (Object.keys(names).length > 0)
|
|
235
|
+
record.keys = names;
|
|
236
|
+
}
|
|
198
237
|
return record;
|
|
199
238
|
}
|
|
200
239
|
function parseRoster(text, path) {
|