@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/files.mjs
CHANGED
|
@@ -374,7 +374,7 @@ export function elsewhere(l, cwd = cwdNow()) {
|
|
|
374
374
|
} catch { return ''; }
|
|
375
375
|
}
|
|
376
376
|
|
|
377
|
-
const expand = p => (p === '~' || p.startsWith('~/') ? os.homedir() + p.slice(1) : p);
|
|
377
|
+
export const expand = p => (p === '~' || p.startsWith('~/') ? os.homedir() + p.slice(1) : p);
|
|
378
378
|
|
|
379
379
|
// files:<path or glob> as stored: absolute, relative paths taken from the git
|
|
380
380
|
// root (or the folder, outside git), and in the main worktree (canon). Null
|
|
@@ -482,8 +482,9 @@ const running = pid => { try { process.kill(pid, 0); return true; } catch (e) {
|
|
|
482
482
|
|
|
483
483
|
// Live file leases, read without the lock: state.json is replaced by rename,
|
|
484
484
|
// so a read sees a whole file. A dead holder or a hold past its time no longer
|
|
485
|
-
// counts, though only the next dibs call takes it off the books.
|
|
486
|
-
|
|
485
|
+
// counts, though only the next dibs call takes it off the books. Work items read them too
|
|
486
|
+
// (src/work.mjs), to skip work whose files another agent is editing.
|
|
487
|
+
export function leases(t = Date.now()) {
|
|
487
488
|
let s;
|
|
488
489
|
try { s = JSON.parse(fs.readFileSync(statePath(), 'utf8')); } catch (e) { if (e.code === 'ENOENT') return []; throw e; }
|
|
489
490
|
return (s.leases || []).filter(l => Array.isArray(l.res) && l.res.some(isFiles)
|
|
@@ -839,7 +840,7 @@ function redirWrites(src, w) {
|
|
|
839
840
|
// a ( ) subshell ends with it. After a cd we can't follow, the folder is null
|
|
840
841
|
// and only absolute paths are known. A command run by xargs also gets the
|
|
841
842
|
// words of the command piped into it, which is where its files come from.
|
|
842
|
-
function* commands(segs, cwd) {
|
|
843
|
+
export function* commands(segs, cwd) {
|
|
843
844
|
let dir = cwd, last = null, depth = 0, prev = null; // last: where cd - goes
|
|
844
845
|
const outer = [], pushed = [], vars = {};
|
|
845
846
|
for (const seg of segs) {
|
|
@@ -939,7 +940,7 @@ const ALIASES = { done: 'release', renew: 'hold', ls: 'status', board: 'status'
|
|
|
939
940
|
// their own. A word the hook can't read ($VAR) matches any one word.
|
|
940
941
|
// Every other call is keyed the same way, by all its words, so two subagents
|
|
941
942
|
// running `dibs run sim -- ...` at once each claim their own note.
|
|
942
|
-
const TALK_VERBS = new Set(['say', 'question', 'later', 'progress', 'listen']);
|
|
943
|
+
const TALK_VERBS = new Set(['say', 'question', 'later', 'progress', 'listen', 'disk']);
|
|
943
944
|
export const talkKey = (verb, words) => `${verb}|${words.join('\0')}`;
|
|
944
945
|
// A word the hook can't read ("files:$R/a.ts", $(...)) stands for any one word.
|
|
945
946
|
const WILD = '\u0001';
|
|
@@ -1079,9 +1080,120 @@ export function fileGuard(input, split) {
|
|
|
1079
1080
|
permissionDecisionReason: `dibs: ${short(FILES + p, cwd).slice(FILES.length)} is leased to ${holder}${elsewhere(l, cwd)}${l.label && l.label !== name ? ` (${l.label})` : ''}`
|
|
1080
1081
|
+ `${l.purpose ? ` for "${l.purpose}"` : ''} (${short(r, cwd)}, held ${dur(t - l.start)}, ${until}), so ${target.why} can't write to it now.\n`
|
|
1081
1082
|
+ `See when it frees up: dibs when ${shellRes(short(r, cwd))}\n`
|
|
1082
|
-
+ `Wait for it and take it yourself: dibs hold ${shellRes(short(r, cwd))} -m "
|
|
1083
|
+
+ `Wait for it and take it yourself: dibs hold ${shellRes(short(r, cwd))} -m "what you'll change there". ${ask} Reading it is fine.`,
|
|
1083
1084
|
} };
|
|
1084
1085
|
}
|
|
1085
1086
|
}
|
|
1086
1087
|
return null;
|
|
1087
1088
|
}
|
|
1089
|
+
|
|
1090
|
+
// ----- shared output folders -----
|
|
1091
|
+
// A file lease keeps other agents' guarded writes out, but only if someone takes it. An old web
|
|
1092
|
+
// agent's preview server once wrote into a folder another agent kept its screenshots in, and
|
|
1093
|
+
// deleted them; neither had held it. So the hook keeps a short note of which agent wrote into
|
|
1094
|
+
// which folder lately (writers.json, a few kilobytes), and a Bash command that writes or deletes
|
|
1095
|
+
// in a folder another agent wrote into within WRITER_LIFE hears who, with the hold that makes
|
|
1096
|
+
// them take turns. Only a nudge, never a refusal: the other agent may be done there. One read of
|
|
1097
|
+
// that file per call, and a write only when this agent's own note there is new or stale.
|
|
1098
|
+
const writersPath = () => path.join(dibsHome(), 'writers.json');
|
|
1099
|
+
// A writer silent this long has likely moved on.
|
|
1100
|
+
const WRITER_LIFE = 15 * 6e4;
|
|
1101
|
+
// The same agent hears about the same folder and writer at most this often.
|
|
1102
|
+
const WRITER_AGAIN = 30 * 6e4;
|
|
1103
|
+
// An agent's own note in a folder is rewritten at most this often for files it already named there.
|
|
1104
|
+
const WRITER_NOTE = 60e3;
|
|
1105
|
+
const WRITER_FOLDERS = 300, WRITER_FILES = 6;
|
|
1106
|
+
const REMOVERS = new Set(['rm', 'rmdir', 'unlink', 'shred', 'find', 'truncate', 'git clean']);
|
|
1107
|
+
|
|
1108
|
+
// Folders where everyone's files mix by design: a note there would fire on every temp file.
|
|
1109
|
+
function common(dir) {
|
|
1110
|
+
const h = os.homedir();
|
|
1111
|
+
if (dir === '/' || dir === h || path.dirname(dir) === '/' || dir === dibsHome() || dir.startsWith(dibsHome() + '/')) return true;
|
|
1112
|
+
if (['/tmp', '/private/tmp', '/var/tmp', '/private/var/tmp', os.tmpdir(), real(os.tmpdir())].includes(dir)) return true;
|
|
1113
|
+
// Claude Code's temp folders are each session's own, and the person's rule already guards them (tmpGuard).
|
|
1114
|
+
return claudeTmp().some(r => dir === r || dir.startsWith(r + '/'));
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
// The words for the hook to add to this call, or null. Edits are noted, never nudged: the nudge is
|
|
1118
|
+
// for commands, whose writes (a server's output, a cleanup) an agent can't see file by file.
|
|
1119
|
+
export function sharedNudge(input, split) {
|
|
1120
|
+
if (!EDITS.has(input?.tool_name) && input?.tool_name !== 'Bash') return null;
|
|
1121
|
+
if (typeof input.session_id !== 'string' || !input.session_id) return null;
|
|
1122
|
+
const me = `${input.session_id}|${agentOf(input)}`;
|
|
1123
|
+
const written = targets(input, split).filter(x => x.guess == null && x.path);
|
|
1124
|
+
if (!written.length) return null;
|
|
1125
|
+
const t = Date.now();
|
|
1126
|
+
let book = {};
|
|
1127
|
+
try { book = JSON.parse(fs.readFileSync(writersPath(), 'utf8')); } catch {}
|
|
1128
|
+
const dirs = book.dirs || {}, told = book.told || {};
|
|
1129
|
+
let changed = false;
|
|
1130
|
+
const hits = [];
|
|
1131
|
+
for (const x of written) {
|
|
1132
|
+
const p = canon(real(x.path));
|
|
1133
|
+
const gone = REMOVERS.has(x.why) || x.recursive;
|
|
1134
|
+
const g = p.search(GLOB);
|
|
1135
|
+
// What it touches: a deleted folder and all under it, a glob's folder, or a file's folder.
|
|
1136
|
+
const dir = g >= 0 ? p.slice(0, g).replace(/\/[^/]*$/, '') : gone && x.recursive ? p : path.dirname(p);
|
|
1137
|
+
if (!dir || common(dir)) continue;
|
|
1138
|
+
const under = gone && x.recursive && g < 0 ? f => f === dir || f.startsWith(dir + '/') : f => f === dir;
|
|
1139
|
+
if (input.tool_name === 'Bash') {
|
|
1140
|
+
for (const [f, ws] of Object.entries(dirs)) {
|
|
1141
|
+
if (!under(f)) continue;
|
|
1142
|
+
for (const [k, w] of Object.entries(ws)) {
|
|
1143
|
+
const key = `${me}>${k}@${f}`;
|
|
1144
|
+
if (k === me || t - w.at >= WRITER_LIFE || t - (told[key] || 0) < WRITER_AGAIN || hits.some(h => h.k === k && h.f === f)) continue;
|
|
1145
|
+
hits.push({ f, k, w, gone });
|
|
1146
|
+
told[key] = t;
|
|
1147
|
+
changed = true;
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
if (gone) continue;
|
|
1152
|
+
const name = path.basename(p);
|
|
1153
|
+
const mine = (dirs[dir] ||= {})[me];
|
|
1154
|
+
if (mine && t - mine.at < WRITER_NOTE && mine.files?.includes(name)) continue;
|
|
1155
|
+
dirs[dir][me] = { at: t, ...(input.agent_type && { label: String(input.agent_type).slice(0, 40) }), files: [name, ...(mine?.files || []).filter(n => n !== name)].slice(0, WRITER_FILES) };
|
|
1156
|
+
changed = true;
|
|
1157
|
+
}
|
|
1158
|
+
if (changed) {
|
|
1159
|
+
// Old notes go, and the oldest folders past WRITER_FOLDERS, so the file stays a few kilobytes.
|
|
1160
|
+
const keep = Object.entries(dirs).map(([f, ws]) => [f, Object.fromEntries(Object.entries(ws).filter(([, w]) => t - w.at < WRITER_LIFE))])
|
|
1161
|
+
.filter(([, ws]) => Object.keys(ws).length).sort((a, b) => Math.max(...Object.values(b[1]).map(w => w.at)) - Math.max(...Object.values(a[1]).map(w => w.at))).slice(0, WRITER_FOLDERS);
|
|
1162
|
+
const toldKept = Object.fromEntries(Object.entries(told).filter(([, at]) => t - at < WRITER_AGAIN));
|
|
1163
|
+
// Best effort: a full disk or two hooks at once cost a note, never the call.
|
|
1164
|
+
try {
|
|
1165
|
+
fs.mkdirSync(dibsHome(), { recursive: true });
|
|
1166
|
+
const tmp = `${writersPath()}.${process.pid}.tmp`;
|
|
1167
|
+
fs.writeFileSync(tmp, JSON.stringify({ dirs: Object.fromEntries(keep), told: toldKept }));
|
|
1168
|
+
fs.renameSync(tmp, writersPath());
|
|
1169
|
+
} catch {}
|
|
1170
|
+
}
|
|
1171
|
+
if (!hits.length) return null;
|
|
1172
|
+
const cwd = canon(real(typeof input.cwd === 'string' ? slash(input.cwd) : cwdNow()));
|
|
1173
|
+
const h = hits[0];
|
|
1174
|
+
const [sid, agent] = h.k.split('|');
|
|
1175
|
+
const who = writerName(sid, agent, h.w.label, input.session_id);
|
|
1176
|
+
const others = hits.length > 1 ? ` (and ${hits.length - 1} more agent${hits.length > 2 ? 's' : ''} or folder${hits.length > 2 ? 's' : ''})` : '';
|
|
1177
|
+
const shownDir = short(FILES + h.f, cwd).slice(FILES.length);
|
|
1178
|
+
return `dibs: ${who} wrote into ${shownDir} ${t - h.w.at < 6e4 ? 'just now' : `${dur(t - h.w.at)} ago`} (${h.w.files.slice(0, 3).join(', ')})${others}, and this command ${h.gone ? 'deletes' : 'writes'} there, so it may take or overwrite that agent's files. `
|
|
1179
|
+
+ `If you share the folder, take turns: dibs hold ${shellRes(short(FILES + h.f + '/**', cwd))} -m "what you'll write there", or ask them. Or use a folder of your own.`;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
// Another agent as the nudge names it: its session's name from Claude Code's records, read only now.
|
|
1183
|
+
function writerName(sid, agent, label, mine) {
|
|
1184
|
+
let name = null;
|
|
1185
|
+
try {
|
|
1186
|
+
const dir = process.env.DIBS_SESSIONS || path.join(os.homedir(), '.claude', 'sessions');
|
|
1187
|
+
for (const n of fs.readdirSync(dir)) {
|
|
1188
|
+
if (!n.endsWith('.json')) continue;
|
|
1189
|
+
const text = fs.readFileSync(path.join(dir, n), 'utf8');
|
|
1190
|
+
if (!text.includes(`"${sid}"`)) continue;
|
|
1191
|
+
name = JSON.parse(text).name || null;
|
|
1192
|
+
break;
|
|
1193
|
+
}
|
|
1194
|
+
} catch {}
|
|
1195
|
+
const sub = agent !== 'main' ? `subagent ${label || agent}` : null;
|
|
1196
|
+
if (sid === mine) return sub ? `another agent of your session (${sub})` : 'your main thread';
|
|
1197
|
+
const base = name || `session ${sid.slice(0, 8)}`;
|
|
1198
|
+
return sub ? `${base}'s ${sub}` : base;
|
|
1199
|
+
}
|