feat: preserve agent options across session restore - #3302
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughNative agent detection now records resume options from detected processes. The options are stored in terminal state and pane snapshots. Restore planning revalidates them against the active manifest before replay. ChangesAgent resume options
Estimated code review effort: 4 (Complex) | ~60 minutes Merge Risk: 🔵 Low · up to Session restore may replay malformed agent options for command lines containing adjacent shell operators or embedded quotes. The bounded issue should receive owner follow-up or explicit acceptance before merge. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b89abf00-3445-4b66-991c-ff65345abb17
📒 Files selected for processing (38)
docs/next/website/src/content/docs/session-state.mdxscripts/agent_detection_manifest_check.pysrc/agent_resume_options.rssrc/app/actions.rssrc/app/agent_resume.rssrc/app/api.rssrc/detect/manifest.rssrc/detect/manifest/tests.rssrc/detect/manifest_update.rssrc/detect/manifests/claude.tomlsrc/detect/manifests/codex.tomlsrc/detect/manifests/cursor.tomlsrc/detect/manifests/droid.tomlsrc/detect/manifests/github-copilot.tomlsrc/detect/manifests/hermes.tomlsrc/detect/manifests/kimi.tomlsrc/detect/manifests/omp.tomlsrc/detect/manifests/opencode.tomlsrc/detect/manifests/pi.tomlsrc/detect/mod.rssrc/events.rssrc/main.rssrc/pane.rssrc/persist/restore.rssrc/persist/snapshot.rssrc/terminal/state.rswebsite/agent-detection/claude.tomlwebsite/agent-detection/codex.tomlwebsite/agent-detection/cursor.tomlwebsite/agent-detection/droid.tomlwebsite/agent-detection/github-copilot.tomlwebsite/agent-detection/hermes.tomlwebsite/agent-detection/index.tomlwebsite/agent-detection/kimi.tomlwebsite/agent-detection/muse.tomlwebsite/agent-detection/omp.tomlwebsite/agent-detection/opencode.tomlwebsite/agent-detection/pi.toml
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Greptile SummaryThe PR preserves manifest-allowlisted agent options across native session restoration while revalidating them against the active policy.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| src/detect/mod.rs | Extracts allowlisted options from detected direct and wrapped agent invocations, including the corrected Windows bundled Cursor layout. |
| src/agent_resume_options.rs | Implements narrow filtering for declared flags and single-value options while dropping unknown and positional arguments. |
| src/pane.rs | Publishes option changes from process probes and clears stale values when a different invocation has unreadable argv. |
| src/persist/snapshot.rs | Adds per-pane resume options to serialized session state. |
| src/persist/restore.rs | Revalidates saved options and applies them to canonical native resume plans. |
| src/detect/manifest.rs | Extends the manifest contract, validation, cache, and reload behavior with resume-option policies. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
P[Foreground agent process] --> D[Detect agent and invocation]
D --> F[Filter argv through active manifest]
F --> S[Persist options with pane snapshot]
S --> V[Revalidate against manifest at restore]
V --> R[Append options to native resume command]
Reviews (4): Last reviewed commit: "fix: preserve options through command wr..." | Re-trigger Greptile
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3aa94fcd-766b-4a3b-bd6c-e092779581af
📒 Files selected for processing (1)
src/detect/mod.rs
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 71dd77e2-3cb7-44bc-8a01-99985fcdaaf5
📒 Files selected for processing (1)
src/detect/mod.rs
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: de04983c-2874-4332-95fe-522166352ce7
📒 Files selected for processing (1)
src/detect/mod.rs
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
| let mut args = Vec::new(); | ||
| while let Some((token, next)) = command_text_token(rest) { | ||
| let token = token.trim(); | ||
| if matches!(token, "&" | "&&" | "|" | "||" | ";") { | ||
| break; | ||
| } | ||
| args.push(token.to_string()); | ||
| rest = next; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Tokenize attached shell operators and embedded quotes.
Line 576 only recognizes a separator when it is a complete whitespace-delimited token. PowerShell command text such as & 'C:\Tools\claude.ps1' --name worker; echo done parses worker; as the --name value instead of stopping at ;. Inline quoted values such as --name='worker one' also split incorrectly. The restore path can then replay a malformed resume option.
Recognize command operators outside quotes without requiring surrounding whitespace. Support quote delimiters within an option token. Add regression tests for both forms.
Summary
This replaces the arbitrary-argv approach from #2614 with a narrow manifest-owned policy. Unknown options, positional prompts, environment variables, wrappers, and arbitrary commands are not persisted.
The capture path reuses the foreground process argv already collected by agent detection. Cached options are tied to the detected agent invocation and cleared when a different process generation cannot provide readable argv.
Related discussions: #1080, #1308, #1430, #2027, #2104.
Verification
just check--name <value>survives detection, serialization, restore planning, and shell quoting