@nodii/dev 0.6.186 → 0.6.188

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
@@ -348,6 +348,7 @@ nodii-dev figma published FILE_KEY|CHANGE_SET --figma-version VERSION
348
348
  nodii-dev figma abandon CHANGE_SET
349
349
  nodii-dev figma withdraw CHANGE_SET # take back a submit before anything is decided
350
350
  nodii-dev figma split CHANGE_SET --nodes NODE[,NODE] --title TEXT # move written nodes to a new set
351
+ nodii-dev figma restore CHANGE_SET --lane KEY|--holder AGENT_ID --reason TEXT # staff or Steward: undo a sweep's abandon (MW8-4.3)
351
352
  nodii-dev figma resubmit CHANGE_SET PAYLOAD.json # round 2: re-submit every rejected item
352
353
  nodii-dev figma changeset show CHANGE_SET # items, variants, round, decision, comment
353
354
  nodii-dev figma release FILE_KEY
@@ -464,6 +465,26 @@ Dev refuses with:
464
465
  - `CHANGE_SET_NOT_EDITABLE` while the set is in review or its submit is running;
465
466
  - `CHANGE_SET_HOLDER_REQUIRED` for anyone but the holder.
466
467
 
468
+ `figma restore CS --lane KEY|--holder AGENT_ID --reason TEXT` returns a set
469
+ that Dev's dead-holder sweep abandoned to `editing` under the named holder
470
+ (Dev's `restoreDesignChangeSet`, hub #705; MW8-4.3, ratified 20 Nov as DEC-0550;
471
+ hub-590). Use it when a lane was frozen on an exhausted account
472
+ and the sweep abandoned its drawn work (CS-3709, CS-3722). Dev takes back the
473
+ set's file lock and the scopes the sweep released, under the file's row lock,
474
+ and keeps its write log, items, base and history. `--lane` sends the lane key
475
+ and Dev resolves the lane's current agent; `--holder` takes an agent id (any
476
+ other value is read as a lane key). Only staff or a live Steward over the
477
+ lane's repositories may run it; a lane is refused.
478
+
479
+ Dev refuses with, and the CLI says what to do next for:
480
+ - `CHANGE_SET_SCOPE_TAKEN` or `CHANGE_SET_ALREADY_HELD` when another set took
481
+ a scope or the file's lock since (the set and its holder are named);
482
+ - `CHANGE_SET_NOT_ABANDONED` for a set that isn't abandoned, and
483
+ `CHANGE_SET_NOT_SWEPT` for one abandoned other than by the sweep;
484
+ - `RESTORE_HOLDER_NOT_LIVE` when the holder has no live lane (it would be swept
485
+ again), `RESTORE_HOLDER_NOT_FOUND` and `RESTORE_HOLDER_MISMATCH`;
486
+ - `CHANGE_SET_RESTORE_NOT_ALLOWED` for a lane caller, and `FILE_RETIRED`.
487
+
467
488
  `figma withdraw` moves a change set you hold from `in_review` back to
468
489
  `editing`, as long as no item has been decided (Dev's
469
490
  `withdrawDesignChangeSet`). Dev refuses when the change set doesn't exist
package/dist/cli.js CHANGED
@@ -70,6 +70,9 @@ import {
70
70
  withdrawItemsFrom,
71
71
  figmaSplit,
72
72
  figmaSplitText,
73
+ figmaRestore,
74
+ figmaRestoreText,
75
+ RESTORE_USAGE,
73
76
  listFlag,
74
77
  SPLIT_USAGE,
75
78
  checkSubmitPayload,
@@ -283,6 +286,10 @@ Usage: nodii-dev <command> [options] [--json]
283
286
  # write log into a new set you hold on the same file, base and seal; receipts
284
287
  # move, never copied. A node an item names stays (SPLIT_NODE_IN_ITEM); the lock
285
288
  # stays with the source. hub-572
289
+ figma restore CHANGE_SET --lane KEY|--holder AGENT_ID --reason TEXT
290
+ # staff or Steward: return a set Dev's dead-holder sweep abandoned to editing
291
+ # under the named holder (a lane key means its current agent), re-taking its
292
+ # file lock and scopes and keeping its write log. hub-590
286
293
  figma withdraw CHANGE_SET # holder takes back a submit: in_review -> editing (or a re-submit -> applying)
287
294
  figma withdraw CHANGE_SET --items ID[,ID] --reason TEXT [--lane-reads FILE [--removed-nodes NODE[,NODE]]]
288
295
  # holder, coordinator or operator: take rejected items (item or node ids)
@@ -1842,6 +1849,16 @@ export async function main(argv = process.argv.slice(2)) {
1842
1849
  (p) => figmaSplitText(rest[0], p.data),
1843
1850
  );
1844
1851
  }
1852
+ if (action === "restore") {
1853
+ if (rest.length !== 1) throw new CliError("USAGE", RESTORE_USAGE, 2);
1854
+ const pick = (value) => (value === true ? "" : value);
1855
+ const named = { lane: pick(f.lane), holder: pick(f.holder) };
1856
+ return emit(
1857
+ await figmaRestore(rest[0], { ...named, reason: pick(f.reason) }),
1858
+ json,
1859
+ (p) => figmaRestoreText(rest[0], p.data, named),
1860
+ );
1861
+ }
1845
1862
  if (action === "resubmit")
1846
1863
  return emit(await figmaResubmit(rest[0], rest[1], { sync: submitMode(f), ...(f["lane-reads"] ? { laneReads: await readLaneReads(f["lane-reads"]) } : {}) }), json, (p) =>
1847
1864
  [`Re-submitted ${rest[0]}; it is ${p.data.state}.`, figmaChangeSetText(p.data), ...conformanceLines({ warnings: p.warnings })].join("\n"));
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.186";
7
+ export const VERSION = "0.6.188";
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
@@ -1153,6 +1153,79 @@ export function figmaSplitText(id, data) {
1153
1153
  return `Moved ${count} node${count === 1 ? "" : "s"} (${moved.receipts ?? 0} write receipt${moved.receipts === 1 ? "" : "s"}) from ${id} to ${created.id} "${created.title}". Both sets are yours and editing; each submits with its own items.`;
1154
1154
  }
1155
1155
 
1156
+ // hub-590: Dev's dead-holder sweep abandons the sets of lanes frozen on an
1157
+ // exhausted account (CS-3709, CS-3722). Staff or a Steward returns such a set
1158
+ // to editing under a named holder: Dev re-acquires its file lock and scopes and
1159
+ // keeps its write log (restoreDesignChangeSet).
1160
+ export const RESTORE_USAGE = "figma restore CHANGE_SET --lane KEY|--holder AGENT_ID --reason TEXT";
1161
+
1162
+ /** Dev's restore route and body, in one place: the holder is { holderAgentId } or { laneKey }. */
1163
+ export const restoreRequest = (id, holder, reason) =>
1164
+ ["POST", `/api/v1/design/change-sets/${encode(id)}/restore`, { ...holder, reason }];
1165
+
1166
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1167
+
1168
+ const blocker = (details, fallback) => {
1169
+ const set = details?.changeSetId ?? details?.heldBy?.changeSetId ?? fallback;
1170
+ return details?.holderAgentId ? `${set} (held by agent ${details.holderAgentId})` : set;
1171
+ };
1172
+
1173
+ // The refusals restoreDesignChangeSet gives (hub #705), each with its next step.
1174
+ const RESTORE_REFUSALS = {
1175
+ CHANGE_SET_SCOPE_TAKEN: (id, details) =>
1176
+ `${blocker(details, "another open set")} took a scope ${id} held, so ${id} can't take its scopes back. Next: finish, withdraw or abandon that set (or have its holder narrow its scopes with figma scope set), then run figma restore ${id} again.`,
1177
+ CHANGE_SET_ALREADY_HELD: (id, details) =>
1178
+ `${blocker(details, "another set")} holds ${id}'s file now, and a file takes one lock per agent. Next: have its holder finish, abandon or release it, or move it with figma transfer CHANGE_SET --to LANE --reason TEXT, then run figma restore ${id} again.`,
1179
+ CHANGE_SET_NOT_SWEPT: (id) =>
1180
+ `${id} was abandoned, but not by Dev's dead-holder sweep, so it can't be restored (MW8-4.3). Next: redraw its work in a new set (figma lock), or read its history with figma changeset show ${id}.`,
1181
+ CHANGE_SET_NOT_ABANDONED: (id, details) =>
1182
+ `${id} is not abandoned${details?.state ? ` (it is ${details.state})` : ""}, so there is nothing to restore. Next: an open set moves to another lane with figma transfer ${id} --to LANE --reason TEXT.`,
1183
+ CHANGE_SET_RESTORE_NOT_ALLOWED: (id) =>
1184
+ `Only staff or a live Steward over the lane's repositories can restore ${id}; a lane can't restore a set, even its own. Next: ask the coordinator or the Steward to run figma restore ${id} --lane KEY --reason TEXT.`,
1185
+ RESTORE_HOLDER_NOT_LIVE: (id) =>
1186
+ `The named holder has no live lane, so ${id} would be swept again. Next: resume the lane (nodii-dev lane resume KEY), then run figma restore ${id} again.`,
1187
+ RESTORE_HOLDER_MISMATCH: (id) =>
1188
+ `--holder and the lane's current agent differ. Next: name the holder once, with --lane KEY or --holder AGENT_ID, and run figma restore ${id} again.`,
1189
+ RESTORE_HOLDER_NOT_FOUND: (id) =>
1190
+ `Dev has no such lane or agent to hold ${id}. Next: name a lane key from nodii-dev lane list, or the holder's agent id.`,
1191
+ FILE_RETIRED: (id) => `${id}'s Figma file is retired, so the set can't come back. Next: redraw the work on the file that replaced it.`,
1192
+ DESIGN_FILE_NOT_FOUND: (id) => `Dev has no record of ${id}'s Figma file. Next: read the set with figma changeset show ${id}.`,
1193
+ CHANGE_SET_NOT_FOUND: (id) => `No change set ${id} in Dev. Next: check the id with figma changeset list --all.`,
1194
+ };
1195
+
1196
+ const given = (value) => typeof value === "string" && value.trim() ? value.trim() : null;
1197
+
1198
+ export async function figmaRestore(id, { lane, holder, reason } = {}, { request = devRequest } = {}) {
1199
+ if (!id) throw new CliError("USAGE", RESTORE_USAGE, 2);
1200
+ if (lane !== undefined && holder !== undefined) throw new CliError("USAGE", `Name the holder with --lane KEY or --holder AGENT_ID, not both: ${RESTORE_USAGE}`, 2);
1201
+ const named = given(lane) ?? given(holder);
1202
+ if (!named) throw new CliError("USAGE", `Name who holds the set with --lane KEY or --holder AGENT_ID: ${RESTORE_USAGE}`, 2);
1203
+ if (!given(reason)) throw new CliError("USAGE", `--reason needs why the set comes back: ${RESTORE_USAGE}`, 2);
1204
+ // An agent id goes as one; anything else is a lane key, which Dev resolves to its current agent.
1205
+ const body = lane === undefined && UUID.test(named) ? { holderAgentId: named } : { laneKey: named };
1206
+ try {
1207
+ return await request(...restoreRequest(id, body, given(reason)));
1208
+ } catch (error) {
1209
+ const say = RESTORE_REFUSALS[error?.code];
1210
+ if (say) throw new CliError(error.code, say(id, error.details), error.exitCode ?? 1, error.details);
1211
+ throw error;
1212
+ }
1213
+ }
1214
+
1215
+ export function figmaRestoreText(id, data, { lane, holder } = {}) {
1216
+ const set = data?.changeSet ?? {};
1217
+ const done = data?.restored ?? {};
1218
+ const agent = done.holderAgentId ?? set.holderAgentId ?? holder;
1219
+ const key = lane ?? (holder && !UUID.test(holder) ? holder : null);
1220
+ const who = key ? `lane ${key}'s agent ${agent}` : `agent ${agent}`;
1221
+ const scopes = done.scopes ?? [];
1222
+ const name = done.changeSetId ?? set.id ?? id;
1223
+ return [
1224
+ `${name} is ${set.state ?? "editing"} again under ${who}, with its file lock, ${scopes.length} scope${scopes.length === 1 ? "" : "s"}${scopes.length ? ` (${scopes.map(scopeText).join(", ")})` : ""} and its write log.`,
1225
+ `Next: the holder carries on drawing, then submits with nodii-dev figma submit ${name} --file SUBMISSION.json.`,
1226
+ ].join("\n");
1227
+ }
1228
+
1156
1229
  /**
1157
1230
  * Apply on the lane's reads (MW1-57.11): the reads' Figma version unless one
1158
1231
  * is named. Reads over a chunk go up to the set first and are named by
package/dist/flags.js CHANGED
@@ -84,6 +84,7 @@ export const COMMAND_FLAGS = {
84
84
  "figma resubmit": [...SUBMIT_MODE, "dry-run", "lane-reads"],
85
85
  "figma withdraw": ["items", "reason", "lane-reads", "removed-nodes"],
86
86
  "figma split": ["nodes", "title"],
87
+ "figma restore": ["lane", "holder", "reason"],
87
88
  "figma lane-reads-script": ["nodes"],
88
89
  "figma abandon": ["file"],
89
90
  // hub-260: list takes these; show takes none.
package/dist/surface.js CHANGED
@@ -34,7 +34,7 @@ import { MIN_FIGMA_INTERVAL_MS, figmaRest } from "./figma-rest.js";
34
34
  import { createRenderer } from "./vendor/render-templates.mjs";
35
35
 
36
36
  /** Bumped whenever the emitted code changes shape for the same inputs. */
37
- export const GENERATOR_FORMAT = 44;
37
+ export const GENERATOR_FORMAT = 45;
38
38
  /**
39
39
  * DS parts that are an item of their parent's own list or grid, so they take no sizing
40
40
  * wrapper: a Detail Section / Row's facts are the section grid's cells, a Right Pane / Row
@@ -2710,27 +2710,35 @@ function emitChildren(children, emitOne, ctx) {
2710
2710
  }
2711
2711
 
2712
2712
  const LABEL_FOR = /<Label\b[^>]*?\bhtmlFor=\{([A-Za-z_$][\w$]*)\}/;
2713
- const LABELLED_CONTROL = /<(?:Checkbox|Switch|RadioGroupItem)(?=[\s/>])/;
2713
+ const LABELLED_CONTROL = /<(?:Checkbox|Switch|RadioGroupItem|Textarea|Input|SelectField)(?=[\s/>])/;
2714
2714
  /**
2715
2715
  * A DS Label beside its control names it: the Label template emits htmlFor={x}, so the
2716
- * Checkbox, Switch or RadioGroupItem next to it (in the same container, with no id of its
2717
- * own) takes id={x}. Without it the label isn't tied to the control and the control has
2716
+ * Checkbox, Switch, RadioGroupItem, Textarea, Input or SelectField next to it (in the same
2717
+ * container) takes id={x}, or, when that control already has an id of its own, the Label's
2718
+ * htmlFor takes that id. Without it the label isn't tied to the control and the control has
2718
2719
  * no accessible name (DESIGN-SYSTEM-817). Each label names the one control beside it.
2719
2720
  */
2720
2721
  function pairLabelledControls(codes) {
2722
+ const out = [...codes];
2721
2723
  const labelOf = codes.map((c) => LABEL_FOR.exec(c ?? "")?.[1] ?? null);
2722
2724
  const used = new Set();
2723
- return codes.map((code, i) => {
2725
+ codes.forEach((code, i) => {
2724
2726
  const control = code ? LABELLED_CONTROL.exec(code) : null;
2725
- if (!control || LABEL_FOR.test(code)) return code;
2726
- const open = code.slice(control.index, control.index + openTagEnd(code.slice(control.index)) + 1);
2727
- if (/\sid=/.test(open)) return code;
2727
+ // A container that holds a Label of its own is already paired, at its own level.
2728
+ if (!control || /<Label\b/.test(code)) return;
2728
2729
  const at = [i + 1, i - 1].find((j) => labelOf[j] && !used.has(j));
2729
- if (at === undefined) return code;
2730
+ if (at === undefined) return;
2730
2731
  used.add(at);
2731
- const end = control.index + control[0].length;
2732
- return `${code.slice(0, end)} id={${labelOf[at]}}${code.slice(end)}`;
2732
+ const open = code.slice(control.index, control.index + openTagEnd(code.slice(control.index)) + 1);
2733
+ const own = /\sid=("(?:[^"\\\n]|\\.)*"|\{[^{}]*\})/.exec(open)?.[1];
2734
+ // The control keeps its own id; its Label points at it.
2735
+ if (own) out[at] = out[at].replace(LABEL_FOR, (tag) => tag.replace(/htmlFor=\{[^}]*\}/, `htmlFor=${own}`));
2736
+ else {
2737
+ const end = control.index + control[0].length;
2738
+ out[i] = `${code.slice(0, end)} id={${labelOf[at]}}${code.slice(end)}`;
2739
+ }
2733
2740
  });
2741
+ return out;
2734
2742
  }
2735
2743
 
2736
2744
  /** What the DescriptionList template emits for one field: one DescriptionItem in its list. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.186",
3
+ "version": "0.6.188",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {