@nodii/dev 0.6.105 → 0.6.107

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
@@ -54,6 +54,9 @@ import {
54
54
  figmaScopeSetText,
55
55
  figmaSubmit,
56
56
  figmaWithdrawItems,
57
+ laneReadsRefusal,
58
+ laneReadsScript,
59
+ readLaneReads,
57
60
  figmaWithdrawItemsText,
58
61
  WITHDRAW_ITEMS_USAGE,
59
62
  withdrawItemsFrom,
@@ -184,13 +187,18 @@ Usage: nodii-dev <command> [options] [--json]
184
187
  # --all --fetch skips and reports a Surface that is not published;
185
188
  # --post-scoreboard comments the per-module scoreboard on the issue;
186
189
  # a 429 stops the read, and --fetch --write --resume keeps what is saved
187
- figma lock FILE_KEY --title TEXT [--scope KIND:ID ...]
190
+ figma lock FILE_KEY --title TEXT [--scope KIND:ID ...] [--lane-reads FILE]
188
191
  # scopes: component:NODE page:NODE section:NODE foundations create:PAGE:NAME;
189
192
  # no --scope locks the whole file (DEC-0032)
190
193
  figma scope add CHANGE_SET --scope KIND:ID [--scope ...] # widen a held set's scopes
191
194
  figma scope set CHANGE_SET --scope KIND:ID [--scope ...] # narrow to exactly these; the rest frees
192
195
  figma publish-plan FILE_KEY # what to publish, and what to leave unchecked in Figma's dialog
193
196
  figma published FILE_KEY|CHANGE_SET --figma-version V # a file key marks every awaiting set published
197
+ figma apply CHANGE_SET --lane-reads FILE
198
+ # MW1-57.11: what you read through the Figma MCP, sent as data. Dev runs its
199
+ # gates on it with no job and no Figma call; FIGMA_READS_NEEDED names what's missing
200
+ figma lane-reads-script --nodes ID[,ID]
201
+ # prints the read-only use_figma script that gathers the nodes for --lane-reads
194
202
  figma check|log-write|submit|apply|abandon|release
195
203
  figma submit CHANGE_SET --file SUBMIT.json [--sync] [--dry-run]
196
204
  # --dry-run (submit and resubmit) runs Dev's dry run of the
@@ -211,7 +219,7 @@ Usage: nodii-dev <command> [options] [--json]
211
219
  # lane's agent, even from a stopped lane. The target can hold no other lock on
212
220
  # the file (TARGET_HOLDS_FILE_LOCK)
213
221
  figma withdraw CHANGE_SET # holder takes back a submit: in_review -> editing (or a re-submit -> applying)
214
- figma withdraw CHANGE_SET --items ID[,ID] --reason TEXT
222
+ figma withdraw CHANGE_SET --items ID[,ID] --reason TEXT [--lane-reads FILE]
215
223
  # holder, coordinator or operator: take rejected items (item or node ids)
216
224
  # out of an applying set so apply takes the approved ones. Each item's nodes
217
225
  # must be back at the set's base version first (CHANGE_ITEM_NOT_AT_BASE lists
@@ -1284,7 +1292,7 @@ export async function main(argv = process.argv.slice(2)) {
1284
1292
  }
1285
1293
  if (command === "figma") {
1286
1294
  if (action === "lock")
1287
- return emit(await figmaLock(rest[0], requireFlag(f, "title"), { scopes: scopesFrom(f) }), json, (p) => figmaLockText(p.data));
1295
+ return emit(await figmaLock(rest[0], requireFlag(f, "title"), { scopes: scopesFrom(f), ...(f["lane-reads"] ? { laneReads: await readLaneReads(f["lane-reads"]) } : {}) }).catch((error) => { throw laneReadsRefusal(error); }), json, (p) => figmaLockText(p.data));
1288
1296
  if (action === "scope") {
1289
1297
  if (!["add", "set"].includes(rest[0]) || !rest[1] || rest.length > 2) throw new CliError("USAGE", "figma scope add|set CHANGE_SET --scope KIND:ID [--scope ...]", 2);
1290
1298
  if (rest[0] === "set") return emit(await figmaScopeSet(rest[1], scopesFrom(f)), json, (p) => figmaScopeSetText(rest[1], p.data));
@@ -1355,6 +1363,18 @@ export async function main(argv = process.argv.slice(2)) {
1355
1363
  }
1356
1364
  if (action === "log-write")
1357
1365
  return emit(await figmaLogWrite(rest[0], requireFlag(f, "tool"), requireFlag(f, "nodes").split(",").filter(Boolean)), json);
1366
+ if (action === "lane-reads-script") return console.log(laneReadsScript(f.nodes));
1367
+ if (action === "apply" && f["lane-reads"]) {
1368
+ const laneReads = await readLaneReads(f["lane-reads"]);
1369
+ return emit(
1370
+ await devRequest(
1371
+ "POST",
1372
+ `/api/v1/design/change-sets/${encode(rest[0])}/apply`,
1373
+ { figmaVersion: f["figma-version"] && f["figma-version"] !== true ? f["figma-version"] : laneReads.figmaVersion, laneReads },
1374
+ ).catch((error) => { throw laneReadsRefusal(error); }),
1375
+ json,
1376
+ );
1377
+ }
1358
1378
  if (["apply", "published", "abandon"].includes(action)) {
1359
1379
  const payload = f.file
1360
1380
  ? JSON.parse(await readFile(f.file, "utf8"))
@@ -1383,7 +1403,7 @@ export async function main(argv = process.argv.slice(2)) {
1383
1403
  if (action === "withdraw") {
1384
1404
  if (rest.length > 1) throw new CliError("USAGE", `figma withdraw CHANGE_SET | ${WITHDRAW_ITEMS_USAGE}`, 2);
1385
1405
  if (f.items !== undefined)
1386
- return emit(await figmaWithdrawItems(rest[0], withdrawItemsFrom(f), f.reason === true ? "" : f.reason), json, (p) => figmaWithdrawItemsText(rest[0], p.data));
1406
+ return emit(await figmaWithdrawItems(rest[0], withdrawItemsFrom(f), f.reason === true ? "" : f.reason, f["lane-reads"] ? { laneReads: await readLaneReads(f["lane-reads"]) } : {}).catch((error) => { throw laneReadsRefusal(error); }), json, (p) => figmaWithdrawItemsText(rest[0], p.data));
1387
1407
  if (f.reason !== undefined)
1388
1408
  throw new CliError("USAGE", `--reason goes with --items: ${WITHDRAW_ITEMS_USAGE} (a whole submit is withdrawn with: figma withdraw CHANGE_SET)`, 2);
1389
1409
  return emit(await figmaWithdraw(rest[0]), json, (p) => `Withdrew ${rest[0]}; it is back in ${p.data?.state ?? "editing"}.`);
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.105";
7
+ export const VERSION = "0.6.107";
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
@@ -642,13 +642,14 @@ export const holdsSet = (check) => Boolean(check?.changeSetId) && (check.allowed
642
642
 
643
643
  const isWholeFile = (scopes) => !scopes?.length || scopes.some((s) => s.kind === "file");
644
644
 
645
- export async function figmaLock(value, title, { scopes = [], request = devRequest, laneScope = currentLaneFigmaScope } = {}) {
645
+ export async function figmaLock(value, title, { scopes = [], request = devRequest, laneScope = currentLaneFigmaScope, laneReads } = {}) {
646
646
  const key = figmaFileKey(value);
647
647
  // The lane's Freeze bounds which files and component sets it may lock.
648
648
  await assertWithinLaneScope(await laneScope({}, { request }), key, scopes);
649
649
  const result = await fileCall(key, request)("POST", `/api/v1/design/files/${encode(key)}/lock`, {
650
650
  changeSetTitle: title,
651
651
  ...(scopes.length ? { scopes } : {}),
652
+ ...(laneReads ? { laneReads } : {}),
652
653
  });
653
654
  // A Dev that doesn't know scopes ignores them and locks the whole file,
654
655
  // which blocks every other lane: say so loudly instead of exiting 0.
@@ -950,11 +951,11 @@ const WITHDRAW_ITEMS_REFUSALS = {
950
951
  * must already be back at the set's base version; apply then takes the
951
952
  * approved items alone, and the scopes only those items sat in are released.
952
953
  */
953
- export async function figmaWithdrawItems(id, items, reason, { request = devRequest } = {}) {
954
+ export async function figmaWithdrawItems(id, items, reason, { request = devRequest, laneReads } = {}) {
954
955
  if (!id || !items?.length) throw new CliError("USAGE", WITHDRAW_ITEMS_USAGE, 2);
955
956
  if (typeof reason !== "string" || !reason.trim()) throw new CliError("USAGE", `--reason needs a reason: ${WITHDRAW_ITEMS_USAGE}`, 2);
956
957
  try {
957
- return await request("POST", `/api/v1/design/change-sets/${encode(id)}/withdraw-items`, { items, reason: reason.trim() });
958
+ return await request("POST", `/api/v1/design/change-sets/${encode(id)}/withdraw-items`, { items, reason: reason.trim(), ...(laneReads ? { laneReads } : {}) });
958
959
  } catch (error) {
959
960
  const say = WITHDRAW_ITEMS_REFUSALS[error?.code];
960
961
  if (say) throw new CliError(error.code, say(id, error.message, error.details), error.exitCode ?? 1, error.details);
@@ -974,3 +975,69 @@ export const figmaWithdrawItemsText = (id, d = {}) => {
974
975
  `Next: apply the approved items with nodii-dev figma apply ${d.changeSetId ?? id} --figma-version V`,
975
976
  ].join("\n");
976
977
  };
978
+
979
+ // MW1-57.11: the lane reads Figma through the MCP in its own session, and sends
980
+ // what it read. Dev runs the same gates on that, with no job and no Figma call.
981
+ export async function readLaneReads(path, { read = readFile } = {}) {
982
+ let reads;
983
+ try { reads = JSON.parse(await read(path, "utf8")); }
984
+ catch (error) { throw new CliError("USAGE", `--lane-reads ${path} is not readable JSON: ${error.message}`, 2); }
985
+ if (typeof reads?.figmaVersion !== "string" || !reads.figmaVersion || !Array.isArray(reads.nodes))
986
+ throw new CliError("USAGE", `--lane-reads ${path} needs figmaVersion and nodes. Print the MCP script that gathers nodes with: nodii-dev figma lane-reads-script --nodes A,B`, 2);
987
+ return reads;
988
+ }
989
+
990
+ /** Says what to do about a read Dev asked for. Any other error is left as it is. */
991
+ export function laneReadsRefusal(error) {
992
+ if (error?.code !== "FIGMA_READS_NEEDED") return error;
993
+ const ids = error.details?.nodeIds ?? [];
994
+ const next = error.details?.read === "base"
995
+ ? "Compare each with the set's base, add it to base.atBase or base.offBase in the lane-reads file, and say how in base.how. Then send this again."
996
+ : ids.length
997
+ ? `Add them with the MCP: nodii-dev figma lane-reads-script --nodes ${ids.join(",")}\nThen send this again.`
998
+ : "This check has no MCP path yet: tell the Steward (hub-295).";
999
+ return new CliError(error.code, `${error.message}\n${next}`, error.exitCode ?? 1, error.details);
1000
+ }
1001
+
1002
+ const nodeIdList = (value) => String(value === true ? "" : (value ?? "")).split(",").map((x) => x.trim()).filter(Boolean);
1003
+
1004
+ /** A script for the Figma MCP's use_figma: where each node sits, as --lane-reads takes it. It only reads. */
1005
+ export function laneReadsScript(nodes) {
1006
+ const ids = nodeIdList(nodes);
1007
+ if (!ids.length) throw new CliError("USAGE", "figma lane-reads-script --nodes ID[,ID]", 2);
1008
+ return `// Run through the Figma MCP's use_figma. It only reads. Set figmaVersion in the
1009
+ // result to the version you read at (for a new claim, the file's newest version), and add
1010
+ // base: { atBase, offBase, how } if Dev asks for a base comparison.
1011
+ const ids = ${JSON.stringify(ids)};
1012
+ const nodes = [];
1013
+ const gone = [];
1014
+ for (const id of ids) {
1015
+ const node = await figma.getNodeByIdAsync(id);
1016
+ const ancestorIds = [];
1017
+ let page = null;
1018
+ let set = null;
1019
+ let top = node && (node.type === "COMPONENT" || node.type === "COMPONENT_SET") ? node : null;
1020
+ for (let at = node ? node.parent : null; at; at = at.parent) {
1021
+ if (at.type === "PAGE") { page = at; break; }
1022
+ ancestorIds.unshift(at.id);
1023
+ if (at.type === "COMPONENT_SET" && !set) set = at;
1024
+ if (at.type === "COMPONENT" || at.type === "COMPONENT_SET") top = at;
1025
+ }
1026
+ // A node with no page is deleted, whatever else still answers for it.
1027
+ if (!node || !page) { gone.push(id); continue; }
1028
+ nodes.push({
1029
+ id,
1030
+ type: node.type,
1031
+ name: node.name,
1032
+ pageId: page.id,
1033
+ pageName: page.name,
1034
+ ancestorIds,
1035
+ componentSetId: set ? set.id : null,
1036
+ componentSetName: set ? set.name : null,
1037
+ topComponent: top ? { id: top.id, name: top.name } : null,
1038
+ });
1039
+ }
1040
+ const pages = figma.root.children.map((page) => ({ id: page.id, name: page.name }));
1041
+ return { figmaVersion: "SET-ME", pages, nodes, gone };
1042
+ `;
1043
+ }
package/dist/flags.js CHANGED
@@ -66,12 +66,13 @@ export const COMMAND_FLAGS = {
66
66
  "docs ratify": ["domain", "decision", ...WAIT],
67
67
  "figma submit": ["file", "figma-version", ...SUBMIT_MODE, "dry-run"],
68
68
  "figma resubmit": [...SUBMIT_MODE, "dry-run"],
69
- "figma withdraw": ["items", "reason"],
69
+ "figma withdraw": ["items", "reason", "lane-reads"],
70
+ "figma lane-reads-script": ["nodes"],
70
71
  "figma abandon": ["file"],
71
72
  // hub-260: list takes these; show takes none.
72
73
  "figma changeset": ["file", "actionable", "all", "limit"],
73
- "figma apply": ["file", "figma-version"],
74
- "figma lock": ["title", "scope"],
74
+ "figma apply": ["file", "figma-version", "lane-reads"],
75
+ "figma lock": ["title", "scope", "lane-reads"],
75
76
  "surface generate": ["write", "check", "fetch", "all", "module", "type", "figma-version", "report", "post-scoreboard", "resume"],
76
77
  };
77
78
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.105",
3
+ "version": "0.6.107",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {