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.
- package/LICENSE +21 -0
- package/README.md +143 -0
- package/dist/candidates.js +155 -0
- package/dist/commands/board.js +41 -0
- package/dist/commands/candidate.js +168 -0
- package/dist/commands/drift.js +67 -0
- package/dist/commands/export.js +160 -0
- package/dist/commands/init.js +194 -0
- package/dist/commands/prompt.js +69 -0
- package/dist/commands/publish.js +139 -0
- package/dist/commands/pull.js +27 -0
- package/dist/commands/record.js +408 -0
- package/dist/commands/review.js +135 -0
- package/dist/commands/rules.js +152 -0
- package/dist/commands/snapshot.js +32 -0
- package/dist/commands/sweep.js +87 -0
- package/dist/commands/verify.js +41 -0
- package/dist/destination.js +99 -0
- package/dist/findings.js +70 -0
- package/dist/format.js +247 -0
- package/dist/hosted.js +222 -0
- package/dist/index.js +232 -0
- package/dist/overlap.js +71 -0
- package/dist/schema.js +233 -0
- package/dist/store.js +133 -0
- package/dist/sweep.js +128 -0
- package/dist/test/hosted.test.js +189 -0
- package/dist/test/init.test.js +54 -0
- package/dist/test/pending.test.js +198 -0
- package/dist/test/polish.test.js +130 -0
- package/dist/test/record.test.js +102 -0
- package/dist/test/stages.test.js +188 -0
- package/dist/verify.js +78 -0
- package/dist/work.js +64 -0
- package/package.json +44 -0
- package/templates/SKILL.md +338 -0
- package/templates/review.html +479 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const record_1 = require("./commands/record");
|
|
6
|
+
const verify_1 = require("./commands/verify");
|
|
7
|
+
const sweep_1 = require("./commands/sweep");
|
|
8
|
+
const candidate_1 = require("./commands/candidate");
|
|
9
|
+
const board_1 = require("./commands/board");
|
|
10
|
+
const drift_1 = require("./commands/drift");
|
|
11
|
+
const export_1 = require("./commands/export");
|
|
12
|
+
const publish_1 = require("./commands/publish");
|
|
13
|
+
const pull_1 = require("./commands/pull");
|
|
14
|
+
const snapshot_1 = require("./commands/snapshot");
|
|
15
|
+
const rules_1 = require("./commands/rules");
|
|
16
|
+
const init_1 = require("./commands/init");
|
|
17
|
+
const review_1 = require("./commands/review");
|
|
18
|
+
const program = new commander_1.Command();
|
|
19
|
+
program
|
|
20
|
+
.name('arbiter')
|
|
21
|
+
.description('Records design decisions made during agent-assisted UI work and feeds them back into the agent.')
|
|
22
|
+
.version(require('../package.json').version);
|
|
23
|
+
program
|
|
24
|
+
.command('record [json-or-pending-id]')
|
|
25
|
+
.description('Append a decision (JSON), queue it (--pending), or judge a queued one (P-0003 --as rule). No input at a terminal: asks step by step.')
|
|
26
|
+
.option('--pending', 'queue in .arbiter/pending.md for later review instead of recording now')
|
|
27
|
+
.option('--findings <file>', "queue one pending decision per finding in a scanner's JSON output")
|
|
28
|
+
.option('--tool <name>', 'with --findings: the scanner name for the record')
|
|
29
|
+
.option('--candidate <id>', 'the candidate (C-0001) this decision was made for')
|
|
30
|
+
.option('--retire <rule-id>', 'drop an active rule with no replacement (needs --why)')
|
|
31
|
+
.option('--why <reason>', 'with --retire: why the rule is dead')
|
|
32
|
+
.option('--unverified', 'record even if the named files contradict the claim')
|
|
33
|
+
.option('--as <action>', 'judge a pending id: accept | rule | skip | fix')
|
|
34
|
+
.option('--all', 'with --as: judge every pending item the same way')
|
|
35
|
+
.option('--level <level>', 'with --all: only this level (feature | pattern | polish)')
|
|
36
|
+
.option('--trigger <text>', 'with --all: only items queued for this piece of work')
|
|
37
|
+
.option('--to <decision>', 'with --as fix: what it should be instead')
|
|
38
|
+
.option('--supersedes <id>', 'the active rule this one replaces')
|
|
39
|
+
.option('--ref <url|key>', 'the ticket this was for: a URL or an issue key like ENG-123')
|
|
40
|
+
.option('--keep-both', 'record alongside overlapping rules instead of replacing one')
|
|
41
|
+
.option('--author <name>', 'override the author')
|
|
42
|
+
.option('--dry-run', 'validate and check overlap without writing')
|
|
43
|
+
.action(async (arg, opts) => {
|
|
44
|
+
let result;
|
|
45
|
+
if (opts.retire) {
|
|
46
|
+
result = (0, record_1.retire)(opts.retire, opts.why, opts);
|
|
47
|
+
}
|
|
48
|
+
else if (opts.findings) {
|
|
49
|
+
result = (0, record_1.queueFindings)(opts.findings, opts);
|
|
50
|
+
}
|
|
51
|
+
else if (opts.all) {
|
|
52
|
+
const as = opts.as;
|
|
53
|
+
if (!as || !['accept', 'rule', 'skip'].includes(as)) {
|
|
54
|
+
result = { exitCode: 1, output: { status: 'invalid', errors: ['--all needs --as accept | rule | skip'] } };
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
result = (0, record_1.judgeAll)({ ...opts, as });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else if (arg && /^P-\d{4,}$/.test(arg)) {
|
|
61
|
+
const as = opts.as;
|
|
62
|
+
if (!as || !['accept', 'rule', 'skip', 'fix'].includes(as)) {
|
|
63
|
+
result = { exitCode: 1, output: { status: 'invalid', errors: ['judging a pending id needs --as accept | rule | skip | fix'] } };
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
result = (0, record_1.judge)(arg, { ...opts, as });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
let input = arg ?? (await readStdin());
|
|
71
|
+
if (!input.trim() && process.stdin.isTTY)
|
|
72
|
+
input = await (0, record_1.interactiveInput)();
|
|
73
|
+
if (!input.trim()) {
|
|
74
|
+
process.stdout.write(JSON.stringify({ status: 'invalid', errors: ['no input — pass JSON as an argument or on stdin'] }, null, 2) + '\n');
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
result = opts.pending ? (0, record_1.queue)(input, opts) : (0, record_1.record)(input, opts);
|
|
78
|
+
}
|
|
79
|
+
process.stdout.write(JSON.stringify(result.output, null, 2) + '\n');
|
|
80
|
+
process.exit(result.exitCode);
|
|
81
|
+
});
|
|
82
|
+
program
|
|
83
|
+
.command('init')
|
|
84
|
+
.description('Install Arbiter into this project: skill, DECISIONS.md, .arbiter/, arbiter.json, one line in AGENTS.md.')
|
|
85
|
+
.option('--client <name>', 'claude-code or cursor (default: detected)')
|
|
86
|
+
.option('--author <name>', 'who decides rules (default: git user.name)')
|
|
87
|
+
.option('--destination <name>', 'local (default) or git — git also commits candidate pages and prints GitHub links')
|
|
88
|
+
.option('-y, --yes', 'no questions — use detected values')
|
|
89
|
+
.option('--skip-install', 'do not add the package to devDependencies')
|
|
90
|
+
.action(async (opts) => {
|
|
91
|
+
const steps = await (0, init_1.init)(opts);
|
|
92
|
+
const w = Math.max(...steps.map((s) => s.file.length));
|
|
93
|
+
for (const s of steps) {
|
|
94
|
+
process.stdout.write(` ${s.file.padEnd(w)} ${s.outcome}${s.note ? ` — ${s.note}` : ''}\n`);
|
|
95
|
+
}
|
|
96
|
+
process.stdout.write('\nDone. Start a new agent session — it will read DECISIONS.md before UI work.\n');
|
|
97
|
+
if (opts.destination === 'git') {
|
|
98
|
+
process.stdout.write([
|
|
99
|
+
'',
|
|
100
|
+
'Git destination: every candidate change commits its page, CANDIDATES.md, and the board page in docs/arbiter/.',
|
|
101
|
+
'To serve the board page publicly, once: GitHub → your repo → Settings → Pages → Source: "Deploy from a branch",',
|
|
102
|
+
'Branch: main, Folder: /docs → Save. Then push. `npx arbiter board` prints the URL.',
|
|
103
|
+
'',
|
|
104
|
+
].join('\n'));
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
program
|
|
108
|
+
.command('verify [id]')
|
|
109
|
+
.description("Re-check a decision's claim against its files. No id: every active rule with evidence.")
|
|
110
|
+
.option('--json', 'machine-readable output')
|
|
111
|
+
.action((id, opts) => {
|
|
112
|
+
const r = (0, verify_1.verifyCommand)(id, opts);
|
|
113
|
+
process.stdout.write(r.text + '\n');
|
|
114
|
+
process.exit(r.ok ? 0 : 4);
|
|
115
|
+
});
|
|
116
|
+
program
|
|
117
|
+
.command('sweep <rule-id>')
|
|
118
|
+
.description('Find existing violations of a mechanical rule. Read-only.')
|
|
119
|
+
.option('--queue', 'queue one pending decision per affected file for review')
|
|
120
|
+
.option('--author <name>', 'author for queued items')
|
|
121
|
+
.option('--json', 'machine-readable output')
|
|
122
|
+
.action((id, opts) => {
|
|
123
|
+
const r = (0, sweep_1.sweepCommand)(id, opts);
|
|
124
|
+
process.stdout.write(r.text + '\n');
|
|
125
|
+
});
|
|
126
|
+
program
|
|
127
|
+
.command('snapshot <work>')
|
|
128
|
+
.description('Attach a picture to a piece of work, named as its decisions named it: snapshot "Settings build" --file shot.png')
|
|
129
|
+
.option('--file <image>', 'screenshot to keep beside the work')
|
|
130
|
+
.option('--capture', 'macOS: drag-select a region of the screen')
|
|
131
|
+
.action((work, opts) => {
|
|
132
|
+
const result = (0, snapshot_1.snapshotWork)(work, opts);
|
|
133
|
+
process.stdout.write(JSON.stringify(result.output, null, 2) + '\n');
|
|
134
|
+
process.exit(result.exitCode);
|
|
135
|
+
});
|
|
136
|
+
program
|
|
137
|
+
.command('candidate <id-or-add> [name]')
|
|
138
|
+
.description('Track a generated screen. `candidate add "<name>"` creates one; `candidate C-0002 --state approved` updates one.')
|
|
139
|
+
.option('--feature <name>', 'group directions for one feature together')
|
|
140
|
+
.option('--snapshot <image>', 'screenshot to keep beside the candidate')
|
|
141
|
+
.option('--capture', 'macOS: drag-select a region of the screen as the snapshot')
|
|
142
|
+
.option('--notes <text>', 'free text')
|
|
143
|
+
.option('--state <state>', 'generated | in_review | approved | rejected | superseded')
|
|
144
|
+
.option('--why <reason>', 'why it was rejected or superseded (kept forever)')
|
|
145
|
+
.option('--by <id>', 'with --state superseded: the candidate that replaced it')
|
|
146
|
+
.option('--keep-others', "approving doesn't supersede sibling directions")
|
|
147
|
+
.option('--author <name>', 'override the author')
|
|
148
|
+
.action((idOrAdd, name, opts) => {
|
|
149
|
+
const result = idOrAdd === 'add' ? (0, candidate_1.addCandidate)(name ?? '', opts) : (0, candidate_1.updateCandidate)(idOrAdd, opts);
|
|
150
|
+
process.stdout.write(JSON.stringify(result.output, null, 2) + '\n');
|
|
151
|
+
process.exit(result.exitCode);
|
|
152
|
+
});
|
|
153
|
+
program
|
|
154
|
+
.command('board')
|
|
155
|
+
.description('Candidates and their states.')
|
|
156
|
+
.option('--feature <name>', 'one feature only')
|
|
157
|
+
.option('--json', 'machine-readable output')
|
|
158
|
+
.action((opts) => {
|
|
159
|
+
process.stdout.write((0, board_1.board)(opts) + '\n');
|
|
160
|
+
});
|
|
161
|
+
program
|
|
162
|
+
.command('drift')
|
|
163
|
+
.description('Deviations per screen: accepted exceptions, unverified claims, rules currently broken.')
|
|
164
|
+
.option('--feature <name>', 'one feature only')
|
|
165
|
+
.option('--json', 'machine-readable output')
|
|
166
|
+
.action((opts) => {
|
|
167
|
+
process.stdout.write((0, drift_1.drift)(opts) + '\n');
|
|
168
|
+
});
|
|
169
|
+
program
|
|
170
|
+
.command('export')
|
|
171
|
+
.description('Write a static, self-contained folder of the board for people without the repo. Opens anywhere.')
|
|
172
|
+
.option('--out <dir>', 'output folder (default: arbiter-export)')
|
|
173
|
+
.option('--feature <name>', 'one feature only')
|
|
174
|
+
.option('--include-rules', 'append the standing rules')
|
|
175
|
+
.option('--open', 'open it in the browser')
|
|
176
|
+
.action((opts) => {
|
|
177
|
+
const r = (0, export_1.exportBoard)(opts);
|
|
178
|
+
process.stdout.write(`Exported ${r.candidates} screen${r.candidates === 1 ? '' : 's'}, ${r.snapshots} snapshot${r.snapshots === 1 ? '' : 's'} → ${r.dir}\nOpen ${r.index}, or put the folder on any static host.\n`);
|
|
179
|
+
});
|
|
180
|
+
program
|
|
181
|
+
.command('publish')
|
|
182
|
+
.description('Put the board online. Default: GitHub Pages (git destination, export, commit, push). --to <url>: a hosted Arbiter board with comments.')
|
|
183
|
+
.option('--to <url>', 'hosted board service (the hosted/ app); saved to .arbiter/hosted.json on first publish')
|
|
184
|
+
.option('--admin-token <token>', 'the site\'s admin token, needed once to create the project (or set ARBITER_ADMIN_TOKEN)')
|
|
185
|
+
.option('--no-push', 'GitHub Pages mode: do everything except push')
|
|
186
|
+
.action(async (opts) => {
|
|
187
|
+
const r = await (0, publish_1.publish)({ noPush: opts.push === false, to: opts.to, admin: opts.adminToken });
|
|
188
|
+
const w = Math.max(...r.steps.map((s) => s.step.length));
|
|
189
|
+
for (const s of r.steps)
|
|
190
|
+
process.stdout.write(` ${s.step.padEnd(w)} ${s.outcome}${s.note ? ` — ${s.note}` : ''}\n`);
|
|
191
|
+
if (r.url)
|
|
192
|
+
process.stdout.write(`\n${r.ok ? 'Live in about a minute' : 'Once the failed step is fixed'}: ${r.url}\n`);
|
|
193
|
+
process.exit(r.ok ? 0 : 1);
|
|
194
|
+
});
|
|
195
|
+
program
|
|
196
|
+
.command('pull')
|
|
197
|
+
.description('Fetch comments and "looks good" reactions from the hosted board into .arbiter/comments.json.')
|
|
198
|
+
.action(async () => {
|
|
199
|
+
process.stdout.write((await (0, pull_1.pull)()) + '\n');
|
|
200
|
+
});
|
|
201
|
+
program
|
|
202
|
+
.command('review')
|
|
203
|
+
.description('Open a local page to judge pending decisions.')
|
|
204
|
+
.option('--port <n>', 'port (default: any free port)', (v) => Number(v))
|
|
205
|
+
.option('--no-open', "print the URL, don't open a browser")
|
|
206
|
+
.action(async (opts) => {
|
|
207
|
+
await (0, review_1.review)(opts);
|
|
208
|
+
});
|
|
209
|
+
program
|
|
210
|
+
.command('rules [id]')
|
|
211
|
+
.description('Read decisions. No args: active rules. An id (D-0003): that one in full.')
|
|
212
|
+
.option('--dimension <name>', 'only one dimension (structure, interaction, states, content, visual, motion, access)')
|
|
213
|
+
.option('--archive', 'everything ever recorded — accepts, fixes, superseded — oldest first')
|
|
214
|
+
.option('--pending', 'queued decisions not yet judged')
|
|
215
|
+
.option('--json', 'machine-readable output')
|
|
216
|
+
.action((id, opts) => {
|
|
217
|
+
process.stdout.write((0, rules_1.rules)(id, opts) + '\n');
|
|
218
|
+
});
|
|
219
|
+
program.parseAsync(process.argv).catch((e) => {
|
|
220
|
+
process.stderr.write(`arbiter: ${e.message}\n`);
|
|
221
|
+
process.exit(1);
|
|
222
|
+
});
|
|
223
|
+
function readStdin() {
|
|
224
|
+
if (process.stdin.isTTY)
|
|
225
|
+
return Promise.resolve('');
|
|
226
|
+
return new Promise((resolve) => {
|
|
227
|
+
let data = '';
|
|
228
|
+
process.stdin.setEncoding('utf8');
|
|
229
|
+
process.stdin.on('data', (c) => (data += c));
|
|
230
|
+
process.stdin.on('end', () => resolve(data));
|
|
231
|
+
});
|
|
232
|
+
}
|
package/dist/overlap.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Scope-overlap detection for new rules against the active set.
|
|
4
|
+
*
|
|
5
|
+
* Two confidence levels, per the PRD's "confidence markers" principle:
|
|
6
|
+
* exact — same scope, or one file scope contains the other. Safe to act on.
|
|
7
|
+
* possible — different scope but the wording shares enough significant words
|
|
8
|
+
* that a human should look. A guess, marked as one.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.findOverlaps = findOverlaps;
|
|
12
|
+
const schema_1 = require("./schema");
|
|
13
|
+
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
|
+
// Generic UI nouns: shared by half of all decisions, so they say nothing about overlap.
|
|
15
|
+
'button buttons page pages card cards link links icon icons text label labels row rows list lists screen screens view views item items section sections header footer form forms field fields input inputs show shows open opens click clicks user users add new first run action actions').split(' '));
|
|
16
|
+
const MIN_SHARED_WORDS = 3;
|
|
17
|
+
function findOverlaps(candidate, active, opts = {}) {
|
|
18
|
+
const out = [];
|
|
19
|
+
const cScope = (0, schema_1.parseScope)(candidate.scope);
|
|
20
|
+
const ignore = new Set((opts.ignore ?? []).map((w) => stem(w.toLowerCase())));
|
|
21
|
+
const cWords = significantWords(candidate, ignore);
|
|
22
|
+
for (const rule of active) {
|
|
23
|
+
if (rule.verdict !== 'rule')
|
|
24
|
+
continue;
|
|
25
|
+
const rScope = (0, schema_1.parseScope)(rule.scope);
|
|
26
|
+
if (rule.scope === candidate.scope && cScope.kind !== 'global') {
|
|
27
|
+
out.push(mark(rule, 'exact', `same scope ${rule.scope}`));
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (cScope.kind === 'file' && rScope.kind === 'file' && fileContains(cScope.target, rScope.target)) {
|
|
31
|
+
out.push(mark(rule, 'exact', `file scope ${narrower(cScope.target, rScope.target)} is inside ${wider(cScope.target, rScope.target)}`));
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
// Wording alone is a guess; only guess within the same dimension.
|
|
35
|
+
if (rule.dimension !== candidate.dimension)
|
|
36
|
+
continue;
|
|
37
|
+
const shared = [...cWords].filter((w) => significantWords(rule, ignore).has(w));
|
|
38
|
+
if (shared.length >= MIN_SHARED_WORDS) {
|
|
39
|
+
out.push(mark(rule, 'possible', `same dimension, wording shares: ${shared.join(', ')}`));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Exact matches first, then possible.
|
|
43
|
+
return out.sort((a, b) => (a.confidence === b.confidence ? 0 : a.confidence === 'exact' ? -1 : 1));
|
|
44
|
+
}
|
|
45
|
+
function mark(rule, confidence, reason) {
|
|
46
|
+
return { id: rule.id, decision: rule.decision, scope: rule.scope, confidence, reason };
|
|
47
|
+
}
|
|
48
|
+
/** Words from the decision statement and the scope target, minus stopwords and short tokens. */
|
|
49
|
+
function significantWords(d, ignore = new Set()) {
|
|
50
|
+
const target = (0, schema_1.parseScope)(d.scope).target ?? '';
|
|
51
|
+
const text = `${d.decision} ${target.replace(/[\/._-]+/g, ' ')}`;
|
|
52
|
+
const words = text
|
|
53
|
+
.toLowerCase()
|
|
54
|
+
.replace(/[^a-z0-9\s]/g, ' ')
|
|
55
|
+
.split(/\s+/)
|
|
56
|
+
.map(stem)
|
|
57
|
+
.filter((w) => w.length > 2 && !STOPWORDS.has(w) && !ignore.has(w));
|
|
58
|
+
return new Set(words);
|
|
59
|
+
}
|
|
60
|
+
/** Crude suffix stripping so "modals" ~ "modal", "confirms" ~ "confirm". */
|
|
61
|
+
function stem(w) {
|
|
62
|
+
return w.replace(/(ing|ed|es|s)$/, '');
|
|
63
|
+
}
|
|
64
|
+
function fileContains(a, b) {
|
|
65
|
+
const na = norm(a);
|
|
66
|
+
const nb = norm(b);
|
|
67
|
+
return na === nb || na.startsWith(nb + '/') || nb.startsWith(na + '/');
|
|
68
|
+
}
|
|
69
|
+
const norm = (p) => p.replace(/\\/g, '/').replace(/\/+$/, '');
|
|
70
|
+
const narrower = (a, b) => (norm(a).length >= norm(b).length ? a : b);
|
|
71
|
+
const wider = (a, b) => (norm(a).length >= norm(b).length ? b : a);
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The decision record. Mirrors the PRD schema, plus `decision` — the one-line
|
|
4
|
+
* statement of what was decided. The PRD has `trigger` (what prompted it) and
|
|
5
|
+
* `rationale` (why), but the statement the agent actually needs to read had
|
|
6
|
+
* nowhere to live.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.CANDIDATE_ID = exports.PENDING_ID = exports.DECISION_ID = exports.ID_PATTERN = exports.FIELDS = exports.DIMENSIONS = exports.SCOPE_KINDS = exports.VERDICTS = exports.LEVELS = exports.CLASSES = void 0;
|
|
10
|
+
exports.validateInput = validateInput;
|
|
11
|
+
exports.parseScope = parseScope;
|
|
12
|
+
exports.CLASSES = ['mechanical', 'judgment'];
|
|
13
|
+
/**
|
|
14
|
+
* How big a call this was. Drives what the review shows:
|
|
15
|
+
* feature a new surface, flow or structure — always surfaced
|
|
16
|
+
* pattern a reusable call that could apply elsewhere — surfaced, "make it a rule" is the likely answer
|
|
17
|
+
* polish a one-off fix to one screen — collapsed to one line, confirmed in bulk
|
|
18
|
+
*/
|
|
19
|
+
exports.LEVELS = ['feature', 'pattern', 'polish'];
|
|
20
|
+
exports.VERDICTS = ['fix', 'accept', 'rule', 'retire'];
|
|
21
|
+
exports.SCOPE_KINDS = ['global', 'file', 'pattern'];
|
|
22
|
+
/** What the decision is about. Fixed order — DECISIONS.md groups by it in this order. */
|
|
23
|
+
exports.DIMENSIONS = ['structure', 'interaction', 'states', 'content', 'visual', 'motion', 'access'];
|
|
24
|
+
/** Fields in file order. Also the order they're serialized in. */
|
|
25
|
+
exports.FIELDS = [
|
|
26
|
+
'id',
|
|
27
|
+
'decision',
|
|
28
|
+
'change',
|
|
29
|
+
'level',
|
|
30
|
+
'rationale',
|
|
31
|
+
'rejected',
|
|
32
|
+
'trigger',
|
|
33
|
+
'scope',
|
|
34
|
+
'dimension',
|
|
35
|
+
'class',
|
|
36
|
+
'verdict',
|
|
37
|
+
'author',
|
|
38
|
+
'date',
|
|
39
|
+
'commit',
|
|
40
|
+
'supersedes',
|
|
41
|
+
'ref',
|
|
42
|
+
'files',
|
|
43
|
+
'paths',
|
|
44
|
+
'expect',
|
|
45
|
+
'verified',
|
|
46
|
+
'candidate',
|
|
47
|
+
];
|
|
48
|
+
exports.ID_PATTERN = /^[DP]-\d{4,}$/;
|
|
49
|
+
exports.DECISION_ID = /^D-\d{4,}$/;
|
|
50
|
+
exports.PENDING_ID = /^P-\d{4,}$/;
|
|
51
|
+
exports.CANDIDATE_ID = /^C-\d{4,}$/;
|
|
52
|
+
const SCOPE_PATTERN = /^(global|file:\S.*|pattern:[A-Za-z0-9][A-Za-z0-9._\/-]*)$/;
|
|
53
|
+
const SHORT_SHA = /^[0-9a-f]{7,40}$/;
|
|
54
|
+
function validateInput(raw, options = {}) {
|
|
55
|
+
const errors = [];
|
|
56
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
|
|
57
|
+
return { ok: false, errors: ['decision must be a JSON object'] };
|
|
58
|
+
}
|
|
59
|
+
const obj = raw;
|
|
60
|
+
const line = (key, required) => {
|
|
61
|
+
const v = obj[key];
|
|
62
|
+
if (v === undefined || v === null || v === '') {
|
|
63
|
+
if (required)
|
|
64
|
+
errors.push(`${key} is required`);
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
if (typeof v !== 'string') {
|
|
68
|
+
errors.push(`${key} must be a string`);
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
const s = v.trim();
|
|
72
|
+
if (s.includes('\n'))
|
|
73
|
+
errors.push(`${key} must be a single line`);
|
|
74
|
+
return s;
|
|
75
|
+
};
|
|
76
|
+
const decision = line('decision', true);
|
|
77
|
+
const trigger = line('trigger', true);
|
|
78
|
+
const rationale = line('rationale', true);
|
|
79
|
+
const scope = line('scope', true);
|
|
80
|
+
const cls = line('class', true);
|
|
81
|
+
const dimension = line('dimension', true);
|
|
82
|
+
const verdict = line('verdict', !options.pending);
|
|
83
|
+
const change = line('change', false);
|
|
84
|
+
const level = line('level', false);
|
|
85
|
+
const author = line('author', false);
|
|
86
|
+
const commit = line('commit', false);
|
|
87
|
+
const date = line('date', false);
|
|
88
|
+
const ref = line('ref', false);
|
|
89
|
+
const supersedesRaw = obj.supersedes;
|
|
90
|
+
if (cls !== undefined && !exports.CLASSES.includes(cls)) {
|
|
91
|
+
errors.push(`class must be one of ${exports.CLASSES.join(' | ')}`);
|
|
92
|
+
}
|
|
93
|
+
if (dimension !== undefined && !exports.DIMENSIONS.includes(dimension)) {
|
|
94
|
+
errors.push(`dimension must be one of ${exports.DIMENSIONS.join(' | ')}`);
|
|
95
|
+
}
|
|
96
|
+
if (verdict !== undefined && !exports.VERDICTS.includes(verdict)) {
|
|
97
|
+
errors.push(`verdict must be one of ${exports.VERDICTS.join(' | ')}`);
|
|
98
|
+
}
|
|
99
|
+
if (level !== undefined && !exports.LEVELS.includes(level)) {
|
|
100
|
+
errors.push(`level must be one of ${exports.LEVELS.join(' | ')}`);
|
|
101
|
+
}
|
|
102
|
+
if (scope !== undefined && !SCOPE_PATTERN.test(scope)) {
|
|
103
|
+
errors.push('scope must be `global`, `file:<path>`, or `pattern:<name>`');
|
|
104
|
+
}
|
|
105
|
+
if (commit !== undefined && !SHORT_SHA.test(commit)) {
|
|
106
|
+
errors.push('commit must be a git SHA (7–40 hex characters)');
|
|
107
|
+
}
|
|
108
|
+
if (date !== undefined && Number.isNaN(Date.parse(date))) {
|
|
109
|
+
errors.push('date must be ISO 8601');
|
|
110
|
+
}
|
|
111
|
+
let rejected;
|
|
112
|
+
if (obj.rejected !== undefined && obj.rejected !== null) {
|
|
113
|
+
if (!Array.isArray(obj.rejected) || obj.rejected.some((r) => typeof r !== 'string')) {
|
|
114
|
+
errors.push('rejected must be an array of strings');
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
rejected = obj.rejected.map((r) => r.trim()).filter(Boolean);
|
|
118
|
+
if (rejected.some((r) => r.includes('\n')))
|
|
119
|
+
errors.push('each rejected item must be a single line');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
let files;
|
|
123
|
+
if (obj.files !== undefined && obj.files !== null) {
|
|
124
|
+
if (!Array.isArray(obj.files) || obj.files.some((f) => typeof f !== 'string')) {
|
|
125
|
+
errors.push('files must be an array of paths');
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
files = obj.files.map((f) => f.trim()).filter(Boolean);
|
|
129
|
+
if (files.some((f) => /[\n·]/.test(f)))
|
|
130
|
+
errors.push('file paths must be single-line and not contain ·');
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
let paths;
|
|
134
|
+
if (obj.paths !== undefined && obj.paths !== null) {
|
|
135
|
+
if (!Array.isArray(obj.paths) || obj.paths.some((f) => typeof f !== 'string')) {
|
|
136
|
+
errors.push('paths must be an array of files or directories');
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
paths = obj.paths.map((f) => f.trim()).filter(Boolean);
|
|
140
|
+
if (paths.some((f) => /[\n·]/.test(f)))
|
|
141
|
+
errors.push('paths must be single-line and not contain ·');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
let expect;
|
|
145
|
+
if (obj.expect !== undefined) {
|
|
146
|
+
const e = obj.expect;
|
|
147
|
+
if (e === null)
|
|
148
|
+
expect = null;
|
|
149
|
+
else if (typeof e !== 'object' || Array.isArray(e))
|
|
150
|
+
errors.push('expect must be an object with present and/or absent arrays');
|
|
151
|
+
else {
|
|
152
|
+
const eo = e;
|
|
153
|
+
const list = (k) => {
|
|
154
|
+
if (eo[k] === undefined)
|
|
155
|
+
return undefined;
|
|
156
|
+
if (!Array.isArray(eo[k]) || eo[k].some((x) => typeof x !== 'string' || !x || /\n/.test(x))) {
|
|
157
|
+
errors.push(`expect.${k} must be an array of non-empty single-line strings`);
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
return eo[k];
|
|
161
|
+
};
|
|
162
|
+
const present = list('present');
|
|
163
|
+
const absent = list('absent');
|
|
164
|
+
for (const k of Object.keys(eo))
|
|
165
|
+
if (k !== 'present' && k !== 'absent')
|
|
166
|
+
errors.push(`unknown expect field: ${k}`);
|
|
167
|
+
expect = { ...(present && { present }), ...(absent && { absent }) };
|
|
168
|
+
if (!present?.length && !absent?.length)
|
|
169
|
+
expect = null;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
let candidate;
|
|
173
|
+
if (obj.candidate !== undefined) {
|
|
174
|
+
if (obj.candidate === null || obj.candidate === '')
|
|
175
|
+
candidate = null;
|
|
176
|
+
else if (typeof obj.candidate !== 'string' || !exports.CANDIDATE_ID.test(obj.candidate.trim()))
|
|
177
|
+
errors.push('candidate must be an id like C-0001, or null');
|
|
178
|
+
else
|
|
179
|
+
candidate = obj.candidate.trim();
|
|
180
|
+
}
|
|
181
|
+
let supersedes;
|
|
182
|
+
if (supersedesRaw === undefined || supersedesRaw === null || supersedesRaw === '') {
|
|
183
|
+
supersedes = supersedesRaw === undefined ? undefined : null;
|
|
184
|
+
}
|
|
185
|
+
else if (typeof supersedesRaw !== 'string' || !exports.DECISION_ID.test(supersedesRaw.trim())) {
|
|
186
|
+
errors.push('supersedes must be a decision id like D-0003, or null');
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
supersedes = supersedesRaw.trim();
|
|
190
|
+
}
|
|
191
|
+
if (supersedes && verdict !== undefined && verdict !== 'rule' && verdict !== 'retire') {
|
|
192
|
+
errors.push('supersedes only applies when verdict is `rule` or `retire`');
|
|
193
|
+
}
|
|
194
|
+
if (verdict === 'retire' && !supersedes)
|
|
195
|
+
errors.push('retire needs supersedes: the rule being retired');
|
|
196
|
+
for (const key of Object.keys(obj)) {
|
|
197
|
+
if (!exports.FIELDS.includes(key) || key === 'verified' || key === 'id')
|
|
198
|
+
errors.push(`unknown field: ${key}`);
|
|
199
|
+
}
|
|
200
|
+
if (errors.length)
|
|
201
|
+
return { ok: false, errors };
|
|
202
|
+
return {
|
|
203
|
+
ok: true,
|
|
204
|
+
value: {
|
|
205
|
+
decision: decision,
|
|
206
|
+
trigger: trigger,
|
|
207
|
+
rationale: rationale,
|
|
208
|
+
scope: scope,
|
|
209
|
+
class: cls,
|
|
210
|
+
dimension: dimension,
|
|
211
|
+
verdict: verdict,
|
|
212
|
+
...(change !== undefined && { change }),
|
|
213
|
+
...(level !== undefined && { level: level }),
|
|
214
|
+
...(rejected !== undefined && { rejected }),
|
|
215
|
+
...(files !== undefined && { files }),
|
|
216
|
+
...(paths !== undefined && { paths }),
|
|
217
|
+
...(expect !== undefined && { expect }),
|
|
218
|
+
...(candidate !== undefined && { candidate }),
|
|
219
|
+
...(author !== undefined && { author }),
|
|
220
|
+
...(commit !== undefined && { commit }),
|
|
221
|
+
...(date !== undefined && { date }),
|
|
222
|
+
...(supersedes !== undefined && { supersedes }),
|
|
223
|
+
...(ref !== undefined && { ref }),
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/** Split a scope into kind + target. `global` has no target. */
|
|
228
|
+
function parseScope(scope) {
|
|
229
|
+
if (scope === 'global')
|
|
230
|
+
return { kind: 'global', target: null };
|
|
231
|
+
const i = scope.indexOf(':');
|
|
232
|
+
return { kind: scope.slice(0, i), target: scope.slice(i + 1) };
|
|
233
|
+
}
|
package/dist/store.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* File I/O for the two decision files and arbiter.json. No other files in the
|
|
4
|
+
* host project are touched from here.
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ACTIVE_CAP = void 0;
|
|
11
|
+
exports.resolvePaths = resolvePaths;
|
|
12
|
+
exports.findRoot = findRoot;
|
|
13
|
+
exports.readConfig = readConfig;
|
|
14
|
+
exports.writeConfig = writeConfig;
|
|
15
|
+
exports.readActive = readActive;
|
|
16
|
+
exports.writeActive = writeActive;
|
|
17
|
+
exports.readArchive = readArchive;
|
|
18
|
+
exports.appendArchive = appendArchive;
|
|
19
|
+
exports.readPending = readPending;
|
|
20
|
+
exports.writePending = writePending;
|
|
21
|
+
exports.nextPendingId = nextPendingId;
|
|
22
|
+
exports.nextId = nextId;
|
|
23
|
+
exports.currentCommit = currentCommit;
|
|
24
|
+
exports.gitUserName = gitUserName;
|
|
25
|
+
exports.now = now;
|
|
26
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
27
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
28
|
+
const node_child_process_1 = require("node:child_process");
|
|
29
|
+
const format_1 = require("./format");
|
|
30
|
+
exports.ACTIVE_CAP = 40;
|
|
31
|
+
function resolvePaths(root = process.cwd()) {
|
|
32
|
+
return {
|
|
33
|
+
root,
|
|
34
|
+
decisions: node_path_1.default.join(root, 'DECISIONS.md'),
|
|
35
|
+
archiveDir: node_path_1.default.join(root, '.arbiter'),
|
|
36
|
+
archive: node_path_1.default.join(root, '.arbiter', 'archive.md'),
|
|
37
|
+
pending: node_path_1.default.join(root, '.arbiter', 'pending.md'),
|
|
38
|
+
config: node_path_1.default.join(root, 'arbiter.json'),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** Walk up from cwd to find the nearest arbiter.json. Falls back to cwd. */
|
|
42
|
+
function findRoot(start = process.cwd()) {
|
|
43
|
+
let dir = node_path_1.default.resolve(start);
|
|
44
|
+
for (;;) {
|
|
45
|
+
if (node_fs_1.default.existsSync(node_path_1.default.join(dir, 'arbiter.json')))
|
|
46
|
+
return dir;
|
|
47
|
+
const parent = node_path_1.default.dirname(dir);
|
|
48
|
+
if (parent === dir)
|
|
49
|
+
return node_path_1.default.resolve(start);
|
|
50
|
+
dir = parent;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function readConfig(paths) {
|
|
54
|
+
if (!node_fs_1.default.existsSync(paths.config))
|
|
55
|
+
return null;
|
|
56
|
+
return JSON.parse(node_fs_1.default.readFileSync(paths.config, 'utf8'));
|
|
57
|
+
}
|
|
58
|
+
function writeConfig(paths, config) {
|
|
59
|
+
node_fs_1.default.writeFileSync(paths.config, JSON.stringify(config, null, 2) + '\n');
|
|
60
|
+
}
|
|
61
|
+
function readActive(paths) {
|
|
62
|
+
if (!node_fs_1.default.existsSync(paths.decisions))
|
|
63
|
+
return [];
|
|
64
|
+
return (0, format_1.parseEntries)(node_fs_1.default.readFileSync(paths.decisions, 'utf8'));
|
|
65
|
+
}
|
|
66
|
+
/** Rewrites DECISIONS.md in full. Entries are re-serialized, so hand edits survive. */
|
|
67
|
+
function writeActive(paths, decisions, cap = exports.ACTIVE_CAP) {
|
|
68
|
+
node_fs_1.default.writeFileSync(paths.decisions, (0, format_1.activeHeader)(decisions.length, cap) + '\n' + (0, format_1.formatGrouped)(decisions));
|
|
69
|
+
}
|
|
70
|
+
function readArchive(paths) {
|
|
71
|
+
if (!node_fs_1.default.existsSync(paths.archive))
|
|
72
|
+
return [];
|
|
73
|
+
return (0, format_1.parseEntries)(node_fs_1.default.readFileSync(paths.archive, 'utf8'));
|
|
74
|
+
}
|
|
75
|
+
/** Append-only. Creates the file with its header on first write. */
|
|
76
|
+
function appendArchive(paths, d) {
|
|
77
|
+
node_fs_1.default.mkdirSync(paths.archiveDir, { recursive: true });
|
|
78
|
+
const exists = node_fs_1.default.existsSync(paths.archive);
|
|
79
|
+
const prefix = exists ? '\n' : (0, format_1.archiveHeader)() + '\n';
|
|
80
|
+
node_fs_1.default.appendFileSync(paths.archive, prefix + (0, format_1.formatEntry)(d));
|
|
81
|
+
}
|
|
82
|
+
function readPending(paths) {
|
|
83
|
+
if (!node_fs_1.default.existsSync(paths.pending))
|
|
84
|
+
return [];
|
|
85
|
+
return (0, format_1.parseEntries)(node_fs_1.default.readFileSync(paths.pending, 'utf8'));
|
|
86
|
+
}
|
|
87
|
+
/** Rewrites pending.md in full. */
|
|
88
|
+
function writePending(paths, decisions) {
|
|
89
|
+
node_fs_1.default.mkdirSync(paths.archiveDir, { recursive: true });
|
|
90
|
+
node_fs_1.default.writeFileSync(paths.pending, (0, format_1.pendingHeader)() + '\n' + decisions.map(format_1.formatEntry).join('\n'));
|
|
91
|
+
}
|
|
92
|
+
/** Next P- id. Pending ids are never reused within the file but may repeat once it empties. */
|
|
93
|
+
function nextPendingId(pending) {
|
|
94
|
+
const max = pending.reduce((m, d) => Math.max(m, Number(d.id.slice(2))), 0);
|
|
95
|
+
return `P-${String(max + 1).padStart(4, '0')}`;
|
|
96
|
+
}
|
|
97
|
+
/** Next sequential id, based on the highest id in the archive. */
|
|
98
|
+
function nextId(archive) {
|
|
99
|
+
const max = archive.reduce((m, d) => Math.max(m, Number(d.id.slice(2))), 0);
|
|
100
|
+
return `D-${String(max + 1).padStart(4, '0')}`;
|
|
101
|
+
}
|
|
102
|
+
/** Short SHA of HEAD, or null if not in a git repo. Never throws. */
|
|
103
|
+
function currentCommit(root) {
|
|
104
|
+
try {
|
|
105
|
+
return (0, node_child_process_1.execFileSync)('git', ['rev-parse', '--short', 'HEAD'], {
|
|
106
|
+
cwd: root,
|
|
107
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
108
|
+
})
|
|
109
|
+
.toString()
|
|
110
|
+
.trim() || null;
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/** git user.name, or null. Never throws. */
|
|
117
|
+
function gitUserName(root) {
|
|
118
|
+
try {
|
|
119
|
+
return (0, node_child_process_1.execFileSync)('git', ['config', 'user.name'], {
|
|
120
|
+
cwd: root,
|
|
121
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
122
|
+
})
|
|
123
|
+
.toString()
|
|
124
|
+
.trim() || null;
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/** Timestamp without milliseconds: 2026-09-15T14:32:10Z */
|
|
131
|
+
function now() {
|
|
132
|
+
return new Date().toISOString().replace(/\.\d{3}Z$/, 'Z');
|
|
133
|
+
}
|