arbiterdesign 0.1.3 → 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 +65 -10
- package/dist/autopublish.js +81 -0
- package/dist/commands/export.js +9 -6
- package/dist/commands/init.js +4 -0
- package/dist/commands/publish.js +33 -5
- package/dist/commands/pull.js +25 -4
- package/dist/commands/record.js +80 -14
- package/dist/commands/remove.js +248 -0
- package/dist/commands/request.js +123 -0
- package/dist/commands/review.js +109 -9
- package/dist/commands/rules.js +61 -7
- package/dist/commands/setup.js +39 -2
- package/dist/commands/snapshot.js +17 -2
- package/dist/findings.js +10 -1
- package/dist/format.js +21 -13
- package/dist/hosted.js +60 -13
- package/dist/index.js +62 -11
- package/dist/pictures.js +52 -0
- package/dist/requests.js +194 -0
- package/dist/store.js +19 -0
- package/package.json +1 -1
- package/templates/SKILL.md +233 -32
- package/templates/review.html +114 -4
package/dist/commands/record.js
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* record P-0003 --as rule judge a queued decision (accept | rule | skip | fix --to "<what instead>")
|
|
8
8
|
* record --all --as accept judge every queued decision the same way [--level polish] [--trigger "…"]
|
|
9
9
|
* record --retire D-0003 --why "…" drop a rule from DECISIONS.md with no replacement; the archive keeps both
|
|
10
|
+
* record R-0001 --as apply answer a request from the board (apply [--to "<instead>"] | decline --why "…")
|
|
11
|
+
* record '<json>' --request R-0001 record the change made for an approved request; it's applied
|
|
10
12
|
* record (a person at a terminal) walk through it step by step
|
|
11
13
|
*
|
|
12
14
|
* Output is JSON on stdout, always — an agent is usually on the other end.
|
|
@@ -22,6 +24,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
24
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
25
|
};
|
|
24
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.REVIEW_EVERY = void 0;
|
|
25
28
|
exports.record = record;
|
|
26
29
|
exports.queue = queue;
|
|
27
30
|
exports.queueFindings = queueFindings;
|
|
@@ -30,7 +33,6 @@ exports.judge = judge;
|
|
|
30
33
|
exports.judgeAll = judgeAll;
|
|
31
34
|
exports.recordInput = recordInput;
|
|
32
35
|
exports.interactiveInput = interactiveInput;
|
|
33
|
-
const node_os_1 = __importDefault(require("node:os"));
|
|
34
36
|
const node_path_1 = __importDefault(require("node:path"));
|
|
35
37
|
const schema_1 = require("../schema");
|
|
36
38
|
const store_1 = require("../store");
|
|
@@ -42,6 +44,8 @@ const prompt_1 = require("./prompt");
|
|
|
42
44
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
43
45
|
const candidate_1 = require("./candidate");
|
|
44
46
|
const update_1 = require("./update");
|
|
47
|
+
const pictures_1 = require("../pictures");
|
|
48
|
+
const request_1 = require("./request");
|
|
45
49
|
// ── Parse + record ─────────────────────────────────────────────────────────
|
|
46
50
|
function record(rawJson, opts = {}) {
|
|
47
51
|
const parsed = parse(rawJson);
|
|
@@ -50,6 +54,8 @@ function record(rawJson, opts = {}) {
|
|
|
50
54
|
return recordInput(parsed.input, opts);
|
|
51
55
|
}
|
|
52
56
|
function queue(rawJson, opts = {}) {
|
|
57
|
+
if (opts.request)
|
|
58
|
+
return fail([`--request records a change made for an approved request, directly: drop --pending. Nothing is queued for a request.`]);
|
|
53
59
|
const parsed = parse(rawJson, { pending: true });
|
|
54
60
|
if (!parsed.ok)
|
|
55
61
|
return parsed.result;
|
|
@@ -64,6 +70,10 @@ function queue(rawJson, opts = {}) {
|
|
|
64
70
|
if (entry.candidate)
|
|
65
71
|
(0, candidate_1.refreshCandidates)(paths);
|
|
66
72
|
}
|
|
73
|
+
// What the user would actually be asked about: polish is logged with its group, never presented.
|
|
74
|
+
const before = pending.filter((d) => d.level !== 'polish').length;
|
|
75
|
+
const waiting = before + (entry.level === 'polish' ? 0 : 1);
|
|
76
|
+
const checkin = (0, store_1.readConfig)(paths)?.checkin ?? 'feature';
|
|
67
77
|
return {
|
|
68
78
|
exitCode: 0,
|
|
69
79
|
output: {
|
|
@@ -72,13 +82,29 @@ function queue(rawJson, opts = {}) {
|
|
|
72
82
|
dimension: entry.dimension,
|
|
73
83
|
verified: entry.verified,
|
|
74
84
|
pending: pending.length + 1,
|
|
75
|
-
checkin
|
|
85
|
+
checkin,
|
|
86
|
+
waiting,
|
|
87
|
+
// A dry run wrote nothing, so the count it reached isn't real yet.
|
|
88
|
+
...(opts.dryRun ? {} : askToReview(before, waiting, checkin)),
|
|
76
89
|
review: 'npx arbiter review',
|
|
90
|
+
...picture(paths, entry),
|
|
77
91
|
// Present only when the project's skill file is from an older Arbiter than this one.
|
|
78
92
|
...(0, update_1.updateNotice)(paths),
|
|
79
93
|
},
|
|
80
94
|
};
|
|
81
95
|
}
|
|
96
|
+
/** Ask once each time the waiting count reaches another multiple of this. */
|
|
97
|
+
exports.REVIEW_EVERY = 5;
|
|
98
|
+
/**
|
|
99
|
+
* At 5, 10, 15 changes waiting, the agent asks whether to review now. A "no" just waits for the
|
|
100
|
+
* next multiple, and judging brings the count down, so the next ask comes when it climbs back.
|
|
101
|
+
* Quiet means quiet: someone who chose "Nothing until I ask" is never asked.
|
|
102
|
+
*/
|
|
103
|
+
function askToReview(before, after, checkin) {
|
|
104
|
+
if (checkin === 'quiet' || Math.floor(after / exports.REVIEW_EVERY) <= Math.floor(before / exports.REVIEW_EVERY))
|
|
105
|
+
return {};
|
|
106
|
+
return { ask: `You have ${after} changes waiting in Arbiter. Review them now? (yes / no)` };
|
|
107
|
+
}
|
|
82
108
|
/** Queue one pending decision per finding in a scanner's JSON output. */
|
|
83
109
|
function queueFindings(file, opts = {}) {
|
|
84
110
|
const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
|
|
@@ -94,6 +120,7 @@ function queueFindings(file, opts = {}) {
|
|
|
94
120
|
return fail(['no findings recognised in that file — expected an array of { file, message, line?, rule?, suggestion? } or ESLint-style output']);
|
|
95
121
|
const tool = opts.tool ?? node_path_1.default.basename(file, node_path_1.default.extname(file));
|
|
96
122
|
const pending = (0, store_1.readPending)(paths);
|
|
123
|
+
const before = pending.filter((d) => d.level !== 'polish').length;
|
|
97
124
|
const seen = new Set(pending.map((d) => d.trigger));
|
|
98
125
|
const added = [];
|
|
99
126
|
let skipped = 0;
|
|
@@ -110,7 +137,24 @@ function queueFindings(file, opts = {}) {
|
|
|
110
137
|
}
|
|
111
138
|
if (!opts.dryRun)
|
|
112
139
|
(0, store_1.writePending)(paths, pending);
|
|
113
|
-
|
|
140
|
+
// Findings are asked about like any other queued change, so they count toward the review question.
|
|
141
|
+
const waiting = pending.filter((d) => d.level !== 'polish').length;
|
|
142
|
+
const checkin = (0, store_1.readConfig)(paths)?.checkin ?? 'feature';
|
|
143
|
+
return {
|
|
144
|
+
exitCode: 0,
|
|
145
|
+
output: {
|
|
146
|
+
status: 'queued',
|
|
147
|
+
tool,
|
|
148
|
+
queued: added.length,
|
|
149
|
+
skippedDuplicates: skipped,
|
|
150
|
+
ids: added,
|
|
151
|
+
pending: pending.length,
|
|
152
|
+
checkin,
|
|
153
|
+
waiting,
|
|
154
|
+
...(opts.dryRun ? {} : askToReview(before, waiting, checkin)),
|
|
155
|
+
review: 'npx arbiter review',
|
|
156
|
+
},
|
|
157
|
+
};
|
|
114
158
|
}
|
|
115
159
|
function parse(rawJson, options = {}) {
|
|
116
160
|
let raw;
|
|
@@ -191,6 +235,9 @@ function judge(pendingId, opts) {
|
|
|
191
235
|
function judgeAll(opts) {
|
|
192
236
|
if (opts.as === 'fix')
|
|
193
237
|
return fail(['fix is one at a time — it needs its own --to']);
|
|
238
|
+
// A request is applied by the change made for it, not by everything that happens to be queued.
|
|
239
|
+
if (opts.request)
|
|
240
|
+
return fail([`--request links one change to ${opts.request}; it can't go on --all`]);
|
|
194
241
|
const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
|
|
195
242
|
const targets = (0, store_1.readPending)(paths).filter((d) => (!opts.level || d.level === opts.level) && (!opts.trigger || d.trigger === opts.trigger));
|
|
196
243
|
if (!targets.length)
|
|
@@ -225,15 +272,28 @@ function recordInput(input, opts = {}) {
|
|
|
225
272
|
const paths = (0, store_1.resolvePaths)(root);
|
|
226
273
|
const config = (0, store_1.readConfig)(paths);
|
|
227
274
|
const cap = config?.activeCap ?? store_1.ACTIVE_CAP;
|
|
275
|
+
// A change made for a request from the board — only once the owner has said yes.
|
|
276
|
+
let request = null;
|
|
277
|
+
if (opts.request) {
|
|
278
|
+
const gate = (0, request_1.requestGate)(paths, opts.request);
|
|
279
|
+
if (!gate.ok)
|
|
280
|
+
return fail(gate.errors);
|
|
281
|
+
request = gate.request;
|
|
282
|
+
input = (0, request_1.withRequest)(paths, input, request);
|
|
283
|
+
}
|
|
228
284
|
const active = (0, store_1.readActive)(paths);
|
|
229
285
|
const archive = (0, store_1.readArchive)(paths);
|
|
230
286
|
const supersedes = opts.supersedes ?? input.supersedes ?? null;
|
|
231
287
|
const entry = { ...fill(input, opts, root), id: (0, store_1.nextId)(archive), supersedes };
|
|
288
|
+
// Nothing written means the request isn't applied yet. Whatever the re-run is, it has to carry
|
|
289
|
+
// --request too, or the change lands and the request stays approved, to be made again.
|
|
290
|
+
const again = request ? ` --request ${request.id}` : '';
|
|
291
|
+
const keepRequest = (r) => request ? { ...r, output: { ...r.output, request: request.id, note: `Nothing was written, so ${request.id} isn't applied yet. Re-run with${again}.` } } : r;
|
|
232
292
|
// An `accept` is a deviation by definition — nothing to verify. Rules and fixes make claims.
|
|
233
293
|
if (entry.verdict !== 'accept') {
|
|
234
294
|
const checked = check(entry, root, opts);
|
|
235
295
|
if (checked)
|
|
236
|
-
return checked;
|
|
296
|
+
return keepRequest(checked);
|
|
237
297
|
}
|
|
238
298
|
let nextActive = active;
|
|
239
299
|
if (entry.verdict === 'retire') {
|
|
@@ -257,7 +317,7 @@ function recordInput(input, opts = {}) {
|
|
|
257
317
|
else if (!opts.keepBoth) {
|
|
258
318
|
const overlaps = (0, overlap_1.findOverlaps)(input, active, { ignore: config?.overlap?.ignore });
|
|
259
319
|
if (overlaps.length) {
|
|
260
|
-
return {
|
|
320
|
+
return keepRequest({
|
|
261
321
|
exitCode: 2,
|
|
262
322
|
output: {
|
|
263
323
|
status: 'overlap',
|
|
@@ -266,17 +326,17 @@ function recordInput(input, opts = {}) {
|
|
|
266
326
|
overlaps,
|
|
267
327
|
options: [
|
|
268
328
|
...overlaps.map((o) => ({
|
|
269
|
-
flag: `--supersedes ${o.id}`,
|
|
329
|
+
flag: `--supersedes ${o.id}${again}`,
|
|
270
330
|
effect: `${o.id} leaves DECISIONS.md and stays in the archive; the new rule records supersedes: ${o.id}`,
|
|
271
331
|
})),
|
|
272
|
-
{ flag:
|
|
332
|
+
{ flag: `--keep-both${again}`, effect: 'both rules stay active' },
|
|
273
333
|
],
|
|
274
334
|
},
|
|
275
|
-
};
|
|
335
|
+
});
|
|
276
336
|
}
|
|
277
337
|
}
|
|
278
338
|
if (nextActive.length >= cap) {
|
|
279
|
-
return {
|
|
339
|
+
return keepRequest({
|
|
280
340
|
exitCode: 3,
|
|
281
341
|
output: {
|
|
282
342
|
status: 'cap',
|
|
@@ -284,7 +344,7 @@ function recordInput(input, opts = {}) {
|
|
|
284
344
|
candidate: input,
|
|
285
345
|
active: nextActive.map((d) => ({ id: d.id, decision: d.decision, scope: d.scope })),
|
|
286
346
|
},
|
|
287
|
-
};
|
|
347
|
+
});
|
|
288
348
|
}
|
|
289
349
|
nextActive = [...nextActive, entry];
|
|
290
350
|
}
|
|
@@ -294,6 +354,8 @@ function recordInput(input, opts = {}) {
|
|
|
294
354
|
(0, store_1.writeActive)(paths, nextActive, cap);
|
|
295
355
|
if (entry.candidate)
|
|
296
356
|
(0, candidate_1.refreshCandidates)(paths);
|
|
357
|
+
if (request)
|
|
358
|
+
(0, request_1.markApplied)(paths, request, entry.id);
|
|
297
359
|
}
|
|
298
360
|
// A new mechanical rule reaches backwards: say how much existing code it touches.
|
|
299
361
|
let sweepSummary;
|
|
@@ -316,10 +378,17 @@ function recordInput(input, opts = {}) {
|
|
|
316
378
|
candidate: entry.candidate,
|
|
317
379
|
active: `${nextActive.length} of ${cap}`,
|
|
318
380
|
wrote: opts.dryRun ? [] : entry.verdict === 'rule' || entry.verdict === 'retire' ? ['.arbiter/archive.md', 'DECISIONS.md'] : ['.arbiter/archive.md'],
|
|
381
|
+
...(request && { request: { id: request.id, status: opts.dryRun ? request.status : 'applied', author: request.author } }),
|
|
319
382
|
...(sweepSummary && { sweep: sweepSummary }),
|
|
383
|
+
...picture(paths, entry),
|
|
320
384
|
},
|
|
321
385
|
};
|
|
322
386
|
}
|
|
387
|
+
/** The agent is still there with the app running: the moment to say a screen has no picture. */
|
|
388
|
+
function picture(paths, entry) {
|
|
389
|
+
const [m] = (0, pictures_1.missingPictures)(paths, [entry]);
|
|
390
|
+
return m ? { picture: (0, pictures_1.pictureHint)(m, (0, store_1.readConfig)(paths)?.app?.url) } : {};
|
|
391
|
+
}
|
|
323
392
|
/**
|
|
324
393
|
* Check a decision's claim against its files. Sets `verified`; returns a
|
|
325
394
|
* failing result if contradicted and the caller didn't say --unverified.
|
|
@@ -344,12 +413,9 @@ function check(entry, root, opts) {
|
|
|
344
413
|
}
|
|
345
414
|
/** Fill the fields the caller doesn't supply. Id is set by the caller. */
|
|
346
415
|
function fill(input, opts, root) {
|
|
347
|
-
const config = (0, store_1.readConfig)((0, store_1.resolvePaths)(root));
|
|
348
416
|
return {
|
|
349
417
|
date: input.date ?? (0, store_1.now)(),
|
|
350
|
-
|
|
351
|
-
// whoever ran init — it's the fallback for a machine with no git identity, not the default.
|
|
352
|
-
author: opts.author ?? input.author ?? (0, store_1.gitUserName)(root) ?? config?.author ?? node_os_1.default.userInfo().username,
|
|
418
|
+
author: opts.author ?? input.author ?? (0, store_1.currentAuthor)(root),
|
|
353
419
|
class: input.class,
|
|
354
420
|
dimension: input.dimension,
|
|
355
421
|
decision: input.decision,
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `arbiter remove` and `arbiter unlink` — the exits Arbiter was missing.
|
|
4
|
+
*
|
|
5
|
+
* Three verbs, and they mean different things:
|
|
6
|
+
*
|
|
7
|
+
* retire it was real, it's over → the rule leaves DECISIONS.md, the archive keeps it
|
|
8
|
+
* remove it was never real → it leaves the record entirely
|
|
9
|
+
* unlink it was real, wrongly attached → the decision stays, its screen doesn't
|
|
10
|
+
*
|
|
11
|
+
* Append-only is right for judgments: a call you changed your mind about is superseded, and that
|
|
12
|
+
* history is the point. It's wrong for mistakes. A test entry, an agent misfire, or a screen
|
|
13
|
+
* invented to work around a bug isn't history — it's a record that says something false, and
|
|
14
|
+
* keeping it forever makes the archive less trustworthy, not more.
|
|
15
|
+
*
|
|
16
|
+
* So `remove` deletes. Git holds the history for anyone who has it, and the output prints what
|
|
17
|
+
* went, in full, for anyone who doesn't. Nothing is removed while something still points at it.
|
|
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.remove = remove;
|
|
24
|
+
exports.removeSnapshot = removeSnapshot;
|
|
25
|
+
exports.unlink = unlink;
|
|
26
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
27
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
28
|
+
const schema_1 = require("../schema");
|
|
29
|
+
const format_1 = require("../format");
|
|
30
|
+
const store_1 = require("../store");
|
|
31
|
+
const candidates_1 = require("../candidates");
|
|
32
|
+
const destination_1 = require("../destination");
|
|
33
|
+
const work_1 = require("../work");
|
|
34
|
+
const requests_1 = require("../requests");
|
|
35
|
+
const fail = (errors) => ({ exitCode: 1, output: { status: 'invalid', errors } });
|
|
36
|
+
// ── remove ─────────────────────────────────────────────────────────────────
|
|
37
|
+
function remove(id, opts = {}) {
|
|
38
|
+
const raw = id?.trim() ?? '';
|
|
39
|
+
if (schema_1.DECISION_ID.test(raw))
|
|
40
|
+
return removeDecision(raw, opts);
|
|
41
|
+
if (schema_1.CANDIDATE_ID.test(raw))
|
|
42
|
+
return removeCandidate(raw, opts);
|
|
43
|
+
if (/^P-\d{4,}$/.test(raw))
|
|
44
|
+
return fail([`${raw} is still in the queue — drop it with: npx arbiter record ${raw} --as skip`]);
|
|
45
|
+
return fail([`not something that can be removed: ${raw} (a decision like D-0004, a candidate like C-0001, or a piece of work by name)`]);
|
|
46
|
+
}
|
|
47
|
+
function removeDecision(id, opts) {
|
|
48
|
+
const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
|
|
49
|
+
const archive = (0, store_1.readArchive)(paths);
|
|
50
|
+
const entry = archive.find((d) => d.id === id);
|
|
51
|
+
if (!entry)
|
|
52
|
+
return fail([`${id} is not in the archive`]);
|
|
53
|
+
const active = (0, store_1.readActive)(paths);
|
|
54
|
+
const isActive = active.some((d) => d.id === id);
|
|
55
|
+
if (isActive && !opts.force) {
|
|
56
|
+
return fail([
|
|
57
|
+
`${id} is an active rule. If the rule is real and simply over, retiring keeps it in the record: npx arbiter record --retire ${id} --why "<reason>"`,
|
|
58
|
+
`If it was never a real rule, take it out of both: npx arbiter remove ${id} --force`,
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
const later = archive.find((d) => d.supersedes === id);
|
|
62
|
+
if (later) {
|
|
63
|
+
return fail([`${later.id} supersedes ${id} — removing it would leave ${later.id} pointing at nothing. Remove ${later.id} first if neither is real.`]);
|
|
64
|
+
}
|
|
65
|
+
// Read before anything is written: a broken requests.json must stop the removal, not interrupt it.
|
|
66
|
+
// A request still waiting that was asked about this decision would outlive it, and then read as
|
|
67
|
+
// if it were about whatever takes the id next.
|
|
68
|
+
const about = (0, requests_1.readRequests)(paths).filter((r) => r.decision === id && (r.status === 'open' || r.status === 'approved'));
|
|
69
|
+
if (about.length)
|
|
70
|
+
return fail([`${about.map((r) => `${r.id} (${r.author})`).join(', ')} ${about.length === 1 ? 'was' : 'were'} asked about ${id} and ${about.length === 1 ? 'is' : 'are'} still waiting. The owner answers first; if ${id} is going, that's a reason they can decline with.`]);
|
|
71
|
+
(0, store_1.writeArchive)(paths, archive.filter((d) => d.id !== id));
|
|
72
|
+
if (isActive) {
|
|
73
|
+
const config = (0, store_1.readConfig)(paths);
|
|
74
|
+
(0, store_1.writeActive)(paths, active.filter((d) => d.id !== id), config?.activeCap ?? store_1.ACTIVE_CAP);
|
|
75
|
+
}
|
|
76
|
+
const touched = refreshLinked(paths, entry.candidate);
|
|
77
|
+
// A request this decision applied isn't applied by nothing: with no record left doing it, it's
|
|
78
|
+
// open again, for the owner to answer afresh.
|
|
79
|
+
const detached = (0, requests_1.detachDecision)(paths, id);
|
|
80
|
+
const reopened = detached.filter((r) => r.status === 'open').map((r) => r.id);
|
|
81
|
+
// Removing a rule doesn't bring back the one it replaced: that one may have been real, and
|
|
82
|
+
// guessing would put a rule back the user never re-confirmed. Say so rather than lose it quietly.
|
|
83
|
+
const replaced = entry.supersedes && archive.find((d) => d.id === entry.supersedes);
|
|
84
|
+
// Ids come from the highest in the file, so taking the last one out frees it for the next
|
|
85
|
+
// decision. Locally that's harmless; on a board already published, comments point at the id.
|
|
86
|
+
const reused = archive.every((d) => d.id <= id) ? id : null;
|
|
87
|
+
return {
|
|
88
|
+
exitCode: 0,
|
|
89
|
+
output: {
|
|
90
|
+
status: 'removed',
|
|
91
|
+
id,
|
|
92
|
+
decision: entry.decision,
|
|
93
|
+
...(replaced ? { note: `${replaced.id} — which ${id} replaced — is still inactive. Record it again if it should apply.` } : {}),
|
|
94
|
+
...(reopened.length ? { requests: `${reopened.join(', ')} ${reopened.length === 1 ? 'is' : 'are'} open again — nothing on record makes ${reopened.length === 1 ? 'that change' : 'those changes'} now, so ${reopened.length === 1 ? 'it needs' : 'they need'} a fresh answer` } : {}),
|
|
95
|
+
...(reused ? { idReuse: `${id} was the newest, so the next decision recorded will take that id again. If this board is published, comments on the old ${id} will read as if they were about the new one — republish after recording.` } : {}),
|
|
96
|
+
wrote: ['.arbiter/archive.md', ...(isActive ? ['DECISIONS.md'] : []), ...touched, ...(detached.length ? ['.arbiter/requests.json'] : [])],
|
|
97
|
+
// Printed in full so it can be put back by hand — not everyone has git.
|
|
98
|
+
removed: (0, format_1.formatEntry)(entry).trimEnd(),
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function removeCandidate(id, opts) {
|
|
103
|
+
const root = (0, store_1.findRoot)(opts.cwd);
|
|
104
|
+
const paths = (0, store_1.resolvePaths)(root);
|
|
105
|
+
const all = (0, candidates_1.readCandidates)(paths);
|
|
106
|
+
const c = all.find((x) => x.id === id);
|
|
107
|
+
if (!c)
|
|
108
|
+
return fail([`${id} is not a candidate here`]);
|
|
109
|
+
const by = all.find((x) => x.supersededBy === id);
|
|
110
|
+
if (by)
|
|
111
|
+
return fail([`${by.id} says it was superseded by ${id} — clear that first: npx arbiter candidate ${by.id} --state generated`]);
|
|
112
|
+
// A request still waiting on this screen would outlive it — and point at whatever takes its id next.
|
|
113
|
+
const asked = (0, requests_1.readRequests)(paths).filter((r) => r.screen === id && (r.status === 'open' || r.status === 'approved'));
|
|
114
|
+
if (asked.length)
|
|
115
|
+
return fail([`${asked.map((r) => `${r.id} (${r.author})`).join(', ')} ${asked.length === 1 ? 'was' : 'were'} asked on ${id} and ${asked.length === 1 ? 'is' : 'are'} still waiting. The owner answers first; if the screen is going, that's a reason they can decline with.`]);
|
|
116
|
+
const archive = (0, store_1.readArchive)(paths);
|
|
117
|
+
const pending = (0, store_1.readPending)(paths);
|
|
118
|
+
const linked = [...archive, ...pending].filter((d) => d.candidate === id);
|
|
119
|
+
if (linked.length && !opts.force) {
|
|
120
|
+
return fail([
|
|
121
|
+
`${linked.length} decision${linked.length === 1 ? '' : 's'} still linked to ${id}: ${linked.map((d) => d.id).join(', ')}.`,
|
|
122
|
+
`Detach them and keep them: npx arbiter unlink ${linked.map((d) => d.id).join(' ')}`,
|
|
123
|
+
`Or remove the screen and detach them in one go: npx arbiter remove ${id} --force`,
|
|
124
|
+
]);
|
|
125
|
+
}
|
|
126
|
+
if (linked.length)
|
|
127
|
+
unlinkAll(paths, linked.map((d) => d.id));
|
|
128
|
+
const file = (0, candidates_1.candidateFile)(paths, id);
|
|
129
|
+
const shot = c.snapshot ? node_path_1.default.join((0, candidates_1.candidatesDir)(paths), c.snapshot) : null;
|
|
130
|
+
const before = node_fs_1.default.existsSync(file) ? node_fs_1.default.readFileSync(file, 'utf8') : '';
|
|
131
|
+
node_fs_1.default.rmSync(file, { force: true });
|
|
132
|
+
if (shot)
|
|
133
|
+
node_fs_1.default.rmSync(shot, { force: true });
|
|
134
|
+
const config = (0, store_1.readConfig)(paths);
|
|
135
|
+
const delivered = (0, destination_1.deliver)(paths, config, [], `remove ${id}`);
|
|
136
|
+
return {
|
|
137
|
+
exitCode: 0,
|
|
138
|
+
output: {
|
|
139
|
+
status: 'removed',
|
|
140
|
+
id,
|
|
141
|
+
name: c.name,
|
|
142
|
+
...(linked.length ? { unlinked: linked.map((d) => d.id) } : {}),
|
|
143
|
+
...(all.every((x) => x.id <= id) ? { idReuse: `${id} was the newest, so the next screen added will take that id again.` } : {}),
|
|
144
|
+
wrote: [node_path_1.default.relative(root, file), ...(shot ? [node_path_1.default.relative(root, shot)] : [])].map((p) => p.split(node_path_1.default.sep).join('/')),
|
|
145
|
+
removed: before.trimEnd(),
|
|
146
|
+
...(delivered.destination === 'git' ? { destination: 'git', committed: delivered.committed } : {}),
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/** `arbiter remove --snapshot "<piece of work>"` — the picture goes, the work stays. */
|
|
151
|
+
function removeSnapshot(name, opts = {}) {
|
|
152
|
+
const root = (0, store_1.findRoot)(opts.cwd);
|
|
153
|
+
const paths = (0, store_1.resolvePaths)(root);
|
|
154
|
+
const trigger = name?.trim() ?? '';
|
|
155
|
+
if (!trigger)
|
|
156
|
+
return fail(['name the piece of work, as the decisions did: npx arbiter remove --snapshot "Settings — billing"']);
|
|
157
|
+
// A candidate's picture belongs to the candidate; take it off there.
|
|
158
|
+
const cand = (0, candidates_1.readCandidates)(paths).find((c) => c.id === trigger || c.name === trigger);
|
|
159
|
+
if (cand) {
|
|
160
|
+
if (!cand.snapshot)
|
|
161
|
+
return fail([`${cand.id} has no picture`]);
|
|
162
|
+
const shot = node_path_1.default.join((0, candidates_1.candidatesDir)(paths), cand.snapshot);
|
|
163
|
+
node_fs_1.default.rmSync(shot, { force: true });
|
|
164
|
+
(0, candidates_1.writeCandidate)(paths, { ...cand, snapshot: null });
|
|
165
|
+
const delivered = (0, destination_1.deliver)(paths, (0, store_1.readConfig)(paths), [{ ...cand, snapshot: null }], `remove snapshot ${cand.id}`);
|
|
166
|
+
return {
|
|
167
|
+
exitCode: 0,
|
|
168
|
+
output: { status: 'removed', id: cand.id, wrote: [node_path_1.default.relative(root, shot).split(node_path_1.default.sep).join('/')], ...(delivered.destination === 'git' ? { committed: delivered.committed } : {}) },
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
const id = (0, work_1.workId)(trigger);
|
|
172
|
+
const file = (0, work_1.workSnapshot)(paths, id);
|
|
173
|
+
if (!file)
|
|
174
|
+
return fail([`no picture attached to "${trigger}"`]);
|
|
175
|
+
node_fs_1.default.rmSync(file, { force: true });
|
|
176
|
+
return {
|
|
177
|
+
exitCode: 0,
|
|
178
|
+
output: {
|
|
179
|
+
status: 'removed',
|
|
180
|
+
work: trigger,
|
|
181
|
+
id,
|
|
182
|
+
wrote: [node_path_1.default.relative(root, file).split(node_path_1.default.sep).join('/')],
|
|
183
|
+
note: 'the board keeps the old picture until the next `npx arbiter publish`',
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
// ── unlink ─────────────────────────────────────────────────────────────────
|
|
188
|
+
/** Detach recorded decisions from their screen. The decisions stay exactly as they are. */
|
|
189
|
+
function unlink(ids, opts = {}) {
|
|
190
|
+
const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
|
|
191
|
+
const wanted = (ids ?? []).map((i) => i.trim()).filter(Boolean);
|
|
192
|
+
if (!wanted.length)
|
|
193
|
+
return fail(['name at least one decision: npx arbiter unlink D-0004']);
|
|
194
|
+
const bad = wanted.filter((i) => !schema_1.DECISION_ID.test(i) && !/^P-\d{4,}$/.test(i));
|
|
195
|
+
if (bad.length)
|
|
196
|
+
return fail([`not decision ids: ${bad.join(', ')} (D-0004, or P-0003 while queued)`]);
|
|
197
|
+
const archive = (0, store_1.readArchive)(paths);
|
|
198
|
+
const pending = (0, store_1.readPending)(paths);
|
|
199
|
+
const known = new Map([...archive, ...pending].map((d) => [d.id, d]));
|
|
200
|
+
const missing = wanted.filter((i) => !known.has(i));
|
|
201
|
+
if (missing.length)
|
|
202
|
+
return fail([`not found: ${missing.join(', ')}`]);
|
|
203
|
+
const unattached = wanted.filter((i) => !known.get(i).candidate);
|
|
204
|
+
if (unattached.length === wanted.length)
|
|
205
|
+
return fail([`already attached to no screen: ${unattached.join(', ')}`]);
|
|
206
|
+
const changed = wanted.filter((i) => known.get(i).candidate);
|
|
207
|
+
const from = new Set(changed.map((i) => known.get(i).candidate));
|
|
208
|
+
unlinkAll(paths, changed);
|
|
209
|
+
return {
|
|
210
|
+
exitCode: 0,
|
|
211
|
+
output: {
|
|
212
|
+
status: 'unlinked',
|
|
213
|
+
ids: changed,
|
|
214
|
+
from: [...from],
|
|
215
|
+
...(unattached.length ? { alreadyLoose: unattached } : {}),
|
|
216
|
+
wrote: ['.arbiter/archive.md', ...refreshMany(paths, from)],
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
// ── shared ─────────────────────────────────────────────────────────────────
|
|
221
|
+
/** Clear `candidate` on the named decisions, wherever they live, and refresh the screens they left. */
|
|
222
|
+
function unlinkAll(paths, ids) {
|
|
223
|
+
const set = new Set(ids);
|
|
224
|
+
const archive = (0, store_1.readArchive)(paths);
|
|
225
|
+
if (archive.some((d) => set.has(d.id))) {
|
|
226
|
+
(0, store_1.writeArchive)(paths, archive.map((d) => (set.has(d.id) ? { ...d, candidate: null } : d)));
|
|
227
|
+
}
|
|
228
|
+
const pending = (0, store_1.readPending)(paths);
|
|
229
|
+
if (pending.some((d) => set.has(d.id))) {
|
|
230
|
+
(0, store_1.writePending)(paths, pending.map((d) => (set.has(d.id) ? { ...d, candidate: null } : d)));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/** A screen's file lists its decisions, so it has to be rewritten when that list changes. */
|
|
234
|
+
function refreshLinked(paths, candidate) {
|
|
235
|
+
if (!candidate)
|
|
236
|
+
return [];
|
|
237
|
+
return refreshMany(paths, new Set([candidate]));
|
|
238
|
+
}
|
|
239
|
+
function refreshMany(paths, ids) {
|
|
240
|
+
const wrote = [];
|
|
241
|
+
for (const c of (0, candidates_1.readCandidates)(paths)) {
|
|
242
|
+
if (!ids.has(c.id))
|
|
243
|
+
continue;
|
|
244
|
+
(0, candidates_1.writeCandidate)(paths, c);
|
|
245
|
+
wrote.push(`.arbiter/candidates/${c.id}.md`);
|
|
246
|
+
}
|
|
247
|
+
return wrote;
|
|
248
|
+
}
|
|
@@ -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
|
+
}
|