Skip to content

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

refactor(hooks): name the runtime instead of copying the workspace helpers

Claudeb6b1110cdc57
diff --git a/cli/beacon-hooks/cmd/cline_event.go b/cli/beacon-hooks/cmd/cline_event.go
index 4d06b21d..e4ddd469 100644
--- a/cli/beacon-hooks/cmd/cline_event.go
+++ b/cli/beacon-hooks/cmd/cline_event.go
@@ -165,23 +165,16 @@ func supportedClineEventTypes() []string {
}
}
+// clineBaseFields builds the fields every Cline event carries.
+//
+// The workspace is resolved for "cline" by name rather than through platformFlag. The shared
+// helpers default to the flag, which made this depend on how the binary was invoked: without
+// --platform cline the default reader found none of Cline's keys and the event carried no working
+// directory, repository or branch, while the file path beside it resolved correctly because that
+// path already named the runtime.
func clineBaseFields(input map[string]interface{}, sessionID string) map[string]interface{} {
- fields := map[string]interface{}{}
- session := map[string]interface{}{}
- if sessionID != "" {
- session["id"] = sessionID
- }
- cwd := resolveCwd(input, "cline")
- if cwd != "" {
- session["working_directory"] = cwd
- fields["repository"] = cwd
- }
- if len(session) > 0 {
- fields["session"] = session
- }
- if branch := resolveBranch(input, cwd); branch != "" {
- fields["branch"] = branch
- }
+ fields := sessionFieldsForPlatform(sessionID, input, "cline")
+ applyWorkspaceFieldsForPlatform(fields, input, "", "cline")
fields["raw"] = map[string]interface{}{"cline": input}
if model := clineModel(input); model != "" {
fields["model"] = model
diff --git a/cli/beacon-hooks/cmd/cline_event_test.go b/cli/beacon-hooks/cmd/cline_event_test.go
index 246eba61..d5468d27 100644
--- a/cli/beacon-hooks/cmd/cline_event_test.go
+++ b/cli/beacon-hooks/cmd/cline_event_test.go
@@ -336,7 +336,7 @@ func TestClineEventSuccessfulToolWithMessageIsNotFailure(t *testing.T) {
"name": "write_to_file",
"input": map[string]interface{}{"path": "out.ts", "content": "done"},
},
- "result": map[string]interface{}{"output": "File written", "message": "File written successfully"},
+ "result": map[string]interface{}{"output": "File written", "message": "File written successfully"},
"workspaceRoots": []interface{}{"/tmp/project"},
})
diff --git a/cli/beacon-hooks/cmd/endpoint_events.go b/cli/beacon-hooks/cmd/endpoint_events.go
index c719b2c5..e940bfce 100644
--- a/cli/beacon-hooks/cmd/endpoint_events.go
+++ b/cli/beacon-hooks/cmd/endpoint_events.go
@@ -88,7 +88,13 @@ func resolveBranch(input map[string]interface{}, cwd string) string {
// such as a file edit identified only by its path; it is never used for
// repository, which must reflect the actual workspace path.
func applyWorkspaceFields(fields map[string]interface{}, input map[string]interface{}, fallbackDir string) {
- cwd := resolveCwd(input, platformFlag)
+ applyWorkspaceFieldsForPlatform(fields, input, fallbackDir, platformFlag)
+}
+
+// applyWorkspaceFieldsForPlatform is applyWorkspaceFields for a named runtime. See
+// sessionFieldsForPlatform for why a single-runtime mapper should name its runtime.
+func applyWorkspaceFieldsForPlatform(fields map[string]interface{}, input map[string]interface{}, fallbackDir, platform string) {
+ cwd := resolveCwd(input, platform)
if cwd != "" {
fields["session"] = mergeNested(fields["session"], map[string]interface{}{"working_directory": cwd})
if existing, ok := fields["repository"]; !ok || existing == "" {
@@ -195,12 +201,24 @@ func firstHookEnv(keys ...string) string {
}
func sessionFields(sessionID string, input map[string]interface{}) map[string]interface{} {
+ return sessionFieldsForPlatform(sessionID, input, platformFlag)
+}
+
+// sessionFieldsForPlatform builds the same fields for a named runtime rather than for whichever
+// --platform the binary happened to be invoked with.
+//
+// A mapper that only ever handles one runtime's payloads should say which one. Reading the flag
+// instead made the workspace resolution depend on the invocation: a Cline payload processed without
+// --platform cline fell through to the default reader, found none of Cline's keys, and produced an
+// event with no working directory, no repository and no branch -- while the file path in the same
+// event resolved correctly, because that path already asked for the Cline shape by name.
+func sessionFieldsForPlatform(sessionID string, input map[string]interface{}, platform string) map[string]interface{} {
fields := map[string]interface{}{}
session := map[string]interface{}{}
if sessionID != "" {
session["id"] = sessionID
}
- if cwd := resolveCwd(input, platformFlag); cwd != "" {
+ if cwd := resolveCwd(input, platform); cwd != "" {
session["working_directory"] = cwd
fields["repository"] = cwd
}