@codyswann/lisa 4.87.12 → 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/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.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 +46 -4
- 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 +1 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// This file is managed by Lisa and IS replaced on each `lisa` run.
|
|
2
|
+
// Do not edit directly — durable changes belong upstream in Lisa.
|
|
3
|
+
|
|
4
|
+
/** One Rails installer shared by startup, apply, doctor and health. */
|
|
5
|
+
import { lstat } from "node:fs/promises";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { inspectRailsHooks } from "./rails-hooks-inspection.mjs";
|
|
8
|
+
import { runHookCommand } from "./rails-hooks-command.mjs";
|
|
9
|
+
|
|
10
|
+
export { inspectRailsHooks } from "./rails-hooks-inspection.mjs";
|
|
11
|
+
export const RAILS_HOOK_INSTALL_COMMAND = "bundle exec lefthook install";
|
|
12
|
+
export const RAILS_HOOK_ENGINE_FILES = Object.freeze([
|
|
13
|
+
"rails-hooks.mjs",
|
|
14
|
+
"rails-hooks-inspection.mjs",
|
|
15
|
+
"rails-hooks-command.mjs",
|
|
16
|
+
]);
|
|
17
|
+
const DEFAULT_INSTALL_BUDGET_MS = 30_000;
|
|
18
|
+
const CANCELLED_INSTALLATION = "installation timed out or was cancelled";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Describe a failed install without echoing Bundler output or credentials.
|
|
22
|
+
* @param {string} reason Bounded operator-readable cause.
|
|
23
|
+
* @returns {{status: "failed", detail: string}} Actionable failure.
|
|
24
|
+
*/
|
|
25
|
+
function failed(reason) {
|
|
26
|
+
return {
|
|
27
|
+
status: "failed",
|
|
28
|
+
detail: `Rails Git hooks: ${reason}; run ${RAILS_HOOK_INSTALL_COMMAND}.`,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Install only absent/invalid wrappers through the actual supported manager.
|
|
34
|
+
* No package installation or interactive shell is part of this operation.
|
|
35
|
+
* @param {string} projectRoot Host checkout (startup may pass a subdirectory).
|
|
36
|
+
* @param {{timeoutMs?: number, signal?: AbortSignal, env?: NodeJS.ProcessEnv}} [options] One total bounded operation.
|
|
37
|
+
* @returns {Promise<{status: "not-applicable"|"already-installed"|"installed"|"failed", detail?: string}>} Outcome; callers keep startup/apply nonblocking on failure.
|
|
38
|
+
*/
|
|
39
|
+
export async function ensureRailsHooks(projectRoot, options = {}) {
|
|
40
|
+
const budget = options.timeoutMs ?? DEFAULT_INSTALL_BUDGET_MS;
|
|
41
|
+
if (!Number.isFinite(budget) || budget <= 0)
|
|
42
|
+
return failed("invalid installation deadline");
|
|
43
|
+
const deadline = Date.now() + budget;
|
|
44
|
+
const remaining = () => Math.max(1, deadline - Date.now());
|
|
45
|
+
const scope = {
|
|
46
|
+
...options,
|
|
47
|
+
cwd: projectRoot,
|
|
48
|
+
timeoutMs: remaining(),
|
|
49
|
+
capture: true,
|
|
50
|
+
};
|
|
51
|
+
const top = await runHookCommand(
|
|
52
|
+
"git",
|
|
53
|
+
["rev-parse", "--show-toplevel"],
|
|
54
|
+
scope
|
|
55
|
+
);
|
|
56
|
+
const validRoot =
|
|
57
|
+
top.code === 0 &&
|
|
58
|
+
top.reason === null &&
|
|
59
|
+
top.stdout.endsWith("\n") &&
|
|
60
|
+
top.stdout.length > 1 &&
|
|
61
|
+
!/[\n\r\0]/.test(top.stdout.slice(0, -1));
|
|
62
|
+
const root = validRoot
|
|
63
|
+
? path.resolve(projectRoot, top.stdout.slice(0, -1))
|
|
64
|
+
: projectRoot;
|
|
65
|
+
try {
|
|
66
|
+
const configuration = await lstat(path.join(root, "lefthook.yml"));
|
|
67
|
+
if (!configuration.isFile() || configuration.isSymbolicLink())
|
|
68
|
+
return failed("lefthook.yml is not a regular file");
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (error.code === "ENOENT") return { status: "not-applicable" };
|
|
71
|
+
return failed("lefthook.yml could not be inspected");
|
|
72
|
+
}
|
|
73
|
+
if (!validRoot) return failed("Git checkout could not be read");
|
|
74
|
+
if (Date.now() >= deadline || options.signal?.aborted)
|
|
75
|
+
return failed(CANCELLED_INSTALLATION);
|
|
76
|
+
const before = await inspectRailsHooks(root, {
|
|
77
|
+
...options,
|
|
78
|
+
timeoutMs: remaining(),
|
|
79
|
+
});
|
|
80
|
+
if (before.status === "pass") return { status: "already-installed" };
|
|
81
|
+
if (before.directory === undefined)
|
|
82
|
+
return failed("Git hooks directory could not be read");
|
|
83
|
+
if (Date.now() >= deadline || options.signal?.aborted)
|
|
84
|
+
return failed(CANCELLED_INSTALLATION);
|
|
85
|
+
const installed = await runHookCommand(
|
|
86
|
+
"bundle",
|
|
87
|
+
["exec", "lefthook", "install"],
|
|
88
|
+
{
|
|
89
|
+
...options,
|
|
90
|
+
cwd: root,
|
|
91
|
+
timeoutMs: remaining(),
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
if (installed.code !== 0 || installed.reason !== null) {
|
|
95
|
+
if (installed.reason === "ENOENT") return failed("Bundler is unavailable");
|
|
96
|
+
if (["ETIMEDOUT", "ABORT_ERR"].includes(installed.reason))
|
|
97
|
+
return failed(CANCELLED_INSTALLATION);
|
|
98
|
+
const exitDetail =
|
|
99
|
+
installed.code === null ? "" : ` (exit ${installed.code})`;
|
|
100
|
+
return failed(`installation failed${exitDetail}`);
|
|
101
|
+
}
|
|
102
|
+
if (Date.now() >= deadline || options.signal?.aborted)
|
|
103
|
+
return failed(CANCELLED_INSTALLATION);
|
|
104
|
+
const after = await inspectRailsHooks(root, {
|
|
105
|
+
...options,
|
|
106
|
+
timeoutMs: remaining(),
|
|
107
|
+
});
|
|
108
|
+
return after.status === "pass"
|
|
109
|
+
? { status: "installed" }
|
|
110
|
+
: failed(
|
|
111
|
+
`installation left missing or invalid hooks: ${after.drift.join(", ")}`
|
|
112
|
+
);
|
|
113
|
+
}
|
|
@@ -98,6 +98,10 @@
|
|
|
98
98
|
"command": "${CURSOR_PLUGIN_ROOT}/hooks/install-pkgs.sh",
|
|
99
99
|
"matcher": "startup"
|
|
100
100
|
},
|
|
101
|
+
{
|
|
102
|
+
"command": "${CURSOR_PLUGIN_ROOT}/hooks/install-rails-hooks.sh",
|
|
103
|
+
"matcher": "startup"
|
|
104
|
+
},
|
|
101
105
|
{
|
|
102
106
|
"command": "${CURSOR_PLUGIN_ROOT}/hooks/withdrawn-rulings.sh --session-start"
|
|
103
107
|
},
|
|
@@ -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
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// This file is managed by Lisa and IS replaced on each `lisa` run.
|
|
2
|
+
// Do not edit directly — durable changes belong upstream in Lisa.
|
|
3
|
+
|
|
4
|
+
/** Bounded local Git/Bundler children used by Rails hook installation. */
|
|
5
|
+
import { spawn } from "node:child_process";
|
|
6
|
+
|
|
7
|
+
const REPOSITORY_ENVIRONMENT = new Set([
|
|
8
|
+
"GIT_DIR",
|
|
9
|
+
"GIT_COMMON_DIR",
|
|
10
|
+
"GIT_WORK_TREE",
|
|
11
|
+
"GIT_INDEX_FILE",
|
|
12
|
+
"GIT_PREFIX",
|
|
13
|
+
]);
|
|
14
|
+
const MAX_OUTPUT_BYTES = 16 * 1024;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Execute one fixed local tool, killing its owned process group at the deadline.
|
|
18
|
+
* @param {string} command Tool selected by the caller, never a shell expression.
|
|
19
|
+
* @param {string[]} args Literal arguments.
|
|
20
|
+
* @param {{cwd: string, timeoutMs: number, signal?: AbortSignal, env?: NodeJS.ProcessEnv, capture?: boolean}} options Execution scope.
|
|
21
|
+
* @returns {Promise<{code: number|null, reason: string|null, stdout: string}>} Actual child outcome.
|
|
22
|
+
*/
|
|
23
|
+
export function runHookCommand(command, args, options) {
|
|
24
|
+
if (options.signal?.aborted)
|
|
25
|
+
return Promise.resolve({ code: null, reason: "ABORT_ERR", stdout: "" });
|
|
26
|
+
return new Promise(resolve => {
|
|
27
|
+
const env = Object.fromEntries(
|
|
28
|
+
Object.entries(options.env ?? process.env).filter(
|
|
29
|
+
([name]) => !REPOSITORY_ENVIRONMENT.has(name)
|
|
30
|
+
)
|
|
31
|
+
);
|
|
32
|
+
const budget = Math.max(1, Math.floor(options.timeoutMs));
|
|
33
|
+
const grouped = process.platform !== "win32";
|
|
34
|
+
const child = spawn(command, args, {
|
|
35
|
+
cwd: options.cwd,
|
|
36
|
+
env,
|
|
37
|
+
detached: grouped,
|
|
38
|
+
stdio: ["ignore", options.capture ? "pipe" : "ignore", "ignore"],
|
|
39
|
+
// The owned timer kills the whole POSIX group first. Node's immediate-
|
|
40
|
+
// child timeout is a second bounded backstop, not the cleanup mechanism.
|
|
41
|
+
timeout: budget + 1_000,
|
|
42
|
+
killSignal: "SIGKILL",
|
|
43
|
+
windowsHide: true,
|
|
44
|
+
});
|
|
45
|
+
let finished = false;
|
|
46
|
+
let reason = null;
|
|
47
|
+
let bytes = 0;
|
|
48
|
+
const chunks = [];
|
|
49
|
+
const stop = failure => {
|
|
50
|
+
if (finished) return;
|
|
51
|
+
reason ??= failure;
|
|
52
|
+
try {
|
|
53
|
+
if (grouped && child.pid) process.kill(-child.pid, "SIGKILL");
|
|
54
|
+
else child.kill("SIGKILL");
|
|
55
|
+
} catch {
|
|
56
|
+
// A group that has already exited needs no further signal.
|
|
57
|
+
child.kill("SIGKILL");
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const timer = setTimeout(() => stop("ETIMEDOUT"), budget);
|
|
61
|
+
const abort = () => stop("ABORT_ERR");
|
|
62
|
+
const complete = (code, failure) => {
|
|
63
|
+
if (finished) return;
|
|
64
|
+
finished = true;
|
|
65
|
+
clearTimeout(timer);
|
|
66
|
+
options.signal?.removeEventListener("abort", abort);
|
|
67
|
+
resolve({
|
|
68
|
+
code,
|
|
69
|
+
reason: reason ?? failure,
|
|
70
|
+
stdout: Buffer.concat(chunks).toString("utf8"),
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
child.stdout?.on("data", chunk => {
|
|
74
|
+
bytes += chunk.length;
|
|
75
|
+
if (bytes > MAX_OUTPUT_BYTES) stop("OUTPUT_LIMIT");
|
|
76
|
+
else chunks.push(chunk);
|
|
77
|
+
});
|
|
78
|
+
child.once("error", error => complete(null, error.code ?? "SPAWN_FAILED"));
|
|
79
|
+
child.once("close", (code, signal) => complete(code, signal));
|
|
80
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
81
|
+
if (options.signal?.aborted) abort();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// This file is managed by Lisa and IS replaced on each `lisa` run.
|
|
2
|
+
// Do not edit directly — durable changes belong upstream in Lisa.
|
|
3
|
+
|
|
4
|
+
/** Safe read-only inspection at the hooks directory Git actually resolves. */
|
|
5
|
+
import { constants } from "node:fs";
|
|
6
|
+
import { lstat, open, realpath } from "node:fs/promises";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { runHookCommand } from "./rails-hooks-command.mjs";
|
|
9
|
+
|
|
10
|
+
export const RAILS_HOOK_NAMES = Object.freeze([
|
|
11
|
+
"commit-msg",
|
|
12
|
+
"pre-commit",
|
|
13
|
+
"pre-push",
|
|
14
|
+
"prepare-commit-msg",
|
|
15
|
+
]);
|
|
16
|
+
const MAX_HOOK_BYTES = 512 * 1024;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Read an executable regular wrapper without following links or special files.
|
|
20
|
+
* @param {string} directory Canonical Git-selected directory.
|
|
21
|
+
* @param {string} name Fixed hook basename.
|
|
22
|
+
* @returns {Promise<boolean>} Whether the wrapper is installed.
|
|
23
|
+
*/
|
|
24
|
+
async function validWrapper(directory, name) {
|
|
25
|
+
const file = path.join(directory, name);
|
|
26
|
+
try {
|
|
27
|
+
const before = await lstat(file);
|
|
28
|
+
if (
|
|
29
|
+
!before.isFile() ||
|
|
30
|
+
before.isSymbolicLink() ||
|
|
31
|
+
(before.mode & 0o100) === 0 ||
|
|
32
|
+
before.size > MAX_HOOK_BYTES ||
|
|
33
|
+
!(await realpath(file)).startsWith(`${directory}${path.sep}`)
|
|
34
|
+
)
|
|
35
|
+
return false;
|
|
36
|
+
const handle = await open(
|
|
37
|
+
file,
|
|
38
|
+
constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK
|
|
39
|
+
);
|
|
40
|
+
try {
|
|
41
|
+
const opened = await handle.stat();
|
|
42
|
+
if (
|
|
43
|
+
!opened.isFile() ||
|
|
44
|
+
(opened.mode & 0o100) === 0 ||
|
|
45
|
+
opened.dev !== before.dev ||
|
|
46
|
+
opened.ino !== before.ino ||
|
|
47
|
+
opened.size > MAX_HOOK_BYTES
|
|
48
|
+
)
|
|
49
|
+
return false;
|
|
50
|
+
const buffer = Buffer.alloc(opened.size + 1);
|
|
51
|
+
let count = 0;
|
|
52
|
+
while (count < buffer.length) {
|
|
53
|
+
const part = await handle.read(
|
|
54
|
+
buffer,
|
|
55
|
+
count,
|
|
56
|
+
buffer.length - count,
|
|
57
|
+
count
|
|
58
|
+
);
|
|
59
|
+
if (part.bytesRead === 0) break;
|
|
60
|
+
count += part.bytesRead;
|
|
61
|
+
}
|
|
62
|
+
const after = await handle.stat();
|
|
63
|
+
return (
|
|
64
|
+
count <= MAX_HOOK_BYTES &&
|
|
65
|
+
count === opened.size &&
|
|
66
|
+
count === after.size &&
|
|
67
|
+
(after.mode & 0o100) !== 0 &&
|
|
68
|
+
new TextDecoder("utf8", { fatal: true })
|
|
69
|
+
.decode(buffer.subarray(0, count))
|
|
70
|
+
.toLowerCase()
|
|
71
|
+
.includes("lefthook")
|
|
72
|
+
);
|
|
73
|
+
} finally {
|
|
74
|
+
await handle.close();
|
|
75
|
+
}
|
|
76
|
+
} catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Observe actual installed hooks, including a worktree's shared directory.
|
|
83
|
+
* The Git-selected directory is the narrow authority for these four reads;
|
|
84
|
+
* ordinary health project-file confinement is not widened.
|
|
85
|
+
* @param {string} projectRoot Host checkout.
|
|
86
|
+
* @param {{timeoutMs?: number, signal?: AbortSignal, env?: NodeJS.ProcessEnv}} [options] Shared deadline/cancellation.
|
|
87
|
+
* @returns {Promise<{status: "pass"|"fail", drift: string[], directory?: string}>} Installation state.
|
|
88
|
+
*/
|
|
89
|
+
export async function inspectRailsHooks(projectRoot, options = {}) {
|
|
90
|
+
const budget = options.timeoutMs ?? 30_000;
|
|
91
|
+
const deadline = Date.now() + budget;
|
|
92
|
+
if (!Number.isFinite(budget) || budget <= 0 || options.signal?.aborted)
|
|
93
|
+
return { status: "fail", drift: ["Git hooks inspection was cancelled"] };
|
|
94
|
+
const result = await runHookCommand(
|
|
95
|
+
"git",
|
|
96
|
+
["rev-parse", "--git-path", "hooks"],
|
|
97
|
+
{
|
|
98
|
+
...options,
|
|
99
|
+
cwd: projectRoot,
|
|
100
|
+
timeoutMs: budget,
|
|
101
|
+
capture: true,
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
if (
|
|
105
|
+
result.code !== 0 ||
|
|
106
|
+
result.reason !== null ||
|
|
107
|
+
!result.stdout.endsWith("\n") ||
|
|
108
|
+
/[\n\r\0]/.test(result.stdout.slice(0, -1)) ||
|
|
109
|
+
result.stdout.length <= 1
|
|
110
|
+
)
|
|
111
|
+
return { status: "fail", drift: ["Git hooks directory unavailable"] };
|
|
112
|
+
const selected = path.resolve(projectRoot, result.stdout.slice(0, -1));
|
|
113
|
+
let directory;
|
|
114
|
+
try {
|
|
115
|
+
directory = await realpath(selected);
|
|
116
|
+
if (!(await lstat(directory)).isDirectory())
|
|
117
|
+
throw new Error("Not a directory");
|
|
118
|
+
} catch {
|
|
119
|
+
return {
|
|
120
|
+
status: "fail",
|
|
121
|
+
drift: [...RAILS_HOOK_NAMES],
|
|
122
|
+
directory: selected,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const missing = await Promise.all(
|
|
126
|
+
RAILS_HOOK_NAMES.map(async name =>
|
|
127
|
+
(await validWrapper(directory, name)) ? undefined : name
|
|
128
|
+
)
|
|
129
|
+
);
|
|
130
|
+
const drift = missing.filter(name => name !== undefined);
|
|
131
|
+
if (Date.now() >= deadline || options.signal?.aborted)
|
|
132
|
+
return {
|
|
133
|
+
status: "fail",
|
|
134
|
+
drift: ["Git hooks inspection timed out or was cancelled"],
|
|
135
|
+
directory,
|
|
136
|
+
};
|
|
137
|
+
return { status: drift.length === 0 ? "pass" : "fail", drift, directory };
|
|
138
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// This file is managed by Lisa and IS replaced on each `lisa` run.
|
|
2
|
+
// Do not edit directly — durable changes belong upstream in Lisa.
|
|
3
|
+
|
|
4
|
+
/** One Rails installer shared by startup, apply, doctor and health. */
|
|
5
|
+
import { lstat } from "node:fs/promises";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { inspectRailsHooks } from "./rails-hooks-inspection.mjs";
|
|
8
|
+
import { runHookCommand } from "./rails-hooks-command.mjs";
|
|
9
|
+
|
|
10
|
+
export { inspectRailsHooks } from "./rails-hooks-inspection.mjs";
|
|
11
|
+
export const RAILS_HOOK_INSTALL_COMMAND = "bundle exec lefthook install";
|
|
12
|
+
export const RAILS_HOOK_ENGINE_FILES = Object.freeze([
|
|
13
|
+
"rails-hooks.mjs",
|
|
14
|
+
"rails-hooks-inspection.mjs",
|
|
15
|
+
"rails-hooks-command.mjs",
|
|
16
|
+
]);
|
|
17
|
+
const DEFAULT_INSTALL_BUDGET_MS = 30_000;
|
|
18
|
+
const CANCELLED_INSTALLATION = "installation timed out or was cancelled";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Describe a failed install without echoing Bundler output or credentials.
|
|
22
|
+
* @param {string} reason Bounded operator-readable cause.
|
|
23
|
+
* @returns {{status: "failed", detail: string}} Actionable failure.
|
|
24
|
+
*/
|
|
25
|
+
function failed(reason) {
|
|
26
|
+
return {
|
|
27
|
+
status: "failed",
|
|
28
|
+
detail: `Rails Git hooks: ${reason}; run ${RAILS_HOOK_INSTALL_COMMAND}.`,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Install only absent/invalid wrappers through the actual supported manager.
|
|
34
|
+
* No package installation or interactive shell is part of this operation.
|
|
35
|
+
* @param {string} projectRoot Host checkout (startup may pass a subdirectory).
|
|
36
|
+
* @param {{timeoutMs?: number, signal?: AbortSignal, env?: NodeJS.ProcessEnv}} [options] One total bounded operation.
|
|
37
|
+
* @returns {Promise<{status: "not-applicable"|"already-installed"|"installed"|"failed", detail?: string}>} Outcome; callers keep startup/apply nonblocking on failure.
|
|
38
|
+
*/
|
|
39
|
+
export async function ensureRailsHooks(projectRoot, options = {}) {
|
|
40
|
+
const budget = options.timeoutMs ?? DEFAULT_INSTALL_BUDGET_MS;
|
|
41
|
+
if (!Number.isFinite(budget) || budget <= 0)
|
|
42
|
+
return failed("invalid installation deadline");
|
|
43
|
+
const deadline = Date.now() + budget;
|
|
44
|
+
const remaining = () => Math.max(1, deadline - Date.now());
|
|
45
|
+
const scope = {
|
|
46
|
+
...options,
|
|
47
|
+
cwd: projectRoot,
|
|
48
|
+
timeoutMs: remaining(),
|
|
49
|
+
capture: true,
|
|
50
|
+
};
|
|
51
|
+
const top = await runHookCommand(
|
|
52
|
+
"git",
|
|
53
|
+
["rev-parse", "--show-toplevel"],
|
|
54
|
+
scope
|
|
55
|
+
);
|
|
56
|
+
const validRoot =
|
|
57
|
+
top.code === 0 &&
|
|
58
|
+
top.reason === null &&
|
|
59
|
+
top.stdout.endsWith("\n") &&
|
|
60
|
+
top.stdout.length > 1 &&
|
|
61
|
+
!/[\n\r\0]/.test(top.stdout.slice(0, -1));
|
|
62
|
+
const root = validRoot
|
|
63
|
+
? path.resolve(projectRoot, top.stdout.slice(0, -1))
|
|
64
|
+
: projectRoot;
|
|
65
|
+
try {
|
|
66
|
+
const configuration = await lstat(path.join(root, "lefthook.yml"));
|
|
67
|
+
if (!configuration.isFile() || configuration.isSymbolicLink())
|
|
68
|
+
return failed("lefthook.yml is not a regular file");
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (error.code === "ENOENT") return { status: "not-applicable" };
|
|
71
|
+
return failed("lefthook.yml could not be inspected");
|
|
72
|
+
}
|
|
73
|
+
if (!validRoot) return failed("Git checkout could not be read");
|
|
74
|
+
if (Date.now() >= deadline || options.signal?.aborted)
|
|
75
|
+
return failed(CANCELLED_INSTALLATION);
|
|
76
|
+
const before = await inspectRailsHooks(root, {
|
|
77
|
+
...options,
|
|
78
|
+
timeoutMs: remaining(),
|
|
79
|
+
});
|
|
80
|
+
if (before.status === "pass") return { status: "already-installed" };
|
|
81
|
+
if (before.directory === undefined)
|
|
82
|
+
return failed("Git hooks directory could not be read");
|
|
83
|
+
if (Date.now() >= deadline || options.signal?.aborted)
|
|
84
|
+
return failed(CANCELLED_INSTALLATION);
|
|
85
|
+
const installed = await runHookCommand(
|
|
86
|
+
"bundle",
|
|
87
|
+
["exec", "lefthook", "install"],
|
|
88
|
+
{
|
|
89
|
+
...options,
|
|
90
|
+
cwd: root,
|
|
91
|
+
timeoutMs: remaining(),
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
if (installed.code !== 0 || installed.reason !== null) {
|
|
95
|
+
if (installed.reason === "ENOENT") return failed("Bundler is unavailable");
|
|
96
|
+
if (["ETIMEDOUT", "ABORT_ERR"].includes(installed.reason))
|
|
97
|
+
return failed(CANCELLED_INSTALLATION);
|
|
98
|
+
const exitDetail =
|
|
99
|
+
installed.code === null ? "" : ` (exit ${installed.code})`;
|
|
100
|
+
return failed(`installation failed${exitDetail}`);
|
|
101
|
+
}
|
|
102
|
+
if (Date.now() >= deadline || options.signal?.aborted)
|
|
103
|
+
return failed(CANCELLED_INSTALLATION);
|
|
104
|
+
const after = await inspectRailsHooks(root, {
|
|
105
|
+
...options,
|
|
106
|
+
timeoutMs: remaining(),
|
|
107
|
+
});
|
|
108
|
+
return after.status === "pass"
|
|
109
|
+
? { status: "installed" }
|
|
110
|
+
: failed(
|
|
111
|
+
`installation left missing or invalid hooks: ${after.drift.join(", ")}`
|
|
112
|
+
);
|
|
113
|
+
}
|
|
@@ -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
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// This file is managed by Lisa and IS replaced on each `lisa` run.
|
|
2
|
+
// Do not edit directly — durable changes belong upstream in Lisa.
|
|
3
|
+
|
|
4
|
+
/** Bounded local Git/Bundler children used by Rails hook installation. */
|
|
5
|
+
import { spawn } from "node:child_process";
|
|
6
|
+
|
|
7
|
+
const REPOSITORY_ENVIRONMENT = new Set([
|
|
8
|
+
"GIT_DIR",
|
|
9
|
+
"GIT_COMMON_DIR",
|
|
10
|
+
"GIT_WORK_TREE",
|
|
11
|
+
"GIT_INDEX_FILE",
|
|
12
|
+
"GIT_PREFIX",
|
|
13
|
+
]);
|
|
14
|
+
const MAX_OUTPUT_BYTES = 16 * 1024;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Execute one fixed local tool, killing its owned process group at the deadline.
|
|
18
|
+
* @param {string} command Tool selected by the caller, never a shell expression.
|
|
19
|
+
* @param {string[]} args Literal arguments.
|
|
20
|
+
* @param {{cwd: string, timeoutMs: number, signal?: AbortSignal, env?: NodeJS.ProcessEnv, capture?: boolean}} options Execution scope.
|
|
21
|
+
* @returns {Promise<{code: number|null, reason: string|null, stdout: string}>} Actual child outcome.
|
|
22
|
+
*/
|
|
23
|
+
export function runHookCommand(command, args, options) {
|
|
24
|
+
if (options.signal?.aborted)
|
|
25
|
+
return Promise.resolve({ code: null, reason: "ABORT_ERR", stdout: "" });
|
|
26
|
+
return new Promise(resolve => {
|
|
27
|
+
const env = Object.fromEntries(
|
|
28
|
+
Object.entries(options.env ?? process.env).filter(
|
|
29
|
+
([name]) => !REPOSITORY_ENVIRONMENT.has(name)
|
|
30
|
+
)
|
|
31
|
+
);
|
|
32
|
+
const budget = Math.max(1, Math.floor(options.timeoutMs));
|
|
33
|
+
const grouped = process.platform !== "win32";
|
|
34
|
+
const child = spawn(command, args, {
|
|
35
|
+
cwd: options.cwd,
|
|
36
|
+
env,
|
|
37
|
+
detached: grouped,
|
|
38
|
+
stdio: ["ignore", options.capture ? "pipe" : "ignore", "ignore"],
|
|
39
|
+
// The owned timer kills the whole POSIX group first. Node's immediate-
|
|
40
|
+
// child timeout is a second bounded backstop, not the cleanup mechanism.
|
|
41
|
+
timeout: budget + 1_000,
|
|
42
|
+
killSignal: "SIGKILL",
|
|
43
|
+
windowsHide: true,
|
|
44
|
+
});
|
|
45
|
+
let finished = false;
|
|
46
|
+
let reason = null;
|
|
47
|
+
let bytes = 0;
|
|
48
|
+
const chunks = [];
|
|
49
|
+
const stop = failure => {
|
|
50
|
+
if (finished) return;
|
|
51
|
+
reason ??= failure;
|
|
52
|
+
try {
|
|
53
|
+
if (grouped && child.pid) process.kill(-child.pid, "SIGKILL");
|
|
54
|
+
else child.kill("SIGKILL");
|
|
55
|
+
} catch {
|
|
56
|
+
// A group that has already exited needs no further signal.
|
|
57
|
+
child.kill("SIGKILL");
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const timer = setTimeout(() => stop("ETIMEDOUT"), budget);
|
|
61
|
+
const abort = () => stop("ABORT_ERR");
|
|
62
|
+
const complete = (code, failure) => {
|
|
63
|
+
if (finished) return;
|
|
64
|
+
finished = true;
|
|
65
|
+
clearTimeout(timer);
|
|
66
|
+
options.signal?.removeEventListener("abort", abort);
|
|
67
|
+
resolve({
|
|
68
|
+
code,
|
|
69
|
+
reason: reason ?? failure,
|
|
70
|
+
stdout: Buffer.concat(chunks).toString("utf8"),
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
child.stdout?.on("data", chunk => {
|
|
74
|
+
bytes += chunk.length;
|
|
75
|
+
if (bytes > MAX_OUTPUT_BYTES) stop("OUTPUT_LIMIT");
|
|
76
|
+
else chunks.push(chunk);
|
|
77
|
+
});
|
|
78
|
+
child.once("error", error => complete(null, error.code ?? "SPAWN_FAILED"));
|
|
79
|
+
child.once("close", (code, signal) => complete(code, signal));
|
|
80
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
81
|
+
if (options.signal?.aborted) abort();
|
|
82
|
+
});
|
|
83
|
+
}
|