arbiterdesign 0.1.4 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,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
+ }
@@ -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,13 +40,34 @@ 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
+ };
52
+ const active = (0, store_1.readActive)(paths);
38
53
  return {
39
54
  project: node_path_1.default.basename(root),
40
- pending: (0, store_1.readPending)(paths).map((d) => ({ ...d, candidateName: d.candidate ? byId.get(d.candidate)?.name ?? null : null, snapshotUrl: d.candidate ? byId.get(d.candidate)?.snapshotUrl ?? null : null })),
55
+ pending: (0, store_1.readPending)(paths).map((d) => ({
56
+ ...d,
57
+ // The rule a clash is with, while it's still in force: the page offers Follow / Replace / Keep as exception.
58
+ againstRule: d.against ? active.filter((r) => r.id === d.against).map((r) => ({ id: r.id, decision: r.decision }))[0] ?? null : null,
59
+ candidateName: d.candidate ? byId.get(d.candidate)?.name ?? null : null,
60
+ snapshotUrl: d.candidate ? byId.get(d.candidate)?.snapshotUrl ?? null : null,
61
+ picture: (0, pictures_1.missingPictures)(paths, [d], candidates)[0] ?? null,
62
+ })),
63
+ // Open ones to answer; approved ones waiting on the agent — shown so it's clear nothing is lost.
64
+ requests: (0, requests_1.readRequests)(paths)
65
+ .filter((r) => r.status === 'open' || r.status === 'approved')
66
+ .map((r) => ({ ...(0, requests_1.describe)(paths, r, version, archive), snapshotUrl: shotOf(r.screen) })),
41
67
  candidates,
42
- hosted: (0, hosted_1.readLink)(paths)?.shareUrl ?? null,
43
- boardVersion: (0, hosted_1.readLink)(paths)?.boardVersion ?? null,
44
- active: (0, store_1.readActive)(paths).length,
68
+ hosted: (0, hosted_1.readLinkOrNull)(paths)?.shareUrl ?? null,
69
+ boardVersion: (0, hosted_1.readLinkOrNull)(paths)?.boardVersion ?? null,
70
+ active: active.length,
45
71
  cap: (0, store_1.readConfig)(paths)?.activeCap ?? store_1.ACTIVE_CAP,
46
72
  };
47
73
  };
@@ -50,12 +76,39 @@ function review(opts = {}) {
50
76
  let changed = false;
51
77
  return new Promise((resolve) => {
52
78
  const server = node_http_1.default.createServer(async (req, res) => {
79
+ try {
80
+ await handle(req, res);
81
+ }
82
+ catch (e) {
83
+ // A broken requests.json, say: the page shows the message instead of the server dying.
84
+ if (!res.headersSent)
85
+ json(res, 500, { exitCode: 1, errors: [e.message] });
86
+ else
87
+ res.end();
88
+ }
89
+ });
90
+ const handle = async (req, res) => {
91
+ // This machine, by its own name, and nothing else. A site that points a domain of its own at
92
+ // 127.0.0.1 (DNS rebinding) is same-origin to the browser, so the JSON check below can't stop
93
+ // it, but its requests carry that domain as their Host.
94
+ if (!fromHere(req)) {
95
+ res.writeHead(403);
96
+ res.end();
97
+ return;
98
+ }
53
99
  const url = new URL(req.url ?? '/', 'http://127.0.0.1');
54
100
  if (req.method === 'GET' && url.pathname === '/') {
55
101
  res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' });
56
102
  res.end(node_fs_1.default.readFileSync(PAGE, 'utf8'));
57
103
  return;
58
104
  }
105
+ // Every write is JSON from this page. A form or a plain-text POST from another site in the same
106
+ // browser can't set that header without asking first — and nothing here answers when it asks.
107
+ if (req.method === 'POST' && !String(req.headers['content-type'] ?? '').startsWith('application/json')) {
108
+ res.writeHead(415);
109
+ res.end();
110
+ return;
111
+ }
59
112
  if (req.method === 'GET' && url.pathname === '/api/state') {
60
113
  json(res, 200, state());
61
114
  return;
@@ -76,10 +129,18 @@ function review(opts = {}) {
76
129
  json(res, 200, { exitCode: result.exitCode, ...result.output });
77
130
  return;
78
131
  }
132
+ if (req.method === 'POST' && url.pathname === '/api/request') {
133
+ const body = JSON.parse(await readBody(req));
134
+ const result = (0, request_1.judgeRequest)(body.id, { as: body.as, to: body.to, why: body.why, cwd });
135
+ if (result.exitCode === 0)
136
+ changed = true;
137
+ json(res, 200, { exitCode: result.exitCode, ...result.output });
138
+ return;
139
+ }
79
140
  if (req.method === 'GET' && url.pathname.startsWith('/snapshots/')) {
80
141
  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)) {
142
+ const abs = node_path_1.default.join(file.startsWith('W-') ? (0, work_1.workDir)(paths) : (0, candidates_1.candidatesDir)(paths), file);
143
+ 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
144
  res.writeHead(404);
84
145
  res.end();
85
146
  return;
@@ -104,12 +165,22 @@ function review(opts = {}) {
104
165
  }
105
166
  res.writeHead(404);
106
167
  res.end();
107
- });
168
+ };
108
169
  server.listen(opts.port ?? 0, '127.0.0.1', () => {
109
170
  const addr = server.address();
110
171
  const url = `http://127.0.0.1:${addr.port}/`;
111
- const s = state();
112
- process.stdout.write(`Arbiter review — ${s.pending.length} pending · ${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`);
172
+ let s;
173
+ try {
174
+ s = state();
175
+ }
176
+ catch (e) {
177
+ process.stderr.write(`arbiter: ${e.message}\n`);
178
+ process.exitCode = 1;
179
+ stop();
180
+ return;
181
+ }
182
+ const asks = s.requests.filter((r) => r.status === 'open').length;
183
+ 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
184
  if (opts.open !== false)
114
185
  openBrowser(url);
115
186
  });
@@ -128,6 +199,21 @@ function review(opts = {}) {
128
199
  process.on('SIGINT', stop);
129
200
  });
130
201
  }
202
+ const LOCAL = /^(127\.0\.0\.1|localhost|\[::1\])(:\d+)?$/i;
203
+ /** Addressed to this machine, and, when a page sent it, sent by a page on this machine. */
204
+ function fromHere(req) {
205
+ if (!LOCAL.test(String(req.headers.host ?? '')))
206
+ return false;
207
+ const origin = req.headers.origin;
208
+ if (!origin)
209
+ return true;
210
+ try {
211
+ return LOCAL.test(new URL(origin).host);
212
+ }
213
+ catch {
214
+ return false;
215
+ }
216
+ }
131
217
  function json(res, status, body) {
132
218
  res.writeHead(status, { 'content-type': 'application/json; charset=utf-8' });
133
219
  res.end(JSON.stringify(body));
@@ -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
- const lines = [
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 = [];
@@ -108,9 +147,26 @@ function reviewLines(d) {
108
147
  lines.push(`${pad}Pattern ${d.decision}`);
109
148
  for (const r of d.rejected)
110
149
  lines.push(`${pad}Rejected ${r}`);
150
+ if (d.against)
151
+ lines.push(`${pad}Against ${d.against}`);
111
152
  lines.push(`${pad}${d.level} · ${d.dimension} · ${d.scope}`);
112
153
  return lines;
113
154
  }
155
+ function oneRequest(id, paths, json) {
156
+ const found = (0, requests_1.findRequest)((0, requests_1.readRequests)(paths), id);
157
+ if (found.error)
158
+ throw new Error(found.error);
159
+ const r = found.request;
160
+ if (!r)
161
+ throw new Error(`${id} not found`);
162
+ if (json)
163
+ return JSON.stringify(r, null, 2);
164
+ const answer = r.status === 'open' ? 'open — waiting on the owner'
165
+ : r.status === 'declined' ? `declined by ${r.judgedBy}: ${r.reason}`
166
+ : r.status === 'approved' ? `approved by ${r.judgedBy}${r.instead ? ` — do instead: ${r.instead}` : ''}`
167
+ : `applied${r.instead ? ` differently (${r.instead})` : ''} — ${r.decisions.join(', ')}`;
168
+ 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');
169
+ }
114
170
  function one(id, paths, json) {
115
171
  if (!schema_1.ID_PATTERN.test(id))
116
172
  throw new Error(`not a decision id: ${id} (looks like D-0003 or P-0003)`);
@@ -122,9 +178,20 @@ function one(id, paths, json) {
122
178
  const later = all.find((x) => x.supersedes === id);
123
179
  const supersededBy = later?.id ?? null;
124
180
  const status = d.verdict !== 'rule' ? d.verdict : activeIds.has(id) ? 'active' : later ? `${later.verdict === 'retire' ? 'retired' : 'superseded'} by ${later.id}` : 'inactive';
181
+ // Where a rule doesn't hold, and why that's settled: the exceptions confirmed to it, and the
182
+ // clashes waiting on the review list. The agent checks these before asking about a screen twice.
183
+ const short = (x) => ({ id: x.id, trigger: x.trigger, change: x.change ?? x.decision });
184
+ const exceptions = id.startsWith('D-') ? all.filter((x) => x.against === id && x.verdict === 'accept').map(short) : [];
185
+ const waiting = id.startsWith('D-') ? (0, store_1.readPending)(paths).filter((x) => x.against === id).map(short) : [];
125
186
  if (json)
126
- return JSON.stringify({ ...d, status, supersededBy }, null, 2);
127
- return `${(0, format_1.formatEntry)(d).trimEnd()}\n- **Status:** ${status}`;
187
+ return JSON.stringify({ ...d, status, supersededBy, exceptions, waiting }, null, 2);
188
+ const list = (xs) => xs.map((x) => `${x.id} (${x.trigger})`).join(' · ');
189
+ return [
190
+ (0, format_1.formatEntry)(d).trimEnd(),
191
+ `- **Status:** ${status}`,
192
+ ...(exceptions.length ? [`- **Exceptions:** ${list(exceptions)}`] : []),
193
+ ...(waiting.length ? [`- **Waiting:** ${list(waiting)}`] : []),
194
+ ].join('\n');
128
195
  }
129
196
  function archive(all, active, opts) {
130
197
  const activeIds = new Set(active.map((d) => d.id));
@@ -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 work still in the queue has
25
- // nothing to hang on yet. Counting the queue here would report success for a board that stays empty.
26
- const judged = (0, store_1.readArchive)(paths).some((d) => (0, work_1.workId)(d.trigger) === id && d.verdict !== 'retire');
27
- const queued = (0, store_1.readPending)(paths).filter((d) => (0, work_1.workId)(d.trigger) === id).length;
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
- : `no decisions mention "${trigger}" yet — the picture shows once some do`;
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 } : {}) },
@@ -49,6 +49,9 @@ function sweepCommand(id, opts = {}) {
49
49
  expect: rule.expect,
50
50
  verified: false,
51
51
  candidate: null,
52
+ against: rule.id,
53
+ call: null,
54
+ reworded: [],
52
55
  };
53
56
  pending.push(entry);
54
57
  queued.push(entry.id);
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: `finding${f.rule ? ` ${f.rule}` : ''} at ${where}`,
70
+ trigger: findingTrigger(f.rule, where),
62
71
  scope: `file:${rel}`,
63
72
  dimension: 'visual',
64
73
  class: 'mechanical',