arbiterdesign 0.1.7 → 0.1.9

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.
Files changed (44) hide show
  1. package/README.md +38 -40
  2. package/dist/area-names.js +120 -0
  3. package/dist/areas.js +131 -0
  4. package/dist/board-types.js +9 -0
  5. package/dist/candidates.js +7 -1
  6. package/dist/commands/areas.js +153 -0
  7. package/dist/commands/candidate.js +4 -2
  8. package/dist/commands/decision.js +100 -0
  9. package/dist/commands/export.js +88 -125
  10. package/dist/commands/init.js +89 -2
  11. package/dist/commands/prompt.js +12 -4
  12. package/dist/commands/publish.js +18 -1
  13. package/dist/commands/record.js +152 -3
  14. package/dist/commands/rename.js +123 -0
  15. package/dist/commands/review.js +469 -76
  16. package/dist/commands/rules.js +8 -1
  17. package/dist/commands/setup.js +1 -0
  18. package/dist/commands/snapshot.js +24 -2
  19. package/dist/commands/sweep.js +1 -1
  20. package/dist/commands/unpublish.js +88 -0
  21. package/dist/comments.js +24 -0
  22. package/dist/handoff.js +283 -0
  23. package/dist/hook.js +80 -0
  24. package/dist/hosted.js +117 -20
  25. package/dist/index.js +93 -24
  26. package/dist/localboard.js +219 -0
  27. package/dist/lock.js +134 -0
  28. package/dist/overlap.js +16 -0
  29. package/dist/pictures.js +4 -0
  30. package/dist/settings.js +107 -0
  31. package/dist/store.js +6 -5
  32. package/dist/verify.js +4 -2
  33. package/dist/wording.js +65 -0
  34. package/dist/work.js +139 -1
  35. package/package.json +3 -2
  36. package/templates/SKILL.md +169 -50
  37. package/templates/board/board.css +2 -0
  38. package/templates/board/board.js +25 -0
  39. package/templates/board/index.html +15 -0
  40. package/templates/fonts/Geist-Variable.woff2 +0 -0
  41. package/templates/fonts/GeistMono-Variable.woff2 +0 -0
  42. package/templates/fonts/OFL.txt +92 -0
  43. package/templates/hooks/arbiter-board.cjs +50 -0
  44. package/templates/review.html +0 -600
@@ -19,6 +19,7 @@ const hosted_1 = require("../hosted");
19
19
  const requests_1 = require("../requests");
20
20
  const update_1 = require("./update");
21
21
  const overlap_1 = require("../overlap");
22
+ const handoff_1 = require("../handoff");
22
23
  function rules(id, opts = {}) {
23
24
  const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
24
25
  opts = { ...opts, config: (0, store_1.readConfig)(paths) };
@@ -75,8 +76,14 @@ function pendingList(pending, opts, paths) {
75
76
  if (opts.json) {
76
77
  const active = (0, store_1.readActive)(paths);
77
78
  const ignore = opts.config?.overlap?.ignore;
79
+ // A Review Board sitting nobody was waiting on: its fixes and approved requests are still to make.
80
+ // Handed over as it is now: once it's made, `done` clears this much, and keeps anything judged since.
81
+ const lastReview = (0, handoff_1.takeHandoff)(paths);
78
82
  return JSON.stringify({
79
- firstRun: !opts.config?.onboarded,
83
+ ...(lastReview && { lastReview: { ...lastReview, file: handoff_1.HANDOFF_FILE, done: 'npx arbiter review --done' } }),
84
+ // Judged decisions mean someone has been through a review, whatever arbiter.json says: the
85
+ // stamp lives in a committed file, and a branch that never merged takes it along.
86
+ firstRun: !opts.config?.onboarded && !archiveAll.length && !active.length,
80
87
  checkin: opts.config?.checkin ?? 'feature',
81
88
  ...(0, update_1.updateNotice)(paths),
82
89
  requests: { open, approved },
@@ -11,6 +11,7 @@
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.CHECKINS = void 0;
13
13
  exports.setup = setup;
14
+ exports.appUrl = appUrl;
14
15
  const store_1 = require("../store");
15
16
  exports.CHECKINS = ['feature', 'quiet', 'every'];
16
17
  function setup(opts) {
@@ -9,6 +9,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.snapshotWork = snapshotWork;
12
+ const node_fs_1 = __importDefault(require("node:fs"));
12
13
  const node_path_1 = __importDefault(require("node:path"));
13
14
  const store_1 = require("../store");
14
15
  const hosted_1 = require("../hosted");
@@ -30,9 +31,19 @@ function snapshotWork(name, opts) {
30
31
  const judged = archive.some((d) => mine(d) && (0, hosted_1.publishable)(d));
31
32
  const queued = pending.filter((d) => mine(d) && d.level !== 'polish').length;
32
33
  const polish = [...archive, ...pending].some((d) => mine(d) && d.level === 'polish' && d.verdict !== 'retire');
34
+ // The picture it had becomes an earlier version, so the board can show how the work got here. The same
35
+ // picture attached again isn't a new version.
36
+ const cur = (0, work_1.workSnapshot)(paths, id);
37
+ const same = !opts.capture && !!cur && sameFile(cur, node_path_1.default.resolve(root, opts.file));
38
+ const moved = same ? null : (0, work_1.keepEarlier)(paths, id);
33
39
  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);
34
- if (!r.ok)
40
+ if (!r.ok) {
41
+ (0, work_1.restoreEarlier)(moved);
35
42
  return { exitCode: 1, output: { status: 'failed', error: r.error } };
43
+ }
44
+ // Dated when it was attached: a copy keeps the source file's own time on some systems.
45
+ const now = new Date();
46
+ node_fs_1.default.utimesSync(node_path_1.default.join((0, work_1.workDir)(paths), r.file), now, now);
36
47
  const note = judged
37
48
  ? null
38
49
  : queued
@@ -42,6 +53,17 @@ function snapshotWork(name, opts) {
42
53
  : `no decisions mention "${trigger}" yet — the picture shows once some do`;
43
54
  return {
44
55
  exitCode: 0,
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 } : {}) },
56
+ 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)), ...(moved ? { earlier: node_path_1.default.relative(root, moved.to) } : {}), ...(note ? { note } : {}) },
46
57
  };
47
58
  }
59
+ /** Byte for byte the same image. */
60
+ function sameFile(a, b) {
61
+ try {
62
+ if (node_fs_1.default.statSync(a).size !== node_fs_1.default.statSync(b).size)
63
+ return false;
64
+ return node_fs_1.default.readFileSync(a).equals(node_fs_1.default.readFileSync(b));
65
+ }
66
+ catch {
67
+ return false;
68
+ }
69
+ }
@@ -33,7 +33,7 @@ function sweepCommand(id, opts = {}) {
33
33
  author: opts.author ?? rule.author,
34
34
  class: 'mechanical',
35
35
  change: null,
36
- level: 'polish',
36
+ level: 'pattern',
37
37
  dimension: rule.dimension,
38
38
  decision: rule.decision,
39
39
  rejected: [],
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ /**
3
+ * `arbiter unpublish --yes` — take the hosted board down, for everyone.
4
+ *
5
+ * The board is a window onto the record, so deleting it loses nothing the repo holds: decisions,
6
+ * rules, pictures and requests all stay. What lives only on the board is what people said there,
7
+ * so the comments are pulled into .arbiter/comments.json first. Then the board, its pictures and
8
+ * its comments are deleted from the service, and the link here goes with them.
9
+ *
10
+ * Without --yes it deletes nothing and says what it would, because nothing brings a board back:
11
+ * publishing again makes a new one, at a new link, with no comments.
12
+ */
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.unpublish = unpublish;
18
+ const node_fs_1 = __importDefault(require("node:fs"));
19
+ const node_path_1 = __importDefault(require("node:path"));
20
+ const hosted_1 = require("../hosted");
21
+ const store_1 = require("../store");
22
+ const publish_1 = require("./publish");
23
+ /**
24
+ * With `board` and `admin`: a takedown of any board on a server you run, by its link, with the
25
+ * server's admin token from ARBITER_ADMIN_TOKEN. Needs no project here and changes nothing in one.
26
+ */
27
+ async function unpublish(opts = {}) {
28
+ if (opts.board || opts.admin)
29
+ return takedown(opts);
30
+ const root = (0, store_1.findRoot)(opts.cwd);
31
+ const paths = (0, store_1.resolvePaths)(root);
32
+ const steps = [];
33
+ const link = (0, hosted_1.readLinkOrNull)(paths);
34
+ if (!link) {
35
+ steps.push({ step: 'board', outcome: 'failed', note: 'this project has no hosted board (.arbiter/hosted.json)' });
36
+ return { ok: false, steps, url: null };
37
+ }
38
+ if (!opts.yes) {
39
+ steps.push({
40
+ step: 'board',
41
+ outcome: 'skipped',
42
+ note: `nothing deleted. This deletes ${link.shareUrl} for everyone: the board, its pictures and every comment on it, saving the comments to .arbiter/comments.json first. To go ahead: npx arbiter unpublish --yes`,
43
+ });
44
+ return { ok: false, steps, url: link.shareUrl };
45
+ }
46
+ try {
47
+ const r = await (0, hosted_1.unpublishHosted)(paths);
48
+ steps.push({ step: 'comments', outcome: 'done', note: `${r.saved} saved to .arbiter/comments.json` });
49
+ steps.push({ step: 'board', outcome: 'done', note: `deleted ${r.link.shareUrl}, with ${r.pictures} picture${r.pictures === 1 ? '' : 's'} and ${r.comments} comment${r.comments === 1 ? '' : 's'}` });
50
+ steps.push({ step: 'link', outcome: 'done', note: 'removed .arbiter/hosted.json and .arbiter/hosted.token — commit that, so teammates stop publishing to it' });
51
+ }
52
+ catch (e) {
53
+ steps.push({ step: 'board', outcome: 'failed', note: e.message });
54
+ return { ok: false, steps, url: null };
55
+ }
56
+ // The workflow would now run on every push and fail: it never creates a board from CI.
57
+ if (node_fs_1.default.existsSync(node_path_1.default.join(root, publish_1.WORKFLOW_FILE))) {
58
+ steps.push({ step: 'workflow', outcome: 'skipped', note: `${publish_1.WORKFLOW_FILE} still runs on every push, and will fail now there's no board. Delete it` });
59
+ }
60
+ return { ok: true, steps, url: null };
61
+ }
62
+ async function takedown(opts) {
63
+ const fail = (note) => ({ ok: false, steps: [{ step: 'board', outcome: 'failed', note }], url: null });
64
+ if (!opts.admin)
65
+ return fail("a board link is for taking down someone else's board, with --admin. To delete this project's own board, leave the link out");
66
+ if (!opts.board)
67
+ return fail('--admin needs the link of the board to take down: npx arbiter unpublish <board link> --admin --yes');
68
+ const board = (0, hosted_1.parseBoardLink)(opts.board);
69
+ if (!board)
70
+ return fail(`${opts.board} isn't a board link. One looks like https://arbiter.design/p/abc123`);
71
+ const admin = process.env[hosted_1.ADMIN_ENV]?.trim();
72
+ if (!admin)
73
+ return fail(`set ${hosted_1.ADMIN_ENV} to the admin token of ${board.origin} first`);
74
+ if (!opts.yes) {
75
+ return {
76
+ ok: false,
77
+ steps: [{ step: 'board', outcome: 'skipped', note: `nothing deleted. This deletes ${board.shareUrl} for everyone: the board, its pictures and every comment on it, and its owner can't get the comments back. To go ahead: npx arbiter unpublish ${board.shareUrl} --admin --yes` }],
78
+ url: board.shareUrl,
79
+ };
80
+ }
81
+ try {
82
+ const r = await (0, hosted_1.takedownHosted)(board.shareUrl, admin);
83
+ return { ok: true, steps: [{ step: 'board', outcome: 'done', note: `deleted ${r.shareUrl}, with ${r.pictures} picture${r.pictures === 1 ? '' : 's'} and ${r.comments} comment${r.comments === 1 ? '' : 's'}` }], url: null };
84
+ }
85
+ catch (e) {
86
+ return fail(e.message);
87
+ }
88
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /**
3
+ * The team board's comments, as `arbiter pull` keeps them: .arbiter/comments.json, committed. Pull
4
+ * writes the file (src/hosted.ts); requests and the local board read it. Kept here, apart from the
5
+ * publish code, so reading them doesn't mean depending on it.
6
+ */
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.readComments = readComments;
12
+ exports.writeComments = writeComments;
13
+ const node_fs_1 = __importDefault(require("node:fs"));
14
+ const node_path_1 = __importDefault(require("node:path"));
15
+ const COMMENTS_FILE = 'comments.json';
16
+ function readComments(paths) {
17
+ const f = node_path_1.default.join(paths.archiveDir, COMMENTS_FILE);
18
+ return node_fs_1.default.existsSync(f) ? JSON.parse(node_fs_1.default.readFileSync(f, 'utf8')) : [];
19
+ }
20
+ /** Every comment on file, minus email addresses: nothing here needs them, and the file is committed. */
21
+ function writeComments(paths, comments) {
22
+ const kept = comments.map(({ author_email: _email, ...c }) => c);
23
+ node_fs_1.default.writeFileSync(node_path_1.default.join(paths.archiveDir, COMMENTS_FILE), JSON.stringify(kept, null, 2) + '\n');
24
+ }
@@ -0,0 +1,283 @@
1
+ "use strict";
2
+ /**
3
+ * The handoff: what you decided on the local board, for the agent to act on.
4
+ *
5
+ * The page records each answer as you give it. What it can't do is change code, so a Fix, a
6
+ * "Follow D-0009" and an approved request wait on the agent, in .arbiter/last-review.json, added to
7
+ * as you go. So does a rule edited or removed on Design rules, since the agent may have read
8
+ * DECISIONS.md before you changed it. The agent takes it with your next message in Claude Code (a
9
+ * hook tells it: see templates/hooks), or at the next /arbiter anywhere. What it was told is kept
10
+ * beside it (last-review.seen.json), and once it's made, `arbiter review --done` clears just that:
11
+ * anything you judged while it worked stays for next time. An agent waiting on the page
12
+ * (`review --json`) gets it when the last tab closes instead.
13
+ */
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.HANDOFF_NAME = exports.HANDOFF_FILE = exports.decidedAnything = exports.SEEN = exports.FILE = void 0;
19
+ exports.summarize = summarize;
20
+ exports.handoffLine = handoffLine;
21
+ exports.mergeHandoffs = mergeHandoffs;
22
+ exports.saveHandoff = saveHandoff;
23
+ exports.takeHandoff = takeHandoff;
24
+ exports.handoffDone = handoffDone;
25
+ exports.saveAnswer = saveAnswer;
26
+ exports.withdrawAnswer = withdrawAnswer;
27
+ exports.withdrawRemoval = withdrawRemoval;
28
+ exports.clearHandoff = clearHandoff;
29
+ exports.readHandoff = readHandoff;
30
+ const node_fs_1 = __importDefault(require("node:fs"));
31
+ const node_path_1 = __importDefault(require("node:path"));
32
+ const lock_1 = require("./lock");
33
+ exports.FILE = 'last-review.json';
34
+ /** What the agent was told, as it was told it: what `review --done` clears, and nothing judged since. */
35
+ exports.SEEN = 'last-review.seen.json';
36
+ function summarize(answers, finished, at = new Date().toISOString()) {
37
+ const h = { finished, at, confirmed: [], rules: [], fixed: [], skipped: [], declined: [], options: [], reworded: [], removed: [], renamed: [], todo: [], next: '' };
38
+ for (const a of answers) {
39
+ if (a.kind === 'option')
40
+ h.options.push({ id: a.id, name: a.name, state: a.state });
41
+ else if (a.kind === 'rename')
42
+ h.renamed = renames(h.renamed ?? [], [{ from: a.from, to: a.to }]);
43
+ // A rule back in DECISIONS.md after the agent heard it was gone is in force again, as a new one is.
44
+ else if (a.kind === 'restore' || a.kind === 'rule')
45
+ h.rules.push(a.id);
46
+ else if (a.kind === 'reword' || a.kind === 'retire')
47
+ rulesChanged(h, a.kind === 'reword' ? [{ id: a.id, to: a.to }] : [], a.kind === 'retire' ? [{ id: a.id, rule: a.rule, why: a.why }] : []);
48
+ else if (a.kind === 'request') {
49
+ if (a.status === 'declined')
50
+ h.declined.push({ id: a.id, author: a.author, reason: a.reason ?? '' });
51
+ else
52
+ h.todo.push({ kind: 'request', id: a.id, author: a.author, screen: a.screenName, do: a.do ?? '' });
53
+ }
54
+ else if (a.as === 'skip')
55
+ h.skipped.push(a.pending);
56
+ else if (a.as === 'accept')
57
+ h.confirmed.push(a.id ?? a.pending);
58
+ else if (a.as === 'rule')
59
+ h.rules.push(a.id ?? a.pending);
60
+ else {
61
+ h.fixed.push(a.id ?? a.pending);
62
+ const id = a.id ?? a.pending;
63
+ if (a.follows)
64
+ h.todo.push({ kind: 'follow', id, rule: a.follows, to: a.to ?? '' });
65
+ else
66
+ h.todo.push({ kind: 'fix', id, change: a.change ?? '', to: a.to ?? '' });
67
+ }
68
+ }
69
+ h.next = nextStep(h);
70
+ return h;
71
+ }
72
+ /**
73
+ * Only a rule's latest words count, and none for a rule removed since. Those go with the removal,
74
+ * so a removal put back brings them back too.
75
+ */
76
+ function rulesChanged(h, reworded, removed) {
77
+ const was = h.reworded ?? [];
78
+ const later = new Set([...reworded, ...removed].map((r) => r.id));
79
+ h.reworded = [...was.filter((r) => !later.has(r.id)), ...reworded];
80
+ // Made a rule and removed again: the removal is what's true now.
81
+ h.rules = h.rules.filter((id) => !removed.some((r) => r.id === id));
82
+ h.removed = [...(h.removed ?? []), ...removed.map((r) => {
83
+ const edited = was.find((x) => x.id === r.id)?.to;
84
+ return edited ? { ...r, edited } : r;
85
+ })];
86
+ }
87
+ /** Renamed twice, A to B then B to C: one rename, A to C. Renamed back: none. */
88
+ function renames(was, next) {
89
+ let out = [...was];
90
+ for (const r of next) {
91
+ const before = out.find((x) => x.to === r.from);
92
+ out = out.filter((x) => x !== before);
93
+ const from = before ? before.from : r.from;
94
+ if (from !== r.to)
95
+ out.push({ from, to: r.to });
96
+ }
97
+ return out;
98
+ }
99
+ function nextStep(h) {
100
+ const rules = (h.reworded?.length || h.removed?.length ? ' Rules were edited or removed on Design rules: follow DECISIONS.md as it is now.' : '')
101
+ + (h.renamed?.length ? ' Work was renamed on the board: use each new name as the trigger from now on.' : '');
102
+ if (!h.todo.length)
103
+ return `Nothing to change in the code.${rules}`;
104
+ return `Make each change in todo. They're recorded already, so don't judge or record them again. An approved request is the exception: record its change with --request <id> once it's made.${rules}`;
105
+ }
106
+ /** Anything decided at all. A sitting where nothing was answered hands nothing over. */
107
+ const decidedAnything = (h) => !!(h.confirmed.length || h.rules.length || h.fixed.length || h.skipped.length || h.declined.length || h.options.length || h.reworded?.length || h.removed?.length || h.renamed?.length || h.todo.length);
108
+ exports.decidedAnything = decidedAnything;
109
+ /** One line for the person at the terminal, when nobody's waiting on the JSON. `when` is when the agent hears of it. */
110
+ function handoffLine(h, when = 'at the next /arbiter') {
111
+ if (!(0, exports.decidedAnything)(h))
112
+ return null;
113
+ const parts = [
114
+ h.confirmed.length && `${h.confirmed.length} confirmed`,
115
+ h.rules.length && `${h.rules.length} made ${h.rules.length === 1 ? 'a rule' : 'rules'}`,
116
+ h.fixed.length && `${h.fixed.length} fixed`,
117
+ h.skipped.length && `${h.skipped.length} skipped`,
118
+ h.reworded?.length && `${h.reworded.length} ${h.reworded.length === 1 ? 'rule' : 'rules'} edited`,
119
+ h.removed?.length && `${h.removed.length} ${h.removed.length === 1 ? 'rule' : 'rules'} removed`,
120
+ h.renamed?.length && `${h.renamed.length} renamed`,
121
+ ].filter(Boolean);
122
+ const said = parts.length ? `Recorded: ${parts.join(', ')}.` : 'Recorded.';
123
+ if (!h.todo.length)
124
+ return said;
125
+ return `${said} ${h.todo.length} ${h.todo.length === 1 ? 'change waits' : 'changes wait'} for your agent, which picks ${h.todo.length === 1 ? 'it' : 'them'} up ${when}.`;
126
+ }
127
+ /**
128
+ * An earlier sitting nobody acted on, then this one: a second sitting adds to the first rather
129
+ * than replacing it, so nothing waiting on the agent is lost.
130
+ */
131
+ function mergeHandoffs(earlier, h) {
132
+ if (!earlier)
133
+ return h;
134
+ const merged = {
135
+ ...h,
136
+ confirmed: [...earlier.confirmed, ...h.confirmed],
137
+ rules: [...earlier.rules, ...h.rules],
138
+ fixed: [...earlier.fixed, ...h.fixed],
139
+ skipped: [...earlier.skipped, ...h.skipped],
140
+ declined: [...earlier.declined, ...h.declined],
141
+ options: [...earlier.options, ...h.options],
142
+ reworded: earlier.reworded ?? [],
143
+ removed: earlier.removed ?? [],
144
+ renamed: renames(earlier.renamed ?? [], h.renamed ?? []),
145
+ todo: [...earlier.todo, ...h.todo],
146
+ };
147
+ rulesChanged(merged, h.reworded ?? [], h.removed ?? []);
148
+ merged.next = nextStep(merged);
149
+ return merged;
150
+ }
151
+ /**
152
+ * Saved for the next /arbiter, which reads it with the queue. Kept out of git: it's one person's
153
+ * sitting, and a teammate's agent mustn't make it.
154
+ */
155
+ function saveHandoff(paths, h) {
156
+ node_fs_1.default.mkdirSync(paths.archiveDir, { recursive: true });
157
+ (0, lock_1.writeAtomic)(node_path_1.default.join(paths.archiveDir, exports.FILE), JSON.stringify(h, null, 2) + '\n');
158
+ const gi = node_path_1.default.join(paths.archiveDir, '.gitignore');
159
+ const lines = (node_fs_1.default.existsSync(gi) ? node_fs_1.default.readFileSync(gi, 'utf8') : '').split(/\r?\n/).filter(Boolean);
160
+ const missing = [exports.FILE, exports.SEEN].filter((x) => !lines.includes(x));
161
+ if (missing.length)
162
+ node_fs_1.default.writeFileSync(gi, [...lines, ...missing].join('\n') + '\n');
163
+ }
164
+ /**
165
+ * What's waiting, handed to the agent: kept as it was given (SEEN), so `review --done` clears that and
166
+ * no more. The Claude Code hook keeps the same copy when it speaks.
167
+ */
168
+ function takeHandoff(paths) {
169
+ const h = readHandoff(paths);
170
+ if (h)
171
+ (0, lock_1.writeAtomic)(node_path_1.default.join(paths.archiveDir, exports.SEEN), JSON.stringify(h, null, 2) + '\n');
172
+ return h;
173
+ }
174
+ /**
175
+ * The agent has made what it was told: that comes out of the file. Anything judged on the board since
176
+ * stays, for the hook to say at the next message. Nothing handed over yet: nothing is cleared.
177
+ */
178
+ function handoffDone(paths) {
179
+ const h = readHandoff(paths);
180
+ const seenFile = node_path_1.default.join(paths.archiveDir, exports.SEEN);
181
+ let seen = null;
182
+ try {
183
+ seen = JSON.parse(node_fs_1.default.readFileSync(seenFile, 'utf8'));
184
+ }
185
+ catch { /* never handed over */ }
186
+ if (!h) {
187
+ node_fs_1.default.rmSync(seenFile, { force: true });
188
+ return { status: 'nothing', left: 0 };
189
+ }
190
+ if (!seen)
191
+ return { status: 'not-taken', left: h.todo.length, errors: ['Nothing was handed over yet, so nothing was cleared: read it first with npx arbiter rules --pending --json'] };
192
+ const key = (x) => JSON.stringify(x);
193
+ const minus = (now, was) => {
194
+ const gone = new Set((was ?? []).map(key));
195
+ return (now ?? []).filter((x) => !gone.has(key(x)));
196
+ };
197
+ const { told: _told, ...rest } = h;
198
+ const left = {
199
+ ...rest,
200
+ confirmed: minus(h.confirmed, seen.confirmed),
201
+ rules: minus(h.rules, seen.rules),
202
+ fixed: minus(h.fixed, seen.fixed),
203
+ skipped: minus(h.skipped, seen.skipped),
204
+ declined: minus(h.declined, seen.declined),
205
+ options: minus(h.options, seen.options),
206
+ reworded: minus(h.reworded, seen.reworded),
207
+ removed: minus(h.removed, seen.removed),
208
+ renamed: minus(h.renamed, seen.renamed),
209
+ todo: minus(h.todo, seen.todo),
210
+ };
211
+ left.next = nextStep(left);
212
+ if ((0, exports.decidedAnything)(left))
213
+ saveHandoff(paths, left);
214
+ else
215
+ clearHandoff(paths);
216
+ node_fs_1.default.rmSync(seenFile, { force: true });
217
+ return { status: 'done', left: left.todo.length };
218
+ }
219
+ /**
220
+ * One answer, added to what's already waiting. Added, never rewritten from the sitting: the agent
221
+ * may have taken the file and made it while the board was still open, and a rewrite would hand
222
+ * those changes over a second time.
223
+ */
224
+ function saveAnswer(paths, a) {
225
+ const h = mergeHandoffs(readHandoff(paths), summarize([a], 'closed'));
226
+ if ((0, exports.decidedAnything)(h))
227
+ saveHandoff(paths, h);
228
+ }
229
+ /**
230
+ * An answer taken back on the page: out of what's waiting, so the agent never acts on it. False when
231
+ * the agent has taken it already, and may have made the change.
232
+ */
233
+ function withdrawAnswer(paths, a) {
234
+ const h = readHandoff(paths);
235
+ const id = a.as === 'skip' ? a.pending : a.id ?? a.pending;
236
+ const list = a.as === 'skip' ? 'skipped' : a.as === 'accept' ? 'confirmed' : a.as === 'rule' ? 'rules' : 'fixed';
237
+ if (!h?.[list].includes(id))
238
+ return false;
239
+ // Rewritten as it is otherwise, `told` and all: taking one back is nothing new for the hook to say.
240
+ const next = { ...h, [list]: h[list].filter((x) => x !== id), todo: h.todo.filter((t) => t.kind === 'request' || t.id !== id) };
241
+ next.next = nextStep(next);
242
+ if ((0, exports.decidedAnything)(next))
243
+ saveHandoff(paths, next);
244
+ else
245
+ clearHandoff(paths);
246
+ return true;
247
+ }
248
+ /** A removal put back on the page: out of what's waiting. False when the agent has heard of it already. */
249
+ function withdrawRemoval(paths, id) {
250
+ const h = readHandoff(paths);
251
+ const gone = h?.removed?.find((r) => r.id === id);
252
+ if (!h || !gone)
253
+ return false;
254
+ const next = {
255
+ ...h,
256
+ removed: h.removed.filter((r) => r.id !== id),
257
+ ...(gone.edited && { reworded: [...(h.reworded ?? []), { id, to: gone.edited }] }),
258
+ };
259
+ next.next = nextStep(next);
260
+ if ((0, exports.decidedAnything)(next))
261
+ saveHandoff(paths, next);
262
+ else
263
+ clearHandoff(paths);
264
+ return true;
265
+ }
266
+ /** Handed over: the agent has it, so the next /arbiter mustn't make it a second time. */
267
+ function clearHandoff(paths) {
268
+ node_fs_1.default.rmSync(node_path_1.default.join(paths.archiveDir, exports.FILE), { force: true });
269
+ node_fs_1.default.rmSync(node_path_1.default.join(paths.archiveDir, exports.SEEN), { force: true });
270
+ }
271
+ function readHandoff(paths) {
272
+ const f = node_path_1.default.join(paths.archiveDir, exports.FILE);
273
+ if (!node_fs_1.default.existsSync(f))
274
+ return null;
275
+ try {
276
+ return JSON.parse(node_fs_1.default.readFileSync(f, 'utf8'));
277
+ }
278
+ catch {
279
+ return null;
280
+ }
281
+ }
282
+ exports.HANDOFF_FILE = `.arbiter/${exports.FILE}`;
283
+ exports.HANDOFF_NAME = exports.FILE;
package/dist/hook.js ADDED
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ /**
3
+ * The Claude Code hook. Before each message you send, it tells the agent what you've judged on
4
+ * the local board since its last turn that needs the code changed, so the agent makes it then,
5
+ * without waiting for /arbiter. A script in .claude/hooks/ (templates/hooks/arbiter-board.cjs),
6
+ * run by a UserPromptSubmit entry in .claude/settings.json. Claude Code only: Cursor and Codex
7
+ * have no such hook, and pick it up at /arbiter.
8
+ *
9
+ * The script is plain node with nothing to install, since it runs before every message: it reads
10
+ * one file and, nearly always, finds nothing to say.
11
+ */
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.HOOK_COMMAND = void 0;
17
+ exports.hookInstalled = hookInstalled;
18
+ exports.installHook = installHook;
19
+ const node_fs_1 = __importDefault(require("node:fs"));
20
+ const node_path_1 = __importDefault(require("node:path"));
21
+ const SCRIPT = node_path_1.default.join('.claude', 'hooks', 'arbiter-board.cjs');
22
+ const SETTINGS = node_path_1.default.join('.claude', 'settings.json');
23
+ const TEMPLATE = node_path_1.default.join(__dirname, '..', 'templates', 'hooks', 'arbiter-board.cjs');
24
+ /** Claude Code sets the project's root in this; the script finds the board's files from there. */
25
+ exports.HOOK_COMMAND = 'node "$CLAUDE_PROJECT_DIR/.claude/hooks/arbiter-board.cjs"';
26
+ const ours = (e) => (e.hooks ?? []).some((h) => h.command?.includes('arbiter-board.cjs'));
27
+ /** Both halves in place: the script, and the entry that runs it. */
28
+ function hookInstalled(root) {
29
+ if (!node_fs_1.default.existsSync(node_path_1.default.join(root, SCRIPT)))
30
+ return false;
31
+ try {
32
+ const s = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(root, SETTINGS), 'utf8'));
33
+ return (s.hooks?.UserPromptSubmit ?? []).some(ours);
34
+ }
35
+ catch {
36
+ return false;
37
+ }
38
+ }
39
+ /**
40
+ * Write the script, and add the entry to .claude/settings.json beside whatever is there. A
41
+ * settings file that isn't plain JSON is left alone: rewriting it could lose what someone wrote.
42
+ */
43
+ function installHook(root) {
44
+ const steps = [];
45
+ const script = node_path_1.default.join(root, SCRIPT);
46
+ const content = node_fs_1.default.readFileSync(TEMPLATE, 'utf8').replace(/\r\n/g, '\n');
47
+ const before = node_fs_1.default.existsSync(script) ? node_fs_1.default.readFileSync(script, 'utf8') : null;
48
+ if (before === content)
49
+ steps.push({ file: '.claude/hooks/arbiter-board.cjs', outcome: 'unchanged' });
50
+ else {
51
+ node_fs_1.default.mkdirSync(node_path_1.default.dirname(script), { recursive: true });
52
+ node_fs_1.default.writeFileSync(script, content);
53
+ steps.push({ file: '.claude/hooks/arbiter-board.cjs', outcome: before === null ? 'created' : 'updated' });
54
+ }
55
+ const file = node_path_1.default.join(root, SETTINGS);
56
+ const exists = node_fs_1.default.existsSync(file);
57
+ let settings = {};
58
+ if (exists) {
59
+ try {
60
+ settings = JSON.parse(node_fs_1.default.readFileSync(file, 'utf8'));
61
+ }
62
+ catch {
63
+ steps.push({ file: '.claude/settings.json', outcome: 'skipped', note: `not plain JSON, so left alone. Add a UserPromptSubmit hook running: ${exports.HOOK_COMMAND}` });
64
+ return steps;
65
+ }
66
+ }
67
+ const entries = settings.hooks?.UserPromptSubmit ?? [];
68
+ const mine = entries.find(ours);
69
+ if (mine?.hooks?.some((h) => h.command === exports.HOOK_COMMAND)) {
70
+ steps.push({ file: '.claude/settings.json', outcome: 'unchanged' });
71
+ return steps;
72
+ }
73
+ const entry = { hooks: [{ type: 'command', command: exports.HOOK_COMMAND }] };
74
+ const next = mine ? entries.map((e) => (e === mine ? entry : e)) : [...entries, entry];
75
+ settings = { ...settings, hooks: { ...settings.hooks, UserPromptSubmit: next } };
76
+ node_fs_1.default.mkdirSync(node_path_1.default.dirname(file), { recursive: true });
77
+ node_fs_1.default.writeFileSync(file, JSON.stringify(settings, null, 2) + '\n');
78
+ steps.push({ file: '.claude/settings.json', outcome: exists ? 'updated' : 'created' });
79
+ return steps;
80
+ }