Init makefiles

From yigitkonur/skills-by-yigitkonur · View interactive version

Init makefiles is an AI agent skill from the GitHub repository yigitkonur/skills-by-yigitkonur. Use if scaffolding Makefile targets for dev, tunnels, deploys, R2, Supabase, Railway, Vercel.

How to use this skill

Skill file

init-makefiles

Make is the project's control plane. Generate one Makefile per app (root + up to 3 sub-Makefiles in monorepos), zero required arguments, scenario-appropriate targets only, with safe replacement of any prior scaffold.

This is the consolidated successor to the old make-local, make-railway, and make-vercel direction. Do not recreate provider-specific Makefile skills — classify the project's scenario here, then generate only the targets that scenario needs.

When to use this skill

Trigger on any of these:

Do NOT use this skill when:

Three principles (apply without exception)

  1. Scenarios beat providers. Don't ask "is this a Vercel project?" — ask "what is this project?" The provider stack (Vercel, Railway, Supabase) falls out of the scenario, never the other way around.
  2. Local = real dev builds, never toy builds. Next.js / Turborepo / monorepo projects use the actual dev pipeline. No shortcuts that diverge from production behavior.
  3. Exposure is opt-in. make local binds 127.0.0.1. make local-lan binds 0.0.0.0. make tunnel runs Tailscale Serve (tailnet-only). make funnel is PUBLIC and gated behind explicit PUBLIC_FUNNEL=1. Funnel never enables as a side effect of any other command.

Hard rules baked into every generated Makefile

Scenario classification

Pick exactly one scenario per deployable app. The seven:

| # | Scenario | Primary signal | What's in scope |

|---|---|---|---|

| A | Frontend-only | next.config.* / vite.config.* / etc.; no backend dir; no Supabase | Local, LAN, tunnel; Vercel deploy by default. Cloudflare Pages is opt-in only — switch to it when (and only when) the user explicitly says "Cloudflare", "Pages", "Wrangler", or names the Pages product. Disk signals alone (a stray wrangler.toml for R2/Workers) never flip the default. |

| B | MCP server | @modelcontextprotocol/sdk or mcp-use in deps | Local; no deploy; inspect target |

| C | Frontend + backend | A signals + apps/api (or similar) with Express/Hono/Fastify | Frontend + Vercel + Railway |

| D | Frontend + Supabase | A signals + @supabase/supabase-js + supabase/ dir | Frontend + Vercel + Supabase CLI ops |

| E | Multi-service Railway | Multiple service dirs / railway.toml files | Railway only; parallel deploy where safe |

| F | Build-artifact | Cargo / Go / Swift / native CLI; no HTTP framework, no remote target | Build + run locally; no deploy |

| G | MacBook ship | .xcodeproj / Package.swift Mac target + remote-Mac SSH alias | Build + ship via rsync + atomic swap + verify |

For single-app projects, the final classification has one tag. For monorepos, each deployable app gets one tag and the root gets a dominant orchestration tag. Use the supported combined tag C+D only when a custom backend deploys separately and Supabase is also in scope.

If detection is ambiguous → ask one targeted question, never guess. Sample disambiguation prompts in references/scenario-detection.md.

Workflow

1. Inspect (read-only)

Capture the project's state before writing anything:

# Package manager
ls bun.lockb pnpm-lock.yaml yarn.lock package-lock.json 2>/dev/null

# Framework signals (frontend)
ls next.config.* vite.config.* astro.config.* nuxt.config.* svelte.config.* remix.config.* 2>/dev/null

# Supabase
ls supabase/config.toml 2>/dev/null
jq -r '.dependencies | keys[]?' package.json 2>/dev/null | grep -i supabase

# Monorepo
ls turbo.json pnpm-workspace.yaml apps/ packages/ 2>/dev/null
jq -r '.workspaces' package.json 2>/dev/null

# Backend signals
find apps server services -maxdepth 2 -name "package.json" 2>/dev/null | head

# MCP server
jq -r '.dependencies | keys[]?' package.json 2>/dev/null | grep -E 'modelcontextprotocol|mcp-use'

# Mac signals
ls *.xcodeproj *.xcworkspace Package.swift Info.plist 2>/dev/null

# Existing Make scaffolding
ls Makefile *.mk scripts/dev.sh scripts/deploy.sh 2>/dev/null
find . -maxdepth 3 -name "Makefile" -not -path "./node_modules/*"

# AGENTS.md / CLAUDE.md state
ls -la AGENTS.md CLAUDE.md 2>/dev/null

Then run the bundled detector for a second, low-freedom signal pass. Resolve scripts/scenario-detect.sh relative to this skill directory and pass the downstream project root:

bash scripts/scenario-detect.sh /path/to/project

The detector is read-only and heuristic-only; it prints observed signals and candidate scenarios, not the final answer. Full detection cheat sheet in references/scenario-detection.md; detector implementation notes in scripts/scenario-detect.md.

If a precondition fails (no package.json, no dev script, no SSH alias for Mac scenario), surface it before generating. Do not generate something that breaks on first run.

2. Classify and announce

Before generating files, print this block:

Scenario: <A-G, or C+D for supported combined shape>
Scope: <repo root or per-app paths>
Confidence: <high|medium>
Signals: <observed files/deps/commands>
Excluded scenarios: <why the near misses were rejected>
Provider scope: <Vercel/Railway/Supabase/MacBook/local-only>
Makefiles to generate: <root + app paths, max 4>
Ambiguity resolved: <none or the answered question>

3. Preview and read existing scaffolding

Run the bundled wipe preview before touching files. Resolve scripts/preview-makefile-wipe.sh relative to this skill directory and pass the downstream project root:

bash scripts/preview-makefile-wipe.sh /path/to/project
bash scripts/preview-makefile-wipe.sh /path/to/project --paths-only > /tmp/init-makefiles-candidates.txt

The script is read-only. It prints exact paths, match reasons, tracked state, and uncommitted status; implementation notes live in scripts/preview-makefile-wipe.md.

For every candidate Makefile, *.mk, make-*.sh, scripts/dev.sh, and scripts/deploy.sh: read the file before classifying it as scaffold. Note useful patterns the user encoded (custom env handling, project-specific port choices, framework-specific dev commands) — those inform regenerated targets.

Write a deletion manifest containing only paths approved for replacement:

DELETION_MANIFEST=/tmp/init-makefiles-delete-manifest.txt
# write one approved path per line, exactly as printed by the preview

Refuse to continue if a candidate has uncommitted non-scaffold edits the agent cannot classify. If unrelated dirty files exist, leave them untouched and state that they were not snapshotted.

4. Snapshot and wipe from manifest

Create a targeted snapshot commit before deletion. Stage only manifest paths:

git status --porcelain
while IFS= read -r path; do
  [ -n "$path" ] || continue
  git add -- "$path"
done < "$DELETION_MANIFEST"
git commit -m "chore(make): snapshot existing scaffold before init-makefiles regen"

Never use git add -A for the snapshot. Never auto-commit unrelated work.

Print recovery before deleting:

SNAPSHOT_SHA=$(git rev-parse --short HEAD)
printf 'Recovery: git revert %s\n' "$SNAPSHOT_SHA"
printf 'Single file: git restore --source=%s -- path/to/Makefile\n' "$SNAPSHOT_SHA"

Delete only manifest paths:

while IFS= read -r path; do
  [ -n "$path" ] || continue
  rm -f -- "$path"
done < "$DELETION_MANIFEST"

5. Generate core Makefiles

Compose the new Makefile(s) from the scenario's references:

Always pull tunnel/funnel rules from references/tailscale-funnel-rules.md (macOS DNS quirks, Funnel port restrictions, ACL preflight) and port-kill behavior from references/port-hygiene.md (kill-only-our-own pattern, default-port squat list, SIGTERM-then-SIGKILL escalation).

Env conventions per scenario live in references/env-vars-conventions.md (.env.local vs .env.railway, Vercel sensitivity defaults, Railway built-in vars).

6. Update AGENTS.md / CLAUDE.md

Apply the 5-state machine in references/agents-md-update.md. The contract:

7. Verify core generation

Run the verification ladder in references/verification-ladder.md. The skill claims at most rung 5 (external curl from this machine, no proxy). Rung 6 (independent client — phone on cellular) is a manual user step printed in the post-deploy banner.

Per scenario:

Core generation is complete when Makefiles, AGENTS.md sync, and verification are done. The skill remains useful and complete if CI/CD is declined.

8. Optional — CI/CD

Ask first: "Generate GitHub Actions deploy wiring locally? (y/n)". If yes, follow references/ci-cd-workflow.md:

  1. Detect GitHub repo via gh repo view --json nameWithOwner -q .nameWithOwner
  2. Generate .github/workflows/deploy.yml for the providers in scope only
  3. Prompt user for ONLY the tokens needed (Vercel / Railway / Supabase)
  4. gh secret set <NAME> --body "$pasted" for each required secret
  5. Verify required secrets by name with gh secret list
  6. Commit the workflow locally
  7. Ask for explicit push authorization
  8. Push only after that authorization; never force-push

If declined, leave .github/workflows/ untouched. No half-baked YAML.

Decision rules

Recovery from wipe

git log --oneline -- Makefile
git show --stat <snapshot-sha>
git revert <snapshot-sha>
# or restore a single file:
git restore --source=<snapshot-sha> -- path/to/Makefile

Failure modes (and where to fix them)

| Symptom | Cause | Fix |

|---|---|---|

| make local fails with "port :PORT held by orbstack" | Foreign port holder; refused per port-hygiene rule | Pick a different port (make local PORT=4000); don't kill OrbStack |

| make tunnel reports "tailscale not signed in" | Tailscale daemon up but account not linked | tailscale up interactively; this skill assumes Tailscale is signed in |

| make deploy-vercel fails with "Project not found" | .vercel/project.json missing or wrong project name | Re-run vercel link --yes --project <name> --token=$VERCEL_TOKEN |

| make deploy-railway returns 502 "Application Failed to Respond" | App listens on localhost:3000 not 0.0.0.0:$PORT | Fix app's bind address; redeploy |

| make supabase-migrate-apply no-ops with "no migrations to apply" | Migration files already in remote history | Run make supabase-pull to detect drift |

| make ship fails preflight with "ssh alias not found" | Host macbook not in ~/.ssh/config | Add the Host block; make ship re-checks |

| AGENTS.md and CLAUDE.md both exist with different content | State 1 of the symlink machine | Skill prompts user; merges into AGENTS.md per references/agents-md-update.md |

| gh secret set fails with "auth required" | Not authenticated | gh auth login; CI/CD step re-runs |

| Vercel build fails with function over 250 MB | Heavy bundled deps | make build-check surfaces sizes; references/makefile-frontend.md lists mitigations |

| make funnel rejects port 3000 | Funnel allows only 443/8443/10000 | Use make funnel TUNNEL_PORT=443 (and PUBLIC_FUNNEL=1) |

| make tunnel works but host <node>.<tailnet>.ts.net fails on macOS | macOS DNS quirk: host/nslookup/bare dig bypass system resolver | Use tailscale dns query <fqdn> or dscacheutil -q host -a name <fqdn> |

Final report contract

Return this shape when the downstream project work is done:

Scenario: <chosen scenario and confidence>
Generated files: <paths>
Deleted/replaced scaffold paths: <paths or none>
Snapshot: <sha and recovery command>
AGENTS.md / CLAUDE.md: <state>
CI/CD: <skipped | generated locally | secrets wired | pushed>
Verification: <rung actually reached per target>
Manual verification still required: <targets, especially rung 6>

Reference routing

| File | Read when |

|---|---|

| references/scenario-detection.md | Classifying a project; resolving ambiguity; sample disambiguation prompts |

| references/makefile-base.md | Universal preamble, ANSI palette, helper conventions; every Makefile uses this |

| references/makefile-frontend.md | Generating Scenarios A / C / D frontend targets (local, local-lan, tunnel, deploy-vercel, verify, env-pull, build-check) |

| references/makefile-cloudflare-pages.md | Scenario A Cloudflare Pages variant — opt-in only. Read this reference only when the user explicitly mentions Cloudflare / Pages / Wrangler. The Scenario A default is Vercel (makefile-frontend.md). Contents: deploy-cloudflare, cf-project-init, cf-list, cf-tail, wrangler.toml shape, _redirects proxying, 25 MiB-per-file / 20k-file limit checks. |

| references/makefile-r2-bulk.md | Cloudflare R2 media (opt-in when R2 is part of the workflow; works with either Vercel or Pages-hosted frontends): r2-info, r2-cors-apply, single-file r2-put/r2-get/r2-rm, hardlink r2-stage, rclone-configure/rclone-check, r2-sync (rclone copy — additive default for mixed-tenant safety), wrangler-OAuth bulk fallback, public-access audit |

| references/makefile-backend.md | Generating Scenarios C / E backend targets (Railway deploy, multi-service parallel, healthcheck rules, railway.toml baseline) |

| references/makefile-supabase.md | Generating Scenario D Supabase targets (supabase-link, -migrate-*, -functions, -types, -secrets-*) |

| references/makefile-macbook.md | Generating Scenario G ship pipeline (preflights, rsync, atomic swap, kill-then-launch, verify) |

| references/makefile-monorepo.md | Multi-Makefile delegation; 4-file ceiling; per-app namespacing; root-Makefile $(MAKE) -C pattern |

| references/tailscale-funnel-rules.md | Tunnel/Funnel target generation; macOS DNS quirks; Funnel port restrictions; ACL preflight |

| references/port-hygiene.md | The kill-only-our-own pattern; default-port squat list; SIGTERM-then-SIGKILL escalation; banner conventions |

| references/agents-md-update.md | The 5-state machine for AGENTS.md / CLAUDE.md; the ## Make targets section template; idempotency rule |

| references/ci-cd-workflow.md | Wiring GitHub Actions; gh secret set sequence; concurrency rules; rotation hint |

| references/env-vars-conventions.md | Where envs live per scenario; .env.local vs .env.railway; Vercel sensitivity defaults; Railway built-in vars |

| references/verification-ladder.md | The 6 rungs; per-target verification; banner template for the user's manual rung-6 step |

| scripts/scenario-detect.md | Read-only heuristic detector script; use before final classification and ambiguity questions |

| scripts/preview-makefile-wipe.md | Read-only wipe preview script; use before manifest, targeted snapshot, and deletion |

Cross-skill handoffs

Guardrails

Final checks

Before declaring done:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.