feat(commands): option groups, invocation scopes and the invocation record - #6156
Draft
edusperoni wants to merge 2 commits into
Draft
edusperoni wants to merge 2 commits into
edusperoni wants to merge 2 commits into
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
edusperoni
force-pushed
the
feat/options-machinery
branch
from
September 23, 2026 15:14
66a2708 to
d9f9735
Compare
…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
force-pushed
the
feat/options-machinery
branch
from
September 23, 2026 16:11
d9f9735 to
75009b0
Compare
This branch has not been deployed
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.
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.mdandextensions.md:defineOptions(name, schema)returns a group that is both a schema and an injection token typed as the parsed values.optionson a definition or aCommand()meta takes a schema or a list of groups and schemas;ctx.optionsis typed as the merged values.CliOptionsis 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.CliOptionsto read those values typed. The six built-ins that redeclared--pathor--helpnow listCliOptions.OptionContributionscontract adds groups to a command by name, or to the root, before the parse that targets them. No manifest surface yet.providedInscopes. 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,optionalor not.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, andrunCommand(definition)defaults its scope to it. An in-process dispatch closes what it opened.No service is migrated onto a group in this PR.