@nodii/dev 0.6.81 → 0.6.83

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/README.md CHANGED
@@ -271,6 +271,19 @@ Sibling sections don't conflict. Dev
271
271
  refuses an overlap with `SCOPE_CONFLICT`; the CLI prints Dev's message, then
272
272
  the set holding the overlapping scope. `figma lock` without `--scope` locks the
273
273
  whole file, as older CLIs do, and that conflicts with every other set.
274
+
275
+ **A DS component set in the Freeze (NODII-DEV-CLI-70).** A lane may lock only
276
+ the component sets its Freeze names. A Surface's nodes come from the DS
277
+ catalog (`registry.json`). A DS component set (Empty State, Pagination) is not
278
+ a Surface, so its node comes from the design catalogue
279
+ (`design-catalog.json`): the entry whose `figma.componentSetKey` (or
280
+ `figma.componentKey`) is the key names its `figma.fileKey` and
281
+ `figma.nodeId`. `lane check`'s Figma boundary resolves it the same way. The
282
+ CLI never reads Figma REST for this. A key in neither catalogue is refused with
283
+ `FIGMA_KEY_UNKNOWN`; the fix is to publish the key on its design catalogue
284
+ entry in the design-system repository (the Figma MCP's
285
+ `search_design_system` returns it as `componentSetKey`).
286
+
274
287
  `figma scope add` widens a set you hold, with the same check; nothing is ever
275
288
  widened silently. `figma scope set` narrows a set you hold to exactly the
276
289
  scopes you give, and releases the rest for other sets: for example, a set
package/dist/cli.js CHANGED
@@ -21,7 +21,7 @@ import {
21
21
  refuseFromLane,
22
22
  revokeOAuth,
23
23
  } from "./oauth.js";
24
- import { FIGMA_HOOK_DENIALS, heartbeatCurrentLane, postHook, postHookFailure, preHook, settingsSnippet, workflowSuggestion } from "./hooks.js";
24
+ import { FIGMA_HOOK_DENIALS, heartbeatFromHook, postHook, postHookFailure, preHook, settingsSnippet, workflowSuggestion } from "./hooks.js";
25
25
  import { setupCommand } from "./setup.js";
26
26
  import { harnessCommand } from "./harness.js";
27
27
  import { repoCommand } from "./repo-policy.js";
@@ -686,7 +686,9 @@ export async function main(argv = process.argv.slice(2)) {
686
686
  // A nudge hook is fail-open and writes only its own JSON: it cannot run a
687
687
  // Delta gather, and a waiting-results banner would corrupt its output.
688
688
  // surface-gen-pre runs in every session, lane or not, so it never reaches Dev.
689
- if (argv[0] !== "__run-supervisor" && !readsHelp(argv) && !(argv[0] === "hook" && (argv[1]?.startsWith("nudge-") || argv[1] === "surface-gen-pre"))) {
689
+ // The heartbeat hook fires on every tool call, so these checks would call Dev each
690
+ // time past its rate limit, and a failed check would silently stop the heartbeat.
691
+ if (argv[0] !== "__run-supervisor" && !readsHelp(argv) && !(argv[0] === "hook" && (argv[1]?.startsWith("nudge-") || argv[1] === "surface-gen-pre" || argv[1] === "lane-heartbeat"))) {
690
692
  await amendmentGuard(argv);
691
693
  await showWaitingResults({ acknowledge: argv[0] !== "hook" });
692
694
  }
@@ -1459,8 +1461,16 @@ export async function main(argv = process.argv.slice(2)) {
1459
1461
  return;
1460
1462
  }
1461
1463
  if (action === "lane-heartbeat") {
1462
- const result = await heartbeatCurrentLane();
1463
- return emit(result, json, result.heartbeated ? `Heartbeat recorded for ${result.key}.` : "No current-branch lane; no heartbeat sent.");
1464
+ // A heartbeat never blocks the tool call or the stop that fired it.
1465
+ try {
1466
+ let payload = {};
1467
+ if (!process.stdin.isTTY) { try { payload = JSON.parse(await stdinText()); } catch {} }
1468
+ const result = await heartbeatFromHook(payload);
1469
+ return emit(result, json, result.heartbeated ? `Heartbeat recorded for ${result.key}.` : `No heartbeat sent: ${result.reason}.`);
1470
+ } catch (error) {
1471
+ process.stderr.write(`nodii-dev lane heartbeat: ${error?.code ?? "ERROR"}: ${error?.message ?? String(error)}\n`);
1472
+ return;
1473
+ }
1464
1474
  }
1465
1475
  const payload = JSON.parse(await stdinText());
1466
1476
  await recordHookFire(payload).catch(() => {});
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.81";
7
+ export const VERSION = "0.6.83";
8
8
  export const configPath = () =>
9
9
  process.env.NODII_DEV_CONFIG_PATH ??
10
10
  join(homedir(), ".config/nodii-dev/config.json");
package/dist/doctor.js CHANGED
@@ -342,7 +342,7 @@ export async function doctorCommand(deps = {}) {
342
342
  else if (claude && runtime.managedState === "merged_stale") checks.push(missing(key, `${runtime.managedPath} was merged by hand and its nodii-dev routes are out of date`, "update its hooks by hand from ~/.config/nodii-dev/claude-managed-hooks/managed-settings.json", extra));
343
343
  else if (!runtime.trusted) checks.push(missing(key, `hooks are installed but not trusted${runtime.trustStatuses?.length ? ` (${runtime.trustStatuses.join(", ")})` : ""}`, runtime.runtime.startsWith("codex") ? "review /hooks, or have an operator run the commands printed by `nodii-dev harness update --system`" : "review the runtime hook configuration", extra));
344
344
  else if (runtime.managed && runtime.cliStatus?.ok === false) checks.push(missing(key, `${runtime.cliStatus.message}; managed hooks fail open until this is fixed`, "update nodii-dev, then run `nodii-dev harness update --system` to refresh the absolute CLI path", extra));
345
- else if (!runtime.firing) checks.push(missing(key, `hooks are installed and trusted${runtime.managed ? " (managed)" : ""}, but no firing receipt exists`, "start a fresh runtime session and run doctor again", extra));
345
+ else if (!runtime.firing) checks.push(missing(key, `hooks are installed and trusted${runtime.managed ? " (managed)" : ""}, but no firing receipt from this profile in this worktree (receipts are per worktree)`, "start a fresh runtime session and run doctor again", extra));
346
346
  else checks.push(ok(key, `installed, trusted${runtime.managed ? " (managed)" : ""}, and firing (last ${runtime.lastFiredAt})`, extra));
347
347
  }
348
348
  } catch (error) {
@@ -290,50 +290,37 @@ 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
293
  /**
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).
294
+ * How a key the DS catalog does not list as a Surface (a DS component set,
295
+ * NODII-DEV-CLI-70) resolves: the design catalogue entry that publishes it
296
+ * (figma.componentSetKey or figma.componentKey) names its file and node. Both
297
+ * come from the DS repository's build, not from a lane-given flag, and the CLI
298
+ * never reads Figma REST for them (operator ruling of 3 Nov: Figma through the
299
+ * MCP). NODII_DEV_DS_DESIGN_CATALOG_URL can point the read elsewhere, as
300
+ * NODII_DEV_DS_REGISTRY_URL can for the registry. A catalogue with no entries
301
+ * list is refused, never read as empty. One read of the catalogue per lookup.
302
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);
303
+ export function designCatalogSets({ fetchImpl = fetch, url = process.env.NODII_DEV_DS_DESIGN_CATALOG_URL || DS_DESIGN_CATALOG_URL } = {}) {
304
+ let entries;
305
+ return async (key) => {
306
+ entries ??= fetchDsJson(url, { fetchImpl }).then((catalog) => {
307
+ if (!Array.isArray(catalog?.entries)) throw new CliError("DS_CATALOG_INVALID", "The design catalogue has no entries list.", 1);
308
+ return catalog.entries;
309
+ });
310
+ const entry = (await entries).find((item) => [item?.figma?.componentSetKey, item?.figma?.componentKey].includes(key));
311
+ if (!entry?.figma?.fileKey || !entry.figma.nodeId) return null;
312
+ return { key, fileKey: entry.figma.fileKey, nodeId: entry.figma.nodeId, name: entry.title ?? entry.key ?? null };
313
+ };
327
314
  }
328
315
 
329
316
  /**
330
317
  * 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.
318
+ * state frames from the DS catalog; else, through `lookupSet`, the design
319
+ * catalogue entry that publishes the key (a DS component set,
320
+ * NODII-DEV-CLI-70), its own node as the one frame. `onlyIfNeeded(resolvedSoFar)` returning false skips
321
+ * those lookups. A key that names nothing in this file is refused.
335
322
  */
336
- export async function componentSetsIn(fileKey, keys, { surfaces = [], lookupSet = figmaComponentSet, onlyIfNeeded } = {}) {
323
+ export async function componentSetsIn(fileKey, keys, { surfaces = [], lookupSet = designCatalogSets(), onlyIfNeeded } = {}) {
337
324
  const sets = new Map();
338
325
  for (const key of keys) {
339
326
  const surface = surfaces.find((item) => item.componentSetKey === key && item.fileKey === fileKey);
@@ -344,10 +331,10 @@ export async function componentSetsIn(fileKey, keys, { surfaces = [], lookupSet
344
331
  for (const key of rest) {
345
332
  const set = await lookupSet(key);
346
333
  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 });
334
+ throw new CliError("FIGMA_KEY_UNKNOWN", `${key} is neither a Surface in the DS catalog nor the published key of a design catalogue entry. A DS component set is resolved only through the design catalogue (figma.componentSetKey beside figma.nodeId), so publish its key there, in the design-system repository: the Figma MCP's search_design_system returns it as componentSetKey.`, 1, { fileKey, key });
348
335
  if (set.fileKey !== fileKey)
349
336
  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" }] });
337
+ sets.set(key, { key, fileKey, name: set.name ?? null, nodeIds: [set.nodeId], frames: [{ nodeId: set.nodeId, state: "default" }] });
351
338
  }
352
339
  return sets;
353
340
  }
@@ -357,7 +344,7 @@ export async function componentSetsIn(fileKey, keys, { surfaces = [], lookupSet
357
344
  * write (lockScopes = null) outside the lane's scope. `scope` null = the lane
358
345
  * declared none, so nothing is bounded here.
359
346
  */
360
- export async function assertWithinLaneScope(scope, fileKey, lockScopes, { catalog = loadDsCatalog, lookupSet = figmaComponentSet } = {}) {
347
+ export async function assertWithinLaneScope(scope, fileKey, lockScopes, { catalog = loadDsCatalog, lookupSet = designCatalogSets() } = {}) {
361
348
  if (scope === null) return { checked: false };
362
349
  const file = scope.find((item) => item.fileKey === fileKey);
363
350
  if (!file)
@@ -366,7 +353,7 @@ export async function assertWithinLaneScope(scope, fileKey, lockScopes, { catalo
366
353
  const wide = lockScopes.length ? lockScopes.filter((item) => item.kind !== "component") : [{ kind: "file" }];
367
354
  if (wide.length)
368
355
  throw outside(`This lane may lock only its component sets in ${fileKey}, not ${wide.map((item) => item.kind).join(", ")}.`, { fileKey, scope: file });
369
- // Surfaces first; Figma is read for a DS set's key only when a node is still unaccounted for.
356
+ // Surfaces first; a DS set's key is looked up only when a node is still unaccounted for.
370
357
  const allowedBy = (sets) => new Set([...sets.values()].flatMap((set) => set.nodeIds));
371
358
  const sets = await componentSetsIn(fileKey, file.componentSets, {
372
359
  surfaces: await catalog(),
package/dist/harness.js CHANGED
@@ -11,6 +11,7 @@ import { fileURLToPath } from "node:url";
11
11
  import { promisify } from "node:util";
12
12
  import { CliError, devRequest, query } from "./core.js";
13
13
  import { classifyClaudeManaged, claudeManagedSettingsPath, managedClaudeHookBundle, managedHookBundle, nodiiCommandArgs, refreshManagedDispatchers, writeManagedClaudeHookBundle, writeManagedHookBundle } from "./managed-hooks.js";
14
+ import { heartbeatSettingsSnippet } from "./hooks.js";
14
15
  import { nudgeSettingsSnippet } from "./nudges.js";
15
16
  import { codexSafetyHooksSnippet, regroundingHooksSnippet, safetySettingsSnippet } from "./safety.js";
16
17
 
@@ -199,6 +200,7 @@ export function withSafetyHooks(harness) {
199
200
  const parsed = JSON.parse(settings.content);
200
201
  let hooks = addHookEntries(parsed.hooks, safetySettingsSnippet().hooks);
201
202
  hooks = addHookEntries(hooks, regroundingHooksSnippet().hooks);
203
+ hooks = addHookEntries(hooks, heartbeatSettingsSnippet().hooks);
202
204
  hooks = addHookEntries(hooks, nudgeSettingsSnippet().hooks);
203
205
  assertNodiiHooks(hooks, ".claude/settings.json");
204
206
  settings.content = JSON.stringify({ ...parsed, hooks });
package/dist/hooks.js CHANGED
@@ -2,7 +2,7 @@ import { CliError, devRequest } from "./core.js";
2
2
  import { FOUNDATIONS_ID, figmaLockCheck, outOfScopeText } from "./figma.js";
3
3
  import { assertWithinLaneScope, currentLaneFigmaScope } from "./figma-scope.js";
4
4
  import { execFile } from "node:child_process";
5
- import { readFile } from "node:fs/promises";
5
+ import { readFile, writeFile } from "node:fs/promises";
6
6
  import { promisify } from "node:util";
7
7
  import { safetySettingsSnippet } from "./safety.js";
8
8
 
@@ -218,13 +218,38 @@ export const settingsSnippet = () => {
218
218
  } };
219
219
  };
220
220
 
221
- export async function heartbeatCurrentLane(request = devRequest) {
221
+ // MW1-34, MW5-17: the harness heartbeats a live lane on tool use and stop, about
222
+ // once a minute. The lane heartbeat also refreshes the lane's run in Dev. The
223
+ // supervisor's run heartbeat says only that the process is alive; this one says
224
+ // the agent acted, which is what keeps `stuck` meaningful.
225
+ export const HEARTBEAT_STAMP = "nodii-lane-heartbeat-at";
226
+ export const HEARTBEAT_MIN_INTERVAL_MS = 60_000;
227
+ export const heartbeatSettingsSnippet = () => {
228
+ const beat = [{ hooks: [{ type: "command", command: "nodii-dev hook lane-heartbeat" }] }];
229
+ return { hooks: { PostToolUse: beat, Stop: beat } };
230
+ };
231
+
232
+ /** One rate-limited heartbeat for the worktree a hook fired in. The stamp is written first, so parallel tool calls send one. */
233
+ export async function heartbeatFromHook(payload, { request = devRequest, now = Date.now, minIntervalMs = HEARTBEAT_MIN_INTERVAL_MS } = {}) {
234
+ const cwd = payload?.cwd ?? process.cwd();
235
+ let stamp;
236
+ try { stamp = (await execFileAsync("git", ["rev-parse", "--path-format=absolute", "--git-path", HEARTBEAT_STAMP], { cwd, encoding: "utf8" })).stdout.trim(); }
237
+ catch { return { heartbeated: false, reason: "not a git worktree" }; }
238
+ const last = Number(await readFile(stamp, "utf8").catch(() => 0));
239
+ const at = now();
240
+ // A stamp from the future (a clock change) must not silence the lane.
241
+ if (at >= last && at - last < minIntervalMs) return { heartbeated: false, reason: "rate limited" };
242
+ await writeFile(stamp, String(at));
243
+ return heartbeatCurrentLane(request, { cwd });
244
+ }
245
+
246
+ export async function heartbeatCurrentLane(request = devRequest, { cwd = process.cwd() } = {}) {
222
247
  let branch;
223
- try { branch = (await execFileAsync("git", ["branch", "--show-current"], { encoding: "utf8" })).stdout.trim(); }
248
+ try { branch = (await execFileAsync("git", ["branch", "--show-current"], { cwd, encoding: "utf8" })).stdout.trim(); }
224
249
  catch { return { heartbeated: false, reason: "not a git worktree" }; }
225
250
  if (!branch) return { heartbeated: false, reason: "detached HEAD" };
226
251
  try {
227
- const markerPath = (await execFileAsync("git", ["rev-parse", "--path-format=absolute", "--git-path", "nodii-lane.json"], { encoding: "utf8" })).stdout.trim();
252
+ const markerPath = (await execFileAsync("git", ["rev-parse", "--path-format=absolute", "--git-path", "nodii-lane.json"], { cwd, encoding: "utf8" })).stdout.trim();
228
253
  const marker = JSON.parse(await readFile(markerPath, "utf8"));
229
254
  const lane = (await request("GET", `/api/v1/lanes/${encodeURIComponent(marker.laneKey)}`)).data;
230
255
  if (lane.repositories?.some((repository) => repository.branch === branch)) {
package/dist/review.js CHANGED
@@ -10,7 +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
+ import { componentSetsIn, designCatalogSets } from "./figma-scope.js";
14
14
  import { gitPrivatePath } from "./safety.js";
15
15
 
16
16
  const execFileAsync = promisify(execFile);
@@ -414,10 +414,10 @@ export const frameUrl = (fileKey, nodeId) => `https://www.figma.com/design/${fil
414
414
  /**
415
415
  * The frames in the Freeze's Figma boundary: each component set's state
416
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
+ * or, for a DS component set, its own node as the design catalogue
418
+ * publishes it under the key (NODII-DEV-CLI-70); a whole-file boundary is the whole file.
419
419
  */
420
- export async function boundaryFrames(figma, { catalog, lookupSet = figmaComponentSet } = {}) {
420
+ export async function boundaryFrames(figma, { catalog, lookupSet = designCatalogSets() } = {}) {
421
421
  const surfaces = figma.some((file) => file.componentSetKeys?.length) ? await catalog() : [];
422
422
  const frames = [];
423
423
  for (const file of figma) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.81",
3
+ "version": "0.6.83",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {