@nodii/dev 0.6.63 → 0.6.65

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
@@ -691,3 +691,80 @@ export function figmaPublishPlanText(plan) {
691
691
  : []),
692
692
  ].join("\n");
693
693
  }
694
+
695
+ export const WITHDRAW_ITEMS_USAGE = "figma withdraw CHANGE_SET --items ID[,ID] --reason TEXT";
696
+
697
+ /** `--items A,B --items C` → ["A", "B", "C"], each an item id or a Figma node id. */
698
+ export function withdrawItemsFrom(flags) {
699
+ const given = [flags.items].flat().filter((x) => x !== undefined);
700
+ if (given.some((x) => x === true)) throw new CliError("USAGE", `--items needs item ids: ${WITHDRAW_ITEMS_USAGE}`, 2);
701
+ const items = [...new Set(given.flatMap((x) => String(x).split(",")).map((x) => x.trim()).filter(Boolean))];
702
+ if (!items.length) throw new CliError("USAGE", `--items needs item ids: ${WITHDRAW_ITEMS_USAGE}`, 2);
703
+ return items;
704
+ }
705
+
706
+ const indented = (ids) => ids.map((x) => ` ${x}`);
707
+
708
+ // Dev's refusals of withdrawDesignChangeItems, said in terms of what to do next.
709
+ const WITHDRAW_ITEMS_REFUSALS = {
710
+ CHANGE_SET_NOT_FOUND: (id) => `No change set ${id} in Dev.`,
711
+ WITHDRAW_NOT_ALLOWED: (id) => `Only ${id}'s holder, a machine's coordinator or the operator can withdraw its items.`,
712
+ INVALID_CHANGE_SET_STATE: (id, message) => `${message}\nItems are withdrawn only while ${id} is applying (decided, with rejected items). Check it with: nodii-dev figma changeset show ${id}`,
713
+ CHANGE_SET_HAS_NO_BASE_VERSION: (id, message) => `${message}\nDev can't tell whether the items' nodes are back at base, so it can't withdraw them.`,
714
+ CHANGE_SET_CHANGED: (id, message) => `${message}\n${id} changed while withdrawing; read it with nodii-dev figma changeset show ${id} and run this again.`,
715
+ CHANGE_ITEM_NOT_AT_BASE: (id, message, d) => {
716
+ const nodes = d?.nodeIds ?? [];
717
+ if (!nodes.length) return message;
718
+ return [
719
+ `${nodes.length} node(s) of ${d?.changeSetId ?? id} still differ from its base version${d?.baseVersion ? ` (${d.baseVersion})` : ""}:`,
720
+ ...indented(nodes),
721
+ "Put each back as it was at base (remove it if the set added it), then run this again. Nothing was withdrawn.",
722
+ ].join("\n");
723
+ },
724
+ CHANGE_ITEM_NOT_REJECTED: (id, message, d) => {
725
+ if (!d?.unmatched?.length) return message;
726
+ return [
727
+ `Only rejected items can be withdrawn. Not a rejected item in ${id}:`,
728
+ ...indented(d.unmatched),
729
+ ...(d.rejected?.length
730
+ ? [`${id}'s rejected items (item id figma node):`, ...indented(d.rejected.map((i) => `${i.id} ${i.figmaNodeId ?? "-"}`))]
731
+ : [`${id} has no rejected items.`]),
732
+ "Nothing was withdrawn.",
733
+ ].join("\n");
734
+ },
735
+ CHANGE_ITEM_AMBIGUOUS: (id, message, d) =>
736
+ d?.ambiguous?.length
737
+ ? [`More than one rejected item of ${id} sits on Figma node:`, ...indented(d.ambiguous), "Name those items by item id instead (nodii-dev figma changeset show " + id + "). Nothing was withdrawn."].join("\n")
738
+ : message,
739
+ };
740
+
741
+ /**
742
+ * Withdraw a set's rejected items (withdrawDesignChangeItems): the holder, a
743
+ * coordinator or the operator, while the set is applying. Each item's nodes
744
+ * must already be back at the set's base version; apply then takes the
745
+ * approved items alone, and the scopes only those items sat in are released.
746
+ */
747
+ export async function figmaWithdrawItems(id, items, reason, { request = devRequest } = {}) {
748
+ if (!id || !items?.length) throw new CliError("USAGE", WITHDRAW_ITEMS_USAGE, 2);
749
+ if (typeof reason !== "string" || !reason.trim()) throw new CliError("USAGE", `--reason needs a reason: ${WITHDRAW_ITEMS_USAGE}`, 2);
750
+ try {
751
+ return await request("POST", `/api/v1/design/change-sets/${encode(id)}/withdraw-items`, { items, reason: reason.trim() });
752
+ } catch (error) {
753
+ const say = WITHDRAW_ITEMS_REFUSALS[error?.code];
754
+ if (say) throw new CliError(error.code, say(id, error.message, error.details), error.exitCode ?? 1, error.details);
755
+ throw scopeRefusal(error, id) ?? error;
756
+ }
757
+ }
758
+
759
+ export const figmaWithdrawItemsText = (id, d = {}) => {
760
+ const withdrawn = d.withdrawn ?? [];
761
+ const released = d.released ?? [];
762
+ const held = d.scopes ?? [];
763
+ return [
764
+ `Withdrew ${withdrawn.length} item(s) from ${d.changeSetId ?? id}; they will never publish:`,
765
+ ...indented(withdrawn),
766
+ released.length ? `Released ${released.length} scope(s): ${released.map(scopeText).join(", ")}` : "Released no scope (another item still sits in each).",
767
+ `Still holds ${held.length} scope(s)${held.length ? `: ${held.map(scopeText).join(", ")}` : ""}.`,
768
+ `Next: apply the approved items with nodii-dev figma apply ${d.changeSetId ?? id} --figma-version V`,
769
+ ].join("\n");
770
+ };
package/dist/flags.js CHANGED
@@ -48,7 +48,7 @@ export const COMMAND_FLAGS = {
48
48
  "docs ratify": ["domain", "decision", ...WAIT],
49
49
  "figma submit": ["file", "figma-version", ...SUBMIT_MODE, "dry-run"],
50
50
  "figma resubmit": [...SUBMIT_MODE, "dry-run"],
51
- "figma withdraw": [],
51
+ "figma withdraw": ["items", "reason"],
52
52
  "figma abandon": ["file"],
53
53
  "figma apply": ["file", "figma-version"],
54
54
  "figma lock": ["title", "scope"],
package/dist/lanes.js CHANGED
@@ -821,7 +821,10 @@ export async function laneCommand(action, args, flags, deps = {}) {
821
821
  const reason = requireFlag(flags, "reason");
822
822
  const toAgentId = flags["to-agent"] ?? (await config()).agentId;
823
823
  if (!toAgentId) throw new CliError("USAGE", "lane transfer needs a registered agent, or --to-agent ID.", 2);
824
- const payload = await request("POST", `/api/v1/lanes/${encode(id)}/transfer`, { toAgentId, reason, ...via });
824
+ const payload = await request("POST", `/api/v1/lanes/${encode(id)}/transfer`, { toAgentId, reason, ...via }).catch((error) => {
825
+ if (error?.code !== "LANE_ALREADY_TERMINAL") throw error;
826
+ throw new CliError(error.code, `Lane ${id} has ended, so it cannot move. Its open change sets can: nodii-dev figma transfer CS --to LIVE_LANE --reason TEXT (coordinator or staff).`, 1);
827
+ });
825
828
  // The fresh run acts as the recovering agent, so the lane's config names it.
826
829
  const launched = await launchReserved(payload, async () => {
827
830
  const owner = payload.data.run.ownerAgentId;
@@ -30,7 +30,7 @@
30
30
  // it until it returns [] (each round can reveal instances inside slot
31
31
  // content).
32
32
 
33
- export const VERSION = "1.0.10";
33
+ export const VERSION = "1.0.11";
34
34
 
35
35
  /** @typedef {{ nodeId: string, check: string, detail: string }} Finding */
36
36
  /**
@@ -628,6 +628,37 @@ export function checkConformance({
628
628
  for (const r of roles)
629
629
  for (const label of r.labels ?? [])
630
630
  labelRoles.set(label.trim().toLowerCase(), r);
631
+ // Labels that mark a role only inside named components: they win there.
632
+ const scopedLabels = new Map();
633
+ for (const r of roles)
634
+ for (const { labels, within } of r.labelsIn ?? [])
635
+ for (const label of labels) {
636
+ const key = label.trim().toLowerCase();
637
+ const scopes = scopedLabels.get(key) ?? [];
638
+ scopes.push({
639
+ role: r,
640
+ within: new Set(within.map((name) => name.trim().toLowerCase())),
641
+ });
642
+ scopedLabels.set(key, scopes);
643
+ }
644
+ const roleOfLabel = (a, n, label) => {
645
+ const scopes = scopedLabels.get(label);
646
+ if (scopes) {
647
+ const names = new Set();
648
+ for (const x of a.ancestors(n)) {
649
+ names.add(x.name?.toLowerCase());
650
+ const set = a.setOf({
651
+ componentId: x.type === "INSTANCE" ? x.componentId : x.id,
652
+ });
653
+ if (set?.name) names.add(set.name.toLowerCase());
654
+ }
655
+ const scoped = scopes.find((s) =>
656
+ [...s.within].some((name) => names.has(name))
657
+ );
658
+ if (scoped) return scoped.role;
659
+ }
660
+ return labelRoles.get(label);
661
+ };
631
662
  const librarySetNames = new Set();
632
663
  const usedRoles = new Set();
633
664
  const analyses = Object.values(nodes ?? {})
@@ -872,7 +903,7 @@ export function checkConformance({
872
903
  // (even one whose variant carries the label) and for a label it
873
904
  // overrode; a button a library block composes with its own label is
874
905
  // the library's (MW6-17).
875
- const role = labelRoles.get(text.toLowerCase());
906
+ const role = roleOfLabel(a, n, text.toLowerCase());
876
907
  if (role) {
877
908
  const up = a.ancestors(n);
878
909
  const holder = up
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.63",
3
+ "version": "0.6.65",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {