Skip to content

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

Fix false tool failures from response message and workspace resolution in Cline mapper

Cursor Agent9b710afe095b
diff --git a/cli/beacon-hooks/cmd/cline_event.go b/cli/beacon-hooks/cmd/cline_event.go
index f37274a7..4d06b21d 100644
--- a/cli/beacon-hooks/cmd/cline_event.go
+++ b/cli/beacon-hooks/cmd/cline_event.go
@@ -166,8 +166,22 @@ func supportedClineEventTypes() []string {
}
func clineBaseFields(input map[string]interface{}, sessionID string) map[string]interface{} {
- fields := sessionFields(sessionID, input)
- applyWorkspaceFields(fields, input, "")
+ 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["raw"] = map[string]interface{}{"cline": input}
if model := clineModel(input); model != "" {
fields["model"] = model
@@ -299,11 +313,13 @@ func clineToolError(input map[string]interface{}) string {
if text := getFirstStr(input, "error", "errorMessage", "error_message"); text != "" {
return text
}
- for _, source := range []map[string]interface{}{firstMap(input, "error"), clineToolResponse(input)} {
- if source == nil {
- continue
+ if errMap := firstMap(input, "error"); errMap != nil {
+ if text := getFirstStr(errMap, "message", "error", "errorMessage", "error_message"); text != "" {
+ return text
}
- if text := getFirstStr(source, "message", "error", "errorMessage", "error_message"); text != "" {
+ }
+ if response := clineToolResponse(input); response != nil {
+ if text := getFirstStr(response, "error", "errorMessage", "error_message"); text != "" {
return text
}
}
diff --git a/cli/beacon-hooks/cmd/cline_event_test.go b/cli/beacon-hooks/cmd/cline_event_test.go
index 72bd8f02..246eba61 100644
--- a/cli/beacon-hooks/cmd/cline_event_test.go
+++ b/cli/beacon-hooks/cmd/cline_event_test.go
@@ -106,6 +106,26 @@ func TestClineEventTaskStartRecordsSessionAndPrompt(t *testing.T) {
}
}
+// Base fields resolve the workspace through the Cline-specific path (workspaceRoots) regardless of
+// what platformFlag is set to. Without this, the session.working_directory stays empty when the
+// binary is invoked without --platform cline.
+func TestClineEventBaseFieldsResolveWorkspaceWithoutPlatformFlag(t *testing.T) {
+ logPath := clineTestLog(t)
+ platformFlag = "claude" // simulate missing --platform cline
+
+ runHookWithInput(t, runClineEvent, map[string]interface{}{
+ "type": "beforeRun",
+ "taskId": "task-platform",
+ "workspaceRoots": []interface{}{"/tmp/project"},
+ "input": map[string]interface{}{"text": "hello"},
+ })
+
+ event := clineEventWithAction(t, logPath, "session.started")
+ if got := nested(t, event, "session")["working_directory"]; got != "/tmp/project" {
+ t.Errorf("session.working_directory = %q, want /tmp/project (resolved from workspaceRoots regardless of platformFlag)", got)
+ }
+}
+
// The file-based hook surface names the hook in `hookName` and sends prompts on their own, so a
// prompt payload with no run-start context still has to produce a prompt event.
func TestClineEventPromptOnlyPayload(t *testing.T) {
@@ -304,6 +324,33 @@ func TestClineEventToolFailureIsHighSeverity(t *testing.T) {
}
}
+// A successful tool result that carries a "message" field (common in Cline for status feedback)
+// must not be treated as a failure. Only explicit error keys indicate a failure.
+func TestClineEventSuccessfulToolWithMessageIsNotFailure(t *testing.T) {
+ logPath := clineTestLog(t)
+
+ runHookWithInput(t, runClineEvent, map[string]interface{}{
+ "type": "afterTool",
+ "taskId": "task-msg",
+ "toolCall": map[string]interface{}{
+ "name": "write_to_file",
+ "input": map[string]interface{}{"path": "out.ts", "content": "done"},
+ },
+ "result": map[string]interface{}{"output": "File written", "message": "File written successfully"},
+ "workspaceRoots": []interface{}{"/tmp/project"},
+ })
+
+ actions := clineEventActions(t, logPath)
+ for _, a := range actions {
+ if a == "tool.failed" {
+ t.Fatalf("actions = %v, want no tool.failed for a successful result with a message field", actions)
+ }
+ }
+ if len(actions) == 0 {
+ t.Fatalf("expected at least one event")
+ }
+}
+
// A file action with no file is not a file action: Cline's search tools take a pattern rather than
// a path, and a file.read with no file field matches every file-scoped query and explains none.
func TestClineEventFileActionWithoutAPathBecomesToolCompleted(t *testing.T) {