@nodii/dev 0.6.188 → 0.6.190
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 +1 -0
- package/dist/accounts.js +23 -4
- package/dist/coordinator-watch.js +41 -5
- package/dist/core.js +1 -1
- package/dist/lanes.js +4 -1
- package/dist/review.js +75 -2
- package/dist/watchdog.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -198,6 +198,7 @@ nodii-dev figma publish FILE --sets CS-1,CS-2 [--dry-run]
|
|
|
198
198
|
|
|
199
199
|
- **Board.** "Waiting on" comes from Dev's real state: the lane's status, the change sets it holds (state, pending items, file order), Dev's wait records, the heavy-slot queue and `answered.md`. It never comes from the lane's note, which is shown as written in its own column. A question counts as the operator's only when it is an open item on the sheet. `--write` puts "What's running" on the status page `docs/open/<sheet>-status.md` and only the lanes that wait on the operator on the sheet, because MW4-31 keeps status off the sheet. It works in the worktree `nodii-infra/.claude/worktrees/<sheet>-board` and merges through a PR. First it copies every answer the operator typed in their checkout, verbatim, into `answered.md` and into the sheet. Then it fast-forwards the operator's checkout, and only when nothing else there differs from main. An empty board, or one that drops by more than half, is refused (`--force` once you have checked Dev). Priority domains are coordinator configuration in `~/.config/nodii-dev/coordinator/settings.json` (`domains`); a lane outside them is listed under "Other lanes".
|
|
200
200
|
- **Watch.** Jobs and intervals: board 15 min, apply-watch 3, publish-watch 10, real-stuck 30, complexity 30, orphan-slots 10, keepalive 10. Everything goes to one log, `coordinator-watch.log`, under `~/Library/Logs/nodii-dev/` on macOS and `~/.local/state/nodii-dev/logs/` on Linux. On Linux the memory guard on a resume reads `MemAvailable` from `/proc/meminfo`. Alerts go to `~/.config/nodii-dev/coordinator/alerts.log` and open the coordinator's next session. A job is paused by `~/.config/nodii-dev/coordinator/hold-<job>`. A resume tries the lane's own account first. On an account refusal it tries the accounts listed in `settings.json` `keepaliveProfiles` (`[{ "profile": "/abs/path", "class": "short" }]`), because the account roster is the operator's call (MW1-38.3). The watch never stops a process it did not start (K02-15). It reports an orphaned slot instead. Keepalive resumes a blocked lane, or any down lane with waits of its own whatever Dev reports as its liveness, only through `lane resume --if-changed` (MW1-102): a lane whose blockers have not changed, or could not be read, stays down, and does not use up the run's resumes. Each resume's log line names the change that let it through. A down lane with no waits (an orphan) resumes as before. At `NODII_DEV_RESUME_IF_CHANGED=0`, keepalive resumes a blocked lane at most once an hour. When the installed `@nodii/dev` is not the version the daemon started with, the daemon logs it and exits, and launchd (`KeepAlive`) or systemd (`Restart=always`) starts it again on the new code.
|
|
201
|
+
- **A restarted lane runs like a launched one (hub-242, the operator's ruling of 20 Nov: "fix the watcher").** The watch daemon and the watchdog run at launchd's `Standard` priority, not `Background`, so the lanes they restart are not starved of CPU; re-run `nodii-dev coordinator watch install` and `nodii-dev watchdog install` after upgrading so the plists change. Before a resume the daemon puts the Figma token in the environment the lane inherits, from where a coordinator's own resume gets it: `FIGMA_PAT`/`FIGMA_TOKEN`, else the Keychain item publish-watch reads, else `FIGMA_PAT` in `~/Projects/design-system/.env.local`; it is never logged. The accounts the operator rules out sit in the coordinator's `settings.json` as `"excludedProfiles": [{ "profile": "/abs/path", "reason": "..." }]` (MW1-38.3, the roster). The one account picker, keepalive's own `keepaliveProfiles` list and a named `lane resume --profile` (refused `ACCOUNT_EXCLUDED`) all skip them. The restart cap is the machine's declared lane cap (`laneCapState.cap` on Dev's machine record, set with `lane cap`), never a fixed 42; a cap that cannot be read refuses the restart.
|
|
201
202
|
- **publish-watch** stays off until the coordinator sets `"publishWatch": true` in `settings.json`. MW8-7 still names the operator as publisher until hub-429 lands. It needs a Figma token to read the new version. It reads the token from `FIGMA_PAT` (or `FIGMA_TOKEN`) in the daemon's own environment first, then from the macOS keychain (`security add-generic-password -s nodii-dev-figma-pat -a "$USER" -w`). The plist that `coordinator watch install` writes carries no token, so the keychain is the usual source; a token someone adds to the plist's environment would be used before it. It never reads a file. On Linux the job answers "macOS only", so nothing there reads a Secret Service for the token.
|
|
202
203
|
- **Chrome.** `chrome start` adopts the Chrome already serving the port, or starts one on the profile, and records the endpoint on Dev's machine record (`hostFacts.sharedChrome`; coordinator or staff only). Every command opens its own background tab and closes only that tab (K02-16, K02-17). `chrome signin` refuses anything but a `tech-*` tenant and a yopmail test identity. It signs in within its own tab and opens `--open PATH` if given. Then it signs out (the app's logout, then that origin's storage and cookies cleared), so no session or token outlives it (MW3-40.2). It never prints or stores a credential, tries each tenant at most once an hour, skips a tenant another tab has open, and rests a tenant after a failed sign-in until `--clear-rest`.
|
|
203
204
|
- **figma publish** refuses a set that is not `awaiting_publish`. It ticks exactly the approved components of the named sets in Figma's Publish library dialog and unticks every other row. It stops if a row won't settle or if it saw fewer rows than the dialog counts. It records a set in Dev only when all of the set's components were published.
|
package/dist/accounts.js
CHANGED
|
@@ -265,20 +265,39 @@ export async function recordExhaustedAccount(profile, entry, { path = exhaustedA
|
|
|
265
265
|
return entries[key];
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
/**
|
|
269
|
+
* hub-242: the accounts the operator ruled out for lanes (19 Nov: no lanes on
|
|
270
|
+
* ~/.claude-naman-sahni-at-nodii). The roster is the operator's call (MW1-38.3),
|
|
271
|
+
* so it is configuration: `excludedProfiles` in the coordinator's settings.json,
|
|
272
|
+
* as `[{ "profile": "/abs/path", "reason": "..." }]` or plain paths. Every account
|
|
273
|
+
* choice asks this one rule: the picker, keepalive's own list and a named --profile.
|
|
274
|
+
*/
|
|
275
|
+
export async function excludedProfiles({ home = homedir(), read = readFile } = {}) {
|
|
276
|
+
let settings = {};
|
|
277
|
+
try { settings = JSON.parse(await read(join(home, ".config", "nodii-dev", "coordinator", "settings.json"), "utf8")); }
|
|
278
|
+
catch { return []; }
|
|
279
|
+
const list = Array.isArray(settings?.excludedProfiles) ? settings.excludedProfiles : [];
|
|
280
|
+
return list.map((entry) => profilePath(typeof entry === "string" ? entry : entry?.profile)).filter((value) => typeof value === "string" && value.length > 1);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export async function accountExcluded(profile, options = {}) {
|
|
284
|
+
return (await excludedProfiles(options)).includes(profilePath(profile));
|
|
285
|
+
}
|
|
286
|
+
|
|
268
287
|
// MW1-38.2: a long resume needs an ok band; a short or no-build one fits up to short_only.
|
|
269
288
|
const ADMITS = { long: ["ok"], short: ["ok", "warning", "short_only"], no_build: ["ok", "warning", "short_only"] };
|
|
270
289
|
|
|
271
290
|
/**
|
|
272
291
|
* Another registered account of the runtime on this machine whose freshly
|
|
273
|
-
* read band admits the work class, skipping `from
|
|
274
|
-
* (recorded exhausted) profiles; null when none has headroom or the
|
|
292
|
+
* read band admits the work class, skipping `from`, the `exclude`d
|
|
293
|
+
* (recorded exhausted) profiles and the operator's excluded ones (hub-242); null when none has headroom or the
|
|
275
294
|
* accounts cannot be listed.
|
|
276
295
|
*/
|
|
277
|
-
export async function pickHeadroomAccount({ runtime, from, exclude = [], workClass = "long" }, { request = devRequest, config = readConfig, readers = READERS } = {}) {
|
|
296
|
+
export async function pickHeadroomAccount({ runtime, from, exclude = [], workClass = "long" }, { request = devRequest, config = readConfig, readers = READERS, home = homedir() } = {}) {
|
|
278
297
|
let accounts;
|
|
279
298
|
try { accounts = await listAccounts(await coordinatorMachineId({ request, config }), { request }); }
|
|
280
299
|
catch { return null; }
|
|
281
|
-
const skip = new Set([from, ...exclude].map(profilePath));
|
|
300
|
+
const skip = new Set([from, ...exclude, ...(await excludedProfiles({ home }))].map(profilePath));
|
|
282
301
|
const candidates = accounts.filter((account) => account.runtime === runtime && !skip.has(profilePath(account.profile)));
|
|
283
302
|
if (!candidates.length) return null;
|
|
284
303
|
const results = await reportUsage(candidates, { request, readers });
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
DEFAULT_DOMAINS, boardCommand, coordinatorHome, heavyQueue, laneDomain, laneProcesses, liveChangeSets, machineLanes, readCoordinatorSettings,
|
|
29
29
|
} from "./coordinator-board.js";
|
|
30
30
|
import { governorMachineId } from "./governor.js";
|
|
31
|
+
import { excludedProfiles } from "./accounts.js";
|
|
31
32
|
import { envAssignment, execLine, installNote, installSupervised, lingerLine, logsDir, supervisedDirs, unitActive, unitPath, unitText } from "./systemd.js";
|
|
32
33
|
|
|
33
34
|
const execFile = promisify(execFileCallback);
|
|
@@ -93,7 +94,11 @@ export async function machineGuards({ execute = execFile, load = loadavg, os = p
|
|
|
93
94
|
|
|
94
95
|
/** Whether a resume may run now. Priority lanes get more room, as on 12 Nov. */
|
|
95
96
|
export function resumeAllowed(guards, { priority, hold = false }) {
|
|
96
|
-
|
|
97
|
+
// hub-242: the cap is the machine's declared lane cap (Dev's laneCapState), never a fixed number.
|
|
98
|
+
if (guards.laneProcesses !== null) {
|
|
99
|
+
if (!Number.isFinite(guards.laneCap)) return { ok: false, reason: "the machine's declared lane cap could not be read" };
|
|
100
|
+
if (guards.laneProcesses >= guards.laneCap) return { ok: false, reason: `${guards.laneProcesses} lane processes (declared cap ${guards.laneCap})` };
|
|
101
|
+
}
|
|
97
102
|
if (guards.freePercent !== null && guards.freePercent < (priority ? 25 : 20)) return { ok: false, reason: `memory ${guards.freePercent}% free` };
|
|
98
103
|
if (guards.load15 >= (priority ? 100 : 60)) return { ok: false, reason: `load ${guards.load15}` };
|
|
99
104
|
if (hold && !priority) return { ok: false, reason: "keepalive hold" };
|
|
@@ -328,17 +333,41 @@ export async function figmaPatFromKeychain(execute) {
|
|
|
328
333
|
catch { return null; }
|
|
329
334
|
}
|
|
330
335
|
|
|
331
|
-
|
|
336
|
+
/**
|
|
337
|
+
* hub-242: the Figma token a restarted lane needs, from where a coordinator's
|
|
338
|
+
* own lane resume gets it: the environment (FIGMA_PAT or FIGMA_TOKEN), else the
|
|
339
|
+
* Keychain item publish-watch reads, else FIGMA_PAT in the design-system
|
|
340
|
+
* checkout's .env.local (as its scripts and the coordinators read it). Never printed.
|
|
341
|
+
*/
|
|
342
|
+
export async function figmaToken({ env = process.env, execute = execFile, home = homedir(), read = readFile } = {}) {
|
|
343
|
+
if (env.FIGMA_PAT || env.FIGMA_TOKEN) return env.FIGMA_PAT || env.FIGMA_TOKEN;
|
|
344
|
+
const fromKeychain = await figmaPatFromKeychain(execute);
|
|
345
|
+
if (fromKeychain) return fromKeychain;
|
|
346
|
+
try {
|
|
347
|
+
const line = (await read(join(home, "Projects", "design-system", ".env.local"), "utf8")).split("\n").find((l) => /^\s*FIGMA_PAT\s*=/.test(l));
|
|
348
|
+
const value = line?.replace(/^\s*FIGMA_PAT\s*=\s*/, "").trim().replace(/^["']|["']$/g, "");
|
|
349
|
+
return value || null;
|
|
350
|
+
} catch { return null; }
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export function watchContext({ home = homedir(), request = devRequest, config = readConfig, execute = execFile, now = Date.now, sleep = delay, log, jobState = {}, os = platform(), resume = async (key, flags) => (await import("./lanes.js")).laneCommand("resume", [key], flags), guardsFor = () => machineGuards({ execute, os }), env = process.env, figmaToken: tokenFor = () => figmaToken({ env, execute, home }) } = {}) {
|
|
332
354
|
let machine = null;
|
|
333
355
|
let processesCache = null;
|
|
334
356
|
let guardsCache = null;
|
|
357
|
+
// hub-242: the restart cap is the cap the machine declared in Dev.
|
|
358
|
+
const withLaneCap = async (guards) => {
|
|
359
|
+
if (guards && "laneCap" in guards) return guards;
|
|
360
|
+
let laneCap = null;
|
|
361
|
+
try { laneCap = (await request("GET", `/api/v1/machines/${encode(await ctx.machineId())}`)).data?.laneCapState?.cap ?? null; } catch {}
|
|
362
|
+
return { ...guards, laneCap: Number.isFinite(laneCap) ? laneCap : null };
|
|
363
|
+
};
|
|
335
364
|
const ctx = {
|
|
336
365
|
home, request, now, sleep, jobState, os,
|
|
337
366
|
stamp: () => new Date(now()).toISOString().slice(11, 16) + "Z",
|
|
338
367
|
machineId: async () => (machine ??= await governorMachineId({}, { request, config })),
|
|
339
368
|
processes: async () => (processesCache ??= await laneProcesses()),
|
|
340
369
|
heavy: () => heavyQueue({ execute, os }),
|
|
341
|
-
guards: async () => (guardsCache ??= await guardsFor()),
|
|
370
|
+
guards: async () => (guardsCache ??= await withLaneCap(await guardsFor())),
|
|
342
371
|
amend: async (key, rules, reason) => {
|
|
343
372
|
const { amendLaneCommand } = await import("./starting.js");
|
|
344
373
|
await amendLaneCommand(key, { rules, reason });
|
|
@@ -352,10 +381,17 @@ export function watchContext({ home = homedir(), request = devRequest, config =
|
|
|
352
381
|
// allowed lane accounts in order (settings.keepaliveProfiles: the account
|
|
353
382
|
// roster is the operator's call, MW1-38.3, so it is configuration).
|
|
354
383
|
const settings = await readCoordinatorSettings(home);
|
|
384
|
+
// hub-242: the restarted lane gets the Figma token a coordinator's own
|
|
385
|
+
// resume has, in the environment it inherits; never logged.
|
|
386
|
+
if (!env.FIGMA_PAT && !env.FIGMA_TOKEN) {
|
|
387
|
+
const token = await tokenFor().catch(() => null);
|
|
388
|
+
if (token) env.FIGMA_PAT = token;
|
|
389
|
+
}
|
|
390
|
+
const excluded = new Set(await excludedProfiles({ home }));
|
|
355
391
|
// A resume the caller knows is due (a set it holds was decided) passes
|
|
356
392
|
// --ungated: that change is not in the blocker fingerprint (NODII-DEV-CLI-191).
|
|
357
393
|
const gate = ifChanged ? { "if-changed": true } : ungated ? { ungated: true } : {};
|
|
358
|
-
const attempts = [{ ...gate }, ...(settings.keepaliveProfiles ?? []).map((p) => ({ ...gate, profile: p.profile, class: p.class ?? "short" }))];
|
|
394
|
+
const attempts = [{ ...gate }, ...(settings.keepaliveProfiles ?? []).filter((p) => !excluded.has(String(p.profile ?? "").replace(/\/+$/, ""))).map((p) => ({ ...gate, profile: p.profile, class: p.class ?? "short" }))];
|
|
359
395
|
let last = "LANE_RESUME_FAILED";
|
|
360
396
|
for (const flags of attempts) {
|
|
361
397
|
try {
|
|
@@ -569,7 +605,7 @@ const xml = (value) => String(value).replaceAll("&", "&").replaceAll("<", "&
|
|
|
569
605
|
|
|
570
606
|
export function watchPlist({ runtime, entry, config, log, path }) {
|
|
571
607
|
const args = [runtime, entry, "coordinator", "watch", "run"].map((v) => `<string>${xml(v)}</string>`).join("");
|
|
572
|
-
return `<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0"><dict><key>Label</key><string>${WATCH_LABEL}</string><key>ProgramArguments</key><array>${args}</array><key>EnvironmentVariables</key><dict><key>NODII_DEV_CONFIG_PATH</key><string>${xml(config)}</string><key>PATH</key><string>${xml(path)}</string></dict><key>RunAtLoad</key><true/><key>KeepAlive</key><true/><key>ThrottleInterval</key><integer>60</integer><key>ProcessType</key><string>
|
|
608
|
+
return `<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0"><dict><key>Label</key><string>${WATCH_LABEL}</string><key>ProgramArguments</key><array>${args}</array><key>EnvironmentVariables</key><dict><key>NODII_DEV_CONFIG_PATH</key><string>${xml(config)}</string><key>PATH</key><string>${xml(path)}</string></dict><key>RunAtLoad</key><true/><key>KeepAlive</key><true/><key>ThrottleInterval</key><integer>60</integer><key>ProcessType</key><string>Standard</string><key>StandardOutPath</key><string>${xml(log)}</string><key>StandardErrorPath</key><string>${xml(log)}</string></dict></plist>\n`;
|
|
573
609
|
}
|
|
574
610
|
|
|
575
611
|
/**
|
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.190";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
package/dist/lanes.js
CHANGED
|
@@ -3,7 +3,7 @@ import { execFile } from "node:child_process";
|
|
|
3
3
|
import { readFile, realpath, writeFile } from "node:fs/promises";
|
|
4
4
|
import { isAbsolute, join } from "node:path";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
|
-
import { coordinatorMachineId, listAccounts, liveExhaustedAccounts, pickHeadroomAccount, profilePath, reportUsage } from "./accounts.js";
|
|
6
|
+
import { accountExcluded, coordinatorMachineId, listAccounts, liveExhaustedAccounts, pickHeadroomAccount, profilePath, reportUsage } from "./accounts.js";
|
|
7
7
|
import { CliError, encode, devRequest, query, readConfig, requireFlag, LANE_CAP_RAISE_PROMPT } from "./core.js";
|
|
8
8
|
import { launchRecovery, recoveryStateRoot } from "./runtime-launcher.js";
|
|
9
9
|
import { defaultReaders, fingerprintStore, resumeGate } from "./resume-gate.js";
|
|
@@ -1121,6 +1121,9 @@ export async function laneCommand(action, args, flags, deps = {}) {
|
|
|
1121
1121
|
const exhausted = await exhaustedAccounts().catch(() => ({}));
|
|
1122
1122
|
const refusal = (profile, entry, why) => new CliError("ACCOUNT_EXHAUSTED", `${ref}: ${profile} is recorded exhausted (${entry.kind}) until ${entry.until}${why}. Resume it after that, or move it with lane resume ${ref} --profile PATH --class long|short|no-build to another account.`, 1);
|
|
1123
1123
|
if (named && exhausted[named.profile]) throw refusal(named.profile, exhausted[named.profile], "");
|
|
1124
|
+
// hub-242: an account the operator ruled out is never used, even when named.
|
|
1125
|
+
if (named && await (deps.accountExcluded ?? accountExcluded)(named.profile))
|
|
1126
|
+
throw new CliError("ACCOUNT_EXCLUDED", `${ref}: ${named.profile} is excluded from lanes (coordinator settings.json excludedProfiles, the operator's ruling). Name another account with --profile PATH.`, 1);
|
|
1124
1127
|
let target = named;
|
|
1125
1128
|
let picked = null;
|
|
1126
1129
|
if (!named && Object.keys(exhausted).length) {
|
package/dist/review.js
CHANGED
|
@@ -12,6 +12,7 @@ import { promisify } from "node:util";
|
|
|
12
12
|
import { CliError, encode } from "./core.js";
|
|
13
13
|
import { pickerPrompt } from "./gather.js";
|
|
14
14
|
import { componentSetsIn, designCatalogSets } from "./figma-scope.js";
|
|
15
|
+
import { figmaClient, figmaToken } from "./design.js";
|
|
15
16
|
import { holdsSet, scopeText } from "./figma.js";
|
|
16
17
|
import { gitPrivatePath } from "./safety.js";
|
|
17
18
|
import { GENERATED_PAGE_GLOB, GENERATED_SUFFIX, hasGeneratedPageStamp } from "./surface.js";
|
|
@@ -687,7 +688,7 @@ export const frameUrl = (fileKey, nodeId) => `https://www.figma.com/design/${fil
|
|
|
687
688
|
* or, for a DS component set, its own node as the design catalogue
|
|
688
689
|
* publishes it under the key (NODII-DEV-CLI-70); a whole-file boundary is the whole file.
|
|
689
690
|
*/
|
|
690
|
-
export async function boundaryFrames(figma, { catalog, lookupSet = designCatalogSets() } = {}) {
|
|
691
|
+
export async function boundaryFrames(figma, { catalog, lookupSet = designCatalogSets(), resolveKey = figmaKeyResolver() } = {}) {
|
|
691
692
|
const surfaces = figma.some((file) => file.componentSetKeys?.length) ? await catalog() : [];
|
|
692
693
|
const frames = [];
|
|
693
694
|
for (const file of figma) {
|
|
@@ -699,11 +700,83 @@ export async function boundaryFrames(figma, { catalog, lookupSet = designCatalog
|
|
|
699
700
|
if (error?.code === "FIGMA_KEY_UNKNOWN") throw new ReviewerError("CRASH", `the Freeze's Figma boundary: ${error.message}`);
|
|
700
701
|
throw error;
|
|
701
702
|
}
|
|
702
|
-
for (const key of keys)
|
|
703
|
+
for (const key of keys) {
|
|
704
|
+
const seen = new Set();
|
|
705
|
+
for (const frame of await framesAsNodes(file.fileKey, key, sets.get(key).frames, resolveKey)) {
|
|
706
|
+
if (seen.has(frame.nodeId)) continue;
|
|
707
|
+
seen.add(frame.nodeId);
|
|
708
|
+
frames.push({ fileKey: file.fileKey, ...frame });
|
|
709
|
+
}
|
|
710
|
+
}
|
|
703
711
|
}
|
|
704
712
|
return frames;
|
|
705
713
|
}
|
|
706
714
|
|
|
715
|
+
/**
|
|
716
|
+
* hub-594: since SWAP-7cb36363 the DS catalog maps a Surface's
|
|
717
|
+
* states to published component KEYS, not node ids. Figma's /nodes takes
|
|
718
|
+
* node ids only (a key is a 400), so each key is resolved to its node first.
|
|
719
|
+
* A state key Figma does not know (an unpublished state) falls back to its
|
|
720
|
+
* set's own node; when neither resolves, the boundary is a named CRASH.
|
|
721
|
+
*/
|
|
722
|
+
async function framesAsNodes(fileKey, setKey, frames, resolveKey) {
|
|
723
|
+
const isKey = (id) => COMPONENT_KEY.test(String(id ?? ""));
|
|
724
|
+
if (!frames.some((frame) => isKey(frame.nodeId))) return frames;
|
|
725
|
+
const homeIn = async (key) => {
|
|
726
|
+
const home = await resolveKey(key, fileKey);
|
|
727
|
+
return home?.nodeId && (!home.fileKey || home.fileKey === fileKey) ? String(home.nodeId) : null;
|
|
728
|
+
};
|
|
729
|
+
let setNode;
|
|
730
|
+
const out = [];
|
|
731
|
+
const unresolved = [];
|
|
732
|
+
for (const frame of frames) {
|
|
733
|
+
if (!isKey(frame.nodeId)) { out.push(frame); continue; }
|
|
734
|
+
let nodeId = await homeIn(frame.nodeId);
|
|
735
|
+
if (!nodeId) {
|
|
736
|
+
setNode ??= { nodeId: await homeIn(setKey) };
|
|
737
|
+
nodeId = setNode.nodeId;
|
|
738
|
+
}
|
|
739
|
+
if (!nodeId) { unresolved.push(`${frame.state} (${frame.nodeId})`); continue; }
|
|
740
|
+
out.push({ ...frame, nodeId });
|
|
741
|
+
}
|
|
742
|
+
if (unresolved.length)
|
|
743
|
+
throw new ReviewerError("CRASH", `the Freeze's Figma boundary: set ${setKey} in ${fileKey} names state component keys Figma resolves to no node, and the set's own key resolves to none either: ${unresolved.join(", ")}. Publish the set, or name its frames by node id.`);
|
|
744
|
+
return out;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
const COMPONENT_KEY = /^[0-9a-f]{40}$/;
|
|
748
|
+
|
|
749
|
+
/**
|
|
750
|
+
* Figma's published components and component sets of a file, on FIGMA_PAT:
|
|
751
|
+
* two listing reads per file, cached, so a Surface with many states costs no
|
|
752
|
+
* per-key read (the machine paces Figma at one call per 8 s). A key the file
|
|
753
|
+
* does not publish resolves to null.
|
|
754
|
+
*/
|
|
755
|
+
export function figmaKeyResolver({ env = process.env, figmaGet } = {}) {
|
|
756
|
+
let get = figmaGet;
|
|
757
|
+
const files = new Map();
|
|
758
|
+
const listing = async (path) => {
|
|
759
|
+
try { return (await get(path)).meta ?? {}; }
|
|
760
|
+
catch (error) {
|
|
761
|
+
if (error instanceof CliError && error.code === "FIGMA_NOT_FOUND") return {};
|
|
762
|
+
throw error;
|
|
763
|
+
}
|
|
764
|
+
};
|
|
765
|
+
const homes = (fileKey) => {
|
|
766
|
+
if (!files.has(fileKey))
|
|
767
|
+
files.set(fileKey, (async () => {
|
|
768
|
+
get ??= figmaClient(figmaToken(env));
|
|
769
|
+
const byKey = new Map();
|
|
770
|
+
for (const kind of ["components", "component_sets"])
|
|
771
|
+
for (const row of (await listing(`/files/${encodeURIComponent(fileKey)}/${kind}`))[kind] ?? [])
|
|
772
|
+
if (row?.key && row?.node_id) byKey.set(String(row.key), { fileKey, nodeId: String(row.node_id) });
|
|
773
|
+
return byKey;
|
|
774
|
+
})());
|
|
775
|
+
return files.get(fileKey);
|
|
776
|
+
};
|
|
777
|
+
return async (key, fileKey) => (fileKey ? (await homes(fileKey)).get(key) ?? null : null);
|
|
778
|
+
}
|
|
779
|
+
|
|
707
780
|
/**
|
|
708
781
|
* MW2-38.3: the nodes of the change sets a lane's agent holds in each
|
|
709
782
|
* boundary file Dev registers as the design system. Returns
|
package/dist/watchdog.js
CHANGED
|
@@ -419,7 +419,7 @@ export function watchdogPath(envPath = process.env.PATH, runtime = process.execP
|
|
|
419
419
|
|
|
420
420
|
export function launchdPlist({ runtime, entry, config, interval, stdoutPath, stderrPath, path = watchdogPath(undefined, runtime) }) {
|
|
421
421
|
const args = [runtime, entry, "watchdog", "sweep", "--json"].map((value) => `<string>${xml(value)}</string>`).join("");
|
|
422
|
-
return `<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0"><dict><key>Label</key><string>${WATCHDOG_LABEL}</string><key>ProgramArguments</key><array>${args}</array><key>EnvironmentVariables</key><dict><key>NODII_DEV_CONFIG_PATH</key><string>${xml(config)}</string><key>PATH</key><string>${xml(path)}</string></dict><key>RunAtLoad</key><true/><key>StartInterval</key><integer>${interval}</integer><key>ProcessType</key><string>
|
|
422
|
+
return `<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0"><dict><key>Label</key><string>${WATCHDOG_LABEL}</string><key>ProgramArguments</key><array>${args}</array><key>EnvironmentVariables</key><dict><key>NODII_DEV_CONFIG_PATH</key><string>${xml(config)}</string><key>PATH</key><string>${xml(path)}</string></dict><key>RunAtLoad</key><true/><key>StartInterval</key><integer>${interval}</integer><key>ProcessType</key><string>Standard</string><key>StandardOutPath</key><string>${xml(stdoutPath)}</string><key>StandardErrorPath</key><string>${xml(stderrPath)}</string></dict></plist>\n`;
|
|
423
423
|
}
|
|
424
424
|
|
|
425
425
|
/**
|