Skip to content

feat: preserve agent options across session restore - #3302

Draft
ogulcancelik wants to merge 5 commits into
masterfrom
feat/agent-resume-options
Draft

feat: preserve agent options across session restore#3302
ogulcancelik wants to merge 5 commits into
masterfrom
feat/agent-resume-options

Conversation

@ogulcancelik

Copy link
Copy Markdown
Collaborator

Summary

  • capture manifest-allowlisted flags and single-value options from each detected agent process
  • persist the options per pane and reapply them to the canonical native resume command
  • revalidate saved options against the active manifest at restore time
  • ship bundled and website policies for Claude, Codex, Pi, OpenCode, Hermes, OMP, Copilot, Cursor, Droid, and Kimi
  • support local and remote manifest updates through the existing hot-reload path

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
  • 3,546 Rust tests passed
  • Windows clippy passed
  • bundled/website manifest parity passed
  • focused contract verifies --name <value> survives detection, serialization, restore planning, and shell quoting

@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Native 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.

Changes

Agent resume options

Layer / File(s) Summary
Manifest contracts and declarations
scripts/agent_detection_manifest_check.py, src/detect/manifest.rs, src/detect/manifest_update.rs, src/detect/manifests/*, website/agent-detection/*, src/main.rs, src/events.rs
Manifests and validators now support resume_options. The manifest engine version advances to 4. The omp agent is added. Muse detection rules are added to the website manifests.
Process argument filtering
src/agent_resume_options.rs, src/detect/mod.rs, src/app/agent_resume.rs
Detected agent arguments are filtered to declared flags and valid option values. Wrapped-agent, Windows Cursor, separator, inline-value, and quoting tests cover the filtering paths.
Detection event and terminal state
src/pane.rs, src/app/actions.rs, src/app/api.rs, src/terminal/state.rs
Detection emits AppEvent::AgentResumeOptionsDetected, caches options on the terminal, deduplicates repeated values, and suppresses unrelated render and post-processing work.
Snapshot persistence and restore planning
src/persist/snapshot.rs, src/persist/restore.rs, docs/next/website/src/content/docs/session-state.mdx
Pane snapshots persist detected options. Restore planning matches the saved agent, revalidates options against the active manifest, and appends surviving options to native resume argv.

Estimated code review effort: 4 (Complex) | ~60 minutes

Merge Risk: 🔵 Low · up to 2315e

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 101 functions across 15 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: preserving agent options across session restore.
Description check ✅ Passed The description directly explains the implementation, policy constraints, manifest updates, persistence flow, restore behavior, and verification for the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/agent-resume-options

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kangal-bot kangal-bot added the ai-review Trigger automated AI reviews for pull requests admitted by the PR gate label Aug 27, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7b675f4 and 71cb877.

📒 Files selected for processing (38)
  • docs/next/website/src/content/docs/session-state.mdx
  • scripts/agent_detection_manifest_check.py
  • src/agent_resume_options.rs
  • src/app/actions.rs
  • src/app/agent_resume.rs
  • src/app/api.rs
  • src/detect/manifest.rs
  • src/detect/manifest/tests.rs
  • src/detect/manifest_update.rs
  • src/detect/manifests/claude.toml
  • src/detect/manifests/codex.toml
  • src/detect/manifests/cursor.toml
  • src/detect/manifests/droid.toml
  • src/detect/manifests/github-copilot.toml
  • src/detect/manifests/hermes.toml
  • src/detect/manifests/kimi.toml
  • src/detect/manifests/omp.toml
  • src/detect/manifests/opencode.toml
  • src/detect/manifests/pi.toml
  • src/detect/mod.rs
  • src/events.rs
  • src/main.rs
  • src/pane.rs
  • src/persist/restore.rs
  • src/persist/snapshot.rs
  • src/terminal/state.rs
  • website/agent-detection/claude.toml
  • website/agent-detection/codex.toml
  • website/agent-detection/cursor.toml
  • website/agent-detection/droid.toml
  • website/agent-detection/github-copilot.toml
  • website/agent-detection/hermes.toml
  • website/agent-detection/index.toml
  • website/agent-detection/kimi.toml
  • website/agent-detection/muse.toml
  • website/agent-detection/omp.toml
  • website/agent-detection/opencode.toml
  • website/agent-detection/pi.toml

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment thread src/detect/manifest.rs Outdated
Comment thread website/agent-detection/claude.toml Outdated
@greptile-apps

greptile-apps Bot commented Aug 27, 2026

Copy link
Copy Markdown

Greptile Summary

The PR preserves manifest-allowlisted agent options across native session restoration while revalidating them against the active policy.

  • Adds option extraction for directly invoked and safely recognized wrapped agent processes.
  • Persists captured options per pane and appends valid options to native resume commands.
  • Extends bundled and website manifests with agent-specific replay policies and hot-reload support.
  • Fixes Windows bundled Cursor extraction by recognizing its validated node.exe/index.js invocation and filtering arguments after the script.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

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]
Loading

Reviews (4): Last reviewed commit: "fix: preserve options through command wr..." | Re-trigger Greptile

Comment thread src/detect/mod.rs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 41d8e36 and 1b59410.

📒 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.

Comment thread src/detect/mod.rs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1b59410 and d43a7c7.

📒 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.

Comment thread src/detect/mod.rs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between d43a7c7 and 2315eac.

📒 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.

Comment thread src/detect/mod.rs
Comment on lines +575 to +582
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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

@ogulcancelik
ogulcancelik marked this pull request as draft August 27, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Trigger automated AI reviews for pull requests admitted by the PR gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants