Skip to content

feat(agents): add Kilo Code external agent#38

Open
rohitg00 wants to merge 3 commits into
entireio:mainfrom
rohitg00:add-kilo-external-agent
Open

feat(agents): add Kilo Code external agent#38
rohitg00 wants to merge 3 commits into
entireio:mainfrom
rohitg00:add-kilo-external-agent

Conversation

@rohitg00

Copy link
Copy Markdown

Closes #16

Summary

Adds entire-agent-kilo, a standalone external agent binary that teaches the Entire CLI how to work with Kilo Code. Follows the same shape as entire-agent-amp and entire-agent-kiro.

Kilo Code is a fork of OpenCode and ships a @kilocode/plugin API that exposes session lifecycle events on its internal event bus — the original blocker on this issue (Kilo missing hook support) is resolved.

How it works

  • Installs a project plugin at .kilo/plugin/entire.ts that runs on Kilo's Bun runtime.
  • Subscribes to Kilo's event hook bus, filtering for session.created and session.idle.
  • On each event, fetches the authoritative session JSON via the local Kilo SDK client (client.session.get + client.session.messages) and forwards a single JSON payload over stdin to entire hooks kilo <event>.
  • The Go binary parses the payload, writes the session JSON to session_ref atomically, and emits the Entire protocol event (SessionStart / TurnEnd).
  • Sub-sessions are filtered to top-level by checking that info.parentID is empty so subagent threads don't double-fire SessionStart.

Capabilities

Capability Declared
hooks true
transcript_analyzer true
transcript_preparer true
token_calculator true
compact_transcript true
uses_terminal true

Resume command

kilo run --session <id> (or kilo run --continue).

Files

  • agents/entire-agent-kilo/ — Go module (binary entrypoint, agent core, protocol handlers, unit tests)
  • e2e/agents/kilo.go — lifecycle adapter for the shared e2e harness
  • agents/entire-agent-kilo/AGENT.md — research notes + protocol mapping
  • agents/entire-agent-kilo/README.md — install + usage
  • README.md, .gitignore — register the new agent in the root layout

Test plan

  • go build ./cmd/entire-agent-kilo
  • go test ./... — 18 unit tests pass (protocol handlers, hooks, transcript, compact, command_runner, types)
  • go vet ./... clean
  • gofmt -s -w . clean
  • Subcommand smoke test: info, detect, format-resume-command, parse-hook session.created, parse-hook session.idle, install-hooks, are-hooks-installed, uninstall-hooks, extract-summary, get-transcript-position, calculate-tokens, compact-transcript
  • CodeRabbit review (1 minor finding, addressed)
  • Local lifecycle e2e: requires kilo installed (mise run test:e2e:lifecycle E2E_AGENT=kilo)
  • Protocol compliance via external-agents-tests
  • Verified against @kilocode/sdk exports (session.get, session.messages shapes)

Notes

Draft because the lifecycle e2e against a real kilo install hasn't run yet locally. The plugin TS source assumes the current @kilocode/sdk shape — happy to adjust once verified against the latest published SDK. Filing as draft for early feedback on architecture and protocol mapping before promoting to ready-for-review.

Will also confirm against the original blocker upstream (Kilo-Org/kilocode#5827) once the integration is validated end-to-end.

Implements Kilo Code as an external agent binary using Kilo's
@kilocode/plugin API. The plugin subscribes to the internal event
bus and forwards session.created and session.idle events to the
Entire CLI hook handler, carrying the authoritative Session.Info
and messages array fetched via the local Kilo SDK client.

Capabilities: hooks, transcript_analyzer, transcript_preparer,
token_calculator, compact_transcript.

Resume command: kilo run --session <id> (or --continue).

Sub-sessions are filtered to top-level by checking info.parentID.

Closes entireio#16
@rohitg00 rohitg00 marked this pull request as ready for review May 22, 2026 14:15
Cross-checked against entireio/cli@ddf1a33 and the OpenCode agent
implementation (cmd/entire/cli/agent/opencode/). Kilo is OpenCode
fork, so the same event-bus semantics apply.

Critical changes:
- Hook names switch to kebab-case (session-start, turn-start, turn-end,
  compaction, session-end) — matches Entire's external-agent convention
  and the engine's hook router at cmd/entire/cli/hooks_cmd.go.
- Plugin subscribes to session.status with status.type=="idle" instead
  of session.idle (deprecated upstream; not reliably emitted in
  `kilo run` mode).
- Plugin now uses Bun.spawn / Bun.spawnSync directly. Sync variants used
  for turn-start, turn-end, and session-end so git hook ordering and
  process-exit teardown are correct.
- Adds __ENTIRE_CMD__ placeholder substitution at install time, with
  --local-dev rewriting to `go run "$(git rev-parse --show-toplevel)"/cmd/entire/main.go`.
- Adds turn-start (message.updated/message.part.updated for user role),
  compaction (session.compacted), and session-end (session.deleted +
  server.instance.disposed) handlers — previously absent.
- Plugin dir is now `.kilo/plugins/entire.ts` (OpenCode-style plural).
- Per-hook payload types (sessionInfoRaw, turnStartRaw, turnEndRaw)
  match OpenCode's contract; turn-end carries optional session+messages
  snapshot from the plugin so session_ref is populated synchronously.

Capabilities and protocol shapes unchanged. All 22 unit tests pass.
@rohitg00

Copy link
Copy Markdown
Author

Update — cross-checked PR against entireio/cli@ddf1a33 and the OpenCode reference impl (cmd/entire/cli/agent/opencode/). Kilo is an OpenCode fork so the same event-bus semantics apply.

Fixes pushed (commit ac27c30):

  • Kebab-case hook namessession-start, turn-start, turn-end, compaction, session-end. Previous dotted names (session.created, session.idle) wouldn't route through entire hooks kilo <X> correctly.
  • Subscribe to session.status (idle) instead of session.idlesession.idle is deprecated upstream and not reliably emitted in kilo run mode.
  • Bun.spawn / Bun.spawnSync instead of node:child_process. Sync variants used for turn-start, turn-end, and session-end so git hook ordering and process-exit teardown are correct.
  • __ENTIRE_CMD__ placeholder substituted at install time, with --local-dev rewriting to go run "$(git rev-parse --show-toplevel)"/cmd/entire/main.go.
  • Full lifecycle coverage — adds turn-start (from message.updated / message.part.updated), compaction (session.compacted), and session-end (session.deleted + server.instance.disposed). Previous PR only handled SessionStart + TurnEnd.
  • Plugin dir is now .kilo/plugins/entire.ts (OpenCode-style plural — Kilo docs support both plugin/ and plugins/).
  • Per-hook payload types (sessionInfoRaw, turnStartRaw, turnEndRaw) match OpenCode's contract.

Tests: 22 unit tests pass (was 18). CodeRabbit re-run pending.

Still draft because the lifecycle e2e against a real kilo install hasn't run yet locally and the @kilocode/sdk method shapes (client.session.get, client.session.messages) need verification against the latest published SDK.

@rohitg00 rohitg00 marked this pull request as draft May 22, 2026 16:54
sessionIDFromTranscriptData previously returned an error when the
transcript blob parsed to a Session struct with an empty ID. The
external-agents-tests compliance suite (tests/transcript:
TestTranscriptPreparer_PrepareTranscript) writes a minimal valid-JSON
fixture and expects prepare-transcript to succeed gracefully — there
is nothing to refresh against when no ID is present.

Match the amp agent's behavior: return ("", nil) when the blob is
empty or parses to a Session with no ID. PrepareTranscript already
short-circuits on an empty session ID, so this becomes a no-op rather
than an error.

Compliance suite now reports 29 PASS / 6 SKIP / 0 FAIL across
hooks, mandatory, optional, subagent, and transcript suites.
@rohitg00 rohitg00 marked this pull request as ready for review May 22, 2026 19:06
@rohitg00

rohitg00 commented Jun 4, 2026

Copy link
Copy Markdown
Author

Any update on this one? @blackgirlbytes Thank you

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.

Kilo Code support

1 participant