-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Description
The FSM implementation flow currently routes successful rebase to STAGE_IMPL (re-implementation), which is wasteful since the code is already implemented and only needs re-review after rebasing. Additionally, there is no standalone lol rebase CLI command for direct git rebase operations (distinct from the AI-assisted wt rebase).
This plan addresses both issues: fixing the FSM transition from rebase→impl to rebase→review, and adding a standalone lol rebase CLI command.
Modules affected:
python/agentize/workflow/impl/— FSM transition table and rebase stage kernelpython/agentize/cli.py— Python CLI entrypointsrc/cli/lol/— Shell CLI dispatch, parser, commands, completion
Proposed Solution
Consensus Summary
This plan balances the bold proposer's full-featured approach with the reducer's minimalism and incorporates the critique's risk findings. The FSM transition fix (rebase→review) is the highest-value change and is paired with review counter resets. The standalone lol rebase CLI is included per the user's explicit request, but uses a thin handle_rebase() in cli.py (modeled after _sync_branch()) instead of reusing rebase_kernel() which requires ImplState. All missing integration files identified by the critique are addressed.
Goal
Fix the FSM transition so successful rebase routes to review (not impl), and add a standalone lol rebase CLI command for direct git rebase operations.
Success criteria:
- FSM transition
(STAGE_REBASE, EVENT_REBASE_OK)routes toSTAGE_REVIEW - Review counters are reset after successful rebase
lol rebase [--target-branch <branch>]works as a standalone command- All existing tests pass, new tests cover the transition and counter reset
Out of scope:
- Modifying
wt rebase(separate AI-assisted rebase command with different scope) - Interactive conflict resolution
- Changes to other FSM transitions
- ✅ Good to have in the future: A
--force-with-leasepush flag forlol rebaseto push after rebasing, useful for quick rebase-and-push workflows.
Codebase Analysis
Files verified (docs/code checked by agents):
python/agentize/workflow/impl/transition.pyline 52: Confirmed(STAGE_REBASE, EVENT_REBASE_OK): STAGE_IMPLpython/agentize/workflow/impl/kernels.pylines 261-298: Confirmedrebase_stage_kernel()with 3-attempt retry guardpython/agentize/workflow/impl/kernels.pylines 1361-1437: Confirmedrebase_kernel()requiresImplStatepython/agentize/workflow/impl/impl.pylines 287-302: Confirmed_sync_branch()pattern (fetch + rebase without ImplState)python/agentize/workflow/impl/impl.mdline 86: Confirmed Mermaid diagram showsrebase -->|rebase_ok| implpython/agentize/cli.py: Confirmed existing subparser pattern (handle_impl(),handle_simp())src/cli/lol/dispatch.sh: Confirmed dispatch case patternsrc/cli/lol/parsers.sh: Confirmed_lol_parse_impl()parser patternsrc/cli/lol/commands/impl.sh: Confirmed shell-to-Python delegation patternsrc/cli/wt/commands.shline 420: Confirmedcmd_rebase()is AI-assisted (different fromlol rebase)
File changes:
| File | Level | Purpose |
|---|---|---|
python/agentize/workflow/impl/transition.py |
minor | Change rebase_ok target from STAGE_IMPL to STAGE_REVIEW |
python/agentize/workflow/impl/kernels.py |
minor | Reset review counters on EVENT_REBASE_OK |
python/agentize/cli.py |
medium | Add handle_rebase() and rebase subparser |
src/cli/lol/commands/rebase.sh (new) |
major | New shell command delegating to Python CLI (Est: 15 LOC) |
src/cli/lol/parsers.sh |
medium | Add _lol_parse_rebase function |
src/cli/lol/dispatch.sh |
minor | Add rebase) case and help text |
src/cli/lol/commands.sh |
minor | Source commands/rebase.sh |
src/cli/lol/completion.sh |
minor | Add rebase to completion |
python/agentize/workflow/impl/impl.md |
minor | Update Mermaid diagram rebase→review |
python/agentize/workflow/impl/transition.md |
minor | Update transition coverage text |
python/agentize/workflow/impl/kernels.md |
minor | Document review counter reset |
src/cli/lol/commands/README.md |
minor | Add rebase.sh to file map |
python/tests/test_impl_fsm.py |
medium | Add transition assertion and counter reset test |
Current architecture notes:
lolcommands follow a shell→Python delegation pattern:dispatch.sh→parsers.sh→commands/X.sh→python -m agentize.cli X- FSM uses a
TRANSITIONSdict mapping(Stage, Event) → Stageintransition.py - Each stage kernel is a function that returns an event; the orchestrator loops through transitions
wt rebaseis AI-assisted (Claude Code session);lol rebasewill be a direct git operation
Interface Design
New interfaces:
-
handle_rebase(args)inpython/agentize/cli.py:- Exposed as
lol rebase [--target-branch <branch>]CLI command - Internal implementation:
- Step 1: Determine remote (default
origin) and base branch (default from--target-branchor detectmain/master) - Step 2: Run
git fetch <remote> - Step 3: Run
git rebase <remote>/<branch> - Step 4: Print result (success / conflict / already-up-to-date) based on return code
- Step 5: If conflict, run
git rebase --abortand exit 1
- Step 1: Determine remote (default
- No data structures needed; stateless function
- Exposed as
-
_lol_parse_rebaseinsrc/cli/lol/parsers.sh:- Parses
--target-branch <branch>flag - Delegates to
_lol_cmd_rebasewith parsed arguments
- Parses
-
_lol_cmd_rebaseinsrc/cli/lol/commands/rebase.sh:- Delegates to
python -m agentize.cli rebasewith--target-branchpassthrough
- Delegates to
Modified interfaces:
# python/agentize/workflow/impl/transition.py line 52
- (STAGE_REBASE, EVENT_REBASE_OK): STAGE_IMPL,
+ (STAGE_REBASE, EVENT_REBASE_OK): STAGE_REVIEW,# python/agentize/workflow/impl/kernels.py in rebase_stage_kernel()
# After the EVENT_REBASE_OK branch (around line 295):
if event == EVENT_REBASE_OK:
state.iteration += 1
+ context.data["review_fail_streak"] = 0
+ context.data["review_attempts"] = 0
+ context.data["last_review_score"] = NoneDocumentation changes:
impl.mdMermaid diagram:rebase -->|rebase_ok| impl→rebase -->|rebase_ok| reviewtransition.mdcoverage:rebase -> impl/fatal→rebase -> review/fatalkernels.md: Add note about review counter reset on rebase success
Documentation Planning
Folder READMEs:
src/cli/lol/commands/README.md— addrebase.sh/_lol_cmd_rebaserow to file map table
Interface docs:
python/agentize/workflow/impl/impl.md— update Mermaid diagram line 86python/agentize/workflow/impl/transition.md— update transition coverage line 34python/agentize/workflow/impl/kernels.md— document review counter reset on rebase success
Test Strategy
Test modifications:
python/tests/test_impl_fsm.py- FSM transition and kernel tests- Test case:
test_next_stage_resolves_expected_edges— add assertionnext_stage(STAGE_REBASE, EVENT_REBASE_OK) == STAGE_REVIEW - Test case:
test_rebase_ok_resets_review_counters— new test inTestRebaseStageKernelverifying counter reset - Test case:
test_fsm_rebase_ok_reaches_review_then_finish— orchestrator test for fullpr → rebase → review → simp → pr → finishpath
- Test case:
Test data required:
- Mock
context.datawith pre-existingreview_fail_streak=2,review_attempts=3,last_review_score=50to verify reset
Implementation Steps
Step 1: Update documentation (Estimated: 8 LOC)
python/agentize/workflow/impl/impl.md: Change line 86rebase -->|rebase_ok| impltorebase -->|rebase_ok| reviewpython/agentize/workflow/impl/transition.md: Changerebase -> impl/fataltorebase -> review/fatalpython/agentize/workflow/impl/kernels.md: Add note about review counter resetsrc/cli/lol/commands/README.md: Addrebase.shrow
Dependencies: None
Correspondence:
- Docs: Establishes expected behavior for transition fix and CLI command
- Tests: N/A
Step 2: Write tests for FSM transition fix (Estimated: 45 LOC)
python/tests/test_impl_fsm.py:- Add
next_stage(STAGE_REBASE, EVENT_REBASE_OK) == STAGE_REVIEWassertion - Add
test_rebase_ok_resets_review_counterstest - Add
test_fsm_rebase_ok_reaches_review_then_finishorchestrator test
- Add
Dependencies: Step 1
Correspondence:
- Docs: Tests verify the documented
rebase → reviewtransition - Tests: New transition assertion, counter reset test, orchestrator path test
Step 3: Fix FSM transition and kernel (Estimated: 5 LOC)
python/agentize/workflow/impl/transition.pyline 52:STAGE_IMPL→STAGE_REVIEWpython/agentize/workflow/impl/kernels.pyinrebase_stage_kernel(): reset review counters
# transition.py
- (STAGE_REBASE, EVENT_REBASE_OK): STAGE_IMPL,
+ (STAGE_REBASE, EVENT_REBASE_OK): STAGE_REVIEW,# kernels.py rebase_stage_kernel()
if event == EVENT_REBASE_OK:
state.iteration += 1
+ context.data["review_fail_streak"] = 0
+ context.data["review_attempts"] = 0
+ context.data["last_review_score"] = NoneDependencies: Step 2
Correspondence:
- Docs: Implements
rebase → reviewtransition documented in Step 1 - Tests: Makes Step 2 transition and counter reset tests pass
Step 4: Add Python CLI rebase handler (Estimated: 35 LOC)
python/agentize/cli.py:- Add
handle_rebase(args)function (fetch + rebase + abort-on-conflict) - Add
rebasesubparser with--target-branchargument - Add dispatch case
- Add
Dependencies: None (independent of FSM changes)
Correspondence:
- Docs: Implements standalone
lol rebasecommand - Tests: Can be verified manually with
python -m agentize.cli rebase --help
Step 5: Add shell CLI integration (Estimated: 51 LOC)
src/cli/lol/commands/rebase.sh(new):_lol_cmd_rebasedelegating to Pythonsrc/cli/lol/parsers.sh: Add_lol_parse_rebasewith--target-branchparsingsrc/cli/lol/dispatch.sh: Addrebase)case and help textsrc/cli/lol/commands.sh: Sourcecommands/rebase.shsrc/cli/lol/completion.sh: Addrebasecommand andrebase-flagscase
Dependencies: Step 4 (Python handler must exist)
Correspondence:
- Docs: Completes CLI integration documented in README
- Tests: Verifiable via
lol rebase --help
Total estimated complexity: ~144 LOC (Small-Medium)
Recommended approach: Single session
Success Criteria
-
(STAGE_REBASE, EVENT_REBASE_OK)routes toSTAGE_REVIEWin transition table - Review counters reset on
EVENT_REBASE_OKinrebase_stage_kernel() -
lol rebase [--target-branch <branch>]works as standalone CLI command -
python -m pytest python/tests/test_impl_fsm.py -vpasses with new tests - Mermaid diagram in
impl.mdshowsrebase → review - Shell completion includes
rebasecommand
Risks and Mitigations
| Risk | Likelihood | Impact | Mitigation |
|---|---|---|---|
| Silent semantic conflicts after rebase go undetected by review | Low | Medium | Review stage analyzes code against requirements; add note in transition docs |
rebase → review → simp → pr re-runs simp on already-simplified code |
Low | Low | Simp is idempotent; running it again is harmless |
User confusion between lol rebase and wt rebase |
Medium | Low | Document distinction: lol rebase = direct git, wt rebase = AI-assisted |
| Force-push not included in standalone command | Low | Low | Deferred to future --push flag; users can run git push --force-with-lease manually |
Dependencies
- Git CLI (already required by the project)
- No new external dependencies
Related PR
TBD - will be updated when PR is created