@nodii/dev 0.6.99 → 0.6.101

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/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.99";
7
+ export const VERSION = "0.6.101";
8
8
  export const configPath = () =>
9
9
  process.env.NODII_DEV_CONFIG_PATH ??
10
10
  join(homedir(), ".config/nodii-dev/config.json");
package/dist/safety.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { execFile } from "node:child_process";
2
+ import { realpathSync } from "node:fs";
2
3
  import { appendFile, mkdir, readFile, realpath, writeFile } from "node:fs/promises";
3
4
  import { homedir, tmpdir } from "node:os";
4
5
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
@@ -185,8 +186,59 @@ function commandRef(after, verb) {
185
186
  return null;
186
187
  }
187
188
 
189
+ /**
190
+ * The one form the record can allow, and nothing else: `-c NAME [START]` or `-b NAME [START]`.
191
+ * An allowlist on purpose. Git takes the last of a repeated option and accepts abbreviated long
192
+ * ones, so any other argument could change the branch or discard work.
193
+ */
194
+ function createdBranchName(args) {
195
+ if (args.length < 2 || args.length > 3 || !["-c", "-b"].includes(args[0])) return null;
196
+ const operands = args.slice(1);
197
+ // Only plain ref characters: the shell would expand anything else, such as `{-f,x}`, into new arguments.
198
+ if (operands.some((item) => !/^[A-Za-z0-9][A-Za-z0-9._/-]*$/.test(item))) return null;
199
+ return operands[0];
200
+ }
201
+
202
+ /**
203
+ * True only when every branch-creating switch or checkout in the command creates the
204
+ * branch Dev's boundary record names, in the worktree that record names. `boundaries`
205
+ * is read from Dev for this call (safetyPreHook); there is no local way to supply it,
206
+ * and with no record nothing is allowed.
207
+ */
208
+ function createsRecordedBranch(raw, context, gitCommands) {
209
+ const boundaries = context.devBoundaries;
210
+ if (!Array.isArray(boundaries)) return false;
211
+ const creating = gitPlaces(raw, context.cwd).filter((x) => ["switch", "checkout"].includes(x.verb) && createsBranch(x.args));
212
+ // The block below reads commands with another parser: if the two disagree, allow nothing.
213
+ const blocking = gitCommands.filter((x) => ["switch", "checkout"].includes(x.verb) && createsBranch(x.args));
214
+ if (creating.length !== blocking.length) return false;
215
+ const real = (path) => { try { return realpathSync(path); } catch { return resolve(path); } };
216
+ return creating.length > 0 && creating.every((x) => {
217
+ // Exactly one absolute -C and no other git option: git fails if it can't go there, where a failed cd would leave
218
+ // the command in another repository, and --work-tree or -c could change what it acts on.
219
+ const name = createdBranchName(x.args);
220
+ const named = x.globals.length === 2 && x.globals[0] === "-C" && isAbsolute(x.globals[1]);
221
+ return Boolean(name && x.target && named) && boundaries.some((b) => b.branch === name && typeof b.worktree === "string" && real(b.worktree) === real(x.target));
222
+ });
223
+ }
224
+
225
+ const createsAnyBranch = (raw) => gitPlaces(raw, null).some((x) => ["switch", "checkout"].includes(x.verb) && createsBranch(x.args));
226
+
227
+ /** The lane's current repository boundaries, read from Dev. null when Dev can't say: the caller refuses. */
228
+ async function devBoundaries(key, request) {
229
+ if (!key) return null;
230
+ try {
231
+ const repos = (await request("GET", `/api/v1/lanes/${encode(key)}/freeze`)).data?.freeze?.boundaries?.repos;
232
+ if (!Array.isArray(repos)) return null;
233
+ return await Promise.all(repos.map(async (x) => ({ branch: x?.branch, worktree: typeof x?.worktree === "string" ? await realpath(x.worktree).catch(() => x.worktree) : null })));
234
+ } catch {
235
+ return null;
236
+ }
237
+ }
238
+
239
+ // Every way git spells it: `-c X`, glued `-cX`, bundled `-fB X`, `--create=X` and abbreviations such as `--cr X`.
188
240
  function createsBranch(after) {
189
- return after.some((item) => ["-b", "-B", "-c", "-C", "--orphan", "--create", "--force-create"].includes(item));
241
+ return after.some((item) => /^-[a-zA-Z]*[bBcC]/.test(item) || /^--(?:cr|or|force-)/.test(item));
190
242
  }
191
243
 
192
244
  // A hook bypass by another name is still --no-verify: lefthook's and husky's
@@ -304,6 +356,11 @@ const insideRoot = (root, path) => { const rel = relative(root, path); return re
304
356
  */
305
357
  const GIT_PLACE_ENV = /^GIT_(?:DIR|WORK_TREE|COMMON_DIR)=/;
306
358
  export function pushTargets(raw, cwd) {
359
+ return gitPlaces(raw, cwd).filter((x) => x.verb === "push").map((x) => x.target);
360
+ }
361
+
362
+ /** Each git command in `raw`, with its verb, arguments and directory (null when unknowable). */
363
+ function gitPlaces(raw, cwd) {
307
364
  const out = [];
308
365
  let dir = cwd;
309
366
  // A path from `from`, as the shell and git place it; null when unknowable.
@@ -342,6 +399,7 @@ export function pushTargets(raw, cwd) {
342
399
  let cursor = at + 1;
343
400
  let target = envChdir ? null : dir;
344
401
  let gitDir = false;
402
+ const start = cursor;
345
403
  while (cursor < texts.length && texts[cursor].startsWith("-")) {
346
404
  const option = texts[cursor];
347
405
  // Each -C is relative to the one before it, as git reads them.
@@ -351,7 +409,7 @@ export function pushTargets(raw, cwd) {
351
409
  cursor += ["-C", "-c", "--git-dir", "--work-tree", "--namespace", "--exec-path"].includes(option) ? 2 : 1;
352
410
  }
353
411
  // A repository named apart from the directory (--git-dir, GIT_DIR) cannot be placed, whatever -C says.
354
- if (texts[cursor] === "push") out.push(gitDir || gitEnvMoved || movesGit ? null : target);
412
+ if (texts[cursor]) out.push({ verb: texts[cursor], args: texts.slice(cursor + 1), target: gitDir || gitEnvMoved || movesGit ? null : target, globals: texts.slice(start, cursor) });
355
413
  }
356
414
  for (let n = 0; n < closing && outer.length; n += 1) dir = outer.pop();
357
415
  }
@@ -523,11 +581,11 @@ export function commandViolations(raw, context) {
523
581
  if (gitCommands.some((x) => x.verb === "stash"))
524
582
  block("SAFETY_GIT_STASH", "git stash is shared by every worktree; lanes and subagents use a work-in-progress commit.");
525
583
 
526
- for (const verb of ["checkout", "switch"]) {
527
- const invocation = gitCommands.find((x) => x.verb === verb);
528
- if (!invocation) continue;
584
+ const recordedCreate = createsRecordedBranch(raw, context, gitCommands);
585
+ for (const invocation of gitCommands.filter((x) => x.verb === "checkout" || x.verb === "switch")) {
586
+ const { verb } = invocation;
529
587
  if (createsBranch(invocation.args)) {
530
- block("SAFETY_GIT_BRANCH", `git ${verb} would create and leave the lane branch ${context.branch}.`);
588
+ if (!recordedCreate) block("SAFETY_GIT_BRANCH", `git ${verb} would create and leave the lane branch ${context.branch}.${context.devBoundaries === null ? " Dev couldn't be read, so no branch can be checked against this lane's record." : ""}`);
531
589
  continue;
532
590
  }
533
591
  const ref = commandRef(invocation.args, verb);
@@ -769,7 +827,7 @@ function blocked(violation) {
769
827
  }
770
828
 
771
829
  /** Runtime-neutral PreToolUse entrypoint. Silent return means allowed. */
772
- export async function safetyPreHook(payload, contextOrResolver = safetyContext) {
830
+ export async function safetyPreHook(payload, contextOrResolver = safetyContext, { request = devRequest } = {}) {
773
831
  const tool = payload.tool_name ?? "";
774
832
  if (!SHELL_TOOLS.has(tool) && !EDIT_TOOLS.has(tool)) return { allowed: true, ignored: true };
775
833
  if (SHELL_TOOLS.has(tool)) {
@@ -782,6 +840,8 @@ export async function safetyPreHook(payload, contextOrResolver = safetyContext)
782
840
  if (SHELL_TOOLS.has(tool)) {
783
841
  const command = String(payload.tool_input?.command ?? "");
784
842
  await expandLaneScope(command, context);
843
+ // Read here, for this call, so it can only come from Dev. A failed read leaves null, which refuses.
844
+ context.devBoundaries = provenLane(context) && createsAnyBranch(command) ? await devBoundaries(context.lane?.key, request) : null;
785
845
  const violation = commandViolations(command, context)[0];
786
846
  if (violation && provenLane(context)) blocked(violation);
787
847
  if (usesNoVerify(command) && context.role === "coordinator" && context.noVerifyReason)
package/dist/surface.js CHANGED
@@ -460,7 +460,7 @@ const JS_LITERALS = new Set(["true", "false", "null", "undefined", "this"]);
460
460
 
461
461
  function dataProps(views) {
462
462
  const data = new Map();
463
- const entry = (name) => data.get(name) ?? data.set(name, { attrs: new Set(), child: false, members: new Map() }).get(name);
463
+ const entry = (name) => data.get(name) ?? data.set(name, { attrs: new Set(), child: false, nested: false, members: new Map() }).get(name);
464
464
  for (const view of views) {
465
465
  view.uses = new Set();
466
466
  const body = view.body;
@@ -479,6 +479,14 @@ function dataProps(views) {
479
479
  entry(m[2]).child = true;
480
480
  view.uses.add(m[2]);
481
481
  }
482
+ // A value inside an object prop (`chip={{ label: chipLabel }}`, `points: series1Points`).
483
+ // Strings go first, so a colon in text or a class name is never read as one.
484
+ const noStrings = body.replace(/"(?:[^"\\\n]|\\.)*"|`[^`]*`/g, '""');
485
+ for (const m of noStrings.matchAll(/\b[A-Za-z_]\w*:\s*([a-z][A-Za-z0-9]*)(?=\s*[,}\]])/g)) {
486
+ if (JS_LITERALS.has(m[1])) continue;
487
+ entry(m[1]).nested = true;
488
+ view.uses.add(m[1]);
489
+ }
482
490
  }
483
491
  return data;
484
492
  }
@@ -497,7 +505,8 @@ function openingTag(body, at) {
497
505
  }
498
506
 
499
507
  const propType = (d) => {
500
- const parts = [...d.attrs, ...(d.child ? ["ReactNode"] : [])];
508
+ // A value nested in an object prop has no ComponentProps path the generator can name.
509
+ const parts = [...d.attrs, ...(d.child ? ["ReactNode"] : []), ...(d.nested ? ["any"] : [])];
501
510
  if (d.members.size) parts.push(`{ ${[...d.members.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([k, refs]) => `${k}: ${[...refs].join(" & ")}`).join("; ")} }`);
502
511
  return parts.join(" & ");
503
512
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.99",
3
+ "version": "0.6.101",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {