@nodii/dev 0.6.85 → 0.6.87

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
@@ -342,6 +342,18 @@ submitted before 31 Oct 2026 has none of these: the CLI says
342
342
  `--json` also gives the replaced rows (`previousRounds`) and the write log.
343
343
  Guideline change sets are `design changeset show`.
344
344
 
345
+ **Submit evidence (hub-258).** `figma submit` and `figma resubmit` add
346
+ an `evidence` object to the body: `baseVersion` from the change set,
347
+ `finishVersion` from the body's `figmaVersion`, and `nodes`, each variant with an
348
+ inline after PNG and that PNG's sha256. The CLI reads only the body and the change
349
+ set, never the file. A node you wrote beyond the items and variants is yours to
350
+ declare, in the body's `evidence.nodes` as `{ "nodeId": "1:9" }`: the CLI never
351
+ fills it from the set's write log. A submit that can't read the set stops there,
352
+ with nothing sent. Dev refuses a wrong version or hash with `EVIDENCE_MISMATCH`,
353
+ and a logged write that is no declared node, or inside none, with
354
+ `WRITE_OUTSIDE_DECLARED`. The CLI refuses a malformed `evidence` with `USAGE`, and
355
+ one node declared with two different after images with `EVIDENCE_MISMATCH`.
356
+
345
357
  **Change-set context (DEC-0204).** A submit tells the reviewer what they are
346
358
  looking at. `figma submit CHANGE_SET --file SUBMIT.json` takes:
347
359
 
@@ -861,8 +873,8 @@ run the same command again.
861
873
  ### Product pages from Surfaces: `surface generate` (MW8-17)
862
874
 
863
875
  ```sh
864
- nodii-dev surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE]
865
- nodii-dev surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--report FILE]
876
+ nodii-dev surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE]
877
+ nodii-dev surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--report FILE] [--post-scoreboard ISSUE]
866
878
  ```
867
879
 
868
880
  Run in a design-system checkout. It turns a Figma Surface into its product
@@ -902,6 +914,17 @@ product-page catalog names the Surface by its published component-set key
902
914
  `surface generate --all --check` with a pinned `@nodii/dev`; `--all`
903
915
  without `--fetch` covers the Surfaces that have a committed tree or a
904
916
  generated file and lists the rest as not generated yet.
917
+ - **Unpublished Surfaces.** `--all --fetch` skips a Surface whose component set
918
+ is not among its file's published sets, names it as not published (`--json`:
919
+ `data.unpublished`), and still generates and scores the rest. A Surface named
920
+ on its own still fails with `SURFACE_NOT_PUBLISHED`.
921
+ - **Scoreboard.** Every run returns `data.scoreboard`, one row per module, and
922
+ `--all` also prints it: Surfaces clean out of total, not published, not
923
+ generated yet, and unmapped layers by kind. A Surface is clean when it has no
924
+ unmapped layer. Total counts every selected Surface, so a skipped one still
925
+ counts against the score. `--post-scoreboard ISSUE` also posts it as a comment
926
+ on that issue, and needs a Dev sign-in. If the post fails, the command exits 1
927
+ with `COMMENT_FAILED`; any files from `--write` are already written.
905
928
 
906
929
  ### Large sets: submit as a Dev job
907
930
 
package/dist/cli.js CHANGED
@@ -165,13 +165,15 @@ Usage: nodii-dev <command> [options] [--json]
165
165
  # values not bound to a variable and non-DS instances; submit reports the
166
166
  # same on any Surface node a set touches (refuses where the host enforces).
167
167
  # Reads Figma on Dev's token; exit 1 = SURFACES_CHECK_FAILED
168
- surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE]
169
- surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--report FILE]
168
+ surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE]
169
+ surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--report FILE] [--post-scoreboard ISSUE]
170
170
  # a Surface -> its product page's presentational code, from Code Connect
171
171
  # (MW8-17), in a design-system checkout. --fetch reads Figma (FIGMA_PAT, one
172
172
  # call per 8 s); --write writes <page>.surface.generated.tsx (and, with --fetch,
173
173
  # the committed tree); --check refuses a difference (the surface-gen-equal gate);
174
- # --report writes the unmapped layers per file (U08-14), .md or .json
174
+ # --report writes the unmapped layers per file (U08-14), .md or .json;
175
+ # --all --fetch skips and reports a Surface that is not published;
176
+ # --post-scoreboard comments the per-module scoreboard on the issue
175
177
  figma lock FILE_KEY --title TEXT [--scope KIND:ID ...]
176
178
  # scopes: component:NODE page:NODE section:NODE foundations create:PAGE:NAME;
177
179
  # no --scope locks the whole file (DEC-0032)
@@ -187,7 +189,9 @@ Usage: nodii-dev <command> [options] [--json]
187
189
  # variants: [{ nodeId, name, context, afterPngBase64 }] }] } (DEC-0204);
188
190
  # a missing writeUp, context or variant name, or an item with no variants,
189
191
  # is refused before Dev is called (writeUp <= 2000, context <= 500, name <= 120;
190
- # never a bare node id)
192
+ # never a bare node id). The CLI adds evidence { baseVersion, finishVersion,
193
+ # nodes: [{ nodeId, afterSha256 }] }: list any node written beyond the variants
194
+ # in the body's evidence.nodes, or Dev refuses WRITE_OUTSIDE_DECLARED
191
195
  figma checked CHANGE_SET --unused-properties --stale-placeholders --dialog-body # the hand checks the submit nudge asks for
192
196
  # submit, resubmit and design check --change-set run as a job in Dev
193
197
  # and poll it (a large set outlasts the edge's timeout); --sync waits
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.85";
7
+ export const VERSION = "0.6.87";
8
8
  export const configPath = () =>
9
9
  process.env.NODII_DEV_CONFIG_PATH ??
10
10
  join(homedir(), ".config/nodii-dev/config.json");
package/dist/figma.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { createHash } from "node:crypto";
1
2
  import { readFile } from "node:fs/promises";
2
3
  import { setTimeout as delay } from "node:timers/promises";
3
4
  import { CliError, devAsyncRequest, devRequest, encode } from "./core.js";
@@ -122,7 +123,20 @@ const noVariantLines = (items = []) =>
122
123
  items.map((i) => ` ${itemLabel(i)} has no variants; add at least one { nodeId, name, context } (an empty item reaches review with nothing to see)`);
123
124
 
124
125
  /** Refuses, before any call to Dev, a submit or re-submit body that Dev would refuse for its context (DEV-DSN-25). */
126
+ /** The evidence a lane states in its body has the shape Dev's gate takes (hub-258). */
127
+ function assertEvidenceShape(evidence, file) {
128
+ if (evidence === undefined) return;
129
+ const bad = (why) => new CliError("USAGE", `${file}: evidence ${why}; nothing was sent`, 2);
130
+ if (!evidence || typeof evidence !== "object" || Array.isArray(evidence)) throw bad("must be an object");
131
+ if (evidence.nodes !== undefined && !Array.isArray(evidence.nodes)) throw bad("nodes must be a list of { nodeId, afterSha256? }");
132
+ (evidence.nodes ?? []).forEach((node, n) => {
133
+ if (typeof node?.nodeId !== "string" || !node.nodeId) throw bad(`nodes[${n}] needs nodeId`);
134
+ if (node.afterSha256 !== undefined && !/^[0-9a-f]{64}$/.test(node.afterSha256)) throw bad(`nodes[${n}] afterSha256 must be a lowercase hex sha256`);
135
+ });
136
+ }
137
+
125
138
  export function assertContext(body, { resubmit = false, file = "the payload" } = {}) {
139
+ assertEvidenceShape(body.evidence, file);
126
140
  const { items, problems } = contextProblems(body, { resubmit });
127
141
  if (items.length)
128
142
  throw new CliError(
@@ -298,15 +312,44 @@ async function afterGatewayTimeout(id, kind, before, error, { sync, request, pro
298
312
  );
299
313
  }
300
314
 
315
+ /** The sha256 Dev stores for an inline PNG: the hash of its decoded bytes. */
316
+ const pngSha256 = (base64) => createHash("sha256").update(Buffer.from(base64, "base64")).digest("hex");
317
+
318
+ /**
319
+ * What a submit declares to Dev's gate (hub-258, option A): the base version, the
320
+ * finish version, and the declared nodes with the hash of each after PNG. It reads
321
+ * only the body and the set, never the file. Nodes the lane wrote beyond its items
322
+ * and variants come from the body's evidence.nodes. They never come from the set's
323
+ * write log: that would declare every logged write and empty WRITE_OUTSIDE_DECLARED.
324
+ */
325
+ export function submitEvidence(body, set) {
326
+ const nodes = new Map();
327
+ const declare = (nodeId, afterSha256) => {
328
+ const known = nodes.get(nodeId);
329
+ if (known && afterSha256 && known.afterSha256 && known.afterSha256 !== afterSha256)
330
+ throw new CliError("EVIDENCE_MISMATCH", `Node ${nodeId} is declared with two different after images: ${known.afterSha256} and ${afterSha256}. Send the one PNG the Figma MCP's get_screenshot returned for it.`, 1, { nodeId, hashes: [known.afterSha256, afterSha256] });
331
+ if (!known || afterSha256) nodes.set(nodeId, { nodeId, ...(afterSha256 ? { afterSha256 } : {}) });
332
+ };
333
+ for (const item of body.items ?? [])
334
+ for (const variant of item.variants ?? [])
335
+ if (variant.afterPngBase64) declare(variant.nodeId, pngSha256(variant.afterPngBase64));
336
+ for (const node of body.evidence?.nodes ?? []) declare(node.nodeId, node.afterSha256);
337
+ const stated = body.evidence ?? {};
338
+ return {
339
+ baseVersion: stated.baseVersion !== undefined ? stated.baseVersion : (set?.baseVersion ?? null),
340
+ finishVersion: stated.finishVersion ?? body.figmaVersion,
341
+ nodes: [...nodes.values()],
342
+ };
343
+ }
344
+
301
345
  /** A submit or re-submit, async unless `sync`; a gateway timeout is checked against the set, not resent. */
302
346
  async function submitCall(id, kind, body, { sync = false, request = devRequest, progress = stderrLine, ...job } = {}) {
303
347
  const path = `/api/v1/design/change-sets/${encode(id)}/${kind}`;
304
- let before = null;
305
- try {
306
- before = (await request("GET", `/api/v1/design/change-sets/${encode(id)}`)).data;
307
- } catch {}
348
+ // The set's base goes in the evidence, so a submit that can't read it doesn't start.
349
+ const before = (await request("GET", `/api/v1/design/change-sets/${encode(id)}`)).data;
350
+ const sent = { ...body, evidence: submitEvidence(body, before) };
308
351
  try {
309
- return sync ? await request("POST", path, body) : await changeSetJob("POST", path, body, { changeSetId: id, kind, request, progress, ...job });
352
+ return sync ? await request("POST", path, sent) : await changeSetJob("POST", path, sent, { changeSetId: id, kind, request, progress, ...job });
310
353
  } catch (error) {
311
354
  if (!GATEWAY.has(error?.code)) throw error;
312
355
  return afterGatewayTimeout(id, kind, before, error, { sync, request, progress });
package/dist/flags.js CHANGED
@@ -70,7 +70,7 @@ export const COMMAND_FLAGS = {
70
70
  "figma changeset": ["file", "actionable", "all", "limit"],
71
71
  "figma apply": ["file", "figma-version"],
72
72
  "figma lock": ["title", "scope"],
73
- "surface generate": ["write", "check", "fetch", "all", "module", "type", "figma-version", "report"],
73
+ "surface generate": ["write", "check", "fetch", "all", "module", "type", "figma-version", "report", "post-scoreboard"],
74
74
  };
75
75
 
76
76
  /** Refuse a flag the command does not declare (USAGE, exit 2), naming the valid ones. */
package/dist/hooks.js CHANGED
@@ -230,7 +230,7 @@ export const heartbeatSettingsSnippet = () => {
230
230
  };
231
231
 
232
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 } = {}) {
233
+ export async function heartbeatFromHook(payload, { request = devRequest, now = Date.now, minIntervalMs = HEARTBEAT_MIN_INTERVAL_MS, env = process.env } = {}) {
234
234
  const cwd = payload?.cwd ?? process.cwd();
235
235
  let stamp;
236
236
  try { stamp = (await execFileAsync("git", ["rev-parse", "--path-format=absolute", "--git-path", HEARTBEAT_STAMP], { cwd, encoding: "utf8" })).stdout.trim(); }
@@ -240,21 +240,27 @@ export async function heartbeatFromHook(payload, { request = devRequest, now = D
240
240
  // A stamp from the future (a clock change) must not silence the lane.
241
241
  if (at >= last && at - last < minIntervalMs) return { heartbeated: false, reason: "rate limited" };
242
242
  await writeFile(stamp, String(at));
243
- return heartbeatCurrentLane(request, { cwd });
243
+ return heartbeatCurrentLane(request, { cwd, env });
244
244
  }
245
245
 
246
- export async function heartbeatCurrentLane(request = devRequest, { cwd = process.cwd() } = {}) {
246
+ export async function heartbeatCurrentLane(request = devRequest, { cwd = process.cwd(), env = process.env } = {}) {
247
247
  let branch;
248
248
  try { branch = (await execFileAsync("git", ["branch", "--show-current"], { cwd, encoding: "utf8" })).stdout.trim(); }
249
249
  catch { return { heartbeated: false, reason: "not a git worktree" }; }
250
250
  if (!branch) return { heartbeated: false, reason: "detached HEAD" };
251
251
  try {
252
252
  const markerPath = (await execFileAsync("git", ["rev-parse", "--path-format=absolute", "--git-path", "nodii-lane.json"], { cwd, encoding: "utf8" })).stdout.trim();
253
- const marker = JSON.parse(await readFile(markerPath, "utf8"));
254
- const lane = (await request("GET", `/api/v1/lanes/${encodeURIComponent(marker.laneKey)}`)).data;
255
- if (lane.repositories?.some((repository) => repository.branch === branch)) {
256
- await request("POST", `/api/v1/lanes/${encodeURIComponent(lane.id)}/heartbeat`, { via: "nodii-dev" });
257
- return { heartbeated: true, key: lane.key };
253
+ // A launched run names its lane in NODII_DEV_LANE_KEY. Older worktrees have
254
+ // no marker, and the branch lookup below only sees the newest 200 lanes, so
255
+ // a lane older than that page would never beat without this (AGENT-HARNESS-86).
256
+ const marker = await readFile(markerPath, "utf8").then(JSON.parse).catch(() => null);
257
+ const laneKey = marker?.laneKey ?? env.NODII_DEV_LANE_KEY;
258
+ if (laneKey) {
259
+ const lane = (await request("GET", `/api/v1/lanes/${encodeURIComponent(laneKey)}`)).data;
260
+ if (lane.repositories?.some((repository) => repository.branch === branch)) {
261
+ await request("POST", `/api/v1/lanes/${encodeURIComponent(lane.id)}/heartbeat`, { via: "nodii-dev" });
262
+ return { heartbeated: true, key: lane.key };
263
+ }
258
264
  }
259
265
  } catch {}
260
266
  const lanes = (await request("GET", "/api/v1/lanes?limit=200")).data ?? [];
package/dist/surface.js CHANGED
@@ -27,7 +27,7 @@ import { execFileSync } from "node:child_process";
27
27
  import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
28
28
  import { tmpdir } from "node:os";
29
29
  import { dirname, join, relative, resolve } from "node:path";
30
- import { CliError } from "./core.js";
30
+ import { CliError, VERSION, devRequest, readConfig } from "./core.js";
31
31
  import { createRenderer } from "./vendor/render-templates.mjs";
32
32
 
33
33
  /** Bumped whenever the emitted code changes shape for the same inputs. */
@@ -46,8 +46,8 @@ const BACKOFF_429_MS = 30_000;
46
46
  const SET_KEY = /^[0-9a-f]{40}$/;
47
47
 
48
48
  export const SURFACE_USAGE =
49
- "surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE]\n" +
50
- "surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--report FILE]";
49
+ "surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE]\n" +
50
+ "surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--report FILE] [--post-scoreboard ISSUE]";
51
51
 
52
52
  // ---------------------------------------------------------------------------
53
53
  // Repository inputs
@@ -705,7 +705,7 @@ function tableOf(node, ctx) {
705
705
  }
706
706
  const module = imports.map((s) => /\{[^}]*\bTable[A-Za-z]*(Cell|Head)\b[^}]*\}\s+from\s+["']([^"']+)["']/.exec(s)?.[2]).find(Boolean);
707
707
  if (!module) return null;
708
- ctx.note(ctx.path, "frame", `table drawn as frames (${rows.length} row${rows.length === 1 ? "" : "s"}); assembled into the DS Table's parts`);
708
+ ctx.note(ctx.path, "table", `table drawn as frames (${rows.length} row${rows.length === 1 ? "" : "s"}); assembled into the DS Table's parts`);
709
709
  ctx.imports.push(...imports, `import { Table, TableBody, TableHeader, TableRow } from "${module}";`);
710
710
  const { depth } = ctx;
711
711
  const cellCode = ({ cell, code }, row, d) => {
@@ -771,7 +771,7 @@ export function unmappedMarkdown(files) {
771
771
  const lines = [
772
772
  "# Surface layers with no Code Connect mapping (U08-14)",
773
773
  "",
774
- "Generated by `nodii-dev surface generate --report`. Kinds: `instance` (a library instance the generator cannot emit through a template), `text` (loose text, drawn with the DS type utility and colour role), `frame` (a frame that paints its own fill, stroke, radius or effect: only its layout is generated), `shape` (a rectangle, ellipse or vector: marked, not drawn), `token` (a text colour that matches no colour v2 role: left out).",
774
+ "Generated by `nodii-dev surface generate --report`. Kinds: `instance` (a library instance the generator cannot emit through a template), `text` (loose text, drawn with the DS type utility and colour role), `frame` (a frame that paints its own fill, stroke, radius or effect: only its layout is generated), `table` (a table drawn as frames, assembled into the DS Table's parts), `layout` (a frame or slot with no auto layout), `shape` (a rectangle, ellipse or vector: marked, not drawn), `token` (a text colour that matches no colour v2 role: left out).",
775
775
  "",
776
776
  ];
777
777
  for (const [fileKey, file] of Object.entries(files)) {
@@ -786,6 +786,70 @@ export function unmappedMarkdown(files) {
786
786
  return lines.join("\n");
787
787
  }
788
788
 
789
+ const moduleOf = (row) => row.product ?? "no module";
790
+
791
+ /**
792
+ * One row per module: how many of its Surfaces are clean, and what keeps the rest from it.
793
+ * `total` counts every selected Surface, so one that was skipped or never generated still
794
+ * counts against `clean`: skipping can never raise a module's score.
795
+ */
796
+ export function surfaceScoreboard(selected, results, { unpublished = [], notGeneratedYet = [] } = {}) {
797
+ const modules = new Map();
798
+ const of = (row) => {
799
+ const name = moduleOf(row);
800
+ if (!modules.has(name)) modules.set(name, { module: name, total: 0, clean: 0, unmapped: 0, byKind: {}, unpublished: [], notGeneratedYet: [] });
801
+ return modules.get(name);
802
+ };
803
+ for (const row of selected) of(row).total += 1;
804
+ for (const row of unpublished) of(row).unpublished.push(row.id);
805
+ for (const row of notGeneratedYet) of(row).notGeneratedYet.push(row.id);
806
+ for (const r of results) {
807
+ const entry = of(r.row);
808
+ if (!r.unmapped.length) entry.clean += 1;
809
+ entry.unmapped += r.unmapped.length;
810
+ for (const u of r.unmapped) entry.byKind[u.kind] = (entry.byKind[u.kind] ?? 0) + 1;
811
+ }
812
+ return [...modules.values()];
813
+ }
814
+
815
+ const byKindText = (byKind) =>
816
+ Object.entries(byKind)
817
+ .sort(([a, x], [b, y]) => y - x || a.localeCompare(b))
818
+ .map(([kind, n]) => `${kind} ${n}`)
819
+ .join(", ") || "none";
820
+
821
+ const NAMES_SHOWN = 20;
822
+ const namesText = (ids) => `${ids.slice(0, NAMES_SHOWN).map((id) => `\`${id}\``).join(", ")}${ids.length > NAMES_SHOWN ? `, and ${ids.length - NAMES_SHOWN} more` : ""}`;
823
+
824
+ export function scoreboardText(board) {
825
+ return board.map((m) => `${m.module}\t${m.clean}/${m.total} clean\t${m.unpublished.length} not published\t${m.notGeneratedYet.length} not generated yet\t${m.unmapped} unmapped (${byKindText(m.byKind)})`).join("\n");
826
+ }
827
+
828
+ /** The scoreboard as an issue comment. `source` names what the run read (P-4). */
829
+ export function scoreboardMarkdown(board, { mode, source }) {
830
+ const lines = [
831
+ `**Surface scoreboard** (\`surface generate\`, ${mode} run, \`@nodii/dev\` ${VERSION}, ${source}).`,
832
+ "",
833
+ "A Surface is clean when it has no unmapped layer. Total counts every selected Surface, including those not published or not generated yet.",
834
+ "",
835
+ "| Module | Clean / total | Not published | Not generated yet | Unmapped | By kind |",
836
+ "|---|---:|---:|---:|---:|---|",
837
+ ...board.map((m) => `| ${m.module} | ${m.clean} / ${m.total} | ${m.unpublished.length} | ${m.notGeneratedYet.length} | ${m.unmapped} | ${byKindText(m.byKind)} |`),
838
+ ];
839
+ const skipped = board.filter((m) => m.unpublished.length);
840
+ if (skipped.length) lines.push("", "**Not published, so not generated or scored:**", ...skipped.map((m) => `- ${m.module}: ${namesText(m.unpublished)}`));
841
+ return lines.join("\n");
842
+ }
843
+
844
+ /** The design-system commit a run read, when the checkout has one. */
845
+ function checkoutCommit(root, exec) {
846
+ try {
847
+ return String(exec("git", ["rev-parse", "--short=9", "HEAD"], { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] })).trim() || null;
848
+ } catch {
849
+ return null;
850
+ }
851
+ }
852
+
789
853
  /**
790
854
  * surface generate: read (or --fetch) each Surface's tree, emit its file,
791
855
  * then print, --write or --check. Exit 1 on a --check difference.
@@ -795,6 +859,8 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
795
859
  if (rest.length > 1 || (rest.length && f.all)) throw new CliError("USAGE", SURFACE_USAGE, 2);
796
860
  if (f.write && f.check) throw new CliError("USAGE", "--write and --check are separate runs: --write updates the files, --check refuses a difference", 2);
797
861
  if (f.check && f.fetch) throw new CliError("USAGE", "--check regenerates from the committed trees and never reads Figma; drop --fetch", 2);
862
+ const postTo = f["post-scoreboard"];
863
+ if (postTo === true || postTo === "") throw new CliError("USAGE", "--post-scoreboard needs an issue key, for example DESIGN-SYSTEM-249", 2);
798
864
  const { env = process.env, exec = execFileSync, log = (line) => process.stderr.write(`${line}\n`), figmaGet: injected, docs, cwd } = deps;
799
865
  const root = findRepoRoot(cwd);
800
866
  const rows = deps.catalog ?? loadCatalog(root, { exec });
@@ -803,16 +869,25 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
803
869
  // file); the rest are listed as not generated yet. A generated file without its tree fails below.
804
870
  const generated = (row) => existsSync(treePath(root, row)) || existsSync(generatedPath(root, row));
805
871
  const targets = f.all && !f.fetch ? selected.filter(generated) : selected;
806
- const notYet = f.all && !f.fetch ? selected.filter((row) => !generated(row)).map((row) => row.id) : [];
872
+ const notYetRows = f.all && !f.fetch ? selected.filter((row) => !generated(row)) : [];
873
+ const notYet = notYetRows.map((row) => row.id);
807
874
 
808
875
  let figmaGet = injected;
809
876
  const indexes = new Map();
810
877
  const trees = new Map();
878
+ const unpublished = [];
811
879
  for (const row of targets) {
812
880
  const path = treePath(root, row);
813
881
  if (f.fetch) {
814
882
  figmaGet ??= pacedFigma(figmaTokenFrom(env), { log });
815
883
  if (!indexes.has(row.fileKey)) indexes.set(row.fileKey, await setIndex(figmaGet, row.fileKey));
884
+ // --all covers a module: one unpublished Surface is reported, and the rest still generate.
885
+ // A Surface named on its own stays a refusal, because the run has nothing else to do.
886
+ if (f.all && !indexes.get(row.fileKey).has(row.componentSetKey)) {
887
+ log(`skipping ${row.componentSetName ?? row.id}: not among ${row.fileKey}'s published component sets`);
888
+ unpublished.push(row);
889
+ continue;
890
+ }
816
891
  log(`reading ${row.componentSetName ?? row.id} from Figma`);
817
892
  trees.set(row, await fetchSurfaceTree(figmaGet, row, { index: indexes.get(row.fileKey), version: pinnedVersion(root, row, f["figma-version"]) }));
818
893
  } else if (existsSync(path)) {
@@ -823,7 +898,7 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
823
898
  }
824
899
 
825
900
  const ds = loadDesignSystem(root, { exec, docs });
826
- const results = targets.map((row) => {
901
+ const results = targets.filter((row) => trees.has(row)).map((row) => {
827
902
  const tree = trees.get(row);
828
903
  if (tree.componentSetKey !== row.componentSetKey) throw new CliError("SURFACE_TREE_MISMATCH", `${relative(root, treePath(root, row))} holds set ${tree.componentSetKey}, not ${row.componentSetKey}`, 1);
829
904
  return { row, tree, ...emitSurface(tree, row, ds) };
@@ -853,23 +928,44 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
853
928
  writeFileSync(target, target.endsWith(".json") ? stable(report) : unmappedMarkdown(report));
854
929
  }
855
930
 
931
+ const mode = f.check ? "check" : f.write ? "write" : "print";
932
+ const scoreboard = surfaceScoreboard(selected, results, { unpublished, notGeneratedYet: notYetRows });
933
+ let posted = null;
934
+ if (postTo) {
935
+ const commit = checkoutCommit(root, exec);
936
+ const source = `${f.fetch ? "trees read from Figma" : "committed trees"}${commit ? ` in checkout \`${commit}\`` : ""}`;
937
+ const { comment = async (key, body) => devRequest("POST", `/api/v1/issues/${encodeURIComponent(key)}/comment`, { body, onBehalfOf: (await readConfig()).person }) } = deps;
938
+ try {
939
+ await comment(String(postTo), scoreboardMarkdown(scoreboard, { mode, source }));
940
+ } catch (error) {
941
+ throw new CliError("COMMENT_FAILED", `The run finished${f.write ? " and its files are written" : ""}, but the scoreboard was not posted on ${postTo} (${error?.code ?? "error"}: ${error?.message ?? error}).`, 1);
942
+ }
943
+ posted = String(postTo);
944
+ }
945
+
856
946
  const payload = {
857
947
  data: {
858
- mode: f.check ? "check" : f.write ? "write" : "print",
948
+ mode,
859
949
  surfaces: results.map((r) => ({ id: r.row.id, componentSetKey: r.row.componentSetKey, file: r.file, states: r.states, unmapped: r.unmapped.length })),
860
950
  differences,
861
951
  notGeneratedYet: notYet,
952
+ unpublished: unpublished.map((row) => ({ id: row.id, componentSetKey: row.componentSetKey, fileKey: row.fileKey })),
953
+ scoreboard,
954
+ scoreboardPostedOn: posted,
862
955
  unmapped: report,
863
956
  },
864
957
  };
865
958
  const human = () => {
866
- if (!f.write && !f.check && results.length === 1) return results[0].code;
959
+ if (!f.write && !f.check && !f.all && results.length === 1) return results[0].code;
867
960
  const lines = results.map(
868
961
  (r) => `${f.write ? "wrote" : f.check ? (differences.some((d) => d.id === r.row.id) ? "DIFFERS" : "equal") : "generated"}\t${r.file}\t${r.states.length} state${r.states.length === 1 ? "" : "s"}\t${r.unmapped.length} unmapped layer${r.unmapped.length === 1 ? "" : "s"}`,
869
962
  );
870
963
  if (notYet.length) lines.push(`not generated yet: ${notYet.length} catalog Surface${notYet.length === 1 ? "" : "s"} (no committed tree); generate one with \`nodii-dev surface generate <componentSetKey> --fetch --write\``);
964
+ if (unpublished.length) lines.push(`not published: ${unpublished.length} Surface${unpublished.length === 1 ? "" : "s"} skipped, not generated or scored: ${unpublished.map((row) => row.id).join(", ")}`);
871
965
  if (f.check && differences.length)
872
966
  lines.push(`SURFACE_GEN_DIFFERS: ${differences.length} product page${differences.length === 1 ? " differs" : "s differ"} from the generator's output; run \`nodii-dev surface generate --all --write\` and commit, never hand-edit a generated file`);
967
+ if (f.all) lines.push("", scoreboardText(scoreboard));
968
+ if (posted) lines.push(`scoreboard posted on ${posted}`);
873
969
  return lines.join("\n");
874
970
  };
875
971
  return { payload, human, exitCode: f.check && differences.length ? 1 : 0 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.85",
3
+ "version": "0.6.87",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {