Skip to content

Pull Request: Integrate Trae Agent and Implement iFlow CLI Agent (Preview)#701

Open
wangxumarshall wants to merge 18 commits intoentireio:mainfrom
wangxumarshall:main
Open

Pull Request: Integrate Trae Agent and Implement iFlow CLI Agent (Preview)#701
wangxumarshall wants to merge 18 commits intoentireio:mainfrom
wangxumarshall:main

Conversation

@wangxumarshall
Copy link

Overview

This PR adds two key AI agent integrations to Entire CLI: Trae Agent (ByteDance's LLM-based software engineering agent) and iFlow CLI Agent, alongside a series of bug fixes, configuration optimizations, and test enhancements for the agent abstraction layer. All core agent interface implementations follow Entire's existing architecture and coding standards, with full hook lifecycle support, transcript parsing, and session management.

Key Features & Changes

1. Trae Agent Integration (Preview)

Full integration of ByteDance's Trae Agent with Entire's agent ecosystem, implementing all core and optional agent interfaces:

  • Implemented the Agent interface with full hook lifecycle support
  • Added new HookTypes (before_agent, after_agent, before_model, after_model, etc.) for Trae Agent's lifecycle
  • Supported JSON trajectory transcript format for session capture
  • Implemented ParseHookEvent for translating Trae Agent's native events to Entire's normalized lifecycle events
  • Added hook installation/uninstallation logic for Trae Agent's .trae/settings.json
  • Cleaned up invalid test cases (removed non-existent SupportsHooks()/GetSupportedHooks() method tests)

2. iFlow CLI Agent Full Implementation

Complete iFlow CLI agent integration with end-to-end session tracking and hook support:

  • Core Structs & Types: Defined settings, hooks, transcript structures and constants in types.go; implemented main agent struct and session management in iflow.go
  • Lifecycle Handling: Parsed iFlow's native hook events into Entire's normalized lifecycle events (lifecycle.go)
  • Hook Support: Implemented HookSupport interface for auto-installation of iFlow hooks; unified all hook configs to follow iFlow CLI spec (nested hooks array wrapper format)
  • Transcript Parsing: Extracted file modifications from iFlow's JSONL transcripts; added computeTranscriptPath() for fallback transcript path derivation (pattern: ~/.iflow/projects/<sanitized-repo-path>/<session-id>.jsonl)
  • Environment Variable Support: Added fallback for reading hook data from env vars (complementary to stdin JSON)
  • Configuration: Added .iflow/settings.json with full hook mappings for iFlow's key lifecycle events (Notification, PreToolUse, PostToolUse, SessionStart/End, etc.) and permission controls
  • Registry: Registered iFlow agent in Entire's agent registry with AgentNameIFlow and AgentTypeIFlow for auto-detection

3. Critical Bug Fixes

  • Hook Config Format: Fixed iFlow hook non-trigger issue by unifying all hook types to use iFlow's official IFlowHookMatcher nested format (replaced flat format for Stop/SubagentStop/SessionEnd/SetUpEnvironment)
  • Settings Loading: Fixed entire enable overwriting existing localDev settings by loading project settings before installing agent hooks (merged with CLI opts instead of direct use)
  • Interface Compliance: Fixed Trae Agent test cases to align with Entire's agent interface (removed tests for non-existent methods, updated to use HookSupport interface for hook-related tests)
  • Path Handling: Added context passing for WorktreeRoot access in parsing functions to ensure correct repo root resolution

4. Documentation & Configuration

  • Added IFLOW.md: Comprehensive architecture overview for the iFlow CLI agent (follows Entire's existing agent documentation standards)
  • Updated .gitignore: Added CLAUDE.md (local development file) to gitignore to prevent accidental commits
  • Added .iflow/settings.json: 86-line hook configuration file with all iFlow lifecycle events mapped to Entire's hook commands and basic permission controls (deny Read on ./.entire/metadata/**)

5. Test Enhancements

  • Added comprehensive unit tests for all iFlow agent components (hooks, lifecycle, transcript, types, core agent)
  • Added lifecycle tests for all iFlow hook types to cover edge cases
  • Improved type definitions with better JSON tags for more reliable unmarshaling
  • Implemented WriteHookResponse and added corresponding tests
  • Fixed whitespace formatting in common_test.go for consistent code style
  • All new tests follow Entire's test isolation standards (use temporary repos, parallel execution with t.Parallel())

6. Minor Refactors & Chores

  • Auto-registered iFlow package in hooks_cmd.go for seamless agent detection
  • Minor code cleanup in traeagent.go (removed unused code)
  • Fixed inconsistent whitespace in map literals after gofmt run
  • Merged latest entireio/cli:main branch to resolve conflicts

Agent Compatibility

  • All new agent implementations follow Entire's existing Agent interface (19 core methods) and optional interfaces (HookSupport, TranscriptAnalyzer)
  • Trae Agent and iFlow Agent work alongside Entire's existing supported agents (Claude Code, Gemini CLI, OpenCode, Cursor, Copilot CLI)
  • No breaking changes to existing agent integrations or Entire's core functionality

Test Coverage

  • All new Go files for Trae Agent and iFlow Agent have accompanying unit tests
  • 100% coverage for core agent methods (interface compliance)
  • Coverage for all hook lifecycle events and transcript parsing logic
  • All tests pass the Entire CI suite (mise run test:ci)

Notes

  1. This integration is marked as preview status - further testing and optimization may be required for production use
  2. iFlow CLI hook configuration strictly follows the official iFlow CLI documentation to ensure compatibility
  3. Trae Agent's JSON trajectory transcript format is fully supported for session capture and rewind
  4. No changes to Entire's core strategy/Checkpoint/Session systems - all new functionality is isolated to the agent abstraction layer

How to Test

  1. Clone the forked repo and check out this branch
  2. Run mise install && mise run build to build the CLI
  3. Enable the Trae/iFlow agent with entire enable --agent traeagent/entire enable --agent iflow
  4. Run mise run test:ci to verify all tests pass
  5. Test end-to-end session tracking with Trae Agent/iFlow CLI and validate checkpoint/rewind functionality

Checklist

  • Follow Entire's contribution workflow (discussed approach, aligned with maintainer architecture)
  • All code passes gofmt and golangci-lint (mise run fmt && mise run lint)
  • All new functionality has accompanying unit tests
  • No breaking changes to existing core functionality
  • Implemented Entire's agent interface standards
  • Added relevant documentation (IFLOW.md)
  • Updated configuration files and gitignore
  • Merged latest main branch to resolve conflicts
  • Marked integration as preview status (per Entire's agent integration guidelines)

WangxuMarshall and others added 17 commits March 7, 2026 13:48
Add support for Trae Agent (ByteDance's LLM-based software engineering agent):
- Implement Agent interface with full hook support
- Add HookTypes for before_agent, after_agent, before_model, after_model, etc.
- Support JSON trajectory transcript format
- Implement ParseHookEvent for lifecycle event translation
- Add hook installation/uninstallation for .trae/settings.json

This integration is marked as preview status.
Add types, main agent struct, and lifecycle event parsing for iFlow CLI integration.

- types.go: Define settings, hooks, transcript structures and constants
- iflow.go: Implement Agent interface with session management
- lifecycle.go: Parse hook events into normalized lifecycle events
- hooks.go: Implement HookSupport interface for auto-installation of hooks
- transcript.go: Parse and extract file modifications from JSONL transcripts
- Add iflow agent to registry with AgentNameIFlow and AgentTypeIFlow
- Import iflow package in hooks_cmd.go for auto-registration
- Add comprehensive unit tests for all iflow agent components
CLAUDE.md is a local development file that should not be committed.
- Add comprehensive lifecycle tests for all hook types
- Improve type definitions with better JSON tags
- Add WriteHookResponse implementation
- Add transcript parsing tests
According to iFlow CLI documentation, all hook configurations must use
the 'hooks' array wrapper format. Previously, SetUpEnvironment, Stop,
SubagentStop, and SessionEnd used a flat format which caused hooks to
not be triggered.

Changes:
- types.go: Unify all hook types to use IFlowHookMatcher format
- hooks.go: Update hook installation to use correct nested format

Before (incorrect):
  "Stop": [{"type": "command", "command": "..."}]

After (correct):
  "Stop": [{"hooks": [{"type": "command", "command": "..."}]}]
iFlow CLI passes hook data via environment variables in addition to stdin
JSON. Add support for reading from env vars as fallback.

Also add computeTranscriptPath() to derive transcript path from session_id
when not provided, using pattern:
~/.iflow/projects/<sanitized-repo-path>/<session-id>.jsonl

Changes:
- Add env var overrides for all hook parsing functions
- Add computeTranscriptPath() for fallback transcript path computation
- Pass context through parsing functions for WorktreeRoot access
Previously, agent hooks were installed using opts.LocalDev directly,
which caused re-running 'entire enable' without --local-dev flag to
overwrite existing localDev settings in agent hook commands.

Fix by loading existing settings BEFORE installing agent hooks, then
using settings.LocalDev (merged with opts flags) for hook installation.

This ensures existing localDev setting is preserved when re-enabling.
The agent.Agent interface doesn't have SupportsHooks() method.
HookSupport interface provides hook-related methods.

Changes:
- Remove TestTraeAgent_SupportsHooks (method doesn't exist)
- Update TestTraeAgent_GetHookNames to use HookSupport interface
- Remove TestTraeAgent_GetSupportedHooks (method doesn't exist)
- Minor code cleanup in traeagent.go
Fix inconsistent whitespace in map literals after gofmt run.
@wangxumarshall wangxumarshall requested a review from a team as a code owner March 16, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant