@nodii/dev 0.6.102 → 0.6.104
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 +22 -7
- package/dist/core.js +1 -1
- package/dist/harness.js +18 -7
- package/dist/review-session.js +55 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -26,7 +26,7 @@ import { setupCommand } from "./setup.js";
|
|
|
26
26
|
import { harnessCommand } from "./harness.js";
|
|
27
27
|
import { repoCommand } from "./repo-policy.js";
|
|
28
28
|
import { hookRuntime, recordHookFire, safetyContext, safetyPostHook, safetyPreHook } from "./safety.js";
|
|
29
|
-
import { isReviewSession } from "./review-session.js";
|
|
29
|
+
import { isLaneRunSession, isReviewSession } from "./review-session.js";
|
|
30
30
|
import { SUBMIT_CHECK_FLAGS, changedPaths, nudgeCandidate, nudgePre, nudgeStop, recordGathered, recordGuidelineRead, recordSubmitChecks, steerAct, stewardSteerNudges, surfaceGenPre } from "./nudges.js";
|
|
31
31
|
import { activeSteward, firstPromptText, isLaneConfig, sessionStartText, stewardCommand } from "./session-kind.js";
|
|
32
32
|
import { doctorCommand } from "./doctor.js";
|
|
@@ -477,10 +477,24 @@ Run a command with --help or see the package README for all flags.`;
|
|
|
477
477
|
// `doctor` is not one of them: `nodii-dev doctor` is this CLI's own preflight.
|
|
478
478
|
const STACK_VERBS = new Set(["up", "down", "sync", "seed", "wipe", "reset", "rebuild", "restart", "smoke", "urls", "peek", "trace", "stats", "bootstrap", "provenance", "stale", "status", "logs", "world", "totp", "token", "bench"]);
|
|
479
479
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
return
|
|
480
|
+
// hub-284: a reviewer by its marker or its process, or any session in this run
|
|
481
|
+
// other than the lane's own, whatever its script did or didn't set.
|
|
482
|
+
async function inSpawnedSession() {
|
|
483
|
+
if (await isReviewSession()) return true;
|
|
484
|
+
if (!process.env.NODII_DEV_RUN_ID || process.stdin.isTTY) return false;
|
|
485
|
+
let payload = null;
|
|
486
|
+
try { payload = JSON.parse(await stdinText()); } catch {}
|
|
487
|
+
return !(await isLaneRunSession(payload));
|
|
488
|
+
}
|
|
489
|
+
// Stdin can be read once, and a hook's guard reads it before the hook does.
|
|
490
|
+
let stdinRead = null;
|
|
491
|
+
function stdinText() {
|
|
492
|
+
stdinRead ??= (async () => {
|
|
493
|
+
let value = "";
|
|
494
|
+
for await (const chunk of stdin) value += chunk;
|
|
495
|
+
return value;
|
|
496
|
+
})();
|
|
497
|
+
return stdinRead;
|
|
484
498
|
}
|
|
485
499
|
const bodyFlag = async (f, name = "body") =>
|
|
486
500
|
f[`${name}-file`] ? readFile(f[`${name}-file`], "utf8") : f[name];
|
|
@@ -709,6 +723,9 @@ export async function figmaFileAdd(value, flags, { request = devRequest } = {})
|
|
|
709
723
|
const readsHelp = (argv) => argv[0] === "help" || argv.some((token) => ["--help", "-h"].includes(token)) || (argv.length === 1 && ["--version", "-v"].includes(argv[0]));
|
|
710
724
|
|
|
711
725
|
export async function main(argv = process.argv.slice(2)) {
|
|
726
|
+
// Ahead of every check that reaches Dev: a session the lane spawned gets
|
|
727
|
+
// nothing from these hooks. The safety hooks still run.
|
|
728
|
+
if (argv[0] === "hook" && LANE_RUN_HOOKS.has(argv[1]) && (await inSpawnedSession())) return;
|
|
712
729
|
// A lane's own exit reporter runs after its runtime ends (NODII-DEV-CLI-1).
|
|
713
730
|
if (argv[0] === "__lane-supervisor") return superviseLane();
|
|
714
731
|
// Amendment acknowledgement is a lane-wide backstop for every other command.
|
|
@@ -1393,8 +1410,6 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
1393
1410
|
);
|
|
1394
1411
|
}
|
|
1395
1412
|
if (command === "hook") {
|
|
1396
|
-
// hub-284: silent in a spawned reviewer. The safety hooks still run.
|
|
1397
|
-
if (LANE_RUN_HOOKS.has(action) && (await isReviewSession())) return;
|
|
1398
1413
|
if (action === "print-settings")
|
|
1399
1414
|
return console.log(JSON.stringify(settingsSnippet(), null, 2));
|
|
1400
1415
|
if (action === "managed-dispatch") {
|
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.104";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
package/dist/harness.js
CHANGED
|
@@ -358,6 +358,8 @@ export function sourceChanges(before = [], after = []) {
|
|
|
358
358
|
const execFileAsync = promisify(execFile);
|
|
359
359
|
|
|
360
360
|
/** The repository root and Dev's `repo` key: the git remote's name, else the folder's. */
|
|
361
|
+
const MACHINE_ONLY_REPO = "machine";
|
|
362
|
+
|
|
361
363
|
export async function repoContext(cwd = process.cwd()) {
|
|
362
364
|
let root;
|
|
363
365
|
try { root = (await execFileAsync("git", ["rev-parse", "--show-toplevel"], { cwd, encoding: "utf8" })).stdout.trim(); }
|
|
@@ -468,10 +470,18 @@ export async function harnessCommand(action, flags, { request = devRequest, cont
|
|
|
468
470
|
if (!["install", "update", "check"].includes(action)) throw new CliError("USAGE", "harness install|update|check [--repo NAME] [--service ID] [--include-drafts[=false]] [--adopt PATH,...] [--dry-run] [--check] [--system]", 2);
|
|
469
471
|
if (flags.fleet || flags.all) throw new CliError("USAGE", "The harness is installed one service at a time, in that service's repository. There is no fleet mode.", 2);
|
|
470
472
|
if (flags.root === true || flags.repo === true) throw new CliError("USAGE", "--root and --repo need a value.", 2);
|
|
471
|
-
|
|
472
|
-
|
|
473
|
+
// `update --system` is about this machine, so a coordinator can run it
|
|
474
|
+
// anywhere: with no checkout or no harness here it refreshes the managed
|
|
475
|
+
// hooks and writes no repository files. Dev's hooks don't depend on the repo.
|
|
476
|
+
const machineWide = action === "update" && Boolean(flags.system) && !flags.check;
|
|
477
|
+
const ctx = flags.root ? { root: flags.root, repo: flags.repo } : await context().catch((error) => {
|
|
478
|
+
if (machineWide && error?.code === "GIT_REQUIRED") return null;
|
|
479
|
+
throw error;
|
|
480
|
+
});
|
|
481
|
+
const repo = flags.repo && flags.repo !== true ? String(flags.repo) : (ctx?.repo ?? (machineWide ? MACHINE_ONLY_REPO : undefined));
|
|
473
482
|
if (!repo) throw new CliError("USAGE", "Pass --repo NAME.", 2);
|
|
474
|
-
const state = await readState(ctx.root);
|
|
483
|
+
const state = ctx ? await readState(ctx.root) : null;
|
|
484
|
+
const machineOnly = machineWide && !state;
|
|
475
485
|
// Update and check ask Dev for what install asked for, unless told otherwise.
|
|
476
486
|
const saved = action === "install" ? {} : (state?.request ?? {});
|
|
477
487
|
const serviceId = flags.service && flags.service !== true ? String(flags.service) : (saved.serviceId ?? undefined);
|
|
@@ -502,7 +512,7 @@ export async function harnessCommand(action, flags, { request = devRequest, cont
|
|
|
502
512
|
if (action === "check" || (action === "update" && flags.check)) return checkCommand(ctx.root, repo, state, fetchHarness);
|
|
503
513
|
|
|
504
514
|
const harness = (await fetchHarness({ draftFallback: true })).data;
|
|
505
|
-
const plan = await planHarness(ctx.root, harness, { install: action === "install", adopt: flagList(flags.adopt), request: { ...(serviceId ? { serviceId } : {}), includeDrafts: effectiveIncludeDrafts } });
|
|
515
|
+
const plan = machineOnly ? { changes: [], conflicts: [] } : await planHarness(ctx.root, harness, { install: action === "install", adopt: flagList(flags.adopt), request: { ...(serviceId ? { serviceId } : {}), includeDrafts: effectiveIncludeDrafts } });
|
|
506
516
|
const summary = {
|
|
507
517
|
repo: harness.repo, serviceId: harness.serviceId ?? null,
|
|
508
518
|
from: state?.methodologyVersion ?? null, to: harness.methodologyVersion,
|
|
@@ -510,6 +520,7 @@ export async function harnessCommand(action, flags, { request = devRequest, cont
|
|
|
510
520
|
changes: plan.changes.map(({ path, action: a, mode }) => ({ path, action: a, mode })),
|
|
511
521
|
conflicts: plan.conflicts, warnings: harness.warnings ?? [],
|
|
512
522
|
};
|
|
523
|
+
if (machineOnly) summary.machineOnly = true;
|
|
513
524
|
const lines = [
|
|
514
525
|
`${harness.repo}${harness.serviceId ? ` (${harness.serviceId})` : ""}: methodology ${summary.from ? `${summary.from} → ` : ""}${summary.to}`,
|
|
515
526
|
...summary.sources.map((x) => ` source ${x}`),
|
|
@@ -528,7 +539,7 @@ export async function harnessCommand(action, flags, { request = devRequest, cont
|
|
|
528
539
|
const systemCli = managedCli?.cliPath ?? managedCliPath;
|
|
529
540
|
const systemCliVersion = managedCli?.version;
|
|
530
541
|
const codexChange = plan.changes.find((change) => change.path === ".codex/hooks.json");
|
|
531
|
-
const codexText = codexChange?.text ?? await optional(join(ctx.root, ".codex/hooks.json"));
|
|
542
|
+
const codexText = codexChange?.text ?? (machineOnly ? harness.files.find((file) => file.path === ".codex/hooks.json")?.content : await optional(join(ctx.root, ".codex/hooks.json")));
|
|
532
543
|
const managedBundle = flags.system ? managedHookBundle(codexText, { home: managedHome, cliPath: systemCli, cliVersion: systemCliVersion }) : null;
|
|
533
544
|
// Claude's managed layer carries only Dev's generated hooks, never the user
|
|
534
545
|
// entries a merged settings file on disk may also hold.
|
|
@@ -553,7 +564,7 @@ export async function harnessCommand(action, flags, { request = devRequest, cont
|
|
|
553
564
|
const systemText = systemCommands.length
|
|
554
565
|
? `\nManaged Codex hooks are staged in ${managedBundle.dir}. One operator install covers codex-personal and codex-work; review ${join(managedBundle.dir, "requirements.toml")}, then run:\n${systemCommands.join("\n")}${claudeText}\nNo privileged command was run. Later --system updates refresh the user-owned managed directories without sudo.`
|
|
555
566
|
: "";
|
|
556
|
-
await applyHarness(ctx.root, plan);
|
|
567
|
+
if (!machineOnly) await applyHarness(ctx.root, plan);
|
|
557
568
|
if (managedBundle) await writeManaged(managedBundle);
|
|
558
569
|
if (claudeBundle) await writeManagedClaude(claudeBundle);
|
|
559
570
|
// Without --system, a machine that already has managed hooks still gets the
|
|
@@ -565,5 +576,5 @@ export async function harnessCommand(action, flags, { request = devRequest, cont
|
|
|
565
576
|
: managedCli.current ? `\nThe managed nodii-dev is at the latest release, ${managedCli.version}.`
|
|
566
577
|
: `\nInstalled the managed nodii-dev ${managedCli.version}${managedCli.previous ? ` over ${managedCli.previous}` : ""} at ${managedCli.cliPath}.`;
|
|
567
578
|
const claudeData = claudePlan ? { claudeManagedDir: claudeBundle.dir, claudeManaged: { state: claudePlan.state, target: claudePlan.target, systemCommands: claudePlan.commands } } : {};
|
|
568
|
-
return { payload: { data: { ...summary, applied: true, ...(systemCommands.length ? { systemCommands: [...systemCommands, ...(claudePlan?.commands ?? [])], managedDir: managedBundle.dir } : {}), ...claudeData, ...(refreshed.length ? { managedDispatchRefreshed: refreshed } : {}), ...(managedCli ? { managedCli } : {}) } }, human: `${lines.join("\n")}\n${plan.changes.length ? `${action === "install" ? "Installed" : "Updated"}: ${plan.changes.length} change${plan.changes.length === 1 ? "" : "s"}.` : "Harness already current."}${systemText}${refreshText}${managedCliText}` };
|
|
579
|
+
return { payload: { data: { ...summary, applied: true, ...(systemCommands.length ? { systemCommands: [...systemCommands, ...(claudePlan?.commands ?? [])], managedDir: managedBundle.dir } : {}), ...claudeData, ...(refreshed.length ? { managedDispatchRefreshed: refreshed } : {}), ...(managedCli ? { managedCli } : {}) } }, human: `${lines.join("\n")}\n${machineOnly ? "No harness in this directory: refreshed this machine's managed hooks only, and wrote no repository files." : plan.changes.length ? `${action === "install" ? "Installed" : "Updated"}: ${plan.changes.length} change${plan.changes.length === 1 ? "" : "s"}.` : "Harness already current."}${systemText}${refreshText}${managedCliText}` };
|
|
569
580
|
}
|
package/dist/review-session.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
// hub-284: lane hooks act only in the lane's own run. A reviewer the
|
|
2
2
|
// push hook or `lane check` spawns inherits the lane's environment, so a Stop
|
|
3
3
|
// nudge would reach it, and it would answer in prose instead of its JSON verdict.
|
|
4
|
+
//
|
|
5
|
+
// No repository's review script could be relied on to mark its reviewer, so the
|
|
6
|
+
// test is the session: the first one to fire a hook in a run owns that run, and
|
|
7
|
+
// the lane's own session always starts before anything it spawns.
|
|
4
8
|
import { execFile } from "node:child_process";
|
|
9
|
+
import { mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
10
|
+
import { dirname, join } from "node:path";
|
|
5
11
|
import { promisify } from "node:util";
|
|
12
|
+
import { configPath } from "./core.js";
|
|
6
13
|
|
|
7
14
|
const execFileAsync = promisify(execFile);
|
|
8
15
|
|
|
@@ -37,3 +44,51 @@ export async function isReviewSession({ env = process.env, pid = process.ppid, r
|
|
|
37
44
|
} catch {}
|
|
38
45
|
return false;
|
|
39
46
|
}
|
|
47
|
+
|
|
48
|
+
const SESSIONS_DIR = "lane-run-sessions";
|
|
49
|
+
const SESSIONS_TTL_MS = 7 * 24 * 60 * 60 * 1000;
|
|
50
|
+
// A resumed run comes back on purpose, under a session that may be new. A
|
|
51
|
+
// reviewer is never resumed or cleared, but it can compact, so compact takes nothing.
|
|
52
|
+
const TAKES_OVER = new Set(["resume", "clear"]);
|
|
53
|
+
|
|
54
|
+
const safeName = (run) => String(run).replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
55
|
+
|
|
56
|
+
async function pruneOld(dir, now) {
|
|
57
|
+
for (const name of await readdir(dir).catch(() => [])) {
|
|
58
|
+
const path = join(dir, name);
|
|
59
|
+
const info = await stat(path).catch(() => null);
|
|
60
|
+
if (info && now - info.mtimeMs > SESSIONS_TTL_MS) await rm(path, { force: true }).catch(() => {});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Is this hook's session the lane's own? Outside a lane run, or with no session
|
|
66
|
+
* in the payload, there is nothing to tell apart. A state file it can't use
|
|
67
|
+
* counts as the lane's own, as a process table it can't read does.
|
|
68
|
+
*/
|
|
69
|
+
export async function isLaneRunSession(payload, { env = process.env, dir = join(dirname(configPath()), SESSIONS_DIR), now = Date.now() } = {}) {
|
|
70
|
+
const run = env.NODII_DEV_RUN_ID;
|
|
71
|
+
const session = payload?.session_id;
|
|
72
|
+
if (!run || !session) return true;
|
|
73
|
+
const path = join(dir, `${safeName(run)}.json`);
|
|
74
|
+
try {
|
|
75
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
76
|
+
const text = `${JSON.stringify({ session })}\n`;
|
|
77
|
+
if (payload.hook_event_name === "SessionStart" && TAKES_OVER.has(payload.source)) {
|
|
78
|
+
const temporary = `${path}.${process.pid}`;
|
|
79
|
+
await writeFile(temporary, text, { mode: 0o600 });
|
|
80
|
+
await rename(temporary, path);
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
await writeFile(path, text, { flag: "wx", mode: 0o600 });
|
|
85
|
+
await pruneOld(dir, now);
|
|
86
|
+
return true;
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if (error?.code !== "EEXIST") throw error;
|
|
89
|
+
}
|
|
90
|
+
return JSON.parse(await readFile(path, "utf8")).session === session;
|
|
91
|
+
} catch {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
}
|