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
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `arbiter rules` — the read verb.
|
|
4
|
+
*
|
|
5
|
+
* arbiter rules active rules, grouped by dimension
|
|
6
|
+
* arbiter rules --dimension x one dimension
|
|
7
|
+
* arbiter rules --archive everything ever: accepts, fixes, superseded, in order
|
|
8
|
+
* arbiter rules --pending queued, not yet judged
|
|
9
|
+
* arbiter rules D-0003 one decision in full, wherever it lives
|
|
10
|
+
* arbiter rules --json any of the above as JSON
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.rules = rules;
|
|
14
|
+
exports.groupByTrigger = groupByTrigger;
|
|
15
|
+
const schema_1 = require("../schema");
|
|
16
|
+
const format_1 = require("../format");
|
|
17
|
+
const store_1 = require("../store");
|
|
18
|
+
function rules(id, opts = {}) {
|
|
19
|
+
const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
|
|
20
|
+
const cap = (0, store_1.readConfig)(paths)?.activeCap ?? store_1.ACTIVE_CAP;
|
|
21
|
+
if (id)
|
|
22
|
+
return one(id, paths, opts.json);
|
|
23
|
+
if (opts.archive)
|
|
24
|
+
return archive((0, store_1.readArchive)(paths), (0, store_1.readActive)(paths), opts);
|
|
25
|
+
if (opts.pending)
|
|
26
|
+
return pendingList((0, store_1.readPending)(paths), opts);
|
|
27
|
+
let active = (0, store_1.readActive)(paths);
|
|
28
|
+
if (opts.dimension) {
|
|
29
|
+
if (!schema_1.DIMENSIONS.includes(opts.dimension)) {
|
|
30
|
+
throw new Error(`unknown dimension: ${opts.dimension} (one of ${schema_1.DIMENSIONS.join(', ')})`);
|
|
31
|
+
}
|
|
32
|
+
active = active.filter((d) => d.dimension === opts.dimension);
|
|
33
|
+
}
|
|
34
|
+
if (opts.json)
|
|
35
|
+
return JSON.stringify({ count: active.length, cap, rules: active }, null, 2);
|
|
36
|
+
if (!active.length)
|
|
37
|
+
return `No active rules${opts.dimension ? ` in ${opts.dimension}` : ''} (0 of ${cap}).`;
|
|
38
|
+
const lines = [`${active.length} of ${cap} active rules`];
|
|
39
|
+
for (const dim of schema_1.DIMENSIONS) {
|
|
40
|
+
const group = active.filter((d) => d.dimension === dim);
|
|
41
|
+
if (!group.length)
|
|
42
|
+
continue;
|
|
43
|
+
lines.push('', format_1.DIMENSION_LABELS[dim]);
|
|
44
|
+
for (const d of group)
|
|
45
|
+
lines.push(...entryLines(d));
|
|
46
|
+
}
|
|
47
|
+
return lines.join('\n');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The queue, as the person judging needs to see it: grouped by the piece
|
|
51
|
+
* of work (trigger), feature and pattern items in full, polish items
|
|
52
|
+
* collapsed to one line each under the group. Each full item reads
|
|
53
|
+
*
|
|
54
|
+
* P-0002 Change The Rescan button on the small Health check card is now just an icon
|
|
55
|
+
* Pattern Half-width cards use icon-only action buttons
|
|
56
|
+
* Rejected A labelled button — wrapped under the text on mobile
|
|
57
|
+
*/
|
|
58
|
+
function pendingList(pending, opts) {
|
|
59
|
+
const groups = groupByTrigger(pending);
|
|
60
|
+
if (opts.json) {
|
|
61
|
+
return JSON.stringify({
|
|
62
|
+
count: pending.length,
|
|
63
|
+
polish: pending.filter((d) => d.level === 'polish').length,
|
|
64
|
+
groups: groups.map((g) => ({ trigger: g.trigger, items: g.items, polish: g.polish })),
|
|
65
|
+
pending,
|
|
66
|
+
}, null, 2);
|
|
67
|
+
}
|
|
68
|
+
if (!pending.length)
|
|
69
|
+
return 'Nothing pending. All caught up.';
|
|
70
|
+
const polish = pending.filter((d) => d.level === 'polish').length;
|
|
71
|
+
const lines = [
|
|
72
|
+
`${pending.length} pending${polish ? ` (${polish} polish)` : ''} — review with \`npx arbiter review\` or /arbiter in chat`,
|
|
73
|
+
];
|
|
74
|
+
for (const g of groups) {
|
|
75
|
+
lines.push('', g.trigger);
|
|
76
|
+
for (const d of g.items)
|
|
77
|
+
lines.push(...reviewLines(d));
|
|
78
|
+
if (g.polish.length) {
|
|
79
|
+
lines.push(` polish · confirm all with \`npx arbiter record --all --level polish --as accept\``);
|
|
80
|
+
for (const d of g.polish)
|
|
81
|
+
lines.push(` ${d.id} ${d.change ?? d.decision}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return lines.join('\n');
|
|
85
|
+
}
|
|
86
|
+
/** Queue order of first appearance; each trigger once. */
|
|
87
|
+
function groupByTrigger(pending) {
|
|
88
|
+
const out = [];
|
|
89
|
+
for (const d of pending) {
|
|
90
|
+
let g = out.find((x) => x.trigger === d.trigger);
|
|
91
|
+
if (!g) {
|
|
92
|
+
g = { trigger: d.trigger, items: [], polish: [] };
|
|
93
|
+
out.push(g);
|
|
94
|
+
}
|
|
95
|
+
(d.level === 'polish' ? g.polish : g.items).push(d);
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
function reviewLines(d) {
|
|
100
|
+
const pad = ' ';
|
|
101
|
+
const lines = [` ${d.id} Change ${d.change ?? d.decision}`];
|
|
102
|
+
if (d.change)
|
|
103
|
+
lines.push(`${pad}Pattern ${d.decision}`);
|
|
104
|
+
for (const r of d.rejected)
|
|
105
|
+
lines.push(`${pad}Rejected ${r}`);
|
|
106
|
+
lines.push(`${pad}${d.level} · ${d.dimension} · ${d.scope}`);
|
|
107
|
+
return lines;
|
|
108
|
+
}
|
|
109
|
+
function one(id, paths, json) {
|
|
110
|
+
if (!schema_1.ID_PATTERN.test(id))
|
|
111
|
+
throw new Error(`not a decision id: ${id} (looks like D-0003 or P-0003)`);
|
|
112
|
+
const all = id.startsWith('P-') ? (0, store_1.readPending)(paths) : (0, store_1.readArchive)(paths);
|
|
113
|
+
const d = all.find((x) => x.id === id);
|
|
114
|
+
if (!d)
|
|
115
|
+
throw new Error(`${id} not found`);
|
|
116
|
+
const activeIds = new Set((0, store_1.readActive)(paths).map((x) => x.id));
|
|
117
|
+
const later = all.find((x) => x.supersedes === id);
|
|
118
|
+
const supersededBy = later?.id ?? null;
|
|
119
|
+
const status = d.verdict !== 'rule' ? d.verdict : activeIds.has(id) ? 'active' : later ? `${later.verdict === 'retire' ? 'retired' : 'superseded'} by ${later.id}` : 'inactive';
|
|
120
|
+
if (json)
|
|
121
|
+
return JSON.stringify({ ...d, status, supersededBy }, null, 2);
|
|
122
|
+
return `${(0, format_1.formatEntry)(d).trimEnd()}\n- **Status:** ${status}`;
|
|
123
|
+
}
|
|
124
|
+
function archive(all, active, opts) {
|
|
125
|
+
const activeIds = new Set(active.map((d) => d.id));
|
|
126
|
+
const later = new Map(all.filter((d) => d.supersedes).map((d) => [d.supersedes, d]));
|
|
127
|
+
const status = (d) => {
|
|
128
|
+
if (d.verdict !== 'rule')
|
|
129
|
+
return d.verdict;
|
|
130
|
+
if (activeIds.has(d.id))
|
|
131
|
+
return 'rule · active';
|
|
132
|
+
const l = later.get(d.id);
|
|
133
|
+
return l ? `rule · ${l.verdict === 'retire' ? 'retired' : 'superseded'} by ${l.id}` : 'rule · inactive';
|
|
134
|
+
};
|
|
135
|
+
if (opts.json)
|
|
136
|
+
return JSON.stringify({ count: all.length, decisions: all.map((d) => ({ ...d, status: status(d) })) }, null, 2);
|
|
137
|
+
if (!all.length)
|
|
138
|
+
return 'No decisions recorded yet.';
|
|
139
|
+
const lines = [`${all.length} decisions, oldest first`];
|
|
140
|
+
for (const d of all) {
|
|
141
|
+
lines.push('', `${d.id} ${d.decision}`, ` ${status(d)} · ${d.dimension} · ${d.scope} · ${d.author} · ${d.date.slice(0, 10)}`);
|
|
142
|
+
}
|
|
143
|
+
return lines.join('\n');
|
|
144
|
+
}
|
|
145
|
+
function entryLines(d) {
|
|
146
|
+
return [
|
|
147
|
+
` ${d.id} ${d.decision}`,
|
|
148
|
+
` ${d.rationale}`,
|
|
149
|
+
...d.rejected.map((r) => ` ✗ ${r}`),
|
|
150
|
+
` ${d.scope} · ${d.class} · ${d.author} · ${d.date.slice(0, 10)}`,
|
|
151
|
+
];
|
|
152
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `arbiter snapshot "<piece of work>" --file shot.png` — a picture for a piece of work that
|
|
4
|
+
* isn't a candidate. Named the way the decisions named it (`trigger`); case and punctuation
|
|
5
|
+
* don't matter. Publish carries it to the board's card for that work.
|
|
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.snapshotWork = snapshotWork;
|
|
12
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
13
|
+
const store_1 = require("../store");
|
|
14
|
+
const work_1 = require("../work");
|
|
15
|
+
function snapshotWork(name, opts) {
|
|
16
|
+
const root = (0, store_1.findRoot)(opts.cwd);
|
|
17
|
+
const paths = (0, store_1.resolvePaths)(root);
|
|
18
|
+
const trigger = name.trim();
|
|
19
|
+
if (!trigger)
|
|
20
|
+
return { exitCode: 1, output: { status: 'invalid', errors: ['name the piece of work, as the decisions did: arbiter snapshot "Settings build" --file shot.png'] } };
|
|
21
|
+
if (!opts.file && !opts.capture)
|
|
22
|
+
return { exitCode: 1, output: { status: 'invalid', errors: ['pass --file <image> or --capture'] } };
|
|
23
|
+
const id = (0, work_1.workId)(trigger);
|
|
24
|
+
const known = [...(0, store_1.readArchive)(paths), ...(0, store_1.readPending)(paths)].some((d) => (0, work_1.workId)(d.trigger) === id);
|
|
25
|
+
const r = opts.capture ? (0, work_1.captureImage)((0, work_1.workDir)(paths), id) : (0, work_1.copyImage)(root, (0, work_1.workDir)(paths), id, opts.file);
|
|
26
|
+
if (!r.ok)
|
|
27
|
+
return { exitCode: 1, output: { status: 'failed', error: r.error } };
|
|
28
|
+
return {
|
|
29
|
+
exitCode: 0,
|
|
30
|
+
output: { status: 'saved', work: trigger, id, file: node_path_1.default.relative(root, node_path_1.default.join((0, work_1.workDir)(paths), r.file)), ...(known ? {} : { note: `no decisions mention "${trigger}" yet — the picture shows once some do` }) },
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `arbiter sweep <rule-id>` — find existing violations of a mechanical rule.
|
|
4
|
+
* Prints them; never edits. `--queue` turns each affected file into a pending
|
|
5
|
+
* decision so the reviewer can confirm (accept the exception) or fix.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.sweepCommand = sweepCommand;
|
|
9
|
+
const store_1 = require("../store");
|
|
10
|
+
const sweep_1 = require("../sweep");
|
|
11
|
+
function sweepCommand(id, opts = {}) {
|
|
12
|
+
const root = (0, store_1.findRoot)(opts.cwd);
|
|
13
|
+
const paths = (0, store_1.resolvePaths)(root);
|
|
14
|
+
const rule = [...(0, store_1.readActive)(paths), ...(0, store_1.readArchive)(paths)].find((d) => d.id === id);
|
|
15
|
+
if (!rule)
|
|
16
|
+
throw new Error(`${id} not found`);
|
|
17
|
+
const result = (0, sweep_1.sweep)(root, rule, { exclude: (0, store_1.readConfig)(paths)?.sweep?.exclude });
|
|
18
|
+
const sum = (0, sweep_1.summarize)(result);
|
|
19
|
+
const byFile = new Map();
|
|
20
|
+
for (const v of result.violations)
|
|
21
|
+
byFile.set(v.file, [...(byFile.get(v.file) ?? []), v]);
|
|
22
|
+
const queued = [];
|
|
23
|
+
if (opts.queue && result.violations.length) {
|
|
24
|
+
const pending = (0, store_1.readPending)(paths);
|
|
25
|
+
const seen = new Set(pending.map((d) => d.trigger));
|
|
26
|
+
for (const [file, vs] of byFile) {
|
|
27
|
+
const trigger = `sweep ${rule.id}: ${vs.length} violation${vs.length === 1 ? '' : 's'} in ${file}`;
|
|
28
|
+
if (seen.has(trigger))
|
|
29
|
+
continue;
|
|
30
|
+
const entry = {
|
|
31
|
+
id: (0, store_1.nextPendingId)(pending),
|
|
32
|
+
date: (0, store_1.now)(),
|
|
33
|
+
author: opts.author ?? rule.author,
|
|
34
|
+
class: 'mechanical',
|
|
35
|
+
change: null,
|
|
36
|
+
level: 'polish',
|
|
37
|
+
dimension: rule.dimension,
|
|
38
|
+
decision: rule.decision,
|
|
39
|
+
rejected: [],
|
|
40
|
+
trigger,
|
|
41
|
+
verdict: 'pending',
|
|
42
|
+
scope: `file:${file}`,
|
|
43
|
+
rationale: `${rule.id} applies here. Confirm to allow this file as an exception; fix to bring it in line.`,
|
|
44
|
+
supersedes: null,
|
|
45
|
+
ref: null,
|
|
46
|
+
commit: (0, store_1.currentCommit)(root),
|
|
47
|
+
files: [file],
|
|
48
|
+
paths: [],
|
|
49
|
+
expect: rule.expect,
|
|
50
|
+
verified: false,
|
|
51
|
+
candidate: null,
|
|
52
|
+
};
|
|
53
|
+
pending.push(entry);
|
|
54
|
+
queued.push(entry.id);
|
|
55
|
+
}
|
|
56
|
+
(0, store_1.writePending)(paths, pending);
|
|
57
|
+
}
|
|
58
|
+
if (opts.json)
|
|
59
|
+
return { text: JSON.stringify({ rule: { id: rule.id, decision: rule.decision }, ...result, summary: sum, queued }, null, 2), result, queued };
|
|
60
|
+
const lines = [`${rule.id} · ${rule.decision}`];
|
|
61
|
+
if (!result.sweepable) {
|
|
62
|
+
lines.push(`Cannot sweep: ${result.reason}.`);
|
|
63
|
+
return { text: lines.join('\n'), result, queued };
|
|
64
|
+
}
|
|
65
|
+
lines.push(`Searched ${result.filesScanned} file${result.filesScanned === 1 ? '' : 's'} for ${result.needles.map((n) => `"${n}"`).join(', ')}.`);
|
|
66
|
+
if (!result.violations.length) {
|
|
67
|
+
lines.push('No existing violations.');
|
|
68
|
+
return { text: lines.join('\n'), result, queued };
|
|
69
|
+
}
|
|
70
|
+
lines.push(`Found ${sum.violations} violation${sum.violations === 1 ? '' : 's'} across ${sum.files} file${sum.files === 1 ? '' : 's'}:`, '');
|
|
71
|
+
if (result.scanned === 'project' && sum.files > 10) {
|
|
72
|
+
lines.push(` (swept the whole project — too wide? give the rule "paths": ["app/components"], or add "sweep": { "exclude": ["app/globals.css", "docs/**"] } to arbiter.json)`, '');
|
|
73
|
+
}
|
|
74
|
+
for (const [file, vs] of byFile) {
|
|
75
|
+
lines.push(` ${file}`);
|
|
76
|
+
for (const v of vs.slice(0, 5))
|
|
77
|
+
lines.push(` ${String(v.line).padStart(4)} ${v.text}`);
|
|
78
|
+
if (vs.length > 5)
|
|
79
|
+
lines.push(` … ${vs.length - 5} more`);
|
|
80
|
+
}
|
|
81
|
+
lines.push('');
|
|
82
|
+
if (queued.length)
|
|
83
|
+
lines.push(`Queued ${queued.length} for review (${queued.join(', ')}) — npx arbiter review`);
|
|
84
|
+
else
|
|
85
|
+
lines.push('Fix now (ask the agent), queue for review (--queue), or ignore.');
|
|
86
|
+
return { text: lines.join('\n'), result, queued };
|
|
87
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** `arbiter verify [id]` — re-check a decision's claim against its files now. No id: every active rule that carries evidence. */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.verifyCommand = verifyCommand;
|
|
5
|
+
const store_1 = require("../store");
|
|
6
|
+
const verify_1 = require("../verify");
|
|
7
|
+
function verifyCommand(id, opts = {}) {
|
|
8
|
+
const root = (0, store_1.findRoot)(opts.cwd);
|
|
9
|
+
const paths = (0, store_1.resolvePaths)(root);
|
|
10
|
+
let targets;
|
|
11
|
+
if (id) {
|
|
12
|
+
const d = [...(0, store_1.readActive)(paths), ...(0, store_1.readArchive)(paths), ...(0, store_1.readPending)(paths)].find((x) => x.id === id);
|
|
13
|
+
if (!d)
|
|
14
|
+
throw new Error(`${id} not found`);
|
|
15
|
+
targets = [d];
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
targets = (0, store_1.readActive)(paths).filter((d) => (0, verify_1.checkable)(d.files, d.expect));
|
|
19
|
+
}
|
|
20
|
+
const results = targets.map((d) => ({ id: d.id, decision: d.decision, files: d.files, result: (0, verify_1.checkable)(d.files, d.expect) ? (0, verify_1.verify)(root, d.files, d.expect) : null }));
|
|
21
|
+
const ok = results.every((r) => r.result === null || r.result.ok);
|
|
22
|
+
if (opts.json)
|
|
23
|
+
return { text: JSON.stringify({ ok, results }, null, 2), ok };
|
|
24
|
+
if (!results.length)
|
|
25
|
+
return { text: 'Nothing to verify — no active rules carry files or expectations.', ok: true };
|
|
26
|
+
const lines = [];
|
|
27
|
+
for (const r of results) {
|
|
28
|
+
if (!r.result) {
|
|
29
|
+
lines.push(`${r.id} ${r.decision}`, ' not checkable — no files or expectations');
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
lines.push(`${r.result.ok ? '✓' : '✗'} ${r.id} ${r.decision}`);
|
|
33
|
+
for (const c of r.result.checks) {
|
|
34
|
+
if (c.ok && r.result.ok)
|
|
35
|
+
continue; // quiet when everything passes
|
|
36
|
+
lines.push(` ${c.ok ? '✓' : '✗'} ${c.kind}${c.needle ? ` "${c.needle}"` : ''} — ${c.file}${c.detail ? ` (${c.detail})` : ''}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
lines.push('', ok ? 'All claims hold.' : 'Contradictions found. Fix the code, or record an accept for the exception.');
|
|
40
|
+
return { text: lines.join('\n'), ok };
|
|
41
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Destination adapter. Capture and record are identical everywhere; only
|
|
4
|
+
* delivery differs.
|
|
5
|
+
*
|
|
6
|
+
* local — files in .arbiter/candidates/. Nothing else.
|
|
7
|
+
* git — also a CANDIDATES.md index at the root, the export page under
|
|
8
|
+
* docs/arbiter/ for GitHub Pages, and a commit of all of it so
|
|
9
|
+
* GitHub renders and serves them. Never pushes. Prints the links
|
|
10
|
+
* that will work once the branch is pushed.
|
|
11
|
+
*/
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.DEFAULT_PAGES_DIR = void 0;
|
|
17
|
+
exports.deliver = deliver;
|
|
18
|
+
exports.pagesUrl = pagesUrl;
|
|
19
|
+
exports.writeIndex = writeIndex;
|
|
20
|
+
exports.linkFor = linkFor;
|
|
21
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
22
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
23
|
+
const node_child_process_1 = require("node:child_process");
|
|
24
|
+
const candidates_1 = require("./candidates");
|
|
25
|
+
const export_1 = require("./commands/export");
|
|
26
|
+
exports.DEFAULT_PAGES_DIR = 'docs/arbiter';
|
|
27
|
+
function deliver(paths, config, changed, message) {
|
|
28
|
+
const destination = config?.destination ?? 'local';
|
|
29
|
+
if (destination !== 'git')
|
|
30
|
+
return { destination: 'local' };
|
|
31
|
+
writeIndex(paths);
|
|
32
|
+
const root = paths.root;
|
|
33
|
+
const pagesDir = config?.pages === false ? null : node_path_1.default.resolve(root, config?.pages?.dir ?? exports.DEFAULT_PAGES_DIR);
|
|
34
|
+
if (pagesDir)
|
|
35
|
+
(0, export_1.exportBoard)({ cwd: root, out: pagesDir, includeRules: config?.pages && config.pages.includeRules });
|
|
36
|
+
if (!git(root, ['rev-parse', '--is-inside-work-tree'])) {
|
|
37
|
+
return { destination, committed: null, warning: 'destination is git but this is not a git repository — files written, nothing committed' };
|
|
38
|
+
}
|
|
39
|
+
const rel = (p) => node_path_1.default.relative(root, p);
|
|
40
|
+
git(root, ['add', '--', rel((0, candidates_1.candidatesDir)(paths)), 'CANDIDATES.md', ...(pagesDir ? [rel(pagesDir)] : [])]);
|
|
41
|
+
const staged = git(root, ['diff', '--cached', '--name-only']);
|
|
42
|
+
let committed = null;
|
|
43
|
+
if (staged) {
|
|
44
|
+
git(root, ['commit', '-q', '-m', `arbiter: ${message}`]);
|
|
45
|
+
committed = git(root, ['rev-parse', '--short', 'HEAD']);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
destination,
|
|
49
|
+
committed,
|
|
50
|
+
links: changed.map((c) => linkFor(root, config, c.id)).filter((l) => !!l),
|
|
51
|
+
pages: pagesDir ? pagesUrl(root, config) : null,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Where GitHub Pages will serve the export, if Pages is pointed at docs/ and origin is GitHub. */
|
|
55
|
+
function pagesUrl(root, config) {
|
|
56
|
+
if (config?.destination !== 'git' || config.pages === false)
|
|
57
|
+
return null;
|
|
58
|
+
const remote = git(root, ['remote', 'get-url', 'origin']);
|
|
59
|
+
const m = remote && /github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?$/.exec(remote);
|
|
60
|
+
if (!m)
|
|
61
|
+
return null;
|
|
62
|
+
const dir = (config.pages?.dir ?? exports.DEFAULT_PAGES_DIR).replace(/\\/g, '/').replace(/\/+$/, '');
|
|
63
|
+
const sub = dir.startsWith('docs/') ? dir.slice(5) : dir === 'docs' ? '' : dir;
|
|
64
|
+
return `https://${m[1].toLowerCase()}.github.io/${m[2]}/${sub ? sub + '/' : ''}`;
|
|
65
|
+
}
|
|
66
|
+
/** Root-level index GitHub renders: every candidate, by feature, linking to its page. */
|
|
67
|
+
function writeIndex(paths) {
|
|
68
|
+
const all = (0, candidates_1.readCandidates)(paths);
|
|
69
|
+
const features = [...new Set(all.map((c) => c.feature ?? '—'))];
|
|
70
|
+
const lines = ['# Candidates', '', 'Generated screens and their state. Managed by `arbiter` — each row links to the candidate page with its snapshot, decisions, and reasoning.', ''];
|
|
71
|
+
for (const f of features) {
|
|
72
|
+
lines.push(`## ${f}`, '', '| Id | Name | State | Author | Date |', '|---|---|---|---|---|');
|
|
73
|
+
for (const c of all.filter((c) => (c.feature ?? '—') === f)) {
|
|
74
|
+
const state = c.state === 'superseded' ? `superseded → ${c.supersededBy}` : c.state.replace('_', ' ');
|
|
75
|
+
lines.push(`| [${c.id}](.arbiter/candidates/${c.id}.md) | ${c.name} | ${state} | ${c.author} | ${c.date.slice(0, 10)} |`);
|
|
76
|
+
}
|
|
77
|
+
lines.push('');
|
|
78
|
+
}
|
|
79
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(paths.root, 'CANDIDATES.md'), lines.join('\n'));
|
|
80
|
+
}
|
|
81
|
+
/** GitHub URL for a candidate page, if the origin remote is GitHub. */
|
|
82
|
+
function linkFor(root, config, id) {
|
|
83
|
+
if (config?.destination !== 'git')
|
|
84
|
+
return null;
|
|
85
|
+
const remote = git(root, ['remote', 'get-url', 'origin']);
|
|
86
|
+
const branch = git(root, ['rev-parse', '--abbrev-ref', 'HEAD']) || 'main';
|
|
87
|
+
const m = remote && /github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?$/.exec(remote);
|
|
88
|
+
if (!m)
|
|
89
|
+
return null;
|
|
90
|
+
return `https://github.com/${m[1]}/${m[2]}/blob/${branch}/.arbiter/candidates/${id}.md`;
|
|
91
|
+
}
|
|
92
|
+
function git(root, args) {
|
|
93
|
+
try {
|
|
94
|
+
return (0, node_child_process_1.execFileSync)('git', args, { cwd: root, stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim() || null;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
package/dist/findings.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* External findings adapter. A design-drift scanner ran and wrote JSON; we
|
|
4
|
+
* turn each finding into a pending decision so a human attaches a verdict
|
|
5
|
+
* instead of the finding being silently ignored. Detection is never
|
|
6
|
+
* implemented here — findings are input, never output.
|
|
7
|
+
*
|
|
8
|
+
* Accepted shapes (best effort):
|
|
9
|
+
* ESLint: [{ filePath, messages: [{ ruleId, message, line, fix? }] }]
|
|
10
|
+
* Flat: [{ file|path|filePath, line?, rule|ruleId|id?, message|msg|description, suggestion|fix|replacement? }]
|
|
11
|
+
* Wrapped: { findings|results|issues: [ ...either of the above ] }
|
|
12
|
+
*/
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.parseFindings = parseFindings;
|
|
18
|
+
exports.toDecisionInput = toDecisionInput;
|
|
19
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
20
|
+
function parseFindings(raw) {
|
|
21
|
+
let list = raw;
|
|
22
|
+
if (list && typeof list === 'object' && !Array.isArray(list)) {
|
|
23
|
+
const o = list;
|
|
24
|
+
list = o.findings ?? o.results ?? o.issues ?? o.violations ?? [];
|
|
25
|
+
}
|
|
26
|
+
if (!Array.isArray(list))
|
|
27
|
+
return [];
|
|
28
|
+
const out = [];
|
|
29
|
+
for (const item of list) {
|
|
30
|
+
if (!item || typeof item !== 'object')
|
|
31
|
+
continue;
|
|
32
|
+
const o = item;
|
|
33
|
+
const file = str(o.file ?? o.path ?? o.filePath ?? o.filename);
|
|
34
|
+
if (!file)
|
|
35
|
+
continue;
|
|
36
|
+
if (Array.isArray(o.messages)) {
|
|
37
|
+
// ESLint-style: one entry per message.
|
|
38
|
+
for (const m of o.messages) {
|
|
39
|
+
const message = str(m.message);
|
|
40
|
+
if (!message)
|
|
41
|
+
continue;
|
|
42
|
+
out.push({ file, line: num(m.line), rule: str(m.ruleId ?? m.rule), message, suggestion: str(m.suggestion ?? m.replacement ?? m.fix?.text) });
|
|
43
|
+
}
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const message = str(o.message ?? o.msg ?? o.description ?? o.text);
|
|
47
|
+
if (!message)
|
|
48
|
+
continue;
|
|
49
|
+
out.push({ file, line: num(o.line), rule: str(o.rule ?? o.ruleId ?? o.id ?? o.code), message, suggestion: str(o.suggestion ?? o.fix ?? o.replacement ?? o.expected) });
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
/** Turn a finding into the decision the reviewer will judge. */
|
|
54
|
+
function toDecisionInput(f, root, tool) {
|
|
55
|
+
const rel = node_path_1.default.isAbsolute(f.file) ? node_path_1.default.relative(root, f.file) : f.file;
|
|
56
|
+
const where = f.line ? `${rel}:${f.line}` : rel;
|
|
57
|
+
return {
|
|
58
|
+
decision: f.suggestion ? f.suggestion : f.message,
|
|
59
|
+
rationale: `${tool} flagged: ${f.message}`,
|
|
60
|
+
rejected: [],
|
|
61
|
+
trigger: `finding${f.rule ? ` ${f.rule}` : ''} at ${where}`,
|
|
62
|
+
scope: `file:${rel}`,
|
|
63
|
+
dimension: 'visual',
|
|
64
|
+
class: 'mechanical',
|
|
65
|
+
verdict: 'rule',
|
|
66
|
+
files: [rel],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const str = (v) => (typeof v === 'string' && v.trim() ? v.trim() : null);
|
|
70
|
+
const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : null);
|