arbiterdesign 0.1.8 → 0.1.10

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.
Files changed (42) hide show
  1. package/README.md +288 -242
  2. package/dist/area-names.js +120 -0
  3. package/dist/areas.js +131 -0
  4. package/dist/board-types.js +9 -0
  5. package/dist/candidates.js +7 -1
  6. package/dist/commands/areas.js +153 -0
  7. package/dist/commands/candidate.js +4 -2
  8. package/dist/commands/decision.js +100 -0
  9. package/dist/commands/export.js +88 -125
  10. package/dist/commands/init.js +198 -73
  11. package/dist/commands/invite.js +67 -0
  12. package/dist/commands/publish.js +4 -4
  13. package/dist/commands/record.js +133 -8
  14. package/dist/commands/remove.js +1 -1
  15. package/dist/commands/rename.js +25 -11
  16. package/dist/commands/review.js +458 -78
  17. package/dist/commands/rules.js +22 -3
  18. package/dist/commands/setup.js +1 -0
  19. package/dist/commands/snapshot.js +24 -2
  20. package/dist/commands/sweep.js +1 -1
  21. package/dist/commands/update.js +5 -0
  22. package/dist/comments.js +24 -0
  23. package/dist/format.js +112 -7
  24. package/dist/handoff.js +286 -0
  25. package/dist/hook.js +82 -0
  26. package/dist/hosted.js +50 -17
  27. package/dist/index.js +99 -37
  28. package/dist/localboard.js +219 -0
  29. package/dist/lock.js +134 -0
  30. package/dist/overlap.js +16 -0
  31. package/dist/pictures.js +4 -0
  32. package/dist/settings.js +107 -0
  33. package/dist/store.js +164 -8
  34. package/dist/verify.js +4 -2
  35. package/dist/work.js +110 -1
  36. package/package.json +3 -2
  37. package/templates/SKILL.md +146 -51
  38. package/templates/board/board.css +2 -0
  39. package/templates/board/board.js +25 -0
  40. package/templates/board/index.html +15 -0
  41. package/templates/hooks/arbiter-board.cjs +50 -0
  42. package/templates/review.html +0 -757
@@ -25,20 +25,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
25
25
  return (mod && mod.__esModule) ? mod : { "default": mod };
26
26
  };
27
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.REVIEW_EVERY = void 0;
28
+ exports.REVIEW_ANSWERS = exports.REVIEW_EVERY = void 0;
29
29
  exports.record = record;
30
+ exports.oneOffGate = oneOffGate;
30
31
  exports.queue = queue;
31
32
  exports.queueFindings = queueFindings;
32
33
  exports.retire = retire;
34
+ exports.unretire = unretire;
33
35
  exports.reword = reword;
34
36
  exports.judge = judge;
35
37
  exports.judgeAll = judgeAll;
38
+ exports.unjudge = unjudge;
36
39
  exports.recordInput = recordInput;
37
40
  exports.interactiveInput = interactiveInput;
38
41
  const node_path_1 = __importDefault(require("node:path"));
39
42
  const schema_1 = require("../schema");
40
43
  const store_1 = require("../store");
41
44
  const overlap_1 = require("../overlap");
45
+ const candidates_1 = require("../candidates");
42
46
  const verify_1 = require("../verify");
43
47
  const sweep_1 = require("../sweep");
44
48
  const findings_1 = require("../findings");
@@ -48,7 +52,9 @@ const candidate_1 = require("./candidate");
48
52
  const update_1 = require("./update");
49
53
  const pictures_1 = require("../pictures");
50
54
  const request_1 = require("./request");
55
+ const requests_1 = require("../requests");
51
56
  const wording_1 = require("../wording");
57
+ const areas_1 = require("./areas");
52
58
  // ── Parse + record ─────────────────────────────────────────────────────────
53
59
  function record(rawJson, opts = {}) {
54
60
  const parsed = parse(rawJson);
@@ -89,16 +95,43 @@ function plainWords(input) {
89
95
  },
90
96
  };
91
97
  }
98
+ /**
99
+ * One-off fixes to a single screen aren't recorded, for now: nobody needs to judge matching two heights,
100
+ * and they made the review long. `record` and `record --pending` turn `level: polish` away and write
101
+ * nothing; the agent is told so, and carries on. Old polish already in a queue is still judged as before.
102
+ */
103
+ function oneOffGate(rawJson) {
104
+ let level;
105
+ try {
106
+ level = JSON.parse(rawJson)?.level;
107
+ }
108
+ catch {
109
+ return null;
110
+ }
111
+ if (level !== 'polish')
112
+ return null;
113
+ return {
114
+ exitCode: 0,
115
+ output: {
116
+ status: 'not-recorded',
117
+ reason: "One-off fixes to a single screen aren't recorded. Nothing was written. Record it as a pattern only if it would apply to other screens too.",
118
+ },
119
+ };
120
+ }
92
121
  function queue(rawJson, opts = {}) {
93
122
  if (opts.request)
94
123
  return fail([`--request records a change made for an approved request, directly: drop --pending. Nothing is queued for a request.`]);
95
124
  const parsed = parse(rawJson, { pending: true });
96
125
  if (!parsed.ok)
97
126
  return parsed.result;
127
+ const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
128
+ // Before the wording check: there's no point rewording a line Preferences keep out anyway.
129
+ const off = notRecorded((0, store_1.readConfig)(paths), parsed.input);
130
+ if (off)
131
+ return { exitCode: 0, output: { status: 'not-recorded', reason: off } };
98
132
  const unclear = plainWords(parsed.input);
99
133
  if (unclear)
100
134
  return unclear;
101
- const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
102
135
  const bad = againstError(paths, parsed.input);
103
136
  if (bad)
104
137
  return bad;
@@ -135,22 +168,44 @@ function queue(rawJson, opts = {}) {
135
168
  ...(opts.dryRun ? {} : askToReview(before, waiting, checkin)),
136
169
  review: 'npx arbiter review',
137
170
  ...picture(paths, entry),
171
+ // Pictures off in Preferences: the agent takes none, and says nothing about them.
172
+ ...((0, store_1.readConfig)(paths)?.pictures === false ? { pictures: false } : {}),
173
+ // Where the work sits on the board, and whether it started an area of its own.
174
+ ...(opts.dryRun ? {} : (0, areas_1.placement)(paths, entry, pending)),
138
175
  // Present only when the project's skill file is from an older Arbiter than this one.
139
176
  ...(0, update_1.updateNotice)(paths),
140
177
  },
141
178
  };
142
179
  }
180
+ /**
181
+ * What Preferences on the board keep out of the queue: patterns, when only features are recorded, and the
182
+ * agent's own calls, when only what the person asked for or corrected is. A clash is always queued:
183
+ * someone has to say which one wins. "Record that" records directly, so it's never stopped here.
184
+ */
185
+ function notRecorded(config, input) {
186
+ if (input.against)
187
+ return null;
188
+ if (config?.record?.level === 'feature' && (input.level ?? 'pattern') !== 'feature') {
189
+ return 'This project records features only (Preferences, on the board). Nothing was written.';
190
+ }
191
+ if (config?.record?.agent === false && input.call === 'agent') {
192
+ return "This project records only what the person asked for or corrected, not the agent's own calls (Preferences, on the board). Nothing was written.";
193
+ }
194
+ return null;
195
+ }
143
196
  /** Ask once each time the waiting count reaches another multiple of this. */
144
197
  exports.REVIEW_EVERY = 5;
145
198
  /**
146
199
  * At 5, 10, 15 changes waiting, the agent asks whether to review now. A "no" just waits for the
147
200
  * next multiple, and judging brings the count down, so the next ask comes when it climbs back.
148
201
  * Quiet means quiet: someone who chose "Nothing until I ask" is never asked.
202
+ * "In the browser" opens the Review Board and waits for Done; "here" is the review in chat.
149
203
  */
204
+ exports.REVIEW_ANSWERS = '(yes, in the browser / yes, here / no)';
150
205
  function askToReview(before, after, checkin) {
151
206
  if (checkin === 'quiet' || Math.floor(after / exports.REVIEW_EVERY) <= Math.floor(before / exports.REVIEW_EVERY))
152
207
  return {};
153
- return { ask: `You have ${after} changes waiting in Arbiter. Review them now? (yes / no)` };
208
+ return { ask: `You have ${after} changes waiting in Arbiter. Review them now? ${exports.REVIEW_ANSWERS}` };
154
209
  }
155
210
  /** Queue one pending decision per finding in a scanner's JSON output. */
156
211
  function queueFindings(file, opts = {}) {
@@ -239,6 +294,30 @@ function retire(ruleId, why, opts = {}) {
239
294
  };
240
295
  return recordInput(input, opts);
241
296
  }
297
+ /**
298
+ * Undo for a retire, for a misclick on the board: the rule is back in DECISIONS.md as it was, and
299
+ * the retire entry leaves the record. Only while DECISIONS.md has room and nothing has built on it since.
300
+ */
301
+ function unretire(r, opts = {}) {
302
+ const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
303
+ const archive = (0, store_1.readArchive)(paths);
304
+ if (!archive.some((d) => d.id === r.id))
305
+ return fail([`${r.id} is no longer in the record`]);
306
+ const active = (0, store_1.readActive)(paths);
307
+ if (active.some((d) => d.id === r.rule.id))
308
+ return fail([`${r.rule.id} is a rule already`]);
309
+ const later = archive.find((d) => (d.id !== r.id && d.supersedes === r.rule.id) || d.supersedes === r.id);
310
+ if (later)
311
+ return fail([`${later.id} has changed ${r.rule.id} since, so it can't come back`]);
312
+ const cap = (0, store_1.readConfig)(paths)?.activeCap ?? store_1.ACTIVE_CAP;
313
+ if (active.length >= cap)
314
+ return fail([`${(0, store_1.rulesName)(paths)} is full (${cap} rules), so ${r.rule.id} can't come back until one goes`]);
315
+ (0, store_1.writeArchive)(paths, archive.filter((d) => d.id !== r.id));
316
+ (0, store_1.writeActive)(paths, [...active, r.rule], cap);
317
+ if (r.rule.candidate)
318
+ (0, candidate_1.refreshCandidates)(paths);
319
+ return { exitCode: 0, output: { status: 'restored', id: r.rule.id, removed: r.id, active: `${active.length + 1} of ${cap}` } };
320
+ }
242
321
  // ── Reword a rule ──────────────────────────────────────────────────────────
243
322
  /**
244
323
  * Same rule, clearer words: "Pills are outlined" becomes "Status pills are outlined", or a rule that
@@ -280,7 +359,7 @@ function reword(ruleId, to, opts = {}) {
280
359
  id: ruleId,
281
360
  decision: next,
282
361
  was: rule.decision,
283
- wrote: opts.dryRun ? [] : ['DECISIONS.md', '.arbiter/archive.md'],
362
+ wrote: opts.dryRun ? [] : [(0, store_1.rulesName)(paths), '.arbiter/archive.md'],
284
363
  },
285
364
  };
286
365
  }
@@ -366,6 +445,49 @@ function judgeAll(opts) {
366
445
  },
367
446
  };
368
447
  }
448
+ /**
449
+ * Undo, for a misclick: the decision leaves the record, a rule it replaced is a rule again, and the
450
+ * item waits where it was, with its id. Only while nothing has built on it since: a later rule
451
+ * replacing it, or a request answered by it.
452
+ */
453
+ function unjudge(j, opts = {}) {
454
+ const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
455
+ const pending = (0, store_1.readPending)(paths);
456
+ if (pending.some((d) => d.id === j.item.id))
457
+ return fail([`${j.item.id} is already waiting`]);
458
+ let reinstated;
459
+ const id = j.id;
460
+ if (id) {
461
+ const archive = (0, store_1.readArchive)(paths);
462
+ const entry = archive.find((d) => d.id === id);
463
+ if (!entry)
464
+ return fail([`${id} is no longer in the record`]);
465
+ const later = archive.find((d) => d.supersedes === id);
466
+ if (later)
467
+ return fail([`${later.id} has replaced ${id} since, so it can't be taken back`]);
468
+ const asked = (0, requests_1.readRequests)(paths).find((r) => r.decision === id || r.decisions.includes(id));
469
+ if (asked)
470
+ return fail([`${asked.id} is about ${id} now, so it can't be taken back`]);
471
+ (0, store_1.writeArchive)(paths, archive.filter((d) => d.id !== id));
472
+ const active = (0, store_1.readActive)(paths);
473
+ let next = active.filter((d) => d.id !== id);
474
+ const r = j.replaced;
475
+ // Back where it was, unless something else has made it a rule again or taken it out since.
476
+ if (r && !next.some((d) => d.id === r.rule.id) && archive.some((d) => d.id === r.rule.id) && !archive.some((d) => d.id !== id && d.supersedes === r.rule.id)) {
477
+ next = [...next.slice(0, r.at), r.rule, ...next.slice(r.at)];
478
+ reinstated = r.rule.id;
479
+ }
480
+ if (next.length !== active.length || reinstated)
481
+ (0, store_1.writeActive)(paths, next, (0, store_1.readConfig)(paths)?.activeCap ?? store_1.ACTIVE_CAP);
482
+ if (entry.candidate)
483
+ (0, candidate_1.refreshCandidates)(paths);
484
+ }
485
+ (0, store_1.writePending)(paths, [...pending.slice(0, j.at), j.item, ...pending.slice(j.at)]);
486
+ return {
487
+ exitCode: 0,
488
+ output: { status: 'undone', id: j.item.id, ...(id && { removed: id }), ...(reinstated && { reinstated }), pending: pending.length + 1 },
489
+ };
490
+ }
369
491
  // ── Core ───────────────────────────────────────────────────────────────────
370
492
  function recordInput(input, opts = {}) {
371
493
  if (opts.supersedes && opts.keepBoth)
@@ -421,17 +543,19 @@ function recordInput(input, opts = {}) {
421
543
  else if (!opts.keepBoth) {
422
544
  const overlaps = (0, overlap_1.findOverlaps)(input, active, { ignore: config?.overlap?.ignore });
423
545
  if (overlaps.length) {
546
+ // Each also says why in plain words (sure: what both apply to; a guess: the words they share), for the board.
547
+ const why = (0, overlap_1.explainOverlaps)(input, overlaps, active, new Map((0, candidates_1.readCandidates)(paths).map((c) => [c.id, c.name])));
424
548
  return keepRequest({
425
549
  exitCode: 2,
426
550
  output: {
427
551
  status: 'overlap',
428
552
  message: `This rule overlaps ${overlaps.length} active rule${overlaps.length === 1 ? '' : 's'}. Nothing was written. Ask the user which it replaces, then re-run.`,
429
553
  candidate: input,
430
- overlaps,
554
+ overlaps: overlaps.map((o, i) => ({ ...o, ...why[i] })),
431
555
  options: [
432
556
  ...overlaps.map((o) => ({
433
557
  flag: `--supersedes ${o.id}${again}`,
434
- effect: `${o.id} leaves DECISIONS.md and stays in the archive; the new rule records supersedes: ${o.id}`,
558
+ effect: `${o.id} leaves ${(0, store_1.rulesName)(paths)} and stays in the archive; the new rule records supersedes: ${o.id}`,
435
559
  })),
436
560
  { flag: `--keep-both${again}`, effect: 'both rules stay active' },
437
561
  ],
@@ -444,7 +568,8 @@ function recordInput(input, opts = {}) {
444
568
  exitCode: 3,
445
569
  output: {
446
570
  status: 'cap',
447
- message: `DECISIONS.md holds ${nextActive.length} of ${cap} rules. Nothing was written. Supersede an existing rule with --supersedes <id> to make room.`,
571
+ cap,
572
+ message: `${(0, store_1.rulesName)(paths)} holds ${nextActive.length} of ${cap} rules. Nothing was written. Supersede an existing rule with --supersedes <id> to make room.`,
448
573
  candidate: input,
449
574
  active: nextActive.map((d) => ({ id: d.id, decision: d.decision, scope: d.scope })),
450
575
  },
@@ -482,7 +607,7 @@ function recordInput(input, opts = {}) {
482
607
  candidate: entry.candidate,
483
608
  ...(entry.against && { against: entry.against }),
484
609
  active: `${nextActive.length} of ${cap}`,
485
- wrote: opts.dryRun ? [] : entry.verdict === 'rule' || entry.verdict === 'retire' ? ['.arbiter/archive.md', 'DECISIONS.md'] : ['.arbiter/archive.md'],
610
+ wrote: opts.dryRun ? [] : entry.verdict === 'rule' || entry.verdict === 'retire' ? ['.arbiter/archive.md', (0, store_1.rulesName)(paths)] : ['.arbiter/archive.md'],
486
611
  ...(request && { request: { id: request.id, status: opts.dryRun ? request.status : 'applied', author: request.author } }),
487
612
  ...(sweepSummary && { sweep: sweepSummary }),
488
613
  ...picture(paths, entry),
@@ -93,7 +93,7 @@ function removeDecision(id, opts) {
93
93
  ...(replaced ? { note: `${replaced.id} — which ${id} replaced — is still inactive. Record it again if it should apply.` } : {}),
94
94
  ...(reopened.length ? { requests: `${reopened.join(', ')} ${reopened.length === 1 ? 'is' : 'are'} open again — nothing on record makes ${reopened.length === 1 ? 'that change' : 'those changes'} now, so ${reopened.length === 1 ? 'it needs' : 'they need'} a fresh answer` } : {}),
95
95
  ...(reused ? { idReuse: `${id} was the newest, so the next decision recorded will take that id again. If this board is published, comments on the old ${id} will read as if they were about the new one — republish after recording.` } : {}),
96
- wrote: ['.arbiter/archive.md', ...(isActive ? ['DECISIONS.md'] : []), ...touched, ...(detached.length ? ['.arbiter/requests.json'] : [])],
96
+ wrote: ['.arbiter/archive.md', ...(isActive ? [(0, store_1.rulesName)(paths)] : []), ...touched, ...(detached.length ? ['.arbiter/requests.json'] : [])],
97
97
  // Printed in full so it can be put back by hand — not everyone has git.
98
98
  removed: (0, format_1.formatEntry)(entry).trimEnd(),
99
99
  },
@@ -8,6 +8,10 @@
8
8
  * the repo keeps it — the archive, the queue, DECISIONS.md, its picture, requests and comments —
9
9
  * and notes the move in .arbiter/renamed.json, so the next publish moves the board's comments too.
10
10
  *
11
+ * With `--merge`, the new name may be one a piece of work already has: this one joins it. Its decisions take
12
+ * that name, its pictures join that one's by when each was taken, and its comments and requests move to
13
+ * it. For work started under a new name that turned out to continue an existing change.
14
+ *
11
15
  * Screens (C-0002) aren't renamed here: their id is a number, so a new name never moves a comment.
12
16
  */
13
17
  var __importDefault = (this && this.__importDefault) || function (mod) {
@@ -19,7 +23,7 @@ const node_fs_1 = __importDefault(require("node:fs"));
19
23
  const node_path_1 = __importDefault(require("node:path"));
20
24
  const store_1 = require("../store");
21
25
  const candidates_1 = require("../candidates");
22
- const hosted_1 = require("../hosted");
26
+ const comments_1 = require("../comments");
23
27
  const requests_1 = require("../requests");
24
28
  const work_1 = require("../work");
25
29
  const fail = (errors) => ({ exitCode: 1, output: { status: 'invalid', errors } });
@@ -49,12 +53,14 @@ function renameWork(from, to, opts = {}) {
49
53
  const current = found[0].trigger;
50
54
  if (current === newName)
51
55
  return fail([`"${current}" is already called that`]);
52
- // Two pieces of work with one id would be one card with two names. Merging them is a different act.
56
+ // Two pieces of work with one id would be one card with two names: merging them is asked for by name.
53
57
  const taken = newId !== oldId ? all.find((d) => (0, work_1.workId)(d.trigger) === newId) : undefined;
54
- if (taken)
55
- return fail([`there's already a piece of work called "${taken.trigger}" — renaming "${current}" onto it would merge the two`]);
58
+ if (taken && !opts.merge)
59
+ return fail([`there's already a piece of work called "${taken.trigger}" — renaming "${current}" onto it would merge the two. To merge them: npx arbiter rename "${current}" "${taken.trigger}" --merge`]);
60
+ // Merged, its decisions take the other's name exactly as that one has it.
61
+ const target = taken ? taken.trigger : newName;
56
62
  const wrote = [];
57
- const rename = (ds) => ds.map((d) => (mine(d) ? { ...d, trigger: newName } : d));
63
+ const rename = (ds) => ds.map((d) => (mine(d) ? { ...d, trigger: target } : d));
58
64
  if (archive.some(mine)) {
59
65
  (0, store_1.writeArchive)(paths, rename(archive));
60
66
  wrote.push('.arbiter/archive.md');
@@ -65,12 +71,17 @@ function renameWork(from, to, opts = {}) {
65
71
  }
66
72
  if (active.some(mine)) {
67
73
  (0, store_1.writeActive)(paths, rename(active));
68
- wrote.push('DECISIONS.md');
74
+ wrote.push((0, store_1.rulesName)(paths));
69
75
  }
70
76
  if (newId !== oldId) {
77
+ // Merged: its pictures join the other's, in the order they were taken.
78
+ if (taken) {
79
+ if ((0, work_1.mergePictures)(paths, oldId, newId))
80
+ wrote.push(`.arbiter/work/${newId}`);
81
+ }
71
82
  // The picture is filed under the id; it follows. Anything already filed under the new id belongs
72
83
  // to no decision (that was checked above), so it's a leftover and goes.
73
- const shot = (0, work_1.workSnapshot)(paths, oldId);
84
+ const shot = taken ? null : (0, work_1.workSnapshot)(paths, oldId);
74
85
  if (shot) {
75
86
  const stale = (0, work_1.workSnapshot)(paths, newId);
76
87
  if (stale)
@@ -79,14 +90,17 @@ function renameWork(from, to, opts = {}) {
79
90
  node_fs_1.default.renameSync(shot, next);
80
91
  wrote.push(`.arbiter/work/${node_path_1.default.basename(next)}`);
81
92
  }
93
+ // Its earlier pictures go with it.
94
+ if (!taken && (0, work_1.moveHistory)(paths, oldId, newId))
95
+ wrote.push(`.arbiter/work/history/${newId}/`);
82
96
  const requests = (0, requests_1.readRequests)(paths);
83
97
  if (requests.some((r) => r.screen === oldId)) {
84
98
  (0, requests_1.writeRequests)(paths, requests.map((r) => (r.screen === oldId ? { ...r, screen: newId } : r)));
85
99
  wrote.push('.arbiter/requests.json');
86
100
  }
87
- const comments = (0, hosted_1.readComments)(paths);
101
+ const comments = (0, comments_1.readComments)(paths);
88
102
  if (comments.some((c) => c.candidate_id === oldId)) {
89
- (0, hosted_1.writeComments)(paths, comments.map((c) => (c.candidate_id === oldId ? { ...c, candidate_id: newId } : c)));
103
+ (0, comments_1.writeComments)(paths, comments.map((c) => (c.candidate_id === oldId ? { ...c, candidate_id: newId } : c)));
90
104
  wrote.push('.arbiter/comments.json');
91
105
  }
92
106
  (0, work_1.addRename)(paths, oldId, newId);
@@ -95,9 +109,9 @@ function renameWork(from, to, opts = {}) {
95
109
  return {
96
110
  exitCode: 0,
97
111
  output: {
98
- status: 'renamed',
112
+ status: taken ? 'merged' : 'renamed',
99
113
  from: current,
100
- to: newName,
114
+ to: target,
101
115
  decisions: found.length,
102
116
  ...(newId !== oldId ? { card: { from: oldId, to: newId } } : {}),
103
117
  wrote,