@nodii/dev 0.6.103 → 0.6.105
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/doctor.js +3 -1
- 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.105";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
package/dist/doctor.js
CHANGED
|
@@ -404,7 +404,9 @@ export async function doctorCommand(deps = {}) {
|
|
|
404
404
|
|
|
405
405
|
// No managed hooks means no managed copy: the hook checks above report that.
|
|
406
406
|
try {
|
|
407
|
-
|
|
407
|
+
// Someone asked now, so not the hour-old answer SessionStart can use: it would
|
|
408
|
+
// call a copy the latest release just after a new one ships.
|
|
409
|
+
const copy = await (deps.managedStatus ?? managedStatus)({ fresh: true });
|
|
408
410
|
if (copy) {
|
|
409
411
|
const extra = { cliPath: copy.cliPath, version: copy.version, latest: copy.latest };
|
|
410
412
|
if (!copy.latest) checks.push(cannot("managed_cli", `${copy.cliPath} is ${copy.version}; the latest release could not be read from npm`, extra));
|
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
|
+
}
|