Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ All six are shared-canonical (identical in `deep_iq_v2`):
|---|---|
| `/prime` | Read-only: loads `CLAUDE.md` + canonical docs (`README.md`, `ROADMAP.md`, `docs/`), reports project state. Start here. |
| `/audit` | `flutter analyze` + `flutter test`, compressed to counts + failures. ~1-2K token cost regardless of suite size. |
| `/checkpoint` | Verify → document → cleanup → commit → push → PR, in strict phases. |
| `/checkpoint` | Clean (`dart fix`) → verify → document → memory → commit → push → PR, in strict phases. Cleanup runs before verify so the gate covers `dart fix` output. |
| `/ship-pr <title>` | Full branch→commit→rebase→push→PR→squash-merge→cleanup. Works local (`gh`) or remote (GitHub MCP). |
| `/clean-branches` | Delete local branches whose squash-merge already landed on the default branch. Content-aware + safe. |
| `/code-analysis` | Fans out 4 **Haiku** scan agents (packages/patterns/perf/dead-code), synthesizes on the session model. |
Expand Down
6 changes: 4 additions & 2 deletions .claude/commands/audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ The user wants a full project audit run.

## What to do

1. **Run `flutter analyze`** in the project root. Capture the output.
2. **Run `flutter test`** in the project root. Capture the output (it can be large; use a tmp file if needed).
Use the analyze and test commands `CLAUDE.md` names as the gate (e.g. a tag exclusion, or `melos run` in a monorepo); if it names none, `flutter analyze` and `flutter test`.

1. **Run the analyze command** in the project root. Capture the output.
2. **Run the test command** in the project root. Capture the output (it can be large; use a tmp file if needed).
3. **Summarize:**
- **Analyze:** count of errors / warnings / infos. List every error and warning with file:line. Infos can be summarized as "N infos (mostly prefer_single_quotes)" without enumeration.
- **Tests:** total passed / failed / skipped. List every failing test with the failure message. If all passed, say so in one line.
Expand Down
69 changes: 9 additions & 60 deletions .claude/commands/checkpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,14 @@
description: Full project checkpoint — verify, document, clean, commit, push, PR.
---

Execute these phases in strict order. Stop and report if any phase fails.
Run these phases in order. Stop and report if one fails.

## Phase 1: Verify
1. **Clean.** `dart fix --apply`, then review its diff: some fixes produce code that does not compile, so revert any hunk that is wrong. This runs before Verify so the gate covers it.
2. **Verify.** `git status`, `git diff --stat`, then the gate (the analyze and test commands `CLAUDE.md` names as the gate, else `flutter analyze` and `flutter test`). Fix failures before going on. Note the passing-test count.
3. **Document.** From the diff and `git log --oneline -5`: what was added, changed or fixed; key decisions and trade-offs; bugs found and resolved.
4. **Update memory.** In the project's memory directory, update milestone status, test count, current branch and key decisions; remove stale entries. Keep `MEMORY.md` under 200 lines, one line per entry, each under 150 characters.
5. **Commit.** Stage named files, never `git add -A`, and never `.env`, credentials or large binaries. Conventional-commit subject (`fix:`, `feat:`, `chore:`…); body says why in 1–2 sentences; end with `Co-Authored-By: Claude <noreply@anthropic.com>`. Use a HEREDOC.
6. **Push.** `git push origin <branch>`, with `-u` if it has no upstream.
7. **PR.** On the default branch, the push is enough. On a feature branch, `gh pr create` with a title under 70 characters, `## Summary` and `## Test plan`, and the footer `Generated with [Claude Code](https://claude.com/claude-code)`.

1. `git status` — note modified/untracked files.
2. `git diff --stat` — scope of changes.
3. `flutter analyze` — fix issues before proceeding.
4. `flutter test` — fix failures before proceeding.
5. Count passing tests from output.

## Phase 2: Document findings

Summarize what changed since last commit. `git log --oneline -5` for recent history, compare against diff:
- What was added/changed/fixed
- Key decisions or trade-offs
- Bugs found and resolved

## Phase 3: Update memory

Read memory index at the project's memory directory. Update memory files to reflect:
- Phase/milestone completion status
- Test count
- Current branch
- New API discoveries, key decisions, architectural changes
- Remove stale entries

Keep MEMORY.md index under 200 lines. Each entry one line, under 150 chars.

## Phase 4: Cleanup

1. `dart fix --apply` to auto-fix remaining issues.
2. `flutter analyze` one final time — zero issues.
3. Resolve any new issues from dart fix manually.

## Phase 5: Commit

1. `git status` — final state.
2. `git diff --stat` — confirm scope.
3. Stage relevant files — prefer named files over `git add -A`. Never stage `.env`, credentials, or large binaries.
4. Write commit message:
- Conventional commit format (fix:, feat:, chore:, etc.)
- Summarize "why" in 1-2 sentences
- End with `Co-Authored-By: Claude <noreply@anthropic.com>`
5. Commit using HEREDOC.

## Phase 6: Push

1. `git branch --show-current`
2. `git status -sb` — check upstream tracking.
3. `git push origin <branch>` (add `-u` if no upstream).

## Phase 7: PR or Direct

- **On main:** push is sufficient.
- **On feature branch:** `gh pr create` with short title (<70 chars), body with `## Summary` + `## Test plan`, footer `Generated with [Claude Code](https://claude.com/claude-code)`. Report PR URL.

## Completion report

- Branch and commit hash
- Test count (passing/total)
- Files changed
- PR URL (if created)
Report: branch and commit hash, tests passing/total, files changed, PR URL if any.
56 changes: 56 additions & 0 deletions .claude/commands/flutter-review.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
description: Diff-scoped Flutter anti-pattern scanner. Run standalone (/flutter-review) at any time, or called internally by ship-pr as a blocking gate before commit. BLOCK findings abort ship-pr.
---

Scan a Dart diff for Flutter anti-patterns. Report only; never edit source.

**Mode.** Standalone (`/flutter-review`): `git diff HEAD -- '*.dart'`, heading label `HEAD`. Ship-pr gate: `git diff --cached -- '*.dart'`, label `staged`; ship-pr aborts on `🚫 BLOCK`.

If the diff is empty, output `✅ PASS — no Dart changes in diff` and stop.

Read `CLAUDE.md` first. Do not flag a pattern its conventions / critical-rules sections sanction.

Check **added or modified lines only** (`+`), except A5. Scope B1/B2 to the same method body: from the `await` to that method's closing brace. Do not flag across methods or callbacks.

## BLOCK

| ID | Look for | Fix |
|---|---|---|
| B1 | `context` used after `await` (`Navigator.of`, `ScaffoldMessenger.of`, `Theme.of`, `showDialog(context:`, `context.go/push`…) with no `if (!mounted) return` between | add the guard after the `await` |
| B2 | `setState(` / `notifyListeners(` after `await` with no `mounted` guard | add the guard before the call |
| B3 | `TextEditingController` / `ScrollController` / `FocusNode` / `PageController` / `AnimationController` constructed inside `build()`. If `initState` is not in the diff, flag as suspected: "initState not visible in diff — verify manually" | create in `initState`, dispose in `dispose` |
| B4 | `super.initState()` not the first statement of `initState` (comments and blank lines don't count) | move it first |
| B5 | `super.dispose()` not the last statement of `dispose` (comments and blank lines don't count) | move it last |
| B6 | `WillPopScope` | `PopScope(canPop:, onPopInvokedWithResult:)` |
| B7 | Under `lib/`: an `http(s)://` URL to a non-localhost host, or a credential literal (`sk_`, `pk_`, `AIza`, `Bearer `, `token=`, or a 32+ char non-UUID hex string assigned to `key`/`secret`/`token`/`password`/`credential`) | move to environment config |

## ADVISORY

| ID | Look for | Prefer |
|---|---|---|
| A1 | `MediaQuery.of(context).size/.padding/.textScaleFactor/.devicePixelRatio/.viewInsets/.viewPadding/.orientation` | `MediaQuery.sizeOf` / `paddingOf` / `textScalerOf` / `viewInsetsOf`… |
| A2 | `ListView(children:` with more than 3 items or any dynamic content (spread, for-in, call, non-const) | `ListView.builder` |
| A3 | `Opacity(opacity:` with a non-literal value | `FadeTransition` / `AnimatedOpacity` |
| A4 | `print(` / `debugPrint(` outside `if (kDebugMode) { }` (a method that opens with `if (!kDebugMode) return;` is fine) | wrap in `kDebugMode` |
| A5 | A **removed** `const WidgetName(` where the diff shows `WidgetName extends StatelessWidget` (skip if the class isn't in the diff) | restore `const` unless args became mutable |

## Output

One line per finding, `file:line | BLOCK|ADVISORY | one-sentence problem | fix`, sorted by file then line within each tier.

No findings at all: output only `✅ PASS — diff is clean`. Otherwise:

```
## Flutter Review — <staged|HEAD>

### BLOCK findings
<lines, or none>

### ADVISORY findings
<lines, or none>

### Verdict
✅ PASS — no blockers
```

or, with any BLOCK finding, the verdict line `🚫 BLOCK — N blocker(s) found, fix before ship`. The verdict is always the last line; ship-pr reads it.
99 changes: 35 additions & 64 deletions .claude/commands/ship-pr.md
Original file line number Diff line number Diff line change
@@ -1,79 +1,50 @@
---
description: Ship the staged work as one squash-merged PR — commit + push + PR + merge + cleanup. The 10-step branch-PR-merge dance run automatically.
description: Ship the staged work as one squash-merged PR — commit + push + PR + merge + cleanup, run automatically.
---

The user wants to ship the current work as a complete pull request — the full mechanical dance from "I have changes" to "merged on the default branch and local cleaned up."
Ship the current work as one PR, from "I have changes" to "squash-merged on the default branch, local cleaned up". `$ARGUMENTS` is the PR title and commit subject; if empty, stop: "Pass a title: `/ship-pr fix(ui): …`".

> **Environment note:** the `gh` steps below assume a local session where `gh` is authed. In a remote / web session `gh` is unavailable — use the GitHub MCP tools (`mcp__github__create_pull_request`, `mcp__github__merge_pull_request`, `mcp__github__pull_request_read`) for the PR open / merge / verify steps instead. The git steps (stage, commit, rebase, push) are the same in both.
Locally use `gh`. In a remote/web session `gh` is unavailable: use the GitHub MCP tools (`create_pull_request`, `merge_pull_request`, `pull_request_read`) for the PR steps. The git steps are the same.

## Preconditions you check before doing anything
## Preconditions — stop if any fails

1. **Detect the default branch** — repos differ (`main` vs `master`), so never hardcode it:
```bash
DEFAULT=$(git remote show origin | sed -n 's/.*HEAD branch: //p')
```
Every reference to `$DEFAULT` below means this detected branch.
2. **You're not on `$DEFAULT`** — `git branch --show-current` must be a feature / fix / docs / chore branch. If on the default branch, error out: "Won't ship from the default branch; create a branch first."
3. **The branch tracks `origin/<same-branch>` OR is brand-new** — either is fine; brand-new means you'll push with `-u`.
4. **There's something to ship** — if `git status --short` is empty AND `git log origin/$DEFAULT..HEAD` is empty, error out: "Nothing to ship."

## What `$ARGUMENTS` contains

The argument string is the PR title (and the commit subject). Required. If empty, error: "Pass a title: `/ship-pr fix(ui): …`"

## What to do

1. **Stage everything**: `git add -A`. (The user has already done their own staging if they cared; staging the rest is the right default at ship time.)
2. **Verify analyze + tests pass.** Run `flutter analyze` and `flutter test` (full suite). If either fails, abort: don't commit, surface the failure, ask the user how to proceed. The user's policy is "tests + analyze clean before ship."
3. **Compose the commit body.** Use the diff (`git diff --cached --stat` + the actual diff hunks for any non-trivial changes) and recent commit history (`git log --oneline -5`) as input. Body should be 1-3 short paragraphs explaining what changed and why, NOT what the diff already shows. Match the user's existing commit style — see recent commits with `git log --format='%B' -5` for tone. Always end with the `Co-Authored-By: Claude <noreply@anthropic.com>` line.
4. **Commit** via HEREDOC so newlines are preserved:
```bash
git commit -m "$(cat <<'EOF'
<title from $ARGUMENTS>
- `DEFAULT=$(git remote show origin | sed -n 's/.*HEAD branch: //p')`. Never hardcode `main`/`master`.
- Not on `$DEFAULT` ("Won't ship from the default branch; create a branch first.").
- Something to ship: `git status --short` or `git log origin/$DEFAULT..HEAD` is non-empty ("Nothing to ship.").

<body you composed>
## Steps

Co-Authored-By: Claude <noreply@anthropic.com>
EOF
)"
```
5. **Pull + rebase before push.** `git fetch origin "$DEFAULT"` and `git rebase "origin/$DEFAULT"`. If conflicts, abort and surface them: "rebase conflict on `<file>`, resolve and re-run /ship-pr."
6. **Push the branch.** `git push -u origin <branch>` if it doesn't track yet, otherwise plain `git push`. Tail the last 3 lines of output.
7. **Open the PR.** Use `gh pr create` with `--title` matching `$ARGUMENTS` and `--body` from a HEREDOC. Body template:
1. **Bump the build number.** `pubspec.yaml` `version: X.Y.Z+N` → `N+1` (the build the app shows in its settings/about version row).
2. **Stage by explicit path**, never `git add -A`: a local `flutter build ios` mutates tracked `ios/` files. Leave out build output, `.env`, credentials and unrelated `ios/` churn.
3. **Gate** (the analyze and test commands `CLAUDE.md` names as the gate, else `flutter analyze` and `flutter test`) must pass. On failure: don't commit; show it and ask how to proceed.
4. **Review gate.** Spawn a subagent: "Follow `.claude/commands/flutter-review.md` in ship-pr mode (staged diff). Return its full output." Read its last non-blank line:
- `✅ PASS` → print any ADVISORY lines under "ℹ️ Advisory (non-blocking):", continue.
- `🚫 BLOCK` → abort without committing; print the BLOCK findings and "flutter-review blocked ship — fix the above findings and re-run /ship-pr."
- Anything else → abort: "flutter-review returned no clear verdict; re-run /ship-pr."
5. **Commit** (HEREDOC). Subject = `$ARGUMENTS`. Body: 1–3 short paragraphs on *why*, matching the tone of `git log --format='%B' -5`. End with `Co-Authored-By: Claude <noreply@anthropic.com>`.
6. **Rebase.** `git fetch origin "$DEFAULT" && git rebase "origin/$DEFAULT"`. On conflict, stop: "rebase conflict on `<file>`, resolve and re-run /ship-pr."
7. **Push.** `git push -u origin <branch>` (plain `git push` if it already tracks).
8. **Open the PR.** Title = `$ARGUMENTS`. Body:
```markdown
## Summary
<2-4 bullet recap, derived from the commit body>
<2-4 bullets from the commit body>

## Test plan
- [x] flutter analyze clean
- [x] flutter test passes
- [ ] <one or two manual smoke checks if the change is UI-visible>
- [x] analyze clean
- [x] tests pass
- [ ] <manual smoke check, if UI-visible>

🤖 Generated with [Claude Code](https://claude.com/claude-code)
```
Capture the PR URL from the output.
8. **Squash-merge with admin.** `gh pr merge <num> --squash --delete-branch --admin`. The command may print one warning that the default branch `is already used by worktree` — that's expected (the merge happens on the remote anyway, and the local default-branch worktree is held by another session). Ignore that line; the next command compensates.
9. **Verify merge** with `gh pr view <num> --json state` — must show `MERGED`.
10. **Force-delete the remote branch** if it still exists: `git push origin --delete <branch>`. The squash-merge with `--delete-branch` usually handles this but the worktree-lock warning sometimes leaves it behind.
11. **Reset locally** to a fresh `working` branch off the default branch:
```bash
git checkout -B working "origin/$DEFAULT"
git fetch --prune origin
git branch -D <feature-branch>
```
12. **Report.** One short line: `Merged via #<num>: <title>`. No essay.

## Edge cases

- **Pre-commit hook fails on commit (step 4):** investigate the underlying issue and fix, then re-stage and re-run `git commit`. NEVER use `--no-verify`. NEVER use `--amend` after a hook failure (the commit didn't happen — amend would modify the previous commit).
- **PR creation fails with `HTTP 504` (step 7):** retry once with the same body. If retry fails, surface the error to the user.
- **gh pr merge fails because PR has merge conflicts:** abort, surface "PR #<num> has merge conflicts, resolve on the branch and re-run."
- **The PR was already merged manually before you got to step 8:** check `gh pr view <num> --json state` first. If MERGED, skip the merge step and proceed with cleanup.

## What you don't do

- Don't run `/audit` or duplicate the analyze + test work it already does — just inline `flutter analyze` and `flutter test`.
- Don't open the user's editor to write the commit message — compose it yourself from the diff.
- Don't push to the default branch directly. Don't bypass `--squash`. Don't skip `--admin` (the user has authorized it for solo work).
- Don't sleep / poll for merge state. `gh pr view` is synchronous.
- Don't use `git push --no-verify` or `git commit --no-verify`. If hooks fail, fix the cause.
On HTTP 504, retry once.
9. **Merge.** `gh pr merge <num> --squash --delete-branch --admin` (`--admin` is authorized for solo work). If it is already merged, skip to 10. A warning that the default branch "is already used by worktree" is expected; ignore it. On merge conflicts, stop: "PR #<num> has merge conflicts, resolve on the branch and re-run."
10. **Verify** `gh pr view <num> --json state` reads `MERGED`. Delete the remote branch if it survived: `git push origin --delete <branch>`.
11. **Reset locally.** `git checkout -B working "origin/$DEFAULT" && git fetch --prune origin && git branch -D <branch>`.
12. **Report** one line: `Merged via #<num>: <title>`.

## Never

- `--no-verify` on commit or push. If a hook fails, fix the cause and re-commit; never `--amend` after a failed commit (it didn't happen).
- Push to `$DEFAULT` directly, or merge without `--squash`.
- Run `/audit` as well: step 3 is the gate.
- Sleep or poll for merge state.
Loading