Repository navigation
Add native Grok Vault resume support - #4398
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
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:
📝 WalkthroughWalkthroughAdds Grok as a built-in Vault agent: registry + detect rules, a Bash grok wrapper that installs cmux hooks and exports launch metadata, shell integrations, Grok session discovery from chat_history.jsonl (with CWD encoding), CLI resume wiring, transcript parsing tweaks, and related tests. ChangesGrok Vault Agent Integration
Sequence Diagram(s)sequenceDiagram
participant Shell
participant GrokWrapper as grok wrapper
participant CMux
participant RealGrok as real grok
Shell->>GrokWrapper: grok [args]
GrokWrapper->>GrokWrapper: find real grok in PATH
GrokWrapper->>GrokWrapper: detect CMUX_SURFACE_ID / socket
alt In cmux environment
GrokWrapper->>CMux: ping CMUX_SOCKET_PATH
CMux-->>GrokWrapper: pong
GrokWrapper->>CMux: hooks grok prompt-submit (install)
CMux-->>GrokWrapper: install result
GrokWrapper->>GrokWrapper: export CMUX_AGENT_LAUNCH_*
end
GrokWrapper->>RealGrok: exec real grok with original args + env
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related issues
Poem
Caution Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional.
❌ Failed checks (2 errors, 1 warning)
✅ Passed checks (14 passed)
✨ Finishing Touches📝 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: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Sources/SessionIndexRegisteredAgents.swift`:
- Around line 34-38: Canonicalize the working directory path (normalize ., ..,
trailing slashes and resolve symlinks) before encoding and after decoding so
equivalent paths map to the same folder: update
workingDirectory(fromProjectDirectoryName:) to produce a standardized path
(e.g., use URL(fileURLWithPath:).standardized.path or
FileManager.stringByResolvingSymlinksInPath then standardized) instead of just
trimming, and apply the same normalization in the places that call
encodedSessionCWD(...) and when decoding its result (affecting the code around
encodedSessionCWD, latestSessionId, and the other helper usages noted) so
encoding/decoding uses the canonical form consistently.
- Around line 325-327: When registration.sessionIdSource ==
.grokSessionDirectory you must derive native sessionId and cwd from
GrokSessionLocator.sessionRoots instead of falling back to candidate.url.path;
update the registered-agent path that builds the Published/RegisteredAgent
(where it currently uses candidate.url.path) to call
GrokSessionLocator.sessionRoots(registration: registration, cwdFilter:
cwdFilter), take the matched sessionsRoot entry, set sessionId to the native ID
returned by that locator and set cwd to the sessionsRoot path (or its .path
component) so resume (-r) and publishing use the native session identifier;
apply the same change in the other branch noted (around the 432-433 area) so
both code paths use GrokSessionLocator.sessionRoots results for sessionId and
cwd.
In `@Sources/SessionIndexView.swift`:
- Around line 1411-1415: transcriptRole(from:) returns .event for unknown roles
which is masking Grok's type fallback; change the role selection so that a
.event result from transcriptRole(from: object["role"] as? String) is treated as
"no explicit role" (nil) and allows grokTypeRole (from object["type"]) and
fallbackRole to be used; specifically update the logic around grokTypeRole and
the guard that sets role so that you first get an explicitRole =
transcriptRole(from: object["role"] as? String) and if explicitRole == .event
then use nil, then let role = explicitRole ?? grokTypeRole ?? fallbackRole
before returning.
In `@Sources/VaultAgentProcessScanner.swift`:
- Around line 792-803: In the .grokSessionDirectory branch do not
unconditionally call
GrokSessionLocator.latestSessionId(cwd:registration:environment:fileManager:);
first detect whether multiple live Grok processes share the same cwd (e.g.,
enumerate running processes and match by executable/name and
CMUX_AGENT_LAUNCH_CWD/PWD or similar environment markers) and only perform the
cwd-only fallback when exactly one Grok process is tied to that cwd; if more
than one is found, avoid returning the newest session ID (return nil / require
explicit -r/--resume) so separate panels do not collapse onto the same session.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 8882c137-9b07-4847-bdf1-cb749e9b30fc
📒 Files selected for processing (13)
CLI/cmux.swiftResources/bin/grokResources/shell-integration/cmux-bash-integration.bashResources/shell-integration/cmux-zsh-integration.zshSources/RestorableAgentTypes.swiftSources/SessionIndexRegisteredAgents.swiftSources/SessionIndexStore.swiftSources/SessionIndexView.swiftSources/VaultAgentProcessScanner.swiftSources/VaultAgentRegistry.swiftcmux.xcodeproj/project.pbxprojcmuxTests/CLINotifyProcessIntegrationRegressionTests.swiftcmuxTests/PiVaultAgentPersistenceTests.swift
There was a problem hiding this comment.
2 issues found across 13 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmuxTests/PiVaultAgentPersistenceTests.swift`:
- Around line 460-463: The test exposes inconsistent shell-quoting: built-in
Grok resume command in PiVaultAgentPersistenceTests compares an unquoted
executable/flags while registered agents use quoted components; inspect the
resumeShellCommand implementation (AgentResumeCommandBuilder or any
Grok-specific resume builder) and ensure all filesystem- or user-derived
components (executable names, arguments, env values) use SessionEntry.shellQuote
consistently; update the Grok path/executable branch so it quotes the executable
and argument tokens the same way as registered-agent code (or centralize quoting
in AgentResumeCommandBuilder/resumeShellCommand) and adjust tests to expect the
consistently-quoted form.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 687d403f-19e2-4279-bd1d-aa30ebc6fd00
📒 Files selected for processing (7)
CLI/cmux.swiftSources/SessionIndexRegisteredAgents.swiftSources/SessionIndexStore.swiftSources/SessionIndexView.swiftSources/VaultAgentProcessScanner.swiftSources/VaultAgentRegistry.swiftcmuxTests/PiVaultAgentPersistenceTests.swift
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Sources/SessionIndexView.swift`:
- Around line 1479-1485: The current logic lets transcriptRole(from:)'s fallback
of .event short-circuit later payload/message fallback; change the role
selection so that when roleFromType == .event you only accept it if the raw type
string actually equals "event" (case-insensitive) — otherwise treat roleFromType
as nil so parsedRole / payload/message fallback can run; update the block using
shouldUseGrokTypeRole, transcriptRole(from:), roleFromType, parsedRole and
fallbackRole to implement this check (i.e., only use roleFromType if it's
non-.event or the raw type string is literally "event").
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: c69d078f-0840-494e-8c36-6e07d09484b1
📒 Files selected for processing (3)
Resources/shell-integration/cmux-bash-integration.bashResources/shell-integration/cmux-zsh-integration.zshSources/SessionIndexView.swift
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmuxTests/SessionIndexViewTests.swift`:
- Around line 134-137: The test asserts for Claude's resumeCommand use
traditional shell syntax while Grok and other tests expect tokenized format;
update the two Claude assertions (the XCTAssertEqual calls around the earlier
Claude checks) to compare entry.resumeCommand against the tokenized form (e.g.,
each token individually quoted like 'env' 'VAR=value' 'command' ...) so they
match the Grok assertion style and SessionPersistenceTests examples, ensuring
you update the expected strings used in those XCTAssertEqual comparisons for the
Claude entries referenced in this test class.
In `@Sources/SessionIndexView.swift`:
- Around line 1082-1089: The grok role detection is currently limited to only
"user" and "assistant" so lines with type: "system", "developer", or tool-like
types are dropped; update shouldParseRawLine(...) and inferredGrokRole(...) to
mirror the broader set used by parseGenericMessage(...) (and
transcriptRole(from:)), including checks for "system", "developer", "tool_use"
and any other tool-like role strings you support, and also add those
corresponding Data needles to grokRoleNeedles if needed so the oversized-record
placeholder path stays consistent with transcriptRole(from:).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: edf07089-2683-45b4-9032-9b179cde5d84
📒 Files selected for processing (5)
Sources/SessionIndexModels.swiftSources/SessionIndexRegisteredAgents.swiftSources/SessionIndexView.swiftcmuxTests/PiVaultAgentPersistenceTests.swiftcmuxTests/SessionIndexViewTests.swift
There was a problem hiding this comment.
1 issue found across 11 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
Greptile SummaryRegisters Grok as a built-in Vault agent and wires up the full session-discovery, search, preview, and one-command resume pipeline. The previously-flagged CWD-filter discard bug (
Confidence Score: 5/5Safe to merge; the previously-flagged CWD-filter discard is fixed and regression-covered, the resume command quoting is sound, and no data-loss or security paths were found. All three bugs surfaced in earlier review rounds are addressed: alternate binary name detection, early-exit branch gate, and the CWD filter being silently discarded. The new single-quoted shell command builder handles special characters correctly throughout, and the shell integration changes are scoped to hardcoded names. Remaining findings are style-level: dead switch arms and a redundant needle sub-array in the transcript pre-filter. Sources/SessionIndexView.swift — the dead Important Files Changed
Sequence DiagramsequenceDiagram
participant Shell as User Shell
participant Wrapper as Resources/bin/grok
participant RealGrok as Real grok binary
participant CLI as cmux CLI
participant Store as SessionIndexStore
participant Locator as GrokSessionLocator
Shell->>Wrapper: grok [args]
Wrapper->>Wrapper: find_real_grok() — searches PATH for grok / grok-macos-aarch64 / grok-macos-aarch
Wrapper->>Wrapper: should_install_grok_hooks() — skip for passthrough flags / subcommands
Wrapper->>CLI: hooks grok install --yes (via CMUX_SOCKET_PATH)
Wrapper->>Wrapper: export CMUX_AGENT_LAUNCH_KIND / EXECUTABLE / ARGV_B64 / CWD
Wrapper->>RealGrok: exec real grok [args]
Note over Store,Locator: Vault search (agent .grok scope)
Store->>Locator: sessionRoots(registration, cwdFilter, env, observedGrokHomes)
Locator->>Locator: encodedSessionCWDs(cwd) — raw + standardizedPath variants
Locator-->>Store: [GrokSessionRoot] (sessionsRoot, grokHomeForResume)
Store->>Store: enumerateGrokHistoryCandidates / ripgrepMatchingPaths
Store->>Store: extractGrokSessionMetadata — title, model, branch
Store-->>Store: SessionEntry with AgentSpecifics.grok(model, permMode, sandbox, grokHome)
Store->>Store: "singleQuotedShellCommand — 'env' 'GROK_HOME=...' 'grok' '-r' 'session-id'"
Reviews (8): Last reviewed commit: "Fix Grok agent-scoped Vault filtering" | Re-trigger Greptile |
There was a problem hiding this comment.
1 issue found across 3 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
|
You're iterating quickly on this pull request. To help protect your rate limits, cubic has paused automatic reviews on new pushes for now—when you're ready for another review, comment |
|
Dogfood update from the tagged dev build:
CI: required checks are green at commit |
|
Follow-up for Cursor Bugbot's custom hook state finding:
Pushed as |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f95b25b. Configure here.
|
Follow-up for the latest review findings:
Pushed as |
Stale automated CodeRabbit review on an old commit. The inline feedback from this review has been addressed or superseded by later commits, review threads are resolved, and the latest CodeRabbit status is passing on head 12ae177.
|
Reviewer-blocker follow-up:
No code changes in this pass. |

Fixes #4394
Summary
~/.grok/sessions/<encoded-cwd>/<session>/chat_history.jsonlhistory.grok -r <id>.grokwrapper plus shell integration so cmux launches install Grok hooks automatically.Verification
git diff --check,plutil -lint cmux.xcodeproj/project.pbxproj,bash -n Resources/bin/grok,bash -n Resources/shell-integration/cmux-bash-integration.bash,zsh -n Resources/shell-integration/cmux-zsh-integration.zsh.Need help on this PR? Tag
@codesmithwith what you need.Note
Medium Risk
Adds new Grok session discovery/resume paths plus bundled shell wrappers, which can affect session search results and CLI launch behavior (PATH/hook installation) across users’ environments.
Overview
Adds native Grok Vault support: registers Grok as a built-in Vault agent and indexes
~/.grok/sessions/<encoded-cwd>/<session>/chat_history.jsonl(includingGROK_HOME-scoped roots and hook-observed homes) to enable Grok sessions to appear in search and be resumed.Updates resume + transcript handling for Grok and Grok-compatible registered agents: builds
grok -r <sessionId>resume commands with safer single-quoted argv/env formatting, adds Grok-specific transcript role inference/layout, and introduces a newgrokSessionDirectorysessionIdSourceplus multi-name process detection.Bundles a
grokCLI wrapper and extends bash/zsh shell integration to install bothclaudeandgrokwrappers, enabling automatic Grok hook installation and launch metadata capture; adds a Grok icon asset and expands test coverage for Grok loading and resume binding behavior.Reviewed by Cursor Bugbot for commit 12ae177. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Adds native Grok Vault indexing, search, and one‑command resume for the built‑in
grokagent and Grok‑compatible registered agents. Also scopes Grok agent searches to the current directory, adds a Grok icon, improves title extraction, honorsGROK_HOMEand custom hook state dirs, deduplicates sessions, and preservesGROK_HOMEin resume commands. Fixes #4394.New Features
grokas a built‑in Vault agent; detectgrok,grok-macos-aarch64, andgrok-macos-aarch; honorGROK_HOME.~/.grok/sessions/<encoded-cwd>/<session>/chat_history.jsonl; de‑dupe across roots and encoded CWD variants; include sessions from hook‑observed homes; honorCMUX_AGENT_HOOK_STATE_DIR.grok -r <id>commands and carryGROK_HOMEfor both built‑in and registeredgrokSessionDirectoryagents.Resources/bin/grokand a unified bash/zsh wrapper installer for bothclaudeandgrok; auto‑install hooks only for chat‑like runs; allow hook setup to create the config dir when missing.Bug Fixes
-r/--resume, including=forms.Written for commit 12ae177. Summary will update on new commits. Review in cubic
Summary by CodeRabbit
New Features
Refactor
Tests