@dibssoftware/dibs 0.0.180 → 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 +111 -1
- package/README.md +10 -8
- package/bin/dibs.mjs +379 -74
- 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 +135 -11
- 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/docs/windows.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 +113 -28
- package/src/after.mjs +127 -0
- package/src/agents.mjs +2 -1
- package/src/alerts.mjs +109 -48
- 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 +254 -86
- package/src/config.mjs +85 -14
- package/src/connect.mjs +4 -2
- package/src/cool.mjs +28 -12
- 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 +121 -7
- package/src/guard.mjs +288 -105
- 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 +51 -11
- package/src/measure.mjs +60 -14
- 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 +29 -7
- package/src/preempt.mjs +123 -15
- package/src/primer.mjs +91 -20
- package/src/prints.mjs +99 -0
- package/src/proc.mjs +11 -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 +262 -26
- 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/service.mjs +5 -1
- 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 +1082 -134
- 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 +354 -60
- package/src/work.mjs +487 -0
- package/src/worker.mjs +7 -1
package/src/work.mjs
ADDED
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
// dibs work: shared work items. One item is a piece of work with a title, a goal, an owner
|
|
2
|
+
// (claimed by one agent at a time, so two agents never do the same job), the items it waits
|
|
3
|
+
// on, the files it touches, who made it, and a log (the progress posts made under its id).
|
|
4
|
+
// When it closes, dibs attaches proof it checked itself (src/proof.mjs).
|
|
5
|
+
//
|
|
6
|
+
// Items live in handoffs.json beside handoffs, as handoffs: a handoff is an item handed to
|
|
7
|
+
// someone, and an item is a handoff with more to it. So dibs handoff and an older dibs keep
|
|
8
|
+
// reading and writing the same list. Stored states stay the handoff words (open, taken,
|
|
9
|
+
// done, cancelled, expired); readers get the item words (open, claimed, blocked, done,
|
|
10
|
+
// dropped). Blocked is never stored: it's an explicit note (blocked) or items waited on
|
|
11
|
+
// (after) that aren't done, so an older dibs that knows neither sees the item as open.
|
|
12
|
+
//
|
|
13
|
+
// A progress task (dibs progress --task auth) is an item too, read from its posts: its
|
|
14
|
+
// poster owns it, its posts are its log. A post under an item's id (--task w3) is that
|
|
15
|
+
// item's log, and --done or --blocked there closes or blocks the item.
|
|
16
|
+
import { identity } from './proc.mjs';
|
|
17
|
+
import { logChange } from './owner.mjs';
|
|
18
|
+
import { whoAmI, send, unreachable, delivery } from './talk.mjs';
|
|
19
|
+
import { locked, load, reap, find, idOf as idIn, blockedWhy, freedBy, tellFreed, tryTell, fromName, nameOf, withoutProject, liveOffer, OFFER_FOR, OPEN, TAKEN } from './handoffs.mjs';
|
|
20
|
+
import { projectName } from './talk.mjs';
|
|
21
|
+
import { pickupOn } from './pickup.mjs';
|
|
22
|
+
import { paths, loadConfig } from './config.mjs';
|
|
23
|
+
import fs from 'node:fs';
|
|
24
|
+
import { gather, runProof, proofView, proofLine } from './proof.mjs';
|
|
25
|
+
import { read as readPosts, tasks } from './progress.mjs';
|
|
26
|
+
import { readEvents } from './events.mjs';
|
|
27
|
+
import { resList, fileRes, clash, isFiles, leases, FILES } from './files.mjs';
|
|
28
|
+
import { bold, dim, red, columns } from './style.mjs';
|
|
29
|
+
import { die, now, clock, dur } from './util.mjs';
|
|
30
|
+
import { minutes } from './plain.mjs';
|
|
31
|
+
// When an offer was made, as the board says it: "2 min ago".
|
|
32
|
+
const agoMin = (t, at) => (t - at < 6e4 ? 'just now' : `${minutes(t - at)} ago`);
|
|
33
|
+
|
|
34
|
+
const MAX_TITLE = 200;
|
|
35
|
+
const MAX_TEXT = 4000;
|
|
36
|
+
// An item waits on at most this many others; more is a plan, and belongs in several items.
|
|
37
|
+
const MAX_AFTER = 20;
|
|
38
|
+
const MAX_FILES = 32;
|
|
39
|
+
// Closed items and finished progress tasks show this long in the list, the board and the page.
|
|
40
|
+
const DONE_SHOWN = 12 * 36e5;
|
|
41
|
+
// The log keeps this many of an item's latest posts in --json and /api/work.
|
|
42
|
+
const LOG_SHOWN = 20;
|
|
43
|
+
|
|
44
|
+
export const USAGE = `dibs work what's in flight: who has what, what's blocked and why, what's done and its proof
|
|
45
|
+
dibs work add "title" [--goal "done when..."] [-m "context"] [--after w2,w5] [--files 'src/auth/**'] [--to <agent>]
|
|
46
|
+
[--project <name>] [--no-pickup]
|
|
47
|
+
a piece of work any agent (or the one named) can claim. It's for your
|
|
48
|
+
project (dibs project), or the one --project names; --no-pickup: never
|
|
49
|
+
offered to an idle agent
|
|
50
|
+
dibs work next claim the oldest item you can take (exit 1: none)
|
|
51
|
+
dibs work claim <id> claim that one; nobody else can while you have it
|
|
52
|
+
dibs work done <id> ["what you did"] [--commit <sha>] [--url <url>] [--build <n>]
|
|
53
|
+
close it: dibs attaches your last passing run and your commit as proof
|
|
54
|
+
dibs work block <id> "why" [--after w7] it can't go on (waits on w7); dibs work unblock <id> clears it
|
|
55
|
+
dibs work back <id> ["why"] give it up: open again for any agent
|
|
56
|
+
dibs work drop <id> ["why"] nobody does it
|
|
57
|
+
dibs work show <id> [--json] one item: its goal, files, log and proof
|
|
58
|
+
dibs work list [--takeable] [--all] [--json] --takeable: only what you could claim now; --all: closed ones too
|
|
59
|
+
dibs work pickup [on|off] offer open items to idle agents on their project (off unless turned on)
|
|
60
|
+
Post as you go under its id: dibs progress "..." --task w3 (--done there closes it, --blocked blocks it).
|
|
61
|
+
dibs handoff and dibs work share one list, with w ids; h3 still means w3.`;
|
|
62
|
+
|
|
63
|
+
const STATE = { open: 'open', taken: 'claimed', done: 'done', cancelled: 'dropped', expired: 'dropped' };
|
|
64
|
+
const wid = x => `w${x.id}`;
|
|
65
|
+
const idOf = arg => idIn(arg, 'which item? Its id is the w number: dibs work claim w3. In flight: dibs work list');
|
|
66
|
+
const said = r => (r && r.err ? die(r.err, r.code ?? 1) : r);
|
|
67
|
+
const refuse = (err, code = 1) => ({ err, code });
|
|
68
|
+
const gone = n => refuse(`no work item w${n}. In flight: dibs work list`);
|
|
69
|
+
const ago = (t, at) => (t - at < 6e4 ? 'just now' : `${dur(t - at)} ago`);
|
|
70
|
+
const one = s => String(s ?? '').replace(/\s+/g, ' ').trim();
|
|
71
|
+
// A note as a sentence, so what's said after it doesn't run into it.
|
|
72
|
+
const stop = s => (/[.!?]$/.test(s) ? s : `${s}.`);
|
|
73
|
+
|
|
74
|
+
export async function work(args) {
|
|
75
|
+
const sub = args[0];
|
|
76
|
+
const rest = args.slice(1);
|
|
77
|
+
if (sub === 'add') return add(rest);
|
|
78
|
+
if (sub === 'next') return claim(rest, true);
|
|
79
|
+
if (sub === 'claim' || sub === 'take') return claim(rest, false);
|
|
80
|
+
if (sub === 'done') return done(rest);
|
|
81
|
+
if (sub === 'back' || sub === 'drop') return close(rest, sub);
|
|
82
|
+
if (sub === 'block') return block(rest);
|
|
83
|
+
if (sub === 'unblock') return unblock(rest);
|
|
84
|
+
if (sub === 'show') return show(rest);
|
|
85
|
+
if (sub === 'pickup') return pickup(rest);
|
|
86
|
+
if (sub === 'help' || sub === '-h' || sub === '--help') return console.log(USAGE);
|
|
87
|
+
if (!sub || sub === 'list' || sub.startsWith('--')) return list(sub === 'list' ? rest : args);
|
|
88
|
+
die(`dibs work has no "${sub}".\n${USAGE}`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Flags with values, the rest as words. Unknown flags are a usage error (exit 2).
|
|
92
|
+
function flags(args, valued, bare = []) {
|
|
93
|
+
const o = { words: [] };
|
|
94
|
+
for (let i = 0; i < args.length; i++) {
|
|
95
|
+
const a = args[i];
|
|
96
|
+
if (valued.includes(a)) o[a.replace(/^-+/, '')] = args[++i] ?? die(`${a} needs a value.\n${USAGE}`);
|
|
97
|
+
else if (bare.includes(a)) o[a.replace(/^-+/, '')] = true;
|
|
98
|
+
else if (a.startsWith('-') && a.length > 1) die(`unknown flag ${a}.\n${USAGE}`);
|
|
99
|
+
else o.words.push(a);
|
|
100
|
+
}
|
|
101
|
+
return o;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// The calling agent, as messages reach it, and the name leases and runs carry (identity's who).
|
|
105
|
+
function caller(verb, args) {
|
|
106
|
+
const me = whoAmI(verb, args);
|
|
107
|
+
return { me: me && withoutProject(me), name: nameOf(me), who: me?.who || identity().who, project: me?.project || null };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ----- making one -----
|
|
111
|
+
|
|
112
|
+
function add(args) {
|
|
113
|
+
const o = flags(args, ['--goal', '-m', '--msg', '--after', '--files', '--to', '--project'], ['--json', '--no-pickup']);
|
|
114
|
+
const title = one(o.words.join(' '));
|
|
115
|
+
if (!title) die(`add what? dibs work add "fix the flaky login test" --goal "passes 20 runs in a row" --files 'src/auth/**'\n${USAGE}`);
|
|
116
|
+
if (title.length > MAX_TITLE) die(`a title is one line (under ${MAX_TITLE} characters); put the rest in --goal or -m. Nothing was added.`);
|
|
117
|
+
const goal = (o.goal || '').trim(), context = (o.m || o.msg || '').trim();
|
|
118
|
+
if (goal.length > MAX_TEXT || context.length > MAX_TEXT) die(`keep --goal and -m under ${MAX_TEXT} characters each, or point to a file. Nothing was added.`);
|
|
119
|
+
const after = o.after ? o.after.split(',').filter(Boolean).map(idOf) : [];
|
|
120
|
+
if (after.length > MAX_AFTER) die(`an item waits on at most ${MAX_AFTER} others; split it up. Nothing was added.`);
|
|
121
|
+
// Split at the commas outside braces, then expand each one's braces as dibs hold does.
|
|
122
|
+
const paths = o.files ? resList(o.files).flatMap(p => resList(FILES + p.trim())).map(r => r.slice(FILES.length)).filter(Boolean) : [];
|
|
123
|
+
if (paths.length > MAX_FILES) die(`name at most ${MAX_FILES} paths or globs. Nothing was added.`);
|
|
124
|
+
const files = paths.map(p => fileRes(FILES + p)).filter(Boolean);
|
|
125
|
+
if (o.to) { const no = unreachable(o.to); if (no) die(no, 1); }
|
|
126
|
+
const { me, name, project: own } = caller('work', args);
|
|
127
|
+
if (o.to && me && o.to === name) die("that's you. Claim it yourself after adding it, or leave out --to.");
|
|
128
|
+
const project = o.project != null ? projectName(o.project) : own;
|
|
129
|
+
if (o.project != null && !/^[\w.-]{1,60}$/.test(project)) die('a project name is one word: --project shop-web. Nothing was added.');
|
|
130
|
+
const x = said(locked(s => {
|
|
131
|
+
for (const n of after) if (!find(s, n)) return refuse(`no work item w${n} to wait on. Nothing was added. In flight: dibs work list`);
|
|
132
|
+
const x = { id: ++s.seq, kind: 'work', title, ...(goal && { goal }), ...(context && { context }), from: me, to: o.to || null, state: OPEN, at: now(),
|
|
133
|
+
...(after.length && { after: [...new Set(after)] }), ...(files.length && { files, paths }), ...(project && { project }), ...(o['no-pickup'] && { pickup: false }) };
|
|
134
|
+
s.handoffs.push(x);
|
|
135
|
+
return { x: { ...x }, why: blockedWhy(s, x) };
|
|
136
|
+
}));
|
|
137
|
+
const it = x.x;
|
|
138
|
+
logChange('work add', { id: wid(it), ...(it.to && { to: it.to }) });
|
|
139
|
+
const later = x.why ? ` It can be claimed once nothing is in its way: it ${x.why}.` : '';
|
|
140
|
+
if (it.to) {
|
|
141
|
+
const r = send(it.to, `Work item ${wid(it)} for you: "${title}"${goal ? `. Done when: ${goal}` : ''}${context ? `. ${context}` : ''}\n`
|
|
142
|
+
+ `${x.why ? `It ${x.why}; you hear when it can be claimed.` : `Claim it: dibs work claim ${wid(it)}.`} Post as you go: dibs progress "..." --task ${wid(it)}. Close it: dibs work done ${wid(it)} "what you did".`, 'work', args);
|
|
143
|
+
if (o.json) return console.log(JSON.stringify({ item: viewOf(load(), it) }));
|
|
144
|
+
return console.log(`${wid(it)} is for ${r.to}: ${delivery(r)}${later}`);
|
|
145
|
+
}
|
|
146
|
+
if (o.json) return console.log(JSON.stringify({ item: viewOf(load(), it) }));
|
|
147
|
+
const offered = it.pickup === false || !pickupOn() ? '' : project ? ` Idle agents on ${project} are offered it.` : ' It has no project, so no idle agent is offered it (dibs project <name>, or --project).';
|
|
148
|
+
console.log(`${wid(it)} is open: any agent can claim it (dibs work next).${later}${offered}`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ----- claiming -----
|
|
152
|
+
|
|
153
|
+
// Another agent's claimed item or live file lease on files x touches, as a sentence, or null.
|
|
154
|
+
export function filesTaken(s, x, mine, live) {
|
|
155
|
+
if (!x.files?.length) return null;
|
|
156
|
+
const hit = fs => fs.some(a => x.files.some(b => clash(a, b)));
|
|
157
|
+
for (const y of s.handoffs) {
|
|
158
|
+
if (y !== x && y.state === TAKEN && y.taker?.name !== mine.name && hit(y.files || [])) return `${y.taker.name} has ${wid(y)}, which touches the same files. Agree who edits what first: dibs tell ${y.taker.name} "..."`;
|
|
159
|
+
}
|
|
160
|
+
for (const l of live) if (l.who !== mine.who && hit(l.res.filter(isFiles))) return `${l.who} holds a file lease on them, so your edits there are refused until it's released`;
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
export function liveLeases() { try { return leases(); } catch { return []; } }
|
|
164
|
+
|
|
165
|
+
function claim(args, next) {
|
|
166
|
+
const o = flags(args, [], ['--json']);
|
|
167
|
+
const mine = caller('work', args);
|
|
168
|
+
const n = next ? null : idOf(o.words[0]);
|
|
169
|
+
const live = liveLeases();
|
|
170
|
+
const r = said(locked(s => {
|
|
171
|
+
if (!next) {
|
|
172
|
+
const x = find(s, n);
|
|
173
|
+
if (!x) return gone(n);
|
|
174
|
+
if (x.state === TAKEN) return refuse(`${wid(x)} is already claimed by ${x.taker.name}${x.taker.name === mine.name ? ' (you)' : ''}.`);
|
|
175
|
+
if (x.state !== OPEN) return refuse(`${wid(x)} is ${STATE[x.state] || x.state}, so there's nothing to claim.`);
|
|
176
|
+
if (x.to && x.to !== mine.name) return refuse(`${wid(x)} is for ${x.to}, not you. If ${x.to} gives it back, any agent can claim it.`);
|
|
177
|
+
const why = blockedWhy(s, x);
|
|
178
|
+
if (why) return refuse(`${wid(x)} can't be claimed yet: it ${why.startsWith('waits') ? why : `is blocked: ${why}`}.`);
|
|
179
|
+
return take(s, x, mine, filesTaken(s, x, mine, live));
|
|
180
|
+
}
|
|
181
|
+
const open = s.handoffs.filter(x => x.state === OPEN && (!x.to || x.to === mine.name));
|
|
182
|
+
const free = open.filter(x => !blockedWhy(s, x) && !filesTaken(s, x, mine, live))
|
|
183
|
+
.sort((a, b) => Number(b.to === mine.name) - Number(a.to === mine.name) || a.id - b.id);
|
|
184
|
+
if (!free.length) {
|
|
185
|
+
const held = open.length ? ` ${open.length} open ${open.length === 1 ? 'item waits' : 'items wait'} on other work or files another agent has: dibs work list` : ' Add one: dibs work add "title"';
|
|
186
|
+
return refuse(`nothing to claim.${held}`);
|
|
187
|
+
}
|
|
188
|
+
return take(s, free[0], mine, null);
|
|
189
|
+
}));
|
|
190
|
+
logChange('work claim', { id: wid(r.x) });
|
|
191
|
+
const x = r.x;
|
|
192
|
+
if (x.from && x.from.name !== mine.name) tryTell(x.from, `${mine.name} claimed your work item ${wid(x)} ("${x.title}"). You hear when it's done.`);
|
|
193
|
+
if (o.json) return console.log(JSON.stringify({ item: viewOf(load(), x) }));
|
|
194
|
+
const out = [`${wid(x)} is yours: "${x.title}"`];
|
|
195
|
+
if (x.goal) out.push(`Done when: ${x.goal}`);
|
|
196
|
+
if (x.context) out.push(x.context);
|
|
197
|
+
if (x.paths?.length) out.push(`Files: ${x.paths.join(', ')}. Keep other agents' edits off them: dibs hold ${x.paths.map(p => `'files:${p}'`).join(',')} --for 2h -m "${wid(x)}"`);
|
|
198
|
+
if (r.warn) out.push(red(`Careful: ${r.warn}.`));
|
|
199
|
+
out.push(`From ${fromName(x)}. Post as you go: dibs progress "..." --task ${wid(x)}. Done: dibs work done ${wid(x)} "what you did" (your last passing dibs run and your commit are its proof). Can't: dibs work back ${wid(x)} "why".`);
|
|
200
|
+
console.log(out.join('\n'));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function take(s, x, mine, warn) {
|
|
204
|
+
Object.assign(x, { state: TAKEN, taker: mine.me || { name: mine.name, who: mine.who }, takenAt: now() });
|
|
205
|
+
delete x.offer;
|
|
206
|
+
return { x: { ...x }, warn };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// ----- closing -----
|
|
210
|
+
|
|
211
|
+
function done(args) {
|
|
212
|
+
const o = flags(args, ['--commit', '--url', '--build'], ['--json']);
|
|
213
|
+
const n = idOf(o.words[0]);
|
|
214
|
+
const note = o.words.slice(1).join(' ').trim().slice(0, MAX_TEXT);
|
|
215
|
+
const mine = caller('work', args);
|
|
216
|
+
const r = closeDone(n, mine, note, o);
|
|
217
|
+
if (o.json) return console.log(JSON.stringify({ item: viewOf(load(), r.x) }));
|
|
218
|
+
console.log(`${wid(r.x)} is done, ${proofLine(r.x.proof)}.${r.x.from && r.x.from.name !== mine.name ? ` ${fromName(r.x)} is told.` : ''}`
|
|
219
|
+
+ (r.freed.length ? ` Now free to claim: ${r.freed.map(wid).join(', ')}.` : ''));
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Close item n as done by mine, with proof gathered before the lock (it reads the event log
|
|
223
|
+
// and asks git). An unclaimed item may be closed too: the person marking it done, say.
|
|
224
|
+
function closeDone(n, mine, note, o = {}) {
|
|
225
|
+
const before = find(load(), n);
|
|
226
|
+
if (!before) said(gone(n));
|
|
227
|
+
const who = before.taker?.who || before.taker?.name || mine.who;
|
|
228
|
+
const proof = gather({ who, since: before.takenAt || before.at, commit: o.commit, url: o.url, build: o.build });
|
|
229
|
+
const r = said(locked(s => {
|
|
230
|
+
const x = find(s, n);
|
|
231
|
+
if (!x) return gone(n);
|
|
232
|
+
if (x.state !== OPEN && x.state !== TAKEN) return refuse(`${wid(x)} is already ${STATE[x.state] || x.state}.`);
|
|
233
|
+
Object.assign(x, { state: 'done', closedAt: now(), doneBy: mine.name, ...(note && { note }), proof });
|
|
234
|
+
delete x.blocked;
|
|
235
|
+
return { x: { ...x }, freed: freedBy(s, x).map(y => ({ ...y })) };
|
|
236
|
+
}));
|
|
237
|
+
logChange('work done', { id: wid(r.x), proved: proofView(r.x.proof).proved });
|
|
238
|
+
if (r.x.from && r.x.from.name !== mine.name) tryTell(r.x.from, `${mine.name} finished your work item ${wid(r.x)} ("${r.x.title}")${note ? `: ${stop(note)}` : '.'} Done, ${proofLine(r.x.proof)}.`);
|
|
239
|
+
tellFreed(r.freed);
|
|
240
|
+
return r;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function close(args, verb) {
|
|
244
|
+
const n = idOf(args[0]);
|
|
245
|
+
const why = args.slice(1).join(' ').trim().slice(0, MAX_TEXT);
|
|
246
|
+
const mine = caller('work', args);
|
|
247
|
+
const r = said(locked(s => {
|
|
248
|
+
const x = find(s, n);
|
|
249
|
+
if (!x) return gone(n);
|
|
250
|
+
if (x.state !== OPEN && x.state !== TAKEN) return refuse(`${wid(x)} is already ${STATE[x.state] || x.state}.`);
|
|
251
|
+
const was = { ...x };
|
|
252
|
+
if (verb === 'drop') Object.assign(x, { state: 'cancelled', closedAt: now(), cancelledBy: mine.name, ...(why && { note: why }) });
|
|
253
|
+
else {
|
|
254
|
+
if (x.state !== TAKEN) return refuse(`nobody has claimed ${wid(x)}, so there's nothing to give back.`);
|
|
255
|
+
(x.returns ||= []).push({ by: mine.name, ...(why && { why }), at: now() });
|
|
256
|
+
Object.assign(x, { state: OPEN, to: null, taker: null, takenAt: null });
|
|
257
|
+
delete x.offer;
|
|
258
|
+
}
|
|
259
|
+
return { x: { ...x }, was };
|
|
260
|
+
}));
|
|
261
|
+
logChange(`work ${verb}`, { id: wid(r.x) });
|
|
262
|
+
const x = r.x, t = `${wid(x)} ("${x.title}")`;
|
|
263
|
+
if (x.from && x.from.name !== mine.name) tryTell(x.from, verb === 'drop' ? `${mine.name} dropped your work item ${t}${why ? `: ${why}` : '.'}`
|
|
264
|
+
: `${mine.name} gave back your work item ${t}${why ? `: ${why}` : ''}. Any agent can claim it now; drop it with dibs work drop ${wid(x)}.`);
|
|
265
|
+
if (verb === 'drop' && r.was.taker && r.was.taker.name !== mine.name) tryTell(r.was.taker, `Work item ${t} was dropped by ${mine.name}: stop working on it.`);
|
|
266
|
+
console.log(verb === 'drop' ? `${wid(x)} is dropped.` : `${wid(x)} is open again, for any agent.`);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function block(args) {
|
|
270
|
+
const o = flags(args, ['--after']);
|
|
271
|
+
const n = idOf(o.words[0]);
|
|
272
|
+
const why = o.words.slice(1).join(' ').trim().slice(0, MAX_TEXT);
|
|
273
|
+
const after = o.after ? o.after.split(',').filter(Boolean).map(idOf) : [];
|
|
274
|
+
if (!why && !after.length) die(`say why, or what it waits on: dibs work block w${n} "the staging database is down" (or --after w7)`);
|
|
275
|
+
const mine = caller('work', args);
|
|
276
|
+
const r = said(locked(s => {
|
|
277
|
+
const x = find(s, n);
|
|
278
|
+
if (!x) return gone(n);
|
|
279
|
+
if (x.state !== OPEN && x.state !== TAKEN) return refuse(`${wid(x)} is ${STATE[x.state] || x.state}; only open and claimed items can be blocked.`);
|
|
280
|
+
for (const d of after) {
|
|
281
|
+
if (!find(s, d)) return refuse(`no work item w${d} to wait on. Nothing was changed.`);
|
|
282
|
+
if (d === n || dependsOn(s, d, n)) return refuse(`w${d} already waits on ${wid(x)}, so ${wid(x)} can't wait on it. Nothing was changed.`);
|
|
283
|
+
}
|
|
284
|
+
if (after.length) x.after = [...new Set([...(x.after || []), ...after])].slice(0, MAX_AFTER);
|
|
285
|
+
if (why) x.blocked = { why, by: mine.name, at: now() };
|
|
286
|
+
return { x: { ...x }, why: blockedWhy(s, x) };
|
|
287
|
+
}));
|
|
288
|
+
logChange('work block', { id: wid(r.x) });
|
|
289
|
+
const x = r.x;
|
|
290
|
+
if (x.taker && x.taker.name !== mine.name) tryTell(x.taker, `${mine.name} marked your work item ${wid(x)} ("${x.title}") blocked: ${r.why}.`);
|
|
291
|
+
console.log(`${wid(x)} is blocked: ${r.why}. ${why ? `Clear it: dibs work unblock ${wid(x)}` : 'That clears when what it waits on is done.'}`);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Whether item a waits on b, directly or through others.
|
|
295
|
+
function dependsOn(s, a, b, seen = new Set()) {
|
|
296
|
+
if (seen.has(a)) return false;
|
|
297
|
+
seen.add(a);
|
|
298
|
+
const x = find(s, a);
|
|
299
|
+
return !!x && (x.after || []).some(d => d === b || dependsOn(s, d, b, seen));
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function unblock(args) {
|
|
303
|
+
const n = idOf(args[0]);
|
|
304
|
+
const r = said(locked(s => {
|
|
305
|
+
const x = find(s, n);
|
|
306
|
+
if (!x) return gone(n);
|
|
307
|
+
if (!x.blocked) return refuse(`${wid(x)} has no block on it${blockedWhy(s, x) ? `; it ${blockedWhy(s, x)}, which clears when that's done` : ''}.`);
|
|
308
|
+
delete x.blocked;
|
|
309
|
+
return { x: { ...x }, why: blockedWhy(s, x) };
|
|
310
|
+
}));
|
|
311
|
+
logChange('work unblock', { id: wid(r.x) });
|
|
312
|
+
console.log(`${wid(r.x)} is unblocked${r.why ? `, though it still ${r.why}` : ''}.`);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// A progress post under an item's id: --done closes the item with proof, --blocked blocks it,
|
|
316
|
+
// and a plain post after a block clears it. Called by dibs progress after the post is down.
|
|
317
|
+
export function fromProgress(p) {
|
|
318
|
+
const n = Number(p.task.slice(1));
|
|
319
|
+
const x = find(load(), n);
|
|
320
|
+
if (!x || (x.state !== OPEN && x.state !== TAKEN)) return;
|
|
321
|
+
const mine = { me: null, name: p.who, who: p.who };
|
|
322
|
+
if (p.state === 'done') {
|
|
323
|
+
if (x.state !== TAKEN) return console.error(`${wid(x)} isn't claimed, so the post didn't close it. Claim it (dibs work claim ${wid(x)}) or close it: dibs work done ${wid(x)} "what you did"`);
|
|
324
|
+
const me = caller('progress', []);
|
|
325
|
+
const r = closeDone(n, me, p.text.slice(0, MAX_TEXT));
|
|
326
|
+
return console.log(`${wid(r.x)} is done, ${proofLine(r.x.proof)}.`);
|
|
327
|
+
}
|
|
328
|
+
if (p.state === 'blocked' || x.blocked) {
|
|
329
|
+
locked(s => {
|
|
330
|
+
const y = find(s, n);
|
|
331
|
+
if (!y || (y.state !== OPEN && y.state !== TAKEN)) return;
|
|
332
|
+
if (p.state === 'blocked') y.blocked = { why: p.text.slice(0, MAX_TEXT), by: mine.name, at: p.at };
|
|
333
|
+
else delete y.blocked;
|
|
334
|
+
});
|
|
335
|
+
if (p.state === 'blocked') console.log(`${wid(x)} is marked blocked. A post without --blocked clears it.`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// ----- reading -----
|
|
340
|
+
|
|
341
|
+
// One stored item as every reader sees it: names, never sessions or pids.
|
|
342
|
+
function viewOf(s, x, t = now(), posts = null) {
|
|
343
|
+
const why = x.state === OPEN || x.state === TAKEN ? blockedWhy(s, x) : null;
|
|
344
|
+
return {
|
|
345
|
+
id: wid(x), source: 'item', kind: x.kind || 'handoff', title: x.title, goal: x.goal || null, context: x.context || null,
|
|
346
|
+
state: why ? 'blocked' : STATE[x.state] || x.state, blocked: why,
|
|
347
|
+
owner: x.taker?.name || null, from: fromName(x), to: x.to || null,
|
|
348
|
+
createdAt: x.at, claimedAt: x.takenAt || null, closedAt: x.closedAt || null, doneBy: x.doneBy || x.cancelledBy || null, note: x.note || null,
|
|
349
|
+
after: (x.after || []).map(n => { const d = find(s, n); return { id: `w${n}`, title: d?.title || null, state: d ? STATE[d.state] || d.state : 'done' }; }),
|
|
350
|
+
files: x.paths || [],
|
|
351
|
+
takeable: x.state === OPEN && !why,
|
|
352
|
+
project: x.project || null, pickup: x.pickup !== false,
|
|
353
|
+
offer: liveOffer(x, t) ? { to: x.offer.to, at: x.offer.at } : null,
|
|
354
|
+
proof: x.state === 'done' ? proofView(x.proof) : null,
|
|
355
|
+
...(posts && { log: logOf(posts, p => p.task === wid(x) || p.task === `h${x.id}`) }),
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const logOf = (posts, mine) => posts.filter(mine).slice(-LOG_SHOWN).map(p => ({ at: p.at, who: p.who, text: p.text, state: p.state }));
|
|
360
|
+
|
|
361
|
+
// The same key progress.mjs's tasks() groups posts by.
|
|
362
|
+
const taskKey = p => `${p.who}\0${p.agentId || ''}\0${p.task || ''}\0${p.task ? '' : p.project || ''}`;
|
|
363
|
+
const ITEM_TASK = /^[wh]\d+$/i;
|
|
364
|
+
|
|
365
|
+
// Progress tasks as items: open ones, and done ones within DONE_SHOWN (all: every one kept).
|
|
366
|
+
function progressItems(posts, events, t, all) {
|
|
367
|
+
const out = [];
|
|
368
|
+
for (const k of tasks(posts, t)) {
|
|
369
|
+
if (k.task && ITEM_TASK.test(k.task)) continue;
|
|
370
|
+
if (!all && (k.state === 'expired' || (k.state === 'done' && t - k.doneAt > DONE_SHOWN))) continue;
|
|
371
|
+
const name = k.task || `untitled, in ${k.project || 'a folder'}`;
|
|
372
|
+
const key = taskKey({ who: k.who, agentId: k.agentId, task: k.task, project: k.project });
|
|
373
|
+
out.push({
|
|
374
|
+
id: `${k.who}/${k.task || k.project || 'untitled'}`, source: 'progress', kind: 'progress', title: name, goal: null, context: null,
|
|
375
|
+
state: { doing: 'claimed', blocked: 'blocked', done: 'done', expired: 'dropped' }[k.state], blocked: k.state === 'blocked' ? k.text : null,
|
|
376
|
+
owner: k.who, from: k.who, to: null, createdAt: k.started, claimedAt: k.started, closedAt: k.doneAt || k.expiredAt || null,
|
|
377
|
+
doneBy: k.state === 'done' ? k.who : null, note: k.state === 'done' ? k.text : null, after: [], files: [], takeable: false,
|
|
378
|
+
eta: k.eta || null, overdue: !!k.overdue, last: k.last,
|
|
379
|
+
proof: k.state === 'done' ? proofView(runProof({ who: k.who, since: k.started, t: k.doneAt, events })) : null,
|
|
380
|
+
log: logOf(posts, p => taskKey(p) === key),
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
return out;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// Stored items, reaped as the next write would, without the lock or a write.
|
|
387
|
+
function stored(t) {
|
|
388
|
+
const s = load();
|
|
389
|
+
reap(s, t);
|
|
390
|
+
return s;
|
|
391
|
+
}
|
|
392
|
+
const live = (i, t) => i.state !== 'done' && i.state !== 'dropped' ? true : t - (i.closedAt || 0) < DONE_SHOWN;
|
|
393
|
+
|
|
394
|
+
// The items for the board and the page: stored ones in flight and those closed within
|
|
395
|
+
// DONE_SHOWN. Reads handoffs.json only, so the board stays quick.
|
|
396
|
+
export function workNow(t = now()) {
|
|
397
|
+
const s = stored(t);
|
|
398
|
+
return s.handoffs.map(x => viewOf(s, x, t)).filter(i => live(i, t));
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// Everything, for dibs work list --json and /api/work: stored items with their logs, then
|
|
402
|
+
// progress tasks. all: closed ones too, as long as they're kept.
|
|
403
|
+
export function workJson({ t = now(), all = false } = {}) {
|
|
404
|
+
const s = stored(t);
|
|
405
|
+
const posts = readPosts({ since: t - 864e5 });
|
|
406
|
+
const items = s.handoffs.map(x => viewOf(s, x, t, posts)).filter(i => all || live(i, t));
|
|
407
|
+
const since = posts.reduce((m, p) => Math.min(m, p.at), t - DONE_SHOWN);
|
|
408
|
+
const events = readEvents(t).filter(e => e.at >= since);
|
|
409
|
+
return { at: t, items: [...items, ...progressItems(posts, events, t, all)] };
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const ORDER = { claimed: 0, blocked: 1, open: 2, done: 3, dropped: 4 };
|
|
413
|
+
const line = (i, t) => {
|
|
414
|
+
const what = i.source === 'progress' ? `${i.owner}'s task ${i.title}` : `"${i.title}"`;
|
|
415
|
+
if (i.state === 'claimed') return `${what} ${i.owner} has it, ${i.source === 'progress' ? `last post ${ago(t, i.last)}` : `since ${ago(t, i.claimedAt)}`}${i.eta ? `, expected by ${clock(i.eta)}` : ''}`;
|
|
416
|
+
if (i.state === 'blocked') return `${what} ${red('blocked')}${i.owner ? ` (${i.owner} has it)` : ''}: ${one(i.blocked).slice(0, 160)}`;
|
|
417
|
+
if (i.state === 'open') return `${what} ${i.to ? `for ${i.to}` : 'open for any agent'}${i.offer ? `, offered to ${i.offer.to} ${agoMin(t, i.offer.at)}` : ''}, from ${i.from}`;
|
|
418
|
+
if (i.state === 'done') return `${what} done by ${i.doneBy || i.owner} ${clock(i.closedAt)}, ${i.proof.proved ? i.proof.line : red(i.proof.line)}`;
|
|
419
|
+
return `${what} dropped${i.doneBy ? ` by ${i.doneBy}` : ''}${i.note ? `: ${one(i.note).slice(0, 100)}` : ''}`;
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
function list(args) {
|
|
423
|
+
const o = flags(args, [], ['--json', '--all', '--takeable']);
|
|
424
|
+
if (o.words.length) die(`dibs work list takes --takeable, --all and --json, not ${o.words[0]}.\n${USAGE}`);
|
|
425
|
+
const t = now();
|
|
426
|
+
let { items } = workJson({ t, all: o.all });
|
|
427
|
+
if (o.takeable) {
|
|
428
|
+
const mine = caller('work', args);
|
|
429
|
+
items = items.filter(i => i.takeable && (!i.to || i.to === mine.name));
|
|
430
|
+
}
|
|
431
|
+
if (o.json) return console.log(JSON.stringify({ items }, null, 1));
|
|
432
|
+
if (!items.length) return console.log(o.takeable ? 'Nothing you can claim now. Everything in flight: dibs work list' : 'No work items. Add one: dibs work add "title" --goal "done when..."');
|
|
433
|
+
items.sort((a, b) => ORDER[a.state] - ORDER[b.state] || (b.closedAt || 0) - (a.closedAt || 0) || a.createdAt - b.createdAt);
|
|
434
|
+
const flight = items.filter(i => ORDER[i.state] < 3), closed = items.filter(i => ORDER[i.state] >= 3);
|
|
435
|
+
const out = [];
|
|
436
|
+
if (flight.length) out.push(bold(`In flight (${flight.length}):`), ...columns(flight.map(i => [i.source === 'item' ? i.id : '', line(i, t)])));
|
|
437
|
+
if (closed.length) out.push(...(out.length ? [''] : []), dim(o.all ? 'Closed:' : 'Closed lately:'), ...columns(closed.map(i => [i.source === 'item' ? i.id : '', line(i, t)])));
|
|
438
|
+
out.push('', dim('Claim the next one: dibs work next. One item: dibs work show <id>. Everything: dibs work help'));
|
|
439
|
+
console.log(out.join('\n'));
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function show(args) {
|
|
443
|
+
const o = flags(args, [], ['--json']);
|
|
444
|
+
const n = idOf(o.words[0]);
|
|
445
|
+
const t = now();
|
|
446
|
+
const i = workJson({ t, all: true }).items.find(x => x.id === `w${n}`);
|
|
447
|
+
if (!i) die(`no work item w${n}. In flight: dibs work list`, 1);
|
|
448
|
+
if (o.json) return console.log(JSON.stringify({ item: i }, null, 1));
|
|
449
|
+
const where = i.state === 'done' || i.state === 'dropped' ? (i.doneBy ? ` by ${i.doneBy} ${clock(i.closedAt)}` : '') : i.owner ? `, ${i.owner} has it` : '';
|
|
450
|
+
const out = [bold(`${i.id} "${i.title}"`), ` ${i.state}${where}${i.blocked ? `: ${i.blocked}` : ''}. From ${i.from}${i.to ? `, for ${i.to}` : ''}, ${clock(i.createdAt)}.`];
|
|
451
|
+
if (i.goal) out.push(` Done when: ${i.goal}`);
|
|
452
|
+
if (i.context) out.push(` ${i.context}`);
|
|
453
|
+
if (i.after.length) out.push(` Waits on: ${i.after.map(d => `${d.id} (${d.state})`).join(', ')}`);
|
|
454
|
+
if (i.files.length) out.push(` Files: ${i.files.join(', ')}`);
|
|
455
|
+
if (i.project || !i.pickup) out.push(` ${i.project ? `Project: ${i.project}` : 'No project'}${i.pickup ? '' : ', never offered to an idle agent (--no-pickup)'}`);
|
|
456
|
+
if (i.offer) out.push(` Offered to ${i.offer.to} ${agoMin(t, i.offer.at)}; it goes to the next idle agent if it isn't claimed in ${OFFER_FOR / 6e4} minutes.`);
|
|
457
|
+
if (i.proof) {
|
|
458
|
+
if (i.note) out.push(` Note: ${i.note}`);
|
|
459
|
+
out.push(` ${i.state === 'done' ? 'Done' : i.state}, ${i.proof.line}`);
|
|
460
|
+
for (const p of i.proof.items) out.push(dim(` ${p.kind}${p.checked ? '' : ' (its word)'}: ${p.kind === 'run' ? `${(p.res || []).join(',')} "${p.what || ''}" exit 0 at ${clock(p.at)}` : p.kind === 'commit' ? `${p.sha} "${p.subject}" ${clock(p.at)}` : p.url || p.build}`));
|
|
461
|
+
}
|
|
462
|
+
if (i.log?.length) out.push(' Log:', ...i.log.map(p => ` ${dim(clock(p.at))} ${p.who}${p.state !== 'doing' ? ` [${p.state}]` : ''}: ${one(p.text).slice(0, 300)}`));
|
|
463
|
+
console.log(out.join('\n'));
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// dibs work pickup [on|off]: whether listening agents with nothing on are offered open items
|
|
467
|
+
// (src/pickup.mjs). Off unless someone turns it on; whoever does is on the record.
|
|
468
|
+
function pickup(args) {
|
|
469
|
+
const word = args[0];
|
|
470
|
+
if (args.length > 1 || (word && word !== 'on' && word !== 'off')) die('dibs work pickup takes on, off, or nothing to show whether it\'s on.');
|
|
471
|
+
if (word) {
|
|
472
|
+
const was = pickupOn();
|
|
473
|
+
loadConfig();
|
|
474
|
+
const c = JSON.parse(fs.readFileSync(paths.config, 'utf8'));
|
|
475
|
+
c.pickup = word === 'on';
|
|
476
|
+
const tmp = `${paths.config}.${process.pid}`;
|
|
477
|
+
fs.writeFileSync(tmp, JSON.stringify(c, null, 2) + '\n');
|
|
478
|
+
fs.renameSync(tmp, paths.config);
|
|
479
|
+
if (was !== c.pickup) logChange('work pickup', { on: c.pickup });
|
|
480
|
+
}
|
|
481
|
+
console.log(pickupOn()
|
|
482
|
+
? `Pickup is on: an agent listening with no task open and no item claimed is offered the oldest open item for its project (dibs project). Unclaimed in ${OFFER_FOR / 6e4} minutes, it goes to the next. Turn off: dibs work pickup off`
|
|
483
|
+
: 'Pickup is off: open items wait for an agent to claim them (dibs work next). Turn on: dibs work pickup on');
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// One line per in-flight item for the plain board (dibs): what, and where it stands.
|
|
487
|
+
export const workLine = (i, t = now()) => `${i.id} ${line(i, t)}`;
|
package/src/worker.mjs
CHANGED
|
@@ -18,6 +18,7 @@ import { now, sleep, bytes, log, SIGNALS, signalExit, LEAN } from './util.mjs';
|
|
|
18
18
|
import { VERSION } from './version.mjs';
|
|
19
19
|
import { runLater } from './later.mjs';
|
|
20
20
|
import { unpatched } from './nodecheck.mjs';
|
|
21
|
+
import { described } from './declare.mjs';
|
|
21
22
|
|
|
22
23
|
const BIN = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'bin', 'dibs.mjs');
|
|
23
24
|
const PIDFILE = path.join(HOME, 'worker.pid');
|
|
@@ -204,10 +205,12 @@ export async function worker(o, cfg) {
|
|
|
204
205
|
// The `dibs run` a job becomes here: the sender's flags, in this machine's queue.
|
|
205
206
|
export function runArgs(job) {
|
|
206
207
|
const args = ['run', job.res.join(','), '--as', job.label || 'remote'];
|
|
207
|
-
|
|
208
|
+
// A sender older than declarations sends none: never refused here, it gets words made from what's known.
|
|
209
|
+
args.push('-m', described(job));
|
|
208
210
|
if (job.prio) args.push('-p', job.prio);
|
|
209
211
|
if (job.by) args.push('--by', String(Math.max(1, Math.round((job.by - now()) / 1000))) + 's');
|
|
210
212
|
if (job.est) args.push('--est', `${Math.round(job.est / 1000)}s`);
|
|
213
|
+
if (job.timeLimit) args.push('--time-limit', `${Math.ceil(job.timeLimit / 1000)}s`);
|
|
211
214
|
// Only a --mem the sender gave: the resource default is this machine's own,
|
|
212
215
|
// and a pool resource adds its simulator on top of any --mem.
|
|
213
216
|
const mem = 'askedMem' in job ? job.askedMem : job.mem;
|
|
@@ -309,6 +312,9 @@ function start(rc, job, running, cfg, name) {
|
|
|
309
312
|
const argv = OS === 'windows' ? [process.execPath, ...LEAN, BIN] : ['/bin/sh', BIN];
|
|
310
313
|
const env = { ...process.env, DIBS_AGENT: `${job.agent || job.who}@${job.from}`, DIBS_NO_SESSION: '1', DIBS_REMOTE_JOB: String(job.id), ...(typeof job.repo === 'string' && job.repo && { DIBS_REPO: job.repo }) };
|
|
311
314
|
delete env.DIBS_AS;
|
|
315
|
+
// An agent's job is that agent's here too (src/owner.mjs actor): with the worker's own environment
|
|
316
|
+
// it would be the person's, who alone may answer a spend question or approve a secret's use.
|
|
317
|
+
if (job.byAgent === true) env.AI_AGENT = '1';
|
|
312
318
|
child = spawn(argv[0], [...argv.slice(1), ...runArgs(job)], { cwd, env, stdio: ['ignore', 'pipe', 'pipe'], detached: OS !== 'windows', windowsHide: true });
|
|
313
319
|
child.stdout.on('data', d => pending.push([1, d]));
|
|
314
320
|
child.stderr.on('data', d => pending.push([2, d]));
|