Skip to content

Add Grok CLI backend and per-engine backend documentation#24

Merged
tony merged 12 commits into
masterfrom
grok-build
May 26, 2026
Merged

Add Grok CLI backend and per-engine backend documentation#24
tony merged 12 commits into
masterfrom
grok-build

Conversation

@tony
Copy link
Copy Markdown
Owner

@tony tony commented May 25, 2026

Summary

  • Add Grok CLI as agentgrep's fifth backend — prompt history, chat sessions, and session search index are all searchable out of the box
  • Add docs/backends/ section with a support matrix and per-engine pages documenting store layouts, adapter IDs, and record schemas for all five agents
  • Add 10 store catalog entries for Grok (3 with live discovery, 7 documentary-only) covering sessions, prompt history, search index, events, summaries, memory, logs, worktrees, and config
  • Add integration tests for all three Grok parsers: JSONL prompt history, JSONL chat transcripts, and SQLite FTS5 session index

Changes by area

Runtime (src/agentgrep/)

  • __init__.py: Register "grok" in AgentName and AGENT_CHOICES; add discover_grok_sources() honouring GROK_HOME env override; add parse_grok_prompt_history, parse_grok_chat_history, parse_grok_session_search_db parsers; wire adapter dispatch in iter_source_records()
  • stores.py: Add "grok" to AgentName literal
  • store_catalog.py: Add _GROK_STORES (10 descriptors), bump catalog_version to 4
  • mcp/_library.py: Add "grok" to AgentName, AgentSelector, and 3 adapter IDs to KNOWN_ADAPTERS
  • mcp/models.py: Add "grok" to all 5 agent Literal fields
  • query/registry.py: Add "grok" to the agent field's enum_values

Tests

  • tests/samples/grok/: Redacted JSONL fixtures for prompt history and chat sessions
  • tests/test_agentgrep.py: 5 new tests — env-override discovery, prompt history parsing, chat session extraction, empty-content filtering, SQLite FTS5 index parsing
  • tests/test_stores.py: Add "grok" to KNOWN_AGENTS so existing catalog invariant tests cover the new entries

Documentation

  • docs/backends/: New section with index.md (support matrix) and per-engine pages (codex.md, claude.md, cursor.md, gemini.md, grok.md)
  • docs/dev/storage-catalog.md: Add Grok CLI section documenting path layout and adapter notes
  • docs/index.md: Add Backends grid card and toctree entry
  • docs/dev/index.md: Update storage catalogue card to mention Grok

Design decisions

  • Catalog-driven discovery: discover_grok_sources delegates to discover_from_catalog() — no custom file-walking logic. The generic machinery handles globs, file checks, and deduplication identically to all other agents.
  • All record types emitted: The chat history parser emits system, user, assistant, tool_use, and tool_result records rather than filtering to user+assistant. This maximises searchable content and matches the Codex session parser's approach.
  • Unix → ISO-8601 timestamp conversion: The SQLite parser converts updated_at (unix seconds) to ISO-8601 for consistency with all other adapters' timestamp fields.

Test plan

  • test_discover_grok_sources_honours_grok_home_envGROK_HOME env override takes priority over ~/.grok
  • test_search_grok_prompt_history — JSONL audit log yields kind="history", role="user" with correct session_id
  • test_search_grok_chat_history_session — JSONL transcripts yield user + assistant records with correct conversation_id
  • test_search_grok_chat_history_drops_empty_content — records with empty/whitespace content are filtered
  • test_search_grok_session_search_db — SQLite FTS5 index yields titled records with ISO-8601 timestamps
  • Existing catalog invariant tests pass with grok entries (test_stores.py)
  • Full suite passes
  • just build-docs builds cleanly with new backend pages

tony added 3 commits May 25, 2026 17:31
…and parsers

why: Grok CLI stores chat transcripts and prompt history under
~/.grok/sessions/ in a layout similar to Codex — URL-encoded project
paths, per-session UUIDs, JSONL transcripts, and a SQLite search
index. Adding Grok as a fifth backend gives agentgrep read-only
search across all major coding-agent CLIs.

what:
- Register "grok" in AgentName, AGENT_CHOICES, AgentSelector,
  KNOWN_ADAPTERS, MCP models (5 Literal fields), and the query
  registry enum_values
- Add 10 StoreDescriptor entries to store_catalog.py (3 searchable
  with DiscoverySpec, 7 documentary-only), bump catalog_version to 4
- Add discover_grok_sources() honouring GROK_HOME env override
- Add parse_grok_prompt_history (JSONL audit log),
  parse_grok_chat_history (JSONL full transcripts), and
  parse_grok_session_search_db (SQLite FTS5 index) parsers
- Wire adapter dispatch in iter_source_records()
why: The new grok parsers and discovery function need end-to-end
verification — env-override priority, record extraction from all
three store formats, and empty-content edge cases.

what:
- Add test fixtures: tests/samples/grok/grok.prompt_history/ and
  tests/samples/grok/grok.sessions/ with redacted sample records
- Add test_discover_grok_sources_honours_grok_home_env
- Add test_search_grok_prompt_history (JSONL audit log)
- Add test_search_grok_chat_history_session (JSONL transcripts)
- Add test_search_grok_chat_history_drops_empty_content
- Add test_search_grok_session_search_db (SQLite FTS5 index)
- Update KNOWN_AGENTS in test_stores.py to include "grok"
why: Users and adapter authors need a single reference showing which
stores each agent exposes, what agentgrep searches by default, and
what the record schemas look like — without reading source code.

what:
- Create docs/backends/ with index.md (support matrix table) and
  per-engine pages: codex.md, claude.md, cursor.md, gemini.md, grok.md
- Add Grok CLI section to docs/dev/storage-catalog.md
- Wire backends/index into docs/index.md grid and toctree
- Update dev/index.md card description to mention Grok
tony added 3 commits May 25, 2026 19:10
why: datetime.fromtimestamp() raises ValueError/OverflowError on NaN,
infinity, or out-of-range timestamps that pass the value <= 0 guard.
In parse_grok_session_search_db this escapes the sqlite3.DatabaseError
handler and crashes the entire search iteration.

what:
- Reject bool values (bool is a subclass of int in Python)
- Wrap fromtimestamp() in try/except (ValueError, OSError,
  OverflowError) returning None on failure
- Add parametrized test covering NaN, inf, extreme int, bool, None,
  and string inputs
why: MCP clients read the server instructions on handshake to decide
which queries to route. Without Grok in the TRIGGERS and SCOPE
strings, clients won't invoke agentgrep for Grok-related history
queries.

what:
- Add Grok to _INSTR_HEADER agent list
- Add Grok to _INSTR_SCOPE trigger examples
…ntries

why: The module-level OBSERVED_AT (2026-05-17) predates the Grok store
observation. Each Grok descriptor's observed_version string says
"observed 2026-05-25" but observed_at inherited the stale date.

what:
- Add _GROK_OBSERVED_AT = datetime.date(2026, 5, 25)
- Replace observed_at=OBSERVED_AT with observed_at=_GROK_OBSERVED_AT
  in all 9 Grok store descriptors
… page

why: Several user-facing strings still listed only four agents after
the Grok backend landed.

what:
- CLI_DESCRIPTION: "…Codex, Claude, Cursor, Gemini, and Grok…"
- Query registry docstring table: add grok to agent enum values
- docs/tui/index.md: add Grok to the stores list
@tony
Copy link
Copy Markdown
Owner Author

tony commented May 26, 2026

Code review

Found 2 issues:

  1. pyproject.toml description and keywords omit Grok. The PR adds Grok as a fifth backend but the package metadata still lists only four agents: (Codex, Claude Code, Cursor, Gemini) in the description and ["ai", "codex", "claude", "cursor", "gemini", ...] in keywords. Users discovering the package via PyPI search won't know Grok is supported.

version = "0.1.0a7"
description = "Read-only search for local AI agent prompts and history (Codex, Claude Code, Cursor, Gemini)"
requires-python = ">=3.14,<4.0"

agentgrep/pyproject.toml

Lines 23 to 25 in bb4115c

keywords = ["ai", "codex", "claude", "cursor", "gemini", "mcp", "search", "agent-history"]
readme = "README.md"

  1. README.md description omits Grok. The opening line lists "Codex, Claude Code, Cursor, and Gemini" without Grok, despite the PR adding full backend support.

agentgrep/README.md

Lines 7 to 8 in bb4115c

Read-only search for local AI agent prompts and history across Codex,
Claude Code, Cursor, and Gemini.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

tony added 4 commits May 25, 2026 19:59
why: Package metadata on PyPI still listed only four agents after
the Grok backend landed — users searching for grok support would
not discover agentgrep.

what:
- Add Grok to pyproject.toml description and keywords
- Add Grok to README.md opening description
why: The catalog-level captured_at still pointed at the pre-Grok
snapshot date (2026-05-17) while the Grok stores were observed
eight days later. The field documents when the catalog was last
updated, so it should reflect the most recent observation.

what:
- Change CATALOG captured_at from OBSERVED_AT to _GROK_OBSERVED_AT
why: The function is a pure offline helper that the project
convention requires to carry inline doctests.

what:
- Add Examples section with valid input, zero, and NaN cases
why: sqlite3 is already imported at module level; the function-local
import adds no cold-start benefit for a stdlib module in a test file.

what:
- Remove `import sqlite3` from test_search_grok_session_search_db
why: The test-local AgentName literal, PRIMARY_FIXTURES tuple, and
adapter-id assertions were not updated when the grok backend landed,
leaving gaps in type coverage and fixture validation.

what:
- Add "grok" to AgentName literal in test_agentgrep.py
- Add grok.prompt_history and grok.sessions to PRIMARY_FIXTURES
- Add explicit grok adapter ID assertions in
  test_runtime_adapter_ids_match_catalogue_discovery
@tony tony merged commit 77fe89c into master May 26, 2026
3 checks passed
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.

1 participant