Improve terminal input handling and task loading (supersedes #235)#265
Improve terminal input handling and task loading (supersedes #235)#265
Conversation
Enhances prompt input by filtering out mouse tracking and escape codes, adds real-time input filtering for text prompts, and disables mouse tracking in the terminal. Also updates the resume command to load tasks from the tracker and passes them to the TUI. Expands user story header parsing to support up to four hash marks.
…orted by coderabbitai Enhances the TUI session to better track active tasks by subscribing to engine events for task activation and completion, ensuring session state is updated and persisted accordingly. Refactors prompt cleanup to remove only the relevant data listener, and updates escape code stripping to use RegExp constructors for better linter compatibility. Also refines historical output loading logic in RunApp to allow showing previous output when resuming in-progress tasks.
…error reported by coderabbitai Refines the regex for filtering mouse tracking codes to avoid false positives and adds error handling for invalid pattern configurations in prompt input validation.
…e error reported by coderabbitai Refines the regex in stripEscapeCodes to avoid false positives when removing mouse tracking patterns. Adds an AnimatedProgressBar component to ChatView for simulating progress during loading states.
The parser now recognizes user stories defined with H4 headers (####) and 'Feature X.Y' formats, normalizing them to 'FEAT-X-Y' IDs. Tests have been added for all header and ID format combinations. The error message in the PRD chat app was updated to document all supported user story header formats. Utility functions for stripping escape codes and disabling mouse tracking are now exported and tested.
Enhanced the PRD parser to recognize user story headers with version-style IDs (e.g., US-2.1.1, US-1.2) and added a fallback mechanism to extract stories from any header with a colon in the User Stories section. Updated related tests and user guidance to reflect the new supported formats. Improved escape code stripping to preserve legitimate semicolons in user input.
…h-tui into Issue-223-fix
Enhanced the parser to better distinguish valid US-XXX formats, exclude US-1 and US-9999 from generic pattern matching, and add a 3-tier fallback strategy to always extract user stories from markdown. Added ultimate fallback to parse any H2/H3/H4 headers with colons, skipping common non-story headers. Updated and expanded tests to cover new parsing logic and edge cases.
…h-tui into Issue-223-fix
Updated the user story header and normalization patterns to handle 'Feature X.Y' identifiers in a case-insensitive manner. This improves flexibility when parsing user story headers with different casing.
Resolved conflict in RunApp.tsx by keeping the PR's more sophisticated historical output loading logic that only loads for active tasks when no current iteration exists (resume scenario).
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
WalkthroughAdds tracker task preloading and lifecycle wiring to the TUI run loop, introduces engine auto-start control, expands PRD parsing to support H2–H4 headers with multiple ID formats and fallbacks, adds terminal escape-code sanitisation utilities, inserts pre-implementation steps and progress logging into tracker templates, and UI tweaks (progress bar, PRD guidance). Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as Client/CLI
participant Resume as resume.tsx
participant Tracker as Tracker Plugin
participant Engine as ExecutionEngine
participant TUI as RunApp/TUI
participant State as Persisted State
CLI->>Resume: runWithTui(engine, cwd, initialState, initialTasks)
Resume->>Tracker: load tasks (open|in_progress|completed)
Tracker-->>Resume: TrackerTask[]
Resume->>TUI: start UI with initialTasks prop
par Engine auto-start
Resume->>Engine: handleStart() (guarded, background)
Engine->>Engine: start background loop
end
TUI->>Engine: user actions (start / control)
Engine->>TUI: events (task:activated / task:completed / iteration:completed)
TUI->>State: update active-tasks & save (errors caught)
State-->>TUI: persisted
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #265 +/- ##
==========================================
+ Coverage 43.57% 43.69% +0.11%
==========================================
Files 94 94
Lines 28756 29040 +284
==========================================
+ Hits 12531 12688 +157
- Misses 16225 16352 +127
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/tui/components/RunApp.tsx`:
- Around line 2393-2403: The current checks can still load historical logs when
in the tasks view because selectedIteration is undefined; add a guard that
returns early if the currently selected task is the same as the task being
executed and there is no selectedIteration to prevent reading disk/stale output.
Specifically, before loading historical data add a condition that checks
selectedTask?.id === effectiveTaskId (and selectedTask?.status === 'active' if
you want to be strict) and that selectedIteration is null/undefined, and return
in that case; update the logic near the existing
isRunning/isActiveTask/hasCurrentIteration checks (references:
selectedIteration, selectedTask, effectiveTaskId, iterations, isRunning,
isActiveTask, hasCurrentIteration).
🧹 Nitpick comments (4)
src/setup/prompts.ts (2)
193-203: Minor: Backspace redraw could cause brief flicker.The double-write approach (clearing and redrawing the full line, then repositioning the cursor) works correctly but may cause visible flicker on slower terminals or with long input. Consider using ANSI cursor positioning sequences (
\x1b[nG) to move the cursor directly instead of redrawing twice.
138-144: Consider adding error handling for stdin.If
process.stdinemits an error whilst in raw mode, the cleanup function won't be called, potentially leaving the terminal in an inconsistent state. Consider adding an error listener that calls cleanup.♻️ Proposed fix to handle stdin errors
const cleanup = () => { process.stdin.removeListener('data', onData); + process.stdin.removeListener('error', onError); process.stdin.pause(); if (process.stdin.isTTY) { process.stdin.setRawMode(false); } }; + const onError = (err: Error) => { + cleanup(); + console.error(`${colors.yellow}Input error: ${err.message}${colors.reset}`); + resolve(options.default || ''); + }; const onData = (key: string) => {And add the listener after
onData:process.stdin.on('data', onData); + process.stdin.on('error', onError);src/prd/parser.ts (2)
94-117: Normalise case for standard IDs when matching is case-insensitive.
With/ion the header regex, lower-case IDs can flow through unchanged; normalising avoids mixed-case IDs downstream.Suggested change
- if (/^(US-\d{3}|[A-Z]+-\d+)$/.test(rawId)) { - return rawId; - } + if (/^(US-\d{3}|US-\d+(?:\.\d+)+|[A-Z]+-\d+)$/i.test(rawId)) { + return rawId.toUpperCase(); + }
472-477: Deduplicate the valid-ID regex to prevent drift.
The same pattern appears in both fallback parsers; extracting a shared constant keeps changes safe and consistent.Suggested change
- const validIdPattern = /^US-\d{3}$|^US-\d+(?:\.\d+)+$|^(?!US-)[A-Z]+-\d+$|^Feature\s+\d+\.\d+$/i; - if (validIdPattern.test(prefix)) { + if (VALID_STORY_ID_PATTERN.test(prefix)) { id = normalizeStoryId(prefix); } else { id = `STORY-${String(storyCounter).padStart(3, '0')}`; } ... - const validIdPattern = /^US-\d{3}$|^US-\d+(?:\.\d+)+$|^(?!US-)[A-Z]+-\d+$|^Feature\s+\d+\.\d+$/i; - if (validIdPattern.test(prefix)) { + if (VALID_STORY_ID_PATTERN.test(prefix)) { id = normalizeStoryId(prefix); } else { id = `STORY-${String(storyCounter).padStart(3, '0')}`; }You can place the shared constant with the other patterns, for example:
const VALID_STORY_ID_PATTERN = /^US-\d{3}$|^US-\d+(?:\.\d+)+$|^(?!US-)[A-Z]+-\d+$|^Feature\s+\d+\.\d+$/i;Also applies to: 550-552
Remove raw mode implementation in favor of simpler readline approach. The raw mode introduced several risks: - Terminal stuck in raw mode on crash - Missing stdin error handler - Hard process.exit(0) bypassing cleanup - Missing arrow key/readline shortcut support The simpler solution: - disableMouseTracking() prevents mouse codes at source - stripEscapeCodes() provides fallback sanitization - Standard readline handles all edge cases properly -84 lines, same protection, no footguns.
Add guard to skip historical data loading when: - Viewing the currently executing task (selectedTask.id === currentTaskId) - Task is active - No iteration is selected (tasks view, not iteration view) This prevents showing stale disk output when live output should be displayed.
Improve terminal input handling and task loading (supersedes subsy#235)
Summary
This PR contains the changes from #235 by @DeliLevente99, merged with current main and conflict resolved.
Original PR: #235 - All credit to the original contributor
Changes included:
stripEscapeCodes(),disableMouseTracking(), and raw modepromptText()for handling mouse tracking codestask:activated,task:completed) now matchesrun.tsxConflict resolution
RunApp.tsx: Kept the PR's more sophisticated historical output loading logic that only loads for active tasks when no current iteration exists (resume scenario)Test plan
Summary by CodeRabbit
New Features
Improvements
Tests