arbiterdesign 0.1.8 → 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.
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ /**
3
+ * Settings, as the local board's Preferences page shows and saves them. They live in arbiter.json, beside
4
+ * the check-in answer, so everyone on the project shares them and the CLI reads them where it acts:
5
+ * `record --pending` keeps out what they say isn't recorded, pictures stop being asked for, and
6
+ * `areas` says when folder suggestions are off.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.MAX_CAP = void 0;
10
+ exports.settingsOf = settingsOf;
11
+ exports.saveSettings = saveSettings;
12
+ const store_1 = require("./store");
13
+ const setup_1 = require("./commands/setup");
14
+ /** The most rules DECISIONS.md can be set to hold: more is more for the agent to read before every change. */
15
+ exports.MAX_CAP = 100;
16
+ function settingsOf(paths, config = (0, store_1.readConfig)(paths)) {
17
+ return {
18
+ checkin: config?.checkin ?? 'feature',
19
+ record: config?.record?.level ?? 'pattern',
20
+ agentCalls: config?.record?.agent ?? true,
21
+ pictures: config?.pictures ?? true,
22
+ app: config?.app?.url ?? null,
23
+ suggestFolders: config?.suggestFolders ?? true,
24
+ cap: config?.activeCap ?? store_1.ACTIVE_CAP,
25
+ rules: (0, store_1.readActive)(paths).length,
26
+ };
27
+ }
28
+ const KEYS = ['checkin', 'record', 'agentCalls', 'pictures', 'app', 'suggestFolders', 'cap'];
29
+ /**
30
+ * One or more settings from the page, checked, then written to arbiter.json. A new cap also rewrites
31
+ * DECISIONS.md's header, which says how many it holds. Choosing a check-in here answers the question
32
+ * install asks, so the project counts as onboarded, as `setup --checkin` does.
33
+ */
34
+ function saveSettings(paths, raw) {
35
+ const config = (0, store_1.readConfig)(paths);
36
+ if (!config)
37
+ return { ok: false, errors: ['no arbiter.json here — run `npx arbiter init` first'] };
38
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
39
+ return { ok: false, errors: ['expected an object of settings'] };
40
+ const body = raw;
41
+ const errors = [];
42
+ const unknown = Object.keys(body).filter((k) => !KEYS.includes(k));
43
+ if (unknown.length)
44
+ errors.push(`not a setting: ${unknown.join(', ')}`);
45
+ const next = { ...config };
46
+ if ('checkin' in body) {
47
+ if (!setup_1.CHECKINS.includes(body.checkin))
48
+ errors.push(`checkin must be one of ${setup_1.CHECKINS.join(' | ')}`);
49
+ else {
50
+ next.checkin = body.checkin;
51
+ next.onboarded = config.onboarded ?? (0, store_1.now)();
52
+ }
53
+ }
54
+ if ('record' in body) {
55
+ if (body.record !== 'pattern' && body.record !== 'feature')
56
+ errors.push('record must be pattern (features and patterns) or feature (features only)');
57
+ else
58
+ next.record = { ...next.record, level: body.record };
59
+ }
60
+ if ('agentCalls' in body) {
61
+ if (typeof body.agentCalls !== 'boolean')
62
+ errors.push('agentCalls must be true or false');
63
+ else
64
+ next.record = { ...next.record, agent: body.agentCalls };
65
+ }
66
+ for (const k of ['pictures', 'suggestFolders']) {
67
+ if (!(k in body))
68
+ continue;
69
+ if (typeof body[k] !== 'boolean')
70
+ errors.push(`${k} must be true or false`);
71
+ else
72
+ next[k] = body[k];
73
+ }
74
+ let cap = null;
75
+ if ('cap' in body) {
76
+ const have = (0, store_1.readActive)(paths).length;
77
+ const n = body.cap;
78
+ if (typeof n !== 'number' || !Number.isInteger(n) || n < 1 || n > exports.MAX_CAP)
79
+ errors.push(`Design rules must be a whole number from 1 to ${exports.MAX_CAP}`);
80
+ else if (n < have)
81
+ errors.push(`DECISIONS.md has ${have} rules, so it can't hold fewer. Remove some first.`);
82
+ else
83
+ cap = next.activeCap = n;
84
+ }
85
+ if ('app' in body) {
86
+ const text = typeof body.app === 'string' ? body.app.trim() : null;
87
+ if (text === null)
88
+ errors.push('app must be an address, or empty');
89
+ else if (!text)
90
+ delete next.app;
91
+ else {
92
+ const url = (0, setup_1.appUrl)(text);
93
+ if (url === 'credentials')
94
+ errors.push('Leave the username and password out: arbiter.json is committed');
95
+ else if (!url)
96
+ errors.push('Give the address the app runs at, like http://localhost:3000');
97
+ else
98
+ next.app = { url };
99
+ }
100
+ }
101
+ if (errors.length)
102
+ return { ok: false, errors };
103
+ (0, store_1.writeConfig)(paths, next);
104
+ if (cap !== null)
105
+ (0, store_1.writeActive)(paths, (0, store_1.readActive)(paths), cap);
106
+ return { ok: true, settings: settingsOf(paths, next) };
107
+ }
package/dist/store.js CHANGED
@@ -30,6 +30,7 @@ const node_os_1 = __importDefault(require("node:os"));
30
30
  const node_path_1 = __importDefault(require("node:path"));
31
31
  const node_child_process_1 = require("node:child_process");
32
32
  const format_1 = require("./format");
33
+ const lock_1 = require("./lock");
33
34
  exports.ACTIVE_CAP = 40;
34
35
  function resolvePaths(root = process.cwd()) {
35
36
  return {
@@ -59,7 +60,7 @@ function readConfig(paths) {
59
60
  return JSON.parse(node_fs_1.default.readFileSync(paths.config, 'utf8'));
60
61
  }
61
62
  function writeConfig(paths, config) {
62
- node_fs_1.default.writeFileSync(paths.config, JSON.stringify(config, null, 2) + '\n');
63
+ (0, lock_1.writeAtomic)(paths.config, JSON.stringify(config, null, 2) + '\n');
63
64
  }
64
65
  function readActive(paths) {
65
66
  if (!node_fs_1.default.existsSync(paths.decisions))
@@ -68,7 +69,7 @@ function readActive(paths) {
68
69
  }
69
70
  /** Rewrites DECISIONS.md in full. Entries are re-serialized, so hand edits survive. */
70
71
  function writeActive(paths, decisions, cap = exports.ACTIVE_CAP) {
71
- node_fs_1.default.writeFileSync(paths.decisions, (0, format_1.activeHeader)(decisions.length, cap) + '\n' + (0, format_1.formatGrouped)(decisions));
72
+ (0, lock_1.writeAtomic)(paths.decisions, (0, format_1.activeHeader)(decisions.length, cap) + '\n' + (0, format_1.formatGrouped)(decisions));
72
73
  }
73
74
  function readArchive(paths) {
74
75
  if (!node_fs_1.default.existsSync(paths.archive))
@@ -89,7 +90,7 @@ function appendArchive(paths, d) {
89
90
  */
90
91
  function writeArchive(paths, decisions) {
91
92
  node_fs_1.default.mkdirSync(paths.archiveDir, { recursive: true });
92
- node_fs_1.default.writeFileSync(paths.archive, (0, format_1.archiveHeader)() + '\n' + decisions.map(format_1.formatEntry).join('\n'));
93
+ (0, lock_1.writeAtomic)(paths.archive, (0, format_1.archiveHeader)() + '\n' + decisions.map(format_1.formatEntry).join('\n'));
93
94
  }
94
95
  function readPending(paths) {
95
96
  if (!node_fs_1.default.existsSync(paths.pending))
@@ -99,7 +100,7 @@ function readPending(paths) {
99
100
  /** Rewrites pending.md in full. */
100
101
  function writePending(paths, decisions) {
101
102
  node_fs_1.default.mkdirSync(paths.archiveDir, { recursive: true });
102
- node_fs_1.default.writeFileSync(paths.pending, (0, format_1.pendingHeader)() + '\n' + decisions.map(format_1.formatEntry).join('\n'));
103
+ (0, lock_1.writeAtomic)(paths.pending, (0, format_1.pendingHeader)() + '\n' + decisions.map(format_1.formatEntry).join('\n'));
103
104
  }
104
105
  /** Next P- id. Pending ids are never reused within the file but may repeat once it empties. */
105
106
  function nextPendingId(pending) {
package/dist/verify.js CHANGED
@@ -49,8 +49,10 @@ function verify(root, files, expect) {
49
49
  for (const needle of expect?.absent ?? []) {
50
50
  for (const [f, text] of contents) {
51
51
  const line = lineOf(text, needle);
52
- if (line !== null)
53
- checks.push({ kind: 'absent', file: f, needle, ok: false, detail: `found at line ${line}` });
52
+ if (line === null)
53
+ continue;
54
+ const found = needle.startsWith('regex:') ? new RegExp(needle.slice(6)).exec(text)?.[0] : undefined;
55
+ checks.push({ kind: 'absent', file: f, needle, ok: false, detail: `found at line ${line}`, ...(found !== undefined && { found }) });
54
56
  }
55
57
  if (!checks.some((c) => c.kind === 'absent' && c.needle === needle && !c.ok)) {
56
58
  checks.push({ kind: 'absent', file: files.join(', '), needle, ok: true });
package/dist/work.js CHANGED
@@ -8,12 +8,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
8
8
  return (mod && mod.__esModule) ? mod : { "default": mod };
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.workDir = exports.workId = void 0;
11
+ exports.KEEP_VERSIONS = exports.workDir = exports.workId = void 0;
12
12
  exports.readRenames = readRenames;
13
13
  exports.addRename = addRename;
14
14
  exports.workSnapshot = workSnapshot;
15
15
  exports.copyImage = copyImage;
16
16
  exports.captureImage = captureImage;
17
+ exports.keepEarlier = keepEarlier;
18
+ exports.restoreEarlier = restoreEarlier;
19
+ exports.moveHistory = moveHistory;
20
+ exports.workVersions = workVersions;
21
+ exports.historyFile = historyFile;
22
+ exports.mergePictures = mergePictures;
17
23
  const node_fs_1 = __importDefault(require("node:fs"));
18
24
  const node_path_1 = __importDefault(require("node:path"));
19
25
  const node_child_process_1 = require("node:child_process");
@@ -91,3 +97,106 @@ function captureImage(dir, id) {
91
97
  return { ok: false, error: 'capture cancelled — no snapshot saved' };
92
98
  return { ok: true, file: `${id}.png` };
93
99
  }
100
+ /**
101
+ * Earlier pictures of a piece of work, so the board can show how it got where it is. A new picture
102
+ * doesn't overwrite the last: the last moves to `.arbiter/work/history/<id>/<when it was taken>.<ext>`,
103
+ * and the newest stays where it always was, `<id>.<ext>`, so everything that reads the current picture
104
+ * still finds it. The ten most recent earlier pictures are kept.
105
+ */
106
+ exports.KEEP_VERSIONS = 10;
107
+ const HISTORY = 'history';
108
+ const STAMP = /^(\d{4}-\d{2}-\d{2})T(\d{2})-(\d{2})-(\d{2})(?:-(\d{3}))?Z$/;
109
+ const stampOf = (d) => d.toISOString().replace(/:/g, '-').replace('.', '-');
110
+ const dateOfStamp = (s) => {
111
+ const m = STAMP.exec(s);
112
+ return m ? `${m[1]}T${m[2]}:${m[3]}:${m[4]}.${m[5] ?? '000'}Z` : null;
113
+ };
114
+ /** The current picture moves into the history, dated when it was taken. Returns where it went, to put it back if the new one fails. */
115
+ function keepEarlier(paths, id) {
116
+ const cur = workSnapshot(paths, id);
117
+ if (!cur)
118
+ return null;
119
+ const dir = node_path_1.default.join((0, exports.workDir)(paths), HISTORY, id);
120
+ node_fs_1.default.mkdirSync(dir, { recursive: true });
121
+ const to = node_path_1.default.join(dir, stampOf(node_fs_1.default.statSync(cur).mtime) + node_path_1.default.extname(cur).toLowerCase());
122
+ node_fs_1.default.renameSync(cur, to);
123
+ // Only the most recent earlier pictures stay.
124
+ const all = node_fs_1.default.readdirSync(dir).filter((f) => dateOfStamp(node_path_1.default.parse(f).name)).sort();
125
+ for (const f of all.slice(0, Math.max(0, all.length - exports.KEEP_VERSIONS)))
126
+ node_fs_1.default.rmSync(node_path_1.default.join(dir, f), { force: true });
127
+ return { from: cur, to };
128
+ }
129
+ /** A new picture didn't come: the one moved into the history goes back. */
130
+ function restoreEarlier(moved) {
131
+ if (moved && node_fs_1.default.existsSync(moved.to) && !node_fs_1.default.existsSync(moved.from))
132
+ node_fs_1.default.renameSync(moved.to, moved.from);
133
+ }
134
+ /** A renamed piece of work takes its earlier pictures with it. */
135
+ function moveHistory(paths, from, to) {
136
+ const src = node_path_1.default.join((0, exports.workDir)(paths), HISTORY, from);
137
+ if (!node_fs_1.default.existsSync(src))
138
+ return false;
139
+ const dst = node_path_1.default.join((0, exports.workDir)(paths), HISTORY, to);
140
+ node_fs_1.default.rmSync(dst, { recursive: true, force: true });
141
+ node_fs_1.default.mkdirSync(node_path_1.default.dirname(dst), { recursive: true });
142
+ node_fs_1.default.renameSync(src, dst);
143
+ return true;
144
+ }
145
+ /**
146
+ * Every picture of a piece of work, oldest first, the current one last: `file` relative to
147
+ * `.arbiter/work/`, and when it was taken. Empty when there's no picture.
148
+ */
149
+ function workVersions(paths, id) {
150
+ const out = [];
151
+ const dir = node_path_1.default.join((0, exports.workDir)(paths), HISTORY, id);
152
+ if (node_fs_1.default.existsSync(dir)) {
153
+ for (const f of node_fs_1.default.readdirSync(dir).sort()) {
154
+ const date = dateOfStamp(node_path_1.default.parse(f).name);
155
+ if (date && IMAGE_EXT.includes(node_path_1.default.extname(f).toLowerCase()))
156
+ out.push({ file: `${HISTORY}/${id}/${f}`, date });
157
+ }
158
+ }
159
+ const cur = workSnapshot(paths, id);
160
+ if (cur)
161
+ out.push({ file: node_path_1.default.basename(cur), date: node_fs_1.default.statSync(cur).mtime.toISOString() });
162
+ return out;
163
+ }
164
+ /** An earlier picture's path under `.arbiter/work/`, as a URL names it: `history/W-…/2026-11-09T17-39-00-000Z.png`. Null for anything else. */
165
+ function historyFile(paths, rel) {
166
+ const m = /^history\/(W-[a-z0-9-]{1,48})\/([0-9T-]+Z)\.(png|jpe?g|webp|gif|svg)$/.exec(rel);
167
+ if (!m || !dateOfStamp(m[2]))
168
+ return null;
169
+ const abs = node_path_1.default.join((0, exports.workDir)(paths), HISTORY, m[1], `${m[2]}.${m[3]}`);
170
+ return node_fs_1.default.existsSync(abs) ? abs : null;
171
+ }
172
+ /**
173
+ * A piece of work merged into another: every picture of both, by when each was taken, becomes the
174
+ * other's. The newest is its picture; the rest are its earlier pictures, the most recent ten kept.
175
+ * False when the merged one had no pictures.
176
+ */
177
+ function mergePictures(paths, from, to) {
178
+ const mine = workVersions(paths, from);
179
+ if (!mine.length)
180
+ return false;
181
+ const all = [...mine, ...workVersions(paths, to)].map((v) => ({ abs: node_path_1.default.join((0, exports.workDir)(paths), v.file), date: v.date }));
182
+ const dir = node_path_1.default.join((0, exports.workDir)(paths), HISTORY, to);
183
+ node_fs_1.default.mkdirSync(dir, { recursive: true });
184
+ // Everything into the history first, named by when it was taken; then the newest comes back out.
185
+ const staged = all.map((v) => {
186
+ let dest = node_path_1.default.join(dir, stampOf(new Date(v.date)) + node_path_1.default.extname(v.abs).toLowerCase());
187
+ if (dest !== v.abs && node_fs_1.default.existsSync(dest))
188
+ dest = node_path_1.default.join(dir, stampOf(new Date(Date.parse(v.date) + 1)) + node_path_1.default.extname(v.abs).toLowerCase());
189
+ if (dest !== v.abs)
190
+ node_fs_1.default.renameSync(v.abs, dest);
191
+ return { abs: dest, date: v.date };
192
+ }).sort((a, b) => Date.parse(a.date) - Date.parse(b.date));
193
+ const newest = staged[staged.length - 1];
194
+ const cur = node_path_1.default.join((0, exports.workDir)(paths), to + node_path_1.default.extname(newest.abs));
195
+ node_fs_1.default.renameSync(newest.abs, cur);
196
+ node_fs_1.default.utimesSync(cur, new Date(newest.date), new Date(newest.date));
197
+ const left = node_fs_1.default.readdirSync(dir).filter((f) => dateOfStamp(node_path_1.default.parse(f).name)).sort();
198
+ for (const f of left.slice(0, Math.max(0, left.length - exports.KEEP_VERSIONS)))
199
+ node_fs_1.default.rmSync(node_path_1.default.join(dir, f), { force: true });
200
+ node_fs_1.default.rmSync(node_path_1.default.join((0, exports.workDir)(paths), HISTORY, from), { recursive: true, force: true });
201
+ return true;
202
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arbiterdesign",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Records design decisions made during agent-assisted UI work and feeds them back into the agent's context.",
5
5
  "homepage": "https://arbiter.design",
6
6
  "repository": {
@@ -28,7 +28,8 @@
28
28
  "templates"
29
29
  ],
30
30
  "scripts": {
31
- "build": "tsc -p tsconfig.json",
31
+ "build": "tsc -p tsconfig.json && node board/build.mjs",
32
+ "board:install": "npm install --prefix board",
32
33
  "prepare": "npm run build",
33
34
  "test": "node --test \"dist/test/**/*.test.js\""
34
35
  },