Skip to content

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

feat(hooks): register cline as a hook platform

Claude2b203d4ee76d
diff --git a/cli/beacon-hooks/cmd/helpers.go b/cli/beacon-hooks/cmd/helpers.go
index fb0477d2..d9c502e8 100644
--- a/cli/beacon-hooks/cmd/helpers.go
+++ b/cli/beacon-hooks/cmd/helpers.go
@@ -118,6 +118,12 @@ func resolveSessionID(input map[string]interface{}, platform string) string {
return hermesFirstString(input, "session_id", "sessionId", "session_key", "task_id")
case "opencode":
return getFirstStr(input, "session_id", "sessionID")
+ // Cline calls this a task, not a session: `taskId` is one of the base fields present on every
+ // hook payload it sends. The session_id spellings are kept as a fallback because the same
+ // binary receives payloads from Cline's plugin host and its CLI, and only the base fields are
+ // documented as common to both.
+ case "cline":
+ return getFirstStr(input, "taskId", "task_id", "sessionId", "session_id")
default:
id, _ := input["session_id"].(string)
return id
@@ -165,6 +171,13 @@ func resolveSessionIDWithTranscript(input map[string]interface{}, platform strin
case "opencode":
sessionID = getFirstStr(input, "session_id", "sessionID")
return
+ // No transcript path: Cline keeps conversation state under its own data directory and does not
+ // hand hooks a path to it, so there is nothing to return here. Left explicit rather than
+ // falling through to the default, which would look for `transcript_path` keys that never
+ // arrive and read as an oversight.
+ case "cline":
+ sessionID = getFirstStr(input, "taskId", "task_id", "sessionId", "session_id")
+ return
default:
sessionID, _ = input["session_id"].(string)
transcriptPath, _ = input["transcript_path"].(string)
@@ -234,6 +247,12 @@ func resolveCwd(input map[string]interface{}, platform string) string {
return cwd
}
}
+ if platform == "cline" {
+ if cwd := getFirstStr(input, "cwd", "workingDirectory", "working_directory"); cwd != "" {
+ return cwd
+ }
+ return firstWorkspaceRoot(input, "workspaceRoots", "workspace_roots")
+ }
if isDevinLikePlatform(platform) {
if cwd := getFirstStr(input, "cwd", "project_dir", "projectDir"); cwd != "" {
return cwd
@@ -272,6 +291,37 @@ func resolveCwd(input map[string]interface{}, platform string) string {
return cwd
}
+// firstWorkspaceRoot reads the first workspace root out of a payload that carries a list of them.
+//
+// Cline's documented base fields name `workspaceRoots` but not the type of its elements, and Cline
+// supports multi-root workspaces, so both shapes are read: a plain path string, and an object whose
+// path lives under a "path" or "root" key.
+//
+// A "uri" key is deliberately not read. A file:// URI is not a filesystem path, and returning one
+// would be worse than returning nothing: this value is what the git helpers resolve a repository
+// and branch from, and it is written into events, so a URI would produce a path that looks real,
+// fails every lookup, and reaches customer logs. An empty result degrades to "no repository
+// context" instead, which is the honest answer until a fixture shows what Cline actually sends.
+func firstWorkspaceRoot(input map[string]interface{}, keys ...string) string {
+ for _, key := range keys {
+ roots, ok := input[key].([]interface{})
+ if !ok || len(roots) == 0 {
+ continue
+ }
+ switch root := roots[0].(type) {
+ case string:
+ if root != "" {
+ return root
+ }
+ case map[string]interface{}:
+ if path := firstToolString(root, "path", "root"); path != "" {
+ return path
+ }
+ }
+ }
+ return ""
+}
+
func hermesExtra(input map[string]interface{}) map[string]interface{} {
if extra, ok := input["extra"].(map[string]interface{}); ok {
return extra
diff --git a/cli/beacon-hooks/cmd/helpers_test.go b/cli/beacon-hooks/cmd/helpers_test.go
index f054268d..76ec3bd4 100644
--- a/cli/beacon-hooks/cmd/helpers_test.go
+++ b/cli/beacon-hooks/cmd/helpers_test.go
@@ -110,6 +110,66 @@ func TestResolveSessionID_Cursor(t *testing.T) {
}
}
+// Cline names its unit of work a task, so the session identifier arrives as `taskId`. Getting this
+// wrong does not fail loudly: every event still writes, with an empty session, and the runtime log
+// silently loses the ability to group one Cline task's activity together.
+func TestResolveSessionID_Cline(t *testing.T) {
+ tests := []struct {
+ name string
+ input map[string]interface{}
+ want string
+ }{
+ {
+ name: "uses taskId",
+ input: map[string]interface{}{"taskId": "task_abc123"},
+ want: "task_abc123",
+ },
+ {
+ name: "accepts snake_case task_id",
+ input: map[string]interface{}{"task_id": "task_abc123"},
+ want: "task_abc123",
+ },
+ {
+ name: "taskId wins over session spellings",
+ input: map[string]interface{}{"taskId": "task_abc123", "sessionId": "ignored"},
+ want: "task_abc123",
+ },
+ {
+ name: "falls back to sessionId",
+ input: map[string]interface{}{"sessionId": "sess_abc123"},
+ want: "sess_abc123",
+ },
+ {
+ name: "empty when the payload carries neither",
+ input: map[string]interface{}{},
+ want: "",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := resolveSessionID(tt.input, "cline"); got != tt.want {
+ t.Errorf("resolveSessionID(%v, \"cline\") = %q, want %q", tt.input, got, tt.want)
+ }
+ })
+ }
+}
+
+// Cline hooks get no transcript path. Asserted rather than assumed: the default branch would look
+// for `transcript_path`, and a future reader could "fix" the missing value by adding a key that
+// Cline never sends.
+func TestResolveSessionIDWithTranscript_Cline(t *testing.T) {
+ sessionID, transcriptPath := resolveSessionIDWithTranscript(
+ map[string]interface{}{"taskId": "task_abc123", "transcript_path": "/not/sent/by/cline"},
+ "cline",
+ )
+ if sessionID != "task_abc123" {
+ t.Errorf("sessionID = %q, want %q", sessionID, "task_abc123")
+ }
+ if transcriptPath != "" {
+ t.Errorf("transcriptPath = %q, want empty -- Cline does not expose a transcript to hooks", transcriptPath)
+ }
+}
+
func TestResolveSessionIDWithTranscript_Cursor(t *testing.T) {
tests := []struct {
name string
@@ -213,6 +273,74 @@ func TestResolveCwd(t *testing.T) {
platform: "cursor",
want: "/projects/myapp",
},
+ {
+ name: "cline uses cwd field",
+ input: map[string]interface{}{"cwd": "/projects/myapp"},
+ platform: "cline",
+ want: "/projects/myapp",
+ },
+ {
+ name: "cline falls back to workspaceRoots",
+ input: map[string]interface{}{
+ "workspaceRoots": []interface{}{"/workspace/root"},
+ },
+ platform: "cline",
+ want: "/workspace/root",
+ },
+ {
+ name: "cline accepts snake_case workspace_roots",
+ input: map[string]interface{}{
+ "workspace_roots": []interface{}{"/workspace/root"},
+ },
+ platform: "cline",
+ want: "/workspace/root",
+ },
+ {
+ name: "cline reads a workspace root object",
+ input: map[string]interface{}{
+ "workspaceRoots": []interface{}{
+ map[string]interface{}{"path": "/workspace/root", "vcs": "git"},
+ },
+ },
+ platform: "cline",
+ want: "/workspace/root",
+ },
+ {
+ name: "cline takes the first of several roots",
+ input: map[string]interface{}{
+ "workspaceRoots": []interface{}{"/workspace/first", "/workspace/second"},
+ },
+ platform: "cline",
+ want: "/workspace/first",
+ },
+ {
+ name: "cline cwd takes precedence over workspaceRoots",
+ input: map[string]interface{}{
+ "cwd": "/projects/myapp",
+ "workspaceRoots": []interface{}{"/workspace/root"},
+ },
+ platform: "cline",
+ want: "/projects/myapp",
+ },
+ {
+ // A file:// URI is not a filesystem path. Empty is the correct answer: it degrades to
+ // "no repository context" instead of writing a path that looks real and resolves to
+ // nothing.
+ name: "cline ignores a uri-only workspace root",
+ input: map[string]interface{}{
+ "workspaceRoots": []interface{}{
+ map[string]interface{}{"uri": "file:///workspace/root"},
+ },
+ },
+ platform: "cline",
+ want: "",
+ },
+ {
+ name: "cline returns empty when no sources",
+ input: map[string]interface{}{},
+ platform: "cline",
+ want: "",
+ },
{
name: "claude uses cwd field",
input: map[string]interface{}{"cwd": "/projects/myapp"},
diff --git a/cli/beacon-hooks/cmd/root.go b/cli/beacon-hooks/cmd/root.go
index 31cdea0a..4ee025f6 100644
--- a/cli/beacon-hooks/cmd/root.go
+++ b/cli/beacon-hooks/cmd/root.go
@@ -29,8 +29,8 @@ var (
var rootCmd = &cobra.Command{
Use: "beacon-hooks",
- Short: "Beacon hooks for Claude Code, Codex, GitHub Copilot, Cursor, VS Code, Devin, Factory, Grok, Hermes, Antigravity, and opencode",
- Long: `Beacon hooks binary for Claude Code, Codex, GitHub Copilot, Cursor, VS Code, Devin, Factory, Grok, Hermes, Antigravity, and opencode integration.
+ Short: "Beacon hooks for Claude Code, Codex, GitHub Copilot, Cursor, VS Code, Devin, Factory, Grok, Hermes, Antigravity, opencode, and Cline",
+ Long: `Beacon hooks binary for Claude Code, Codex, GitHub Copilot, Cursor, VS Code, Devin, Factory, Grok, Hermes, Antigravity, opencode, and Cline integration.
This binary provides hook commands that are called by IDE plugin systems
to evaluate code changes for security violations.
@@ -39,7 +39,7 @@ Use --platform to specify the calling platform (default: claude).`,
}
func init() {
- rootCmd.PersistentFlags().StringVar(&platformFlag, "platform", "claude", "Platform context: claude, codex, antigravity, copilot, cursor, vscode, devin, devin-cli, devin-desktop, factory, grok, hermes, or opencode")
+ rootCmd.PersistentFlags().StringVar(&platformFlag, "platform", "claude", "Platform context: claude, cline, codex, antigravity, copilot, cursor, vscode, devin, devin-cli, devin-desktop, factory, grok, hermes, or opencode")
rootCmd.PersistentFlags().StringVar(&logFlag, "log", "", "Endpoint runtime log to append to (same value as BEACON_ENDPOINT_LOG)")
rootCmd.PersistentFlags().StringVar(&configFlag, "config", "", "Endpoint config to read (same value as BEACON_ENDPOINT_CONFIG)")
rootCmd.PersistentFlags().StringVar(&cliFlag, "cli", "", "Path to the beacon CLI for inventory heartbeats (same value as BEACON_ENDPOINT_CLI)")
diff --git a/cli/beacon-hooks/internal/config/config.go b/cli/beacon-hooks/internal/config/config.go
index ed8ee43e..dc9aea23 100644
--- a/cli/beacon-hooks/internal/config/config.go
+++ b/cli/beacon-hooks/internal/config/config.go
@@ -21,6 +21,7 @@ var (
GrokDir = filepath.Join(BeaconDir, "grok")
HermesDir = filepath.Join(BeaconDir, "hermes")
OpenCodeDir = filepath.Join(BeaconDir, "opencode")
+ ClineDir = filepath.Join(BeaconDir, "cline")
)
// Log rotation
@@ -99,6 +100,8 @@ func GetStateDir(platform string) string {
return HermesDir
case "opencode":
return OpenCodeDir
+ case "cline":
+ return ClineDir
default:
return ClaudeDir
}
diff --git a/cli/beacon-hooks/internal/config/config_test.go b/cli/beacon-hooks/internal/config/config_test.go
index 15c94960..5f14c4a6 100644
--- a/cli/beacon-hooks/internal/config/config_test.go
+++ b/cli/beacon-hooks/internal/config/config_test.go
@@ -15,6 +15,10 @@ func TestGetStateDir(t *testing.T) {
{"copilot", CopilotDir},
{"cursor", CursorDir},
{"vscode", VSCodeDir},
+ // An unregistered platform falls back to ClaudeDir, so this row is what proves cline is
+ // registered at all: without the case, cline's hook log and per-session state would be
+ // written into Claude Code's state directory and the two runtimes would share files.
+ {"cline", ClineDir},
{"unknown", ClaudeDir}, // defaults to claude
}