Skip to content

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

Record a Kiro file creation as a create, not a modify

Claude7800c3b95005
diff --git a/cli/beacon-hooks/cmd/kiro.go b/cli/beacon-hooks/cmd/kiro.go
index 148d6487..303cf68a 100644
--- a/cli/beacon-hooks/cmd/kiro.go
+++ b/cli/beacon-hooks/cmd/kiro.go
@@ -606,6 +606,9 @@ func parseKiroEdit(input map[string]interface{}, logger *logging.Logger) *evalua
toolName: toolName,
filePath: filePath,
diffStr: diffStr,
+ // The taxonomy already answered this, and the shared diff path would otherwise write
+ // "modify" for a file that did not exist a moment ago.
+ fileOperation: kiroFileOperation(toolName, toolInput, toolResponse),
}
}
diff --git a/cli/beacon-hooks/cmd/kiro_hooks_test.go b/cli/beacon-hooks/cmd/kiro_hooks_test.go
index 98c03fb1..d4e8e130 100644
--- a/cli/beacon-hooks/cmd/kiro_hooks_test.go
+++ b/cli/beacon-hooks/cmd/kiro_hooks_test.go
@@ -674,6 +674,12 @@ func TestKiroCreateProducesAWholeFileDiff(t *testing.T) {
if got := leaf(event, "event", "action"); got != "file.modified" {
t.Fatalf("event.action = %q, want file.modified", got)
}
+ // The shared diff path writes "modify" unless the runtime's parser says otherwise, which
+ // would record a file that did not exist a moment ago as an edit -- and a rule matching
+ // file.operation == "create" would never fire for Kiro.
+ if got := leaf(event, "file", "operation"); got != "create" {
+ t.Fatalf("file.operation = %q, want create", got)
+ }
diff := leaf(event, "file", "diff")
if diff == "" {
t.Fatal("no diff recorded for a create")
@@ -723,7 +729,11 @@ func TestKiroStrReplaceProducesAnEditDiff(t *testing.T) {
"tool_response": kiroResult(true, "Edited /repo/app.go"),
})
- diff := leaf(lastEndpointEvent(t, logPath), "file", "diff")
+ event := lastEndpointEvent(t, logPath)
+ if got := leaf(event, "file", "operation"); got != "modify" {
+ t.Fatalf("file.operation = %q, want modify", got)
+ }
+ diff := leaf(event, "file", "diff")
if !containsLine(diff, "-return nil") || !containsLine(diff, "+return err") {
t.Fatalf("edit diff did not describe the replacement:\n%s", diff)
}
@@ -1089,3 +1099,29 @@ func runKiroPolicyDeny(t *testing.T, input map[string]interface{}) (code int, st
}
return code, stderr, stdout
}
+
+// The override is opt-in, so no runtime that does not set it changes shape. Claude Code's Write
+// tool creates a file and has always been recorded as "modify" on this path; that is a separate
+// question from Kiro's, and answering it here would change a recorded shape with no fixture to say
+// what it should become.
+func TestFileOperationOverrideIsOptIn(t *testing.T) {
+ setupHookConfigDirs(t)
+ platformFlag = "claude"
+ logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
+ t.Setenv("BEACON_ENDPOINT_MODE", "1")
+ t.Setenv("BEACON_ENDPOINT_LOG", logPath)
+ t.Setenv("BEACON_DISABLE_GIT_METADATA", "1")
+
+ runHookWithInput(t, runPostTool, map[string]interface{}{
+ "hook_event_name": "PostToolUse",
+ "session_id": "claude-write",
+ "cwd": "/repo",
+ "tool_name": "Write",
+ "tool_input": map[string]interface{}{"file_path": "/repo/new.go", "content": "package main\n"},
+ "tool_response": map[string]interface{}{"success": true},
+ })
+
+ if got := leaf(lastEndpointEvent(t, logPath), "file", "operation"); got != "modify" {
+ t.Fatalf("file.operation = %q, want the unchanged default modify", got)
+ }
+}
diff --git a/cli/beacon-hooks/cmd/post_tool.go b/cli/beacon-hooks/cmd/post_tool.go
index de31a83a..e3b584b2 100644
--- a/cli/beacon-hooks/cmd/post_tool.go
+++ b/cli/beacon-hooks/cmd/post_tool.go
@@ -26,11 +26,24 @@ func init() {
// evaluationParams holds the platform-independent fields needed for local hook handling.
type evaluationParams struct {
- sessionID string
- toolName string
- filePath string
- diffStr string
- extraFields map[string]interface{}
+ sessionID string
+ toolName string
+ filePath string
+ diffStr string
+ // fileOperation overrides the operation recordLocalEdit would otherwise write.
+ //
+ // That default is the literal string "modify", from diffFields, which is right for the
+ // majority of calls that reach this path and wrong for a creation: a file that did not exist
+ // before is recorded as a modification, so a rule matching file.operation == "create" never
+ // fires and a log reader cannot tell a new file from an edited one. It went unnoticed because
+ // most runtimes' create and edit tools both land here and neither told this function which it
+ // was.
+ //
+ // Empty means "leave the default alone", so no existing runtime's recorded shape changes: a
+ // runtime opts in by having its parser answer the question, which is where the answer is
+ // already known.
+ fileOperation string
+ extraFields map[string]interface{}
}
func runPostTool(cmd *cobra.Command, args []string) {
@@ -257,6 +270,12 @@ func recordLocalEdit(params *evaluationParams, input map[string]interface{}, log
for key, value := range diffFields(params.filePath, params.diffStr) {
fields[key] = value
}
+ // Applied after diffFields, which is what wrote the default this replaces.
+ if params.fileOperation != "" {
+ if file, ok := fields["file"].(map[string]interface{}); ok {
+ file["operation"] = params.fileOperation
+ }
+ }
fields["tool"] = mergeNested(fields["tool"], map[string]interface{}{"name": params.toolName, "path": params.filePath})
if params.sessionID != "" {
fields["session"] = mergeNested(fields["session"], map[string]interface{}{"id": params.sessionID})