arbiterdesign 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const node_test_1 = require("node:test");
7
+ const strict_1 = __importDefault(require("node:assert/strict"));
8
+ const node_fs_1 = __importDefault(require("node:fs"));
9
+ const node_os_1 = __importDefault(require("node:os"));
10
+ const node_path_1 = __importDefault(require("node:path"));
11
+ const node_http_1 = __importDefault(require("node:http"));
12
+ const record_1 = require("../commands/record");
13
+ const candidate_1 = require("../commands/candidate");
14
+ const review_1 = require("../commands/review");
15
+ const drift_1 = require("../commands/drift");
16
+ const rules_1 = require("../commands/rules");
17
+ const store_1 = require("../store");
18
+ const verify_1 = require("../verify");
19
+ const candidates_1 = require("../candidates");
20
+ const tmp = () => node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'arbiter-polish-'));
21
+ const write = (cwd, rel, text) => { node_fs_1.default.mkdirSync(node_path_1.default.join(cwd, node_path_1.default.dirname(rel)), { recursive: true }); node_fs_1.default.writeFileSync(node_path_1.default.join(cwd, rel), text); };
22
+ const rule = (over = {}) => JSON.stringify({ decision: 'Modals for destructive actions', rationale: 'r', trigger: 't', scope: 'pattern:destructive', dimension: 'interaction', class: 'judgment', verdict: 'rule', ...over });
23
+ (0, node_test_1.test)('retire drops a rule with no replacement; archive keeps both; status reads retired', () => {
24
+ const cwd = tmp();
25
+ const o = { cwd, author: 'test' };
26
+ (0, record_1.record)(rule(), o);
27
+ strict_1.default.equal((0, record_1.retire)('D-0001', undefined, o).exitCode, 1, 'why is required');
28
+ strict_1.default.equal((0, record_1.retire)('D-0009', 'x', o).exitCode, 1, 'must be active');
29
+ const r = (0, record_1.retire)('D-0001', 'Component library handles it now', o);
30
+ strict_1.default.equal(r.exitCode, 0);
31
+ strict_1.default.equal(r.output.verdict, 'retire');
32
+ strict_1.default.equal(r.output.supersedes, 'D-0001');
33
+ const p = (0, store_1.resolvePaths)(cwd);
34
+ strict_1.default.equal((0, store_1.readActive)(p).length, 0);
35
+ strict_1.default.equal((0, store_1.readArchive)(p).length, 2);
36
+ strict_1.default.ok((0, rules_1.rules)('D-0001', { cwd }).includes('retired by D-0002'));
37
+ strict_1.default.ok((0, rules_1.rules)(undefined, { cwd, archive: true }).includes('retired by D-0002'));
38
+ strict_1.default.equal((0, record_1.retire)('D-0001', 'again', o).exitCode, 1, 'cannot retire twice');
39
+ });
40
+ (0, node_test_1.test)('regex: needles work in verify and sweep', () => {
41
+ const cwd = tmp();
42
+ write(cwd, 'a.css', 'color: #3b7be0;');
43
+ const r = (0, verify_1.verify)(cwd, ['a.css'], { absent: ['regex:#[0-9a-fA-F]{6}\\b'] });
44
+ strict_1.default.equal(r.ok, false);
45
+ strict_1.default.ok((0, verify_1.verify)(cwd, ['a.css'], { present: ['regex:color:\\s*#'] }).ok);
46
+ const rec = (0, record_1.record)(rule({ class: 'mechanical', dimension: 'visual', scope: 'global', expect: { absent: ['regex:#[0-9a-fA-F]{6}\\b'] } }), { cwd, author: 'test' });
47
+ strict_1.default.equal(rec.output.sweep.violations, 1);
48
+ });
49
+ (0, node_test_1.test)('drift counts accepts and rule breaks per screen', () => {
50
+ const cwd = tmp();
51
+ const o = { cwd, author: 'test' };
52
+ write(cwd, 'src/Badge.tsx', '"#3B7BE0"');
53
+ write(cwd, 'src/Card.tsx', 'brand-500');
54
+ (0, record_1.record)(rule({ class: 'mechanical', dimension: 'visual', scope: 'global', expect: { absent: ['#3B7BE0'] }, files: ['src/Card.tsx'] }), o);
55
+ (0, candidate_1.addCandidate)('Billing', { ...o, feature: 'billing' });
56
+ (0, record_1.record)(rule({ verdict: 'accept', class: 'mechanical', dimension: 'visual', scope: 'file:src/Badge.tsx', files: ['src/Badge.tsx'] }), { ...o, candidate: 'C-0001' });
57
+ const j = JSON.parse((0, drift_1.drift)({ cwd, json: true }));
58
+ strict_1.default.equal(j.screens[0].accepts, 1);
59
+ strict_1.default.deepEqual(j.screens[0].broken.map((b) => b.id), ['D-0001']);
60
+ strict_1.default.ok((0, drift_1.drift)({ cwd }).includes('1 rule broken'));
61
+ });
62
+ (0, node_test_1.test)('review page serves candidates, snapshots, and candidate actions', async () => {
63
+ const cwd = tmp();
64
+ const o = { cwd, author: 'test' };
65
+ write(cwd, 'shot.svg', '<svg xmlns="http://www.w3.org/2000/svg"/>');
66
+ (0, candidate_1.addCandidate)('A', { ...o, feature: 'f', snapshot: 'shot.svg' });
67
+ (0, candidate_1.addCandidate)('B', { ...o, feature: 'f' });
68
+ (0, record_1.queue)(rule(), { ...o, candidate: 'C-0001' });
69
+ const port = 48000 + Math.floor(Math.random() * 1000);
70
+ const done = (0, review_1.review)({ cwd, port, open: false });
71
+ await new Promise((r) => setTimeout(r, 200));
72
+ const state = await get(port, '/api/state');
73
+ strict_1.default.equal(state.candidates.length, 2);
74
+ strict_1.default.equal(state.pending[0].snapshotUrl, '/snapshots/C-0001.svg');
75
+ strict_1.default.equal(state.pending[0].candidateName, 'A');
76
+ strict_1.default.equal((await getRaw(port, '/snapshots/C-0001.svg')).status, 200);
77
+ strict_1.default.equal((await getRaw(port, '/snapshots/../arbiter.json')).status, 404);
78
+ const up = await post(port, '/api/candidate', { id: 'C-0001', state: 'approved', why: 'because' });
79
+ strict_1.default.equal(up.exitCode, 0);
80
+ strict_1.default.deepEqual(up.superseded, ['C-0002']);
81
+ strict_1.default.equal((0, candidates_1.readCandidates)((0, store_1.resolvePaths)(cwd))[1].reason, 'because');
82
+ await post(port, '/api/done', {});
83
+ await done;
84
+ });
85
+ function getRaw(port, p) {
86
+ return new Promise((resolve, reject) => {
87
+ node_http_1.default.get({ host: '127.0.0.1', port, path: p }, (res) => { res.resume(); res.on('end', () => resolve({ status: res.statusCode })); }).on('error', reject);
88
+ });
89
+ }
90
+ function get(port, p) {
91
+ return new Promise((resolve, reject) => {
92
+ node_http_1.default.get({ host: '127.0.0.1', port, path: p }, (res) => { let d = ''; res.on('data', (c) => (d += c)); res.on('end', () => resolve(JSON.parse(d))); }).on('error', reject);
93
+ });
94
+ }
95
+ function post(port, p, body) {
96
+ return new Promise((resolve, reject) => {
97
+ const req = node_http_1.default.request({ host: '127.0.0.1', port, path: p, method: 'POST', headers: { 'content-type': 'application/json' } }, (res) => { let d = ''; res.on('data', (c) => (d += c)); res.on('end', () => resolve(JSON.parse(d))); });
98
+ req.on('error', reject);
99
+ req.end(JSON.stringify(body));
100
+ });
101
+ }
102
+ (0, node_test_1.test)('export writes a self-contained folder: index.html, snapshots, stakeholder view only', () => {
103
+ const cwd = tmp();
104
+ const o = { cwd, author: 'test' };
105
+ write(cwd, 'shot.svg', '<svg xmlns="http://www.w3.org/2000/svg"/>');
106
+ (0, candidate_1.addCandidate)('Settings — single <page>', { ...o, feature: 'settings', snapshot: 'shot.svg' });
107
+ (0, candidate_1.addCandidate)('Settings — tabs', { ...o, feature: 'settings' });
108
+ (0, candidate_1.addCandidate)('Billing', { ...o, feature: 'billing' });
109
+ (0, record_1.record)(rule({ change: 'Danger zone is at the bottom', decision: 'Destructive settings live last', rejected: ['Tabs — hid it'] }), { ...o, candidate: 'C-0001' });
110
+ (0, record_1.record)(rule({ decision: 'h-9', level: 'polish', scope: 'file:x', verdict: 'accept' }), { ...o, candidate: 'C-0001' });
111
+ (0, record_1.queue)(rule({ decision: 'Pending thing', scope: 'pattern:pending' }), { ...o, candidate: 'C-0001' });
112
+ (0, candidate_1.updateCandidate)('C-0001', { ...o, state: 'approved', why: 'tabs hid it' });
113
+ const { exportBoard } = require('../commands/export');
114
+ const r = exportBoard({ cwd, includeRules: true });
115
+ strict_1.default.equal(r.candidates, 3);
116
+ strict_1.default.equal(r.snapshots, 1);
117
+ const html = node_fs_1.default.readFileSync(r.index, 'utf8');
118
+ strict_1.default.ok(node_fs_1.default.existsSync(node_path_1.default.join(r.dir, 'snapshots', 'C-0001.svg')));
119
+ strict_1.default.ok(html.includes('Settings — single &lt;page&gt;'), 'escaped');
120
+ strict_1.default.ok(html.includes('Superseded by Settings — single &lt;page&gt;'));
121
+ strict_1.default.ok(html.includes('Danger zone is at the bottom'), 'Change text, not rule text');
122
+ strict_1.default.ok(html.includes('over Tabs'));
123
+ strict_1.default.ok(!html.includes('h-9'), 'polish omitted');
124
+ strict_1.default.ok(!html.includes('Pending thing'), 'pending omitted');
125
+ strict_1.default.ok(html.includes('Standing rules'));
126
+ strict_1.default.ok(!html.includes('Make it a rule'), 'no verdict controls');
127
+ const one = exportBoard({ cwd, feature: 'billing', out: 'out-billing' });
128
+ strict_1.default.equal(one.candidates, 1);
129
+ strict_1.default.ok(!node_fs_1.default.readFileSync(one.index, 'utf8').includes('Settings'));
130
+ });
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const node_test_1 = require("node:test");
7
+ const strict_1 = __importDefault(require("node:assert/strict"));
8
+ const node_fs_1 = __importDefault(require("node:fs"));
9
+ const node_os_1 = __importDefault(require("node:os"));
10
+ const node_path_1 = __importDefault(require("node:path"));
11
+ const record_1 = require("../commands/record");
12
+ const format_1 = require("../format");
13
+ const store_1 = require("../store");
14
+ const rule = (over = {}) => JSON.stringify({
15
+ decision: 'Destructive actions confirm in a modal, never inline',
16
+ rationale: 'Inline confirms get clicked through.',
17
+ trigger: 'Delete flow used an inline link',
18
+ scope: 'pattern:destructive-confirm',
19
+ class: 'judgment',
20
+ dimension: 'interaction',
21
+ verdict: 'rule',
22
+ ...over,
23
+ });
24
+ const tmp = () => node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'arbiter-'));
25
+ const opts = (cwd, extra = {}) => ({ cwd, author: 'test', ...extra });
26
+ (0, node_test_1.test)('format round-trips losslessly', () => {
27
+ const d = {
28
+ id: 'D-0001', date: '2026-09-15T10:00:00Z', author: 'Edmond Hua', class: 'judgment', dimension: 'interaction',
29
+ rejected: ['Inline confirm — clicked through', 'Toast with undo — too easy to miss · and this has a dot'],
30
+ decision: 'Use · dots · freely in the statement', trigger: 'A "quoted" trigger: with colons',
31
+ change: 'The confirm · link became a modal', level: 'feature',
32
+ verdict: 'rule', scope: 'file:src/a b/c.tsx', rationale: 'Because **bold** and `code` should survive.',
33
+ supersedes: null, ref: 'https://linear.app/acme/issue/ENG-123', commit: null,
34
+ files: ['src/a b/c.tsx', 'src/d.tsx'], paths: ['src/components', 'src/marketing/Hero.tsx'], expect: { present: ['brand.500'], absent: ['#3B7BE0', 'weird · dot'] }, verified: true, candidate: 'C-0002',
35
+ };
36
+ strict_1.default.deepEqual((0, format_1.parseEntries)((0, format_1.formatEntry)(d)), [d]);
37
+ const d2 = { ...d, id: 'D-0002', supersedes: 'D-0001', commit: 'abc1234', rejected: [], dimension: 'states', ref: null, files: [], paths: [], expect: null, verified: null, candidate: null };
38
+ strict_1.default.deepEqual((0, format_1.parseEntries)((0, format_1.formatEntry)(d) + '\n' + (0, format_1.formatEntry)(d2)), [d, d2]);
39
+ });
40
+ (0, node_test_1.test)('rule goes to both files; accept and fix go to archive only', () => {
41
+ const cwd = tmp();
42
+ strict_1.default.equal((0, record_1.record)(rule(), opts(cwd)).exitCode, 0);
43
+ strict_1.default.equal((0, record_1.record)(rule({ verdict: 'accept', scope: 'file:x.tsx' }), opts(cwd)).exitCode, 0);
44
+ strict_1.default.equal((0, record_1.record)(rule({ verdict: 'fix', scope: 'file:y.tsx' }), opts(cwd)).exitCode, 0);
45
+ const p = (0, store_1.resolvePaths)(cwd);
46
+ strict_1.default.equal((0, store_1.readActive)(p).length, 1);
47
+ strict_1.default.equal((0, store_1.readArchive)(p).length, 3);
48
+ strict_1.default.deepEqual((0, store_1.readArchive)(p).map((d) => d.id), ['D-0001', 'D-0002', 'D-0003']);
49
+ });
50
+ (0, node_test_1.test)('overlap blocks the write and offers supersedes', () => {
51
+ const cwd = tmp();
52
+ (0, record_1.record)(rule(), opts(cwd));
53
+ const r = (0, record_1.record)(rule({ decision: 'Destructive confirms name the thing being deleted' }), opts(cwd));
54
+ strict_1.default.equal(r.exitCode, 2);
55
+ const overlaps = r.output.overlaps;
56
+ strict_1.default.deepEqual(overlaps.map((o) => [o.id, o.confidence]), [['D-0001', 'exact']]);
57
+ strict_1.default.equal((0, store_1.readArchive)((0, store_1.resolvePaths)(cwd)).length, 1, 'nothing written');
58
+ const r2 = (0, record_1.record)(rule({ decision: 'Destructive confirms name the thing being deleted' }), opts(cwd, { supersedes: 'D-0001' }));
59
+ strict_1.default.equal(r2.exitCode, 0);
60
+ const active = (0, store_1.readActive)((0, store_1.resolvePaths)(cwd));
61
+ strict_1.default.deepEqual(active.map((d) => [d.id, d.supersedes]), [['D-0002', 'D-0001']]);
62
+ strict_1.default.equal((0, store_1.readArchive)((0, store_1.resolvePaths)(cwd)).length, 2, 'old rule stays in archive');
63
+ });
64
+ (0, node_test_1.test)('fuzzy overlap is marked possible; --keep-both bypasses', () => {
65
+ const cwd = tmp();
66
+ (0, record_1.record)(rule({ decision: 'Interactive elements use brand tokens, never raw hex', scope: 'global' }), opts(cwd));
67
+ const r = (0, record_1.record)(rule({ decision: 'Text colours come from tokens, not raw hex', scope: 'global' }), opts(cwd));
68
+ strict_1.default.equal(r.exitCode, 2);
69
+ strict_1.default.equal(r.output.overlaps[0].confidence, 'possible');
70
+ strict_1.default.equal((0, record_1.record)(rule({ decision: 'Text colours come from tokens, not raw hex', scope: 'global' }), opts(cwd, { keepBoth: true })).exitCode, 0);
71
+ strict_1.default.equal((0, store_1.readActive)((0, store_1.resolvePaths)(cwd)).length, 2);
72
+ });
73
+ (0, node_test_1.test)('cap refuses the 41st rule', () => {
74
+ const cwd = tmp();
75
+ for (let i = 0; i < 40; i++) {
76
+ strict_1.default.equal((0, record_1.record)(rule({ decision: `Rule number ${i} about widget${i}`, scope: `pattern:p${i}` }), opts(cwd, { keepBoth: true })).exitCode, 0, `rule ${i}`);
77
+ }
78
+ const r = (0, record_1.record)(rule({ decision: 'One too many', scope: 'pattern:extra' }), opts(cwd));
79
+ strict_1.default.equal(r.exitCode, 3);
80
+ strict_1.default.equal((0, store_1.readActive)((0, store_1.resolvePaths)(cwd)).length, 40);
81
+ });
82
+ (0, node_test_1.test)('invalid input is rejected with field-level errors', () => {
83
+ const r = (0, record_1.record)('{"decision":"x","verdict":"maybe"}', opts(tmp()));
84
+ strict_1.default.equal(r.exitCode, 1);
85
+ strict_1.default.ok(r.output.errors.some((e) => e.includes('verdict')));
86
+ strict_1.default.equal((0, record_1.record)('not json', opts(tmp())).exitCode, 1);
87
+ });
88
+ (0, node_test_1.test)('DECISIONS.md groups by dimension and still round-trips', () => {
89
+ const cwd = tmp();
90
+ (0, record_1.record)(rule({ decision: 'Modal for destructive confirms', dimension: 'interaction', scope: 'pattern:destructive-confirm', rejected: ['Inline confirm — clicked through'] }), opts(cwd));
91
+ (0, record_1.record)(rule({ decision: 'Empty states are one line and one action', dimension: 'states', scope: 'pattern:empty-state' }), opts(cwd));
92
+ (0, record_1.record)(rule({ decision: 'Page titles are sentence case', dimension: 'content', scope: 'global' }), opts(cwd));
93
+ (0, record_1.record)(rule({ decision: 'Sheets put primary action bottom-right', dimension: 'interaction', scope: 'pattern:sheet-actions' }), opts(cwd));
94
+ const p = (0, store_1.resolvePaths)(cwd);
95
+ const md = node_fs_1.default.readFileSync(p.decisions, 'utf8');
96
+ const headings = md.split('\n').filter((l) => /^## /.test(l));
97
+ strict_1.default.deepEqual(headings, ['## Interaction', '## States', '## Content']);
98
+ const active = (0, store_1.readActive)(p);
99
+ strict_1.default.deepEqual(active.map((d) => d.id), ['D-0001', 'D-0004', 'D-0002', 'D-0003']);
100
+ strict_1.default.deepEqual(active[0].rejected, ['Inline confirm — clicked through']);
101
+ strict_1.default.deepEqual((0, store_1.readArchive)(p).map((d) => d.id), ['D-0001', 'D-0002', 'D-0003', 'D-0004']);
102
+ });
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const node_test_1 = require("node:test");
7
+ const strict_1 = __importDefault(require("node:assert/strict"));
8
+ const node_fs_1 = __importDefault(require("node:fs"));
9
+ const node_os_1 = __importDefault(require("node:os"));
10
+ const node_path_1 = __importDefault(require("node:path"));
11
+ const node_child_process_1 = require("node:child_process");
12
+ const record_1 = require("../commands/record");
13
+ const sweep_1 = require("../commands/sweep");
14
+ const verify_1 = require("../commands/verify");
15
+ const candidate_1 = require("../commands/candidate");
16
+ const board_1 = require("../commands/board");
17
+ const candidates_1 = require("../candidates");
18
+ const store_1 = require("../store");
19
+ const findings_1 = require("../findings");
20
+ const tmp = () => node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'arbiter-stages-'));
21
+ const write = (cwd, rel, text) => {
22
+ node_fs_1.default.mkdirSync(node_path_1.default.join(cwd, node_path_1.default.dirname(rel)), { recursive: true });
23
+ node_fs_1.default.writeFileSync(node_path_1.default.join(cwd, rel), text);
24
+ };
25
+ const mech = (over = {}) => JSON.stringify({
26
+ decision: 'Interactive elements use brand tokens, never raw hex',
27
+ rationale: 'Raw hex drifts.',
28
+ trigger: 'Button build',
29
+ scope: 'global',
30
+ dimension: 'visual',
31
+ class: 'mechanical',
32
+ verdict: 'rule',
33
+ files: ['src/Button.tsx'],
34
+ expect: { present: ['brand-500'], absent: ['#3B7BE0'] },
35
+ ...over,
36
+ });
37
+ (0, node_test_1.test)('stage 2: contradicted claims are refused; verified once true', () => {
38
+ const cwd = tmp();
39
+ const o = { cwd, author: 'test' };
40
+ write(cwd, 'src/Button.tsx', 'const c = "#3B7BE0";');
41
+ const r = (0, record_1.record)(mech(), o);
42
+ strict_1.default.equal(r.exitCode, 4);
43
+ strict_1.default.equal((0, store_1.readArchive)((0, store_1.resolvePaths)(cwd)).length, 0);
44
+ strict_1.default.equal(r.output.failed.length, 2);
45
+ strict_1.default.equal((0, record_1.record)(mech(), { ...o, unverified: true }).exitCode, 0, '--unverified records anyway');
46
+ strict_1.default.equal((0, store_1.readActive)((0, store_1.resolvePaths)(cwd))[0].verified, false);
47
+ write(cwd, 'src/Button.tsx', 'const c = "brand-500";');
48
+ const ok = (0, record_1.record)(mech({ scope: 'pattern:buttons' }), { ...o, keepBoth: true });
49
+ strict_1.default.equal(ok.exitCode, 0);
50
+ strict_1.default.equal(ok.output.verified, true);
51
+ strict_1.default.equal((0, verify_1.verifyCommand)(undefined, { cwd }).ok, true, 'both rules hold now the file is fixed');
52
+ write(cwd, 'src/Button.tsx', 'const c = "#3B7BE0"; // regressed');
53
+ strict_1.default.equal((0, verify_1.verifyCommand)(undefined, { cwd }).ok, false, 're-check catches a regression');
54
+ });
55
+ (0, node_test_1.test)('stage 2: accept is never verified; fix is', () => {
56
+ const cwd = tmp();
57
+ const o = { cwd, author: 'test' };
58
+ write(cwd, 'src/Hero.tsx', 'bg: "#0A0A0A"');
59
+ const a = (0, record_1.record)(mech({ verdict: 'accept', files: ['src/Hero.tsx'], expect: { absent: ['#0A0A0A'] } }), o);
60
+ strict_1.default.equal(a.exitCode, 0);
61
+ strict_1.default.equal(a.output.verified, null);
62
+ const f = (0, record_1.record)(mech({ verdict: 'fix', files: ['src/Hero.tsx'], expect: { absent: ['#0A0A0A'] } }), o);
63
+ strict_1.default.equal(f.exitCode, 4);
64
+ });
65
+ (0, node_test_1.test)('stage 2: findings adapter parses ESLint and flat shapes and queues them', () => {
66
+ const eslint = [{ filePath: '/p/src/A.tsx', messages: [{ ruleId: 'x/no-hex', line: 3, message: 'Raw hex', suggestion: 'Use token' }, { message: 'Other' }] }];
67
+ const flat = { findings: [{ file: 'src/B.tsx', rule: 'r', message: 'm' }, { path: 'src/C.css', description: 'd', line: 9 }, { nope: true }] };
68
+ strict_1.default.equal((0, findings_1.parseFindings)(eslint).length, 2);
69
+ strict_1.default.equal((0, findings_1.parseFindings)(flat).length, 2);
70
+ strict_1.default.equal((0, findings_1.parseFindings)(eslint)[0].suggestion, 'Use token');
71
+ const cwd = tmp();
72
+ write(cwd, 'findings.json', JSON.stringify(flat));
73
+ const r = (0, record_1.queueFindings)('findings.json', { cwd, author: 'test', tool: 'lint' });
74
+ strict_1.default.equal(r.output.queued, 2);
75
+ strict_1.default.equal((0, record_1.queueFindings)('findings.json', { cwd, author: 'test', tool: 'lint' }).output.skippedDuplicates, 2);
76
+ const p = (0, store_1.readPending)((0, store_1.resolvePaths)(cwd));
77
+ strict_1.default.equal(p.length, 2);
78
+ strict_1.default.equal(p[0].scope, 'file:src/B.tsx');
79
+ strict_1.default.equal(p[0].class, 'mechanical');
80
+ });
81
+ (0, node_test_1.test)('stage 3: sweep finds violations, skips docs and node_modules, queues per file', () => {
82
+ const cwd = tmp();
83
+ const o = { cwd, author: 'test' };
84
+ write(cwd, 'src/Button.tsx', 'brand-500');
85
+ write(cwd, 'src/Badge.tsx', 'x = "#3B7BE0"');
86
+ write(cwd, 'src/Hero.tsx', 'a = "#3B7BE0"; b = "#3B7BE0"');
87
+ write(cwd, 'node_modules/lib/index.js', '"#3B7BE0"');
88
+ write(cwd, 'README.md', '#3B7BE0');
89
+ const r = (0, record_1.record)(mech(), o);
90
+ strict_1.default.equal(r.exitCode, 0);
91
+ // Counted per line: Hero's two hits on one line are one violation.
92
+ strict_1.default.deepEqual(r.output.sweep.violations, 2);
93
+ strict_1.default.deepEqual(r.output.sweep.files, 2);
94
+ const s = (0, sweep_1.sweepCommand)('D-0001', { cwd, queue: true, author: 'test' });
95
+ strict_1.default.equal(s.result.violations.length, 2);
96
+ strict_1.default.deepEqual(s.queued, ['P-0001', 'P-0002']);
97
+ strict_1.default.equal((0, sweep_1.sweepCommand)('D-0001', { cwd, queue: true, author: 'test' }).queued.length, 0, 'no duplicate queue');
98
+ // Confirm one file as an exception: an accept, unverified by design.
99
+ const acc = (0, record_1.judge)('P-0001', { cwd, author: 'test', as: 'accept' });
100
+ strict_1.default.equal(acc.exitCode, 0);
101
+ strict_1.default.equal(acc.output.verified, null);
102
+ });
103
+ (0, node_test_1.test)('stage 3: judgment rules cannot sweep', () => {
104
+ const cwd = tmp();
105
+ (0, record_1.record)(mech({ class: 'judgment', files: [], expect: null }), { cwd, author: 'test' });
106
+ const s = (0, sweep_1.sweepCommand)('D-0001', { cwd });
107
+ strict_1.default.equal(s.result.sweepable, false);
108
+ });
109
+ (0, node_test_1.test)('stage 4: candidates round-trip; approve supersedes siblings with reason', () => {
110
+ const cwd = tmp();
111
+ const o = { cwd, author: 'test' };
112
+ const a = (0, candidate_1.addCandidate)('Settings — single page', { ...o, feature: 'settings', notes: 'first pass' });
113
+ const b = (0, candidate_1.addCandidate)('Settings — tabs', { ...o, feature: 'settings' });
114
+ const c = (0, candidate_1.addCandidate)('Billing', { ...o, feature: 'billing' });
115
+ strict_1.default.deepEqual([a.output.id, b.output.id, c.output.id], ['C-0001', 'C-0002', 'C-0003']);
116
+ (0, record_1.queue)(mech({ class: 'judgment', files: [], expect: null, scope: 'pattern:settings-layout', dimension: 'structure' }), { ...o, candidate: 'C-0001' });
117
+ const md = node_fs_1.default.readFileSync(node_path_1.default.join(cwd, '.arbiter/candidates/C-0001.md'), 'utf8');
118
+ strict_1.default.ok(md.includes('**P-0001**'), 'candidate page lists linked pending decision');
119
+ const up = (0, candidate_1.updateCandidate)('C-0001', { ...o, state: 'approved', why: 'tabs hid the danger zone' });
120
+ strict_1.default.deepEqual(up.output.superseded, ['C-0002']);
121
+ const all = (0, candidates_1.readCandidates)((0, store_1.resolvePaths)(cwd));
122
+ const tabs = all.find((x) => x.id === 'C-0002');
123
+ strict_1.default.equal(tabs.state, 'superseded');
124
+ strict_1.default.equal(tabs.supersededBy, 'C-0001');
125
+ strict_1.default.equal(tabs.reason, 'tabs hid the danger zone');
126
+ strict_1.default.equal(all.find((x) => x.id === 'C-0003').state, 'generated', 'other feature untouched');
127
+ for (const cand of all)
128
+ strict_1.default.deepEqual((0, candidates_1.parseCandidate)((0, candidates_1.formatCandidate)(cand, [])), cand);
129
+ strict_1.default.ok((0, board_1.board)({ cwd }).includes('superseded → C-0001'));
130
+ strict_1.default.equal((0, candidate_1.updateCandidate)('C-0003', { ...o, state: 'superseded' }).exitCode, 1, 'superseded needs --by');
131
+ });
132
+ (0, node_test_1.test)('stage 5: git destination writes index, commits candidate files only, links to GitHub', () => {
133
+ const cwd = tmp();
134
+ const git = (...a) => (0, node_child_process_1.execFileSync)('git', a, { cwd, stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim();
135
+ git('init', '-q', '-b', 'main');
136
+ git('config', 'user.email', 't@t');
137
+ git('config', 'user.name', 'T');
138
+ git('remote', 'add', 'origin', 'https://github.com/acme/app.git');
139
+ write(cwd, 'src/unrelated.ts', 'x');
140
+ git('add', '-A');
141
+ git('commit', '-qm', 'init');
142
+ write(cwd, 'src/unrelated.ts', 'y — uncommitted, must stay uncommitted');
143
+ (0, store_1.writeConfig)((0, store_1.resolvePaths)(cwd), { version: 1, destination: 'git', author: 'test' });
144
+ const r = (0, candidate_1.addCandidate)('Billing v1', { cwd, feature: 'billing' });
145
+ strict_1.default.equal(r.output.destination, 'git');
146
+ strict_1.default.ok(r.output.committed);
147
+ strict_1.default.deepEqual(r.output.links, ['https://github.com/acme/app/blob/main/.arbiter/candidates/C-0001.md']);
148
+ strict_1.default.ok(node_fs_1.default.existsSync(node_path_1.default.join(cwd, 'CANDIDATES.md')));
149
+ strict_1.default.equal(r.output.pages, 'https://acme.github.io/app/arbiter/');
150
+ strict_1.default.ok(node_fs_1.default.existsSync(node_path_1.default.join(cwd, 'docs/arbiter/index.html')), 'board page exported for GitHub Pages');
151
+ strict_1.default.ok(git('show', '--stat', '--oneline', 'HEAD').includes('docs/arbiter/index.html'), 'and committed');
152
+ strict_1.default.ok(git('log', '-1', '--pretty=%s').startsWith('arbiter: add C-0001'));
153
+ strict_1.default.equal(git('status', '--porcelain', 'src/'), 'M src/unrelated.ts', 'host changes never swept into the commit');
154
+ const again = (0, candidate_1.updateCandidate)('C-0001', { cwd, notes: 'unchanged state' });
155
+ strict_1.default.ok(again.output.committed, 'edits commit too');
156
+ });
157
+ (0, node_test_1.test)('stage 5: local destination commits nothing', () => {
158
+ const cwd = tmp();
159
+ const r = (0, candidate_1.addCandidate)('X', { cwd, author: 'test' });
160
+ strict_1.default.equal(r.output.destination, 'local');
161
+ strict_1.default.equal(r.output.committed, undefined);
162
+ strict_1.default.ok(!node_fs_1.default.existsSync(node_path_1.default.join(cwd, 'CANDIDATES.md')));
163
+ });
164
+ (0, node_test_1.test)('sweep: rule.files narrows the scan; config excludes apply; globs match', () => {
165
+ const cwd = tmp();
166
+ const o = { cwd, author: 'test' };
167
+ write(cwd, 'app/components/A.tsx', '"#3B7BE0"');
168
+ write(cwd, 'app/globals.css', '--brand: #3B7BE0;');
169
+ write(cwd, 'docs/ref.html', '#3B7BE0');
170
+ write(cwd, 'design-reference/x/y.html', '#3B7BE0');
171
+ write(cwd, 'arbiter.json', JSON.stringify({ version: 1, destination: 'local', sweep: { exclude: ['app/globals.css', 'docs/**', 'design-reference/**'] } }));
172
+ const wide = (0, record_1.record)(mech({ files: [], expect: { absent: ['#3B7BE0'] } }), o);
173
+ strict_1.default.equal(wide.output.sweep.files, 1, 'excludes removed three of four');
174
+ const narrow = (0, record_1.record)(mech({ scope: 'pattern:components', files: [], paths: ['app/components'], expect: { absent: ['#3B7BE0'] } }), { ...o, keepBoth: true });
175
+ const s = (0, sweep_1.sweepCommand)(narrow.output.id, { cwd });
176
+ strict_1.default.equal(s.result.scanned, 'rule.paths');
177
+ strict_1.default.equal(s.result.filesScanned, 1);
178
+ });
179
+ (0, node_test_1.test)('overlap: generic UI nouns and other dimensions do not trigger possible matches', () => {
180
+ const cwd = tmp();
181
+ const o = { cwd, author: 'test' };
182
+ (0, record_1.record)(mech({ class: 'judgment', files: [], expect: null, decision: 'Audit run button shows a spinner while the scan is running', dimension: 'states', scope: 'pattern:audit-run' }), o);
183
+ const r = (0, record_1.record)(mech({ class: 'judgment', files: [], expect: null, decision: 'Audit empty state offers a Run first audit button', dimension: 'states', scope: 'pattern:audit-empty' }), o);
184
+ strict_1.default.equal(r.exitCode, 0, 'shared: audit, run, button, state — but button/run/state are generic and audit alone is not enough');
185
+ write(cwd, 'arbiter.json', JSON.stringify({ version: 1, destination: 'local', overlap: { ignore: ['spinner'] } }));
186
+ const r2 = (0, record_1.record)(mech({ class: 'judgment', files: [], expect: null, decision: 'Journeys board shows a spinner while journeys load', dimension: 'interaction', scope: 'pattern:board-loading' }), o);
187
+ strict_1.default.equal(r2.exitCode, 0, 'different dimension never matches on wording');
188
+ });
package/dist/verify.js ADDED
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ /**
3
+ * Claim checking. The agent says "used brand.500 in Button.tsx"; we read
4
+ * Button.tsx and look. Read-only, only the files the decision names — never
5
+ * a repo-wide scan. Literal string matching, nothing cleverer: detection is
6
+ * someone else's product.
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.verify = verify;
13
+ exports.matcher = matcher;
14
+ exports.lineOf = lineOf;
15
+ exports.checkable = checkable;
16
+ const node_fs_1 = __importDefault(require("node:fs"));
17
+ const node_path_1 = __importDefault(require("node:path"));
18
+ /**
19
+ * `present` needles must appear in at least one of the files; `absent` needles
20
+ * must appear in none. Every file must exist.
21
+ */
22
+ function verify(root, files, expect) {
23
+ const checks = [];
24
+ const contents = new Map();
25
+ for (const f of files) {
26
+ const abs = node_path_1.default.resolve(root, f);
27
+ if (!abs.startsWith(node_path_1.default.resolve(root))) {
28
+ checks.push({ kind: 'exists', file: f, ok: false, detail: 'outside the project' });
29
+ continue;
30
+ }
31
+ if (!node_fs_1.default.existsSync(abs) || !node_fs_1.default.statSync(abs).isFile()) {
32
+ checks.push({ kind: 'exists', file: f, ok: false, detail: 'file not found' });
33
+ continue;
34
+ }
35
+ contents.set(f, node_fs_1.default.readFileSync(abs, 'utf8'));
36
+ checks.push({ kind: 'exists', file: f, ok: true });
37
+ }
38
+ for (const needle of expect?.present ?? []) {
39
+ const find = matcher(needle);
40
+ const hit = [...contents.entries()].find(([, text]) => find(text) >= 0);
41
+ checks.push({
42
+ kind: 'present',
43
+ file: hit?.[0] ?? files.join(', '),
44
+ needle,
45
+ ok: !!hit,
46
+ detail: hit ? undefined : `not found in ${files.length} file${files.length === 1 ? '' : 's'}`,
47
+ });
48
+ }
49
+ for (const needle of expect?.absent ?? []) {
50
+ for (const [f, text] of contents) {
51
+ const line = lineOf(text, needle);
52
+ if (line !== null)
53
+ checks.push({ kind: 'absent', file: f, needle, ok: false, detail: `found at line ${line}` });
54
+ }
55
+ if (!checks.some((c) => c.kind === 'absent' && c.needle === needle && !c.ok)) {
56
+ checks.push({ kind: 'absent', file: files.join(', '), needle, ok: true });
57
+ }
58
+ }
59
+ return { ok: checks.every((c) => c.ok), checks };
60
+ }
61
+ /** A needle is a literal string, or a pattern when written `regex:<source>`. */
62
+ function matcher(needle) {
63
+ if (needle.startsWith('regex:')) {
64
+ const re = new RegExp(needle.slice(6));
65
+ return (text) => text.search(re);
66
+ }
67
+ return (text) => text.indexOf(needle);
68
+ }
69
+ function lineOf(text, needle) {
70
+ const i = matcher(needle)(text);
71
+ if (i < 0)
72
+ return null;
73
+ return text.slice(0, i).split('\n').length;
74
+ }
75
+ /** True when the decision carries something checkable. */
76
+ function checkable(files, expect) {
77
+ return files.length > 0 || !!(expect?.present?.length || expect?.absent?.length);
78
+ }
package/dist/work.js ADDED
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ /**
3
+ * Pieces of work — the groups the queue already makes (`trigger`) — as the hosted board shows
4
+ * them. A piece of work isn't a candidate: nothing competes, nothing is approved. But it can
5
+ * carry a picture, kept in .arbiter/work/ under a stable id derived from its name.
6
+ */
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.workDir = exports.workId = void 0;
12
+ exports.workSnapshot = workSnapshot;
13
+ exports.copyImage = copyImage;
14
+ exports.captureImage = captureImage;
15
+ const node_fs_1 = __importDefault(require("node:fs"));
16
+ const node_path_1 = __importDefault(require("node:path"));
17
+ const node_child_process_1 = require("node:child_process");
18
+ const IMAGE_EXT = ['.png', '.jpg', '.jpeg', '.webp', '.gif', '.svg'];
19
+ /** `Settings build` → `W-settings-build`: stable across republishes, so comments on it survive. */
20
+ const workId = (trigger) => 'W-' + trigger.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 48);
21
+ exports.workId = workId;
22
+ const workDir = (paths) => node_path_1.default.join(paths.archiveDir, 'work');
23
+ exports.workDir = workDir;
24
+ /** The snapshot file for a piece of work, if one was attached. */
25
+ function workSnapshot(paths, id) {
26
+ for (const ext of IMAGE_EXT) {
27
+ const f = node_path_1.default.join((0, exports.workDir)(paths), id + ext);
28
+ if (node_fs_1.default.existsSync(f))
29
+ return f;
30
+ }
31
+ return null;
32
+ }
33
+ /** Copy an image in as `<dir>/<id><ext>`; any earlier one for that id goes. */
34
+ function copyImage(root, dir, id, src) {
35
+ const abs = node_path_1.default.resolve(root, src);
36
+ if (!node_fs_1.default.existsSync(abs))
37
+ return { ok: false, error: `snapshot not found: ${src}` };
38
+ const ext = node_path_1.default.extname(abs).toLowerCase() || '.png';
39
+ if (!IMAGE_EXT.includes(ext))
40
+ return { ok: false, error: `snapshot must be an image (png, jpg, webp, gif, svg), got ${ext}` };
41
+ node_fs_1.default.mkdirSync(dir, { recursive: true });
42
+ for (const e of IMAGE_EXT)
43
+ if (e !== ext && node_fs_1.default.existsSync(node_path_1.default.join(dir, id + e)))
44
+ node_fs_1.default.unlinkSync(node_path_1.default.join(dir, id + e));
45
+ node_fs_1.default.copyFileSync(abs, node_path_1.default.join(dir, id + ext));
46
+ return { ok: true, file: id + ext };
47
+ }
48
+ /** Drag-to-select a screen region with macOS's built-in `screencapture -i`. Escape cancels. */
49
+ function captureImage(dir, id) {
50
+ if (process.platform !== 'darwin')
51
+ return { ok: false, error: '--capture uses macOS screencapture; on other platforms pass an image file' };
52
+ node_fs_1.default.mkdirSync(dir, { recursive: true });
53
+ const out = node_path_1.default.join(dir, `${id}.png`);
54
+ process.stderr.write('Drag to select the region to capture (Esc to cancel)…\n');
55
+ try {
56
+ (0, node_child_process_1.execFileSync)('screencapture', ['-i', '-x', out], { stdio: 'ignore' });
57
+ }
58
+ catch {
59
+ return { ok: false, error: 'screencapture failed' };
60
+ }
61
+ if (!node_fs_1.default.existsSync(out) || node_fs_1.default.statSync(out).size === 0)
62
+ return { ok: false, error: 'capture cancelled — no snapshot saved' };
63
+ return { ok: true, file: `${id}.png` };
64
+ }
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "arbiterdesign",
3
+ "version": "0.1.0",
4
+ "description": "Records design decisions made during agent-assisted UI work and feeds them back into the agent's context.",
5
+ "homepage": "https://arbiter.design",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/eddie199/arbiter.git"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/eddie199/arbiter/issues"
12
+ },
13
+ "keywords": [
14
+ "design",
15
+ "decisions",
16
+ "claude-code",
17
+ "cursor",
18
+ "agents",
19
+ "ui"
20
+ ],
21
+ "license": "MIT",
22
+ "bin": {
23
+ "arbiter": "dist/index.js"
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "templates"
28
+ ],
29
+ "scripts": {
30
+ "build": "tsc -p tsconfig.json",
31
+ "prepare": "npm run build",
32
+ "test": "node --test \"dist/test/**/*.test.js\""
33
+ },
34
+ "engines": {
35
+ "node": ">=20"
36
+ },
37
+ "dependencies": {
38
+ "commander": "^12.1.0"
39
+ },
40
+ "devDependencies": {
41
+ "@types/node": "^20.14.0",
42
+ "typescript": "^5.5.0"
43
+ }
44
+ }