Skip to content

Add Autohand Code agent integration#585

Open
igorcosta wants to merge 11 commits intoentireio:mainfrom
autohandai:main
Open

Add Autohand Code agent integration#585
igorcosta wants to merge 11 commits intoentireio:mainfrom
autohandai:main

Conversation

@igorcosta
Copy link

We're delighted to join the alliance, this PR introduces Autohand code cli to it.

  • Adds autohand-code as a new agent in the Entire CLI, following the same pattern as
    the Factory AI Droid integration (Add Factory AI Droid agent integration #435)
  • Implements all required agent interfaces: identity, hook management, lifecycle event
    parsing, transcript analysis, and token calculation
  • Installs 5 hooks into .autohand/config.json (session-start, pre-prompt, stop,
    session-end, subagent-stop) plus a permission deny rule for .entire/metadata/**
  • Parses Autohand's direct-role JSONL transcript format with file modifications
    extracted from toolCalls arrays and token usage from _meta fields
  • 86 unit tests + 2 integration tests with full race detection coverage

New Files

  • cmd/entire/cli/agent/autohandcode/ - Full agent package (autohandcode.go,
    types.go, hooks.go, lifecycle.go, transcript.go)
  • cmd/entire/cli/agent/autohandcode/*_test.go - Unit tests (4 files)
  • cmd/entire/cli/integration_test/setup_autohand_hooks_test.go - Integration tests

Modified Files

  • cmd/entire/cli/agent/registry.go - Added agent name/type constants
  • cmd/entire/cli/config.go - Added blank import for self-registration
  • cmd/entire/cli/hooks_cmd.go - Added blank import for hook subcommands
  • CLAUDE.md - Updated agent list

Test plan

  • mise run test - all unit tests pass
  • mise run test:integration - integration tests pass with race detection
  • mise run lint - no lint issues
  • Manual test: entire enable --agent autohand-code installs hooks to
    .autohand/config.json
  • Manual test: pipe hook stdin JSON to entire hooks autohand-code <event> and
    verify processing

Igor Costa and others added 11 commits March 3, 2026 10:46
Register autohand-code as a new agent in the registry with
its corresponding display name "Autohand Code".
Create the autohandcode package with:
- Core agent struct implementing the Agent interface
- Self-registration via init()
- Session storage at ~/.autohand/sessions/<id>/conversation.jsonl
- AUTOHAND_HOME env var support for custom home directory
- Type definitions for Autohand's config format, hook stdin
  JSON schema, transcript message format, and file modification
  tool names (write_file, edit_file, create_file, patch_file)
Implement InstallHooks, UninstallHooks, AreHooksInstalled for
.autohand/config.json. Hooks use Autohand's array-based config
format with event/command/description fields. Installs hooks for
session-start, pre-prompt, stop, session-end, and subagent-stop
events. Adds permission deny rule for .entire/metadata files.
Implement ParseHookEvent mapping Autohand hooks to normalized events:
- session-start -> SessionStart
- pre-prompt -> TurnStart (with instruction as prompt)
- stop -> TurnEnd
- session-end -> SessionEnd
- subagent-stop -> SubagentEnd
- notification -> no-op

Also implement TranscriptAnalyzer, TokenCalculator,
SubagentAwareExtractor, and HookResponseWriter interfaces.
Transcript path is computed from session_id since Autohand
does not include transcript_path in hook stdin.
Parse Autohand's JSONL transcript format which uses direct role
fields (no envelope wrapper). Extract modified files from the
toolCalls array on assistant messages. Calculate token usage from
_meta fields. Support subagent transcript aggregation.
86 tests covering all agent components:
- autohandcode_test.go: identity, session storage, transcript I/O
- hooks_test.go: install/uninstall, idempotency, force reinstall,
  permission rules, user hook preservation
- lifecycle_test.go: event parsing for all hook types, table-driven
- transcript_test.go: JSONL parsing, file extraction from toolCalls,
  token usage from _meta, subagent ID extraction, deduplication
Add blank imports in config.go and hooks_cmd.go to trigger
init() self-registration. This makes autohand-code available
in the agent registry and generates hook subcommands under
entire hooks autohand-code.
Apply gofmt -s -w to fix struct tag alignment and
spacing issues in types.go and hooks.go.
Verify entire enable --agent autohand-code:
- Installs all 5 required hooks in .autohand/config.json
- Adds permission deny rule for .entire/metadata/**
- Preserves existing user hooks and custom config fields
Add Autohand Code and Factory AI Droid to the agent
implementations list in the Key Directories section.
Copilot AI review requested due to automatic review settings March 3, 2026 02:00
@igorcosta igorcosta requested a review from a team as a code owner March 3, 2026 02:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Autohand Code as a first-class agent integration in Entire CLI, following the established agent strategy pattern (hooks + lifecycle events + transcript parsing/token usage) so Autohand sessions can be captured and analyzed like other supported agents.

Changes:

  • Introduces cmd/entire/cli/agent/autohandcode/ implementing agent identity, hook installation/uninstall, lifecycle parsing, transcript analysis, and token accounting.
  • Registers the new agent via blank imports and adds new agent name/type constants to the registry.
  • Adds extensive unit tests and an integration test to validate hook installation into .autohand/config.json.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cmd/entire/cli/integration_test/setup_autohand_hooks_test.go Integration coverage ensuring entire enable --agent autohand-code writes hooks + deny rule to .autohand/config.json.
cmd/entire/cli/hooks_cmd.go Ensures Autohand agent is registered before hook subcommands enumerate agents.
cmd/entire/cli/config.go Ensures Autohand agent self-registers during CLI initialization.
cmd/entire/cli/agent/registry.go Adds AgentNameAutohandCode / AgentTypeAutohandCode constants.
cmd/entire/cli/agent/autohandcode/types.go Defines Autohand config schema + transcript/hook payload types used across the integration.
cmd/entire/cli/agent/autohandcode/transcript.go Implements JSONL parsing, modified-file extraction, subagent detection, and token usage aggregation.
cmd/entire/cli/agent/autohandcode/lifecycle.go Implements lifecycle hook parsing + transcript analyzer/token calculator adapters for Entire’s normalized event model.
cmd/entire/cli/agent/autohandcode/hooks.go Implements .autohand/config.json hook installation/uninstall and permissions deny rule management.
cmd/entire/cli/agent/autohandcode/transcript_test.go Unit tests for transcript parsing, file extraction, subagent handling, prompts/summary, and token logic.
cmd/entire/cli/agent/autohandcode/lifecycle_test.go Unit tests for lifecycle hook parsing and hook response writer behavior.
cmd/entire/cli/agent/autohandcode/hooks_test.go Unit tests for hook installation/uninstall idempotency, preservation, and permissions deny rule behavior.
cmd/entire/cli/agent/autohandcode/autohandcode_test.go Unit tests for agent identity, session dir resolution, transcript read/write, and session round-trips.
cmd/entire/cli/agent/autohandcode/autohandcode.go New agent implementation + self-registration with the agent registry.
CLAUDE.md Documentation update to include Autohand Code in the agent list.

Comment on lines +136 to +137
// If parsing fails, start with empty rules
rules = nil
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

permissions.rules parsing errors are silently ignored (rules = nil) and then the code may overwrite the existing rules with only metadataDenyRule. If the existing config has an unexpected-but-valid schema (or is temporarily malformed), this can cause silent data loss. Prefer returning an error when rules exists but can’t be unmarshaled into the expected shape (or preserve the raw JSON and only append when parsing succeeds).

Suggested change
// If parsing fails, start with empty rules
rules = nil
return 0, fmt.Errorf("failed to parse permissions.rules in config.json: %w", err)

Copilot uses AI. Check for mistakes.
Comment on lines +294 to +295
// ExtractSpawnedAgentIDs extracts agent IDs from subagent-stop data in the transcript.
// Returns a map of agentID -> toolUseID for all spawned agents.
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment for ExtractSpawnedAgentIDs says it extracts IDs from “subagent-stop data” and returns “agentID -> toolUseID”, but the implementation actually scans assistant toolCalls for Task/task and stores agentIDs[tc.ID] = tc.ID. Please update the comment (or the implementation) so the source and map values are described accurately.

Suggested change
// ExtractSpawnedAgentIDs extracts agent IDs from subagent-stop data in the transcript.
// Returns a map of agentID -> toolUseID for all spawned agents.
// ExtractSpawnedAgentIDs scans assistant messages for Task/task tool calls and
// returns a map of spawned agent IDs, keyed and valued by the tool call ID.

Copilot uses AI. Check for mistakes.
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.

2 participants