diff options
| author | Kit Langton <[email protected]> | 2026-05-02 22:27:41 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-05-03 02:27:41 +0000 |
| commit | c4311dda3125256e1207a8d1f130e8d0d3fde7b2 (patch) | |
| tree | c2b09a0cff5f0526574e90abe72fb827e5742285 | |
| parent | ad05a46d747bad0c03a511ccef1115ee95a997c6 (diff) | |
| download | opencode-c4311dda3125256e1207a8d1f130e8d0d3fde7b2.tar.gz opencode-c4311dda3125256e1207a8d1f130e8d0d3fde7b2.zip | |
feat(cli): allow effectCmd instance to be a function of args (#25517)
| -rw-r--r-- | packages/opencode/src/cli/effect-cmd.ts | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/packages/opencode/src/cli/effect-cmd.ts b/packages/opencode/src/cli/effect-cmd.ts index 94ad0232c..ceb52d07a 100644 --- a/packages/opencode/src/cli/effect-cmd.ts +++ b/packages/opencode/src/cli/effect-cmd.ts @@ -37,10 +37,14 @@ interface EffectCmdOpts<Args, A> { * directly under AppRuntime — it can yield any `AppServices` but must not * yield `InstanceRef` (it'd be undefined, causing a defect). * + * Function form: `(args) => boolean` decides per-invocation. Useful for + * commands like `run --attach <url>` where one flag flips between local + * (needs instance) and remote (doesn't). + * * Use `false` for commands that don't read project state (e.g. `models`, * `serve`, `web`, `account`, `db`, `upgrade`). */ - instance?: boolean + instance?: boolean | ((args: Args) => boolean) /** Defaults to process.cwd(). Override for commands that take a directory positional. */ directory?: (args: Args) => string handler: (args: Args) => Effect.Effect<A, CliError, AppServices | InstanceStore.Service> @@ -72,7 +76,8 @@ export const effectCmd = <Args, A>(opts: EffectCmdOpts<Args, A>) => async handler(rawArgs) { // yargs typing wraps Args in ArgumentsCamelCase<WithDoubleDash<...>>; cast at the boundary. const args = rawArgs as unknown as Args - if (opts.instance === false) { + const useInstance = typeof opts.instance === "function" ? opts.instance(args) : opts.instance !== false + if (!useInstance) { await AppRuntime.runPromise(opts.handler(args)) return } |
