The fastest browser for AI agents to run browser automation, built for sharing your logged-in browser state with your AI agents, like Codex or Claude Code, without disturbing you. Zero cost, zero config.
JavaScript agent-skillsai-agentautomationbrowserbrowser-automationclaude-codecodexhermes-agentskillsskills-sh
fix(tools): kill the whole process tree on timeout and drop cd/node/npx from the Claude allowlist
Zhuowei Wang9b27e70c3215
diff --git a/tools/linear-autofix/src/implement.mjs b/tools/linear-autofix/src/implement.mjsindex 0361b1d..5bf3829 100644--- a/tools/linear-autofix/src/implement.mjs+++ b/tools/linear-autofix/src/implement.mjs@@ -8,19 +8,23 @@ import * as linear from "./linear.mjs";import { note, runDir, transition, worktreePath } from "./state.mjs";import { escalate, FOOTER } from "./actions.mjs";+/**+ * Tools the implementer and the review fixer may use. The list keeps Claude on+ * rails and out of `git push`, `gh` and anything with network side effects; it+ * is not a sandbox against a hostile model (Edit plus `npm run` can execute+ * arbitrary code). Containment comes from the dedicated host and its limited+ * credentials. No `cd`, so every command runs at the worktree root; no bare+ * `node`/`npx`, which would allow arbitrary code outside the test runner.+ */export const CODE_TOOLS = ["Read","Edit","Write","Grep","Glob",- "Bash(cd *)",- "Bash(ls *)",- "Bash(cat *)",- "Bash(npm *)",- "Bash(npx *)",- "Bash(node *)",- "Bash(*/node_modules/.bin/*)",+ "Bash(npm --prefix package/ego-browser *)",+ "Bash(npm --prefix plugins/ego *)",+ "Bash(package/ego-browser/node_modules/.bin/prettier *)","Bash(git add *)","Bash(git commit *)","Bash(git diff *)",diff --git a/tools/linear-autofix/src/proc.mjs b/tools/linear-autofix/src/proc.mjsindex ce2aa22..8d66b13 100644--- a/tools/linear-autofix/src/proc.mjs+++ b/tools/linear-autofix/src/proc.mjs@@ -9,8 +9,14 @@ export class ProcessError extends Error {}/**- * Run a child process to completion. Rejects on a non-zero exit or on timeout- * (SIGTERM, then SIGKILL 10 s later). `input` is written to stdin.+ * Run a child process to completion. Rejects on a non-zero exit or on timeout.+ * `input` is written to stdin.+ *+ * The child is started in its own process group (`detached`), so a timeout+ * terminates the whole tree: Claude's npm, node and shell descendants go with+ * it (SIGTERM, then SIGKILL 10 s later). The promise settles only when every+ * holder of the stdio pipes has exited, so a worktree is quiet by the time a+ * timeout is reported.*/export function run(cmd,@@ -22,6 +28,7 @@ export function run(cwd,env: { ...process.env, ...env },stdio: ["pipe", "pipe", "pipe"],+ detached: true,});let stdout = "";let stderr = "";@@ -30,8 +37,8 @@ export function run(child.stderr.on("data", (d) => (stderr += d));const timer = setTimeout(() => {timedOut = true;- child.kill("SIGTERM");- setTimeout(() => child.kill("SIGKILL"), 10_000).unref();+ killTree(child, "SIGTERM");+ setTimeout(() => killTree(child, "SIGKILL"), 10_000).unref();}, timeoutMs);child.on("error", (err) => {clearTimeout(timer);@@ -69,6 +76,20 @@ export function run(});}+/** Signal the child's whole process group; fall back to the child alone. */+export function killTree(child, signal) {+ if (!child.pid) return;+ try {+ process.kill(-child.pid, signal);+ } catch (err) {+ if (err.code !== "ESRCH") {+ try {+ child.kill(signal);+ } catch {}+ }+ }+}+export function tail(text, lines = 40) {return String(text ?? "").trimEnd()diff --git a/tools/linear-autofix/src/proc.test.mjs b/tools/linear-autofix/src/proc.test.mjsnew file mode 100644index 0000000..dc9090a--- /dev/null+++ b/tools/linear-autofix/src/proc.test.mjs@@ -0,0 +1,48 @@+import assert from "node:assert/strict";+import fs from "node:fs";+import os from "node:os";+import path from "node:path";+import { test } from "node:test";+import { run, ProcessError } from "./proc.mjs";++const alive = (pid) => {+ try {+ process.kill(pid, 0);+ return true;+ } catch {+ return false;+ }+};++test("run resolves with stdout and rejects on a non-zero exit", async () => {+ const ok = await run("sh", ["-c", "printf hi; cat"], { input: " there" });+ assert.equal(ok.stdout, "hi there");+ await assert.rejects(run("sh", ["-c", "echo boom >&2; exit 3"]), (err) => {+ assert.ok(err instanceof ProcessError);+ assert.equal(err.code, 3);+ assert.match(err.message, /boom/);+ return true;+ });+ const tolerated = await run("sh", ["-c", "exit 2"], { allowFailure: true });+ assert.equal(tolerated.code, 2);+});++test("a timeout kills the child's descendants too", async () => {+ const pidFile = path.join(+ fs.mkdtempSync(path.join(os.tmpdir(), "autofix-proc-")),+ "pid",+ );+ await assert.rejects(+ run("sh", ["-c", `sleep 30 & echo $! > ${pidFile}; wait`], {+ timeoutMs: 300,+ }),+ (err) => err.timedOut === true,+ );+ const grandchild = Number(fs.readFileSync(pidFile, "utf8"));+ assert.ok(grandchild > 0);+ assert.equal(+ alive(grandchild),+ false,+ "background sleep should have been killed with the group",+ );+});diff --git a/tools/linear-autofix/src/prompts/implement.md b/tools/linear-autofix/src/prompts/implement.mdindex 46f5b2b..feb533e 100644--- a/tools/linear-autofix/src/prompts/implement.md+++ b/tools/linear-autofix/src/prompts/implement.md@@ -11,11 +11,11 @@ about them.1. Reproduce first: write a failing colocated `*.test.mjs` test (or extend anexisting one) that captures the defect. Tests run against the build, so- `cd {{packageDir}} && npm test` builds, typechecks and runs them.+ `npm --prefix {{packageDir}} test` builds, typechecks and runs them.2. Fix the root cause with the smallest change that is honest and complete.Keep `public-api-schema.ts`, `help()` JSDoc and `skill-body/SKILL.md` insync if the public surface or its documentation changes.-3. Run `cd {{packageDir}} && npm test` until it passes. Format changed files+3. Run `npm --prefix {{packageDir}} test` until it passes. Stay at the worktree root: `cd` is not permitted, so use paths and `npm --prefix` from here. Format changed fileswith `{{packageDir}}/node_modules/.bin/prettier --write <files>`.4. Commit everything on this branch. Use one or a few focused commits. Thesubject follows the repository style, for examplediff --git a/tools/linear-autofix/src/prompts/review-fix.md b/tools/linear-autofix/src/prompts/review-fix.mdindex 06d5c45..fc8cc9b 100644--- a/tools/linear-autofix/src/prompts/review-fix.md+++ b/tools/linear-autofix/src/prompts/review-fix.md@@ -12,7 +12,7 @@ Do not modify `AGENTS.md`, `CLAUDE.md`, `lefthook.yml` or anything under1. For each finding, either fix it or decide, with a concrete reason, that itis not a defect. Prefer fixing. A reviewer asking for a test gets a test.-2. Run `cd {{packageDir}} && npm test` until it passes. Format changed files+2. Run `npm --prefix {{packageDir}} test` until it passes. Stay at the worktree root: `cd` is not permitted, so use paths and `npm --prefix` from here. Format changed fileswith `{{packageDir}}/node_modules/.bin/prettier --write <files>`.3. Commit on this branch with the repository's commit style and the trailer`Co-Authored-By: Claude Fable 5.1 <[email protected]>`. Do **not** push.