arbiterdesign 0.1.7 → 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 +38 -40
- package/dist/area-names.js +120 -0
- package/dist/areas.js +131 -0
- package/dist/board-types.js +9 -0
- package/dist/candidates.js +7 -1
- package/dist/commands/areas.js +153 -0
- package/dist/commands/candidate.js +4 -2
- package/dist/commands/decision.js +100 -0
- package/dist/commands/export.js +88 -125
- package/dist/commands/init.js +89 -2
- package/dist/commands/prompt.js +12 -4
- package/dist/commands/publish.js +18 -1
- package/dist/commands/record.js +152 -3
- package/dist/commands/rename.js +123 -0
- package/dist/commands/review.js +469 -76
- package/dist/commands/rules.js +8 -1
- package/dist/commands/setup.js +1 -0
- package/dist/commands/snapshot.js +24 -2
- package/dist/commands/sweep.js +1 -1
- package/dist/commands/unpublish.js +88 -0
- package/dist/comments.js +24 -0
- package/dist/handoff.js +283 -0
- package/dist/hook.js +80 -0
- package/dist/hosted.js +117 -20
- package/dist/index.js +93 -24
- package/dist/localboard.js +219 -0
- package/dist/lock.js +134 -0
- package/dist/overlap.js +16 -0
- package/dist/pictures.js +4 -0
- package/dist/settings.js +107 -0
- package/dist/store.js +6 -5
- package/dist/verify.js +4 -2
- package/dist/wording.js +65 -0
- package/dist/work.js +139 -1
- package/package.json +3 -2
- package/templates/SKILL.md +169 -50
- package/templates/board/board.css +2 -0
- package/templates/board/board.js +25 -0
- package/templates/board/index.html +15 -0
- package/templates/fonts/Geist-Variable.woff2 +0 -0
- package/templates/fonts/GeistMono-Variable.woff2 +0 -0
- package/templates/fonts/OFL.txt +92 -0
- package/templates/hooks/arbiter-board.cjs +50 -0
- package/templates/review.html +0 -600
|
@@ -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) };
|
|
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) {
|
package/dist/settings.js
ADDED
|
@@ -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(`DECISIONS.md 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
|
+
}
|
package/dist/store.js
CHANGED
|
@@ -30,6 +30,7 @@ const node_os_1 = __importDefault(require("node:os"));
|
|
|
30
30
|
const node_path_1 = __importDefault(require("node:path"));
|
|
31
31
|
const node_child_process_1 = require("node:child_process");
|
|
32
32
|
const format_1 = require("./format");
|
|
33
|
+
const lock_1 = require("./lock");
|
|
33
34
|
exports.ACTIVE_CAP = 40;
|
|
34
35
|
function resolvePaths(root = process.cwd()) {
|
|
35
36
|
return {
|
|
@@ -59,7 +60,7 @@ function readConfig(paths) {
|
|
|
59
60
|
return JSON.parse(node_fs_1.default.readFileSync(paths.config, 'utf8'));
|
|
60
61
|
}
|
|
61
62
|
function writeConfig(paths, config) {
|
|
62
|
-
|
|
63
|
+
(0, lock_1.writeAtomic)(paths.config, JSON.stringify(config, null, 2) + '\n');
|
|
63
64
|
}
|
|
64
65
|
function readActive(paths) {
|
|
65
66
|
if (!node_fs_1.default.existsSync(paths.decisions))
|
|
@@ -68,7 +69,7 @@ function readActive(paths) {
|
|
|
68
69
|
}
|
|
69
70
|
/** Rewrites DECISIONS.md in full. Entries are re-serialized, so hand edits survive. */
|
|
70
71
|
function writeActive(paths, decisions, cap = exports.ACTIVE_CAP) {
|
|
71
|
-
|
|
72
|
+
(0, lock_1.writeAtomic)(paths.decisions, (0, format_1.activeHeader)(decisions.length, cap) + '\n' + (0, format_1.formatGrouped)(decisions));
|
|
72
73
|
}
|
|
73
74
|
function readArchive(paths) {
|
|
74
75
|
if (!node_fs_1.default.existsSync(paths.archive))
|
|
@@ -83,13 +84,13 @@ function appendArchive(paths, d) {
|
|
|
83
84
|
node_fs_1.default.appendFileSync(paths.archive, prefix + (0, format_1.formatEntry)(d));
|
|
84
85
|
}
|
|
85
86
|
/**
|
|
86
|
-
* Rewrites the archive in full. Only `remove` and `
|
|
87
|
+
* Rewrites the archive in full. Only `remove`, `unlink` and `rename` use this: the archive is append-only
|
|
87
88
|
* for judgments — a decision you changed your mind about is superseded, never rewritten — but a
|
|
88
89
|
* record of something that never happened is noise, not history, and has to be able to leave.
|
|
89
90
|
*/
|
|
90
91
|
function writeArchive(paths, decisions) {
|
|
91
92
|
node_fs_1.default.mkdirSync(paths.archiveDir, { recursive: true });
|
|
92
|
-
|
|
93
|
+
(0, lock_1.writeAtomic)(paths.archive, (0, format_1.archiveHeader)() + '\n' + decisions.map(format_1.formatEntry).join('\n'));
|
|
93
94
|
}
|
|
94
95
|
function readPending(paths) {
|
|
95
96
|
if (!node_fs_1.default.existsSync(paths.pending))
|
|
@@ -99,7 +100,7 @@ function readPending(paths) {
|
|
|
99
100
|
/** Rewrites pending.md in full. */
|
|
100
101
|
function writePending(paths, decisions) {
|
|
101
102
|
node_fs_1.default.mkdirSync(paths.archiveDir, { recursive: true });
|
|
102
|
-
|
|
103
|
+
(0, lock_1.writeAtomic)(paths.pending, (0, format_1.pendingHeader)() + '\n' + decisions.map(format_1.formatEntry).join('\n'));
|
|
103
104
|
}
|
|
104
105
|
/** Next P- id. Pending ids are never reused within the file but may repeat once it empties. */
|
|
105
106
|
function nextPendingId(pending) {
|
package/dist/verify.js
CHANGED
|
@@ -49,8 +49,10 @@ function verify(root, files, expect) {
|
|
|
49
49
|
for (const needle of expect?.absent ?? []) {
|
|
50
50
|
for (const [f, text] of contents) {
|
|
51
51
|
const line = lineOf(text, needle);
|
|
52
|
-
if (line
|
|
53
|
-
|
|
52
|
+
if (line === null)
|
|
53
|
+
continue;
|
|
54
|
+
const found = needle.startsWith('regex:') ? new RegExp(needle.slice(6)).exec(text)?.[0] : undefined;
|
|
55
|
+
checks.push({ kind: 'absent', file: f, needle, ok: false, detail: `found at line ${line}`, ...(found !== undefined && { found }) });
|
|
54
56
|
}
|
|
55
57
|
if (!checks.some((c) => c.kind === 'absent' && c.needle === needle && !c.ok)) {
|
|
56
58
|
checks.push({ kind: 'absent', file: files.join(', '), needle, ok: true });
|
package/dist/wording.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The people judging are PMs and designers. They read a decision in the review, on the board and
|
|
4
|
+
* in DECISIONS.md, never next to the code, so a line written in code words gets misread or
|
|
5
|
+
* skipped. `record` refuses one, and the agent says it again in plain words before anyone sees it.
|
|
6
|
+
*
|
|
7
|
+
* Only what is surely code is caught: a file name, a class name, a name stuck together like
|
|
8
|
+
* onClick or ArrowUpRight, backticks. A product name (Next.js, iPhone, GitHub) or a size a
|
|
9
|
+
* designer would say (16px) passes. Two-part names like TagPill do too, since they can't be told
|
|
10
|
+
* apart from brands like FigJam; the skill's examples cover those.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.MAX_WORDS = void 0;
|
|
14
|
+
exports.codeWords = codeWords;
|
|
15
|
+
exports.unclearLines = unclearLines;
|
|
16
|
+
/** Words in one line. The skill asks for 20 or fewer; this is where it stops being one thing. */
|
|
17
|
+
exports.MAX_WORDS = 25;
|
|
18
|
+
const SIZE = String.raw `(?:\d+(?:\.\d+)?|px|xs|sm|base|md|lg|xl|[2-9]xl|full|screen|auto|none)`;
|
|
19
|
+
const UTILITY = String.raw `(?:text|bg|border|rounded|shadow|font|leading|tracking|gap|space|ring|opacity|grid-cols|col-span|row-span|basis|w|h|size|min-w|max-w|min-h|max-h|p|px|py|pt|pb|pl|pr|m|mx|my|mt|mb|ml|mr|z|inset)`;
|
|
20
|
+
const CODE = [
|
|
21
|
+
/`[^`]*`?/g,
|
|
22
|
+
// A path, a source file, or a lowercase .js/.md file (Next.js is a product; next.config.js is a file).
|
|
23
|
+
/\b[\w.-]*\/[\w./-]*\.[a-z]{2,5}\b|\b[\w-]+\.(?:tsx|jsx|ts|css|scss|vue|svelte|json|html|py|rb|swift|kt)\b|\b[a-z][\w-]*\.(?:js|mjs|md)\b/g,
|
|
24
|
+
// onClick, useState: lowercase then humps. iPhone and macOS aren't.
|
|
25
|
+
/\b[a-z]{2,}(?:[A-Z][a-z0-9]+)+\b/g,
|
|
26
|
+
// ArrowUpRight: three humps or more.
|
|
27
|
+
/\b[A-Z][a-z]+(?:[A-Z][a-z]+){2,}\b/g,
|
|
28
|
+
// Utility classes with a size or a shade: text-xs, w-24, gap-x-2, md:grid-cols-3, bg-ink-500.
|
|
29
|
+
new RegExp(String.raw `\b(?:(?:sm|md|lg|xl|2xl):)?${UTILITY}(?:-[xy])?-(?:${SIZE}|[a-z]+-\d{2,3})\b|\b(?:sm|md|lg|xl|2xl):[a-z][\w-]*|\bfont-(?:light|normal|medium|semibold|bold|sans|serif|mono)\b`, 'g'),
|
|
30
|
+
/\baria-[a-z]+/g,
|
|
31
|
+
/<\/?[a-z][a-z0-9-]*[\s/>]|=>|[{}]|\b\w+\(\)/g,
|
|
32
|
+
/\b(?:fg|bg|div|props|href|z-index|boolean|enum|regex)\b|\b\d+(?:\.\d+)?fr\b/g,
|
|
33
|
+
];
|
|
34
|
+
/** What reads like code in a line, as written, at most three. */
|
|
35
|
+
function codeWords(text) {
|
|
36
|
+
const found = new Set();
|
|
37
|
+
for (const re of CODE)
|
|
38
|
+
for (const m of text.matchAll(re))
|
|
39
|
+
found.add(m[0].trim());
|
|
40
|
+
return [...found].filter(Boolean).slice(0, 3);
|
|
41
|
+
}
|
|
42
|
+
const words = (text) => text.trim().split(/\s+/).filter(Boolean).length;
|
|
43
|
+
/**
|
|
44
|
+
* Problems with the lines a person reads: Change, Pattern and each Rejected. A mechanical rule's
|
|
45
|
+
* `decision` may name a token, since that's what its check looks for; its `change` still can't.
|
|
46
|
+
*/
|
|
47
|
+
function unclearLines(input) {
|
|
48
|
+
const lines = [
|
|
49
|
+
...(input.change ? [['change', input.change]] : []),
|
|
50
|
+
['decision', input.decision],
|
|
51
|
+
...(input.rejected ?? []).map((r, i) => [`rejected[${i}]`, r]),
|
|
52
|
+
];
|
|
53
|
+
const problems = [];
|
|
54
|
+
for (const [field, text] of lines) {
|
|
55
|
+
const n = words(text);
|
|
56
|
+
if (n > exports.MAX_WORDS)
|
|
57
|
+
problems.push(`${field} is ${n} words, over ${exports.MAX_WORDS}: say one thing, what a person sees or does`);
|
|
58
|
+
if (field === 'decision' && input.class === 'mechanical')
|
|
59
|
+
continue;
|
|
60
|
+
const code = codeWords(text);
|
|
61
|
+
if (code.length)
|
|
62
|
+
problems.push(`${field} reads like code (${code.map((c) => `"${c}"`).join(', ')}): say it the way it looks on screen`);
|
|
63
|
+
}
|
|
64
|
+
return problems;
|
|
65
|
+
}
|