arbiterdesign 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ /**
3
+ * `arbiter export` — a static, self-contained folder of the board for people
4
+ * without the repo. index.html + snapshots. No server, no JS, no login.
5
+ *
6
+ * Stakeholder view only: screen, state, who approved, why the others lost,
7
+ * what was decided — in plain Change language. No verdict buttons, no scope
8
+ * tags. Feedback comes back through a human; comments never become rules.
9
+ *
10
+ * The cheap test of Stage 6's assumption: does a stakeholder, given a link,
11
+ * actually look?
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.exportBoard = exportBoard;
18
+ const node_fs_1 = __importDefault(require("node:fs"));
19
+ const node_path_1 = __importDefault(require("node:path"));
20
+ const node_child_process_1 = require("node:child_process");
21
+ const candidates_1 = require("../candidates");
22
+ const schema_1 = require("../schema");
23
+ const format_1 = require("../format");
24
+ const store_1 = require("../store");
25
+ const STATE_ORDER = ['approved', 'in_review', 'generated', 'rejected', 'superseded'];
26
+ const STATE_LABEL = { approved: 'Approved', in_review: 'In review', generated: 'Generated', rejected: 'Rejected', superseded: 'Superseded' };
27
+ function exportBoard(opts = {}) {
28
+ const root = (0, store_1.findRoot)(opts.cwd);
29
+ const paths = (0, store_1.resolvePaths)(root);
30
+ const outDir = node_path_1.default.resolve(root, opts.out ?? 'arbiter-export');
31
+ const snapDir = node_path_1.default.join(outDir, 'snapshots');
32
+ node_fs_1.default.mkdirSync(snapDir, { recursive: true });
33
+ let candidates = (0, candidates_1.readCandidates)(paths);
34
+ if (opts.feature)
35
+ candidates = candidates.filter((c) => c.feature === opts.feature);
36
+ const byId = new Map(candidates.map((c) => [c.id, c]));
37
+ let snapshots = 0;
38
+ for (const c of candidates) {
39
+ if (!c.snapshot)
40
+ continue;
41
+ const src = node_path_1.default.join((0, candidates_1.candidatesDir)(paths), c.snapshot);
42
+ if (!node_fs_1.default.existsSync(src))
43
+ continue;
44
+ node_fs_1.default.copyFileSync(src, node_path_1.default.join(snapDir, c.snapshot));
45
+ snapshots++;
46
+ }
47
+ const project = (0, store_1.readConfig)(paths)?.author ? node_path_1.default.basename(root) : node_path_1.default.basename(root);
48
+ const html = page({
49
+ project,
50
+ generated: new Date().toISOString().slice(0, 10),
51
+ candidates,
52
+ byId,
53
+ decisions: (id) => (0, candidates_1.decisionsFor)(paths, id).filter((d) => d.verdict !== 'pending' && d.level !== 'polish'),
54
+ rules: opts.includeRules ? (0, store_1.readActive)(paths) : null,
55
+ });
56
+ const index = node_path_1.default.join(outDir, 'index.html');
57
+ node_fs_1.default.writeFileSync(index, html);
58
+ if (opts.open) {
59
+ const cmd = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'cmd' : 'xdg-open';
60
+ const args = process.platform === 'win32' ? ['/c', 'start', '', index] : [index];
61
+ try {
62
+ (0, node_child_process_1.spawn)(cmd, args, { stdio: 'ignore', detached: true }).unref();
63
+ }
64
+ catch { /* path is printed anyway */ }
65
+ }
66
+ return { dir: outDir, index, candidates: candidates.length, snapshots };
67
+ }
68
+ function page(d) {
69
+ const features = [...new Set(d.candidates.map((c) => c.feature ?? 'Other'))];
70
+ const body = d.candidates.length
71
+ ? features.map((f) => section(f, d.candidates.filter((c) => (c.feature ?? 'Other') === f), d)).join('\n')
72
+ : `<p class="empty">Nothing to show yet.</p>`;
73
+ const rules = d.rules ? rulesSection(d.rules) : '';
74
+ const counts = STATE_ORDER.map((s) => [s, d.candidates.filter((c) => c.state === s).length]).filter(([, n]) => n);
75
+ return `<!doctype html>
76
+ <html lang="en">
77
+ <head>
78
+ <meta charset="utf-8">
79
+ <meta name="viewport" content="width=device-width, initial-scale=1">
80
+ <title>${esc(d.project)} — design decisions</title>
81
+ <style>
82
+ :root { color-scheme: light dark; --bg:#fafaf9; --card:#fff; --ink:#1c1917; --muted:#78716c; --line:#e7e5e4; --tag:#f5f5f4; --ok:#15803d; --bad:#b91c1c; --warn:#b45309; }
83
+ @media (prefers-color-scheme: dark) { :root { --bg:#0c0a09; --card:#1c1917; --ink:#fafaf9; --muted:#a8a29e; --line:#292524; --tag:#292524; --ok:#4ade80; --bad:#f87171; --warn:#fbbf24; } }
84
+ * { box-sizing: border-box; }
85
+ body { margin:0; background:var(--bg); color:var(--ink); font:16px/1.55 -apple-system,BlinkMacSystemFont,"Segoe UI",Inter,system-ui,sans-serif; padding:0 20px 80px; }
86
+ header, main { max-width: 920px; margin: 0 auto; }
87
+ header { padding: 40px 0 8px; }
88
+ header h1 { font-size: 22px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
89
+ header p { color: var(--muted); margin: 6px 0 0; font-size: 14px; }
90
+ h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 44px 0 14px; }
91
+ .cand { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 24px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px; margin-bottom: 14px; }
92
+ .cand.lesser { grid-template-columns: 220px minmax(0,1fr); padding: 16px 20px; opacity: .85; }
93
+ @media (max-width: 680px) { .cand, .cand.lesser { grid-template-columns: 1fr; } }
94
+ .shot { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--tag); min-height: 60px; display:flex; align-items:center; justify-content:center; color: var(--muted); font-size: 13px; }
95
+ .shot img { display:block; width:100%; height:auto; }
96
+ h3 { font-size: 18px; font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }
97
+ .lesser h3 { font-size: 15px; }
98
+ .state { font-size: 12px; font-weight: 500; padding: 2px 9px; border-radius: 999px; background: var(--tag); color: var(--muted); vertical-align: 2px; margin-left: 8px; }
99
+ .state.approved { color: var(--ok); } .state.rejected, .state.superseded { color: var(--bad); } .state.in_review { color: var(--warn); }
100
+ .who { color: var(--muted); font-size: 14px; margin: 0 0 10px; }
101
+ .reason { font-style: italic; margin: 0 0 12px; }
102
+ .decs h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 6px; font-weight: 600; }
103
+ .decs ul { margin: 0; padding-left: 18px; }
104
+ .decs li { margin: 3px 0; }
105
+ .decs li small { color: var(--muted); display: block; }
106
+ .empty { color: var(--muted); text-align: center; padding: 80px 0; }
107
+ .rules { margin-top: 60px; border-top: 1px solid var(--line); padding-top: 30px; }
108
+ .rules ul { padding-left: 18px; } .rules li { margin: 6px 0; } .rules li small { color: var(--muted); display: block; }
109
+ footer { max-width: 920px; margin: 60px auto 0; color: var(--muted); font-size: 13px; }
110
+ </style>
111
+ </head>
112
+ <body>
113
+ <header>
114
+ <h1>${esc(d.project)} — design decisions</h1>
115
+ <p>${d.candidates.length} screen${d.candidates.length === 1 ? '' : 's'}${counts.length ? ' · ' + counts.map(([s, n]) => `${n} ${STATE_LABEL[s].toLowerCase()}`).join(' · ') : ''} · exported ${d.generated}</p>
116
+ </header>
117
+ <main>
118
+ ${body}
119
+ ${rules}
120
+ </main>
121
+ <footer>Read-only. Feedback goes to whoever owns these decisions — they decide what becomes a rule. Made with Arbiter.</footer>
122
+ </body>
123
+ </html>
124
+ `;
125
+ }
126
+ function section(feature, cands, d) {
127
+ const sorted = [...cands].sort((a, b) => STATE_ORDER.indexOf(a.state) - STATE_ORDER.indexOf(b.state) || a.id.localeCompare(b.id));
128
+ return `<h2>${esc(feature)}</h2>\n${sorted.map((c) => card(c, d)).join('\n')}`;
129
+ }
130
+ function card(c, d) {
131
+ const lesser = c.state === 'rejected' || c.state === 'superseded';
132
+ const by = c.supersededBy ? d.byId.get(c.supersededBy) : null;
133
+ const state = c.state === 'superseded' && by ? `Superseded by ${esc(by.name)}` : STATE_LABEL[c.state];
134
+ const shot = c.snapshot ? `<img src="snapshots/${esc(c.snapshot)}" alt="${esc(c.name)}">` : 'No screenshot';
135
+ const decs = d.decisions(c.id);
136
+ const decisions = decs.length
137
+ ? `<div class="decs"><h4>Decided here</h4><ul>${decs.map((x) => `<li>${esc(x.change ?? x.decision)}${x.rejected.length ? `<small>over ${esc(x.rejected.map((r) => r.split(' — ')[0]).join(', '))}</small>` : ''}</li>`).join('')}</ul></div>`
138
+ : '';
139
+ return `<article class="cand${lesser ? ' lesser' : ''}">
140
+ <div class="shot">${shot}</div>
141
+ <div>
142
+ <h3>${esc(c.name)}<span class="state ${c.state}">${state}</span></h3>
143
+ <p class="who">${esc(c.author)} · ${c.date.slice(0, 10)}</p>
144
+ ${c.reason ? `<p class="reason">“${esc(c.reason)}”</p>` : ''}
145
+ ${c.notes ? `<p>${esc(c.notes)}</p>` : ''}
146
+ ${decisions}
147
+ </div>
148
+ </article>`;
149
+ }
150
+ function rulesSection(rules) {
151
+ if (!rules.length)
152
+ return '';
153
+ const groups = schema_1.DIMENSIONS.map((dim) => [dim, rules.filter((r) => r.dimension === dim)]).filter(([, rs]) => rs.length);
154
+ return `<section class="rules"><h2>Standing rules — ${rules.length}</h2>${groups
155
+ .map(([dim, rs]) => `<h4>${format_1.DIMENSION_LABELS[dim]}</h4><ul>${rs.map((r) => `<li>${esc(r.decision)}<small>${esc(r.rationale)}</small></li>`).join('')}</ul>`)
156
+ .join('')}</section>`;
157
+ }
158
+ function esc(s) {
159
+ return s.replace(/[&<>"']/g, (ch) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[ch]);
160
+ }
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ /**
3
+ * `arbiter init` — install into the host project.
4
+ *
5
+ * Writes only files Arbiter owns, plus one merged line in AGENTS.md. Every
6
+ * write is idempotent: a second run reports "unchanged" for everything.
7
+ * Never touches host source files. Never starts anything.
8
+ */
9
+ var __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.init = init;
14
+ exports.detectClient = detectClient;
15
+ const node_fs_1 = __importDefault(require("node:fs"));
16
+ const node_os_1 = __importDefault(require("node:os"));
17
+ const node_path_1 = __importDefault(require("node:path"));
18
+ const node_child_process_1 = require("node:child_process");
19
+ const store_1 = require("../store");
20
+ const format_1 = require("../format");
21
+ const prompt_1 = require("./prompt");
22
+ const AGENTS_MARKER = '<!-- arbiter -->';
23
+ const AGENTS_LINE = `Before any UI work, read \`DECISIONS.md\` — the design decisions this project has already made. Follow them; don't re-decide them. Record new ones with the \`arbiter\` skill. ${AGENTS_MARKER}`;
24
+ const PKG_ROOT = node_path_1.default.join(__dirname, '..', '..');
25
+ const SKILL_TEMPLATE = node_path_1.default.join(PKG_ROOT, 'templates', 'SKILL.md');
26
+ async function init(opts = {}) {
27
+ const root = node_path_1.default.resolve(opts.cwd ?? process.cwd());
28
+ const paths = (0, store_1.resolvePaths)(root);
29
+ const existing = (0, store_1.readConfig)(paths);
30
+ const steps = [];
31
+ const ask = opts.yes ? null : new prompt_1.Prompter();
32
+ try {
33
+ // ── Question 1 (only if ambiguous): which client? ────────────────────
34
+ let client = opts.client ?? existing?.client;
35
+ if (!client) {
36
+ const detected = detectClient(root);
37
+ if (detected.length === 1) {
38
+ client = detected[0];
39
+ console.log(`Detected ${label(client)}.`);
40
+ }
41
+ else if (ask) {
42
+ const hint = detected.length ? 'both found' : 'neither found';
43
+ const a = (await ask.question(`Which agent client? (${hint}) [claude-code/cursor] (claude-code): `)).trim();
44
+ client = a === 'cursor' ? 'cursor' : 'claude-code';
45
+ }
46
+ else {
47
+ client = 'claude-code';
48
+ }
49
+ }
50
+ // ── Question 2: who holds the pen? ───────────────────────────────────
51
+ let author = opts.author ?? existing?.author;
52
+ if (!author) {
53
+ const guess = (0, store_1.gitUserName)(root) ?? node_os_1.default.userInfo().username;
54
+ if (ask) {
55
+ const a = (await ask.question(`Who decides rules? (author on every record) (${guess}): `)).trim();
56
+ author = a || guess;
57
+ }
58
+ else {
59
+ author = guess;
60
+ }
61
+ }
62
+ // ── arbiter.json ─────────────────────────────────────────────────────
63
+ const config = { version: 1, destination: 'local', ...existing, author, client, ...(opts.destination && { destination: opts.destination }) };
64
+ if (!existing) {
65
+ (0, store_1.writeConfig)(paths, config);
66
+ steps.push({ file: 'arbiter.json', outcome: 'created' });
67
+ }
68
+ else if (JSON.stringify(existing) !== JSON.stringify(config)) {
69
+ (0, store_1.writeConfig)(paths, config);
70
+ steps.push({ file: 'arbiter.json', outcome: 'updated' });
71
+ }
72
+ else {
73
+ steps.push({ file: 'arbiter.json', outcome: 'unchanged' });
74
+ }
75
+ // ── DECISIONS.md — never overwritten once it exists ──────────────────
76
+ if (node_fs_1.default.existsSync(paths.decisions)) {
77
+ steps.push({ file: 'DECISIONS.md', outcome: 'unchanged' });
78
+ }
79
+ else {
80
+ (0, store_1.writeActive)(paths, [], config.activeCap ?? store_1.ACTIVE_CAP);
81
+ steps.push({ file: 'DECISIONS.md', outcome: 'created' });
82
+ }
83
+ // ── .arbiter/archive.md ──────────────────────────────────────────────
84
+ node_fs_1.default.mkdirSync(paths.archiveDir, { recursive: true });
85
+ steps.push(writeIfChanged(root, node_path_1.default.join('.arbiter', '.gitignore'), 'hosted.token\n'));
86
+ if (node_fs_1.default.existsSync(paths.archive)) {
87
+ steps.push({ file: '.arbiter/archive.md', outcome: 'unchanged' });
88
+ }
89
+ else {
90
+ node_fs_1.default.writeFileSync(paths.archive, (0, format_1.archiveHeader)());
91
+ steps.push({ file: '.arbiter/archive.md', outcome: 'created' });
92
+ }
93
+ // ── Skill file ───────────────────────────────────────────────────────
94
+ const skill = skillFor(client);
95
+ steps.push(writeIfChanged(root, skill.file, skill.content));
96
+ // ── AGENTS.md — merge one line, never overwrite ──────────────────────
97
+ steps.push(mergeAgentsLine(root, 'AGENTS.md', true));
98
+ // ── Client-specific entry points ─────────────────────────────────────
99
+ if (client === 'claude-code') {
100
+ // Claude Code's own context file. Same line, same marker; created if missing so injection has a path that's certain to load.
101
+ steps.push(mergeAgentsLine(root, 'CLAUDE.md', true));
102
+ }
103
+ else {
104
+ // Cursor has no skill-invoked slash commands; give it a command file that does what `/arbiter` does.
105
+ steps.push(writeIfChanged(root, node_path_1.default.join('.cursor', 'commands', 'arbiter.md'), CURSOR_COMMAND));
106
+ }
107
+ // ── Local dev dependency ─────────────────────────────────────────────
108
+ steps.push(opts.skipInstall ? { file: 'package.json', outcome: 'skipped', note: '--skip-install' } : installSelf(root));
109
+ }
110
+ finally {
111
+ ask?.close();
112
+ }
113
+ return steps;
114
+ }
115
+ function detectClient(root) {
116
+ const out = [];
117
+ if (node_fs_1.default.existsSync(node_path_1.default.join(root, '.claude')) || node_fs_1.default.existsSync(node_path_1.default.join(root, 'CLAUDE.md')))
118
+ out.push('claude-code');
119
+ if (node_fs_1.default.existsSync(node_path_1.default.join(root, '.cursor')) || node_fs_1.default.existsSync(node_path_1.default.join(root, '.cursorrules')))
120
+ out.push('cursor');
121
+ return out;
122
+ }
123
+ const label = (c) => (c === 'cursor' ? 'Cursor' : 'Claude Code');
124
+ function skillFor(client) {
125
+ const template = node_fs_1.default.readFileSync(SKILL_TEMPLATE, 'utf8');
126
+ if (client === 'claude-code') {
127
+ return { file: node_path_1.default.join('.claude', 'skills', 'arbiter', 'SKILL.md'), content: template };
128
+ }
129
+ // Cursor: same body, Cursor's rule frontmatter. "Agent requested" — picked by description.
130
+ const m = /^---\n([\s\S]*?)\n---\n/.exec(template);
131
+ const desc = /^description:\s*(.*)$/m.exec(m?.[1] ?? '')?.[1] ?? 'Record design decisions made during UI work.';
132
+ const body = template.slice(m?.[0].length ?? 0);
133
+ const front = `---\ndescription: ${desc}\nglobs:\nalwaysApply: false\n---\n`;
134
+ return { file: node_path_1.default.join('.cursor', 'rules', 'arbiter.mdc'), content: front + body };
135
+ }
136
+ function writeIfChanged(root, rel, content) {
137
+ const abs = node_path_1.default.join(root, rel);
138
+ const before = node_fs_1.default.existsSync(abs) ? node_fs_1.default.readFileSync(abs, 'utf8') : null;
139
+ if (before === content)
140
+ return { file: rel, outcome: 'unchanged' };
141
+ node_fs_1.default.mkdirSync(node_path_1.default.dirname(abs), { recursive: true });
142
+ node_fs_1.default.writeFileSync(abs, content);
143
+ return { file: rel, outcome: before === null ? 'created' : 'updated' };
144
+ }
145
+ function mergeAgentsLine(root, file, createIfMissing) {
146
+ const abs = node_path_1.default.join(root, file);
147
+ if (!node_fs_1.default.existsSync(abs)) {
148
+ if (!createIfMissing)
149
+ return { file, outcome: 'skipped', note: 'not present' };
150
+ node_fs_1.default.writeFileSync(abs, `# Agent instructions\n\n${AGENTS_LINE}\n`);
151
+ return { file, outcome: 'created' };
152
+ }
153
+ const before = node_fs_1.default.readFileSync(abs, 'utf8');
154
+ if (before.includes(AGENTS_MARKER))
155
+ return { file, outcome: 'unchanged' };
156
+ const sep = before.endsWith('\n') ? (before.endsWith('\n\n') ? '' : '\n') : '\n\n';
157
+ node_fs_1.default.writeFileSync(abs, before + sep + AGENTS_LINE + '\n');
158
+ return { file, outcome: 'updated', note: 'one line appended' };
159
+ }
160
+ const CURSOR_COMMAND = `# Arbiter — review queued design decisions
161
+
162
+ Run \`npx arbiter rules --pending --json\` and present every queued decision, grouped by dimension, one line each with what it was chosen over. Ask the user to reply per number: confirm · rule · skip · or type what it should be. Then judge each with \`npx arbiter record P-xxxx --as accept|rule|skip|fix --to "…"\`. If the user wrote something after the command, treat it as "record that" and run \`npx arbiter record\` with it as a rule. Follow the arbiter rule file for the full protocol.
163
+ `;
164
+ /** Add this package to the host's devDependencies so `npx arbiter` resolves locally. */
165
+ function installSelf(root) {
166
+ const self = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(PKG_ROOT, 'package.json'), 'utf8'));
167
+ const hostPkgPath = node_path_1.default.join(root, 'package.json');
168
+ if (!node_fs_1.default.existsSync(hostPkgPath)) {
169
+ return { file: 'package.json', outcome: 'skipped', note: `no package.json here — add ${self.name} as a dev dependency yourself` };
170
+ }
171
+ const host = JSON.parse(node_fs_1.default.readFileSync(hostPkgPath, 'utf8'));
172
+ if (host.devDependencies?.[self.name] || host.dependencies?.[self.name]) {
173
+ return { file: 'package.json', outcome: 'unchanged', note: `${self.name} already a dependency` };
174
+ }
175
+ const pm = node_fs_1.default.existsSync(node_path_1.default.join(root, 'pnpm-lock.yaml')) ? 'pnpm' : node_fs_1.default.existsSync(node_path_1.default.join(root, 'yarn.lock')) ? 'yarn' : 'npm';
176
+ const add = (spec) => {
177
+ const args = pm === 'npm' ? ['install', '--save-dev', '--no-audit', '--no-fund', spec] : ['add', '-D', spec];
178
+ try {
179
+ (0, node_child_process_1.execFileSync)(pm, args, { cwd: root, stdio: ['ignore', 'ignore', 'ignore'] });
180
+ return true;
181
+ }
182
+ catch {
183
+ return false;
184
+ }
185
+ };
186
+ // Registry first; fall back to the copy we're running from (unpublished / local dev).
187
+ if (add(`${self.name}@^${self.version}`)) {
188
+ return { file: 'package.json', outcome: 'updated', note: `${self.name} added to devDependencies (${pm})` };
189
+ }
190
+ if (add(PKG_ROOT)) {
191
+ return { file: 'package.json', outcome: 'updated', note: `${self.name} added from ${PKG_ROOT} (registry unavailable)` };
192
+ }
193
+ return { file: 'package.json', outcome: 'skipped', note: `could not install — run: ${pm} ${pm === 'npm' ? 'install --save-dev' : 'add -D'} ${self.name}` };
194
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ /**
3
+ * Minimal line prompter for interactive commands. Buffers input lines so
4
+ * answers that arrive together (piped stdin, fast typists) aren't dropped
5
+ * between questions. Resolves '' once input closes, so a short pipe falls
6
+ * through to defaults.
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Prompter = void 0;
13
+ const node_readline_1 = __importDefault(require("node:readline"));
14
+ class Prompter {
15
+ rl = node_readline_1.default.createInterface({ input: process.stdin, terminal: false });
16
+ lines = [];
17
+ waiting = [];
18
+ closed = false;
19
+ constructor() {
20
+ this.rl.on('line', (l) => {
21
+ const w = this.waiting.shift();
22
+ if (w)
23
+ w(l);
24
+ else
25
+ this.lines.push(l);
26
+ });
27
+ this.rl.on('close', () => {
28
+ this.closed = true;
29
+ for (const w of this.waiting.splice(0))
30
+ w('');
31
+ });
32
+ }
33
+ question(q) {
34
+ process.stdout.write(q);
35
+ const l = this.lines.shift();
36
+ if (l !== undefined)
37
+ return Promise.resolve(l);
38
+ if (this.closed)
39
+ return Promise.resolve('');
40
+ return new Promise((res) => this.waiting.push(res));
41
+ }
42
+ /** Ask until non-empty, or return the default. */
43
+ async required(q, dflt) {
44
+ for (;;) {
45
+ const a = (await this.question(dflt ? `${q} (${dflt}): ` : `${q}: `)).trim();
46
+ if (a)
47
+ return a;
48
+ if (dflt)
49
+ return dflt;
50
+ if (this.closed)
51
+ return '';
52
+ }
53
+ }
54
+ /** Numbered pick. Returns the chosen value. */
55
+ async pick(q, options, dflt) {
56
+ const menu = options.map((o, i) => ` ${i + 1}. ${o}`).join('\n');
57
+ const a = (await this.question(`${q}\n${menu}\n(${options.indexOf(dflt) + 1}): `)).trim();
58
+ const n = Number(a);
59
+ if (n >= 1 && n <= options.length)
60
+ return options[n - 1];
61
+ if (options.includes(a))
62
+ return a;
63
+ return dflt;
64
+ }
65
+ close() {
66
+ this.rl.close();
67
+ }
68
+ }
69
+ exports.Prompter = Prompter;
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ /**
3
+ * `arbiter publish` — put the board online, one command.
4
+ *
5
+ * The only command that touches the network, and only because the user typed
6
+ * it. Everything else in Arbiter is local.
7
+ *
8
+ * 1. destination → git (if not already)
9
+ * 2. export the board page, commit it with the candidate files
10
+ * 3. enable GitHub Pages for docs/ via `gh` (if installed and signed in)
11
+ * 4. git push
12
+ * 5. print the link
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.publish = publish;
16
+ const node_child_process_1 = require("node:child_process");
17
+ const candidates_1 = require("../candidates");
18
+ const destination_1 = require("../destination");
19
+ const store_1 = require("../store");
20
+ const hosted_1 = require("../hosted");
21
+ async function publish(opts = {}) {
22
+ const root = (0, store_1.findRoot)(opts.cwd);
23
+ const paths = (0, store_1.resolvePaths)(root);
24
+ const steps = [];
25
+ const done = (step, note) => steps.push({ step, outcome: 'done', note });
26
+ const skip = (step, note) => steps.push({ step, outcome: 'skipped', note });
27
+ const fail = (step, note) => steps.push({ step, outcome: 'failed', note });
28
+ const to = opts.to ?? (0, store_1.readConfig)(paths)?.hosted?.url;
29
+ if (to) {
30
+ try {
31
+ const r = await (0, hosted_1.publishHosted)(paths, to, { admin: opts.admin });
32
+ if (r.created)
33
+ done('project', `created on ${to} — link in .arbiter/hosted.json (commit it); token in .arbiter/hosted.token (git-ignored — teammates set ARBITER_PUBLISH_TOKEN)`);
34
+ done('board', `${r.candidates} screen${r.candidates === 1 ? '' : 's'} published${r.snapshots ? `, ${r.snapshots} image${r.snapshots === 1 ? '' : 's'}` : ''}`);
35
+ for (const s of r.skipped)
36
+ skip('snapshot', s);
37
+ return { ok: true, steps, url: r.link.shareUrl };
38
+ }
39
+ catch (e) {
40
+ fail('hosted', e.message);
41
+ return { ok: false, steps, url: null };
42
+ }
43
+ }
44
+ if (!git(root, ['rev-parse', '--is-inside-work-tree'])) {
45
+ fail('git', 'not a git repository — run `git init` and add a GitHub remote first');
46
+ return { ok: false, steps, url: null };
47
+ }
48
+ const remote = git(root, ['remote', 'get-url', 'origin']);
49
+ const gh = remote && /github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?$/.exec(remote);
50
+ if (!gh) {
51
+ fail('remote', 'no GitHub remote named origin — `git remote add origin git@github.com:you/repo.git`');
52
+ return { ok: false, steps, url: null };
53
+ }
54
+ const [, owner, repo] = gh;
55
+ // 1. destination → git
56
+ let config = (0, store_1.readConfig)(paths) ?? { version: 1, destination: 'local' };
57
+ if (config.destination !== 'git') {
58
+ config = { ...config, destination: 'git' };
59
+ (0, store_1.writeConfig)(paths, config);
60
+ done('destination', 'arbiter.json → "git"');
61
+ }
62
+ else
63
+ skip('destination', 'already git');
64
+ // 2. export + commit (deliver does both; rewriting candidates refreshes their decision lists)
65
+ const candidates = (0, candidates_1.readCandidates)(paths);
66
+ for (const c of candidates)
67
+ (0, candidates_1.writeCandidate)(paths, c);
68
+ const delivered = (0, destination_1.deliver)(paths, config, candidates, 'publish board');
69
+ if (delivered.committed)
70
+ done('commit', `${delivered.committed} — board page, ${candidates.length} candidate${candidates.length === 1 ? '' : 's'}`);
71
+ else
72
+ skip('commit', 'nothing changed since last publish');
73
+ // 3. GitHub Pages via gh
74
+ const branch = git(root, ['rev-parse', '--abbrev-ref', 'HEAD']) || 'main';
75
+ if (!has('gh')) {
76
+ skip('pages', `gh not installed — once, on github.com: ${owner}/${repo} → Settings → Pages → Deploy from a branch → ${branch} / docs → Save`);
77
+ }
78
+ else if (!ghOk(root)) {
79
+ skip('pages', `gh not signed in (run \`gh auth login\`) — or once, on github.com: ${owner}/${repo} → Settings → Pages → Deploy from a branch → ${branch} / docs → Save`);
80
+ }
81
+ else {
82
+ const existing = ghApi(root, ['repos/' + owner + '/' + repo + '/pages']);
83
+ if (existing && existing.includes('"path":"/docs"') && existing.includes(`"branch":"${branch}"`)) {
84
+ skip('pages', 'already on (docs/)');
85
+ }
86
+ else {
87
+ const method = existing ? 'PUT' : 'POST';
88
+ const r = ghApi(root, ['-X', method, 'repos/' + owner + '/' + repo + '/pages', '-f', `source[branch]=${branch}`, '-f', 'source[path]=/docs'], true);
89
+ if (r !== null)
90
+ done('pages', `GitHub Pages → ${branch} / docs`);
91
+ else
92
+ fail('pages', `could not enable — once, on github.com: ${owner}/${repo} → Settings → Pages → Deploy from a branch → ${branch} / docs → Save`);
93
+ }
94
+ }
95
+ // 4. push
96
+ if (opts.noPush)
97
+ skip('push', '--no-push');
98
+ else if (git(root, ['push', '-u', 'origin', branch]) !== null)
99
+ done('push', `origin/${branch}`);
100
+ else
101
+ fail('push', 'git push failed — check access to the remote, then `git push`');
102
+ const url = (0, destination_1.pagesUrl)(root, config);
103
+ const ok = steps.every((s) => s.outcome !== 'failed');
104
+ return { ok, steps, url };
105
+ }
106
+ function git(root, args) {
107
+ try {
108
+ return (0, node_child_process_1.execFileSync)('git', args, { cwd: root, stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim();
109
+ }
110
+ catch {
111
+ return null;
112
+ }
113
+ }
114
+ function has(cmd) {
115
+ try {
116
+ (0, node_child_process_1.execFileSync)(process.platform === 'win32' ? 'where' : 'which', [cmd], { stdio: 'ignore' });
117
+ return true;
118
+ }
119
+ catch {
120
+ return false;
121
+ }
122
+ }
123
+ function ghOk(root) {
124
+ try {
125
+ (0, node_child_process_1.execFileSync)('gh', ['auth', 'status'], { cwd: root, stdio: 'ignore' });
126
+ return true;
127
+ }
128
+ catch {
129
+ return false;
130
+ }
131
+ }
132
+ function ghApi(root, args, write = false) {
133
+ try {
134
+ return (0, node_child_process_1.execFileSync)('gh', ['api', ...args], { cwd: root, stdio: ['ignore', 'pipe', 'ignore'] }).toString();
135
+ }
136
+ catch {
137
+ return write ? null : null;
138
+ }
139
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ /** `arbiter pull` — bring comments and "looks good" reactions down from the hosted board. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.pull = pull;
5
+ const candidates_1 = require("../candidates");
6
+ const hosted_1 = require("../hosted");
7
+ const store_1 = require("../store");
8
+ async function pull(opts = {}) {
9
+ const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
10
+ const { link, fresh, total } = await (0, hosted_1.pullHosted)(paths);
11
+ if (!fresh.length)
12
+ return `Nothing new on ${link.shareUrl} (${total} comment${total === 1 ? '' : 's'} so far).`;
13
+ const names = new Map((0, candidates_1.readCandidates)(paths).map((c) => [c.id, c.name]));
14
+ const lines = [`${fresh.length} new from ${link.shareUrl}:`, ''];
15
+ const byCand = new Map();
16
+ for (const c of fresh)
17
+ byCand.set(c.candidate_id, [...(byCand.get(c.candidate_id) ?? []), c]);
18
+ for (const [cid, cs] of byCand) {
19
+ lines.push(` ${cid} ${names.get(cid) ?? (cid.startsWith('W-') ? cid.slice(2).replace(/-/g, ' ').replace(/^\w/, (ch) => ch.toUpperCase()) : '')}`);
20
+ for (const c of cs) {
21
+ const stale = c.board_version && link.boardVersion && c.board_version !== link.boardVersion ? ' (earlier version)' : '';
22
+ lines.push((c.kind === 'approve' ? ` ✓ ${c.author_name} — looks good` : ` ${c.author_name}${c.decision_id ? ` on ${c.decision_id}` : ''}: ${c.body}`) + stale);
23
+ }
24
+ }
25
+ lines.push('', 'Saved to .arbiter/comments.json — npx arbiter review shows them beside each screen. Say "record Sam\'s comment as a rule" in a session to act on one.');
26
+ return lines.join('\n');
27
+ }