-
-
Notifications
You must be signed in to change notification settings - Fork 2
Fix Optimize Earth root row showing zero delay metrics #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #!/usr/bin/env node | ||
| // block-codex-rescue-agent.mjs | ||
| // | ||
| // PreToolUse hook on the Agent tool: blocks dispatches with | ||
| // `subagent_type: "codex:codex-rescue"`. The wrapper is strictly | ||
| // worse than direct `codex exec` via Bash and the protocol already | ||
| // says so — see .claude/codex-delegation.md line 7 + line 105 ("Why | ||
| // CLI not Agent tool"). I keep using it anyway despite the doc rule. | ||
| // | ||
| // 2026-05-14: written after I used the wrapper twice in one session | ||
| // (anonymized-preview, ICEWAD rename). Both showed exactly the | ||
| // failure mode line 113 names verbatim — wrapper returns "will | ||
| // report when done" while underlying work has already finished or | ||
| // fizzled. Per feedback_promote_violated_text_rules_to_hooks.md: | ||
| // passive text loses to active enforcement. | ||
|
|
||
| import { readFileSync } from "node:fs"; | ||
|
|
||
| try { | ||
| let hookData = null; | ||
| try { | ||
| const raw = readFileSync(0, "utf-8"); | ||
| if (raw && raw.trim()) hookData = JSON.parse(raw); | ||
| } catch { | ||
| process.exit(0); | ||
| } | ||
| if (!hookData) process.exit(0); | ||
|
|
||
| if (hookData.tool_name !== "Agent") process.exit(0); | ||
|
|
||
| const subagent = hookData?.tool_input?.subagent_type ?? ""; | ||
| if (subagent !== "codex:codex-rescue") process.exit(0); | ||
|
|
||
| const msg = `[block-codex-rescue-agent] BLOCKED — Agent(subagent_type: "codex:codex-rescue"). | ||
|
|
||
| The Agent wrapper is strictly worse than direct \`codex exec\` via Bash | ||
| for Codex dispatches. See \`.claude/codex-delegation.md\` line 105+ | ||
| ("Why CLI not Agent tool"). Common failure mode (line 113): | ||
|
|
||
| Wrapper returns "Codex is running in the background, will report | ||
| when done" narration AFTER the work has already finished — looks | ||
| like it's still running when it's already done (or fizzled). | ||
|
|
||
| Use this shape instead: | ||
|
|
||
| Bash( | ||
| command: "codex exec --skip-git-repo-check '<prompt>'", | ||
| run_in_background: true | ||
| ) | ||
|
|
||
| For substantial / multi-turn tasks where you want steer/interrupt, | ||
| the upgrade path is \`codex app-server\` (JSON-RPC) — see the | ||
| "App-server upgrade path" section in codex-delegation.md. | ||
|
|
||
| If you HAVE a specific reason to use the wrapper (need Claude-side | ||
| review between dispatch and result), say so in chat first. There is | ||
| no 5-minute bypass on this hook — every dispatch decision should be | ||
| deliberate.`; | ||
|
|
||
| process.stderr.write(msg + "\n"); | ||
| process.exit(2); | ||
| } catch { | ||
| process.exit(0); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| #!/usr/bin/env node | ||
| // block-snapshot-handedit.mjs | ||
| // | ||
| // PreToolUse hook: blocks `Write` / `Edit` of generated `.md` snapshots. | ||
| // They are produced by `pnpm copy:preview` (smart by default — auto- | ||
| // detects affected routes) and `pnpm email:preview-md`. Hand-editing | ||
| // drifts from the rendered source; the right move is to fix the | ||
| // underlying page/email and re-run the script. | ||
| // | ||
| // Match paths: | ||
| // packages/web/src/app/**/page.logged-out.md | ||
| // packages/web/src/app/**/page.logged-in.md | ||
| // packages/web/**/*.email.md | ||
| // | ||
| // 2026-05-14: written after I hand-edited HVG snapshots three times in | ||
| // one session before the user pushed back. Per | ||
| // `feedback_promote_violated_text_rules_to_hooks.md`: rules in | ||
| // CLAUDE.md lose to active enforcement. | ||
|
|
||
| import { readFileSync } from "node:fs"; | ||
|
|
||
| try { | ||
| let hookData = null; | ||
| try { | ||
| const raw = readFileSync(0, "utf-8"); | ||
| if (raw && raw.trim()) hookData = JSON.parse(raw); | ||
| } catch { | ||
| process.exit(0); | ||
| } | ||
| if (!hookData) process.exit(0); | ||
|
|
||
| const tool = hookData.tool_name; | ||
| if (tool !== "Write" && tool !== "Edit") process.exit(0); | ||
|
|
||
| const filePath = hookData?.tool_input?.file_path; | ||
| if (!filePath) process.exit(0); | ||
|
|
||
| const normalized = filePath.replace(/\\/g, "/"); | ||
|
|
||
| const isSnapshot = | ||
| /\/packages\/web\/src\/app\/.+\/page\.logged-(out|in)\.md$/.test(normalized) || | ||
| /\/packages\/web\/.+\.email\.md$/.test(normalized); | ||
|
|
||
| if (!isSnapshot) process.exit(0); | ||
|
|
||
| const relPath = normalized.replace(/.*\/(packages\/.+)$/, "$1"); | ||
|
|
||
| const msg = `[block-snapshot-handedit] BLOCKED — about to hand-edit a generated snapshot: | ||
| ${relPath} | ||
|
|
||
| These files are output, not source. They're regenerated by: | ||
| pnpm --filter @optimitron/web copy:preview (smart, only affected routes) | ||
| pnpm --filter @optimitron/web email:preview-md (for *.email.md) | ||
|
|
||
| If the rendered output is wrong, fix the underlying page.tsx / email | ||
| module / template and re-run the script. Hand-editing drifts from | ||
| source and CI will flag the snapshot diff at PR time. | ||
|
|
||
| If you're SURE this is a one-off (e.g., a known-broken script you're | ||
| fixing in the same commit), bypass by acknowledging in chat: | ||
| "Hand-editing <filename> intentionally because <reason>." and the | ||
| hook allows a retry within 5 minutes. | ||
|
|
||
| Rule source: CLAUDE.md "Never hand-edit page.logged-out.md / *.email.md | ||
| snapshots" + memory feedback_promote_violated_text_rules_to_hooks.md`; | ||
|
|
||
| process.stderr.write(msg + "\n"); | ||
| process.exit(2); | ||
| } catch { | ||
| process.exit(0); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| #!/usr/bin/env node | ||
| // dev-server-check.mjs | ||
| // | ||
| // SessionStart hook: probes http://127.0.0.1:3001 and prints one of: | ||
| // DEV SERVER: 200 OK | ||
| // DEV SERVER: DOWN — run `pnpm --filter @optimitron/web dev:fast ...` | ||
| // DEV SERVER: PORT BOUND but UNRESPONSIVE — kill PID then restart | ||
| // | ||
| // Per CLAUDE.md HVD#2: Claude pre-warms the dev server at session | ||
| // start if curl doesn't return 2xx/3xx. I keep forgetting to run the | ||
| // curl, so I never reach the conditional. This hook runs the check | ||
| // FOR me + prints loud status + the exact command to restart. | ||
| // | ||
| // Does NOT auto-start — too many edge cases (intentional teardown, | ||
| // different port, sibling repo bound to 3001). Loud warn + concrete | ||
| // command is sufficient if I actually read the output. | ||
| // | ||
| // 2026-05-14: written after I dispatched Codex agents claiming "Dev | ||
| // server is running at :3001" while a 17-hour zombie PID was bound | ||
| // but unresponsive. Per | ||
| // feedback_promote_violated_text_rules_to_hooks.md. | ||
|
|
||
| import { execSync } from "node:child_process"; | ||
|
|
||
| const PORT = 3001; | ||
| const URL = `http://127.0.0.1:${PORT}`; | ||
| const START_CMD = | ||
| "pnpm --filter @optimitron/web dev:fast > packages/web/.dev-server.log 2>&1"; | ||
|
|
||
| try { | ||
| let status = null; | ||
| try { | ||
| const devNull = process.platform === "win32" ? "NUL" : "/dev/null"; | ||
| const out = execSync( | ||
| `curl -sS -m 3 -o ${devNull} -w "%{http_code}" ${URL}`, | ||
| { stdio: ["ignore", "pipe", "ignore"], encoding: "utf-8" }, | ||
| ).trim(); | ||
| status = parseInt(out, 10); | ||
| } catch { | ||
| status = 0; | ||
| } | ||
|
|
||
| if (status >= 200 && status < 400) { | ||
| process.stdout.write(`[dev-server-check] DEV SERVER: ${status} OK on ${URL}\n`); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| // Down or unresponsive. Check if port is bound to a zombie PID. | ||
| let zombiePid = null; | ||
| try { | ||
| const netstat = execSync( | ||
| `powershell -NoProfile -Command "(Get-NetTCPConnection -LocalPort ${PORT} -State Listen -ErrorAction SilentlyContinue | Select-Object -First 1).OwningProcess"`, | ||
| { stdio: ["ignore", "pipe", "ignore"], encoding: "utf-8" }, | ||
| ).trim(); | ||
| if (netstat && /^\d+$/.test(netstat)) zombiePid = netstat; | ||
| } catch { | ||
| // ignore; Windows-specific | ||
| } | ||
|
|
||
| if (zombiePid) { | ||
| process.stdout.write( | ||
| `[dev-server-check] DEV SERVER: PORT ${PORT} BOUND by PID ${zombiePid} but UNRESPONSIVE (zombie).\n` + | ||
| ` Kill + restart:\n` + | ||
| ` powershell -NoProfile -Command "Stop-Process -Id ${zombiePid} -Force"\n` + | ||
| ` ${START_CMD}\n`, | ||
| ); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| process.stdout.write( | ||
| `[dev-server-check] DEV SERVER: DOWN on ${URL}.\n` + | ||
| ` Start it now (orchestrator-only — per CLAUDE.md HVD#2):\n` + | ||
| ` ${START_CMD}\n` + | ||
| ` Codex dispatches will fail or run blind without it.\n`, | ||
| ); | ||
| process.exit(0); | ||
| } catch { | ||
| process.exit(0); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.