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
package/dist/hosted.js
CHANGED
|
@@ -12,7 +12,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.ADMIN_ENV = exports.TOKEN_ENV = void 0;
|
|
15
|
+
exports.publishable = exports.ADMIN_ENV = exports.TOKEN_ENV = void 0;
|
|
16
|
+
exports.readLinkOrNull = readLinkOrNull;
|
|
16
17
|
exports.readLink = readLink;
|
|
17
18
|
exports.writeLink = writeLink;
|
|
18
19
|
exports.readToken = readToken;
|
|
@@ -27,6 +28,16 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
27
28
|
const candidates_1 = require("./candidates");
|
|
28
29
|
const store_1 = require("./store");
|
|
29
30
|
const work_1 = require("./work");
|
|
31
|
+
const requests_1 = require("./requests");
|
|
32
|
+
/** The link for places that only want to know about the board, where a broken hosted.json shouldn't stop the command. */
|
|
33
|
+
function readLinkOrNull(paths) {
|
|
34
|
+
try {
|
|
35
|
+
return readLink(paths);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
30
41
|
const LINK_FILE = 'hosted.json';
|
|
31
42
|
const TOKEN_FILE = 'hosted.token';
|
|
32
43
|
const COMMENTS_FILE = 'comments.json';
|
|
@@ -72,10 +83,13 @@ function readComments(paths) {
|
|
|
72
83
|
const f = node_path_1.default.join(paths.archiveDir, COMMENTS_FILE);
|
|
73
84
|
return node_fs_1.default.existsSync(f) ? JSON.parse(node_fs_1.default.readFileSync(f, 'utf8')) : [];
|
|
74
85
|
}
|
|
86
|
+
/** Every comment on file, minus email addresses: nothing here needs them, and the file is committed. */
|
|
75
87
|
function writeComments(paths, comments) {
|
|
76
|
-
|
|
88
|
+
const kept = comments.map(({ author_email: _email, ...c }) => c);
|
|
89
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(paths.archiveDir, COMMENTS_FILE), JSON.stringify(kept, null, 2) + '\n');
|
|
77
90
|
}
|
|
78
91
|
const publishable = (d) => d.verdict !== 'pending' && d.verdict !== 'retire' && d.level !== 'polish';
|
|
92
|
+
exports.publishable = publishable;
|
|
79
93
|
const wire = (d) => ({ id: d.id, change: d.change, decision: d.decision, rejected: d.rejected, verdict: d.verdict, dimension: d.dimension, scope: d.scope, ref: d.ref });
|
|
80
94
|
/**
|
|
81
95
|
* The upload manifest: every judged, non-polish decision, and the rules. A decision attached to a
|
|
@@ -109,12 +123,13 @@ function buildManifest(paths, opts = {}) {
|
|
|
109
123
|
supersededBy: c.supersededBy,
|
|
110
124
|
url: null,
|
|
111
125
|
snapshot,
|
|
112
|
-
decisions: (0, candidates_1.decisionsFor)(paths, c.id).filter(publishable).map(wire),
|
|
126
|
+
decisions: (0, candidates_1.decisionsFor)(paths, c.id).filter(exports.publishable).map(wire),
|
|
113
127
|
};
|
|
114
128
|
});
|
|
115
129
|
// Screenless decisions: one card per piece of work.
|
|
116
130
|
const ids = new Set(known.map((c) => c.id));
|
|
117
|
-
const
|
|
131
|
+
const archive = (0, store_1.readArchive)(paths);
|
|
132
|
+
const loose = archive.filter((d) => (0, exports.publishable)(d) && (!d.candidate || !ids.has(d.candidate)));
|
|
118
133
|
const byWork = new Map();
|
|
119
134
|
for (const d of loose)
|
|
120
135
|
byWork.set(d.trigger, [...(byWork.get(d.trigger) ?? []), d]);
|
|
@@ -138,8 +153,27 @@ function buildManifest(paths, opts = {}) {
|
|
|
138
153
|
decisions: ds.map(wire),
|
|
139
154
|
});
|
|
140
155
|
}
|
|
141
|
-
|
|
142
|
-
|
|
156
|
+
// The day each became a rule, for the board's Design rules page.
|
|
157
|
+
const rules = opts.includeRules ? (0, store_1.readActive)(paths).map((r) => ({ id: r.id, dimension: r.dimension, decision: r.decision, rationale: r.rationale, candidate: r.candidate ?? null, date: r.date.slice(0, 10) })) : null;
|
|
158
|
+
// The owner's answers to requests made on the board, matched there by comment. An open request
|
|
159
|
+
// needs nothing sent — the board already has it. What happened is the recorded change itself,
|
|
160
|
+
// polish included, so the requester reads it even when no card shows that decision.
|
|
161
|
+
const requests = (0, requests_1.readRequests)(paths)
|
|
162
|
+
.filter((r) => r.status !== 'open')
|
|
163
|
+
.map((r) => ({
|
|
164
|
+
comment: r.comment,
|
|
165
|
+
id: r.id,
|
|
166
|
+
status: r.status,
|
|
167
|
+
instead: r.instead,
|
|
168
|
+
reason: r.reason,
|
|
169
|
+
by: r.judgedBy,
|
|
170
|
+
at: r.appliedAt ?? r.judgedAt,
|
|
171
|
+
decisions: r.decisions.flatMap((id) => {
|
|
172
|
+
const d = archive.find((x) => x.id === id);
|
|
173
|
+
return d ? [{ id: d.id, change: d.change ?? d.decision, card: (0, requests_1.cardOf)(paths, d, ids) }] : [];
|
|
174
|
+
}),
|
|
175
|
+
}));
|
|
176
|
+
return { manifest: { project: node_path_1.default.basename(paths.root), exported: new Date().toISOString().slice(0, 10), candidates, rules, requests }, skipped };
|
|
143
177
|
}
|
|
144
178
|
async function api(url, init = {}) {
|
|
145
179
|
const headers = { 'content-type': 'application/json', ...init.headers };
|
|
@@ -207,7 +241,11 @@ async function publishHosted(paths, serviceUrl, opts = {}) {
|
|
|
207
241
|
throw new Error(`publish failed: ${r.body.error ?? r.status}`);
|
|
208
242
|
return { link, candidates: Number(r.body.candidates ?? 0), snapshots, skipped, created };
|
|
209
243
|
}
|
|
210
|
-
/**
|
|
244
|
+
/**
|
|
245
|
+
* Fetch every comment on the board; merge the new ones into .arbiter/comments.json. All of them,
|
|
246
|
+
* not only those since last time: it's how a request deleted on the board is noticed, and a
|
|
247
|
+
* cursor could skip a comment that landed mid-pull. `current` is what the board holds now.
|
|
248
|
+
*/
|
|
211
249
|
async function pullHosted(paths) {
|
|
212
250
|
const link = readLink(paths);
|
|
213
251
|
if (!link)
|
|
@@ -215,15 +253,24 @@ async function pullHosted(paths) {
|
|
|
215
253
|
const token = readToken(paths);
|
|
216
254
|
if (!token)
|
|
217
255
|
throw new Error(`no publish token for ${link.shareUrl}. Get it from whoever first published, then: ${exports.TOKEN_ENV}=<token> npx arbiter pull`);
|
|
218
|
-
const
|
|
219
|
-
const r = await api(`${link.url}/api/projects/${link.projectId}/comments${q}`, { token });
|
|
256
|
+
const r = await api(`${link.url}/api/projects/${link.projectId}/comments`, { token });
|
|
220
257
|
if (!r.ok)
|
|
221
258
|
throw new Error(`pull failed: ${r.body.error ?? r.status}`);
|
|
222
|
-
|
|
259
|
+
// An empty list would read as every request withdrawn, so a reply without one is a failure.
|
|
260
|
+
if (!Array.isArray(r.body.comments))
|
|
261
|
+
throw new Error('pull failed: the board sent no comment list');
|
|
262
|
+
const current = r.body.comments;
|
|
223
263
|
const existing = readComments(paths);
|
|
224
264
|
const seen = new Set(existing.map((c) => c.id));
|
|
225
|
-
const
|
|
265
|
+
const fresh = current.filter((c) => !seen.has(c.id));
|
|
266
|
+
const merged = [...existing, ...fresh].sort((a, b) => String(a.created_at ?? '').localeCompare(String(b.created_at ?? '')));
|
|
226
267
|
writeComments(paths, merged);
|
|
227
|
-
|
|
228
|
-
|
|
268
|
+
// hosted.json is committed: rewrite it only when the board has moved on, or every pull on every
|
|
269
|
+
// machine would leave it changed, and two of them would conflict.
|
|
270
|
+
const boardVersion = r.body.board_version ?? link.boardVersion ?? null;
|
|
271
|
+
if (boardVersion !== (link.boardVersion ?? null)) {
|
|
272
|
+
const { lastPull: _old, ...rest } = link;
|
|
273
|
+
writeLink(paths, { ...rest, boardVersion });
|
|
274
|
+
}
|
|
275
|
+
return { link, fresh, current, total: merged.length };
|
|
229
276
|
}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const commander_1 = require("commander");
|
|
5
5
|
const record_1 = require("./commands/record");
|
|
6
|
+
const request_1 = require("./commands/request");
|
|
6
7
|
const verify_1 = require("./commands/verify");
|
|
7
8
|
const sweep_1 = require("./commands/sweep");
|
|
8
9
|
const candidate_1 = require("./commands/candidate");
|
|
@@ -26,19 +27,20 @@ program
|
|
|
26
27
|
.version(require('../package.json').version);
|
|
27
28
|
program
|
|
28
29
|
.command('record [json-or-pending-id]')
|
|
29
|
-
.description('Append a decision (JSON), queue it (--pending),
|
|
30
|
+
.description('Append a decision (JSON), queue it (--pending), judge a queued one (P-0003 --as rule), or answer a request from the board (R-0001 --as apply). No input at a terminal: asks step by step.')
|
|
30
31
|
.option('--pending', 'queue in .arbiter/pending.md for later review instead of recording now')
|
|
31
32
|
.option('--findings <file>', "queue one pending decision per finding in a scanner's JSON output")
|
|
32
33
|
.option('--tool <name>', 'with --findings: the scanner name for the record')
|
|
33
34
|
.option('--candidate <id>', 'the candidate (C-0001) this decision was made for')
|
|
34
35
|
.option('--retire <rule-id>', 'drop an active rule with no replacement (needs --why)')
|
|
35
|
-
.option('--why <reason>', 'with --retire: why the rule is dead')
|
|
36
|
+
.option('--why <reason>', 'with --retire: why the rule is dead; with a request and --as decline: why not')
|
|
36
37
|
.option('--unverified', 'record even if the named files contradict the claim')
|
|
37
|
-
.option('--as <action>', 'judge a pending id: accept | rule | skip | fix')
|
|
38
|
+
.option('--as <action>', 'judge a pending id: accept | rule | skip | fix; answer a request id: apply | decline')
|
|
39
|
+
.option('--request <id>', 'the approved request (R-0001) this change was made for — recording it applies the request')
|
|
38
40
|
.option('--all', 'with --as: judge every pending item the same way')
|
|
39
41
|
.option('--level <level>', 'with --all: only this level (feature | pattern | polish)')
|
|
40
42
|
.option('--trigger <text>', 'with --all: only items queued for this piece of work')
|
|
41
|
-
.option('--to <decision>', 'with --as fix: what it should be instead')
|
|
43
|
+
.option('--to <decision>', 'with --as fix: what it should be instead; with a request and --as apply: what to do instead of what was asked')
|
|
42
44
|
.option('--supersedes <id>', 'the active rule this one replaces')
|
|
43
45
|
.option('--ref <url|key>', 'the ticket this was for: a URL or an issue key like ENG-123')
|
|
44
46
|
.option('--keep-both', 'record alongside overlapping rules instead of replacing one')
|
|
@@ -70,6 +72,15 @@ program
|
|
|
70
72
|
result = (0, record_1.judge)(arg, { ...opts, as });
|
|
71
73
|
}
|
|
72
74
|
}
|
|
75
|
+
else if (arg && /^R-\d{4,}$/.test(arg)) {
|
|
76
|
+
const as = opts.as;
|
|
77
|
+
if (!as || !['apply', 'decline'].includes(as)) {
|
|
78
|
+
result = { exitCode: 1, output: { status: 'invalid', errors: ['answering a request needs --as apply (Apply, but…: add --to "<instead>") | decline --why "<reason>"'] } };
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
result = (0, request_1.judgeRequest)(arg, { ...opts, as });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
73
84
|
else {
|
|
74
85
|
let input = arg ?? (await readStdin());
|
|
75
86
|
if (!input.trim() && process.stdin.isTTY)
|
|
@@ -132,8 +143,9 @@ program
|
|
|
132
143
|
});
|
|
133
144
|
program
|
|
134
145
|
.command('setup')
|
|
135
|
-
.description('Save how Arbiter checks in while you work: --checkin feature (one line after big work) | quiet | every. Marks the project as onboarded.')
|
|
146
|
+
.description('Save how Arbiter checks in while you work: --checkin feature (one line after big work) | quiet (nothing, no questions) | every. Except under quiet, the agent asks whether to review at 5, 10, 15 waiting. Marks the project as onboarded. --app saves where the app runs.')
|
|
136
147
|
.option('--checkin <mode>', 'feature | quiet | every')
|
|
148
|
+
.option('--app <url>', 'where the app runs, for screenshots: http://localhost:3000 or a staging address (on its own, saves only this)')
|
|
137
149
|
.action((opts) => {
|
|
138
150
|
const result = (0, setup_1.setup)(opts);
|
|
139
151
|
process.stdout.write(JSON.stringify(result.output, null, 2) + '\n');
|
|
@@ -217,7 +229,7 @@ program
|
|
|
217
229
|
});
|
|
218
230
|
program
|
|
219
231
|
.command('pull')
|
|
220
|
-
.description('Fetch comments and "looks good" reactions from the hosted board into .arbiter/comments.json.')
|
|
232
|
+
.description('Fetch comments and "looks good" reactions from the hosted board into .arbiter/comments.json. "Request change" becomes a request (R-0001) to answer.')
|
|
221
233
|
.action(async () => {
|
|
222
234
|
process.stdout.write((await (0, pull_1.pull)()) + '\n');
|
|
223
235
|
});
|
|
@@ -275,10 +287,10 @@ program
|
|
|
275
287
|
});
|
|
276
288
|
program
|
|
277
289
|
.command('rules [id]')
|
|
278
|
-
.description('Read decisions. No args: active rules. An id (D-0003): that one in full.')
|
|
290
|
+
.description('Read decisions. No args: active rules. An id (D-0003, or a request R-0001): that one in full.')
|
|
279
291
|
.option('--dimension <name>', 'only one dimension (structure, interaction, states, content, visual, motion, access)')
|
|
280
292
|
.option('--archive', 'everything ever recorded — accepts, fixes, superseded — oldest first')
|
|
281
|
-
.option('--pending', 'queued decisions not yet judged')
|
|
293
|
+
.option('--pending', 'queued decisions not yet judged, and requests from the board not yet answered or made')
|
|
282
294
|
.option('--json', 'machine-readable output')
|
|
283
295
|
.action((id, opts) => {
|
|
284
296
|
process.stdout.write((0, rules_1.rules)(id, opts) + '\n');
|
package/dist/pictures.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Which cards should have a picture and don't. The board covers a card without one in an icon
|
|
4
|
+
* of its kind, so a missing picture never looks broken there, which is exactly why nobody
|
|
5
|
+
* notices. This tells the only people who can still fix it: the agent at `record`, the author
|
|
6
|
+
* at `publish` and on the review page. Never the board's viewers.
|
|
7
|
+
*
|
|
8
|
+
* A change earns a picture when you could point at it on one screen and a still would show it:
|
|
9
|
+
* its layout, its words, its looks. Behaviour doesn't show in a still (interaction, motion,
|
|
10
|
+
* access), a state is photographed only if you were already looking at it, and a global change
|
|
11
|
+
* has no one screen. Polish never reaches the board, so it never asks either, and nor does a
|
|
12
|
+
* scanner finding: it's a line in a file, not a screen.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.pictureHint = exports.needsPicture = void 0;
|
|
16
|
+
exports.missingPictures = missingPictures;
|
|
17
|
+
const candidates_1 = require("./candidates");
|
|
18
|
+
const findings_1 = require("./findings");
|
|
19
|
+
const work_1 = require("./work");
|
|
20
|
+
const PICTURED = ['structure', 'content', 'visual'];
|
|
21
|
+
/** Would a picture of one screen show this change, on a card the board will have? */
|
|
22
|
+
const needsPicture = (d) => d.scope !== 'global' && d.level !== 'polish' && d.verdict !== 'retire' && PICTURED.includes(d.dimension) && !(0, findings_1.isFinding)(d);
|
|
23
|
+
exports.needsPicture = needsPicture;
|
|
24
|
+
/**
|
|
25
|
+
* One entry per card that should have a picture and has none. Cards are found the way the board
|
|
26
|
+
* builds them: a decision on a known candidate rides with it, the rest group by piece of work.
|
|
27
|
+
* A rejected or replaced direction is gone from the app, so nothing asks for its picture.
|
|
28
|
+
*/
|
|
29
|
+
function missingPictures(paths, decisions, candidates = (0, candidates_1.readCandidates)(paths)) {
|
|
30
|
+
const byId = new Map(candidates.map((c) => [c.id, c]));
|
|
31
|
+
const out = new Map();
|
|
32
|
+
for (const d of decisions) {
|
|
33
|
+
if (!(0, exports.needsPicture)(d))
|
|
34
|
+
continue;
|
|
35
|
+
const c = d.candidate ? byId.get(d.candidate) : undefined;
|
|
36
|
+
if (c) {
|
|
37
|
+
if (c.snapshot || c.state === 'rejected' || c.state === 'superseded')
|
|
38
|
+
continue;
|
|
39
|
+
out.set(c.id, { name: c.name, command: `npx arbiter candidate ${c.id} --snapshot shot.png` });
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const id = (0, work_1.workId)(d.trigger);
|
|
43
|
+
if ((0, work_1.workSnapshot)(paths, id))
|
|
44
|
+
continue;
|
|
45
|
+
out.set(id, { name: d.trigger, command: `npx arbiter snapshot ${JSON.stringify(d.trigger)} --file shot.png` });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return [...out.values()];
|
|
49
|
+
}
|
|
50
|
+
/** The line an agent reads in `record`'s reply, with the app's address when arbiter.json has one. */
|
|
51
|
+
const pictureHint = (m, app) => `No picture of "${m.name}" yet. ${app ? `The app runs at ${app}; if` : 'If'} you can open that screen, take one now (see Screenshots in the skill): ${m.command}`;
|
|
52
|
+
exports.pictureHint = pictureHint;
|
package/dist/requests.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Requests — someone on the board asked for a change, and it has to go somewhere.
|
|
4
|
+
*
|
|
5
|
+
* A comment is input: it sits in .arbiter/comments.json until the owner points at it. A request
|
|
6
|
+
* is a comment that asks for something, so it gets a status and an answer:
|
|
7
|
+
*
|
|
8
|
+
* open pulled, nobody has answered it
|
|
9
|
+
* approved the owner said Apply (or Apply, but…) — the agent makes the change at the next /arbiter
|
|
10
|
+
* applied the change is in the code and recorded; `decisions` says which records did it
|
|
11
|
+
* declined the owner said no, with a reason the requester reads on the board
|
|
12
|
+
*
|
|
13
|
+
* Nothing moves without the owner: pull opens them, only the owner approves or declines, and only
|
|
14
|
+
* an approved request can be applied. The board never writes here — publish carries the answers
|
|
15
|
+
* back as part of the board.
|
|
16
|
+
*
|
|
17
|
+
* .arbiter/requests.json, committed, so everyone on the project sees the same answers.
|
|
18
|
+
*/
|
|
19
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
20
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.oneLine = exports.REQUEST_STATUSES = exports.REQUEST_ID = void 0;
|
|
24
|
+
exports.readRequests = readRequests;
|
|
25
|
+
exports.writeRequests = writeRequests;
|
|
26
|
+
exports.findRequest = findRequest;
|
|
27
|
+
exports.nextRequestId = nextRequestId;
|
|
28
|
+
exports.openRequests = openRequests;
|
|
29
|
+
exports.dropWithdrawn = dropWithdrawn;
|
|
30
|
+
exports.detachDecision = detachDecision;
|
|
31
|
+
exports.replaceRequest = replaceRequest;
|
|
32
|
+
exports.screenName = screenName;
|
|
33
|
+
exports.cardOf = cardOf;
|
|
34
|
+
exports.describe = describe;
|
|
35
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
36
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
37
|
+
const candidates_1 = require("./candidates");
|
|
38
|
+
const store_1 = require("./store");
|
|
39
|
+
const work_1 = require("./work");
|
|
40
|
+
exports.REQUEST_ID = /^R-\d{4,}$/;
|
|
41
|
+
exports.REQUEST_STATUSES = ['open', 'approved', 'applied', 'declined'];
|
|
42
|
+
const FILE = 'requests.json';
|
|
43
|
+
const NAME_MAX = 120;
|
|
44
|
+
/** The board's own limit on what someone can write. */
|
|
45
|
+
const BODY_MAX = 4000;
|
|
46
|
+
function readRequests(paths) {
|
|
47
|
+
const f = node_path_1.default.join(paths.archiveDir, FILE);
|
|
48
|
+
if (!node_fs_1.default.existsSync(f))
|
|
49
|
+
return [];
|
|
50
|
+
// Committed and rewritten on every pull, so a merge conflict is the likely way it breaks: say so
|
|
51
|
+
// plainly, before any command has written anything else.
|
|
52
|
+
try {
|
|
53
|
+
// A byte-order mark is what a file saved from PowerShell 5 starts with; it's not a conflict.
|
|
54
|
+
const all = JSON.parse(node_fs_1.default.readFileSync(f, 'utf8').replace(/^/, ''));
|
|
55
|
+
if (!Array.isArray(all))
|
|
56
|
+
throw new Error('not a list');
|
|
57
|
+
return all;
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
throw new Error(`.arbiter/requests.json can't be read (${e.message.split('\n')[0]}) — a merge conflict? Fix the file, then run this again.`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function writeRequests(paths, requests) {
|
|
64
|
+
node_fs_1.default.mkdirSync(paths.archiveDir, { recursive: true });
|
|
65
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(paths.archiveDir, FILE), JSON.stringify(requests, null, 2) + '\n');
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* One request by its id. Two sharing an id (a hand-merged file) is refused, not guessed: answering
|
|
69
|
+
* the wrong one would make, or decline, a change nobody asked about.
|
|
70
|
+
*/
|
|
71
|
+
function findRequest(all, id) {
|
|
72
|
+
const hits = all.filter((r) => r.id === id);
|
|
73
|
+
if (hits.length > 1)
|
|
74
|
+
return { error: `${id} is in .arbiter/requests.json ${hits.length} times, for different requests (a merge kept both?). Give each its own id in the file, then run this again.` };
|
|
75
|
+
return { request: hits[0] };
|
|
76
|
+
}
|
|
77
|
+
function nextRequestId(requests) {
|
|
78
|
+
const max = requests.reduce((m, r) => Math.max(m, Number(r.id.slice(2))), 0);
|
|
79
|
+
return `R-${String(max + 1).padStart(4, '0')}`;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Every request comment that isn't a request here yet becomes one, open. Keyed on the comment,
|
|
83
|
+
* so pulling twice — or two people pulling the same board — never asks the owner twice.
|
|
84
|
+
*/
|
|
85
|
+
function openRequests(paths, comments) {
|
|
86
|
+
const all = readRequests(paths);
|
|
87
|
+
const seen = new Set(all.map((r) => r.comment));
|
|
88
|
+
const added = [];
|
|
89
|
+
for (const c of comments) {
|
|
90
|
+
// A request with no words, or not attached to a card, is nothing to answer — and saving it would
|
|
91
|
+
// break every later read of the queue.
|
|
92
|
+
if (c.kind !== 'request' || seen.has(c.id) || typeof c.body !== 'string' || !c.body.trim() || typeof c.candidate_id !== 'string' || !c.candidate_id)
|
|
93
|
+
continue;
|
|
94
|
+
// Anyone signed in on the board writes these, name included, and the name ends up in the
|
|
95
|
+
// record: one line, a sane length. The words keep their lines; they're cut at the board's cap.
|
|
96
|
+
const name = typeof c.author_name === 'string' ? (0, exports.oneLine)(c.author_name).slice(0, NAME_MAX) : '';
|
|
97
|
+
const r = {
|
|
98
|
+
id: nextRequestId(all),
|
|
99
|
+
comment: c.id,
|
|
100
|
+
screen: c.candidate_id,
|
|
101
|
+
decision: c.decision_id,
|
|
102
|
+
author: name || 'Someone',
|
|
103
|
+
body: c.body.trim().slice(0, BODY_MAX),
|
|
104
|
+
date: typeof c.created_at === 'string' && c.created_at ? c.created_at : (0, store_1.now)(),
|
|
105
|
+
boardVersion: c.board_version ?? null,
|
|
106
|
+
status: 'open',
|
|
107
|
+
instead: null,
|
|
108
|
+
reason: null,
|
|
109
|
+
judgedBy: null,
|
|
110
|
+
judgedAt: null,
|
|
111
|
+
decisions: [],
|
|
112
|
+
appliedAt: null,
|
|
113
|
+
};
|
|
114
|
+
all.push(r);
|
|
115
|
+
added.push(r);
|
|
116
|
+
seen.add(c.id);
|
|
117
|
+
}
|
|
118
|
+
if (added.length)
|
|
119
|
+
writeRequests(paths, all);
|
|
120
|
+
return added;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Requests the person who asked has deleted from the board. Only ones nobody has acted on go: an
|
|
124
|
+
* open one, or an approved one the agent hasn't made yet. Once the change is made it's in the
|
|
125
|
+
* record, and the board won't let an answered request be deleted anyway.
|
|
126
|
+
*/
|
|
127
|
+
function dropWithdrawn(paths, onBoard) {
|
|
128
|
+
const all = readRequests(paths);
|
|
129
|
+
const gone = all.filter((r) => (r.status === 'open' || r.status === 'approved') && !onBoard.has(r.comment));
|
|
130
|
+
if (gone.length)
|
|
131
|
+
writeRequests(paths, all.filter((r) => !gone.includes(r)));
|
|
132
|
+
return gone;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* A decision is leaving the record (`remove`). If a request was applied by it, the request no
|
|
136
|
+
* longer is. With nothing left doing it, it goes back to open — not approved: the owner removed
|
|
137
|
+
* that record for a reason, and an approved request is one the agent makes without asking.
|
|
138
|
+
*/
|
|
139
|
+
function detachDecision(paths, decisionId) {
|
|
140
|
+
const all = readRequests(paths);
|
|
141
|
+
const touched = all.filter((r) => r.decisions.includes(decisionId));
|
|
142
|
+
if (!touched.length)
|
|
143
|
+
return [];
|
|
144
|
+
const next = all.map((r) => {
|
|
145
|
+
if (!r.decisions.includes(decisionId))
|
|
146
|
+
return r;
|
|
147
|
+
const decisions = r.decisions.filter((d) => d !== decisionId);
|
|
148
|
+
return decisions.length ? { ...r, decisions } : { ...r, decisions, status: 'open', instead: null, judgedBy: null, judgedAt: null, appliedAt: null };
|
|
149
|
+
});
|
|
150
|
+
writeRequests(paths, next);
|
|
151
|
+
return next.filter((r) => touched.some((t) => t.comment === r.comment));
|
|
152
|
+
}
|
|
153
|
+
/** Replace one request, found by its comment — unique, where a hand-merged file could repeat an id. */
|
|
154
|
+
function replaceRequest(paths, all, next) {
|
|
155
|
+
writeRequests(paths, all.map((x) => (x.comment === next.comment ? next : x)));
|
|
156
|
+
}
|
|
157
|
+
/** One line, however it was typed on the board — for places that need a single line. */
|
|
158
|
+
const oneLine = (s) => s.replace(/\s+/g, ' ').trim();
|
|
159
|
+
exports.oneLine = oneLine;
|
|
160
|
+
/**
|
|
161
|
+
* What a card is called. A candidate by its name; a piece of work by the trigger its decisions
|
|
162
|
+
* share — the same name to use as the trigger when recording the change, so it lands on that card.
|
|
163
|
+
*/
|
|
164
|
+
function screenName(paths, screen, archive = (0, store_1.readArchive)(paths)) {
|
|
165
|
+
if (typeof screen !== 'string')
|
|
166
|
+
return null;
|
|
167
|
+
if (screen.startsWith('C-'))
|
|
168
|
+
return (0, candidates_1.readCandidates)(paths).find((c) => c.id === screen)?.name ?? null;
|
|
169
|
+
return archive.find((d) => (0, work_1.workId)(d.trigger) === screen)?.trigger ?? null;
|
|
170
|
+
}
|
|
171
|
+
/** The card a recorded decision shows on: its candidate if that's still a screen, else its piece of work. */
|
|
172
|
+
function cardOf(paths, d, candidateIds = new Set((0, candidates_1.readCandidates)(paths).map((c) => c.id))) {
|
|
173
|
+
return d.candidate && candidateIds.has(d.candidate) ? d.candidate : (0, work_1.workId)(d.trigger);
|
|
174
|
+
}
|
|
175
|
+
/** A request as the queue shows it: who asked what, where, and whether the board has moved on since. */
|
|
176
|
+
function describe(paths, r, boardVersion, archive = (0, store_1.readArchive)(paths)) {
|
|
177
|
+
return {
|
|
178
|
+
id: r.id,
|
|
179
|
+
author: r.author,
|
|
180
|
+
body: r.body,
|
|
181
|
+
screen: r.screen,
|
|
182
|
+
screenName: screenName(paths, r.screen, archive),
|
|
183
|
+
decision: r.decision,
|
|
184
|
+
// What that decision says, so the question can show it without another lookup.
|
|
185
|
+
decisionText: r.decision ? (archive.find((d) => d.id === r.decision)?.decision ?? null) : null,
|
|
186
|
+
date: r.date,
|
|
187
|
+
// Asked about a board that has since been republished — what they saw may already have changed.
|
|
188
|
+
earlierVersion: !!(r.boardVersion && boardVersion && r.boardVersion !== boardVersion),
|
|
189
|
+
status: r.status,
|
|
190
|
+
instead: r.instead,
|
|
191
|
+
// Approved: what the agent is to make — the ask, or what the owner said instead.
|
|
192
|
+
...(r.status === 'approved' && { do: r.instead ?? r.body }),
|
|
193
|
+
};
|
|
194
|
+
}
|
package/dist/store.js
CHANGED
|
@@ -23,8 +23,10 @@ exports.nextPendingId = nextPendingId;
|
|
|
23
23
|
exports.nextId = nextId;
|
|
24
24
|
exports.currentCommit = currentCommit;
|
|
25
25
|
exports.gitUserName = gitUserName;
|
|
26
|
+
exports.currentAuthor = currentAuthor;
|
|
26
27
|
exports.now = now;
|
|
27
28
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
29
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
28
30
|
const node_path_1 = __importDefault(require("node:path"));
|
|
29
31
|
const node_child_process_1 = require("node:child_process");
|
|
30
32
|
const format_1 = require("./format");
|
|
@@ -137,6 +139,13 @@ function gitUserName(root) {
|
|
|
137
139
|
return null;
|
|
138
140
|
}
|
|
139
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Whoever is at the keyboard. arbiter.json's author is committed, so in a shared repo it names
|
|
144
|
+
* whoever ran init — it's the fallback for a machine with no git identity, not the default.
|
|
145
|
+
*/
|
|
146
|
+
function currentAuthor(root) {
|
|
147
|
+
return gitUserName(root) ?? readConfig(resolvePaths(root))?.author ?? node_os_1.default.userInfo().username;
|
|
148
|
+
}
|
|
140
149
|
/** Timestamp without milliseconds: 2026-09-15T14:32:10Z */
|
|
141
150
|
function now() {
|
|
142
151
|
return new Date().toISOString().replace(/\.\d{3}Z$/, 'Z');
|
package/package.json
CHANGED