Skip to content

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

Stop duplicate hook endpoint telemetry

shukieshah0fa3ace06572
diff --git a/cli/beacon-hooks/cmd/post_tool.go b/cli/beacon-hooks/cmd/post_tool.go
index ffd9d1a7..95fc70e1 100644
--- a/cli/beacon-hooks/cmd/post_tool.go
+++ b/cli/beacon-hooks/cmd/post_tool.go
@@ -49,8 +49,6 @@ func runPostTool(cmd *cobra.Command, args []string) {
var params *evaluationParams
- emitPostToolObserved(logger, input)
-
if platformFlag == "cursor" {
// Cursor fires two hook types through post-tool:
// - afterFileEdit: has "edits" array and top-level "file_path" (no output supported)
@@ -58,6 +56,7 @@ func runPostTool(cmd *cobra.Command, args []string) {
// We use hook_event_name (present in all Cursor hook inputs) to distinguish them.
hookEvent, _ := input["hook_event_name"].(string)
if hookEvent != "afterFileEdit" {
+ emitPostToolObserved(logger, input)
outputJSON(emptyResponse)
return
}
@@ -68,6 +67,9 @@ func runPostTool(cmd *cobra.Command, args []string) {
}
if params == nil {
+ if platformFlag != "cursor" {
+ emitPostToolObserved(logger, input)
+ }
outputJSON(emptyResponse)
return
}
diff --git a/cli/beacon-hooks/internal/logging/endpoint_event_test.go b/cli/beacon-hooks/internal/logging/endpoint_event_test.go
index e8cded6d..b8cb85b7 100644
--- a/cli/beacon-hooks/internal/logging/endpoint_event_test.go
+++ b/cli/beacon-hooks/internal/logging/endpoint_event_test.go
@@ -1,24 +1,38 @@
package logging
-import "testing"
+import (
+ "os"
+ "path/filepath"
+ "testing"
+)
-func TestEndpointActionDoesNotClassifyRoutineStopAsBlocked(t *testing.T) {
- action, severity := endpointAction("stop-async-handler", map[string]interface{}{"message": "stop completed"})
- if action != "session.ended" || severity != "info" {
- t.Fatalf("endpointAction() = %s/%s, want session.ended/info", action, severity)
+func TestEndpointRedaction(t *testing.T) {
+ got := redactEndpointString("token=super-secret")
+ if got == "token=super-secret" {
+ t.Fatal("expected token to be redacted")
}
}
-func TestEndpointActionClassifiesViolationBlock(t *testing.T) {
- action, severity := endpointAction("stop-async-handler", map[string]interface{}{"message": "Blocking with violations"})
- if action != "policy.blocked" || severity != "high" {
- t.Fatalf("endpointAction() = %s/%s, want policy.blocked/high", action, severity)
+func TestRegularLogDoesNotWriteEndpointEventByDefault(t *testing.T) {
+ logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
+ t.Setenv("BEACON_ENDPOINT_LOG", logPath)
+
+ logger := NewLoggerForPlatform("pre-tool", "test")
+ logger.Info("diagnostic only")
+
+ if _, err := os.Stat(logPath); !os.IsNotExist(err) {
+ t.Fatalf("generic logger wrote endpoint event by default, stat err=%v", err)
}
}
-func TestEndpointRedaction(t *testing.T) {
- got := redactEndpointString("token=super-secret")
- if got == "token=super-secret" {
- t.Fatal("expected token to be redacted")
+func TestEndpointEventStillWritesStructuredTelemetry(t *testing.T) {
+ logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
+ t.Setenv("BEACON_ENDPOINT_LOG", logPath)
+
+ logger := NewLoggerForPlatform("pre-tool", "test")
+ logger.EndpointEvent("approval.allowed", "approval", "info", "Pre-tool observed", nil)
+
+ if data, err := os.ReadFile(logPath); err != nil || len(data) == 0 {
+ t.Fatalf("expected structured endpoint event, len=%d err=%v", len(data), err)
}
}
diff --git a/cli/beacon-hooks/internal/logging/logging.go b/cli/beacon-hooks/internal/logging/logging.go
index ce66c432..1d4c173f 100644
--- a/cli/beacon-hooks/internal/logging/logging.go
+++ b/cli/beacon-hooks/internal/logging/logging.go
@@ -95,67 +95,6 @@ func (l *Logger) write(entry map[string]interface{}) {
}
}
-func (l *Logger) writeEndpointEvent(entry map[string]interface{}) {
- path := endpointLogPath()
- if path == "" {
- return
- }
- if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
- return
- }
- hostname, _ := os.Hostname()
- action, severity := endpointAction(l.hookName, entry)
- event := map[string]interface{}{
- "timestamp": time.Now().UTC().Format(time.RFC3339),
- "vendor": "beacon",
- "product": "endpoint-agent",
- "schema_version": "1.0",
- "event": map[string]interface{}{
- "kind": "agent_runtime",
- "action": action,
- "category": "hook",
- },
- "severity": severity,
- "endpoint": map[string]interface{}{
- "hostname": hostname,
- "os": runtime.GOOS,
- },
- "user": map[string]interface{}{
- "name": os.Getenv("USER"),
- },
- "harness": map[string]interface{}{
- "name": l.platform,
- },
- "message": redactEndpointString(truncateEndpoint(fmt.Sprint(entry["message"]), 4096)),
- }
- if l.sessionID != "" {
- event["session"] = map[string]interface{}{"id": l.sessionID}
- }
- data, err := json.Marshal(event)
- if err != nil {
- return
- }
- if len(data) > 64*1024 {
- event["field_truncated"] = true
- event["message"] = truncateEndpoint(fmt.Sprint(event["message"]), 1024)
- data, err = json.Marshal(event)
- if err != nil {
- return
- }
- }
- f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
- if err != nil {
- return
- }
- if err := syscall.Flock(int(f.Fd()), syscall.LOCK_EX); err != nil {
- _ = f.Close()
- return
- }
- defer syscall.Flock(int(f.Fd()), syscall.LOCK_UN)
- defer f.Close()
- _, _ = f.Write(append(data, '\n'))
-}
-
func (l *Logger) EndpointEvent(action, category, severity, message string, fields map[string]interface{}) {
path := endpointLogPath()
if path == "" {
@@ -247,31 +186,6 @@ func writeEndpointJSON(path string, event map[string]interface{}) {
_, _ = f.Write(append(data, '\n'))
}
-func endpointAction(hookName string, entry map[string]interface{}) (action, severity string) {
- message := strings.ToLower(fmt.Sprint(entry["message"]))
- switch hookName {
- case "session-start":
- return "session.started", "info"
- case "session-end":
- return "session.ended", "info"
- case "pre-tool":
- if strings.Contains(message, "denying") || strings.Contains(message, "block") {
- return "policy.warned", "medium"
- }
- return "tool.invoked", "info"
- case "stop-async-handler":
- if strings.Contains(message, "blocking with violations") {
- return "policy.blocked", "high"
- }
- if strings.Contains(message, "warning") {
- return "policy.warned", "medium"
- }
- return "session.ended", "info"
- default:
- return "tool.invoked", "info"
- }
-}
-
func endpointLogPath() string {
if path := os.Getenv("BEACON_ENDPOINT_LOG"); path != "" {
return path