Skip to content

feat(cli): allow effectCmd instance to be a function of args#25517

Merged
kitlangton merged 1 commit into
devfrom
kit/cli-effect-cmd-instance-fn
May 3, 2026
Merged

feat(cli): allow effectCmd instance to be a function of args#25517
kitlangton merged 1 commit into
devfrom
kit/cli-effect-cmd-instance-fn

Conversation

@kitlangton
Copy link
Copy Markdown
Contributor

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

  • `bun run typecheck`
  • `bun run test test/cli/` — 137 pass
  • Smoke: `serve` (existing `instance: false`) still works
  • Smoke: `models` (existing default `instance: true` via `undefined`) still works

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.
@kitlangton kitlangton enabled auto-merge (squash) May 3, 2026 02:19
@kitlangton kitlangton merged commit c4311dd into dev May 3, 2026
13 checks passed
@kitlangton kitlangton deleted the kit/cli-effect-cmd-instance-fn branch May 3, 2026 02:27
oleksii-honchar pushed a commit to oleksii-honchar/better-opencode that referenced this pull request May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant