@nodii/dev 0.6.147 → 0.6.149
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 +12 -2
- package/dist/core.js +55 -3
- package/dist/freeze.js +14 -9
- package/dist/nodii-dev.js +3 -1
- package/dist/read-cache.js +75 -0
- package/dist/runs.js +8 -2
- package/dist/starting.js +5 -2
- package/dist/surface.js +7 -1
- package/dist/vendor/ds-conformance.mjs +190 -24
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -35,6 +35,7 @@ import { installManagedLatest, managedStatus } from "./managed-version.js";
|
|
|
35
35
|
import { dispatchManagedClaudeHook, dispatchManagedHook } from "./managed-hooks.js";
|
|
36
36
|
import { governorCommand, laneClose } from "./governor.js";
|
|
37
37
|
import { freezeCommand } from "./freeze.js";
|
|
38
|
+
import { laneReadCache } from "./read-cache.js";
|
|
38
39
|
import {
|
|
39
40
|
figmaChangeSetShow,
|
|
40
41
|
figmaChangeSetList,
|
|
@@ -838,6 +839,14 @@ export async function figmaFileAdd(value, flags, { request = devRequest } = {})
|
|
|
838
839
|
// blocks the lane: a blocked lane needs them to unblock itself (AGENT-HARNESS-14).
|
|
839
840
|
const readsHelp = (argv) => argv[0] === "help" || argv.some((token) => ["--help", "-h"].includes(token)) || (argv.length === 1 && ["--version", "-v"].includes(argv[0]));
|
|
840
841
|
|
|
842
|
+
// cli-134: the managed hooks run this backstop on every tool call (one lane read
|
|
843
|
+
// both routes about once a second), yet a hook cannot enforce it: a hook exits 0
|
|
844
|
+
// on anything but a SAFETY_ or Figma denial, and its banner is never claimed. So
|
|
845
|
+
// a hook reuses an answer for 15 seconds. Every other command reads Dev fresh,
|
|
846
|
+
// so it is blocked by an unacknowledged amendment (CTRL-CLI-34) and shows a
|
|
847
|
+
// new Result (MW5-16) on its next call, exactly as before.
|
|
848
|
+
export const backstopCache = (argv) => (argv[0] === "hook" ? laneReadCache() : null);
|
|
849
|
+
|
|
841
850
|
export async function main(argv = process.argv.slice(2)) {
|
|
842
851
|
// Ahead of every check that reaches Dev: a session the lane spawned gets
|
|
843
852
|
// nothing from these hooks. The safety hooks still run.
|
|
@@ -851,8 +860,9 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
851
860
|
// The heartbeat hook fires on every tool call, so these checks would call Dev each
|
|
852
861
|
// time past its rate limit, and a failed check would silently stop the heartbeat.
|
|
853
862
|
if (argv[0] !== "__run-supervisor" && !readsHelp(argv) && !(argv[0] === "hook" && (argv[1]?.startsWith("nudge-") || argv[1] === "surface-gen-pre" || argv[1] === "lane-heartbeat"))) {
|
|
854
|
-
|
|
855
|
-
await
|
|
863
|
+
const cache = backstopCache(argv);
|
|
864
|
+
await amendmentGuard(argv, { cache });
|
|
865
|
+
await showWaitingResults({ acknowledge: argv[0] !== "hook", cache });
|
|
856
866
|
}
|
|
857
867
|
if (argv.length === 1 && ["--version", "-v"].includes(argv[0]))
|
|
858
868
|
return console.log(VERSION);
|
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.149";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
|
@@ -135,7 +135,56 @@ const withSignal = (promise, signal) => {
|
|
|
135
135
|
});
|
|
136
136
|
};
|
|
137
137
|
|
|
138
|
+
// cli-134: a 429 with Retry-After is shown and waited out once, then the call
|
|
139
|
+
// is sent once more; a second 429, a missing Retry-After or a wait longer than
|
|
140
|
+
// RETRY_AFTER_MAX_MS is surfaced with Dev's message. Never a loop.
|
|
141
|
+
export const RETRY_AFTER_MAX_MS = 20_000;
|
|
142
|
+
const defaultRetrySleep = (ms, signal) => new Promise((resolvePromise, rejectPromise) => {
|
|
143
|
+
const timer = setTimeout(resolvePromise, ms);
|
|
144
|
+
signal?.addEventListener("abort", () => { clearTimeout(timer); rejectPromise(signal.reason ?? new Error("aborted")); }, { once: true });
|
|
145
|
+
});
|
|
146
|
+
let retrySleep = defaultRetrySleep;
|
|
147
|
+
/** Tests replace the Retry-After wait; `null` restores the real one. */
|
|
148
|
+
export function setRetrySleep(fn) {
|
|
149
|
+
retrySleep = fn ?? defaultRetrySleep;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Retry-After in milliseconds (delta-seconds or an HTTP date), or null. */
|
|
153
|
+
export function retryAfterMs(value, now = Date.now()) {
|
|
154
|
+
const text = String(value ?? "").trim();
|
|
155
|
+
if (!text) return null;
|
|
156
|
+
if (/^\d+$/.test(text)) return Number(text) * 1000;
|
|
157
|
+
const at = Date.parse(text);
|
|
158
|
+
return Number.isFinite(at) ? Math.max(0, at - now) : null;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const refusalMessage = (raw) => {
|
|
162
|
+
try {
|
|
163
|
+
return JSON.parse(raw)?.message ?? null;
|
|
164
|
+
} catch {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
138
169
|
async function devFetchOnce(method, path, bodyText, contentType, accept, extra = {}, signal) {
|
|
170
|
+
const first = await devFetchSend(method, path, bodyText, contentType, accept, extra, signal);
|
|
171
|
+
if (first.response.status !== 429) return first;
|
|
172
|
+
const waitMs = retryAfterMs(first.response.headers?.get?.("retry-after"));
|
|
173
|
+
if (waitMs === null || waitMs > RETRY_AFTER_MAX_MS) return first;
|
|
174
|
+
const seconds = Math.ceil(waitMs / 1000);
|
|
175
|
+
try {
|
|
176
|
+
process.stderr.write(`Dev is rate limiting ${method} ${path}: ${refusalMessage(first.raw) ?? "HTTP 429"} Waiting ${seconds} s as Dev asks, then sending it once more.\n`);
|
|
177
|
+
} catch {}
|
|
178
|
+
try {
|
|
179
|
+
await retrySleep(waitMs, signal);
|
|
180
|
+
} catch (error) {
|
|
181
|
+
if (signal?.aborted) throw new CliError("DEV_TIMEOUT", `Dev request timed out: ${method} ${path}`, 1);
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
return devFetchSend(method, path, bodyText, contentType, accept, extra, signal);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async function devFetchSend(method, path, bodyText, contentType, accept, extra = {}, signal) {
|
|
139
188
|
const wait = async (promise) => {
|
|
140
189
|
try {
|
|
141
190
|
return await withSignal(promise, signal);
|
|
@@ -301,13 +350,16 @@ export async function devExchange(method, path, bodyText, { contentType = "appli
|
|
|
301
350
|
}
|
|
302
351
|
// Dev answers pending work as 202 with its error envelope (FIGMA_PLACEMENT_PENDING):
|
|
303
352
|
// a 2xx alone doesn't mean the change was made.
|
|
304
|
-
if (!response.ok || payload.error === true)
|
|
353
|
+
if (!response.ok || payload.error === true) {
|
|
354
|
+
const waitMs = response.status === 429 ? retryAfterMs(response.headers?.get?.("retry-after")) : null;
|
|
355
|
+
const after = waitMs === null ? "" : ` Dev asks to wait ${Math.ceil(waitMs / 1000)} s before trying again.`;
|
|
305
356
|
throw new CliError(
|
|
306
357
|
payload.code ?? `HTTP_${response.status}`,
|
|
307
|
-
payload.message ?? `Dev returned HTTP ${response.status}`,
|
|
358
|
+
`${payload.message ?? `Dev returned HTTP ${response.status}`}${after}`,
|
|
308
359
|
1,
|
|
309
360
|
payload.details,
|
|
310
361
|
);
|
|
362
|
+
}
|
|
311
363
|
return { status: response.status, payload };
|
|
312
364
|
}
|
|
313
365
|
|
package/dist/freeze.js
CHANGED
|
@@ -3,6 +3,7 @@ import { readFile, realpath } from "node:fs/promises";
|
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
5
|
import { CliError, devRequest, encode, query, readConfig, requireFlag } from "./core.js";
|
|
6
|
+
import { cachedGet, cachingRequest } from "./read-cache.js";
|
|
6
7
|
|
|
7
8
|
const execFileAsync = promisify(execFile);
|
|
8
9
|
const TERMINAL = new Set(["on_dev", "stopped", "non_issue"]);
|
|
@@ -262,11 +263,13 @@ async function acknowledge(ref, data, request) {
|
|
|
262
263
|
*/
|
|
263
264
|
export async function regroundCurrentLane(
|
|
264
265
|
{ cwd = process.cwd(), force = false, write = (text) => process.stderr.write(text) } = {},
|
|
265
|
-
{ request = devRequest, config = readConfig } = {},
|
|
266
|
+
{ request = devRequest, config = readConfig, cache = null } = {},
|
|
266
267
|
) {
|
|
267
|
-
|
|
268
|
+
// cli-134: the entry point passes the lane read cache, so a script calling
|
|
269
|
+
// nodii-dev twice a second finds its lane and Freeze at most once per 15 s.
|
|
270
|
+
const lane = await currentLane({ cwd }, { request: cachingRequest(cache, request), config });
|
|
268
271
|
if (!lane) return { shown: false, reason: "no active lane" };
|
|
269
|
-
return regroundLane(lane, { force, write }, { request });
|
|
272
|
+
return regroundLane(lane, { force, write }, { request, cache });
|
|
270
273
|
}
|
|
271
274
|
|
|
272
275
|
/**
|
|
@@ -276,12 +279,12 @@ export async function regroundCurrentLane(
|
|
|
276
279
|
export async function regroundLane(
|
|
277
280
|
lane,
|
|
278
281
|
{ force = false, write = (text) => process.stderr.write(text) } = {},
|
|
279
|
-
{ request = devRequest } = {},
|
|
282
|
+
{ request = devRequest, cache = null } = {},
|
|
280
283
|
) {
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
);
|
|
284
|
+
const path = `/api/v1/lanes/${encode(lane.key)}/freeze`;
|
|
285
|
+
// A Freeze that asks to be acknowledged is never cached: it is shown and
|
|
286
|
+
// acknowledged from Dev's own answer, and only then remembered as acknowledged.
|
|
287
|
+
const response = await cachedGet(force ? null : cache, request, path, (answer) => !answer?.data?.requiresAcknowledgement);
|
|
285
288
|
const data = response.data;
|
|
286
289
|
if (!data?.freeze || !data.markdown)
|
|
287
290
|
return { shown: false, reason: "Freeze not initialized", lane };
|
|
@@ -289,7 +292,9 @@ export async function regroundLane(
|
|
|
289
292
|
return { shown: false, reason: "already acknowledged", lane, data };
|
|
290
293
|
write(`Freeze re-grounding for ${lane.key} (v${data.version}):\n${data.markdown}\n`);
|
|
291
294
|
await acknowledge(lane.key, data, request);
|
|
292
|
-
|
|
295
|
+
const acknowledged = { ...data, acknowledged: true, requiresAcknowledgement: false };
|
|
296
|
+
await cache?.set(path, { ...response, data: acknowledged });
|
|
297
|
+
return { shown: true, lane, data: acknowledged };
|
|
293
298
|
}
|
|
294
299
|
|
|
295
300
|
async function valueFromFile(flags, read) {
|
package/dist/nodii-dev.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { fail, main } from "./cli.js";
|
|
3
3
|
import { regroundCurrentLane, shouldReground } from "./freeze.js";
|
|
4
4
|
import { isHookDenial } from "./hooks.js";
|
|
5
|
+
import { laneReadCache } from "./read-cache.js";
|
|
5
6
|
import { drainStdout, routeStdout } from "./stdout.js";
|
|
6
7
|
|
|
7
8
|
routeStdout();
|
|
@@ -21,7 +22,8 @@ async function run() {
|
|
|
21
22
|
}
|
|
22
23
|
// AGENT-HARNESS-19: this is the executable boundary, so every ordinary CLI
|
|
23
24
|
// invocation re-grounds without adding hidden requests to library callers.
|
|
24
|
-
|
|
25
|
+
// cli-134: through the lane read cache, at most once per 15 seconds.
|
|
26
|
+
if (shouldReground(argv)) await regroundCurrentLane({}, { cache: laneReadCache() });
|
|
25
27
|
await main(argv);
|
|
26
28
|
}
|
|
27
29
|
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { configPath } from "./core.js";
|
|
5
|
+
|
|
6
|
+
// cli-134: every nodii-dev invocation from a lane (the managed hooks run on every
|
|
7
|
+
// tool call) read the lane's amendments, the run's results and the lane's Freeze.
|
|
8
|
+
// One lane made 1,322 requests in 10 minutes. These reads now go through a small
|
|
9
|
+
// on-disk cache: a repeat within 15 seconds reuses the last answer, so an approved
|
|
10
|
+
// amendment or a new Freeze still reaches the lane within about 15 seconds.
|
|
11
|
+
// Only "nothing to do" answers are kept (see each caller): an answer that blocks
|
|
12
|
+
// the lane or asks for an acknowledgement is always read fresh.
|
|
13
|
+
export const READ_CACHE_TTL_MS = 15_000;
|
|
14
|
+
const PRUNE_AFTER_MS = 60 * 60_000;
|
|
15
|
+
|
|
16
|
+
const defaultDir = () => join(dirname(configPath()), "read-cache");
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A best-effort cache keyed by Dev path (and this agent's config). Every file
|
|
20
|
+
* error is a miss: the cache never fails a command.
|
|
21
|
+
*/
|
|
22
|
+
export function laneReadCache({ dir = defaultDir(), ttlMs = READ_CACHE_TTL_MS, now = Date.now } = {}) {
|
|
23
|
+
const scope = configPath();
|
|
24
|
+
const file = (path) => join(dir, `${createHash("sha256").update(`${scope}\n${path}`).digest("hex").slice(0, 32)}.json`);
|
|
25
|
+
return {
|
|
26
|
+
async get(path) {
|
|
27
|
+
try {
|
|
28
|
+
const entry = JSON.parse(await readFile(file(path), "utf8"));
|
|
29
|
+
const age = now() - entry.at;
|
|
30
|
+
if (entry.path !== path || !(age >= 0 && age < ttlMs)) return undefined;
|
|
31
|
+
return entry.value;
|
|
32
|
+
} catch {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
async set(path, value) {
|
|
37
|
+
try {
|
|
38
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
39
|
+
const target = file(path);
|
|
40
|
+
const temporary = `${target}.${process.pid}.${randomUUID()}`;
|
|
41
|
+
await writeFile(temporary, JSON.stringify({ path, at: now(), value }), { mode: 0o600 });
|
|
42
|
+
await rename(temporary, target);
|
|
43
|
+
if (Math.random() < 0.05) await prune(dir, now());
|
|
44
|
+
} catch {}
|
|
45
|
+
},
|
|
46
|
+
async drop(path) {
|
|
47
|
+
try {
|
|
48
|
+
await rm(file(path), { force: true });
|
|
49
|
+
} catch {}
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function prune(dir, at) {
|
|
55
|
+
for (const name of await readdir(dir)) {
|
|
56
|
+
try {
|
|
57
|
+
const path = join(dir, name);
|
|
58
|
+
if (at - (await stat(path)).mtimeMs > PRUNE_AFTER_MS) await rm(path, { force: true });
|
|
59
|
+
} catch {}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** A GET through the cache: a fresh entry answers; else Dev does, and `keep(answer)` decides whether to store it. */
|
|
64
|
+
export async function cachedGet(cache, request, path, keep = () => true) {
|
|
65
|
+
if (!cache) return request("GET", path);
|
|
66
|
+
const hit = await cache.get(path);
|
|
67
|
+
if (hit !== undefined) return hit;
|
|
68
|
+
const answer = await request("GET", path);
|
|
69
|
+
if (keep(answer)) await cache.set(path, answer);
|
|
70
|
+
return answer;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** A request function whose GETs go through the cache; every other method goes to Dev. */
|
|
74
|
+
export const cachingRequest = (cache, request) =>
|
|
75
|
+
cache ? (method, path, body, options) => (method === "GET" && body === undefined ? cachedGet(cache, request, path) : request(method, path, body, options)) : request;
|
package/dist/runs.js
CHANGED
|
@@ -4,6 +4,7 @@ import { readFile } from "node:fs/promises";
|
|
|
4
4
|
import { basename } from "node:path";
|
|
5
5
|
import { CliError, devRequest, encode } from "./core.js";
|
|
6
6
|
import { heavySlotArgv, needsSlot } from "./heavy.js";
|
|
7
|
+
import { cachedGet } from "./read-cache.js";
|
|
7
8
|
|
|
8
9
|
export const RUN_ID_ENV = "NODII_DEV_RUN_ID";
|
|
9
10
|
const DEFAULT_HEARTBEAT_MS = 60_000;
|
|
@@ -80,12 +81,17 @@ export async function showWaitingResults({
|
|
|
80
81
|
request = devRequest,
|
|
81
82
|
write = (value) => process.stderr.write(value),
|
|
82
83
|
acknowledge = true,
|
|
84
|
+
cache = null,
|
|
83
85
|
} = {}) {
|
|
84
86
|
const waiterRunId = currentRunId(runId);
|
|
85
87
|
if (!waiterRunId) return [];
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
// cli-134: only "no results waiting" is cached; a waiting result is always
|
|
89
|
+
// read fresh, so it is shown and acknowledged from Dev's own answer.
|
|
90
|
+
const payload = await cachedGet(
|
|
91
|
+
cache,
|
|
92
|
+
request,
|
|
88
93
|
`/api/v1/runs/${encode(waiterRunId)}/results`,
|
|
94
|
+
(answer) => Array.isArray(answer?.data) && !answer.data.length,
|
|
89
95
|
);
|
|
90
96
|
const results = payload.data ?? [];
|
|
91
97
|
if (!results.length) return [];
|
package/dist/starting.js
CHANGED
|
@@ -10,6 +10,7 @@ import { laneCommand, nextCommand } from "./lanes.js";
|
|
|
10
10
|
import { assertGovernorOpen, readGovernor } from "./governor.js";
|
|
11
11
|
import { laneConfigName } from "./lane-env.js";
|
|
12
12
|
import { hostBootedAt } from "./host.js";
|
|
13
|
+
import { cachedGet } from "./read-cache.js";
|
|
13
14
|
import { accountFlags, listAccounts, profilePath, registerAccount, reportUsage, usageLine } from "./accounts.js";
|
|
14
15
|
|
|
15
16
|
const execFile = promisify(execFileCallback);
|
|
@@ -951,12 +952,14 @@ export async function currentMarker(run = execFile, load = loadJson, env = proce
|
|
|
951
952
|
return { ...marker, runId };
|
|
952
953
|
}
|
|
953
954
|
|
|
954
|
-
export async function amendmentGuard(argv, { request = devRequest, marker = currentMarker } = {}) {
|
|
955
|
+
export async function amendmentGuard(argv, { request = devRequest, marker = currentMarker, cache = null } = {}) {
|
|
955
956
|
const lane = await marker();
|
|
956
957
|
if (!lane) return null;
|
|
957
958
|
const [command, action] = argv.filter((token) => !token.startsWith("--"));
|
|
958
959
|
if ((command === "lane" && action === "gather" && argv.includes("--delta")) || (command === "lane" && action === "amend")) return lane;
|
|
959
|
-
|
|
960
|
+
// cli-134: only "nothing pending" is cached, so a pending amendment always
|
|
961
|
+
// blocks from Dev's own answer and its acknowledgement is seen at once.
|
|
962
|
+
const pending = await cachedGet(cache, request, `/api/v1/lanes/${encode(lane.laneKey)}/amendments${query({ runId: lane.runId })}`, (answer) => Array.isArray(answer?.data) && !answer.data.length);
|
|
960
963
|
if (!pending.data.length) return lane;
|
|
961
964
|
const detail = pending.data.map((item) => `v${item.version} ${item.reason}: ${JSON.stringify(item.change)}`).join("\n");
|
|
962
965
|
const next = `nodii-dev lane gather ${lane.laneKey} --delta`;
|
package/dist/surface.js
CHANGED
|
@@ -1451,7 +1451,8 @@ function liftFieldControls(code, node, ctx, lift, scope) {
|
|
|
1451
1451
|
}
|
|
1452
1452
|
|
|
1453
1453
|
/** A metric card's values that are Figma's sample, never copy (NODII-DEV-CLI-84). */
|
|
1454
|
-
|
|
1454
|
+
// statusTone and tone are the KPI's state ("Unresolved" warning or danger), never the sample's dot (hub-477).
|
|
1455
|
+
const METRIC_VALUES = ["value", "caption", "changeAmount", "period", "statusTone", "tone"];
|
|
1455
1456
|
|
|
1456
1457
|
/**
|
|
1457
1458
|
* Each opening tag of `names` (a regex alternation) in `code`, its attributes
|
|
@@ -2286,6 +2287,11 @@ function tabStrip(run, ctx) {
|
|
|
2286
2287
|
const triggers = tabs.map((t, i) => {
|
|
2287
2288
|
let trigger = t.trigger.replace(/(<TabsTrigger\b[\s\S]*?)\bvalue="tab"/, `$1value="${values[i]}"`);
|
|
2288
2289
|
if (counted[i]) trigger = trigger.replace(counted[i], `{${mark(ctx, strip, joinName(camelName(values[i]), "tabLabel"), null)}}`);
|
|
2290
|
+
// A tab's count badge counts the viewer's action items: the page's, named by its tab, never
|
|
2291
|
+
// Figma's sample (`actionableCount={5}`) or one count every tab shares; its floor ("99+") too (hub-477).
|
|
2292
|
+
const own = (prop) => `${prop}={${mark(ctx, strip, joinName(camelName(values[i]), prop), null)}}`;
|
|
2293
|
+
trigger = trigger.replace(/(<TabsTrigger\b[\s\S]*?)\bactionableCount=\{(?:\d+|(?:__s\d+_)?actionableCount)\}/, (_, head) => `${head}${own("actionableCount")}`);
|
|
2294
|
+
trigger = trigger.replace(/(<TabsTrigger\b[\s\S]*?)\bcountIsFloor(?=\s|>)/, (_, head) => `${head}${own("countIsFloor")}`);
|
|
2289
2295
|
return shownWhen(`(${visible}?.includes(${JSON.stringify(values[i])}) ?? true)`, indent(trigger, 3), 2);
|
|
2290
2296
|
});
|
|
2291
2297
|
return [
|
|
@@ -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.
|
|
33
|
+
export const VERSION = "1.0.16";
|
|
34
34
|
|
|
35
35
|
/** @typedef {{ nodeId: string, check: string, detail: string }} Finding */
|
|
36
36
|
/**
|
|
@@ -140,6 +140,26 @@ const PERSON_NAME_COMPONENT_SET_KEY =
|
|
|
140
140
|
"08370f38bcbbcf88eaf3a6923dc91b5de5f38ea0";
|
|
141
141
|
const TABLE_COMPONENT_SET_KEY = "7ccc1dbb6ebd149fb9aaf42b9c638f5ce7169638";
|
|
142
142
|
const TABLE_CELL_COMPONENT_SET_KEY = "528898c19702ed4b169d023de30380e05169dfa5";
|
|
143
|
+
// The sets a product screen composes a library component from, by the name
|
|
144
|
+
// of the frame that holds them (hub-488). The library publishes the table's
|
|
145
|
+
// header, cells and tree rows as sets of their own, so a product table is a
|
|
146
|
+
// frame of rows of them. These are the Table entry's family sets in the
|
|
147
|
+
// design catalogue (figma.familySets): Table cell, Table Header, Table Rich
|
|
148
|
+
// Cell, Table Tree Branch Row, Table Tree Leaf Row. Listed by key, not by a
|
|
149
|
+
// "Table " name prefix: Alert Dialog is no part of Alert, nor Button Group
|
|
150
|
+
// of Button, and another file's set of the same name is not the library's.
|
|
151
|
+
const LIBRARY_PARTS = new Map([
|
|
152
|
+
[
|
|
153
|
+
"Table",
|
|
154
|
+
new Set([
|
|
155
|
+
TABLE_CELL_COMPONENT_SET_KEY,
|
|
156
|
+
"00021ae4ef4ba8069387315ad45ff56b7d850060",
|
|
157
|
+
"7addadd082840b7593cee54da20029fa33a30404",
|
|
158
|
+
"f6c4560fd9b9bd2d552b3b173616b3251e9f35f8",
|
|
159
|
+
"b1a781204386a699581a1a1ef332b21c8f35f454",
|
|
160
|
+
]),
|
|
161
|
+
],
|
|
162
|
+
]);
|
|
143
163
|
const ITEM_COMPONENT_SET_KEY = "46abc8cb0d57c22a365da94a03cfd72a0b089b87";
|
|
144
164
|
const SELF_COMPONENT_SET_KEYS = new Set([
|
|
145
165
|
"af8df2e85ba4d53b26b28ffa69f264758a50fe66", // Account Context
|
|
@@ -173,6 +193,20 @@ const PERSON_FIELD =
|
|
|
173
193
|
/\b(user|member|customer|recipient|applicant|employee|candidate|assignee|owner|invitee|requester|reviewer|agent|engineer|staff|rep|manager|person|personal|your|my)\b/i;
|
|
174
194
|
// A field's frame names its label: field/Caller ID, select/Sender ID.
|
|
175
195
|
const FIELD_FRAME = /^(field|select|input|textarea|kv|detail|row) ?\/ ?(.+)$/i;
|
|
196
|
+
// A field part from the library: its value, label and hint are one field.
|
|
197
|
+
const FIELD_PART = /\b(field|input|text ?area|select|kv)\b/i;
|
|
198
|
+
// A field's label or hint that says the value is the viewer's own
|
|
199
|
+
// (hub-236): "Your own address is filled in", "Your email",
|
|
200
|
+
// "Your phone number". "Your provider" or "your customer's email" is not.
|
|
201
|
+
const SELF_FIELD =
|
|
202
|
+
/\byour (own\b|(e-?mail|email address|address|phone|phone number|mobile|mobile number|name|full name)\b)/i;
|
|
203
|
+
// "(you)" marks the viewer in a list, picker or people cell (U05-7).
|
|
204
|
+
const YOU_MARKER = /\(you\)/i;
|
|
205
|
+
// An Aadhaar number: twelve digits, the first 2-9, grouped 4-4-4 as it is
|
|
206
|
+
// written. It stays last-four for every viewer, its owner too (PII-26).
|
|
207
|
+
const AADHAAR = /(?<![\w.+\-/])[2-9]\d{3}[ -]\d{4}[ -]\d{4}(?![\w\-/])/g;
|
|
208
|
+
const AADHAAR_RUN = /(?<![\w.+\-/])[2-9]\d{11}(?![\w\-/])/g;
|
|
209
|
+
const AADHAAR_FIELD = /\baadhaa?r\b/i;
|
|
176
210
|
|
|
177
211
|
/** "I12:34;56:78" -> ["12:34", "56:78"]; "12:34" -> ["12:34"]. */
|
|
178
212
|
const segments = (id) => (id.startsWith("I") ? id.slice(1) : id).split(";");
|
|
@@ -362,6 +396,8 @@ function analyse(entry, mains, library = false) {
|
|
|
362
396
|
};
|
|
363
397
|
const componentLabel = (inst) =>
|
|
364
398
|
setOf(inst)?.name ?? componentOf(inst)?.name ?? inst.name;
|
|
399
|
+
const setNameOf = (id) =>
|
|
400
|
+
componentSets[components[id]?.componentSetId]?.name;
|
|
365
401
|
// What the app-UI gate leaves out: each root, outermost first (byId is in
|
|
366
402
|
// document order, so a parent is decided before its children).
|
|
367
403
|
/** @type {Map<string, string>} */
|
|
@@ -375,7 +411,7 @@ function analyse(entry, mains, library = false) {
|
|
|
375
411
|
out.add(n.id);
|
|
376
412
|
continue;
|
|
377
413
|
}
|
|
378
|
-
const why = outOfScopeRoot(n, parent, componentLabel, placedMemo);
|
|
414
|
+
const why = outOfScopeRoot(n, parent, componentLabel, placedMemo, setNameOf);
|
|
379
415
|
if (why) {
|
|
380
416
|
out.add(n.id);
|
|
381
417
|
scopeRoots.set(n.id, why);
|
|
@@ -385,6 +421,7 @@ function analyse(entry, mains, library = false) {
|
|
|
385
421
|
root,
|
|
386
422
|
components,
|
|
387
423
|
componentSets,
|
|
424
|
+
setNameOf,
|
|
388
425
|
styles: entry.styles ?? {},
|
|
389
426
|
byId,
|
|
390
427
|
parent,
|
|
@@ -401,20 +438,27 @@ function analyse(entry, mains, library = false) {
|
|
|
401
438
|
};
|
|
402
439
|
}
|
|
403
440
|
|
|
404
|
-
const emailKitPart = (n, parent, componentLabel) =>
|
|
441
|
+
const emailKitPart = (n, parent, componentLabel, setNameOf) =>
|
|
405
442
|
(n.type === "INSTANCE" && EMAIL_KIT.test(componentLabel(n) ?? "")) ||
|
|
406
443
|
((n.type === "COMPONENT" || n.type === "COMPONENT_SET") &&
|
|
407
444
|
(EMAIL_KIT.test(n.name ?? "") ||
|
|
408
445
|
(n.type === "COMPONENT" &&
|
|
409
|
-
EMAIL_KIT.test(
|
|
446
|
+
EMAIL_KIT.test(setOfComponent(n, parent, setNameOf) ?? ""))));
|
|
447
|
+
/**
|
|
448
|
+
* The name of a variant's set: its parent in the walked tree, or, for a
|
|
449
|
+
* submitted variant that is its own root, the set Figma's components map
|
|
450
|
+
* names for it.
|
|
451
|
+
*/
|
|
452
|
+
const setOfComponent = (n, parent, setNameOf) =>
|
|
453
|
+
parent.get(n.id)?.name ?? setNameOf?.(n.id);
|
|
410
454
|
/**
|
|
411
455
|
* Why a node and everything in it is outside the app-UI gate, or null: an
|
|
412
456
|
* Email kit part, an email made of them (a frame named Email whose only
|
|
413
457
|
* placed parts, at any depth, are the kit's), or the template editor's
|
|
414
458
|
* block palette.
|
|
415
459
|
*/
|
|
416
|
-
function outOfScopeRoot(n, parent, componentLabel, memo) {
|
|
417
|
-
if (emailKitPart(n, parent, componentLabel))
|
|
460
|
+
function outOfScopeRoot(n, parent, componentLabel, memo, setNameOf) {
|
|
461
|
+
if (emailKitPart(n, parent, componentLabel, setNameOf))
|
|
418
462
|
return `Email kit part ${n.type === "INSTANCE" ? componentLabel(n) : n.name}`;
|
|
419
463
|
if (n.type !== "FRAME" && n.type !== "GROUP" && n.type !== "SECTION")
|
|
420
464
|
return null;
|
|
@@ -426,7 +470,7 @@ function outOfScopeRoot(n, parent, componentLabel, memo) {
|
|
|
426
470
|
if (hit) return hit;
|
|
427
471
|
let kind = /** @type {"kit" | "other" | "none"} */ ("none");
|
|
428
472
|
if (!visibleNode(x)) kind = "none";
|
|
429
|
-
else if (emailKitPart(x, parent, componentLabel)) kind = "kit";
|
|
473
|
+
else if (emailKitPart(x, parent, componentLabel, setNameOf)) kind = "kit";
|
|
430
474
|
else if (
|
|
431
475
|
x.type === "INSTANCE" ||
|
|
432
476
|
x.type === "TEXT" ||
|
|
@@ -505,6 +549,45 @@ function headerCell(a, inst) {
|
|
|
505
549
|
return /(^|,\s*)part=head(er)?(\s*,|$)/i.test(c?.name ?? "");
|
|
506
550
|
}
|
|
507
551
|
|
|
552
|
+
/**
|
|
553
|
+
* What a frame composed of a library component's parts holds, outside the
|
|
554
|
+
* instances it places: `held` part instances, and `rows` frames that place
|
|
555
|
+
* two or more of them side by side (a row, as the Surfaces checker reads
|
|
556
|
+
* one). Null when something in it is drawn by hand: a text or a shape that
|
|
557
|
+
* is no instance, an image paint, or a frame with a paint or an effect that
|
|
558
|
+
* holds no part. Other library instances (a pager, an empty state) and
|
|
559
|
+
* unpainted layout frames are not drawn. A hidden or fully transparent
|
|
560
|
+
* layer is not there, so a part that cannot be seen is not held.
|
|
561
|
+
*/
|
|
562
|
+
function partsHeld(a, frame, parts) {
|
|
563
|
+
if ((frame.fills ?? []).some((p) => visibleNode(p) && p.type === "IMAGE"))
|
|
564
|
+
return null;
|
|
565
|
+
let held = 0;
|
|
566
|
+
let rows = 0;
|
|
567
|
+
let placed = 0;
|
|
568
|
+
for (const child of frame.children ?? []) {
|
|
569
|
+
if (!visibleNode(child) || (child.opacity ?? 1) <= 0) continue;
|
|
570
|
+
if (child.type === "INSTANCE") {
|
|
571
|
+
const key = a.setOf(child)?.key ?? a.componentOf(child)?.key;
|
|
572
|
+
if (key && parts.has(key)) placed++;
|
|
573
|
+
continue;
|
|
574
|
+
}
|
|
575
|
+
if (child.type !== "FRAME" && child.type !== "GROUP") return null;
|
|
576
|
+
const inner = partsHeld(a, child, parts);
|
|
577
|
+
if (!inner) return null;
|
|
578
|
+
if (
|
|
579
|
+
inner.held === 0 &&
|
|
580
|
+
(visiblePaints(child.fills) ||
|
|
581
|
+
visiblePaints(child.strokes) ||
|
|
582
|
+
(child.effects ?? []).some(visibleNode))
|
|
583
|
+
)
|
|
584
|
+
return null;
|
|
585
|
+
held += inner.held;
|
|
586
|
+
rows += inner.rows;
|
|
587
|
+
}
|
|
588
|
+
return { held: held + placed, rows: rows + (placed >= 2 ? 1 : 0) };
|
|
589
|
+
}
|
|
590
|
+
|
|
508
591
|
function matchesRole(a, inst, role, library) {
|
|
509
592
|
const c = a.componentOf(inst);
|
|
510
593
|
const set = a.setOf(inst);
|
|
@@ -828,12 +911,9 @@ export function checkConformance({
|
|
|
828
911
|
// notFromLibrary: local parts and hand-drawn stand-ins, off the library.
|
|
829
912
|
if (!library && own) {
|
|
830
913
|
if (n.type === "COMPONENT" || n.type === "COMPONENT_SET") {
|
|
831
|
-
// A submitted variant is its own root, so its set is not in the
|
|
832
|
-
// walked tree; Figma's components map still names the set.
|
|
833
914
|
const setName =
|
|
834
915
|
n.type === "COMPONENT"
|
|
835
|
-
? (a.parent.
|
|
836
|
-
a.componentSets[a.components[n.id]?.componentSetId]?.name)
|
|
916
|
+
? setOfComponent(n, a.parent, a.setNameOf)
|
|
837
917
|
: null;
|
|
838
918
|
if (!SURFACE_NAME.test(n.name) && !SURFACE_NAME.test(setName ?? ""))
|
|
839
919
|
push(
|
|
@@ -858,17 +938,22 @@ export function checkConformance({
|
|
|
858
938
|
`instance of local component ${set?.name ?? c.name}`,
|
|
859
939
|
);
|
|
860
940
|
} else if (n.type === "FRAME" || n.type === "GROUP") {
|
|
861
|
-
// A frame named for a library
|
|
862
|
-
//
|
|
863
|
-
// the
|
|
941
|
+
// A frame named for a library component that holds none of it. It
|
|
942
|
+
// holds it when it places an instance of that set, or (hub-488)
|
|
943
|
+
// when it is composed of the set's parts: a "Table" frame whose
|
|
944
|
+
// rows are Table Header and Table cell instances, with nothing
|
|
945
|
+
// drawn by hand beside them, is the library's own pattern, not a
|
|
946
|
+
// stand-in.
|
|
864
947
|
const named =
|
|
865
948
|
roles.find((r) => r.componentName === n.name) ||
|
|
866
949
|
librarySetNames.has(n.name);
|
|
950
|
+
const parts = LIBRARY_PARTS.get(n.name);
|
|
867
951
|
const holdsIt =
|
|
868
952
|
named &&
|
|
869
|
-
[...indexTree(n).byId.values()].some(
|
|
953
|
+
([...indexTree(n).byId.values()].some(
|
|
870
954
|
(x) => x.type === "INSTANCE" && a.componentLabel(x) === n.name,
|
|
871
|
-
)
|
|
955
|
+
) ||
|
|
956
|
+
(parts && (partsHeld(a, n, parts)?.rows ?? 0) > 0));
|
|
872
957
|
const drawn = visiblePaints(n.fills) || visiblePaints(n.strokes);
|
|
873
958
|
if (named && !holdsIt && drawn)
|
|
874
959
|
push(
|
|
@@ -938,8 +1023,27 @@ export function checkConformance({
|
|
|
938
1023
|
}
|
|
939
1024
|
}
|
|
940
1025
|
|
|
941
|
-
//
|
|
942
|
-
//
|
|
1026
|
+
// An Aadhaar shown in full is flagged for every viewer, the viewer's
|
|
1027
|
+
// own included, and a permission reveal does not lift it (PII-26).
|
|
1028
|
+
if (screenText(a, n, overridden)) {
|
|
1029
|
+
const aadhaarField = [...fieldLabels(a, n), ...fieldWords(a, n)].some(
|
|
1030
|
+
(l) => AADHAAR_FIELD.test(l),
|
|
1031
|
+
);
|
|
1032
|
+
const full = [
|
|
1033
|
+
...text.matchAll(AADHAAR),
|
|
1034
|
+
...(aadhaarField ? text.matchAll(AADHAAR_RUN) : []),
|
|
1035
|
+
];
|
|
1036
|
+
for (const m of full)
|
|
1037
|
+
push(
|
|
1038
|
+
findings,
|
|
1039
|
+
n.id,
|
|
1040
|
+
"otherPersonRevealed",
|
|
1041
|
+
`unmasked Aadhaar ${m[0]}; Aadhaar shows only its last four digits, to its owner too (PII-26)`,
|
|
1042
|
+
);
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
// otherPersonRevealed (DEC-0045). Never the viewer's own record (R5,
|
|
1046
|
+
// P-10), never a colleague's display name on a staff surface (D1104).
|
|
943
1047
|
if (
|
|
944
1048
|
!screenText(a, n, overridden) ||
|
|
945
1049
|
isSelf(a, n) ||
|
|
@@ -957,6 +1061,8 @@ export function checkConformance({
|
|
|
957
1061
|
const digits = m[0].replace(/\D/g, "");
|
|
958
1062
|
if (DATE.test(m[0]) || MASKED.test(m[0]) || viewer.has(digits))
|
|
959
1063
|
continue;
|
|
1064
|
+
// An Aadhaar is reported once, by the Aadhaar rule above.
|
|
1065
|
+
if (new RegExp(`^${AADHAAR.source}$`).test(m[0].trim())) continue;
|
|
960
1066
|
const phoneShaped =
|
|
961
1067
|
m[0].startsWith("+") || LOCAL_PHONE.test(m[0].trim());
|
|
962
1068
|
if (phoneShaped && digits.length >= 10 && digits.length <= 15)
|
|
@@ -1269,15 +1375,75 @@ function selfRow(a, n) {
|
|
|
1269
1375
|
) ?? null
|
|
1270
1376
|
);
|
|
1271
1377
|
}
|
|
1378
|
+
/**
|
|
1379
|
+
* The field a text fills: the outermost library field part (Field, Input,
|
|
1380
|
+
* Select...) or field frame (field/Email) within four levels, so a value in
|
|
1381
|
+
* a Field's Input control reads the Field's label and hint (CS-2946's
|
|
1382
|
+
* Send to). Null when the text fills no field.
|
|
1383
|
+
*/
|
|
1384
|
+
function fieldOf(a, n) {
|
|
1385
|
+
return (
|
|
1386
|
+
a
|
|
1387
|
+
.ancestors(n)
|
|
1388
|
+
.slice(0, 4)
|
|
1389
|
+
.findLast((x) =>
|
|
1390
|
+
x.type === "INSTANCE"
|
|
1391
|
+
? FIELD_PART.test(a.componentLabel(x) ?? "")
|
|
1392
|
+
: FIELD_FRAME.test(x.name ?? ""),
|
|
1393
|
+
) ?? null
|
|
1394
|
+
);
|
|
1395
|
+
}
|
|
1396
|
+
/**
|
|
1397
|
+
* The words of the field a text fills, other than the text itself: the
|
|
1398
|
+
* field's label, hint and helper, as properties or as its own texts.
|
|
1399
|
+
*/
|
|
1400
|
+
function fieldWords(a, n) {
|
|
1401
|
+
const field = fieldOf(a, n);
|
|
1402
|
+
if (!field) return [];
|
|
1403
|
+
const words = [];
|
|
1404
|
+
for (const [prop, v] of Object.entries(field.componentProperties ?? {}))
|
|
1405
|
+
if (
|
|
1406
|
+
/^(label|hint|helper|description|caption)\b/i.test(prop) &&
|
|
1407
|
+
typeof v?.value === "string"
|
|
1408
|
+
)
|
|
1409
|
+
words.push(v.value);
|
|
1410
|
+
for (const x of indexTree(field).byId.values())
|
|
1411
|
+
if (x.type === "TEXT" && x.id !== n.id && x.visible !== false)
|
|
1412
|
+
words.push(textOf(x));
|
|
1413
|
+
return words;
|
|
1414
|
+
}
|
|
1415
|
+
/**
|
|
1416
|
+
* The viewer's own value in a field (hub-236, P-10): the field's
|
|
1417
|
+
* label or hint says so ("Your own address is filled in", "Your email").
|
|
1418
|
+
* Only the field's own words count, never the value itself.
|
|
1419
|
+
*/
|
|
1420
|
+
function selfField(a, n) {
|
|
1421
|
+
return fieldWords(a, n).some((w) => SELF_FIELD.test(w));
|
|
1422
|
+
}
|
|
1423
|
+
/** "(you)" on the value or on a text beside it (U05-7). */
|
|
1424
|
+
function markedYou(a, n) {
|
|
1425
|
+
if (YOU_MARKER.test(textOf(n))) return true;
|
|
1426
|
+
const siblings = a.parent.get(n.id)?.children ?? [];
|
|
1427
|
+
return siblings.some(
|
|
1428
|
+
(x) =>
|
|
1429
|
+
x.id !== n.id &&
|
|
1430
|
+
x.type === "TEXT" &&
|
|
1431
|
+
x.visible !== false &&
|
|
1432
|
+
/^\(you\)$/i.test(textOf(x)),
|
|
1433
|
+
);
|
|
1434
|
+
}
|
|
1435
|
+
/** The component set a node draws: an instance's, a variant's, or the set. */
|
|
1436
|
+
function drawnSet(a, x) {
|
|
1437
|
+
if (x.type === "INSTANCE") return a.setOf(x);
|
|
1438
|
+
if (x.type === "COMPONENT") return a.setOf({ componentId: x.id });
|
|
1439
|
+
if (x.type === "COMPONENT_SET") return a.componentSets[x.id] ?? null;
|
|
1440
|
+
return null;
|
|
1441
|
+
}
|
|
1272
1442
|
function isSelf(a, n) {
|
|
1273
1443
|
const up = a.ancestors(n);
|
|
1274
1444
|
if (up.some((x) => selfPersonName(a, x))) return true;
|
|
1275
|
-
if (
|
|
1276
|
-
|
|
1277
|
-
(x) =>
|
|
1278
|
-
x.type === "INSTANCE" && SELF_COMPONENT_SET_KEYS.has(a.setOf(x)?.key),
|
|
1279
|
-
)
|
|
1280
|
-
)
|
|
1445
|
+
if (selfField(a, n) || markedYou(a, n)) return true;
|
|
1446
|
+
if (up.some((x) => SELF_COMPONENT_SET_KEYS.has(drawnSet(a, x)?.key)))
|
|
1281
1447
|
return true;
|
|
1282
1448
|
|
|
1283
1449
|
// INTERIM: identify a Table row from its direct Table-cell children, or a
|