arbiterdesign 0.1.4 → 0.1.7

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.
@@ -23,7 +23,8 @@ const schema_1 = require("../schema");
23
23
  const format_1 = require("../format");
24
24
  const store_1 = require("../store");
25
25
  const STATE_ORDER = ['approved', 'in_review', 'generated', 'rejected', 'superseded'];
26
- const STATE_LABEL = { approved: 'Approved', in_review: 'In review', generated: 'Generated', rejected: 'Rejected', superseded: 'Superseded' };
26
+ /** In a designer's words, as the hosted board says them. The record keeps its own (`generated`, `superseded`). */
27
+ const STATE_LABEL = { approved: 'Approved', in_review: 'In review', generated: 'Draft', rejected: 'Rejected', superseded: 'Replaced' };
27
28
  function exportBoard(opts = {}) {
28
29
  const root = (0, store_1.findRoot)(opts.cwd);
29
30
  const paths = (0, store_1.resolvePaths)(root);
@@ -90,6 +91,7 @@ function page(d) {
90
91
  h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 44px 0 14px; }
91
92
  .cand { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 24px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px; margin-bottom: 14px; }
92
93
  .cand.lesser { grid-template-columns: 220px minmax(0,1fr); padding: 16px 20px; opacity: .85; }
94
+ .cand.noshot { grid-template-columns: minmax(0,1fr); }
93
95
  @media (max-width: 680px) { .cand, .cand.lesser { grid-template-columns: 1fr; } }
94
96
  .shot { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--tag); min-height: 60px; display:flex; align-items:center; justify-content:center; color: var(--muted); font-size: 13px; }
95
97
  .shot img { display:block; width:100%; height:auto; }
@@ -130,14 +132,15 @@ function section(feature, cands, d) {
130
132
  function card(c, d) {
131
133
  const lesser = c.state === 'rejected' || c.state === 'superseded';
132
134
  const by = c.supersededBy ? d.byId.get(c.supersededBy) : null;
133
- const state = c.state === 'superseded' && by ? `Superseded by ${esc(by.name)}` : STATE_LABEL[c.state];
134
- const shot = c.snapshot ? `<img src="snapshots/${esc(c.snapshot)}" alt="${esc(c.name)}">` : 'No screenshot';
135
+ const state = c.state === 'superseded' && by ? `Replaced by ${esc(by.name)}` : STATE_LABEL[c.state];
136
+ // No picture, no frame — the card is its words alone, as on the hosted board.
137
+ const shot = c.snapshot ? `<div class="shot"><img src="snapshots/${esc(c.snapshot)}" alt="${esc(c.name)}"></div>` : '';
135
138
  const decs = d.decisions(c.id);
136
139
  const decisions = decs.length
137
140
  ? `<div class="decs"><h4>Decided here</h4><ul>${decs.map((x) => `<li>${esc(x.change ?? x.decision)}${x.rejected.length ? `<small>over ${esc(x.rejected.map((r) => r.split(' — ')[0]).join(', '))}</small>` : ''}</li>`).join('')}</ul></div>`
138
141
  : '';
139
- return `<article class="cand${lesser ? ' lesser' : ''}">
140
- <div class="shot">${shot}</div>
142
+ return `<article class="cand${lesser ? ' lesser' : ''}${shot ? '' : ' noshot'}">
143
+ ${shot}
141
144
  <div>
142
145
  <h3>${esc(c.name)}<span class="state ${c.state}">${state}</span></h3>
143
146
  <p class="who">${esc(c.author)} · ${c.date.slice(0, 10)}</p>
@@ -151,7 +154,7 @@ function rulesSection(rules) {
151
154
  if (!rules.length)
152
155
  return '';
153
156
  const groups = schema_1.DIMENSIONS.map((dim) => [dim, rules.filter((r) => r.dimension === dim)]).filter(([, rs]) => rs.length);
154
- return `<section class="rules"><h2>Standing rules — ${rules.length}</h2>${groups
157
+ return `<section class="rules"><h2>Design rules · ${rules.length}</h2>${groups
155
158
  .map(([dim, rs]) => `<h4>${format_1.DIMENSION_LABELS[dim]}</h4><ul>${rs.map((r) => `<li>${esc(r.decision)}<small>${esc(r.rationale)}</small></li>`).join('')}</ul>`)
156
159
  .join('')}</section>`;
157
160
  }
@@ -10,7 +10,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
10
10
  return (mod && mod.__esModule) ? mod : { "default": mod };
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.skillMarker = exports.SKILL_MARKER = exports.PKG_ROOT = void 0;
13
+ exports.skillMarker = exports.SKILL_MARKER = exports.PKG_ROOT = exports.AGENTS_LINE = void 0;
14
14
  exports.selfVersion = selfVersion;
15
15
  exports.skillPath = skillPath;
16
16
  exports.init = init;
@@ -25,7 +25,14 @@ const store_1 = require("../store");
25
25
  const format_1 = require("../format");
26
26
  const prompt_1 = require("./prompt");
27
27
  const AGENTS_MARKER = '<!-- arbiter -->';
28
- const AGENTS_LINE = `Before any UI work, read \`DECISIONS.md\` — the design decisions this project has already made. Follow them; don't re-decide them. Record new ones with the \`arbiter\` skill. ${AGENTS_MARKER}`;
28
+ /**
29
+ * The one line in AGENTS.md and CLAUDE.md. It's always loaded, so it carries the one thing that has
30
+ * to hold even when the skill isn't: which wins when a decision and the design system disagree.
31
+ * Without it the decision won 17 times in 20; with it the design system won 20 in 20, and an
32
+ * exception won 20 in 20 (clash study, Opus 5.5, October 2026).
33
+ */
34
+ exports.AGENTS_LINE = `Before any UI work, read \`DECISIONS.md\` — the design decisions this project has already made. Follow them; don't re-decide them. Record new ones with the \`arbiter\` skill. ` +
35
+ `If the request, or the design system (DESIGN.md, design-system or pattern docs, component guidelines, or the shared components), goes against a decision, don't build yet: ask first, the way the \`arbiter\` skill shows. A decision written as an exception ("Exception to the design system: …") beats the design system without asking: follow it and say so. ${AGENTS_MARKER}`;
29
36
  exports.PKG_ROOT = node_path_1.default.join(__dirname, '..', '..');
30
37
  const SKILL_TEMPLATE = node_path_1.default.join(exports.PKG_ROOT, 'templates', 'SKILL.md');
31
38
  /** The version of the package that's running. */
@@ -173,14 +180,21 @@ function mergeAgentsLine(root, file, createIfMissing) {
173
180
  if (!node_fs_1.default.existsSync(abs)) {
174
181
  if (!createIfMissing)
175
182
  return { file, outcome: 'skipped', note: 'not present' };
176
- node_fs_1.default.writeFileSync(abs, `# Agent instructions\n\n${AGENTS_LINE}\n`);
183
+ node_fs_1.default.writeFileSync(abs, `# Agent instructions\n\n${exports.AGENTS_LINE}\n`);
177
184
  return { file, outcome: 'created' };
178
185
  }
179
186
  const before = node_fs_1.default.readFileSync(abs, 'utf8');
180
- if (before.includes(AGENTS_MARKER))
181
- return { file, outcome: 'unchanged' };
187
+ if (before.includes(AGENTS_MARKER)) {
188
+ // The marked line is Arbiter's: an older Arbiter wrote different words, so swap in these.
189
+ // Only that line — whatever else the file says, and where the line sits in it, stays.
190
+ const after = before.replace(/^.*<!-- arbiter -->.*$/m, () => exports.AGENTS_LINE);
191
+ if (after === before)
192
+ return { file, outcome: 'unchanged' };
193
+ node_fs_1.default.writeFileSync(abs, after);
194
+ return { file, outcome: 'updated', note: 'Arbiter line refreshed' };
195
+ }
182
196
  const sep = before.endsWith('\n') ? (before.endsWith('\n\n') ? '' : '\n') : '\n\n';
183
- node_fs_1.default.writeFileSync(abs, before + sep + AGENTS_LINE + '\n');
197
+ node_fs_1.default.writeFileSync(abs, before + sep + exports.AGENTS_LINE + '\n');
184
198
  return { file, outcome: 'updated', note: 'one line appended' };
185
199
  }
186
200
  const CURSOR_COMMAND = `# Arbiter — review queued design decisions
@@ -218,6 +232,10 @@ function installSelf(root) {
218
232
  return { file: 'package.json', outcome: 'skipped', note: `no package.json here — add ${self.name} as a dev dependency yourself` };
219
233
  }
220
234
  const host = JSON.parse(node_fs_1.default.readFileSync(hostPkgPath, 'utf8'));
235
+ // Arbiter's own repo, dogfooding: `npx arbiter` already resolves to the package itself.
236
+ if (host.name === self.name) {
237
+ return { file: 'package.json', outcome: 'unchanged', note: `this is ${self.name} itself — not adding it as its own dependency` };
238
+ }
221
239
  if (host.devDependencies?.[self.name] || host.dependencies?.[self.name]) {
222
240
  return { file: 'package.json', outcome: 'unchanged', note: `${self.name} already a dependency` };
223
241
  }
@@ -24,6 +24,7 @@ const candidates_1 = require("../candidates");
24
24
  const destination_1 = require("../destination");
25
25
  const store_1 = require("../store");
26
26
  const hosted_1 = require("../hosted");
27
+ const pictures_1 = require("../pictures");
27
28
  const init_1 = require("./init");
28
29
  /** Where `arbiter publish` goes when nothing says otherwise. */
29
30
  exports.DEFAULT_HOST = 'https://arbiter.design';
@@ -44,9 +45,11 @@ async function publish(opts = {}) {
44
45
  const r = await (0, hosted_1.publishHosted)(paths, to, { admin: opts.admin });
45
46
  if (r.created)
46
47
  done('project', `created on ${to} — link in .arbiter/hosted.json (commit it); token in .arbiter/hosted.token (git-ignored — teammates set ARBITER_PUBLISH_TOKEN)`);
47
- done('board', `${r.candidates} screen${r.candidates === 1 ? '' : 's'} published${r.snapshots ? `, ${r.snapshots} image${r.snapshots === 1 ? '' : 's'}` : ''}`);
48
+ // No image count: a card without a picture shows an icon of its kind, and that's usually right.
49
+ done('board', `${r.candidates} screen${r.candidates === 1 ? '' : 's'} published`);
48
50
  for (const s of r.skipped)
49
51
  skip('snapshot', s);
52
+ steps.push(...pictureSteps(paths));
50
53
  if (opts.onPush)
51
54
  for (const s of onPush(root, paths))
52
55
  steps.push(s);
@@ -126,6 +129,14 @@ async function publish(opts = {}) {
126
129
  const ok = steps.every((s) => s.outcome !== 'failed');
127
130
  return { ok, steps, url };
128
131
  }
132
+ /**
133
+ * The last chance to notice before someone opens the board: a line per card that should have a
134
+ * picture and doesn't, with the command. Cards that are right as an icon say nothing. Hosted
135
+ * only: the Pages export has no work cards, so it would be asking for pictures nobody sees.
136
+ */
137
+ function pictureSteps(paths) {
138
+ return (0, pictures_1.missingPictures)(paths, (0, store_1.readArchive)(paths).filter(hosted_1.publishable)).map((m) => ({ step: 'picture', outcome: 'missing', note: `${m.name}: ${m.command}` }));
139
+ }
129
140
  /**
130
141
  * Keep the board current without anyone remembering to publish: a workflow that runs `publish`
131
142
  * when decisions land on the default branch. The publish token becomes a repository secret —
@@ -1,15 +1,26 @@
1
1
  "use strict";
2
- /** `arbiter pull` — bring comments and "looks good" reactions down from the hosted board. */
2
+ /**
3
+ * `arbiter pull` — bring comments and "looks good" reactions down from the hosted board. A
4
+ * "Request change" becomes a request (R-0001) waiting on the owner's answer.
5
+ */
3
6
  Object.defineProperty(exports, "__esModule", { value: true });
4
7
  exports.pull = pull;
5
8
  const candidates_1 = require("../candidates");
6
9
  const hosted_1 = require("../hosted");
10
+ const requests_1 = require("../requests");
7
11
  const store_1 = require("../store");
8
12
  async function pull(opts = {}) {
9
13
  const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
10
- const { link, fresh, total } = await (0, hosted_1.pullHosted)(paths);
14
+ const { link, fresh, current, total } = await (0, hosted_1.pullHosted)(paths);
15
+ // Withdrawn first: a request deleted on the board leaves the queue before anything new arrives.
16
+ const withdrawn = (0, requests_1.dropWithdrawn)(paths, new Set(current.filter((c) => c.kind === 'request').map((c) => c.id)));
17
+ // Every request on the board, not only the fresh ones: one pulled by an older Arbiter still counts.
18
+ const opened = new Map((0, requests_1.openRequests)(paths, current).map((r) => [r.comment, r.id]));
19
+ const waiting = (0, requests_1.readRequests)(paths).filter((r) => r.status === 'open').length;
20
+ const toAnswer = `${waiting} request${waiting === 1 ? '' : 's'} to answer — /arbiter in chat, or npx arbiter review.`;
21
+ const gone = withdrawn.map((r) => `${r.author} withdrew ${r.id} on the board, so it's off your queue: ${(0, requests_1.oneLine)(r.body)}`);
11
22
  if (!fresh.length)
12
- return `Nothing new on ${link.shareUrl} (${total} comment${total === 1 ? '' : 's'} so far).`;
23
+ return [`Nothing new on ${link.shareUrl} (${total} comment${total === 1 ? '' : 's'} so far).`, ...gone, ...(waiting ? [toAnswer] : [])].join('\n');
13
24
  const names = new Map((0, candidates_1.readCandidates)(paths).map((c) => [c.id, c.name]));
14
25
  const lines = [`${fresh.length} new from ${link.shareUrl}:`, ''];
15
26
  const byCand = new Map();
@@ -19,9 +30,19 @@ async function pull(opts = {}) {
19
30
  lines.push(` ${cid} ${names.get(cid) ?? (cid.startsWith('W-') ? cid.slice(2).replace(/-/g, ' ').replace(/^\w/, (ch) => ch.toUpperCase()) : '')}`);
20
31
  for (const c of cs) {
21
32
  const stale = c.board_version && link.boardVersion && c.board_version !== link.boardVersion ? ' (earlier version)' : '';
22
- lines.push((c.kind === 'approve' ? ` ✓ ${c.author_name} — looks good` : ` ${c.author_name}${c.decision_id ? ` on ${c.decision_id}` : ''}: ${c.body}`) + stale);
33
+ const on = c.decision_id ? ` on ${c.decision_id}` : '';
34
+ if (c.kind === 'approve')
35
+ lines.push(` ✓ ${c.author_name} — looks good${stale}`);
36
+ else if (c.kind === 'request')
37
+ lines.push(` ${c.author_name} requests a change${on}: ${c.body}${stale}${opened.has(c.id) ? ` → ${opened.get(c.id)}` : ''}`);
38
+ else
39
+ lines.push(` ${c.author_name}${on}: ${c.body}${stale}`);
23
40
  }
24
41
  }
25
42
  lines.push('', 'Saved to .arbiter/comments.json — npx arbiter review shows them beside each screen. Say "record Sam\'s comment as a rule" in a session to act on one.');
43
+ if (gone.length)
44
+ lines.push(...gone);
45
+ if (waiting)
46
+ lines.push(toAnswer);
26
47
  return lines.join('\n');
27
48
  }
@@ -7,6 +7,9 @@
7
7
  * record P-0003 --as rule judge a queued decision (accept | rule | skip | fix --to "<what instead>")
8
8
  * record --all --as accept judge every queued decision the same way [--level polish] [--trigger "…"]
9
9
  * record --retire D-0003 --why "…" drop a rule from DECISIONS.md with no replacement; the archive keeps both
10
+ * record --reword D-0003 --to "…" change a rule's wording, same id; the old wording stays on the entry
11
+ * record R-0001 --as apply answer a request from the board (apply [--to "<instead>"] | decline --why "…")
12
+ * record '<json>' --request R-0001 record the change made for an approved request; it's applied
10
13
  * record (a person at a terminal) walk through it step by step
11
14
  *
12
15
  * Output is JSON on stdout, always — an agent is usually on the other end.
@@ -22,15 +25,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
25
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
26
  };
24
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.REVIEW_EVERY = void 0;
25
29
  exports.record = record;
26
30
  exports.queue = queue;
27
31
  exports.queueFindings = queueFindings;
28
32
  exports.retire = retire;
33
+ exports.reword = reword;
29
34
  exports.judge = judge;
30
35
  exports.judgeAll = judgeAll;
31
36
  exports.recordInput = recordInput;
32
37
  exports.interactiveInput = interactiveInput;
33
- const node_os_1 = __importDefault(require("node:os"));
34
38
  const node_path_1 = __importDefault(require("node:path"));
35
39
  const schema_1 = require("../schema");
36
40
  const store_1 = require("../store");
@@ -42,19 +46,44 @@ const prompt_1 = require("./prompt");
42
46
  const node_fs_1 = __importDefault(require("node:fs"));
43
47
  const candidate_1 = require("./candidate");
44
48
  const update_1 = require("./update");
49
+ const pictures_1 = require("../pictures");
50
+ const request_1 = require("./request");
45
51
  // ── Parse + record ─────────────────────────────────────────────────────────
46
52
  function record(rawJson, opts = {}) {
47
53
  const parsed = parse(rawJson);
48
54
  if (!parsed.ok)
49
55
  return parsed.result;
56
+ const bad = againstError((0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd)), parsed.input);
57
+ if (bad)
58
+ return bad;
50
59
  return recordInput(parsed.input, opts);
51
60
  }
61
+ /**
62
+ * `against` has to name a rule that's in force now: an exception to a rule nobody follows any more
63
+ * isn't one. Checked when a decision comes in, not when a queued one is judged — by then the rule
64
+ * may have been replaced, and the clash is still part of the record.
65
+ */
66
+ function againstError(paths, input) {
67
+ if (!input.against || (0, store_1.readActive)(paths).some((d) => d.id === input.against))
68
+ return null;
69
+ return fail([`against: ${input.against} is not an active rule`]);
70
+ }
52
71
  function queue(rawJson, opts = {}) {
72
+ if (opts.request)
73
+ return fail([`--request records a change made for an approved request, directly: drop --pending. Nothing is queued for a request.`]);
53
74
  const parsed = parse(rawJson, { pending: true });
54
75
  if (!parsed.ok)
55
76
  return parsed.result;
56
77
  const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
78
+ const bad = againstError(paths, parsed.input);
79
+ if (bad)
80
+ return bad;
57
81
  const pending = (0, store_1.readPending)(paths);
82
+ // "Not now" on the same screen against the same rule, a second time: it's on the review list
83
+ // already. Asking about it again is what the list is there to stop.
84
+ const same = parsed.input.against && pending.find((d) => d.against === parsed.input.against && d.trigger === parsed.input.trigger);
85
+ if (same)
86
+ return { exitCode: 0, output: { status: 'already-queued', id: same.id, against: same.against, pending: pending.length } };
58
87
  const entry = { ...fill(parsed.input, opts, paths.root), id: (0, store_1.nextPendingId)(pending), verdict: 'pending' };
59
88
  const checked = check(entry, paths.root, opts);
60
89
  if (checked)
@@ -64,6 +93,10 @@ function queue(rawJson, opts = {}) {
64
93
  if (entry.candidate)
65
94
  (0, candidate_1.refreshCandidates)(paths);
66
95
  }
96
+ // What the user would actually be asked about: polish is logged with its group, never presented.
97
+ const before = pending.filter((d) => d.level !== 'polish').length;
98
+ const waiting = before + (entry.level === 'polish' ? 0 : 1);
99
+ const checkin = (0, store_1.readConfig)(paths)?.checkin ?? 'feature';
67
100
  return {
68
101
  exitCode: 0,
69
102
  output: {
@@ -72,13 +105,29 @@ function queue(rawJson, opts = {}) {
72
105
  dimension: entry.dimension,
73
106
  verified: entry.verified,
74
107
  pending: pending.length + 1,
75
- checkin: (0, store_1.readConfig)(paths)?.checkin ?? 'feature',
108
+ checkin,
109
+ waiting,
110
+ // A dry run wrote nothing, so the count it reached isn't real yet.
111
+ ...(opts.dryRun ? {} : askToReview(before, waiting, checkin)),
76
112
  review: 'npx arbiter review',
113
+ ...picture(paths, entry),
77
114
  // Present only when the project's skill file is from an older Arbiter than this one.
78
115
  ...(0, update_1.updateNotice)(paths),
79
116
  },
80
117
  };
81
118
  }
119
+ /** Ask once each time the waiting count reaches another multiple of this. */
120
+ exports.REVIEW_EVERY = 5;
121
+ /**
122
+ * At 5, 10, 15 changes waiting, the agent asks whether to review now. A "no" just waits for the
123
+ * next multiple, and judging brings the count down, so the next ask comes when it climbs back.
124
+ * Quiet means quiet: someone who chose "Nothing until I ask" is never asked.
125
+ */
126
+ function askToReview(before, after, checkin) {
127
+ if (checkin === 'quiet' || Math.floor(after / exports.REVIEW_EVERY) <= Math.floor(before / exports.REVIEW_EVERY))
128
+ return {};
129
+ return { ask: `You have ${after} changes waiting in Arbiter. Review them now? (yes / no)` };
130
+ }
82
131
  /** Queue one pending decision per finding in a scanner's JSON output. */
83
132
  function queueFindings(file, opts = {}) {
84
133
  const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
@@ -94,6 +143,7 @@ function queueFindings(file, opts = {}) {
94
143
  return fail(['no findings recognised in that file — expected an array of { file, message, line?, rule?, suggestion? } or ESLint-style output']);
95
144
  const tool = opts.tool ?? node_path_1.default.basename(file, node_path_1.default.extname(file));
96
145
  const pending = (0, store_1.readPending)(paths);
146
+ const before = pending.filter((d) => d.level !== 'polish').length;
97
147
  const seen = new Set(pending.map((d) => d.trigger));
98
148
  const added = [];
99
149
  let skipped = 0;
@@ -110,7 +160,24 @@ function queueFindings(file, opts = {}) {
110
160
  }
111
161
  if (!opts.dryRun)
112
162
  (0, store_1.writePending)(paths, pending);
113
- return { exitCode: 0, output: { status: 'queued', tool, queued: added.length, skippedDuplicates: skipped, ids: added, pending: pending.length, review: 'npx arbiter review' } };
163
+ // Findings are asked about like any other queued change, so they count toward the review question.
164
+ const waiting = pending.filter((d) => d.level !== 'polish').length;
165
+ const checkin = (0, store_1.readConfig)(paths)?.checkin ?? 'feature';
166
+ return {
167
+ exitCode: 0,
168
+ output: {
169
+ status: 'queued',
170
+ tool,
171
+ queued: added.length,
172
+ skippedDuplicates: skipped,
173
+ ids: added,
174
+ pending: pending.length,
175
+ checkin,
176
+ waiting,
177
+ ...(opts.dryRun ? {} : askToReview(before, waiting, checkin)),
178
+ review: 'npx arbiter review',
179
+ },
180
+ };
114
181
  }
115
182
  function parse(rawJson, options = {}) {
116
183
  let raw;
@@ -148,6 +215,51 @@ function retire(ruleId, why, opts = {}) {
148
215
  };
149
216
  return recordInput(input, opts);
150
217
  }
218
+ // ── Reword a rule ──────────────────────────────────────────────────────────
219
+ /**
220
+ * Same rule, clearer words: "Pills are outlined" becomes "Status pills are outlined", or a rule that
221
+ * beats the design system on purpose becomes "Exception to the design system: …". The id stays, so
222
+ * everything that names it still points at it. Rewording isn't a change of mind — that's a new rule
223
+ * that supersedes this one — so the entry is changed in place, in DECISIONS.md and the archive
224
+ * both, and keeps the wording it replaced.
225
+ */
226
+ function reword(ruleId, to, opts = {}) {
227
+ if (!schema_1.DECISION_ID.test(ruleId))
228
+ return fail([`not a rule id: ${ruleId} (looks like D-0003)`]);
229
+ const next = to?.trim();
230
+ if (!next)
231
+ return fail(['reword needs --to "<the new wording>"']);
232
+ if (/[\r\n]/.test(next))
233
+ return fail(['the new wording must be a single line']);
234
+ const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
235
+ const active = (0, store_1.readActive)(paths);
236
+ const rule = active.find((d) => d.id === ruleId);
237
+ if (!rule)
238
+ return fail([`${ruleId} is not an active rule`]);
239
+ if (next === rule.decision)
240
+ return fail([`${ruleId} already says that`]);
241
+ const was = `${rule.decision} (until ${(0, store_1.now)().slice(0, 10)})`;
242
+ const change = (d) => (d.id === ruleId ? { ...d, decision: next, reworded: [...d.reworded, was] } : d);
243
+ const archive = (0, store_1.readArchive)(paths);
244
+ if (!opts.dryRun) {
245
+ (0, store_1.writeActive)(paths, active.map(change), (0, store_1.readConfig)(paths)?.activeCap ?? store_1.ACTIVE_CAP);
246
+ // A rule recorded before the archive existed lives only in DECISIONS.md; there's nothing to rewrite.
247
+ if (archive.some((d) => d.id === ruleId))
248
+ (0, store_1.writeArchive)(paths, archive.map(change));
249
+ if (rule.candidate)
250
+ (0, candidate_1.refreshCandidates)(paths);
251
+ }
252
+ return {
253
+ exitCode: 0,
254
+ output: {
255
+ status: opts.dryRun ? 'dry-run' : 'reworded',
256
+ id: ruleId,
257
+ decision: next,
258
+ was: rule.decision,
259
+ wrote: opts.dryRun ? [] : ['DECISIONS.md', '.arbiter/archive.md'],
260
+ },
261
+ };
262
+ }
151
263
  // ── Judge a pending item ───────────────────────────────────────────────────
152
264
  function judge(pendingId, opts) {
153
265
  if (!schema_1.PENDING_ID.test(pendingId))
@@ -174,11 +286,21 @@ function judge(pendingId, opts) {
174
286
  decision: to,
175
287
  rejected: [`${item.decision} — corrected by ${opts.author ?? item.author}`, ...item.rejected],
176
288
  verdict: 'fix',
289
+ // Whoever made the call before, the user just changed it.
290
+ call: 'corrected',
177
291
  };
178
292
  }
179
293
  else {
180
294
  input = { ...base, verdict: opts.as };
181
295
  }
296
+ if (opts.against) {
297
+ if (!schema_1.DECISION_ID.test(opts.against))
298
+ return fail([`--against needs a rule id like D-0009, not ${opts.against}`]);
299
+ input = { ...input, against: opts.against };
300
+ const bad = againstError(paths, input);
301
+ if (bad)
302
+ return bad;
303
+ }
182
304
  const result = recordInput(input, opts);
183
305
  if (result.exitCode === 0 && !opts.dryRun)
184
306
  (0, store_1.writePending)(paths, rest);
@@ -191,6 +313,11 @@ function judge(pendingId, opts) {
191
313
  function judgeAll(opts) {
192
314
  if (opts.as === 'fix')
193
315
  return fail(['fix is one at a time — it needs its own --to']);
316
+ // A request is applied by the change made for it, not by everything that happens to be queued.
317
+ if (opts.request)
318
+ return fail([`--request links one change to ${opts.request}; it can't go on --all`]);
319
+ if (opts.against)
320
+ return fail([`--against marks one exception to ${opts.against}; it can't go on --all`]);
194
321
  const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
195
322
  const targets = (0, store_1.readPending)(paths).filter((d) => (!opts.level || d.level === opts.level) && (!opts.trigger || d.trigger === opts.trigger));
196
323
  if (!targets.length)
@@ -225,15 +352,28 @@ function recordInput(input, opts = {}) {
225
352
  const paths = (0, store_1.resolvePaths)(root);
226
353
  const config = (0, store_1.readConfig)(paths);
227
354
  const cap = config?.activeCap ?? store_1.ACTIVE_CAP;
355
+ // A change made for a request from the board — only once the owner has said yes.
356
+ let request = null;
357
+ if (opts.request) {
358
+ const gate = (0, request_1.requestGate)(paths, opts.request);
359
+ if (!gate.ok)
360
+ return fail(gate.errors);
361
+ request = gate.request;
362
+ input = (0, request_1.withRequest)(paths, input, request);
363
+ }
228
364
  const active = (0, store_1.readActive)(paths);
229
365
  const archive = (0, store_1.readArchive)(paths);
230
366
  const supersedes = opts.supersedes ?? input.supersedes ?? null;
231
367
  const entry = { ...fill(input, opts, root), id: (0, store_1.nextId)(archive), supersedes };
368
+ // Nothing written means the request isn't applied yet. Whatever the re-run is, it has to carry
369
+ // --request too, or the change lands and the request stays approved, to be made again.
370
+ const again = request ? ` --request ${request.id}` : '';
371
+ const keepRequest = (r) => request ? { ...r, output: { ...r.output, request: request.id, note: `Nothing was written, so ${request.id} isn't applied yet. Re-run with${again}.` } } : r;
232
372
  // An `accept` is a deviation by definition — nothing to verify. Rules and fixes make claims.
233
373
  if (entry.verdict !== 'accept') {
234
374
  const checked = check(entry, root, opts);
235
375
  if (checked)
236
- return checked;
376
+ return keepRequest(checked);
237
377
  }
238
378
  let nextActive = active;
239
379
  if (entry.verdict === 'retire') {
@@ -257,7 +397,7 @@ function recordInput(input, opts = {}) {
257
397
  else if (!opts.keepBoth) {
258
398
  const overlaps = (0, overlap_1.findOverlaps)(input, active, { ignore: config?.overlap?.ignore });
259
399
  if (overlaps.length) {
260
- return {
400
+ return keepRequest({
261
401
  exitCode: 2,
262
402
  output: {
263
403
  status: 'overlap',
@@ -266,17 +406,17 @@ function recordInput(input, opts = {}) {
266
406
  overlaps,
267
407
  options: [
268
408
  ...overlaps.map((o) => ({
269
- flag: `--supersedes ${o.id}`,
409
+ flag: `--supersedes ${o.id}${again}`,
270
410
  effect: `${o.id} leaves DECISIONS.md and stays in the archive; the new rule records supersedes: ${o.id}`,
271
411
  })),
272
- { flag: '--keep-both', effect: 'both rules stay active' },
412
+ { flag: `--keep-both${again}`, effect: 'both rules stay active' },
273
413
  ],
274
414
  },
275
- };
415
+ });
276
416
  }
277
417
  }
278
418
  if (nextActive.length >= cap) {
279
- return {
419
+ return keepRequest({
280
420
  exitCode: 3,
281
421
  output: {
282
422
  status: 'cap',
@@ -284,7 +424,7 @@ function recordInput(input, opts = {}) {
284
424
  candidate: input,
285
425
  active: nextActive.map((d) => ({ id: d.id, decision: d.decision, scope: d.scope })),
286
426
  },
287
- };
427
+ });
288
428
  }
289
429
  nextActive = [...nextActive, entry];
290
430
  }
@@ -294,6 +434,8 @@ function recordInput(input, opts = {}) {
294
434
  (0, store_1.writeActive)(paths, nextActive, cap);
295
435
  if (entry.candidate)
296
436
  (0, candidate_1.refreshCandidates)(paths);
437
+ if (request)
438
+ (0, request_1.markApplied)(paths, request, entry.id);
297
439
  }
298
440
  // A new mechanical rule reaches backwards: say how much existing code it touches.
299
441
  let sweepSummary;
@@ -314,12 +456,20 @@ function recordInput(input, opts = {}) {
314
456
  supersedes: entry.supersedes,
315
457
  verified: entry.verified,
316
458
  candidate: entry.candidate,
459
+ ...(entry.against && { against: entry.against }),
317
460
  active: `${nextActive.length} of ${cap}`,
318
461
  wrote: opts.dryRun ? [] : entry.verdict === 'rule' || entry.verdict === 'retire' ? ['.arbiter/archive.md', 'DECISIONS.md'] : ['.arbiter/archive.md'],
462
+ ...(request && { request: { id: request.id, status: opts.dryRun ? request.status : 'applied', author: request.author } }),
319
463
  ...(sweepSummary && { sweep: sweepSummary }),
464
+ ...picture(paths, entry),
320
465
  },
321
466
  };
322
467
  }
468
+ /** The agent is still there with the app running: the moment to say a screen has no picture. */
469
+ function picture(paths, entry) {
470
+ const [m] = (0, pictures_1.missingPictures)(paths, [entry]);
471
+ return m ? { picture: (0, pictures_1.pictureHint)(m, (0, store_1.readConfig)(paths)?.app?.url) } : {};
472
+ }
323
473
  /**
324
474
  * Check a decision's claim against its files. Sets `verified`; returns a
325
475
  * failing result if contradicted and the caller didn't say --unverified.
@@ -344,12 +494,9 @@ function check(entry, root, opts) {
344
494
  }
345
495
  /** Fill the fields the caller doesn't supply. Id is set by the caller. */
346
496
  function fill(input, opts, root) {
347
- const config = (0, store_1.readConfig)((0, store_1.resolvePaths)(root));
348
497
  return {
349
498
  date: input.date ?? (0, store_1.now)(),
350
- // Whoever is at the keyboard. arbiter.json's author is committed, so in a shared repo it names
351
- // whoever ran init — it's the fallback for a machine with no git identity, not the default.
352
- author: opts.author ?? input.author ?? (0, store_1.gitUserName)(root) ?? config?.author ?? node_os_1.default.userInfo().username,
499
+ author: opts.author ?? input.author ?? (0, store_1.currentAuthor)(root),
353
500
  class: input.class,
354
501
  dimension: input.dimension,
355
502
  decision: input.decision,
@@ -368,6 +515,9 @@ function fill(input, opts, root) {
368
515
  expect: input.expect ?? null,
369
516
  verified: null,
370
517
  candidate: opts.candidate ?? input.candidate ?? null,
518
+ against: input.against ?? null,
519
+ call: input.call ?? null,
520
+ reworded: [],
371
521
  };
372
522
  }
373
523
  function fail(errors) {
@@ -31,6 +31,7 @@ const store_1 = require("../store");
31
31
  const candidates_1 = require("../candidates");
32
32
  const destination_1 = require("../destination");
33
33
  const work_1 = require("../work");
34
+ const requests_1 = require("../requests");
34
35
  const fail = (errors) => ({ exitCode: 1, output: { status: 'invalid', errors } });
35
36
  // ── remove ─────────────────────────────────────────────────────────────────
36
37
  function remove(id, opts = {}) {
@@ -61,12 +62,22 @@ function removeDecision(id, opts) {
61
62
  if (later) {
62
63
  return fail([`${later.id} supersedes ${id} — removing it would leave ${later.id} pointing at nothing. Remove ${later.id} first if neither is real.`]);
63
64
  }
65
+ // Read before anything is written: a broken requests.json must stop the removal, not interrupt it.
66
+ // A request still waiting that was asked about this decision would outlive it, and then read as
67
+ // if it were about whatever takes the id next.
68
+ const about = (0, requests_1.readRequests)(paths).filter((r) => r.decision === id && (r.status === 'open' || r.status === 'approved'));
69
+ if (about.length)
70
+ return fail([`${about.map((r) => `${r.id} (${r.author})`).join(', ')} ${about.length === 1 ? 'was' : 'were'} asked about ${id} and ${about.length === 1 ? 'is' : 'are'} still waiting. The owner answers first; if ${id} is going, that's a reason they can decline with.`]);
64
71
  (0, store_1.writeArchive)(paths, archive.filter((d) => d.id !== id));
65
72
  if (isActive) {
66
73
  const config = (0, store_1.readConfig)(paths);
67
74
  (0, store_1.writeActive)(paths, active.filter((d) => d.id !== id), config?.activeCap ?? store_1.ACTIVE_CAP);
68
75
  }
69
76
  const touched = refreshLinked(paths, entry.candidate);
77
+ // A request this decision applied isn't applied by nothing: with no record left doing it, it's
78
+ // open again, for the owner to answer afresh.
79
+ const detached = (0, requests_1.detachDecision)(paths, id);
80
+ const reopened = detached.filter((r) => r.status === 'open').map((r) => r.id);
70
81
  // Removing a rule doesn't bring back the one it replaced: that one may have been real, and
71
82
  // guessing would put a rule back the user never re-confirmed. Say so rather than lose it quietly.
72
83
  const replaced = entry.supersedes && archive.find((d) => d.id === entry.supersedes);
@@ -80,8 +91,9 @@ function removeDecision(id, opts) {
80
91
  id,
81
92
  decision: entry.decision,
82
93
  ...(replaced ? { note: `${replaced.id} — which ${id} replaced — is still inactive. Record it again if it should apply.` } : {}),
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` } : {}),
83
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.` } : {}),
84
- wrote: ['.arbiter/archive.md', ...(isActive ? ['DECISIONS.md'] : []), ...touched],
96
+ wrote: ['.arbiter/archive.md', ...(isActive ? ['DECISIONS.md'] : []), ...touched, ...(detached.length ? ['.arbiter/requests.json'] : [])],
85
97
  // Printed in full so it can be put back by hand — not everyone has git.
86
98
  removed: (0, format_1.formatEntry)(entry).trimEnd(),
87
99
  },
@@ -97,6 +109,10 @@ function removeCandidate(id, opts) {
97
109
  const by = all.find((x) => x.supersededBy === id);
98
110
  if (by)
99
111
  return fail([`${by.id} says it was superseded by ${id} — clear that first: npx arbiter candidate ${by.id} --state generated`]);
112
+ // A request still waiting on this screen would outlive it — and point at whatever takes its id next.
113
+ const asked = (0, requests_1.readRequests)(paths).filter((r) => r.screen === id && (r.status === 'open' || r.status === 'approved'));
114
+ if (asked.length)
115
+ return fail([`${asked.map((r) => `${r.id} (${r.author})`).join(', ')} ${asked.length === 1 ? 'was' : 'were'} asked on ${id} and ${asked.length === 1 ? 'is' : 'are'} still waiting. The owner answers first; if the screen is going, that's a reason they can decline with.`]);
100
116
  const archive = (0, store_1.readArchive)(paths);
101
117
  const pending = (0, store_1.readPending)(paths);
102
118
  const linked = [...archive, ...pending].filter((d) => d.candidate === id);