Skip to content

feat(commands): option groups, invocation scopes and the invocation record - #6156

Draft
edusperoni wants to merge 2 commits into
feat/define-command-migrationfrom
feat/options-machinery
Draft

edusperoni wants to merge 2 commits into
feat/define-command-migrationfrom
feat/options-machinery

Conversation

@edusperoni

Copy link
Copy Markdown
Collaborator

PR Checklist

Stacked on #6153; merge that first. Draft: this is the machinery the service-side options migration builds on, with the extension surface (a manifest-level way to contribute options) deliberately left for a later design.

What is the current behavior?

A command declares its options as one schema object, and only the command reads the parsed values, through ctx.options. Services read the process-wide options object. There is no way for an option set to be shared between commands and injected by a service, no scope between a root singleton and a per-invocation provider, and nothing records which invocation is running for code that resolves by name outside an injection context (hooks, plugin callbacks).

What is the new behavior?

Six pieces of machinery, each with tests, documented in defining-commands.md and extensions.md:

  1. Option groups. defineOptions(name, schema) returns a group that is both a schema and an injection token typed as the parsed values. options on a definition or a Command() meta takes a schema or a list of groups and schemas; ctx.options is typed as the merged values.
  2. Per-invocation provision. Every non-root group a command declares is provided in the invocation injector with its slice of the parsed values, so a service in reach of the invocation injects the group instead of the options object. CliOptions is the process-level group (log, verbose, version, help, profileDir, analyticsClient, path, config); it is provided at the root, and the option table derives its global entries from it.
  3. Collision rules. One spelling may be declared by several parts only with the same spec; an alias may not equal another option's spelling; a command may not redeclare a process-level spelling, but may list CliOptions to read those values typed. The six built-ins that redeclared --path or --help now list CliOptions.
  4. Contribution seams. The OptionContributions contract adds groups to a command by name, or to the root, before the parse that targets them. No manifest surface yet.
  5. providedIn scopes. A provider, an implementation class (@ProvidedIn) or a contract (@Contract({ providedIn })) can declare "invocation"; the instance lives on the nearest invocation injector and is disposed when the invocation ends. Resolving one from the root is an error, optional or not.
  6. The invocation record. currentInvocationInjector() resolves, in order, the synchronous injection context, the invocation's asynchronous flow, the most recently opened invocation, then null. Hooks resolve their by-name dependencies against it, and runCommand(definition) defaults its scope to it. An in-process dispatch closes what it opened.

No service is migrated onto a group in this PR.

@coderabbitai

coderabbitai Bot commented Sep 23, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@edusperoni
edusperoni force-pushed the feat/options-machinery branch from 66a2708 to d9f9735 Compare September 23, 2026 15:14
…ecord

- `defineOptions(name, schema)` declares an option group: a schema that is
  also an injection token typed as its parsed values. `options` takes a
  schema or a list of groups and schemas, and `ctx.options` is typed as the
  merged values. Spellings collide only with different specs; an alias may
  not equal another option's spelling.
- Every non-root group a command declares is provided in the invocation
  injector with its slice of the parsed values. `CliOptions` is the
  process-level group, provided at the root; the option table derives its
  global entries from it, and a command may list it but not redeclare its
  spellings. The built-ins that redeclared `--path` or `--help` list it.
- `OptionContributions` adds groups to a command by any of its names, own or
  registered, or to the root, ahead of the parse that targets them.
- `providedIn` on a provider, an implementation class (`@ProvidedIn`) or a
  contract puts the instance on the nearest injector of that scope in the
  resolving chain; the adapter opens each invocation's injector in the
  `invocation` scope and disposes it when the invocation ends. Resolving a
  scoped record from outside its scope is an error, `optional` or not.
- `currentInvocationInjector()` resolves the synchronous injection context,
  then the invocation's asynchronous flow, then the most recently opened
  invocation. Hooks resolve their by-name dependencies against it, and a
  definition run as given defaults its scope to it. An in-process dispatch
  closes the invocations it opened.
…invocation record

Option groups and the list form of `options`, the collision rules, `CliOptions`
and the spellings it protects, contributions and their timing, `providedIn`
with its disposal, and `currentInvocationInjector()` with its lookup order.
extensions.md states what an extension can use today and that a manifest-level
contribution does not exist yet.
@edusperoni
edusperoni force-pushed the feat/options-machinery branch from d9f9735 to 75009b0 Compare September 23, 2026 16:11

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant