Skip to content

Feature parity dec 2025#10

Merged
lancekrogers merged 36 commits intomainfrom
feature-parity-dec-2025
Jan 2, 2026
Merged

Feature parity dec 2025#10
lancekrogers merged 36 commits intomainfrom
feature-parity-dec-2025

Conversation

@lancekrogers
Copy link
Owner

@lancekrogers lancekrogers commented Jan 1, 2026

PR: CLI Feature Parity Release (v1.0.0)

Summary

This PR brings the Go SDK to feature parity with the Claude Code CLI, adding comprehensive abstractions for plugins, budget tracking, session management, streaming, subagent orchestration, and MCP integration.

What's Changed

New Features

Plugin System

  • Full plugin lifecycle with hooks: OnToolCall, OnMessage, OnComplete, Initialize, Shutdown
  • PluginManager for registering and coordinating multiple plugins
  • Built-in plugins:
    • LoggingPlugin - Configurable logging with secret sanitization
    • MetricsPlugin - Execution metrics collection
    • ToolFilterPlugin - Block specific tools
    • AuditPlugin - Record all tool calls for auditing

Budget Tracking

  • BudgetTracker with configurable spending limits
  • Warning threshold callbacks
  • Per-session and total spending tracking
  • Thread-safe concurrent access

Session Management

  • SessionManager for multi-turn conversation state
  • Automatic session resumption with ResumeID
  • Session lifecycle management

Streaming Support

  • StreamPrompt for real-time response processing
  • Proper handling of Claude CLI stream-json format
  • Channel-based message delivery

Subagent Orchestration

  • SubagentManager for spawning and managing child agents
  • Concurrent execution with configurable limits
  • Result aggregation and error handling

MCP Integration

  • Full Model Context Protocol support
  • MCP tool name validation (mcp__<server>__<tool>)
  • MCP server configuration

Additional CLI Flag Support

  • JSONSchema - Structured output validation with JSON Schema
  • FallbackModel - Automatic fallback when primary model is overloaded
  • Debug - Debug mode with category filtering

Code Quality Improvements

  • Refactored claude.go from ~800 lines to focused modules:
    • options.go - Configuration and validation
    • streaming.go - Stream handling
    • session.go - Session management
  • Extracted builtin_plugins.go - 313 lines of reusable plugins
  • Enhanced error handling with structured ClaudeError types

Testing

  • plugin_test.go: 929 lines covering all plugin scenarios
  • subagent_test.go: 570 lines with concurrent execution tests
  • budget_test.go: 214 lines with thread-safety tests
  • mcp_test.go: 815 lines for MCP validation

Documentation & Examples

  • 9 complete example programs:
    • examples/budget/ - Budget tracking demo
    • examples/mcp/ - MCP integration
    • examples/permissions/ - Permission modes
    • examples/plugins/ - Plugin system usage
    • examples/retry/ - Retry with backoff
    • examples/sessions/ - Session management
    • examples/streaming/ - Real-time streaming
    • examples/subagents/ - Subagent orchestration
    • examples/workflow/ - Complex workflow patterns
  • Demo GIF generation system with automated recording
  • docs/DEMOS.md documentation

Build System

  • Modular justfile system (.justfiles/)
  • just build, just test, just demo commands
  • just release module for release management

Breaking Changes

None. This release is fully backward compatible with v0.1.x.

Testing Checklist

  • All unit tests pass (just test all)
  • Integration tests pass
  • All example programs compile and run
  • Demo recordings verified
  • Linting passes (just lint)

Merge Checklist

  • Tests pass
  • Documentation reviewed
  • Examples verified
  • Tag v1.0.0 after merge

…ager

Adopts three major features from bnema/claude-agent-sdk-go fork:

Budget Tracking (budget.go):
- BudgetTracker for cumulative spending across sessions
- Warning thresholds with callbacks
- Per-session spending breakdown

Plugin System (plugin.go):
- Plugin interface with lifecycle hooks (OnToolCall, OnMessage, OnComplete)
- Priority-based execution ordering
- Pre-built plugins: Logging, Metrics, ToolFilter, Audit
- BasePlugin for easy extension

Subagent Management (subagent.go):
- SubagentManager for registering and executing specialized agents
- SubagentConfig with description, prompt, tools, model
- Pre-built templates: SecurityReviewer, CodeReviewer, TestAnalyst, etc.
- Session continuity support

Also updates:
- RunOptions with new fields (BudgetTracker, PluginManager, Agents, etc.)
- permissions.go with ToolInput, PermissionResult, PermissionCallback
- Pre-built permission callbacks (ReadOnlyCallback, SafeBashCallback, etc.)
- JSON response parsing to handle CLI's new array format
Examples added:
- sessions: Session management (SessionID, ForkSession, ephemeral)
- mcp: MCP configuration with builder pattern
- permissions: Permission callbacks and chaining
- retry: RetryPolicy and error recovery patterns
- streaming: StreamPrompt with channel handling
- workflow: CI/CD automation patterns

Build system:
- Removed Taskfile.yml (project uses just/make)
- Updated build.just with new example targets
- Fixed modular justfile path resolution

Code review fixes applied:
- Use math.Pow instead of custom pow function
- Added security warning for hardcoded credentials
1. Use errors.Join in PluginManager.Shutdown to collect all plugin
   shutdown failures instead of only returning the last error

2. Fix mutex-held-during-callback pattern in PluginManager callbacks
   (OnToolCall, OnMessage, OnComplete) using copy-under-lock to
   prevent potential deadlocks

3. Implement proper glob matching in ToolPermission.MatchesPattern
   using filepath.Match for standard patterns (*, ?, [...]) and
   custom logic for ** recursive directory matching

4. Use crypto/rand for backoff jitter calculation to prevent timing
   prediction and ensure cryptographically secure randomization
- Expand dangerous package tests from 41.5% to 90.4%
  - Add BYPASS_ALL_PERMISSIONS context and variant tests
  - Add DANGEROUS_RunWithEnvironment tests
  - Add GetSecurityWarnings with MCP debug tests
  - Add AllProductionEnvChecks test cases
  - Replace custom containsString helper with strings.Contains

- Add comprehensive context cancellation tests to claude package
  - TestRunPromptCtx_ContextCancellation
  - TestRunPromptCtx_ContextDeadlineExceeded
  - TestStreamPrompt_ContextCancellation
  - TestStreamPrompt_ContextDeadline
  - TestRunFromStdinCtx_ContextCancellation
  - TestRunOptionsTimeout
  - TestContextPropagationThroughMethods

- Add MCP configuration error path tests
  - TestParseMCPConfig_InvalidJSONVariants
  - TestLoadMCPConfigFile_Errors
  - TestMCPConfig_Merge_EdgeCases
  - TestMCPConfig_GetServer_EdgeCases
  - TestParseMCPConfig_NullJSON

Coverage: 82.9% (claude), 90.4% (dangerous)
Extract claude.go into smaller, focused files:

- options.go: RunOptions struct, OutputFormat, PermissionMode,
  PreprocessOptions, validation helpers, RetryPolicy

- session.go: Session management (GenerateSessionID, ValidateSessionID,
  RunWithSession, RunEphemeral, ForkAndRun methods)

- streaming.go: Message type and StreamPrompt method

This refactoring:
- Reduces claude.go from 1019 lines to 487 lines
- Improves code organization and maintainability
- Maintains 100% backward compatibility (no API changes)
- All tests pass with same coverage (82.9%/90.4%)
Move pre-built plugin implementations from plugin.go to dedicated file:

- LoggingPlugin: Tool call and message logging with secret redaction
- MetricsPlugin: Execution metrics collection
- ToolFilterPlugin: Tool blocking by name
- AuditPlugin: Audit trail recording

Also moved supporting code:
- secretPatterns regex patterns
- truncateString, redactSecrets, getCurrentTimestamp helpers

This refactoring:
- Reduces plugin.go from 634 lines to 327 lines
- Separates core interface/manager from built-in implementations
- Maintains 100% backward compatibility
- All tests pass with same coverage (82.9%/90.4%)
- Full README.md rewrite covering all SDK features including plugins,
  budget tracking, subagents, session control, MCP, retry, and permissions
- Update demo README with 4 new interactive demos
- Add Makefile and justfile targets for all 9 demos
- Fix sessions demo GenerateSessionID signature (returns 1 value)
- Fix permissions demo PermissionMode constant names
- Add new demo modules to go.work workspace
- Replace fmt.Print/Println with os.Stdout.WriteString for documentation
  blocks containing Printf format specifiers (avoids go vet false positives)
- Remove redundant trailing newlines from multi-line string literals
- All examples now pass go vet without warnings
- Add scripts/record-demo-gif.sh for automated GIF recording
- Add 9 demo scripts in scripts/demo-scripts/ for each SDK feature
- Add GIF commands to .justfiles/demos.just (gif, gif-all, gif-list)
- Create docs/DEMOS.md with sections for each demo
- Create docs/gif/ directory for storing generated GIFs

Uses asciinema + agg for terminal recording and GIF conversion.
Generate GIFs with: just demo gif <name> or just demo gif-all
Replace demo shell scripts with input files for recording actual Go demos:
- Delete scripts/demo-scripts/*.sh (code snippet display scripts)
- Add scripts/demo-inputs/*.txt (input for real demo recordings)
- Update record-demo-gif.sh to build and run real Go binaries
- Update docs/DEMOS.md to reflect new approach

The GIF recordings now capture real Claude API interactions instead of
static code snippets, showing actual SDK functionality in action.
@lancekrogers lancekrogers merged commit 8ebda5c into main Jan 2, 2026
1 check passed
@lancekrogers lancekrogers deleted the feature-parity-dec-2025 branch January 2, 2026 02:00
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