Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

feat(endpoint): report Kimi Code in inventory, dashboard and token coverage

Claude0862ceb5a165
diff --git a/cli/beacon/internal/endpoint/dashboard/kimi_test.go b/cli/beacon/internal/endpoint/dashboard/kimi_test.go
new file mode 100644
index 00000000..2bf95f73
--- /dev/null
+++ b/cli/beacon/internal/endpoint/dashboard/kimi_test.go
@@ -0,0 +1,56 @@
+package dashboard
+
+import (
+ "path/filepath"
+ "testing"
+
+ endpointhooks "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/hooks"
+)
+
+// The dashboard's harness list is a hand-written sequence of calls, one per runtime, so a runtime
+// left out of it is simply absent from the page with nothing to say it should have been there. An
+// operator checking their coverage would conclude Kimi Code is not supported.
+func TestHookStatusesIncludesKimi(t *testing.T) {
+ home := t.TempDir()
+ t.Setenv("HOME", home)
+ t.Setenv("USERPROFILE", home)
+ t.Setenv("KIMI_CODE_HOME", "")
+
+ logPath := filepath.Join(home, "runtime.jsonl")
+ find := func() *HookStatus {
+ statuses := hookStatuses(logPath, true)
+ for i := range statuses {
+ if statuses[i].Target == "kimi" {
+ return &statuses[i]
+ }
+ }
+ return nil
+ }
+
+ kimi := find()
+ if kimi == nil {
+ t.Fatal("hookStatuses omits kimi; the dashboard would show it as an unsupported runtime")
+ }
+ if kimi.Installed {
+ t.Fatalf("kimi reported installed with no config on the machine: %+v", kimi)
+ }
+ // The path is what an operator opens to check for themselves, and on this runtime it is the
+ // runtime's own config rather than a file Beacon owns -- so an empty one would send them
+ // looking for a Beacon file that does not exist.
+ if kimi.Path == "" {
+ t.Fatalf("kimi reported no path: %+v", kimi)
+ }
+
+ if _, err := endpointhooks.InstallKimi(endpointhooks.KimiOptions{
+ Level: endpointhooks.LevelUser, LogPath: logPath, UserMode: true,
+ }); err != nil {
+ t.Fatalf("InstallKimi: %v", err)
+ }
+ after := find()
+ if after == nil {
+ t.Fatal("kimi disappeared from hookStatuses after an install")
+ }
+ if !after.Installed {
+ t.Fatalf("kimi still reported not installed after an install: %+v", after)
+ }
+}
diff --git a/cli/beacon/internal/endpoint/dashboard/server.go b/cli/beacon/internal/endpoint/dashboard/server.go
index 814c9483..34743e56 100644
--- a/cli/beacon/internal/endpoint/dashboard/server.go
+++ b/cli/beacon/internal/endpoint/dashboard/server.go
@@ -479,6 +479,8 @@ func hookStatuses(logPath string, userMode bool) []HookStatus {
// `beacon endpoint hooks status` reports both.
dsh := endpointhooks.DshHookStatus(endpointhooks.DshOptions{Level: level, LogPath: logPath, UserMode: userMode})
add("dsh", dsh.Installed, dsh.HooksPath, dsh.BinaryPath, dsh.Message)
+ kimi := endpointhooks.KimiHookStatus(endpointhooks.KimiOptions{Level: level, LogPath: logPath, UserMode: userMode})
+ add("kimi", kimi.Installed, kimi.HooksPath, kimi.BinaryPath, kimi.Message)
muse := endpointhooks.MuseHookStatus(endpointhooks.MuseOptions{Level: level, LogPath: logPath, UserMode: userMode})
add("muse", muse.Installed, muse.HooksPath, muse.BinaryPath, muse.Message)
qwen := endpointhooks.QwenHookStatus(endpointhooks.QwenOptions{Level: level, LogPath: logPath, UserMode: userMode})
diff --git a/cli/beacon/internal/endpoint/inventory/inventory.go b/cli/beacon/internal/endpoint/inventory/inventory.go
index 725af338..645fe2bb 100644
--- a/cli/beacon/internal/endpoint/inventory/inventory.go
+++ b/cli/beacon/internal/endpoint/inventory/inventory.go
@@ -248,6 +248,7 @@ func candidates(home, wd string) []candidate {
items = append(items, openHandsCandidates(home, wd)...)
items = append(items, kiroCandidates(home, wd)...)
items = append(items, dshCandidates(home)...)
+ items = append(items, kimiCandidates(home)...)
items = append(items, fxCandidates(home, wd)...)
seen := map[string]bool{}
out := make([]candidate, 0, len(items))
@@ -580,6 +581,36 @@ func dshCandidates(home string) []candidate {
}
}
+// kimiCandidates covers the one file a Kimi Code install touches.
+//
+// One file, and it is the runtime's own `config.toml` -- the same file that holds
+// `[providers.<name>].api_key`, the model catalog and the permission rules. That is worth
+// noticing here rather than only in the installer: this row points the inventory at a document
+// where Beacon's hooks are a minority of the content, so detection keys on the hook command and
+// nothing about the file existing counts as an install.
+//
+// No project scope, because Kimi Code has none: it reads one user-level config file, and the
+// project-local `.kimi-code` directory holds only a workspace override and an MCP server list,
+// neither of which can register a hook. A `wd` parameter is therefore not taken at all rather
+// than taken and ignored -- the same shape as dsh above.
+func kimiCandidates(home string) []candidate {
+ return []candidate{
+ {runtime: "kimi_code", path: filepath.Join(kimiUserDir(home), "config.toml"), scope: ScopeUser, format: formatTOML, kind: KindNativeConfig},
+ }
+}
+
+// kimiUserDir resolves the Kimi Code data root, mirroring the installer.
+//
+// Exported to the test as a function rather than restated there as a literal path, so the
+// expected-candidate list stays correct on a developer machine that happens to set
+// KIMI_CODE_HOME.
+func kimiUserDir(home string) string {
+ if base := strings.TrimSpace(os.Getenv("KIMI_CODE_HOME")); base != "" {
+ return base
+ }
+ return filepath.Join(home, ".kimi-code")
+}
+
// dshUserDir resolves the Harness home, mirroring the installer.
//
// Exported to the test as a function rather than restated there as a literal path, so the
@@ -1046,6 +1077,14 @@ func beaconManaged(item candidate, data []byte) bool {
case "deepseek_harness":
return strings.Contains(text, "--platform dsh") || strings.Contains(text, "--platform=dsh") ||
strings.Contains(text, "@deepseek-ai/dsh-hooks-claude-code")
+ // Matched on the hook command rather than on the comment Beacon writes above its block, and
+ // here that is not a preference between two working options: Kimi Code's legacy migration
+ // from `kimi-cli` rewrites this file by serializing the merged config, which keeps the
+ // `[[hooks]]` entries and drops every comment in the document. A marker-based tell would
+ // report "not managed" on any machine that had been through that upgrade, for an install that
+ // is still running.
+ case "kimi_code":
+ return strings.Contains(text, "--platform kimi") || strings.Contains(text, "--platform=kimi")
}
if item.runtime == "claude_code" || item.runtime == "codex_cli" {
if strings.Contains(text, "OTEL_EXPORTER_OTLP_ENDPOINT") && localEndpointText(text) {
diff --git a/cli/beacon/internal/endpoint/inventory/inventory_test.go b/cli/beacon/internal/endpoint/inventory/inventory_test.go
index 23f76f88..3224e55f 100644
--- a/cli/beacon/internal/endpoint/inventory/inventory_test.go
+++ b/cli/beacon/internal/endpoint/inventory/inventory_test.go
@@ -450,6 +450,13 @@ func TestScanIncludesAllSupportedCurrentUserAndProjectConfigs(t *testing.T) {
// than on a Beacon marker.
{runtime: "deepseek_harness", path: filepath.Join(dshUserDir(home), "beacon-endpoint-hooks.json"), scope: ScopeUser, format: formatJSON, kind: KindHookConfig},
{runtime: "deepseek_harness", path: filepath.Join(dshUserDir(home), "cordis.patch.yml"), scope: ScopeUser, format: formatYAML, kind: KindHookConfig},
+ // Kimi Code is one file and no project entry, and the file is not Beacon's: config.toml
+ // is where the runtime keeps its provider credentials, its model catalog and its
+ // permission rules, and Beacon's hooks are a minority of it. That is why it is listed as
+ // KindNativeConfig rather than KindHookConfig, and why the tell is the hook command
+ // rather than the file existing. The project scope is absent because Kimi Code reads one
+ // user-level config file and has no project-level config mechanism at all.
+ {runtime: "kimi_code", path: filepath.Join(kimiUserDir(home), "config.toml"), scope: ScopeUser, format: formatTOML, kind: KindNativeConfig},
// fx has no Beacon-written file, so all three are its own configuration. The two MCP files
// are the ones that carry information nothing else here reports: fx's profile server list
// and the workspace servers it shares with Claude-compatible runtimes.
diff --git a/cli/beacon/internal/endpoint/inventory/kimi_test.go b/cli/beacon/internal/endpoint/inventory/kimi_test.go
new file mode 100644
index 00000000..ace318c8
--- /dev/null
+++ b/cli/beacon/internal/endpoint/inventory/kimi_test.go
@@ -0,0 +1,137 @@
+package inventory
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+)
+
+// Kimi Code's inventory row points at a file Beacon does not own: config.toml holds the runtime's
+// provider credentials, its model catalog and its permission rules, and Beacon's hooks are a
+// minority of it. So "this file exists" says nothing about whether Beacon is collecting, and the
+// scan has to key on the hook command -- otherwise every machine with Kimi Code installed would
+// report a managed config it never touched.
+func TestScanReportsKimiConfigOnlyAsManagedWhenBeaconWroteIt(t *testing.T) {
+ home := t.TempDir()
+ work := t.TempDir()
+ t.Setenv("KIMI_CODE_HOME", "")
+
+ dir := filepath.Join(home, ".kimi-code")
+ if err := os.MkdirAll(dir, 0o700); err != nil {
+ t.Fatalf("mkdir: %v", err)
+ }
+ configPath := filepath.Join(dir, "config.toml")
+
+ // The user's own config, with their own hook in it and no Beacon entry.
+ if err := os.WriteFile(configPath, []byte(`default_model = "k2"
+
+[providers.kimi]
+api_key = "sk-secret"
+
+[[hooks]]
+event = "PreToolUse"
+command = "node ~/.kimi-code/hooks/block-dangerous-bash.mjs"
+`), 0o600); err != nil {
+ t.Fatalf("write config: %v", err)
+ }
+
+ config := findConfig(Scan(Options{HomeDir: home, WorkingDir: work}).Configs, "kimi_code", configPath)
+ if config == nil {
+ t.Fatalf("scan did not report %s", configPath)
+ }
+ if !config.Exists {
+ t.Fatal("the config exists but the scan reported otherwise")
+ }
+ if config.BeaconManaged {
+ t.Fatal("a config carrying only the user's own hook was reported as Beacon-managed")
+ }
+ if config.ParserMode != formatTOML {
+ t.Fatalf("parser mode = %q, want toml", config.ParserMode)
+ }
+
+ if err := os.WriteFile(configPath, []byte(`default_model = "k2"
+
+[[hooks]]
+event = "PreToolUse"
+command = "'/opt/beacon/bin/beacon-hooks' --platform kimi --log '/l' pre-tool"
+timeout = 10
+`), 0o600); err != nil {
+ t.Fatalf("rewrite config: %v", err)
+ }
+ config = findConfig(Scan(Options{HomeDir: home, WorkingDir: work}).Configs, "kimi_code", configPath)
+ if config == nil || !config.BeaconManaged {
+ t.Fatalf("a config carrying Beacon's hook command was not reported as managed: %+v", config)
+ }
+}
+
+// The tell is the hook command rather than the comment Beacon writes above its block, and this is
+// the case that makes the difference reachable: Kimi Code's legacy migration from `kimi-cli`
+// rewrites config.toml by serializing the merged config, which keeps the `[[hooks]]` entries and
+// drops every comment in the document. A marker-based tell would report "not managed" for an
+// install that is still running.
+func TestScanRecognizesKimiHooksAfterTheRuntimeDropsComments(t *testing.T) {
+ home := t.TempDir()
+ work := t.TempDir()
+ t.Setenv("KIMI_CODE_HOME", "")
+
+ dir := filepath.Join(home, ".kimi-code")
+ if err := os.MkdirAll(dir, 0o700); err != nil {
+ t.Fatalf("mkdir: %v", err)
+ }
+ configPath := filepath.Join(dir, "config.toml")
+ // No comments anywhere, the way a re-serialized config looks.
+ if err := os.WriteFile(configPath, []byte(`default_model = 'k2'
+
+[[hooks]]
+command = "'/opt/beacon/bin/beacon-hooks' --platform kimi --log '/l' stop"
+event = 'Stop'
+timeout = 45
+`), 0o600); err != nil {
+ t.Fatalf("write config: %v", err)
+ }
+
+ config := findConfig(Scan(Options{HomeDir: home, WorkingDir: work}).Configs, "kimi_code", configPath)
+ if config == nil || !config.BeaconManaged {
+ t.Fatalf("a re-serialized config still carrying Beacon's hooks was not reported as managed: %+v", config)
+ }
+}
+
+// KIMI_CODE_HOME moves the whole Kimi Code data root. A scan that looked only under ~/.kimi-code
+// would report "not found" for a machine whose config is live somewhere else.
+func TestScanHonorsKimiCodeHome(t *testing.T) {
+ home := t.TempDir()
+ work := t.TempDir()
+ elsewhere := filepath.Join(t.TempDir(), "kimi-root")
+ t.Setenv("KIMI_CODE_HOME", elsewhere)
+ if err := os.MkdirAll(elsewhere, 0o700); err != nil {
+ t.Fatalf("mkdir: %v", err)
+ }
+ configPath := filepath.Join(elsewhere, "config.toml")
+ if err := os.WriteFile(configPath, []byte("default_model = \"k2\"\n"), 0o600); err != nil {
+ t.Fatalf("write config: %v", err)
+ }
+
+ result := Scan(Options{HomeDir: home, WorkingDir: work})
+ if findConfig(result.Configs, "kimi_code", configPath) == nil {
+ t.Fatalf("scan did not follow KIMI_CODE_HOME to %s", configPath)
+ }
+ if findConfig(result.Configs, "kimi_code", filepath.Join(home, ".kimi-code", "config.toml")) != nil {
+ t.Fatal("scan also reported the default path while KIMI_CODE_HOME was set")
+ }
+}
+
+// There is no project-scoped Kimi Code config to find: the runtime reads one user-level file, and
+// the project-local .kimi-code directory holds a workspace override and an MCP server list,
+// neither of which can register a hook. Reporting a project candidate would invite an operator to
+// look for an install that cannot exist.
+func TestScanReportsNoProjectScopedKimiConfig(t *testing.T) {
+ home := t.TempDir()
+ work := t.TempDir()
+ t.Setenv("KIMI_CODE_HOME", "")
+
+ for _, config := range Scan(Options{HomeDir: home, WorkingDir: work}).Configs {
+ if config.Runtime == "kimi_code" && config.Scope == ScopeProject {
+ t.Fatalf("scan reported a project-scoped Kimi Code config: %s", config.Path)
+ }
+ }
+}
diff --git a/cli/beacon/internal/tokens/coverage.go b/cli/beacon/internal/tokens/coverage.go
index 334b5e1b..ae81d8e8 100644
--- a/cli/beacon/internal/tokens/coverage.go
+++ b/cli/beacon/internal/tokens/coverage.go
@@ -118,6 +118,13 @@ var usageExpectation = map[string]struct {
// own session log -- but nothing in the hook surface exposes it, so a DeepSeek Harness session
// reporting no tokens is correct rather than silent.
"deepseek_harness": {ExpectNone, "the hook bridge's payloads carry no token counts"},
+ // Kimi Code assembles each hook payload from a fixed envelope plus per-event fields, and no
+ // usage count is among them on any of the twenty events it exposes. The runtime does count
+ // tokens -- the TUI shows context occupancy, and PreCompact carries a `token_count` for the
+ // history it is about to summarize -- but neither is per-call spend, so promoting either into
+ // gen_ai.usage would make a level look like an additive total. A Kimi Code session reporting
+ // no tokens is therefore correct rather than silent.
+ "kimi_code": {ExpectNone, "hook payloads carry no token counts; PreCompact reports context only"},
}
// InstalledConfig is the part of a config-scanner row that install detection reads.
diff --git a/cli/beacon/internal/tokens/coverage_test.go b/cli/beacon/internal/tokens/coverage_test.go
index 078cb914..58eb9a3d 100644
--- a/cli/beacon/internal/tokens/coverage_test.go
+++ b/cli/beacon/internal/tokens/coverage_test.go
@@ -212,7 +212,8 @@ func TestEveryScannedRuntimeHasAnExpectation(t *testing.T) {
scanned := []string{
"antigravity_cli", "claude_code", "cline", "codex_cli", "copilot_cli", "cursor",
"devin-cli", "devin-desktop", "factory", "gemini_cli", "grok", "hermes",
- "kiro", "muse_code", "omp", "opencode", "openhands", "pi_cli", "qwen_code", "vscode",
+ "kimi_code", "kiro", "muse_code", "omp", "opencode", "openhands", "pi_cli", "qwen_code",
+ "vscode",
}
for _, runtime := range scanned {
harness := normalizedHarnessForTest(runtime)
@@ -258,6 +259,15 @@ func TestNewHarnessesAreClassifiedNotAlerted(t *testing.T) {
t.Errorf("kiro = %+v, want not_instrumented/none -- no Kiro hook payload carries token counts", kiro)
}
+ // Kimi Code is the case where the runtime does count tokens and still expects none here. It
+ // reports context occupancy in its TUI and a `token_count` on PreCompact, but neither is
+ // per-call spend and no hook payload carries any -- so the row has to say expected-none, and
+ // promoting either number into gen_ai.usage would make a level look like an additive total.
+ kimi := lineFor(t, Coverage([]schema.Event{plainEvent("kimi_code")}, []string{"kimi_code"}), "kimi_code")
+ if kimi.Status != CoverageNotInstrumented || kimi.Expectation != ExpectNone {
+ t.Errorf("kimi_code = %+v, want not_instrumented/none -- no Kimi Code hook payload carries token counts", kimi)
+ }
+
grokBot := lineFor(t, Coverage([]schema.Event{plainEvent("grok_bot")}, nil), "grok_bot")
if grokBot.Expectation != ExpectGenericOTLP {
t.Errorf("grok_bot expectation = %q, want generic_otlp -- it arrives only via Cursor's OTel export", grokBot.Expectation)