Skip to content

feat(grok): add Grok CLI integration#281

Open
hyiiiii wants to merge 1 commit into
wxtsky:mainfrom
hyiiiii:agent/feat-grok-cli
Open

feat(grok): add Grok CLI integration#281
hyiiiii wants to merge 1 commit into
wxtsky:mainfrom
hyiiiii:agent/feat-grok-cli

Conversation

@hyiiiii

@hyiiiii hyiiiii commented Jul 23, 2026

Copy link
Copy Markdown

Summary

  • Add local Grok CLI support through $GROK_HOME/hooks/codeisland.json.
  • Normalize Grok lifecycle, tool, failure, notification, subagent, and compaction events while suppressing duplicate Claude/Cursor-compatible hooks imported by Grok.
  • Discover Grok processes and session summaries, including cardinality-preserving one-to-one matching for parallel sessions in the same working directory.
  • Recover model metadata and recent messages from chat_history.jsonl.
  • Add Grok source metadata, settings and panel routing, the classic February 2025 geometric icon, and English/Chinese documentation.

Background

Grok Build exposes native global hooks under $GROK_HOME/hooks and stores sessions under $GROK_HOME/sessions. It can also import Claude/Cursor hook configurations, so forwarding every compatible copy produces duplicate lifecycle events. Interactive and one-shot Grok processes can share a working directory, which requires a real one-to-one assignment rather than a simple CWD lookup or greedy match.

Verified Grok version

grok 0.2.106 (bde89716f679)

Duplicate-delivery policy

GrokHookForwardingPolicy is the production source of truth for all 14 managed events. In a Grok hook runtime (GROK_SESSION_ID or GROK_HOOK_EVENT), only the explicitly managed --source grok invocation is forwarded; imported untagged, Claude, and Cursor copies are suppressed. Outside Grok, existing sources retain their prior behavior.

Scope and limitations

  • This change supports local macOS Grok CLI sessions only; remote-host hook installation is not included.
  • CodeIsland observes Grok PreToolUse events, while permission decisions remain in the terminal.
  • If CodeIsland starts during an already-running response, a recovered session may initially appear idle until the next native hook event.
  • Grok's over-255-byte encoded-CWD slug+hash session-directory fallback is not included in this PR.
  • A long-running process that creates a much later /new session may be rejected by the conservative process-start matching window.

Verification

  • Swift frontend parse for all changed Swift files.
  • swift build -c release --product CodeIsland.
  • swift build -c release --product codeisland-bridge.
  • git diff --check origin/main..HEAD.
  • Automated policy matrix covers all 14 events with managed Grok, imported untagged, Claude, and Cursor invocations; exactly one delivery per lifecycle event.
  • Production bridge/socket E2E: 14/14 managed Grok events delivered exactly once, 42/42 imported duplicate invocations suppressed, and 6/6 non-Grok/blank-environment regressions delivered normally.
  • Standalone policy harness passed against the final source.
  • Added a counterexample proving the old greedy PID/session matcher could drop a viable session; deterministic augmenting-path matching now preserves maximum assignment cardinality and passes the matching harness.
  • Hook install is idempotent and matcher-free; uninstall preserves unrelated user entries.
  • Manually exercised a Grok 0.2.106 one-turn run: SessionStart, UserPromptSubmit, and Stop were delivered once each, the current PID won over an older same-CWD process, and the session was removed after process exit.
  • swift test --filter 'GrokHookForwardingPolicyTests|GrokSupportTests' — this machine only has CommandLineTools and cannot import XCTest; CI or a full Xcode installation is required to execute the suite.

The release build emits the pre-existing Swift 6 warning for the captured cache variable in AppState.refreshClaudeUsageIfStale(); this PR does not introduce that warning.

Asset provenance

The static mark geometry follows Wikimedia Commons' “Grok logo used since February 2025”, attributed there to X.AI Corp. Wikimedia classifies the geometry as public domain for copyright purposes and separately identifies it as trademarked. The mark is rendered without animation or geometric modification, consistent with the xAI Brand Guidelines.

“Grok” and its logo are trademarks of xAI. CodeIsland is not affiliated with or endorsed by xAI.

@wxtsky

wxtsky commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Nice scope control on the draft (dedup of imported Claude/Cursor hooks and PID/session one-to-one matching are exactly the right hard parts to call out). Two asks for when you mark it ready: (1) the suppression of duplicate imported hooks is the riskiest bit — a test that simulates Grok having imported a Claude-compatible hook config and asserts single delivery per lifecycle event would make that reviewable; (2) please note which Grok CLI version you verified against in the PR body (you mention 0.2.106 — keep that updated if you re-test). Will do a full review pass once it's out of draft.

@hyiiiii
hyiiiii force-pushed the agent/feat-grok-cli branch from ec56b36 to ec791bb Compare July 23, 2026 06:29
@hyiiiii
hyiiiii marked this pull request as ready for review July 23, 2026 07:22
@hyiiiii

hyiiiii commented Jul 23, 2026

Copy link
Copy Markdown
Author

Both requested follow-ups are now in:

  • Verified against grok 0.2.106 (bde89716f679) and recorded the exact version in the PR body.
  • Added an automated single-delivery matrix for all 14 managed lifecycle events. In a Grok runtime, the managed --source grok invocation is forwarded while imported untagged, Claude, and Cursor copies are suppressed; non-Grok behavior remains unchanged.

I also exercised the production bridge over a Unix socket: 14/14 managed events were delivered exactly once, 42/42 imported duplicates were suppressed, and 6/6 non-Grok/blank-environment regressions were delivered normally.

While covering parallel same-CWD sessions, I found that the original greedy assignment could drop a viable session. It now uses deterministic augmenting-path matching, with a regression test for that counterexample.

The PR is ready for the full review pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants