@nodii/dev 0.6.78 → 0.6.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -34,6 +34,8 @@ import { governorCommand, laneClose } from "./governor.js";
34
34
  import { freezeCommand } from "./freeze.js";
35
35
  import {
36
36
  figmaChangeSetShow,
37
+ figmaChangeSetList,
38
+ figmaChangeSetListText,
37
39
  figmaChangeSetText,
38
40
  figmaFileKey,
39
41
  figmaFilePublished,
@@ -96,6 +98,7 @@ import {
96
98
  deltaGatherFlags,
97
99
  laneCommand,
98
100
  laneCapCommand,
101
+ laneRepoCommand,
99
102
  machineCommand,
100
103
  nextCommand,
101
104
  peopleCommand,
@@ -203,6 +206,9 @@ Usage: nodii-dev <command> [options] [--json]
203
206
  # holder re-submits every rejected item: applying -> in_review, round + 1;
204
207
  # each item needs context, each variant name and context; writeUp optional
205
208
  figma changeset show CHANGE_SET # write-up, items, context, variants, round, decision and comment (with the previous round's)
209
+ figma changeset list [--file KEY] [--actionable] [--all]
210
+ # change sets in dependency order (hub-260): each file's sets are actioned
211
+ # in order; NEXT marks the ones an operator can act on now
206
212
  figma file add FILE_KEY --name TEXT --kind design-system|surfaces|prototype [--module M]
207
213
  # register a Figma file in Dev so it can be locked
208
214
  hook claude-figma-pre|claude-figma-post|safety-pre|safety-post|nudge-pre|nudge-stop|surface-gen-pre|session-start|session-kind|managed-dispatch|claude-managed-dispatch|print-settings
@@ -371,6 +377,11 @@ Usage: nodii-dev <command> [options] [--json]
371
377
  # Stopped label, the lane's test stacks go down and the worktree is removed
372
378
  # (only after the push, clean, and with no process in it). Recorded on the issue
373
379
  lane closeout <key> --reason TEXT # re-run that machine half for an ended lane (a worktree kept earlier)
380
+ lane repo add <key> --repo NAME --branch BRANCH --worktree PATH [--read-only] --reason TEXT
381
+ # coordinator or staff: add a repository to a running lane (or change its
382
+ # branch, worktree or read-only mark). Dev changes the lane's repositories
383
+ # and its Freeze boundaries together; this also repairs a lane where they
384
+ # diverged (GATHER_SHORTLIST_MISMATCH). REPO_NOT_GRANTED without a grant
374
385
  lane close <key> [--delivered-by <PR URL|lane key|issue key>] --reason TEXT [--sweeper LANE] [--no-closeout]
375
386
  # hub-232. The machine's coordinator closes a lane that marked itself
376
387
  # finished with a reason and evidence (MW1-28.2); LANE_NOT_FINISHED
@@ -888,6 +899,7 @@ export async function main(argv = process.argv.slice(2)) {
888
899
  if (command === "coordinator") return emitCommand(await coordinatorCommand(action, f, { installWatchdog }));
889
900
  if (command === "steward") return emitCommand(await stewardCommand(action, rest, f));
890
901
  if (command === "lane" && action === "launch") return emitCommand(await launchLaneCommand(rest[0], f));
902
+ if (command === "lane" && action === "repo") return emitCommand(await laneRepoCommand(rest[0], rest.slice(1), f));
891
903
  if (command === "lane" && action === "cap") return emitCommand(await laneCapCommand(rest, f));
892
904
  if (command === "lane" && action === "close") {
893
905
  const result = await laneClose(rest[0], f);
@@ -1315,7 +1327,11 @@ export async function main(argv = process.argv.slice(2)) {
1315
1327
  return emit(await figmaResubmit(rest[0], rest[1], { sync: submitMode(f) }), json, (p) =>
1316
1328
  [`Re-submitted ${rest[0]}; it is ${p.data.state}.`, figmaChangeSetText(p.data), ...conformanceLines({ warnings: p.warnings })].join("\n"));
1317
1329
  if (action === "changeset") {
1318
- if (rest[0] !== "show" || !rest[1] || rest.length > 2) throw new CliError("USAGE", "figma changeset show CHANGE_SET", 2);
1330
+ if (rest[0] === "list") {
1331
+ if (rest.length > 1) throw new CliError("USAGE", "figma changeset list [--file KEY] [--actionable] [--all]", 2);
1332
+ return emit(await figmaChangeSetList(f), json, (p) => figmaChangeSetListText(p.data, p.total));
1333
+ }
1334
+ if (rest[0] !== "show" || !rest[1] || rest.length > 2) throw new CliError("USAGE", "figma changeset show CHANGE_SET | figma changeset list [--file KEY] [--actionable] [--all]", 2);
1319
1335
  return emit(await figmaChangeSetShow(rest[1]), json, (p) => figmaChangeSetText(p.data));
1320
1336
  }
1321
1337
  if (action === "release")
package/dist/closeout.js CHANGED
@@ -125,7 +125,13 @@ export async function closeoutRepository(lane, repository, { reason, issueKeys =
125
125
  const gh = (...args) => exec("gh", args, { cwd: worktree });
126
126
  const base = repository.baseRef ?? "origin/main";
127
127
  let pushedOk = false;
128
- try {
128
+ // A read-only repository (hub-257) holds no work of the lane's:
129
+ // nothing to push and no PR to record.
130
+ if (repository.readOnly) {
131
+ out.pushed = { ahead: 0, head: null, needed: false };
132
+ out.notes.push("read-only for this lane: not pushed, no PR");
133
+ pushedOk = true;
134
+ } else try {
129
135
  try { await git("fetch", "--quiet", "origin"); } catch { out.notes.push("git fetch failed; compared against the last fetched base"); }
130
136
  const head = (await git("rev-parse", "HEAD")).trim();
131
137
  const ahead = Number((await git("rev-list", "--count", `${base}..HEAD`)).trim());
@@ -145,7 +151,7 @@ export async function closeoutRepository(lane, repository, { reason, issueKeys =
145
151
  out.notes.push(`push failed: ${String(error?.stderr || error?.message || error).trim().slice(0, 300)}`);
146
152
  }
147
153
  // An open PR is closed as Stopped even when nothing new needed a push.
148
- if (pushedOk) {
154
+ if (pushedOk && !repository.readOnly) {
149
155
  try {
150
156
  if (out.pushed.needed) out.pr = await closeStoppedPr({ lane, repository, reason, issueKeys, gh });
151
157
  else {
package/dist/core.js CHANGED
@@ -4,7 +4,7 @@ import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
4
4
  import { homedir, platform } from "node:os";
5
5
  import { dirname, join } from "node:path";
6
6
 
7
- export const VERSION = "0.6.78";
7
+ export const VERSION = "0.6.80";
8
8
  export const configPath = () =>
9
9
  process.env.NODII_DEV_CONFIG_PATH ??
10
10
  join(homedir(), ".config/nodii-dev/config.json");
@@ -135,7 +135,7 @@ const withSignal = (promise, signal) => {
135
135
  });
136
136
  };
137
137
 
138
- async function devFetch(method, path, bodyText, contentType, accept, extra = {}, signal) {
138
+ async function devFetchOnce(method, path, bodyText, contentType, accept, extra = {}, signal) {
139
139
  const wait = async (promise) => {
140
140
  try {
141
141
  return await withSignal(promise, signal);
@@ -175,6 +175,118 @@ async function devFetch(method, path, bodyText, contentType, accept, extra = {},
175
175
  }
176
176
  }
177
177
 
178
+ // hub-254: an operator-only route refuses the CLI's sign-in (an
179
+ // OAuth agent) with 403 OPERATOR_REQUIRED. When a person is at the terminal,
180
+ // the CLI asks for their TOTP code, Dev verifies it against the signed-in
181
+ // person, and the call is sent again with the ten-minute grant Dev returns.
182
+ // The code is never stored, logged or passed on; the grant lives only in this
183
+ // process's memory. Without a TTY (an agent) the refusal is surfaced as it is.
184
+ export const OPERATOR_STEP_UP_PATH = "/api/v1/operator/step-up";
185
+ export const OPERATOR_STEP_UP_HEADER = "x-operator-step-up";
186
+ let stepUpGrant = null; // { grant, expiresAt } for this process only
187
+ let pendingStepUp = null; // the step-up in flight, shared by concurrent refusals
188
+ let totpPrompt = defaultTotpPrompt;
189
+
190
+ /** Tests replace the TTY prompt; `null` restores the default. Also forgets the grant. */
191
+ export function setTotpPrompt(fn) {
192
+ totpPrompt = fn ?? defaultTotpPrompt;
193
+ stepUpGrant = null;
194
+ pendingStepUp = null;
195
+ }
196
+
197
+ /** Reads one code from the terminal without echoing it, or null when there is no TTY. */
198
+ async function defaultTotpPrompt() {
199
+ if (!process.stdin.isTTY || !process.stderr.isTTY) return null;
200
+ const { createInterface } = await import("node:readline");
201
+ const { Writable } = await import("node:stream");
202
+ let muted = false;
203
+ const output = new Writable({
204
+ write(chunk, encoding, done) {
205
+ if (!muted) process.stderr.write(chunk, encoding);
206
+ done();
207
+ },
208
+ });
209
+ const rl = createInterface({ input: process.stdin, output, terminal: true });
210
+ try {
211
+ return await new Promise((resolvePromise, rejectPromise) => {
212
+ rl.once("close", () => resolvePromise(null));
213
+ // In raw mode Ctrl-C reaches readline, not the process: without this the
214
+ // prompt would pause and never settle.
215
+ rl.once("SIGINT", () => {
216
+ rejectPromise(new CliError("OPERATOR_STEP_UP_CANCELLED", "Cancelled at the TOTP prompt.", 130));
217
+ rl.close();
218
+ });
219
+ rl.question("Enter your TOTP code: ", (answer) => resolvePromise(answer.trim()));
220
+ muted = true;
221
+ });
222
+ } finally {
223
+ rl.close();
224
+ process.stderr.write("\n");
225
+ }
226
+ }
227
+
228
+ const refusalCode = (raw) => {
229
+ try {
230
+ return JSON.parse(raw)?.code ?? null;
231
+ } catch {
232
+ return null;
233
+ }
234
+ };
235
+
236
+ const liveGrant = () => (stepUpGrant && Date.parse(stepUpGrant.expiresAt) - Date.now() > 5_000 ? stepUpGrant.grant : null);
237
+
238
+ /** Ask for the code once and trade it for a grant; null when there is no TTY and the refusal stands. */
239
+ async function stepUpOnce(refusal, signal) {
240
+ const typed = await totpPrompt();
241
+ if (typed === null || typed === undefined) {
242
+ if (refusal !== "OPERATOR_REQUIRED") return null;
243
+ throw new CliError(
244
+ "OPERATOR_REQUIRED",
245
+ "This is operator-only. Run it yourself in a terminal: the CLI then asks for your TOTP code. An agent cannot answer it.",
246
+ 1,
247
+ );
248
+ }
249
+ if (!/^[0-9]{6}$/.test(typed)) throw new CliError("OPERATOR_STEP_UP_CODE_REJECTED", "A TOTP code is six digits.", 1);
250
+ const stepUp = await devFetchOnce("POST", OPERATOR_STEP_UP_PATH, JSON.stringify({ code: typed }), "application/json", "application/json", {}, signal);
251
+ let payload = {};
252
+ try {
253
+ payload = JSON.parse(stepUp.raw);
254
+ } catch {}
255
+ if (!stepUp.response.ok)
256
+ throw new CliError(payload.code ?? `HTTP_${stepUp.response.status}`, payload.message ?? `Dev returned HTTP ${stepUp.response.status}`, 1, payload.details);
257
+ const grant = payload?.data?.grant;
258
+ const expiresAt = payload?.data?.expiresAt;
259
+ if (typeof grant !== "string" || typeof expiresAt !== "string" || !Number.isFinite(Date.parse(expiresAt)))
260
+ throw new CliError("OPERATOR_STEP_UP_UNAVAILABLE", "Dev's step-up answer carried no usable grant.", 1);
261
+ stepUpGrant = { grant, expiresAt };
262
+ return grant;
263
+ }
264
+
265
+ async function devFetch(method, path, bodyText, contentType, accept, extra = {}, signal) {
266
+ const send = (grant) =>
267
+ devFetchOnce(method, path, bodyText, contentType, accept, grant ? { ...extra, [OPERATOR_STEP_UP_HEADER]: grant } : extra, signal);
268
+ if (path === OPERATOR_STEP_UP_PATH) return devFetchOnce(method, path, bodyText, contentType, accept, extra, signal);
269
+ const held = liveGrant();
270
+ const first = await send(held);
271
+ const code = refusalCode(first.raw);
272
+ const refused =
273
+ (first.response.status === 403 && code === "OPERATOR_REQUIRED") ||
274
+ (first.response.status === 401 && code === "OPERATOR_STEP_UP_INVALID");
275
+ if (!refused) return first;
276
+ // Drop only the grant this call was refused with; one obtained meanwhile by
277
+ // a concurrent call is used as it is, without a second prompt.
278
+ if (stepUpGrant?.grant === held) stepUpGrant = null;
279
+ const fresh = liveGrant();
280
+ if (fresh && fresh !== held) return send(fresh);
281
+ // Concurrent refusals share one prompt and one grant (one TTY, one code).
282
+ pendingStepUp ??= stepUpOnce(code, signal).finally(() => {
283
+ pendingStepUp = null;
284
+ });
285
+ const grant = await pendingStepUp;
286
+ if (grant === null) return first;
287
+ return send(grant);
288
+ }
289
+
178
290
  /** A JSON call that keeps the status: `{ status, payload }`. Errors throw as devRawRequest's do. */
179
291
  export async function devExchange(method, path, bodyText, { contentType = "application/json", headers = {}, signal } = {}) {
180
292
  const { response, raw } = await devFetch(method, path, bodyText, contentType, "application/json", headers, signal);
@@ -225,7 +337,7 @@ export async function checkLogin() {
225
337
  export const encode = (value) => encodeURIComponent(value);
226
338
  // Switches never take the next token as their value, so
227
339
  // `docs upload --wait rulebook/` keeps rulebook/ as a path.
228
- const SWITCHES = new Set(["confirm-raise", "json", "wait", "pending", "dry-run", "check", "all", "fleet", "help", "yes", "mine", "no-browser", "include-drafts", "drafted", "library", "async", "sync", "force", "system", "delta", "probe", "no-probe", "not-required", "override", "critical", "no-embed", "behind", "write", "fetch"]);
340
+ const SWITCHES = new Set(["confirm-raise", "actionable", "json", "wait", "pending", "dry-run", "check", "all", "fleet", "help", "yes", "mine", "no-browser", "include-drafts", "drafted", "library", "async", "sync", "force", "system", "delta", "probe", "no-probe", "not-required", "override", "critical", "no-embed", "behind", "write", "fetch"]);
229
341
  export function parseArgs(argv) {
230
342
  const flags = {};
231
343
  const args = [];
@@ -290,12 +290,74 @@ export const SWAP_BOUNDARIES = (key = "<key>") => `\`nodii-dev lane freeze swap
290
290
 
291
291
  const outside = (message, details) => new CliError("FIGMA_OUTSIDE_LANE_SCOPE", `${message} Change the scope only with ${SWAP_BOUNDARIES()}, or ask the coordinator to amend the lane.`, 2, details);
292
292
 
293
+ const setLookups = new Map();
294
+ export const clearComponentSetLookups = () => setLookups.clear();
295
+
296
+ /**
297
+ * A published component set as Figma lists it under its key: { key, fileKey,
298
+ * nodeId, name }, or null when Figma has no set with that key. One REST read
299
+ * per key per process, because the CLI cannot call the Figma MCP; it is only
300
+ * made for a key the DS catalog does not list as a Surface (a DS component
301
+ * set, NODII-DEV-CLI-70).
302
+ */
303
+ export function figmaComponentSet(key, { env = process.env, figmaGet } = {}) {
304
+ if (!setLookups.has(key)) {
305
+ const lookup = (async () => {
306
+ let get = figmaGet;
307
+ if (!get) {
308
+ const token = env.FIGMA_PAT || env.FIGMA_TOKEN;
309
+ if (!token)
310
+ throw new CliError("FIGMA_TOKEN_REQUIRED", `Component set ${key} is not a Surface in the DS catalog, so nodii-dev reads which node it is from Figma: set FIGMA_PAT (or FIGMA_TOKEN) in this shell's environment.`, 2);
311
+ const { figmaClient } = await import("./design.js");
312
+ get = figmaClient(token, { attempts: 3, timeoutMs: 20_000 });
313
+ }
314
+ try {
315
+ const meta = (await get(`/component_sets/${encodeURIComponent(key)}`))?.meta;
316
+ return meta?.node_id && meta?.file_key ? { key, fileKey: meta.file_key, nodeId: meta.node_id, name: meta.name ?? null } : null;
317
+ } catch (error) {
318
+ if (error?.code === "FIGMA_NOT_FOUND") return null;
319
+ throw error;
320
+ }
321
+ })();
322
+ // A failed read is not remembered; the next caller asks again.
323
+ lookup.catch(() => setLookups.delete(key));
324
+ setLookups.set(key, lookup);
325
+ }
326
+ return setLookups.get(key);
327
+ }
328
+
329
+ /**
330
+ * What each published set key in a file names (MW8-20): a Surface's nodes and
331
+ * state frames from the DS catalog; else, through `lookupSet`, the set Figma
332
+ * publishes under that key (a DS component set, NODII-DEV-CLI-70), its own
333
+ * node as the one frame. `onlyIfNeeded(resolvedSoFar)` returning false skips
334
+ * the Figma reads. A key that names nothing in this file is refused.
335
+ */
336
+ export async function componentSetsIn(fileKey, keys, { surfaces = [], lookupSet = figmaComponentSet, onlyIfNeeded } = {}) {
337
+ const sets = new Map();
338
+ for (const key of keys) {
339
+ const surface = surfaces.find((item) => item.componentSetKey === key && item.fileKey === fileKey);
340
+ if (surface) sets.set(key, { key, fileKey, name: surface.name, nodeIds: surface.nodeIds, frames: surface.frames ?? surface.nodeIds.map((nodeId) => ({ nodeId, state: "default" })) });
341
+ }
342
+ const rest = keys.filter((key) => !sets.has(key));
343
+ if (!rest.length || (onlyIfNeeded && !onlyIfNeeded(sets))) return sets;
344
+ for (const key of rest) {
345
+ const set = await lookupSet(key);
346
+ if (!set)
347
+ throw new CliError("FIGMA_KEY_UNKNOWN", `${key} is neither a Surface in the DS catalog nor a component set Figma publishes.`, 1, { fileKey, key });
348
+ if (set.fileKey !== fileKey)
349
+ throw new CliError("FIGMA_KEY_UNKNOWN", `${key}${set.name ? ` (${set.name})` : ""} is in file ${set.fileKey}, not ${fileKey}.`, 1, { fileKey, key, setFileKey: set.fileKey });
350
+ sets.set(key, { key, fileKey, name: set.name, nodeIds: [set.nodeId], frames: [{ nodeId: set.nodeId, state: "default" }] });
351
+ }
352
+ return sets;
353
+ }
354
+
293
355
  /**
294
356
  * Refuse a Figma lock (lockScopes = the scopes asked for; [] = whole file) or a
295
357
  * write (lockScopes = null) outside the lane's scope. `scope` null = the lane
296
358
  * declared none, so nothing is bounded here.
297
359
  */
298
- export async function assertWithinLaneScope(scope, fileKey, lockScopes, { catalog = loadDsCatalog } = {}) {
360
+ export async function assertWithinLaneScope(scope, fileKey, lockScopes, { catalog = loadDsCatalog, lookupSet = figmaComponentSet } = {}) {
299
361
  if (scope === null) return { checked: false };
300
362
  const file = scope.find((item) => item.fileKey === fileKey);
301
363
  if (!file)
@@ -304,7 +366,14 @@ export async function assertWithinLaneScope(scope, fileKey, lockScopes, { catalo
304
366
  const wide = lockScopes.length ? lockScopes.filter((item) => item.kind !== "component") : [{ kind: "file" }];
305
367
  if (wide.length)
306
368
  throw outside(`This lane may lock only its component sets in ${fileKey}, not ${wide.map((item) => item.kind).join(", ")}.`, { fileKey, scope: file });
307
- const allowed = new Set((await catalog()).filter((surface) => file.componentSets.includes(surface.componentSetKey)).flatMap((surface) => surface.nodeIds));
369
+ // Surfaces first; Figma is read for a DS set's key only when a node is still unaccounted for.
370
+ const allowedBy = (sets) => new Set([...sets.values()].flatMap((set) => set.nodeIds));
371
+ const sets = await componentSetsIn(fileKey, file.componentSets, {
372
+ surfaces: await catalog(),
373
+ lookupSet,
374
+ onlyIfNeeded: (found) => lockScopes.some((item) => !allowedBy(found).has(item.nodeId)),
375
+ });
376
+ const allowed = allowedBy(sets);
308
377
  const stray = lockScopes.filter((item) => !allowed.has(item.nodeId));
309
378
  if (stray.length)
310
379
  throw outside(`${stray.map((item) => item.nodeId).join(", ")} in ${fileKey} is not one of this lane's component sets (${file.componentSets.join(", ")}).`, { fileKey, scope: file, nodeIds: stray.map((item) => item.nodeId) });
package/dist/figma.js CHANGED
@@ -346,6 +346,38 @@ const BEFORE_CONTEXT = "submitted before 31 Oct";
346
346
  const variantLine = (v) =>
347
347
  ` variant ${v.figmaNodeId} ${v.name ?? `(no name: ${BEFORE_CONTEXT})`} (${[v.beforeImageId && "before", v.afterImageId && "after"].filter(Boolean).join(", ") || "no images"})${v.context ? `: ${v.context}` : ""}`;
348
348
 
349
+ /**
350
+ * hub-260: change sets in dependency order. Each file's sets are actioned in
351
+ * their order (file_sequence); by default only the review queue (in review or
352
+ * applying), `--actionable` only the sets an operator can act on now, `--all`
353
+ * every state.
354
+ */
355
+ export async function figmaChangeSetList(flags = {}, { request = devRequest } = {}) {
356
+ const params = new URLSearchParams({ sort: "dependency", limit: String(flags.limit ?? 200) });
357
+ if (flags.file) params.set("fileKey", figmaFileKey(flags.file));
358
+ if (flags.actionable) params.set("actionable", "true");
359
+ if (!flags.all) for (const state of ["in_review", "applying"]) params.append("state", state);
360
+ return request("GET", `/api/v1/design/change-sets?${params}`);
361
+ }
362
+
363
+ /** One line per set: its place on its file, whether it can be acted on now, and what it waits behind. */
364
+ export function figmaChangeSetListText(rows = [], total = rows.length) {
365
+ if (!rows.length) return "No change sets.";
366
+ const lines = [];
367
+ let file = null;
368
+ for (const cs of rows) {
369
+ if (cs.fileKey !== file) {
370
+ file = cs.fileKey;
371
+ lines.push(`${cs.file?.name ?? cs.fileKey} (${cs.fileKey})`);
372
+ }
373
+ const place = cs.fileSequence ? `#${cs.fileSequence}` : "-";
374
+ const now = cs.actionable ? "NEXT" : cs.blockedBy ? `waits behind ${cs.blockedBy}` : "";
375
+ lines.push(` ${place}\t${cs.id}\t${cs.state}\t${cs.title}${now ? `\t${now}` : ""}`);
376
+ }
377
+ if (total > rows.length) lines.push(`(${rows.length} of ${total} shown; narrow with --file or --actionable, or pass --limit)`);
378
+ return lines.join("\n");
379
+ }
380
+
349
381
  /**
350
382
  * One change set as lines: its write-up, and its items' round, decision, comment,
351
383
  * the previous round's decision and comment, context and variants. An item with
package/dist/flags.js CHANGED
@@ -42,6 +42,7 @@ export const COMMAND_FLAGS = {
42
42
  "lane transfer": ["reason", "to-agent"],
43
43
  "lane stop": ["reason", "sweeper", "no-closeout"],
44
44
  "lane closeout": ["reason"],
45
+ "lane repo": ["repo", "branch", "worktree", "read-only", "reason"],
45
46
  // hub-232: the honest close-out and the governor.
46
47
  "lane close": ["delivered-by", "reason", "sweeper", "no-closeout"],
47
48
  "governor show": ["machine-id"],
@@ -63,6 +64,8 @@ export const COMMAND_FLAGS = {
63
64
  "figma resubmit": [...SUBMIT_MODE, "dry-run"],
64
65
  "figma withdraw": ["items", "reason"],
65
66
  "figma abandon": ["file"],
67
+ // hub-260: list takes these; show takes none.
68
+ "figma changeset": ["file", "actionable", "all", "limit"],
66
69
  "figma apply": ["file", "figma-version"],
67
70
  "figma lock": ["title", "scope"],
68
71
  "surface generate": ["write", "check", "fetch", "all", "module", "type", "figma-version", "report"],
package/dist/lanes.js CHANGED
@@ -574,12 +574,7 @@ export async function laneCommand(action, args, flags, deps = {}) {
574
574
  throw new CliError("GATHER_PATHS_UNAVAILABLE", "Gather could not read every recorded worktree. Repair the lane boundary or make its repositories available before continuing.", 1);
575
575
  const paths = flags.paths ? list(flags.paths) : [...new Set([...recordedPaths, ...driftPaths])];
576
576
  if (paths.length > 5000) throw new CliError("GATHER_SCOPE_TOO_LARGE", `Gather found ${paths.length} paths; Dev accepts at most 5,000. Narrow the lane's recorded scope before continuing.`, 1);
577
- const repoRefs = [
578
- ...(lane.repositories ?? []).map((repository) => repository.repo),
579
- ...(lane.freeze?.boundaries?.repos ?? []).map((repository) => repository.repo),
580
- ...(Array.isArray(lane.repos) ? lane.repos.map((repo) => typeof repo === "string" ? repo : repo.repo) : []),
581
- ];
582
- const repos = [...new Set(repoRefs.filter(Boolean).map(repoName))];
577
+ const repos = shortlistRepos(lane);
583
578
  // The Figma scope (published keys) pulls in the DS components its
584
579
  // Surfaces are built from, so their guidelines and U-docs apply.
585
580
  // null = no declared Figma scope (kept undeclared); [] = declared "no Figma".
@@ -1090,6 +1085,76 @@ export async function laneCommand(action, args, flags, deps = {}) {
1090
1085
  throw new CliError("USAGE", `Unknown lane action: ${action}`, 2);
1091
1086
  }
1092
1087
 
1088
+ /**
1089
+ * `nodii-dev lane repo add <key> --repo NAME --branch BRANCH --worktree PATH
1090
+ * [--read-only] --reason TEXT` (hub-257): the lane's machine
1091
+ * coordinator or staff adds a repository to a running lane. Dev changes the
1092
+ * lane's repositories and its Freeze boundaries together, so they cannot
1093
+ * diverge; it also repairs a lane where they already have.
1094
+ */
1095
+ export async function laneRepoCommand(sub, args, flags, { request = devRequest } = {}) {
1096
+ if (sub !== "add") throw new CliError("USAGE", "lane repo add <key> --repo NAME --branch BRANCH --worktree PATH [--read-only] --reason TEXT", 2);
1097
+ const key = args[0];
1098
+ if (!key) throw new CliError("USAGE", "lane repo add needs <key>.", 2);
1099
+ const repo = String(requireFlag(flags, "repo"));
1100
+ const reason = requireFlag(flags, "reason");
1101
+ const entry = {
1102
+ repo,
1103
+ ...(flags.branch ? { branch: String(flags.branch) } : {}),
1104
+ ...(flags.worktree ? { worktree: String(flags.worktree) } : {}),
1105
+ ...(flags["read-only"] ? { readOnly: true } : {}),
1106
+ };
1107
+ const current = (await request("GET", `/api/v1/lanes/${encode(key)}/freeze`)).data;
1108
+ if (!current?.freeze) {
1109
+ // No Freeze yet: only the repositories change; the first Gather builds the
1110
+ // boundaries from them.
1111
+ const payload = await request("POST", `/api/v1/lanes/${encode(key)}/repositories`, { ...entry, reason, ...via });
1112
+ const { repos = [] } = payload?.data ?? {};
1113
+ return { payload, human: `${key}: repositories now ${repos.join(", ")} (no Freeze yet; the first Gather builds it from these).` };
1114
+ }
1115
+ // With a Freeze, a boundaries swap: Dev writes it through to the lane's
1116
+ // repositories in the same step (hub-257), and the edge routes it today.
1117
+ const lane = (await request("GET", `/api/v1/lanes/${encode(key)}`)).data ?? {};
1118
+ const merged = [...current.freeze.boundaries.repos];
1119
+ // A repository Dev's record holds and the Freeze lacks comes along too.
1120
+ for (const known of lane.repositories ?? [])
1121
+ if (!merged.some((x) => x.repo === known.repo))
1122
+ merged.push(Object.fromEntries(Object.entries({ repo: known.repo, branch: known.branch, worktree: known.worktree, ownedPaths: known.ownedPaths?.length ? known.ownedPaths : undefined, readOnly: known.readOnly || undefined }).filter(([, v]) => v !== undefined)));
1123
+ const at = merged.findIndex((x) => x.repo === repo);
1124
+ if (at >= 0) {
1125
+ const { readOnly: _was, ...kept } = merged[at];
1126
+ merged[at] = { ...kept, ...entry };
1127
+ } else merged.push(entry);
1128
+ const payload = await request("POST", `/api/v1/lanes/${encode(key)}/freeze/swap`, {
1129
+ section: "boundaries",
1130
+ expectedVersion: current.version,
1131
+ reason,
1132
+ value: { ...current.freeze.boundaries, repos: merged },
1133
+ ...via,
1134
+ });
1135
+ return {
1136
+ payload,
1137
+ human: `${key}: repositories now ${merged.map((x) => x.repo).join(", ")}; Freeze v${payload?.data?.version ?? "?"} lists the same.`,
1138
+ };
1139
+ }
1140
+
1141
+ /**
1142
+ * The repositories a Gather shortlist answers (hub-257). Dev checks a
1143
+ * shortlist against the lane's own repos field, so it is built from that
1144
+ * field alone: a repository only the Freeze or the repository list names
1145
+ * would fail every pick (GATHER_SHORTLIST_MISMATCH). A record from before the
1146
+ * field falls back to the repositories and the Freeze.
1147
+ */
1148
+ export function shortlistRepos(lane) {
1149
+ const refs = Array.isArray(lane.repos) && lane.repos.length
1150
+ ? lane.repos.map((repo) => typeof repo === "string" ? repo : repo.repo)
1151
+ : [
1152
+ ...(lane.repositories ?? []).map((repository) => repository.repo),
1153
+ ...(lane.freeze?.boundaries?.repos ?? []).map((repository) => repository.repo),
1154
+ ];
1155
+ return [...new Set(refs.filter(Boolean))];
1156
+ }
1157
+
1093
1158
  /** What Dev released in a lane's end, in one line (hub-244). */
1094
1159
  export function holdsLine(released) {
1095
1160
  if (!released) return null;
package/dist/review.js CHANGED
@@ -10,6 +10,7 @@ import { dirname, join } from "node:path";
10
10
  import { promisify } from "node:util";
11
11
  import { CliError, encode } from "./core.js";
12
12
  import { pickerPrompt } from "./gather.js";
13
+ import { componentSetsIn, figmaComponentSet } from "./figma-scope.js";
13
14
  import { gitPrivatePath } from "./safety.js";
14
15
 
15
16
  const execFileAsync = promisify(execFile);
@@ -412,19 +413,25 @@ export const frameUrl = (fileKey, nodeId) => `https://www.figma.com/design/${fil
412
413
 
413
414
  /**
414
415
  * The frames in the Freeze's Figma boundary: each component set's state
415
- * nodes from the DS catalog (its main node as "default" when it has none);
416
- * a whole-file boundary is the whole file.
416
+ * nodes from the DS catalog (its main node as "default" when it has none),
417
+ * or, for a DS component set, its own node as Figma publishes it under the
418
+ * key (NODII-DEV-CLI-70); a whole-file boundary is the whole file.
417
419
  */
418
- export function boundaryFrames(figma, surfaces) {
419
- return figma.flatMap((file) => {
420
+ export async function boundaryFrames(figma, { catalog, lookupSet = figmaComponentSet } = {}) {
421
+ const surfaces = figma.some((file) => file.componentSetKeys?.length) ? await catalog() : [];
422
+ const frames = [];
423
+ for (const file of figma) {
420
424
  const keys = file.componentSetKeys ?? [];
421
- if (!keys.length) return [{ fileKey: file.fileKey, nodeId: null, state: "default" }];
422
- return keys.flatMap((key) => {
423
- const surface = surfaces.find((x) => x.componentSetKey === key && x.fileKey === file.fileKey);
424
- if (!surface) throw new ReviewerError("CRASH", `component set ${key} in the Freeze's Figma boundary is not a Surface in the DS catalog`);
425
- return surface.frames.map((frame) => ({ fileKey: file.fileKey, ...frame }));
426
- });
427
- });
425
+ if (!keys.length) { frames.push({ fileKey: file.fileKey, nodeId: null, state: "default" }); continue; }
426
+ let sets;
427
+ try { sets = await componentSetsIn(file.fileKey, keys, { surfaces, lookupSet }); }
428
+ catch (error) {
429
+ if (error?.code === "FIGMA_KEY_UNKNOWN") throw new ReviewerError("CRASH", `the Freeze's Figma boundary: ${error.message}`);
430
+ throw error;
431
+ }
432
+ for (const key of keys) for (const frame of sets.get(key).frames) frames.push({ fileKey: file.fileKey, ...frame });
433
+ }
434
+ return frames;
428
435
  }
429
436
 
430
437
  /**
@@ -519,13 +526,13 @@ export async function swapFor(swaps, { fileKey, nodeId }, readSet) {
519
526
  * Without a Swap in Dev whose change set holds the node (swapFor), or when
520
527
  * Dev's Swaps or change sets can't be read, the missing node stays a finding.
521
528
  */
522
- export async function figmaFindings(figma, { catalog, check, changeSets = {}, swaps, readSet }) {
529
+ export async function figmaFindings(figma, { catalog, check, changeSets = {}, swaps, readSet, lookupSet }) {
523
530
  const scopedFrames = Object.entries(changeSets).flatMap(([fileKey, scoped]) => scoped.nodes.map((nodeId) => {
524
531
  const item = scoped.items?.find((x) => x.nodeId === nodeId);
525
532
  return { fileKey, nodeId, state: "default", ...(item ? { changeSet: item.changeSet } : {}) };
526
533
  }));
527
534
  const rest = figma.filter((file) => !changeSets[file.fileKey]);
528
- const frames = [...scopedFrames, ...boundaryFrames(rest, rest.some((file) => file.componentSetKeys?.length) ? await catalog() : [])];
535
+ const frames = [...scopedFrames, ...(await boundaryFrames(rest, { catalog, ...(lookupSet ? { lookupSet } : {}) }))];
529
536
  const findings = [];
530
537
  const removed = [];
531
538
  const versions = new Set();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.78",
3
+ "version": "0.6.80",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {