Skip to content

feat(agents): add grok, cursor, qwen, copilot, kimi adapters#145

Merged
harshitsinghbhandari merged 8 commits into
mainfrom
land/adapters-batch1
Jun 6, 2026
Merged

feat(agents): add grok, cursor, qwen, copilot, kimi adapters#145
harshitsinghbhandari merged 8 commits into
mainfrom
land/adapters-batch1

Conversation

@harshitsinghbhandari
Copy link
Copy Markdown
Collaborator

Stacks five agent adapters on top of the agent platform (#119). Each adapter lives in backend/internal/adapters/agent// and is wired via registry.Constructors() and daemon/wiring_test.go.

Notes:

  • copilot includes the documented preToolUse hook event fix (Copilot CLI does not recognize 'permissionRequest').
  • kimi drops the approval flags on -p and --session code paths.

Originally part of yyovil's agents/* stacked branches; cherry-picked clean onto main.

yyovil and others added 6 commits June 7, 2026 01:04
Registers the grok harness (xAI Grok CLI). grok installs Claude Code-compatible
hooks, so it reuses the claude-code activity deriver already in the platform.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Registers the cursor harness, stacked on the agent platform. Includes its own activity deriver.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Registers the qwen harness, stacked on the agent platform. Includes its own activity deriver.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* feat(agents): add copilot adapter

Registers the copilot harness, stacked on the agent platform. Includes its own activity deriver.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Update backend/internal/adapters/agent/copilot/hooks.go

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* fix(copilot): map permission-request to documented preToolUse event

Copilot CLI does not document a "permissionRequest" hook event. Per
https://docs.github.com/en/copilot/how-tos/copilot-cli/customize-copilot/use-hooks
the documented camelCase events are sessionStart, sessionEnd,
userPromptSubmitted, preToolUse, postToolUse, errorOccurred, agentStop.
Writing "permissionRequest" into .github/hooks/ao.json silently disables
that hook because Copilot does not recognize the key.

Remap AO's permission-request sub-command onto preToolUse (the closest
documented signal — fires before any tool invocation, including ones
that would prompt for approval) and add a tripwire test asserting the
JSON keys AO writes match the documented camelCase names.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* chore(copilot): gofmt the new tripwire test

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Harshit Singh Bhandari <dev@theharshitsingh.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: harshitsinghbhandari <24b4506@iitb.ac.in>
Registers the kimi harness, stacked on the agent platform.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Kimi rejects `--prompt` combined with `--yolo`/`--auto`/`--plan`, and
rejects `--yolo`/`--auto` combined with `--session`/`--continue`
(non-interactive and resumed sessions inherit the auto permission
policy). The previous mapping appended one of those flags before `-p`
on every launch and before `--session` on every restore, so every
non-interactive launch would fail at startup. The local binary
(v1.37.0) additionally has no `--auto` option at all, which would
fail even on otherwise-permissible paths.

- GetLaunchCommand: emit approval flags only on the interactive path
  (no prompt). The `-p <prompt>` path is now bare.
- GetRestoreCommand: never emit approval flags; resumed sessions
  inherit the original session's approval settings.
- Tests assert no approval/plan flag leaks onto either path for any
  PermissionMode, and keep the interactive mapping unchanged.

Refs: https://moonshotai.github.io/kimi-code/en/reference/kimi-command.html
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 6, 2026

Greptile Summary

This PR adds five agent adapters — Grok Build, Cursor, Qwen Code, GitHub Copilot, and Kimi CLI — wiring them into the registry and activity-dispatch layer alongside the existing claude-code and codex adapters.

  • Hook-capable adapters (cursor, qwen, copilot) each install a small set of native lifecycle hooks into their respective config files (.cursor/hooks.json, .qwen/settings.json, .github/hooks/ao.json) using an atomic write-then-rename strategy; all three implement GetAgentHooks, UninstallHooks, and AreHooksInstalled with idempotent install and clean teardown.
  • Grok delegates hook installation to claudecode.Plugin via its documented zero-config Claude Code compatibility layer, and is therefore dispatched under the existing "claude-code" deriver rather than a new entry in activitydispatch.
  • Kimi is a Tier C (no-hook) adapter that correctly omits approval flags on the -p and --session code paths per CLI docs, and intentionally leaves GetAgentHooks and SessionInfo as no-ops.

Confidence Score: 5/5

All five adapters are self-contained and additive; no existing adapter logic is modified. Each new adapter is backed by focused unit tests and the end-to-end wiring test.

The changes are purely additive — new adapter packages wired into the registry and activity dispatcher, with no modifications to shared infrastructure. Hook installation uses atomic writes, the qwen sync-before-rename gap previously flagged was already fixed in an earlier commit, and the Kimi no-hook/no-approval-flag invariants are well-tested. The only notable issue is a stale one-liner in the grok package comment that contradicts the actual flag the binary receives.

No files require special attention; grok.go has a minor package-level comment inconsistency worth tidying.

Important Files Changed

Filename Overview
backend/internal/adapters/agent/grok/grok.go Grok adapter delegating hook install/uninstall to claudecode.Plugin; binary resolution, permission-mode flags, and restore command look correct. Package-level comment says --always-approve for bypass but code emits --permission-mode bypassPermissions.
backend/internal/adapters/agent/kimi/kimi.go Tier C (no-hook) adapter; correctly omits approval flags on -p and --session paths per Kimi CLI docs. SessionInfo is a no-op. Binary resolution and restore command look correct.
backend/internal/adapters/agent/copilot/copilot.go Copilot adapter with permission flags (--allow-tool write / --allow-all-tools / --allow-all) and session restore via --resume. Binary resolution covers npm global and Homebrew paths.
backend/internal/adapters/agent/copilot/hooks.go Installs four Copilot CLI hooks (sessionStart, userPromptSubmitted, preToolUse→permission-request, agentStop) into .github/hooks/ao.json; atomicWriteFile includes tmp.Sync() before rename; idempotent install and clean uninstall verified by tests.
backend/internal/adapters/agent/cursor/cursor.go Cursor adapter targets cursor-agent binary; AcceptEdits intentionally produces no flag (no native equivalent); restore uses --resume; prompt guarded with -- sentinel. Correct.
backend/internal/adapters/agent/cursor/hooks.go Installs five Cursor hooks (sessionStart, beforeSubmitPrompt, stop, beforeShellExecution, beforeMCPExecution) into .cursor/hooks.json; delegates to hookutil.AtomicWriteFile (which syncs); deduplication and uninstall are correct.
backend/internal/adapters/agent/qwen/qwen.go Qwen adapter with --approval-mode flag mapping and --append-system-prompt injection; restore via -r; binary resolution covers npm-global, Homebrew, and ~/.local/bin paths.
backend/internal/adapters/agent/qwen/hooks.go Installs four Qwen hooks into .qwen/settings.json (SessionStart under startup matcher, UserPromptSubmit, PermissionRequest, Stop); local atomicWriteFile now includes tmp.Sync() (prior issue fixed); settings round-trip preserves unrelated keys.
backend/internal/adapters/agent/registry/registry.go All five new adapters (grok, cursor, qwen, copilot, kimi) are wired into Constructors() in a stable order; Build() and Harnessed() are unchanged.
backend/internal/adapters/agent/activitydispatch/dispatch.go Adds cursor, qwen, copilot DeriveActivityState entries; grok omitted intentionally (delegates to claude-code hooks); kimi omitted intentionally (Tier C, no hooks).
backend/internal/daemon/wiring_test.go TestWiring_AgentResolverResolvesRealAdapters extended with harness table entries for all five new adapters; validates end-to-end registration through the real registry.

Sequence Diagram

sequenceDiagram
    participant AO as AO Daemon
    participant Reg as registry.Constructors()
    participant Adapter as Agent Adapter
    participant HooksFile as Hooks Config File
    participant Agent as Agent CLI Binary
    participant Dispatch as activitydispatch.Derive()

    AO->>Reg: Build()
    Reg-->>AO: [claudecode, codex, grok, cursor, qwen, copilot, kimi]

    AO->>Adapter: GetAgentHooks(WorkspaceHookConfig)
    Adapter->>HooksFile: atomicWrite(hooks.json / settings.json / ao.json)
    HooksFile-->>Adapter: ok

    AO->>Adapter: GetLaunchCommand(LaunchConfig)
    Adapter-->>AO: [binary, flags..., -p, prompt]

    AO->>Agent: exec(cmd)

    Agent->>AO: ao hooks agent event
    AO->>Dispatch: Derive(agent, event, payload)
    Dispatch-->>AO: ActivityState

    AO->>AO: ApplyActivitySignal
Loading

Reviews (2): Last reviewed commit: "fix(agents/grok): delegate hook cleanup ..." | Re-trigger Greptile

Comment thread backend/internal/adapters/agent/qwen/hooks.go
@harshitsinghbhandari
Copy link
Copy Markdown
Collaborator Author

Also addressed the Greptile comment outside the diff: Grok now delegates AreHooksInstalled and UninstallHooks to the Claude Code adapter, matching its delegated GetAgentHooks path. Added a lifecycle test and ran: cd backend && go test -race ./internal/adapters/agent/grok ./internal/adapters/agent/claudecode

@harshitsinghbhandari harshitsinghbhandari merged commit b13f413 into main Jun 6, 2026
8 checks passed
harshitsinghbhandari added a commit that referenced this pull request Jun 6, 2026
…r, goose, auggie, continue, devin, cline, kiro, kilocode, vibe, pi, autohand) (#150)

* feat(agents): add droid adapter

Registers the droid harness, stacked on the agent platform. Includes its own activity deriver.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* feat(agents): add amp adapter

Registers the amp harness, stacked on the agent platform.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* feat(agents): add agy adapter

Registers the agy harness, stacked on the agent platform. Includes its own activity deriver.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* feat(agents): add crush, aider, goose, auggie, continue, devin, cline, kiro, kilocode, vibe, pi, autohand adapters

Cherry-pick batch landing the remaining 12 yyovil adapter directories per
Discussion #148 recipe, on top of #145 (grok/cursor/qwen/copilot/kimi) and
the droid/amp/agy commits earlier on this branch. Each adapter is a
self-contained package under backend/internal/adapters/agent/<name>/;
registry.Constructors(), activitydispatch.Derivers (for adapters with
activity.go), and wiring_test.go are unified to register all 23 shipped
adapters in one place. No new migration: 0007_allow_implemented_harnesses
already widens the sessions.harness CHECK to cover every adapter.

* fix(agents/kilocode): return error from json.Marshal of permission config

Previously the marshal error was discarded and the function returned a
prefix carrying an empty KILO_CONFIG_CONTENT. An unrecoverable marshal
failure for the typed map should never happen in practice, but if it ever
did, Kilo would silently launch with default permissions regardless of
the requested mode. Surface it as "no prefix" so the caller's mode choice
can't be misrepresented.

---------

Co-authored-by: yyovil <itsyyovil@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

2 participants