@nodii/dev 0.6.66 → 0.6.68

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/figma.js CHANGED
@@ -663,9 +663,49 @@ export function isChangeSetId(value) {
663
663
  return true;
664
664
  }
665
665
 
666
- export async function figmaPublishPlan(value, { request = devRequest } = {}) {
666
+ // The plan reads the design file for minutes on a large library, so Dev works it
667
+ // out as a job (DESIGN-SYSTEM-PARITY-153): the POST answers 202, here it's polled
668
+ // until it ends. Dev's job stops itself after an hour; stop a little later.
669
+ const PLAN_JOB_WAIT_MS = 65 * 60_000;
670
+ const planJobPath = (key, id) => `/api/v1/design/files/${encode(key)}/publish-plan/jobs/${encode(id)}`;
671
+
672
+ /** A finished plan job as the plan itself: the plan, or the refusal Dev ended it with. */
673
+ export function planJobOutcome(job) {
674
+ if (job.state === "succeeded") return { data: job.result };
675
+ const e = job.error ?? {};
676
+ if (e.code === "PUBLISH_PLAN_JOB_LOST") throw new CliError(e.code, `${e.message ?? "Dev lost this job"} (job ${job.id} on ${job.fileKey}). Run the same command again.`, 1, e.details);
677
+ throw new CliError(!e.code || GATEWAY.has(e.code) ? "PUBLISH_PLAN_JOB_FAILED" : e.code, e.message ?? `Dev's publish plan job ${job.id} failed with HTTP ${job.httpStatus}`, 1, e.details);
678
+ }
679
+
680
+ /** Starts or joins the file's plan job (startDesignPublishPlan) and polls it until it ends, printing progress. */
681
+ export async function figmaPublishPlan(value, { request = devRequest, sleep = delay, progress = stderrLine, now = Date.now } = {}) {
667
682
  const key = figmaFileKey(value);
668
- return fileCall(key, request)("GET", `/api/v1/design/files/${encode(key)}/publish-plan`);
683
+ const call = fileCall(key, request);
684
+ let job = (await call("POST", `/api/v1/design/files/${encode(key)}/publish-plan`, {})).data;
685
+ const start = now();
686
+ let printed = start;
687
+ let misses = 0;
688
+ for (let n = 0; !DONE.has(job.state); n++) {
689
+ if (now() - start > PLAN_JOB_WAIT_MS)
690
+ throw new CliError("PUBLISH_PLAN_JOB_TIMEOUT", `Dev's publish plan job ${job.id} on ${key} is still running after ${Math.round(PLAN_JOB_WAIT_MS / 60_000)} minutes. Run the same command again to join it.`, 1);
691
+ await sleep(JOB_POLL_MS[Math.min(n, JOB_POLL_MS.length - 1)]);
692
+ try {
693
+ job = (await call("GET", planJobPath(key, job.id))).data;
694
+ misses = 0;
695
+ } catch (error) {
696
+ if (!TRANSIENT.has(error?.code)) throw error;
697
+ // A poll that hit the edge's gateway or a blip retries; the job runs on in Dev.
698
+ if (++misses > 5) throw new CliError("PUBLISH_PLAN_JOB_UNREACHABLE", `Lost touch with Dev (${error.code}) while its publish plan job ${job.id} on ${key} runs. Run the same command again to join it.`, 1);
699
+ progress(`polling ${job.id} again (${error.code})`);
700
+ continue;
701
+ }
702
+ if (!DONE.has(job.state) && now() - printed >= JOB_PROGRESS_MS) {
703
+ printed = now();
704
+ const done = job.progress ? `, ${job.progress.compared} of ${job.progress.total} components compared` : "";
705
+ progress(`${key}: publish plan job ${job.id} still running (${Math.round((printed - start) / 1000)} s${done})`);
706
+ }
707
+ }
708
+ return planJobOutcome(job);
669
709
  }
670
710
 
671
711
  const planLine = (x) => ` ${x.nodeId ?? (x.kind ? scopeText(x) : "(no node)")} ${x.name ?? ""} (${x.changeSetId} ${x.state}${x.title ? `: ${x.title}` : ""})`;
package/dist/review.js CHANGED
@@ -26,6 +26,8 @@ export const MAX_DIFF_CHARS = 600_000;
26
26
  export const CODE_NOT_REQUIRED = { decision: "DEC-0085" };
27
27
  const PASSING = { rules: ["CLEAN"], figma: ["CLEAN", "NOT_APPLICABLE"], code: ["CLEAN", "NOT_REQUIRED"] };
28
28
  const UNAVAILABLE = "REVIEWER_UNAVAILABLE";
29
+ // Figma errors that mean Figma was not reachable in time, not that the design failed.
30
+ const FIGMA_OUTAGE = ["FIGMA_TIMEOUT", "FIGMA_UNREACHABLE", "FIGMA_RATE_LIMITED"];
29
31
 
30
32
  class ReviewerError extends Error {
31
33
  constructor(outcome, message) {
@@ -353,9 +355,47 @@ export function boundaryFrames(figma, surfaces) {
353
355
  });
354
356
  }
355
357
 
356
- /** DEV-REV-9, design-check part: designCheck on every boundary frame; per-state frame comparison is Q-162. */
357
- export async function figmaFindings(figma, { catalog, check }) {
358
- const frames = boundaryFrames(figma, figma.some((file) => file.componentSetKeys?.length) ? await catalog() : []);
358
+ /**
359
+ * MW2-38.3: the nodes of the change sets a lane's agent holds in each
360
+ * boundary file Dev registers as the design system. Returns
361
+ * { fileKey: { changeSets: [id], nodes: [nodeId] } } for files with at least
362
+ * one node. Dev's holderAgentId filter is checked again here, because a Dev
363
+ * without it ignores the parameter and lists every set on the file. Items the
364
+ * lane withdrew are left out; rejected items stay in until withdrawn. A
365
+ * removed item's node is gone from Figma, so there is nothing to check.
366
+ */
367
+ export async function laneChangeSetNodes(request, agentId, fileKeys) {
368
+ if (!agentId || !fileKeys.length) return {};
369
+ const files = (await request("GET", "/api/v1/design/files")).data ?? [];
370
+ const ds = new Set(files.filter((file) => file.kind === "design-system").map((file) => file.fileKey));
371
+ const scoped = {};
372
+ for (const fileKey of [...new Set(fileKeys)].filter((key) => ds.has(key))) {
373
+ const rows = (await request("GET", `/api/v1/design/change-sets?holderAgentId=${encodeURIComponent(agentId)}&fileKey=${encodeURIComponent(fileKey)}&limit=500`)).data ?? [];
374
+ const held = rows.filter((row) => row.holder?.agent?.id === agentId && row.fileKey === fileKey && row.state !== "abandoned");
375
+ const nodes = new Set();
376
+ const changeSets = [];
377
+ for (const row of held) {
378
+ const set = (await request("GET", `/api/v1/design/change-sets/${encodeURIComponent(row.id)}`)).data;
379
+ const live = (set?.items ?? []).filter((item) => item.decision !== "withdrawn" && item.change !== "removed" && item.figmaNodeId);
380
+ if (!live.length) continue;
381
+ changeSets.push(row.id);
382
+ for (const item of live) nodes.add(item.figmaNodeId);
383
+ }
384
+ if (nodes.size) scoped[fileKey] = { changeSets, nodes: [...nodes] };
385
+ }
386
+ return scoped;
387
+ }
388
+
389
+ /**
390
+ * DEV-REV-9, design-check part: designCheck on every boundary frame; per-state
391
+ * frame comparison is Q-162. A boundary file with held change-set nodes
392
+ * (MW2-38.3, from laneChangeSetNodes) is checked on those nodes only, never
393
+ * as the whole file.
394
+ */
395
+ export async function figmaFindings(figma, { catalog, check, changeSets = {} }) {
396
+ const scopedFrames = Object.entries(changeSets).flatMap(([fileKey, scoped]) => scoped.nodes.map((nodeId) => ({ fileKey, nodeId, state: "default" })));
397
+ const rest = figma.filter((file) => !changeSets[file.fileKey]);
398
+ const frames = [...scopedFrames, ...boundaryFrames(rest, rest.some((file) => file.componentSetKeys?.length) ? await catalog() : [])];
359
399
  const findings = [];
360
400
  const versions = new Set();
361
401
  for (const frame of frames) {
@@ -378,6 +418,7 @@ export async function figmaFindings(figma, { catalog, check }) {
378
418
  frames: frames.map((frame) => ({ fileKey: frame.fileKey, nodeId: frame.nodeId, state: frame.state, frameUrl: frame.nodeId ? frameUrl(frame.fileKey, frame.nodeId) : `https://www.figma.com/design/${frame.fileKey}` })),
379
419
  libraryVersions: [...versions],
380
420
  frameComparison: "not_built",
421
+ ...(scopedFrames.length ? { changeSets: Object.entries(changeSets).map(([fileKey, scoped]) => ({ fileKey, ids: scoped.changeSets, nodes: scoped.nodes.length })), rule: "MW2-38.3" } : {}),
381
422
  },
382
423
  };
383
424
  }
@@ -480,10 +521,20 @@ export async function runLaneCheck(ref, flags, { request, lane, freeze, current,
480
521
  } else {
481
522
  const boundary = freeze.boundaries.figma;
482
523
  try {
524
+ let changeSets;
525
+ try { changeSets = await laneChangeSetNodes(request, lane.agentId, boundary.map((file) => file.fileKey)); }
526
+ catch (error) {
527
+ throw new ReviewerError(UNAVAILABLE, `the lane's change sets could not be read from Dev (${error?.code ?? "ERROR"}: ${error?.message ?? error}), so the Figma check cannot be scoped to their nodes (MW2-38.3) and did not fall back to the whole file`);
528
+ }
483
529
  let checked;
484
- try { checked = await figmaFindings(boundary, { catalog, check: designCheck }); }
530
+ try { checked = await figmaFindings(boundary, { catalog, check: designCheck, changeSets }); }
485
531
  catch (error) {
486
532
  if (error instanceof ReviewerError) throw error;
533
+ // A Figma outage (a read past its clock, no answer, rate limited) means
534
+ // the check did not run: recorded as not run with the reason, never as
535
+ // a failure, so an outage never blocks a push.
536
+ if (FIGMA_OUTAGE.includes(error?.code))
537
+ throw new ReviewerError(UNAVAILABLE, `not run: Figma did not answer the design check (${error.code}: ${error?.message ?? error}); nothing was checked, so rerun nodii-dev lane check once Figma answers`);
487
538
  throw new ReviewerError(["FIGMA_TOKEN_REQUIRED", "DS_CATALOG_UNAVAILABLE"].includes(error?.code) ? UNAVAILABLE : "CRASH", `design check failed (${error?.code ?? "ERROR"}: ${error?.message ?? error})`);
488
539
  }
489
540
  figma = round("figma", checked.findings, checked.inputs);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.66",
3
+ "version": "0.6.68",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {