@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.
Files changed (105) hide show
  1. package/CHANGELOG.md +103 -1
  2. package/README.md +10 -8
  3. package/bin/dibs.mjs +370 -73
  4. package/docs/agents.md +303 -0
  5. package/docs/council.md +88 -0
  6. package/docs/files.md +3 -3
  7. package/docs/guard.md +86 -11
  8. package/docs/json.md +211 -0
  9. package/docs/later.md +5 -5
  10. package/docs/machines.md +6 -6
  11. package/docs/questions.md +104 -3
  12. package/docs/reference.md +124 -30
  13. package/docs/relay.md +120 -9
  14. package/docs/releasing.md +7 -1
  15. package/docs/scheduling.md +28 -6
  16. package/docs/secrets.md +53 -0
  17. package/docs/simulators.md +3 -3
  18. package/package.json +1 -1
  19. package/skills/dibs/SKILL.md +79 -149
  20. package/src/about.mjs +341 -0
  21. package/src/acquire.mjs +111 -27
  22. package/src/after.mjs +127 -0
  23. package/src/agents.mjs +2 -1
  24. package/src/alerts.mjs +95 -42
  25. package/src/answers.mjs +2 -2
  26. package/src/board.mjs +21 -16
  27. package/src/broker.mjs +23 -7
  28. package/src/carry.mjs +287 -0
  29. package/src/codex.mjs +132 -0
  30. package/src/commands.mjs +243 -82
  31. package/src/config.mjs +85 -14
  32. package/src/connect.mjs +4 -2
  33. package/src/cool.mjs +27 -11
  34. package/src/council.mjs +482 -0
  35. package/src/cwd.mjs +9 -0
  36. package/src/decisions.mjs +250 -0
  37. package/src/declare.mjs +96 -0
  38. package/src/diskreport.mjs +306 -0
  39. package/src/diskuse.mjs +420 -0
  40. package/src/diskwarn.mjs +68 -13
  41. package/src/doctor.mjs +149 -0
  42. package/src/doors.mjs +547 -0
  43. package/src/durable.mjs +143 -0
  44. package/src/envs.mjs +372 -0
  45. package/src/events.mjs +7 -2
  46. package/src/files.mjs +118 -6
  47. package/src/guard.mjs +239 -86
  48. package/src/guardd.mjs +8 -1
  49. package/src/halt.mjs +63 -0
  50. package/src/handoffs.mjs +362 -0
  51. package/src/history.mjs +34 -4
  52. package/src/hogs.mjs +36 -8
  53. package/src/jobprogress.mjs +283 -0
  54. package/src/later.mjs +21 -10
  55. package/src/lock.mjs +33 -9
  56. package/src/measure.mjs +42 -11
  57. package/src/media.mjs +240 -0
  58. package/src/news.mjs +31 -0
  59. package/src/notes.mjs +49 -8
  60. package/src/notices.mjs +126 -43
  61. package/src/ondemand.mjs +25 -2
  62. package/src/outcome.mjs +163 -0
  63. package/src/overlap.mjs +2 -2
  64. package/src/override.mjs +149 -79
  65. package/src/owner.mjs +15 -2
  66. package/src/people.mjs +236 -0
  67. package/src/pickup.mjs +72 -0
  68. package/src/picture.mjs +321 -0
  69. package/src/plain.mjs +84 -18
  70. package/src/platform.mjs +19 -0
  71. package/src/preempt.mjs +123 -15
  72. package/src/primer.mjs +91 -20
  73. package/src/prints.mjs +99 -0
  74. package/src/proc.mjs +1 -1
  75. package/src/progress.mjs +49 -3
  76. package/src/proof.mjs +102 -0
  77. package/src/push.mjs +271 -0
  78. package/src/questions.mjs +328 -57
  79. package/src/quota.mjs +1 -1
  80. package/src/recap.mjs +205 -0
  81. package/src/relay.mjs +139 -20
  82. package/src/remote.mjs +23 -10
  83. package/src/reviewgate.mjs +268 -0
  84. package/src/reviews.mjs +377 -0
  85. package/src/route.mjs +263 -0
  86. package/src/rules.mjs +216 -0
  87. package/src/schedule.mjs +238 -44
  88. package/src/schema.mjs +62 -0
  89. package/src/scratch.mjs +2 -2
  90. package/src/serve.mjs +3 -2
  91. package/src/signed.mjs +97 -0
  92. package/src/simpool.mjs +46 -1
  93. package/src/spend.mjs +375 -0
  94. package/src/state.mjs +43 -17
  95. package/src/talk.mjs +1078 -133
  96. package/src/thin.sh +2 -0
  97. package/src/trail.mjs +290 -0
  98. package/src/trailnote.mjs +209 -0
  99. package/src/util.mjs +7 -0
  100. package/src/vault.mjs +435 -0
  101. package/src/vendors.mjs +327 -0
  102. package/src/version.mjs +1 -1
  103. package/src/web.mjs +353 -60
  104. package/src/work.mjs +487 -0
  105. package/src/worker.mjs +7 -1
@@ -0,0 +1,250 @@
1
+ // Decisions agents can look up, so nobody asks the person the same thing twice.
2
+ // Every question the person (or an agent for them) answered, every two-way door an
3
+ // agent walked through, and every decision recorded with `dibs decide`, kept for
4
+ // good: questions.json forgets its closed questions after a week, this doesn't.
5
+ //
6
+ // Each decision belongs to a project (src/files.mjs projectKey: the repo's origin,
7
+ // the same in every clone and worktree, else the folder), or to every project.
8
+ // `dibs question` looks here first and, when a past decision clearly says the same
9
+ // thing for the same project, hands that back instead of asking. "Clearly" is
10
+ // strict on purpose: citing the wrong decision does more harm than asking again.
11
+ // A revoked decision stays in the file for the record and is never cited again.
12
+ //
13
+ // Its own file and lock, like questions.json: the page polls it and it never
14
+ // decides who runs next.
15
+ import fs from 'node:fs';
16
+ import os from 'node:os';
17
+ import path from 'node:path';
18
+ import { HOME } from './config.mjs';
19
+ import { actor, logChange } from './owner.mjs';
20
+ import { projectKey } from './files.mjs';
21
+ import { words } from './answers.mjs';
22
+ import { underLock, commit } from './lock.mjs';
23
+ import { die, now, say, fakeFull } from './util.mjs';
24
+ import { bold, dim, wrap } from './style.mjs';
25
+ import { readJSON } from './durable.mjs';
26
+
27
+ const FILE = path.join(HOME, 'decisions.json');
28
+ const LOCK = path.join(HOME, 'decisions.lock');
29
+ const LOCK_WAIT = 15e3;
30
+ // A decision is a few hundred bytes, and every new session's primer reads the
31
+ // file. Two-way doors can come by the dozen a day, so past this many the oldest
32
+ // agents' and revoked ones go first; the person's own go only when nothing else is left.
33
+ const KEEP = 2000;
34
+ // A match shares at least this many words, and this share of all the words in
35
+ // either: "Delete the release branch now?" doesn't answer "Delete the staging branch now?" (3 of 5).
36
+ const MIN_SHARED = 2;
37
+ const CLOSE = 0.7;
38
+ // Words that turn a question around, which the docs' stop words drop.
39
+ const NEGATION = /\b(not|no|never|don't|dont|without|stop|skip)\b/;
40
+ // dibs decisions shows this many unless --all.
41
+ const SHOWN = 20;
42
+
43
+ function locked(fn) {
44
+ const r = underLock(LOCK, h => {
45
+ const s = load();
46
+ const before = JSON.stringify(s);
47
+ const out = fn(s);
48
+ if (JSON.stringify(s) !== before) commit(h, FILE, JSON.stringify(s, null, 1), { fake: () => fakeFull('state') });
49
+ return out;
50
+ }, { wait: LOCK_WAIT, files: [FILE] });
51
+ if (!r) die(`${LOCK} is held by a dibs that's still running, and stayed held for ${LOCK_WAIT / 1000}s. Nothing was changed: run the same command again.`, 75);
52
+ return r.out;
53
+ }
54
+
55
+ // Writes are renames, so reading without the lock always sees a whole file.
56
+ function load() {
57
+ let s = {};
58
+ try { s = readJSON(FILE); } catch (e) {
59
+ if (e.code !== 'ENOENT') say(`${FILE} was unreadable (${e.message}); reading it as no decisions.`);
60
+ }
61
+ s.seq ||= 0; s.decisions ||= [];
62
+ return s;
63
+ }
64
+
65
+ // The project the caller works in. A job sent from another machine carries its
66
+ // sender's (src/worker.mjs sets DIBS_REPO), since its copy has no .git.
67
+ export const projectHere = () => process.env.DIBS_REPO || projectKey(process.cwd());
68
+
69
+ // A project as people read it: no scheme, no credentials, no .git, ~ for home.
70
+ export function place(key) {
71
+ if (!key) return 'every project';
72
+ const home = os.homedir();
73
+ if (key.startsWith(home + path.sep)) return `~${key.slice(home.length)}`;
74
+ return key.replace(/^[a-z+]+:\/\//i, '').replace(/^[^@/]+@/, '').replace(/^([^/:]+):(?!\d)/, '$1/').replace(/\.git$/, '');
75
+ }
76
+
77
+ // Keep one decision. d: { text, answer, why, by, byAgent, via, project, tags, kind, question }.
78
+ export function remember(d) {
79
+ return locked(s => {
80
+ const x = { id: ++s.seq, at: now(), tags: [], answer: null, why: null, question: null, ...d };
81
+ s.decisions.push(x);
82
+ // A question asked again (--again) and answered: the decision it would have been answered
83
+ // from is taken back, so the newer answer is the only one cited.
84
+ const old = d.supersedes && s.decisions.find(y => y.id === d.supersedes && !y.revoked);
85
+ if (old) old.revoked = { at: x.at, by: x.by, why: `answered again: decision ${x.id}` };
86
+ while (s.decisions.length > KEEP) {
87
+ const i = s.decisions.findIndex(y => y.byAgent || y.revoked);
88
+ s.decisions.splice(i < 0 ? 0 : i, 1);
89
+ }
90
+ return { ...x };
91
+ });
92
+ }
93
+
94
+ // A question asked before dibs kept its project: its decision is listed, never cited,
95
+ // since no folder's project is this word.
96
+ const UNKNOWN = 'unknown project';
97
+
98
+ // What a closed question decided, kept as a decision: the person's answer (or an
99
+ // agent's for them), or a two-way door the asker walked through. The asker's reason
100
+ // stands as the why when the answer took their recommendation.
101
+ // A yes to one action isn't a decision: spending past a cap and a one-way environment
102
+ // (personOnly) ask every time, and a --needs-you question (approving one use of a secret, a
103
+ // login) is a thing only the person can do now. Kept, they read as precedent in dibs decisions.
104
+ // With several people, the one who answered is named, and a one-way door is cited only to
105
+ // agents of the same owner (precedent): jordan's yes doesn't stand in for sam's.
106
+ export function rememberQuestion(q) {
107
+ if (q.personOnly || q.needsYou) return;
108
+ try {
109
+ const two = q.state === 'decided';
110
+ const person = q.answeredPerson || 'the person';
111
+ remember({ kind: two ? 'two-way' : 'answered', text: q.text, answer: q.answer, why: q.answer === q.recommend ? q.purpose || null : null,
112
+ by: two ? q.decidedBy : q.answeredBy || (q.answeredVia ? `${person} via ${q.answeredVia}` : person),
113
+ byAgent: two || !!q.answeredBy, project: q.project || UNKNOWN, question: q.id, ...(q.freeText && { freeText: true }),
114
+ ...(q.owner && { owner: q.owner }), ...(q.supersedes && { supersedes: q.supersedes }) });
115
+ } catch (e) {
116
+ // The answer itself went through; only its copy in the log didn't.
117
+ say(`the answer was given, but couldn't be kept as a decision (${e.message}).`);
118
+ }
119
+ }
120
+
121
+ const tokens = text => new Set(words(text));
122
+ const numbers = set => [...set].filter(w => /\d/.test(w)).sort().join();
123
+ const negated = text => NEGATION.test(String(text).toLowerCase());
124
+
125
+ // Whether two texts ask the same thing: most words shared, the same numbers
126
+ // (build 123 isn't build 124), and both or neither turned around by a "not".
127
+ export function same(a, b) {
128
+ const x = tokens(a), y = tokens(b);
129
+ const both = [...x].filter(w => y.has(w)).length;
130
+ return both >= MIN_SHARED && both / (x.size + y.size - both) >= CLOSE && numbers(x) === numbers(y) && negated(a) === negated(b);
131
+ }
132
+
133
+ const live = d => !d.revoked;
134
+ const inProject = (d, key) => d.project == null || d.project === key;
135
+
136
+ // The newest decision that clearly answers this question in this project, or null.
137
+ // A one-way door is for the person, so only what the person decided stands in for
138
+ // asking them. An answer in the person's own words is listed, never cited: those
139
+ // are often "not yet, ask me Monday". skip: question ids this asker already has,
140
+ // which it's collecting. options: the question offers options, so only a decision born
141
+ // from a question (an answer or a two-way door) stands in: a dibs decide sentence isn't one of them.
142
+ export function precedent(text, key, { oneWay = false, options = false, skip = [], owner = null } = {}) {
143
+ return load().decisions.filter(d => live(d) && !d.freeText && inProject(d, key) && !(oneWay && d.byAgent) && !(oneWay && (d.owner || null) !== owner) && !(options && d.question == null)
144
+ && !skip.includes(d.question) && same(text, d.text)).pop() || null;
145
+ }
146
+
147
+ const day = t => { const d = new Date(t); return `${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`; };
148
+ export const verdict = d => d.answer ?? d.text;
149
+
150
+ // "decided on 11-20 by the person: yes, because ..." for the asker.
151
+ export const cite = d => `decided on ${day(d.at)} by ${d.by}: ${verdict(d)}${d.why ? `, because ${d.why}` : ''} (decision ${d.id}${d.answer != null ? `, on "${d.text}"` : ''})`;
152
+
153
+ // A plural is the word it counts: "friday deploys" finds "deploy on Fridays". Only in a
154
+ // search; whether a question is the same one stays word for word.
155
+ const stem = w => (w.length > 4 && w.endsWith('s') && !w.endsWith('ss') ? w.slice(0, -1) : w);
156
+ const stems = text => new Set(words(text).map(stem));
157
+
158
+ // The best decisions for some words: each word found counts once, a rare one more
159
+ // than a common one (src/answers.mjs does the same over the docs).
160
+ function search(list, about) {
161
+ const want = [...stems(about)];
162
+ if (!want.length) return list;
163
+ const has = list.map(d => stems(`${d.text} ${d.answer ?? ''} ${d.why ?? ''} ${(d.tags || []).join(' ')}`));
164
+ const weight = new Map(want.map(w => [w, Math.log(1 + list.length / (1 + has.filter(s => s.has(w)).length))]));
165
+ return list.map((d, i) => ({ d, score: want.reduce((n, w) => n + (has[i].has(w) ? weight.get(w) : 0), 0), hits: want.filter(w => has[i].has(w)).length }))
166
+ .filter(x => x.hits >= Math.min(2, want.length))
167
+ .sort((a, b) => b.score - a.score || b.d.at - a.d.at)
168
+ .map(x => x.d);
169
+ }
170
+
171
+ // What the page, the phone and --json see: the project as people read it.
172
+ const shown = d => ({ id: d.id, text: d.text, answer: d.answer, why: d.why, by: d.by, byAgent: !!d.byAgent, at: d.at, kind: d.kind,
173
+ project: place(d.project), everywhere: d.project == null, tags: d.tags || [], question: d.question, revoked: d.revoked || null });
174
+
175
+ // For GET /api/decisions: newest first, revoked ones marked.
176
+ export function decisionsJson({ about = '', key = null, all = true } = {}) {
177
+ let list = load().decisions.filter(d => (all || live(d)) && (key == null || inProject(d, key))).reverse();
178
+ if (about) list = search(list, about);
179
+ return { decisions: list.map(shown) };
180
+ }
181
+
182
+ // dibs decide "use Postgres 16 for staging" -m why [--tags a,b] [--everywhere]
183
+ export function decide(args) {
184
+ const o = { words: [], tags: [] };
185
+ for (let i = 0; i < args.length; i++) {
186
+ const a = args[i], next = () => args[++i] ?? die(`${a} needs a value`);
187
+ if (a === '-m' || a === '--msg') o.why = next().trim();
188
+ else if (a === '--tags') o.tags = next().split(',').map(x => x.trim().toLowerCase()).filter(Boolean);
189
+ else if (a === '--everywhere') o.everywhere = true;
190
+ else if (a.startsWith('-') && a.length > 1) die(`unknown flag ${a}. dibs decide "what was decided" -m "why" [--tags a,b] [--everywhere]`);
191
+ else o.words.push(a);
192
+ }
193
+ const text = o.words.join(' ').trim();
194
+ if (text.split(/\s+/).filter(w => /\p{L}{2,}/u.test(w)).length < 3)
195
+ die(`say what was decided in a short sentence, e.g. dibs decide "use Postgres 16 for staging" -m "matches production". Nothing was kept.`);
196
+ if (!o.why) die('say why: -m "why". The next agent reads it before going against it. Nothing was kept.');
197
+ const who = actor();
198
+ const d = remember({ kind: 'recorded', text, why: o.why, tags: o.tags, by: who.name, byAgent: who.agent, ...(who.via && { via: who.via }),
199
+ project: o.everywhere ? null : projectHere() });
200
+ logChange('decide', { decision: d.id, text });
201
+ console.log(`decision ${d.id} kept for ${place(d.project)}: ${text}. dibs question cites it instead of asking; dibs decisions revoke ${d.id} takes it back.`);
202
+ }
203
+
204
+ // dibs decisions [--about words] [--project] [--all] [--json] | dibs decisions revoke <id> [-m why]
205
+ export function decisions(args) {
206
+ if (args[0] === 'revoke') return revoke(args.slice(1));
207
+ const o = { about: [] };
208
+ for (let i = 0; i < args.length; i++) {
209
+ const a = args[i];
210
+ if (a === '--about') o.about.push(args[++i] ?? die('--about needs words'));
211
+ else if (a === '--project') o.project = true;
212
+ else if (a === '--all') o.all = true;
213
+ else if (a === '--json') o.json = true;
214
+ else if (a.startsWith('-')) die(`unknown flag ${a}. Try: dibs decisions [--about words] [--project] [--all] [--json], dibs decisions revoke <id>`);
215
+ else o.about.push(a);
216
+ }
217
+ const key = o.project ? projectHere() : null;
218
+ const { decisions: list } = decisionsJson({ about: o.about.join(' '), key, all: !!o.all });
219
+ if (o.json) return console.log(JSON.stringify({ decisions: list }, null, 1));
220
+ const where = o.project ? ` for ${place(key)}` : '';
221
+ if (!list.length) return console.log(o.about.length ? `No decision${where} matches "${o.about.join(' ')}".` : `No decisions${where} yet. Keep one: dibs decide "what was decided" -m "why"`);
222
+ const out = [bold(`${list.length} decision${list.length > 1 ? 's' : ''}${where}${o.about.length ? `, closest to "${o.about.join(' ')}" first` : ', newest first'}.`)];
223
+ for (const d of list.slice(0, o.all ? Infinity : SHOWN)) {
224
+ out.push('', ` #${d.id} ${day(d.at)} ${d.by}${d.revoked ? dim(` [revoked ${day(d.revoked.at)} by ${d.revoked.by}]`) : ''}`);
225
+ out.push(wrap(` ${d.answer != null ? `${d.text} -> ${d.answer}` : d.text}`, ' '));
226
+ if (d.why) out.push(dim(wrap(` because ${d.why}`, ' ')));
227
+ out.push(dim(` ${d.project}${d.tags.length ? ` [${d.tags.join(', ')}]` : ''}`));
228
+ }
229
+ if (!o.all && list.length > SHOWN) out.push('', dim(`${list.length - SHOWN} more: dibs decisions --all`));
230
+ out.push('', dim(`Take one back: dibs decisions revoke <id>. Keep one: dibs decide "..." -m why`));
231
+ console.log(out.join('\n'));
232
+ }
233
+
234
+ function revoke(args) {
235
+ const n = Number(args[0]);
236
+ if (!Number.isInteger(n) || n < 1) die('which decision? dibs decisions revoke <id> (the ids: dibs decisions)');
237
+ const mi = args.indexOf('-m');
238
+ const why = mi > 0 ? args[mi + 1]?.trim() || null : null;
239
+ const who = actor();
240
+ const r = locked(s => {
241
+ const d = s.decisions.find(x => x.id === n);
242
+ if (!d) return { no: `no decision ${n}. See them: dibs decisions` };
243
+ if (d.revoked) return { no: `decision ${n} was already revoked by ${d.revoked.by}` };
244
+ d.revoked = { at: now(), by: who.name, why, ...(who.via && { via: who.via }) };
245
+ return { d: { ...d } };
246
+ });
247
+ if (r.no) die(r.no, 1);
248
+ logChange('revoke decision', { decision: n, text: r.d.text });
249
+ console.log(`revoked decision ${n}: ${r.d.text}. It's never cited again; the next agent to ask gets a fresh answer.`);
250
+ }
@@ -0,0 +1,96 @@
1
+ // Every job dibs starts says, in plain words, what it's doing: -m on dibs run,
2
+ // hold and later. The person reads these on the board, the page and the phone,
3
+ // and doesn't think in commands, so "npm test" or "zsh -c ..." tells them
4
+ // nothing. A run or hold without words a person can follow is refused (exit 2)
5
+ // before it gets in line, with the command to send again.
6
+ //
7
+ // Jobs dibs didn't get words for (state rows and events from before 0.0.191, a
8
+ // job an older dibs sent from another machine, a script's dibs run inside an
9
+ // outer one) are never refused: they're shown with words made from what's known.
10
+ import { named } from './plain.mjs';
11
+ import { quoted } from './style.mjs';
12
+ import { die } from './util.mjs';
13
+
14
+ // Fewer words than this can't say what and why: "tests", "build it".
15
+ export const MIN_WORDS = 3;
16
+ // Half or more of the words being flags, paths, pipes or variables makes it a command, not words.
17
+ export const SHELL_SHARE = 0.5;
18
+ // The words the refusal suggests, and that a declaration may not be left as.
19
+ export const PLACEHOLDER = '...';
20
+ export const GOOD = 'run the login tests after fixing the redirect';
21
+
22
+ // Words that say nothing on their own, left out when asking whether a
23
+ // declaration only repeats its command: "run npm test" is "npm test".
24
+ const FILLER = new Set(('a an the to of for and or on in at with by from this that these it its my our your some all again now then just '
25
+ + 'run runs ran running rerun execute exec start starts starting launch do does call invoke command cmd script job hold holding use using').split(' '));
26
+ const SHELLISH = /[|&;<>$`=\\{}()[\]*]|^-|^\.{0,2}\/|^~|\/\S/;
27
+ const norm = w => w.toLowerCase().replace(/[^a-z0-9]/g, '').replace(/(.{3,})s$/, '$1');
28
+ const wordsOf = s => String(s).split(/[^A-Za-z0-9]+/).map(norm).filter(Boolean);
29
+
30
+ // A declaration that restates its command repeats the program and its first
31
+ // words ("npm test", "run xcodebuild build"). Only those count: a long script's
32
+ // later words would make good words like "deploy the docs site" look like a copy.
33
+ export const COMMAND_WORDS = 4;
34
+ const SHELLS = new Set(['sh', 'bash', 'zsh', 'dash']);
35
+ // A hold has no command: null.
36
+ function leading(cmd) {
37
+ cmd = cmd || [];
38
+ const argv = SHELLS.has(String(cmd[0] || '').split('/').pop()) && cmd[1] === '-c' ? String(cmd[2] || '').split(/\s+/) : cmd;
39
+ return argv.filter(w => w && !w.startsWith('-')).slice(0, COMMAND_WORDS);
40
+ }
41
+
42
+ // What's wrong with a declaration, or null when it says something. cmd is the
43
+ // command's words (an array), res the resources it asks for.
44
+ export function declarationProblem(text, cmd = [], res = []) {
45
+ const t = typeof text === 'string' ? text.trim() : '';
46
+ if (!t) return 'it has no -m';
47
+ if (/<[^>]*>/.test(t) || t === PLACEHOLDER) return `-m "${t}" is still the placeholder`;
48
+ const tokens = t.split(/\s+/);
49
+ if (tokens.filter(w => SHELLISH.test(w)).length / tokens.length >= SHELL_SHARE) return `-m "${t}" is shell, not words`;
50
+ const words = tokens.filter(w => /[A-Za-z]/.test(w));
51
+ if (words.length < MIN_WORDS) return `-m "${t}" is ${words.length === 1 ? 'one word' : `${words.length} words`}; it takes at least ${MIN_WORDS}`;
52
+ const theirs = new Set([...leading(cmd).flatMap(wordsOf), ...(res || []).flatMap(wordsOf)]);
53
+ const meant = words.map(norm).filter(w => w && !FILLER.has(w));
54
+ if (!meant.length || meant.every(w => theirs.has(w))) return `-m "${t}" only repeats the ${cmd?.length ? 'command' : 'resource'}`;
55
+ return null;
56
+ }
57
+
58
+ // The command as typed, with -m "..." in place of whatever -m it had, for the agent to send again.
59
+ export function retyped(argv) {
60
+ const dd = argv.indexOf('--');
61
+ const head = dd < 0 ? argv : argv.slice(0, dd);
62
+ const kept = head.filter((a, i) => !(a === '-m' || a === '--msg' || head[i - 1] === '-m' || head[i - 1] === '--msg'));
63
+ return `dibs ${quoted(kept)} -m "${PLACEHOLDER}"${dd < 0 ? '' : ` ${quoted(argv.slice(dd))}`}`;
64
+ }
65
+
66
+ export function refusal(problem, argv, verb) {
67
+ return `dibs ${verb} needs -m with plain words saying what this does and why: the person reads them on the board and their phone,`
68
+ + ` and doesn't read commands. ${verb === 'later' ? 'Nothing was scheduled' : 'Nothing ran and nothing got in line'} (exit 2): ${problem}. Send it again with your own words:\n`
69
+ + ` ${retyped(argv)}\n`
70
+ + `Like -m "${GOOD}", not -m "npm test".`;
71
+ }
72
+
73
+ // Words for a job that came without any: what it was doing, by its resources.
74
+ // A guard-wrapped run from before 0.0.191 is labelled "guard: <its command>", which is no better.
75
+ export function fallback(x, cfg = {}) {
76
+ const res = (x?.res || []).filter(Boolean);
77
+ const doing = res.length ? named(cfg, res[0]).doing : 'A job';
78
+ const hold = x?.kind === 'hold' || x?.type === 'hold';
79
+ const what = hold ? `Holding ${res.length ? named(cfg, res[0]).the : 'a resource'}` : doing;
80
+ return `${what}${x?.from ? `, sent from ${x.from}` : ''}, not described`;
81
+ }
82
+
83
+ // Refuses a run, hold or later without plain words, before anything gets in line.
84
+ // Not asked: a thin waiter's turn (--lease: checked when it got in line), and jobs
85
+ // another machine or dibs later started, which an older dibs may have sent without
86
+ // words. A script's dibs run inside an outer one is let through by the caller.
87
+ export function requireDeclaration(o, verb, argv) {
88
+ if (o.lease || process.env.DIBS_REMOTE_JOB || process.env.DIBS_LATER_JOB) return;
89
+ const problem = declarationProblem(o.purpose, o.cmd, o.res);
90
+ if (problem) die(refusal(problem, argv, verb), 2);
91
+ }
92
+
93
+ export const declared = x => typeof x?.purpose === 'string' && !!x.purpose.trim() && !x.purpose.startsWith('guard: ');
94
+
95
+ // What a job is doing, in words: its own, or ones made from what's known.
96
+ export const described = (x, cfg) => (declared(x) ? x.purpose.trim() : fallback(x, cfg));