@nodii/dev 0.6.116 → 0.6.118
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 +27 -8
- package/dist/core.js +1 -1
- package/dist/design.js +48 -4
- package/dist/figma.js +183 -14
- package/dist/flags.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -60,6 +60,8 @@ import {
|
|
|
60
60
|
readLaneReads,
|
|
61
61
|
figmaWithdrawItemsText,
|
|
62
62
|
WITHDRAW_ITEMS_USAGE,
|
|
63
|
+
removedNodesFrom,
|
|
64
|
+
removedNodesInReads,
|
|
63
65
|
withdrawItemsFrom,
|
|
64
66
|
checkSubmitPayload,
|
|
65
67
|
assertContext,
|
|
@@ -70,7 +72,7 @@ import {
|
|
|
70
72
|
scopesFrom,
|
|
71
73
|
conformanceLines,
|
|
72
74
|
} from "./figma.js";
|
|
73
|
-
export { figmaLock, figmaWithdrawItems, figmaWithdrawItemsText, submitMode, withdrawItemsFrom } from "./figma.js";
|
|
75
|
+
export { figmaLock, figmaWithdrawItems, figmaWithdrawItemsText, removedNodesFrom, removedNodesInReads, submitMode, withdrawItemsFrom } from "./figma.js";
|
|
74
76
|
import { tuneCommand } from "./tune.js";
|
|
75
77
|
import { TUNING_MODELS, pickerModelName, pickerPin, measurePickerLatency, pickTimingStats, pickTimingText, pickTimingsPath, readPickTimings } from "./gather.js";
|
|
76
78
|
import { docsCommand, rulebookCommand, rulesCommand } from "./upload.js";
|
|
@@ -212,6 +214,9 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
212
214
|
# submit gate on the same body, as design check --change-set; never writes
|
|
213
215
|
# --lane-reads (submit, resubmit, --dry-run): Dev runs no job and answers on
|
|
214
216
|
# the request from your MCP and REST reads; it names any read it still needs
|
|
217
|
+
# reads over 8 MB go up to the set in chunks first (hub-310), and a chunk
|
|
218
|
+
# that drops is sent again; the dry run of a submit past 300 node ids
|
|
219
|
+
# runs in parts and reports once
|
|
215
220
|
# SUBMIT.json: { figmaVersion, writeUp, items: [{ figmaNodeId, change, context,
|
|
216
221
|
# variants: [{ nodeId, name, context, afterPngBase64 }] }] } (DEC-0204);
|
|
217
222
|
# a missing writeUp, context or variant name, or an item with no variants,
|
|
@@ -228,12 +233,15 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
228
233
|
# lane's agent, even from a stopped lane. The target can hold no other lock on
|
|
229
234
|
# the file (TARGET_HOLDS_FILE_LOCK)
|
|
230
235
|
figma withdraw CHANGE_SET # holder takes back a submit: in_review -> editing (or a re-submit -> applying)
|
|
231
|
-
figma withdraw CHANGE_SET --items ID[,ID] --reason TEXT [--lane-reads FILE]
|
|
236
|
+
figma withdraw CHANGE_SET --items ID[,ID] --reason TEXT [--lane-reads FILE [--removed-nodes NODE[,NODE]]]
|
|
232
237
|
# holder, coordinator or operator: take rejected items (item or node ids)
|
|
233
238
|
# out of an applying set so apply takes the approved ones. Each item's nodes
|
|
234
239
|
# must be back at the set's base version first (CHANGE_ITEM_NOT_AT_BASE lists
|
|
235
240
|
# the ones that differ); a withdrawn item never publishes, and the scopes only
|
|
236
|
-
# it sat in are released
|
|
241
|
+
# it sat in are released. --removed-nodes: nodes you deleted (sent as
|
|
242
|
+
# removedNodeIds); Dev takes each as gone when your reads list it in gone and
|
|
243
|
+
# its /nodes entry is null or the empty ghost Figma answers for a deleted
|
|
244
|
+
# component or variant
|
|
237
245
|
figma resubmit CHANGE_SET PAYLOAD.json [--sync] [--dry-run] [--lane-reads FILE]
|
|
238
246
|
# holder re-submits every rejected item: applying -> in_review, round + 1;
|
|
239
247
|
# each item needs context, each variant name and context; writeUp optional
|
|
@@ -1344,10 +1352,10 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
1344
1352
|
return emit(await figmaFilePublished(rest[0], await publishedBody(f)).catch((error) => { throw laneReadsRefusal(error); }), json, (p) => figmaFilePublishedText(p.data));
|
|
1345
1353
|
// --dry-run runs Dev's dry run of the submit gate (design check --change-set)
|
|
1346
1354
|
// on the same body, and never writes (CLI-18).
|
|
1347
|
-
const dryRun = async (id, text, file) => {
|
|
1355
|
+
const dryRun = async (id, text, file, { split = false } = {}) => {
|
|
1348
1356
|
const laneReads = f["lane-reads"] ? await readLaneReads(f["lane-reads"]) : undefined;
|
|
1349
1357
|
const result = await designCheckChangeSet(undefined, { "change-set": id, ...(text ? { file } : {}), ...(f["figma-version"] ? { "figma-version": f["figma-version"] } : {}), ...(f.sync ? { sync: true } : {}), ...(f.async ? { async: true } : {}) },
|
|
1350
|
-
{ read: async () => text, ...(laneReads ? { laneReads } : {}) }).catch((error) => { throw laneReadsRefusal(error); });
|
|
1358
|
+
{ read: async () => text, split, ...(laneReads ? { laneReads } : {}) }).catch((error) => { throw laneReadsRefusal(error); });
|
|
1351
1359
|
emit(result.payload, json, result.human);
|
|
1352
1360
|
if (result.exitCode) {
|
|
1353
1361
|
if (!json) console.error(`DS_CONFORMANCE_FAILED: ${result.payload.data.findings.length} finding(s)`);
|
|
@@ -1359,7 +1367,7 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
1359
1367
|
// The same body checks as the real submit, which needs --file.
|
|
1360
1368
|
const text = f.file ? await readFile(f.file, "utf8") : null;
|
|
1361
1369
|
checkSubmitPayload(text ? JSON.parse(text) : { figmaVersion: f["figma-version"] }, f.file || "the submit (no --file)");
|
|
1362
|
-
return dryRun(rest[0], text, f.file);
|
|
1370
|
+
return dryRun(rest[0], text, f.file, { split: true });
|
|
1363
1371
|
}
|
|
1364
1372
|
if (action === "resubmit" && f["dry-run"]) {
|
|
1365
1373
|
if (!rest[0] || !rest[1]) throw new CliError("USAGE", "figma resubmit CHANGE_SET PAYLOAD.json --dry-run", 2);
|
|
@@ -1450,8 +1458,19 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
1450
1458
|
}
|
|
1451
1459
|
if (action === "withdraw") {
|
|
1452
1460
|
if (rest.length > 1) throw new CliError("USAGE", `figma withdraw CHANGE_SET | ${WITHDRAW_ITEMS_USAGE}`, 2);
|
|
1453
|
-
if (f.items !== undefined)
|
|
1454
|
-
|
|
1461
|
+
if (f.items !== undefined) {
|
|
1462
|
+
const items = withdrawItemsFrom(f);
|
|
1463
|
+
const removedNodeIds = removedNodesFrom(f);
|
|
1464
|
+
const laneReads = f["lane-reads"] ? await readLaneReads(f["lane-reads"]) : undefined;
|
|
1465
|
+
if (removedNodeIds) removedNodesInReads(removedNodeIds, laneReads);
|
|
1466
|
+
return emit(
|
|
1467
|
+
await figmaWithdrawItems(rest[0], items, f.reason === true ? "" : f.reason, { laneReads, removedNodeIds }).catch((error) => { throw laneReadsRefusal(error); }),
|
|
1468
|
+
json,
|
|
1469
|
+
(p) => figmaWithdrawItemsText(rest[0], p.data),
|
|
1470
|
+
);
|
|
1471
|
+
}
|
|
1472
|
+
if (f["removed-nodes"] !== undefined)
|
|
1473
|
+
throw new CliError("USAGE", `--removed-nodes goes with --items: ${WITHDRAW_ITEMS_USAGE}`, 2);
|
|
1455
1474
|
if (f.reason !== undefined)
|
|
1456
1475
|
throw new CliError("USAGE", `--reason goes with --items: ${WITHDRAW_ITEMS_USAGE} (a whole submit is withdrawn with: figma withdraw CHANGE_SET)`, 2);
|
|
1457
1476
|
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.
|
|
7
|
+
export const VERSION = "0.6.118";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
package/dist/design.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// library main.
|
|
9
9
|
import { readFile } from "node:fs/promises";
|
|
10
10
|
import { CliError, devRequest } from "./core.js";
|
|
11
|
-
import { conformanceLines, figmaConformance, figmaFileKey, submitMode, surfacesCheck } from "./figma.js";
|
|
11
|
+
import { conformanceLines, figmaConformance, figmaFileKey, laneReadsBody, submitMode, surfacesCheck } from "./figma.js";
|
|
12
12
|
import { checkConformance, neededMains, VERSION as CHECK_VERSION } from "./vendor/ds-conformance.mjs";
|
|
13
13
|
|
|
14
14
|
const FIGMA_API = "https://api.figma.com/v1";
|
|
@@ -439,13 +439,48 @@ export function designCheckText({ data }) {
|
|
|
439
439
|
return [...lines, ...conformanceLines(data)].join("\n");
|
|
440
440
|
}
|
|
441
441
|
|
|
442
|
+
// Dev's dry run checks at most this many node ids (an item and each of its
|
|
443
|
+
// variants count one each), refused CONFORMANCE_TOO_MANY_NODES past it.
|
|
444
|
+
export const DRY_RUN_MAX_NODES = 300;
|
|
445
|
+
const itemNodes = (item) => 1 + (item.variants?.length ?? 0);
|
|
446
|
+
/** A submit body's items in runs of at most `max` node ids; an item larger than that runs alone. */
|
|
447
|
+
export function dryRunGroups(items, max = DRY_RUN_MAX_NODES) {
|
|
448
|
+
const groups = [];
|
|
449
|
+
let group = [];
|
|
450
|
+
let nodes = 0;
|
|
451
|
+
for (const item of items) {
|
|
452
|
+
if (group.length > 0 && nodes + itemNodes(item) > max) {
|
|
453
|
+
groups.push(group);
|
|
454
|
+
group = [];
|
|
455
|
+
nodes = 0;
|
|
456
|
+
}
|
|
457
|
+
group.push(item);
|
|
458
|
+
nodes += itemNodes(item);
|
|
459
|
+
}
|
|
460
|
+
if (group.length > 0) groups.push(group);
|
|
461
|
+
return groups;
|
|
462
|
+
}
|
|
463
|
+
// The dry runs of a split body, as one report: it passes when every run passed.
|
|
464
|
+
function mergedReports(reports) {
|
|
465
|
+
const all = (key) => reports.flatMap((r) => r[key] ?? []);
|
|
466
|
+
const sum = (key) => reports.reduce((n, r) => n + (r.checked?.[key] ?? 0), 0);
|
|
467
|
+
return {
|
|
468
|
+
version: reports[0]?.version,
|
|
469
|
+
passed: reports.every((r) => Boolean(r.passed)),
|
|
470
|
+
checked: { roots: sum("roots"), mains: sum("mains"), images: sum("images"), libraryVersion: reports.find((r) => r.checked?.libraryVersion)?.checked.libraryVersion ?? null },
|
|
471
|
+
findings: all("findings"), staleOverrides: all("staleOverrides"), libraryUpdatePending: all("libraryUpdatePending"),
|
|
472
|
+
outOfScope: all("outOfScope"), outOfScopeNodes: reports.reduce((n, r) => n + (r.outOfScopeNodes ?? 0), 0), warnings: all("warnings"),
|
|
473
|
+
staleVersion: reports.find((r) => r.staleVersion)?.staleVersion ?? null,
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
|
|
442
477
|
/**
|
|
443
478
|
* `design check --change-set CS-1 [--file SUBMIT.json] [--figma-version V]`: Dev's own dry run of
|
|
444
479
|
* the submit gate on a change set (checkDesignConformance): the same checks
|
|
445
480
|
* plus the submit-time guards against the set's items: IMAGE_NOT_TRUECOLOR
|
|
446
481
|
* refuses; STALE_FIGMA_VERSION is a warning. Changes no state.
|
|
447
482
|
*/
|
|
448
|
-
export async function designCheckChangeSet(target, flags, { request = devRequest, send, progress, read = (f) => readFile(f, "utf8"), laneReads } = {}) {
|
|
483
|
+
export async function designCheckChangeSet(target, flags, { request = devRequest, send, progress, read = (f) => readFile(f, "utf8"), laneReads, split = false } = {}) {
|
|
449
484
|
const id = flags["change-set"];
|
|
450
485
|
// On the lane's reads Dev answers on the request, with no job (hub-295).
|
|
451
486
|
const sync = laneReads ? true : submitMode(flags);
|
|
@@ -465,10 +500,19 @@ export async function designCheckChangeSet(target, flags, { request = devRequest
|
|
|
465
500
|
if (!body || typeof body !== "object" || Array.isArray(body)) throw new CliError("USAGE", `${flags.file}: expected the submit body, a JSON object`, 2);
|
|
466
501
|
}
|
|
467
502
|
if (flags["figma-version"]) body = { ...body, figmaVersion: String(flags["figma-version"]) };
|
|
468
|
-
|
|
503
|
+
// hub-310: large reads go up once, in chunks, and every run names them.
|
|
504
|
+
if (laneReads) body = { ...body, ...(await laneReadsBody(id, laneReads, { request, ...(progress ? { progress } : {}) })) };
|
|
505
|
+
// A submit body past the dry run's node limit runs in parts, each under it;
|
|
506
|
+
// a re-submit's can't be split, since it must name every rejected item.
|
|
507
|
+
const groups = split && Array.isArray(body.items) ? dryRunGroups(body.items) : [];
|
|
469
508
|
let p;
|
|
470
509
|
try {
|
|
471
|
-
|
|
510
|
+
const run = (b) => figmaConformance(id, b, { request, sync, ...(send ? { send } : {}), ...(progress ? { progress } : {}) });
|
|
511
|
+
if (groups.length > 1) {
|
|
512
|
+
const reports = [];
|
|
513
|
+
for (const items of groups) reports.push((await run({ ...body, items })).data ?? {});
|
|
514
|
+
p = { data: mergedReports(reports) };
|
|
515
|
+
} else p = await run(body);
|
|
472
516
|
} catch (error) {
|
|
473
517
|
// A cold run reads every root and main from Figma and can outlast the
|
|
474
518
|
// edge's gateway (504, an HTML page). Dev keeps the mains it read for 5
|
package/dist/figma.js
CHANGED
|
@@ -369,7 +369,8 @@ export async function figmaResubmit(id, file, { request = devRequest, read = (f)
|
|
|
369
369
|
const body = assertContext(resubmitPayload(text, file), { resubmit: true, file });
|
|
370
370
|
try {
|
|
371
371
|
// On the lane's reads Dev answers on the request, with no job (hub-295).
|
|
372
|
-
|
|
372
|
+
const reads = await laneReadsBody(id, laneReads, { request, ...(options.progress ? { progress: options.progress } : {}) });
|
|
373
|
+
return await submitCall(id, "resubmit", { ...body, ...reads }, { request, ...options, ...(laneReads ? { sync: true } : {}) });
|
|
373
374
|
} catch (error) {
|
|
374
375
|
if (error?.code === "FIGMA_READS_NEEDED") throw laneReadsRefusal(error);
|
|
375
376
|
const say = RESUBMIT_REFUSALS[error?.code];
|
|
@@ -748,12 +749,13 @@ export function checkSubmitPayload(payload, file = "the submit body") {
|
|
|
748
749
|
return assertContext(payload, { file });
|
|
749
750
|
}
|
|
750
751
|
|
|
751
|
-
export async function figmaSubmit(id, payload, { request = devRequest, file = "the submit body", laneReads, ...options } = {}) {
|
|
752
|
+
export async function figmaSubmit(id, payload, { request = devRequest, file = "the submit body", laneReads, progress, ...options } = {}) {
|
|
752
753
|
checkSubmitPayload(payload, file);
|
|
753
754
|
// On the lane's reads Dev answers on the request, with no job (hub-295).
|
|
754
755
|
const sync = laneReads ? { sync: true } : {};
|
|
755
|
-
|
|
756
|
-
|
|
756
|
+
const reads = await laneReadsBody(id, laneReads, { request, ...(progress ? { progress } : {}) });
|
|
757
|
+
return changeSetCall(id, (method, path, body) => submitCall(id, "submit", body, { request, ...options, ...(progress ? { progress } : {}), ...sync }))(
|
|
758
|
+
"POST", `/api/v1/design/change-sets/${encode(id)}/submit`, { ...payload, ...reads }).catch((error) => {
|
|
757
759
|
throw laneReadsRefusal(error);
|
|
758
760
|
});
|
|
759
761
|
}
|
|
@@ -950,7 +952,7 @@ export function figmaPublishPlanText(plan) {
|
|
|
950
952
|
].join("\n");
|
|
951
953
|
}
|
|
952
954
|
|
|
953
|
-
export const WITHDRAW_ITEMS_USAGE = "figma withdraw CHANGE_SET --items ID[,ID] --reason TEXT";
|
|
955
|
+
export const WITHDRAW_ITEMS_USAGE = "figma withdraw CHANGE_SET --items ID[,ID] --reason TEXT [--lane-reads FILE [--removed-nodes NODE[,NODE]]]";
|
|
954
956
|
|
|
955
957
|
/** `--items A,B --items C` → ["A", "B", "C"], each an item id or a Figma node id. */
|
|
956
958
|
export function withdrawItemsFrom(flags) {
|
|
@@ -961,6 +963,32 @@ export function withdrawItemsFrom(flags) {
|
|
|
961
963
|
return items;
|
|
962
964
|
}
|
|
963
965
|
|
|
966
|
+
/**
|
|
967
|
+
* `--removed-nodes 47:9554,47-9501` → the Figma node ids the lane deleted
|
|
968
|
+
* (a figma.com link's 47-9501 is 47:9501), sent as removedNodeIds (hub-312).
|
|
969
|
+
* Dev takes each as absent only with the lane's reads: in their `gone`, with a
|
|
970
|
+
* /nodes entry at the version read that is null or the empty ghost Figma
|
|
971
|
+
* answers for a deleted component or variant. So it goes with --lane-reads.
|
|
972
|
+
*/
|
|
973
|
+
export function removedNodesFrom(flags) {
|
|
974
|
+
if (flags["removed-nodes"] === undefined) return undefined;
|
|
975
|
+
const ids = [...new Set([flags["removed-nodes"]].flat().flatMap(nodeIdList).map(nodeId))];
|
|
976
|
+
if (!ids.length) throw new CliError("USAGE", `--removed-nodes needs Figma node ids: ${WITHDRAW_ITEMS_USAGE}`, 2);
|
|
977
|
+
const bad = ids.filter((x) => !BARE_NODE_ID.test(x));
|
|
978
|
+
if (bad.length) throw new CliError("USAGE", `--removed-nodes takes Figma node ids (like 47:9554), not: ${bad.join(", ")}`, 2);
|
|
979
|
+
if (!flags["lane-reads"] || flags["lane-reads"] === true)
|
|
980
|
+
throw new CliError("USAGE", `--removed-nodes goes with --lane-reads FILE: Dev takes a node as deleted only when your reads show it gone. ${WITHDRAW_ITEMS_USAGE}`, 2);
|
|
981
|
+
return ids;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
/** Each removed node must be in the reads' `gone`, or Dev refuses it; say so before calling Dev. */
|
|
985
|
+
export function removedNodesInReads(ids, reads) {
|
|
986
|
+
const gone = new Set(Array.isArray(reads?.gone) ? reads.gone : []);
|
|
987
|
+
const missing = ids.filter((x) => !gone.has(x));
|
|
988
|
+
if (missing.length)
|
|
989
|
+
throw new CliError("USAGE", `--removed-nodes ${missing.join(", ")} ${missing.length === 1 ? "is" : "are"} not in your lane reads' gone list. Read ${missing.length === 1 ? "it" : "them"} through the Figma MCP and list ${missing.length === 1 ? "it" : "them"} in gone if deleted, then run this again. Nothing was sent.`, 2);
|
|
990
|
+
}
|
|
991
|
+
|
|
964
992
|
const indented = (ids) => ids.map((x) => ` ${x}`);
|
|
965
993
|
|
|
966
994
|
// Dev's refusals of withdrawDesignChangeItems, said in terms of what to do next.
|
|
@@ -970,13 +998,22 @@ const WITHDRAW_ITEMS_REFUSALS = {
|
|
|
970
998
|
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}`,
|
|
971
999
|
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.`,
|
|
972
1000
|
CHANGE_SET_CHANGED: (id, message) => `${message}\n${id} changed while withdrawing; read it with nodii-dev figma changeset show ${id} and run this again.`,
|
|
973
|
-
CHANGE_ITEM_NOT_AT_BASE: (id, message, d) => {
|
|
974
|
-
const
|
|
975
|
-
if (!
|
|
1001
|
+
CHANGE_ITEM_NOT_AT_BASE: (id, message, d, removed = []) => {
|
|
1002
|
+
const all = d?.nodeIds ?? [];
|
|
1003
|
+
if (!all.length) return message;
|
|
1004
|
+
// A node named in --removed-nodes that Dev still finds: Dev's own words say
|
|
1005
|
+
// why (not in the reads' gone, or still in the file). The rest differ from base.
|
|
1006
|
+
const named = all.filter((n) => removed.includes(n));
|
|
1007
|
+
const nodes = all.filter((n) => !removed.includes(n));
|
|
976
1008
|
return [
|
|
977
|
-
|
|
978
|
-
...
|
|
979
|
-
|
|
1009
|
+
...(named.length ? [message] : []),
|
|
1010
|
+
...(nodes.length
|
|
1011
|
+
? [
|
|
1012
|
+
`${nodes.length} node(s) of ${d?.changeSetId ?? id} still differ from its base version${d?.baseVersion ? ` (${d.baseVersion})` : ""}:`,
|
|
1013
|
+
...indented(nodes),
|
|
1014
|
+
"Put each back as it was at base (remove it if the set added it), then run this again. Nothing was withdrawn.",
|
|
1015
|
+
]
|
|
1016
|
+
: ["Nothing was withdrawn."]),
|
|
980
1017
|
].join("\n");
|
|
981
1018
|
},
|
|
982
1019
|
CHANGE_ITEM_NOT_REJECTED: (id, message, d) => {
|
|
@@ -1002,14 +1039,20 @@ const WITHDRAW_ITEMS_REFUSALS = {
|
|
|
1002
1039
|
* must already be back at the set's base version; apply then takes the
|
|
1003
1040
|
* approved items alone, and the scopes only those items sat in are released.
|
|
1004
1041
|
*/
|
|
1005
|
-
export async function figmaWithdrawItems(id, items, reason, { request = devRequest, laneReads } = {}) {
|
|
1042
|
+
export async function figmaWithdrawItems(id, items, reason, { request = devRequest, laneReads, removedNodeIds } = {}) {
|
|
1006
1043
|
if (!id || !items?.length) throw new CliError("USAGE", WITHDRAW_ITEMS_USAGE, 2);
|
|
1007
1044
|
if (typeof reason !== "string" || !reason.trim()) throw new CliError("USAGE", `--reason needs a reason: ${WITHDRAW_ITEMS_USAGE}`, 2);
|
|
1045
|
+
const removed = removedNodeIds?.length ? removedNodeIds : null;
|
|
1008
1046
|
try {
|
|
1009
|
-
return await request("POST", `/api/v1/design/change-sets/${encode(id)}/withdraw-items`, {
|
|
1047
|
+
return await request("POST", `/api/v1/design/change-sets/${encode(id)}/withdraw-items`, {
|
|
1048
|
+
items,
|
|
1049
|
+
reason: reason.trim(),
|
|
1050
|
+
...(removed ? { removedNodeIds: removed } : {}),
|
|
1051
|
+
...(laneReads ? { laneReads } : {}),
|
|
1052
|
+
});
|
|
1010
1053
|
} catch (error) {
|
|
1011
1054
|
const say = WITHDRAW_ITEMS_REFUSALS[error?.code];
|
|
1012
|
-
if (say) throw new CliError(error.code, say(id, error.message, error.details), error.exitCode ?? 1, error.details);
|
|
1055
|
+
if (say) throw new CliError(error.code, say(id, error.message, error.details, removed ?? []), error.exitCode ?? 1, error.details);
|
|
1013
1056
|
throw scopeRefusal(error, id) ?? error;
|
|
1014
1057
|
}
|
|
1015
1058
|
}
|
|
@@ -1027,6 +1070,132 @@ export const figmaWithdrawItemsText = (id, d = {}) => {
|
|
|
1027
1070
|
].join("\n");
|
|
1028
1071
|
};
|
|
1029
1072
|
|
|
1073
|
+
// hub-310 (hub-ee's design of 7 Nov): reads larger than this go up to
|
|
1074
|
+
// Dev in chunks of about this size, by id, so no submit body passes Dev's 32 MB
|
|
1075
|
+
// cap. Smaller reads still go inline. One read bigger than this goes up in
|
|
1076
|
+
// parts (laneReadsParts).
|
|
1077
|
+
export const LANE_READS_CHUNK_BYTES = 8 * 1024 * 1024;
|
|
1078
|
+
const jsonBytes = (value) => Buffer.byteLength(JSON.stringify(value));
|
|
1079
|
+
// The lists that hold the bulk of a lane's reads; everything else rides in the
|
|
1080
|
+
// first chunk.
|
|
1081
|
+
const CHUNKED_LISTS = ["nodes", "documents", "rest"];
|
|
1082
|
+
|
|
1083
|
+
/**
|
|
1084
|
+
* The lane's reads as chunks of about `limit` bytes each, every one at the
|
|
1085
|
+
* reads' Figma version. The first carries the small parts (pages, gone, base,
|
|
1086
|
+
* publish, restReads); nodes, documents and REST answers are split entry by
|
|
1087
|
+
* entry. One entry larger than `limit` goes alone, in a chunk of just that
|
|
1088
|
+
* entry at the reads' version, which goes up in parts. Dev puts them back together.
|
|
1089
|
+
*/
|
|
1090
|
+
export function laneReadsChunks(reads, limit = LANE_READS_CHUNK_BYTES) {
|
|
1091
|
+
const { figmaVersion } = reads;
|
|
1092
|
+
const small = Object.fromEntries(Object.entries(reads).filter(([key]) => !CHUNKED_LISTS.includes(key)));
|
|
1093
|
+
const chunks = [];
|
|
1094
|
+
const alone = [];
|
|
1095
|
+
let chunk = { ...small, nodes: [] };
|
|
1096
|
+
let used = jsonBytes(chunk);
|
|
1097
|
+
let entries = 0;
|
|
1098
|
+
for (const list of CHUNKED_LISTS)
|
|
1099
|
+
for (const entry of reads[list] ?? []) {
|
|
1100
|
+
const bytes = jsonBytes(entry) + 1;
|
|
1101
|
+
// One entry bigger than a chunk goes in a chunk of its own, the same
|
|
1102
|
+
// bytes whatever else the reads hold: Dev then has it by its hash after
|
|
1103
|
+
// the first upload, and a later request sends it no more (hub-ee, 8 Nov:
|
|
1104
|
+
// the same library main once per set).
|
|
1105
|
+
if (bytes > limit) {
|
|
1106
|
+
alone.push({ figmaVersion, nodes: [], [list]: [entry] });
|
|
1107
|
+
continue;
|
|
1108
|
+
}
|
|
1109
|
+
if (entries > 0 && used + bytes > limit) {
|
|
1110
|
+
chunks.push(chunk);
|
|
1111
|
+
chunk = { figmaVersion, nodes: [] };
|
|
1112
|
+
used = jsonBytes(chunk);
|
|
1113
|
+
entries = 0;
|
|
1114
|
+
}
|
|
1115
|
+
(chunk[list] ??= []).push(entry);
|
|
1116
|
+
used += bytes;
|
|
1117
|
+
entries += 1;
|
|
1118
|
+
}
|
|
1119
|
+
chunks.push(chunk);
|
|
1120
|
+
return [...chunks, ...alone];
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
// One part of a chunk that one read makes bigger than a chunk: about this many
|
|
1124
|
+
// of the chunk's bytes, base64 encoded, under Dev's 16 MB request cap.
|
|
1125
|
+
export const LANE_READS_PART_BYTES = 6 * 1024 * 1024;
|
|
1126
|
+
|
|
1127
|
+
/**
|
|
1128
|
+
* A chunk's JSON split by bytes into parts, each with the whole chunk's hash,
|
|
1129
|
+
* its index and the count, as POST /design/change-sets/:id/reads/parts takes
|
|
1130
|
+
* them (hub-310, hub-ee 8 Nov: the App Frame main alone is a 34.3 MB read).
|
|
1131
|
+
*/
|
|
1132
|
+
export function laneReadsParts(chunk, size = LANE_READS_PART_BYTES) {
|
|
1133
|
+
const bytes = Buffer.from(JSON.stringify(chunk));
|
|
1134
|
+
const sha256 = createHash("sha256").update(bytes).digest("hex");
|
|
1135
|
+
const count = Math.max(1, Math.ceil(bytes.length / size));
|
|
1136
|
+
return Array.from({ length: count }, (_, index) => ({
|
|
1137
|
+
sha256, index, count, data: bytes.subarray(index * size, (index + 1) * size).toString("base64"),
|
|
1138
|
+
}));
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
/**
|
|
1142
|
+
* What a submit, re-submit or dry run sends for the lane's reads: inline when
|
|
1143
|
+
* they fit in one chunk, else uploaded chunk by chunk to the set and named by
|
|
1144
|
+
* `readIds`. A chunk that one read makes bigger than a chunk goes up in parts,
|
|
1145
|
+
* by bytes, and Dev puts it back together. Dev keeps a chunk by its content,
|
|
1146
|
+
* and a part by the chunk's hash and its index, so one sent again is the same
|
|
1147
|
+
* one: an upload that hits a gateway timeout or a dropped connection is sent
|
|
1148
|
+
* again, and a rerun after a failure sends only what it must.
|
|
1149
|
+
*/
|
|
1150
|
+
export async function laneReadsBody(id, laneReads, { request = devRequest, progress = stderrLine, limit = LANE_READS_CHUNK_BYTES, partBytes = LANE_READS_PART_BYTES, wait = delay, attempts = 4 } = {}) {
|
|
1151
|
+
if (!laneReads) return {};
|
|
1152
|
+
if (jsonBytes(laneReads) <= limit) return { laneReads };
|
|
1153
|
+
const chunks = laneReadsChunks(laneReads, limit);
|
|
1154
|
+
const path = `/api/v1/design/change-sets/${encode(id)}/reads`;
|
|
1155
|
+
const send = async (at, body) => {
|
|
1156
|
+
for (let attempt = 1; ; attempt += 1) {
|
|
1157
|
+
try {
|
|
1158
|
+
return await request("POST", at, body);
|
|
1159
|
+
} catch (error) {
|
|
1160
|
+
if (!TRANSIENT.has(error?.code) || attempt >= attempts) throw laneReadsUploadRefusal(error, id);
|
|
1161
|
+
await wait(attempt * 2_000);
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
};
|
|
1165
|
+
// The parts in order; Dev answers the chunk on the last one, or names the
|
|
1166
|
+
// parts it still needs, which go again. A chunk Dev already has from these
|
|
1167
|
+
// parts is answered on the first, and the rest aren't sent.
|
|
1168
|
+
const sendParts = async (chunk) => {
|
|
1169
|
+
const parts = laneReadsParts(chunk, partBytes);
|
|
1170
|
+
let todo = parts.map((_, i) => i);
|
|
1171
|
+
for (let round = 1; ; round += 1) {
|
|
1172
|
+
let answer;
|
|
1173
|
+
for (const i of todo) {
|
|
1174
|
+
answer = (await send(`${path}/parts`, parts[i])).data;
|
|
1175
|
+
if (answer?.chunk) return answer.chunk.id;
|
|
1176
|
+
}
|
|
1177
|
+
if (!answer?.missing?.length || round >= attempts)
|
|
1178
|
+
throw new CliError("LANE_READS_UPLOAD_INCOMPLETE", `Dev didn't put the ${parts.length} parts of one lane-reads chunk together for ${id}; run the command again (sent parts are kept).`, 1, answer);
|
|
1179
|
+
todo = answer.missing;
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
const readIds = [];
|
|
1183
|
+
for (const [index, chunk] of chunks.entries()) {
|
|
1184
|
+
readIds.push(jsonBytes(chunk) > limit ? await sendParts(chunk) : (await send(path, chunk)).data.id);
|
|
1185
|
+
progress(`lane reads: ${index + 1} of ${chunks.length} chunks uploaded to ${id}`);
|
|
1186
|
+
}
|
|
1187
|
+
return { readIds };
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
function laneReadsUploadRefusal(error, id) {
|
|
1191
|
+
if (error?.code === "LANE_READS_TOO_LARGE")
|
|
1192
|
+
return new CliError(error.code, `${error.message}
|
|
1193
|
+
The lane-reads chunk is larger than Dev takes, even in parts; tell the Steward (hub-310).`, error.exitCode ?? 1, error.details);
|
|
1194
|
+
if (["HTTP_404", "NOT_FOUND", "ROUTE_NOT_FOUND"].includes(error?.code))
|
|
1195
|
+
return new CliError(error.code, `Dev doesn't take lane reads in chunks yet (POST /design/change-sets/${id}/reads): this nodii-dev needs Dev with the lane-reads upload (hub-310) deployed.`, error.exitCode ?? 1, error.details);
|
|
1196
|
+
return error;
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1030
1199
|
// MW1-57.11: the lane reads Figma through the MCP in its own session, and sends
|
|
1031
1200
|
// what it read. Dev runs the same gates on that, with no job and no Figma call.
|
|
1032
1201
|
export async function readLaneReads(path, { read = readFile } = {}) {
|
package/dist/flags.js
CHANGED
|
@@ -67,7 +67,7 @@ export const COMMAND_FLAGS = {
|
|
|
67
67
|
"docs ratify": ["domain", "decision", ...WAIT],
|
|
68
68
|
"figma submit": ["file", "figma-version", ...SUBMIT_MODE, "dry-run", "lane-reads"],
|
|
69
69
|
"figma resubmit": [...SUBMIT_MODE, "dry-run", "lane-reads"],
|
|
70
|
-
"figma withdraw": ["items", "reason", "lane-reads"],
|
|
70
|
+
"figma withdraw": ["items", "reason", "lane-reads", "removed-nodes"],
|
|
71
71
|
"figma lane-reads-script": ["nodes"],
|
|
72
72
|
"figma abandon": ["file"],
|
|
73
73
|
// hub-260: list takes these; show takes none.
|