Skip to content

feat: add Cortex Code session support#284

Merged
wesm merged 5 commits intowesm:mainfrom
andrewwowens:feat/cortex-support
Apr 8, 2026
Merged

feat: add Cortex Code session support#284
wesm merged 5 commits intowesm:mainfrom
andrewwowens:feat/cortex-support

Conversation

@andrewwowens
Copy link
Copy Markdown
Contributor

Summary

Adds complete parser and sync support for Snowflake Cortex Code sessions.

Changes

Backend

  • Parser (internal/parser/cortex.go): Complete session parser handling both embedded history and split-file formats
    • Parses messages with tool calls and tool results
    • Filters internal blocks and system reminders
    • Supports backup file detection and skipping
    • Extracts session metadata and timestamps from both .json and .history.jsonl files
  • Types (internal/parser/types.go): Added AgentCortex constant and registry entry
  • Sync Engine (internal/sync/engine.go): Added processCortex function and wired into agent switch

Frontend

  • Agent Definitions (frontend/src/lib/utils/agents.ts): Added Cortex with cyan color and "Cortex Code" label

Documentation

  • README.md: Added Cortex Code to supported agents table

Session Discovery

  • Default directory: ~/.snowflake/cortex/conversations/
  • Environment variable: CORTEX_DIR
  • Config key: cortex_dirs
  • ID prefix: cortex:

File Format Support

Handles both Cortex session formats:

  1. Embedded history: Large .json files with history array
  2. Split-file format: Metadata .json + .history.jsonl companion file
  3. Backup files: Automatically skips .back.*.json files

Testing

Tested with real Cortex sessions:

  • ✅ 12 sessions discovered and synced
  • ✅ 2,164 messages parsed
  • ✅ 1,288 tool calls extracted and categorized
  • ✅ Both file formats working correctly
  • ✅ Backup files properly skipped
  • ✅ Frontend displaying sessions with correct metadata

Screenshots

Session list showing Cortex sessions with cyan badge alongside Claude and Codex sessions.

Add complete parser and sync support for Snowflake Cortex Code sessions:

- Add AgentCortex type and registry entry to internal/parser/types.go
- Implement ParseCortexSession parser in internal/parser/cortex.go:
  - Handle split-file format (.json + .history.jsonl)
  - Parse messages with tool calls and tool results
  - Filter internal blocks and system reminders
  - Support backup file detection and skipping
  - Extract session metadata and timestamps
- Add processCortex function to sync engine (internal/sync/engine.go)
- Wire up Cortex agent in sync engine switch statement
- Add Cortex to frontend agent definitions with cyan color
- Update README with Cortex directory and env var

Session discovery path: ~/.snowflake/cortex/conversations/
Environment variable: CORTEX_DIR

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@roborev-ci
Copy link
Copy Markdown

roborev-ci bot commented Apr 6, 2026

roborev: Combined Review (b1eabeb)

Verdict: Changes are not ready to merge; there is one High-severity sync/cache regression in the new Cortex session handling.

High

  • Cortex sessions will bypass sync caching and be reparsed on every sync
    • Location: internal/parser/cortex.go#L405, internal/parser/cortex.go#L497, internal/sync/engine.go#L1897
    • Problem: Split Cortex sessions persist ParsedSession.File metadata from <uuid>.history.jsonl, while discovery and sync skip/hash logic still operate on <uuid>.json. That makes the stored path/mtime/size inconsistent with the file the sync engine checks, so shouldSkipByPath will never match for split sessions and they can be reparsed on every sync tick.
    • Fix: Keep ParsedSession.File aligned with the discovered .json file, or update discovery/hash/skip logic so it consistently uses the .history.jsonl companion when present.

Synthesized from 3 reviews (agents: codex, gemini | types: default, security)

Keep ParsedSession.File aligned with the discovered .json file
instead of the .history.jsonl companion. The sync engine's
shouldSkipByPath checks the discovered file against stored
metadata, so they must match for caching to work.

This fixes a High-severity issue where split Cortex sessions
would bypass sync caching and be reparsed on every sync tick.

Fixes roborev feedback on PR wesm#284.
@roborev-ci
Copy link
Copy Markdown

roborev-ci bot commented Apr 6, 2026

roborev: Combined Review (5d1e019)

Verdict: 2 medium-severity issues should be addressed before merge.

Medium

  • internal/parser/cortex.go:537 / internal/parser/cortex.go:552: FindCortexSourceFile validates sessionID before stripping the optional cortex: prefix, so IDs stored as cortex:<uuid> fail lookup even though the function appears intended to accept that form. Trim the prefix before calling IsValidSessionID.

  • internal/parser/cortex.go:352: When a split session has no embedded history, failures reading the companion .history.jsonl file are silently treated as “session missing” by returning nil, nil, nil. This can hide permission errors or transient I/O failures and cause sessions to disappear from sync without an actionable error. Only suppress os.IsNotExist; propagate other read errors.


Synthesized from 3 reviews (agents: codex, gemini | types: default, security)

wesm and others added 3 commits April 8, 2026 14:56
Strip the "cortex:" prefix before calling IsValidSessionID in
FindCortexSourceFile so prefixed IDs are accepted. Propagate non-ENOENT
errors from reading .history.jsonl instead of treating all failures as
"session missing". Add comprehensive test suite for the Cortex parser.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
classifyOnePath had no Cortex branch, so watcher-driven SyncPaths
ignored Cortex files entirely. Add classification for <uuid>.json and
remap <uuid>.history.jsonl events back to the metadata .json file.

Populate ParsedToolResult.ContentLength for Cortex tool results so
analytics and fingerprinting work correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@roborev-ci
Copy link
Copy Markdown

roborev-ci bot commented Apr 8, 2026

roborev: Combined Review (df9f864)

Verdict: No medium-or-higher issues found; this change looks clean based on the submitted reviews.


Synthesized from 3 reviews (agents: codex, gemini | types: default, security)

@wesm wesm merged commit 89109f9 into wesm:main Apr 8, 2026
9 of 10 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.

2 participants