arbiterdesign 0.1.2 → 0.1.3

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.
@@ -10,8 +10,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
10
10
  return (mod && mod.__esModule) ? mod : { "default": mod };
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.skillMarker = exports.SKILL_MARKER = exports.PKG_ROOT = void 0;
14
+ exports.selfVersion = selfVersion;
15
+ exports.skillPath = skillPath;
13
16
  exports.init = init;
14
17
  exports.detectClient = detectClient;
18
+ exports.detectPm = detectPm;
19
+ exports.addDevDependency = addDevDependency;
15
20
  const node_fs_1 = __importDefault(require("node:fs"));
16
21
  const node_os_1 = __importDefault(require("node:os"));
17
22
  const node_path_1 = __importDefault(require("node:path"));
@@ -21,8 +26,24 @@ const format_1 = require("../format");
21
26
  const prompt_1 = require("./prompt");
22
27
  const AGENTS_MARKER = '<!-- arbiter -->';
23
28
  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');
29
+ exports.PKG_ROOT = node_path_1.default.join(__dirname, '..', '..');
30
+ const SKILL_TEMPLATE = node_path_1.default.join(exports.PKG_ROOT, 'templates', 'SKILL.md');
31
+ /** The version of the package that's running. */
32
+ function selfVersion() {
33
+ return JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(exports.PKG_ROOT, 'package.json'), 'utf8')).version;
34
+ }
35
+ /**
36
+ * The skill file is a copy: it goes stale when the package moves on and nobody re-runs init.
37
+ * A comment on its first body line says which version wrote it, so `update` can tell without
38
+ * touching the network. A skill file with no marker predates 0.1.3 — always stale.
39
+ */
40
+ exports.SKILL_MARKER = /<!-- arbiter skill (\S+) -->/;
41
+ const skillMarker = (version) => `<!-- arbiter skill ${version} -->`;
42
+ exports.skillMarker = skillMarker;
43
+ /** Where the skill lives for a client. */
44
+ function skillPath(client) {
45
+ return client === 'cursor' ? node_path_1.default.join('.cursor', 'rules', 'arbiter.mdc') : node_path_1.default.join('.claude', 'skills', 'arbiter', 'SKILL.md');
46
+ }
26
47
  async function init(opts = {}) {
27
48
  const root = node_path_1.default.resolve(opts.cwd ?? process.cwd());
28
49
  const paths = (0, store_1.resolvePaths)(root);
@@ -52,7 +73,7 @@ async function init(opts = {}) {
52
73
  if (!author) {
53
74
  const guess = (0, store_1.gitUserName)(root) ?? node_os_1.default.userInfo().username;
54
75
  if (ask) {
55
- const a = (await ask.question(`Who decides rules? (author on every record) (${guess}): `)).trim();
76
+ const a = (await ask.question(`Who decides rules? (the author when git has no user.name) (${guess}): `)).trim();
56
77
  author = a || guess;
57
78
  }
58
79
  else {
@@ -122,25 +143,30 @@ function detectClient(root) {
122
143
  }
123
144
  const label = (c) => (c === 'cursor' ? 'Cursor' : 'Claude Code');
124
145
  function skillFor(client) {
125
- const template = node_fs_1.default.readFileSync(SKILL_TEMPLATE, 'utf8');
146
+ // A Windows checkout with autocrlf hands us CRLF; the frontmatter regex and the marker line assume LF.
147
+ const template = node_fs_1.default.readFileSync(SKILL_TEMPLATE, 'utf8').replace(/\r\n/g, '\n');
148
+ const m = /^---\n([\s\S]*?)\n---\n/.exec(template);
149
+ // The version marker is the first body line, under the frontmatter, so both clients carry it.
150
+ const body = (0, exports.skillMarker)(selfVersion()) + '\n' + template.slice(m?.[0].length ?? 0);
126
151
  if (client === 'claude-code') {
127
- return { file: node_path_1.default.join('.claude', 'skills', 'arbiter', 'SKILL.md'), content: template };
152
+ return { file: skillPath(client), content: (m?.[0] ?? '') + body };
128
153
  }
129
154
  // Cursor: same body, Cursor's rule frontmatter. "Agent requested" — picked by description.
130
- const m = /^---\n([\s\S]*?)\n---\n/.exec(template);
131
155
  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
156
  const front = `---\ndescription: ${desc}\nglobs:\nalwaysApply: false\n---\n`;
134
- return { file: node_path_1.default.join('.cursor', 'rules', 'arbiter.mdc'), content: front + body };
157
+ return { file: skillPath(client), content: front + body };
135
158
  }
136
159
  function writeIfChanged(root, rel, content) {
137
160
  const abs = node_path_1.default.join(root, rel);
161
+ // The label is written with `/` on every platform, like the literals above it and
162
+ // updateStatus's file. Only the name shown changes; abs is the platform's own path.
163
+ const name = rel.split(node_path_1.default.sep).join('/');
138
164
  const before = node_fs_1.default.existsSync(abs) ? node_fs_1.default.readFileSync(abs, 'utf8') : null;
139
165
  if (before === content)
140
- return { file: rel, outcome: 'unchanged' };
166
+ return { file: name, outcome: 'unchanged' };
141
167
  node_fs_1.default.mkdirSync(node_path_1.default.dirname(abs), { recursive: true });
142
168
  node_fs_1.default.writeFileSync(abs, content);
143
- return { file: rel, outcome: before === null ? 'created' : 'updated' };
169
+ return { file: name, outcome: before === null ? 'created' : 'updated' };
144
170
  }
145
171
  function mergeAgentsLine(root, file, createIfMissing) {
146
172
  const abs = node_path_1.default.join(root, file);
@@ -157,13 +183,36 @@ function mergeAgentsLine(root, file, createIfMissing) {
157
183
  node_fs_1.default.writeFileSync(abs, before + sep + AGENTS_LINE + '\n');
158
184
  return { file, outcome: 'updated', note: 'one line appended' };
159
185
  }
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.
186
+ const CURSOR_COMMAND = `# Arbiter — review queued design decisions
187
+
188
+ 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
189
  `;
190
+ /** Which package manager the host uses, by lockfile. */
191
+ function detectPm(root) {
192
+ return 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';
193
+ }
194
+ /**
195
+ * Add a dev dependency. Quiet; true on success.
196
+ *
197
+ * On Windows the package managers are .cmd shims, which execFile can't run on its own — it
198
+ * raises ENOENT. `shell: true` fixes that but makes Node warn about unescaped arguments
199
+ * (DEP0190) on every install, which is the first thing a new user would see. Going through
200
+ * cmd.exe resolves the shim with the arguments still a real array, so neither happens.
201
+ */
202
+ function addDevDependency(root, pm, spec) {
203
+ const args = pm === 'npm' ? ['install', '--save-dev', '--no-audit', '--no-fund', spec] : ['add', '-D', spec];
204
+ const win = process.platform === 'win32';
205
+ try {
206
+ (0, node_child_process_1.execFileSync)(win ? 'cmd.exe' : pm, win ? ['/c', pm, ...args] : args, { cwd: root, stdio: ['ignore', 'ignore', 'ignore'] });
207
+ return true;
208
+ }
209
+ catch {
210
+ return false;
211
+ }
212
+ }
164
213
  /** Add this package to the host's devDependencies so `npx arbiter` resolves locally. */
165
214
  function installSelf(root) {
166
- const self = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(PKG_ROOT, 'package.json'), 'utf8'));
215
+ const self = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(exports.PKG_ROOT, 'package.json'), 'utf8'));
167
216
  const hostPkgPath = node_path_1.default.join(root, 'package.json');
168
217
  if (!node_fs_1.default.existsSync(hostPkgPath)) {
169
218
  return { file: 'package.json', outcome: 'skipped', note: `no package.json here — add ${self.name} as a dev dependency yourself` };
@@ -172,23 +221,14 @@ function installSelf(root) {
172
221
  if (host.devDependencies?.[self.name] || host.dependencies?.[self.name]) {
173
222
  return { file: 'package.json', outcome: 'unchanged', note: `${self.name} already a dependency` };
174
223
  }
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
- };
224
+ const pm = detectPm(root);
225
+ const add = (spec) => addDevDependency(root, pm, spec);
186
226
  // Registry first; fall back to the copy we're running from (unpublished / local dev).
187
227
  if (add(`${self.name}@^${self.version}`)) {
188
228
  return { file: 'package.json', outcome: 'updated', note: `${self.name} added to devDependencies (${pm})` };
189
229
  }
190
- if (add(PKG_ROOT)) {
191
- return { file: 'package.json', outcome: 'updated', note: `${self.name} added from ${PKG_ROOT} (registry unavailable)` };
230
+ if (add(exports.PKG_ROOT)) {
231
+ return { file: 'package.json', outcome: 'updated', note: `${self.name} added from ${exports.PKG_ROOT} (registry unavailable)` };
192
232
  }
193
233
  return { file: 'package.json', outcome: 'skipped', note: `could not install — run: ${pm} ${pm === 'npm' ? 'install --save-dev' : 'add -D'} ${self.name}` };
194
234
  }
@@ -11,16 +11,24 @@
11
11
  * 4. git push
12
12
  * 5. print the link
13
13
  */
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
14
17
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.DEFAULT_HOST = void 0;
18
+ exports.WORKFLOW_FILE = exports.DEFAULT_HOST = void 0;
16
19
  exports.publish = publish;
20
+ const node_fs_1 = __importDefault(require("node:fs"));
21
+ const node_path_1 = __importDefault(require("node:path"));
17
22
  const node_child_process_1 = require("node:child_process");
18
23
  const candidates_1 = require("../candidates");
19
24
  const destination_1 = require("../destination");
20
25
  const store_1 = require("../store");
21
26
  const hosted_1 = require("../hosted");
27
+ const init_1 = require("./init");
22
28
  /** Where `arbiter publish` goes when nothing says otherwise. */
23
29
  exports.DEFAULT_HOST = 'https://arbiter.design';
30
+ /** The GitHub Actions workflow `--on-push` writes. `update` re-pins the version in it. */
31
+ exports.WORKFLOW_FILE = node_path_1.default.join('.github', 'workflows', 'arbiter.yml');
24
32
  async function publish(opts = {}) {
25
33
  const root = (0, store_1.findRoot)(opts.cwd);
26
34
  const paths = (0, store_1.resolvePaths)(root);
@@ -39,7 +47,10 @@ async function publish(opts = {}) {
39
47
  done('board', `${r.candidates} screen${r.candidates === 1 ? '' : 's'} published${r.snapshots ? `, ${r.snapshots} image${r.snapshots === 1 ? '' : 's'}` : ''}`);
40
48
  for (const s of r.skipped)
41
49
  skip('snapshot', s);
42
- return { ok: true, steps, url: r.link.shareUrl };
50
+ if (opts.onPush)
51
+ for (const s of onPush(root, paths))
52
+ steps.push(s);
53
+ return { ok: steps.every((s) => s.outcome !== 'failed'), steps, url: r.link.shareUrl };
43
54
  }
44
55
  catch (e) {
45
56
  fail('hosted', e.message);
@@ -108,6 +119,80 @@ async function publish(opts = {}) {
108
119
  const ok = steps.every((s) => s.outcome !== 'failed');
109
120
  return { ok, steps, url };
110
121
  }
122
+ /**
123
+ * Keep the board current without anyone remembering to publish: a workflow that runs `publish`
124
+ * when decisions land on the default branch. The publish token becomes a repository secret —
125
+ * set through `gh` when it's signed in, otherwise a one-line instruction. The workflow itself
126
+ * is committed by the user; Arbiter only commits under `destination: git`.
127
+ */
128
+ function onPush(root, paths) {
129
+ const steps = [];
130
+ const branch = git(root, ['rev-parse', '--abbrev-ref', 'HEAD']) || 'main';
131
+ const file = node_path_1.default.join(root, exports.WORKFLOW_FILE);
132
+ const content = workflow(branch, (0, init_1.selfVersion)());
133
+ if (!node_fs_1.default.existsSync(file)) {
134
+ node_fs_1.default.mkdirSync(node_path_1.default.dirname(file), { recursive: true });
135
+ node_fs_1.default.writeFileSync(file, content);
136
+ steps.push({ step: 'workflow', outcome: 'done', note: `${exports.WORKFLOW_FILE} — commit it with .arbiter/hosted.json` });
137
+ }
138
+ else if (node_fs_1.default.readFileSync(file, 'utf8') === content) {
139
+ steps.push({ step: 'workflow', outcome: 'skipped', note: `${exports.WORKFLOW_FILE} already there` });
140
+ }
141
+ else {
142
+ steps.push({ step: 'workflow', outcome: 'skipped', note: `${exports.WORKFLOW_FILE} exists and differs — leaving your edits` });
143
+ }
144
+ const token = (0, hosted_1.readToken)(paths);
145
+ const remote = git(root, ['remote', 'get-url', 'origin']);
146
+ const gh = remote && /github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?$/.exec(remote);
147
+ const manual = `once, on github.com: Settings → Secrets and variables → Actions → New repository secret → ${hosted_1.TOKEN_ENV} = the contents of .arbiter/hosted.token`;
148
+ if (!token)
149
+ steps.push({ step: 'secret', outcome: 'skipped', note: `no publish token here — ${manual}` });
150
+ else if (!gh)
151
+ steps.push({ step: 'secret', outcome: 'skipped', note: `no GitHub remote named origin — ${manual}` });
152
+ else if (!has('gh') || !ghOk(root))
153
+ steps.push({ step: 'secret', outcome: 'skipped', note: `gh not ${has('gh') ? 'signed in' : 'installed'} — ${manual}` });
154
+ else {
155
+ try {
156
+ // The token goes in on stdin, not argv, so it never shows in a process list.
157
+ (0, node_child_process_1.execFileSync)('gh', ['secret', 'set', hosted_1.TOKEN_ENV, '--repo', `${gh[1]}/${gh[2]}`], { cwd: root, input: token, stdio: ['pipe', 'ignore', 'ignore'] });
158
+ steps.push({ step: 'secret', outcome: 'done', note: `${hosted_1.TOKEN_ENV} set on ${gh[1]}/${gh[2]}` });
159
+ }
160
+ catch {
161
+ steps.push({ step: 'secret', outcome: 'failed', note: `gh could not set the secret — ${manual}` });
162
+ }
163
+ }
164
+ return steps;
165
+ }
166
+ function workflow(branch, version) {
167
+ return [
168
+ '# Written by `npx arbiter publish --on-push`. Republishes the board when decisions land.',
169
+ '# Needs one repository secret, ARBITER_PUBLISH_TOKEN: the contents of .arbiter/hosted.token.',
170
+ '# `npx arbiter update` re-pins the version below.',
171
+ 'name: Arbiter',
172
+ 'on:',
173
+ ' push:',
174
+ ` branches: [${branch}]`,
175
+ ' paths:',
176
+ " - '.arbiter/**'",
177
+ " - 'DECISIONS.md'",
178
+ " - 'CANDIDATES.md'",
179
+ 'concurrency:',
180
+ ' group: arbiter-publish',
181
+ ' cancel-in-progress: true',
182
+ 'jobs:',
183
+ ' publish:',
184
+ ' runs-on: ubuntu-latest',
185
+ ' steps:',
186
+ ' - uses: actions/checkout@v4',
187
+ ' - uses: actions/setup-node@v4',
188
+ ' with:',
189
+ ' node-version: 20',
190
+ ` - run: npx --yes arbiterdesign@${version} publish`,
191
+ ' env:',
192
+ ' ARBITER_PUBLISH_TOKEN: ${{ secrets.ARBITER_PUBLISH_TOKEN }}',
193
+ '',
194
+ ].join('\n');
195
+ }
111
196
  function git(root, args) {
112
197
  try {
113
198
  return (0, node_child_process_1.execFileSync)('git', args, { cwd: root, stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim();
@@ -41,6 +41,7 @@ const findings_1 = require("../findings");
41
41
  const prompt_1 = require("./prompt");
42
42
  const node_fs_1 = __importDefault(require("node:fs"));
43
43
  const candidate_1 = require("./candidate");
44
+ const update_1 = require("./update");
44
45
  // ── Parse + record ─────────────────────────────────────────────────────────
45
46
  function record(rawJson, opts = {}) {
46
47
  const parsed = parse(rawJson);
@@ -73,6 +74,8 @@ function queue(rawJson, opts = {}) {
73
74
  pending: pending.length + 1,
74
75
  checkin: (0, store_1.readConfig)(paths)?.checkin ?? 'feature',
75
76
  review: 'npx arbiter review',
77
+ // Present only when the project's skill file is from an older Arbiter than this one.
78
+ ...(0, update_1.updateNotice)(paths),
76
79
  },
77
80
  };
78
81
  }
@@ -344,7 +347,9 @@ function fill(input, opts, root) {
344
347
  const config = (0, store_1.readConfig)((0, store_1.resolvePaths)(root));
345
348
  return {
346
349
  date: input.date ?? (0, store_1.now)(),
347
- author: opts.author ?? input.author ?? config?.author ?? (0, store_1.gitUserName)(root) ?? node_os_1.default.userInfo().username,
350
+ // Whoever is at the keyboard. arbiter.json's author is committed, so in a shared repo it names
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,
348
353
  class: input.class,
349
354
  dimension: input.dimension,
350
355
  decision: input.decision,
@@ -15,6 +15,7 @@ exports.groupByTrigger = groupByTrigger;
15
15
  const schema_1 = require("../schema");
16
16
  const format_1 = require("../format");
17
17
  const store_1 = require("../store");
18
+ const update_1 = require("./update");
18
19
  function rules(id, opts = {}) {
19
20
  const paths = (0, store_1.resolvePaths)((0, store_1.findRoot)(opts.cwd));
20
21
  opts = { ...opts, config: (0, store_1.readConfig)(paths) };
@@ -24,7 +25,7 @@ function rules(id, opts = {}) {
24
25
  if (opts.archive)
25
26
  return archive((0, store_1.readArchive)(paths), (0, store_1.readActive)(paths), opts);
26
27
  if (opts.pending)
27
- return pendingList((0, store_1.readPending)(paths), opts);
28
+ return pendingList((0, store_1.readPending)(paths), opts, paths);
28
29
  let active = (0, store_1.readActive)(paths);
29
30
  if (opts.dimension) {
30
31
  if (!schema_1.DIMENSIONS.includes(opts.dimension)) {
@@ -56,12 +57,13 @@ function rules(id, opts = {}) {
56
57
  * Pattern Half-width cards use icon-only action buttons
57
58
  * Rejected A labelled button — wrapped under the text on mobile
58
59
  */
59
- function pendingList(pending, opts) {
60
+ function pendingList(pending, opts, paths) {
60
61
  const groups = groupByTrigger(pending);
61
62
  if (opts.json) {
62
63
  return JSON.stringify({
63
64
  firstRun: !opts.config?.onboarded,
64
65
  checkin: opts.config?.checkin ?? 'feature',
66
+ ...(0, update_1.updateNotice)(paths),
65
67
  count: pending.length,
66
68
  polish: pending.filter((d) => d.level === 'polish').length,
67
69
  groups: groups.map((g) => ({ trigger: g.trigger, items: g.items, polish: g.polish })),
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ /**
3
+ * `arbiter update` — bring a project up to the newest Arbiter, and `updateStatus`, the offline
4
+ * check behind the agent's one-line notice.
5
+ *
6
+ * Two things go stale independently: the package pinned in the host's devDependencies, and the
7
+ * skill file init copied into the project — the agent's whole protocol. The second is the one
8
+ * that matters, and it's detectable with no network: init stamps the skill with the version
9
+ * that wrote it. Nothing here checks the registry; "is there a newer version" is the package
10
+ * manager's job when `update` runs.
11
+ *
12
+ * 1. install arbiterdesign@latest as a dev dependency (skipped without a package.json)
13
+ * 2. re-run init from the *installed* copy — the running process is the old version
14
+ * 3. re-pin the publish workflow, if there is one
15
+ *
16
+ * Never touches arbiter.json's settings, DECISIONS.md, or the archive: init leaves those alone.
17
+ */
18
+ var __importDefault = (this && this.__importDefault) || function (mod) {
19
+ return (mod && mod.__esModule) ? mod : { "default": mod };
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.updateStatus = updateStatus;
23
+ exports.updateNotice = updateNotice;
24
+ exports.update = update;
25
+ const node_fs_1 = __importDefault(require("node:fs"));
26
+ const node_path_1 = __importDefault(require("node:path"));
27
+ const node_child_process_1 = require("node:child_process");
28
+ const init_1 = require("./init");
29
+ const publish_1 = require("./publish");
30
+ const store_1 = require("../store");
31
+ /** Offline. Null when this isn't an Arbiter project. */
32
+ function updateStatus(paths) {
33
+ const config = (0, store_1.readConfig)(paths);
34
+ if (!config)
35
+ return null;
36
+ const cli = (0, init_1.selfVersion)();
37
+ const clients = config.client === 'cursor' ? ['cursor'] : config.client === 'claude-code' ? ['claude-code'] : ['claude-code', 'cursor'];
38
+ const file = clients.map(init_1.skillPath).find((f) => node_fs_1.default.existsSync(node_path_1.default.join(paths.root, f))) ?? null;
39
+ if (!file)
40
+ return { cli, skill: null, file: null, stale: false };
41
+ const skill = init_1.SKILL_MARKER.exec(node_fs_1.default.readFileSync(node_path_1.default.join(paths.root, file), 'utf8'))?.[1] ?? null;
42
+ return { cli, skill, file: file.split(node_path_1.default.sep).join('/'), stale: skill !== cli };
43
+ }
44
+ /** What `record --pending` and `rules --pending --json` carry when the skill file is behind. */
45
+ function updateNotice(paths) {
46
+ const s = updateStatus(paths);
47
+ return s?.stale ? { update: { skill: s.skill ?? 'before 0.1.3', cli: s.cli, command: 'npx arbiter update' } } : {};
48
+ }
49
+ async function update(opts = {}) {
50
+ const root = (0, store_1.findRoot)(opts.cwd);
51
+ const paths = (0, store_1.resolvePaths)(root);
52
+ const before = updateStatus(paths);
53
+ if (!before)
54
+ throw new Error('no arbiter.json here — run `npx arbiter init` first');
55
+ const steps = [];
56
+ if (opts.check)
57
+ return { ok: true, before, after: before, steps };
58
+ const done = (step, note) => steps.push({ step, outcome: 'done', note });
59
+ const skip = (step, note) => steps.push({ step, outcome: 'skipped', note });
60
+ const fail = (step, note) => steps.push({ step, outcome: 'failed', note });
61
+ // 1. the package
62
+ let installed = null;
63
+ if (opts.skipInstall)
64
+ skip('package', '--skip-install');
65
+ else if (!node_fs_1.default.existsSync(node_path_1.default.join(root, 'package.json')))
66
+ skip('package', 'no package.json here — the skill is refreshed from this copy');
67
+ else {
68
+ const pm = (0, init_1.detectPm)(root);
69
+ if ((0, init_1.addDevDependency)(root, pm, 'arbiterdesign@latest')) {
70
+ installed = installedCopy(root);
71
+ done('package', installed ? `arbiterdesign ${installed.version} (${pm})` : `installed (${pm})`);
72
+ }
73
+ else
74
+ fail('package', `${pm} could not install arbiterdesign@latest — check the network, then re-run`);
75
+ }
76
+ // 2. the skill — from the copy that was just installed, so a new template lands, not this one's
77
+ try {
78
+ if (installed && installed.version !== (0, init_1.selfVersion)()) {
79
+ (0, node_child_process_1.execFileSync)(process.execPath, [installed.bin, 'init', '--yes', '--skip-install'], { cwd: root, stdio: ['ignore', 'ignore', 'pipe'] });
80
+ done('skill', `refreshed by arbiter ${installed.version}`);
81
+ }
82
+ else {
83
+ await (0, init_1.init)({ cwd: root, yes: true, skipInstall: true });
84
+ done('skill', `refreshed by this copy (${(0, init_1.selfVersion)()})`);
85
+ }
86
+ }
87
+ catch (e) {
88
+ fail('skill', `init failed: ${e.message.split('\n')[0]}`);
89
+ }
90
+ // 3. the publish workflow, if publish --on-push wrote one: it pins a version
91
+ const wf = node_path_1.default.join(root, publish_1.WORKFLOW_FILE);
92
+ if (node_fs_1.default.existsSync(wf)) {
93
+ const to = installed?.version ?? (0, init_1.selfVersion)();
94
+ const text = node_fs_1.default.readFileSync(wf, 'utf8');
95
+ const next = text.replace(/arbiterdesign@[^\s'"]+/g, `arbiterdesign@${to}`);
96
+ if (next !== text) {
97
+ node_fs_1.default.writeFileSync(wf, next);
98
+ done('workflow', `${publish_1.WORKFLOW_FILE} → arbiterdesign@${to} (commit it)`);
99
+ }
100
+ else
101
+ skip('workflow', `already arbiterdesign@${to}`);
102
+ }
103
+ const after = updateStatus(paths) ?? before;
104
+ return { ok: steps.every((s) => s.outcome !== 'failed'), before, after, steps };
105
+ }
106
+ /** The package as installed in the host's node_modules, if it's there. */
107
+ function installedCopy(root) {
108
+ const dir = node_path_1.default.join(root, 'node_modules', 'arbiterdesign');
109
+ const pkg = node_path_1.default.join(dir, 'package.json');
110
+ const bin = node_path_1.default.join(dir, 'dist', 'index.js');
111
+ if (!node_fs_1.default.existsSync(pkg) || !node_fs_1.default.existsSync(bin))
112
+ return null;
113
+ return { version: JSON.parse(node_fs_1.default.readFileSync(pkg, 'utf8')).version, bin };
114
+ }
package/dist/hosted.js CHANGED
@@ -165,6 +165,11 @@ async function publishHosted(paths, serviceUrl, opts = {}) {
165
165
  let link = readLink(paths);
166
166
  let created = false;
167
167
  if (!link || link.url !== base) {
168
+ // Automation republishes an existing board; it never creates one. Without this, a repo where
169
+ // hosted.json wasn't committed would mint a fresh orphan board on every push.
170
+ if (process.env.CI && !process.env.ARBITER_CREATE_IN_CI) {
171
+ throw new Error(`no .arbiter/hosted.json for ${base} — publish once from a laptop and commit that file, so CI updates the existing board instead of creating a new one`);
172
+ }
168
173
  const admin = opts.admin ?? process.env[exports.ADMIN_ENV];
169
174
  const r = await api(`${base}/api/projects`, { method: 'POST', body: JSON.stringify({ name: node_path_1.default.basename(paths.root) }), admin });
170
175
  if (r.status === 401)
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ const setup_1 = require("./commands/setup");
16
16
  const rules_1 = require("./commands/rules");
17
17
  const init_1 = require("./commands/init");
18
18
  const review_1 = require("./commands/review");
19
+ const update_1 = require("./commands/update");
19
20
  const program = new commander_1.Command();
20
21
  program
21
22
  .name('arbiter')
@@ -189,12 +190,13 @@ program
189
190
  });
190
191
  program
191
192
  .command('publish')
192
- .description('Put the board online at arbiter.design and print the link. --to <url> for your own hosted Arbiter; --to pages for GitHub Pages (git destination, export, commit, push). Nothing to set up first.nts.')
193
+ .description('Put the board online at arbiter.design and print the link. --to <url> for your own hosted Arbiter; --to pages for GitHub Pages (git destination, export, commit, push). Nothing to set up first.')
193
194
  .option('--to <url|pages>', 'where to publish: a hosted Arbiter (default arbiter.design), or `pages` for GitHub Pages')
194
195
  .option('--admin-token <token>', 'only for a self-hosted Arbiter that gates board creation')
195
196
  .option('--no-push', 'GitHub Pages mode: do everything except push')
197
+ .option('--on-push', 'also write a GitHub Actions workflow that republishes on every push, and set its secret')
196
198
  .action(async (opts) => {
197
- const r = await (0, publish_1.publish)({ noPush: opts.push === false, to: opts.to, admin: opts.adminToken });
199
+ const r = await (0, publish_1.publish)({ noPush: opts.push === false, to: opts.to, admin: opts.adminToken, onPush: opts.onPush });
198
200
  const w = Math.max(...r.steps.map((s) => s.step.length));
199
201
  for (const s of r.steps)
200
202
  process.stdout.write(` ${s.step.padEnd(w)} ${s.outcome}${s.note ? ` — ${s.note}` : ''}\n`);
@@ -216,6 +218,28 @@ program
216
218
  .action(async (opts) => {
217
219
  await (0, review_1.review)(opts);
218
220
  });
221
+ program
222
+ .command('update')
223
+ .description('Bring this project up to the newest Arbiter: install it, refresh the skill file, re-pin the publish workflow. Settings and decisions untouched.')
224
+ .option('--check', 'report whether the skill file is behind the CLI; change nothing')
225
+ .option('--skip-install', 'refresh the skill from this copy without touching package.json')
226
+ .action(async (opts) => {
227
+ const r = await (0, update_1.update)(opts);
228
+ const ver = (v) => v ?? 'before 0.1.3';
229
+ if (opts.check) {
230
+ const s = r.before;
231
+ const line = s.file
232
+ ? `${s.file}: ${ver(s.skill)} · cli: ${s.cli} · ${s.stale ? 'behind — run: npx arbiter update' : 'current'}`
233
+ : 'no skill file — run: npx arbiter init';
234
+ process.stdout.write(line + '\n');
235
+ process.exit(s.stale ? 1 : 0);
236
+ }
237
+ const w = Math.max(...r.steps.map((s) => s.step.length));
238
+ for (const s of r.steps)
239
+ process.stdout.write(` ${s.step.padEnd(w)} ${s.outcome}${s.note ? ` — ${s.note}` : ''}\n`);
240
+ process.stdout.write(`\n${r.after.file ?? 'skill'}: ${ver(r.before.skill)} → ${ver(r.after.skill)}${r.ok ? '. Start a new agent session to pick it up.' : ''}\n`);
241
+ process.exit(r.ok ? 0 : 1);
242
+ });
219
243
  program
220
244
  .command('rules [id]')
221
245
  .description('Read decisions. No args: active rules. An id (D-0003): that one in full.')
package/dist/sweep.js CHANGED
@@ -66,7 +66,7 @@ function targetFiles(root, rule) {
66
66
  const abs = node_path_1.default.resolve(root, p);
67
67
  if (!abs.startsWith(node_path_1.default.resolve(root)) || !node_fs_1.default.existsSync(abs))
68
68
  return [];
69
- return node_fs_1.default.statSync(abs).isFile() ? [node_path_1.default.relative(root, abs)] : walk(abs, root);
69
+ return node_fs_1.default.statSync(abs).isFile() ? [rel(root, abs)] : walk(abs, root);
70
70
  };
71
71
  if (rule.paths.length)
72
72
  return { files: [...new Set(rule.paths.flatMap(expand))], scanned: 'rule.paths' };
@@ -75,6 +75,13 @@ function targetFiles(root, rule) {
75
75
  return { files: expand(scope.target), scanned: 'scope' };
76
76
  return { files: walk(root, root), scanned: 'project' };
77
77
  }
78
+ /**
79
+ * A path relative to the root, always with `/`. Windows' path.relative gives `docs\ref.html`,
80
+ * but excludes and rule.paths are written as globs with `/` — unnormalised, every exclude
81
+ * silently matched nothing there. It's also what gets recorded and published, so one project's
82
+ * violations shouldn't read differently depending on who swept.
83
+ */
84
+ const rel = (root, abs) => node_path_1.default.relative(root, abs).split(node_path_1.default.sep).join('/');
78
85
  function walk(dir, root, out = []) {
79
86
  if (out.length >= MAX_FILES)
80
87
  return out;
@@ -93,7 +100,7 @@ function walk(dir, root, out = []) {
93
100
  walk(node_path_1.default.join(dir, e.name), root, out);
94
101
  }
95
102
  else if (e.isFile() && SOURCE_EXT.has(node_path_1.default.extname(e.name))) {
96
- out.push(node_path_1.default.relative(root, node_path_1.default.join(dir, e.name)));
103
+ out.push(rel(root, node_path_1.default.join(dir, e.name)));
97
104
  }
98
105
  }
99
106
  return out;
package/package.json CHANGED
@@ -1,44 +1,45 @@
1
- {
2
- "name": "arbiterdesign",
3
- "version": "0.1.2",
4
- "description": "Records design decisions made during agent-assisted UI work and feeds them back into the agent's context.",
5
- "homepage": "https://arbiter.design",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/eddie199/arbiter.git"
9
- },
10
- "bugs": {
11
- "url": "https://github.com/eddie199/arbiter/issues"
12
- },
13
- "keywords": [
14
- "design",
15
- "decisions",
16
- "claude-code",
17
- "cursor",
18
- "agents",
19
- "ui"
20
- ],
21
- "license": "MIT",
22
- "bin": {
23
- "arbiter": "dist/index.js"
24
- },
25
- "files": [
26
- "dist",
27
- "templates"
28
- ],
29
- "scripts": {
30
- "build": "tsc -p tsconfig.json",
31
- "prepare": "npm run build",
32
- "test": "node --test \"dist/test/**/*.test.js\""
33
- },
34
- "engines": {
35
- "node": ">=20"
36
- },
37
- "dependencies": {
38
- "commander": "^12.1.0"
39
- },
40
- "devDependencies": {
41
- "@types/node": "^20.14.0",
42
- "typescript": "^5.5.0"
43
- }
44
- }
1
+ {
2
+ "name": "arbiterdesign",
3
+ "version": "0.1.3",
4
+ "description": "Records design decisions made during agent-assisted UI work and feeds them back into the agent's context.",
5
+ "homepage": "https://arbiter.design",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/eddie199/arbiter.git"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/eddie199/arbiter/issues"
12
+ },
13
+ "keywords": [
14
+ "design",
15
+ "decisions",
16
+ "claude-code",
17
+ "cursor",
18
+ "agents",
19
+ "ui"
20
+ ],
21
+ "license": "MIT",
22
+ "bin": {
23
+ "arbiter": "dist/index.js"
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "!dist/test",
28
+ "templates"
29
+ ],
30
+ "scripts": {
31
+ "build": "tsc -p tsconfig.json",
32
+ "prepare": "npm run build",
33
+ "test": "node --test \"dist/test/**/*.test.js\""
34
+ },
35
+ "engines": {
36
+ "node": ">=20"
37
+ },
38
+ "dependencies": {
39
+ "commander": "^12.1.0"
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "^20.14.0",
43
+ "typescript": "^5.5.0"
44
+ }
45
+ }