Conversation
Entire-Checkpoint: f92b8ef4844d
There was a problem hiding this comment.
Pull request overview
This PR updates the OpenCode agent hook installer to rewrite the .opencode/plugins/entire.ts plugin when the generated content has changed, instead of only treating the file as “installed” based on an embedded marker.
Changes:
- Replace marker-based idempotency with exact content equality (skip rewrite only when identical).
- Ensure mode/template changes (e.g., localDev vs prod command prefix) trigger a rewrite unless
--forceis used to override the idempotency check.
| // Check if already installed with identical content (idempotent) unless force | ||
| if !force { | ||
| if existing, readErr := os.ReadFile(pluginPath); readErr == nil { //nolint:gosec // Path constructed from repo root | ||
| if string(existing) == content { | ||
| return 0, nil // Already up-to-date | ||
| } | ||
| } |
There was a problem hiding this comment.
New behavior: when the plugin file exists but its content differs (e.g., switching localDev/prod or template updates), InstallHooks now rewrites it. There isn’t a test covering this update path (only fresh/idempotent/force/localDev). Add a unit test that pre-writes a different entire.ts (or installs once with localDev=true then installs with localDev=false) and asserts InstallHooks returns 1 and rewrites the file when force=false.
| if string(existing) == content { | ||
| return 0, nil // Already up-to-date | ||
| } |
There was a problem hiding this comment.
The InstallHooks doc comment says it returns 0 when the plugin is "already present". With the new content-equality idempotency check, a file can be present but still be rewritten (returning 1). Consider updating the wording to "0 if already up-to-date" (and/or mention that differing content will be rewritten unless --force is false).
| // Check if already installed with identical content (idempotent) unless force | ||
| if !force { | ||
| if existing, readErr := os.ReadFile(pluginPath); readErr == nil { //nolint:gosec // Path constructed from repo root | ||
| if string(existing) == content { |
There was a problem hiding this comment.
I'm assuming this is an optimization to avoid having to overwrite the same file over and over again, correct?
There was a problem hiding this comment.
As it was before we did not update it at all but just checked if it's there so I went with this. But I guess on the other side since this happens only in the context of entire enable we could also just always write it? 🤔
Entire-Checkpoint: f92b8ef4844d
Note
Low Risk
Low risk behavioral tweak limited to OpenCode hook installation; main change is that
InstallHookswill now overwrite stale plugin content instead of treating any file with the marker as already installed.Overview
Makes
opencodehook installation truly idempotent by comparing the on-disk.opencode/plugins/entire.tscontents to the newly generated template output.InstallHooksnow returns no-op only when the file is exactly up-to-date (unlessforce), and will rewrite the plugin when content differs (e.g.,localDevvs released command prefix).Written by Cursor Bugbot for commit 13238aa. Configure here.