@dibssoftware/dibs 0.0.181 → 0.0.195
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +103 -1
- package/README.md +10 -8
- package/bin/dibs.mjs +370 -73
- package/docs/agents.md +303 -0
- package/docs/council.md +88 -0
- package/docs/files.md +3 -3
- package/docs/guard.md +86 -11
- package/docs/json.md +211 -0
- package/docs/later.md +5 -5
- package/docs/machines.md +6 -6
- package/docs/questions.md +104 -3
- package/docs/reference.md +124 -30
- package/docs/relay.md +120 -9
- package/docs/releasing.md +7 -1
- package/docs/scheduling.md +28 -6
- package/docs/secrets.md +53 -0
- package/docs/simulators.md +3 -3
- package/package.json +1 -1
- package/skills/dibs/SKILL.md +79 -149
- package/src/about.mjs +341 -0
- package/src/acquire.mjs +111 -27
- package/src/after.mjs +127 -0
- package/src/agents.mjs +2 -1
- package/src/alerts.mjs +95 -42
- package/src/answers.mjs +2 -2
- package/src/board.mjs +21 -16
- package/src/broker.mjs +23 -7
- package/src/carry.mjs +287 -0
- package/src/codex.mjs +132 -0
- package/src/commands.mjs +243 -82
- package/src/config.mjs +85 -14
- package/src/connect.mjs +4 -2
- package/src/cool.mjs +27 -11
- package/src/council.mjs +482 -0
- package/src/cwd.mjs +9 -0
- package/src/decisions.mjs +250 -0
- package/src/declare.mjs +96 -0
- package/src/diskreport.mjs +306 -0
- package/src/diskuse.mjs +420 -0
- package/src/diskwarn.mjs +68 -13
- package/src/doctor.mjs +149 -0
- package/src/doors.mjs +547 -0
- package/src/durable.mjs +143 -0
- package/src/envs.mjs +372 -0
- package/src/events.mjs +7 -2
- package/src/files.mjs +118 -6
- package/src/guard.mjs +239 -86
- package/src/guardd.mjs +8 -1
- package/src/halt.mjs +63 -0
- package/src/handoffs.mjs +362 -0
- package/src/history.mjs +34 -4
- package/src/hogs.mjs +36 -8
- package/src/jobprogress.mjs +283 -0
- package/src/later.mjs +21 -10
- package/src/lock.mjs +33 -9
- package/src/measure.mjs +42 -11
- package/src/media.mjs +240 -0
- package/src/news.mjs +31 -0
- package/src/notes.mjs +49 -8
- package/src/notices.mjs +126 -43
- package/src/ondemand.mjs +25 -2
- package/src/outcome.mjs +163 -0
- package/src/overlap.mjs +2 -2
- package/src/override.mjs +149 -79
- package/src/owner.mjs +15 -2
- package/src/people.mjs +236 -0
- package/src/pickup.mjs +72 -0
- package/src/picture.mjs +321 -0
- package/src/plain.mjs +84 -18
- package/src/platform.mjs +19 -0
- package/src/preempt.mjs +123 -15
- package/src/primer.mjs +91 -20
- package/src/prints.mjs +99 -0
- package/src/proc.mjs +1 -1
- package/src/progress.mjs +49 -3
- package/src/proof.mjs +102 -0
- package/src/push.mjs +271 -0
- package/src/questions.mjs +328 -57
- package/src/quota.mjs +1 -1
- package/src/recap.mjs +205 -0
- package/src/relay.mjs +139 -20
- package/src/remote.mjs +23 -10
- package/src/reviewgate.mjs +268 -0
- package/src/reviews.mjs +377 -0
- package/src/route.mjs +263 -0
- package/src/rules.mjs +216 -0
- package/src/schedule.mjs +238 -44
- package/src/schema.mjs +62 -0
- package/src/scratch.mjs +2 -2
- package/src/serve.mjs +3 -2
- package/src/signed.mjs +97 -0
- package/src/simpool.mjs +46 -1
- package/src/spend.mjs +375 -0
- package/src/state.mjs +43 -17
- package/src/talk.mjs +1078 -133
- package/src/thin.sh +2 -0
- package/src/trail.mjs +290 -0
- package/src/trailnote.mjs +209 -0
- package/src/util.mjs +7 -0
- package/src/vault.mjs +435 -0
- package/src/vendors.mjs +327 -0
- package/src/version.mjs +1 -1
- package/src/web.mjs +353 -60
- package/src/work.mjs +487 -0
- package/src/worker.mjs +7 -1
package/src/council.mjs
ADDED
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
// dibs council: one question put to several agents at once, each with its own
|
|
2
|
+
// voice (a named system prompt) on its own model, then combined so the places
|
|
3
|
+
// they disagree stay visible. Three methods (docs/council.md says when each pays):
|
|
4
|
+
// merge everyone answers blind, then one judge writes AGREED / SPLIT / ANSWER
|
|
5
|
+
// critique everyone answers blind, reads the others' answers, answers again; then the judge
|
|
6
|
+
// debate a thread in rounds: posts reply to posts and vote on them; then a judge
|
|
7
|
+
// Each call is a headless agent (claude -p, codex exec, opencode run, or any CLI
|
|
8
|
+
// council.json names) run through `dibs run quota:council`, so a loop of councils
|
|
9
|
+
// waits on the bucket instead of spending the account's limits, and every call is
|
|
10
|
+
// a dibs job: on the board, killed with its tree when the council is.
|
|
11
|
+
//
|
|
12
|
+
// --live <agent> also asks agent sessions already working here, with dibs tell.
|
|
13
|
+
// They answer with dibs council reply <id> "...". They take part in the first
|
|
14
|
+
// round only: asking a busy agent once already costs it its focus.
|
|
15
|
+
//
|
|
16
|
+
// Runs are kept in ~/.dibs/council/<id>.json, rewritten as the run goes, so
|
|
17
|
+
// dibs council show <id> works while one is still running. Only the council
|
|
18
|
+
// process writes it; live replies go in <id>.replies.jsonl, one appended line each.
|
|
19
|
+
import fs from 'node:fs';
|
|
20
|
+
import os from 'node:os';
|
|
21
|
+
import path from 'node:path';
|
|
22
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
23
|
+
import { HOME } from './config.mjs';
|
|
24
|
+
import { actor } from './owner.mjs';
|
|
25
|
+
import { identity } from './proc.mjs';
|
|
26
|
+
import { bold, dim, wrap } from './style.mjs';
|
|
27
|
+
import { die, now, dur, ms, sleep } from './util.mjs';
|
|
28
|
+
import { jsonLines } from './durable.mjs';
|
|
29
|
+
|
|
30
|
+
const DIR = path.join(HOME, 'council');
|
|
31
|
+
export const FILE = path.join(HOME, 'council.json');
|
|
32
|
+
const DIBS = path.join(import.meta.dirname, '..', 'bin', 'dibs.mjs');
|
|
33
|
+
// The newest runs kept; older ones are deleted when a new one starts. A run is a few dozen KB.
|
|
34
|
+
const KEEP = 100;
|
|
35
|
+
// An answer longer than this is cut before it goes into another agent's prompt:
|
|
36
|
+
// four voices over three rounds would otherwise make the judge's prompt huge.
|
|
37
|
+
const QUOTE_MAX = 3000;
|
|
38
|
+
// The default seats when --voices isn't given.
|
|
39
|
+
const DEFAULT_VOICES = ['skeptic', 'builder', 'user'];
|
|
40
|
+
// How often a council waiting on live agents looks for their replies.
|
|
41
|
+
const REPLY_POLL = 1000;
|
|
42
|
+
|
|
43
|
+
// Every voice gets this after its own prompt. The POSITION line is what the
|
|
44
|
+
// summary shows for each voice, in its own words, so a judge that smooths the
|
|
45
|
+
// answers over can't hide a disagreement.
|
|
46
|
+
const SHARED = 'You are one of several advisers answering the same question independently. Give your own answer, not a balanced survey. '
|
|
47
|
+
+ 'If the question is about code in the current folder, read the code before answering. Under 250 words. '
|
|
48
|
+
+ 'End with one line: POSITION: <your answer in one sentence>.';
|
|
49
|
+
|
|
50
|
+
// Written to ~/.dibs/council.json on first use, for the person to edit. Keys left out of
|
|
51
|
+
// that file come from here, so a dibs update can add an agent without touching it.
|
|
52
|
+
export const DEFAULTS = {
|
|
53
|
+
voices: {
|
|
54
|
+
skeptic: 'You look for why this is wrong or will fail. Name the specific case that breaks it and what that costs. If it holds up, say so plainly.',
|
|
55
|
+
builder: 'You would build and maintain this. Favor the smallest change that works today. Name files, commands and steps, and call out work nobody needs.',
|
|
56
|
+
user: 'You are the person who uses this every day and never reads the docs. Judge it by what they see, type and wait for, and name the moment it confuses or annoys them.',
|
|
57
|
+
contrarian: 'Make the strongest case for the option the others are most likely to dismiss. Argue it honestly; drop it only if it really fails.',
|
|
58
|
+
outsider: 'You know nothing of how this project does things. Say what someone from outside would expect, and how other tools handle it.',
|
|
59
|
+
plain: '',
|
|
60
|
+
},
|
|
61
|
+
// How to run each agent. {system} is the voice's prompt, {out} a file the agent writes its
|
|
62
|
+
// answer to, {model} the model after agent: in --via. The question goes last, or where {prompt} is.
|
|
63
|
+
// system "inline": the agent has no system prompt flag, so the voice goes before the question.
|
|
64
|
+
// read "claude-json": stdout is claude's --output-format json, with the cost and tokens.
|
|
65
|
+
agents: {
|
|
66
|
+
// No MCP servers, skills or settings files: with them one "say ok" cost 245,000 tokens of the
|
|
67
|
+
// person's own context (2026-11-25); without, 3,500. Read-only tools: a voice advises, never edits.
|
|
68
|
+
claude: { cmd: ['claude', '-p', '--no-session-persistence', '--strict-mcp-config', '--disable-slash-commands', '--setting-sources', '',
|
|
69
|
+
'--tools', 'Read,Grep,Glob', '--output-format', 'json', '--append-system-prompt', '{system}'], model: ['--model', '{model}'], read: 'claude-json' },
|
|
70
|
+
codex: { cmd: ['codex', 'exec', '--sandbox', 'read-only', '--skip-git-repo-check', '--ephemeral', '--color', 'never', '-o', '{out}'],
|
|
71
|
+
model: ['-m', '{model}'], system: 'inline' },
|
|
72
|
+
opencode: { cmd: ['opencode', 'run'], model: ['-m', '{model}'], system: 'inline' },
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const MODES = ['merge', 'critique', 'debate'];
|
|
77
|
+
const HELP = `dibs council "question" [flags] ask several agents at once and combine their answers
|
|
78
|
+
--voices skeptic,builder,user which voices (named system prompts in ${FILE}); voice@agent:model pins one
|
|
79
|
+
--via claude,codex which agents answer, in turn (agent:model picks a model); default claude
|
|
80
|
+
--mode merge|critique|debate merge: blind answers, then one synthesis (default)
|
|
81
|
+
critique: blind answers, each reads the others and answers again, then synthesis
|
|
82
|
+
debate: rounds of posts that reply to and vote on each other, then a judge
|
|
83
|
+
--rounds 2 debate rounds, counting the opening one (1-4)
|
|
84
|
+
--judge claude the agent (agent:model) that writes the synthesis or verdict; default the first in --via
|
|
85
|
+
--live <agent>[,<agent>] also ask agents already working here (dibs tell); they answer once, in the first round
|
|
86
|
+
--live-wait 10m how long to wait for them
|
|
87
|
+
--timeout 5m stop any one call after this long
|
|
88
|
+
--max-wait 8m how long each call may wait for the council budget (quota:council)
|
|
89
|
+
--parallel 4 calls at once
|
|
90
|
+
--json the stored run as JSON
|
|
91
|
+
dibs council list [--json] recent runs
|
|
92
|
+
dibs council show <id> [--json] one run: every answer, round by round, and the result
|
|
93
|
+
dibs council voices the voices and agents, and the file to edit
|
|
94
|
+
dibs council reply <id> "..." a live agent's answer to a council that asked it
|
|
95
|
+
Every call is a dibs run quota:council job: 60 an hour unless config.json "quotas" sets "council".
|
|
96
|
+
Exit codes: 0 done, 2 bad usage, 127 an agent's CLI isn't installed, 75 the council budget stayed empty
|
|
97
|
+
past --max-wait (nothing more ran), 1 no voice answered or the synthesis failed (the answers are kept).`;
|
|
98
|
+
|
|
99
|
+
export async function council(args) {
|
|
100
|
+
const [sub, ...rest] = args;
|
|
101
|
+
if (!sub || /^(help|-h|--help)$/.test(sub)) return console.log(HELP);
|
|
102
|
+
if (sub === 'list') return list(rest);
|
|
103
|
+
if (sub === 'show') return show(rest);
|
|
104
|
+
if (sub === 'voices') return voices();
|
|
105
|
+
if (sub === 'reply') return reply(rest);
|
|
106
|
+
return ask(parse(args));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function parse(args) {
|
|
110
|
+
const o = { words: [], mode: 'merge', rounds: 2, liveWait: ms('10m'), timeout: ms('5m'), parallel: 4 };
|
|
111
|
+
const val = (i, f) => args[i + 1] ?? die(`${f} needs a value. dibs council help`);
|
|
112
|
+
for (let i = 0; i < args.length; i++) {
|
|
113
|
+
const a = args[i];
|
|
114
|
+
if (a === '--voices') o.voices = val(i, a).split(',').filter(Boolean), i++;
|
|
115
|
+
else if (a === '--via') o.via = val(i, a).split(',').filter(Boolean), i++;
|
|
116
|
+
else if (a === '--mode') o.mode = val(i, a), i++;
|
|
117
|
+
else if (a === '--rounds') o.rounds = Number(val(i, a)), i++;
|
|
118
|
+
else if (a === '--judge') o.judge = val(i, a), i++;
|
|
119
|
+
else if (a === '--live') o.live = val(i, a).split(',').filter(Boolean), i++;
|
|
120
|
+
else if (a === '--live-wait') o.liveWait = ms(val(i, a)), i++;
|
|
121
|
+
else if (a === '--timeout') o.timeout = ms(val(i, a)), i++;
|
|
122
|
+
else if (a === '--max-wait') o.maxWait = val(i, a), i++;
|
|
123
|
+
else if (a === '--parallel') o.parallel = Number(val(i, a)), i++;
|
|
124
|
+
else if (a === '--json') o.json = true;
|
|
125
|
+
else if (a.startsWith('--')) die(`unknown flag ${a}. dibs council help`);
|
|
126
|
+
else o.words.push(a);
|
|
127
|
+
}
|
|
128
|
+
o.question = o.words.join(' ').trim();
|
|
129
|
+
if (!o.question) die('ask what? dibs council "should the cache live in the worker or the coordinator?" (dibs council help)');
|
|
130
|
+
if (!MODES.includes(o.mode)) die(`--mode is one of ${MODES.join(', ')}`);
|
|
131
|
+
if (!(Number.isInteger(o.rounds) && o.rounds >= 1 && o.rounds <= 4)) die('--rounds is 1 to 4');
|
|
132
|
+
if (!(Number.isInteger(o.parallel) && o.parallel >= 1)) die('--parallel is a whole number above 0');
|
|
133
|
+
return o;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// The person's file over the defaults, one level deep. Written whole on first use.
|
|
137
|
+
export function loadSetup() {
|
|
138
|
+
fs.mkdirSync(HOME, { recursive: true });
|
|
139
|
+
if (!fs.existsSync(FILE)) {
|
|
140
|
+
const tmp = `${FILE}.${process.pid}`;
|
|
141
|
+
fs.writeFileSync(tmp, JSON.stringify(DEFAULTS, null, 2) + '\n');
|
|
142
|
+
try { fs.linkSync(tmp, FILE); } catch (e) { if (e.code !== 'EEXIST') throw e; } finally { fs.rmSync(tmp, { force: true }); }
|
|
143
|
+
}
|
|
144
|
+
let c;
|
|
145
|
+
try { c = JSON.parse(fs.readFileSync(FILE, 'utf8')); } catch { die(`${FILE} isn't valid JSON. Fix it, or delete it to get the defaults back.`); }
|
|
146
|
+
return { voices: { ...DEFAULTS.voices, ...c.voices }, agents: { ...DEFAULTS.agents, ...c.agents } };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// "codex:gpt-6" -> { agent: 'codex', model: 'gpt-6' }, checked against the known agents.
|
|
150
|
+
function agentOf(spec, setup) {
|
|
151
|
+
const [agent, ...m] = spec.split(':');
|
|
152
|
+
if (!setup.agents[agent]) die(`no agent called ${agent}. Agents: ${Object.keys(setup.agents).join(', ')} (add one in ${FILE})`);
|
|
153
|
+
const cmd = setup.agents[agent].cmd;
|
|
154
|
+
if (!Array.isArray(cmd) || !cmd.length || cmd.some(x => typeof x !== 'string')) die(`agents.${agent}.cmd in ${FILE} is a list of strings, like ["claude", "-p"]`);
|
|
155
|
+
return { agent, model: m.join(':') || null };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Seat i takes voice i and agent i, each list repeating as needed, so two voices on
|
|
159
|
+
// three agents makes three seats. voice@agent:model pins a seat's agent.
|
|
160
|
+
function seats(o, setup) {
|
|
161
|
+
const via = (o.via || ['claude']).map(v => agentOf(v, setup));
|
|
162
|
+
const vs = o.voices || DEFAULT_VOICES;
|
|
163
|
+
for (const v of vs) {
|
|
164
|
+
const name = v.split('@')[0];
|
|
165
|
+
if (setup.voices[name] == null) die(`no voice called ${name}. Voices: ${Object.keys(setup.voices).join(', ')} (add one in ${FILE})`);
|
|
166
|
+
}
|
|
167
|
+
const n = Math.max(vs.length, via.length);
|
|
168
|
+
const out = [];
|
|
169
|
+
for (let i = 0; i < n; i++) {
|
|
170
|
+
const [voice, pin] = vs[i % vs.length].split('@');
|
|
171
|
+
const { agent, model } = pin ? agentOf(pin, setup) : via[i % via.length];
|
|
172
|
+
const taken = out.filter(s => s.voice === voice).length;
|
|
173
|
+
out.push({ name: taken ? `${voice}-${taken + 1}` : voice, voice, agent, model });
|
|
174
|
+
}
|
|
175
|
+
return out;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const runFile = id => path.join(DIR, `${id}.json`);
|
|
179
|
+
const repliesFile = id => path.join(DIR, `${id}.replies.jsonl`);
|
|
180
|
+
function save(run) {
|
|
181
|
+
const f = runFile(run.id);
|
|
182
|
+
fs.writeFileSync(`${f}.${process.pid}`, JSON.stringify(run, null, 2) + '\n');
|
|
183
|
+
fs.renameSync(`${f}.${process.pid}`, f);
|
|
184
|
+
}
|
|
185
|
+
function load(id) {
|
|
186
|
+
if (!/^[a-z0-9]+$/.test(id || '')) die('which run? dibs council show <id> (ids: dibs council list)');
|
|
187
|
+
try { return JSON.parse(fs.readFileSync(runFile(id), 'utf8')); } catch { die(`no council run ${id}. Runs: dibs council list`, 1); }
|
|
188
|
+
}
|
|
189
|
+
function runs() {
|
|
190
|
+
let names = [];
|
|
191
|
+
try { names = fs.readdirSync(DIR).filter(f => /^[a-z0-9]+\.json$/.test(f)); } catch {}
|
|
192
|
+
return names.map(f => { try { return JSON.parse(fs.readFileSync(path.join(DIR, f), 'utf8')); } catch { return null; } })
|
|
193
|
+
.filter(Boolean).sort((a, b) => b.at - a.at);
|
|
194
|
+
}
|
|
195
|
+
function prune() {
|
|
196
|
+
for (const r of runs().slice(KEEP)) for (const f of [runFile(r.id), repliesFile(r.id)]) fs.rmSync(f, { force: true });
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Whether a command can start, so a missing CLI fails before anything is spent.
|
|
200
|
+
function installed(bin) {
|
|
201
|
+
if (process.platform === 'win32') return true;
|
|
202
|
+
if (bin.includes('/')) return fs.existsSync(bin);
|
|
203
|
+
return (process.env.PATH || '').split(path.delimiter).some(d => { try { fs.accessSync(path.join(d, bin), fs.constants.X_OK); return true; } catch { return false; } });
|
|
204
|
+
}
|
|
205
|
+
// claude is often a shell function or alias, which a spawned process can't see; CLAUDE_BIN names the binary.
|
|
206
|
+
const binOf = cmd0 => (cmd0 === 'claude' && process.env.CLAUDE_BIN) || cmd0;
|
|
207
|
+
|
|
208
|
+
const position = text => {
|
|
209
|
+
// Anywhere on a line: a live agent's reply is often one line typed into a shell.
|
|
210
|
+
const m = [...String(text).matchAll(/\bPOSITION[*_]*:[*_]*\s*(.+)$/gm)].at(-1);
|
|
211
|
+
return m ? m[1].replace(/[*_]+$/, '').trim() : null;
|
|
212
|
+
};
|
|
213
|
+
const quote = t => (t.length > QUOTE_MAX ? `${t.slice(0, QUOTE_MAX)} [cut]` : t);
|
|
214
|
+
|
|
215
|
+
let calls = 0;
|
|
216
|
+
// One headless agent call as a dibs job. Resolves to what it said and what it cost; never throws.
|
|
217
|
+
function call(run, o, setup, seat, system, prompt, label) {
|
|
218
|
+
const ag = setup.agents[seat.agent];
|
|
219
|
+
const out = path.join(os.tmpdir(), `dibs-council-${process.pid}-${++calls}.txt`);
|
|
220
|
+
const fill = list => list.map(x => x.replace(/\{(system|out|model|prompt)\}/g, (_, k) => ({ system, out, model: seat.model, prompt: text })[k] ?? ''));
|
|
221
|
+
const text = ag.system === 'inline' && system ? `${system}\n\n${prompt}` : prompt;
|
|
222
|
+
const argv = [...fill(ag.cmd), ...(seat.model ? fill(ag.model || []) : [])];
|
|
223
|
+
if (!ag.cmd.some(x => x.includes('{prompt}'))) argv.push(text);
|
|
224
|
+
argv[0] = binOf(argv[0]);
|
|
225
|
+
const job = ['run', 'quota:council', '-m', `council ${run.id}: ${label}`, ...(o.maxWait ? ['--max-wait', o.maxWait] : []), '--', ...argv];
|
|
226
|
+
const t0 = now();
|
|
227
|
+
return new Promise(resolve => {
|
|
228
|
+
const p = spawn(process.execPath, [DIBS, ...job], { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
229
|
+
let so = '', se = '', late = false;
|
|
230
|
+
p.stdout.on('data', d => (so += d));
|
|
231
|
+
p.stderr.on('data', d => (se += d));
|
|
232
|
+
const timer = setTimeout(() => { late = true; p.kill('SIGTERM'); }, o.timeout);
|
|
233
|
+
p.on('close', code => {
|
|
234
|
+
clearTimeout(timer);
|
|
235
|
+
const r = { ms: now() - t0, code };
|
|
236
|
+
let answer = so;
|
|
237
|
+
try { answer = fs.readFileSync(out, 'utf8'); fs.rmSync(out, { force: true }); } catch {}
|
|
238
|
+
if (ag.read === 'claude-json') {
|
|
239
|
+
try {
|
|
240
|
+
const j = JSON.parse(so);
|
|
241
|
+
answer = j.is_error ? '' : String(j.result ?? '');
|
|
242
|
+
if (j.is_error) r.error = String(j.result || 'claude said it failed');
|
|
243
|
+
r.cost = j.total_cost_usd;
|
|
244
|
+
const u = j.usage || {};
|
|
245
|
+
r.tokens = (u.input_tokens || 0) + (u.cache_creation_input_tokens || 0) + (u.cache_read_input_tokens || 0) + (u.output_tokens || 0);
|
|
246
|
+
} catch {}
|
|
247
|
+
}
|
|
248
|
+
const used = se.match(/tokens used\s*\n?\s*([\d,]+)/i);
|
|
249
|
+
if (used && r.tokens == null) r.tokens = Number(used[1].replace(/,/g, ''));
|
|
250
|
+
r.text = answer.trim();
|
|
251
|
+
if (late) r.error = `took longer than ${dur(o.timeout)}, so it was stopped (--timeout)`;
|
|
252
|
+
else if (code === 75) r.error = 'waited too long for the council budget (quota:council) and never ran';
|
|
253
|
+
else if (code !== 0 && !r.error) r.error = `exited ${code}: ${(se.trim().split('\n').filter(l => !/^dibs: /.test(l)).at(-1) || se.trim().split('\n').at(-1) || '').slice(0, 300)}`;
|
|
254
|
+
else if (!r.text && !r.error) r.error = 'answered with nothing';
|
|
255
|
+
if (!r.error) r.position = position(r.text);
|
|
256
|
+
resolve(r);
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async function pool(jobs, n) {
|
|
262
|
+
const out = [];
|
|
263
|
+
let next = 0;
|
|
264
|
+
const worker = async () => { while (next < jobs.length) { const k = next++; out[k] = await jobs[k](); } };
|
|
265
|
+
await Promise.all(Array.from({ length: Math.min(n, jobs.length) }, worker));
|
|
266
|
+
return out;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const systemOf = (setup, seat) => [setup.voices[seat.voice], `Your name in this discussion is ${seat.name}.`, SHARED].filter(Boolean).join('\n\n');
|
|
270
|
+
const answered = r => r && !r.error;
|
|
271
|
+
|
|
272
|
+
// The other answers, by seat name only: which company made which model stays out,
|
|
273
|
+
// so no voice defers to a brand.
|
|
274
|
+
const others = (round, me) => round.filter(r => r.seat !== me && answered(r)).map(r => `--- ${r.seat}\n${quote(r.text)}`).join('\n\n');
|
|
275
|
+
|
|
276
|
+
function judgePrompt(run, round) {
|
|
277
|
+
const answers = round.filter(answered).map(r => `--- ${r.seat}\n${quote(r.text)}`).join('\n\n');
|
|
278
|
+
if (run.mode === 'debate') {
|
|
279
|
+
return `You are judging a debate among advisers. Votes show what the advisers found convincing, not who is right: a lone dissent can be right, and models tend to agree with each other.\n\n`
|
|
280
|
+
+ `Question: ${run.question}\n\nThe thread (#n is a post, score is up and down votes):\n${thread(run)}\n\n`
|
|
281
|
+
+ 'Write exactly these sections, under 300 words in all:\nVERDICT: the answer, and the two or three reasons that decide it.\n'
|
|
282
|
+
+ 'DISSENT: the strongest point against the verdict and who made it. If nobody disagreed, say so.\nOPEN: what fact or test would settle what is still in doubt.';
|
|
283
|
+
}
|
|
284
|
+
return `Several advisers answered the question below independently${run.mode === 'critique' ? ', then read each other and answered again' : ''}. Combine them into one answer. `
|
|
285
|
+
+ 'Do not average the answers away: a real disagreement is the most useful thing you can report.\n\n'
|
|
286
|
+
+ `Question: ${run.question}\n\nAnswers:\n${answers}\n\n`
|
|
287
|
+
+ 'Write exactly these sections, under 300 words in all:\nAGREED: what all or most answers share, one line each.\n'
|
|
288
|
+
+ 'SPLIT: each real disagreement: what it turns on, who holds which side, and the best point for each. If there is none, say so.\n'
|
|
289
|
+
+ 'ANSWER: your recommendation, and which side of each split it takes and why.';
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// The debate so far as numbered posts, replies after what they answer, with scores.
|
|
293
|
+
function thread(run) {
|
|
294
|
+
return run.posts.map(p => `#${p.n} ${p.seat}${p.reply ? `, replying to #${p.reply}` : ''} (score ${score(p)}):\n${quote(p.text)}`).join('\n\n');
|
|
295
|
+
}
|
|
296
|
+
const score = p => { const s = (p.up || 0) - (p.down || 0); return s > 0 ? `+${s}` : String(s); };
|
|
297
|
+
|
|
298
|
+
function debatePrompt(run, seat) {
|
|
299
|
+
return `Question: ${run.question}\n\nThe debate so far:\n${thread(run)}\n\n`
|
|
300
|
+
+ 'Write your next post. Answer the post you most disagree with, or the strongest one, and say whether you have changed your mind. '
|
|
301
|
+
+ 'Agree only where the argument convinced you. Start with these two lines:\n'
|
|
302
|
+
+ 'REPLY: #<the post you answer>\nVOTE: up to two votes like +#2 -#5 (never on your own posts)\nand end with POSITION: <your answer now, in one sentence>.';
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Parse a debate post's REPLY and VOTE lines, apply the votes, add it to the thread.
|
|
306
|
+
function post(run, seat, round, r) {
|
|
307
|
+
const n = run.posts.length + 1;
|
|
308
|
+
const mine = new Set(run.posts.filter(p => p.seat === seat).map(p => p.n));
|
|
309
|
+
const exists = k => k >= 1 && k < n && !mine.has(k);
|
|
310
|
+
const reply = Number(r.text.match(/^\W*REPLY\W*#?(\d+)/im)?.[1]) || null;
|
|
311
|
+
const p = { n, seat, round, text: r.text.replace(/^\W*(REPLY|VOTE)\b.*$/gim, '').trim(), position: r.position, reply: exists(reply) ? reply : null, up: 0, down: 0 };
|
|
312
|
+
const votes = r.text.match(/^\W*VOTE\b(.*)$/im)?.[1] || '';
|
|
313
|
+
for (const [, sign, k] of votes.matchAll(/([+-])\s*#(\d+)/g)) {
|
|
314
|
+
const target = run.posts.find(x => x.n === Number(k));
|
|
315
|
+
if (target && exists(target.n)) target[sign === '+' ? 'up' : 'down']++;
|
|
316
|
+
}
|
|
317
|
+
run.posts.push(p);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
async function ask(o) {
|
|
321
|
+
const setup = loadSetup();
|
|
322
|
+
const table = seats(o, setup);
|
|
323
|
+
const judge = agentOf(o.judge || o.via?.[0] || table[0].agent, setup);
|
|
324
|
+
for (const a of new Set([...table.map(s => s.agent), judge.agent])) {
|
|
325
|
+
const bin = binOf(setup.agents[a].cmd[0]);
|
|
326
|
+
if (!installed(bin)) die(`${bin} isn't installed or isn't on PATH, so the ${a} voices can't run. Install it, or leave ${a} out of --via${a === 'claude' ? ' (or set CLAUDE_BIN to its path)' : ''}.`, 127);
|
|
327
|
+
}
|
|
328
|
+
fs.mkdirSync(DIR, { recursive: true });
|
|
329
|
+
prune();
|
|
330
|
+
const id = now().toString(36);
|
|
331
|
+
const run = { id, at: now(), by: actor().name, cwd: process.cwd(), question: o.question, mode: o.mode, rounds: [], posts: [], live: o.live || [],
|
|
332
|
+
seats: table.map(s => ({ ...s, system: systemOf(setup, s) })), judge, state: 'running' };
|
|
333
|
+
save(run);
|
|
334
|
+
process.stderr.write(dim(`council ${id}: ${table.length} voice${table.length === 1 ? '' : 's'}, ${o.mode}${o.live ? `, asking ${o.live.join(', ')}` : ''}. Watch: dibs council show ${id}`, process.stderr) + '\n');
|
|
335
|
+
const live = o.live ? askLive(run, o) : Promise.resolve([]);
|
|
336
|
+
const label = (s, k) => `${s.name} via ${s.agent}${s.model ? `:${s.model}` : ''}, round ${k}`;
|
|
337
|
+
const round = async (k, promptOf) => {
|
|
338
|
+
const done = await pool(table.map(s => () => call(run, o, setup, s, systemOf(setup, s), promptOf(s), label(s, k)).then(r => ({ seat: s.name, ...r }))), o.parallel);
|
|
339
|
+
run.rounds.push(done);
|
|
340
|
+
save(run);
|
|
341
|
+
return done;
|
|
342
|
+
};
|
|
343
|
+
const first = await round(1, () => `Question: ${o.question}`);
|
|
344
|
+
// Live agents answer in the first round, beside the headless ones.
|
|
345
|
+
first.push(...await live);
|
|
346
|
+
for (const s of run.live) if (!table.some(x => x.name === s)) run.seats.push({ name: s, voice: null, agent: 'live', model: null });
|
|
347
|
+
save(run);
|
|
348
|
+
if (o.mode === 'debate') {
|
|
349
|
+
for (const r of first) if (answered(r)) post(run, r.seat, 1, r);
|
|
350
|
+
for (let k = 2; k <= o.rounds; k++) {
|
|
351
|
+
const done = await round(k, s => debatePrompt(run, s.name));
|
|
352
|
+
for (const r of done) if (answered(r)) post(run, r.seat, k, r);
|
|
353
|
+
save(run);
|
|
354
|
+
}
|
|
355
|
+
} else if (o.mode === 'critique') {
|
|
356
|
+
await round(2, s => `Question: ${o.question}\n\nYour first answer:\n${quote(first.find(r => r.seat === s.name)?.text || '(none)')}\n\n`
|
|
357
|
+
+ `The other advisers answered:\n${others(first, s.name)}\n\nSay where each is wrong or missing something, then give your final answer. `
|
|
358
|
+
+ 'Change your mind only if an argument convinced you, and say which. End with POSITION: <your final answer in one sentence>.');
|
|
359
|
+
// A live agent's first answer stands as its last.
|
|
360
|
+
run.rounds[1].push(...first.filter(r => !table.some(s => s.name === r.seat)));
|
|
361
|
+
}
|
|
362
|
+
const last = run.rounds.at(-1);
|
|
363
|
+
const exitWith = finish => { run.state = finish ? 'done' : 'failed'; run.ms = now() - run.at; save(run); };
|
|
364
|
+
if (!run.rounds.flat().some(answered)) {
|
|
365
|
+
exitWith(false);
|
|
366
|
+
print(run);
|
|
367
|
+
const budget = run.rounds.flat().every(r => r.code === 75);
|
|
368
|
+
die(budget ? 'the council budget (quota:council) stayed empty, so no voice ran. See it on the board: dibs. Run the same council again later.'
|
|
369
|
+
: `no voice answered. What each said: dibs council show ${id}`, budget ? 75 : 1);
|
|
370
|
+
}
|
|
371
|
+
const jseat = { name: 'judge', voice: null, ...judge };
|
|
372
|
+
run.result = { ...await call(run, o, setup, jseat, '', judgePrompt(run, last), `judge via ${judge.agent}`), agent: judge.agent, model: judge.model };
|
|
373
|
+
exitWith(answered(run.result));
|
|
374
|
+
if (o.json) console.log(JSON.stringify(run, null, 2));
|
|
375
|
+
else print(run);
|
|
376
|
+
if (!answered(run.result)) die(`the ${run.mode === 'debate' ? 'judge' : 'synthesis'} failed (${run.result.error}). The answers are kept: dibs council show ${id}`, run.result.code === 75 ? 75 : 1);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// Ask each live agent once, with dibs tell, then wait for their replies until --live-wait.
|
|
380
|
+
async function askLive(run, o) {
|
|
381
|
+
const asked = [], failed = [];
|
|
382
|
+
const text = `Council question from ${run.by} (dibs council ${run.id}). Answer from what you know of your own work, in under 200 words, `
|
|
383
|
+
+ `and don't stop that work for long. End with POSITION: <your answer in one sentence>. Reply with: dibs council reply ${run.id} "your answer"\n\nQuestion: ${run.question}`;
|
|
384
|
+
for (const name of run.live) {
|
|
385
|
+
const r = spawnSync(process.execPath, [DIBS, 'tell', name, text.slice(0, 3900)], { encoding: 'utf8' });
|
|
386
|
+
if (r.status === 0) asked.push(name);
|
|
387
|
+
else failed.push({ seat: name, live: true, error: `couldn't ask it: ${(r.stderr || '').trim().replace(/^dibs: /, '')}` });
|
|
388
|
+
}
|
|
389
|
+
const until = now() + o.liveWait;
|
|
390
|
+
while (asked.length && now() < until && replies(run.id, asked).length < asked.length) await sleep(REPLY_POLL);
|
|
391
|
+
const got = replies(run.id, asked);
|
|
392
|
+
const missing = asked.filter(n => !got.some(g => g.seat === n)).map(n => ({ seat: n, live: true, error: `didn't reply within ${dur(o.liveWait)} (--live-wait)` }));
|
|
393
|
+
return [...failed, ...got, ...missing];
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// Each asked agent's first reply. A reply signed with another name (a session's name
|
|
397
|
+
// can differ from what the person typed) goes to the one agent still unanswered, if only one is.
|
|
398
|
+
function replies(id, asked) {
|
|
399
|
+
let lines = [];
|
|
400
|
+
try { lines = jsonLines(fs.readFileSync(repliesFile(id), 'utf8')); } catch {}
|
|
401
|
+
const out = [];
|
|
402
|
+
for (const l of lines) {
|
|
403
|
+
const open = asked.filter(n => !out.some(x => x.seat === n));
|
|
404
|
+
const seat = open.includes(l.who) ? l.who : open.length === 1 ? open[0] : null;
|
|
405
|
+
if (seat) out.push({ seat, live: true, text: l.text, position: position(l.text), from: l.who, ms: l.at - Number.parseInt(id, 36), code: 0 });
|
|
406
|
+
}
|
|
407
|
+
return out;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function reply(args) {
|
|
411
|
+
const [id, ...words] = args;
|
|
412
|
+
const text = words.join(' ').trim();
|
|
413
|
+
if (!id || !text) die('dibs council reply <id> "your answer" (the id is in the message that asked you)');
|
|
414
|
+
const run = load(id);
|
|
415
|
+
if (run.state !== 'running') die(`council ${id} has already finished; your answer wasn't added. Its result: dibs council show ${id}`, 1);
|
|
416
|
+
const me = identity();
|
|
417
|
+
fs.appendFileSync(repliesFile(id), JSON.stringify({ who: me.agent || me.who, at: now(), text: text.slice(0, 8000) }) + '\n');
|
|
418
|
+
console.log(`Sent to council ${id}. Back to your own work.`);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
const seatOf = (run, name) => run.seats.find(s => s.name === name) || { name, agent: '?' };
|
|
422
|
+
const who = s => `${s.name} ${dim(`(${s.agent}${s.model ? `:${s.model}` : ''})`)}`;
|
|
423
|
+
const cost = run => {
|
|
424
|
+
const all = [...run.rounds.flat().filter(r => !r.live && r.ms != null), run.result].filter(Boolean);
|
|
425
|
+
const usd = all.reduce((a, r) => a + (r.cost || 0), 0);
|
|
426
|
+
const tok = all.reduce((a, r) => a + (r.tokens || 0), 0);
|
|
427
|
+
return `${all.length} calls${tok ? `, ${tok < 1000 ? tok : `${Math.round(tok / 1000)}k`} tokens` : ''}${usd ? `, $${usd.toFixed(2)} on claude` : ''}${run.ms ? `, ${dur(run.ms)}` : ''}`;
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
// The summary: each voice's own last position, then the synthesis or verdict.
|
|
431
|
+
function print(run) {
|
|
432
|
+
const out = [bold(`Council ${run.id}: ${run.question}`), dim(`${run.mode}, ${cost(run)}`), ''];
|
|
433
|
+
const firsts = new Map((run.rounds[0] || []).map(r => [r.seat, r]));
|
|
434
|
+
for (const r of run.rounds.at(-1) || []) {
|
|
435
|
+
const s = seatOf(run, r.seat);
|
|
436
|
+
const was = firsts.get(r.seat);
|
|
437
|
+
const moved = run.rounds.length > 1 && answered(was) && answered(r) && was.position && r.position && was.position !== r.position;
|
|
438
|
+
out.push(`${who(s)}: ${answered(r) ? r.position || dim('(no POSITION line) ') + r.text.split('\n')[0].slice(0, 200) : dim(r.error)}`);
|
|
439
|
+
if (moved && run.mode === 'critique') out.push(dim(` first said: ${was.position}`));
|
|
440
|
+
}
|
|
441
|
+
if (run.mode === 'debate' && run.posts.length) {
|
|
442
|
+
out.push('', bold('Thread'));
|
|
443
|
+
const kids = p => run.posts.filter(x => x.reply === p.n);
|
|
444
|
+
const line = (p, depth) => {
|
|
445
|
+
const pad = ' '.repeat(depth + 1);
|
|
446
|
+
out.push(wrap(`${pad}#${p.n} ${p.seat} ${dim(`[${score(p)}]`)} ${p.position || p.text.split('\n')[0].slice(0, 160)}`, `${pad} `));
|
|
447
|
+
for (const k of kids(p)) line(k, depth + 1);
|
|
448
|
+
};
|
|
449
|
+
for (const p of run.posts.filter(x => !x.reply)) line(p, 0);
|
|
450
|
+
}
|
|
451
|
+
if (run.result) out.push('', bold(run.mode === 'debate' ? 'Judge' : 'Synthesis') + dim(` (${run.result.agent})`), answered(run.result) ? run.result.text : dim(run.result.error));
|
|
452
|
+
out.push('', dim(`Every answer in full: dibs council show ${run.id}`));
|
|
453
|
+
console.log(out.join('\n'));
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function show(args) {
|
|
457
|
+
const id = args.find(a => !a.startsWith('-'));
|
|
458
|
+
const run = load(id);
|
|
459
|
+
if (args.includes('--json')) return console.log(JSON.stringify(run, null, 2));
|
|
460
|
+
const out = [bold(`Council ${run.id}: ${run.question}`), dim(`${run.mode}, asked by ${run.by} ${new Date(run.at).toLocaleString()}, ${run.state}, ${cost(run)}`)];
|
|
461
|
+
run.rounds.forEach((round, i) => {
|
|
462
|
+
out.push('', bold(`Round ${i + 1}`));
|
|
463
|
+
for (const r of round) out.push('', `${who(seatOf(run, r.seat))}${r.ms != null ? dim(` ${dur(r.ms)}`) : ''}`, answered(r) ? r.text : dim(r.error));
|
|
464
|
+
});
|
|
465
|
+
if (run.result) out.push('', bold(run.mode === 'debate' ? 'Judge' : 'Synthesis'), answered(run.result) ? run.result.text : dim(run.result.error));
|
|
466
|
+
console.log(out.join('\n'));
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function list(args) {
|
|
470
|
+
const all = runs();
|
|
471
|
+
if (args.includes('--json')) return console.log(JSON.stringify(all.map(({ id, at, question, mode, state, by }) => ({ id, at, question, mode, state, by }))));
|
|
472
|
+
if (!all.length) return console.log('No council runs yet. dibs council "question" asks one.');
|
|
473
|
+
for (const r of all.slice(0, 20)) console.log(`${r.id} ${dim(new Date(r.at).toLocaleString())} ${r.mode}${r.state === 'done' ? '' : ` (${r.state})`} ${r.question.slice(0, 80)}`);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
function voices() {
|
|
477
|
+
const s = loadSetup();
|
|
478
|
+
const out = [bold('Voices'), ...Object.entries(s.voices).map(([k, v]) => ` ${k}: ${v || dim('(no prompt: the agent as it is)')}`),
|
|
479
|
+
'', bold('Agents'), ...Object.entries(s.agents).map(([k, a]) => ` ${k}: ${a.cmd.join(' ')}${installed(binOf(a.cmd[0])) ? '' : dim(' (not installed)')}`),
|
|
480
|
+
'', `Edit ${FILE} to add or change them.`];
|
|
481
|
+
console.log(out.join('\n'));
|
|
482
|
+
}
|
package/src/cwd.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Imported first by bin/dibs.mjs. An agent whose folder was deleted under it (a worktree
|
|
2
|
+
// removed while its shell still sat in it) made every dibs call crash with exit 70 the first
|
|
3
|
+
// time anything asked for the working directory (2026-11-17). Running its command somewhere
|
|
4
|
+
// else could do harm, so dibs stops at once and says why: the command never ran.
|
|
5
|
+
try { process.cwd(); } catch (e) {
|
|
6
|
+
if (e?.code !== 'ENOENT') throw e;
|
|
7
|
+
process.stderr.write(`dibs: the folder you're in no longer exists${process.env.PWD ? ` (${process.env.PWD})` : ''}. cd to one that does and run the same command again. Nothing ran.\n`);
|
|
8
|
+
process.exit(2);
|
|
9
|
+
}
|