Skip to content

feat: generalize session markers to support Codex, Amp, etc#107

Merged
rsnodgrass merged 2 commits into
mainfrom
ryan/muscat-work
Mar 3, 2026
Merged

feat: generalize session markers to support Codex, Amp, etc#107
rsnodgrass merged 2 commits into
mainfrom
ryan/muscat-work

Conversation

@rsnodgrass
Copy link
Copy Markdown
Contributor

@rsnodgrass rsnodgrass commented Mar 3, 2026

Summary

Adds SupportsSession() and SessionID() methods to the Agent interface, enabling agent-agnostic session identification across all 15 coding agents and 2 orchestrators. Generalizes session marker naming and documentation from Claude-specific to agent-agnostic terminology. Wires the env-var fallback into the prime flow so Codex, Amp, and Claude Code sessions create markers even outside hook context.

Changes

  • agentx interface: Add AgentSession interface with SupportsSession() and SessionID() methods, embedded in Agent
  • Agent implementations: Implement on all agents — session-supporting agents return env var sources (Claude Code, Codex, Amp) or empty string for hook-only agents; non-session agents return false/empty
  • Prime flow wiring: Fallback to agent.SessionID(env) when hook stdin doesn't provide a session ID — enables Codex (CODEX_THREAD_ID), Amp (AMP_THREAD_URL), and Claude Code (CLAUDE_CODE_SESSION_ID) to create session markers natively
  • Session markers: Rename ClaudeSessionIDAgentSessionID, ReadClaudeHookInput()ReadAgentHookInput(), etc.
  • Documentation: Add comprehensive doc comments on marker lifecycle, purpose, and cleanup strategy (markers in /tmp are ephemeral, OS cleans on reboot)
  • Tests: Sweep test for all 15 agents' session support, unit tests for env-var agents, integration test for fallback path
flowchart TD
    A[ox agent prime] --> B{Hook stdin<br/>has session_id?}
    B -- Yes --> D[Use hook session ID]
    B -- No --> C{agent.SupportsSession()?}
    C -- Yes --> E[agent.SessionID env]
    C -- No --> F[No session tracking]
    E --> G{SessionID non-empty?}
    G -- Yes --> D
    G -- No --> F
    D --> H[Write/check session marker]
Loading

Verification

  • All short tests pass (go test -short ./cmd/ox/ ./pkg/agentx/...)
  • Integration test passes (TestSessionIDFallbackFromEnvVar)
  • Build succeeds with no new lint issues

Session Recording

View session recording

Co-Authored-By: SageOx ox@sageox.ai

Summary by CodeRabbit

Release Notes

  • New Features

    • Extended session support and idempotency tracking across multiple coding agents, with environment variable configuration options for agent session retrieval.
  • Improvements

    • Generalized session management architecture for improved cross-agent compatibility and fallback session ID handling.

- Add SupportsSession() and SessionID() to Agent interface
- Implement for all 15 agents and 2 orchestrators
- Rename Claude-specific to agent-agnostic: ClaudeSessionID→AgentSessionID
- Add comprehensive documentation on marker lifecycle and cleanup
- Update all callers and tests

Co-Authored-By: SageOx <ox@sageox.ai>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 3, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a09e3a2 and 9eb1a2f.

📒 Files selected for processing (28)
  • cmd/ox/agent_prime.go
  • cmd/ox/prime_idempotent_integration_test.go
  • cmd/ox/prime_idempotent_test.go
  • cmd/ox/prime_session_marker.go
  • cmd/ox/prime_session_marker_test.go
  • pkg/agentx/agent.go
  • pkg/agentx/agent_test.go
  • pkg/agentx/agents/aider.go
  • pkg/agentx/agents/amp.go
  • pkg/agentx/agents/amp_test.go
  • pkg/agentx/agents/claudecode.go
  • pkg/agentx/agents/claudecode_test.go
  • pkg/agentx/agents/cline.go
  • pkg/agentx/agents/codepuppy.go
  • pkg/agentx/agents/codex.go
  • pkg/agentx/agents/codex_test.go
  • pkg/agentx/agents/cody.go
  • pkg/agentx/agents/continue.go
  • pkg/agentx/agents/copilot.go
  • pkg/agentx/agents/cursor.go
  • pkg/agentx/agents/droid.go
  • pkg/agentx/agents/goose.go
  • pkg/agentx/agents/kiro.go
  • pkg/agentx/agents/opencode.go
  • pkg/agentx/agents/session_test.go
  • pkg/agentx/agents/windsurf.go
  • pkg/agentx/orchestrators/conductor.go
  • pkg/agentx/orchestrators/openclaw.go

📝 Walkthrough

Walkthrough

The PR generalizes Claude-specific session handling to agent-agnostic context across the codebase. It introduces a new AgentSession interface, renames session-related functions and types (ClaudeSessionID → AgentSessionID, ReadClaudeHookInput → ReadAgentHookInput, etc.), implements the new interface across all agent types, and updates tests accordingly.

Changes

Cohort / File(s) Summary
Core Session Marker Logic
cmd/ox/prime_session_marker.go, cmd/ox/prime_session_marker_test.go
Generalizes session handling from Claude-specific to agent-agnostic terminology. Replaces ClaudeSessionID with AgentSessionID, renames ReadClaudeHookInputReadAgentHookInput, WriteToClaudeEnvFileWriteToAgentEnvFile, and IsClaudeHookContextIsAgentHookContext. Updates marker path/status logic and public API signatures.
Agent Prime Idempotent Logic
cmd/ox/agent_prime.go, cmd/ox/prime_idempotent_test.go, cmd/ox/prime_idempotent_integration_test.go
Aligns session handling from Claude-specific to agent-centric context. Adds fallback to derive agent_session_id from environment if not provided by hook input. Updates marker reading/writing to use AgentSessionID. Changes environment write path from WriteToClaudeEnvFile to WriteToAgentEnvFile. Adds new test suite TestSessionIDFallbackFromEnvVar to verify env var fallback behavior.
Agent Interface Extension
pkg/agentx/agent.go, pkg/agentx/agent_test.go
Introduces new AgentSession interface with SupportsSession() bool and SessionID(env Environment) string methods. Updates Agent interface to embed AgentSession, extending agent capabilities.
Agent Implementations - Session Support
pkg/agentx/agents/amp.go, pkg/agentx/agents/amp_test.go, pkg/agentx/agents/claudecode.go, pkg/agentx/agents/claudecode_test.go, pkg/agentx/agents/codex.go, pkg/agentx/agents/codex_test.go
Adds session support methods to agents that manage sessions via environment variables. AMP returns AMP_THREAD_URL, ClaudeCode returns CLAUDE_CODE_SESSION_ID, Codex returns CODEX_THREAD_ID. Includes test coverage for session ID retrieval and fallback behavior.
Agent Implementations - Hook-Based Sessions
pkg/agentx/agents/copilot.go, pkg/agentx/agents/cursor.go, pkg/agentx/agents/cline.go, pkg/agentx/agents/droid.go, pkg/agentx/agents/kiro.go, pkg/agentx/agents/opencode.go, pkg/agentx/agents/windsurf.go
Adds session support methods returning true for SupportsSession() and empty string for SessionID(), indicating these agents provide session IDs via hook stdin JSON rather than environment variables.
Agent Implementations - No Session Support
pkg/agentx/agents/aider.go, pkg/agentx/agents/cody.go, pkg/agentx/agents/continue.go, pkg/agentx/agents/codepuppy.go, pkg/agentx/agents/goose.go
Adds session support methods returning false for SupportsSession() and empty string for SessionID(), indicating these agents do not have native session concepts.
Orchestrator Implementations
pkg/agentx/orchestrators/conductor.go, pkg/agentx/orchestrators/openclaw.go
Adds session support methods returning false for SupportsSession() and empty string for SessionID(), aligning orchestrators with the new interface requirements.
Session Support Test Suite
pkg/agentx/agents/session_test.go
Adds comprehensive unit tests covering session support across all agent implementations. Organizes tests into three categories: env-var agents (ClaudeCode, Codex, Amp), hook-only agents (Cursor, Windsurf, Copilot, Cline, Kiro, Droid, OpenCode), and non-session agents (Aider, Goose, Cody, Continue, CodePuppy).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

session, sageox

Poem

🐰 A rabbit's delight in agent sessions true,
From Claude-specific paths to vistas anew!
Each agent now learns its session to keep,
Whether from hooks or env vars so deep.
Generalized handling, a hop toward the sky! 🌟

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ryan/muscat-work

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 and usage tips.

Co-Authored-By: SageOx <ox@sageox.ai>
@rsnodgrass rsnodgrass changed the title feat: add SessionProvider to agentx.Agent, generalize session markers feat: generalize session markers to support Codex, Amp, etc Mar 3, 2026
@rsnodgrass rsnodgrass merged commit 7300ffa into main Mar 3, 2026
1 check was pending
@rsnodgrass rsnodgrass deleted the ryan/muscat-work branch March 3, 2026 21:12
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