The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
fix(devin-desktop): record Cascade's reply from post_cascade_response
Clauded0842b77bdcf
diff --git a/cli/beacon-hooks/cmd/cascade_response.go b/cli/beacon-hooks/cmd/cascade_response.gonew file mode 100644index 00000000..9dd78cf7--- /dev/null+++ b/cli/beacon-hooks/cmd/cascade_response.go@@ -0,0 +1,64 @@+package cmd++import (+ "github.com/spf13/cobra"+)++var cascadeResponseCmd = &cobra.Command{+ Use: "cascade-response",+ Short: "Record a Cascade response for local endpoint telemetry",+ Hidden: true,+ Run: runCascadeResponse,+}++func init() {+ rootCmd.AddCommand(cascadeResponseCmd)+}++// runCascadeResponse is Devin Desktop's post_cascade_response hook. Cascade runs it after it+// finishes answering a prompt, with `tool_info.response`: the Markdown of everything Cascade said+// since the user's last input. It is the only place a Cascade reply reaches a hook; without it a+// Devin Desktop session recorded prompts and tool calls but never what the agent answered.+//+// The text is Cascade's own rendering of the turn, so it can include planner notes and one-line+// summaries of the actions Cascade took ("*Created file ...*") around the answer. It is recorded as+// Cascade reports it rather than parsed apart, because the format is not documented beyond being+// Markdown, and a parser guessing at it could drop the answer.+func runCascadeResponse(cmd *cobra.Command, args []string) {+ input, err := readStdinJSON()+ if err != nil || !isCascadePlatform(platformFlag) {+ outputJSON(hookNoopResponse())+ return+ }+ info := cascadeToolInfo(input)+ response := getFirstStr(info, "response")+ sessionID := resolveSessionID(input, platformFlag)+ logger := newHookLogger("cascade-response", platformFlag, sessionID)+ // raw.cascade keeps the whole Cascade payload on every event of this runtime. The response is+ // already the event's gen_ai output, so the raw copy leaves it out instead of storing it twice.+ payload := cascadePayloadWithoutResponse(input)+ emitAssistantMessage(logger, payload, cascadeMetadataFields(sessionID, payload), response)+ outputJSON(hookNoopResponse())+}++// cascadePayloadWithoutResponse is input with tool_info.response removed, leaving input unchanged.+func cascadePayloadWithoutResponse(input map[string]interface{}) map[string]interface{} {+ out := make(map[string]interface{}, len(input))+ for key, value := range input {+ out[key] = value+ }+ for _, key := range []string{"tool_info", "toolInfo"} {+ info, ok := input[key].(map[string]interface{})+ if !ok {+ continue+ }+ trimmed := make(map[string]interface{}, len(info))+ for k, v := range info {+ if k != "response" {+ trimmed[k] = v+ }+ }+ out[key] = trimmed+ }+ return out+}diff --git a/cli/beacon-hooks/cmd/cascade_response_test.go b/cli/beacon-hooks/cmd/cascade_response_test.gonew file mode 100644index 00000000..19c1df84--- /dev/null+++ b/cli/beacon-hooks/cmd/cascade_response_test.go@@ -0,0 +1,107 @@+package cmd++import (+ "strings"+ "testing"++ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve"+)++// cascadeResponsePayload is Devin Desktop's documented post_cascade_response input: the common+// Cascade fields plus tool_info.response, the Markdown of Cascade's reply since the last user input.+func cascadeResponsePayload(response interface{}) map[string]interface{} {+ info := map[string]interface{}{}+ if response != nil {+ info["response"] = response+ }+ return map[string]interface{}{+ "agent_action_name": "post_cascade_response",+ "trajectory_id": "cascade-session",+ "execution_id": "cascade-turn",+ "timestamp": "2026-10-15T10:00:00Z",+ "model_name": "SWE-2",+ "tool_info": info,+ }+}++func TestCascadeResponseRecordsTheReply(t *testing.T) {+ reply := "### Planner Response\n\nI'll help you create that file.\n\n*Created file `/repo/a.py`*\n\n### Planner Response\n\nThe file has been created: \"a.py\""+ logPath, stdout := runHookProcess(t, cascadeResponsePayload(reply), "--platform", "devin-desktop", "cascade-response")++ if strings.TrimSpace(string(stdout)) != "{}" {+ t.Fatalf("stdout = %q, want {}", stdout)+ }+ events := endpointEvents(t, logPath)+ if len(events) != 1 {+ t.Fatalf("wrote %d events, want only the reply: %#v", len(events), events)+ }+ message := events[0]+ if got := leaf(message, "event", "action"); got != "agent.message" {+ t.Fatalf("event.action = %q, want agent.message", got)+ }+ // Verbatim, including the trailing quote and Markdown: nothing is trimmed or reparsed.+ if got := outputText(t, message); got != reply {+ t.Fatalf("reply = %q, want %q", got, reply)+ }+ for _, check := range []struct {+ path []string+ want string+ }{+ {[]string{"harness", "name"}, "devin-desktop"},+ {[]string{"harness", "collection_method"}, "hook"},+ {[]string{"session", "id"}, "cascade-session"},+ {[]string{"session", "execution_id"}, "cascade-turn"},+ {[]string{"raw", "cascade", "agent_action_name"}, "post_cascade_response"},+ } {+ if got := leaf(message, check.path...); got != check.want {+ t.Errorf("%s = %q, want %q", strings.Join(check.path, "."), got, check.want)+ }+ }+ // The response is stored once, as the reply, not a second time in the raw payload.+ raw, _ := message["raw"].(map[string]interface{})+ cascade, _ := raw["cascade"].(map[string]interface{})+ info, _ := cascade["tool_info"].(map[string]interface{})+ if _, dup := info["response"]; dup {+ t.Fatalf("raw.cascade.tool_info kept a second copy of the response: %#v", info)+ }++ var texts []string+ for _, m := range chatView(t, logPath) {+ if m.Kind == asymptoteobserve.TraceMessageKindAssistant {+ texts = append(texts, m.Text)+ }+ }+ if len(texts) != 1 || texts[0] != reply {+ t.Fatalf("chat view assistant text = %q, want the reply", texts)+ }+}++func TestCascadeResponseWithoutAResponseWritesNothing(t *testing.T) {+ for name, value := range map[string]interface{}{"absent": nil, "empty": "", "blank": " "} {+ t.Run(name, func(t *testing.T) {+ logPath, _ := runHookProcess(t, cascadeResponsePayload(value), "--platform", "devin-desktop", "cascade-response")+ if events := endpointEventsIfAny(t, logPath); len(events) != 0 {+ t.Fatalf("wrote %d events with no response: %#v", len(events), events)+ }+ })+ }+}++// The command reads Cascade's payload only under Cascade's platform.+func TestCascadeResponseIgnoresOtherPlatforms(t *testing.T) {+ logPath, _ := runHookProcess(t, cascadeResponsePayload("not a cascade runtime"), "--platform", "devin-cli", "cascade-response")+ if events := endpointEventsIfAny(t, logPath); len(events) != 0 {+ t.Fatalf("recorded %d events under --platform devin-cli: %#v", len(events), events)+ }+}++func TestCascadePayloadWithoutResponseLeavesTheInputAlone(t *testing.T) {+ input := cascadeResponsePayload("text")+ trimmed := cascadePayloadWithoutResponse(input)+ if _, ok := trimmed["tool_info"].(map[string]interface{})["response"]; ok {+ t.Fatal("response not removed from the copy")+ }+ if input["tool_info"].(map[string]interface{})["response"] != "text" {+ t.Fatal("removing the response from the copy changed the input")+ }+}diff --git a/cli/beacon/internal/endpoint/hooks/devin.go b/cli/beacon/internal/endpoint/hooks/devin.goindex 5eb2f7af..14a33eb6 100644--- a/cli/beacon/internal/endpoint/hooks/devin.go+++ b/cli/beacon/internal/endpoint/hooks/devin.go@@ -139,6 +139,8 @@ func installDevinDesktopHooks(path, binaryPath, logPath, configPath string) erro"post_run_command": {Command: prefix + " post-tool", ShowOutput: &hideOutput},"post_mcp_tool_use": {Command: prefix + " post-tool", ShowOutput: &hideOutput},"post_read_code": {Command: prefix + " post-tool", ShowOutput: &hideOutput},+ // The only Cascade hook that carries the agent's reply.+ "post_cascade_response": {Command: prefix + " cascade-response", ShowOutput: &hideOutput},}for eventName, hook := range endpointHooks {config.hooks[eventName] = mergeWindsurfEndpointHook(config.hooks[eventName], hook, "devin-desktop")diff --git a/cli/beacon/internal/endpoint/hooks/devin_test.go b/cli/beacon/internal/endpoint/hooks/devin_test.goindex 8f716991..257a439d 100644--- a/cli/beacon/internal/endpoint/hooks/devin_test.go+++ b/cli/beacon/internal/endpoint/hooks/devin_test.go@@ -102,7 +102,7 @@ func TestInstallDevinDesktopHooksUsesCascadeEvents(t *testing.T) {t.Fatalf("read hooks: %v", err)}text := string(data)- for _, want := range []string{"pre_user_prompt", "post_write_code", "post_run_command", "post_mcp_tool_use", "post_read_code", "--platform devin-desktop", "prompt-submit", "post-tool"} {+ for _, want := range []string{"pre_user_prompt", "post_write_code", "post_run_command", "post_mcp_tool_use", "post_read_code", "post_cascade_response", "--platform devin-desktop", "prompt-submit", "post-tool", "cascade-response"} {if !strings.Contains(text, want) {t.Fatalf("Devin Desktop hooks missing %q:\n%s", want, text)}@@ -114,6 +114,52 @@ func TestInstallDevinDesktopHooksUsesCascadeEvents(t *testing.T) {}}+func TestInstallDevinDesktopCascadeResponseHookIsIdempotentAndRemovable(t *testing.T) {+ path := filepath.Join(t.TempDir(), "hooks.json")+ existing := `{"hooks":{"post_cascade_response":[{"command":"python3 mine.py","show_output":true}]}}`+ if err := os.WriteFile(path, []byte(existing), 0600); err != nil {+ t.Fatal(err)+ }+ for i := 0; i < 2; i++ {+ if err := installDevinDesktopHooks(path, "/tmp/beacon-hooks", "/tmp/runtime.jsonl", ""); err != nil {+ t.Fatal(err)+ }+ }+ var parsed struct {+ Hooks map[string][]windsurfHookRef `json:"hooks"`+ }+ data, err := os.ReadFile(path)+ if err != nil {+ t.Fatal(err)+ }+ if err := json.Unmarshal(data, &parsed); err != nil {+ t.Fatal(err)+ }+ var beacon []windsurfHookRef+ kept := false+ for _, ref := range parsed.Hooks["post_cascade_response"] {+ switch {+ case strings.HasSuffix(ref.Command, " cascade-response"):+ beacon = append(beacon, ref)+ case ref.Command == "python3 mine.py":+ kept = true+ }+ }+ if len(beacon) != 1 || beacon[0].ShowOutput == nil || *beacon[0].ShowOutput {+ t.Fatalf("post_cascade_response Beacon hooks = %#v, want one with show_output false", beacon)+ }+ if !kept {+ t.Fatalf("the user's own post_cascade_response hook was not kept: %s", data)+ }+ if _, err := removeDevinDesktopEndpointHooks(path); err != nil {+ t.Fatal(err)+ }+ data, _ = os.ReadFile(path)+ if strings.Contains(string(data), "cascade-response") || !strings.Contains(string(data), "python3 mine.py") {+ t.Fatalf("uninstall should remove only Beacon's post_cascade_response hook: %s", data)+ }+}+func TestInstallDevinHooksReplacesOldBeaconHooks(t *testing.T) {path := filepath.Join(t.TempDir(), "hooks.v1.json")existing := `{"PostToolUse":[{"hooks":[{"type":"command","command":"BEACON_ENDPOINT_MODE=1 old-beacon-hooks --platform devin post-tool"}]},{"hooks":[{"type":"command","command":"echo keep"}]}]}`diff --git a/docs/runtimes/devin-desktop.mdx b/docs/runtimes/devin-desktop.mdxindex a05727ea..02f3ea2d 100644--- a/docs/runtimes/devin-desktop.mdx+++ b/docs/runtimes/devin-desktop.mdx@@ -52,6 +52,7 @@ beacon endpoint install --harness claude,codex,devin-desktop| Area | Support ||------|---------|| Prompt telemetry | Supported through Cascade prompt hooks |+| Agent responses | Supported through the `post_cascade_response` hook. Cascade's `tool_info.response`, the Markdown of everything Cascade said since the last prompt, is recorded verbatim as an `agent.message` event in `gen_ai.output.messages`. Cascade writes that text itself, so it can include planner headings and one-line notes about actions it took around the answer || Command, tool, and file telemetry | Supported for prompt, command, MCP tool, file read, and file write telemetry where Cascade/Windsurf hook payloads are available || Local JSONL and dashboard | Supported || MDM deployment | Supported for the endpoint agent. Devin Desktop hooks are installed separately in the logged-in user's context or project context |