fix(go): mirror Claude async rewake metadata

This commit is contained in:
ZacharyZhang-NY committed 2026-07-20 09:14:58 -04:00
1 parent fad1968c25
commit 6c2654a4b5
3 files changed
+26 -3

No files matched your search

@@ -34,7 +34,8 @@ var claudeHookEvents = stringSet(
var claudeHandlerKeys = map[string]map[string]struct{}{ var claudeHandlerKeys = map[string]map[string]struct{}{
"command": stringSet( "command": stringSet(
"if", "once", "statusMessage", "timeout", "args", "async", "if", "once", "statusMessage", "timeout", "args", "async",
"asyncRewake", "command", "shell", "type", "asyncRewake", "command", "rewakeMessage", "rewakeSummary",
"shell", "type",
), ),
"prompt": stringSet( "prompt": stringSet(
"if", "once", "statusMessage", "timeout", "continueOnBlock", "model", "if", "once", "statusMessage", "timeout", "continueOnBlock", "model",
@@ -252,6 +253,13 @@ func validateClaudeHandler(
return nil, err return nil, err
} }
} }
for _, field := range []string{"rewakeMessage", "rewakeSummary"} {
if _, exists := handler[field]; exists {
if _, err := requireClaudeString(handler, field, label); err != nil {
return nil, err
}
}
}
if shell, exists := handler["shell"]; exists && if shell, exists := handler["shell"]; exists &&
shell != "bash" && shell != "powershell" { shell != "bash" && shell != "powershell" {
return nil, fmt.Errorf( return nil, fmt.Errorf(
@@ -12,7 +12,20 @@ func TestClaudeOfficialBinaryAcceptsInstalledSettings(t *testing.T) {
if binary == "" { if binary == "" {
t.Skip("ELYDORA_CLAUDE_BINARY is unset") t.Skip("ELYDORA_CLAUDE_BINARY is unset")
} }
fixture := prepareClaudeFixture(t, claudeFixtureOptions{}) source := `{"hooks":{
"Stop":[{"hooks":[{
"type":"command",
"command":"node",
"args":["--version"],
"asyncRewake":true,
"rewakeMessage":"Background validation failed",
"rewakeSummary":"Validation feedback"
}]}]
}}`
fixture := prepareClaudeFixture(
t,
claudeFixtureOptions{existingRaw: &source},
)
if err := fixture.plugin.Install(fixture.config); err != nil { if err := fixture.plugin.Install(fixture.config); err != nil {
t.Fatalf("install Claude hooks: %v", err) t.Fatalf("install Claude hooks: %v", err)
} }
@@ -122,7 +122,7 @@ func TestClaudeMalformedSettingsFailBeforeRuntimeCreation(t *testing.T) {
func TestClaudePreservesEveryOfficialHandlerType(t *testing.T) { func TestClaudePreservesEveryOfficialHandlerType(t *testing.T) {
source := `{"hooks":{ source := `{"hooks":{
"SessionStart":[{"hooks":[{"type":"prompt","prompt":"Review context","model":"haiku","continueOnBlock":true,"if":"always","once":false,"statusMessage":"Reviewing","timeout":0.5}]}], "SessionStart":[{"hooks":[{"type":"prompt","prompt":"Review context","model":"haiku","continueOnBlock":true,"if":"always","once":false,"statusMessage":"Reviewing","timeout":0.5}]}],
"PreToolUse":[{"matcher":"Bash","hooks":[{"type":"command","command":"user-command","args":["--safe"],"async":false,"asyncRewake":true,"shell":"powershell"}]}], "PreToolUse":[{"matcher":"Bash","hooks":[{"type":"command","command":"user-command","args":["--safe"],"async":false,"asyncRewake":true,"rewakeMessage":"Background validation failed","rewakeSummary":"Validation feedback","shell":"powershell"}]}],
"Stop":[{"hooks":[{"type":"agent","prompt":"Verify completion","model":"sonnet"}]}], "Stop":[{"hooks":[{"type":"agent","prompt":"Verify completion","model":"sonnet"}]}],
"Notification":[{"hooks":[{"type":"http","url":"https://example.test/hook","headers":{"Authorization":"Bearer ${TOKEN}"},"allowedEnvVars":["TOKEN"]}]}], "Notification":[{"hooks":[{"type":"http","url":"https://example.test/hook","headers":{"Authorization":"Bearer ${TOKEN}"},"allowedEnvVars":["TOKEN"]}]}],
"PostToolUse":[{"hooks":[{"type":"mcp_tool","server":"audit","tool":"record","input":{"source":"claude"}}]}] "PostToolUse":[{"hooks":[{"type":"mcp_tool","server":"audit","tool":"record","input":{"source":"claude"}}]}]
@@ -163,6 +163,8 @@ func TestClaudeInvalidOfficialHookShapesFailBeforeWrites(t *testing.T) {
{"command", `{"hooks":{"PreToolUse":[{"hooks":[{"type":"command","command":""}]}]}}`, "non-empty string"}, {"command", `{"hooks":{"PreToolUse":[{"hooks":[{"type":"command","command":""}]}]}}`, "non-empty string"},
{"args", `{"hooks":{"PreToolUse":[{"hooks":[{"type":"command","command":"x","args":[1]}]}]}}`, "array of strings"}, {"args", `{"hooks":{"PreToolUse":[{"hooks":[{"type":"command","command":"x","args":[1]}]}]}}`, "array of strings"},
{"timeout", `{"hooks":{"PreToolUse":[{"hooks":[{"type":"command","command":"x","timeout":0}]}]}}`, "positive finite"}, {"timeout", `{"hooks":{"PreToolUse":[{"hooks":[{"type":"command","command":"x","timeout":0}]}]}}`, "positive finite"},
{"rewake message", `{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"x","rewakeMessage":""}]}]}}`, `field "rewakeMessage" must be a non-empty string`},
{"rewake summary", `{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"x","rewakeSummary":""}]}]}}`, `field "rewakeSummary" must be a non-empty string`},
{"headers", `{"hooks":{"PreToolUse":[{"hooks":[{"type":"http","url":"https://example.test","headers":{"A":1}}]}]}}`, "map names to strings"}, {"headers", `{"hooks":{"PreToolUse":[{"hooks":[{"type":"http","url":"https://example.test","headers":{"A":1}}]}]}}`, "map names to strings"},
{"input", `{"hooks":{"PreToolUse":[{"hooks":[{"type":"mcp_tool","server":"s","tool":"t","input":[]}]}]}}`, "must be an object"}, {"input", `{"hooks":{"PreToolUse":[{"hooks":[{"type":"mcp_tool","server":"s","tool":"t","input":[]}]}]}}`, "must be an object"},
} }