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,219 @@
1
+ "use strict";
2
+ /**
3
+ * The local board's data, read from the project's files: what `arbiter review` sends the page
4
+ * (/api/board and /api/state) and what `arbiter export` writes into a read-only copy.
5
+ *
6
+ * Built here, apart from the manifest `publish` uploads (src/hosted.ts), so the local board can change
7
+ * what it shows without changing what the team board receives, and the other way round. The shapes
8
+ * are in src/board-types.ts, which the page reads too.
9
+ */
10
+ var __importDefault = (this && this.__importDefault) || function (mod) {
11
+ return (mod && mod.__esModule) ? mod : { "default": mod };
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.boardOf = boardOf;
15
+ exports.liveBoard = liveBoard;
16
+ exports.reviewState = reviewState;
17
+ const node_fs_1 = __importDefault(require("node:fs"));
18
+ const node_path_1 = __importDefault(require("node:path"));
19
+ const candidates_1 = require("./candidates");
20
+ const store_1 = require("./store");
21
+ const work_1 = require("./work");
22
+ const requests_1 = require("./requests");
23
+ const comments_1 = require("./comments");
24
+ const hosted_1 = require("./hosted");
25
+ const pictures_1 = require("./pictures");
26
+ const areas_1 = require("./areas");
27
+ const settings_1 = require("./settings");
28
+ const verify_1 = require("./verify");
29
+ /** On the board: judged, still in force, and not polish. */
30
+ const shown = (d) => d.verdict !== 'pending' && d.verdict !== 'retire' && d.level !== 'polish';
31
+ /**
32
+ * A decision as the board shows it. An exception carries the rule it goes against, found among every rule
33
+ * ever recorded, retired ones too; a rule no longer in force, how it left.
34
+ */
35
+ const toDecision = (d, inForce, rules, ends) => {
36
+ const rule = d.against && d.verdict !== 'rule' ? rules?.get(d.against) : undefined;
37
+ const ended = inForce && d.verdict === 'rule' && !inForce.has(d.id) ? ends?.(d.id) ?? null : null;
38
+ return { id: d.id, change: d.change, decision: d.decision, rejected: d.rejected, verdict: d.verdict, dimension: d.dimension, scope: d.scope, ref: d.ref, date: d.date, ...(inForce && d.verdict === 'rule' ? { active: inForce.has(d.id) } : {}), ...(rule ? { against: { id: rule.id, decision: rule.decision, rationale: rule.rationale } } : {}), ...(ended ? { ended } : {}) };
39
+ };
40
+ /**
41
+ * How each rule left DECISIONS.md, from the entry that ended it: a retirement says why, a newer rule
42
+ * that replaced it says what it says now. A rule still in force has none.
43
+ */
44
+ function endsOf(archive) {
45
+ const by = new Map();
46
+ for (const x of archive)
47
+ if (x.supersedes && !by.has(x.supersedes))
48
+ by.set(x.supersedes, x);
49
+ return (id) => {
50
+ const x = by.get(id);
51
+ if (!x)
52
+ return null;
53
+ return x.verdict === 'retire' ? { kind: 'retired', date: x.date, why: x.rationale } : { kind: 'replaced', date: x.date, by: { id: x.id, decision: x.decision } };
54
+ };
55
+ }
56
+ /**
57
+ * Every card and rule. A decision made on a screen rides with that screen; the rest are grouped by the
58
+ * piece of work they came from (`trigger`) into a card each. Pictures are links, never bytes.
59
+ */
60
+ function boardOf(paths, opts) {
61
+ const known = (0, candidates_1.readCandidates)(paths);
62
+ // Which rules are still in force, so a retired one doesn't read as a rule on its change's page.
63
+ const inForce = new Set((0, store_1.readActive)(paths).map((d) => d.id));
64
+ const archive = (0, store_1.readArchive)(paths);
65
+ const ruleById = new Map(archive.filter((d) => d.verdict === 'rule').map((d) => [d.id, d]));
66
+ const ends = endsOf(archive);
67
+ const candidates = known.map((c) => ({
68
+ id: c.id,
69
+ name: c.name,
70
+ feature: c.feature,
71
+ state: c.state,
72
+ author: c.author,
73
+ date: c.date,
74
+ reason: c.reason,
75
+ notes: c.notes,
76
+ supersededBy: c.supersededBy,
77
+ url: null,
78
+ snapshot: c.snapshot && node_fs_1.default.existsSync(node_path_1.default.join((0, candidates_1.candidatesDir)(paths), c.snapshot)) ? `${opts.pictures}${c.snapshot}` : null,
79
+ decisions: (0, candidates_1.decisionsFor)(paths, c.id).filter(shown).map((d) => toDecision(d, inForce, ruleById, ends)),
80
+ }));
81
+ // Screenless decisions: one card per piece of work.
82
+ const ids = new Set(known.map((c) => c.id));
83
+ const loose = archive.filter((d) => shown(d) && (!d.candidate || !ids.has(d.candidate)));
84
+ const byWork = new Map();
85
+ for (const d of loose)
86
+ byWork.set(d.trigger, [...(byWork.get(d.trigger) ?? []), d]);
87
+ const waitingOnly = new Map();
88
+ for (const d of opts.queued) {
89
+ if (d.level === 'polish' || (d.candidate && ids.has(d.candidate)) || byWork.has(d.trigger))
90
+ continue;
91
+ waitingOnly.set(d.trigger, [...(waitingOnly.get(d.trigger) ?? []), d]);
92
+ }
93
+ const areas = new Map(known.filter((c) => c.feature).map((c) => [c.feature.toLowerCase(), c.feature]));
94
+ for (const [trigger, ds] of [...byWork, ...waitingOnly]) {
95
+ const last = ds.reduce((a, b) => (a.date > b.date ? a : b));
96
+ const id = (0, work_1.workId)(trigger);
97
+ const shot = (0, work_1.workSnapshot)(paths, id);
98
+ candidates.push({
99
+ // Work has no product area of its own; it joins one only when the trigger names an existing one.
100
+ id, name: trigger, feature: areas.get(trigger.toLowerCase()) ?? null, state: 'recorded', work: true,
101
+ author: last.author, date: last.date, reason: null, notes: '', supersededBy: null, url: null,
102
+ snapshot: shot ? `${opts.pictures}${node_path_1.default.basename(shot)}` : null,
103
+ decisions: ds.filter(shown).map((d) => toDecision(d, inForce, ruleById, ends)),
104
+ ...versionsOf(paths, id, opts.pictures),
105
+ });
106
+ }
107
+ // The day each became a rule, for the Design rules page.
108
+ // With each, where it doesn't hold and what waits against it: the exceptions kept to it, and clashes in the Review inbox.
109
+ const link = (d) => {
110
+ const card = (0, requests_1.cardOf)(paths, d, ids);
111
+ return { id: d.id, card, name: known.find((c) => c.id === card)?.name ?? d.trigger, change: d.change ?? d.decision };
112
+ };
113
+ const rules = opts.includeRules ? (0, store_1.readActive)(paths).map((r) => ({
114
+ id: r.id, dimension: r.dimension, decision: r.decision, rationale: r.rationale, candidate: r.candidate ?? null, date: r.date.slice(0, 10),
115
+ exceptions: archive.filter((x) => x.against === r.id && x.verdict === 'accept').map(link),
116
+ waiting: opts.queued.filter((x) => x.against === r.id && x.verdict === 'pending').map(link),
117
+ })) : null;
118
+ // The rules taken out of it, the latest to go first: what they said, and how each left.
119
+ const retired = opts.includeRules ? archive.filter((r) => r.verdict === 'rule' && !inForce.has(r.id))
120
+ .map((r) => ({ id: r.id, dimension: r.dimension, decision: r.decision, rationale: r.rationale, candidate: r.candidate ?? null, date: r.date.slice(0, 10), ended: ends(r.id) }))
121
+ .sort((a, b) => (b.ended?.date ?? '').localeCompare(a.ended?.date ?? '') || b.id.localeCompare(a.id)) : null;
122
+ // The owner's answers to the team's change requests, so a thread shows the answer under its request.
123
+ const requests = (0, requests_1.readRequests)(paths)
124
+ .filter((r) => r.status !== 'open')
125
+ .map((r) => ({
126
+ comment: r.comment,
127
+ id: r.id,
128
+ status: r.status,
129
+ instead: r.instead,
130
+ reason: r.reason,
131
+ by: r.judgedBy,
132
+ at: r.appliedAt ?? r.judgedAt,
133
+ decisions: r.decisions.flatMap((id) => {
134
+ const d = archive.find((x) => x.id === id);
135
+ return d ? [{ id: d.id, change: d.change ?? d.decision, card: (0, requests_1.cardOf)(paths, d, ids) }] : [];
136
+ }),
137
+ }));
138
+ return { project: node_path_1.default.basename(paths.root), exported: new Date().toISOString().slice(0, 10), candidates, rules, retired, requests };
139
+ }
140
+ /** A piece of work's pictures, oldest first, when it has had more than one. */
141
+ function versionsOf(paths, id, pictures) {
142
+ const all = (0, work_1.workVersions)(paths, id);
143
+ return all.length > 1 ? { versions: all.map((v) => ({ src: `${pictures}${v.file}`, date: v.date })) } : {};
144
+ }
145
+ /**
146
+ * What `/api/board` sends: the board, plus what only this machine knows: what's waiting for review,
147
+ * and the team's comments as the last `pull` brought them.
148
+ */
149
+ function liveBoard(paths) {
150
+ const queued = (0, store_1.readPending)(paths);
151
+ const board = boardOf(paths, { pictures: '/snapshots/', includeRules: true, queued });
152
+ const ids = new Set((0, candidates_1.readCandidates)(paths).map((c) => c.id));
153
+ const waiting = {};
154
+ // Enough of each to draw a card and place it in its area before anything on it is judged.
155
+ const lines = {};
156
+ for (const d of queued) {
157
+ if (d.level === 'polish')
158
+ continue;
159
+ const card = (0, requests_1.cardOf)(paths, d, ids);
160
+ waiting[card] = (waiting[card] ?? 0) + 1;
161
+ (lines[card] ??= []).push({ id: d.id, change: d.change ?? null, decision: d.decision, dimension: d.dimension, scope: d.scope, date: d.date });
162
+ }
163
+ const link = (0, hosted_1.readLinkOrNull)(paths);
164
+ return { board, comments: (0, comments_1.readComments)(paths), waiting, queued: lines, pending: queued.filter((d) => d.level !== 'polish').length, hosted: link?.shareUrl ?? null, version: link?.boardVersion ?? null, live: true, arrangement: (0, areas_1.readArrangement)(paths), settings: (0, settings_1.settingsOf)(paths), rulesFile: (0, store_1.rulesName)(paths), command: (0, store_1.arbiterCommand)(paths.root) };
165
+ }
166
+ /** What `/api/state` sends: the review queue. */
167
+ /** The last picture taken before `date`, when a newer one was taken since: the before to this decision's now. */
168
+ function beforeOf(all, date) {
169
+ const at = (s) => Date.parse(s);
170
+ if (all.length < 2 || at(all[all.length - 1].date) < at(date))
171
+ return null;
172
+ const earlier = all.filter((v) => at(v.date) < at(date));
173
+ const v = earlier[earlier.length - 1];
174
+ return v ? { src: `/snapshots/${v.file}`, date: v.date } : null;
175
+ }
176
+ /**
177
+ * What the files a waiting decision names say now, read again each time the inbox loads: each check that
178
+ * fails, for the card's Code Clash. Null when they match, or it names none. A fix made since clears it, and
179
+ * code broken since shows here instead of only when it's judged.
180
+ */
181
+ function codeClashOf(root, d) {
182
+ if (!(0, verify_1.checkable)(d.files ?? [], d.expect ?? null))
183
+ return null;
184
+ const failed = (0, verify_1.verify)(root, d.files ?? [], d.expect ?? null).checks.filter((c) => !c.ok);
185
+ return failed.length ? failed.map(({ ok: _ok, ...c }) => c) : null;
186
+ }
187
+ function reviewState(paths, agent) {
188
+ const candidates = (0, candidates_1.readCandidates)(paths);
189
+ const byId = new Map(candidates.map((c) => [c.id, c]));
190
+ const ids = new Set(byId.keys());
191
+ const active = (0, store_1.readActive)(paths);
192
+ // The card a decision is on: its picture, a screen's or a piece of work's.
193
+ const shotOf = (card) => {
194
+ if (card.startsWith('C-')) {
195
+ const c = byId.get(card);
196
+ return c?.snapshot ? `/snapshots/${c.snapshot}` : null;
197
+ }
198
+ const f = (0, work_1.workSnapshot)(paths, card);
199
+ return f ? `/snapshots/${node_path_1.default.basename(f)}` : null;
200
+ };
201
+ const pending = (0, store_1.readPending)(paths).map((d) => {
202
+ // The card it waits on, so a change marked Waiting can open the Review inbox at its work.
203
+ const card = (0, requests_1.cardOf)(paths, d, ids);
204
+ return {
205
+ ...d,
206
+ card,
207
+ // The rule a clash is with, while it's still in force: the page offers Keep as exception / Follow / Make this the rule. Its reason shows on hover.
208
+ againstRule: d.against ? active.filter((r) => r.id === d.against).map((r) => ({ id: r.id, decision: r.decision, rationale: r.rationale }))[0] ?? null : null,
209
+ codeClash: codeClashOf(paths.root, d),
210
+ candidateName: d.candidate ? byId.get(d.candidate)?.name ?? null : null,
211
+ // Its card's picture, so what changed is in view where it's judged.
212
+ snapshotUrl: shotOf(card),
213
+ // The picture from before this decision, when the work's picture was retaken after it was queued.
214
+ before: card.startsWith('W-') ? beforeOf((0, work_1.workVersions)(paths, card), d.date) : null,
215
+ picture: (0, pictures_1.missingPictures)(paths, [d], candidates)[0] ?? null,
216
+ };
217
+ });
218
+ return { project: node_path_1.default.basename(paths.root), pending, active: active.length, cap: (0, store_1.readConfig)(paths)?.activeCap ?? store_1.ACTIVE_CAP, agent };
219
+ }
package/dist/lock.js ADDED
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ /**
3
+ * One write at a time. The agent runs `arbiter record` in a terminal while you click on the board, and
4
+ * Claude Code may run several commands at once; each reads a file, changes it and writes it back, so
5
+ * two at the same moment would each write over the other (both say "queued P-0009", one is lost).
6
+ * Every write takes .arbiter/.lock first and lets it go when done; the next one waits its turn.
7
+ *
8
+ * And no half-written file: each is written beside itself and renamed into place, so a reader never
9
+ * sees one cut short, and a crash mid-write leaves the old one whole.
10
+ */
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.LOCK = void 0;
16
+ exports.withLock = withLock;
17
+ exports.withLockAsync = withLockAsync;
18
+ exports.writeAtomic = writeAtomic;
19
+ const node_fs_1 = __importDefault(require("node:fs"));
20
+ const node_path_1 = __importDefault(require("node:path"));
21
+ exports.LOCK = '.lock';
22
+ /**
23
+ * Older than any write takes, by far: left by a process that died holding it, so it's cleared. Age is
24
+ * the only sign trusted. Asking whether the holder is still running isn't: by the time the answer comes,
25
+ * it may have finished and another taken the lock, and clearing that one lets two writes in at once.
26
+ */
27
+ const STALE = 10_000;
28
+ /** How long a write waits its turn before it gives up and says why. */
29
+ const WAIT = 25_000;
30
+ /** Held by this process: a write inside another one (judging that records) doesn't wait on itself. */
31
+ let held = 0;
32
+ const pause = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
33
+ /** The lock, taken: waits while another process holds it, and clears one left by a process that died. */
34
+ function acquire(paths) {
35
+ node_fs_1.default.mkdirSync(paths.archiveDir, { recursive: true });
36
+ const file = node_path_1.default.join(paths.archiveDir, exports.LOCK);
37
+ const start = Date.now();
38
+ for (;;) {
39
+ try {
40
+ const fd = node_fs_1.default.openSync(file, 'wx');
41
+ node_fs_1.default.writeSync(fd, `${process.pid}\n`);
42
+ node_fs_1.default.closeSync(fd);
43
+ return;
44
+ }
45
+ catch (e) {
46
+ // EPERM, EACCES: Windows, while the last holder's file is still being deleted. Its turn is ending.
47
+ const code = e.code;
48
+ if (code !== 'EEXIST' && code !== 'EPERM' && code !== 'EACCES')
49
+ throw e;
50
+ }
51
+ try {
52
+ if (Date.now() - node_fs_1.default.statSync(file).mtimeMs > STALE) {
53
+ node_fs_1.default.rmSync(file, { force: true });
54
+ continue;
55
+ }
56
+ }
57
+ catch {
58
+ continue; // gone since: try again at once
59
+ }
60
+ if (Date.now() - start > WAIT) {
61
+ throw new Error(`another arbiter command has held .arbiter/${exports.LOCK} for ${Math.round(WAIT / 1000)}s. If none is running, delete that file and try again.`);
62
+ }
63
+ pause(15 + Math.random() * 20);
64
+ }
65
+ }
66
+ function release(paths) {
67
+ node_fs_1.default.rmSync(node_path_1.default.join(paths.archiveDir, exports.LOCK), { force: true });
68
+ }
69
+ /** `fn` as the only write to this project's record, start to finish. */
70
+ function withLock(paths, fn) {
71
+ if (held) {
72
+ held++;
73
+ try {
74
+ return fn();
75
+ }
76
+ finally {
77
+ held--;
78
+ }
79
+ }
80
+ acquire(paths);
81
+ held = 1;
82
+ try {
83
+ return fn();
84
+ }
85
+ finally {
86
+ held = 0;
87
+ release(paths);
88
+ }
89
+ }
90
+ /** The same for a write that awaits, like the board's: nothing else in this process writes meanwhile, as the caller sees to. */
91
+ async function withLockAsync(paths, fn) {
92
+ if (held) {
93
+ held++;
94
+ try {
95
+ return await fn();
96
+ }
97
+ finally {
98
+ held--;
99
+ }
100
+ }
101
+ acquire(paths);
102
+ held = 1;
103
+ try {
104
+ return await fn();
105
+ }
106
+ finally {
107
+ held = 0;
108
+ release(paths);
109
+ }
110
+ }
111
+ /**
112
+ * A whole file, written beside itself and renamed into place. Windows can refuse the rename for a moment
113
+ * while something else has the file open (an editor, a virus scan): it tries again, then writes in place.
114
+ */
115
+ function writeAtomic(file, text) {
116
+ const tmp = `${file}.${process.pid}.tmp`;
117
+ node_fs_1.default.writeFileSync(tmp, text);
118
+ for (let i = 0;; i++) {
119
+ try {
120
+ node_fs_1.default.renameSync(tmp, file);
121
+ return;
122
+ }
123
+ catch (e) {
124
+ const code = e.code;
125
+ if (i < 5 && (code === 'EPERM' || code === 'EACCES' || code === 'EBUSY')) {
126
+ pause(20 * (i + 1));
127
+ continue;
128
+ }
129
+ node_fs_1.default.rmSync(tmp, { force: true });
130
+ node_fs_1.default.writeFileSync(file, text);
131
+ return;
132
+ }
133
+ }
134
+ }
package/dist/overlap.js CHANGED
@@ -9,6 +9,8 @@
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.findOverlaps = findOverlaps;
12
+ exports.stem = stem;
13
+ exports.explainOverlaps = explainOverlaps;
12
14
  const schema_1 = require("./schema");
13
15
  const STOPWORDS = new Set(('a an the and or not never always no yes of in on at to for with by from as is are be use uses using than rather instead only its it this that these those all any one ' +
14
16
  // Generic UI nouns: shared by half of all decisions, so they say nothing about overlap.
@@ -69,3 +71,17 @@ function fileContains(a, b) {
69
71
  const norm = (p) => p.replace(/\\/g, '/').replace(/\/+$/, '');
70
72
  const narrower = (a, b) => (norm(a).length >= norm(b).length ? a : b);
71
73
  const wider = (a, b) => (norm(a).length >= norm(b).length ? b : a);
74
+ function explainOverlaps(entry, overlaps, active, changeNames) {
75
+ const changeOf = (d) => (d.candidate ? changeNames.get(d.candidate) : undefined) ?? d.trigger;
76
+ return overlaps.map((o) => {
77
+ if (o.confidence !== 'exact')
78
+ return { id: o.id, decision: o.decision, sure: false, words: asWritten(entry.decision, (o.reason.split('shares: ')[1] ?? '').split(', ').filter(Boolean)) };
79
+ const narrow = o.scope.length >= entry.scope.length ? (active.find((d) => d.id === o.id) ?? entry) : entry;
80
+ return { id: o.id, decision: o.decision, sure: true, scope: narrow.scope, ...(narrow.scope.startsWith('file:') ? { change: changeOf(narrow) } : {}), words: [] };
81
+ });
82
+ }
83
+ /** The shared words as the decision writes them, not as the overlap check trims them ("prices", not "pric"). */
84
+ function asWritten(text, stems) {
85
+ const words = text.toLowerCase().replace(/[^a-z0-9\s]/g, ' ').split(/\s+/).filter(Boolean);
86
+ return stems.map((s) => words.find((w) => stem(w) === s) ?? s);
87
+ }
package/dist/pictures.js CHANGED
@@ -16,6 +16,7 @@ exports.pictureHint = exports.needsPicture = void 0;
16
16
  exports.missingPictures = missingPictures;
17
17
  const candidates_1 = require("./candidates");
18
18
  const findings_1 = require("./findings");
19
+ const store_1 = require("./store");
19
20
  const work_1 = require("./work");
20
21
  const PICTURED = ['structure', 'content', 'visual'];
21
22
  /** Would a picture of one screen show this change, on a card the board will have? */
@@ -27,6 +28,9 @@ exports.needsPicture = needsPicture;
27
28
  * A rejected or replaced direction is gone from the app, so nothing asks for its picture.
28
29
  */
29
30
  function missingPictures(paths, decisions, candidates = (0, candidates_1.readCandidates)(paths)) {
31
+ // Pictures turned off in Settings: none is missing, so nothing asks for one.
32
+ if ((0, store_1.readConfig)(paths)?.pictures === false)
33
+ return [];
30
34
  const byId = new Map(candidates.map((c) => [c.id, c]));
31
35
  const out = new Map();
32
36
  for (const d of decisions) {
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ /**
3
+ * Settings, as the local board's Preferences page shows and saves them. They live in arbiter.json, beside
4
+ * the check-in answer, so everyone on the project shares them and the CLI reads them where it acts:
5
+ * `record --pending` keeps out what they say isn't recorded, pictures stop being asked for, and
6
+ * `areas` says when folder suggestions are off.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.MAX_CAP = void 0;
10
+ exports.settingsOf = settingsOf;
11
+ exports.saveSettings = saveSettings;
12
+ const store_1 = require("./store");
13
+ const setup_1 = require("./commands/setup");
14
+ /** The most rules DECISIONS.md can be set to hold: more is more for the agent to read before every change. */
15
+ exports.MAX_CAP = 100;
16
+ function settingsOf(paths, config = (0, store_1.readConfig)(paths)) {
17
+ return {
18
+ checkin: config?.checkin ?? 'feature',
19
+ record: config?.record?.level ?? 'pattern',
20
+ agentCalls: config?.record?.agent ?? true,
21
+ pictures: config?.pictures ?? true,
22
+ app: config?.app?.url ?? null,
23
+ suggestFolders: config?.suggestFolders ?? true,
24
+ cap: config?.activeCap ?? store_1.ACTIVE_CAP,
25
+ rules: (0, store_1.readActive)(paths).length,
26
+ };
27
+ }
28
+ const KEYS = ['checkin', 'record', 'agentCalls', 'pictures', 'app', 'suggestFolders', 'cap'];
29
+ /**
30
+ * One or more settings from the page, checked, then written to arbiter.json. A new cap also rewrites
31
+ * DECISIONS.md's header, which says how many it holds. Choosing a check-in here answers the question
32
+ * install asks, so the project counts as onboarded, as `setup --checkin` does.
33
+ */
34
+ function saveSettings(paths, raw) {
35
+ const config = (0, store_1.readConfig)(paths);
36
+ if (!config)
37
+ return { ok: false, errors: ['no arbiter.json here — run `npx arbiter init` first'] };
38
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
39
+ return { ok: false, errors: ['expected an object of settings'] };
40
+ const body = raw;
41
+ const errors = [];
42
+ const unknown = Object.keys(body).filter((k) => !KEYS.includes(k));
43
+ if (unknown.length)
44
+ errors.push(`not a setting: ${unknown.join(', ')}`);
45
+ const next = { ...config };
46
+ if ('checkin' in body) {
47
+ if (!setup_1.CHECKINS.includes(body.checkin))
48
+ errors.push(`checkin must be one of ${setup_1.CHECKINS.join(' | ')}`);
49
+ else {
50
+ next.checkin = body.checkin;
51
+ next.onboarded = config.onboarded ?? (0, store_1.now)();
52
+ }
53
+ }
54
+ if ('record' in body) {
55
+ if (body.record !== 'pattern' && body.record !== 'feature')
56
+ errors.push('record must be pattern (features and patterns) or feature (features only)');
57
+ else
58
+ next.record = { ...next.record, level: body.record };
59
+ }
60
+ if ('agentCalls' in body) {
61
+ if (typeof body.agentCalls !== 'boolean')
62
+ errors.push('agentCalls must be true or false');
63
+ else
64
+ next.record = { ...next.record, agent: body.agentCalls };
65
+ }
66
+ for (const k of ['pictures', 'suggestFolders']) {
67
+ if (!(k in body))
68
+ continue;
69
+ if (typeof body[k] !== 'boolean')
70
+ errors.push(`${k} must be true or false`);
71
+ else
72
+ next[k] = body[k];
73
+ }
74
+ let cap = null;
75
+ if ('cap' in body) {
76
+ const have = (0, store_1.readActive)(paths).length;
77
+ const n = body.cap;
78
+ if (typeof n !== 'number' || !Number.isInteger(n) || n < 1 || n > exports.MAX_CAP)
79
+ errors.push(`Design rules must be a whole number from 1 to ${exports.MAX_CAP}`);
80
+ else if (n < have)
81
+ errors.push(`${(0, store_1.rulesName)(paths)} has ${have} rules, so it can't hold fewer. Remove some first.`);
82
+ else
83
+ cap = next.activeCap = n;
84
+ }
85
+ if ('app' in body) {
86
+ const text = typeof body.app === 'string' ? body.app.trim() : null;
87
+ if (text === null)
88
+ errors.push('app must be an address, or empty');
89
+ else if (!text)
90
+ delete next.app;
91
+ else {
92
+ const url = (0, setup_1.appUrl)(text);
93
+ if (url === 'credentials')
94
+ errors.push('Leave the username and password out: arbiter.json is committed');
95
+ else if (!url)
96
+ errors.push('Give the address the app runs at, like http://localhost:3000');
97
+ else
98
+ next.app = { url };
99
+ }
100
+ }
101
+ if (errors.length)
102
+ return { ok: false, errors };
103
+ (0, store_1.writeConfig)(paths, next);
104
+ if (cap !== null)
105
+ (0, store_1.writeActive)(paths, (0, store_1.readActive)(paths), cap);
106
+ return { ok: true, settings: settingsOf(paths, next) };
107
+ }