You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What changed: Added a new /improve slash command that enables Qwen Code to iteratively improve its own codebase within isolated git worktrees. Introduces selfImproveCommand.ts, selfImproveState.ts, SelfImproveSourceDialog.tsx, and supporting changes across the CLI UI.
Why it changed: To provide a structured, self-directed improvement workflow where the agent can analyze, plan, and implement changes in an isolated environment before presenting them for review.
Reviewer focus: Verify the worktree isolation model, state management during improve sessions, and the source selection dialog UX.
Validation
Commands run:
npm run build && npm run typecheck
cd packages/cli && npx vitest run src/ui/commands/selfImproveCommand.test.ts
Prompts / inputs used: /improve followed by improvement descriptions
This PR introduces a well-architected /self-improve command that enables session-scoped, automated repository improvement loops. The implementation demonstrates solid design with clean separation between state management, UI components, and command processing. The code follows existing project conventions and includes comprehensive test coverage.
🔍 General Feedback
Architecture: Clean separation of concerns between selfImproveCommand.ts (command logic), selfImproveState.ts (state persistence), and SelfImproveSourceDialog.tsx (UI). The design doc clearly outlines the intended behavior.
State Management: Thoughtful use of JSON files under .qwen/self-improve/ with proper error handling for missing/corrupt files.
Test Coverage: 140 lines of tests covering core functionality including source dialog, session startup, and status reporting.
Integration: Minimal, surgical changes to existing files (contexts, dialog manager, command loader) follow established patterns.
Internationalization: Consistent use of t() for all user-facing strings.
🎯 Specific Feedback
🟡 High
packages/cli/src/ui/commands/selfImproveCommand.ts:157 — The buildTickPrompt() function constructs a detailed prompt but hardcodes the "5 repair attempts" rule in the prompt text. This magic number should be a named constant at the module level for clarity and future configurability.
packages/cli/src/ui/commands/selfImproveCommand.ts:204-212 — In startSelfImprove(), the cron job is created before the loop state is fully initialized. If initializeSelfImproveLoopFiles() fails, the cron job remains registered but points to non-existent state. Consider initializing files first, then registering the scheduler.
packages/cli/src/ui/commands/selfImproveState.ts:93-103 — The normalizeConfig() function silently defaults malformed config to safe defaults. While this prevents crashes, it may hide configuration errors from users. Consider logging a warning when normalization occurs.
🟢 Medium
packages/cli/src/ui/commands/selfImproveCommand.ts:78 — The parseInterval() function supports multiple languages (分钟,小时) but the error messages reference these in English only. Ensure consistency or document the localization strategy.
packages/cli/src/ui/commands/selfImproveCommand.ts:100-101 — The cron expression 7 */${value} * * * includes a 7-minute offset to avoid hour-boundary thundering herd. This is a good practice, but should be documented with a comment explaining the intent.
packages/cli/src/ui/components/SelfImproveSourceDialog.tsx:62-76 — The useEffect cleanup pattern is correct, but consider extracting the async loading logic into a separate function for testability and readability.
packages/cli/src/ui/commands/selfImproveCommand.test.ts:46-53 — Tests use a mock scheduler but don't verify that the cron job is properly cleaned up on stop. Add a test case for the stop flow verifying scheduler.delete() is called.
🔵 Low
packages/cli/src/ui/commands/selfImproveCommand.ts:1 — The execFile import from node:child_process is used only for git commands. Consider documenting why execFile is preferred over the git service from @qwen-code/qwen-code-core (which is used elsewhere in the codebase).
packages/cli/src/ui/commands/selfImproveState.ts:188 — The initializeSelfImproveLoopFiles() function writes state.json twice (once via writeSelfImproveLoopState() and once directly). The writeSelfImproveLoopState() already creates the runs directory, making the earlier mkdir call redundant.
packages/cli/src/ui/components/SelfImproveSourceDialog.tsx:145 — The useKeypress handler checks activeIndex < SOURCE_ROWS.length which allows the "User context" input row to be selected, but the navigation logic for onUp/onDown in TextInput (lines 204-205) uses hardcoded indices. Consider defining a constant for USER_CONTEXT_ROW_INDEX = SOURCE_ROWS.length.
packages/cli/src/ui/contexts/UIStateContext.tsx:148 — The isSelfImproveSourceDialogOpen field is added but no corresponding initial state value is shown in this diff. Verify the provider initializes this to false.
packages/cli/src/ui/commands/selfImproveCommand.ts:139 — The describeSources() function returns "none configured" when all sources are disabled. This string could benefit from localization via t().
✅ Highlights
Design Document: Excellent design doc (.qwen/design/2026-05-15-self-improve-command.md) that clearly explains the goal, user commands, state layout, loop behavior, and implementation shape. This makes the PR significantly easier to review.
Session-Scoped Loops: Smart design decision to make loops session-scoped rather than persistent. This reduces complexity around orphaned worktrees and simplifies state management.
Graceful Stop Handling: The stopSelfImprove() function correctly handles both idle and active run scenarios, setting stopRequested: true for graceful shutdown when a run is in progress.
Stale Loop Detection: The statusSelfImprove() function checks if the cron job still exists to detect stale loops (lines 247-249), preventing false "running" status after CLI crashes.
Worktree Isolation: The tick prompt explicitly instructs the agent to work in isolated git worktrees and never overwrite uncommitted user changes—critical safety guarantees.
Test Structure: Well-organized tests using createMockCommandContext test utility, proper cleanup with afterEach, and meaningful assertions on both return values and side effects (file system state).
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/improveslash command that enables Qwen Code to iteratively improve its own codebase within isolated git worktrees. IntroducesselfImproveCommand.ts,selfImproveState.ts,SelfImproveSourceDialog.tsx, and supporting changes across the CLI UI.Validation
/improvefollowed by improvement descriptions/improvein the CLIScope / Risk
Testing Matrix
Testing matrix notes:
Linked Issues / Bugs
No linked issues.
🤖 Generated with Qwen Code