@nodii/dev 0.6.213 → 0.6.215

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
@@ -248,6 +248,20 @@ nodii-dev figma publish FILE --sets CS-1,CS-2 [--dry-run]
248
248
  - **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`.
249
249
  - **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.
250
250
 
251
+ ## GitHub reads: the research token
252
+
253
+ `nodii-dev github research-token` prints a 1-hour installation token for the read-only GitHub App `nodii-research-readonly` (Actions, Contents, Pull requests, Metadata and the organization's self-hosted runners, all read-only). The App's tokens have their own API allowance (7,650 calls an hour), separate from the shared account's 5,000 that every lane and the coordinator spend. On 25 Nov 2026 one research scan used that whole allowance and blocked every session for 30 minutes.
254
+
255
+ ```bash
256
+ GH_TOKEN=$(nodii-dev github research-token) gh api 'repos/cognion-nucleus/nodii-auth/actions/runs?per_page=100'
257
+ nodii-dev github research-token --json # {"token": "ghs_...", "expiresAt": "..."}
258
+ ```
259
+
260
+ - **Where the key lives.** AWS Secrets Manager, `nodii/dev/github-research-app` (nodii-infra `envs/dev/github_research_app.tf`), so any machine signed in to AWS can mint a token. Set `NODII_AWS_PROFILE` to pick an AWS profile.
261
+ - **What it can't do.** Write anything: GitHub refuses with "Resource not accessible by integration".
262
+ - **When to use it.** Bulk reads: run and job history, scans across many repos, reports. It's an optional utility; no rule requires it yet.
263
+ - **Errors.** `RESEARCH_SECRET_UNREADABLE` means this machine isn't signed in to AWS. `RESEARCH_SECRET_INCOMPLETE` means the secret is missing a field. `RESEARCH_TOKEN_REFUSED` means GitHub turned the App down, and the message carries its HTTP status.
264
+
251
265
  ## Receipts
252
266
 
253
267
  A gate that lets work move writes a signed receipt (STD-22, K04-27, S06-53 to S06-56). `lane check` and `lane review` write and attach a `review` receipt listing the `--gate` commands and the review checks, and stop if they cannot. A `test` receipt needs what those commands cannot see (scope, stack, auth posture), so it comes from `receipt write` or the stack tool's `test --receipt`. A receipt must name the lane it is attached to. Anything else uses:
@@ -273,6 +287,7 @@ nodii-dev logout
273
287
  nodii-dev whoami # OAuth identity plus the registered agent
274
288
  nodii-dev config show
275
289
  nodii-dev doctor [--figma-file KEY] [--json] # preflight: Dev, hooks, local Ollama + Gather model, optional Figma
290
+ nodii-dev github research-token [--json] # a 1-hour read-only GitHub token with its own rate limit (below)
276
291
 
277
292
  nodii-dev api list [--tag TAG] [--json]
278
293
  nodii-dev api OPERATION_ID [--param name=value ...] [--body @file|-|JSON]
package/dist/cli.js CHANGED
@@ -37,6 +37,7 @@ import { SUBMIT_CHECK_FLAGS, changedPaths, nudgeStop, recordGathered, recordGuid
37
37
  import { isLaneConfig, promptTurnText, sessionStartText, stewardCommand } from "./session-kind.js";
38
38
  import { rulingCommand } from "./rulings.js";
39
39
  import { doctorCommand } from "./doctor.js";
40
+ import { githubCommand } from "./github-token.js";
40
41
  import { installManagedLatest, managedStatus } from "./managed-version.js";
41
42
  import { dispatchManagedClaudeHook, dispatchManagedHook } from "./managed-hooks.js";
42
43
  import { governorCommand, laneClose } from "./governor.js";
@@ -166,6 +167,8 @@ Usage: nodii-dev <command> [options] [--json]
166
167
  login [--force] | logout | whoami | config show
167
168
  # login says so when the machine is already signed in; --force
168
169
  # replaces that one sign-in (never from a lane)
170
+ github research-token [--json] # a 1-hour read-only GitHub token from the research App (own rate limit);
171
+ # GH_TOKEN=$(nodii-dev github research-token) gh api ... for bulk reads
169
172
  doctor [--figma-file KEY] [--json] # preflight: sign-in, agent, permissions, machine, repo, lane slots,
170
173
  # local Ollama + pinned Gather model, the Figma token, the coordinator watch daemon (for a
171
174
  # coordinator), whether a clean environment finds the lane runtime, and optional Figma registration
@@ -1313,6 +1316,7 @@ export async function main(argv = process.argv.slice(2)) {
1313
1316
  if (result.exitCode) process.exitCode = result.exitCode;
1314
1317
  };
1315
1318
  if (command === "setup") return emitCommand(await setupCommand(f));
1319
+ if (command === "github") return emitCommand(await githubCommand(action, rest, f));
1316
1320
  if (command === "doctor") {
1317
1321
  if (action) throw new CliError("USAGE", `doctor takes no arguments, got: ${[action, ...rest].join(" ")}`, 2);
1318
1322
  if (f["figma-file"] === true) throw new CliError("USAGE", "--figma-file needs a file key or figma.com link", 2);
package/dist/core.js CHANGED
@@ -4,7 +4,7 @@ import { chmod, lstat, mkdir, readFile, rename, rm, writeFile } from "node:fs/pr
4
4
  import { homedir, platform } from "node:os";
5
5
  import { basename, dirname, join } from "node:path";
6
6
 
7
- export const VERSION = "0.6.213";
7
+ export const VERSION = "0.6.215";
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
@@ -9,7 +9,7 @@
9
9
  import { readFile } from "node:fs/promises";
10
10
  import { CliError, devRequest } from "./core.js";
11
11
  import { FIGMA_API, figmaRest } from "./figma-rest.js";
12
- import { conformanceLines, figmaConformance, figmaFileKey, laneReadsBody, submitMode, surfacesCheck, uploadSubmitImages, withCodePr } from "./figma.js";
12
+ import { conformanceLines, figmaConformance, figmaFileKey, laneReadsBody, submitEvidence, submitMode, surfacesCheck, uploadSubmitImages, withCodePr, withVersionHistoryReads } from "./figma.js";
13
13
  import { checkConformance, neededMains, VERSION as CHECK_VERSION } from "./vendor/ds-conformance.mjs";
14
14
 
15
15
  // The Figma nodes endpoint takes many ids per call; keep URLs well short of limits.
@@ -149,20 +149,6 @@ const PUBLISH_LABEL = "Components published";
149
149
  const VERSION_PAGES = 5;
150
150
  const KEY_LOOKUPS_AT_ONCE = 3;
151
151
 
152
- async function versionHistoryReads(figmaGet, path) {
153
- const reads = [];
154
- let at = `/${path}?page_size=100`;
155
- for (let page = 0; page < VERSION_PAGES && at; page++) {
156
- const body = await figmaGet(at);
157
- reads.push({ path: at.slice(1), body });
158
- const older = body?.pagination?.prev_page;
159
- if (typeof older !== "string" || !older.startsWith(`${FIGMA_API}/${path}`)) break;
160
- const next = new URL(older);
161
- at = next.origin === new URL(FIGMA_API).origin && next.pathname === `/v1/${path}` ? `${next.pathname.slice(3)}${next.search}` : null;
162
- }
163
- return reads;
164
- }
165
-
166
152
  /**
167
153
  * A library's newest "Components published" version (DEC-0047): what a
168
154
  * consuming file can have. Null when none is in its recent history; its
@@ -506,23 +492,18 @@ export async function designCheckChangeSet(target, flags, { request = devRequest
506
492
  // hub-558: images go up one by one and the body names them; --code-pr rides in the body.
507
493
  body = withCodePr(body, codePr, { ...(progress ? { progress } : {}) });
508
494
  body = await uploadSubmitImages(id, body, { request, ...(progress ? { progress } : {}) });
495
+ const set = (await request("GET", `/api/v1/design/change-sets/${encodeURIComponent(id)}`)).data;
496
+ body = { ...body, evidence: submitEvidence(body, set) };
509
497
  // Upload a large read corpus once. A versions negotiation below keeps its
510
498
  // readIds and adds only one small inline REST supplement.
511
499
  const storedReads = laneReads
512
500
  ? await laneReadsBody(id, laneReads, { request, ...(progress ? { progress } : {}), ...(laneReadsLimit ? { limit: laneReadsLimit } : {}) })
513
501
  : {};
514
- let versionReads = [];
515
- const withReads = () => {
516
- if (!versionReads.length) return { ...body, ...storedReads };
517
- if (storedReads.laneReads)
518
- return { ...body, laneReads: { ...storedReads.laneReads, rest: [...(storedReads.laneReads.rest ?? []).filter((entry) => !versionReads.some((read) => read.path === entry.path)), ...versionReads] } };
519
- return { ...body, ...storedReads, laneReads: { figmaVersion: laneReads.figmaVersion, nodes: [], rest: versionReads } };
520
- };
521
502
  let p;
522
503
  try {
523
504
  const run = (sent) => figmaConformance(id, sent, { request, sync, ...(send ? { send } : {}), ...(progress ? { progress } : {}) });
524
- const runAll = async () => {
525
- const sent = withReads();
505
+ const runAll = async (reads) => {
506
+ const sent = { ...body, ...reads };
526
507
  // A submit body past the dry run's node limit runs in parts, each under it;
527
508
  // a re-submit's can't be split, since it must name every rejected item.
528
509
  const groups = split && Array.isArray(sent.items) ? dryRunGroups(sent.items) : [];
@@ -531,15 +512,7 @@ export async function designCheckChangeSet(target, flags, { request = devRequest
531
512
  for (const items of groups) reports.push((await run({ ...sent, items })).data ?? {});
532
513
  return { data: mergedReports(reports) };
533
514
  };
534
- try {
535
- p = await runAll();
536
- } catch (error) {
537
- const path = String(error?.details?.path ?? "").replace(/^\/+/, "");
538
- if (!laneReads || error?.code !== "FIGMA_READS_NEEDED" || !/^files\/[^/]+\/versions$/.test(path)) throw error;
539
- const get = figmaGet ?? figmaClient(figmaToken(env));
540
- versionReads = await versionHistoryReads(get, path);
541
- p = await runAll();
542
- }
515
+ p = await withVersionHistoryReads({ laneReads, storedReads, run: runAll, figmaGet: () => figmaGet ?? figmaClient(figmaToken(env)) });
543
516
  } catch (error) {
544
517
  // A cold run reads every root and main from Figma and can outlast the
545
518
  // edge's gateway (504, an HTML page). Dev keeps the mains it read for 5
package/dist/figma.js CHANGED
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
2
2
  import { readFile } from "node:fs/promises";
3
3
  import { setTimeout as delay } from "node:timers/promises";
4
4
  import { CliError, devAsyncRequest, devRequest, encode } from "./core.js";
5
+ import { FIGMA_API } from "./figma-rest.js";
5
6
  import { assertWithinLaneScope, currentLaneFigmaScope } from "./figma-scope.js";
6
7
  import { answerPlanReads, countedReads, figmaToken } from "./publish-compare.js";
7
8
  import { pacedFigma } from "./surface.js";
@@ -473,6 +474,46 @@ export function withCodePr(body, flag, { progress = stderrLine } = {}) {
473
474
  return { ...body, codePr };
474
475
  }
475
476
 
477
+ const VERSION_HISTORY_PAGES = 5;
478
+
479
+ /** The bounded, same-file version-history reads Dev asks a lane to supply. */
480
+ async function versionHistoryReads(figmaGet, path) {
481
+ const reads = [];
482
+ let at = `/${path}?page_size=100`;
483
+ for (let page = 0; page < VERSION_HISTORY_PAGES && at; page++) {
484
+ const body = await figmaGet(at);
485
+ reads.push({ path: at.slice(1), body });
486
+ const older = body?.pagination?.prev_page;
487
+ if (typeof older !== "string" || !older.startsWith(`${FIGMA_API}/${path}`)) break;
488
+ const next = new URL(older);
489
+ at = next.origin === new URL(FIGMA_API).origin && next.pathname === `/v1/${path}` ? `${next.pathname.slice(3)}${next.search}` : null;
490
+ }
491
+ return reads;
492
+ }
493
+
494
+ /**
495
+ * Run one submit-family call with the lane's reads. If Dev asks for this file's
496
+ * version history, fetch it in the lane and retry exactly once. Dry runs and
497
+ * real re-submits share this loop so they promise the same read negotiation.
498
+ */
499
+ export async function withVersionHistoryReads({ laneReads, storedReads, run, figmaGet }) {
500
+ let versionReads = [];
501
+ const reads = () => {
502
+ if (!versionReads.length) return storedReads;
503
+ if (storedReads.laneReads)
504
+ return { laneReads: { ...storedReads.laneReads, rest: [...(storedReads.laneReads.rest ?? []).filter((entry) => !versionReads.some((read) => read.path === entry.path)), ...versionReads] } };
505
+ return { ...storedReads, laneReads: { figmaVersion: laneReads.figmaVersion, nodes: [], rest: versionReads } };
506
+ };
507
+ try {
508
+ return await run(reads());
509
+ } catch (error) {
510
+ const path = String(error?.details?.path ?? "").replace(/^\/+/, "");
511
+ if (!laneReads || error?.code !== "FIGMA_READS_NEEDED" || !/^files\/[^/]+\/versions$/.test(path)) throw error;
512
+ versionReads = await versionHistoryReads(figmaGet(), path);
513
+ return run(reads());
514
+ }
515
+ }
516
+
476
517
  /** A submit or re-submit, async unless `sync`; a gateway timeout is checked against the set, not resent. */
477
518
  async function submitCall(id, kind, body, { sync = false, request = devRequest, progress = stderrLine, ...job } = {}) {
478
519
  const path = `/api/v1/design/change-sets/${encode(id)}/${kind}`;
@@ -487,7 +528,7 @@ async function submitCall(id, kind, body, { sync = false, request = devRequest,
487
528
  }
488
529
  }
489
530
 
490
- export async function figmaResubmit(id, file, { request = devRequest, read = (f) => readFile(f, "utf8"), laneReads, codePr, ...options } = {}) {
531
+ export async function figmaResubmit(id, file, { request = devRequest, read = (f) => readFile(f, "utf8"), laneReads, codePr, env = process.env, figmaGet, laneReadsLimit, ...options } = {}) {
491
532
  if (!id || !file) throw new CliError("USAGE", "figma resubmit CHANGE_SET PAYLOAD.json", 2);
492
533
  let text;
493
534
  try {
@@ -501,8 +542,13 @@ export async function figmaResubmit(id, file, { request = devRequest, read = (f)
501
542
  const body = await uploadSubmitImages(id, flagged, { request, ...(options.progress ? { progress: options.progress } : {}) });
502
543
  // On the lane's reads Dev runs the gate as a submit job too (hub-448), so
503
544
  // they go async like any re-submit; --sync still sends the plain call.
504
- const reads = await laneReadsBody(id, laneReads, { request, ...(options.progress ? { progress: options.progress } : {}) });
505
- return await submitCall(id, "resubmit", { ...body, ...reads }, { request, ...options });
545
+ const reads = await laneReadsBody(id, laneReads, { request, ...(options.progress ? { progress: options.progress } : {}), ...(laneReadsLimit ? { limit: laneReadsLimit } : {}) });
546
+ return await withVersionHistoryReads({
547
+ laneReads,
548
+ storedReads: reads,
549
+ run: (supplemented) => submitCall(id, "resubmit", { ...body, ...supplemented }, { request, ...options }),
550
+ figmaGet: () => figmaGet ?? pacedFigma(figmaToken(env), { log: options.progress }),
551
+ });
506
552
  } catch (error) {
507
553
  if (error?.code === "FIGMA_READS_NEEDED") throw laneReadsRefusal(error);
508
554
  const say = RESUBMIT_REFUSALS[error?.code];
@@ -0,0 +1,71 @@
1
+ // `nodii-dev github research-token`: a short-lived GitHub token for bulk reads.
2
+ //
3
+ // Research, reports and history scans used to run on the shared account, whose
4
+ // 5,000/h API limit every lane and the coordinator share. On 25 Nov 2026 one
5
+ // scan drove it to 0 for 30 minutes and blocked all of them. The operator then
6
+ // created a read-only GitHub App (nodii-research-readonly: Actions, Contents,
7
+ // Pull requests, Metadata, org Self-hosted runners, all read) whose
8
+ // installation tokens have their own limit, and ruled: "make the key a github
9
+ // variable you can do without me. or make it an AWS variable." The key lives in
10
+ // AWS Secrets Manager (nodii-infra envs/dev/github_research_app.tf).
11
+ //
12
+ // GH_TOKEN=$(nodii-dev github research-token) gh api 'repos/...'
13
+ import { createSign } from "node:crypto";
14
+ import { execFile } from "node:child_process";
15
+ import { promisify } from "node:util";
16
+ import { CliError } from "./core.js";
17
+
18
+ export const RESEARCH_SECRET_ID = "nodii/dev/github-research-app";
19
+ export const RESEARCH_SECRET_REGION = "ap-south-1";
20
+
21
+ const b64url = (buf) => Buffer.from(buf).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
22
+
23
+ /** The App's credentials from Secrets Manager, via the AWS CLI (NODII_AWS_PROFILE picks a profile). */
24
+ export async function readResearchSecret({ run = promisify(execFile), env = process.env } = {}) {
25
+ const args = ["secretsmanager", "get-secret-value", "--secret-id", RESEARCH_SECRET_ID, "--region", RESEARCH_SECRET_REGION, "--query", "SecretString", "--output", "text"];
26
+ if (env.NODII_AWS_PROFILE) args.push("--profile", env.NODII_AWS_PROFILE);
27
+ let stdout;
28
+ try {
29
+ ({ stdout } = await run("aws", args));
30
+ } catch (error) {
31
+ throw new CliError("RESEARCH_SECRET_UNREADABLE", `Could not read ${RESEARCH_SECRET_ID} from AWS Secrets Manager: ${String(error.stderr || error.message).trim()}. Sign in to AWS on this machine (or set NODII_AWS_PROFILE) and try again.`, 1);
32
+ }
33
+ return JSON.parse(stdout);
34
+ }
35
+
36
+ /** A GitHub App JWT (RS256), valid 9 minutes, backdated 60 s for clock skew. */
37
+ export function appJwt(appId, privateKeyPem, nowSeconds = Math.floor(Date.now() / 1000)) {
38
+ const header = b64url(JSON.stringify({ alg: "RS256", typ: "JWT" }));
39
+ const payload = b64url(JSON.stringify({ iat: nowSeconds - 60, exp: nowSeconds + 540, iss: String(appId) }));
40
+ const signer = createSign("RSA-SHA256");
41
+ signer.update(`${header}.${payload}`);
42
+ return `${header}.${payload}.${b64url(signer.sign(privateKeyPem))}`;
43
+ }
44
+
45
+ /** Mint a 1-hour installation token. Returns { token, expiresAt }. */
46
+ export async function researchToken({ readSecret = readResearchSecret, fetchImpl = fetch, now } = {}) {
47
+ const secret = await readSecret();
48
+ for (const field of ["app_id", "installation_id", "key_base64"]) {
49
+ if (!secret?.[field]) throw new CliError("RESEARCH_SECRET_INCOMPLETE", `${RESEARCH_SECRET_ID} has no ${field}; write the App credentials into it (see nodii-infra envs/dev/github_research_app.tf).`, 1);
50
+ }
51
+ const pem = Buffer.from(secret.key_base64, "base64").toString("utf8");
52
+ const jwt = appJwt(secret.app_id, pem, now);
53
+ const response = await fetchImpl(`https://api.github.com/app/installations/${secret.installation_id}/access_tokens`, {
54
+ method: "POST",
55
+ headers: { Authorization: `Bearer ${jwt}`, Accept: "application/vnd.github+json", "X-GitHub-Api-Version": "2022-11-28" },
56
+ });
57
+ const body = await response.json().catch(() => ({}));
58
+ if (!response.ok || !body.token) {
59
+ throw new CliError("RESEARCH_TOKEN_REFUSED", `GitHub refused the research App token (HTTP ${response.status}): ${body.message ?? "no message"}`, 1);
60
+ }
61
+ return { token: body.token, expiresAt: body.expires_at };
62
+ }
63
+
64
+ /** CLI entry: human output is the bare token, so `GH_TOKEN=$(nodii-dev github research-token)` works. */
65
+ export async function githubCommand(action, rest, _flags, deps = {}) {
66
+ if (action !== "research-token" || rest.length) {
67
+ throw new CliError("USAGE", "usage: nodii-dev github research-token [--json]", 2);
68
+ }
69
+ const { token, expiresAt } = await researchToken(deps);
70
+ return { payload: { token, expiresAt }, human: token };
71
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.213",
3
+ "version": "0.6.215",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {