arbiterdesign 0.1.8 → 0.1.9

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/dist/index.js CHANGED
@@ -13,17 +13,21 @@ const export_1 = require("./commands/export");
13
13
  const publish_1 = require("./commands/publish");
14
14
  const unpublish_1 = require("./commands/unpublish");
15
15
  const rename_1 = require("./commands/rename");
16
+ const areas_1 = require("./commands/areas");
16
17
  const pull_1 = require("./commands/pull");
17
18
  const snapshot_1 = require("./commands/snapshot");
18
19
  const setup_1 = require("./commands/setup");
19
20
  const rules_1 = require("./commands/rules");
20
21
  const init_1 = require("./commands/init");
21
22
  const review_1 = require("./commands/review");
23
+ const handoff_1 = require("./handoff");
22
24
  const update_1 = require("./commands/update");
23
25
  const remove_1 = require("./commands/remove");
24
26
  const autopublish_1 = require("./autopublish");
25
27
  const hosted_1 = require("./hosted");
26
28
  const store_1 = require("./store");
29
+ const hook_1 = require("./hook");
30
+ const lock_1 = require("./lock");
27
31
  const program = new commander_1.Command();
28
32
  program
29
33
  .name('arbiter')
@@ -43,7 +47,7 @@ program
43
47
  .option('--as <action>', 'judge a pending id: accept | rule | skip | fix; answer a request id: apply | decline')
44
48
  .option('--request <id>', 'the approved request (R-0001) this change was made for — recording it applies the request')
45
49
  .option('--all', 'with --as: judge every pending item the same way')
46
- .option('--level <level>', 'with --all: only this level (feature | pattern | polish)')
50
+ .option('--level <level>', 'with --all: only this level (feature | pattern)')
47
51
  .option('--trigger <text>', 'with --all: only items queued for this piece of work')
48
52
  .option('--to <decision>', 'with --as fix: what it should be instead; with --reword: the new wording; with a request and --as apply: what to do instead of what was asked')
49
53
  .option('--supersedes <id>', 'the active rule this one replaces')
@@ -55,13 +59,13 @@ program
55
59
  .action(async (arg, opts) => {
56
60
  let result;
57
61
  if (opts.retire) {
58
- result = (0, record_1.retire)(opts.retire, opts.why, opts);
62
+ result = locked(opts.cwd, () => (0, record_1.retire)(opts.retire, opts.why, opts));
59
63
  }
60
64
  else if (opts.reword) {
61
- result = (0, record_1.reword)(opts.reword, opts.to, opts);
65
+ result = locked(opts.cwd, () => (0, record_1.reword)(opts.reword, opts.to, opts));
62
66
  }
63
67
  else if (opts.findings) {
64
- result = (0, record_1.queueFindings)(opts.findings, opts);
68
+ result = locked(opts.cwd, () => (0, record_1.queueFindings)(opts.findings, opts));
65
69
  }
66
70
  else if (opts.all) {
67
71
  const as = opts.as;
@@ -69,7 +73,7 @@ program
69
73
  result = { exitCode: 1, output: { status: 'invalid', errors: ['--all needs --as accept | rule | skip'] } };
70
74
  }
71
75
  else {
72
- result = (0, record_1.judgeAll)({ ...opts, as });
76
+ result = locked(opts.cwd, () => (0, record_1.judgeAll)({ ...opts, as }));
73
77
  }
74
78
  }
75
79
  else if (arg && /^P-\d{4,}$/.test(arg)) {
@@ -78,7 +82,7 @@ program
78
82
  result = { exitCode: 1, output: { status: 'invalid', errors: ['judging a pending id needs --as accept | rule | skip | fix'] } };
79
83
  }
80
84
  else {
81
- result = (0, record_1.judge)(arg, { ...opts, as });
85
+ result = locked(opts.cwd, () => (0, record_1.judge)(arg, { ...opts, as }));
82
86
  }
83
87
  }
84
88
  else if (arg && /^R-\d{4,}$/.test(arg)) {
@@ -87,7 +91,7 @@ program
87
91
  result = { exitCode: 1, output: { status: 'invalid', errors: ['answering a request needs --as apply (Apply, but…: add --to "<instead>") | decline --why "<reason>"'] } };
88
92
  }
89
93
  else {
90
- result = (0, request_1.judgeRequest)(arg, { ...opts, as });
94
+ result = locked(opts.cwd, () => (0, request_1.judgeRequest)(arg, { ...opts, as }));
91
95
  }
92
96
  }
93
97
  else {
@@ -98,7 +102,7 @@ program
98
102
  process.stdout.write(JSON.stringify({ status: 'invalid', errors: ['no input — pass JSON as an argument or on stdin'] }, null, 2) + '\n');
99
103
  process.exit(1);
100
104
  }
101
- result = opts.pending ? (0, record_1.queue)(input, opts) : (0, record_1.record)(input, opts);
105
+ result = (0, record_1.oneOffGate)(input) ?? locked(opts.cwd, () => (opts.pending ? (0, record_1.queue)(input, opts) : (0, record_1.record)(input, opts)));
102
106
  }
103
107
  process.stdout.write(JSON.stringify(result.output, null, 2) + '\n');
104
108
  // Queueing never reaches the board — work cards are built from judged decisions.
@@ -150,7 +154,7 @@ program
150
154
  .option('--author <name>', 'author for queued items')
151
155
  .option('--json', 'machine-readable output')
152
156
  .action((id, opts) => {
153
- const r = (0, sweep_1.sweepCommand)(id, opts);
157
+ const r = opts.queue ? locked(opts.cwd, () => (0, sweep_1.sweepCommand)(id, opts)) : (0, sweep_1.sweepCommand)(id, opts);
154
158
  process.stdout.write(r.text + '\n');
155
159
  });
156
160
  program
@@ -159,7 +163,7 @@ program
159
163
  .option('--checkin <mode>', 'feature | quiet | every')
160
164
  .option('--app <url>', 'where the app runs, for screenshots: http://localhost:3000 or a staging address (on its own, saves only this)')
161
165
  .action((opts) => {
162
- const result = (0, setup_1.setup)(opts);
166
+ const result = locked(opts.cwd, () => (0, setup_1.setup)(opts));
163
167
  process.stdout.write(JSON.stringify(result.output, null, 2) + '\n');
164
168
  process.exit(result.exitCode);
165
169
  });
@@ -169,7 +173,7 @@ program
169
173
  .option('--file <image>', 'screenshot to keep beside the work')
170
174
  .option('--capture', 'macOS: drag-select a region of the screen')
171
175
  .action(async (work, opts) => {
172
- const result = (0, snapshot_1.snapshotWork)(work, opts);
176
+ const result = locked(opts.cwd, () => (0, snapshot_1.snapshotWork)(work, opts));
173
177
  process.stdout.write(JSON.stringify(result.output, null, 2) + '\n');
174
178
  if (result.exitCode === 0)
175
179
  await boardUpdated(opts.cwd);
@@ -188,7 +192,7 @@ program
188
192
  .option('--keep-others', "approving doesn't supersede sibling directions")
189
193
  .option('--author <name>', 'override the author')
190
194
  .action(async (idOrAdd, name, opts) => {
191
- const result = idOrAdd === 'add' ? (0, candidate_1.addCandidate)(name ?? '', opts) : (0, candidate_1.updateCandidate)(idOrAdd, opts);
195
+ const result = locked(opts.cwd, () => (idOrAdd === 'add' ? (0, candidate_1.addCandidate)(name ?? '', opts) : (0, candidate_1.updateCandidate)(idOrAdd, opts)));
192
196
  process.stdout.write(JSON.stringify(result.output, null, 2) + '\n');
193
197
  if (result.exitCode === 0)
194
198
  await boardUpdated(opts.cwd);
@@ -212,14 +216,14 @@ program
212
216
  });
213
217
  program
214
218
  .command('export')
215
- .description('Write a static, self-contained folder of the board for people without the repo. Opens anywhere.')
219
+ .description('Write your board as a read-only folder for people without the repo: the same pages as arbiter review, without the review queue. Opens anywhere.')
216
220
  .option('--out <dir>', 'output folder (default: arbiter-export)')
217
221
  .option('--feature <name>', 'one feature only')
218
- .option('--include-rules', 'append the standing rules')
222
+ .option('--include-rules', 'add the design rules page')
219
223
  .option('--open', 'open it in the browser')
220
224
  .action((opts) => {
221
225
  const r = (0, export_1.exportBoard)(opts);
222
- process.stdout.write(`Exported ${r.candidates} screen${r.candidates === 1 ? '' : 's'}, ${r.snapshots} snapshot${r.snapshots === 1 ? '' : 's'} → ${r.dir}\nOpen ${r.index}, or put the folder on any static host.\n`);
226
+ process.stdout.write(`Exported ${r.candidates} change${r.candidates === 1 ? '' : 's'}, ${r.snapshots} picture${r.snapshots === 1 ? '' : 's'} → ${r.dir}\nOpen ${r.index}, or put the folder on any static host.\n`);
223
227
  });
224
228
  program
225
229
  .command('publish')
@@ -249,11 +253,22 @@ program
249
253
  printSteps(r.steps);
250
254
  process.exit(r.ok ? 0 : 1);
251
255
  });
256
+ program
257
+ .command('areas')
258
+ .description('Where everything sits on the board: folders, the areas in them, and the changes in each. Read it before naming new work, so it joins an area that is already there. --save writes folders, once the person has said yes to them.')
259
+ .option('--json', 'print it as JSON')
260
+ .option('--save <json>', 'replace the folders: {"folders":[{"name":"Local board","areas":["Review inbox","Change page"]}]}')
261
+ .action((opts) => {
262
+ const result = opts.save ? locked(undefined, () => (0, areas_1.areasCommand)({ json: opts.json, save: opts.save })) : (0, areas_1.areasCommand)({ json: opts.json, save: opts.save });
263
+ process.stdout.write(result.exitCode !== 0 || opts.json ? JSON.stringify(result.output, null, 2) + '\n' : `${result.text}\n`);
264
+ process.exit(result.exitCode);
265
+ });
252
266
  program
253
267
  .command('rename <work> <new-name>')
254
268
  .description('Rename a piece of work everywhere the record keeps it. Its comments on the board follow it at the next publish.')
269
+ .option('--merge', 'the new name is a piece of work that already exists: this one joins it, decisions, pictures and comments')
255
270
  .action(async (work, newName, opts) => {
256
- const result = (0, rename_1.renameWork)(work, newName, opts);
271
+ const result = locked(opts.cwd, () => (0, rename_1.renameWork)(work, newName, opts));
257
272
  process.stdout.write(JSON.stringify(result.output, null, 2) + '\n');
258
273
  if (result.exitCode === 0)
259
274
  await boardUpdated(opts.cwd);
@@ -267,11 +282,25 @@ program
267
282
  });
268
283
  program
269
284
  .command('review')
270
- .description('Open a local page to judge pending decisions.')
271
- .option('--port <n>', 'port (default: any free port)', (v) => Number(v))
285
+ .description('Open your local board: everything decided, and what waits for review. Keep it open while you work: it redraws as the agent records, and the fixes you ask for reach your agent with your next message (Claude Code) or at the next /arbiter. Stops when you close its tab.')
286
+ .option('--port <n>', "port (default: the same one each time for this project, or the next free one; if this project's board is already running, it opens that one)", (v) => Number(v))
272
287
  .option('--no-open', "print the URL, don't open a browser")
288
+ .option('--json', "for an agent waiting on the page: when the last tab closes, print what was decided, and what's left to change in the code, as JSON")
289
+ .option('--done', 'for the agent, once it has made what it was handed from the board: clears that from .arbiter/last-review.json, keeping anything judged since')
273
290
  .action(async (opts) => {
274
- await (0, review_1.review)(opts);
291
+ if (opts.done) {
292
+ const r = locked(opts.cwd, () => (0, handoff_1.handoffDone)((0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd))));
293
+ process.stdout.write(JSON.stringify(r, null, 2) + '\n');
294
+ process.exit(r.status === 'not-taken' ? 1 : 0);
295
+ }
296
+ const handoff = await (0, review_1.review)(opts);
297
+ if (opts.json)
298
+ process.stdout.write(JSON.stringify(handoff, null, 2) + '\n');
299
+ else {
300
+ const line = (0, handoff_1.handoffLine)(handoff, (0, hook_1.hookInstalled)((0, store_1.findRoot)()) ? 'with your next message' : 'at the next /arbiter');
301
+ if (line)
302
+ process.stdout.write(line + '\n');
303
+ }
275
304
  });
276
305
  program
277
306
  .command('remove [id]')
@@ -279,7 +308,7 @@ program
279
308
  .option('--snapshot <work>', 'remove the picture attached to a piece of work or a screen, keeping the record')
280
309
  .option('--force', 'with a screen: unlink the decisions on it rather than refusing')
281
310
  .action(async (id, opts) => {
282
- const result = opts.snapshot ? (0, remove_1.removeSnapshot)(opts.snapshot, opts) : (0, remove_1.remove)(id ?? '', opts);
311
+ const result = locked(opts.cwd, () => (opts.snapshot ? (0, remove_1.removeSnapshot)(opts.snapshot, opts) : (0, remove_1.remove)(id ?? '', opts)));
283
312
  process.stdout.write(JSON.stringify(result.output, null, 2) + '\n');
284
313
  if (result.exitCode === 0)
285
314
  await boardUpdated(opts.cwd);
@@ -289,7 +318,7 @@ program
289
318
  .command('unlink <ids...>')
290
319
  .description('Detach decisions from the screen they were recorded against. The decisions stay exactly as they are.')
291
320
  .action(async (ids, opts) => {
292
- const result = (0, remove_1.unlink)(ids, opts);
321
+ const result = locked(opts.cwd, () => (0, remove_1.unlink)(ids, opts));
293
322
  process.stdout.write(JSON.stringify(result.output, null, 2) + '\n');
294
323
  if (result.exitCode === 0)
295
324
  await boardUpdated(opts.cwd);
@@ -331,6 +360,13 @@ program.parseAsync(process.argv).catch((e) => {
331
360
  process.stderr.write(`arbiter: ${e.message}\n`);
332
361
  process.exit(1);
333
362
  });
363
+ /**
364
+ * One write at a time: the agent's commands, several at once perhaps, and the board's clicks take turns
365
+ * on the record (.arbiter/.lock), so none writes over another.
366
+ */
367
+ function locked(cwd, fn) {
368
+ return (0, lock_1.withLock)((0, store_1.resolvePaths)((0, store_1.findRoot)(cwd)), fn);
369
+ }
334
370
  /** `publish` and `unpublish` report one line per step: name, outcome, why. */
335
371
  function printSteps(steps) {
336
372
  const w = Math.max(...steps.map((s) => s.step.length));
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ /**
3
+ * The local board's data, read from the project's files: what `arbiter review` sends the page
4
+ * (/api/board and /api/state) and what `arbiter export` writes into a read-only copy.
5
+ *
6
+ * Built here, apart from the manifest `publish` uploads (src/hosted.ts), so the local board can change
7
+ * what it shows without changing what the team board receives, and the other way round. The shapes
8
+ * are in src/board-types.ts, which the page reads too.
9
+ */
10
+ var __importDefault = (this && this.__importDefault) || function (mod) {
11
+ return (mod && mod.__esModule) ? mod : { "default": mod };
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.boardOf = boardOf;
15
+ exports.liveBoard = liveBoard;
16
+ exports.reviewState = reviewState;
17
+ const node_fs_1 = __importDefault(require("node:fs"));
18
+ const node_path_1 = __importDefault(require("node:path"));
19
+ const candidates_1 = require("./candidates");
20
+ const store_1 = require("./store");
21
+ const work_1 = require("./work");
22
+ const requests_1 = require("./requests");
23
+ const comments_1 = require("./comments");
24
+ const hosted_1 = require("./hosted");
25
+ const pictures_1 = require("./pictures");
26
+ const areas_1 = require("./areas");
27
+ const settings_1 = require("./settings");
28
+ const verify_1 = require("./verify");
29
+ /** On the board: judged, still in force, and not polish. */
30
+ const shown = (d) => d.verdict !== 'pending' && d.verdict !== 'retire' && d.level !== 'polish';
31
+ /**
32
+ * A decision as the board shows it. An exception carries the rule it goes against, found among every rule
33
+ * ever recorded, retired ones too; a rule no longer in force, how it left.
34
+ */
35
+ const toDecision = (d, inForce, rules, ends) => {
36
+ const rule = d.against && d.verdict !== 'rule' ? rules?.get(d.against) : undefined;
37
+ const ended = inForce && d.verdict === 'rule' && !inForce.has(d.id) ? ends?.(d.id) ?? null : null;
38
+ return { id: d.id, change: d.change, decision: d.decision, rejected: d.rejected, verdict: d.verdict, dimension: d.dimension, scope: d.scope, ref: d.ref, date: d.date, ...(inForce && d.verdict === 'rule' ? { active: inForce.has(d.id) } : {}), ...(rule ? { against: { id: rule.id, decision: rule.decision, rationale: rule.rationale } } : {}), ...(ended ? { ended } : {}) };
39
+ };
40
+ /**
41
+ * How each rule left DECISIONS.md, from the entry that ended it: a retirement says why, a newer rule
42
+ * that replaced it says what it says now. A rule still in force has none.
43
+ */
44
+ function endsOf(archive) {
45
+ const by = new Map();
46
+ for (const x of archive)
47
+ if (x.supersedes && !by.has(x.supersedes))
48
+ by.set(x.supersedes, x);
49
+ return (id) => {
50
+ const x = by.get(id);
51
+ if (!x)
52
+ return null;
53
+ return x.verdict === 'retire' ? { kind: 'retired', date: x.date, why: x.rationale } : { kind: 'replaced', date: x.date, by: { id: x.id, decision: x.decision } };
54
+ };
55
+ }
56
+ /**
57
+ * Every card and rule. A decision made on a screen rides with that screen; the rest are grouped by the
58
+ * piece of work they came from (`trigger`) into a card each. Pictures are links, never bytes.
59
+ */
60
+ function boardOf(paths, opts) {
61
+ const known = (0, candidates_1.readCandidates)(paths);
62
+ // Which rules are still in force, so a retired one doesn't read as a rule on its change's page.
63
+ const inForce = new Set((0, store_1.readActive)(paths).map((d) => d.id));
64
+ const archive = (0, store_1.readArchive)(paths);
65
+ const ruleById = new Map(archive.filter((d) => d.verdict === 'rule').map((d) => [d.id, d]));
66
+ const ends = endsOf(archive);
67
+ const candidates = known.map((c) => ({
68
+ id: c.id,
69
+ name: c.name,
70
+ feature: c.feature,
71
+ state: c.state,
72
+ author: c.author,
73
+ date: c.date,
74
+ reason: c.reason,
75
+ notes: c.notes,
76
+ supersededBy: c.supersededBy,
77
+ url: null,
78
+ snapshot: c.snapshot && node_fs_1.default.existsSync(node_path_1.default.join((0, candidates_1.candidatesDir)(paths), c.snapshot)) ? `${opts.pictures}${c.snapshot}` : null,
79
+ decisions: (0, candidates_1.decisionsFor)(paths, c.id).filter(shown).map((d) => toDecision(d, inForce, ruleById, ends)),
80
+ }));
81
+ // Screenless decisions: one card per piece of work.
82
+ const ids = new Set(known.map((c) => c.id));
83
+ const loose = archive.filter((d) => shown(d) && (!d.candidate || !ids.has(d.candidate)));
84
+ const byWork = new Map();
85
+ for (const d of loose)
86
+ byWork.set(d.trigger, [...(byWork.get(d.trigger) ?? []), d]);
87
+ const waitingOnly = new Map();
88
+ for (const d of opts.queued) {
89
+ if (d.level === 'polish' || (d.candidate && ids.has(d.candidate)) || byWork.has(d.trigger))
90
+ continue;
91
+ waitingOnly.set(d.trigger, [...(waitingOnly.get(d.trigger) ?? []), d]);
92
+ }
93
+ const areas = new Map(known.filter((c) => c.feature).map((c) => [c.feature.toLowerCase(), c.feature]));
94
+ for (const [trigger, ds] of [...byWork, ...waitingOnly]) {
95
+ const last = ds.reduce((a, b) => (a.date > b.date ? a : b));
96
+ const id = (0, work_1.workId)(trigger);
97
+ const shot = (0, work_1.workSnapshot)(paths, id);
98
+ candidates.push({
99
+ // Work has no product area of its own; it joins one only when the trigger names an existing one.
100
+ id, name: trigger, feature: areas.get(trigger.toLowerCase()) ?? null, state: 'recorded', work: true,
101
+ author: last.author, date: last.date, reason: null, notes: '', supersededBy: null, url: null,
102
+ snapshot: shot ? `${opts.pictures}${node_path_1.default.basename(shot)}` : null,
103
+ decisions: ds.filter(shown).map((d) => toDecision(d, inForce, ruleById, ends)),
104
+ ...versionsOf(paths, id, opts.pictures),
105
+ });
106
+ }
107
+ // The day each became a rule, for the Design rules page.
108
+ // With each, where it doesn't hold and what waits against it: the exceptions kept to it, and clashes in the Review inbox.
109
+ const link = (d) => {
110
+ const card = (0, requests_1.cardOf)(paths, d, ids);
111
+ return { id: d.id, card, name: known.find((c) => c.id === card)?.name ?? d.trigger, change: d.change ?? d.decision };
112
+ };
113
+ const rules = opts.includeRules ? (0, store_1.readActive)(paths).map((r) => ({
114
+ id: r.id, dimension: r.dimension, decision: r.decision, rationale: r.rationale, candidate: r.candidate ?? null, date: r.date.slice(0, 10),
115
+ exceptions: archive.filter((x) => x.against === r.id && x.verdict === 'accept').map(link),
116
+ waiting: opts.queued.filter((x) => x.against === r.id && x.verdict === 'pending').map(link),
117
+ })) : null;
118
+ // The rules taken out of it, the latest to go first: what they said, and how each left.
119
+ const retired = opts.includeRules ? archive.filter((r) => r.verdict === 'rule' && !inForce.has(r.id))
120
+ .map((r) => ({ id: r.id, dimension: r.dimension, decision: r.decision, rationale: r.rationale, candidate: r.candidate ?? null, date: r.date.slice(0, 10), ended: ends(r.id) }))
121
+ .sort((a, b) => (b.ended?.date ?? '').localeCompare(a.ended?.date ?? '') || b.id.localeCompare(a.id)) : null;
122
+ // The owner's answers to the team's change requests, so a thread shows the answer under its request.
123
+ const requests = (0, requests_1.readRequests)(paths)
124
+ .filter((r) => r.status !== 'open')
125
+ .map((r) => ({
126
+ comment: r.comment,
127
+ id: r.id,
128
+ status: r.status,
129
+ instead: r.instead,
130
+ reason: r.reason,
131
+ by: r.judgedBy,
132
+ at: r.appliedAt ?? r.judgedAt,
133
+ decisions: r.decisions.flatMap((id) => {
134
+ const d = archive.find((x) => x.id === id);
135
+ return d ? [{ id: d.id, change: d.change ?? d.decision, card: (0, requests_1.cardOf)(paths, d, ids) }] : [];
136
+ }),
137
+ }));
138
+ return { project: node_path_1.default.basename(paths.root), exported: new Date().toISOString().slice(0, 10), candidates, rules, retired, requests };
139
+ }
140
+ /** A piece of work's pictures, oldest first, when it has had more than one. */
141
+ function versionsOf(paths, id, pictures) {
142
+ const all = (0, work_1.workVersions)(paths, id);
143
+ return all.length > 1 ? { versions: all.map((v) => ({ src: `${pictures}${v.file}`, date: v.date })) } : {};
144
+ }
145
+ /**
146
+ * What `/api/board` sends: the board, plus what only this machine knows: what's waiting for review,
147
+ * and the team's comments as the last `pull` brought them.
148
+ */
149
+ function liveBoard(paths) {
150
+ const queued = (0, store_1.readPending)(paths);
151
+ const board = boardOf(paths, { pictures: '/snapshots/', includeRules: true, queued });
152
+ const ids = new Set((0, candidates_1.readCandidates)(paths).map((c) => c.id));
153
+ const waiting = {};
154
+ // Enough of each to draw a card and place it in its area before anything on it is judged.
155
+ const lines = {};
156
+ for (const d of queued) {
157
+ if (d.level === 'polish')
158
+ continue;
159
+ const card = (0, requests_1.cardOf)(paths, d, ids);
160
+ waiting[card] = (waiting[card] ?? 0) + 1;
161
+ (lines[card] ??= []).push({ id: d.id, change: d.change ?? null, decision: d.decision, dimension: d.dimension, scope: d.scope, date: d.date });
162
+ }
163
+ const link = (0, hosted_1.readLinkOrNull)(paths);
164
+ return { board, comments: (0, comments_1.readComments)(paths), waiting, queued: lines, pending: queued.filter((d) => d.level !== 'polish').length, hosted: link?.shareUrl ?? null, version: link?.boardVersion ?? null, live: true, arrangement: (0, areas_1.readArrangement)(paths), settings: (0, settings_1.settingsOf)(paths) };
165
+ }
166
+ /** What `/api/state` sends: the review queue. */
167
+ /** The last picture taken before `date`, when a newer one was taken since: the before to this decision's now. */
168
+ function beforeOf(all, date) {
169
+ const at = (s) => Date.parse(s);
170
+ if (all.length < 2 || at(all[all.length - 1].date) < at(date))
171
+ return null;
172
+ const earlier = all.filter((v) => at(v.date) < at(date));
173
+ const v = earlier[earlier.length - 1];
174
+ return v ? { src: `/snapshots/${v.file}`, date: v.date } : null;
175
+ }
176
+ /**
177
+ * What the files a waiting decision names say now, read again each time the inbox loads: each check that
178
+ * fails, for the card's Code Clash. Null when they match, or it names none. A fix made since clears it, and
179
+ * code broken since shows here instead of only when it's judged.
180
+ */
181
+ function codeClashOf(root, d) {
182
+ if (!(0, verify_1.checkable)(d.files ?? [], d.expect ?? null))
183
+ return null;
184
+ const failed = (0, verify_1.verify)(root, d.files ?? [], d.expect ?? null).checks.filter((c) => !c.ok);
185
+ return failed.length ? failed.map(({ ok: _ok, ...c }) => c) : null;
186
+ }
187
+ function reviewState(paths, agent) {
188
+ const candidates = (0, candidates_1.readCandidates)(paths);
189
+ const byId = new Map(candidates.map((c) => [c.id, c]));
190
+ const ids = new Set(byId.keys());
191
+ const active = (0, store_1.readActive)(paths);
192
+ // The card a decision is on: its picture, a screen's or a piece of work's.
193
+ const shotOf = (card) => {
194
+ if (card.startsWith('C-')) {
195
+ const c = byId.get(card);
196
+ return c?.snapshot ? `/snapshots/${c.snapshot}` : null;
197
+ }
198
+ const f = (0, work_1.workSnapshot)(paths, card);
199
+ return f ? `/snapshots/${node_path_1.default.basename(f)}` : null;
200
+ };
201
+ const pending = (0, store_1.readPending)(paths).map((d) => {
202
+ // The card it waits on, so a change marked Waiting can open the Review inbox at its work.
203
+ const card = (0, requests_1.cardOf)(paths, d, ids);
204
+ return {
205
+ ...d,
206
+ card,
207
+ // The rule a clash is with, while it's still in force: the page offers Keep as exception / Follow / Make this the rule. Its reason shows on hover.
208
+ againstRule: d.against ? active.filter((r) => r.id === d.against).map((r) => ({ id: r.id, decision: r.decision, rationale: r.rationale }))[0] ?? null : null,
209
+ codeClash: codeClashOf(paths.root, d),
210
+ candidateName: d.candidate ? byId.get(d.candidate)?.name ?? null : null,
211
+ // Its card's picture, so what changed is in view where it's judged.
212
+ snapshotUrl: shotOf(card),
213
+ // The picture from before this decision, when the work's picture was retaken after it was queued.
214
+ before: card.startsWith('W-') ? beforeOf((0, work_1.workVersions)(paths, card), d.date) : null,
215
+ picture: (0, pictures_1.missingPictures)(paths, [d], candidates)[0] ?? null,
216
+ };
217
+ });
218
+ return { project: node_path_1.default.basename(paths.root), pending, active: active.length, cap: (0, store_1.readConfig)(paths)?.activeCap ?? store_1.ACTIVE_CAP, agent };
219
+ }
package/dist/lock.js ADDED
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ /**
3
+ * One write at a time. The agent runs `arbiter record` in a terminal while you click on the board, and
4
+ * Claude Code may run several commands at once; each reads a file, changes it and writes it back, so
5
+ * two at the same moment would each write over the other (both say "queued P-0009", one is lost).
6
+ * Every write takes .arbiter/.lock first and lets it go when done; the next one waits its turn.
7
+ *
8
+ * And no half-written file: each is written beside itself and renamed into place, so a reader never
9
+ * sees one cut short, and a crash mid-write leaves the old one whole.
10
+ */
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.LOCK = void 0;
16
+ exports.withLock = withLock;
17
+ exports.withLockAsync = withLockAsync;
18
+ exports.writeAtomic = writeAtomic;
19
+ const node_fs_1 = __importDefault(require("node:fs"));
20
+ const node_path_1 = __importDefault(require("node:path"));
21
+ exports.LOCK = '.lock';
22
+ /**
23
+ * Older than any write takes, by far: left by a process that died holding it, so it's cleared. Age is
24
+ * the only sign trusted. Asking whether the holder is still running isn't: by the time the answer comes,
25
+ * it may have finished and another taken the lock, and clearing that one lets two writes in at once.
26
+ */
27
+ const STALE = 10_000;
28
+ /** How long a write waits its turn before it gives up and says why. */
29
+ const WAIT = 25_000;
30
+ /** Held by this process: a write inside another one (judging that records) doesn't wait on itself. */
31
+ let held = 0;
32
+ const pause = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
33
+ /** The lock, taken: waits while another process holds it, and clears one left by a process that died. */
34
+ function acquire(paths) {
35
+ node_fs_1.default.mkdirSync(paths.archiveDir, { recursive: true });
36
+ const file = node_path_1.default.join(paths.archiveDir, exports.LOCK);
37
+ const start = Date.now();
38
+ for (;;) {
39
+ try {
40
+ const fd = node_fs_1.default.openSync(file, 'wx');
41
+ node_fs_1.default.writeSync(fd, `${process.pid}\n`);
42
+ node_fs_1.default.closeSync(fd);
43
+ return;
44
+ }
45
+ catch (e) {
46
+ // EPERM, EACCES: Windows, while the last holder's file is still being deleted. Its turn is ending.
47
+ const code = e.code;
48
+ if (code !== 'EEXIST' && code !== 'EPERM' && code !== 'EACCES')
49
+ throw e;
50
+ }
51
+ try {
52
+ if (Date.now() - node_fs_1.default.statSync(file).mtimeMs > STALE) {
53
+ node_fs_1.default.rmSync(file, { force: true });
54
+ continue;
55
+ }
56
+ }
57
+ catch {
58
+ continue; // gone since: try again at once
59
+ }
60
+ if (Date.now() - start > WAIT) {
61
+ throw new Error(`another arbiter command has held .arbiter/${exports.LOCK} for ${Math.round(WAIT / 1000)}s. If none is running, delete that file and try again.`);
62
+ }
63
+ pause(15 + Math.random() * 20);
64
+ }
65
+ }
66
+ function release(paths) {
67
+ node_fs_1.default.rmSync(node_path_1.default.join(paths.archiveDir, exports.LOCK), { force: true });
68
+ }
69
+ /** `fn` as the only write to this project's record, start to finish. */
70
+ function withLock(paths, fn) {
71
+ if (held) {
72
+ held++;
73
+ try {
74
+ return fn();
75
+ }
76
+ finally {
77
+ held--;
78
+ }
79
+ }
80
+ acquire(paths);
81
+ held = 1;
82
+ try {
83
+ return fn();
84
+ }
85
+ finally {
86
+ held = 0;
87
+ release(paths);
88
+ }
89
+ }
90
+ /** The same for a write that awaits, like the board's: nothing else in this process writes meanwhile, as the caller sees to. */
91
+ async function withLockAsync(paths, fn) {
92
+ if (held) {
93
+ held++;
94
+ try {
95
+ return await fn();
96
+ }
97
+ finally {
98
+ held--;
99
+ }
100
+ }
101
+ acquire(paths);
102
+ held = 1;
103
+ try {
104
+ return await fn();
105
+ }
106
+ finally {
107
+ held = 0;
108
+ release(paths);
109
+ }
110
+ }
111
+ /**
112
+ * A whole file, written beside itself and renamed into place. Windows can refuse the rename for a moment
113
+ * while something else has the file open (an editor, a virus scan): it tries again, then writes in place.
114
+ */
115
+ function writeAtomic(file, text) {
116
+ const tmp = `${file}.${process.pid}.tmp`;
117
+ node_fs_1.default.writeFileSync(tmp, text);
118
+ for (let i = 0;; i++) {
119
+ try {
120
+ node_fs_1.default.renameSync(tmp, file);
121
+ return;
122
+ }
123
+ catch (e) {
124
+ const code = e.code;
125
+ if (i < 5 && (code === 'EPERM' || code === 'EACCES' || code === 'EBUSY')) {
126
+ pause(20 * (i + 1));
127
+ continue;
128
+ }
129
+ node_fs_1.default.rmSync(tmp, { force: true });
130
+ node_fs_1.default.writeFileSync(file, text);
131
+ return;
132
+ }
133
+ }
134
+ }
package/dist/overlap.js CHANGED
@@ -9,6 +9,8 @@
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.findOverlaps = findOverlaps;
12
+ exports.stem = stem;
13
+ exports.explainOverlaps = explainOverlaps;
12
14
  const schema_1 = require("./schema");
13
15
  const STOPWORDS = new Set(('a an the and or not never always no yes of in on at to for with by from as is are be use uses using than rather instead only its it this that these those all any one ' +
14
16
  // Generic UI nouns: shared by half of all decisions, so they say nothing about overlap.
@@ -69,3 +71,17 @@ function fileContains(a, b) {
69
71
  const norm = (p) => p.replace(/\\/g, '/').replace(/\/+$/, '');
70
72
  const narrower = (a, b) => (norm(a).length >= norm(b).length ? a : b);
71
73
  const wider = (a, b) => (norm(a).length >= norm(b).length ? b : a);
74
+ function explainOverlaps(entry, overlaps, active, changeNames) {
75
+ const changeOf = (d) => (d.candidate ? changeNames.get(d.candidate) : undefined) ?? d.trigger;
76
+ return overlaps.map((o) => {
77
+ if (o.confidence !== 'exact')
78
+ return { id: o.id, decision: o.decision, sure: false, words: asWritten(entry.decision, (o.reason.split('shares: ')[1] ?? '').split(', ').filter(Boolean)) };
79
+ const narrow = o.scope.length >= entry.scope.length ? (active.find((d) => d.id === o.id) ?? entry) : entry;
80
+ return { id: o.id, decision: o.decision, sure: true, scope: narrow.scope, ...(narrow.scope.startsWith('file:') ? { change: changeOf(narrow) } : {}), words: [] };
81
+ });
82
+ }
83
+ /** The shared words as the decision writes them, not as the overlap check trims them ("prices", not "pric"). */
84
+ function asWritten(text, stems) {
85
+ const words = text.toLowerCase().replace(/[^a-z0-9\s]/g, ' ').split(/\s+/).filter(Boolean);
86
+ return stems.map((s) => words.find((w) => stem(w) === s) ?? s);
87
+ }
package/dist/pictures.js CHANGED
@@ -16,6 +16,7 @@ exports.pictureHint = exports.needsPicture = void 0;
16
16
  exports.missingPictures = missingPictures;
17
17
  const candidates_1 = require("./candidates");
18
18
  const findings_1 = require("./findings");
19
+ const store_1 = require("./store");
19
20
  const work_1 = require("./work");
20
21
  const PICTURED = ['structure', 'content', 'visual'];
21
22
  /** Would a picture of one screen show this change, on a card the board will have? */
@@ -27,6 +28,9 @@ exports.needsPicture = needsPicture;
27
28
  * A rejected or replaced direction is gone from the app, so nothing asks for its picture.
28
29
  */
29
30
  function missingPictures(paths, decisions, candidates = (0, candidates_1.readCandidates)(paths)) {
31
+ // Pictures turned off in Settings: none is missing, so nothing asks for one.
32
+ if ((0, store_1.readConfig)(paths)?.pictures === false)
33
+ return [];
30
34
  const byId = new Map(candidates.map((c) => [c.id, c]));
31
35
  const out = new Map();
32
36
  for (const d of decisions) {