Skip to content

feat(completion): live "/" completion for claude, codex, and gemini (no adapter, per-tool config) - #55

Merged
lambdalisue merged 8 commits into
mainfrom
claude/acp-overview-j4ocj4
Jul 7, 2026
Merged

lambdalisue merged 8 commits into
mainfrom
claude/acp-overview-j4ocj4

Conversation

@lambdalisue

@lambdalisue lambdalisue commented Jun 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds a live "/" completion source per tool, replacing the hand-synced BUILTIN_COMMANDS table and on-disk scanning with each agent's own, session-accurate command/skill list. The interactive session keeps running over the PTY exactly as today — this is a read-only side-channel purely for completion candidates.

Motivation: a hardcoded table drifts with every release (manual sync toil), and plugin-/MCP-/dynamically-enabled commands are invisible to a disk scan. Each agent already knows its own authoritative, version-accurate list.

Design: three probes, no external adapter

Claude and Codex do not speak the Agent Client Protocol (ACP) themselves — that only exists via separate community/vendor adapters (claude-agent-acp, codex-acp) wrapping their SDKs/runtimes, a real external dependency (Node.js, npm, a package to keep updated) for a feature that only needs a list of strings. Since aibo already hard-depends on the claude/codex binaries themselves, each is probed directly instead:

  • Claude (completion/claude.lua) — talks claude's own internal stream-json control protocol (reverse-engineered from @anthropic-ai/claude-agent-sdk's sdk.mjs, the library claude-agent-acp itself uses).
  • Codex (completion/codex.lua) — talks codex app-server, a subcommand already built into the codex binary with a self-documenting schema (codex app-server generate-json-schema) — a meaningfully stronger foundation than Claude's reverse-engineered case.
  • Gemini (completion/gemini.lua) — Gemini CLI speaks the real, documented ACP natively (gemini --acp), so this wires up a generic, agent-agnostic ACP client (completion/acp.lua, no default cmd) instead of a bespoke protocol. Ready to reuse for any other ACP-native agent (Copilot, Cursor, Cline, ...) without modification once it gets its own aibo integration.

All three send only a control-plane request — never a prompt turn (session/prompt, control_request{subtype:"initialize"}, or initialize/skills/list, critically never thread/start) — so no inference runs and no tokens are consumed. The real interactive session stays first-party regardless of any Agent-SDK/ACP billing split. See doc/aibo-live-completion.txt for the full design, and doc/aibo-acp.txt/doc/aibo-claude.txt/doc/aibo-codex.txt for each probe's protocol details and live-verification notes.

Shared plumbing (completion/probe.lua, completion/cwd_cache.lua, completion/omnifunc.lua, completion/prompt_ftplugin.lua) factors out the async subprocess/JSON-message handling, per-cwd cache, omnifunc/prefix-filtering, and ftplugin wiring common to all three, so each module only carries its own protocol-specific logic.

Activation model: per-tool config, on by default

None of the three probes has a static or disk-scanned fallback anymore, so each is on by default. Completion config lives under tools.<tool>.completion.<source> — alongside each tool's other settings (on_attach, no_default_mappings) — rather than as a separate global list, so it can be configured per tool profile rather than once globally:

require("aibo").setup({
  tools = {
    claude = { completion = { claude = true } }, -- probes `claude` directly (does not speak ACP itself)
    codex = { completion = { codex = true } },   -- probes `codex app-server` directly (does not speak ACP itself)
    gemini = { completion = { acp = true } },     -- generic ACP client; Gemini CLI speaks ACP natively
    -- <source> = { cmd = {...}, timeout = 10000 } for overrides, or false to disable
  },
})

<tool> is whatever name aibo dispatches on (the first word of the invoked command); <source> selects which completion module backs it. A custom tool profile can opt into any module, not just the one matching its own name — e.g. a wrapper that launches a claude-flavored model can set tools["my-wrapper"].completion.claude = true to reuse Claude's probe. :checkhealth aibo reports whether each probe target resolves.

What's in this PR

  • lua/aibo/completion/{acp,claude,codex,gemini}.lua — the four completion sources described above.
  • lua/aibo/completion/{probe,cwd_cache,omnifunc,prompt_ftplugin}.lua — shared plumbing.
  • ftplugin/aibo-tool-{claude,codex,gemini}.lua — wire live completion into prompt buffers via prompt_ftplugin.lua.
  • init.lua — tools.<name>.completion.<source> config, on by default for the three built-in tools.
  • health.lua — :checkhealth aibo section per completion source.
  • Docs — doc/aibo-live-completion.txt (overview), doc/aibo-acp.txt, doc/aibo-claude.txt, doc/aibo-codex.txt, README.
  • Removed: BUILTIN_COMMANDS and the ~/.claude/commands/~/.claude/skills disk scan (superseded by Claude's own live list, which already includes custom commands/skills), Codex's .codex/skills disk scan (same reasoning), and the now-obsolete sync-claude-slash-commands.md maintenance rule.

Testing

  • tests/completion/test_{acp,claude,codex,gemini}.lua — pure parsers, per-cwd cache, refresh/refresh_acp against fake responder fixtures (tests/completion/fixtures/fake_{acp,claude_probe,codex_probe}.lua) that replay recorded protocol exchanges, resolve_cmd/is_available, and probe-missing error paths.
  • tests/internal/test_init.lua — per-tool completion config defaults/override/disable, including a custom tool-name profile.
  • Full suite green: 288 cases, 0 fails. stylua --check and luacheck clean.
  • All three probes additionally verified live against real, logged-in claude/codex/gemini binaries (not just fakes): Claude ~1s round trip with real account data and no ~/.claude/projects side effect (--no-session-persistence); Codex ~1-2s round trip with real skill metadata; Gemini's ACP handshake completes correctly at the protocol level (blocked only by an unrelated account-tier restriction on the specific test account).

Notes / follow-ups

  • Codex's and Claude's internal control protocols are not versioned public APIs — they can change on any release without notice. Every failure mode (timeout, parse error, exit, unrecognized response shape) is treated as routine; there is no fallback, so a broken probe just means no "/" completion until it's fixed or the source is turned off.
  • acp.lua's cache is keyed only by cwd, not by agent — fine while Gemini is the only ACP-native agent wired up; revisit if a second one is added for the same cwd.
  • aibo dispatches purely on the invoked command's first word — there is no -tool=/alias option, so a custom tools.<name> profile only applies to invocations whose first word is literally <name> (e.g. tools.ollama for :Aibo ollama launch claude ..., not an arbitrary label). Adding such an override is a separate, larger change (touches argument parsing and buffer naming), not included here.
  • GitHub Copilot CLI, Cursor CLI, and Cline CLI 2.0 also speak ACP natively but have no aibo integration yet; wiring them up would just be another thin completion/<agent>.lua over the existing generic client.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings June 27, 2026 08:07
@coderabbitai

coderabbitai Bot commented Jun 27, 2026 •

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR replaces static/disk-scanned slash-command completion sources with live probing for Claude, Codex, and ACP-native agents (Gemini). It adds configuration types, shared probe/cache/omnifunc infrastructure, per-tool probe modules, ftplugin wiring, health checks, tests, and documentation.

Changes

Live probe-based slash completion

Layer / File(s) Summary
Completion configuration surface
lua/aibo/init.lua, tests/internal/test_init.lua
Adds AiboProbeConfig/AiboCompletionConfig types, completion field/defaults, and get_completion_config(name) accessor.
Shared probe, cache, and omnifunc helpers
lua/aibo/completion/probe.lua, lua/aibo/completion/cwd_cache.lua, lua/aibo/completion/omnifunc.lua
Adds subprocess JSON-RPC exchange helper, per-cwd caching, and a shared omnifunc factory for / and @ completion routing.
Generic ACP probe and Gemini wiring
lua/aibo/completion/acp.lua, lua/aibo/completion/gemini.lua, tests/completion/fixtures/fake_acp.lua, tests/completion/test_acp.lua, tests/completion/test_gemini.lua
Implements ACP-native probing (initialize, session/new, session/update parsing, caching) and wires Gemini onto it.
Claude live probe
lua/aibo/completion/claude.lua, tests/completion/fixtures/fake_claude_probe.lua, tests/completion/test_claude.lua
Replaces static command list with a stream-json control-protocol probe, caching, and omnifunc wiring.
Codex live probe
lua/aibo/completion/codex.lua, tests/completion/fixtures/fake_codex_probe.lua, tests/completion/test_codex.lua
Adds a Codex app-server JSON-RPC probe (initialize then skills/list), caching, and omnifunc wiring.
Ftplugin wiring and health checks
lua/aibo/completion/prompt_ftplugin.lua, ftplugin/aibo-tool-claude.lua, ftplugin/aibo-tool-codex.lua, ftplugin/aibo-tool-gemini.lua, lua/aibo/health.lua
Adds shared prompt-buffer setup/trigger helpers, wires all three tool ftplugins, and reports probe resolution status in :checkhealth.
Documentation
README.md, doc/aibo-live-completion.txt, doc/aibo-acp.txt, doc/aibo-claude.txt, doc/aibo-codex.txt, doc/aibo-dev.txt
Documents the live completion design, per-tool probe behavior, billing safety, and configuration.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Ftplugin as ftplugin/aibo-tool-*.lua
  participant PromptFtplugin as prompt_ftplugin
  participant Completion as completion module (claude/codex/gemini)
  participant Agent as CLI/Adapter process

  Ftplugin->>PromptFtplugin: setup_completion(bufnr, module, config_key)
  PromptFtplugin->>Completion: refresh_acp(opts, callback)
  Completion->>Agent: spawn probe (initialize, protocol-specific request)
  Agent-->>Completion: command/skill list
  Completion-->>PromptFtplugin: cached entries or error
  Ftplugin->>PromptFtplugin: setup_triggers(bufnr)
  Note over Ftplugin,Completion: omnifunc later reads cached entries for "/" completion
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 65.38% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is clear and accurately summarizes the main change: live slash-command completion for Claude, Codex, and Gemini with per-tool config.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/acp-overview-j4ocj4

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds an opt-in Claude slash-command completion source that probes the Agent Client Protocol (ACP) adapter for a live, version-accurate command list, caches it per-cwd, and prefers it over the static BUILTIN_COMMANDS when present—while preserving the existing PTY-based interactive session and falling back to the static sources when ACP is unavailable.

Changes:

  • Introduces an async ACP probe client (vim.system, newline-delimited JSON-RPC) with per-cwd caching and defensive parsing.
  • Updates Claude completion to prefer cached ACP commands as the base list and adds an explicit refresh_acp() warmer.
  • Adds opt-in cache warming in the Claude ftplugin plus documentation and test coverage (including a fake adapter fixture).

Reviewed changes

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

Show a summary per file
File Description
lua/aibo/completion/acp.lua New ACP probe client: initialize → session/new → cache available_commands_update.
lua/aibo/completion/claude.lua Prefer cached ACP list as completion base; expose refresh_acp().
ftplugin/aibo-tool-claude.lua Opt-in cache warming on Claude prompt buffer load (only if adapter exists).
tests/completion/test_acp.lua New unit/integration tests for parser, cache, refresh, and adapter-missing path.
tests/completion/fixtures/fake_acp.lua Fake ACP adapter fixture that replays a recorded available_commands_update.
tests/completion/test_claude.lua Tests that builtin base is used on cache miss and ACP base is preferred once cached.
README.md Documents tools.claude.acp_completion option and requirements.
lua/aibo/init.lua Adds acp_completion to the Claude tool config type annotation.
ACP_COMPLETION_OVERVIEW.md Design/overview doc for ACP-backed completion and rationale.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ACP_COMPLETION_OVERVIEW.md Resolved
Comment thread lua/aibo/completion/acp.lua Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
ftplugin/aibo-tool-claude.lua (1)

24-34: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Minor duplication: get_tool_config("claude") fetched twice.

claude_cfg (line 24) and cfg (line 34) resolve the same tool config. Reuse a single lookup to keep the ftplugin tidy.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ftplugin/aibo-tool-claude.lua` around lines 24 - 34, The claude ftplugin is
doing the same tool-config lookup twice, once in the completion setup and again
before the default key mappings. Reuse a single `aibo.get_tool_config("claude")`
result in `aibo-tool-claude.lua` and thread that config through the completion
and mapping setup so the file only resolves the claude config once.
lua/aibo/completion/acp.lua (1)

182-217: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Adapter early-exit / stdout EOF isn't handled, so failures wait the full timeout.

The on_exit handler is a no-op (Line 212) and on_stdout simply returns on EOF (data == nil, Line 183). If the adapter spawns but crashes, exits, or closes stdout before pushing available_commands_update (e.g. not logged in, version mismatch), nothing calls finish until the timer expires — the caller waits the full timeout (default 10s) before silently falling back. Wiring finish(nil, err) into on_exit (and on stdout EOF) lets the fallback happen promptly with a clearer error.

♻️ Finish early on unexpected exit
   state.proc = vim.system(cmd, {
     cwd = cwd,
     stdin = true,
     stdout = on_stdout,
     text = true,
-  }, function() end)
+  }, function(obj)
+    -- If the adapter exits before delivering available_commands_update,
+    -- fail fast instead of waiting out the timeout.
+    finish(nil, ("ACP adapter exited (code=%s, signal=%s) before delivering commands"):format(
+      tostring(obj.code), tostring(obj.signal)))
+  end)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lua/aibo/completion/acp.lua` around lines 182 - 217, The ACP probe path in
on_stdout and the vim.system exit callback does not finish early when the
adapter exits or closes stdout before sending available_commands_update, so
failures wait for the full timeout. Update the acp.lua flow by handling EOF in
on_stdout and replacing the no-op vim.system callback with an on_exit handler
that calls finish(nil, err) for unexpected exits, while keeping the existing
state.done guard so the fallback happens promptly instead of silently timing
out.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ACP_COMPLETION_OVERVIEW.md`:
- Around line 1-6: The status header in ACP_COMPLETION_OVERVIEW.md is stale and
still says the design is only a proposal, which conflicts with the implemented
sections and shipped feature. Update the top-level status text to reflect the
completed/implemented state, and make it consistent with the ✅ items in §8 so
readers see the correct lifecycle for the ACP completion work.

In `@ftplugin/aibo-tool-claude.lua`:
- Line 28: The warm-up call to refresh_acp in aibo-tool-claude.lua is using
empty options, which makes the probe fall back to a different cwd and MCP server
set than the live Claude session. Update the call site to pass the session’s
actual cwd and mcpServers into refresh_acp so the ACP probe uses the same
configuration as the real session and returns a matching command list.

In `@lua/aibo/completion/acp.lua`:
- Around line 82-94: The ACP refresh path in M.refresh should not respawn the
adapter when the cache already has a live entry for the current cwd. Add a
short-circuit near the existing executable check and before launching the
refresh command so it consults acp.get_cached() (or the existing cache helper
used by the ACP module) and returns the cached result when warm, instead of
re-probing on every ftplugin load. Keep the behavior localized to M.refresh and
preserve the current callback/error flow when the adapter is actually missing or
stale.

---

Nitpick comments:
In `@ftplugin/aibo-tool-claude.lua`:
- Around line 24-34: The claude ftplugin is doing the same tool-config lookup
twice, once in the completion setup and again before the default key mappings.
Reuse a single `aibo.get_tool_config("claude")` result in `aibo-tool-claude.lua`
and thread that config through the completion and mapping setup so the file only
resolves the claude config once.

In `@lua/aibo/completion/acp.lua`:
- Around line 182-217: The ACP probe path in on_stdout and the vim.system exit
callback does not finish early when the adapter exits or closes stdout before
sending available_commands_update, so failures wait for the full timeout. Update
the acp.lua flow by handling EOF in on_stdout and replacing the no-op vim.system
callback with an on_exit handler that calls finish(nil, err) for unexpected
exits, while keeping the existing state.done guard so the fallback happens
promptly instead of silently timing out.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a3bb71ad-9071-4b64-9a80-3006d890198a

📥 Commits

Reviewing files that changed from the base of the PR and between 0e9034d and 53c39d3.

📒 Files selected for processing (9)
  • ACP_COMPLETION_OVERVIEW.md
  • README.md
  • ftplugin/aibo-tool-claude.lua
  • lua/aibo/completion/acp.lua
  • lua/aibo/completion/claude.lua
  • lua/aibo/init.lua
  • tests/completion/fixtures/fake_acp.lua
  • tests/completion/test_acp.lua
  • tests/completion/test_claude.lua

Comment thread ACP_COMPLETION_OVERVIEW.md Resolved
Comment thread ftplugin/aibo-tool-claude.lua Resolved
Comment thread lua/aibo/completion/acp.lua Resolved
@lambdalisue
lambdalisue force-pushed the claude/acp-overview-j4ocj4 branch 2 times, most recently from 6bf7f1f to ef66d3f Compare June 28, 2026 09:40
@lambdalisue lambdalisue changed the title feat(completion): live ACP-sourced slash-command completion for Claude (opt-in) feat(completion): live ACP-sourced slash-command completion for Claude (auto-detected) Jun 28, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lua/aibo/completion/acp.lua`:
- Around line 174-188: The auto-install flow in M.acp currently runs even for
custom opts.cmd values that cannot use the plugin-local fallback, which can lead
to an unnecessary npm install followed by a refresh failure. Update the logic
around M.is_available, M.install, and the auto_install branch so installation
only happens for the default adapter command, or alternatively make
resolve_cmd() reuse the installed local bin for those cases; ensure custom
commands skip auto-install when they cannot resolve to the local binary.
- Around line 137-139: The npm-missing branch in the ACP auto-install flow
returns before the one-shot state is recorded, so repeated Claude prompt buffers
keep retrying the same failed install. Update the ACP adapter install logic
around the `install_attempted` flag so this failure path also marks the attempt
as handled before returning, and keep the early `callback(false, ...)` behavior
in the same `acp.lua` install routine.

In `@lua/aibo/init.lua`:
- Around line 39-48: The default ACP completion config for the Claude tool is
currently enabling warm-up implicitly, making it opt-out instead of opt-in.
Update the default in the `tools.claude.acp` setup so it is `false` or omitted
by default, and only activates when a user explicitly configures it; make sure
the `ftplugin/aibo-tool-claude.lua` warm-up path still keys off `claude_cfg.acp`
so explicit user settings continue to work.

In `@tests/completion/test_acp.lua`:
- Around line 95-116: The test mutates process-wide state by overriding
vim.env.XDG_DATA_HOME, but the cleanup runs only after the assertions, so a
failure can leak the temporary value into later tests. Update the test around
acp.resolve_cmd to restore the original XDG_DATA_HOME and delete the temp dir in
a guaranteed cleanup path (for example using pcall/xpcall or a finally-like
helper) so cleanup runs even when the assertion fails.

In `@tests/internal/test_init.lua`:
- Around line 102-123: The default ACP assertions in the `claude acp config
defaults and override` test are order-dependent because `aibo.setup()` is
incremental and previous tests may have already mutated `tools.claude.acp`.
Reload `aibo` before the initial default checks so the test starts from a clean
configuration state, then keep the existing override assertions against
`aibo.get_tool_config("claude")` and the later `aibo.setup(...)` calls
unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fd3fadc7-ff65-4a6a-af97-f388658bf970

📥 Commits

Reviewing files that changed from the base of the PR and between 6bf7f1f and ef66d3f.

📒 Files selected for processing (11)
  • ACP_COMPLETION_OVERVIEW.md
  • README.md
  • ftplugin/aibo-tool-claude.lua
  • lua/aibo/completion/acp.lua
  • lua/aibo/completion/claude.lua
  • lua/aibo/health.lua
  • lua/aibo/init.lua
  • tests/completion/fixtures/fake_acp.lua
  • tests/completion/test_acp.lua
  • tests/completion/test_claude.lua
  • tests/internal/test_init.lua
✅ Files skipped from review due to trivial changes (1)
  • ACP_COMPLETION_OVERVIEW.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/completion/fixtures/fake_acp.lua
  • lua/aibo/completion/claude.lua
  • tests/completion/test_claude.lua

Comment thread lua/aibo/completion/acp.lua Resolved
Comment thread lua/aibo/completion/acp.lua Resolved
Comment thread lua/aibo/init.lua Resolved
Comment thread tests/completion/test_acp.lua Resolved
Comment thread tests/internal/test_init.lua Resolved
@lambdalisue lambdalisue changed the title feat(completion): live ACP-sourced slash-command completion for Claude (auto-detected) feat(completion): live ACP-sourced slash-command completion for Claude (opt-in) Jul 1, 2026
@lambdalisue
lambdalisue force-pushed the claude/acp-overview-j4ocj4 branch 2 times, most recently from 17ea918 to 674ef06 Compare July 7, 2026 05:38
@lambdalisue lambdalisue changed the title feat(completion): live ACP-sourced slash-command completion for Claude (opt-in) feat(completion): live / completion for claude, codex, and gemini (no adapter, opt-in) Jul 7, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (6)
lua/aibo/completion/probe.lua (1)

53-76: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Consider bounding state.buf growth.

If the spawned process emits data without newlines (e.g., a malfunctioning binary), state.buf grows unbounded until the timeout fires. Low risk given trusted CLI targets, but a simple size cap (finish with an error) would guard against pathological cases.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lua/aibo/completion/probe.lua` around lines 53 - 76, The stdout parser in
on_stdout can accumulate an unbounded state.buf when the child process emits no
newline-delimited output. Add a maximum buffer size check in probe.lua’s
on_stdout loop, and if the cap is exceeded, stop processing and call finish with
an error so malformed output cannot grow memory indefinitely. Keep the existing
line-splitting and handlers.on_message flow intact while guarding the state.buf
append path.
lua/aibo/completion/codex.lua (1)

183-197: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Same synchronous-callback inconsistency as flagged in acp.lua's ensure_and_refresh (Lines 192-195 here mirror that pattern).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lua/aibo/completion/codex.lua` around lines 183 - 197, The refresh_acp
callback path has the same synchronous-callback inconsistency as
ensure_and_refresh: when codex is unavailable, callback is invoked immediately
while the successful path is asynchronous via refresh_probe. Update
M.refresh_acp to make callback timing consistent across both branches by
deferring the error callback in the unavailable case, and keep the behavior
aligned with the pattern used in the related ACP refresh flow.
lua/aibo/completion/gemini.lua (1)

58-62: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Avoid mutating the caller-supplied opts table.

opts.cmd = opts.cmd or DEFAULT_PROBE_CMD mutates the table passed in by the caller (e.g. a shared tools.gemini.acp config table) rather than working on a local copy. Harmless today since the effective value stays consistent, but it's a side-effect surprise for callers reusing the same table across calls.

♻️ Proposed fix
 function M.refresh_acp(opts, callback)
-  opts = opts or {}
-  opts.cmd = opts.cmd or DEFAULT_PROBE_CMD
-  acp.ensure_and_refresh(opts, callback)
+  opts = opts or {}
+  acp.ensure_and_refresh(vim.tbl_extend("force", { cmd = DEFAULT_PROBE_CMD }, opts), callback)
 end
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lua/aibo/completion/gemini.lua` around lines 58 - 62, In M.refresh_acp, avoid
changing the caller’s opts table in place; the current opts.cmd assignment
mutates shared config passed by callers. Make a local copy of opts inside
refresh_acp, apply the DEFAULT_PROBE_CMD fallback on that copy, and pass the
copied table to acp.ensure_and_refresh so repeated calls with the same
tools.gemini.acp settings do not get side effects.
lua/aibo/completion/acp.lua (1)

88-96: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Inconsistent sync/async callback contract in ensure_and_refresh.

The "not available" early return (Line 92) invokes callback synchronously, while refresh's own "cmd not found" branch (Lines 108-113) wraps it in vim.schedule. Callers that assume the callback always fires asynchronously (e.g., after the current call stack unwinds) can be surprised by the sync path. Worth making both branches consistently scheduled. The same pattern is repeated in claude.lua's and codex.lua's refresh_acp.

♻️ Proposed fix
 function M.ensure_and_refresh(opts, callback)
   opts = opts or {}
   callback = callback or function() end
   if not M.is_available(opts) then
-    callback(nil, "ACP agent not found: " .. tostring(opts.cmd and opts.cmd[1]))
-    return
+    vim.schedule(function()
+      callback(nil, "ACP agent not found: " .. tostring(opts.cmd and opts.cmd[1]))
+    end)
+    return
   end
   M.refresh(opts, callback)
 end

Also applies to: 102-113

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lua/aibo/completion/acp.lua` around lines 88 - 96, `ensure_and_refresh`
currently mixes synchronous and scheduled callback delivery: the early
`M.is_available(opts)` failure calls `callback` immediately, while `M.refresh`
and its missing-command path use `vim.schedule`. Make the not-available branch
in `ensure_and_refresh` also invoke the callback via `vim.schedule` so the
contract is consistently async; apply the same pattern in the corresponding
`refresh_acp` flow in `claude.lua` and `codex.lua` if they have the same
early-return path.
lua/aibo/completion/claude.lua (1)

185-199: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Same synchronous-callback inconsistency as acp.lua's ensure_and_refresh: the "not found" branch (Lines 194-197) calls callback directly instead of scheduling it, unlike refresh_probe's own not-found path (Lines 122-127). See the comment on lua/aibo/completion/acp.lua (Lines 88-96) for the suggested fix; same pattern applies here.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lua/aibo/completion/claude.lua` around lines 185 - 199, In M.refresh_acp, the
"claude not found" branch currently invokes callback synchronously, which is
inconsistent with the async callback behavior used elsewhere in the completion
flow. Update this branch to schedule the callback on the next tick, matching the
pattern used by refresh_probe and the corresponding ensure_and_refresh logic in
acp.lua, and keep the same error message construction using M.is_available,
DEFAULT_PROBE_CMD, and callback.
lua/aibo/completion/prompt_ftplugin.lua (1)

25-34: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Concurrent buffer opens in the same cwd can trigger duplicate probe spawns.

get_cached() (sync) is checked before refresh_acp() (async) with no in-flight tracking. Opening two prompt buffers for the same cwd back-to-back, before the first probe's callback populates the cache, spawns the external agent process twice for the same cache key.

♻️ Sketch: track in-flight refresh per cwd
+local inflight = {}
+
 function M.setup_completion(bufnr, module_name, config_key)
   ...
   if probe_cfg then
     local cfg = type(probe_cfg) == "table" and probe_cfg or {}
-    if not completion.get_cached() then
-      completion.refresh_acp({ cmd = cfg.cmd, timeout = cfg.timeout })
+    local cwd = cfg.cwd or vim.fn.getcwd()
+    local key = module_name .. ":" .. cwd
+    if not completion.get_cached(cwd) and not inflight[key] then
+      inflight[key] = true
+      completion.refresh_acp({ cmd = cfg.cmd, cwd = cwd, timeout = cfg.timeout }, function()
+        inflight[key] = nil
+      end)
     end
   end
 end
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lua/aibo/completion/prompt_ftplugin.lua` around lines 25 - 34, The probe path
in prompt_ftplugin.lua can spawn duplicate agents because
completion.get_cached() is checked before the async refresh_acp() finishes.
Update the prompt buffer setup logic around aibo.get_completion_config,
completion.get_cached, and completion.refresh_acp to track an in-flight refresh
per cwd and skip starting another probe while one is already pending. Use the
existing cwd/cache-key flow in completion so back-to-back opens reuse the same
pending request instead of launching the external agent twice.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lua/aibo/completion/acp.lua`:
- Around line 126-131: The initialize handshake in acp.lua is advertising a
capability that this client does not actually support. Update the on_start/send
path in the request("initialize", ...) setup so
clientCapabilities.fs.readTextFile is reported as false instead of true, since
fs/read_text_file is not implemented and should not be promised by this client.

---

Nitpick comments:
In `@lua/aibo/completion/acp.lua`:
- Around line 88-96: `ensure_and_refresh` currently mixes synchronous and
scheduled callback delivery: the early `M.is_available(opts)` failure calls
`callback` immediately, while `M.refresh` and its missing-command path use
`vim.schedule`. Make the not-available branch in `ensure_and_refresh` also
invoke the callback via `vim.schedule` so the contract is consistently async;
apply the same pattern in the corresponding `refresh_acp` flow in `claude.lua`
and `codex.lua` if they have the same early-return path.

In `@lua/aibo/completion/claude.lua`:
- Around line 185-199: In M.refresh_acp, the "claude not found" branch currently
invokes callback synchronously, which is inconsistent with the async callback
behavior used elsewhere in the completion flow. Update this branch to schedule
the callback on the next tick, matching the pattern used by refresh_probe and
the corresponding ensure_and_refresh logic in acp.lua, and keep the same error
message construction using M.is_available, DEFAULT_PROBE_CMD, and callback.

In `@lua/aibo/completion/codex.lua`:
- Around line 183-197: The refresh_acp callback path has the same
synchronous-callback inconsistency as ensure_and_refresh: when codex is
unavailable, callback is invoked immediately while the successful path is
asynchronous via refresh_probe. Update M.refresh_acp to make callback timing
consistent across both branches by deferring the error callback in the
unavailable case, and keep the behavior aligned with the pattern used in the
related ACP refresh flow.

In `@lua/aibo/completion/gemini.lua`:
- Around line 58-62: In M.refresh_acp, avoid changing the caller’s opts table in
place; the current opts.cmd assignment mutates shared config passed by callers.
Make a local copy of opts inside refresh_acp, apply the DEFAULT_PROBE_CMD
fallback on that copy, and pass the copied table to acp.ensure_and_refresh so
repeated calls with the same tools.gemini.acp settings do not get side effects.

In `@lua/aibo/completion/probe.lua`:
- Around line 53-76: The stdout parser in on_stdout can accumulate an unbounded
state.buf when the child process emits no newline-delimited output. Add a
maximum buffer size check in probe.lua’s on_stdout loop, and if the cap is
exceeded, stop processing and call finish with an error so malformed output
cannot grow memory indefinitely. Keep the existing line-splitting and
handlers.on_message flow intact while guarding the state.buf append path.

In `@lua/aibo/completion/prompt_ftplugin.lua`:
- Around line 25-34: The probe path in prompt_ftplugin.lua can spawn duplicate
agents because completion.get_cached() is checked before the async refresh_acp()
finishes. Update the prompt buffer setup logic around
aibo.get_completion_config, completion.get_cached, and completion.refresh_acp to
track an in-flight refresh per cwd and skip starting another probe while one is
already pending. Use the existing cwd/cache-key flow in completion so
back-to-back opens reuse the same pending request instead of launching the
external agent twice.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 42cf6b48-1b9a-4322-b3a8-5312ddc04f62

📥 Commits

Reviewing files that changed from the base of the PR and between 17ea918 and 674ef06.

📒 Files selected for processing (28)
  • .claude/rules/completion/sync-claude-slash-commands.md
  • README.md
  • doc/aibo-acp.txt
  • doc/aibo-claude.txt
  • doc/aibo-codex.txt
  • doc/aibo-dev.txt
  • doc/aibo-live-completion.txt
  • ftplugin/aibo-tool-claude.lua
  • ftplugin/aibo-tool-codex.lua
  • ftplugin/aibo-tool-gemini.lua
  • lua/aibo/completion/acp.lua
  • lua/aibo/completion/claude.lua
  • lua/aibo/completion/codex.lua
  • lua/aibo/completion/cwd_cache.lua
  • lua/aibo/completion/gemini.lua
  • lua/aibo/completion/omnifunc.lua
  • lua/aibo/completion/probe.lua
  • lua/aibo/completion/prompt_ftplugin.lua
  • lua/aibo/health.lua
  • lua/aibo/init.lua
  • tests/completion/fixtures/fake_acp.lua
  • tests/completion/fixtures/fake_claude_probe.lua
  • tests/completion/fixtures/fake_codex_probe.lua
  • tests/completion/test_acp.lua
  • tests/completion/test_claude.lua
  • tests/completion/test_codex.lua
  • tests/completion/test_gemini.lua
  • tests/internal/test_init.lua
💤 Files with no reviewable changes (1)
  • .claude/rules/completion/sync-claude-slash-commands.md
✅ Files skipped from review due to trivial changes (5)
  • lua/aibo/completion/cwd_cache.lua
  • README.md
  • doc/aibo-dev.txt
  • doc/aibo-live-completion.txt
  • doc/aibo-acp.txt
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/completion/fixtures/fake_acp.lua

Comment on lines +126 to +131
on_start = function(send)
request(send, "initialize", {
protocolVersion = 1,
clientCapabilities = { fs = { readTextFile = true, writeTextFile = false } },
})
end,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Does the Agent Client Protocol require a client that advertises fs.readTextFile=true to actually implement fs/read_text_file, and what happens if a client returns an empty object instead of {content}?

💡 Result:

Yes, the Agent Client Protocol (ACP) requires a client that advertises the fs.readTextFile capability to implement the fs/read_text_file method [1][2]. If a client signals this capability during initialization, it is committing to providing that functionality, and an agent is permitted to call the method [1][3]. If a client returns an empty object {} instead of the expected {content: string} response for an fs/read_text_file request, it violates the protocol's expected response schema [4]. The fs/read_text_file method is defined to return a response containing the file's content [1][5]. Because the agent expects a specific structure containing the file content to proceed with its task, receiving an empty object will cause a runtime error, deserialization failure, or an agent-side logic error when it attempts to access the missing 'content' property [4]. In contrast, the fs/write_text_file method is explicitly designed to return an empty object {} upon successful completion [4]. Clients must strictly adhere to the defined return types for each method to ensure protocol interoperability [5][4].

Citations:


🏁 Script executed:

git ls-files 'lua/aibo/completion/acp.lua' && wc -l lua/aibo/completion/acp.lua && sed -n '1,220p' lua/aibo/completion/acp.lua

Repository: lambdalisue/nvim-aibo

Length of output: 6888


🏁 Script executed:

rg -n "readTextFile|writeTextFile|session/request_permission|available_commands_update|fs/read_text_file|vim.empty_dict|on_message|initialize" lua/aibo/completion/acp.lua

Repository: lambdalisue/nvim-aibo

Length of output: 1036


🏁 Script executed:

#!/bin/bash
set -euo pipefail
file='lua/aibo/completion/acp.lua'
echo '--- line count ---'
wc -l "$file"
echo '--- matching lines ---'
rg -n "readTextFile|writeTextFile|session/request_permission|available_commands_update|fs/read_text_file|vim.empty_dict|on_message|initialize" "$file"
echo '--- excerpt ---'
sed -n '100,190p' "$file"

Repository: lambdalisue/nvim-aibo

Length of output: 3770


🏁 Script executed:

python3 - <<'PY'
from pathlib import Path
p = Path('lua/aibo/completion/acp.lua')
text = p.read_text()
for needle in ['readTextFile', 'writeTextFile', 'session/request_permission', 'available_commands_update', 'fs/read_text_file', 'vim.empty_dict', 'on_message', 'initialize']:
    print(f'## {needle}')
    for i, line in enumerate(text.splitlines(), 1):
        if needle in line:
            print(f'{i}: {line}')
PY

Repository: lambdalisue/nvim-aibo

Length of output: 1298


Advertise readTextFile: false here. fs/read_text_file isn’t implemented, so readTextFile: true promises a request this client answers with {} and can leave the agent hanging until timeout.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lua/aibo/completion/acp.lua` around lines 126 - 131, The initialize handshake
in acp.lua is advertising a capability that this client does not actually
support. Update the on_start/send path in the request("initialize", ...) setup
so clientCapabilities.fs.readTextFile is reported as false instead of true,
since fs/read_text_file is not implemented and should not be promised by this
client.

… for live "/" completion

Claude's static BUILTIN_COMMANDS table and the ~/.claude/commands and
~/.claude/skills disk scans drift with every release and never see
plugin-provided, MCP-provided, or dynamically-enabled commands. Neither
claude nor codex speaks the Agent Client Protocol (ACP) themselves --
that only exists via separate adapters wrapping their SDKs/runtimes --
so both are probed directly instead: claude via its own internal
stream-json control protocol, codex via its self-documenting
`codex app-server` JSON-RPC protocol. Both send only a control-plane
request, never a prompt, so no inference runs and no tokens are spent.

acp.lua stays a generic, agent-agnostic Agent Client Protocol client
(no default cmd) for agents that speak ACP natively -- gemini.lua wires
it up for Gemini CLI (`gemini --acp`) as the first consumer.

probe.lua, cwd_cache.lua, and omnifunc.lua factor out the async
subprocess/JSON-message plumbing, per-cwd result cache, and
omnifunc/prefix-filtering logic shared by all of the above, since none
of that differs between the three probes.
… helper

The omnifunc setup, probe-cache warming, and "/"/"@" auto-trigger
keymaps were identical across aibo-tool-claude.lua and
aibo-tool-codex.lua, differing only in which completion submodule and
config key they used. prompt_ftplugin.lua factors that out so adding
Gemini's ftplugin is a few lines instead of a full copy.
New completion.{claude,codex,acp} config, keyed by tool (acp.lua itself
has no default agent, so a bare true/false wouldn't mean anything
without a tool-specific module to supply the default cmd). All three
are on by default since none of them has a static or disk-scanned
fallback to preserve.

checkhealth reports whether each probe target resolves.
test_claude.lua drops the BUILTIN_COMMANDS/disk-scan coverage (removed
in the previous commits) and adds cases for the empty-cache and
probed-cache states instead. test_acp.lua, test_codex.lua, and
test_gemini.lua are new, each driven against a fake responder fixture
that replays a recorded protocol exchange so no real agent binary is
needed in CI.
Replace the root-level ACP_COMPLETION_OVERVIEW.md with proper :help
pages, since this is a Neovim plugin: aibo-live-completion.txt is the
overview (motivation, billing safety, process management,
configuration); aibo-acp.txt narrows to the real Agent Client Protocol
and Gemini's use of it; aibo-claude.txt and aibo-codex.txt cover each
tool's own (non-ACP) probe protocol and verification notes.
Summarized a long-since-completed refactor (agent→tool terminology,
module reorganization) with nothing left to track.
@lambdalisue
lambdalisue force-pushed the claude/acp-overview-j4ocj4 branch from 84a4de0 to de68033 Compare July 7, 2026 06:47
@lambdalisue lambdalisue changed the title feat(completion): live / completion for claude, codex, and gemini (no adapter, opt-in) feat(completion): live "/" completion for claude, codex, and gemini (no adapter, per-tool config) Jul 7, 2026
leafo/gh-actions-lua downloads and builds Lua from lua.org, which was
consistently failing with a TLS connection reset (reproduced across
multiple CI runs, unrelated to any code change). Ubuntu's own lua5.1
package needs no external download beyond GitHub's apt mirrors.
@lambdalisue
lambdalisue merged commit ec9ab10 into main Jul 7, 2026
5 checks passed
@lambdalisue
lambdalisue deleted the claude/acp-overview-j4ocj4 branch July 7, 2026 08:31
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