arbiterdesign 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -142,8 +142,8 @@ flowchart TB
142
142
 
143
143
  1. **You ask for a screen.** The agent reads `DECISIONS.md` first. After a sizeable piece of work it names up to three rules that shaped it, like *Following D-0001 (removing asks first, no undo bar)*, so you can see the record working.
144
144
  2. **You iterate.** The agent says nothing about decisions while you're going back and forth. Each version you move past becomes a rejected alternative on the one that replaced it.
145
- 3. **You move on.** The agent queues the design calls it made, sized as `feature`, `pattern` or `polish`. When 5 are waiting (then 10, 15…) it asks if you want to review them. Polish doesn't count toward that. Only real choices get queued: things you asked for, things you corrected, and options the agent actually weighed. Its habits don't.
146
- 4. **You judge them when you want.** In chat with `/arbiter`, or in the browser with `npx arbiter review`.
145
+ 3. **You move on.** The agent queues the design calls it made, sized as `feature` or `pattern` (a small one-off fix isn't recorded at all). When 5 are waiting (then 10, 15…) it asks if you want to review them. Only real choices get queued: things you asked for, things you corrected, and options the agent actually weighed. Its habits don't.
146
+ 4. **You judge them when you want.** In chat with `/arbiter`, or on your local board: answer "yes, in the browser" when it asks, or open it yourself with `npx arbiter review`. Keep it open while you work: it shows what the agent records as it records it, and in Claude Code the fixes you ask for there reach the agent with your next message. Elsewhere they come at the next `/arbiter`. Close the tab when you're done with it.
147
147
  5. **Rules go into `DECISIONS.md`.** Everything you judged goes into the archive. Skipped items disappear. The next session reads the new rules.
148
148
  6. **You share it.** `npx arbiter publish` puts the board online, so your team can see each screen, what was decided and why. They can comment or request a change, and `npx arbiter pull` brings that back for you to answer. More in [Share it with your team](#share-it-with-your-team).
149
149
 
@@ -173,7 +173,7 @@ Each item reads as **Change** (what happened), **Pattern** (the rule) and **Reje
173
173
  | **Skip** | Thrown away. |
174
174
  | **Fix** | Type a correction and it's recorded your way. |
175
175
 
176
- Polish items come as one line per group with a single **Confirm all**. If an item goes against an existing rule, Arbiter says so (*Clashes with D-0009*) and asks which one wins: **Follow D-0009**, **Replace D-0009**, or **Keep as exception**.
176
+ Small one-off fixes never reach the queue, so each item is a real call. If an item goes against an existing rule, Arbiter says so (*Clashes with D-0009*) and asks which one wins: **Follow D-0009**, **Replace D-0009**, or **Keep as exception**.
177
177
 
178
178
  > [!TIP]
179
179
  > Too chatty? `npx arbiter setup --checkin quiet` turns off the check-ins. `--checkin every` does the opposite and mentions a rule every time one changed something.
@@ -228,11 +228,11 @@ Git stays the source of truth. The service only holds the latest board and its c
228
228
  A comment is just input. **Request change** is different: someone wants something changed, so it gets a proper answer.
229
229
 
230
230
  1. `npx arbiter pull` turns each request into `R-0001` in `.arbiter/requests.json`. Commit it so everyone sees the same answers.
231
- 2. You answer in chat with `/arbiter`, or on the **Requests** tab of `arbiter review`:
231
+ 2. You answer in chat with `/arbiter`:
232
232
  - **Apply**: `record R-0001 --as apply`
233
233
  - **Apply, but…**: `record R-0001 --as apply --to "keep the tab, make the button red"`
234
234
  - **Decline**: `record R-0001 --as decline --why "…"` (a reason is required, since the requester reads it)
235
- 3. The agent makes the change. Approving from chat makes it right away; approving from the review page makes it at the next `/arbiter`.
235
+ 3. The agent makes the change right away.
236
236
  4. `publish` sends the answer back. The requester sees *Open*, *Approved*, *Applied* (with what changed) or *Declined* (with the reason).
237
237
 
238
238
  > [!NOTE]
@@ -252,7 +252,7 @@ A comment is just input. **Request change** is different: someone wants somethin
252
252
 
253
253
  ### Other ways to share
254
254
 
255
- - **Static export.** `npx arbiter export` writes `arbiter-export/`: one `index.html` plus snapshots, no server, no JavaScript. Drop it on any static host. It's a read-only view: each screen, its state, who approved it, why the others lost, and what was decided in plain words.
255
+ - **Static export.** `npx arbiter export` writes `arbiter-export/`: the same board as `arbiter review`, read-only, as a folder (`index.html`, the board's script and styles, and the pictures). No server: open it from disk or drop it on any static host. Each change with its picture and how it got there, what was decided in plain words, and with `--include-rules`, your design rules.
256
256
  - **GitHub Pages.** With `"destination": "git"` in `arbiter.json`, every candidate change also writes the export to `docs/arbiter/`. Turn on Pages for the `docs` folder once and the board lives at `https://<owner>.github.io/<repo>/arbiter/`. `npx arbiter publish --to pages` does the whole setup in one go.
257
257
 
258
258
  ## Screenshots
@@ -260,7 +260,7 @@ A comment is just input. **Request change** is different: someone wants somethin
260
260
  The agent takes one picture per piece of work, when the work settles and it changed how a specific screen looks.
261
261
 
262
262
  - **Gets a picture:** layout, wording or visual changes to one screen. Even a small pattern change counts.
263
- - **Doesn't:** font or token changes (no single screen to show), motion and behaviour (a still can't show it), and polish (it never reaches the board).
263
+ - **Doesn't:** font or token changes (no single screen to show), motion and behaviour (a still can't show it), and small one-off fixes (they aren't recorded).
264
264
 
265
265
  The agent renders pictures with a headless browser. If it can't (no browser, app not running, screen behind a login) it tells you once and says why. On macOS, `--capture` lets you drag-select a picture yourself; elsewhere, save one and pass `--file`.
266
266
 
@@ -339,7 +339,7 @@ npx arbiter pull # bring comments and requests back
339
339
  | `arbiter record '<json>'` | Record now (what the agent calls). |
340
340
  | `arbiter record --pending '<json>'` | Queue for later. |
341
341
  | `arbiter record P-0003 --as rule` | Judge a queued item: `accept`, `rule`, `skip` or `fix --to "…"`. Add `--candidate C-0001` to link it, or `--against D-0009` to name the rule it goes against (with `accept`, it's logged as an exception to that rule). |
342
- | `arbiter record --all --as accept` | Judge every queued item. Narrow with `--level polish` or `--trigger "Settings build"`. |
342
+ | `arbiter record --all --as accept` | Judge every queued item. Narrow with `--level pattern` or `--trigger "Settings build"`. |
343
343
  | `arbiter record --findings f.json` | Queue a scanner's findings for verdicts. |
344
344
  | `arbiter record --retire D-0003 --why "…"` | Drop a rule with no replacement. |
345
345
  | `arbiter record --reword D-0003 --to "…"` | Change a rule's wording. It keeps its id, and the old wording stays on the entry. |
@@ -351,7 +351,9 @@ npx arbiter pull # bring comments and requests back
351
351
 
352
352
  | Command | What it does |
353
353
  |---|---|
354
- | `arbiter review` | Judge the queue, screens and requests in a browser page. |
354
+ | `arbiter review` | Your local board, in the browser: what's waiting for you to judge, every change with its picture, and your design rules. It keeps itself current while it's open, and stops when you close its tab. Nothing is uploaded. What still needs a code change reaches your agent with your next message in Claude Code (a hook `init` installs), or at the next `/arbiter`. |
355
+ | `arbiter review --json` | For an agent that waits on the board: when its last tab closes, hands over what you decided as JSON. |
356
+ | `arbiter review --done` | For the agent, once it has made what the board handed it: clears that, and keeps anything you judged meanwhile. |
355
357
  | `arbiter rules [--dimension <name>] [--json]` | Active rules. |
356
358
  | `arbiter rules --pending` | The queue, plus requests waiting on an answer. |
357
359
  | `arbiter rules --archive` | Everything ever recorded. |
@@ -407,7 +409,7 @@ npx arbiter pull # bring comments and requests back
407
409
  | `date` | ISO 8601. |
408
410
  | `author` | Who decided. |
409
411
  | `class` | `mechanical` (checkable in code) or `judgment`. |
410
- | `level` | `feature`, `pattern` or `polish`. How big a call it is. Polish is never reviewed one by one. |
412
+ | `level` | `feature` or `pattern`. How big a call it is. A `polish` one-off fix isn't recorded: `record` answers `not-recorded` and writes nothing. |
411
413
  | `dimension` | `structure`, `interaction`, `states`, `content`, `visual`, `motion` or `access`. |
412
414
  | `change` | What happened, in plain words. What the reviewer reads. |
413
415
  | `decision` | The same call written as a rule. What future sessions read. |
@@ -458,23 +460,9 @@ Run `npx arbiterdesign init` in the folder your agent works in, or ask the agent
458
460
  </details>
459
461
 
460
462
  <details>
461
- <summary><b>Do I have to write anything?</b></summary>
463
+ <summary><b>Will it interrupt me, or bury me in reviews?</b></summary>
462
464
 
463
- No. The agent records what it decided and what it chose over. You confirm, make it a rule, or skip, in chat or on the review page. Mid-session you can also just say *"make that a rule"* and it's recorded without a question.
464
-
465
- </details>
466
-
467
- <details>
468
- <summary><b>Does it interrupt me while I'm iterating?</b></summary>
469
-
470
- No. A screen you redesign six times is one piece of work, not six prompts. Decisions queue silently and surface in one line when you move on. You judge them when you want, or never.
471
-
472
- </details>
473
-
474
- <details>
475
- <summary><b>Will I be reviewing hundreds of tiny decisions?</b></summary>
476
-
477
- No. Every decision is sized as feature, pattern or polish. Feature and pattern items get a card each. Polish is one line per piece of work with a single **Confirm all**. A 7px height fix and a new settings architecture don't get the same treatment.
465
+ No. Decisions queue silently while you iterate and surface in one line when you move on. Only features and patterns are queued, a card each; small one-off fixes aren't recorded at all. You judge them when you want, or never.
478
466
 
479
467
  </details>
480
468
 
@@ -507,23 +495,16 @@ Good. Arbiter records decisions, not tokens. Rules can name your components and
507
495
  </details>
508
496
 
509
497
  <details>
510
- <summary><b>Which agents does it work with?</b></summary>
511
-
512
- Claude Code and Cursor get the whole loop: the agent reads your rules before UI work and records what it decides. Other agents that read a project's instructions file, like Codex, Copilot and Gemini CLI, follow the rules but don't record.
513
-
514
- </details>
515
-
516
- <details>
517
- <summary><b>Who installs it, and what does the rest of the team need?</b></summary>
498
+ <summary><b>Is this like ADRs?</b></summary>
518
499
 
519
- Whoever has the repo runs one command. Everyone else gets a link to the board. To comment or say "looks good", they sign in with an email link. No account to create, nothing to install.
500
+ Yes, same idea: a call, what it beat, and why. ADRs (architecture decision records) are for engineering: the stack, the data model, the API. Arbiter is for design: layout, flow, copy and states. And no one writes it up. The agent records each call as it works and you approve in seconds.
520
501
 
521
502
  </details>
522
503
 
523
504
  <details>
524
- <summary><b>Will it slow the agent down?</b></summary>
505
+ <summary><b>Doesn't Claude have memory now?</b></summary>
525
506
 
526
- No. Active rules are capped at 40 and read once, before UI work, not on every turn. The archive of everything ever decided is never loaded.
507
+ Yes, but memory is what the agent learned. Arbiter is what your team decided. Claude Code's auto memory is notes Claude keeps for itself: nobody approves them, and they stay on one machine. Arbiter's rules are ones you approved, kept in the repo for every teammate, and each one records what it beat and what it replaced.
527
508
 
528
509
  </details>
529
510
 
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.arrangementOf = exports.keyOf = exports.setName = exports.sameHead = exports.headOf = exports.FOUNDATIONS = void 0;
4
+ exports.areasFor = areasFor;
5
+ exports.layoutOf = layoutOf;
6
+ /** A change to the whole product — type, colour, spacing, voice — rather than to a place in it. */
7
+ exports.FOUNDATIONS = 'Foundations';
8
+ /**
9
+ * "Settings — billing", "Settings—billing", "Settings: billing", "Settings - billing" → "Settings". The way
10
+ * the agent is asked to name work. A dash needs no spaces; a hyphen does, or "Sign-in page" would split.
11
+ */
12
+ const headOf = (name) => {
13
+ const head = name.split(/\s*[—–]\s*|\s+-\s+|:\s+/)[0].trim();
14
+ return head && head !== name.trim() ? head : null;
15
+ };
16
+ exports.headOf = headOf;
17
+ /**
18
+ * Two options are in one set, the versions of one thing to choose between, when they share their feature
19
+ * (the area) and what their names start with: "Empty state — illustration" and "Empty state — checklist"
20
+ * are one set; "Row layout — compact", in the same area, is another. Names with no head share one set.
21
+ * The board groups by it, and approving one supersedes only the rest of its set.
22
+ */
23
+ const sameHead = (a, b) => ((0, exports.headOf)(a.name) ?? '').toLowerCase() === ((0, exports.headOf)(b.name) ?? '').toLowerCase();
24
+ exports.sameHead = sameHead;
25
+ /**
26
+ * A set's name: what its options' names start with ("Empty state", in Projects), or its area when the names
27
+ * only say that ("Project card — compact" in Project card, "Card — compact" in Card component).
28
+ */
29
+ const setName = (area, c) => {
30
+ const head = (0, exports.headOf)(c.name);
31
+ return head && !area.toLowerCase().startsWith(head.toLowerCase()) ? head : area;
32
+ };
33
+ exports.setName = setName;
34
+ const everywhere = (c) => c.decisions.length > 0 && c.decisions.every((d) => d.scope === 'global');
35
+ /** `name` starts with the area `k` at a word boundary: "reports filters", "reports—x", "reports: x" — not "reportsx". */
36
+ const under = (name, k) => name === k || (name.startsWith(k) && /^[\s:—–]/.test(name.slice(k.length)));
37
+ /**
38
+ * The product area each card belongs to — what the board groups by, and what the rail lists.
39
+ * A set of options has one: the feature it was explored for. A change that was simply made
40
+ * (a piece of work) takes one from its name: "Settings — billing" is Settings, and "Reports
41
+ * filters" is Reports when Reports is an area on this board. A change where every decision
42
+ * applies everywhere is Foundations. Anything else is an area of its own, by its name.
43
+ *
44
+ * Needs the whole board: which areas exist decides where a name like "Reports filters" goes.
45
+ */
46
+ function areasFor(cards) {
47
+ const known = new Map();
48
+ const learn = (name) => { if (!known.has(name.toLowerCase()))
49
+ known.set(name.toLowerCase(), name); };
50
+ for (const c of cards)
51
+ if (c.feature)
52
+ learn(c.feature);
53
+ for (const c of cards) {
54
+ if (!c.work || c.feature)
55
+ continue;
56
+ // A named head is an area; so is a plain change's whole name ("Reports"), unless it's a foundation.
57
+ const head = (0, exports.headOf)(c.name);
58
+ if (head)
59
+ learn(head);
60
+ else if (!everywhere(c))
61
+ learn(c.name.trim());
62
+ }
63
+ // Longest first, so "Settings billing" isn't taken by an area called "Set".
64
+ const byLength = [...known.entries()].sort((a, b) => b[0].length - a[0].length);
65
+ return (c) => {
66
+ if (c.feature)
67
+ return c.feature;
68
+ const lower = c.name.trim().toLowerCase();
69
+ // An area it sits under — never itself: its own name is an area for others, not a match for it.
70
+ for (const [k, v] of byLength)
71
+ if (k !== lower && under(lower, k))
72
+ return v;
73
+ if (everywhere(c))
74
+ return exports.FOUNDATIONS;
75
+ return known.get(lower) ?? c.name.trim();
76
+ };
77
+ }
78
+ const low = (s) => s.toLowerCase();
79
+ const keyOf = (e) => (e.kind === 'folder' ? `folder:${e.id}` : low(e.name));
80
+ exports.keyOf = keyOf;
81
+ /**
82
+ * The Areas list as it was arranged: that order first, then anything new in the board's own order. A
83
+ * folder keeps only the areas on the board now, and an area sits in one folder at most.
84
+ */
85
+ function layoutOf(names, arr) {
86
+ const known = new Map(names.map((n) => [low(n), n]));
87
+ const filed = new Set();
88
+ const folders = (arr?.folders ?? []).map((f) => {
89
+ const areas = [];
90
+ for (const a of f.areas) {
91
+ const n = known.get(low(a));
92
+ if (n && !filed.has(low(n))) {
93
+ filed.add(low(n));
94
+ areas.push(n);
95
+ }
96
+ }
97
+ return { kind: 'folder', id: f.id, name: f.name, areas };
98
+ });
99
+ const all = [...folders, ...names.filter((n) => !filed.has(low(n))).map((name) => ({ kind: 'area', name }))];
100
+ const byKey = new Map(all.map((e) => [(0, exports.keyOf)(e), e]));
101
+ const out = [];
102
+ const used = new Set();
103
+ for (const k of arr?.order ?? []) {
104
+ const e = byKey.get(k.startsWith('folder:') ? k : low(k));
105
+ if (e && !used.has((0, exports.keyOf)(e))) {
106
+ used.add((0, exports.keyOf)(e));
107
+ out.push(e);
108
+ }
109
+ }
110
+ for (const e of all)
111
+ if (!used.has((0, exports.keyOf)(e)))
112
+ out.push(e);
113
+ return out;
114
+ }
115
+ /** The rows as they're saved. */
116
+ const arrangementOf = (es) => ({
117
+ folders: es.flatMap((e) => (e.kind === 'folder' ? [{ id: e.id, name: e.name, areas: e.areas }] : [])),
118
+ order: es.map((e) => (e.kind === 'folder' ? `folder:${e.id}` : e.name)),
119
+ });
120
+ exports.arrangementOf = arrangementOf;
package/dist/areas.js ADDED
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ /**
3
+ * Folders in the local board's side nav: what you make under Areas, name, and drag areas into. Saved
4
+ * in `.arbiter/areas.json`, beside the record, so it travels with the project: teammates and an
5
+ * exported copy see the same folders. Areas themselves stay automatic (src/board-types.ts, `areasFor`
6
+ * on the page); a folder only holds them, by name, so a change that joins an area joins its folder too.
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.areasPath = exports.AREAS_FILE = void 0;
13
+ exports.readArrangement = readArrangement;
14
+ exports.cleanArrangement = cleanArrangement;
15
+ exports.writeArrangement = writeArrangement;
16
+ const node_fs_1 = __importDefault(require("node:fs"));
17
+ const node_path_1 = __importDefault(require("node:path"));
18
+ exports.AREAS_FILE = 'areas.json';
19
+ const MAX_FOLDERS = 50;
20
+ const MAX_NAME = 60;
21
+ const MAX_AREA = 200;
22
+ const MAX_ORDER = 1000;
23
+ const FOLDER_ID = /^[a-z0-9]{1,24}$/;
24
+ const areasPath = (paths) => node_path_1.default.join(paths.archiveDir, exports.AREAS_FILE);
25
+ exports.areasPath = areasPath;
26
+ /** The saved folders, or null when there are none. A file that doesn't read is no folders, not a broken board. */
27
+ function readArrangement(paths) {
28
+ const file = (0, exports.areasPath)(paths);
29
+ if (!node_fs_1.default.existsSync(file))
30
+ return null;
31
+ try {
32
+ const r = cleanArrangement(JSON.parse(node_fs_1.default.readFileSync(file, 'utf8')));
33
+ return r.ok ? r.value : null;
34
+ }
35
+ catch {
36
+ return null;
37
+ }
38
+ }
39
+ /**
40
+ * What the page sent, checked and tidied: names trimmed, an area in one folder at most (the first),
41
+ * one entry per thing in the order. Anything it can't make sense of is refused whole, with why.
42
+ */
43
+ function cleanArrangement(input) {
44
+ const errors = [];
45
+ const raw = (input ?? {});
46
+ if (!Array.isArray(raw.folders))
47
+ errors.push('folders must be a list');
48
+ if (raw.order !== undefined && !Array.isArray(raw.order))
49
+ errors.push('order must be a list');
50
+ if (errors.length)
51
+ return { ok: false, errors };
52
+ const list = raw.folders;
53
+ if (list.length > MAX_FOLDERS)
54
+ return { ok: false, errors: [`At most ${MAX_FOLDERS} folders`] };
55
+ const folders = [];
56
+ const ids = new Set();
57
+ const names = new Set();
58
+ const filed = new Set();
59
+ for (const f of list) {
60
+ const x = (f ?? {});
61
+ const id = typeof x.id === 'string' ? x.id : '';
62
+ const name = typeof x.name === 'string' ? x.name.replace(/\s+/g, ' ').trim() : '';
63
+ if (!FOLDER_ID.test(id)) {
64
+ errors.push(`A folder id must be letters and digits: ${JSON.stringify(x.id)}`);
65
+ continue;
66
+ }
67
+ if (ids.has(id)) {
68
+ errors.push(`Two folders share the id ${id}`);
69
+ continue;
70
+ }
71
+ if (!name) {
72
+ errors.push('A folder needs a name');
73
+ continue;
74
+ }
75
+ if (name.length > MAX_NAME) {
76
+ errors.push(`A folder name is ${MAX_NAME} characters at most`);
77
+ continue;
78
+ }
79
+ if (names.has(name.toLowerCase())) {
80
+ errors.push(`There's already a folder called ${name}`);
81
+ continue;
82
+ }
83
+ if (!Array.isArray(x.areas)) {
84
+ errors.push(`${name}: areas must be a list`);
85
+ continue;
86
+ }
87
+ ids.add(id);
88
+ names.add(name.toLowerCase());
89
+ const areas = [];
90
+ for (const a of x.areas) {
91
+ if (typeof a !== 'string')
92
+ continue;
93
+ const area = a.trim();
94
+ if (!area || area.length > MAX_AREA || filed.has(area.toLowerCase()))
95
+ continue;
96
+ filed.add(area.toLowerCase());
97
+ areas.push(area);
98
+ }
99
+ folders.push({ id, name, areas });
100
+ }
101
+ if (errors.length)
102
+ return { ok: false, errors };
103
+ const order = [];
104
+ const seen = new Set();
105
+ for (const k of raw.order ?? []) {
106
+ if (typeof k !== 'string')
107
+ continue;
108
+ const key = k.trim();
109
+ if (!key || key.length > MAX_AREA + 7 || seen.has(key.toLowerCase()))
110
+ continue;
111
+ // A folder that isn't there, or an area that's inside a folder, has no place at the top.
112
+ if (key.startsWith('folder:') ? !ids.has(key.slice(7)) : filed.has(key.toLowerCase()))
113
+ continue;
114
+ seen.add(key.toLowerCase());
115
+ order.push(key);
116
+ if (order.length >= MAX_ORDER)
117
+ break;
118
+ }
119
+ return { ok: true, value: { folders, order } };
120
+ }
121
+ /** Saves the folders. With none left and no order of your own, the file goes, and the board is as it was. */
122
+ function writeArrangement(paths, a) {
123
+ const file = (0, exports.areasPath)(paths);
124
+ if (!a.folders.length && !a.order.length) {
125
+ if (node_fs_1.default.existsSync(file))
126
+ node_fs_1.default.rmSync(file);
127
+ return;
128
+ }
129
+ node_fs_1.default.mkdirSync(paths.archiveDir, { recursive: true });
130
+ node_fs_1.default.writeFileSync(file, `${JSON.stringify(a, null, 2)}\n`);
131
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * What the local board draws, as the CLI sends it: one definition for both sides. The CLI builds it
4
+ * (src/localboard.ts) and the page reads it (board/types.ts, board/lib/board.ts), so a change to one
5
+ * that the other doesn't follow fails the build instead of breaking the page.
6
+ *
7
+ * Types only, with no imports: the page's build reads this file too.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -81,6 +81,12 @@ function formatCandidate(c, decisions) {
81
81
  }
82
82
  const HEADING = /^# (C-\d{4,}) · (.*)$/;
83
83
  const IMG = /^!\[.*?\]\((.+?)\)$/;
84
+ /**
85
+ * The only pictures a card has: the ones `candidate` copies in, named by its id. Anything else in the
86
+ * file (`../hosted.token`, a path out of the project) is no picture, so export, the board and remove
87
+ * never read, copy or delete outside the candidates folder.
88
+ */
89
+ const PICTURE = /^C-\d{4,}\.(png|jpe?g|webp|gif|svg)$/;
84
90
  const FIELD = /\*\*([A-Za-z ]+):\*\* (.*?)(?=\s·\s\*\*|$)/g;
85
91
  function parseCandidate(md) {
86
92
  const lines = md.split('\n');
@@ -111,7 +117,7 @@ function parseCandidate(md) {
111
117
  continue;
112
118
  const img = IMG.exec(line);
113
119
  if (img) {
114
- c.snapshot = img[1];
120
+ c.snapshot = PICTURE.test(img[1]) ? img[1] : null;
115
121
  continue;
116
122
  }
117
123
  if (!line.startsWith('- **'))
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ /**
3
+ * `arbiter areas` — where everything sits on the board: Folder → Area → Change → Decision.
4
+ *
5
+ * The agent reads it before naming a piece of work, so new work joins an area that's already there
6
+ * ("Review inbox — Sorting") instead of starting one of its own. `--save` writes the folders, once the
7
+ * person has said yes to them; it's the same file the board's side nav saves (`.arbiter/areas.json`).
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.structureOf = structureOf;
11
+ exports.structureText = structureText;
12
+ exports.areasCommand = areasCommand;
13
+ exports.saveFolders = saveFolders;
14
+ exports.placement = placement;
15
+ const store_1 = require("../store");
16
+ const localboard_1 = require("../localboard");
17
+ const area_names_1 = require("../area-names");
18
+ const areas_1 = require("../areas");
19
+ const work_1 = require("../work");
20
+ /** The board as the side nav shows it: folders with their areas, then the areas in no folder, each with its changes. */
21
+ function structureOf(paths) {
22
+ const data = (0, localboard_1.liveBoard)(paths);
23
+ // Work with nothing judged yet is placed by what's waiting on it, as the board places it.
24
+ const cards = data.board.candidates.map((c) => (c.work && !c.decisions.length ? { ...c, decisions: data.queued[c.id] ?? [] } : c));
25
+ const of = (0, area_names_1.areasFor)(cards);
26
+ const changes = new Map();
27
+ for (const c of cards)
28
+ changes.set(of(c), [...(changes.get(of(c)) ?? []), c.name]);
29
+ const view = (name) => ({ name, changes: changes.get(name) ?? [] });
30
+ const rows = (0, area_names_1.layoutOf)([...changes.keys()], data.arrangement);
31
+ const folders = rows.flatMap((e) => (e.kind === 'folder' ? [{ id: e.id, name: e.name, areas: e.areas.map(view) }] : []));
32
+ const loose = rows.flatMap((e) => (e.kind === 'area' ? [view(e.name)] : []));
33
+ return { folders, loose, counts: { folders: folders.length, areas: changes.size, changes: cards.length } };
34
+ }
35
+ /** The structure as lines: folders, their areas with a count, the changes under each. */
36
+ function structureText(s) {
37
+ const n = (k, one) => `${k} ${one}${k === 1 ? '' : 's'}`;
38
+ const out = [`Areas · ${[s.counts.folders ? n(s.counts.folders, 'folder') : '', n(s.counts.areas, 'area'), n(s.counts.changes, 'change')].filter(Boolean).join(', ')}`, ''];
39
+ const area = (a, indent) => {
40
+ out.push(`${indent}${a.name} · ${a.changes.length}`);
41
+ for (const c of a.changes)
42
+ out.push(`${indent} ${c}`);
43
+ };
44
+ for (const f of s.folders) {
45
+ out.push(f.name);
46
+ if (!f.areas.length)
47
+ out.push(' (empty)');
48
+ for (const a of f.areas)
49
+ area(a, ' ');
50
+ }
51
+ if (s.folders.length && s.loose.length)
52
+ out.push('Not in a folder');
53
+ for (const a of s.loose)
54
+ area(a, s.folders.length ? ' ' : '');
55
+ return out.join('\n');
56
+ }
57
+ function areasCommand(opts = {}) {
58
+ const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
59
+ if (opts.save !== undefined) {
60
+ const saved = saveFolders(paths, opts.save);
61
+ if (saved.exitCode !== 0)
62
+ return saved;
63
+ }
64
+ const s = structureOf(paths);
65
+ // Turned off in Preferences: the agent doesn't offer to group areas into folders.
66
+ const quiet = (0, store_1.readConfig)(paths)?.suggestFolders === false;
67
+ return {
68
+ exitCode: 0,
69
+ output: { ...(opts.save !== undefined ? { status: 'saved' } : {}), ...s, ...(quiet ? { suggestFolders: false } : {}) },
70
+ text: structureText(s) + (quiet ? '\n\nFolder suggestions are off (Preferences, on the board): don\'t offer to group areas.' : ''),
71
+ };
72
+ }
73
+ /**
74
+ * Folders as the agent proposes them, once the person has said yes: `{ "folders": [{ "name", "areas" }] }`.
75
+ * It replaces the folders there were. Every area named has to be on the board, so a typo is caught
76
+ * rather than saved; areas left out stay where they are, in no folder.
77
+ */
78
+ function saveFolders(paths, raw) {
79
+ let input;
80
+ try {
81
+ input = JSON.parse(raw);
82
+ }
83
+ catch (e) {
84
+ return fail([`not JSON: ${e.message}`]);
85
+ }
86
+ if (!Array.isArray(input?.folders))
87
+ return fail(['expected { "folders": [{ "name": "Local board", "areas": ["Review inbox", "Change page"] }] }']);
88
+ const s = structureOf(paths);
89
+ const known = new Map([...s.folders.flatMap((f) => f.areas), ...s.loose].map((a) => [a.name.toLowerCase(), a.name]));
90
+ const unknown = input.folders.flatMap((f) => (f.areas ?? []).filter((a) => !known.has(String(a).trim().toLowerCase())));
91
+ if (unknown.length)
92
+ return fail([`not an area on the board: ${unknown.join(', ')}`, `areas: ${[...known.values()].join(', ')}`]);
93
+ // Ids from names, kept for folders that already had one, so the board's open folders stay open.
94
+ const had = new Map(s.folders.map((f) => [f.name.toLowerCase(), f.id]));
95
+ const used = new Set();
96
+ const idFor = (name) => {
97
+ const base = had.get(name.toLowerCase()) ?? (name.toLowerCase().replace(/[^a-z0-9]+/g, '').slice(0, 20) || 'folder');
98
+ let id = base;
99
+ for (let i = 2; used.has(id); i++)
100
+ id = `${base.slice(0, 20)}${i}`;
101
+ used.add(id);
102
+ return id;
103
+ };
104
+ const folders = input.folders.map((f) => ({ kind: 'folder', id: f.id && /^[a-z0-9]{1,24}$/.test(f.id) ? f.id : idFor(String(f.name ?? '')), name: String(f.name ?? ''), areas: (f.areas ?? []).map((a) => known.get(String(a).trim().toLowerCase())) }));
105
+ const filed = new Set(folders.flatMap((f) => (f.kind === 'folder' ? f.areas.map((a) => a.toLowerCase()) : [])));
106
+ // The folders first, in the order given, then every area left out, in the order it had.
107
+ const rest = [...s.folders.flatMap((f) => f.areas), ...s.loose].filter((a) => !filed.has(a.name.toLowerCase())).map((a) => ({ kind: 'area', name: a.name }));
108
+ const r = (0, areas_1.cleanArrangement)((0, area_names_1.arrangementOf)([...folders, ...rest]));
109
+ if (!r.ok)
110
+ return fail(r.errors);
111
+ (0, areas_1.writeArrangement)(paths, r.value);
112
+ return { exitCode: 0, output: { status: 'saved' } };
113
+ }
114
+ /**
115
+ * For the reply to `record --pending`: the area a piece of work landed in, and, when it's the first
116
+ * decision of new work that starts an area of its own, the areas already there, so the agent can
117
+ * rename it into one of them.
118
+ */
119
+ function placement(paths, entry, earlier) {
120
+ if (entry.candidate)
121
+ return {};
122
+ try {
123
+ const s = structureOf(paths);
124
+ const all = [...s.folders.flatMap((f) => f.areas.map((a) => ({ ...a, folder: f.name }))), ...s.loose.map((a) => ({ ...a, folder: null }))];
125
+ const mine = all.find((a) => a.changes.some((c) => (0, work_1.workId)(c) === (0, work_1.workId)(entry.trigger)));
126
+ if (!mine)
127
+ return {};
128
+ const first = !earlier.some((d) => (0, work_1.workId)(d.trigger) === (0, work_1.workId)(entry.trigger)) && !(0, store_1.readArchive)(paths).some((d) => (0, work_1.workId)(d.trigger) === (0, work_1.workId)(entry.trigger));
129
+ const others = all.filter((a) => a !== mine).map((a) => a.name);
130
+ const fresh = first && mine.changes.length === 1 && others.length > 0;
131
+ // New work beside changes already in its area: it may continue one of them, and then it belongs in it.
132
+ const beside = first && !fresh ? mine.changes.filter((c) => (0, work_1.workId)(c) !== (0, work_1.workId)(entry.trigger)) : [];
133
+ return {
134
+ area: mine.name,
135
+ ...(mine.folder ? { folder: mine.folder } : {}),
136
+ ...(fresh ? {
137
+ newArea: true,
138
+ areas: others.slice(0, 40),
139
+ hint: `"${entry.trigger}" starts an area of its own. If it belongs in one of these, rename it: npx arbiter rename "${entry.trigger}" "<Area> — <what changed>"`,
140
+ } : {}),
141
+ ...(beside.length ? {
142
+ newChange: true,
143
+ changes: beside.slice(0, 40),
144
+ hint: `"${entry.trigger}" is a new change in ${mine.name}. If it continues one of these, merge it, so its picture becomes that change's next version: npx arbiter rename "${entry.trigger}" "<that change>" --merge`,
145
+ } : {}),
146
+ };
147
+ }
148
+ catch {
149
+ // Where it sits is a courtesy: a board that won't read never stops a decision being queued.
150
+ return {};
151
+ }
152
+ }
153
+ const fail = (errors) => ({ exitCode: 1, output: { status: 'invalid', errors } });
@@ -7,7 +7,7 @@
7
7
  * candidate C-0002 --state rejected --why "…"
8
8
  * candidate C-0002 --snapshot new.png
9
9
  *
10
- * Approving one direction supersedes its siblings (same feature, still open)
10
+ * Approving one direction supersedes its siblings (same set: feature and name head, still open)
11
11
  * with the reason retained — the rejected branches are the point.
12
12
  */
13
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
@@ -24,6 +24,7 @@ const node_child_process_1 = require("node:child_process");
24
24
  const candidates_1 = require("../candidates");
25
25
  const store_1 = require("../store");
26
26
  const destination_1 = require("../destination");
27
+ const area_names_1 = require("../area-names");
27
28
  function addCandidate(name, opts = {}) {
28
29
  if (!name?.trim())
29
30
  return fail(['a name is required']);
@@ -84,7 +85,8 @@ function updateCandidate(id, opts = {}) {
84
85
  c.reason = opts.why.trim() || null;
85
86
  if (state === 'approved' && !opts.keepOthers && c.feature) {
86
87
  for (const sib of all) {
87
- if (sib.id === c.id || sib.feature !== c.feature)
88
+ // Only its own set: another thing explored in the same area stays open.
89
+ if (sib.id === c.id || sib.feature !== c.feature || !(0, area_names_1.sameHead)(sib, c))
88
90
  continue;
89
91
  if (sib.state !== 'generated' && sib.state !== 'in_review')
90
92
  continue;