arbiterdesign 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -9
- package/dist/commands/export.js +9 -6
- package/dist/commands/init.js +4 -0
- package/dist/commands/publish.js +12 -1
- package/dist/commands/pull.js +25 -4
- package/dist/commands/record.js +80 -14
- package/dist/commands/remove.js +17 -1
- package/dist/commands/request.js +123 -0
- package/dist/commands/review.js +91 -8
- package/dist/commands/rules.js +61 -7
- package/dist/commands/setup.js +39 -2
- package/dist/commands/snapshot.js +12 -5
- package/dist/findings.js +10 -1
- package/dist/format.js +17 -10
- package/dist/hosted.js +60 -13
- package/dist/index.js +20 -8
- package/dist/pictures.js +52 -0
- package/dist/requests.js +194 -0
- package/dist/store.js +9 -0
- package/package.json +1 -1
- package/templates/SKILL.md +162 -26
- package/templates/review.html +114 -4
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Answering a request from the board.
|
|
4
|
+
*
|
|
5
|
+
* record R-0001 --as apply Apply — the agent makes the change as asked
|
|
6
|
+
* record R-0001 --as apply --to "…" Apply, but… — the agent does this instead
|
|
7
|
+
* record R-0001 --as decline --why "…" Decline — the requester reads the reason on the board
|
|
8
|
+
*
|
|
9
|
+
* Approving changes no code; only the agent can do that. It marks the request so the agent makes
|
|
10
|
+
* the change — right away in chat, or at the next /arbiter when it was approved from the review
|
|
11
|
+
* page. Recording that change with `record '<json>' --request R-0001` is what applies it, and
|
|
12
|
+
* only an approved request can be applied.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.judgeRequest = judgeRequest;
|
|
16
|
+
exports.requestGate = requestGate;
|
|
17
|
+
exports.withRequest = withRequest;
|
|
18
|
+
exports.markApplied = markApplied;
|
|
19
|
+
const store_1 = require("../store");
|
|
20
|
+
const requests_1 = require("../requests");
|
|
21
|
+
const candidates_1 = require("../candidates");
|
|
22
|
+
const fail = (errors) => ({ exitCode: 1, output: { status: 'invalid', errors } });
|
|
23
|
+
function judgeRequest(id, opts) {
|
|
24
|
+
if (!requests_1.REQUEST_ID.test(id))
|
|
25
|
+
return fail([`not a request id: ${id} (looks like R-0001)`]);
|
|
26
|
+
const root = (0, store_1.findRoot)(opts.cwd);
|
|
27
|
+
const paths = (0, store_1.resolvePaths)(root);
|
|
28
|
+
const all = (0, requests_1.readRequests)(paths);
|
|
29
|
+
const found = (0, requests_1.findRequest)(all, id);
|
|
30
|
+
if (found.error)
|
|
31
|
+
return fail([found.error]);
|
|
32
|
+
const r = found.request;
|
|
33
|
+
if (!r)
|
|
34
|
+
return fail([`${id} is not a request here — npx arbiter rules --pending lists them`]);
|
|
35
|
+
if (r.status === 'applied')
|
|
36
|
+
return fail([`${id} was already applied (${r.decisions.join(', ')}). To undo that, it's a new change — and a new decision.`]);
|
|
37
|
+
const by = opts.author ?? (0, store_1.currentAuthor)(root);
|
|
38
|
+
let next;
|
|
39
|
+
if (opts.as === 'decline') {
|
|
40
|
+
if (opts.to)
|
|
41
|
+
return fail(['--to is for Apply, but…; a decline takes --why "<reason>"']);
|
|
42
|
+
const why = opts.why?.trim();
|
|
43
|
+
if (!why)
|
|
44
|
+
return fail([`decline needs --why "<reason>" — ${r.author} reads it on the board`]);
|
|
45
|
+
next = { ...r, status: 'declined', reason: (0, requests_1.oneLine)(why), instead: null, judgedBy: by, judgedAt: (0, store_1.now)() };
|
|
46
|
+
}
|
|
47
|
+
else if (opts.as === 'apply') {
|
|
48
|
+
if (opts.why)
|
|
49
|
+
return fail(['--why is for decline; Apply, but… is --to "<what to do instead>"']);
|
|
50
|
+
const instead = opts.to?.trim() ? (0, requests_1.oneLine)(opts.to) : null;
|
|
51
|
+
// A decline can be taken back: the owner changed their mind, and the board says so.
|
|
52
|
+
next = { ...r, status: 'approved', instead, reason: null, judgedBy: by, judgedAt: (0, store_1.now)() };
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return fail(['a request is answered with --as apply | decline']);
|
|
56
|
+
}
|
|
57
|
+
if (!opts.dryRun)
|
|
58
|
+
(0, requests_1.replaceRequest)(paths, all, next);
|
|
59
|
+
const name = (0, requests_1.screenName)(paths, r.screen);
|
|
60
|
+
return {
|
|
61
|
+
exitCode: 0,
|
|
62
|
+
output: {
|
|
63
|
+
status: next.status,
|
|
64
|
+
id,
|
|
65
|
+
author: r.author,
|
|
66
|
+
asked: r.body,
|
|
67
|
+
screen: r.screen,
|
|
68
|
+
screenName: name,
|
|
69
|
+
...(next.status === 'approved'
|
|
70
|
+
? {
|
|
71
|
+
...(next.instead && { instead: next.instead }),
|
|
72
|
+
// What the agent is to do, whichever way it was approved.
|
|
73
|
+
do: next.instead ?? r.body,
|
|
74
|
+
next: `Make the change, then record it: npx arbiter record '<json>' --request ${id}${name ? ` — trigger "${name}"` : ''}`,
|
|
75
|
+
}
|
|
76
|
+
: { reason: next.reason, next: `${r.author} sees this on the board once it's published` }),
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Before a change is recorded against a request: the request exists, and the owner said yes.
|
|
82
|
+
* Returns what the record should carry, or why it can't.
|
|
83
|
+
*/
|
|
84
|
+
function requestGate(paths, id) {
|
|
85
|
+
if (!requests_1.REQUEST_ID.test(id))
|
|
86
|
+
return { ok: false, errors: [`--request takes a request id like R-0001, not ${id}`] };
|
|
87
|
+
const found = (0, requests_1.findRequest)((0, requests_1.readRequests)(paths), id);
|
|
88
|
+
if (found.error)
|
|
89
|
+
return { ok: false, errors: [found.error] };
|
|
90
|
+
const r = found.request;
|
|
91
|
+
if (!r)
|
|
92
|
+
return { ok: false, errors: [`${id} is not a request here`] };
|
|
93
|
+
// No command in these: the answer is the owner's, so the way forward is to ask them.
|
|
94
|
+
if (r.status === 'open')
|
|
95
|
+
return { ok: false, errors: [`${id} hasn't been answered. Ask the owner whether to apply it; don't make it until they say yes.`] };
|
|
96
|
+
if (r.status === 'declined')
|
|
97
|
+
return { ok: false, errors: [`${id} was declined (${r.reason}). Only the owner can change that; ask them.`] };
|
|
98
|
+
return { ok: true, request: r };
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* What a change made for a request carries without being told: the screen it was asked on, and —
|
|
102
|
+
* when the owner applied it differently — the ask itself, as the alternative that lost.
|
|
103
|
+
*/
|
|
104
|
+
function withRequest(paths, input, r) {
|
|
105
|
+
const out = { ...input };
|
|
106
|
+
// Not given, or given as none (a queued item carries `candidate: null`): the screen it was asked on.
|
|
107
|
+
if (!out.candidate && r.screen.startsWith('C-') && (0, candidates_1.readCandidates)(paths).some((c) => c.id === r.screen))
|
|
108
|
+
out.candidate = r.screen;
|
|
109
|
+
if (r.instead) {
|
|
110
|
+
const asked = (0, requests_1.oneLine)(r.body);
|
|
111
|
+
const rejected = out.rejected ?? [];
|
|
112
|
+
// Added after the input was checked, so it's made one line here: both parts came from the board.
|
|
113
|
+
if (!rejected.some((x) => x.includes(asked)))
|
|
114
|
+
out.rejected = [`${asked} — ${(0, requests_1.oneLine)(r.author)}'s request, applied differently`, ...rejected];
|
|
115
|
+
}
|
|
116
|
+
return out;
|
|
117
|
+
}
|
|
118
|
+
/** After the change is recorded: link it, and the request is applied. */
|
|
119
|
+
function markApplied(paths, request, decisionId) {
|
|
120
|
+
const all = (0, requests_1.readRequests)(paths);
|
|
121
|
+
const r = all.find((x) => x.comment === request.comment) ?? request;
|
|
122
|
+
(0, requests_1.replaceRequest)(paths, all, { ...r, status: 'applied', decisions: [...new Set([...r.decisions, decisionId])], appliedAt: r.appliedAt ?? (0, store_1.now)() });
|
|
123
|
+
}
|
package/dist/commands/review.js
CHANGED
|
@@ -11,6 +11,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.review = review;
|
|
14
|
+
exports.fromHere = fromHere;
|
|
14
15
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
15
16
|
const node_http_1 = __importDefault(require("node:http"));
|
|
16
17
|
const node_path_1 = __importDefault(require("node:path"));
|
|
@@ -21,6 +22,10 @@ const candidates_1 = require("../candidates");
|
|
|
21
22
|
const hosted_1 = require("../hosted");
|
|
22
23
|
const store_1 = require("../store");
|
|
23
24
|
const autopublish_1 = require("../autopublish");
|
|
25
|
+
const pictures_1 = require("../pictures");
|
|
26
|
+
const requests_1 = require("../requests");
|
|
27
|
+
const work_1 = require("../work");
|
|
28
|
+
const request_1 = require("./request");
|
|
24
29
|
const PAGE = node_path_1.default.join(__dirname, '..', '..', 'templates', 'review.html');
|
|
25
30
|
function review(opts = {}) {
|
|
26
31
|
const root = (0, store_1.findRoot)(opts.cwd);
|
|
@@ -35,12 +40,30 @@ function review(opts = {}) {
|
|
|
35
40
|
comments: comments.filter((x) => x.candidate_id === c.id),
|
|
36
41
|
}));
|
|
37
42
|
const byId = new Map(candidates.map((c) => [c.id, c]));
|
|
43
|
+
const version = (0, hosted_1.readLinkOrNull)(paths)?.boardVersion ?? null;
|
|
44
|
+
const archive = (0, store_1.readArchive)(paths);
|
|
45
|
+
// The card a request was made on: its picture, a candidate's or a piece of work's.
|
|
46
|
+
const shotOf = (screen) => {
|
|
47
|
+
if (screen.startsWith('C-'))
|
|
48
|
+
return byId.get(screen)?.snapshotUrl ?? null;
|
|
49
|
+
const f = (0, work_1.workSnapshot)(paths, screen);
|
|
50
|
+
return f ? `/snapshots/${node_path_1.default.basename(f)}` : null;
|
|
51
|
+
};
|
|
38
52
|
return {
|
|
39
53
|
project: node_path_1.default.basename(root),
|
|
40
|
-
pending: (0, store_1.readPending)(paths).map((d) => ({
|
|
54
|
+
pending: (0, store_1.readPending)(paths).map((d) => ({
|
|
55
|
+
...d,
|
|
56
|
+
candidateName: d.candidate ? byId.get(d.candidate)?.name ?? null : null,
|
|
57
|
+
snapshotUrl: d.candidate ? byId.get(d.candidate)?.snapshotUrl ?? null : null,
|
|
58
|
+
picture: (0, pictures_1.missingPictures)(paths, [d], candidates)[0] ?? null,
|
|
59
|
+
})),
|
|
60
|
+
// Open ones to answer; approved ones waiting on the agent — shown so it's clear nothing is lost.
|
|
61
|
+
requests: (0, requests_1.readRequests)(paths)
|
|
62
|
+
.filter((r) => r.status === 'open' || r.status === 'approved')
|
|
63
|
+
.map((r) => ({ ...(0, requests_1.describe)(paths, r, version, archive), snapshotUrl: shotOf(r.screen) })),
|
|
41
64
|
candidates,
|
|
42
|
-
hosted: (0, hosted_1.
|
|
43
|
-
boardVersion: (0, hosted_1.
|
|
65
|
+
hosted: (0, hosted_1.readLinkOrNull)(paths)?.shareUrl ?? null,
|
|
66
|
+
boardVersion: (0, hosted_1.readLinkOrNull)(paths)?.boardVersion ?? null,
|
|
44
67
|
active: (0, store_1.readActive)(paths).length,
|
|
45
68
|
cap: (0, store_1.readConfig)(paths)?.activeCap ?? store_1.ACTIVE_CAP,
|
|
46
69
|
};
|
|
@@ -50,12 +73,39 @@ function review(opts = {}) {
|
|
|
50
73
|
let changed = false;
|
|
51
74
|
return new Promise((resolve) => {
|
|
52
75
|
const server = node_http_1.default.createServer(async (req, res) => {
|
|
76
|
+
try {
|
|
77
|
+
await handle(req, res);
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
// A broken requests.json, say: the page shows the message instead of the server dying.
|
|
81
|
+
if (!res.headersSent)
|
|
82
|
+
json(res, 500, { exitCode: 1, errors: [e.message] });
|
|
83
|
+
else
|
|
84
|
+
res.end();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
const handle = async (req, res) => {
|
|
88
|
+
// This machine, by its own name, and nothing else. A site that points a domain of its own at
|
|
89
|
+
// 127.0.0.1 (DNS rebinding) is same-origin to the browser, so the JSON check below can't stop
|
|
90
|
+
// it, but its requests carry that domain as their Host.
|
|
91
|
+
if (!fromHere(req)) {
|
|
92
|
+
res.writeHead(403);
|
|
93
|
+
res.end();
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
53
96
|
const url = new URL(req.url ?? '/', 'http://127.0.0.1');
|
|
54
97
|
if (req.method === 'GET' && url.pathname === '/') {
|
|
55
98
|
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' });
|
|
56
99
|
res.end(node_fs_1.default.readFileSync(PAGE, 'utf8'));
|
|
57
100
|
return;
|
|
58
101
|
}
|
|
102
|
+
// Every write is JSON from this page. A form or a plain-text POST from another site in the same
|
|
103
|
+
// browser can't set that header without asking first — and nothing here answers when it asks.
|
|
104
|
+
if (req.method === 'POST' && !String(req.headers['content-type'] ?? '').startsWith('application/json')) {
|
|
105
|
+
res.writeHead(415);
|
|
106
|
+
res.end();
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
59
109
|
if (req.method === 'GET' && url.pathname === '/api/state') {
|
|
60
110
|
json(res, 200, state());
|
|
61
111
|
return;
|
|
@@ -76,10 +126,18 @@ function review(opts = {}) {
|
|
|
76
126
|
json(res, 200, { exitCode: result.exitCode, ...result.output });
|
|
77
127
|
return;
|
|
78
128
|
}
|
|
129
|
+
if (req.method === 'POST' && url.pathname === '/api/request') {
|
|
130
|
+
const body = JSON.parse(await readBody(req));
|
|
131
|
+
const result = (0, request_1.judgeRequest)(body.id, { as: body.as, to: body.to, why: body.why, cwd });
|
|
132
|
+
if (result.exitCode === 0)
|
|
133
|
+
changed = true;
|
|
134
|
+
json(res, 200, { exitCode: result.exitCode, ...result.output });
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
79
137
|
if (req.method === 'GET' && url.pathname.startsWith('/snapshots/')) {
|
|
80
138
|
const file = node_path_1.default.basename(url.pathname);
|
|
81
|
-
const abs = node_path_1.default.join((0, candidates_1.candidatesDir)(paths), file);
|
|
82
|
-
if (!/^C-\d{4,}\.(png|jpe?g|webp|gif|svg)$/.test(file) || !node_fs_1.default.existsSync(abs)) {
|
|
139
|
+
const abs = node_path_1.default.join(file.startsWith('W-') ? (0, work_1.workDir)(paths) : (0, candidates_1.candidatesDir)(paths), file);
|
|
140
|
+
if (!/^(C-\d{4,}|W-[a-z0-9-]{1,48})\.(png|jpe?g|webp|gif|svg)$/.test(file) || !node_fs_1.default.existsSync(abs)) {
|
|
83
141
|
res.writeHead(404);
|
|
84
142
|
res.end();
|
|
85
143
|
return;
|
|
@@ -104,12 +162,22 @@ function review(opts = {}) {
|
|
|
104
162
|
}
|
|
105
163
|
res.writeHead(404);
|
|
106
164
|
res.end();
|
|
107
|
-
}
|
|
165
|
+
};
|
|
108
166
|
server.listen(opts.port ?? 0, '127.0.0.1', () => {
|
|
109
167
|
const addr = server.address();
|
|
110
168
|
const url = `http://127.0.0.1:${addr.port}/`;
|
|
111
|
-
|
|
112
|
-
|
|
169
|
+
let s;
|
|
170
|
+
try {
|
|
171
|
+
s = state();
|
|
172
|
+
}
|
|
173
|
+
catch (e) {
|
|
174
|
+
process.stderr.write(`arbiter: ${e.message}\n`);
|
|
175
|
+
process.exitCode = 1;
|
|
176
|
+
stop();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const asks = s.requests.filter((r) => r.status === 'open').length;
|
|
180
|
+
process.stdout.write(`Arbiter review — ${s.pending.length} pending${asks ? ` · ${asks} request${asks === 1 ? '' : 's'}` : ''} · ${s.candidates.length} candidate${s.candidates.length === 1 ? '' : 's'} · ${s.active} of ${s.cap} rules\n${url}\nPress Done in the page, or Ctrl-C here, to stop.\n`);
|
|
113
181
|
if (opts.open !== false)
|
|
114
182
|
openBrowser(url);
|
|
115
183
|
});
|
|
@@ -128,6 +196,21 @@ function review(opts = {}) {
|
|
|
128
196
|
process.on('SIGINT', stop);
|
|
129
197
|
});
|
|
130
198
|
}
|
|
199
|
+
const LOCAL = /^(127\.0\.0\.1|localhost|\[::1\])(:\d+)?$/i;
|
|
200
|
+
/** Addressed to this machine, and, when a page sent it, sent by a page on this machine. */
|
|
201
|
+
function fromHere(req) {
|
|
202
|
+
if (!LOCAL.test(String(req.headers.host ?? '')))
|
|
203
|
+
return false;
|
|
204
|
+
const origin = req.headers.origin;
|
|
205
|
+
if (!origin)
|
|
206
|
+
return true;
|
|
207
|
+
try {
|
|
208
|
+
return LOCAL.test(new URL(origin).host);
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
131
214
|
function json(res, status, body) {
|
|
132
215
|
res.writeHead(status, { 'content-type': 'application/json; charset=utf-8' });
|
|
133
216
|
res.end(JSON.stringify(body));
|
package/dist/commands/rules.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* arbiter rules active rules, grouped by dimension
|
|
6
6
|
* arbiter rules --dimension x one dimension
|
|
7
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
|
|
8
|
+
* arbiter rules --pending queued, not yet judged — and requests from the board waiting on an answer
|
|
9
|
+
* arbiter rules D-0003 one decision in full, wherever it lives (R-0001: one request)
|
|
10
10
|
* arbiter rules --json any of the above as JSON
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -15,11 +15,16 @@ exports.groupByTrigger = groupByTrigger;
|
|
|
15
15
|
const schema_1 = require("../schema");
|
|
16
16
|
const format_1 = require("../format");
|
|
17
17
|
const store_1 = require("../store");
|
|
18
|
+
const hosted_1 = require("../hosted");
|
|
19
|
+
const requests_1 = require("../requests");
|
|
18
20
|
const update_1 = require("./update");
|
|
21
|
+
const overlap_1 = require("../overlap");
|
|
19
22
|
function rules(id, opts = {}) {
|
|
20
23
|
const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
|
|
21
24
|
opts = { ...opts, config: (0, store_1.readConfig)(paths) };
|
|
22
25
|
const cap = (0, store_1.readConfig)(paths)?.activeCap ?? store_1.ACTIVE_CAP;
|
|
26
|
+
if (id && requests_1.REQUEST_ID.test(id))
|
|
27
|
+
return oneRequest(id, paths, opts.json);
|
|
23
28
|
if (id)
|
|
24
29
|
return one(id, paths, opts.json);
|
|
25
30
|
if (opts.archive)
|
|
@@ -59,23 +64,48 @@ function rules(id, opts = {}) {
|
|
|
59
64
|
*/
|
|
60
65
|
function pendingList(pending, opts, paths) {
|
|
61
66
|
const groups = groupByTrigger(pending);
|
|
67
|
+
// Requests from the board: open ones wait on the owner's answer; approved ones on the agent.
|
|
68
|
+
const archiveAll = (0, store_1.readArchive)(paths);
|
|
69
|
+
// Only for "asked about an earlier version": a hosted.json in a merge conflict mustn't stop the queue.
|
|
70
|
+
const version = (0, hosted_1.readLinkOrNull)(paths)?.boardVersion ?? null;
|
|
71
|
+
const requests = (0, requests_1.readRequests)(paths);
|
|
72
|
+
const show = (status) => requests.filter((r) => r.status === status).map((r) => (0, requests_1.describe)(paths, r, version, archiveAll));
|
|
73
|
+
const open = show('open');
|
|
74
|
+
const approved = show('approved');
|
|
62
75
|
if (opts.json) {
|
|
76
|
+
const active = (0, store_1.readActive)(paths);
|
|
77
|
+
const ignore = opts.config?.overlap?.ignore;
|
|
63
78
|
return JSON.stringify({
|
|
64
79
|
firstRun: !opts.config?.onboarded,
|
|
65
80
|
checkin: opts.config?.checkin ?? 'feature',
|
|
66
81
|
...(0, update_1.updateNotice)(paths),
|
|
82
|
+
requests: { open, approved },
|
|
67
83
|
count: pending.length,
|
|
68
84
|
polish: pending.filter((d) => d.level === 'polish').length,
|
|
69
|
-
groups: groups.map((g) => ({ trigger: g.trigger, items: g.items, polish: g.polish })),
|
|
85
|
+
groups: groups.map((g) => ({ trigger: g.trigger, items: g.items.map((d) => withOverlaps(d, active, ignore)), polish: g.polish })),
|
|
86
|
+
// The active rules, short, so the review can check every item for a clash without another read.
|
|
87
|
+
rules: active.map((d) => ({ id: d.id, decision: d.decision, scope: d.scope, dimension: d.dimension })),
|
|
70
88
|
pending,
|
|
71
89
|
}, null, 2);
|
|
72
90
|
}
|
|
73
|
-
if (!pending.length)
|
|
91
|
+
if (!pending.length && !open.length && !approved.length)
|
|
74
92
|
return 'Nothing pending. All caught up.';
|
|
93
|
+
const lines = [];
|
|
94
|
+
if (open.length || approved.length) {
|
|
95
|
+
lines.push(`Requests from the board — ${[open.length ? `${open.length} to answer` : '', approved.length ? `${approved.length} approved, not yet made` : ''].filter(Boolean).join(', ')}`);
|
|
96
|
+
for (const r of [...open, ...approved]) {
|
|
97
|
+
lines.push(` ${r.id} ${r.author}${r.screenName ? `, on ${r.screenName}` : ''}${r.decision ? ` (${r.decision})` : ''}: ${(0, requests_1.oneLine)(r.body)}${r.earlierVersion ? ' (earlier version)' : ''}`);
|
|
98
|
+
if (r.status === 'approved')
|
|
99
|
+
lines.push(` approved${r.instead ? ` — do instead: ${r.instead}` : ''}`);
|
|
100
|
+
}
|
|
101
|
+
if (open.length)
|
|
102
|
+
lines.push(` answer: npx arbiter record ${open[0].id} --as apply · --as apply --to "<instead>" · --as decline --why "<reason>"`);
|
|
103
|
+
if (!pending.length)
|
|
104
|
+
return lines.join('\n');
|
|
105
|
+
lines.push('');
|
|
106
|
+
}
|
|
75
107
|
const polish = pending.filter((d) => d.level === 'polish').length;
|
|
76
|
-
|
|
77
|
-
`${pending.length} pending${polish ? ` (${polish} polish)` : ''} — review with \`npx arbiter review\` or /arbiter in chat`,
|
|
78
|
-
];
|
|
108
|
+
lines.push(`${pending.length} pending${polish ? ` (${polish} polish)` : ''} — review with \`npx arbiter review\` or /arbiter in chat`);
|
|
79
109
|
for (const g of groups) {
|
|
80
110
|
lines.push('', g.trigger);
|
|
81
111
|
for (const d of g.items)
|
|
@@ -88,6 +118,15 @@ function pendingList(pending, opts, paths) {
|
|
|
88
118
|
}
|
|
89
119
|
return lines.join('\n');
|
|
90
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* A feature/pattern item with `overlaps` — active rules it may repeat or contradict — so the
|
|
123
|
+
* review can spot a clash. Word and scope matches only: the agent reads both sides and decides.
|
|
124
|
+
* The key is there only when there's a hit.
|
|
125
|
+
*/
|
|
126
|
+
function withOverlaps(d, active, ignore) {
|
|
127
|
+
const overlaps = (0, overlap_1.findOverlaps)(d, active, { ignore });
|
|
128
|
+
return overlaps.length ? { ...d, overlaps } : d;
|
|
129
|
+
}
|
|
91
130
|
/** Queue order of first appearance; each trigger once. */
|
|
92
131
|
function groupByTrigger(pending) {
|
|
93
132
|
const out = [];
|
|
@@ -111,6 +150,21 @@ function reviewLines(d) {
|
|
|
111
150
|
lines.push(`${pad}${d.level} · ${d.dimension} · ${d.scope}`);
|
|
112
151
|
return lines;
|
|
113
152
|
}
|
|
153
|
+
function oneRequest(id, paths, json) {
|
|
154
|
+
const found = (0, requests_1.findRequest)((0, requests_1.readRequests)(paths), id);
|
|
155
|
+
if (found.error)
|
|
156
|
+
throw new Error(found.error);
|
|
157
|
+
const r = found.request;
|
|
158
|
+
if (!r)
|
|
159
|
+
throw new Error(`${id} not found`);
|
|
160
|
+
if (json)
|
|
161
|
+
return JSON.stringify(r, null, 2);
|
|
162
|
+
const answer = r.status === 'open' ? 'open — waiting on the owner'
|
|
163
|
+
: r.status === 'declined' ? `declined by ${r.judgedBy}: ${r.reason}`
|
|
164
|
+
: r.status === 'approved' ? `approved by ${r.judgedBy}${r.instead ? ` — do instead: ${r.instead}` : ''}`
|
|
165
|
+
: `applied${r.instead ? ` differently (${r.instead})` : ''} — ${r.decisions.join(', ')}`;
|
|
166
|
+
return [`${r.id} ${r.author} on ${(0, requests_1.screenName)(paths, r.screen) ?? r.screen}${r.decision ? ` (${r.decision})` : ''}, ${String(r.date ?? '').slice(0, 10)}`, ` ${r.body}`, ` ${answer}`].join('\n');
|
|
167
|
+
}
|
|
114
168
|
function one(id, paths, json) {
|
|
115
169
|
if (!schema_1.ID_PATTERN.test(id))
|
|
116
170
|
throw new Error(`not a decision id: ${id} (looks like D-0003 or P-0003)`);
|
package/dist/commands/setup.js
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* `arbiter setup --checkin <feature|quiet|every>` — the one preference the first `/arbiter` asks
|
|
4
4
|
* for, written to arbiter.json. Running it also marks the project as onboarded, so the intro
|
|
5
5
|
* never shows twice. Later: "be quieter" → the agent runs it again.
|
|
6
|
+
*
|
|
7
|
+
* `arbiter setup --app <url>` — where the app runs, so the agent has an address to open for a
|
|
8
|
+
* screenshot instead of assuming localhost. On its own it saves only that: the agent can learn
|
|
9
|
+
* the address before the first /arbiter, and that mustn't skip the intro.
|
|
6
10
|
*/
|
|
7
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
12
|
exports.CHECKINS = void 0;
|
|
@@ -14,10 +18,43 @@ function setup(opts) {
|
|
|
14
18
|
const config = (0, store_1.readConfig)(paths);
|
|
15
19
|
if (!config)
|
|
16
20
|
return { exitCode: 1, output: { status: 'invalid', errors: ['no arbiter.json here — run `npx arbiter init` first'] } };
|
|
21
|
+
let app = config.app;
|
|
22
|
+
if (opts.app !== undefined) {
|
|
23
|
+
const url = appUrl(opts.app);
|
|
24
|
+
if (url === 'credentials')
|
|
25
|
+
return { exitCode: 1, output: { status: 'invalid', errors: ['--app goes in arbiter.json, which is committed — give the address without a username or password'] } };
|
|
26
|
+
if (!url)
|
|
27
|
+
return { exitCode: 1, output: { status: 'invalid', errors: ['--app must be the address the app runs at, like http://localhost:3000'] } };
|
|
28
|
+
app = { url };
|
|
29
|
+
}
|
|
30
|
+
// --app on its own goes before the check-in is read, so a hand-edited arbiter.json can't stop it.
|
|
31
|
+
if (opts.app !== undefined && opts.checkin === undefined) {
|
|
32
|
+
(0, store_1.writeConfig)(paths, { ...config, app });
|
|
33
|
+
return { exitCode: 0, output: { status: 'saved', app: app.url } };
|
|
34
|
+
}
|
|
17
35
|
const checkin = (opts.checkin ?? config.checkin ?? 'feature');
|
|
18
36
|
if (!exports.CHECKINS.includes(checkin))
|
|
19
37
|
return { exitCode: 1, output: { status: 'invalid', errors: [`--checkin must be one of ${exports.CHECKINS.join(' | ')}`] } };
|
|
20
|
-
const next = { ...config, checkin, onboarded: config.onboarded ?? (0, store_1.now)() };
|
|
38
|
+
const next = { ...config, checkin, onboarded: config.onboarded ?? (0, store_1.now)(), ...(app && { app }) };
|
|
21
39
|
(0, store_1.writeConfig)(paths, next);
|
|
22
|
-
return { exitCode: 0, output: { status: 'saved', checkin, onboarded: next.onboarded } };
|
|
40
|
+
return { exitCode: 0, output: { status: 'saved', checkin, onboarded: next.onboarded, ...(app && { app: app.url }) } };
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* An http(s) address a route can go on the end of: no query or fragment, no trailing slash.
|
|
44
|
+
* One with a username or password is refused rather than written to a committed file.
|
|
45
|
+
*/
|
|
46
|
+
function appUrl(raw) {
|
|
47
|
+
try {
|
|
48
|
+
const u = new URL(raw.trim());
|
|
49
|
+
if (u.protocol !== 'http:' && u.protocol !== 'https:')
|
|
50
|
+
return null;
|
|
51
|
+
if (u.username || u.password)
|
|
52
|
+
return 'credentials';
|
|
53
|
+
u.search = '';
|
|
54
|
+
u.hash = '';
|
|
55
|
+
return u.href.replace(/\/+$/, '');
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
23
60
|
}
|
|
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
11
11
|
exports.snapshotWork = snapshotWork;
|
|
12
12
|
const node_path_1 = __importDefault(require("node:path"));
|
|
13
13
|
const store_1 = require("../store");
|
|
14
|
+
const hosted_1 = require("../hosted");
|
|
14
15
|
const work_1 = require("../work");
|
|
15
16
|
function snapshotWork(name, opts) {
|
|
16
17
|
const root = (0, store_1.findRoot)(opts.cwd);
|
|
@@ -21,10 +22,14 @@ function snapshotWork(name, opts) {
|
|
|
21
22
|
if (!opts.file && !opts.capture)
|
|
22
23
|
return { exitCode: 1, output: { status: 'invalid', errors: ['pass --file <image> or --capture'] } };
|
|
23
24
|
const id = (0, work_1.workId)(trigger);
|
|
24
|
-
// A work card is built from judged decisions only, so a picture for
|
|
25
|
-
// nothing to hang on yet. Counting the queue here would report success for a board that stays empty.
|
|
26
|
-
const
|
|
27
|
-
const
|
|
25
|
+
// A work card is built from judged, non-polish decisions only, so a picture for anything else has
|
|
26
|
+
// nothing to hang on yet. Counting the queue or polish here would report success for a board that stays empty.
|
|
27
|
+
const mine = (d) => (0, work_1.workId)(d.trigger) === id;
|
|
28
|
+
const archive = (0, store_1.readArchive)(paths);
|
|
29
|
+
const pending = (0, store_1.readPending)(paths);
|
|
30
|
+
const judged = archive.some((d) => mine(d) && (0, hosted_1.publishable)(d));
|
|
31
|
+
const queued = pending.filter((d) => mine(d) && d.level !== 'polish').length;
|
|
32
|
+
const polish = [...archive, ...pending].some((d) => mine(d) && d.level === 'polish' && d.verdict !== 'retire');
|
|
28
33
|
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);
|
|
29
34
|
if (!r.ok)
|
|
30
35
|
return { exitCode: 1, output: { status: 'failed', error: r.error } };
|
|
@@ -32,7 +37,9 @@ function snapshotWork(name, opts) {
|
|
|
32
37
|
? null
|
|
33
38
|
: queued
|
|
34
39
|
? `"${trigger}" has ${queued} decision${queued === 1 ? '' : 's'} still in the queue — the picture shows on the board once they're judged (/arbiter, or npx arbiter review)`
|
|
35
|
-
:
|
|
40
|
+
: polish
|
|
41
|
+
? `"${trigger}" only has polish so far, and polish never reaches the board — the picture shows once a feature or pattern decision lands`
|
|
42
|
+
: `no decisions mention "${trigger}" yet — the picture shows once some do`;
|
|
36
43
|
return {
|
|
37
44
|
exitCode: 0,
|
|
38
45
|
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)), ...(note ? { note } : {}) },
|
package/dist/findings.js
CHANGED
|
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.isFinding = void 0;
|
|
17
18
|
exports.parseFindings = parseFindings;
|
|
18
19
|
exports.toDecisionInput = toDecisionInput;
|
|
19
20
|
const node_path_1 = __importDefault(require("node:path"));
|
|
@@ -50,6 +51,14 @@ function parseFindings(raw) {
|
|
|
50
51
|
}
|
|
51
52
|
return out;
|
|
52
53
|
}
|
|
54
|
+
/** The piece of work a finding is queued under: the rule that fired, and where. */
|
|
55
|
+
const findingTrigger = (rule, where) => `finding${rule ? ` ${rule}` : ''} at ${where}`;
|
|
56
|
+
/**
|
|
57
|
+
* A scanner finding, known by the shape `toDecisionInput` gives it. It's one line in one file,
|
|
58
|
+
* not a screen, so nothing asks for its picture.
|
|
59
|
+
*/
|
|
60
|
+
const isFinding = (d) => d.class === 'mechanical' && /^finding(?: \S+)? at \S/.test(d.trigger);
|
|
61
|
+
exports.isFinding = isFinding;
|
|
53
62
|
/** Turn a finding into the decision the reviewer will judge. */
|
|
54
63
|
function toDecisionInput(f, root, tool) {
|
|
55
64
|
const rel = node_path_1.default.isAbsolute(f.file) ? node_path_1.default.relative(root, f.file) : f.file;
|
|
@@ -58,7 +67,7 @@ function toDecisionInput(f, root, tool) {
|
|
|
58
67
|
decision: f.suggestion ? f.suggestion : f.message,
|
|
59
68
|
rationale: `${tool} flagged: ${f.message}`,
|
|
60
69
|
rejected: [],
|
|
61
|
-
trigger:
|
|
70
|
+
trigger: findingTrigger(f.rule, where),
|
|
62
71
|
scope: `file:${rel}`,
|
|
63
72
|
dimension: 'visual',
|
|
64
73
|
class: 'mechanical',
|
package/dist/format.js
CHANGED
|
@@ -31,19 +31,26 @@ const NONE = '—';
|
|
|
31
31
|
const HEADING = /^#{2,3} ([DP]-\d{4,}) · (.*)$/;
|
|
32
32
|
const REJECTED_ITEM = /^ {2}- (.*)$/;
|
|
33
33
|
const FIELD = /\*\*([A-Za-z]+):\*\* (.*?)(?=\s·\s\*\*|$)/g;
|
|
34
|
+
/**
|
|
35
|
+
* A value as an entry may hold it: one line, with no `**Field:**` marker of its own. Input is
|
|
36
|
+
* checked before it gets here, but some of it comes from outside the project (a board request's
|
|
37
|
+
* author and words, a scanner's message), and one line break would let it write a whole entry,
|
|
38
|
+
* a rule included.
|
|
39
|
+
*/
|
|
40
|
+
const text = (s) => s.replace(/\s*[\r\n]+\s*/g, ' ').replace(/\*\*([A-Za-z]+):\*\*/g, '$1:');
|
|
34
41
|
function formatEntry(d) {
|
|
35
42
|
return [
|
|
36
|
-
`### ${d.id}${SEP}${d.decision}`,
|
|
43
|
+
`### ${d.id}${SEP}${text(d.decision)}`,
|
|
37
44
|
'',
|
|
38
|
-
...(d.change ? [`- **Change:** ${d.change}`] : []),
|
|
39
|
-
`- **Rationale:** ${d.rationale}`,
|
|
40
|
-
...(d.rejected.length ? ['- **Rejected:**', ...d.rejected.map((r) => ` - ${r}`)] : []),
|
|
41
|
-
`- **Trigger:** ${d.trigger}`,
|
|
42
|
-
`- **Scope:** ${d.scope}${SEP}**Dimension:** ${d.dimension}${SEP}**Level:** ${d.level}${SEP}**Class:** ${d.class}${SEP}**Verdict:** ${d.verdict}`,
|
|
43
|
-
`- **Author:** ${d.author}${SEP}**Date:** ${d.date}${SEP}**Commit:** ${d.commit ?? NONE}${SEP}**Supersedes:** ${d.supersedes ?? NONE}${d.candidate ? `${SEP}**Candidate:** ${d.candidate}` : ''}`,
|
|
44
|
-
...(d.ref ? [`- **Ref:** ${d.ref}`] : []),
|
|
45
|
-
...(d.files.length ? [`- **Files:** ${d.files.join(SEP)}`] : []),
|
|
46
|
-
...(d.paths.length ? [`- **Paths:** ${d.paths.join(SEP)}`] : []),
|
|
45
|
+
...(d.change ? [`- **Change:** ${text(d.change)}`] : []),
|
|
46
|
+
`- **Rationale:** ${text(d.rationale)}`,
|
|
47
|
+
...(d.rejected.length ? ['- **Rejected:**', ...d.rejected.map((r) => ` - ${text(r)}`)] : []),
|
|
48
|
+
`- **Trigger:** ${text(d.trigger)}`,
|
|
49
|
+
`- **Scope:** ${text(d.scope)}${SEP}**Dimension:** ${d.dimension}${SEP}**Level:** ${d.level}${SEP}**Class:** ${d.class}${SEP}**Verdict:** ${d.verdict}`,
|
|
50
|
+
`- **Author:** ${text(d.author)}${SEP}**Date:** ${text(d.date)}${SEP}**Commit:** ${d.commit ?? NONE}${SEP}**Supersedes:** ${d.supersedes ?? NONE}${d.candidate ? `${SEP}**Candidate:** ${d.candidate}` : ''}`,
|
|
51
|
+
...(d.ref ? [`- **Ref:** ${text(d.ref)}`] : []),
|
|
52
|
+
...(d.files.length ? [`- **Files:** ${d.files.map(text).join(SEP)}`] : []),
|
|
53
|
+
...(d.paths.length ? [`- **Paths:** ${d.paths.map(text).join(SEP)}`] : []),
|
|
47
54
|
...(d.expect ? [`- **Expect:** ${JSON.stringify(d.expect)}${SEP}**Verified:** ${d.verified === null ? NONE : d.verified ? 'yes' : 'no'}`] : []),
|
|
48
55
|
'',
|
|
49
56
|
].join('\n');
|