Implement the following plan: OpenClaw Integration Plan Context The CLI currently…
- User
Implement the following plan:
OpenClaw Integration Plan
Context
The CLI currently supports Claude Code and Gemini CLI as agents. The user wants to add OpenClaw as a third agent, following the same patterns. OpenClaw is a self-hosted AI agent gateway that uses TypeScript-based hooks discovered from directories. The integration requires:
- Go CLI code — new agent package + handlers (follows Gemini pattern exactly)
- TypeScript hook handler — a TS file installed into OpenClaw's hooks directory that shells out to
entire hooks openclaw <verb>with JSON on stdin
Hook Event Mapping (Confirmed by user)
OpenClaw Event Entire Hook Equivalent in Claude/Gemini agent:bootstrapsession-start + capture state SessionStart + UserPromptSubmit/BeforeAgent agent:responsecommit checkpoint Stop/AfterAgent command:newsession-start (new session) SessionStart command:stopsession-end SessionEnd session:compactedpre-compress (backup) PreCompress Key Differences from Claude/Gemini
- Hook installation: TypeScript file in
<workspace>/.openclaw/hooks/(not settings.json entries) - Transcript format: JSONL (same as Claude Code — can reuse
CapturePrePromptState) - No explicit "before next prompt" hook:
agent:bootstrapfires once; pre-prompt state must be re-captured after eachagent:responsecheckpoint - Session storage:
~/.openclaw/agents/<agentId>/sessions/<SessionId>.jsonl
Implementation Steps
Step 1: Add Agent Constants
Modify:
cmd/entire/cli/agent/registry.gogoAgentNameOpenClaw AgentName = "openclaw" AgentTypeOpenClaw AgentType = "OpenClaw"Step 2: Create Agent Package
New directory:
Assistant
I'll start by exploring the existing codebase to understand the patterns, then implement the OpenClaw integration step by step.
Assistant
Good. Now let me read the key files I need to reference directly.
Assistant
Now let me read the remaining critical files.
Assistant
Now let me also read the state.go file and the existing test patterns.
Assistant
Let me check what other common files exist and look at test patterns.
Assistant
Now I have a thorough understanding of the patterns. Let me also check the
TranscriptPositiontype andGetTranscriptPositionfunction used in state.go.Assistant
Now I have everything I need. Let me create task tracking and start implementing.
Assistant
Step 1: Add agent constants to registry.
Assistant
Step 2: Create the openclaw agent package. I'll create all the files.
Assistant
2a. types.go
Assistant
2b. openclaw.go
Assistant
2c. transcript.go
Assistant
Good, the diagnostics are resolving now that transcript.go exists. Now let me create the hooks.go file with the embedded TS handler.
2d. hooks.go
Assistant
Let me fix those lint warnings and create the embedded files.
Assistant
Let me check agent types.go to see if RawData uses
interface{}orany.Assistant
The type definition uses
interface{}, somake(map[string]interface{})is correct. The lint warning is about this matching the type definition. Let me check the Gemini file to see if it also usesinterface{}.Looking at
geminicli/gemini.go:98, it also usesmake(map[string]interface{}). So this is consistent. The lint warning is just a suggestion, not an error. Let me now create the embedded files.Assistant
Now let me verify the package compiles so far.
Assistant
Package compiles. Let me check the lint suggestion about
interface{}vsany.Assistant
Several lint issues to fix. Let me address them all.
Assistant
Now let me fix all the lint issues:
OpenClawAgentstutters - but this follows the same pattern asGeminiCLIAgent. Let me check how Gemini handles it.
Looking at
geminicli/gemini.go:29://nolint:revive // GeminiCLIAgent is clearer than Agent in this contextI'll add the same nolint and fix the other issues.
Assistant
Fix the unused
repoPathparameter - use_like other places or add nolint:Assistant
Now fix the
unparamissues in transcript.go - the error returns are always nil. Let me check how Gemini handles this... Looking at geminicli/transcript.go,ExtractModifiedFilesreturns([]string, error)- and the linter doesn't flag it there because it can return an error fromParseTranscript. For OpenClaw, the functions never return an error. But for API consistency with the Gemini pattern, I'll add nolint comments.Actually, let me just keep the error return for API consistency but suppress the lint warning:
Assistant
Let me fix all lint issues:
Assistant
Now add the
messageTypeconstant for "message":Assistant
Now fix the hooks.go file permissions (gosec) and unused var:
Assistant
Remove the unused
entireHookPrefixes:Assistant
Fix the
ReassembleTranscriptunparam issue:Assistant
Now let me run lint again:
Assistant
Clean lint. Now mark task 2 complete and move to the handlers.
Assistant
Step 3: Create the OpenClaw hook handlers.
Assistant
Now let me check if it compiles and lint:
Assistant
It compiles. The "unused" warnings are because the handlers aren't registered yet. Let me also check there's a
handleSessionStartCommonstdin issue. Looking at the bootstrap handler -handleSessionStartCommon()consumes stdin, then we try to parse it again. Let me fix the bootstrap handler to work correctly.The issue is that
handleSessionStartCommon()reads fromos.Stdin, which is a one-time read. So the secondParseHookInputinhandleOpenClawBootstrapwould fail. Let me refactor the bootstrap handler to parse stdin once and use the data for both purposes.Assistant
Wait, I need to think about this more carefully. The bootstrap handler needs to:
- Run session start logic
- Capture pre-prompt state
- Initialize session
But
handleSessionStartCommon()consumes stdin. The cleanest approach is to buffer stdin, then pass it to both operations. Let me look at how this works more carefully.Actually, looking at the Gemini pattern:
handleGeminiBeforeAgent()does both capture + initialize, whilehandleGeminiSessionStart()just callshandleSessionStartCommon(). These are separate hooks called at different times.For OpenClaw,
agent:bootstrapcombines both. The simplest approach: buffer stdin, then usebytes.NewReaderfor the parse, and call the session start logic manually rather than throughhandleSessionStartCommon.Assistant
Now rewrite the bootstrap handler properly:
Assistant
Hmm, the diagnostics say
bytes,io, andsessionare unused but I clearly just added code using them. This is likely because the diagnostic scanner hasn't caught up yet, or there's a compile error. Let me check:Assistant
Compiles fine. The handlers are "unused" because they aren't registered yet. Let me now do Step 4.
Assistant
Step 4: Register handlers and add blank import.
Assistant
Now add the OpenClaw handler registrations after the Gemini ones:
Assistant
Now add the blank import in hooks_cmd.go:
Assistant
Now let me compile and lint:
Assistant
The init function maintainability index dropped because we added more handlers. Let me check if this is a new issue or existing:
Assistant
No maintidx issue before. The init function grew too large. Let me check if the existing codebase already has a nolint for this or if I need to restructure. Let me check the
.golangci.yml:Assistant
It's an enabled linter. The simplest fix is to add a
//nolint:maintidxto the init function, since the pattern of registering handlers in init is deliberate and already established:Assistant
Step 5: Create tests. I'll create all three test files.
Assistant
Now let's run the tests and lint:
- User
Verification
mise run fmt— format all new Go filesmise run lint— ensure no lint errorsmise run test— run unit tests (new openclaw tests must pass)mise run test:ci— run all tests including integration- Manual test:
entire enable --agent openclawshould install hooks - Verify
entire hooks openclaw bootstrapaccepts JSON on stdin - Verify
.openclaw/hooks/entire-hook/handler.tsis created correctly
If you need specific details from before exiting plan mode (like exact code snippets, error messages, or content you generated), read the full transcript at: /Users/gtrrz-victor/.REDACTED.jsonl
- User
Assistant
Let me re-run the tests to see which ones are failing.
Assistant
The output shows all tests PASS individually but the overall result is FAIL. Let me get the early output to find the failing test.
Assistant
Two failing tests:
- TestInstallHooks_Fresh - handler file doesn't contain
'entire hooks openclaw' - TestInstallHooks_Idempotent - second install returns 5 instead of 0
Let me check the handler.ts content to understand the issue.
- TestInstallHooks_Fresh - handler file doesn't contain
Assistant
I see the issues. The handler.ts uses a JS variable
${ENTIRE_CMD}in the template literal, so the file content never contains the literal string"entire hooks openclaw". The string"entire"is only in the variable declarationconst ENTIRE_CMD = 'entire';. Let me fix both theisHandlerInstalledfunction and the test.Assistant
Now fix the test to check for the correct string:
Assistant
Now re-run the tests:
Assistant
All InstallHooks tests pass. Let me run the full test suite for the package:
Assistant
All tests pass. Now let me mark task 5 as complete and proceed to task 6 — run fmt, lint, and the full test suite.
Assistant
The lint errors are all pre-existing
ireturnissues in the strategy package, unrelated to my changes. Let me verify by checking if these exist on the main branch:Assistant
The
ireturnlint errors are pre-existing (strategy package, not my changes). Let me verify thatgofmtdidn't inadvertently modify those files:Assistant
The
gofmtrun removed thenolint:ireturncomments from the strategy files. Those are pre-existing nolint comments I shouldn't have touched. Let me restore them:Assistant
Now let me run lint again focused only on my changes:
Assistant
Zero lint issues. Now let me run the full test suite:
Assistant
All tests pass, including the new
openclawpackage. Let me also run the CI test suite:Assistant
All tests pass including integration tests with race detection. Let me mark task 6 as complete.
Assistant
The OpenClaw integration is complete. Here's a summary of everything that was done:
Files created:
cmd/entire/cli/agent/openclaw/types.go— OpenClaw-specific types (hook events, transcript, tool calls)cmd/entire/cli/agent/openclaw/openclaw.go— Agent implementation (full interface: Agent, TranscriptAnalyzer, TranscriptChunker)cmd/entire/cli/agent/openclaw/transcript.go— Transcript parsing (extract files, prompts, messages, token usage)cmd/entire/cli/agent/openclaw/hooks.go— Hook management (install/uninstall TypeScript handler)cmd/entire/cli/agent/openclaw/handler.ts— Embedded TypeScript handler that shells out toentire hooks openclaw <verb>cmd/entire/cli/agent/openclaw/HOOK.md.tmpl— Embedded hook metadata filecmd/entire/cli/hooks_openclaw_handlers.go— Hook handlers (bootstrap, response, command-new, command-stop, session-compacted)