@dibssoftware/dibs 0.0.181 → 0.0.195
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/CHANGELOG.md +103 -1
- package/README.md +10 -8
- package/bin/dibs.mjs +370 -73
- package/docs/agents.md +303 -0
- package/docs/council.md +88 -0
- package/docs/files.md +3 -3
- package/docs/guard.md +86 -11
- package/docs/json.md +211 -0
- package/docs/later.md +5 -5
- package/docs/machines.md +6 -6
- package/docs/questions.md +104 -3
- package/docs/reference.md +124 -30
- package/docs/relay.md +120 -9
- package/docs/releasing.md +7 -1
- package/docs/scheduling.md +28 -6
- package/docs/secrets.md +53 -0
- package/docs/simulators.md +3 -3
- package/package.json +1 -1
- package/skills/dibs/SKILL.md +79 -149
- package/src/about.mjs +341 -0
- package/src/acquire.mjs +111 -27
- package/src/after.mjs +127 -0
- package/src/agents.mjs +2 -1
- package/src/alerts.mjs +95 -42
- package/src/answers.mjs +2 -2
- package/src/board.mjs +21 -16
- package/src/broker.mjs +23 -7
- package/src/carry.mjs +287 -0
- package/src/codex.mjs +132 -0
- package/src/commands.mjs +243 -82
- package/src/config.mjs +85 -14
- package/src/connect.mjs +4 -2
- package/src/cool.mjs +27 -11
- package/src/council.mjs +482 -0
- package/src/cwd.mjs +9 -0
- package/src/decisions.mjs +250 -0
- package/src/declare.mjs +96 -0
- package/src/diskreport.mjs +306 -0
- package/src/diskuse.mjs +420 -0
- package/src/diskwarn.mjs +68 -13
- package/src/doctor.mjs +149 -0
- package/src/doors.mjs +547 -0
- package/src/durable.mjs +143 -0
- package/src/envs.mjs +372 -0
- package/src/events.mjs +7 -2
- package/src/files.mjs +118 -6
- package/src/guard.mjs +239 -86
- package/src/guardd.mjs +8 -1
- package/src/halt.mjs +63 -0
- package/src/handoffs.mjs +362 -0
- package/src/history.mjs +34 -4
- package/src/hogs.mjs +36 -8
- package/src/jobprogress.mjs +283 -0
- package/src/later.mjs +21 -10
- package/src/lock.mjs +33 -9
- package/src/measure.mjs +42 -11
- package/src/media.mjs +240 -0
- package/src/news.mjs +31 -0
- package/src/notes.mjs +49 -8
- package/src/notices.mjs +126 -43
- package/src/ondemand.mjs +25 -2
- package/src/outcome.mjs +163 -0
- package/src/overlap.mjs +2 -2
- package/src/override.mjs +149 -79
- package/src/owner.mjs +15 -2
- package/src/people.mjs +236 -0
- package/src/pickup.mjs +72 -0
- package/src/picture.mjs +321 -0
- package/src/plain.mjs +84 -18
- package/src/platform.mjs +19 -0
- package/src/preempt.mjs +123 -15
- package/src/primer.mjs +91 -20
- package/src/prints.mjs +99 -0
- package/src/proc.mjs +1 -1
- package/src/progress.mjs +49 -3
- package/src/proof.mjs +102 -0
- package/src/push.mjs +271 -0
- package/src/questions.mjs +328 -57
- package/src/quota.mjs +1 -1
- package/src/recap.mjs +205 -0
- package/src/relay.mjs +139 -20
- package/src/remote.mjs +23 -10
- package/src/reviewgate.mjs +268 -0
- package/src/reviews.mjs +377 -0
- package/src/route.mjs +263 -0
- package/src/rules.mjs +216 -0
- package/src/schedule.mjs +238 -44
- package/src/schema.mjs +62 -0
- package/src/scratch.mjs +2 -2
- package/src/serve.mjs +3 -2
- package/src/signed.mjs +97 -0
- package/src/simpool.mjs +46 -1
- package/src/spend.mjs +375 -0
- package/src/state.mjs +43 -17
- package/src/talk.mjs +1078 -133
- package/src/thin.sh +2 -0
- package/src/trail.mjs +290 -0
- package/src/trailnote.mjs +209 -0
- package/src/util.mjs +7 -0
- package/src/vault.mjs +435 -0
- package/src/vendors.mjs +327 -0
- package/src/version.mjs +1 -1
- package/src/web.mjs +353 -60
- package/src/work.mjs +487 -0
- package/src/worker.mjs +7 -1
package/src/web.mjs
CHANGED
|
@@ -30,18 +30,32 @@ import { execFile } from 'node:child_process';
|
|
|
30
30
|
import { fileURLToPath } from 'node:url';
|
|
31
31
|
import { HOME, PACES, loadConfig } from './config.mjs';
|
|
32
32
|
import { read as readPosts, tasks as taskList } from './progress.mjs';
|
|
33
|
-
import { readEvents } from './events.mjs';
|
|
33
|
+
import { readEvents, EVENTS } from './events.mjs';
|
|
34
34
|
import { summarize, verdict, span } from './history.mjs';
|
|
35
35
|
import { collect, readRuns, text as statsText } from './stats.mjs';
|
|
36
36
|
import { AGENT_ENV, logChange } from './owner.mjs';
|
|
37
|
+
import { readPeople, several, personOf, byDevice } from './people.mjs';
|
|
37
38
|
import { PRIORITIES } from './schedule.mjs';
|
|
38
39
|
import { die, now, log, dur, clock, masked, inProcess } from './util.mjs';
|
|
39
40
|
import { peek } from './state.mjs';
|
|
40
41
|
import { underLock, commit } from './lock.mjs';
|
|
41
42
|
import { boardJson, paceJson } from './commands.mjs';
|
|
42
|
-
import { questionsJson, hours as hoursOf } from './questions.mjs';
|
|
43
|
-
import {
|
|
43
|
+
import { questionsJson, asked as allQuestions, hours as hoursOf, attention as attentionOf } from './questions.mjs';
|
|
44
|
+
import { rulesJson, ABOUT } from './rules.mjs';
|
|
45
|
+
import { threadsJson, pendingJson } from './talk.mjs';
|
|
46
|
+
import { fileOf, linkOf, rangeOf, readRange, inline, RELAY_CHUNK } from './media.mjs';
|
|
47
|
+
import { sweepSoon } from './carry.mjs';
|
|
48
|
+
import { recapNow, sinceOf } from './recap.mjs';
|
|
49
|
+
import { decisionsJson } from './decisions.mjs';
|
|
50
|
+
import { trailNow } from './trail.mjs';
|
|
51
|
+
import { agentsJson, runJson } from './picture.mjs';
|
|
52
|
+
import { workJson } from './work.mjs';
|
|
53
|
+
import { secretsJson } from './vault.mjs';
|
|
54
|
+
import { spendJson } from './spend.mjs';
|
|
55
|
+
import { reviewsNow } from './reviews.mjs';
|
|
44
56
|
import { laterJson } from './later.mjs';
|
|
57
|
+
import { envsJson } from './envs.mjs';
|
|
58
|
+
import { described, declared } from './declare.mjs';
|
|
45
59
|
import { guardJson } from './guard.mjs';
|
|
46
60
|
import { servicesJson } from './service.mjs';
|
|
47
61
|
import { poolJson } from './simpool.mjs';
|
|
@@ -51,6 +65,7 @@ import { quotasNow } from './quota.mjs';
|
|
|
51
65
|
import { machine } from './config.mjs';
|
|
52
66
|
import { qr } from './qr.mjs';
|
|
53
67
|
import { VERSION } from './version.mjs';
|
|
68
|
+
import { readJSON } from './durable.mjs';
|
|
54
69
|
|
|
55
70
|
const ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
56
71
|
const BIN = path.join(ROOT, 'bin', 'dibs.mjs');
|
|
@@ -110,11 +125,13 @@ const STATIC = {
|
|
|
110
125
|
'/web/authorize.js': ['authorize.js', 'text/javascript; charset=utf-8'],
|
|
111
126
|
'/web/transport.js': ['transport.js', 'text/javascript; charset=utf-8'],
|
|
112
127
|
'/web/dither.js': ['dither.js', 'text/javascript; charset=utf-8'],
|
|
128
|
+
'/web/threads.js': ['threads.js', 'text/javascript; charset=utf-8'],
|
|
113
129
|
'/web/logo.png': ['logo.png', 'image/png'],
|
|
114
130
|
'/web/SchibstedGrotesk.woff2': ['SchibstedGrotesk.woff2', 'font/woff2'],
|
|
115
131
|
};
|
|
116
132
|
const HEADERS = {
|
|
117
|
-
|
|
133
|
+
// blob: for what a message carries (web/app.js blobUrl): its images, and a PDF in the browser's own viewer.
|
|
134
|
+
'Content-Security-Policy': "default-src 'self'; img-src 'self' data: blob:; frame-src blob:; style-src 'self'; script-src 'self'; font-src 'self'; connect-src 'self'; frame-ancestors 'none'; form-action 'self'; base-uri 'none'",
|
|
118
135
|
'X-Content-Type-Options': 'nosniff',
|
|
119
136
|
'Referrer-Policy': 'no-referrer',
|
|
120
137
|
'Cache-Control': 'no-store',
|
|
@@ -130,7 +147,7 @@ const fail = (status, msg, extra = {}) => Object.assign(new Error(msg), { status
|
|
|
130
147
|
// relay count on their own (rfails, rregistered), so the internet can't lock out this machine.
|
|
131
148
|
function load() {
|
|
132
149
|
try {
|
|
133
|
-
const w =
|
|
150
|
+
const w = readJSON(FILE);
|
|
134
151
|
const list = k => (Array.isArray(w[k]) ? w[k] : []);
|
|
135
152
|
return { codes: w.codes || [], fails: list('fails'), rfails: list('rfails'), registered: list('registered'), rregistered: list('rregistered'),
|
|
136
153
|
clients: w.clients || {}, grants: w.grants || {}, tokens: w.tokens || {} };
|
|
@@ -204,8 +221,18 @@ export async function pair(args) {
|
|
|
204
221
|
if (args[0] === '--machine' || args[0] === 'machine') return (await import('./admin.mjs')).pairMachine(args.slice(1));
|
|
205
222
|
if (args[0] === '--remote' || args[0] === 'remote') {
|
|
206
223
|
const rest = args.slice(1);
|
|
207
|
-
|
|
208
|
-
|
|
224
|
+
// --for <person>: the phone is theirs once it pairs (dibs people).
|
|
225
|
+
const f = rest.indexOf('--for');
|
|
226
|
+
let person = null;
|
|
227
|
+
if (f >= 0) {
|
|
228
|
+
const { readPeople, find } = await import('./people.mjs');
|
|
229
|
+
const p = readPeople();
|
|
230
|
+
const name = rest[f + 1] ?? die('--for needs a person\'s name: dibs connect --phone --for sam');
|
|
231
|
+
person = find(p, name) || die(`nobody called ${name} here. ${Object.keys(p).length ? `People: ${Object.keys(p).join(', ')}.` : 'Add them first: dibs people add ' + name}`);
|
|
232
|
+
rest.splice(f, 2);
|
|
233
|
+
}
|
|
234
|
+
if (rest.some(x => x !== '--allow-actions' && x !== '--allow-talk')) die('dibs pair --remote [--allow-actions | --allow-talk] [--for <person>]: --allow-actions lets that browser change things, not only look; --allow-talk also lets it message agents and answer them, with Face ID each time');
|
|
235
|
+
return (await import('./relay.mjs')).pairRemote({ act: rest.includes('--allow-actions'), talk: rest.includes('--allow-talk'), person });
|
|
209
236
|
}
|
|
210
237
|
if (args[0] === '--list' || args[0] === 'list') {
|
|
211
238
|
const w = load();
|
|
@@ -281,13 +308,15 @@ export function snapshot(j, t = now()) {
|
|
|
281
308
|
const m = j.machine || {};
|
|
282
309
|
const jobs = [
|
|
283
310
|
...(j.held || []).map(l => ({
|
|
284
|
-
id: l.id, state: l.plain?.paused ? 'paused' : 'running', who: l.agent || l.who, label: l.label || null, res: l.res, purpose: l.purpose || null,
|
|
311
|
+
id: l.id, state: l.plain?.paused ? 'paused' : 'running', who: l.agent || l.who, label: l.label || null, res: l.res, purpose: l.purpose || null, declared: l.declared ?? null,
|
|
285
312
|
cmd: short(masked(l.cmd)), project: base(l.cwd), kind: l.kind, started: l.start || null, endsAt: l.remaining > 0 ? t + l.remaining : null,
|
|
286
313
|
headline: l.plain?.headline || null, ends: l.plain?.endsText || null, paused: l.plain?.paused || null, mem: l.mem || null,
|
|
287
314
|
prio: l.prio || 'normal', idleMs: l.kind === 'hold' ? null : l.idleMs || null,
|
|
315
|
+
// How far the job says it is (src/jobprogress.mjs): ends already says it in words.
|
|
316
|
+
progress: l.progress ? { pct: l.progress.pct, done: l.progress.done ?? null, total: l.progress.total ?? null, unit: oneLine(short(l.progress.unit, 40)) } : null,
|
|
288
317
|
})),
|
|
289
318
|
...(j.waiting || []).map(q => ({
|
|
290
|
-
id: q.id, state: 'waiting', who: q.agent || q.who, label: q.label || null, res: q.res, purpose: q.purpose || null, cmd: short(masked(q.cmd)),
|
|
319
|
+
id: q.id, state: 'waiting', who: q.agent || q.who, label: q.label || null, res: q.res, purpose: q.purpose || null, declared: q.declared ?? null, cmd: short(masked(q.cmd)),
|
|
291
320
|
project: base(q.cwd), place: q.place, queued: q.enq || null, startsAt: q.expectStart || null, blocked: q.blocked || null,
|
|
292
321
|
headline: q.plain?.headline || null, est: q.est || null,
|
|
293
322
|
// What the Mac app's Needs and Queues read: how urgent, what kind of wait, why this place.
|
|
@@ -308,19 +337,81 @@ export function snapshot(j, t = now()) {
|
|
|
308
337
|
job: a.job ?? null, who: a.who || null, since: a.since, resolvedAt: a.resolvedAt || null, dismissed: !!a.dismissed })),
|
|
309
338
|
// Agents waiting on dibs listen: a message to them wakes them within seconds.
|
|
310
339
|
listening: Array.isArray(j.listening) ? j.listening : [],
|
|
340
|
+
// dibs halt: no new job starts until it lifts (null when none is on).
|
|
341
|
+
halt: j.halt ? { at: j.halt.at, until: j.halt.until ?? null, reason: j.halt.reason || null, by: j.halt.by || null } : null,
|
|
342
|
+
// Tasks agents handed to each other (src/handoffs.mjs), open or taken: names only, never sessions.
|
|
343
|
+
// carry: work an agent left unfinished when its session ended (src/carry.mjs), for the person to give to an agent or drop.
|
|
344
|
+
handoffs: (j.handoffs || []).map(x => ({ id: x.id, title: x.title, context: x.context, from: x.from, to: x.to, state: x.state, at: x.at, taker: x.taker, takenAt: x.takenAt,
|
|
345
|
+
...(x.carry && { carry: x.carry }) })),
|
|
346
|
+
// Work items (src/work.mjs): in flight, and closed lately with their proof. Names only.
|
|
347
|
+
work: Array.isArray(j.work) ? j.work : [],
|
|
311
348
|
};
|
|
312
349
|
}
|
|
313
350
|
|
|
314
351
|
// The agents, merged from their jobs and their progress posts.
|
|
315
|
-
|
|
352
|
+
// The last runs that ended today, newest first, for the phone's Jobs screen: what ran, for
|
|
353
|
+
// whom, how long, and whether it worked. Read from the event log's tail only: the whole log
|
|
354
|
+
// is up to 20 MB and the phone asks every few seconds.
|
|
355
|
+
const RECENT_SHOWN = 15;
|
|
356
|
+
const RECENT_TAIL = 512 * 1024;
|
|
357
|
+
// The Mac's name as its owner set it ("Jordan's Mac mini"), for the screens' titles; the board's
|
|
358
|
+
// name is the host name, which macOS makes from it by dropping what DNS can't carry ("Alexs-Mac-mini").
|
|
359
|
+
let computer;
|
|
360
|
+
const computerName = () => computer ??= process.platform !== 'darwin' ? Promise.resolve(null)
|
|
361
|
+
: new Promise(done => execFile('scutil', ['--get', 'ComputerName'], { timeout: 2000 }, (e, out) => done(e ? null : String(out).trim() || null)));
|
|
362
|
+
|
|
363
|
+
// What a job was doing in words: its agent's, or made from its resources for one without
|
|
364
|
+
// (before 0.0.191, a run the guard wrapped was labelled with its command's first words,
|
|
365
|
+
// which can hold a simulator's id or a long path). declared false marks words nobody wrote.
|
|
366
|
+
export const plainJob = j => ({ ...j, purpose: described(j), declared: declared(j) });
|
|
367
|
+
|
|
368
|
+
function recentRuns(t = now()) {
|
|
369
|
+
let text = '';
|
|
370
|
+
try {
|
|
371
|
+
const size = fs.statSync(EVENTS).size, from = Math.max(0, size - RECENT_TAIL);
|
|
372
|
+
const fd = fs.openSync(EVENTS, 'r');
|
|
373
|
+
try { const buf = Buffer.alloc(size - from); fs.readSync(fd, buf, 0, buf.length, from); text = buf.toString('utf8'); } finally { fs.closeSync(fd); }
|
|
374
|
+
if (from > 0) text = text.slice(text.indexOf('\n') + 1);
|
|
375
|
+
} catch { return []; }
|
|
376
|
+
const out = [];
|
|
377
|
+
for (const line of text.split('\n').reverse()) {
|
|
378
|
+
if (out.length >= RECENT_SHOWN) break;
|
|
379
|
+
if (!line.includes('"kind":"end"')) continue;
|
|
380
|
+
let e;
|
|
381
|
+
try { e = JSON.parse(line); } catch { continue; }
|
|
382
|
+
if (e.kind !== 'end' || t - e.at > DAY || !Array.isArray(e.res)) continue;
|
|
383
|
+
out.push(plainJob({ id: e.id, res: e.res, who: e.who, ...(e.label && { label: e.label }), purpose: e.purpose || null, code: e.code ?? null, ms: e.ms || 0, at: e.at, type: e.type || 'run' }));
|
|
384
|
+
}
|
|
385
|
+
return out;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// What dibs saw each agent do in the last day (src/trail.mjs), newest last: commits, merges,
|
|
389
|
+
// releases, uploads, test suites, deploys. Marked auto: dibs's record, not the agent's words.
|
|
390
|
+
const TRAIL_SHOWN = 12;
|
|
391
|
+
const trailDay = t => fresh('trail', () => trailNow({ since: t - DAY, t }), EVENTS_FRESH);
|
|
392
|
+
|
|
393
|
+
// me: with two or more people, the person looking. Each agent then says whose it is (owners: agent
|
|
394
|
+
// name -> person, from its threads; its posts say too), and the looker's own come first.
|
|
395
|
+
function people(b, posts, trail = [], me = null, owners = new Map()) {
|
|
316
396
|
const ts = taskList(posts);
|
|
317
|
-
const names = new Set([...b.jobs.map(x => x.who), ...b.later.map(x => x.who), ...ts.map(x => x.who), ...(b.listening || [])]);
|
|
397
|
+
const names = new Set([...b.jobs.map(x => x.who), ...b.later.map(x => x.who), ...ts.map(x => x.who), ...(b.listening || []), ...trail.map(x => x.who)]);
|
|
318
398
|
const last = new Map();
|
|
319
399
|
for (const p of posts) last.set(p.who, p);
|
|
400
|
+
const ownerOf = who => last.get(who)?.owner || owners.get(who) || null;
|
|
401
|
+
const others = a => (me && a.owner !== me ? 1 : 0);
|
|
320
402
|
return [...names].map(who => ({
|
|
321
403
|
who, jobs: b.jobs.filter(x => x.who === who), later: b.later.filter(x => x.who === who), tasks: ts.filter(x => x.who === who),
|
|
322
|
-
lastPost: last.get(who) || null, listening: (b.listening || []).includes(who),
|
|
323
|
-
|
|
404
|
+
lastPost: last.get(who) || null, listening: (b.listening || []).includes(who), trail: trail.filter(x => x.who === who).slice(-TRAIL_SHOWN),
|
|
405
|
+
...(me && ownerOf(who) && { owner: ownerOf(who) }),
|
|
406
|
+
})).sort((a, b2) => others(a) - others(b2) || (b2.lastPost?.at || 0) - (a.lastPost?.at || 0) || b2.jobs.length - a.jobs.length);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// Which person is looking, with two or more people: a paired device's owner (dibs people set
|
|
410
|
+
// <name> --device), or at the Mac itself, its macOS user's. null with one person, or when dibs can't tell.
|
|
411
|
+
export function viewer(session, p = readPeople()) {
|
|
412
|
+
if (!several(p)) return null;
|
|
413
|
+
if (session?.kind === 'remote') return byDevice(p, session.device);
|
|
414
|
+
return personOf({ p })?.name || null;
|
|
324
415
|
}
|
|
325
416
|
|
|
326
417
|
// The CLI, run as the person. What makes dibs take a caller for an agent is
|
|
@@ -328,7 +419,9 @@ function people(b, posts) {
|
|
|
328
419
|
// server was started as, and, with DIBS_NO_SESSION, the walk up the process
|
|
329
420
|
// tree for a Claude Code session. Without that, a server an agent started
|
|
330
421
|
// would sign the person's actions with the agent's name.
|
|
331
|
-
|
|
422
|
+
// DIBS_PERSON too: whoever started this server isn't whoever is on the paired phone (cli() sets it per call).
|
|
423
|
+
// DIBS_PROOF too: only a call src/relay.mjs checked brings one (actAs).
|
|
424
|
+
const NOT_PERSON = ['DIBS_AGENT', 'DIBS_AS', 'DIBS_LEASE', 'DIBS_REMOTE_JOB', 'DIBS_LATER_JOB', 'DIBS_PERSON', 'DIBS_PROOF'];
|
|
332
425
|
function personEnv() {
|
|
333
426
|
const env = { ...process.env, DIBS_NO_SESSION: '1', NO_COLOR: '1' };
|
|
334
427
|
for (const k of Object.keys(env)) if (AGENT_ENV.includes(k) || NOT_PERSON.includes(k) || /^(CLAUDE_CODE|CODEX_)/.test(k)) delete env[k];
|
|
@@ -357,8 +450,10 @@ function fresh(key, fn, life = BOARD_FRESH) {
|
|
|
357
450
|
return v;
|
|
358
451
|
}
|
|
359
452
|
// An action: the CLI's own words back, or its refusal. Exit 1 is "nothing matched" (gone already).
|
|
360
|
-
|
|
361
|
-
|
|
453
|
+
// me: the person acting, with two or more people (viewer()), so the record and the agents name them.
|
|
454
|
+
// proof: the phone's signature on this call (src/signed.mjs), kept with the message or answer it makes.
|
|
455
|
+
async function actAs(args, via, me = null, proof = null) {
|
|
456
|
+
const r = await cli(args, via, { ...(me && { DIBS_PERSON: me }), ...(proof && { DIBS_PROOF: JSON.stringify(proof) }) });
|
|
362
457
|
cached = null;
|
|
363
458
|
reads.clear();
|
|
364
459
|
if (r.code === 0) return { status: 200, json: { ok: true, said: r.out.trim() } };
|
|
@@ -366,6 +461,9 @@ async function actAs(args, via) {
|
|
|
366
461
|
return { status: r.code === 1 ? 404 : 409, json: { error: r.err || `dibs exited ${r.code}`, code: r.code } };
|
|
367
462
|
}
|
|
368
463
|
|
|
464
|
+
// A CLI answer that ran fine but changed nothing (its words match none): 404 with those words, as exit 1 would be.
|
|
465
|
+
const gone = (r, none) => (r.status === 200 && none.test(r.json.said) ? { status: 404, json: { error: r.json.said } } : r);
|
|
466
|
+
|
|
369
467
|
// What the CLI's JSON carries that the page never needs: session ids, pids,
|
|
370
468
|
// the folder and environment a scheduled run keeps (which can hold secrets).
|
|
371
469
|
const PRIVATE = new Set(['session', 'sessionId', 'spid', 'sstart', 'pid', 'pstart', 'pgid', 'env', 'cwd', 'agentId', 'sender']);
|
|
@@ -419,6 +517,8 @@ const nameOf = v => (typeof v === 'string' && NAME.test(v) ? v : bad('that is no
|
|
|
419
517
|
// A message's words are one argument. One that starts with a dash would read as a
|
|
420
518
|
// flag, so it goes with a space in front, which dibs trims.
|
|
421
519
|
const words = v => (v.startsWith('-') ? ` ${v}` : v);
|
|
520
|
+
// How much of a question the phone signs with its answer (asked): the start says which question it was.
|
|
521
|
+
const ASKED_MAX = 300;
|
|
422
522
|
|
|
423
523
|
// Agents dibs has seen in the last 30 days, or on the board now.
|
|
424
524
|
async function known() {
|
|
@@ -447,13 +547,13 @@ async function machinesOf() {
|
|
|
447
547
|
|
|
448
548
|
// Who's signed in, as dibs pair --list says it: the page's sessions, MCP clients, paired devices.
|
|
449
549
|
async function pairedList() {
|
|
450
|
-
// relay.mjs imports this file, so it comes in when needed, as dibs pair does it.
|
|
451
|
-
const relayDevices = (await import('./relay.mjs')).devices;
|
|
452
550
|
const w = load(), t = now();
|
|
453
551
|
const live = Object.entries(w.tokens).filter(([, x]) => x.kind !== 'access' && x.exp > t)
|
|
454
552
|
.map(([h, x]) => ({ id: h.slice(0, 8), what: x.kind === 'session' ? 'web page' : `MCP: ${w.clients[x.client]?.name || x.client}`, when: `signed in ${new Date(x.created).toLocaleString()}`, at: x.created }));
|
|
455
|
-
|
|
456
|
-
|
|
553
|
+
// relay.mjs imports this file, so it comes in when needed, as dibs pair does it.
|
|
554
|
+
const { devices: relayDevices, level } = await import('./relay.mjs');
|
|
555
|
+
return [...live, ...relayDevices().map(d => ({ id: d.id.slice(0, 8), what: `remote: ${d.name}, ${level(d)}`,
|
|
556
|
+
when: `paired ${new Date(d.created).toLocaleString()}`, at: d.created, seen: d.seen || null, remote: true, act: d.act === true, talk: d.talk === true && !!d.tk }))];
|
|
457
557
|
}
|
|
458
558
|
|
|
459
559
|
function historyOf(since, b, t = now()) {
|
|
@@ -466,67 +566,141 @@ function historyOf(since, b, t = now()) {
|
|
|
466
566
|
return {
|
|
467
567
|
since, from: h.since, until: h.until, lines: verdict(h, loadConfig()), resources: h.resources, agents: h.agents, hourly: h.hourly,
|
|
468
568
|
changes: recent.filter(e => e.kind === 'override').reverse().slice(0, 60).map(scrub),
|
|
469
|
-
|
|
569
|
+
// A run's start and end lead with what it was doing, in words, as the board does.
|
|
570
|
+
events: recent.filter(e => e.kind !== 'override').reverse().map(e => scrub(['start', 'end'].includes(e.kind) && Array.isArray(e.res) ? plainJob(e) : e)),
|
|
470
571
|
};
|
|
471
572
|
}
|
|
472
573
|
|
|
473
574
|
// What a paired browser may call through the relay. An allow-list, so a route added
|
|
474
575
|
// later stays on the Mac until someone decides it's safe remotely. Everything else is
|
|
475
|
-
// local-only:
|
|
476
|
-
//
|
|
477
|
-
//
|
|
478
|
-
|
|
479
|
-
//
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
576
|
+
// local-only: the hook edits ~/.claude/settings.json; the hours decide when the person
|
|
577
|
+
// gets asked. Telling an agent something or answering its question arrives as "Message
|
|
578
|
+
// from the person", which agents act on, shell commands included, so those (REMOTE_TALK)
|
|
579
|
+
// go only from a phone paired with --allow-talk, each call signed after Face ID.
|
|
580
|
+
// The paired devices list (/api/paired) is here so the dibs app can show who else can reach
|
|
581
|
+
// this Mac; signing one out is a talk call.
|
|
582
|
+
const REMOTE_READ = new Set(['/api/board', '/api/posts', '/api/questions', '/api/threads', '/api/later', '/api/recap', '/api/decisions', '/api/work', '/api/agents', '/api/secrets', '/api/spend', '/api/reviews', '/api/history', '/api/stats', '/api/settings', '/api/machines', '/api/paired', '/api/rules', '/api/envs', '/api/pending']);
|
|
583
|
+
// One run's details (/api/runs/<id>): what it meant, its command (masked, as the board shows it) and its numbers.
|
|
584
|
+
const REMOTE_READ_ONE = [/^\/api\/runs\/\d{1,12}$/];
|
|
585
|
+
// What a message carries: a file sent with it, and a file or folder shared live with --link.
|
|
586
|
+
// Agents chose to show these to the person, and nothing secret-looking is ever served (src/media.mjs).
|
|
587
|
+
const REMOTE_READ_AT = [/^\/api\/file\/[^/]+$/, /^\/api\/link\/[^/]+$/];
|
|
588
|
+
// Only for a device paired with --allow-actions. Marking a thread read (/api/read) is here, not
|
|
589
|
+
// with the talk calls: it tells no agent anything, so a phone can do it on opening a thread
|
|
590
|
+
// without asking for Face ID.
|
|
591
|
+
// Dismissing an alert and setting the hours or the attention budget change what the person is
|
|
592
|
+
// shown and when, and tell no agent anything. Nor does revoking a decision: the next agent to ask
|
|
593
|
+
// is just asked. Removing a standing rule only sends that kind of question back to the person.
|
|
594
|
+
// Dropping a handoff tells no agent anything new: the one that took it hears it was cancelled, as with stopping its job.
|
|
595
|
+
const REMOTE_ACT = [/^\/api\/jobs\/[^/]+\/(boost|pause|resume|stop)$/, /^\/api\/cap$/, /^\/api\/pace$/, /^\/api\/later\/[^/]+\/cancel$/, /^\/api\/read$/, /^\/api\/seen$/, /^\/api\/reveal$/,
|
|
596
|
+
/^\/api\/alerts\/dismiss$/, /^\/api\/hours$/, /^\/api\/attention$/, /^\/api\/decisions\/[^/]+\/revoke$/, /^\/api\/rules\/[^/]+\/remove$/, /^\/api\/secrets\/revoke$/, /^\/api\/handoffs\/[^/]+\/drop$/, /^\/api\/work\/[^/]+\/drop$/];
|
|
597
|
+
// Any paired device, about itself only: the dibs app signing up for notifications (src/relay.mjs
|
|
598
|
+
// registerPush, which handles it before api(), on the session's own device record).
|
|
599
|
+
const REMOTE_SELF = new Set(['/api/push']);
|
|
600
|
+
// Only for a phone paired with --allow-talk, and only with a signature src/relay.mjs checked (checkTalk).
|
|
601
|
+
// A message to every agent and a halt reach agents in the person's words, so they're talk calls
|
|
602
|
+
// too; so is signing a device out, which a stolen phone mustn't do without Face ID. Adding a standing
|
|
603
|
+
// rule answers questions in the person's place from then on, so it's a talk call like an answer.
|
|
604
|
+
// Giving a handoff to an agent sends it work to do, so it's a talk call too.
|
|
605
|
+
// A vote reaches the agent that asked as the person's choice, as an answer does; clearing what's
|
|
606
|
+
// pending dismisses questions, which ends a waiting agent's wait.
|
|
607
|
+
const REMOTE_TALK = [/^\/api\/rules$/, /^\/api\/vote$/, /^\/api\/pending\/clear$/, /^\/api\/questions\/[^/]+\/(answer|dismiss)$/, /^\/api\/handoffs\/[^/]+\/give$/, /^\/api\/tell$/, /^\/api\/tell\/all$/, /^\/api\/halt$/, /^\/api\/halt\/off$/, /^\/api\/pair\/revoke$/];
|
|
608
|
+
export const talkRoute = (method, route) => method === 'POST' && REMOTE_TALK.some(r => r.test(route));
|
|
609
|
+
// null when a remote device may make this call, else 'look' (it needs --allow-actions), 'talk'
|
|
610
|
+
// (it needs --allow-talk and a signed call: signed) or 'local' (never remotely).
|
|
611
|
+
export function remoteAccess(method, route, canAct, signed = false) {
|
|
612
|
+
if (method === 'GET' && (REMOTE_READ.has(route) || REMOTE_READ_ONE.some(r => r.test(route)) || REMOTE_READ_AT.some(r => r.test(route)))) return null;
|
|
613
|
+
if (method === 'POST' && REMOTE_SELF.has(route)) return null;
|
|
484
614
|
if (method === 'POST' && REMOTE_ACT.some(r => r.test(route))) return canAct ? null : 'look';
|
|
615
|
+
if (talkRoute(method, route)) return signed ? null : 'talk';
|
|
485
616
|
return 'local';
|
|
486
617
|
}
|
|
487
|
-
// Every name web/transport.js deviceName() can produce.
|
|
488
|
-
const BROWSER_LABEL = /^(Edge|Firefox|Chrome|Safari|A browser)( on (iPhone|iPad|Android|Mac|Windows|Linux))?$/;
|
|
618
|
+
// Every name web/transport.js deviceName() can produce, and the dibs app's (docs/relay.md).
|
|
619
|
+
const BROWSER_LABEL = /^(Edge|Firefox|Chrome|Safari|A browser|dibs app)( on (iPhone|iPad|Android|Mac|Windows|Linux))?$/;
|
|
489
620
|
export const LOCAL_ONLY_TEXT = 'That only works on the Mac itself (the dibs app, or dibs web at http://127.0.0.1:7421), never from a paired browser.';
|
|
621
|
+
export const talkText = id => `This browser can't message agents or answer their questions. To let a phone do that, with Face ID each time, run dibs pair --remote --allow-talk on your Mac and open that link on it, then dibs pair --revoke ${String(id || '').slice(0, 8)} to remove this pairing.`;
|
|
622
|
+
const NEEDS_UV = 'Sending that from this phone needs Face ID each time, and this request came without it.';
|
|
490
623
|
export const lookOnlyText = id => `This browser can only look. To let it change things, run dibs pair --remote --allow-actions on your Mac and open that link here, then dibs pair --revoke ${String(id || '').slice(0, 8)} to remove this look-only pairing.`;
|
|
491
624
|
|
|
492
625
|
// Every page request, after the caller's session was checked: the HTTP
|
|
493
626
|
// handler here, or the relay for a decrypted request. session is that check's
|
|
494
627
|
// record, for the log. Returns { status, json }.
|
|
495
|
-
|
|
628
|
+
// range: the HTTP Range header, for a file read (?range= says the same through the relay).
|
|
629
|
+
export async function api({ method = 'GET', path: where = '/', body = null, session = null, range = null } = {}) {
|
|
496
630
|
const url = new URL(where, 'http://dibs');
|
|
497
631
|
const route = url.pathname, q = url.searchParams;
|
|
498
632
|
// src/relay.mjs refuses these before calling; this is the second lock on the same door.
|
|
499
633
|
const remote = session?.kind === 'remote';
|
|
500
|
-
const refused = remote && remoteAccess(method, route, session.act === true);
|
|
501
|
-
if (refused) return { status: 403, json: { error: refused === 'look' ? lookOnlyText(session.device) : LOCAL_ONLY_TEXT } };
|
|
634
|
+
const refused = remote && remoteAccess(method, route, session.act === true, session.talk === true && session.uv === true);
|
|
635
|
+
if (refused) return { status: 403, json: { error: refused === 'look' ? lookOnlyText(session.device) : refused === 'talk' ? (session.talk === true ? NEEDS_UV : talkText(session.device)) : LOCAL_ONLY_TEXT } };
|
|
502
636
|
// The device chose its own name, and this text reaches agents ("stopped by the person via ..."),
|
|
503
637
|
// so only a label from the page's own fixed vocabulary goes in it; the free name stays in dibs pair --list.
|
|
504
638
|
const label = BROWSER_LABEL.test(session?.name || '') ? session.name : 'a browser';
|
|
505
639
|
const via = remote ? `${label} (remote ${String(session.device || '').replace(/[^A-Za-z0-9_-]/g, '').slice(0, 8)})` : null;
|
|
506
|
-
const
|
|
640
|
+
const me = viewer(session);
|
|
641
|
+
const act = args => actAs(args, via, me, remote && session.uv === true ? session.proof : null);
|
|
507
642
|
const given = body && typeof body === 'object' && !Array.isArray(body) ? body : {};
|
|
508
|
-
// A reason travels to the job's agent as the person's words; from a paired browser the action runs, the words
|
|
509
|
-
|
|
643
|
+
// A reason travels to the job's agent as the person's words; from a paired browser the action runs, the words
|
|
644
|
+
// don't, unless the call was signed after Face ID (a talk call: a halt's reason, say).
|
|
645
|
+
const a = remote && session.uv !== true ? { ...given, reason: undefined } : given;
|
|
510
646
|
const ok = json => ({ status: 200, json });
|
|
511
647
|
try {
|
|
512
648
|
if (method === 'GET') {
|
|
513
649
|
if (route === '/api/board') {
|
|
650
|
+
// The page is one of the looks that finds sessions ended mid-task; what it finds shows on the next.
|
|
651
|
+
sweepSoon();
|
|
514
652
|
const b = await board();
|
|
515
653
|
const t = now();
|
|
516
654
|
const posts = readPosts({ since: t - DAY, limit: POSTS_SHOWN }).map(shown);
|
|
655
|
+
// Who's looking: the page hides what this caller would only be refused (remoteAccess).
|
|
656
|
+
const caller = { remote, canAct: !remote || session.act === true, canTalk: !remote || session.talk === true };
|
|
517
657
|
// ?posts=0: the day's posts (most of the board's bytes) stay apart, at GET /api/posts, for
|
|
518
658
|
// the one view that lists them; the agents still carry each one's tasks and last post.
|
|
519
659
|
// The page's first paint through the relay waits on a third of the bytes.
|
|
520
|
-
|
|
521
|
-
|
|
660
|
+
const named = { computer: await computerName() };
|
|
661
|
+
const owners = me ? new Map(fresh(`threads ${me}`, () => threadsJson(now(), null, { described: true, me })).threads.filter(th => th.owner).map(th => [th.agent, th.owner])) : undefined;
|
|
662
|
+
const agents = people(b, posts, trailDay(t), me, owners);
|
|
663
|
+
const you = me ? { you: me } : {};
|
|
664
|
+
if (q.get('posts') === '0') return ok({ ...b, ...named, jobs: b.jobs.map(plainJob), agents, posts: [], postsApart: true, recent: fresh('recent', () => recentRuns(t), EVENTS_FRESH), now: t, ...caller, ...you });
|
|
665
|
+
return ok({ ...b, ...named, jobs: b.jobs.map(plainJob), agents, posts, now: t, ...caller, ...you });
|
|
522
666
|
}
|
|
667
|
+
const fm = route.match(/^\/api\/file\/([^/]+)$/);
|
|
668
|
+
if (fm) return bytesOf(fileOf(fm[1]), range ?? q.get('range'), remote);
|
|
669
|
+
const lm = route.match(/^\/api\/link\/([^/]+)$/);
|
|
670
|
+
if (lm) {
|
|
671
|
+
const r = linkOf(lm[1], q.get('path') || '');
|
|
672
|
+
if (r?.refused) return { status: 403, json: { error: r.refused } };
|
|
673
|
+
return r?.dir ? ok(r.dir) : bytesOf(r, range ?? q.get('range'), remote);
|
|
674
|
+
}
|
|
675
|
+
// Everything waiting on the person, most pressing first (src/talk.mjs pendingJson). /api/decisions is the
|
|
676
|
+
// kept decisions (src/decisions.mjs), not this list.
|
|
677
|
+
if (route === '/api/pending') return ok(scrub(fresh('pending', () => pendingJson())));
|
|
523
678
|
if (route === '/api/posts') return ok(readPosts({ since: now() - DAY, limit: POSTS_SHOWN }).map(shown));
|
|
524
|
-
|
|
679
|
+
// With two or more people, each sees their own agents' questions and threads first (me), and everyone's after.
|
|
680
|
+
if (route === '/api/questions') return ok(scrub(fresh(`questions ${me}`, () => ({ ...questionsJson(loadConfig(), now(), null, me), ...(me && { you: me }) }))));
|
|
525
681
|
if (route === '/api/threads') {
|
|
526
|
-
const j = fresh(
|
|
527
|
-
return ok(scrub({ ...j, threads: j.threads.map(th => ({ ...th, messages: th.messages.slice(-THREAD_SHOWN) })) }));
|
|
682
|
+
const j = fresh(`threads ${me}`, () => threadsJson(now(), null, { described: true, me }));
|
|
683
|
+
return ok(scrub({ ...j, ...(me && { you: me }), threads: j.threads.map(th => ({ ...th, messages: th.messages.slice(-THREAD_SHOWN) })) }));
|
|
528
684
|
}
|
|
529
685
|
if (route === '/api/later') return ok(scrub(fresh('later', () => laterJson()).jobs));
|
|
686
|
+
// Every project's environments: what's on each, who has it now, and its last turns (src/envs.mjs).
|
|
687
|
+
if (route === '/api/envs') return ok(scrub(fresh('envs', () => ({ envs: envsJson({ st: peek() }) }))));
|
|
688
|
+
// ?since=<ms>: the browser's own last look (the page keeps it), so each device catches up from its own.
|
|
689
|
+
if (route === '/api/recap') return ok(scrub(recapNow(sinceOf(Number(q.get('since'))), now(), me)));
|
|
690
|
+
// Every decision kept, newest first, revoked ones marked; ?about=words: the closest first.
|
|
691
|
+
if (route === '/api/decisions') return ok(fresh(`decisions ${q.get('about') || ''}`, () => decisionsJson({ about: String(q.get('about') || '').slice(0, 200) })));
|
|
692
|
+
// Every work item with its log and proof, and agents' progress tasks as items (src/work.mjs). ?all=1: closed ones too.
|
|
693
|
+
if (route === '/api/work') { const all = q.get('all') === '1'; return ok(scrub(fresh(`work ${all}`, () => workJson({ all })))); }
|
|
694
|
+
// Names, rules and the use log of stored credentials (src/vault.mjs). Never a value.
|
|
695
|
+
if (route === '/api/secrets') return ok(secretsJson());
|
|
696
|
+
// The spend ledger (src/spend.mjs): this month and today by project, agent and category, the caps, open holds.
|
|
697
|
+
if (route === '/api/spend') return ok(scrub(fresh('spend', () => spendJson())));
|
|
698
|
+
// Reviews agents asked of each other (src/reviews.mjs): open ones and the last day's answers, for the phone.
|
|
699
|
+
if (route === '/api/reviews') return ok(scrub({ reviews: reviewsNow() }));
|
|
700
|
+
// Each agent in plain words (src/picture.mjs): for, needs you, blocked, now, plan, results, latest.
|
|
701
|
+
if (route === '/api/agents') return ok(scrub(fresh('agents', () => agentsJson())));
|
|
702
|
+
const run = route.match(/^\/api\/runs\/([^/]+)$/);
|
|
703
|
+
if (run) { const r = runJson(idOf(run[1])); return r ? ok(scrub(r)) : { status: 404, json: { error: `dibs has no record of run #${run[1]}. Runs are kept 30 days.` } }; }
|
|
530
704
|
if (route === '/api/history') {
|
|
531
705
|
const since = spanOf(q.get('since'));
|
|
532
706
|
return ok(fresh(`history ${since}`, () => historyOf(since, board()), EVENTS_FRESH));
|
|
@@ -543,12 +717,21 @@ export async function api({ method = 'GET', path: where = '/', body = null, sess
|
|
|
543
717
|
if (route === '/api/accounts') return ok(await (await import('./connect.mjs')).accountsJson());
|
|
544
718
|
// The coordinator's open machine codes and machines; { none } when this machine runs no coordinator. Local only.
|
|
545
719
|
if (route === '/api/machines/pairs') return ok((await (await import('./admin.mjs')).machinePairs()) || { none: true });
|
|
720
|
+
if (route === '/api/rules') return ok(scrub(rulesJson()));
|
|
546
721
|
if (route === '/api/settings') {
|
|
547
|
-
return ok(fresh('settings', () => ({ pace: paceJson(), hours: hoursOf(loadConfig()), hook: scrub(guardJson()) })));
|
|
722
|
+
return ok(fresh('settings', () => ({ pace: paceJson(), hours: hoursOf(loadConfig()), attention: attentionOf(loadConfig()), rules: scrub(rulesJson().rules), hook: scrub(guardJson()) })));
|
|
548
723
|
}
|
|
549
724
|
return { status: 404, json: { error: 'not here' } };
|
|
550
725
|
}
|
|
551
726
|
if (method !== 'POST') return { status: 405, json: { error: 'GET to read, POST to change' } };
|
|
727
|
+
// Dropping a work item, as dibs work drop: its maker and whoever claimed it are told, by name. The reason
|
|
728
|
+
// reaches them only from the Mac or a call signed after Face ID (a), like a job's stop.
|
|
729
|
+
const item = route.match(/^\/api\/work\/([^/]+)\/drop$/);
|
|
730
|
+
if (item) {
|
|
731
|
+
const id = /^[wh]?\d{1,9}$/i.test(item[1]) ? `w${item[1].replace(/^[wh]/i, '')}` : bad('a work item id looks like w3');
|
|
732
|
+
const why = a.reason == null || a.reason === '' ? [] : [words(textOf(a.reason, MAX_REASON, 'the reason').replace(/[\r\n]+/g, ' '))];
|
|
733
|
+
return act(['work', 'drop', id, ...why]);
|
|
734
|
+
}
|
|
552
735
|
const job = route.match(/^\/api\/jobs\/([^/]+)\/(boost|pause|resume|stop)$/);
|
|
553
736
|
if (job) {
|
|
554
737
|
const id = idOf(job[1]), verb = job[2];
|
|
@@ -571,15 +754,79 @@ export async function api({ method = 'GET', path: where = '/', body = null, sess
|
|
|
571
754
|
if (!(await known()).has(who)) return { status: 404, json: { error: `dibs hasn't seen an agent called ${who} in the last 30 days.` } };
|
|
572
755
|
return act(['cap', who, prioOf(a.prio, ['off'])]);
|
|
573
756
|
}
|
|
574
|
-
|
|
757
|
+
// The CLI says so and exits 0 when nothing matched; the page shows that as not done.
|
|
758
|
+
// Revoking a credential only ever takes access away, so a phone that may act can do it.
|
|
759
|
+
if (route === '/api/secrets/revoke') return gone(await act(['secret', 'revoke', /^[A-Za-z_][A-Za-z0-9_]{0,63}$/.test(String(a.name)) ? String(a.name) : bad('revoke a secret by its name')]), /^no secret called/);
|
|
760
|
+
if (route === '/api/alerts/dismiss') return gone(await act(['alerts', 'dismiss', /^[\w:#.-]{1,80}$/.test(String(a.id)) ? String(a.id) : bad('dismiss an alert by its id')]), /^No open alert matches/);
|
|
575
761
|
const qa = route.match(/^\/api\/questions\/([^/]+)\/(answer|dismiss)$/);
|
|
762
|
+
// asked: the question as the phone showed it, signed with the answer, so a question changed since
|
|
763
|
+
// can't collect an answer the person gave to other words.
|
|
764
|
+
if (qa?.[2] === 'answer' && typeof a.asked === 'string' && allQuestions().find(x => x.id === Number(qa[1]))?.text?.slice(0, ASKED_MAX) !== a.asked.slice(0, ASKED_MAX))
|
|
765
|
+
return { status: 409, json: { error: 'That question changed after your phone showed it, so nothing was answered. Look at it again.' } };
|
|
576
766
|
if (qa) return qa[2] === 'answer' ? act(['answer', qidOf(qa[1]), words(textOf(a.text, MAX_MESSAGE, 'the answer'))]) : act(['questions', 'dismiss', qidOf(qa[1])]);
|
|
767
|
+
// Taking a decision back tells no agent anything; the next one to ask just gets asked.
|
|
768
|
+
const dr = route.match(/^\/api\/decisions\/([^/]+)\/revoke$/);
|
|
769
|
+
if (dr) return act(['decisions', 'revoke', /^\d{1,9}$/.test(dr[1]) ? String(Number(dr[1])) : bad('a decision id is a number'), ...reasonOf(a.reason)]);
|
|
770
|
+
// The relay connector signs a phone up for notifications itself; nothing else may.
|
|
771
|
+
if (route === '/api/push') return { status: 403, json: { error: 'Only the dibs app on a paired phone signs up for notifications, and it does that itself.' } };
|
|
772
|
+
// A handoff (work an agent left unfinished, most often) given to an agent, or dropped.
|
|
773
|
+
const ho = route.match(/^\/api\/handoffs\/([^/]+)\/(give|drop)$/);
|
|
774
|
+
if (ho) {
|
|
775
|
+
const id = /^[hw]?\d{1,9}$/.test(ho[1]) ? ho[1] : bad('a handoff id is its w number');
|
|
776
|
+
return ho[2] === 'give' ? act(['handoff', 'give', id, nameOf(a.to)]) : act(['handoff', 'cancel', id]);
|
|
777
|
+
}
|
|
778
|
+
// A vote on a poll, as dibs poll vote. Through the relay a signed body is flat strings, so
|
|
779
|
+
// options may come as one string, a choice a line.
|
|
780
|
+
if (route === '/api/vote') {
|
|
781
|
+
const id = /^p\d{1,9}$/.test(String(a.poll)) ? String(a.poll) : bad('a poll id looks like p3');
|
|
782
|
+
const list = Array.isArray(a.options) ? a.options : typeof a.options === 'string' ? a.options.split('\n') : typeof a.option === 'string' ? [a.option] : bad('options is the list of choices to vote for');
|
|
783
|
+
if (!list.length || list.length > 12 || !list.every(x => typeof x === 'string' && x.trim() && x.length <= 200)) bad('options is 1 to 12 of the poll\'s choices');
|
|
784
|
+
return act(['poll', 'vote', id, ...list.map(x => words(x.trim()))]);
|
|
785
|
+
}
|
|
786
|
+
if (route === '/api/pending/clear') return act(['pending', 'clear', /^[qpm]\d{1,12}$/.test(String(a.id)) ? String(a.id) : bad('clear an id from the pending list: q12, p3 or m40')]);
|
|
787
|
+
// answers: a reply typed under a question is that question's answer (dibs answer), so it reaches
|
|
788
|
+
// the agent tied to the question, not as a bare line it has to guess about.
|
|
789
|
+
if (route === '/api/tell' && a.answers != null && a.answers !== '') return act(['answer', qidOf(a.answers), words(textOf(a.text, MAX_MESSAGE, 'the answer'))]);
|
|
577
790
|
if (route === '/api/tell') return act(['tell', nameOf(a.to), words(textOf(a.text, MAX_MESSAGE, 'the message'))]);
|
|
791
|
+
// Every agent running here, as dibs tell --all.
|
|
792
|
+
if (route === '/api/tell/all') return act(['tell', '--all', words(textOf(a.text, MAX_MESSAGE, 'the message'))]);
|
|
793
|
+
// dibs halt: every running agent is told, in the person's words.
|
|
794
|
+
if (route === '/api/halt') {
|
|
795
|
+
const span = a.for == null || a.for === '' ? null : /^\d{1,4}[smh]$/.test(String(a.for)) ? String(a.for) : bad('for is how long, like 10m or 1h');
|
|
796
|
+
if (!span && !a.reason) bad('say how long, or why: it holds until lifted');
|
|
797
|
+
return act(['halt', ...(span ? ['--for', span] : []), ...reasonOf(a.reason)]);
|
|
798
|
+
}
|
|
799
|
+
if (route === '/api/halt/off') return act(['halt', 'off']);
|
|
578
800
|
if (route === '/api/read') return act(['threads', 'read', nameOf(a.to)]);
|
|
801
|
+
// The person saw a thread's messages: each agent line gets seenAt, which its agent can read back.
|
|
802
|
+
if (route === '/api/seen') return act(['threads', 'read', nameOf(a.to)]);
|
|
803
|
+
// Show a message's file, or a file under a shared link, in the Mac's Finder. Opens nothing, runs nothing.
|
|
804
|
+
if (route === '/api/reveal') {
|
|
805
|
+
const found = typeof a.file === 'string' ? fileOf(a.file) : typeof a.link === 'string' ? linkOf(a.link, typeof a.path === 'string' ? a.path : '') : bad('reveal a file id (file) or a link id (link, path)');
|
|
806
|
+
if (found?.refused) return { status: 403, json: { error: found.refused } };
|
|
807
|
+
const where = found?.file || (found?.dir && path.join(found.dir.root, found.dir.path));
|
|
808
|
+
if (!where) return { status: 404, json: { error: 'no such file: it was never sent, or it is more than a week old' } };
|
|
809
|
+
const [cmd, ...pre] = process.env.DIBS_REVEAL ? [process.env.DIBS_REVEAL] : process.platform === 'darwin' ? ['open', '-R'] : ['xdg-open'];
|
|
810
|
+
const args = process.platform === 'darwin' || process.env.DIBS_REVEAL ? [...pre, where] : [path.dirname(where)];
|
|
811
|
+
await new Promise(done => execFile(cmd, args, { timeout: 5000 }, () => done()));
|
|
812
|
+
return ok({ ok: true, path: where });
|
|
813
|
+
}
|
|
579
814
|
const lc = route.match(/^\/api\/later\/([^/]+)\/cancel$/);
|
|
580
815
|
if (lc) return act(['later', 'cancel', laterOf(lc[1])]);
|
|
581
816
|
if (route === '/api/pace') return act(['pace', a.pace === 'off' || Object.hasOwn(PACES, a.pace) ? a.pace : bad(`pace is one of ${Object.keys(PACES).join(', ')}, or off`)]);
|
|
582
817
|
if (route === '/api/hours') return act(['hours', a.hours === 'off' || /^\d{1,2}:\d{2}-\d{1,2}:\d{2}$/.test(a.hours) ? a.hours : bad('hours look like 09:00-23:00, or off')]);
|
|
818
|
+
if (route === '/api/attention') return act(['attention', a.perHour === 'off' || a.perHour === null ? 'off' : Number.isInteger(a.perHour) && a.perHour >= 0 && a.perHour < 1000 ? String(a.perHour) : bad('perHour is how many notifications an hour (0 to 999), or off')]);
|
|
819
|
+
const rr = route.match(/^\/api\/rules\/([^/]+)\/remove$/);
|
|
820
|
+
if (rr) return act(['rules', 'remove', /^r\d{1,6}$/.test(rr[1]) ? rr[1] : bad('remove a rule by its id, like r3')]);
|
|
821
|
+
// A standing rule, as dibs rules add has it.
|
|
822
|
+
if (route === '/api/rules') {
|
|
823
|
+
const about = typeof a.about === 'string' && ABOUT.test(a.about) ? a.about : bad('about is the kind of question: lowercase letters, digits and dashes');
|
|
824
|
+
const list = (v, what) => (v == null ? [] : Array.isArray(v) && v.length <= 10 && v.every(w => typeof w === 'string' && w.trim() && w.length <= 60 && !w.includes(',')) ? v.map(w => w.trim()) : bad(`${what} is a list of up to 10 words`));
|
|
825
|
+
const span = a.between == null || a.between === '' ? null : /^\d{1,2}:\d{2}-\d{1,2}:\d{2}$/.test(a.between) ? a.between : bad('between looks like 18:00-08:00');
|
|
826
|
+
return act(['rules', 'add', '--about', about, '--answer', words(textOf(a.answer, 200, 'the answer')),
|
|
827
|
+
...list(a.if, 'if').flatMap(w => ['--if', w]), ...list(a.unless, 'unless').flatMap(w => ['--unless', w]),
|
|
828
|
+
...(span ? ['--between', span] : []), ...(a.why ? ['-m', words(textOf(a.why, MAX_MESSAGE, 'why'))] : [])]);
|
|
829
|
+
}
|
|
583
830
|
if (route === '/api/hook') return act(['guard', 'install']);
|
|
584
831
|
// A new one-time code, shown on the page as the Mac app shows it. Local only, as every pairing is.
|
|
585
832
|
if (route === '/api/pair') {
|
|
@@ -588,11 +835,11 @@ export async function api({ method = 'GET', path: where = '/', body = null, sess
|
|
|
588
835
|
}
|
|
589
836
|
// A phone or another browser: the link dibs pair --remote prints, and its QR code as a grid the page draws.
|
|
590
837
|
if (route === '/api/pair/remote') {
|
|
591
|
-
const r = await act(['pair', '--remote', ...(a.act === true ? ['--allow-actions'] : [])]);
|
|
838
|
+
const r = await act(['pair', '--remote', ...(a.talk === true ? ['--allow-talk'] : a.act === true ? ['--allow-actions'] : [])]);
|
|
592
839
|
const link = r.status === 200 ? r.json.said.split('\n').find(l => /^https:\/\//.test(l.trim()))?.trim() : null;
|
|
593
840
|
if (!link) return r.status === 200 ? { status: 502, json: { error: 'dibs pair --remote printed no link' } } : r;
|
|
594
841
|
const code = /^Code: ([0-9A-Z]{4}-[0-9A-Z]{4}-[0-9A-Z]{4})$/m.exec(r.json.said)?.[1] || null;
|
|
595
|
-
return ok({ link, code, qr: qr(link).map(row => row.map(Boolean)), act: a.act === true });
|
|
842
|
+
return ok({ link, code, qr: qr(link).map(row => row.map(Boolean)), act: a.act === true || a.talk === true, talk: a.talk === true });
|
|
596
843
|
}
|
|
597
844
|
// A machine joins the group with this code: dibs pair --machine. Local only, never through the relay:
|
|
598
845
|
// whoever joins can run commands on every machine in the group.
|
|
@@ -624,7 +871,7 @@ export async function api({ method = 'GET', path: where = '/', body = null, sess
|
|
|
624
871
|
if (!link) return r.status === 200 ? { status: 502, json: { error: 'dibs connect --account printed no link' } } : r;
|
|
625
872
|
return ok({ link, qr: qr(link).map(row => row.map(Boolean)) });
|
|
626
873
|
}
|
|
627
|
-
if (route === '/api/pair/revoke') return act(['pair', '--revoke', a.id === 'all' || /^[0-9a-f]{8}$/.test(a.id) ? a.id : bad('sign out an id from the list, or all')]);
|
|
874
|
+
if (route === '/api/pair/revoke') return gone(await act(['pair', '--revoke', a.id === 'all' || /^[0-9a-f]{8}$/.test(a.id) ? a.id : bad('sign out an id from the list, or all')]), /^Nothing matched/);
|
|
628
875
|
return { status: 404, json: { error: 'not here' } };
|
|
629
876
|
} catch (e) {
|
|
630
877
|
// A read that couldn't be done is on the record, so the next one can be traced.
|
|
@@ -634,12 +881,47 @@ export async function api({ method = 'GET', path: where = '/', body = null, sess
|
|
|
634
881
|
}
|
|
635
882
|
}
|
|
636
883
|
|
|
884
|
+
// A stored or linked file's bytes. Here: { raw } for the HTTP handler to stream, the whole file or the
|
|
885
|
+
// range asked for. Through the relay, whose frames carry JSON: the bytes as base64, at most
|
|
886
|
+
// RELAY_CHUNK at a time, and next says the range to ask for after these.
|
|
887
|
+
function bytesOf(found, spec, remote) {
|
|
888
|
+
if (!found?.file) return { status: 404, json: { error: 'no such file: it was never sent, or it is more than a week old' } };
|
|
889
|
+
const { file, meta } = found;
|
|
890
|
+
let size;
|
|
891
|
+
try { size = fs.statSync(file).size; } catch { return { status: 404, json: { error: 'that file is gone from this Mac' } }; }
|
|
892
|
+
const rg = rangeOf(spec, size);
|
|
893
|
+
if (rg === false) return { status: 416, json: { error: `that range isn't inside the file's ${size} bytes`, size } };
|
|
894
|
+
const head = { id: meta.id, name: meta.name, mime: meta.mime, kind: meta.kind, size };
|
|
895
|
+
if (!remote) return { status: rg ? 206 : 200, json: head, raw: { file, size, mime: meta.mime, name: meta.name, ...(rg || { start: 0, end: size - 1 }) } };
|
|
896
|
+
const start = rg ? rg.start : 0;
|
|
897
|
+
const end = Math.min(rg ? rg.end : size - 1, start + RELAY_CHUNK - 1);
|
|
898
|
+
const data = size ? readRange(file, start, end).toString('base64') : '';
|
|
899
|
+
const whole = start === 0 && end >= size - 1;
|
|
900
|
+
return { status: whole ? 200 : 206, json: { ...head, start, end, data, ...(end < size - 1 && { next: `${end + 1}-` }) } };
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
// The bytes as HTTP, with a type a browser can show only for kinds that can't run script in this
|
|
904
|
+
// origin: anything else (HTML, say) downloads. Content-Range for a part.
|
|
905
|
+
function sendRaw(res, status, raw) {
|
|
906
|
+
const show = inline(raw.mime);
|
|
907
|
+
const type = !show ? 'application/octet-stream' : raw.mime.startsWith('text/') ? `${raw.mime}; charset=utf-8` : raw.mime;
|
|
908
|
+
const head = { ...HEADERS, 'Content-Type': type, 'Content-Length': String(Math.max(0, raw.end - raw.start + 1)), 'Accept-Ranges': 'bytes',
|
|
909
|
+
'Content-Disposition': `${show ? 'inline' : 'attachment'}; filename*=UTF-8''${encodeURIComponent(raw.name)}`,
|
|
910
|
+
// A PDF opens in the browser's own viewer, which a sandbox would block; anything else gets no script at all.
|
|
911
|
+
'Content-Security-Policy': raw.mime === 'application/pdf' ? "default-src 'none'; frame-ancestors 'self'" : "sandbox; default-src 'none'; img-src 'self' data:; style-src 'unsafe-inline'",
|
|
912
|
+
...(status === 206 && { 'Content-Range': `bytes ${raw.start}-${raw.end}/${raw.size}` }) };
|
|
913
|
+
res.writeHead(status, head);
|
|
914
|
+
if (!raw.size) return res.end();
|
|
915
|
+
fs.createReadStream(raw.file, { start: raw.start, end: raw.end }).on('error', () => res.destroy()).pipe(res);
|
|
916
|
+
}
|
|
917
|
+
|
|
637
918
|
// MCP tools. Each answers in plain text a model reads well, plus the same as data.
|
|
638
919
|
const TOOLS = [
|
|
639
920
|
{ name: 'board', description: 'What every agent on this machine is doing right now through dibs: running, paused and waiting jobs with their resource, purpose, start time and expected end or start, plus scheduled runs and what is holding new jobs back.', inputSchema: { type: 'object', properties: {} } },
|
|
640
|
-
{ name: 'agents', description: 'One entry per agent: its jobs, its tasks with their latest progress and expected finish time (from dibs progress posts),
|
|
921
|
+
{ name: 'agents', description: 'One entry per agent: its jobs, its tasks with their latest progress and expected finish time (from dibs progress posts), when it last posted, and what dibs saw it do itself: commits, merges, releases, uploads, test suites and deploys.', inputSchema: { type: 'object', properties: {} } },
|
|
641
922
|
{ name: 'progress', description: 'Progress posts agents wrote with dibs progress, newest last. Filter by agent name and by how far back to look.', inputSchema: { type: 'object', properties: { agent: { type: 'string', description: 'session name, as on the board' }, since_minutes: { type: 'number', description: 'only posts newer than this many minutes (default 180)' }, limit: { type: 'number', description: 'at most this many posts (default 100, max 400)' } } } },
|
|
642
923
|
{ name: 'agent', description: "One agent's whole picture: its jobs, its tasks and every progress post it wrote in the last day.", inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'session name, as on the board' } }, required: ['name'] } },
|
|
924
|
+
{ name: 'work', description: 'Shared work items (dibs work and dibs handoff) and agents\' progress tasks: who has each, what is blocked and why, what nobody has claimed, and what closed lately with its proof (the passing run and commit dibs checked, or no proof).', inputSchema: { type: 'object', properties: {} } },
|
|
643
925
|
{ name: 'questions', description: 'Questions agents asked the person that are still open: who asked, what, the options offered and the recommended one, how urgent, and how long it has waited.', inputSchema: { type: 'object', properties: {} } },
|
|
644
926
|
{ name: 'history', description: 'What happened on this machine: busy time per resource, waits and who waited, by agent and by hour.', inputSchema: { type: 'object', properties: { since: { type: 'string', enum: SPANS, description: 'how far back (default 7d)' } } } },
|
|
645
927
|
{ name: 'resource', description: 'One resource (test, sim, xcode-build, playwright, heavy, deploy, ...): who holds it and who waits (dibs who), and when a new job would get it if asked now (dibs when).', inputSchema: { type: 'object', properties: { res: { type: 'string', description: 'resource name, as on the board' } }, required: ['res'] } },
|
|
@@ -652,7 +934,7 @@ const when = (at, t = now()) => (at ? `${clock(at)} (${at > t ? `in ${dur(at - t
|
|
|
652
934
|
function jobText(x, t = now()) {
|
|
653
935
|
const what = oneLine(x.purpose || x.cmd || '(no reason given)');
|
|
654
936
|
if (x.state === 'waiting') return `#${x.id} waiting for ${x.res.join(',')} (place ${x.place}${x.blocked ? `, ${x.blocked}` : ''}): ${what}. Queued ${when(x.queued, t)}; expected to start ${x.startsAt ? when(x.startsAt, t) : 'unknown'}.`;
|
|
655
|
-
return `#${x.id} ${x.state} on ${x.res.join(',')}: ${what}. Started ${when(x.started, t)}; ${x.endsAt ? `expected to end ${when(x.endsAt, t)}` : x.ends || 'end unknown'}.${x.paused ? ` Paused: ${x.paused}.` : ''}`;
|
|
937
|
+
return `#${x.id} ${x.state} on ${x.res.join(',')}: ${what}. Started ${when(x.started, t)}; ${x.progress && x.ends ? `${x.ends}; ` : ''}${x.endsAt ? `expected to end ${when(x.endsAt, t)}` : x.progress ? '' : x.ends || 'end unknown'}.${x.paused ? ` Paused: ${x.paused}.` : ''}`;
|
|
656
938
|
}
|
|
657
939
|
function taskText(k, t = now()) {
|
|
658
940
|
return `${oneLine(k.task) || 'untitled'}${k.project ? ` in ${oneLine(k.project)}${k.branch ? `@${oneLine(k.branch)}` : ''}` : ''}: ${k.state}, started ${when(k.started, t)}`
|
|
@@ -670,10 +952,11 @@ async function callTool(name, a = {}) {
|
|
|
670
952
|
return { text: lines.join('\n'), data: b };
|
|
671
953
|
}
|
|
672
954
|
if (name === 'agents') {
|
|
673
|
-
const ps = people(b, readPosts({ since: t - DAY }));
|
|
955
|
+
const ps = people(b, readPosts({ since: t - DAY }), trailDay(t));
|
|
674
956
|
if (!ps.length) return { text: 'No agent has a job or a progress post in the last day.', data: [] };
|
|
675
957
|
return { text: ps.map(p => [`== ${oneLine(p.who)}${p.lastPost ? ` (last posted ${when(p.lastPost.at, t)})` : ''}`,
|
|
676
|
-
...p.tasks.slice(0, 6).map(k => `task ${taskText(k, t)}`), ...p.jobs.map(x => `job ${jobText(x, t)}`)
|
|
958
|
+
...p.tasks.slice(0, 6).map(k => `task ${taskText(k, t)}`), ...p.jobs.map(x => `job ${jobText(x, t)}`),
|
|
959
|
+
...p.trail.slice(-4).map(x => `seen by dibs ${clock(x.at)}: ${oneLine(x.text)}`)].join('\n')).join('\n\n'), data: ps.map(x => ({ ...x, lastPost: x.lastPost && shown(x.lastPost) })) };
|
|
677
960
|
}
|
|
678
961
|
if (name === 'progress') {
|
|
679
962
|
const mins = Number(a.since_minutes) > 0 ? Number(a.since_minutes) : 180;
|
|
@@ -684,10 +967,11 @@ async function callTool(name, a = {}) {
|
|
|
684
967
|
}
|
|
685
968
|
if (name === 'agent') {
|
|
686
969
|
if (typeof a.name !== 'string' || !a.name) throw fail(400, 'name is required', { rpc: -32602 });
|
|
687
|
-
const p = people(b, readPosts({ since: t - DAY })).find(x => x.who === a.name);
|
|
970
|
+
const p = people(b, readPosts({ since: t - DAY }), trailDay(t)).find(x => x.who === a.name);
|
|
688
971
|
if (!p) return { text: `No agent called ${a.name} has a job or a post in the last day. The agents tool lists who does.`, data: null };
|
|
689
972
|
const posts = readPosts({ since: t - DAY, agent: a.name }).map(shown);
|
|
690
|
-
return { text: [`== ${oneLine(p.who)}`, ...p.tasks.map(k => `task ${taskText(k, t)}`), ...p.jobs.map(x => `job ${jobText(x, t)}`),
|
|
973
|
+
return { text: [`== ${oneLine(p.who)}`, ...p.tasks.map(k => `task ${taskText(k, t)}`), ...p.jobs.map(x => `job ${jobText(x, t)}`),
|
|
974
|
+
...(p.trail.length ? ['', 'Seen by dibs (not its words):', ...p.trail.map(x => `${clock(x.at)} ${oneLine(x.text)}`)] : []), '', 'Posts:',
|
|
691
975
|
...posts.map(x => `${clock(x.at)}${x.task ? ` [${oneLine(x.task)}]` : ''}: ${oneLine(x.text)}`)].join('\n'), data: { ...p, lastPost: p.lastPost && shown(p.lastPost), posts } };
|
|
692
976
|
}
|
|
693
977
|
if (name === 'stats') {
|
|
@@ -696,12 +980,18 @@ async function callTool(name, a = {}) {
|
|
|
696
980
|
const st = statsFor(since, agent, t);
|
|
697
981
|
return { text: statsText(st).map(oneLine).join('\n'), data: st };
|
|
698
982
|
}
|
|
983
|
+
if (name === 'work') {
|
|
984
|
+
const items = workJson({ t }).items;
|
|
985
|
+
if (!items.length) return { text: 'No work items or open progress tasks.', data: [] };
|
|
986
|
+
return { text: items.map(i => `${i.id} "${oneLine(i.title)}": ${i.state}${i.owner ? `, ${oneLine(i.owner)} has it` : ''}`
|
|
987
|
+
+ `${i.blocked ? `, blocked: ${oneLine(i.blocked)}` : ''}${i.proof ? `, ${i.proof.line}` : ''}.`).join('\n'), data: items };
|
|
988
|
+
}
|
|
699
989
|
if (name === 'questions') {
|
|
700
990
|
const qs = scrub(await cliJson(['questions', '--json'])).questions.filter(q => q.state === 'open');
|
|
701
991
|
if (!qs.length) return { text: 'No open questions.', data: [] };
|
|
702
992
|
return { text: qs.map(q => `#${q.id} from ${oneLine(q.who)} (${q.prio}), asked ${when(q.asked, t)}: ${oneLine(q.text)}`
|
|
703
993
|
+ `${q.options?.length ? ` Options: ${q.options.map(oneLine).join(', ')}.` : ''}${q.recommend ? ` Recommended: ${oneLine(q.recommend)}.` : ''}`
|
|
704
|
-
+ `${q.why ? ` Why: ${oneLine(q.why)}.` : ''}${q.oneWay ? ` Can't be undone: ${oneLine(q.cantUndo || 'yes')}.` : ''}`).join('\n'), data: qs };
|
|
994
|
+
+ `${q.why ? ` Why: ${oneLine(q.why)}.` : ''}${q.needsYou ? ` Only you can: ${oneLine(q.needsYou)}.` : q.oneWay ? ` Can't be undone: ${oneLine(q.cantUndo || 'yes')}.` : ''}`).join('\n'), data: qs };
|
|
705
995
|
}
|
|
706
996
|
if (name === 'history') {
|
|
707
997
|
const since = spanOf(a.since);
|
|
@@ -749,16 +1039,18 @@ const resOf = v => (typeof v === 'string' && RES.test(v) ? v : bad('a resource i
|
|
|
749
1039
|
// Tools that change things, for a client paired with dibs pair --allow-actions: listed and
|
|
750
1040
|
// callable only then. Each runs the CLI as an agent named after the client (mcpAgent()), never
|
|
751
1041
|
// as the person, so agents read its messages as another agent's and the record names it.
|
|
752
|
-
//
|
|
753
|
-
const OWNER = { owner: { type: 'string', description: '
|
|
1042
|
+
// owner was once needed on another session's job; it's accepted from older clients and ignored.
|
|
1043
|
+
const OWNER = { owner: { type: 'string', description: 'not needed: any job may be acted on, and the board and history name who did it. Accepted from older clients and ignored' } };
|
|
754
1044
|
const REASON = { reason: { type: 'string', description: 'why, in a line; everyone sees it' } };
|
|
1045
|
+
// What a hold or a queued run is for: dibs refuses one without plain words (src/declare.mjs).
|
|
1046
|
+
const DECLARE = { reason: { type: 'string', description: 'what this is for and why, in plain words of 3 or more, not the command: "run the nightly tests after the schema change". The person reads it in place of the command' } };
|
|
755
1047
|
const JOB = { id: { type: 'string', description: 'the job\'s number on the board' } };
|
|
756
1048
|
const ACT_TOOLS = [
|
|
757
1049
|
{ name: 'post_progress', description: 'Post a progress note under this client\'s name, as agents do with dibs progress: what was just done, found or decided. The person reads these live.', inputSchema: { type: 'object', properties: { text: { type: 'string' }, task: { type: 'string', description: 'a short task name, the same across posts' }, eta: { type: 'string', description: 'when it should be done: 30m, 2h or 17:30' }, state: { type: 'string', enum: ['doing', 'done', 'blocked'] } }, required: ['text'] } },
|
|
758
1050
|
{ name: 'answer_question', description: 'Answer an open question an agent asked, with one of its options or any words. The asking agent gets the answer, from this client (not from the person).', inputSchema: { type: 'object', properties: { id: { type: 'string', description: 'the question\'s number (questions tool)' }, text: { type: 'string' } }, required: ['id', 'text'] } },
|
|
759
1051
|
{ name: 'tell_agent', description: 'Send an agent a message. It arrives with its next tool call as a message from this client, another agent, not from the person.', inputSchema: { type: 'object', properties: { agent: { type: 'string', description: 'session name, as on the board' }, text: { type: 'string' } }, required: ['agent', 'text'] } },
|
|
760
1052
|
{ name: 'say_to_person', description: 'Leave the person a note in this client\'s own thread (dibs say): progress, done, blocked on something.', inputSchema: { type: 'object', properties: { text: { type: 'string' } }, required: ['text'] } },
|
|
761
|
-
{ name: 'hold', description: 'Hold a resource for a while under this client\'s name, so no job gets it (dibs hold). At most an hour; hold again to extend; release gives it back.', inputSchema: { type: 'object', properties: { res: { type: 'string' }, for: { type: 'string', description: 'how long: 10m, 1h (default 20m)' }, ...
|
|
1053
|
+
{ name: 'hold', description: 'Hold a resource for a while under this client\'s name, so no job gets it (dibs hold). At most an hour; hold again to extend; release gives it back.', inputSchema: { type: 'object', properties: { res: { type: 'string' }, for: { type: 'string', description: 'how long: 10m, 1h (default 20m)' }, ...DECLARE }, required: ['res', 'reason'] } },
|
|
762
1054
|
{ name: 'release', description: 'Give back this client\'s holds: one resource, or all of them.', inputSchema: { type: 'object', properties: { res: { type: 'string', description: 'leave out to release every hold this client has' } } } },
|
|
763
1055
|
{ name: 'boost_job', description: 'Change a waiting or running job\'s priority (dibs boost). urgent and high need a reason.', inputSchema: { type: 'object', properties: { ...JOB, prio: { type: 'string', enum: PRIORITIES }, ...REASON, ...OWNER }, required: ['id', 'prio'] } },
|
|
764
1056
|
{ name: 'pause_job', description: 'Freeze a running job where it stands (dibs pause); it keeps its lease. force pauses a job dibs would otherwise refuse to.', inputSchema: { type: 'object', properties: { ...JOB, force: { type: 'boolean' }, ...REASON, ...OWNER }, required: ['id'] } },
|
|
@@ -777,7 +1069,7 @@ const CMD_TOOLS = [
|
|
|
777
1069
|
cwd: { type: 'string', description: 'the folder to run it in: an absolute path that exists' },
|
|
778
1070
|
at: { type: 'string', description: 'when: 02:00 (within 7 days)' }, in: { type: 'string', description: 'or a while from now: 30m, 3h' },
|
|
779
1071
|
after: { type: 'string', description: 'or when something ends: #42, an agent name, or l3' }, after_ok: { type: 'boolean', description: 'with after: only if it succeeded' },
|
|
780
|
-
...
|
|
1072
|
+
...DECLARE }, required: ['res', 'command', 'cwd', 'reason'] } },
|
|
781
1073
|
];
|
|
782
1074
|
const MAX_ARGV = 64, MAX_ARG = 4096;
|
|
783
1075
|
async function queueRun(a, grant) {
|
|
@@ -945,7 +1237,8 @@ function handler({ allowed = new Set(), remote = null } = {}) {
|
|
|
945
1237
|
if (p.startsWith('/api/')) {
|
|
946
1238
|
const session = check(bearer(req), 'session');
|
|
947
1239
|
if (!session) return send(res, 401, { error: 'sign in with a code from dibs pair' });
|
|
948
|
-
const r = await api({ method: req.method, path: req.url, body: req.method === 'POST' ? parseJson((await body(req)) || '{}') : null, session });
|
|
1240
|
+
const r = await api({ method: req.method, path: req.url, body: req.method === 'POST' ? parseJson((await body(req)) || '{}') : null, session, range: req.headers.range || null });
|
|
1241
|
+
if (r.raw) return sendRaw(res, r.status, r.raw);
|
|
949
1242
|
return send(res, r.status, r.json, 'application/json', r.retryAfter ? { 'Retry-After': String(r.retryAfter) } : {});
|
|
950
1243
|
}
|
|
951
1244
|
|