arbiterdesign 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ /**
3
+ * What a change's page can do to one of its decisions, beside what Design rules does to a rule: fix
4
+ * the words of its Change line, make a decision you only confirmed a rule, and put back a decision
5
+ * removed from the page by mistake. Removing one is `remove`; a rule is retired instead.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.editChange = editChange;
9
+ exports.promote = promote;
10
+ exports.restoreDecision = restoreDecision;
11
+ const store_1 = require("../store");
12
+ const schema_1 = require("../schema");
13
+ const overlap_1 = require("../overlap");
14
+ const candidate_1 = require("./candidate");
15
+ const candidates_1 = require("../candidates");
16
+ const fail = (errors) => ({ exitCode: 1, output: { status: 'invalid', errors } });
17
+ /**
18
+ * New words for what happened, the Change line, on a decision that isn't a rule (a rule's own words are
19
+ * reworded on Design rules). The id stays; the old words stay on the entry, under Reworded, so editing
20
+ * tidies the wording without quietly changing what was decided.
21
+ */
22
+ function editChange(id, to, opts = {}) {
23
+ if (!schema_1.DECISION_ID.test(id))
24
+ return fail([`not a decision id: ${id} (looks like D-0003)`]);
25
+ const next = to?.replace(/\s+/g, ' ').trim();
26
+ if (!next)
27
+ return fail(['say what changed, in one line']);
28
+ const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
29
+ const archive = (0, store_1.readArchive)(paths);
30
+ const entry = archive.find((d) => d.id === id);
31
+ if (!entry)
32
+ return fail([`${id} is not in the record`]);
33
+ const was = entry.change ?? entry.decision;
34
+ if (next === was)
35
+ return fail([`${id} already says that`]);
36
+ const edited = { ...entry, change: next, reworded: [...entry.reworded, `Change was: ${was} (until ${(0, store_1.now)().slice(0, 10)})`] };
37
+ (0, store_1.writeArchive)(paths, archive.map((d) => (d.id === id ? edited : d)));
38
+ // A rule's entry in DECISIONS.md carries its Change line too.
39
+ const active = (0, store_1.readActive)(paths);
40
+ if (active.some((d) => d.id === id))
41
+ (0, store_1.writeActive)(paths, active.map((d) => (d.id === id ? { ...d, change: next, reworded: edited.reworded } : d)), (0, store_1.readConfig)(paths)?.activeCap ?? store_1.ACTIVE_CAP);
42
+ if (entry.candidate)
43
+ (0, candidate_1.refreshCandidates)(paths);
44
+ return { exitCode: 0, output: { status: 'edited', id, change: next } };
45
+ }
46
+ /**
47
+ * Make it a rule, for a decision you only confirmed: the same entry, now a rule in DECISIONS.md, so its
48
+ * id and its page stay as they are. Checked against the rules already there, as any new rule is: an
49
+ * overlap comes back (exit 2) to keep both or replace one, and a full DECISIONS.md (exit 3) waits for room.
50
+ */
51
+ function promote(id, opts = {}) {
52
+ if (!schema_1.DECISION_ID.test(id))
53
+ return fail([`not a decision id: ${id} (looks like D-0003)`]);
54
+ const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
55
+ const archive = (0, store_1.readArchive)(paths);
56
+ const entry = archive.find((d) => d.id === id);
57
+ if (!entry)
58
+ return fail([`${id} is not in the record`]);
59
+ let active = (0, store_1.readActive)(paths);
60
+ if (active.some((d) => d.id === id))
61
+ return fail([`${id} is a rule already`]);
62
+ if (entry.verdict !== 'accept' && entry.verdict !== 'fix')
63
+ return fail([`${id} can't become a rule`]);
64
+ const config = (0, store_1.readConfig)(paths);
65
+ const cap = config?.activeCap ?? store_1.ACTIVE_CAP;
66
+ if (opts.supersedes) {
67
+ if (!active.some((d) => d.id === opts.supersedes))
68
+ return fail([`${opts.supersedes} is not an active rule`]);
69
+ active = active.filter((d) => d.id !== opts.supersedes);
70
+ }
71
+ else if (!opts.keepBoth) {
72
+ const overlaps = (0, overlap_1.findOverlaps)(entry, active, { ignore: config?.overlap?.ignore });
73
+ // Each with why, as the Review inbox has it: what both apply to (a sure match), or the words they share
74
+ // (a guess), so a guess doesn't read as sure.
75
+ if (overlaps.length)
76
+ return { exitCode: 2, output: { status: 'overlap', overlaps: (0, overlap_1.explainOverlaps)(entry, overlaps, active, new Map((0, candidates_1.readCandidates)(paths).map((c) => [c.id, c.name]))) } };
77
+ }
78
+ // Full: the rules there, so one can be picked for this to replace without leaving the page.
79
+ if (active.length >= cap)
80
+ return { exitCode: 3, output: { status: 'cap', cap, active: active.map((d) => ({ id: d.id, decision: d.decision })), errors: [`DECISIONS.md is full (${cap} rules). Remove one first, or raise the limit in Preferences.`] } };
81
+ const rule = { ...entry, verdict: 'rule', ...(opts.supersedes ? { supersedes: opts.supersedes } : {}) };
82
+ (0, store_1.writeArchive)(paths, archive.map((d) => (d.id === id ? rule : d)));
83
+ (0, store_1.writeActive)(paths, [...active, rule], cap);
84
+ if (rule.candidate)
85
+ (0, candidate_1.refreshCandidates)(paths);
86
+ return { exitCode: 0, output: { status: 'rule', id, active: `${active.length + 1} of ${cap}`, ...(opts.supersedes ? { replaced: opts.supersedes } : {}) } };
87
+ }
88
+ /** Undo for a decision removed on the board: back in the record where it was. */
89
+ function restoreDecision(r, opts = {}) {
90
+ const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
91
+ const archive = (0, store_1.readArchive)(paths);
92
+ if (archive.some((d) => d.id === r.entry.id))
93
+ return fail([`${r.entry.id} is in the record already`]);
94
+ const next = [...archive];
95
+ next.splice(Math.min(r.index, next.length), 0, r.entry);
96
+ (0, store_1.writeArchive)(paths, next);
97
+ if (r.entry.candidate)
98
+ (0, candidate_1.refreshCandidates)(paths);
99
+ return { exitCode: 0, output: { status: 'restored', id: r.entry.id } };
100
+ }
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
2
  /**
3
- * `arbiter export` — a static, self-contained folder of the board for people
4
- * without the repo. index.html + snapshots. No server, no JS, no login.
3
+ * `arbiter export` — the local board as a folder, for people without the repo. Open index.html, or
4
+ * put the folder on any static host (`publish --to pages` does). No server, no login.
5
5
  *
6
- * Stakeholder view only: screen, state, who approved, why the others lost,
7
- * what was decided — in plain Change language. No verdict buttons, no scope
8
- * tags. Feedback comes back through a human; comments never become rules.
9
- *
10
- * The cheap test of Stage 6's assumption: does a stakeholder, given a link,
11
- * actually look?
6
+ * The same pages `arbiter review` serves (templates/board), read-only: every change with its
7
+ * picture, and the design rules if asked for. No review queue, no buttons, and no comments: people
8
+ * wrote those on the team board, not in a file that gets passed around.
12
9
  */
13
10
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
11
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -18,44 +15,73 @@ exports.exportBoard = exportBoard;
18
15
  const node_fs_1 = __importDefault(require("node:fs"));
19
16
  const node_path_1 = __importDefault(require("node:path"));
20
17
  const node_child_process_1 = require("node:child_process");
18
+ const localboard_1 = require("../localboard");
21
19
  const candidates_1 = require("../candidates");
22
- const schema_1 = require("../schema");
23
- const format_1 = require("../format");
20
+ const work_1 = require("../work");
24
21
  const store_1 = require("../store");
25
- const STATE_ORDER = ['approved', 'in_review', 'generated', 'rejected', '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' };
22
+ const areas_1 = require("../areas");
23
+ const BOARD = node_path_1.default.join(__dirname, '..', '..', 'templates', 'board');
24
+ const FONTS = node_path_1.default.join(__dirname, '..', '..', 'templates', 'fonts');
25
+ const PICTURES = 'snapshots/';
26
+ // Line and paragraph separators end a line inside a <script>, so they are escaped like <.
27
+ const LINE_SEP = String.fromCharCode(0x2028);
28
+ const PARA_SEP = String.fromCharCode(0x2029);
28
29
  function exportBoard(opts = {}) {
29
30
  const root = (0, store_1.findRoot)(opts.cwd);
30
31
  const paths = (0, store_1.resolvePaths)(root);
31
32
  const outDir = node_path_1.default.resolve(root, opts.out ?? 'arbiter-export');
32
33
  const snapDir = node_path_1.default.join(outDir, 'snapshots');
34
+ // Pictures from an earlier export go: a screen since removed mustn't stay in a folder people get sent.
35
+ // Only those, by their names: anything else in a snapshots/ folder is someone's own, and stays.
36
+ clearPictures(snapDir);
33
37
  node_fs_1.default.mkdirSync(snapDir, { recursive: true });
34
- let candidates = (0, candidates_1.readCandidates)(paths);
38
+ const manifest = (0, localboard_1.boardOf)(paths, { pictures: PICTURES, includeRules: !!opts.includeRules, queued: [] });
39
+ let cards = manifest.candidates;
35
40
  if (opts.feature)
36
- candidates = candidates.filter((c) => c.feature === opts.feature);
37
- const byId = new Map(candidates.map((c) => [c.id, c]));
41
+ cards = cards.filter((c) => c.feature === opts.feature);
38
42
  let snapshots = 0;
39
- for (const c of candidates) {
43
+ for (const c of cards) {
40
44
  if (!c.snapshot)
41
45
  continue;
42
- const src = node_path_1.default.join((0, candidates_1.candidatesDir)(paths), c.snapshot);
43
- if (!node_fs_1.default.existsSync(src))
44
- continue;
45
- node_fs_1.default.copyFileSync(src, node_path_1.default.join(snapDir, c.snapshot));
46
- snapshots++;
46
+ const file = c.snapshot.slice(PICTURES.length);
47
+ const src = node_path_1.default.join(file.startsWith('W-') ? (0, work_1.workDir)(paths) : (0, candidates_1.candidatesDir)(paths), file);
48
+ if (node_fs_1.default.existsSync(src)) {
49
+ node_fs_1.default.copyFileSync(src, node_path_1.default.join(snapDir, file));
50
+ snapshots++;
51
+ }
52
+ else
53
+ c.snapshot = null;
54
+ // Its earlier pictures too, so the copy shows how it got here.
55
+ if (c.versions) {
56
+ c.versions = c.versions.filter((v) => {
57
+ const rel = v.src.slice(PICTURES.length);
58
+ if (rel === file)
59
+ return true;
60
+ const abs = (0, work_1.historyFile)(paths, rel);
61
+ if (!abs)
62
+ return false;
63
+ node_fs_1.default.mkdirSync(node_path_1.default.dirname(node_path_1.default.join(snapDir, rel)), { recursive: true });
64
+ node_fs_1.default.copyFileSync(abs, node_path_1.default.join(snapDir, rel));
65
+ return true;
66
+ });
67
+ if (c.versions.length < 2)
68
+ delete c.versions;
69
+ }
47
70
  }
48
- const project = (0, store_1.readConfig)(paths)?.author ? node_path_1.default.basename(root) : node_path_1.default.basename(root);
49
- const html = page({
50
- project,
51
- generated: new Date().toISOString().slice(0, 10),
52
- candidates,
53
- byId,
54
- decisions: (id) => (0, candidates_1.decisionsFor)(paths, id).filter((d) => d.verdict !== 'pending' && d.level !== 'polish'),
55
- rules: opts.includeRules ? (0, store_1.readActive)(paths) : null,
56
- });
71
+ // Read-only: `live: false` keeps the review pages, Done and the team board buttons out of it.
72
+ const board = { ...manifest, candidates: cards, requests: [] };
73
+ // The folders as you made them, so the copy's side nav reads the same as yours. Nobody can move them in it.
74
+ const data = { board, comments: [], waiting: {}, queued: {}, pending: 0, hosted: null, version: null, live: false, arrangement: (0, areas_1.readArrangement)(paths), settings: null };
75
+ // In a <script>, so nothing in a name can close the tag or run.
76
+ const json = JSON.stringify(data).replace(/</g, '\\u003c').split(LINE_SEP).join('\\u2028').split(PARA_SEP).join('\\u2029');
77
+ // Functions, not strings: a `$&` in someone's decision would otherwise be read as a pattern.
78
+ const html = node_fs_1.default.readFileSync(node_path_1.default.join(BOARD, 'index.html'), 'utf8')
79
+ .replace('</head>', () => `<style>${fontFaces()}</style>\n</head>`)
80
+ .replace('<script src="board.js">', () => `<script>window.__ARBITER_BOARD__ = ${json};</script>\n<script src="board.js">`);
57
81
  const index = node_path_1.default.join(outDir, 'index.html');
58
82
  node_fs_1.default.writeFileSync(index, html);
83
+ for (const f of ['board.js', 'board.css'])
84
+ node_fs_1.default.copyFileSync(node_path_1.default.join(BOARD, f), node_path_1.default.join(outDir, f));
59
85
  if (opts.open) {
60
86
  const cmd = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'cmd' : 'xdg-open';
61
87
  const args = process.platform === 'win32' ? ['/c', 'start', '', index] : [index];
@@ -64,100 +90,37 @@ function exportBoard(opts = {}) {
64
90
  }
65
91
  catch { /* path is printed anyway */ }
66
92
  }
67
- return { dir: outDir, index, candidates: candidates.length, snapshots };
68
- }
69
- function page(d) {
70
- const features = [...new Set(d.candidates.map((c) => c.feature ?? 'Other'))];
71
- const body = d.candidates.length
72
- ? features.map((f) => section(f, d.candidates.filter((c) => (c.feature ?? 'Other') === f), d)).join('\n')
73
- : `<p class="empty">Nothing to show yet.</p>`;
74
- const rules = d.rules ? rulesSection(d.rules) : '';
75
- const counts = STATE_ORDER.map((s) => [s, d.candidates.filter((c) => c.state === s).length]).filter(([, n]) => n);
76
- return `<!doctype html>
77
- <html lang="en">
78
- <head>
79
- <meta charset="utf-8">
80
- <meta name="viewport" content="width=device-width, initial-scale=1">
81
- <title>${esc(d.project)} — design decisions</title>
82
- <style>
83
- :root { color-scheme: light dark; --bg:#fafaf9; --card:#fff; --ink:#1c1917; --muted:#78716c; --line:#e7e5e4; --tag:#f5f5f4; --ok:#15803d; --bad:#b91c1c; --warn:#b45309; }
84
- @media (prefers-color-scheme: dark) { :root { --bg:#0c0a09; --card:#1c1917; --ink:#fafaf9; --muted:#a8a29e; --line:#292524; --tag:#292524; --ok:#4ade80; --bad:#f87171; --warn:#fbbf24; } }
85
- * { box-sizing: border-box; }
86
- body { margin:0; background:var(--bg); color:var(--ink); font:16px/1.55 -apple-system,BlinkMacSystemFont,"Segoe UI",Inter,system-ui,sans-serif; padding:0 20px 80px; }
87
- header, main { max-width: 920px; margin: 0 auto; }
88
- header { padding: 40px 0 8px; }
89
- header h1 { font-size: 22px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
90
- header p { color: var(--muted); margin: 6px 0 0; font-size: 14px; }
91
- h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 44px 0 14px; }
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; }
93
- .cand.lesser { grid-template-columns: 220px minmax(0,1fr); padding: 16px 20px; opacity: .85; }
94
- .cand.noshot { grid-template-columns: minmax(0,1fr); }
95
- @media (max-width: 680px) { .cand, .cand.lesser { grid-template-columns: 1fr; } }
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; }
97
- .shot img { display:block; width:100%; height:auto; }
98
- h3 { font-size: 18px; font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }
99
- .lesser h3 { font-size: 15px; }
100
- .state { font-size: 12px; font-weight: 500; padding: 2px 9px; border-radius: 999px; background: var(--tag); color: var(--muted); vertical-align: 2px; margin-left: 8px; }
101
- .state.approved { color: var(--ok); } .state.rejected, .state.superseded { color: var(--bad); } .state.in_review { color: var(--warn); }
102
- .who { color: var(--muted); font-size: 14px; margin: 0 0 10px; }
103
- .reason { font-style: italic; margin: 0 0 12px; }
104
- .decs h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 6px; font-weight: 600; }
105
- .decs ul { margin: 0; padding-left: 18px; }
106
- .decs li { margin: 3px 0; }
107
- .decs li small { color: var(--muted); display: block; }
108
- .empty { color: var(--muted); text-align: center; padding: 80px 0; }
109
- .rules { margin-top: 60px; border-top: 1px solid var(--line); padding-top: 30px; }
110
- .rules ul { padding-left: 18px; } .rules li { margin: 6px 0; } .rules li small { color: var(--muted); display: block; }
111
- footer { max-width: 920px; margin: 60px auto 0; color: var(--muted); font-size: 13px; }
112
- </style>
113
- </head>
114
- <body>
115
- <header>
116
- <h1>${esc(d.project)} — design decisions</h1>
117
- <p>${d.candidates.length} screen${d.candidates.length === 1 ? '' : 's'}${counts.length ? ' · ' + counts.map(([s, n]) => `${n} ${STATE_LABEL[s].toLowerCase()}`).join(' · ') : ''} · exported ${d.generated}</p>
118
- </header>
119
- <main>
120
- ${body}
121
- ${rules}
122
- </main>
123
- <footer>Read-only. Feedback goes to whoever owns these decisions — they decide what becomes a rule. Made with Arbiter.</footer>
124
- </body>
125
- </html>
126
- `;
127
- }
128
- function section(feature, cands, d) {
129
- const sorted = [...cands].sort((a, b) => STATE_ORDER.indexOf(a.state) - STATE_ORDER.indexOf(b.state) || a.id.localeCompare(b.id));
130
- return `<h2>${esc(feature)}</h2>\n${sorted.map((c) => card(c, d)).join('\n')}`;
93
+ return { dir: outDir, index, candidates: cards.length, snapshots };
131
94
  }
132
- function card(c, d) {
133
- const lesser = c.state === 'rejected' || c.state === 'superseded';
134
- const by = c.supersededBy ? d.byId.get(c.supersededBy) : null;
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>` : '';
138
- const decs = d.decisions(c.id);
139
- const decisions = decs.length
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>`
141
- : '';
142
- return `<article class="cand${lesser ? ' lesser' : ''}${shot ? '' : ' noshot'}">
143
- ${shot}
144
- <div>
145
- <h3>${esc(c.name)}<span class="state ${c.state}">${state}</span></h3>
146
- <p class="who">${esc(c.author)} · ${c.date.slice(0, 10)}</p>
147
- ${c.reason ? `<p class="reason">“${esc(c.reason)}”</p>` : ''}
148
- ${c.notes ? `<p>${esc(c.notes)}</p>` : ''}
149
- ${decisions}
150
- </div>
151
- </article>`;
152
- }
153
- function rulesSection(rules) {
154
- if (!rules.length)
155
- return '';
156
- const groups = schema_1.DIMENSIONS.map((dim) => [dim, rules.filter((r) => r.dimension === dim)]).filter(([, rs]) => rs.length);
157
- return `<section class="rules"><h2>Design rules · ${rules.length}</h2>${groups
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>`)
159
- .join('')}</section>`;
95
+ /**
96
+ * The pictures an export writes, and only those: a card's or a piece of work's own (C-0001.png,
97
+ * W-settings-billing.png) and its earlier ones under history/<W-…>/. A folder left empty goes too.
98
+ */
99
+ function clearPictures(snapDir) {
100
+ const id = /^(C-\d{4,}|W-[a-z0-9-]{1,48})$/;
101
+ const picture = /^(C-\d{4,}|W-[a-z0-9-]{1,48})\.(png|jpe?g|webp|gif|svg)$/;
102
+ const list = (dir) => { try {
103
+ return node_fs_1.default.readdirSync(dir, { withFileTypes: true });
104
+ }
105
+ catch {
106
+ return [];
107
+ } };
108
+ for (const e of list(snapDir))
109
+ if (e.isFile() && picture.test(e.name))
110
+ node_fs_1.default.rmSync(node_path_1.default.join(snapDir, e.name));
111
+ const history = node_path_1.default.join(snapDir, 'history');
112
+ for (const e of list(history))
113
+ if (e.isDirectory() && id.test(e.name))
114
+ node_fs_1.default.rmSync(node_path_1.default.join(history, e.name), { recursive: true, force: true });
115
+ for (const dir of [history, snapDir])
116
+ if (node_fs_1.default.existsSync(dir) && !list(dir).length)
117
+ node_fs_1.default.rmdirSync(dir);
160
118
  }
161
- function esc(s) {
162
- return s.replace(/[&<>"']/g, (ch) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[ch]);
119
+ /**
120
+ * Geist, inside the page. Opened from disk, a browser won't load a font file sitting next to it, and
121
+ * the board would fall back to the system font.
122
+ */
123
+ function fontFaces() {
124
+ const face = (family, file) => `@font-face{font-family:"${family}";src:url(data:font/woff2;base64,${node_fs_1.default.readFileSync(node_path_1.default.join(FONTS, file)).toString('base64')}) format("woff2");font-weight:100 900;font-display:swap}`;
125
+ return face('Geist', 'Geist-Variable.woff2') + face('Geist Mono', 'GeistMono-Variable.woff2');
163
126
  }
@@ -27,6 +27,9 @@ const store_1 = require("../store");
27
27
  const format_1 = require("../format");
28
28
  const prompt_1 = require("./prompt");
29
29
  const setup_1 = require("./setup");
30
+ const hook_1 = require("../hook");
31
+ const handoff_1 = require("../handoff");
32
+ const lock_1 = require("../lock");
30
33
  const AGENTS_MARKER = '<!-- arbiter -->';
31
34
  /**
32
35
  * The one line in AGENTS.md and CLAUDE.md. It's always loaded, so it carries the one thing that has
@@ -141,7 +144,13 @@ async function init(opts = {}) {
141
144
  }
142
145
  // ── .arbiter/archive.md ──────────────────────────────────────────────
143
146
  node_fs_1.default.mkdirSync(paths.archiveDir, { recursive: true });
144
- 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'));
145
154
  if (node_fs_1.default.existsSync(paths.archive)) {
146
155
  steps.push({ file: '.arbiter/archive.md', outcome: 'unchanged' });
147
156
  }
@@ -158,6 +167,8 @@ async function init(opts = {}) {
158
167
  if (client === 'claude-code') {
159
168
  // Claude Code's own context file. Same line, same marker; created if missing so injection has a path that's certain to load.
160
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));
161
172
  }
162
173
  else {
163
174
  // Cursor has no skill-invoked slash commands; give it a command file that does what `/arbiter` does.
@@ -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([`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
+ }
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
@@ -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,13 +543,15 @@ 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}`,
@@ -444,6 +568,7 @@ function recordInput(input, opts = {}) {
444
568
  exitCode: 3,
445
569
  output: {
446
570
  status: 'cap',
571
+ cap,
447
572
  message: `DECISIONS.md 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 })),