Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/entire/cli/agent/opencode/entire_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
39 changes: 39 additions & 0 deletions cmd/entire/cli/agent/opencode/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,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=%d hook=%d assignment=%d",
guardIdx, hookIdx, assignIdx)
}
}

func TestInstallHooks_ForceReinstall(t *testing.T) {
dir := t.TempDir()
t.Chdir(dir)
Expand Down