Last active
October 27, 2025 17:24
-
-
Save toml0006/eb18814a8c7c065a007fac28c9c16efa to your computer and use it in GitHub Desktop.
Makefile from navigator repository
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
| # portable Makefile (GNU make 3.81 friendly; no .RECIPEPREFIX, no here-docs) | |
| # | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # Quick Reference | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # | |
| # make setup — writes: | |
| # • .mcp.json (Claude↔Codex MCP) | |
| # • .codex-guard.sh (prevents editing main) | |
| # • .git/hooks/pre-commit (blocks noisy paths) | |
| # | |
| # make setup-claude-agent — creates .claude/agents.json with the codex-bridge | |
| # agent preset | |
| # | |
| # make codex-branch — fresh codex/YYYYmmdd-HHMMSS branch | |
| # | |
| # make claude-codex — launches Claude Code CLI with the agent loaded | |
| # | |
| # make codex-review-exec — read-only Codex repo review → Markdown report | |
| # | |
| # make codex-apply PATCH=… — apply a unified diff and commit | |
| # | |
| # make codex-push — push current branch and print a PR hint | |
| # | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| SHELL := /usr/bin/env bash | |
| TS := $(shell date +%Y%m%d-%H%M%S) | |
| .DEFAULT_GOAL := help | |
| .PHONY: help | |
| help: ## Show targets | |
| @echo "Targets:" | |
| @grep -E '^[a-zA-Z0-9_-]+:.*?## ' Makefile | sed 's/:.*##/: /' | sort | |
| # ── Checks & Setup ──────────────────────────────────────────────────────────── | |
| .PHONY: check-deps | |
| check-deps: ## Ensure required CLIs exist (git, claude, codex) | |
| @for bin in git claude codex; do \ | |
| if ! command -v $$bin >/dev/null 2>&1; then \ | |
| echo "Missing dependency: $$bin"; exit 1; \ | |
| fi; \ | |
| done | |
| @echo "All deps OK." | |
| .PHONY: setup-codex-mcp | |
| setup-codex-mcp: ## Configure Codex MCP server in ~/.claude/settings.json | |
| @echo "Configuring Codex MCP server in ~/.claude/settings.json..." | |
| @node .codex-setup-mcp.js | |
| .PHONY: setup-guard | |
| setup-guard: ## Install .codex-guard.sh to block running on main | |
| @printf '%s\n' \ | |
| '#!/usr/bin/env bash' \ | |
| 'set -euo pipefail' \ | |
| 'branch="$$(git rev-parse --abbrev-ref HEAD)"' \ | |
| 'if [[ "$$branch" == "main" || "$$branch" == "master" ]]; then' \ | |
| ' echo "Refusing to proceed on $$branch (use a feature branch)."' \ | |
| ' exit 1' \ | |
| 'fi' > .codex-guard.sh | |
| @chmod +x .codex-guard.sh | |
| @echo "Installed .codex-guard.sh" | |
| .PHONY: setup-hooks | |
| setup-hooks: ## Install pre-commit guard to avoid committing build artifacts | |
| @mkdir -p .git/hooks | |
| @printf '%s\n' \ | |
| '#!/usr/bin/env bash' \ | |
| 'set -euo pipefail' \ | |
| "blocked_regex='^(dist/|build/|node_modules/|coverage/|.cache/|.*\\.lock$$|.*\\.min\\..*)'" \ | |
| 'if git diff --cached --name-only | grep -E "$$blocked_regex" >/dev/null; then' \ | |
| ' echo "Pre-commit: refusing to commit blocked files/paths."' \ | |
| ' echo "Adjust the regex in .git/hooks/pre-commit if needed."' \ | |
| ' exit 1' \ | |
| 'fi' > .git/hooks/pre-commit | |
| @chmod +x .git/hooks/pre-commit | |
| @echo "Installed .git/hooks/pre-commit" | |
| .PHONY: setup | |
| setup: check-deps setup-codex-mcp setup-guard setup-hooks ## One-shot setup | |
| @echo "" | |
| @echo "✓ Setup complete!" | |
| @echo "⚠️ If you configured Codex MCP for the first time, restart Claude Code for changes to take effect." | |
| # ── Branch Utilities ────────────────────────────────────────────────────────── | |
| .PHONY: codex-branch | |
| codex-branch: ## Create a fresh work branch: codex/YYYYmmdd-HHMMSS | |
| @git fetch --all --prune | |
| @git checkout main && git pull --ff-only | |
| @git checkout -b codex/$(TS) | |
| @echo "Created branch: codex/$(TS)" | |
| # ── Optional headless review (no writes) via `codex exec` ───────────────────── | |
| REPORT_DIR := reports | |
| REPORT_MD := $(REPORT_DIR)/codex-review-$(TS).md | |
| .PHONY: codex-review-exec | |
| codex-review-exec: check-deps ## Run a read-only repository review and save a report | |
| @mkdir -p "$(REPORT_DIR)" | |
| @echo "Running Codex headless review (no writes)..." | |
| @codex exec "Review this repository and produce a concise Markdown report grouped by severity (Sev-1/2/3) with exact file:line references and concrete fixes. Do not modify files." \ | |
| > "$(REPORT_MD)" | |
| @echo "Wrote $(REPORT_MD)" | |
| # ── Apply a patch that Codex (or Claude) proposed ───────────────────────────── | |
| # Usage: make codex-apply PATCH=path/to/patch.diff | |
| .PHONY: codex-apply | |
| codex-apply: ## Apply a unified diff and commit | |
| @:[ -n "$$PATCH" ] || { echo "Usage: make codex-apply PATCH=path/to/patch.diff"; exit 1; } | |
| @./.codex-guard.sh | |
| @echo "Applying $$PATCH ..." | |
| @git apply --index "$$PATCH" | |
| @git commit -m "codex: apply $$(basename "$$PATCH")" | |
| @echo "Applied and committed." | |
| # ── Convenience: push current codex branch ──────────────────────────────────── | |
| .PHONY: codex-push | |
| codex-push: ## Push current branch and print a PR hint | |
| @./.codex-guard.sh | |
| @branch="$$(git rev-parse --abbrev-ref HEAD)"; \ | |
| git push -u origin "$$branch"; \ | |
| echo "Pushed $$branch. Open a PR as usual." | |
| # ── Claude agent bootstrap ──────────────────────────────────────────────────── | |
| CLAUDE_DIR := .claude | |
| AGENTS_JSON := $(CLAUDE_DIR)/agents.json | |
| .PHONY: setup-claude-agent | |
| setup-claude-agent: ## Create .claude/agents.json (codex-bridge agent) | |
| @mkdir -p $(CLAUDE_DIR) | |
| @if [ -e $(AGENTS_JSON) ]; then \ | |
| echo "$(AGENTS_JSON) already exists; skipping."; \ | |
| else \ | |
| printf '%s\n' \ | |
| '{' \ | |
| ' "agents": {' \ | |
| ' "codex-bridge": {' \ | |
| ' "description": "Bridge to Codex via MCP. Follows plan → diff → apply → commit. Uses workspace-write only with explicit approval.",' \ | |
| ' "prompt": "You are a coding assistant working in a local git repo. Prefer the MCP server named \"codex\" for code review and edits. Default to read-only analysis. Always follow this loop: (1) Produce a SHORT plan; (2) Propose a unified diff with exact file:line refs; (3) WAIT for approval; (4) When explicitly approved to write, switch to workspace-write, apply changes, and then run: ./.codex-guard.sh && git add -A && git commit -m \"codex: <short purpose>\"; (5) Summarize changes. Never touch main/master directly. Ignore: dist/, build/, node_modules/, coverage/, .cache/, *.lock, *.min.*. Ask before running any shell commands. If a hunk fails to apply, generate the smallest follow-up patch for the conflicted files only.",' \ | |
| ' "defaults": {' \ | |
| ' "mcpPreferredServers": ["codex"],' \ | |
| ' "allowShell": true,' \ | |
| ' "temperature": 0.2' \ | |
| ' }' \ | |
| ' }' \ | |
| ' }' \ | |
| '}' > $(AGENTS_JSON); \ | |
| echo "Wrote $(AGENTS_JSON)"; \ | |
| fi | |
| .PHONY: claude-codex | |
| claude-codex: ## Launch Claude Code CLI with the codex-bridge agent preloaded | |
| @[ -f $(AGENTS_JSON) ] || { echo "Run: make setup-claude-agent"; exit 1; } | |
| @echo "Starting Claude with codex-bridge agent…" | |
| @claude --agents "$$(cat $(AGENTS_JSON))" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment