@nodii/dev 0.6.173 → 0.6.175
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 +242 -8
- package/dist/cli.js +178 -14
- package/dist/coordinator-items.js +235 -0
- package/dist/core.js +13 -2
- package/dist/flags.js +10 -1
- package/dist/harness.js +2 -0
- package/dist/lane-asks.js +115 -0
- package/dist/lane-supervisor.js +83 -5
- package/dist/lanes.js +43 -3
- package/dist/leeway.js +218 -0
- package/dist/managed-hooks.js +37 -4
- package/dist/nudges.js +1 -1
- package/dist/repo-policy.js +13 -1
- package/dist/safety.js +11 -1
- package/dist/session-kind.js +18 -5
- package/dist/setup.js +5 -4
- package/dist/starting.js +111 -20
- package/dist/surface.js +17 -0
- package/dist/tooling-docs.js +127 -0
- package/package.json +1 -1
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// `nodii-dev repo docs-check` and `nodii-dev hook tooling-docs`: docs move with
|
|
2
|
+
// tooling (hub-525; MW1-46.3, DEC-0486; operator, 17 Nov 2026).
|
|
3
|
+
//
|
|
4
|
+
// A repository names, in the `toolingDocs` block of nodii.repo.yaml, the files
|
|
5
|
+
// that hold its commands, routes, refusal codes and hooks (`tooling`) and the
|
|
6
|
+
// files that describe them (`docs`). A range that changes a tooling file and no
|
|
7
|
+
// docs file is stale, unless a commit in the range carries a
|
|
8
|
+
// `Docs-unaffected: <reason>` trailer. The hook refuses `git push` and
|
|
9
|
+
// `gh pr create|ready` on a stale range. A repository without the block is not
|
|
10
|
+
// checked. The check reads git only; it never calls Dev.
|
|
11
|
+
import { execFile } from "node:child_process";
|
|
12
|
+
import { promisify } from "node:util";
|
|
13
|
+
import { CliError } from "./core.js";
|
|
14
|
+
import { POLICY_FILE, readPolicy } from "./repo-policy.js";
|
|
15
|
+
import { withoutHeredocBodies } from "./safety.js";
|
|
16
|
+
|
|
17
|
+
const execFileAsync = promisify(execFile);
|
|
18
|
+
export const TOOLING_DOCS_BASE = "origin/main";
|
|
19
|
+
export const DOCS_UNAFFECTED = "Docs-unaffected";
|
|
20
|
+
|
|
21
|
+
/** Does the glob match the whole path? `*` and `?` stay in one folder; `**` crosses folders. */
|
|
22
|
+
export function globMatches(glob, path) {
|
|
23
|
+
let source = "";
|
|
24
|
+
for (let i = 0; i < glob.length; i++) {
|
|
25
|
+
const c = glob[i];
|
|
26
|
+
if (c === "*" && glob[i + 1] === "*") {
|
|
27
|
+
// `**/` also matches no folder at all, so docs/**/*.md takes docs/a.md.
|
|
28
|
+
if (glob[i + 2] === "/") { source += "(?:.*/)?"; i += 2; } else { source += ".*"; i += 1; }
|
|
29
|
+
} else if (c === "*") source += "[^/]*";
|
|
30
|
+
else if (c === "?") source += "[^/]";
|
|
31
|
+
else source += c.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
32
|
+
}
|
|
33
|
+
return new RegExp(`^${source}$`).test(path);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function git(root, args) {
|
|
37
|
+
const { stdout } = await execFileAsync("git", ["-C", root, ...args], { maxBuffer: 64 * 1024 * 1024 });
|
|
38
|
+
return stdout;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Check the range `<base>...HEAD` of one repository. Returns
|
|
43
|
+
* `{ checked: false, stale: false, reason }` when there is nothing to check
|
|
44
|
+
* against, else `{ checked: true, stale, base, tooling, docs, unaffected }`.
|
|
45
|
+
*/
|
|
46
|
+
export async function toolingDocsCheck(root, { base = TOOLING_DOCS_BASE } = {}) {
|
|
47
|
+
const skip = (reason) => ({ checked: false, stale: false, reason });
|
|
48
|
+
let policy;
|
|
49
|
+
try { policy = await readPolicy(root); } catch (error) {
|
|
50
|
+
if (error.code !== "POLICY_MISSING" && error.code !== "POLICY_INVALID") throw error;
|
|
51
|
+
return skip(error.message);
|
|
52
|
+
}
|
|
53
|
+
if (!policy.toolingDocs) return skip(`${POLICY_FILE} has no toolingDocs block`);
|
|
54
|
+
try { await git(root, ["rev-parse", "--verify", "--quiet", `${base}^{commit}`]); } catch { return skip(`${base} is not a commit here; fetch it or pass --base`); }
|
|
55
|
+
const changed = (await git(root, ["diff", "--name-only", `${base}...HEAD`])).split("\n").filter(Boolean);
|
|
56
|
+
const matching = (globs) => changed.filter((path) => globs.some((glob) => globMatches(glob, path))).sort();
|
|
57
|
+
const tooling = matching(policy.toolingDocs.tooling);
|
|
58
|
+
const docs = matching(policy.toolingDocs.docs);
|
|
59
|
+
const messages = await git(root, ["log", "--format=%B", `${base}..HEAD`]);
|
|
60
|
+
const unaffected = new RegExp(`^${DOCS_UNAFFECTED}:[ \\t]*(\\S.*)$`, "m").exec(messages)?.[1].trim() ?? null;
|
|
61
|
+
return { checked: true, stale: tooling.length > 0 && docs.length === 0 && !unaffected, base, tooling, docs, unaffected, docsGlobs: policy.toolingDocs.docs };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const listed = (paths, max = 8) => `${paths.slice(0, max).join(", ")}${paths.length > max ? ` and ${paths.length - max} more` : ""}`;
|
|
65
|
+
|
|
66
|
+
/** The refusal's text: what changed, where its docs are, and the two ways to clear it. */
|
|
67
|
+
export function toolingDocsStaleText(result) {
|
|
68
|
+
return `TOOLING_DOCS_STALE: this change touches tooling (${listed(result.tooling)}) and no file that describes it, in ${result.base}...HEAD (MW1-46.3). `
|
|
69
|
+
+ `Update the docs it makes stale in the same change (${listed(result.docsGlobs)}), `
|
|
70
|
+
+ `or declare them unaffected in a commit message with the trailer \`${DOCS_UNAFFECTED}: <reason>\`. Check again: nodii-dev repo docs-check.`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// `git [-C DIR | -c k=v | --flag]... push` and `gh pr create|ready`, at the start of a command in a chain.
|
|
74
|
+
const SEGMENT = /(?:^|&&|\|\||[;|\n(])\s*(?:[A-Za-z_][A-Za-z0-9_]*=\S*\s+)*(git((?:\s+(?:-C\s+(?:"[^"]*"|'[^']*'|\S+)|-c\s+\S+|--?[A-Za-z][\w-]*(?:=\S+)?))*)\s+push\b|gh\s+pr\s+(?:create|ready)\b)/g;
|
|
75
|
+
|
|
76
|
+
/** The directories a command pushes or opens a pull request from: `cwd`, or a `git -C` target. */
|
|
77
|
+
export function toolingDocsTargets(command, cwd) {
|
|
78
|
+
const out = [];
|
|
79
|
+
for (const match of withoutHeredocBodies(String(command ?? "")).matchAll(SEGMENT)) {
|
|
80
|
+
const dir = /(?:^|\s)-C\s+("[^"]*"|'[^']*'|\S+)/.exec(match[2] ?? "")?.[1];
|
|
81
|
+
out.push(dir ? dir.replace(/^(["'])(.*)\1$/, "$2") : cwd);
|
|
82
|
+
}
|
|
83
|
+
return [...new Set(out)];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* PreToolUse on Bash. Returns `{ deny }` for a `git push` or `gh pr
|
|
88
|
+
* create|ready` over a stale range, else null. Fails open: outside a
|
|
89
|
+
* repository, or on any git error, the call passes.
|
|
90
|
+
*/
|
|
91
|
+
export async function toolingDocsHook(payload) {
|
|
92
|
+
if (payload?.tool_name !== "Bash") return null;
|
|
93
|
+
const cwd = payload.cwd ?? process.cwd();
|
|
94
|
+
for (const dir of toolingDocsTargets(payload.tool_input?.command, cwd)) {
|
|
95
|
+
try {
|
|
96
|
+
const root = (await git(dir, ["rev-parse", "--show-toplevel"])).trim();
|
|
97
|
+
const result = await toolingDocsCheck(root);
|
|
98
|
+
if (result.stale) return { deny: toolingDocsStaleText(result) };
|
|
99
|
+
} catch {}
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export const toolingDocsSettingsSnippet = () => ({
|
|
105
|
+
hooks: { PreToolUse: [{ matcher: "^Bash$", hooks: [{ type: "command", command: "nodii-dev hook tooling-docs" }] }] },
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const human = (result) => {
|
|
109
|
+
if (!result.checked) return `Not checked: ${result.reason}.`;
|
|
110
|
+
if (result.stale) return toolingDocsStaleText(result);
|
|
111
|
+
if (!result.tooling.length) return `${result.base}...HEAD changes no tooling file.`;
|
|
112
|
+
return result.docs.length
|
|
113
|
+
? `${result.base}...HEAD changes tooling (${listed(result.tooling)}) and its docs (${listed(result.docs)}).`
|
|
114
|
+
: `${result.base}...HEAD changes tooling (${listed(result.tooling)}); docs declared unaffected: ${result.unaffected}`;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/** `repo docs-check [--base REF]`: 0 clean or not checked, 1 TOOLING_DOCS_STALE. */
|
|
118
|
+
export async function repoDocsCheckCommand(rest, flags = {}) {
|
|
119
|
+
if (rest.length) throw new CliError("USAGE", `repo docs-check [--base REF] takes no arguments, got: ${rest.join(" ")}`, 2);
|
|
120
|
+
if (flags.base === true) throw new CliError("USAGE", "repo docs-check --base REF", 2);
|
|
121
|
+
let root;
|
|
122
|
+
try { root = flags.root && flags.root !== true ? String(flags.root) : (await git(process.cwd(), ["rev-parse", "--show-toplevel"])).trim(); } catch { throw new CliError("USAGE", "Run this inside a git repository.", 2); }
|
|
123
|
+
const result = await toolingDocsCheck(root, flags.base ? { base: String(flags.base) } : {});
|
|
124
|
+
const { docsGlobs: _globs, ...rest_ } = result;
|
|
125
|
+
const payload = { root, passed: !result.stale, ...(result.stale ? { code: "TOOLING_DOCS_STALE" } : {}), ...rest_ };
|
|
126
|
+
return { payload, human: () => human(result), exitCode: result.stale ? 1 : 0 };
|
|
127
|
+
}
|