Prompt file imported from zoolutions/phlex-reactive (
.claude/commands/lfg.md). Fill in{{arguments}}before use. Copyright stays with the author.
LFG - Full Autonomous Workflow
Execute a complete engineering workflow with verification at each phase.
Phase 0: Branch Setup
BEFORE any other work, prepare the git branch:
- Check the current branch:
git branch --show-current - If NOT on
main, switch:git checkout main - Pull latest:
git pull origin main - Create feature branch:
git checkout -b issue-{number}-{brief-description}(orfeature/{description}if no issue number)
Phase 1: Understand
Step 1: Gather Requirements
If {{arguments}} is a GitHub issue number or URL:
gh issue view <number> --json title,body,labels,assignees,comments
If {{arguments}} is a description, use it directly.
Step 2: Define Acceptance Criteria
MANDATORY: Write explicit acceptance criteria:
- GIVEN [context/setup]
- WHEN [action taken]
- THEN [expected outcome]
You MUST NOT proceed until you can articulate these clearly.
Step 3: Comprehension Gate
Before proceeding, you must:
- State the problem/feature in one sentence
- Explain WHY this is needed (the user-facing payoff — "a pleasure to work with")
- List what changes from the developer's perspective (the API delta)
- Identify edge cases not explicitly mentioned
- Explain the data flow: client event → endpoint → action → re-render → DOM, and/or the broadcast path
If you cannot complete ALL five items, investigate further.
Step 4: Create Task List
Create a TaskCreate todo list with specific implementation steps.
Phase 2: Explore
- Find related files (Glob/Grep or Explore agent)
- Read existing patterns in similar features
- Understand integration points across the layers
- Check existing test coverage in
spec/ - Review the Streamable mixin in
lib/phlex/reactive/streamable.rb - Review the Component mixin in
lib/phlex/reactive/component.rb - Review the action endpoint in
app/controllers/phlex/reactive/actions_controller.rb - Review the client runtime in
app/javascript/phlex/reactive/reactive_controller.js - If a pgbus primitive is involved, verify its real signature in
~/Code/mhenrixon/pgbus— do not assume the wire format
Phase 3: Plan
- List files to modify with specific changes
- List new files to create with purpose
- Identify the pgbus-present vs pgbus-absent behavior (the optionality invariant)
- Plan test coverage across layers (TDD: tests FIRST) — unit, request, broadcast, system
- Update the task list
- Consider backwards compatibility (existing components must keep working verbatim)
Phase 4: Implement (TDD)
The deviation log (keep it from the first edit)
The plan is the map; the codebase is the territory. The moment reality forces a choice the plan or issue didn't settle, log it in implementation-notes.md at the repo root — one line, at the moment it happens, not reconstructed later:
- Deviations — the plan said X, you did Y, because Z
- Discoveries — facts about the codebase the plan didn't know
- Judgment calls — choices the user might have made differently (defaults, naming, scope cuts)
Pick the conservative option and keep going. The log is how the user audits your judgment afterwards. Never commit the file: its contents move into the PR body (Phase 7), then the file is deleted.
For each logical unit:
4.1: Write Failing Test First
bundle exec rspec <spec_file>
4.2: Implement Minimum Code
Write the MINIMUM code to make the test pass. Follow project patterns:
| Never Do | Always Do |
|---|---|
| Hand-pick a Turbo target | Component self-targets via #id |
| Ship state to the client | Sign identity ({c, gid}); re-find server-side |
| Trust client input for authz | authorize! inside the action |
| Undeclared / raw-param actions | action :name, params: {...} (default-deny) |
| Fabricate a view context | Render through Phlex::Reactive.renderer |
| Assume pgbus / call a pgbus keyword blind | Capability-gate (pgbus_streams?) + fallback |
dom_id (Phlex helper) in #id |
Streamable#dom_id (render-context-free) |
4.3: Refactor
Once green, refactor while keeping tests passing.
4.4: Validate
bundle exec rubocop
4.5: Repeat
Move to the next unit. Mark task items complete.
Phase 5: Deep Root Cause Analysis (Bug Fixes Only)
If this is a bug fix, investigate before implementing.
Trace the lifecycle
For the failing interaction:
- Where did the client event originate? What token did it carry?
- Did the action re-render, or did a broadcast deliver it? Both?
- What ASSUMPTIONS does the code make at the failure point? Which was violated, and WHY?
Use git history
git log --oneline -20 <file>
git blame <file>
Map all callers
Use Grep to find every call site. Does the bug happen only on the pgbus path? Only on Action Cable? Only for the actor (echo)? Only on the first action (connection-id race)?
Five Whys
Keep asking WHY until you reach the real fix point.
Fix-location principle
The best fix is usually NOT where the error surfaced:
- Double-applied broadcast → suppress the actor echo / dedup by id, not a
rescue ArgumentError: unknown keyword :exclude→ the capability gate, not abegin/rescue- Stale token under rapid clicks → the request queue + token threading, not a debounce
HelpersCalledBeforeRenderErrorin#id→ useStreamable#dom_id, not arescue
Unacceptable superficial fixes — DO NOT DO THESE
rescue nil/ barerescueto silence an error you don't understand&.to paper over a nil without finding why it's nilreturn if x.nil?to silently skip- swallowing errors instead of logging + fixing the cause
These HIDE bugs. Find the EARLIEST point you could prevent the error and fix there.
Phase 6: Verify
ALL of these must pass before committing:
bundle exec rubocop
bundle exec rspec spec/phlex spec/requests
# client-touching changes: also run the browser suite
bundle exec rspec spec/system # Puma (default); CAPYBARA_SERVER=falcon for the async server
bundle exec rake spec:system_servers # client-touching changes: run BOTH real servers (puma + falcon)
Solution verification
- "If I were the requester, is this fully resolved?"
- "Did I fix the ROOT CAUSE, not the symptom?"
- "Do the tests prove it, including the pgbus-absent fallback?"
- "Does every existing component still work verbatim (backwards compatible)?"
Phase 7: Commit & PR
Commit
git add <specific_files>
git commit -m "$(cat <<'EOF'
feat(scope): brief description
## Summary
[What changed and why]
## Test Coverage
- spec 1: validates X
- spec 2: validates the pgbus-absent fallback
## Verification
- [x] bundle exec rubocop passes
- [x] bundle exec rspec passes
EOF
)"
Push & PR
git push -u origin $(git branch --show-current)
gh pr create --title "feat(scope): brief description" --body-file /tmp/pr-body.md
Write the PR body to a temp file (--body-file) to avoid shell-interpolation of
backticks/tables. The body is copied verbatim — if you would not type a
backslash in a GitHub comment, do not type one in the heredoc.
The PR body MUST end with a ## Deviations & judgment calls section copied from
implementation-notes.md (then delete the file). If the plan held completely,
write "None — the plan held." This section is read FIRST in review — it is the
audit trail for every decision the plan didn't make.
Phase 8: Comprehension Close-Out
The tests prove the CODE is right; this phase keeps the USER's mental model right. After the PR is up, end your final message with:
- The decisions, not the diff — the 3–5 non-obvious choices in this change someone must understand to maintain it. Lead with anything from the deviation log; the user has never seen those.
- Three merge-gate questions the user should be able to answer before merging (e.g. "why does the verify run inside the transaction?"). If any answer isn't obvious to them, offer a walkthrough — an unanswerable question is comprehension debt, and merging anyway is how it compounds.
Verification Checklist
- All acceptance criteria met
- Tests written BEFORE implementation
-
bundle exec rubocoppasses -
bundle exec rspecpasses (browser suite too, if the client changed) - Backwards compatible — existing components unchanged
- pgbus optionality preserved (works with pgbus AND on Action Cable)
- PR created with summary + test plan
- PR body ends with
## Deviations & judgment calls(from implementation-notes.md, since deleted) - Comprehension close-out delivered (decisions + three merge-gate questions)
Now, execute this workflow for the provided issue or feature.