@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/questions.mjs
CHANGED
|
@@ -8,7 +8,12 @@
|
|
|
8
8
|
// undone", it's a two-way door: dibs answers at once with the recommendation,
|
|
9
9
|
// logs the decision, and shows it to the person as done, to overrule with a
|
|
10
10
|
// message if they like. The person's standing rule: walk through two-way
|
|
11
|
-
// doors, bring them only what can't be undone.
|
|
11
|
+
// doors, bring them only what can't be undone. And --needs-you "what only the
|
|
12
|
+
// person can do" (a login, a captcha, a code on their phone) reaches them too: no
|
|
13
|
+
// agent can walk through that door, whether or not it can be undone.
|
|
14
|
+
//
|
|
15
|
+
// A question asked with --about <kind> may be answered by one of the person's standing rules
|
|
16
|
+
// (src/rules.mjs) instead: at once, door or not, and on the record as that rule's answer.
|
|
12
17
|
//
|
|
13
18
|
// Questions keep their own file and lock, not state.json's: the Mac app polls
|
|
14
19
|
// them often, and they never decide who runs next, so there's no reason to
|
|
@@ -18,15 +23,24 @@ import path from 'node:path';
|
|
|
18
23
|
import { HOME, paths, loadConfig } from './config.mjs';
|
|
19
24
|
import { identity, isMine, makeAlive, pstart, tag } from './proc.mjs';
|
|
20
25
|
import { actor, logChange } from './owner.mjs';
|
|
26
|
+
import { readPeople, several, find, ownerOf, hoursCfg } from './people.mjs';
|
|
21
27
|
import { KEEP_PLACE } from './state.mjs';
|
|
22
28
|
import { PRIORITY_SHIFT, PRIORITIES, priority } from './schedule.mjs';
|
|
23
29
|
import { defaultMaxWait } from './acquire.mjs';
|
|
24
30
|
import { event } from './events.mjs';
|
|
25
31
|
import { takeAgent, talkKey } from './files.mjs';
|
|
26
32
|
import { messageAsker } from './talk.mjs';
|
|
33
|
+
import { precedent, rememberQuestion, projectHere, cite, verdict, same as sameWords, place } from './decisions.mjs';
|
|
34
|
+
import { checkProof } from './signed.mjs';
|
|
35
|
+
import { ruleFor, noteHit, describeRule, ABOUT } from './rules.mjs';
|
|
36
|
+
import { doorOf, yesFromAnswer, KINDS } from './doors.mjs';
|
|
27
37
|
import { underLock, commit } from './lock.mjs';
|
|
28
|
-
import { clock, die, dur, ms, now, say, sleep, fakeFull } from './util.mjs';
|
|
38
|
+
import { clock, die, dur, ms, now, say, sleep, fakeFull, SCHEMA } from './util.mjs';
|
|
29
39
|
import { bold, dim, amber, wrap } from './style.mjs';
|
|
40
|
+
import { readJSON } from './durable.mjs';
|
|
41
|
+
|
|
42
|
+
// Exit code for an answer turned away because only a person's word counts (as dibs secret's refusals).
|
|
43
|
+
const REFUSED = 78;
|
|
30
44
|
|
|
31
45
|
const FILE = path.join(HOME, 'questions.json');
|
|
32
46
|
const LOCK = path.join(HOME, 'questions.lock');
|
|
@@ -61,7 +75,7 @@ function locked(fn) {
|
|
|
61
75
|
// Writes are renames, so reading without the lock always sees a whole file.
|
|
62
76
|
function load() {
|
|
63
77
|
let s = {};
|
|
64
|
-
try { s =
|
|
78
|
+
try { s = readJSON(FILE); } catch (e) {
|
|
65
79
|
if (e.code !== 'ENOENT') say(`${FILE} was unreadable (${e.message}); starting with no questions.`);
|
|
66
80
|
}
|
|
67
81
|
s.seq ||= 0; s.questions ||= [];
|
|
@@ -73,14 +87,20 @@ function load() {
|
|
|
73
87
|
// up at its limit keeps the question open KEEP_PLACE for the same command to
|
|
74
88
|
// pick back up, as a waiter's place in line does. One asked without --wait
|
|
75
89
|
// belongs to the agent session that asked, and lasts until --timeout if it says.
|
|
90
|
+
// Agents that asked the same thing since (askers) keep it open while any of them is still there.
|
|
76
91
|
function reap(s, t = now()) {
|
|
77
92
|
const open = s.questions.filter(q => q.state === OPEN);
|
|
78
|
-
const alive = makeAlive(open.flatMap(q => [q.pid, q.spid]).filter(Boolean));
|
|
93
|
+
const alive = makeAlive(open.flatMap(q => [q.pid, q.spid, ...(q.askers || []).flatMap(a => [a.pid, a.spid])]).filter(Boolean));
|
|
79
94
|
for (const q of open) {
|
|
80
95
|
if (q.pid && !alive(q.pid, q.pstart)) q.pid = null;
|
|
96
|
+
if (q.askers) {
|
|
97
|
+
for (const a of q.askers) if (a.pid && !alive(a.pid, a.pstart)) a.pid = null;
|
|
98
|
+
q.askers = q.askers.filter(a => a.pid || (a.keepUntil && t < a.keepUntil) || (a.spid ? alive(a.spid, a.sstart) : !a.waits));
|
|
99
|
+
if (!q.askers.length) delete q.askers;
|
|
100
|
+
}
|
|
81
101
|
const gone = q.waits ? !q.pid && !(q.keepUntil && t < q.keepUntil)
|
|
82
102
|
: (q.spid && !alive(q.spid, q.sstart)) || (!q.pid && q.due && t >= q.due);
|
|
83
|
-
if (gone) Object.assign(q, { state: 'expired', answeredAt: t });
|
|
103
|
+
if (gone && !q.askers) Object.assign(q, { state: 'expired', answeredAt: t });
|
|
84
104
|
}
|
|
85
105
|
const done = s.questions.filter(q => q.state !== OPEN && t - (q.answeredAt || q.asked) < DONE_FOR).slice(-KEEP_DONE);
|
|
86
106
|
s.questions = s.questions.filter(q => q.state === OPEN || done.includes(q));
|
|
@@ -112,27 +132,64 @@ export function offHours(cfg, t = now()) {
|
|
|
112
132
|
const a = minutes(h.start), b = minutes(h.end);
|
|
113
133
|
return a <= b ? at < a || at >= b : at < a && at >= b;
|
|
114
134
|
}
|
|
115
|
-
|
|
135
|
+
// A question for one person waits for that person's hours, when they set their own.
|
|
136
|
+
const held = (q, cfg, t) => q.state === OPEN && q.prio !== 'urgent' && offHours(q.for ? hoursCfg(cfg, q.for) : cfg, t);
|
|
116
137
|
|
|
117
138
|
// The same idea as the queue's rank: arrival time, moved by priority.
|
|
118
139
|
const rank = q => q.asked - (PRIORITY_SHIFT[q.prio] || 0);
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
140
|
+
// An agent is stopped on it: its asker, or an agent that asked the same since, waits for the answer.
|
|
141
|
+
const blocking = q => !!q.pid || !!q.askers?.some(a => a.pid);
|
|
142
|
+
// How pressing a question is, most first: an agent stopped on it, then a door only the person may go
|
|
143
|
+
// through (it can't be undone, or only they can do it), then the rest. The person's attention is
|
|
144
|
+
// the scarcest thing here, so what holds up running work comes before what can wait.
|
|
145
|
+
export function urgency(q) {
|
|
146
|
+
if (blocking(q) && q.oneWay) return { tier: 0, why: 'an agent is stopped until you answer' };
|
|
147
|
+
if (q.needsYou) return { tier: 1, why: 'only you can do it' };
|
|
148
|
+
if (q.cantUndo || q.oneWay) return { tier: 1, why: "it can't be undone" };
|
|
149
|
+
return { tier: 2, why: 'nothing waits on it' };
|
|
150
|
+
}
|
|
151
|
+
// Open ones first, the ones for now before the held ones, the most pressing first (urgency, then
|
|
152
|
+
// rank), each project's together where the first of them falls; then the closed ones newest first.
|
|
153
|
+
// me: with two or more people, the person looking, whose questions come before everyone else's.
|
|
154
|
+
function ordered(list, cfg, t, me = null) {
|
|
155
|
+
const others = q => (me && q.for && q.for !== me ? 1 : 0);
|
|
156
|
+
const band = q => others(q) * 2 + held(q, cfg, t);
|
|
157
|
+
const open = list.filter(q => q.state === OPEN).sort((a, b) => band(a) - band(b) || urgency(a).tier - urgency(b).tier || rank(a) - rank(b) || a.id - b.id);
|
|
158
|
+
const grouped = [];
|
|
159
|
+
for (const q of open) if (!grouped.includes(q)) grouped.push(...open.filter(x => band(x) === band(q) && (x.project || null) === (q.project || null) && !grouped.includes(x)));
|
|
122
160
|
const closed = list.filter(q => q.state !== OPEN).sort((a, b) => (b.answeredAt || 0) - (a.answeredAt || 0));
|
|
123
|
-
return [...
|
|
161
|
+
return [...grouped, ...closed];
|
|
124
162
|
}
|
|
125
163
|
|
|
126
164
|
// What the app and `dibs questions --json` see: no pids, and held as a flag.
|
|
127
165
|
const shown = (q, cfg, t) => ({
|
|
128
166
|
id: q.id, who: q.who, agent: q.agent, session: q.session, text: q.text, options: q.options, prio: q.prio, purpose: q.purpose,
|
|
129
|
-
asked: q.asked, due: q.due, state: q.state, answer: q.answer, answeredAt: q.answeredAt, answeredBy: q.answeredBy, waiting:
|
|
130
|
-
|
|
167
|
+
asked: q.asked, due: q.due, state: q.state, answer: q.answer, answeredAt: q.answeredAt, answeredBy: q.answeredBy, waiting: blocking(q), held: held(q, cfg, t),
|
|
168
|
+
// Which project it's about, the other agents that asked the same thing (folded in, not asked again), and why it ranks where it does.
|
|
169
|
+
project: q.project ? place(q.project) : null, askers: (q.askers || []).map(a => ({ who: a.who, agent: a.agent, waiting: !!a.pid, ...(a.text && { text: a.text }) })),
|
|
170
|
+
...(q.state === OPEN && { rank: urgency(q) }),
|
|
171
|
+
recommend: q.recommend ?? null, why: q.purpose || null, oneWay: !!q.oneWay, cantUndo: q.cantUndo ?? null, needsYou: q.needsYou ?? null, freeText: !!q.freeText,
|
|
172
|
+
about: q.about ?? null, rule: q.rule ?? null, ruleSays: q.ruleSays ?? null, ruleBy: q.ruleBy ?? null, ruleClash: q.ruleClash ?? null,
|
|
173
|
+
// Only with two or more people: who it's for, whether only they may answer, and who did.
|
|
174
|
+
...(q.owner && { owner: q.owner }), ...(q.for && { for: q.for, onlyFor: !!q.onlyFor }), ...(q.answeredPerson != null && { answeredPerson: q.answeredPerson }),
|
|
175
|
+
...(q.personOnly && { personOnly: true }),
|
|
131
176
|
});
|
|
132
177
|
|
|
133
178
|
// What `dibs questions --json` prints. dibs web reads it without the lock, as forYou does.
|
|
134
|
-
|
|
135
|
-
|
|
179
|
+
// me: the person looking (two or more people), whose questions come first.
|
|
180
|
+
// groups: the open questions by project, in the order they come, so a screen can head each project's.
|
|
181
|
+
export function questionsJson(cfg, t = now(), list = null, me = null) {
|
|
182
|
+
list ??= ordered(asked(t).map(q => ({ ...q })), cfg, t, me);
|
|
183
|
+
return { schema: SCHEMA, questions: list.map(q => shown(q, cfg, t)), hours: hours(cfg), open: list.filter(q => q.state === OPEN).length, groups: groupsOf(list) };
|
|
184
|
+
}
|
|
185
|
+
function groupsOf(list) {
|
|
186
|
+
const out = [];
|
|
187
|
+
for (const q of list.filter(x => x.state === OPEN)) {
|
|
188
|
+
const project = q.project ? place(q.project) : null;
|
|
189
|
+
const g = out.find(x => x.project === project) || (out.push({ project, ids: [] }), out.at(-1));
|
|
190
|
+
g.ids.push(q.id);
|
|
191
|
+
}
|
|
192
|
+
return out;
|
|
136
193
|
}
|
|
137
194
|
|
|
138
195
|
// For the board: open questions the person should look at now. Read without
|
|
@@ -148,7 +205,7 @@ export function asked(t = now()) {
|
|
|
148
205
|
return s.questions;
|
|
149
206
|
}
|
|
150
207
|
|
|
151
|
-
function parseAsk(args) {
|
|
208
|
+
export function parseAsk(args) {
|
|
152
209
|
const o = { words: [] };
|
|
153
210
|
for (let i = 0; i < args.length; i++) {
|
|
154
211
|
const a = args[i], next = () => args[++i] ?? die(`${a} needs a value`);
|
|
@@ -157,9 +214,13 @@ function parseAsk(args) {
|
|
|
157
214
|
else if (a === '-m' || a === '--msg') o.purpose = next();
|
|
158
215
|
else if (a === '--recommend') o.recommend = next().trim();
|
|
159
216
|
else if (a === '--one-way') o.oneWay = next().trim();
|
|
217
|
+
else if (a === '--needs-you') o.needsYou = next().trim();
|
|
160
218
|
else if (a === '--timeout') o.timeout = ms(next());
|
|
161
219
|
else if (a === '--wait') o.wait = true;
|
|
220
|
+
else if (a === '--again') o.again = true;
|
|
162
221
|
else if (a === '--as') o.as = next();
|
|
222
|
+
else if (a === '--about') { o.about = next().trim().toLowerCase(); if (!ABOUT.test(o.about)) die(`--about is the kind of question, in lowercase letters, digits and dashes (testflight, deploy, simulators), not "${o.about}". Nothing was asked.`); }
|
|
223
|
+
else if (a === '--for') o.for = next();
|
|
163
224
|
else if (a.startsWith('-') && a.length > 1) die(`unknown flag ${a}. Every flag: dibs help all`);
|
|
164
225
|
else o.words.push(a);
|
|
165
226
|
}
|
|
@@ -184,25 +245,65 @@ function junk(o) {
|
|
|
184
245
|
if (seen.size !== o.options.length) return `--options has the same choice twice (${o.options.join(', ')}). Nothing was asked.`;
|
|
185
246
|
if (!seen.has(o.recommend.toLowerCase())) return `--recommend ${o.recommend} isn't one of the --options (${o.options.join(', ')}). Nothing was asked.`;
|
|
186
247
|
}
|
|
248
|
+
if (o.needsYou != null && !realWords(o.needsYou)) return `--needs-you says what only the person can do, in a short sentence ("sign in to GitHub in the bison tab"), not "${o.needsYou}". Nothing was asked.`;
|
|
249
|
+
if (o.oneWay != null && o.needsYou != null) return 'a question is --one-way or --needs-you, not both. Nothing was asked.';
|
|
187
250
|
if (o.oneWay != null && !realWords(o.oneWay)) return `--one-way says what can't be undone, in a short sentence ("deleting the branch loses 3 unmerged commits"), not "${o.oneWay}". Nothing was asked.`;
|
|
251
|
+
if (o.for != null && o.oneWay == null && o.needsYou == null) return `--for ${o.for} names who must answer, and only a --one-way or --needs-you question reaches anyone. Nothing was asked.`;
|
|
188
252
|
return null;
|
|
189
253
|
}
|
|
190
254
|
|
|
191
|
-
// dibs question "text" --recommend <option> -m why [--one-way "what can't be undone"] [--options a,b] [-p prio] [--wait] [--timeout 2h]
|
|
192
|
-
|
|
255
|
+
// dibs question "text" --recommend <option> -m why [--one-way "what can't be undone" | --needs-you "what only the person can do"] [--options a,b] [-p prio] [--wait] [--timeout 2h]
|
|
256
|
+
// Returns the answer, when there is one. print: false keeps stdout for the caller (dibs spend check).
|
|
257
|
+
// personOnly: only the person's answer counts (spending past a cap): an agent's dibs answer is
|
|
258
|
+
// turned away and the asker keeps waiting.
|
|
259
|
+
export async function question(args, cfg, { print = true, personOnly = false } = {}) {
|
|
260
|
+
const out = x => { if (print) console.log(x); };
|
|
193
261
|
const o = parseAsk(args);
|
|
262
|
+
// With dibs doors on, a question about a kind of door (deploy, testflight, ...) can't be undone whatever the
|
|
263
|
+
// asker says, and only the person's answer counts: their yes is what lets the command through (src/doors.mjs).
|
|
264
|
+
const door = o.needsYou == null ? doorOf(cfg, o.about) : null;
|
|
265
|
+
if (door) { o.oneWay ??= KINDS[door].cant; personOnly = true; }
|
|
194
266
|
const bad = junk(o);
|
|
195
267
|
if (bad) die(bad);
|
|
196
268
|
if (o.options) o.recommend = o.options.find(x => x.toLowerCase() === o.recommend.toLowerCase());
|
|
269
|
+
// Who it's for: the person --for names (only they may answer), else, with two or more people, the asker's owner.
|
|
270
|
+
const people = readPeople();
|
|
271
|
+
if (o.for != null && !find(people, o.for)) die(`nobody called ${o.for} here. ${Object.keys(people).length ? `People: ${Object.keys(people).join(', ')}.` : 'Nobody is named on this machine (dibs people).'} Nothing was asked.`);
|
|
272
|
+
const owner = several(people) ? ownerOf({ p: people })?.name || null : null;
|
|
273
|
+
const forWho = o.for != null ? find(people, o.for) : owner;
|
|
197
274
|
const id = identity(o);
|
|
275
|
+
// Only the person's yes counts for a personOnly question (spending past a cap): no past decision
|
|
276
|
+
// or standing rule answers it.
|
|
277
|
+
if (!o.again && !personOnly && cited(o, id, owner)) return;
|
|
278
|
+
// Asked anyway (--again): its answer replaces the decision that would have been cited, which is revoked then.
|
|
279
|
+
const supersedes = o.again && !personOnly ? pastDecision(o, id, owner)?.id ?? null : null;
|
|
280
|
+
// The person's standing rules, read before the lock: a rule that covers this question answers it.
|
|
281
|
+
// Not a --for question: only the person it names may answer that one.
|
|
282
|
+
const ruled = o.for != null || personOnly ? {} : ruleFor({ ...o, cantUndo: o.oneWay });
|
|
283
|
+
const byRule = ruled.rule && { state: DECIDED, answer: ruled.answer, rule: ruled.rule.id, ruleSays: describeRule(ruled.rule), ruleBy: ruled.rule.by,
|
|
284
|
+
...(ruled.rule.byAgent && { ruleByAgent: true }), decidedBy: `rule ${ruled.rule.id}`, collected: true };
|
|
198
285
|
const limit = o.wait ? o.timeout ?? defaultMaxWait() : o.timeout ?? Infinity;
|
|
199
286
|
const t = now();
|
|
200
287
|
const due = limit === Infinity ? null : t + limit;
|
|
201
288
|
// The same question from the same asker, still open or with an answer it
|
|
202
289
|
// hasn't read, is that one again: asking without --wait and later with it
|
|
203
290
|
// collects the answer, and a wait that gave up picks its question back up.
|
|
291
|
+
// folded: another agent asked the same thing first and it's still open, so this asker joins that
|
|
292
|
+
// question instead of putting a second card in front of the person.
|
|
293
|
+
let folded = null;
|
|
294
|
+
const project = projectHere();
|
|
204
295
|
const q = locked(s => {
|
|
205
|
-
let q = s.questions.find(x => x
|
|
296
|
+
let q = s.questions.find(x => { const w = askedBy(x, id, o.text); return w && (!door || x.door === door) && (x.state === OPEN || x.state === DECIDED || (!w.collected && x.state !== 'expired')); });
|
|
297
|
+
const twin = !q && !byRule && !personOnly && (o.oneWay != null || o.needsYou != null) && sameAsOpen(s, o, project, forWho);
|
|
298
|
+
if (twin) {
|
|
299
|
+
const by = process.env.CLAUDE_CODE_SESSION_ID ? takeAgent('question', [], talkKey('question', args)) : null;
|
|
300
|
+
twin.askers = [...(twin.askers || []).filter(a => !isMine(a, id)), { who: id.who, agent: id.agent, label: id.label || by?.agentType || '',
|
|
301
|
+
session: process.env.CLAUDE_CODE_SESSION_ID || null, agentId: by?.agentId || null, spid: id.spid, sstart: id.sstart, asked: t,
|
|
302
|
+
waits: !!o.wait, ...(o.text !== twin.text && { text: o.text }) }];
|
|
303
|
+
// The more pressing of the two asks decides where it sits in the person's list.
|
|
304
|
+
if (o.prio && (PRIORITY_SHIFT[o.prio] || 0) > (PRIORITY_SHIFT[twin.prio] || 0)) twin.prio = o.prio;
|
|
305
|
+
q = folded = twin;
|
|
306
|
+
}
|
|
206
307
|
if (!q) {
|
|
207
308
|
// Which of the session's agents asked, when the guard saw it, so the question lands in that agent's thread.
|
|
208
309
|
const by = process.env.CLAUDE_CODE_SESSION_ID ? takeAgent('question', [], talkKey('question', args)) : null;
|
|
@@ -210,60 +311,144 @@ export async function question(args, cfg) {
|
|
|
210
311
|
agentId: by?.agentId || null,
|
|
211
312
|
spid: id.spid, sstart: id.sstart, text: o.text, options: o.options || null, prio: o.prio || 'normal', purpose: o.purpose || '',
|
|
212
313
|
asked: t, due, state: OPEN, answer: null, answeredAt: null, waits: !!o.wait, recommend: o.recommend,
|
|
213
|
-
oneWay: o.oneWay != null, cantUndo: o.oneWay ?? null }
|
|
314
|
+
oneWay: o.oneWay != null || o.needsYou != null, cantUndo: o.oneWay ?? null, ...(o.needsYou != null && { needsYou: o.needsYou }),
|
|
315
|
+
...(o.about && { about: o.about }), ...(ruled.clash && { ruleClash: ruled.clash.map(r => r.id) }),
|
|
316
|
+
...(owner && { owner }), ...(forWho && { for: forWho }), ...(o.for != null && { onlyFor: true }),
|
|
317
|
+
...(personOnly && { personOnly: true }), ...(door && { door }), ...(supersedes && { supersedes }) };
|
|
318
|
+
q.project = projectHere();
|
|
319
|
+
// A rule covers it: nobody is asked, and the rule's answer is the answer, now.
|
|
320
|
+
if (byRule) Object.assign(q, byRule, { answeredAt: t });
|
|
214
321
|
// A two-way door: nobody is asked. The recommendation is the answer, now.
|
|
215
|
-
if (!q.oneWay) Object.assign(q, { state: DECIDED, answer: o.recommend, answeredAt: t, decidedBy: id.agent || id.who, collected: true });
|
|
322
|
+
else if (!q.oneWay) Object.assign(q, { state: DECIDED, answer: o.recommend, answeredAt: t, decidedBy: id.agent || id.who, collected: true });
|
|
216
323
|
s.questions.push(q);
|
|
217
|
-
} else if (q.state === OPEN) {
|
|
324
|
+
} else if (q.state === OPEN && byRule) {
|
|
325
|
+
// A rule the person set after it was asked answers it when its agent comes back for it.
|
|
326
|
+
Object.assign(q, byRule, { answeredAt: t, pid: null });
|
|
327
|
+
} else if (q.state === OPEN && !folded && isMine(q, id)) {
|
|
218
328
|
if (o.prio) q.prio = o.prio;
|
|
219
329
|
if (o.options) q.options = o.options;
|
|
220
330
|
if (o.purpose) q.purpose = o.purpose;
|
|
331
|
+
if (o.for != null) Object.assign(q, { for: forWho, onlyFor: true });
|
|
221
332
|
// A session's question keeps its own --timeout; a later wait's limit is only the wait's.
|
|
222
333
|
// (It once took the wait's --timeout as its own, so asking, then collecting with --wait
|
|
223
334
|
// --timeout 1m, expired the question the moment that wait gave up.)
|
|
224
335
|
if ((!o.wait && o.timeout != null) || (o.wait && q.waits)) q.due = due;
|
|
225
336
|
}
|
|
226
|
-
if (o.wait && q.state === OPEN) Object.assign(q, { pid: process.pid, pstart: pstart(process.pid), keepUntil: null });
|
|
337
|
+
if (o.wait && q.state === OPEN) Object.assign(whose(q, id), { pid: process.pid, pstart: pstart(process.pid), keepUntil: null });
|
|
227
338
|
return { ...q };
|
|
228
339
|
});
|
|
340
|
+
if (folded) say(`${tag(folded)} already asked this (question ${folded.id}: "${folded.text}"), and it's still open, so you're added to it rather than asking the person twice. Its answer reaches you too.`);
|
|
341
|
+
if (q.state === DECIDED && q.rule) {
|
|
342
|
+
if (q.answeredAt === t) {
|
|
343
|
+
event({ kind: 'override', act: 'decided', question: q.id, who: tag(q), answer: q.answer, rule: q.rule, says: q.ruleSays, by: `rule ${q.rule} (set by ${q.ruleBy})`, byAgent: !!q.ruleByAgent });
|
|
344
|
+
noteHit(q.rule, q.id, t);
|
|
345
|
+
}
|
|
346
|
+
say(`answered by ${q.ruleByAgent ? 'standing rule' : "the person's standing rule"} ${q.rule} (${q.ruleSays}), set by ${q.ruleBy}${q.ruleByAgent ? ', an agent, not the person' : ''}: nobody was asked. Go ahead with ${q.answer}.`
|
|
347
|
+
+ ` It's logged, and the person sees which rule answered.`);
|
|
348
|
+
out(q.answer);
|
|
349
|
+
return q.answer;
|
|
350
|
+
}
|
|
351
|
+
if (ruled.clash && q.asked === t) say(`rules ${ruled.clash.map(r => `${r.id} (${r.answer})`).join(' and ')} both cover this question and disagree, so neither answered it. It goes the usual way.`);
|
|
229
352
|
if (q.state === DECIDED) {
|
|
353
|
+
if (q.asked === t) rememberQuestion(q);
|
|
230
354
|
if (q.asked === t) event({ kind: 'override', act: 'decided', question: q.id, who: tag(q), answer: q.answer, why: q.purpose, by: q.decidedBy, byAgent: true });
|
|
231
355
|
say(`decided by ${q.decidedBy}: two-way door, so nobody was asked. Go ahead with ${q.answer}. It's logged, and the person sees it as done; they'll message you if they want it otherwise.`
|
|
232
356
|
+ ' Bring a question to the person only when it can\'t be undone: --one-way "what can\'t be undone".');
|
|
233
|
-
|
|
234
|
-
return;
|
|
357
|
+
out(q.answer);
|
|
358
|
+
return q.answer;
|
|
235
359
|
}
|
|
236
360
|
if (!o.wait) {
|
|
237
|
-
|
|
361
|
+
out(q.id);
|
|
238
362
|
if (q.state === OPEN)
|
|
239
|
-
say(`question ${q.id} is queued for
|
|
363
|
+
say(`question ${q.id} is queued for ${forName(q)}${heldNote(q, cfg)}. Keep working; to get the answer, run the same command with --wait.`);
|
|
240
364
|
else say(`question ${q.id} was already ${q.state}${q.answer != null ? `: ${q.answer}` : ''}. Run the same command with --wait to read the answer.`);
|
|
241
365
|
return;
|
|
242
366
|
}
|
|
243
|
-
say(`waiting for
|
|
367
|
+
say(`waiting for ${forName(q)} to answer question ${q.id}${heldNote(q, cfg)}. ${waitTerms(o, limit, t)}`);
|
|
244
368
|
for (;;) {
|
|
245
369
|
const cur = load().questions.find(x => x.id === q.id);
|
|
246
|
-
if (cur?.state === 'answered') {
|
|
247
|
-
locked(s => { const x = s.questions.find(x => x.id === q.id); if (x) x.collected = true; });
|
|
370
|
+
if (cur?.state === 'answered' || cur?.rule) {
|
|
371
|
+
locked(s => { const x = s.questions.find(x => x.id === q.id); if (x) whose(x, id).collected = true; });
|
|
248
372
|
// stdout stays the bare answer; who gave it goes beside it.
|
|
249
|
-
if (cur.answeredBy) say(`answered by ${cur.answeredBy}, an agent, not the person.`);
|
|
250
|
-
|
|
251
|
-
|
|
373
|
+
if (cur.answeredBy) say(`answered by ${cur.answeredBy}, an agent, not ${cur.for || 'the person'}.`);
|
|
374
|
+
else if (cur.answeredPerson != null && cur.answeredPerson !== cur.for) say(`answered by ${cur.answeredPerson || 'a person here dibs couldn\'t name'}${cur.for ? `, not ${cur.for}, who it was for` : ''}.`);
|
|
375
|
+
if (cur.rule) say(`answered by ${cur.ruleByAgent ? 'standing rule' : "the person's standing rule"} ${cur.rule} (${cur.ruleSays}), set by ${cur.ruleBy}${cur.ruleByAgent ? ', an agent, not the person' : ''}.`);
|
|
376
|
+
const unsigned = !cur.answeredBy && !cur.rule && signedAnswer(cur);
|
|
377
|
+
if (unsigned) say(unsigned);
|
|
378
|
+
out(cur.answer);
|
|
379
|
+
return cur.answer;
|
|
252
380
|
}
|
|
253
381
|
if (!cur || cur.state !== OPEN) {
|
|
254
|
-
locked(s => { const x = s.questions.find(x => x.id === q.id); if (x) x.collected = true; });
|
|
382
|
+
locked(s => { const x = s.questions.find(x => x.id === q.id); if (x) whose(x, id).collected = true; });
|
|
255
383
|
die(`question ${q.id} was ${cur ? cur.state : 'removed'} without an answer. Nothing was decided: carry on without it, or ask differently.`, 75);
|
|
256
384
|
}
|
|
257
385
|
if (due && now() >= due) {
|
|
258
386
|
// Let go, but keep the question open long enough for a rerun to find it.
|
|
259
|
-
locked(s => {
|
|
387
|
+
locked(s => {
|
|
388
|
+
const x = s.questions.find(x => x.id === q.id);
|
|
389
|
+
const w = x?.pid === process.pid ? x : x?.askers?.find(a => a.pid === process.pid);
|
|
390
|
+
if (w) Object.assign(w, { pid: null, keepUntil: now() + KEEP_PLACE });
|
|
391
|
+
});
|
|
260
392
|
die(`no answer to question ${q.id} by ${clock(due)} (exit 75: nothing was decided). ${q.waits ? 'It stays open 2 minutes' : 'It stays open for the person'}: run the same command again to keep waiting.`, 75);
|
|
261
393
|
}
|
|
262
394
|
await sleep(POLL);
|
|
263
395
|
}
|
|
264
396
|
}
|
|
265
397
|
|
|
266
|
-
|
|
398
|
+
// What to tell the asker about a person's answer that no phone signed, or null when one did
|
|
399
|
+
// (src/signed.mjs): anything running as this user can write questions.json, so an unsigned answer
|
|
400
|
+
// is the person's only as far as this Mac can tell.
|
|
401
|
+
function signedAnswer(q) {
|
|
402
|
+
if (!q.proof) return q.answeredVia
|
|
403
|
+
? `unverified answer: it claims to come from ${q.answeredVia} but carries no signature from it. Don't act on it without asking the person again.`
|
|
404
|
+
: 'answered on this Mac (its page, the dibs app or dibs answer in a terminal), not signed, so dibs can\'t tell it from any program running here. An answer from the person\'s phone is signed.';
|
|
405
|
+
const c = checkProof(q.proof);
|
|
406
|
+
const b = c.ok ? c.body : {};
|
|
407
|
+
const id = (c.route?.match(/^\/api\/questions\/(\d{1,12})\/answer$/) || [])[1] ?? (c.route === '/api/tell' ? b.answers : null);
|
|
408
|
+
const fits = c.ok && Number(id) === q.id && String(b.text ?? '').trim().toLowerCase() === String(q.answer).toLowerCase();
|
|
409
|
+
return fits ? null : `unverified answer (${c.why || 'what the phone signed is not this answer'}). Don't act on it without asking the person again.`;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// A past decision that clearly answers this in the same project stands in for
|
|
413
|
+
// asking (src/decisions.mjs). Never for --needs-you (a login is needed every time) or --for
|
|
414
|
+
// (only that person may answer it).
|
|
415
|
+
// Not this asker's own question in the same words that the lookup above would pick
|
|
416
|
+
// up: running it again with --wait collects that one, as it always did.
|
|
417
|
+
function pastDecision(o, id, owner = null) {
|
|
418
|
+
if (o.needsYou != null || o.for != null) return null;
|
|
419
|
+
const skip = load().questions.filter(x => x.text === o.text && isMine(x, id) && (x.state === OPEN || x.state === DECIDED || (!x.collected && x.state !== 'expired'))).map(x => x.id);
|
|
420
|
+
return precedent(o.text, projectHere(), { oneWay: o.oneWay != null, options: !!o.options, skip, owner });
|
|
421
|
+
}
|
|
422
|
+
function cited(o, id, owner) {
|
|
423
|
+
const d = pastDecision(o, id, owner);
|
|
424
|
+
if (!d) return false;
|
|
425
|
+
say(`${cite(d)}. Nobody was asked; act on that. If things have changed since, ask anyway: the same command plus --again.`);
|
|
426
|
+
console.log(verdict(d));
|
|
427
|
+
return true;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// Where the caller asked x in these words: x itself (its first asker), the caller's entry among
|
|
431
|
+
// the agents folded into it since, or null.
|
|
432
|
+
const askedBy = (x, id, text) => (x.text === text && isMine(x, id) ? x : x.askers?.find(a => isMine(a, id) && (a.text ?? x.text) === text) || null);
|
|
433
|
+
// The caller's own record in x: x when it asked first, else its entry among the askers.
|
|
434
|
+
const whose = (x, id) => (isMine(x, id) ? x : x.askers?.find(a => isMine(a, id)) || x);
|
|
435
|
+
|
|
436
|
+
// An open question this one repeats: the same project, for the same person, the same kind of door
|
|
437
|
+
// (a --needs-you is never folded into a --one-way), and the same words or close to them (most words
|
|
438
|
+
// shared, the same numbers, both or neither turned around by a "not": src/decisions.mjs same).
|
|
439
|
+
// Questions that only share an --about are related, not repeats: "deploy web?" isn't "deploy api?".
|
|
440
|
+
// They sit together in the person's list instead (ordered()).
|
|
441
|
+
function sameAsOpen(s, o, project, forWho) {
|
|
442
|
+
return s.questions.find(x => x.state === OPEN && !x.personOnly && (x.project || null) === (project || null) && (x.for || null) === (forWho || null)
|
|
443
|
+
&& x.oneWay && (x.needsYou != null) === (o.needsYou != null) && (x.text === o.text || sameWords(o.text, x.text))) || null;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const forName = q => (q.for ? `${q.for}${q.onlyFor ? ' (only they may answer it)' : ''}` : 'the person');
|
|
447
|
+
const heldNote = (q, cfg) => {
|
|
448
|
+
if (!held(q, cfg, now())) return '';
|
|
449
|
+
const h = hours(q.for ? hoursCfg(cfg, q.for) : cfg);
|
|
450
|
+
return ` (it's outside ${q.for ? `${q.for}'s` : "the person's"} hours, ${h.start} to ${h.end}, so it waits for ${h.start} unless it's urgent)`;
|
|
451
|
+
};
|
|
267
452
|
|
|
268
453
|
function waitTerms(o, limit, t) {
|
|
269
454
|
if (limit === Infinity)
|
|
@@ -280,18 +465,28 @@ export function questions(args, cfg) {
|
|
|
280
465
|
const bad = args.find(a => a !== '--json');
|
|
281
466
|
if (bad) die(`unknown ${bad.startsWith('-') ? 'flag' : 'word'} ${bad}. Try: dibs questions [--json], dibs questions dismiss <id>`);
|
|
282
467
|
const t = now();
|
|
283
|
-
const
|
|
468
|
+
const me = actor();
|
|
469
|
+
const list = ordered(locked(s => s.questions.map(q => ({ ...q }))), cfg, t, me.agent ? null : me.person);
|
|
284
470
|
if (json) return console.log(JSON.stringify(questionsJson(cfg, t, list), null, 1));
|
|
285
471
|
const open = list.filter(q => q.state === OPEN);
|
|
286
472
|
const later = open.filter(q => held(q, cfg, t)).length;
|
|
287
|
-
const out = [bold(open.length ? `${open.length} open question${open.length > 1 ? 's' : ''}${later ? ` (${later} held until ${cfg.hours.start})` : ''}, most
|
|
473
|
+
const out = [bold(open.length ? `${open.length} open question${open.length > 1 ? 's' : ''}${later ? ` (${later} held until ${cfg.hours ? cfg.hours.start : 'their person\'s hours start'})` : ''}, most pressing first, each project's together.` : 'No open questions.')];
|
|
474
|
+
// A project's heading once, where its first question falls, when there's more than one project.
|
|
475
|
+
const projects = new Set(open.map(q => q.project || null));
|
|
476
|
+
let heading;
|
|
288
477
|
for (const q of open) {
|
|
289
|
-
const
|
|
290
|
-
out.push('',
|
|
478
|
+
const p = q.project || null;
|
|
479
|
+
if (projects.size > 1 && p !== heading) out.push('', bold(p ? place(p) : 'No project'));
|
|
480
|
+
heading = p;
|
|
481
|
+
const flags = [q.prio !== 'normal' ? q.prio : '', blocking(q) ? 'an agent is waiting on it' : '', held(q, cfg, t) ? 'for tomorrow' : ''].filter(Boolean).join(', ');
|
|
482
|
+
const forWhom = q.for ? `, for ${q.for}${q.onlyFor ? ' only' : ''}` : '';
|
|
483
|
+
const also = q.askers?.length ? `, and ${q.askers.map(a => tag(a)).join(', ')} asked the same` : '';
|
|
484
|
+
out.push('', ` #${q.id} ${tag(q)} asked ${dur(t - q.asked)} ago${also}${forWhom}${flags ? amber(` [${flags}]`) : ''}`);
|
|
291
485
|
out.push(wrap(` ${q.text}${q.options ? ` (${q.options.join(' / ')})` : ''}`, ' '));
|
|
292
486
|
if (q.recommend) out.push(wrap(` They recommend ${q.recommend}${q.purpose ? `: ${q.purpose}` : ''}`, ' '));
|
|
293
487
|
else if (q.purpose) out.push(dim(wrap(` ${q.purpose}`, ' ')));
|
|
294
488
|
if (q.cantUndo) out.push(amber(wrap(` Can't be undone: ${q.cantUndo}`, ' ')));
|
|
489
|
+
if (q.ruleClash) out.push(dim(` Rules ${q.ruleClash.join(' and ')} cover it and disagree, so neither answered it.`));
|
|
295
490
|
}
|
|
296
491
|
if (open.length) {
|
|
297
492
|
const q = open[0];
|
|
@@ -300,7 +495,7 @@ export function questions(args, cfg) {
|
|
|
300
495
|
const closed = list.filter(q => q.state !== OPEN).slice(0, RECENT);
|
|
301
496
|
if (closed.length) out.push('', 'Recently closed');
|
|
302
497
|
for (const q of closed)
|
|
303
|
-
out.push(dim(` #${q.id} ${q.state}${q.answer != null ? ` "${q.answer}"` : ''} ${dur(t - q.answeredAt)} ago, ${tag(q)}: ${q.text}`));
|
|
498
|
+
out.push(dim(` #${q.id} ${q.rule ? `answered by rule ${q.rule}` : q.state}${q.answer != null ? ` "${q.answer}"` : ''} ${dur(t - q.answeredAt)} ago, ${tag(q)}: ${q.text}`));
|
|
304
499
|
console.log(out.join('\n'));
|
|
305
500
|
}
|
|
306
501
|
|
|
@@ -315,22 +510,36 @@ function close(idArg, verb, change) {
|
|
|
315
510
|
const q = s.questions.find(x => x.id === n);
|
|
316
511
|
if (!q) return { no: [`no question ${n}. See them: dibs questions`, 1] };
|
|
317
512
|
if (q.state !== OPEN) return { no: [`question ${n} is already ${q.state}${q.answer != null ? ` ("${q.answer}")` : ''}`, 1] };
|
|
513
|
+
// The asker said only this person may answer (--for): not another person, not someone dibs
|
|
514
|
+
// can't name, and not an agent. The one thing an agent can't do for a person (the owner, 2026-11-26).
|
|
515
|
+
if (q.onlyFor && (who.agent || who.person !== q.for)) {
|
|
516
|
+
const you = who.agent ? `You're an agent (${who.name}): ask ${q.for} to answer it.` : who.person ? `You're ${who.person}.`
|
|
517
|
+
: `dibs can't tell who you are: if you are ${q.for}, set DIBS_PERSON=${q.for} or dibs people set ${q.for} --user <your macOS user>.`;
|
|
518
|
+
return { no: [`question ${n} is for ${q.for}, and only ${q.for} may answer it (the agent asked with --for ${q.for}). ${you} Nothing was changed (exit 78: refused).`, REFUSED] };
|
|
519
|
+
}
|
|
520
|
+
// Agents may answer what the person can, except where only the person's word counts.
|
|
521
|
+
if (q.personOnly && who.agent && verb === 'answer')
|
|
522
|
+
return { no: [`only the person can answer question ${n} (${tag(q)} needs the person's own word: spending past a cap, a one-way environment, or a command that can't be undone). You're an agent (${who.name}), so nothing was answered and it stays open for them (exit 78: refused).`, REFUSED] };
|
|
318
523
|
const no = change(q);
|
|
319
524
|
if (no) return { no: [no, 2] };
|
|
320
525
|
q.answeredAt = now();
|
|
321
526
|
if (who.agent && q.state === 'answered') q.answeredBy = who.name;
|
|
527
|
+
if (who.via) q.answeredVia = who.via;
|
|
528
|
+
if (!who.agent && who.person != null) q.answeredPerson = who.person;
|
|
529
|
+
// The phone's signature on the answer, checked again when the asker reads it (signedAnswer).
|
|
530
|
+
if (!who.agent && who.proof && q.state === 'answered') q.proof = who.proof;
|
|
322
531
|
return { q: { ...q } };
|
|
323
532
|
});
|
|
324
533
|
if (r.no) die(...r.no);
|
|
325
534
|
// The history shows these decisions next to the other overrides, with who made them.
|
|
326
|
-
event({ kind: 'override', act: verb.split(' ').pop(), question: n, who: tag(r.q), answer: r.q.answer, by: who.name, byAgent: who.agent });
|
|
535
|
+
event({ kind: 'override', act: verb.split(' ').pop(), question: n, who: tag(r.q), answer: r.q.answer, by: who.name, byAgent: who.agent, ...(who.via && { via: who.via }) });
|
|
327
536
|
return r.q;
|
|
328
537
|
}
|
|
329
538
|
|
|
330
539
|
// dibs answer <id> <text>: one of its options, or any words. Words that pick
|
|
331
540
|
// no option are the answer too, and reach the asker as a message as well, so
|
|
332
541
|
// the person can reply in words instead of picking.
|
|
333
|
-
export function answer(args) {
|
|
542
|
+
export async function answer(args) {
|
|
334
543
|
const [idArg, ...rest] = args;
|
|
335
544
|
const text = rest.join(' ').trim();
|
|
336
545
|
if (!text) die('answer with what? dibs answer <id> <text>');
|
|
@@ -338,8 +547,16 @@ export function answer(args) {
|
|
|
338
547
|
const a = q.options?.find(x => x.toLowerCase() === text.toLowerCase());
|
|
339
548
|
Object.assign(q, { state: 'answered', answer: a ?? text, ...(a == null && { freeText: true }) });
|
|
340
549
|
});
|
|
341
|
-
|
|
342
|
-
|
|
550
|
+
rememberQuestion(q);
|
|
551
|
+
// Words always go to the asker as a message; a picked option too when nobody waits on it (2026-11-26:
|
|
552
|
+
// an agent that asked without --wait never heard the person's "yes", and guessed). The message
|
|
553
|
+
// names the question and the option, so it can't be taken for an answer to something else.
|
|
554
|
+
const told = q.freeText || !q.pid;
|
|
555
|
+
if (told) messageAsker(q, q.answer);
|
|
556
|
+
// Agents that asked the same thing since hear it the same way, in their own threads.
|
|
557
|
+
for (const a of q.askers || []) if (q.freeText || !a.pid) messageAsker({ ...q, who: a.who, label: a.label, session: a.session, agentId: a.agentId, spid: a.spid, sstart: a.sstart, owner: q.owner }, q.answer);
|
|
558
|
+
const opens = await yesFromAnswer(q);
|
|
559
|
+
console.log(`answered question ${q.id} for ${tag(q)}: ${q.answer}${told ? '. It reaches them as a message, with their next tool call.' : ''}${opens ? `${told ? '' : '.'} ${opens[0].toUpperCase()}${opens.slice(1)}.` : ''}`);
|
|
343
560
|
}
|
|
344
561
|
|
|
345
562
|
function dismiss(args) {
|
|
@@ -347,25 +564,51 @@ function dismiss(args) {
|
|
|
347
564
|
console.log(`dismissed question ${q.id} from ${tag(q)}`);
|
|
348
565
|
}
|
|
349
566
|
|
|
567
|
+
function setConfig(key, value) {
|
|
568
|
+
const c = JSON.parse(fs.readFileSync(paths.config, 'utf8'));
|
|
569
|
+
c[key] = value;
|
|
570
|
+
const tmp = `${paths.config}.${process.pid}`;
|
|
571
|
+
fs.writeFileSync(tmp, JSON.stringify(c, null, 2) + '\n');
|
|
572
|
+
fs.renameSync(tmp, paths.config);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// The attention budget: phone notifications an hour at most, or null for no cap.
|
|
576
|
+
export const attention = cfg => (cfg.attention == null ? null : cfg.attention);
|
|
577
|
+
|
|
578
|
+
// dibs attention [<n> | off] [--json]: show or set how many times an hour the person's phone may buzz.
|
|
579
|
+
export function attentionCmd(args, cfg) {
|
|
580
|
+
const json = args.includes('--json');
|
|
581
|
+
const word = args.find(a => a !== '--json');
|
|
582
|
+
if (args.filter(a => a !== '--json').length > 1 || (word && word !== 'off' && !/^\d{1,3}$/.test(word))) die('dibs attention takes how many notifications an hour (6, or 0 for urgent questions only), off, or --json');
|
|
583
|
+
if (word) {
|
|
584
|
+
const set = word === 'off' ? null : Number(word);
|
|
585
|
+
setConfig('attention', set);
|
|
586
|
+
logChange('attention', { attention: set, from: attention(cfg) });
|
|
587
|
+
cfg = loadConfig();
|
|
588
|
+
}
|
|
589
|
+
const n = attention(cfg);
|
|
590
|
+
if (json) return console.log(JSON.stringify({ perHour: n }));
|
|
591
|
+
console.log(n == null ? 'no cap: your phone hears of everything that reaches you, at most once every 30 seconds. Cap it: dibs attention 6'
|
|
592
|
+
: `your phone buzzes at most ${n} time${n === 1 ? '' : 's'} an hour. Past that, only urgent questions buzz; the rest wait for the next hour's batch, or the recap. Lift it: dibs attention off`);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// "09:00-23:00" -> { start, end }, "off" -> false, anything else -> null.
|
|
596
|
+
export function parseHours(word) {
|
|
597
|
+
if (word === 'off') return false;
|
|
598
|
+
const [start, end, extra] = String(word).split('-');
|
|
599
|
+
if (extra != null || readTime(start) == null || readTime(end) == null || readTime(start) === readTime(end)) return null;
|
|
600
|
+
return { start: start.padStart(5, '0'), end: end.padStart(5, '0') };
|
|
601
|
+
}
|
|
602
|
+
|
|
350
603
|
// dibs hours [09:00-23:00 | off] [--json]: show or set the person's working hours.
|
|
351
604
|
export function hoursCmd(args, cfg) {
|
|
352
605
|
const json = args.includes('--json');
|
|
353
606
|
const word = args.find(a => a !== '--json');
|
|
354
607
|
if (args.some(a => a.startsWith('-') && a !== '--json')) die('dibs hours takes 09:00-23:00, off, or --json');
|
|
355
608
|
if (word) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
if (extra != null || readTime(start) == null || readTime(end) == null || readTime(start) === readTime(end))
|
|
360
|
-
die(`can't read hours "${word}". Use: dibs hours 09:00-23:00 (an end before the start runs past midnight), or dibs hours off`);
|
|
361
|
-
set = { start: start.padStart(5, '0'), end: end.padStart(5, '0') };
|
|
362
|
-
}
|
|
363
|
-
const c = JSON.parse(fs.readFileSync(paths.config, 'utf8'));
|
|
364
|
-
c.hours = set;
|
|
365
|
-
const tmp = `${paths.config}.${process.pid}`;
|
|
366
|
-
fs.writeFileSync(tmp, JSON.stringify(c, null, 2) + '\n');
|
|
367
|
-
fs.renameSync(tmp, paths.config);
|
|
368
|
-
logChange('hours', { hours: set, from: cfg.hours || null });
|
|
609
|
+
const set = parseHours(word) ?? die(`can't read hours "${word}". Use: dibs hours 09:00-23:00 (an end before the start runs past midnight), or dibs hours off`);
|
|
610
|
+
setConfig('hours', set || null);
|
|
611
|
+
logChange('hours', { hours: set || null, from: cfg.hours || null });
|
|
369
612
|
cfg = loadConfig();
|
|
370
613
|
}
|
|
371
614
|
const h = hours(cfg);
|
|
@@ -373,3 +616,31 @@ export function hoursCmd(args, cfg) {
|
|
|
373
616
|
console.log(h ? `hours ${h.start} to ${h.end}: outside them, questions below urgent wait for ${h.start}. Clear: dibs hours off`
|
|
374
617
|
: 'no hours set: questions reach you any time. Set: dibs hours 09:00-23:00');
|
|
375
618
|
}
|
|
619
|
+
|
|
620
|
+
// dibs rules test "question" --about <kind> [--options a,b] [--one-way "..."] [--needs-you "..."] [--at 19:00]:
|
|
621
|
+
// would a rule answer this question, and if not, why each rule about its kind stepped aside.
|
|
622
|
+
// Exit 0 when one would, 1 when none would.
|
|
623
|
+
export function testRule(args) {
|
|
624
|
+
let at = now();
|
|
625
|
+
const i = args.indexOf('--at');
|
|
626
|
+
if (i >= 0) {
|
|
627
|
+
const v = args[i + 1];
|
|
628
|
+
const m = readTime(v ?? '');
|
|
629
|
+
if (m == null) die(`--at is a clock time like 19:00, not ${v ?? 'nothing'}`);
|
|
630
|
+
const d = new Date(); d.setHours(Math.floor(m / 60), m % 60, 0, 0);
|
|
631
|
+
at = d.getTime();
|
|
632
|
+
args = [...args.slice(0, i), ...args.slice(i + 2)];
|
|
633
|
+
}
|
|
634
|
+
const o = parseAsk(args);
|
|
635
|
+
if (!o.text) die('test what? dibs rules test "Upload build 12 to TestFlight?" --about testflight');
|
|
636
|
+
if (!o.about) die(`a rule answers only a question asked with --about: dibs rules test "${o.text}" --about <kind>`);
|
|
637
|
+
const r = ruleFor({ ...o, cantUndo: o.oneWay }, undefined, at);
|
|
638
|
+
const out = [];
|
|
639
|
+
if (r.rule) out.push(`${r.rule.id} would answer ${r.answer}: ${describeRule(r.rule)}.`);
|
|
640
|
+
else if (r.clash) out.push(`no rule would answer it: ${r.clash.map(x => `${x.id} (${x.answer})`).join(' and ')} both cover it and disagree.`);
|
|
641
|
+
else out.push(`no rule would answer it: ${r.none}.`);
|
|
642
|
+
for (const x of r.near) out.push(dim(` ${x.rule.id} (${describeRule(x.rule)}) steps aside: ${x.why}.`));
|
|
643
|
+
if (!r.rule) out.push(o.needsYou != null || o.oneWay != null ? 'Asked like this, it goes to the person.' : "Asked like this, it's a two-way door: the asker's --recommend decides it.");
|
|
644
|
+
console.log(out.join('\n'));
|
|
645
|
+
if (!r.rule) process.exitCode = 1;
|
|
646
|
+
}
|
package/src/quota.mjs
CHANGED
|
@@ -74,7 +74,7 @@ export function takeQuota(s, me, cfg, t = now()) {
|
|
|
74
74
|
|
|
75
75
|
// For the board: every configured bucket and what's left in it.
|
|
76
76
|
export function quotasNow(s, cfg, t = now()) {
|
|
77
|
-
return Object.keys(cfg.quotas || {}).map(name => {
|
|
77
|
+
return Object.keys(cfg.quotas || {}).filter(name => !cfg.quotas[name].quiet || s.quotas?.[name]).map(name => {
|
|
78
78
|
const q = bucketCfg(cfg, name);
|
|
79
79
|
return q.error ? { name, error: q.error } : { name, left: round(level(s.quotas?.[name], q, t)), limit: q.limit, per: q.per };
|
|
80
80
|
});
|