Skip to content

Commit bb725e3

Browse files
authored
Merge pull request #318 from sirmacik/feat/add-kilo-backend
Feat: Add Kilo backend support (Opencode fork)
2 parents 2e20ca5 + 322043f commit bb725e3

8 files changed

Lines changed: 265 additions & 29 deletions

AGENTS.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The project uses melpazoid for CI checks. The workflow is defined in `.github/wo
3434
## High-Level Architecture
3535

3636
### Core Design Philosophy
37-
This is a unified interface package for AI-assisted software development that abstracts over multiple AI coding CLI backends (Claude Code, Gemini CLI, OpenAI Codex, GitHub Copilot CLI, Opencode, Grok CLI, Cursor CLI, CodeBuddy Code CLI, Kiro CLI). The package provides a consistent user experience across different AI tools while maintaining context-aware code actions and agile development workflows.
37+
This is a unified interface package for AI-assisted software development that abstracts over multiple AI coding CLI backends (Claude Code, Gemini CLI, OpenAI Codex, GitHub Copilot CLI, Opencode, Kilo, Grok CLI, Cursor CLI, CodeBuddy Code CLI, Kiro CLI). The package provides a consistent user experience across different AI tools while maintaining context-aware code actions and agile development workflows.
3838

3939
### Backend System Architecture
4040

@@ -93,7 +93,7 @@ The codebase is organized into focused modules:
9393
- **`ai-code-prompt-mode.el`**: Prompt file management (`.ai.code.prompt.org`), @-completion, yasnippet integration
9494
- **`ai-code-input.el`**: User input handling, context gathering, completion utilities
9595
- **`ai-code-notifications.el`**: Desktop notifications for AI session completion
96-
- **Backend implementations**: `ai-code-codex-cli.el`, `ai-code-github-copilot-cli.el`, `ai-code-gemini-cli.el`, `ai-code-codebuddy-cli.el`, `ai-code-opencode.el`, `ai-code-grok-cli.el`, `ai-code-cursor-cli.el`, `ai-code-kiro-cli.el`, `ai-code-claude-code.el`
96+
- **Backend implementations**: `ai-code-codex-cli.el`, `ai-code-github-copilot-cli.el`, `ai-code-gemini-cli.el`, `ai-code-codebuddy-cli.el`, `ai-code-opencode.el`, `ai-code-kilo.el`, `ai-code-grok-cli.el`, `ai-code-cursor-cli.el`, `ai-code-kiro-cli.el`, `ai-code-claude-code.el`
9797

9898
### Transient Menu System
9999

@@ -205,6 +205,7 @@ Each backend requires the corresponding CLI to be installed and available on PAT
205205
- OpenAI Codex: `codex`
206206
- GitHub Copilot CLI: `copilot`
207207
- Opencode: `opencode`
208+
- Kilo: `kilo`
208209
- Grok CLI: `grok`
209210
- Cursor CLI: `cursor`
210211
- Kiro CLI: `kiro`

README.org

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ An Emacs interface for AI-assisted software development. *The purpose is to prov
1515
- [[https://github.com/google-gemini/gemini-cli][Gemini CLI]]
1616
- [[https://github.com/anthropics/claude-code][Claude Code]]
1717
- [[https://opencode.ai/][Opencode]]
18+
- [[https://kilo.dev/][Kilo]]
1819
- [[https://grokcli.io/][Grok CLI]]
1920
- [[https://docs.cursor.com/en/cli][Cursor CLI]]
2021
- [[https://kiro.dev/cli/][Kiro CLI]]
@@ -83,7 +84,7 @@ Enable installation of packages from MELPA by adding an entry to package-archive
8384
(use-package ai-code
8485
;; :straight (:host github :repo "tninja/ai-code-interface.el") ;; if you want to use straight to install, no need to have MELPA setting above
8586
:config
86-
;; use codex as backend, other options are 'claude-code, 'gemini, 'github-copilot-cli, 'opencode, 'grok, 'cursor, 'kiro, 'codebuddy, 'aider, 'eca, 'agent-shell, 'claude-code-ide, 'claude-code-el
87+
;; use codex as backend, other options are 'claude-code, 'gemini, 'github-copilot-cli, 'opencode, 'kilo, 'grok, 'cursor, 'kiro, 'codebuddy, 'aider, 'eca, 'agent-shell, 'claude-code-ide, 'claude-code-el
8788
(ai-code-set-backend 'codex)
8889
;; Optional: default menu stays unchanged; use a narrower 2-column layout on smaller frames
8990
;; (setq ai-code-menu-layout 'two-columns)
@@ -418,6 +419,7 @@ When working with multiple AI sessions, it can be useful to receive desktop noti
418419
- Binds =Shift+Enter=/=Ctrl+Enter= inside Claude sessions to send Claude's
419420
multiline input sequence.
420421
- [[https://opencode.ai/][Opencode]] (`[[./ai-code-opencode.el][ai-code-opencode.el]]`)
422+
- [[https://kilo.dev/][Kilo]] (`[[./ai-code-kilo.el][ai-code-kilo.el]]`)
421423
- [[https://grokcli.io/][Grok CLI]] (`[[./ai-code-grok-cli.el][ai-code-grok-cli.el]]`)
422424
- [[https://docs.cursor.com/en/cli][Cursor CLI]] (`[[./ai-code-cursor-cli.el][ai-code-cursor-cli.el]]`)
423425
- [[https://kiro.dev/cli/][Kiro CLI]] (`[[./ai-code-kiro-cli.el][ai-code-kiro-cli.el]]`)

ai-code-autoloads.el

Lines changed: 108 additions & 24 deletions
Large diffs are not rendered by default.

ai-code-backends.el

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,18 @@ so the CLI itself handles the installation details."
258258
:upgrade "npm i -g opencode-ai@latest"
259259
:install-skills nil
260260
:cli "opencode")
261+
(kilo
262+
:label "Kilo"
263+
:require ai-code-kilo
264+
:start ai-code-kilo
265+
:switch ai-code-kilo-switch-to-buffer
266+
:send ai-code-kilo-send-command
267+
:resume ai-code-kilo-resume
268+
:config "~/.config/kilo/kilo.json"
269+
:agent-file nil
270+
:upgrade "npm install -g kilo@latest"
271+
:install-skills nil
272+
:cli "kilo")
261273
(grok
262274
:label "Grok CLI"
263275
:require ai-code-grok-cli

ai-code-behaviors.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,6 +2234,7 @@ Call this when completely disabling ai-code-behaviors."
22342234

22352235
(defconst ai-code--backend-session-prefixes
22362236
'((opencode . "opencode")
2237+
(kilo . "kilo")
22372238
(claude-code . "claude")
22382239
(gemini . "gemini")
22392240
(github-copilot-cli . "copilot")

ai-code-kilo.el

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
;;; ai-code-kilo.el --- Thin wrapper for Kilo -*- lexical-binding: t; -*-
2+
3+
;; Author: sirmacik <sirmacik@wioo.waw.pl>
4+
;; SPDX-License-Identifier: Apache-2.0
5+
6+
;;; Commentary:
7+
;;
8+
;; Thin wrapper that reuses `ai-code-backends-infra' to run Kilo.
9+
;; Provides interactive commands and aliases for the AI Code suite.
10+
;;
11+
;; Kilo is a fork of Opencode, an open-source alternative to Claude Code
12+
;; that provides HTTP server APIs and customization features (LSP, custom
13+
;; LLM providers, etc.)
14+
;; See: https://kilo.dev/
15+
;;
16+
;;; Code:
17+
18+
(require 'ai-code-backends)
19+
(require 'ai-code-backends-infra)
20+
21+
22+
(defgroup ai-code-kilo nil
23+
"Kilo integration via `ai-code-backends-infra.el'."
24+
:group 'tools
25+
:prefix "ai-code-kilo-")
26+
27+
(defcustom ai-code-kilo-program "kilo"
28+
"Path to the Kilo executable."
29+
:type 'string
30+
:group 'ai-code-kilo)
31+
32+
(defcustom ai-code-kilo-program-switches nil
33+
"Command line switches to pass to Kilo on startup."
34+
:type '(repeat string)
35+
:group 'ai-code-kilo)
36+
37+
(defcustom ai-code-kilo-extra-env-vars
38+
'("OTUI_USE_ALTERNATE_SCREEN=main-screen")
39+
"Extra environment variables passed to the Kilo terminal session.
40+
`OTUI_USE_ALTERNATE_SCREEN=main-screen' avoids the alternate screen
41+
buffer so that terminal scrollback is partially preserved."
42+
:type '(repeat string)
43+
:group 'ai-code-kilo)
44+
45+
(defconst ai-code-kilo--session-prefix "kilo"
46+
"Session prefix used in Kilo buffer names.")
47+
48+
(defvar ai-code-kilo--processes (make-hash-table :test 'equal)
49+
"Hash table mapping Kilo session keys to processes.")
50+
51+
;;;###autoload
52+
(defun ai-code-kilo (&optional arg)
53+
"Start Kilo (uses `ai-code-backends-infra' logic).
54+
With prefix ARG, prompt for CLI args using
55+
`ai-code-kilo-program-switches' as the default input."
56+
(interactive "P")
57+
(let* ((working-dir (ai-code-backends-infra--session-working-directory))
58+
(resolved (ai-code-backends-infra--resolve-start-command
59+
ai-code-kilo-program
60+
ai-code-kilo-program-switches
61+
arg
62+
"Kilo"))
63+
(command (plist-get resolved :command)))
64+
(ai-code-backends-infra--toggle-or-create-session
65+
working-dir
66+
nil
67+
ai-code-kilo--processes
68+
command
69+
nil
70+
nil
71+
nil
72+
ai-code-kilo--session-prefix
73+
nil
74+
ai-code-kilo-extra-env-vars)))
75+
76+
;;;###autoload
77+
(defun ai-code-kilo-switch-to-buffer (&optional force-prompt)
78+
"Switch to the Kilo buffer.
79+
When FORCE-PROMPT is non-nil, prompt to select a session."
80+
(interactive "P")
81+
(let ((working-dir (ai-code-backends-infra--session-working-directory)))
82+
(ai-code-backends-infra--switch-to-session-buffer
83+
nil
84+
"No Kilo session for this project"
85+
ai-code-kilo--session-prefix
86+
working-dir
87+
force-prompt)))
88+
89+
;;;###autoload
90+
(defun ai-code-kilo-send-command (line)
91+
"Send LINE to Kilo.
92+
When called interactively, prompts for the command."
93+
(interactive "sKilo> ")
94+
(let ((working-dir (ai-code-backends-infra--session-working-directory)))
95+
(ai-code-backends-infra--send-line-to-session
96+
nil
97+
"No Kilo session for this project"
98+
line
99+
ai-code-kilo--session-prefix
100+
working-dir)))
101+
102+
;;;###autoload
103+
(defun ai-code-kilo-resume (&optional arg)
104+
"Resume a previous Kilo session.
105+
106+
This command starts Kilo with the --continue flag to resume
107+
a specific past session. The CLI will present an interactive list of past
108+
sessions to choose from.
109+
110+
If current buffer belongs to a project, start in the project's root
111+
directory. Otherwise start in the directory of the current buffer file,
112+
or the current value of `default-directory' if no project and no buffer file.
113+
114+
With double prefix ARG (\\[universal-argument] \\[universal-argument]),
115+
prompt for the project directory."
116+
(interactive "P")
117+
(let ((ai-code-kilo-program-switches
118+
(append ai-code-kilo-program-switches '("--continue"))))
119+
(ai-code-kilo arg)
120+
(let* ((working-dir (ai-code-backends-infra--session-working-directory))
121+
(buffer (ai-code-backends-infra--select-session-buffer
122+
ai-code-kilo--session-prefix
123+
working-dir)))
124+
(when buffer
125+
(with-current-buffer buffer
126+
(sit-for 0.5)
127+
(ai-code-backends-infra--terminal-send-string "")
128+
(goto-char (point-min)))))))
129+
130+
(provide 'ai-code-kilo)
131+
132+
;;; ai-code-kilo.el ends here

ai-code.el

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;;; ai-code.el --- Unified interface for AI coding backends such as Codex CLI, Copilot CLI, Claude Code, Gemini CLI, Opencode, Grok CLI, etc -*- lexical-binding: t; -*-
1+
;;; ai-code.el --- Unified interface for AI coding backends such as Codex CLI, Copilot CLI, Claude Code, Gemini CLI, Opencode, Kilo, Grok CLI, etc -*- lexical-binding: t; -*-
22

33
;; Author: Kang Tu <tninja@gmail.com>
44
;; Version: 1.74
@@ -21,6 +21,7 @@
2121
;; - Gemini CLI
2222
;; - Claude Code
2323
;; - Opencode
24+
;; - Kilo
2425
;; - Grok CLI
2526
;; - Cursor CLI
2627
;; - Kiro CLI
@@ -49,7 +50,7 @@
4950
;;
5051
;; (use-package ai-code
5152
;; :config
52-
;; ;; use codex as backend, other options are 'gemini, 'github-copilot-cli, 'opencode, 'grok, 'claude-code-ide, 'claude-code-el, 'claude-code, 'cursor, 'kiro, 'codebuddy, 'aider, 'agent-shell, 'eca
53+
;; ;; use codex as backend, other options are 'gemini, 'github-copilot-cli, 'opencode, 'kilo, 'grok, 'claude-code-ide, 'claude-code-el, 'claude-code, 'cursor, 'kiro, 'codebuddy, 'aider, 'agent-shell, 'eca
5354
;; (ai-code-set-backend 'codex) ;; set your preferred backend
5455
;; ;; Optional: use a narrower transient menu on smaller frames
5556
;; ;; (setq ai-code-menu-layout 'two-columns)
@@ -112,6 +113,7 @@
112113
(require 'ai-code-aider-cli)
113114
(require 'ai-code-github-copilot-cli)
114115
(require 'ai-code-opencode)
116+
(require 'ai-code-kilo)
115117
(require 'ai-code-grok-cli)
116118
(require 'ai-code-codebuddy-cli)
117119
(require 'ai-code-file)

test/test_ai-code-behaviors.el

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,12 +554,14 @@
554554
"Test that CLI backend session prefixes are defined."
555555
(should ai-code--backend-session-prefixes)
556556
(should (assoc 'opencode ai-code--backend-session-prefixes))
557+
(should (assoc 'kilo ai-code--backend-session-prefixes))
557558
(should (assoc 'claude-code ai-code--backend-session-prefixes))
558559
(should-not (assoc 'eca ai-code--backend-session-prefixes)))
559560

560561
(ert-deftest ai-code-test-get-session-prefix ()
561562
"Test getting session prefix for different backends."
562563
(should (equal "opencode" (alist-get 'opencode ai-code--backend-session-prefixes)))
564+
(should (equal "kilo" (alist-get 'kilo ai-code--backend-session-prefixes)))
563565
(should (equal "claude" (alist-get 'claude-code ai-code--backend-session-prefixes)))
564566
(should-not (alist-get 'eca ai-code--backend-session-prefixes)))
565567

0 commit comments

Comments
 (0)