arbiterdesign 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +288 -242
  2. package/dist/area-names.js +120 -0
  3. package/dist/areas.js +131 -0
  4. package/dist/board-types.js +9 -0
  5. package/dist/candidates.js +7 -1
  6. package/dist/commands/areas.js +153 -0
  7. package/dist/commands/candidate.js +4 -2
  8. package/dist/commands/decision.js +100 -0
  9. package/dist/commands/export.js +88 -125
  10. package/dist/commands/init.js +198 -73
  11. package/dist/commands/invite.js +67 -0
  12. package/dist/commands/publish.js +4 -4
  13. package/dist/commands/record.js +133 -8
  14. package/dist/commands/remove.js +1 -1
  15. package/dist/commands/rename.js +25 -11
  16. package/dist/commands/review.js +458 -78
  17. package/dist/commands/rules.js +22 -3
  18. package/dist/commands/setup.js +1 -0
  19. package/dist/commands/snapshot.js +24 -2
  20. package/dist/commands/sweep.js +1 -1
  21. package/dist/commands/update.js +5 -0
  22. package/dist/comments.js +24 -0
  23. package/dist/format.js +112 -7
  24. package/dist/handoff.js +286 -0
  25. package/dist/hook.js +82 -0
  26. package/dist/hosted.js +50 -17
  27. package/dist/index.js +99 -37
  28. package/dist/localboard.js +219 -0
  29. package/dist/lock.js +134 -0
  30. package/dist/overlap.js +16 -0
  31. package/dist/pictures.js +4 -0
  32. package/dist/settings.js +107 -0
  33. package/dist/store.js +164 -8
  34. package/dist/verify.js +4 -2
  35. package/dist/work.js +110 -1
  36. package/package.json +3 -2
  37. package/templates/SKILL.md +146 -51
  38. package/templates/board/board.css +2 -0
  39. package/templates/board/board.js +25 -0
  40. package/templates/board/index.html +15 -0
  41. package/templates/hooks/arbiter-board.cjs +50 -0
  42. package/templates/review.html +0 -757
@@ -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;
@@ -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: [`${(0, store_1.rulesName)(paths)} 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
+ }