Skip to content

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.

feat(tools): post a per-tick execution log to a Linear ticket and document the Mac mini deployment

Zhuowei Wang3de804fee645
diff --git a/tools/linear-autofix/README.md b/tools/linear-autofix/README.md
index f8a02c7..65d6796 100644
--- a/tools/linear-autofix/README.md
+++ b/tools/linear-autofix/README.md
@@ -42,64 +42,123 @@ bot on it; it also writes `agent:fix`, `agent:skipped` and `agent:escalated`.
## What Claude may and may not do
-| Stage | Working dir | Allowed tools |
-| ---------- | ----------- | ---------------------------------------------------------------------------------- |
-| triage | repo root | Read, Grep, Glob, `git log/show/grep` |
-| implement | worktree | Read, Edit, Write, Grep, Glob, `npm`, `npx`, `node`, `git add/commit/diff/status…` |
-| review-fix | worktree | same as implement |
+| Stage | Working dir | Allowed tools |
+| ---------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| triage | repo root | Read, Grep, Glob, `git log/show/grep` |
+| implement | worktree | Read, Edit, Write, Grep, Glob, `npm --prefix package/ego-browser …`, `npm --prefix plugins/ego …`, prettier, `git add/commit/diff/status/log/show/grep/restore/rm/mv` |
+| review-fix | worktree | same as implement |
Runs use `--permission-mode dontAsk`, so anything outside the list is denied:
-Claude cannot push, cannot call `gh`, cannot touch Linear. MCP servers are
-disabled (`--strict-mcp-config`). Each run has a dollar budget and a wall-clock
-timeout (see Configuration). Prompts tell Claude that ticket text and review
-comments are data, never instructions, and `.github/`, `AGENTS.md`,
-`lefthook.yml` are off limits.
+Claude cannot push, cannot call `gh`, cannot touch Linear, and cannot `cd` out
+of the worktree (there is no `cd`, `node` or `npx` rule). MCP servers are
+disabled (`--strict-mcp-config`). The allowlist keeps the model on rails; it is
+not a sandbox against a hostile model, since Edit plus `npm run` can execute
+arbitrary code. Containment comes from running on a dedicated host whose
+credentials (GitHub, Linear, Claude) are the only ones the bot needs. Each run
+has a dollar budget and a wall-clock timeout, and a timeout kills the whole
+process tree. Prompts tell Claude that ticket text and review comments are
+data, never instructions, and `.github/`, `AGENTS.md`, `lefthook.yml` are off
+limits.
+
+## Deploying on the Mac mini
+
+Prerequisites on the host:
+
+- macOS with a logged-in GUI session that stays up: enable automatic login,
+ disable the screen saver and screen lock, and keep the machine awake
+ (`sudo pmset -a sleep 0 displaysleep 0`). The pre-push E2E drives ego lite
+ windows, and background or locked windows break it.
+- ego lite installed at `/Applications/ego lite.app` and running. The E2E
+ runner uses the CLI bundled inside the app. Nobody takes manual control of
+ it while ticks run.
+- Node 22+ (fnm or nvm, loaded from the login shell), `git`, `gh`, `claude`.
+- `gh auth login` as the GitHub account that owns the PRs, with push access.
+ Use a personal account: the Codex review workflow skips PRs opened by bot
+ users.
+- `claude` logged in once interactively on that machine.
+- A Linear personal API key for the user whose assigned tickets should be
+ processed (Linear → Settings → Security & access → Personal API keys). The
+ bot's Linear comments and labels are written as that user.
+
+Install:
-## Requirements on the host (the Mac mini)
+```sh
+git clone [email protected]:citrolabs/ego-lite.git ~/code/ego-lite
+cd ~/code/ego-lite && git switch dev
+(cd package/ego-browser && npm install) # also installs the lefthook hooks
+(cd tools/linear-autofix && npm test)
-- Node 22+, `git`, `gh` logged in as the GitHub account that owns the PRs,
- `claude` logged in.
-- ego lite installed and running, with nobody taking manual control of it: the
- pre-push hook runs the real-browser E2E suite for every bot push.
-- A clone of `ego-lite` with hooks installed (`cd package/ego-browser && npm install`).
-- A Linear personal API key (Settings → API) in `LINEAR_API_KEY`.
+mkdir -p ~/.config/linear-autofix
+cat > ~/.config/linear-autofix/env <<'ENV'
+export LINEAR_API_KEY=lin_api_…
+# export AUTOFIX_LOG_ISSUE=CITRO-4786 # where tick logs are posted (default)
+# export AUTOFIX_MAX_IMPLEMENTING=2
+ENV
+chmod 600 ~/.config/linear-autofix/env
+```
-## Running
+First run, by hand, before scheduling anything:
```sh
-cd tools/linear-autofix
-export LINEAR_API_KEY=lin_api_…
+cd ~/code/ego-lite/tools/linear-autofix && source ~/.config/linear-autofix/env
+AUTOFIX_DRY_RUN=1 node src/cli.mjs tick # triages everything, writes nothing
+node src/cli.mjs status
+AUTOFIX_ISSUE=CITRO-2908 node src/cli.mjs tick # one real ticket end to end
+```
-AUTOFIX_DRY_RUN=1 node src/cli.mjs tick # read + run Claude, write nothing, push nothing
-AUTOFIX_DRY_RUN=1 node src/cli.mjs triage CITRO-2908
+Watch that PR through a full review loop (`node src/cli.mjs status`, the tick
+log comments on the log ticket), then schedule:
+
+```sh
+cp launchd/com.citrolabs.linear-autofix.plist ~/Library/LaunchAgents/
+launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.citrolabs.linear-autofix.plist
+launchctl kickstart -k gui/$(id -u)/com.citrolabs.linear-autofix # run now
+```
+
+The agent runs `node src/cli.mjs tick` every 30 minutes from a login shell, so
+fnm/nvm, `gh` and `claude` resolve as they do in a terminal. A pass still
+running when the next one fires makes the newcomer exit (`tick.lock`). Local
+logs go to `/tmp/linear-autofix.log`.
+
+Operations:
+
+```sh
node src/cli.mjs status
-node src/cli.mjs tick # the real thing
-node src/cli.mjs stop # kill switch (STOP file); `resume` removes it
-node src/cli.mjs retry CITRO-2908 # reset a skipped/escalated ticket to new
-npm test
+node src/cli.mjs stop # STOP file: running tick finishes its step, later ticks exit
+node src/cli.mjs resume
+node src/cli.mjs retry CITRO-2908
+launchctl bootout gui/$(id -u)/com.citrolabs.linear-autofix # uninstall the schedule
```
-Schedule it with the launchd agent in `launchd/` (edit the path and the key,
-then `launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.citrolabs.linear-autofix.plist`).
-Logs go to `/tmp/linear-autofix.log`.
+Updating the bot: `git pull` on `dev`; the next tick picks up the new code.
+State in `~/.local/state/linear-autofix` survives updates.
+
+## Execution log on Linear
+
+Every tick that did something (a triage, a PR, a review round, an escalation,
+an error) posts one summary comment to the log ticket named by
+`AUTOFIX_LOG_ISSUE` (default `CITRO-4786`): host, duration, Claude cost, and
+one line per event. Ticks where every PR was merely waiting post nothing, so
+the ticket stays readable. Set `AUTOFIX_LOG_ISSUE=` (empty) to disable.
## Configuration
-| Variable | Default | Meaning |
-| --------------------------- | ----------------------------------------- | ----------------------------------------- |
-| `LINEAR_API_KEY` | — | required |
-| `AUTOFIX_REPO` | this checkout | repository the worktrees are created from |
-| `AUTOFIX_STATE_DIR` | `~/.local/state/linear-autofix` | records, runs, worktrees, lock, STOP |
-| `AUTOFIX_LINEAR_STATES` | `Backlog,Todo,In Progress,Pending Review` | states polled |
-| `AUTOFIX_BASE_BRANCH` | `dev` | PR base and worktree base |
-| `AUTOFIX_MAX_IMPLEMENTING` | `2` | bot PRs allowed in review at once |
-| `AUTOFIX_MAX_REVIEW_ROUNDS` | `5` | fix rounds per PR before escalating |
-| `AUTOFIX_*_BUDGET_USD` | triage 2 / implement 25 / review 15 | `--max-budget-usd` per Claude run |
-| `AUTOFIX_*_TIMEOUT_MS` | triage 10 min / implement 90 / review 60 | wall-clock limit per Claude run |
-| `AUTOFIX_PUSH_TIMEOUT_MS` | 45 min | covers the pre-push E2E suite |
-| `AUTOFIX_CLAUDE_MODEL` | Claude Code default | `--model` |
-| `AUTOFIX_DRY_RUN` | unset | `1`: no Linear/GitHub writes, no push |
-| `AUTOFIX_ISSUE` | unset | restrict a tick to one identifier |
+| Variable | Default | Meaning |
+| --------------------------- | ----------------------------------------- | ------------------------------------------------------- |
+| `LINEAR_API_KEY` | — | required |
+| `AUTOFIX_REPO` | this checkout | repository the worktrees are created from |
+| `AUTOFIX_STATE_DIR` | `~/.local/state/linear-autofix` | records, runs, worktrees, lock, STOP |
+| `AUTOFIX_LINEAR_STATES` | `Backlog,Todo,In Progress,Pending Review` | states polled |
+| `AUTOFIX_BASE_BRANCH` | `dev` | PR base and worktree base |
+| `AUTOFIX_MAX_IMPLEMENTING` | `2` | bot PRs allowed in review at once |
+| `AUTOFIX_MAX_REVIEW_ROUNDS` | `5` | fix rounds per PR before escalating |
+| `AUTOFIX_*_BUDGET_USD` | triage 2 / implement 25 / review 15 | `--max-budget-usd` per Claude run |
+| `AUTOFIX_*_TIMEOUT_MS` | triage 10 min / implement 90 / review 60 | wall-clock limit per Claude run |
+| `AUTOFIX_PUSH_TIMEOUT_MS` | 45 min | covers the pre-push E2E suite |
+| `AUTOFIX_CLAUDE_MODEL` | Claude Code default | `--model` |
+| `AUTOFIX_LOG_ISSUE` | `CITRO-4786` | Linear ticket that receives one comment per active tick |
+| `AUTOFIX_DRY_RUN` | unset | `1`: no Linear/GitHub writes, no push |
+| `AUTOFIX_ISSUE` | unset | restrict a tick to one identifier |
## Review-loop termination
diff --git a/tools/linear-autofix/launchd/com.citrolabs.linear-autofix.plist b/tools/linear-autofix/launchd/com.citrolabs.linear-autofix.plist
index 7a69af5..8a79f8c 100644
--- a/tools/linear-autofix/launchd/com.citrolabs.linear-autofix.plist
+++ b/tools/linear-autofix/launchd/com.citrolabs.linear-autofix.plist
@@ -6,7 +6,8 @@
Runs one scheduler pass every 30 minutes. A pass that is still running
when the next one fires makes the newcomer exit at once (tick.lock).
- Install (edit the paths and the API key first):
+ Secrets live in ~/.config/linear-autofix/env (chmod 600), not here.
+ Install (edit the repository path first if it differs):
cp tools/linear-autofix/launchd/com.citrolabs.linear-autofix.plist ~/Library/LaunchAgents/
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.citrolabs.linear-autofix.plist
Stop:
@@ -19,18 +20,9 @@
<array>
<string>/bin/zsh</string>
<string>-lc</string>
- <string>cd ~/code/ego-lite/tools/linear-autofix && exec node src/cli.mjs tick</string>
+ <string>source ~/.config/linear-autofix/env &amp;&amp; cd ~/code/ego-lite/tools/linear-autofix &amp;&amp; exec node src/cli.mjs tick</string>
</array>
- <key>EnvironmentVariables</key>
- <dict>
- <key>LINEAR_API_KEY</key>
- <string>lin_api_REPLACE_ME</string>
- <!-- Optional overrides; see README. -->
- <key>AUTOFIX_MAX_IMPLEMENTING</key>
- <string>2</string>
- </dict>
-
<key>StartInterval</key>
<integer>1800</integer>
diff --git a/tools/linear-autofix/src/claude.mjs b/tools/linear-autofix/src/claude.mjs
index c2319d2..a849f54 100644
--- a/tools/linear-autofix/src/claude.mjs
+++ b/tools/linear-autofix/src/claude.mjs
@@ -11,6 +11,12 @@ import { run, tail } from "./proc.mjs";
* Permission model: `dontAsk` denies every tool call outside `allowedTools`,
* which is how the orchestrator keeps `git push` and `gh` in its own hands.
*/
+let processCostUsd = 0;
+/** Total `claude -p` cost of this process so far. */
+export function claudeCostUsd() {
+ return processCostUsd;
+}
+
export async function runClaude({
prompt,
cwd,
@@ -78,6 +84,8 @@ export async function runClaude({
: JSON.stringify(parsed.result ?? "");
let structured = parsed.structured_output ?? null;
if (schema && !structured) structured = parseJsonBlock(text);
+ if (typeof parsed.total_cost_usd === "number")
+ processCostUsd += parsed.total_cost_usd;
return {
text,
structured,
diff --git a/tools/linear-autofix/src/cli.mjs b/tools/linear-autofix/src/cli.mjs
index 293a61d..e0d215c 100755
--- a/tools/linear-autofix/src/cli.mjs
+++ b/tools/linear-autofix/src/cli.mjs
@@ -13,6 +13,7 @@ import { reconcile, tick } from "./tick.mjs";
import { triage } from "./triage.mjs";
import { implement } from "./implement.mjs";
import { review } from "./review.mjs";
+import { flushTickLog } from "./journal.mjs";
const USAGE = `linear-autofix — Linear ticket → PR → review loop, unattended
@@ -25,10 +26,27 @@ Usage:
linear-autofix status list tracked tickets and their stage
linear-autofix stop | resume create / remove the STOP file (kill switch)
-Environment: LINEAR_API_KEY (required), AUTOFIX_DRY_RUN=1, AUTOFIX_ISSUE=<ID>,
+Environment: LINEAR_API_KEY (required), AUTOFIX_DRY_RUN=1, AUTOFIX_ISSUE=<ID>, AUTOFIX_LOG_ISSUE,
AUTOFIX_STATE_DIR, AUTOFIX_MAX_IMPLEMENTING, AUTOFIX_MAX_REVIEW_ROUNDS, … see README.
`;
+/** Run a single-ticket stage and post its events to the log ticket. */
+async function logged(label, fn) {
+ const startedAt = Date.now();
+ try {
+ await fn();
+ } catch (err) {
+ await flushTickLog({
+ label,
+ startedAt,
+ issueCount: 1,
+ error: err?.message ?? String(err),
+ });
+ throw err;
+ }
+ await flushTickLog({ label, startedAt, issueCount: 1 });
+}
+
async function one(identifier) {
if (!identifier) throw new Error("issue identifier required");
const issue = await linear.fetchIssue(identifier);
diff --git a/tools/linear-autofix/src/config.mjs b/tools/linear-autofix/src/config.mjs
index 4384901..5bd1bd8 100644
--- a/tools/linear-autofix/src/config.mjs
+++ b/tools/linear-autofix/src/config.mjs
@@ -38,6 +38,10 @@ export const config = Object.freeze({
linearStatePendingReview:
process.env.AUTOFIX_LINEAR_STATE_PENDING_REVIEW ?? "Pending Review",
+ // Linear ticket that receives one summary comment per tick that did
+ // something. Empty disables it.
+ logIssue: process.env.AUTOFIX_LOG_ISSUE ?? "CITRO-4786",
+
remote: process.env.AUTOFIX_REMOTE ?? "origin",
baseBranch: process.env.AUTOFIX_BASE_BRANCH ?? "dev",
packageDir: "package/ego-browser",
diff --git a/tools/linear-autofix/src/journal.mjs b/tools/linear-autofix/src/journal.mjs
new file mode 100644
index 0000000..ce560cc
--- /dev/null
+++ b/tools/linear-autofix/src/journal.mjs
@@ -0,0 +1,86 @@
+import os from "node:os";
+import { config } from "./config.mjs";
+import { claudeCostUsd } from "./claude.mjs";
+import * as linear from "./linear.mjs";
+import { clearJournal, journalEvents, truncate } from "./state.mjs";
+
+/** Events that only say "nothing to do yet"; a tick made of these posts no log. */
+export function isQuiet(event) {
+ return (
+ event.event === "waiting" ||
+ (event.event.startsWith("review check") && /-> wait$/.test(event.detail))
+ );
+}
+
+/**
+ * Render one tick's events as a Linear comment. Pure. Returns null when the
+ * tick was quiet (every event was a wait) and there were no errors.
+ */
+export function renderTickLog({
+ label,
+ events,
+ startedAt,
+ finishedAt,
+ costUsd,
+ issueCount,
+ error,
+ host = os.hostname(),
+}) {
+ const active = events.filter((e) => !isQuiet(e));
+ if (!active.length && !error) return null;
+ const seconds = Math.round((finishedAt - startedAt) / 1000);
+ const duration =
+ seconds >= 60
+ ? `${Math.floor(seconds / 60)}m${String(seconds % 60).padStart(2, "0")}s`
+ : `${seconds}s`;
+ const head = [
+ `**${label}** · ${new Date(startedAt).toISOString().replace("T", " ").slice(0, 16)} UTC · ${host}`,
+ `${issueCount ?? "?"} ticket(s) scanned · ${duration} · Claude $${costUsd.toFixed(2)}${config.dryRun ? " · dry-run" : ""}`,
+ ];
+ const byIssue = new Map();
+ for (const e of active) {
+ if (!byIssue.has(e.identifier)) byIssue.set(e.identifier, []);
+ byIssue.get(e.identifier).push(e);
+ }
+ const body = [];
+ for (const [identifier, list] of byIssue) {
+ body.push(`- **${identifier}**`);
+ for (const e of list)
+ body.push(
+ ` - ${e.event}${e.detail ? `: ${truncate(e.detail, 300)}` : ""}`,
+ );
+ }
+ if (error) body.push(``, `**Tick failed:** \`${truncate(error, 500)}\``);
+ const quiet = events.length - active.length;
+ if (quiet) body.push(``, `_${quiet} wait event(s) omitted._`);
+ return [...head, ``, ...body].join("\n");
+}
+
+/** Post the journal of this process to the log ticket, then clear it. Never throws. */
+export async function flushTickLog({ label, startedAt, issueCount, error }) {
+ const events = journalEvents();
+ clearJournal();
+ if (!config.logIssue) return;
+ const text = renderTickLog({
+ label,
+ events,
+ startedAt,
+ finishedAt: Date.now(),
+ costUsd: claudeCostUsd(),
+ issueCount,
+ error,
+ });
+ if (!text) return;
+ try {
+ const issue = await linear.fetchIssue(config.logIssue);
+ if (!issue) throw new Error(`log issue ${config.logIssue} not found`);
+ await linear.comment(
+ { id: issue.id, identifier: issue.identifier, teamId: issue.team?.id },
+ text,
+ );
+ } catch (err) {
+ console.error(
+ `could not post the tick log to ${config.logIssue}: ${err.message}`,
+ );
+ }
+}
diff --git a/tools/linear-autofix/src/journal.test.mjs b/tools/linear-autofix/src/journal.test.mjs
new file mode 100644
index 0000000..97b2e24
--- /dev/null
+++ b/tools/linear-autofix/src/journal.test.mjs
@@ -0,0 +1,66 @@
+import assert from "node:assert/strict";
+import { test } from "node:test";
+import { isQuiet, renderTickLog } from "./journal.mjs";
+
+const t0 = Date.parse("2026-11-02T04:00:00Z");
+const base = {
+ label: "tick",
+ startedAt: t0,
+ finishedAt: t0 + 95_000,
+ costUsd: 3.2,
+ issueCount: 35,
+ host: "mac-mini",
+};
+
+test("a tick made only of waits posts nothing", () => {
+ const events = [
+ {
+ identifier: "CITRO-1",
+ event: "review check 28f5f732",
+ detail: "ci=pending codex=none threads=0 -> wait",
+ },
+ {
+ identifier: "CITRO-2",
+ event: "waiting",
+ detail: "2 PR(s) already in review (limit 2)",
+ },
+ ];
+ assert.ok(events.every(isQuiet));
+ assert.equal(renderTickLog({ ...base, events }), null);
+});
+
+test("an active tick lists events per ticket with header, duration and cost", () => {
+ const events = [
+ {
+ identifier: "CITRO-1",
+ event: "review check 28f5f732",
+ detail: "ci=success codex=clean threads=0 -> done",
+ },
+ {
+ identifier: "CITRO-1",
+ event: "stage in_review -> done",
+ detail: "Codex clean, CI green, no open threads",
+ },
+ { identifier: "CITRO-2", event: "waiting", detail: "limit" },
+ {
+ identifier: "CITRO-3",
+ event: "triaged",
+ detail: "needs_info (0.70) screenshot only",
+ },
+ ];
+ const text = renderTickLog({ ...base, events });
+ assert.match(text, /^\*\*tick\*\* · 2026-11-02 04:00 UTC · mac-mini/);
+ assert.match(text, /35 ticket\(s\) scanned · 1m35s · Claude \$3\.20/);
+ assert.match(
+ text,
+ /- \*\*CITRO-1\*\*\n {2}- review check 28f5f732: .*-> done\n {2}- stage in_review -> done/,
+ );
+ assert.match(text, /- \*\*CITRO-3\*\*\n {2}- triaged: needs_info/);
+ assert.doesNotMatch(text, /CITRO-2/);
+ assert.match(text, /1 wait event\(s\) omitted/);
+});
+
+test("a failed tick is logged even without events", () => {
+ const text = renderTickLog({ ...base, events: [], error: "Linear HTTP 500" });
+ assert.match(text, /Tick failed:.*Linear HTTP 500/);
+});
diff --git a/tools/linear-autofix/src/state.mjs b/tools/linear-autofix/src/state.mjs
index 2a58ac2..8197a33 100644
--- a/tools/linear-autofix/src/state.mjs
+++ b/tools/linear-autofix/src/state.mjs
@@ -52,6 +52,17 @@ export function save(record) {
return record;
}
+/** Events of the current process, drained into the Linear execution log. */
+const journal = [];
+
+export function journalEvents() {
+ return journal.slice();
+}
+
+export function clearJournal() {
+ journal.length = 0;
+}
+
/** Append a history event and persist. */
export function note(record, event, detail) {
record.history ??= [];
@@ -62,6 +73,11 @@ export function note(record, event, detail) {
});
if (record.history.length > 200)
record.history.splice(0, record.history.length - 200);
+ journal.push({
+ identifier: record.identifier,
+ event,
+ detail: detail ? String(detail) : "",
+ });
console.log(
`[${record.identifier}] ${event}${detail ? `: ${truncate(detail)}` : ""}`,
);
diff --git a/tools/linear-autofix/src/tick.mjs b/tools/linear-autofix/src/tick.mjs
index cec3642..b68006c 100644
--- a/tools/linear-autofix/src/tick.mjs
+++ b/tools/linear-autofix/src/tick.mjs
@@ -14,6 +14,7 @@ import { triage } from "./triage.mjs";
import { implement } from "./implement.mjs";
import { review } from "./review.mjs";
import { clearErrors, recordError } from "./actions.mjs";
+import { flushTickLog } from "./journal.mjs";
/** Linear priority: 0 = none, 1 = urgent … 4 = low. Sort none last. */
export function byPriority(a, b) {
@@ -67,6 +68,9 @@ export async function tick() {
console.log("another tick is running; exiting");
return;
}
+ const startedAt = Date.now();
+ let issueCount;
+ let failure;
try {
if (stopRequested()) {
console.log(`STOP file present in ${config.stateDir}; exiting`);
@@ -137,7 +141,16 @@ export async function tick() {
}
await guarded(record, () => implement(issue, record));
}
+ } catch (err) {
+ failure = err?.message ?? String(err);
+ throw err;
} finally {
+ await flushTickLog({
+ label: "tick",
+ startedAt,
+ issueCount,
+ error: failure,
+ });
releaseLock();
}
}