arbiterdesign 0.1.7 → 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.
Files changed (44) hide show
  1. package/README.md +38 -40
  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 +89 -2
  11. package/dist/commands/prompt.js +12 -4
  12. package/dist/commands/publish.js +18 -1
  13. package/dist/commands/record.js +152 -3
  14. package/dist/commands/rename.js +123 -0
  15. package/dist/commands/review.js +469 -76
  16. package/dist/commands/rules.js +8 -1
  17. package/dist/commands/setup.js +1 -0
  18. package/dist/commands/snapshot.js +24 -2
  19. package/dist/commands/sweep.js +1 -1
  20. package/dist/commands/unpublish.js +88 -0
  21. package/dist/comments.js +24 -0
  22. package/dist/handoff.js +283 -0
  23. package/dist/hook.js +80 -0
  24. package/dist/hosted.js +117 -20
  25. package/dist/index.js +93 -24
  26. package/dist/localboard.js +219 -0
  27. package/dist/lock.js +134 -0
  28. package/dist/overlap.js +16 -0
  29. package/dist/pictures.js +4 -0
  30. package/dist/settings.js +107 -0
  31. package/dist/store.js +6 -5
  32. package/dist/verify.js +4 -2
  33. package/dist/wording.js +65 -0
  34. package/dist/work.js +139 -1
  35. package/package.json +3 -2
  36. package/templates/SKILL.md +169 -50
  37. package/templates/board/board.css +2 -0
  38. package/templates/board/board.js +25 -0
  39. package/templates/board/index.html +15 -0
  40. package/templates/fonts/Geist-Variable.woff2 +0 -0
  41. package/templates/fonts/GeistMono-Variable.woff2 +0 -0
  42. package/templates/fonts/OFL.txt +92 -0
  43. package/templates/hooks/arbiter-board.cjs +50 -0
  44. package/templates/review.html +0 -600
@@ -15,6 +15,8 @@ exports.selfVersion = selfVersion;
15
15
  exports.skillPath = skillPath;
16
16
  exports.init = init;
17
17
  exports.detectClient = detectClient;
18
+ exports.askCheckin = askCheckin;
19
+ exports.checkinHandoff = checkinHandoff;
18
20
  exports.detectPm = detectPm;
19
21
  exports.addDevDependency = addDevDependency;
20
22
  const node_fs_1 = __importDefault(require("node:fs"));
@@ -24,6 +26,10 @@ const node_child_process_1 = require("node:child_process");
24
26
  const store_1 = require("../store");
25
27
  const format_1 = require("../format");
26
28
  const prompt_1 = require("./prompt");
29
+ const setup_1 = require("./setup");
30
+ const hook_1 = require("../hook");
31
+ const handoff_1 = require("../handoff");
32
+ const lock_1 = require("../lock");
27
33
  const AGENTS_MARKER = '<!-- arbiter -->';
28
34
  /**
29
35
  * The one line in AGENTS.md and CLAUDE.md. It's always loaded, so it carries the one thing that has
@@ -87,8 +93,36 @@ async function init(opts = {}) {
87
93
  author = guess;
88
94
  }
89
95
  }
96
+ // ── Question 3: how Arbiter checks in while you work ─────────────────
97
+ // Asked once, here, so no /arbiter has to. Nobody at the terminal (an agent ran this, or
98
+ // --yes): it stays unanswered, and the closing lines hand the question to the agent.
99
+ let checkin = existing?.checkin;
100
+ let onboarded = existing?.onboarded;
101
+ if (opts.checkin !== undefined) {
102
+ if (!setup_1.CHECKINS.includes(opts.checkin))
103
+ throw new Error(`--checkin must be one of ${setup_1.CHECKINS.join(' | ')}`);
104
+ checkin = opts.checkin;
105
+ onboarded ??= (0, store_1.now)();
106
+ }
107
+ else if (!onboarded && ask) {
108
+ const picked = await askCheckin(ask);
109
+ if (picked) {
110
+ checkin = picked;
111
+ onboarded = (0, store_1.now)();
112
+ }
113
+ }
90
114
  // ── arbiter.json ─────────────────────────────────────────────────────
91
- const config = { version: 1, destination: 'local', hosted: { url: 'https://arbiter.design' }, ...existing, author, client, ...(opts.destination && { destination: opts.destination }) };
115
+ const config = {
116
+ version: 1,
117
+ destination: 'local',
118
+ hosted: { url: 'https://arbiter.design' },
119
+ ...existing,
120
+ author,
121
+ client,
122
+ ...(opts.destination && { destination: opts.destination }),
123
+ ...(checkin && { checkin }),
124
+ ...(onboarded && { onboarded }),
125
+ };
92
126
  if (!existing) {
93
127
  (0, store_1.writeConfig)(paths, config);
94
128
  steps.push({ file: 'arbiter.json', outcome: 'created' });
@@ -110,7 +144,13 @@ async function init(opts = {}) {
110
144
  }
111
145
  // ── .arbiter/archive.md ──────────────────────────────────────────────
112
146
  node_fs_1.default.mkdirSync(paths.archiveDir, { recursive: true });
113
- steps.push(writeIfChanged(root, node_path_1.default.join('.arbiter', '.gitignore'), 'hosted.token\n'));
147
+ // Never committed: the publish token, what the board hands this machine's agent and what it was told
148
+ // (a teammate's agent mustn't make it), and the lock a write holds for a moment. Lines already there
149
+ // stay, so a re-run never un-ignores anything.
150
+ const ignore = node_path_1.default.join(paths.archiveDir, '.gitignore');
151
+ const had = node_fs_1.default.existsSync(ignore) ? node_fs_1.default.readFileSync(ignore, 'utf8').split(/\r?\n/).filter(Boolean) : [];
152
+ const lines = [...had, ...['hosted.token', handoff_1.FILE, handoff_1.SEEN, lock_1.LOCK].filter((x) => !had.includes(x))];
153
+ steps.push(writeIfChanged(root, node_path_1.default.join('.arbiter', '.gitignore'), lines.join('\n') + '\n'));
114
154
  if (node_fs_1.default.existsSync(paths.archive)) {
115
155
  steps.push({ file: '.arbiter/archive.md', outcome: 'unchanged' });
116
156
  }
@@ -127,6 +167,8 @@ async function init(opts = {}) {
127
167
  if (client === 'claude-code') {
128
168
  // Claude Code's own context file. Same line, same marker; created if missing so injection has a path that's certain to load.
129
169
  steps.push(mergeAgentsLine(root, 'CLAUDE.md', true));
170
+ // The hook that hands the agent what you judged on the board, with your next message.
171
+ steps.push(...(0, hook_1.installHook)(root));
130
172
  }
131
173
  else {
132
174
  // Cursor has no skill-invoked slash commands; give it a command file that does what `/arbiter` does.
@@ -149,6 +191,51 @@ function detectClient(root) {
149
191
  return out;
150
192
  }
151
193
  const label = (c) => (c === 'cursor' ? 'Cursor' : 'Claude Code');
194
+ /** The one preference Arbiter asks for. The skill asks the same, in the same words, when install couldn't. */
195
+ const CHECKIN_QUESTION = 'When should Arbiter check in about decisions while you work?';
196
+ const CHECKIN_OPTIONS = [
197
+ { mode: 'feature', label: 'A line after big work (recommended)', detail: 'When a feature-sized piece settles, one sentence saying what changed. Every 5 changes waiting, a yes/no on reviewing. Never mid-iteration.' },
198
+ { mode: 'quiet', label: 'Nothing until I ask', detail: 'Saved silently. Asks only when something clashes with a rule. /arbiter whenever you want to see it.' },
199
+ { mode: 'every', label: 'A line after everything', detail: 'One sentence every time a piece of work settles, big or small. Every 5 changes waiting, a yes/no on reviewing.' },
200
+ ];
201
+ /**
202
+ * The check-in question at the terminal. Enter takes the recommended one. Null when input ended
203
+ * with no answer: an agent ran install, and a choice nobody made mustn't be recorded as theirs.
204
+ */
205
+ async function askCheckin(ask) {
206
+ const menu = CHECKIN_OPTIONS.map((o, i) => ` ${i + 1}. ${o.label}. ${o.detail}`).join('\n');
207
+ let q = `\n${CHECKIN_QUESTION}\n${menu}\n(1): `;
208
+ for (;;) {
209
+ const a = await ask.answer(q);
210
+ if (a === null)
211
+ return null;
212
+ const t = a.trim().toLowerCase();
213
+ if (!t)
214
+ return 'feature';
215
+ const n = Number(t);
216
+ if (Number.isInteger(n) && n >= 1 && n <= CHECKIN_OPTIONS.length)
217
+ return CHECKIN_OPTIONS[n - 1].mode;
218
+ if (setup_1.CHECKINS.includes(t))
219
+ return t;
220
+ q = 'Pick 1, 2 or 3 (1): ';
221
+ }
222
+ }
223
+ /**
224
+ * Install's closing lines when nobody at the terminal answered the check-in question. Usually an
225
+ * agent ran it: it asks the user in chat, on its own, then saves the answer. Bundled with review
226
+ * questions it got dismissed with them and came back on every /arbiter.
227
+ */
228
+ function checkinHandoff() {
229
+ const w = Math.max(...setup_1.CHECKINS.map((c) => c.length));
230
+ return [
231
+ '',
232
+ `One question left, asked once. ${CHECKIN_QUESTION}`,
233
+ ...CHECKIN_OPTIONS.map((o) => ` ${o.mode.padEnd(w)} ${o.label}. ${o.detail}`),
234
+ 'Save the answer: npx arbiter setup --checkin feature (or quiet, or every)',
235
+ 'Agent: ask the user now, in chat, as one pick-one question on its own, then save their answer. No answer means feature.',
236
+ '',
237
+ ].join('\n');
238
+ }
152
239
  function skillFor(client) {
153
240
  // A Windows checkout with autocrlf hands us CRLF; the frontmatter regex and the marker line assume LF.
154
241
  const template = node_fs_1.default.readFileSync(SKILL_TEMPLATE, 'utf8').replace(/\r\n/g, '\n');
@@ -12,11 +12,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Prompter = void 0;
13
13
  const node_readline_1 = __importDefault(require("node:readline"));
14
14
  class Prompter {
15
- rl = node_readline_1.default.createInterface({ input: process.stdin, terminal: false });
15
+ rl;
16
16
  lines = [];
17
17
  waiting = [];
18
18
  closed = false;
19
- constructor() {
19
+ constructor(input = process.stdin) {
20
+ this.rl = node_readline_1.default.createInterface({ input, terminal: false });
20
21
  this.rl.on('line', (l) => {
21
22
  const w = this.waiting.shift();
22
23
  if (w)
@@ -27,16 +28,23 @@ class Prompter {
27
28
  this.rl.on('close', () => {
28
29
  this.closed = true;
29
30
  for (const w of this.waiting.splice(0))
30
- w('');
31
+ w(null);
31
32
  });
32
33
  }
33
34
  question(q) {
35
+ return this.answer(q).then((a) => a ?? '');
36
+ }
37
+ /**
38
+ * Like question, but null when input ended with no line for it: nobody is there to answer.
39
+ * That's an agent running the command (its input is closed), not someone pressing Enter.
40
+ */
41
+ answer(q) {
34
42
  process.stdout.write(q);
35
43
  const l = this.lines.shift();
36
44
  if (l !== undefined)
37
45
  return Promise.resolve(l);
38
46
  if (this.closed)
39
- return Promise.resolve('');
47
+ return Promise.resolve(null);
40
48
  return new Promise((res) => this.waiting.push(res));
41
49
  }
42
50
  /** Ask until non-empty, or return the default. */
@@ -40,11 +40,28 @@ async function publish(opts = {}) {
40
40
  // Hosted by default: the flag, then arbiter.json, then arbiter.design. `--to pages` is the git route.
41
41
  const chosen = opts.to ?? (0, store_1.readConfig)(paths)?.hosted?.url ?? exports.DEFAULT_HOST;
42
42
  const to = chosen === 'pages' || chosen === 'git' ? null : chosen;
43
+ if (opts.password !== undefined && !to) {
44
+ fail('password', 'a GitHub Pages site is public; only a hosted board can ask for a password');
45
+ return { ok: false, steps, url: null };
46
+ }
47
+ // Checked before anything is created, so a short one never leaves a new board up without it.
48
+ if (typeof opts.password === 'string' && opts.password.length < hosted_1.PASSWORD_MIN) {
49
+ fail('password', `at least ${hosted_1.PASSWORD_MIN} characters — or leave it out and get one made up: npx arbiter publish --password`);
50
+ return { ok: false, steps, url: null };
51
+ }
43
52
  if (to) {
53
+ const password = opts.password === undefined ? undefined : opts.password === false ? null : opts.password === true ? (0, hosted_1.newPassword)() : opts.password;
44
54
  try {
45
- const r = await (0, hosted_1.publishHosted)(paths, to, { admin: opts.admin });
55
+ const r = await (0, hosted_1.publishHosted)(paths, to, { admin: opts.admin, password });
46
56
  if (r.created)
47
57
  done('project', `created on ${to} — link in .arbiter/hosted.json (commit it); token in .arbiter/hosted.token (git-ignored — teammates set ARBITER_PUBLISH_TOKEN)`);
58
+ // A made-up password is printed once, here: the service keeps only a hash. One you chose isn't echoed.
59
+ if (password === null)
60
+ done('password', 'off — anyone with the link can see the board');
61
+ else if (password !== undefined)
62
+ done('password', opts.password === true
63
+ ? `${password} — send it with the link. It isn't saved anywhere it can be read back; to change it, run --password again`
64
+ : 'set — send it with the link');
48
65
  // No image count: a card without a picture shows an icon of its kind, and that's usually right.
49
66
  done('board', `${r.candidates} screen${r.candidates === 1 ? '' : 's'} published`);
50
67
  for (const s of r.skipped)
@@ -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,11 +52,17 @@ 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");
56
+ const wording_1 = require("../wording");
57
+ const areas_1 = require("./areas");
51
58
  // ── Parse + record ─────────────────────────────────────────────────────────
52
59
  function record(rawJson, opts = {}) {
53
60
  const parsed = parse(rawJson);
54
61
  if (!parsed.ok)
55
62
  return parsed.result;
63
+ const unclear = plainWords(parsed.input);
64
+ if (unclear)
65
+ return unclear;
56
66
  const bad = againstError((0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd)), parsed.input);
57
67
  if (bad)
58
68
  return bad;
@@ -68,6 +78,46 @@ function againstError(paths, input) {
68
78
  return null;
69
79
  return fail([`against: ${input.against} is not an active rule`]);
70
80
  }
81
+ /**
82
+ * A PM or a designer reads these lines, so one in code words or one that runs on is refused
83
+ * before it's written, and the agent says it again. Nothing is written either way.
84
+ */
85
+ function plainWords(input) {
86
+ const problems = (0, wording_1.unclearLines)(input);
87
+ if (!problems.length)
88
+ return null;
89
+ return {
90
+ exitCode: 1,
91
+ output: {
92
+ status: 'unclear',
93
+ errors: problems,
94
+ hint: "Nothing was written. Rewrite these lines in a PM's or designer's words, 20 words or fewer, and run it again.",
95
+ },
96
+ };
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
+ }
71
121
  function queue(rawJson, opts = {}) {
72
122
  if (opts.request)
73
123
  return fail([`--request records a change made for an approved request, directly: drop --pending. Nothing is queued for a request.`]);
@@ -75,6 +125,13 @@ function queue(rawJson, opts = {}) {
75
125
  if (!parsed.ok)
76
126
  return parsed.result;
77
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 } };
132
+ const unclear = plainWords(parsed.input);
133
+ if (unclear)
134
+ return unclear;
78
135
  const bad = againstError(paths, parsed.input);
79
136
  if (bad)
80
137
  return bad;
@@ -111,22 +168,44 @@ function queue(rawJson, opts = {}) {
111
168
  ...(opts.dryRun ? {} : askToReview(before, waiting, checkin)),
112
169
  review: 'npx arbiter review',
113
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)),
114
175
  // Present only when the project's skill file is from an older Arbiter than this one.
115
176
  ...(0, update_1.updateNotice)(paths),
116
177
  },
117
178
  };
118
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
+ }
119
196
  /** Ask once each time the waiting count reaches another multiple of this. */
120
197
  exports.REVIEW_EVERY = 5;
121
198
  /**
122
199
  * At 5, 10, 15 changes waiting, the agent asks whether to review now. A "no" just waits for the
123
200
  * next multiple, and judging brings the count down, so the next ask comes when it climbs back.
124
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.
125
203
  */
204
+ exports.REVIEW_ANSWERS = '(yes, in the browser / yes, here / no)';
126
205
  function askToReview(before, after, checkin) {
127
206
  if (checkin === 'quiet' || Math.floor(after / exports.REVIEW_EVERY) <= Math.floor(before / exports.REVIEW_EVERY))
128
207
  return {};
129
- 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}` };
130
209
  }
131
210
  /** Queue one pending decision per finding in a scanner's JSON output. */
132
211
  function queueFindings(file, opts = {}) {
@@ -215,6 +294,30 @@ function retire(ruleId, why, opts = {}) {
215
294
  };
216
295
  return recordInput(input, opts);
217
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([`DECISIONS.md 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
+ }
218
321
  // ── Reword a rule ──────────────────────────────────────────────────────────
219
322
  /**
220
323
  * Same rule, clearer words: "Pills are outlined" becomes "Status pills are outlined", or a rule that
@@ -342,6 +445,49 @@ function judgeAll(opts) {
342
445
  },
343
446
  };
344
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
+ }
345
491
  // ── Core ───────────────────────────────────────────────────────────────────
346
492
  function recordInput(input, opts = {}) {
347
493
  if (opts.supersedes && opts.keepBoth)
@@ -397,13 +543,15 @@ function recordInput(input, opts = {}) {
397
543
  else if (!opts.keepBoth) {
398
544
  const overlaps = (0, overlap_1.findOverlaps)(input, active, { ignore: config?.overlap?.ignore });
399
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])));
400
548
  return keepRequest({
401
549
  exitCode: 2,
402
550
  output: {
403
551
  status: 'overlap',
404
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.`,
405
553
  candidate: input,
406
- overlaps,
554
+ overlaps: overlaps.map((o, i) => ({ ...o, ...why[i] })),
407
555
  options: [
408
556
  ...overlaps.map((o) => ({
409
557
  flag: `--supersedes ${o.id}${again}`,
@@ -420,6 +568,7 @@ function recordInput(input, opts = {}) {
420
568
  exitCode: 3,
421
569
  output: {
422
570
  status: 'cap',
571
+ cap,
423
572
  message: `DECISIONS.md holds ${nextActive.length} of ${cap} rules. Nothing was written. Supersede an existing rule with --supersedes <id> to make room.`,
424
573
  candidate: input,
425
574
  active: nextActive.map((d) => ({ id: d.id, decision: d.decision, scope: d.scope })),
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ /**
3
+ * `arbiter rename "<old name>" "<new name>"` — rename a piece of work, keeping its comments.
4
+ *
5
+ * A piece of work is the decisions that share a `trigger`, and its card id on the board comes from
6
+ * that name (`Settings build` → `W-settings-build`). Changing the name by hand made a new card and
7
+ * left every comment on the old one, which the board no longer shows. This renames it everywhere
8
+ * the repo keeps it — the archive, the queue, DECISIONS.md, its picture, requests and comments —
9
+ * and notes the move in .arbiter/renamed.json, so the next publish moves the board's comments too.
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
+ *
15
+ * Screens (C-0002) aren't renamed here: their id is a number, so a new name never moves a comment.
16
+ */
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.renameWork = renameWork;
22
+ const node_fs_1 = __importDefault(require("node:fs"));
23
+ const node_path_1 = __importDefault(require("node:path"));
24
+ const store_1 = require("../store");
25
+ const candidates_1 = require("../candidates");
26
+ const comments_1 = require("../comments");
27
+ const requests_1 = require("../requests");
28
+ const work_1 = require("../work");
29
+ const fail = (errors) => ({ exitCode: 1, output: { status: 'invalid', errors } });
30
+ function renameWork(from, to, opts = {}) {
31
+ const root = (0, store_1.findRoot)(opts.cwd);
32
+ const paths = (0, store_1.resolvePaths)(root);
33
+ const oldName = (0, requests_1.oneLine)(from ?? '');
34
+ const newName = (0, requests_1.oneLine)(to ?? '');
35
+ if (!oldName || !newName)
36
+ return fail(['name the piece of work and what to call it: npx arbiter rename "Settings build" "Settings — billing"']);
37
+ const screen = (0, candidates_1.readCandidates)(paths).find((c) => c.id === oldName || c.name === oldName);
38
+ if (screen)
39
+ return fail([`${screen.id} is a screen, not a piece of work. Its id doesn't come from its name, so its comments stay with it whatever it's called.`]);
40
+ // By id, so case and punctuation don't matter, the way `snapshot` finds work. The id itself works too.
41
+ const oldId = /^W-[a-z0-9-]+$/.test(oldName) ? oldName : (0, work_1.workId)(oldName);
42
+ const newId = (0, work_1.workId)(newName);
43
+ if (newId === 'W-')
44
+ return fail([`"${newName}" has no letters or numbers to name a card by`]);
45
+ const mine = (d) => (0, work_1.workId)(d.trigger) === oldId;
46
+ const archive = (0, store_1.readArchive)(paths);
47
+ const pending = (0, store_1.readPending)(paths);
48
+ const active = (0, store_1.readActive)(paths);
49
+ const all = [...archive, ...pending];
50
+ const found = all.filter(mine);
51
+ if (!found.length)
52
+ return fail([`no piece of work called "${oldName}" — name it as its decisions did (npx arbiter rules --archive shows them)`]);
53
+ const current = found[0].trigger;
54
+ if (current === newName)
55
+ return fail([`"${current}" is already called that`]);
56
+ // Two pieces of work with one id would be one card with two names: merging them is asked for by name.
57
+ const taken = newId !== oldId ? all.find((d) => (0, work_1.workId)(d.trigger) === newId) : undefined;
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;
62
+ const wrote = [];
63
+ const rename = (ds) => ds.map((d) => (mine(d) ? { ...d, trigger: target } : d));
64
+ if (archive.some(mine)) {
65
+ (0, store_1.writeArchive)(paths, rename(archive));
66
+ wrote.push('.arbiter/archive.md');
67
+ }
68
+ if (pending.some(mine)) {
69
+ (0, store_1.writePending)(paths, rename(pending));
70
+ wrote.push('.arbiter/pending.md');
71
+ }
72
+ if (active.some(mine)) {
73
+ (0, store_1.writeActive)(paths, rename(active));
74
+ wrote.push('DECISIONS.md');
75
+ }
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
+ }
82
+ // The picture is filed under the id; it follows. Anything already filed under the new id belongs
83
+ // to no decision (that was checked above), so it's a leftover and goes.
84
+ const shot = taken ? null : (0, work_1.workSnapshot)(paths, oldId);
85
+ if (shot) {
86
+ const stale = (0, work_1.workSnapshot)(paths, newId);
87
+ if (stale)
88
+ node_fs_1.default.rmSync(stale, { force: true });
89
+ const next = node_path_1.default.join((0, work_1.workDir)(paths), newId + node_path_1.default.extname(shot));
90
+ node_fs_1.default.renameSync(shot, next);
91
+ wrote.push(`.arbiter/work/${node_path_1.default.basename(next)}`);
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}/`);
96
+ const requests = (0, requests_1.readRequests)(paths);
97
+ if (requests.some((r) => r.screen === oldId)) {
98
+ (0, requests_1.writeRequests)(paths, requests.map((r) => (r.screen === oldId ? { ...r, screen: newId } : r)));
99
+ wrote.push('.arbiter/requests.json');
100
+ }
101
+ const comments = (0, comments_1.readComments)(paths);
102
+ if (comments.some((c) => c.candidate_id === oldId)) {
103
+ (0, comments_1.writeComments)(paths, comments.map((c) => (c.candidate_id === oldId ? { ...c, candidate_id: newId } : c)));
104
+ wrote.push('.arbiter/comments.json');
105
+ }
106
+ (0, work_1.addRename)(paths, oldId, newId);
107
+ wrote.push('.arbiter/renamed.json');
108
+ }
109
+ return {
110
+ exitCode: 0,
111
+ output: {
112
+ status: taken ? 'merged' : 'renamed',
113
+ from: current,
114
+ to: target,
115
+ decisions: found.length,
116
+ ...(newId !== oldId ? { card: { from: oldId, to: newId } } : {}),
117
+ wrote,
118
+ note: newId !== oldId
119
+ ? 'the board shows the new name, with its comments, after the next `npx arbiter publish`'
120
+ : 'same card on the board; only its name changes, at the next `npx arbiter publish`',
121
+ },
122
+ };
123
+ }