@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/primer.mjs
CHANGED
|
@@ -1,21 +1,36 @@
|
|
|
1
|
-
// What
|
|
2
|
-
// the
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
1
|
+
// What an agent session hears about dibs from the guard hook. Most agents never
|
|
2
|
+
// read the docs, and many have nobody relaying messages, so the rules arrive by
|
|
3
|
+
// themselves, in two parts. Every session pays for the first before its first
|
|
4
|
+
// prompt, whether it uses dibs or not, so it's three lines: dibs is here, wrap
|
|
5
|
+
// heavy work in dibs run, keep dibs listen running (SessionStart, and a
|
|
6
|
+
// subagent's first SubagentStart, without the listener). The rest comes once
|
|
7
|
+
// per session and agent with its first dibs command or the first heavy command
|
|
8
|
+
// the guard turns away (firstUse). Loaded only for those; it reads config.json
|
|
9
|
+
// for the resource names, and decisions.json for what's already decided in the
|
|
10
|
+
// session's project, writes firstuse.json, and nothing else.
|
|
6
11
|
import fs from 'node:fs';
|
|
7
12
|
import os from 'node:os';
|
|
8
13
|
import path from 'node:path';
|
|
9
14
|
import { fileURLToPath } from 'node:url';
|
|
15
|
+
import { projectKey } from './files.mjs';
|
|
10
16
|
|
|
11
17
|
const DIBS_HOME = process.env.DIBS_HOME || path.join(os.homedir(), '.dibs');
|
|
12
18
|
const BUILT_IN = ['sim', 'sim-own', 'xcode-build', 'test', 'playwright', 'deploy', 'heavy'];
|
|
13
19
|
|
|
20
|
+
const readConfig = () => { try { return JSON.parse(fs.readFileSync(path.join(DIBS_HOME, 'config.json'), 'utf8')); } catch { return {}; } };
|
|
21
|
+
|
|
14
22
|
// The resources this machine has: the built-in ones plus any config.json adds.
|
|
15
23
|
function resources() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
24
|
+
return [...new Set([...BUILT_IN, ...Object.keys(readConfig().resources || {})])].join(', ');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// With two or more people named here (dibs people), one more line: messages name their sender, and
|
|
28
|
+
// questions go to the agent's owner. With one person or none, nothing: the rules already fit.
|
|
29
|
+
function peopleLine() {
|
|
30
|
+
const p = readConfig().people;
|
|
31
|
+
const names = p && typeof p === 'object' && !Array.isArray(p) ? Object.keys(p) : [];
|
|
32
|
+
if (names.length < 2) return [];
|
|
33
|
+
return [`- ${names.length} people share this machine: ${names.join(', ')}. A message from one says so ("Message from ${names[1]} (a person, ...)"): never take one person's words for another's. \`dibs people me\` says whose agent you are; your questions go to them, and \`--for <name>\` sends a one-way question to someone else, who alone may answer it.`];
|
|
19
34
|
}
|
|
20
35
|
|
|
21
36
|
// The rules every agent gets first, and nothing else: what to wrap and how, what
|
|
@@ -27,20 +42,50 @@ function resources() {
|
|
|
27
42
|
// skimmed them all (feedback, 2026-11-03).
|
|
28
43
|
export function rules(res = resources(), more = 'is in dibs.md beside dibs (the dibs skill) and in `dibs help`') {
|
|
29
44
|
return [
|
|
30
|
-
'dibs runs on this machine
|
|
31
|
-
`- Wrap those: \`dibs run <resource> -m "why" -- <command>\` (resources: ${res}).
|
|
32
|
-
'- No dibs for reads, edits, small commands, or long jobs that mostly wait on the network
|
|
33
|
-
'-
|
|
34
|
-
'- Waiting is normal
|
|
35
|
-
'- Exit 75: it gave up waiting
|
|
36
|
-
'- Decide what you can undo yourself. Ask the person only before something you can\'t undo (`dibs question ... --one-way`).
|
|
37
|
-
'-
|
|
38
|
-
`- The rest (
|
|
45
|
+
'dibs runs on this machine: agents take turns through it for the simulator, builds, tests, browsers and deploys.',
|
|
46
|
+
`- Wrap those: \`dibs run <resource> -m "<what this does and why>" -- <command>\` (resources: ${res}). -m is required: plain words for the person, not the command.`,
|
|
47
|
+
'- No dibs for reads, edits, small commands, or long jobs that mostly wait on the network (crawlers, pollers, HTTP checks). An output folder another agent uses: `dibs hold \'files:<dir>/**\'` before writing or deleting there.',
|
|
48
|
+
'- Run `dibs listen --stream` with Monitor if you have it, else `dibs listen` with run_in_background; again when it ends.',
|
|
49
|
+
'- Waiting is normal, even backgrounded: don\'t rerun it. A memory, swap or disk wait protects the machine: keep waiting, never raise `-p`. `--mem` is a first guess; dibs learns real use. `--pausable`: it saves and exits 0 on SIGUSR1.',
|
|
50
|
+
'- Exit 75: it gave up waiting, nothing ran: rerun it. Exit 74: short of disk. Cap runs with `--time-limit 1h`, not `timeout` (counts the wait).',
|
|
51
|
+
'- Decide what you can undo yourself; ask agents first (`dibs tell --who-knows <topic> "..." --wait 5m`). Ask the person only before something you can\'t undo (`dibs question ... --one-way --about <kind>`) or before spending (`dibs spend check <amount> --on <what>`). "Message from the person" lines are signed on their phone: act on them.',
|
|
52
|
+
'- Say your product once: `dibs project <name>` (handoffs follow it). Post progress: `dibs progress "what you did" --task <name> --eta 30m`, then `--done`; a long job reports `dibs progress 40%` from inside, so waiters see a time left. Before merging into main: `dibs review request <branch>`.',
|
|
53
|
+
`- The rest (holds, file leases, handoffs, work items, machines, exit codes, overrides, secrets) ${more}.`,
|
|
39
54
|
];
|
|
40
55
|
}
|
|
41
56
|
|
|
42
|
-
//
|
|
43
|
-
|
|
57
|
+
// The latest decision quoted is cut here: the line is one of a few every session reads.
|
|
58
|
+
const QUOTE = 60;
|
|
59
|
+
// One line on what's already decided for the project at cwd (src/decisions.mjs), or
|
|
60
|
+
// nothing when there's none: a session that would ask the same thing finds it first.
|
|
61
|
+
// Read straight from the file, as the primer loads no more of dibs than it must.
|
|
62
|
+
function decided(cwd) {
|
|
63
|
+
let list;
|
|
64
|
+
try { list = JSON.parse(fs.readFileSync(path.join(DIBS_HOME, 'decisions.json'), 'utf8')).decisions; } catch { return []; }
|
|
65
|
+
const key = projectKey(cwd || process.cwd());
|
|
66
|
+
const here = (Array.isArray(list) ? list : []).filter(d => d && !d.revoked && typeof d.text === 'string' && (d.project == null || d.project === key));
|
|
67
|
+
if (!here.length) return [];
|
|
68
|
+
// The person's own say more than an agent's two-way doors.
|
|
69
|
+
const d = here.filter(x => !x.byAgent).at(-1) || here.at(-1);
|
|
70
|
+
const said = `${d.text}${d.answer != null ? ` -> ${d.answer}` : ''}`.replace(/\s+/g, ' ');
|
|
71
|
+
const quote = said.length > QUOTE ? `${said.slice(0, QUOTE).replace(/\s+\S*$/, '')} ...` : said;
|
|
72
|
+
return [`- ${here.length} decision${here.length > 1 ? 's' : ''} already made for this project, latest "${quote}": see \`dibs decisions --project\` before asking.`];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// The lines of rules() a session hears at its start: what dibs is, how to wrap, the listener.
|
|
76
|
+
const START = [0, 1, 3];
|
|
77
|
+
// A subagent ends with its task, so it isn't told to keep a listener running. full: every rule at
|
|
78
|
+
// once, for tools whose hook can't add a line to an allowed call (Gemini CLI, Cursor, OpenCode, Codex).
|
|
79
|
+
export function primerText({ subagent = false, cwd, full = false } = {}) {
|
|
80
|
+
const all = rules();
|
|
81
|
+
const lines = full ? [...all, ...decided(cwd), ...peopleLine()] : all.filter((l, i) => START.includes(i));
|
|
82
|
+
return lines.filter(l => !(subagent && l.includes('dibs listen'))).join('\n');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// The rest of the rules, for an agent's first dibs command or its first heavy command the guard
|
|
86
|
+
// turned away: what it needs now that it uses dibs, and nothing it heard at the start.
|
|
87
|
+
export const firstUseText = ({ cwd } = {}) =>
|
|
88
|
+
['dibs, the first time you use it here:', ...rules().filter((l, i) => !START.includes(i)), ...decided(cwd), ...peopleLine()].join('\n');
|
|
44
89
|
|
|
45
90
|
// The rules as the skill and docs/reference.md carry them, between their markers, with the
|
|
46
91
|
// built-in resources (a machine's config adds its own; the primer names those).
|
|
@@ -62,6 +107,32 @@ export function writeRules(root = ROOT) {
|
|
|
62
107
|
}
|
|
63
108
|
|
|
64
109
|
|
|
110
|
+
// Who has heard firstUseText: "session|agent" keys, newest last. The hook reads it on each dibs
|
|
111
|
+
// call (src/guard.mjs toldFirstUse) and loads this module only for a key that isn't in it.
|
|
112
|
+
const FIRST_USE = path.join(DIBS_HOME, 'firstuse.json');
|
|
113
|
+
export const FIRST_USE_KEEP = 500;
|
|
114
|
+
|
|
115
|
+
// The hook's answer for a first dibs call: the rest of the rules added to it once. A call turned
|
|
116
|
+
// away carries them in its reason, which is all the agent reads of it; any other in additionalContext.
|
|
117
|
+
export function firstUse(input, out) {
|
|
118
|
+
const key = `${input.session_id}|${input.agent_id || 'main'}`;
|
|
119
|
+
let told = [];
|
|
120
|
+
try { told = JSON.parse(fs.readFileSync(FIRST_USE, 'utf8')); } catch {}
|
|
121
|
+
if (!Array.isArray(told)) told = [];
|
|
122
|
+
if (told.includes(key)) return out;
|
|
123
|
+
told.push(key);
|
|
124
|
+
try {
|
|
125
|
+
fs.mkdirSync(DIBS_HOME, { recursive: true });
|
|
126
|
+
fs.writeFileSync(`${FIRST_USE}.${process.pid}`, JSON.stringify(told.slice(-FIRST_USE_KEEP)));
|
|
127
|
+
fs.renameSync(`${FIRST_USE}.${process.pid}`, FIRST_USE);
|
|
128
|
+
} catch {}
|
|
129
|
+
const text = firstUseText({ cwd: input.cwd });
|
|
130
|
+
const h = out?.hookSpecificOutput;
|
|
131
|
+
if (h?.permissionDecision === 'deny') return { ...out, hookSpecificOutput: { ...h, permissionDecisionReason: `${h.permissionDecisionReason}\n\n${text}` } };
|
|
132
|
+
if (!h) return { hookSpecificOutput: { hookEventName: 'PreToolUse', additionalContext: text } };
|
|
133
|
+
return { ...out, hookSpecificOutput: { ...h, additionalContext: [h.additionalContext, text].filter(Boolean).join('\n\n') } };
|
|
134
|
+
}
|
|
135
|
+
|
|
65
136
|
// Each subagent hears it once: SubagentStart also fires every time an agent
|
|
66
137
|
// team teammate takes a new message. A short list of ids it was told, newest last.
|
|
67
138
|
const TOLD = path.join(DIBS_HOME, 'primed.json');
|
|
@@ -85,5 +156,5 @@ function firstTime(agentId) {
|
|
|
85
156
|
export function primer(input, out) {
|
|
86
157
|
const event = input.hook_event_name;
|
|
87
158
|
if (event === 'SubagentStart' && (typeof input.agent_id !== 'string' || !firstTime(input.agent_id))) return out;
|
|
88
|
-
return { ...out, hookSpecificOutput: { hookEventName: event, additionalContext: primerText({ subagent: event === 'SubagentStart' }) } };
|
|
159
|
+
return { ...out, hookSpecificOutput: { hookEventName: event, additionalContext: primerText({ subagent: event === 'SubagentStart', cwd: input.cwd }) } };
|
|
89
160
|
}
|
package/src/prints.mjs
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Fingerprints of the stored secrets' values (src/vault.mjs), so dibs can spot a value in a
|
|
2
|
+
// command, an edit, an event or a command's output without ever loading the values themselves.
|
|
3
|
+
// The guard reads only this one small file, and only when it exists (no secrets set: no cost).
|
|
4
|
+
//
|
|
5
|
+
// Each value is kept as its length, a keyed rolling hash (to find candidates in one pass over a
|
|
6
|
+
// text) and a salted SHA-256 cut to 64 bits (to confirm one). Both keys are random per machine.
|
|
7
|
+
// The file is the person's alone (0600). It does let someone who can read it test guesses
|
|
8
|
+
// offline, so a short, guessable value is weakly protected; docs/secrets.md says so.
|
|
9
|
+
// Values shorter than MIN_LEN aren't fingerprinted: they'd turn up by chance in ordinary text.
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import crypto from 'node:crypto';
|
|
13
|
+
import { HOME } from './config.mjs';
|
|
14
|
+
|
|
15
|
+
export const FILE = path.join(HOME, 'prints.json');
|
|
16
|
+
export const MIN_LEN = 8;
|
|
17
|
+
// A prime under 2^31: with a base under 2^16, every product stays exact in a double.
|
|
18
|
+
const MOD = 2147483647;
|
|
19
|
+
|
|
20
|
+
const confirm = (salt, s) => crypto.createHash('sha256').update(salt).update(s).digest('hex').slice(0, 16);
|
|
21
|
+
function rolling(s, base) {
|
|
22
|
+
let r = 0;
|
|
23
|
+
for (let i = 0; i < s.length; i++) r = (r * base + s.charCodeAt(i)) % MOD;
|
|
24
|
+
return r;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// The fingerprints for these values, { name: value }, with fresh keys. Written whole.
|
|
28
|
+
export function writePrints(values) {
|
|
29
|
+
const salt = crypto.randomBytes(16).toString('hex');
|
|
30
|
+
const base = 257 + crypto.randomInt(60000);
|
|
31
|
+
const prints = Object.entries(values).filter(([, v]) => typeof v === 'string' && v.length >= MIN_LEN)
|
|
32
|
+
.map(([name, v]) => ({ name, len: v.length, r: rolling(v, base), h: confirm(salt, v) }));
|
|
33
|
+
if (!prints.length) { fs.rmSync(FILE, { force: true }); cache = null; return; }
|
|
34
|
+
fs.mkdirSync(HOME, { recursive: true });
|
|
35
|
+
const tmp = `${FILE}.${process.pid}`;
|
|
36
|
+
fs.writeFileSync(tmp, JSON.stringify({ salt, base, prints }), { mode: 0o600 });
|
|
37
|
+
fs.renameSync(tmp, FILE);
|
|
38
|
+
cache = null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// The fingerprints as on disk, reread only when the file changes. null with none set.
|
|
42
|
+
let cache = null;
|
|
43
|
+
export function readPrints() {
|
|
44
|
+
let st;
|
|
45
|
+
try { st = fs.statSync(FILE); } catch { cache = null; return null; }
|
|
46
|
+
if (cache && cache.mtime === st.mtimeMs && cache.size === st.size) return cache.p;
|
|
47
|
+
try {
|
|
48
|
+
const p = JSON.parse(fs.readFileSync(FILE, 'utf8'));
|
|
49
|
+
if (!p || !Array.isArray(p.prints) || typeof p.salt !== 'string' || !Number.isInteger(p.base)) return null;
|
|
50
|
+
cache = { mtime: st.mtimeMs, size: st.size, p };
|
|
51
|
+
return p;
|
|
52
|
+
} catch { return null; }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Where stored values appear in text: [{ name, at, len }], left to right, not overlapping.
|
|
56
|
+
export function find(text, p = readPrints()) {
|
|
57
|
+
if (!p || typeof text !== 'string' || !text) return [];
|
|
58
|
+
const byLen = new Map();
|
|
59
|
+
for (const x of p.prints) {
|
|
60
|
+
if (!byLen.has(x.len)) byLen.set(x.len, new Map());
|
|
61
|
+
const m = byLen.get(x.len);
|
|
62
|
+
if (!m.has(x.r)) m.set(x.r, []);
|
|
63
|
+
m.get(x.r).push(x);
|
|
64
|
+
}
|
|
65
|
+
const hits = [];
|
|
66
|
+
for (const [len, want] of byLen) {
|
|
67
|
+
if (text.length < len) continue;
|
|
68
|
+
let pow = 1;
|
|
69
|
+
for (let i = 1; i < len; i++) pow = (pow * p.base) % MOD;
|
|
70
|
+
let r = rolling(text.slice(0, len), p.base);
|
|
71
|
+
for (let i = 0; ; i++) {
|
|
72
|
+
const c = want.get(r);
|
|
73
|
+
if (c) {
|
|
74
|
+
const h = confirm(p.salt, text.slice(i, i + len));
|
|
75
|
+
const x = c.find(y => y.h === h);
|
|
76
|
+
if (x) hits.push({ name: x.name, at: i, len });
|
|
77
|
+
}
|
|
78
|
+
if (i + len >= text.length) break;
|
|
79
|
+
r = (r - (text.charCodeAt(i) * pow) % MOD + MOD) % MOD;
|
|
80
|
+
r = (r * p.base + text.charCodeAt(i + len)) % MOD;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
hits.sort((a, b) => a.at - b.at || b.len - a.len);
|
|
84
|
+
const out = [];
|
|
85
|
+
for (const h of hits) if (!out.length || h.at >= out.at(-1).at + out.at(-1).len) out.push(h);
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// The names of the stored secrets whose values appear in any of these texts.
|
|
90
|
+
export const leaked = (...texts) => [...new Set(texts.flatMap(t => find(t).map(h => h.name)))];
|
|
91
|
+
|
|
92
|
+
// The text with every stored value in it replaced by [secret NAME].
|
|
93
|
+
export function redact(text, p = readPrints()) {
|
|
94
|
+
const hits = find(text, p);
|
|
95
|
+
if (!hits.length) return text;
|
|
96
|
+
let out = '', from = 0;
|
|
97
|
+
for (const h of hits) { out += text.slice(from, h.at) + `[secret ${h.name}]`; from = h.at + h.len; }
|
|
98
|
+
return out + text.slice(from);
|
|
99
|
+
}
|
package/src/proc.mjs
CHANGED
|
@@ -111,7 +111,7 @@ export function sessionFiles() {
|
|
|
111
111
|
for (const n of names) {
|
|
112
112
|
try {
|
|
113
113
|
const x = sessionFile(path.join(SESSIONS, n));
|
|
114
|
-
if (x.pid && x.sessionId) out.push({ pid: x.pid, sessionId: x.sessionId, name: x.name || null, status: typeof x.status === 'string' ? x.status : null, updated: x.statusUpdatedAt || x.updatedAt || 0 });
|
|
114
|
+
if (x.pid && x.sessionId) out.push({ pid: x.pid, sessionId: x.sessionId, name: x.name || null, status: typeof x.status === 'string' ? x.status : null, cwd: typeof x.cwd === 'string' ? x.cwd : null, started: typeof x.startedAt === 'number' ? x.startedAt : null, updated: x.statusUpdatedAt || x.updatedAt || 0 });
|
|
115
115
|
} catch {}
|
|
116
116
|
}
|
|
117
117
|
return out;
|
package/src/progress.mjs
CHANGED
|
@@ -12,8 +12,9 @@ import fs from 'node:fs';
|
|
|
12
12
|
import path from 'node:path';
|
|
13
13
|
import { HOME } from './config.mjs';
|
|
14
14
|
import { identity, sessionFiles } from './proc.mjs';
|
|
15
|
-
import { die, now, deadline, dur, clock } from './util.mjs';
|
|
15
|
+
import { die, now, deadline, dur, clock, codexThread, say } from './util.mjs';
|
|
16
16
|
import { bold, dim } from './style.mjs';
|
|
17
|
+
import { looksLike, parse as parseDone, note, WRITE_GAP, MAX_UNIT } from './jobprogress.mjs';
|
|
17
18
|
|
|
18
19
|
export const FILE = path.join(HOME, 'progress.jsonl');
|
|
19
20
|
const OLDER = path.join(HOME, 'progress.1.jsonl');
|
|
@@ -42,6 +43,7 @@ function parse(args) {
|
|
|
42
43
|
else if (a === '--eta') o.eta = val();
|
|
43
44
|
else if (a === '--done') o.state = 'done';
|
|
44
45
|
else if (a === '--blocked') o.state = 'blocked';
|
|
46
|
+
else if (a === '--job') o.job = val();
|
|
45
47
|
else if (a === '--as') o.as = val();
|
|
46
48
|
else if (a === '--agent') o.agent = val();
|
|
47
49
|
else if (a === '-n') o.n = Number(val());
|
|
@@ -73,6 +75,12 @@ function branch(dir) {
|
|
|
73
75
|
|
|
74
76
|
export async function post(args) {
|
|
75
77
|
const o = parse(args);
|
|
78
|
+
// How far a job is (src/jobprogress.mjs): dibs progress 40% inside a dibs run, or --job <id> from anywhere.
|
|
79
|
+
// Inside a run, words or --task, --eta, --done or --blocked still post an agent's progress, as before.
|
|
80
|
+
const inJob = process.env.DIBS_LEASE && !o.task && !o.state && !o.eta && looksLike(o.words[0]);
|
|
81
|
+
if (o.job != null || inJob) return job(o, o.job ?? process.env.DIBS_LEASE, o.job != null);
|
|
82
|
+
if (o.words.length === 1 && looksLike(o.words[0]))
|
|
83
|
+
die(`dibs progress ${o.words[0]} says how far a job is, from inside it (dibs run sets DIBS_LEASE there). From outside, name the job: dibs progress ${o.words[0]} --job <id> (dibs mine lists yours). Nothing was posted.`, 2);
|
|
76
84
|
// dibs progress list: the open tasks. One word "list" is the command, never a post (2026-11-03: crews kept typing it).
|
|
77
85
|
if (o.words.length === 1 && o.words[0] === 'list' && !o.task && !o.state && !o.eta) return openTasks(o);
|
|
78
86
|
if (o.all) die('--all goes with dibs progress list');
|
|
@@ -97,15 +105,22 @@ export async function post(args) {
|
|
|
97
105
|
const p = {
|
|
98
106
|
at: now(), who: id.who, ...((id.label || by?.agentType) && { label: id.label || by.agentType }), ...(session && { session }),
|
|
99
107
|
...(by?.agentId && by.agentId !== 'main' && { agentId: by.agentId }),
|
|
108
|
+
...(codexThread() && { codex: codexThread() }),
|
|
100
109
|
project: path.basename(where.root || process.cwd()), ...(where.branch && { branch: where.branch }),
|
|
101
110
|
...(o.task && { task: o.task }), state: o.state || 'doing', ...(eta && { eta }), text: o.text,
|
|
102
111
|
};
|
|
112
|
+
// With two or more people, whose agent posted: their phone hears when it's done or stuck.
|
|
113
|
+
const { readPeople, several, ownerOf } = await import('./people.mjs');
|
|
114
|
+
const people = readPeople();
|
|
115
|
+
if (several(people)) { const owner = ownerOf({ p: people })?.name; if (owner) p.owner = owner; }
|
|
103
116
|
fs.mkdirSync(HOME, { recursive: true });
|
|
104
117
|
fs.appendFileSync(FILE, `${JSON.stringify(p)}\n`);
|
|
105
118
|
rotate();
|
|
106
119
|
// "done by" read as done to agents; and a closing post needs no nudge to keep posting.
|
|
107
|
-
if (p.state !== 'doing')
|
|
108
|
-
console.log(`Posted${o.task ? ` to ${o.task}` : ''}${eta ? `, expected by ${clock(eta)}` : ''}. Keep posting as you go: dibs progress "..."`);
|
|
120
|
+
if (p.state !== 'doing') console.log(`Posted${o.task ? ` to ${o.task}` : ''}, marked ${p.state}.`);
|
|
121
|
+
else console.log(`Posted${o.task ? ` to ${o.task}` : ''}${eta ? `, expected by ${clock(eta)}` : ''}. Keep posting as you go: dibs progress "..."`);
|
|
122
|
+
// A post under a work item's id (w3) is that item's log, and closes or blocks it (src/work.mjs).
|
|
123
|
+
if (/^[wh]\d+$/i.test(p.task || '')) (await import('./work.mjs')).fromProgress(p);
|
|
109
124
|
}
|
|
110
125
|
|
|
111
126
|
function rotate() {
|
|
@@ -129,6 +144,34 @@ export function read({ since = 0, agent = null, limit = Infinity } = {}) {
|
|
|
129
144
|
return Number.isFinite(limit) ? out.slice(-limit) : out;
|
|
130
145
|
}
|
|
131
146
|
|
|
147
|
+
// dibs progress 40% | 1200/9000 ["what's counted"] [--job <id>]: put how far a running job is
|
|
148
|
+
// on its lease. Quiet inside the job, which may report in a loop; said back when named with --job.
|
|
149
|
+
// A loop reporting faster than WRITE_GAP has its in-between readings skipped, not written.
|
|
150
|
+
async function job(o, which, named) {
|
|
151
|
+
if (o.task || o.state || o.eta) die('--job goes with how far the job is (dibs progress 40% --job 12), not with --task, --eta, --done or --blocked. Nothing was recorded.');
|
|
152
|
+
const id = Number(String(which).replace(/^#/, ''));
|
|
153
|
+
if (!Number.isInteger(id) || id <= 0) die(`--job takes a job number from the board, like --job 42 (dibs mine lists yours), not ${which}. Nothing was recorded.`);
|
|
154
|
+
const [spec, ...rest] = o.words;
|
|
155
|
+
const p = parseDone(spec);
|
|
156
|
+
if (!p) die(`say how far the job is as a percent up to 100 or a count: dibs progress 40%, or dibs progress 1200/9000 "flops solved"${spec ? `, not ${spec}` : ''}. Nothing was recorded.`);
|
|
157
|
+
const unit = rest.join(' ').replace(/[\u0000-\u001f\u007f]/g, ' ').replace(/\s+/g, ' ').trim().slice(0, MAX_UNIT);
|
|
158
|
+
if (unit) p.unit = unit;
|
|
159
|
+
const { peek, withStateIfRoom } = await import('./state.mjs');
|
|
160
|
+
const t = now();
|
|
161
|
+
const was = (peek().leases || []).find(l => l.id === id && l.kind === 'run');
|
|
162
|
+
const skip = was?.progress?.src === 'job' && t - was.progress.at < WRITE_GAP && p.pct < 100 && Math.abs(p.pct - was.progress.pct) < 1;
|
|
163
|
+
const r = skip ? 'ok' : withStateIfRoom(s => {
|
|
164
|
+
const l = s.leases.find(x => x.id === id && x.kind === 'run');
|
|
165
|
+
if (!l) return 'gone';
|
|
166
|
+
note(l, p, t, 'job');
|
|
167
|
+
return 'ok';
|
|
168
|
+
});
|
|
169
|
+
// Never fails the job over a full disk: its progress is worth less than its work.
|
|
170
|
+
if (r === undefined) return say('the disk is full, so this progress went unrecorded. The job carries on.');
|
|
171
|
+
if (r === 'gone') die(`job #${id} isn't running here (it may have ended, or it's a hold). Nothing was recorded. dibs mine lists your running jobs.`, 1);
|
|
172
|
+
if (named) console.log(`#${id}: ${Math.floor(p.pct)}% done${p.total != null ? `, ${p.done}/${p.total}${unit ? ` ${unit}` : ''}` : ''}. The board shows it, with a time left once it has a rate.`);
|
|
173
|
+
}
|
|
174
|
+
|
|
132
175
|
// Each agent's tasks, from its posts: the latest word on each, when it started,
|
|
133
176
|
// and when it should end. A post without --task belongs to the agent's
|
|
134
177
|
// untitled task in that project. One still doing past its ETA is overdue; one
|
|
@@ -141,9 +184,12 @@ export function tasks(posts, at = now()) {
|
|
|
141
184
|
let t = by.get(key);
|
|
142
185
|
if (!t) by.set(key, t = { who: p.who, label: p.label || null, ...(p.agentId && { agentId: p.agentId }), task: p.task || null, project: p.project || null, branch: p.branch || null, started: p.at, posts: 0 });
|
|
143
186
|
Object.assign(t, { last: p.at, state: p.state, text: p.text, branch: p.branch || t.branch, project: p.project || t.project, session: p.session || t.session || null });
|
|
187
|
+
if (p.owner) t.owner = p.owner;
|
|
144
188
|
if (p.eta) t.eta = p.eta;
|
|
145
189
|
if (p.state === 'doing' && t.state === 'doing' && t.doneAt) delete t.doneAt;
|
|
146
190
|
if (p.state === 'done') t.doneAt = p.at;
|
|
191
|
+
// Closed by dibs, not its agent (src/notices.mjs: a subagent that ended with it open): not news of work done.
|
|
192
|
+
if (p.by === 'dibs') t.closedBy = 'dibs'; else delete t.closedBy;
|
|
147
193
|
t.posts++;
|
|
148
194
|
}
|
|
149
195
|
for (const k of by.values()) {
|
package/src/proof.mjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Proof that a work item is done, from what dibs can check for itself rather than the agent's
|
|
2
|
+
// word: the last run of the agent's that passed since it took the item (events.jsonl), and a
|
|
3
|
+
// commit that exists in the repo (asked of git). A URL or a build number the agent names is kept
|
|
4
|
+
// too, marked as its word, since dibs can't check it.
|
|
5
|
+
//
|
|
6
|
+
// A proof is { at, items: [...] }, each item { kind, checked, at?, ... }: kind run, commit, url or
|
|
7
|
+
// build, and checked true only for what dibs verified. The finders below are the places it
|
|
8
|
+
// looks; a record of milestones kept as they happen (commits, runs, deploys) can be one more
|
|
9
|
+
// finder, and every reader (the page, the phone, dibs recap) shows its items without change.
|
|
10
|
+
import { execFileSync } from 'node:child_process';
|
|
11
|
+
import { readEvents } from './events.mjs';
|
|
12
|
+
import { now, clock, die } from './util.mjs';
|
|
13
|
+
|
|
14
|
+
// git answers in milliseconds; past this it's stuck on something (a lock, a slow disk) and the
|
|
15
|
+
// commit is left out rather than holding the close up.
|
|
16
|
+
const GIT_WAIT = 5000;
|
|
17
|
+
// A sha, a tag or a branch name: never one that starts with -, which git would read as a flag.
|
|
18
|
+
const REF = /^[\w./][\w./-]{0,99}$/;
|
|
19
|
+
|
|
20
|
+
function git(cwd, args) {
|
|
21
|
+
try { return execFileSync('git', ['-C', cwd, ...args], { encoding: 'utf8', timeout: GIT_WAIT, stdio: ['ignore', 'pipe', 'ignore'] }).trim(); }
|
|
22
|
+
catch { return null; }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// The commit a name stands for in the repo at cwd, or null when there's none: { sha, at, subject }.
|
|
26
|
+
export function commitOf(cwd, ref) {
|
|
27
|
+
const out = git(cwd, ['log', '-1', '--format=%H%x00%ct%x00%s', `${ref}^{commit}`, '--']);
|
|
28
|
+
if (!out) return null;
|
|
29
|
+
const [sha, ct, subject] = out.split('\0');
|
|
30
|
+
return { sha, at: Number(ct) * 1000, subject: (subject || '').slice(0, 120) };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// The newest run of who's that passed since `since`, preferring a test suite. Only the last run on
|
|
34
|
+
// each resource counts: a suite that passed and then failed proves nothing, even run another way.
|
|
35
|
+
function passedRun({ who, since, t, events }) {
|
|
36
|
+
if (!who) return null;
|
|
37
|
+
const last = new Map();
|
|
38
|
+
for (const e of events) {
|
|
39
|
+
if (e.kind !== 'end' || e.type !== 'run' || e.who !== who || e.at < since || e.at > t) continue;
|
|
40
|
+
last.set((e.res || []).join(','), e);
|
|
41
|
+
}
|
|
42
|
+
const passed = [...last.values()].filter(e => e.code === 0).sort((a, b) => b.at - a.at);
|
|
43
|
+
const e = passed.find(e => (e.res || []).includes('test')) || passed[0];
|
|
44
|
+
return e && { kind: 'run', checked: true, at: e.at, res: e.res || [], what: e.purpose || e.cmd || null, job: e.id ?? null };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// HEAD of the repo the agent closes from, when it was committed after the item was taken.
|
|
48
|
+
function headCommit({ since, cwd }) {
|
|
49
|
+
const c = cwd && commitOf(cwd, 'HEAD');
|
|
50
|
+
return c && c.at >= since - CLOCK_SLACK ? { kind: 'commit', checked: true, ...c } : null;
|
|
51
|
+
}
|
|
52
|
+
// git keeps commit times in whole seconds, and a commit can land in the second an item was taken.
|
|
53
|
+
const CLOCK_SLACK = 1000;
|
|
54
|
+
|
|
55
|
+
const FINDERS = [passedRun, headCommit];
|
|
56
|
+
|
|
57
|
+
// The proof for an item taken at `since` by the agent `who`, closed now from cwd. commit, url and
|
|
58
|
+
// build are what the agent named; a commit it names that git doesn't have stops the close
|
|
59
|
+
// (exit 1), since a proof that points nowhere is worse than none.
|
|
60
|
+
export function gather({ who, since = 0, t = now(), cwd = process.cwd(), commit, url, build, events } = {}) {
|
|
61
|
+
const items = [];
|
|
62
|
+
if (commit) {
|
|
63
|
+
const c = REF.test(commit) ? commitOf(cwd, commit) : null;
|
|
64
|
+
if (!c) die(`git has no commit ${commit} in ${cwd}. Nothing was closed: name a commit that exists there (git log), or leave out --commit.`, 1);
|
|
65
|
+
items.push({ kind: 'commit', checked: true, ...c });
|
|
66
|
+
}
|
|
67
|
+
const ctx = { who, since, t, cwd, events: events || readEvents(t).filter(e => e.at >= since) };
|
|
68
|
+
for (const find of FINDERS) {
|
|
69
|
+
const x = find(ctx);
|
|
70
|
+
if (x && !(x.kind === 'commit' && items.some(i => i.kind === 'commit'))) items.push(x);
|
|
71
|
+
}
|
|
72
|
+
if (url) items.push({ kind: 'url', checked: false, url: String(url).slice(0, 300) });
|
|
73
|
+
if (build) items.push({ kind: 'build', checked: false, build: String(build).slice(0, 80) });
|
|
74
|
+
return { at: t, items };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// The proof for a progress task, worked out when it's read: progress posts take no lock, so a
|
|
78
|
+
// task closed with dibs progress --done carries only what the event log shows.
|
|
79
|
+
export const runProof = ({ who, since, t, events }) => {
|
|
80
|
+
const r = passedRun({ who, since, t, events });
|
|
81
|
+
return { at: t, items: r ? [r] : [] };
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const runName = i => ((i.res || []).includes('test') ? 'suite' : (i.res || []).join(',') || 'run');
|
|
85
|
+
const itemText = i => i.kind === 'run' ? `${runName(i)} passed ${clock(i.at)}`
|
|
86
|
+
: i.kind === 'commit' ? `commit ${i.sha.slice(0, 7)}`
|
|
87
|
+
: i.kind === 'url' ? i.url : `build ${i.build}`;
|
|
88
|
+
|
|
89
|
+
// "proved by: suite passed 12:04, commit 1a2b3c4", or "no proof": how a done item reads everywhere.
|
|
90
|
+
export function proofLine(p) {
|
|
91
|
+
const items = Array.isArray(p?.items) ? p.items : [];
|
|
92
|
+
const checked = items.filter(i => i.checked), named = items.filter(i => !i.checked);
|
|
93
|
+
const word = named.length ? `${named.map(itemText).join(', ')}, on the agent's word` : '';
|
|
94
|
+
if (!checked.length) return named.length ? `no proof dibs could check (${word})` : 'no proof';
|
|
95
|
+
return `proved by: ${checked.map(itemText).join(', ')}${word ? `; ${word}` : ''}`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// The proof as the page, the phone and --json read it.
|
|
99
|
+
export const proofView = p => {
|
|
100
|
+
const items = Array.isArray(p?.items) ? p.items : [];
|
|
101
|
+
return { proved: items.some(i => i.checked), line: proofLine(p), items };
|
|
102
|
+
};
|