@codyswann/lisa 4.87.11 → 4.87.13
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/all/copy-overwrite/scripts/review-evidence-event.mjs +202 -0
- package/dist/cli/doctor-git-hooks.d.ts +8 -0
- package/dist/cli/doctor-git-hooks.d.ts.map +1 -0
- package/dist/cli/doctor-git-hooks.js +49 -0
- package/dist/cli/doctor-git-hooks.js.map +1 -0
- package/dist/cli/doctor-project-type.d.ts +10 -0
- package/dist/cli/doctor-project-type.d.ts.map +1 -1
- package/dist/cli/doctor-project-type.js +16 -4
- package/dist/cli/doctor-project-type.js.map +1 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +2 -2
- package/dist/cli/doctor.js.map +1 -1
- package/dist/codex/hooks-installer.d.ts.map +1 -1
- package/dist/codex/hooks-installer.js +52 -4
- package/dist/codex/hooks-installer.js.map +1 -1
- package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
- package/dist/core/lisa-owned-hash-ledger.js +8 -0
- package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
- package/dist/core/lisa.d.ts +7 -0
- package/dist/core/lisa.d.ts.map +1 -1
- package/dist/core/lisa.js +22 -0
- package/dist/core/lisa.js.map +1 -1
- package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
- package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
- package/dist/core/upstream-evidence-manifest.js +55 -8
- package/dist/core/upstream-evidence-manifest.js.map +1 -1
- package/dist/health/hook-inspection.d.ts.map +1 -1
- package/dist/health/hook-inspection.js +6 -32
- package/dist/health/hook-inspection.js.map +1 -1
- package/dist/opencode/hooks-installer.d.ts.map +1 -1
- package/dist/opencode/hooks-installer.js +2 -0
- package/dist/opencode/hooks-installer.js.map +1 -1
- package/dist/opencode/plugin-templates/lisa-session-bootstrap.ts +14 -0
- package/dist/opencode/plugin-templates/rails-hooks-command.mjs +83 -0
- package/dist/opencode/plugin-templates/rails-hooks-inspection.mjs +138 -0
- package/dist/opencode/plugin-templates/rails-hooks.mjs +113 -0
- package/dist/opencode/support-file-resolver.d.ts.map +1 -1
- package/dist/opencode/support-file-resolver.js +3 -0
- package/dist/opencode/support-file-resolver.js.map +1 -1
- package/package.json +4 -4
- package/plugins/lisa/.claude-plugin/plugin.json +6 -1
- package/plugins/lisa/.codex-plugin/hooks.json +5 -0
- package/plugins/lisa/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa/hooks/install-rails-hooks.mjs +10 -0
- package/plugins/lisa/hooks/install-rails-hooks.sh +10 -0
- package/plugins/lisa/hooks/rails-hooks-command.mjs +83 -0
- package/plugins/lisa/hooks/rails-hooks-inspection.mjs +138 -0
- package/plugins/lisa/hooks/rails-hooks.mjs +113 -0
- package/plugins/lisa-agy/plugin.json +1 -1
- package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-agy/plugin.json +1 -1
- package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/.claude-plugin/plugin.json +6 -1
- package/plugins/lisa-copilot/hooks/install-rails-hooks.mjs +10 -0
- package/plugins/lisa-copilot/hooks/install-rails-hooks.sh +10 -0
- package/plugins/lisa-copilot/hooks/rails-hooks-command.mjs +83 -0
- package/plugins/lisa-copilot/hooks/rails-hooks-inspection.mjs +138 -0
- package/plugins/lisa-copilot/hooks/rails-hooks.mjs +113 -0
- package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cursor/hooks/hooks.json +4 -0
- package/plugins/lisa-cursor/hooks/install-rails-hooks.mjs +10 -0
- package/plugins/lisa-cursor/hooks/install-rails-hooks.sh +10 -0
- package/plugins/lisa-cursor/hooks/rails-hooks-command.mjs +83 -0
- package/plugins/lisa-cursor/hooks/rails-hooks-inspection.mjs +138 -0
- package/plugins/lisa-cursor/hooks/rails-hooks.mjs +113 -0
- package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/hooks/install-rails-hooks.mjs +10 -0
- package/plugins/lisa-devin/hooks/install-rails-hooks.sh +10 -0
- package/plugins/lisa-devin/hooks/rails-hooks-command.mjs +83 -0
- package/plugins/lisa-devin/hooks/rails-hooks-inspection.mjs +138 -0
- package/plugins/lisa-devin/hooks/rails-hooks.mjs +113 -0
- package/plugins/lisa-devin/hooks.json +5 -0
- package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-agy/plugin.json +1 -1
- package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-agy/plugin.json +1 -1
- package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-agy/plugin.json +1 -1
- package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-agy/plugin.json +1 -1
- package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-agy/plugin.json +1 -1
- package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-agy/plugin.json +1 -1
- package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-agy/plugin.json +1 -1
- package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/materialized-artifacts.json +3 -0
- package/plugins/src/base/.claude-plugin/plugin.json +5 -0
- package/plugins/src/base/hooks/install-rails-hooks.mjs +10 -0
- package/plugins/src/base/hooks/install-rails-hooks.sh +10 -0
- package/scripts/build-plugins.sh +12 -0
- package/scripts/copy-opencode-plugin-templates.mjs +5 -1
- package/scripts/lib/per-agent-hook-filter.mjs +8 -0
- package/scripts/lib/rails-hooks-command.mjs +80 -0
- package/scripts/lib/rails-hooks-inspection.mjs +135 -0
- package/scripts/lib/rails-hooks.d.mts +31 -0
- package/scripts/lib/rails-hooks.mjs +110 -0
- package/scripts/two-channel-couplings.json +2 -2
- package/typescript/copy-overwrite/.prettierignore +1 -0
- package/typescript/copy-overwrite/scripts/check-skipped-required-checks.mjs +52 -5
- package/typescript/create-only/.github/required-checks.json +1 -0
- package/typescript/create-only/.github/workflows/review-evidence.yml +43 -1
|
@@ -31,6 +31,9 @@
|
|
|
31
31
|
"plugins/lisa/hooks/guard-dedupe.bash",
|
|
32
32
|
"plugins/lisa/hooks/parity-safety-net-heredoc.py",
|
|
33
33
|
"plugins/lisa/hooks/parity-safety-net.sh",
|
|
34
|
+
"plugins/lisa/hooks/rails-hooks-command.mjs",
|
|
35
|
+
"plugins/lisa/hooks/rails-hooks-inspection.mjs",
|
|
36
|
+
"plugins/lisa/hooks/rails-hooks.mjs",
|
|
34
37
|
"plugins/lisa/hooks/worktree-binding-guard.mjs",
|
|
35
38
|
"plugins/lisa/hooks/worktree-binding-guard.sh",
|
|
36
39
|
"rails/copy-overwrite/scripts/check-threshold-ratchet.mjs",
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Nonblocking startup adapter; the engine also serves apply/doctor/health. */
|
|
2
|
+
try {
|
|
3
|
+
const { ensureRailsHooks } = await import("./rails-hooks.mjs");
|
|
4
|
+
const result = await ensureRailsHooks(process.cwd());
|
|
5
|
+
if (result.status === "failed") process.stderr.write(`${result.detail}\n`);
|
|
6
|
+
} catch {
|
|
7
|
+
process.stderr.write(
|
|
8
|
+
"Rails Git hooks could not be installed; run bundle exec lefthook install.\n"
|
|
9
|
+
);
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Install Rails Git wrappers in non-interactive agent sessions.
|
|
3
|
+
cat >/dev/null
|
|
4
|
+
HOOK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
5
|
+
if ! command -v node >/dev/null 2>&1; then
|
|
6
|
+
printf '%s\n' 'Rails Git hooks: Node.js is unavailable; run bundle exec lefthook install.' >&2
|
|
7
|
+
exit 0
|
|
8
|
+
fi
|
|
9
|
+
node "$HOOK_DIR/install-rails-hooks.mjs"
|
|
10
|
+
exit 0
|
package/scripts/build-plugins.sh
CHANGED
|
@@ -131,6 +131,18 @@ if [ -f "$ROOT_DIR/scripts/generate-scratch-supervisor-profile.mjs" ]; then
|
|
|
131
131
|
fi
|
|
132
132
|
build_plugin base lisa
|
|
133
133
|
|
|
134
|
+
# Startup and the CLI share one Node-builtins-only Rails hook engine. Stage
|
|
135
|
+
# the complete fresh closure before per-agent fan-out; source/type imports use
|
|
136
|
+
# scripts/lib directly and do not depend on a previous plugin build.
|
|
137
|
+
if [ -f "$ROOT_DIR/scripts/lib/rails-hooks.mjs" ] && \
|
|
138
|
+
[ -f "$ROOT_DIR/scripts/materialize-copy-overwrite.mjs" ]; then
|
|
139
|
+
mkdir -p "$PLUGINS_DIR/lisa/hooks"
|
|
140
|
+
for rails_hook_asset in rails-hooks.mjs rails-hooks-inspection.mjs rails-hooks-command.mjs; do
|
|
141
|
+
materialize "$ROOT_DIR/scripts/lib/$rails_hook_asset" \
|
|
142
|
+
"$PLUGINS_DIR/lisa/hooks/$rails_hook_asset"
|
|
143
|
+
done
|
|
144
|
+
fi
|
|
145
|
+
|
|
134
146
|
# Threshold-ratchet comparator: the canonical implementation lives in the base
|
|
135
147
|
# plugin's hooks/ (agent-time layer). The pre-commit (husky/lefthook) and CI
|
|
136
148
|
# layers in downstream projects run the same file as scripts/
|
|
@@ -13,6 +13,7 @@ import fs from "node:fs";
|
|
|
13
13
|
import path from "node:path";
|
|
14
14
|
|
|
15
15
|
import { materialize } from "./materialize-copy-overwrite.mjs";
|
|
16
|
+
import { RAILS_HOOK_ENGINE_FILES } from "./lib/rails-hooks.mjs";
|
|
16
17
|
|
|
17
18
|
const repoRoot = path.resolve(import.meta.dirname, "..");
|
|
18
19
|
const sourceDir = path.join(repoRoot, "src", "opencode", "plugin-templates");
|
|
@@ -28,6 +29,7 @@ const canonicalSupportFiles = [
|
|
|
28
29
|
"parity-safety-net.sh",
|
|
29
30
|
"parity-safety-net-heredoc.py",
|
|
30
31
|
"guard-dedupe.bash",
|
|
32
|
+
...RAILS_HOOK_ENGINE_FILES,
|
|
31
33
|
];
|
|
32
34
|
|
|
33
35
|
fs.rmSync(destDir, { recursive: true, force: true });
|
|
@@ -46,7 +48,9 @@ for (const filename of canonicalSupportFiles) {
|
|
|
46
48
|
// build:dist precedes build:plugins. Stamp fresh authoring sources rather
|
|
47
49
|
// than copying possibly stale generated hooks, preserving channel parity.
|
|
48
50
|
materialize(
|
|
49
|
-
|
|
51
|
+
RAILS_HOOK_ENGINE_FILES.includes(filename)
|
|
52
|
+
? path.join(repoRoot, "scripts/lib", filename)
|
|
53
|
+
: path.join(canonicalHookDir, filename),
|
|
50
54
|
path.join(destDir, filename)
|
|
51
55
|
);
|
|
52
56
|
}
|
|
@@ -215,6 +215,14 @@ const SCRIPT_RULES = {
|
|
|
215
215
|
copilot: true,
|
|
216
216
|
devin: true,
|
|
217
217
|
},
|
|
218
|
+
"install-rails-hooks.sh": {
|
|
219
|
+
claude: true,
|
|
220
|
+
codex: true,
|
|
221
|
+
cursor: true,
|
|
222
|
+
agy: false, // No SessionStart event; apply installs and doctor reports the remaining gap.
|
|
223
|
+
copilot: true,
|
|
224
|
+
devin: true,
|
|
225
|
+
},
|
|
218
226
|
"setup-jira-cli.sh": {
|
|
219
227
|
claude: true,
|
|
220
228
|
codex: true,
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** Bounded local Git/Bundler children used by Rails hook installation. */
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
|
|
4
|
+
const REPOSITORY_ENVIRONMENT = new Set([
|
|
5
|
+
"GIT_DIR",
|
|
6
|
+
"GIT_COMMON_DIR",
|
|
7
|
+
"GIT_WORK_TREE",
|
|
8
|
+
"GIT_INDEX_FILE",
|
|
9
|
+
"GIT_PREFIX",
|
|
10
|
+
]);
|
|
11
|
+
const MAX_OUTPUT_BYTES = 16 * 1024;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Execute one fixed local tool, killing its owned process group at the deadline.
|
|
15
|
+
* @param {string} command Tool selected by the caller, never a shell expression.
|
|
16
|
+
* @param {string[]} args Literal arguments.
|
|
17
|
+
* @param {{cwd: string, timeoutMs: number, signal?: AbortSignal, env?: NodeJS.ProcessEnv, capture?: boolean}} options Execution scope.
|
|
18
|
+
* @returns {Promise<{code: number|null, reason: string|null, stdout: string}>} Actual child outcome.
|
|
19
|
+
*/
|
|
20
|
+
export function runHookCommand(command, args, options) {
|
|
21
|
+
if (options.signal?.aborted)
|
|
22
|
+
return Promise.resolve({ code: null, reason: "ABORT_ERR", stdout: "" });
|
|
23
|
+
return new Promise(resolve => {
|
|
24
|
+
const env = Object.fromEntries(
|
|
25
|
+
Object.entries(options.env ?? process.env).filter(
|
|
26
|
+
([name]) => !REPOSITORY_ENVIRONMENT.has(name)
|
|
27
|
+
)
|
|
28
|
+
);
|
|
29
|
+
const budget = Math.max(1, Math.floor(options.timeoutMs));
|
|
30
|
+
const grouped = process.platform !== "win32";
|
|
31
|
+
const child = spawn(command, args, {
|
|
32
|
+
cwd: options.cwd,
|
|
33
|
+
env,
|
|
34
|
+
detached: grouped,
|
|
35
|
+
stdio: ["ignore", options.capture ? "pipe" : "ignore", "ignore"],
|
|
36
|
+
// The owned timer kills the whole POSIX group first. Node's immediate-
|
|
37
|
+
// child timeout is a second bounded backstop, not the cleanup mechanism.
|
|
38
|
+
timeout: budget + 1_000,
|
|
39
|
+
killSignal: "SIGKILL",
|
|
40
|
+
windowsHide: true,
|
|
41
|
+
});
|
|
42
|
+
let finished = false;
|
|
43
|
+
let reason = null;
|
|
44
|
+
let bytes = 0;
|
|
45
|
+
const chunks = [];
|
|
46
|
+
const stop = failure => {
|
|
47
|
+
if (finished) return;
|
|
48
|
+
reason ??= failure;
|
|
49
|
+
try {
|
|
50
|
+
if (grouped && child.pid) process.kill(-child.pid, "SIGKILL");
|
|
51
|
+
else child.kill("SIGKILL");
|
|
52
|
+
} catch {
|
|
53
|
+
// A group that has already exited needs no further signal.
|
|
54
|
+
child.kill("SIGKILL");
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const timer = setTimeout(() => stop("ETIMEDOUT"), budget);
|
|
58
|
+
const abort = () => stop("ABORT_ERR");
|
|
59
|
+
const complete = (code, failure) => {
|
|
60
|
+
if (finished) return;
|
|
61
|
+
finished = true;
|
|
62
|
+
clearTimeout(timer);
|
|
63
|
+
options.signal?.removeEventListener("abort", abort);
|
|
64
|
+
resolve({
|
|
65
|
+
code,
|
|
66
|
+
reason: reason ?? failure,
|
|
67
|
+
stdout: Buffer.concat(chunks).toString("utf8"),
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
child.stdout?.on("data", chunk => {
|
|
71
|
+
bytes += chunk.length;
|
|
72
|
+
if (bytes > MAX_OUTPUT_BYTES) stop("OUTPUT_LIMIT");
|
|
73
|
+
else chunks.push(chunk);
|
|
74
|
+
});
|
|
75
|
+
child.once("error", error => complete(null, error.code ?? "SPAWN_FAILED"));
|
|
76
|
+
child.once("close", (code, signal) => complete(code, signal));
|
|
77
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
78
|
+
if (options.signal?.aborted) abort();
|
|
79
|
+
});
|
|
80
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/** Safe read-only inspection at the hooks directory Git actually resolves. */
|
|
2
|
+
import { constants } from "node:fs";
|
|
3
|
+
import { lstat, open, realpath } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { runHookCommand } from "./rails-hooks-command.mjs";
|
|
6
|
+
|
|
7
|
+
export const RAILS_HOOK_NAMES = Object.freeze([
|
|
8
|
+
"commit-msg",
|
|
9
|
+
"pre-commit",
|
|
10
|
+
"pre-push",
|
|
11
|
+
"prepare-commit-msg",
|
|
12
|
+
]);
|
|
13
|
+
const MAX_HOOK_BYTES = 512 * 1024;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Read an executable regular wrapper without following links or special files.
|
|
17
|
+
* @param {string} directory Canonical Git-selected directory.
|
|
18
|
+
* @param {string} name Fixed hook basename.
|
|
19
|
+
* @returns {Promise<boolean>} Whether the wrapper is installed.
|
|
20
|
+
*/
|
|
21
|
+
async function validWrapper(directory, name) {
|
|
22
|
+
const file = path.join(directory, name);
|
|
23
|
+
try {
|
|
24
|
+
const before = await lstat(file);
|
|
25
|
+
if (
|
|
26
|
+
!before.isFile() ||
|
|
27
|
+
before.isSymbolicLink() ||
|
|
28
|
+
(before.mode & 0o100) === 0 ||
|
|
29
|
+
before.size > MAX_HOOK_BYTES ||
|
|
30
|
+
!(await realpath(file)).startsWith(`${directory}${path.sep}`)
|
|
31
|
+
)
|
|
32
|
+
return false;
|
|
33
|
+
const handle = await open(
|
|
34
|
+
file,
|
|
35
|
+
constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK
|
|
36
|
+
);
|
|
37
|
+
try {
|
|
38
|
+
const opened = await handle.stat();
|
|
39
|
+
if (
|
|
40
|
+
!opened.isFile() ||
|
|
41
|
+
(opened.mode & 0o100) === 0 ||
|
|
42
|
+
opened.dev !== before.dev ||
|
|
43
|
+
opened.ino !== before.ino ||
|
|
44
|
+
opened.size > MAX_HOOK_BYTES
|
|
45
|
+
)
|
|
46
|
+
return false;
|
|
47
|
+
const buffer = Buffer.alloc(opened.size + 1);
|
|
48
|
+
let count = 0;
|
|
49
|
+
while (count < buffer.length) {
|
|
50
|
+
const part = await handle.read(
|
|
51
|
+
buffer,
|
|
52
|
+
count,
|
|
53
|
+
buffer.length - count,
|
|
54
|
+
count
|
|
55
|
+
);
|
|
56
|
+
if (part.bytesRead === 0) break;
|
|
57
|
+
count += part.bytesRead;
|
|
58
|
+
}
|
|
59
|
+
const after = await handle.stat();
|
|
60
|
+
return (
|
|
61
|
+
count <= MAX_HOOK_BYTES &&
|
|
62
|
+
count === opened.size &&
|
|
63
|
+
count === after.size &&
|
|
64
|
+
(after.mode & 0o100) !== 0 &&
|
|
65
|
+
new TextDecoder("utf8", { fatal: true })
|
|
66
|
+
.decode(buffer.subarray(0, count))
|
|
67
|
+
.toLowerCase()
|
|
68
|
+
.includes("lefthook")
|
|
69
|
+
);
|
|
70
|
+
} finally {
|
|
71
|
+
await handle.close();
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Observe actual installed hooks, including a worktree's shared directory.
|
|
80
|
+
* The Git-selected directory is the narrow authority for these four reads;
|
|
81
|
+
* ordinary health project-file confinement is not widened.
|
|
82
|
+
* @param {string} projectRoot Host checkout.
|
|
83
|
+
* @param {{timeoutMs?: number, signal?: AbortSignal, env?: NodeJS.ProcessEnv}} [options] Shared deadline/cancellation.
|
|
84
|
+
* @returns {Promise<{status: "pass"|"fail", drift: string[], directory?: string}>} Installation state.
|
|
85
|
+
*/
|
|
86
|
+
export async function inspectRailsHooks(projectRoot, options = {}) {
|
|
87
|
+
const budget = options.timeoutMs ?? 30_000;
|
|
88
|
+
const deadline = Date.now() + budget;
|
|
89
|
+
if (!Number.isFinite(budget) || budget <= 0 || options.signal?.aborted)
|
|
90
|
+
return { status: "fail", drift: ["Git hooks inspection was cancelled"] };
|
|
91
|
+
const result = await runHookCommand(
|
|
92
|
+
"git",
|
|
93
|
+
["rev-parse", "--git-path", "hooks"],
|
|
94
|
+
{
|
|
95
|
+
...options,
|
|
96
|
+
cwd: projectRoot,
|
|
97
|
+
timeoutMs: budget,
|
|
98
|
+
capture: true,
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
if (
|
|
102
|
+
result.code !== 0 ||
|
|
103
|
+
result.reason !== null ||
|
|
104
|
+
!result.stdout.endsWith("\n") ||
|
|
105
|
+
/[\n\r\0]/.test(result.stdout.slice(0, -1)) ||
|
|
106
|
+
result.stdout.length <= 1
|
|
107
|
+
)
|
|
108
|
+
return { status: "fail", drift: ["Git hooks directory unavailable"] };
|
|
109
|
+
const selected = path.resolve(projectRoot, result.stdout.slice(0, -1));
|
|
110
|
+
let directory;
|
|
111
|
+
try {
|
|
112
|
+
directory = await realpath(selected);
|
|
113
|
+
if (!(await lstat(directory)).isDirectory())
|
|
114
|
+
throw new Error("Not a directory");
|
|
115
|
+
} catch {
|
|
116
|
+
return {
|
|
117
|
+
status: "fail",
|
|
118
|
+
drift: [...RAILS_HOOK_NAMES],
|
|
119
|
+
directory: selected,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const missing = await Promise.all(
|
|
123
|
+
RAILS_HOOK_NAMES.map(async name =>
|
|
124
|
+
(await validWrapper(directory, name)) ? undefined : name
|
|
125
|
+
)
|
|
126
|
+
);
|
|
127
|
+
const drift = missing.filter(name => name !== undefined);
|
|
128
|
+
if (Date.now() >= deadline || options.signal?.aborted)
|
|
129
|
+
return {
|
|
130
|
+
status: "fail",
|
|
131
|
+
drift: ["Git hooks inspection timed out or was cancelled"],
|
|
132
|
+
directory,
|
|
133
|
+
};
|
|
134
|
+
return { status: drift.length === 0 ? "pass" : "fail", drift, directory };
|
|
135
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface RailsHooksOptions {
|
|
2
|
+
readonly timeoutMs?: number;
|
|
3
|
+
readonly signal?: AbortSignal;
|
|
4
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
5
|
+
}
|
|
6
|
+
export interface RailsHookInspection {
|
|
7
|
+
readonly status: "pass" | "fail";
|
|
8
|
+
readonly drift: readonly string[];
|
|
9
|
+
readonly directory?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const RAILS_HOOK_INSTALL_COMMAND: "bundle exec lefthook install";
|
|
12
|
+
export declare const RAILS_HOOK_ENGINE_FILES: readonly [
|
|
13
|
+
"rails-hooks.mjs",
|
|
14
|
+
"rails-hooks-inspection.mjs",
|
|
15
|
+
"rails-hooks-command.mjs",
|
|
16
|
+
];
|
|
17
|
+
export declare function inspectRailsHooks(
|
|
18
|
+
projectRoot: string,
|
|
19
|
+
options?: RailsHooksOptions
|
|
20
|
+
): Promise<RailsHookInspection>;
|
|
21
|
+
export declare function ensureRailsHooks(
|
|
22
|
+
projectRoot: string,
|
|
23
|
+
options?: RailsHooksOptions
|
|
24
|
+
): Promise<{
|
|
25
|
+
readonly status:
|
|
26
|
+
| "not-applicable"
|
|
27
|
+
| "already-installed"
|
|
28
|
+
| "installed"
|
|
29
|
+
| "failed";
|
|
30
|
+
readonly detail?: string;
|
|
31
|
+
}>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/** One Rails installer shared by startup, apply, doctor and health. */
|
|
2
|
+
import { lstat } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { inspectRailsHooks } from "./rails-hooks-inspection.mjs";
|
|
5
|
+
import { runHookCommand } from "./rails-hooks-command.mjs";
|
|
6
|
+
|
|
7
|
+
export { inspectRailsHooks } from "./rails-hooks-inspection.mjs";
|
|
8
|
+
export const RAILS_HOOK_INSTALL_COMMAND = "bundle exec lefthook install";
|
|
9
|
+
export const RAILS_HOOK_ENGINE_FILES = Object.freeze([
|
|
10
|
+
"rails-hooks.mjs",
|
|
11
|
+
"rails-hooks-inspection.mjs",
|
|
12
|
+
"rails-hooks-command.mjs",
|
|
13
|
+
]);
|
|
14
|
+
const DEFAULT_INSTALL_BUDGET_MS = 30_000;
|
|
15
|
+
const CANCELLED_INSTALLATION = "installation timed out or was cancelled";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Describe a failed install without echoing Bundler output or credentials.
|
|
19
|
+
* @param {string} reason Bounded operator-readable cause.
|
|
20
|
+
* @returns {{status: "failed", detail: string}} Actionable failure.
|
|
21
|
+
*/
|
|
22
|
+
function failed(reason) {
|
|
23
|
+
return {
|
|
24
|
+
status: "failed",
|
|
25
|
+
detail: `Rails Git hooks: ${reason}; run ${RAILS_HOOK_INSTALL_COMMAND}.`,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Install only absent/invalid wrappers through the actual supported manager.
|
|
31
|
+
* No package installation or interactive shell is part of this operation.
|
|
32
|
+
* @param {string} projectRoot Host checkout (startup may pass a subdirectory).
|
|
33
|
+
* @param {{timeoutMs?: number, signal?: AbortSignal, env?: NodeJS.ProcessEnv}} [options] One total bounded operation.
|
|
34
|
+
* @returns {Promise<{status: "not-applicable"|"already-installed"|"installed"|"failed", detail?: string}>} Outcome; callers keep startup/apply nonblocking on failure.
|
|
35
|
+
*/
|
|
36
|
+
export async function ensureRailsHooks(projectRoot, options = {}) {
|
|
37
|
+
const budget = options.timeoutMs ?? DEFAULT_INSTALL_BUDGET_MS;
|
|
38
|
+
if (!Number.isFinite(budget) || budget <= 0)
|
|
39
|
+
return failed("invalid installation deadline");
|
|
40
|
+
const deadline = Date.now() + budget;
|
|
41
|
+
const remaining = () => Math.max(1, deadline - Date.now());
|
|
42
|
+
const scope = {
|
|
43
|
+
...options,
|
|
44
|
+
cwd: projectRoot,
|
|
45
|
+
timeoutMs: remaining(),
|
|
46
|
+
capture: true,
|
|
47
|
+
};
|
|
48
|
+
const top = await runHookCommand(
|
|
49
|
+
"git",
|
|
50
|
+
["rev-parse", "--show-toplevel"],
|
|
51
|
+
scope
|
|
52
|
+
);
|
|
53
|
+
const validRoot =
|
|
54
|
+
top.code === 0 &&
|
|
55
|
+
top.reason === null &&
|
|
56
|
+
top.stdout.endsWith("\n") &&
|
|
57
|
+
top.stdout.length > 1 &&
|
|
58
|
+
!/[\n\r\0]/.test(top.stdout.slice(0, -1));
|
|
59
|
+
const root = validRoot
|
|
60
|
+
? path.resolve(projectRoot, top.stdout.slice(0, -1))
|
|
61
|
+
: projectRoot;
|
|
62
|
+
try {
|
|
63
|
+
const configuration = await lstat(path.join(root, "lefthook.yml"));
|
|
64
|
+
if (!configuration.isFile() || configuration.isSymbolicLink())
|
|
65
|
+
return failed("lefthook.yml is not a regular file");
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (error.code === "ENOENT") return { status: "not-applicable" };
|
|
68
|
+
return failed("lefthook.yml could not be inspected");
|
|
69
|
+
}
|
|
70
|
+
if (!validRoot) return failed("Git checkout could not be read");
|
|
71
|
+
if (Date.now() >= deadline || options.signal?.aborted)
|
|
72
|
+
return failed(CANCELLED_INSTALLATION);
|
|
73
|
+
const before = await inspectRailsHooks(root, {
|
|
74
|
+
...options,
|
|
75
|
+
timeoutMs: remaining(),
|
|
76
|
+
});
|
|
77
|
+
if (before.status === "pass") return { status: "already-installed" };
|
|
78
|
+
if (before.directory === undefined)
|
|
79
|
+
return failed("Git hooks directory could not be read");
|
|
80
|
+
if (Date.now() >= deadline || options.signal?.aborted)
|
|
81
|
+
return failed(CANCELLED_INSTALLATION);
|
|
82
|
+
const installed = await runHookCommand(
|
|
83
|
+
"bundle",
|
|
84
|
+
["exec", "lefthook", "install"],
|
|
85
|
+
{
|
|
86
|
+
...options,
|
|
87
|
+
cwd: root,
|
|
88
|
+
timeoutMs: remaining(),
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
if (installed.code !== 0 || installed.reason !== null) {
|
|
92
|
+
if (installed.reason === "ENOENT") return failed("Bundler is unavailable");
|
|
93
|
+
if (["ETIMEDOUT", "ABORT_ERR"].includes(installed.reason))
|
|
94
|
+
return failed(CANCELLED_INSTALLATION);
|
|
95
|
+
const exitDetail =
|
|
96
|
+
installed.code === null ? "" : ` (exit ${installed.code})`;
|
|
97
|
+
return failed(`installation failed${exitDetail}`);
|
|
98
|
+
}
|
|
99
|
+
if (Date.now() >= deadline || options.signal?.aborted)
|
|
100
|
+
return failed(CANCELLED_INSTALLATION);
|
|
101
|
+
const after = await inspectRailsHooks(root, {
|
|
102
|
+
...options,
|
|
103
|
+
timeoutMs: remaining(),
|
|
104
|
+
});
|
|
105
|
+
return after.status === "pass"
|
|
106
|
+
? { status: "installed" }
|
|
107
|
+
: failed(
|
|
108
|
+
`installation left missing or invalid hooks: ${after.drift.join(", ")}`
|
|
109
|
+
);
|
|
110
|
+
}
|
|
@@ -75,6 +75,7 @@ scripts/check-skipped-required-checks.mjs
|
|
|
75
75
|
scripts/check-state-classification.mjs
|
|
76
76
|
scripts/check-third-party-action-pins.mjs
|
|
77
77
|
scripts/check-third-party-review-evidence.mjs
|
|
78
|
+
scripts/review-evidence-event.mjs
|
|
78
79
|
scripts/check-threshold-ratchet.mjs
|
|
79
80
|
scripts/check-verification-coverage.mjs
|
|
80
81
|
scripts/check-workflow-load-failures.mjs
|