feat(cli): allow effectCmd instance to be a function of args#25517
Merged
Conversation
Add `instance: (args) => boolean` form to effectCmd. Useful for commands where one flag flips between needing and not needing a project instance — e.g. `run --attach <url>` (remote, no instance) vs `run "hello"` (local, needs bootstrap). Backward compatible: `boolean | undefined` form unchanged. Default behavior (load instance) preserved when `instance` is not set. Resolution: typeof check on call, then the same true/false branches.
6 tasks
oleksii-honchar
pushed a commit
to oleksii-honchar/better-opencode
that referenced
this pull request
May 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extend the `instance` opt-out from #25507 to also accept a function:
```ts
effectCmd({
command: "run [message..]",
instance: (args) => !args.attach, // ← per-invocation decision
handler: ...,
})
```
For commands where one flag flips between needing and not needing a project instance — e.g. `run --attach ` (remote server, no local instance) vs `run "hello"` (local server, needs bootstrap).
Backward compatibility
`instance: boolean | undefined` form unchanged. Default behavior (load instance) preserved when `instance` is not set. Type union widened from `boolean` to `boolean | ((args: Args) => boolean)` — only additive.
Implementation
```ts
const useInstance = typeof opts.instance === "function" ? opts.instance(args) : opts.instance !== false
```
Then the same true/false branches as before.
Why
Stage 1 of converting `run.ts` (672 lines) — its handler has two paths (`--attach` skips bootstrap, default uses it). Static `instance: true|false` can't express that.
Test plan