Here's my review of the branch changes (committed + unstaged):
Overview
This branch fixes several OpenCode integration issues across 6 commits plus additional unstaged work. Two main themes:
1. OpenCode Plugin Reliability (committed)
Turn-start made synchronous — callHookSync replaces await callHook for turn-start. This is the right call — if a fast mid-turn commit hits git hooks before the async turn-start completes, session state won't be initialized yet.
Fallback session/turn bootstrapping in message.updated — Handles the case where opencode run commits before message.part.updated fires. The resetSessionTracking() extraction is clean and eliminates the duplicated clear/reset logic.
Prompt backfill from transcript — ExtractPrompts implements agent.PromptExtractor so turn-end can backfill prompts from the OpenCode export file when they weren't captured during turn-start (empty prompt fallback).
2. Agent file exclusion from session tracking (committed + unstaged)
Committed:shouldIgnoreSessionTrackingPath centralizes the filtering of agent-owned files (opencode.json, .opencode/, .entire/, etc.) from DetectFileChanges, FilterAndNormalizePaths, and getUntrackedFilesForState. Previously only .entire/ was excluded.
Unstaged: Generalizes this further by adding ProtectedFiles() []string to the Agent interface, so shouldIgnoreSessionTrackingPath queries the registry dynamically instead of hardcoding opencode.json.
Issues & Suggestions
1. Interface change blast radius. The ProtectedFiles() addition touches every Agent implementation and every mock — 15+ files. Every agent except OpenCode returns nil. Consider making this an optional interface (like PromptExtractor) instead:
go
type FileProtector interface {
ProtectedFiles() []string
}
This eliminates all the return nil boilerplate and keeps the core Agent interface stable.
2. AllProtectedFiles() instantiates every agent on every call. Same pattern as AllProtectedDirs() so it's consistent, but both allocate fresh agents each time. Not a problem now but worth noting if call frequency increases. Consider caching if this gets called in hot paths.
3. Hardcoded opencode.json in committed code is superseded by unstaged work. The committed shouldIgnoreSessionTrackingPath has:
go
if cleanPath == "opencode.json" {
return true
}
The unstaged diff replaces this with the dynamic AllProtectedFiles() check. The committed code on its own is correct but will look odd in git history — the hardcoded check lives for exactly one commit before being generalized. Not a blocker, just worth squashing or noting.
4. Test uses t.Chdir without the t.Parallel() exception comment.TestHandleLifecycleTurnEnd_BackfillsPromptFromOpenCodeTranscript correctly avoids t.Parallel() and has the comment, but TestDetectFileChanges_IgnoresOpenCodeAgentFiles uses t.Chdir without t.Parallel() and is missing the explanatory comment. Minor consistency nit.
5. Plugin resetSessionTracking returns bool but the return value semantics are subtle. It returns true when a reset actually happened (session ID changed) and false when it's the same session. The callers use it correctly, but a brief doc comment on the function would help future readers.
Looks Good
The sync hook approach is well-motivated and the comment update explains the "why"
Test coverage is solid — new tests for sync dispatch, fallback session-start, fallback turn-start, file exclusion
Using testutil.InitRepo consistently across new tests
User
/copy
copy
User
can you review again
Assistant· claude-opus-4-6
Good — I can see you've addressed the main concern from my previous review. Here's the updated review:
What Changed Since Last Review
You switched ProtectedFiles from a required Agent interface method to an optional interface (ProtectedFilesProvider), exactly as suggested. This eliminated the return nil boilerplate from every agent and mock.
AllProtectedFiles() now does a type assertion:
go
pf, ok := factory().(ProtectedFilesProvider)
if !ok {
continue
}
Only OpenCode and the external agent implement it. Much cleaner.
Remaining Issues
1. wrappedAgent in external/capabilities.go unconditionally delegates ProtectedFiles(). But wrappedAgent embeds an Agent (the base interface), not a ProtectedFilesProvider. If the wrapped agent doesn't implement ProtectedFiles(), this will fail to compile — or if it does compile because external.Agent always has the method, the wrapper still unconditionally exposes it, which means any external agent gets opted into ProtectedFilesProvider whether they declared protected_files or not. This is probably fine in practice (returns nil), but worth verifying the intent.
2. Test mock protectedDirAgent implements ProtectedFiles() directly, which means it always satisfies ProtectedFilesProvider. The "collects files" test will pass, but it doesn't test the skip path where an agent doesn't implement the interface. Consider adding an agent without ProtectedFiles() to the "collects files" test to verify the type assertion branch.
3. Hardcoded opencode.json in committed code (8c67f69bb) is still superseded by this unstaged work. When you commit the unstaged changes, consider squashing or at least noting this in the commit message so the history reads cleanly.
Looks Good
Optional interface approach is the right design — no interface pollution
AllProtectedFiles() correctly copies factories before releasing the lock, matching AllProtectedDirs() pattern
External agent types properly expose protected_files in the JSON schema
Tests cover empty registry, collection, and deduplication
User
/copy
copy
Assistant· <synthetic>
No response requested.
User
/exit
exit
User
can you give me a good short pr description for this?
Make turn-start synchronous (callHookSync) so session state is initialized before fast mid-turn commits hit git hooks
Add fallback session/turn bootstrapping in message.updated for opencode run flows where message.part.updated fires too late
Backfill prompts from OpenCode transcript on turn-end when turn-start sent an empty prompt
Exclude agent-owned files (opencode.json, .opencode/) from session tracking via new ProtectedFilesProvider optional interface
Test plan
New tests for sync turn-start dispatch
New tests for message.updated fallback (session-start and turn-start)
New test for prompt backfill from OpenCode transcript
New test for agent file exclusion in DetectFileChanges and FilterAndNormalizePaths
New tests for AllProtectedFiles() registry function
mise run check passes
User
/copy
copy
User
can you check for me: when is plugin.ts written for opencode?
Assistant· claude-opus-4-6
The plugin is written in InstallHooks() at hooks.go:45, which is called when the user runs entire enable --agent opencode. It:
Embeds entire_plugin.ts into the binary at compile time via //go:embed (plugin.go:5)
Replaces the __ENTIRE_CMD__ placeholder with either entire or a go run path (for local dev)
Writes it to .opencode/plugins/entire.ts in the repo root
Is idempotent — skips the write if content is identical (unless force=true)
It's not written dynamically at session start or hook time — only during the explicit entire enable setup step.
User
but we have ensure hooks?
Assistant· claude-opus-4-6
You're right — EnsureSetup is called on every user-prompt-submit (turn-start) at lifecycle.go:260, and it installs git hooks. But those are the git hooks (prepare-commit-msg, post-commit, etc.), not the OpenCode plugin file.
The OpenCode plugin (entire_plugin.ts) is only written during entire enable via setup.go:1065. EnsureSetup doesn't re-check or reinstall agent-specific hooks like the OpenCode plugin — it only handles the generic .git/hooks/ scripts.
So if the OpenCode plugin gets deleted or modified after entire enable, it won't be auto-restored on next turn-start. Is that the concern you're looking at?
User
/copy
copy
User
yeah we have a fix in plugin.ts and thinking now how to make it as easy as possible for users to know they need an update there
Assistant· claude-opus-4-6
Good question. Right now the plugin is a static file written once at entire enable time. If a user updates their entire CLI (which embeds a new entire_plugin.ts), the old plugin stays in .opencode/plugins/entire.ts until they manually re-run entire enable.
A few options, lightest to heaviest:
1. Version check in EnsureSetup (recommended) — Embed a version comment in the plugin template (e.g., // entire-plugin-version: 3), then add a check in EnsureSetup or at turn-start that reads the installed plugin, compares the version, and auto-reinstalls if stale. Minimal user friction — they just get the fix on next session.
2. AreHooksInstalled content check — AreHooksInstalled currently just checks for the marker string. You could make it also compare content against the embedded template. Then EnsureSetup would see hooks as "not installed" and reinstall. Same effect as option 1, just uses the existing hook-check path.
3. Warn on version mismatch — Same detection as above but instead of auto-reinstalling, print a warning like "OpenCode plugin is outdated, run 'entire enable --agent opencode' to update". Less magic, more user control.
Option 2 feels cleanest — it reuses the existing !IsGitHookInstalled → reinstall pattern that EnsureSetup already has for git hooks, just extending it to agent-specific hooks. Want me to look at what that would take?
User
but I also remember we did some work on that recently?
Assistant· claude-opus-4-6
EnsureSetup at lifecycle.go:260 only ensures git hooks (prepare-commit-msg, post-commit, etc.) — it doesn't check agent-specific hooks like the OpenCode plugin.
But the building blocks are already there: InstallHooks already does a content comparison (hooks.go:64) and rewrites if the embedded template differs from what's on disk. So the fix is simple — just call InstallHooks from the turn-start path.
You could add it to handleLifecycleUserPromptSubmit right after EnsureSetup, something like:
go
if hs, ok := agent.AsHookSupport(ag); ok {
if _, err := hs.InstallHooks(ctx, false, false); err != nil {
logging.Warn(logCtx, "failed to ensure agent hooks", ...)
}
}
Since InstallHooks is already idempotent and content-diffing, it'll be a no-op when the plugin is current and auto-update when stale. No version comments needed. Want me to implement that?
User
/copy
copy
User
turnstart is pretty aggressive session start would be better?
Assistant· claude-opus-4-6
Good call — session-start fires once per session vs turn-start on every prompt. The content diff in InstallHooks makes it cheap either way, but session-start is the more natural place.
Let me check where session-start is handled.
Assistant· claude-opus-4-6
Yeah, session-start is the right place. It fires once, early, before any work happens. I'd add it right before the state machine transition block (around line 124). Want me to implement it?
User
could we add something to plugin.ts that self updates?
Assistant· claude-opus-4-6
Interesting idea. The bootstrap problem is that old plugin code is what's running — but if the self-update logic is simple enough, it'll survive across versions.
The plugin could shell out to the CLI on session start to rewrite itself:
typescript
// In session.created handler, before calling session-start hook:
Bun.spawnSync(["entire", "enable", "--agent", "opencode"], {
cwd: directory,
stdout: "ignore",
stderr: "ignore",
})
Since InstallHooks already does content-diffing, this is a no-op when current and a silent rewrite when stale. And entire enable --agent opencode is idempotent.
The catch: this only works for users who already have the self-update line in their plugin. Anyone on an older plugin without it still needs a manual entire enable --agent opencode. So it solves "future updates after this one" but not "getting this fix out to existing users."
Also, entire enable does more than just install hooks (settings, gitignore, etc.) — might want a lighter command like entire hooks opencode update that just does the plugin content-diff write. Or we could add a --hooks-only flag.
What do you think — worth adding a lightweight update subcommand, or just call entire enable --agent opencode and accept the extra work?
Now let me check how the branch actually addresses this.
Assistant· claude-opus-4-6
The issue is fully addressed by this branch. Here's the mapping:
Issue #883:currentSessionID is updated afterawait callHook(...), so a second session.created event during the await passes the guard and fires session-start again.
Branch fix: The resetSessionTracking() function updates currentSessionIDsynchronously before any hook call:
typescript
function resetSessionTracking(sessionID: string) {
if (currentSessionID === sessionID) {
return false // guard: same session, skip
}
// ... clear state ...
currentSessionID = sessionID // ← updated BEFORE returning
return true
}
The caller then does the await after the ID is already set, so a second session.created for the same session hits return false immediately. This closes the race window the issue describes.
The fix is actually slightly stronger than the issue's suggested fix — it extracts the logic into a reusable function that's also called from message.updated as a fallback path, ensuring consistent behavior across both event sources.