From 0a73a1481c26066c8c25211e671332663777ebbc Mon Sep 17 00:00:00 2001 From: sanogueralorenzo Date: Tue, 31 Mar 2026 22:15:37 -0700 Subject: [PATCH 1/2] Fix duplicate OpenCode session-start hooks --- .../cli/agent/opencode/entire_plugin.ts | 6 +-- cmd/entire/cli/agent/opencode/hooks_test.go | 40 +++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/cmd/entire/cli/agent/opencode/entire_plugin.ts b/cmd/entire/cli/agent/opencode/entire_plugin.ts index 8544aa59a..a8a30d274 100644 --- a/cmd/entire/cli/agent/opencode/entire_plugin.ts +++ b/cmd/entire/cli/agent/opencode/entire_plugin.ts @@ -75,11 +75,11 @@ export const EntirePlugin: Plugin = async ({ directory }) => { seenUserMessages.clear() messageStore.clear() currentModel = null + await callHook("session-start", { + session_id: session.id, + }) } currentSessionID = session.id - await callHook("session-start", { - session_id: session.id, - }) break } diff --git a/cmd/entire/cli/agent/opencode/hooks_test.go b/cmd/entire/cli/agent/opencode/hooks_test.go index 744714b26..e6ac6760e 100644 --- a/cmd/entire/cli/agent/opencode/hooks_test.go +++ b/cmd/entire/cli/agent/opencode/hooks_test.go @@ -4,6 +4,7 @@ import ( "context" "os" "path/filepath" + "strconv" "strings" "testing" @@ -101,6 +102,45 @@ func TestInstallHooks_LocalDev(t *testing.T) { } } +func TestInstallHooks_SessionStartIsGuardedBySessionSwitch(t *testing.T) { + dir := t.TempDir() + t.Chdir(dir) + ag := &OpenCodeAgent{} + + if _, err := ag.InstallHooks(context.Background(), false, false); err != nil { + t.Fatalf("install failed: %v", err) + } + + pluginPath := filepath.Join(dir, ".opencode", "plugins", "entire.ts") + data, err := os.ReadFile(pluginPath) + if err != nil { + t.Fatalf("plugin file not created: %v", err) + } + + content := string(data) + guard := "if (currentSessionID !== session.id) {" + hook := `await callHook("session-start", {` + currentSessionAssignment := "currentSessionID = session.id" + + guardIdx := strings.Index(content, guard) + hookIdx := strings.Index(content, hook) + assignIdx := strings.Index(content, currentSessionAssignment) + + if guardIdx == -1 { + t.Fatalf("plugin file missing guard %q", guard) + } + if hookIdx == -1 { + t.Fatalf("plugin file missing session-start hook call %q", hook) + } + if assignIdx == -1 { + t.Fatalf("plugin file missing current session assignment %q", currentSessionAssignment) + } + if !(guardIdx < hookIdx && hookIdx < assignIdx) { + t.Fatalf("expected guarded session-start call before session assignment, got guard=%s hook=%s assignment=%s", + strconv.Itoa(guardIdx), strconv.Itoa(hookIdx), strconv.Itoa(assignIdx)) + } +} + func TestInstallHooks_ForceReinstall(t *testing.T) { dir := t.TempDir() t.Chdir(dir) From a9522ad5cf8d0cf12e6647c295aeddb9eb946c37 Mon Sep 17 00:00:00 2001 From: sanogueralorenzo Date: Tue, 31 Mar 2026 22:17:48 -0700 Subject: [PATCH 2/2] Drop unnecessary strconv in OpenCode hook test --- cmd/entire/cli/agent/opencode/hooks_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmd/entire/cli/agent/opencode/hooks_test.go b/cmd/entire/cli/agent/opencode/hooks_test.go index e6ac6760e..aaf39a593 100644 --- a/cmd/entire/cli/agent/opencode/hooks_test.go +++ b/cmd/entire/cli/agent/opencode/hooks_test.go @@ -4,7 +4,6 @@ import ( "context" "os" "path/filepath" - "strconv" "strings" "testing" @@ -136,8 +135,8 @@ func TestInstallHooks_SessionStartIsGuardedBySessionSwitch(t *testing.T) { t.Fatalf("plugin file missing current session assignment %q", currentSessionAssignment) } if !(guardIdx < hookIdx && hookIdx < assignIdx) { - t.Fatalf("expected guarded session-start call before session assignment, got guard=%s hook=%s assignment=%s", - strconv.Itoa(guardIdx), strconv.Itoa(hookIdx), strconv.Itoa(assignIdx)) + t.Fatalf("expected guarded session-start call before session assignment, got guard=%d hook=%d assignment=%d", + guardIdx, hookIdx, assignIdx) } }