@optique/core 1.0.0-dev.1616 → 1.0.0-dev.1659

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/parser.cjs CHANGED
@@ -1,16 +1,49 @@
1
1
  const require_annotations = require('./annotations.cjs');
2
2
  const require_message = require('./message.cjs');
3
- const require_dependency = require('./dependency.cjs');
4
- const require_dependency_runtime = require('./dependency-runtime.cjs');
5
- const require_mode_dispatch = require('./mode-dispatch.cjs');
6
3
  const require_usage = require('./usage.cjs');
7
4
  const require_doc = require('./doc.cjs');
8
- const require_constructs = require('./constructs.cjs');
5
+ const require_mode_dispatch = require('./mode-dispatch.cjs');
6
+ const require_input_trace = require('./input-trace.cjs');
9
7
  const require_modifiers = require('./modifiers.cjs');
10
8
  const require_primitives = require('./primitives.cjs');
9
+ const require_dependency_runtime = require('./dependency-runtime.cjs');
10
+ const require_constructs = require('./constructs.cjs');
11
11
 
12
12
  //#region src/parser.ts
13
13
  /**
14
+ * Internal marker for wrappers whose `{ hasCliValue: false }` states should
15
+ * be treated as unmatched dependency-source states during completion-time
16
+ * Phase 1.
17
+ *
18
+ * Wrappers like `bindEnv()` and `bindConfig()` opt in because their missing
19
+ * CLI states still carry enough fallback context to pre-complete exactly
20
+ * once. Wrappers like `prompt()` intentionally do not opt in because
21
+ * prompted values are not yet registered as dependency sources.
22
+ *
23
+ * @internal
24
+ */
25
+ const unmatchedNonCliDependencySourceStateMarker = Symbol.for("@optique/core/parser/unmatchedNonCliDependencySourceStateMarker");
26
+ /**
27
+ * Internal marker for parsers that want parent-state annotations injected
28
+ * directly into rebuilt child states instead of relying on structural
29
+ * inheritance.
30
+ *
31
+ * Wrappers like `bindConfig()`, `bindEnv()`, and `prompt()` opt in because
32
+ * their fallback contracts depend on carrying annotations through wrapper
33
+ * state objects during parse, complete, and suggest.
34
+ *
35
+ * @internal
36
+ */
37
+ const inheritParentAnnotationsKey = Symbol.for("@optique/core/inheritParentAnnotations");
38
+ /**
39
+ * Internal marker for wrapper parsers that should only treat annotation-only
40
+ * primitive wrapper states as completable when a nested source-binding wrapper
41
+ * produced them.
42
+ *
43
+ * @internal
44
+ */
45
+ const annotationWrapperRequiresSourceBindingKey = Symbol.for("@optique/core/annotationWrapperRequiresSourceBinding");
46
+ /**
14
47
  * Creates a {@link ParserContext} from a {@link ParseFrame} and an
15
48
  * {@link ExecutionContext}. The returned object provides both structured
16
49
  * access (`frame`, `exec`) and flat access (`buffer`, `state`, etc.)
@@ -25,6 +58,7 @@ const require_primitives = require('./primitives.cjs');
25
58
  function createParserContext(frame, exec) {
26
59
  return {
27
60
  exec,
61
+ trace: exec.trace,
28
62
  buffer: frame.buffer,
29
63
  state: frame.state,
30
64
  optionsTerminated: frame.optionsTerminated,
@@ -55,6 +89,8 @@ function injectAnnotationsIntoState(state, options) {
55
89
  * successful or not. If successful, it contains the parsed value of
56
90
  * type `T`. If not, it contains an error message describing the
57
91
  * failure.
92
+ * @throws {TypeError} When a synchronous dependency source extractor returns a
93
+ * thenable during completion-time dependency seeding.
58
94
  * @since 0.9.0 Renamed from the original `parse` function which now delegates
59
95
  * to this for sync parsers.
60
96
  * @since 0.10.0 Added optional `options` parameter for annotations support.
@@ -65,7 +101,8 @@ function parseSync(parser, args, options) {
65
101
  const exec = {
66
102
  usage: parser.usage,
67
103
  phase: "parse",
68
- path: []
104
+ path: [],
105
+ trace: require_input_trace.createInputTrace()
69
106
  };
70
107
  let context = createParserContext({
71
108
  buffer: args,
@@ -86,14 +123,14 @@ function parseSync(parser, args, options) {
86
123
  };
87
124
  } while (context.buffer.length > 0);
88
125
  const runtime = require_dependency_runtime.createDependencyRuntimeContext();
89
- const resolvedState = require_dependency.isDeferredParseState(context.state) ? require_dependency_runtime.resolveStateWithRuntime(context.state, runtime) : context.state;
90
126
  const completeExec = {
91
127
  ...exec,
92
128
  phase: "complete",
93
129
  dependencyRuntime: runtime,
94
- dependencyRegistry: runtime.registry
130
+ dependencyRegistry: runtime.registry,
131
+ trace: context.exec?.trace ?? context.trace ?? exec.trace
95
132
  };
96
- const endResult = parser.complete(resolvedState, completeExec);
133
+ const endResult = parser.complete(context.state, completeExec);
97
134
  return endResult.success ? {
98
135
  success: true,
99
136
  value: shouldUnwrapAnnotatedValue ? require_annotations.unwrapInjectedAnnotationWrapper(endResult.value) : endResult.value,
@@ -136,7 +173,8 @@ async function parseAsync(parser, args, options) {
136
173
  const exec = {
137
174
  usage: parser.usage,
138
175
  phase: "parse",
139
- path: []
176
+ path: [],
177
+ trace: require_input_trace.createInputTrace()
140
178
  };
141
179
  let context = createParserContext({
142
180
  buffer: args,
@@ -157,14 +195,14 @@ async function parseAsync(parser, args, options) {
157
195
  };
158
196
  } while (context.buffer.length > 0);
159
197
  const runtime = require_dependency_runtime.createDependencyRuntimeContext();
160
- const resolvedState = require_dependency.isDeferredParseState(context.state) ? await require_dependency_runtime.resolveStateWithRuntimeAsync(context.state, runtime) : context.state;
161
198
  const completeExec = {
162
199
  ...exec,
163
200
  phase: "complete",
164
201
  dependencyRuntime: runtime,
165
- dependencyRegistry: runtime.registry
202
+ dependencyRegistry: runtime.registry,
203
+ trace: context.exec?.trace ?? context.trace ?? exec.trace
166
204
  };
167
- const endResult = await parser.complete(resolvedState, completeExec);
205
+ const endResult = await parser.complete(context.state, completeExec);
168
206
  return endResult.success ? {
169
207
  success: true,
170
208
  value: shouldUnwrapAnnotatedValue ? require_annotations.unwrapInjectedAnnotationWrapper(endResult.value) : endResult.value,
@@ -195,6 +233,8 @@ async function parseAsync(parser, args, options) {
195
233
  * @param options Optional {@link ParseOptions} for customizing parsing behavior.
196
234
  * @returns A {@link Result} object (for sync) or Promise thereof (for async)
197
235
  * indicating whether the parsing was successful or not.
236
+ * @throws {TypeError} When a synchronous dependency source extractor returns a
237
+ * thenable during completion-time dependency seeding.
198
238
  * @since 0.10.0 Added optional `options` parameter for annotations support.
199
239
  */
200
240
  function parse(parser, args, options) {
@@ -232,6 +272,8 @@ function parse(parser, args, options) {
232
272
  * const suggestions2 = suggestSync(parser, ["-v", "--format="]);
233
273
  * // Returns: [{ text: "--format=json" }, { text: "--format=yaml" }]
234
274
  * ```
275
+ * @throws {TypeError} When a synchronous dependency source extractor returns a
276
+ * thenable during suggestion seeding.
235
277
  * @since 0.6.0
236
278
  * @since 0.9.0 Renamed from the original `suggest` function.
237
279
  * @since 0.10.0 Added optional `options` parameter for annotations support.
@@ -247,16 +289,17 @@ function suggestSync(parser, args, options) {
247
289
  }, {
248
290
  usage: parser.usage,
249
291
  phase: "suggest",
250
- path: []
292
+ path: [],
293
+ trace: require_input_trace.createInputTrace()
251
294
  });
252
295
  while (context.buffer.length > 0) {
253
296
  const result = parser.parse(context);
254
- if (!result.success) return Array.from(parser.suggest(withSuggestRuntime(context), prefix));
297
+ if (!result.success) return Array.from(parser.suggest(withSuggestRuntime(parser, context), prefix));
255
298
  const previousBuffer = context.buffer;
256
299
  context = result.next;
257
300
  if (isBufferUnchanged(previousBuffer, context.buffer)) return [];
258
301
  }
259
- return Array.from(parser.suggest(withSuggestRuntime(context), prefix));
302
+ return Array.from(parser.suggest(withSuggestRuntime(parser, context), prefix));
260
303
  }
261
304
  /**
262
305
  * Creates a dependency runtime from the current parser state and returns
@@ -265,19 +308,114 @@ function suggestSync(parser, args, options) {
265
308
  * a context with a dependency registry.
266
309
  * @internal
267
310
  */
268
- function withSuggestRuntime(context) {
311
+ function withSuggestRuntime(parser, context) {
312
+ const runtime = require_dependency_runtime.createDependencyRuntimeContext();
313
+ const nodes = getParserSuggestRuntimeNodes(parser, context.state, context.exec?.path ?? []);
314
+ if (nodes.length > 0) require_dependency_runtime.collectExplicitSourceValues(nodes, runtime);
315
+ return {
316
+ ...context,
317
+ dependencyRegistry: runtime.registry,
318
+ exec: context.exec ? {
319
+ ...context.exec,
320
+ dependencyRuntime: runtime,
321
+ dependencyRegistry: runtime.registry
322
+ } : void 0
323
+ };
324
+ }
325
+ async function withSuggestRuntimeAsync(parser, context) {
269
326
  const runtime = require_dependency_runtime.createDependencyRuntimeContext();
270
- require_dependency_runtime.collectSourcesFromState(context.state, runtime);
327
+ const nodes = getParserSuggestRuntimeNodes(parser, context.state, context.exec?.path ?? []);
328
+ if (nodes.length > 0) await require_dependency_runtime.collectExplicitSourceValuesAsync(nodes, runtime);
271
329
  return {
272
330
  ...context,
273
331
  dependencyRegistry: runtime.registry,
274
332
  exec: context.exec ? {
275
333
  ...context.exec,
334
+ dependencyRuntime: runtime,
276
335
  dependencyRegistry: runtime.registry
277
336
  } : void 0
278
337
  };
279
338
  }
280
339
  /**
340
+ * Returns suggest-time runtime nodes for a parser, falling back to the
341
+ * parser's own source metadata when it does not expose a custom hook.
342
+ *
343
+ * @param parser The parser whose suggest-time runtime nodes should be resolved.
344
+ * @param state The current parser state.
345
+ * @param path The path to this parser within the parse tree.
346
+ * @returns The runtime nodes used to seed suggest-time dependency resolution.
347
+ * @internal
348
+ */
349
+ function getParserSuggestRuntimeNodes(parser, state, path) {
350
+ if (typeof parser.getSuggestRuntimeNodes === "function") return parser.getSuggestRuntimeNodes(state, path);
351
+ if (parser.dependencyMetadata?.source == null) return [];
352
+ return [{
353
+ path,
354
+ parser,
355
+ state
356
+ }];
357
+ }
358
+ /**
359
+ * Returns wrapper-aware suggest-time runtime nodes for parsers that delegate
360
+ * to an inner parser while also exposing their own source metadata.
361
+ *
362
+ * The inner parser's nodes are always preserved so nested wrappers and
363
+ * constructs can continue to seed the dependency runtime recursively. When
364
+ * the outer parser itself owns source metadata, its `(path, parser, state)`
365
+ * node is appended so outer precedence rules still apply.
366
+ *
367
+ * @internal
368
+ */
369
+ function getDelegatingSuggestRuntimeNodes(innerParser, outerParser, state, path, innerState, outerPosition = "append") {
370
+ const innerNodes = getParserSuggestRuntimeNodes(innerParser, innerState, path);
371
+ if (outerParser.dependencyMetadata?.source == null) return innerNodes;
372
+ const outerNode = {
373
+ path,
374
+ parser: outerParser,
375
+ state
376
+ };
377
+ return outerPosition === "prepend" ? [outerNode, ...innerNodes] : [...innerNodes, outerNode];
378
+ }
379
+ /**
380
+ * Composes source metadata for a wrapper parser while preserving any derived
381
+ * or transform capabilities from the inner parser unchanged.
382
+ *
383
+ * @internal
384
+ */
385
+ function composeWrappedSourceMetadata(dependencyMetadata, wrapSource) {
386
+ if (dependencyMetadata?.source == null) return dependencyMetadata;
387
+ return {
388
+ ...dependencyMetadata,
389
+ source: wrapSource(dependencyMetadata.source)
390
+ };
391
+ }
392
+ /**
393
+ * Marks a parser as inheriting parent-state annotations through wrapper-state
394
+ * reconstruction.
395
+ *
396
+ * @internal
397
+ */
398
+ function defineInheritedAnnotationParser(parser) {
399
+ Object.defineProperty(parser, inheritParentAnnotationsKey, {
400
+ value: true,
401
+ configurable: true,
402
+ enumerable: false
403
+ });
404
+ }
405
+ /**
406
+ * Marks a wrapper parser as requiring a real source-binding state before
407
+ * annotation-only primitive wrappers should trigger completion.
408
+ *
409
+ * @internal
410
+ */
411
+ function defineSourceBindingOnlyAnnotationCompletionParser(parser) {
412
+ Object.defineProperty(parser, annotationWrapperRequiresSourceBindingKey, {
413
+ value: true,
414
+ configurable: true,
415
+ enumerable: false
416
+ });
417
+ }
418
+ /**
281
419
  * Generates command-line suggestions based on current parsing state.
282
420
  * This function processes the input arguments up to the last argument,
283
421
  * then calls the parser's suggest method with the remaining prefix.
@@ -308,12 +446,13 @@ async function suggestAsync(parser, args, options) {
308
446
  }, {
309
447
  usage: parser.usage,
310
448
  phase: "suggest",
311
- path: []
449
+ path: [],
450
+ trace: require_input_trace.createInputTrace()
312
451
  });
313
452
  while (context.buffer.length > 0) {
314
453
  const result = await parser.parse(context);
315
454
  if (!result.success) {
316
- const ctx$1 = withSuggestRuntime(context);
455
+ const ctx$1 = await withSuggestRuntimeAsync(parser, context);
317
456
  const suggestions$1 = [];
318
457
  for await (const suggestion of parser.suggest(ctx$1, prefix)) suggestions$1.push(suggestion);
319
458
  return suggestions$1;
@@ -322,7 +461,7 @@ async function suggestAsync(parser, args, options) {
322
461
  context = result.next;
323
462
  if (isBufferUnchanged(previousBuffer, context.buffer)) return [];
324
463
  }
325
- const ctx = withSuggestRuntime(context);
464
+ const ctx = await withSuggestRuntimeAsync(parser, context);
326
465
  const suggestions = [];
327
466
  for await (const suggestion of parser.suggest(ctx, prefix)) suggestions.push(suggestion);
328
467
  return suggestions;
@@ -347,6 +486,8 @@ async function suggestAsync(parser, args, options) {
347
486
  * @param options Optional {@link ParseOptions} for customizing parsing behavior.
348
487
  * @returns An array of {@link Suggestion} objects (for sync) or Promise thereof
349
488
  * (for async) containing completion candidates.
489
+ * @throws {TypeError} When a synchronous dependency source extractor returns a
490
+ * thenable during suggestion seeding.
350
491
  * @since 0.6.0
351
492
  * @since 0.10.0 Added optional `options` parameter for annotations support.
352
493
  */
@@ -563,18 +704,25 @@ function buildDocPage(parser, context, args) {
563
704
  //#endregion
564
705
  exports.DuplicateOptionError = require_constructs.DuplicateOptionError;
565
706
  exports.WithDefaultError = require_modifiers.WithDefaultError;
707
+ exports.annotationWrapperRequiresSourceBindingKey = annotationWrapperRequiresSourceBindingKey;
566
708
  exports.argument = require_primitives.argument;
567
709
  exports.command = require_primitives.command;
710
+ exports.composeWrappedSourceMetadata = composeWrappedSourceMetadata;
568
711
  exports.concat = require_constructs.concat;
569
712
  exports.conditional = require_constructs.conditional;
570
713
  exports.constant = require_primitives.constant;
571
714
  exports.createParserContext = createParserContext;
715
+ exports.defineInheritedAnnotationParser = defineInheritedAnnotationParser;
716
+ exports.defineSourceBindingOnlyAnnotationCompletionParser = defineSourceBindingOnlyAnnotationCompletionParser;
572
717
  exports.fail = require_primitives.fail;
573
718
  exports.flag = require_primitives.flag;
719
+ exports.getDelegatingSuggestRuntimeNodes = getDelegatingSuggestRuntimeNodes;
574
720
  exports.getDocPage = getDocPage;
575
721
  exports.getDocPageAsync = getDocPageAsync;
576
722
  exports.getDocPageSync = getDocPageSync;
723
+ exports.getParserSuggestRuntimeNodes = getParserSuggestRuntimeNodes;
577
724
  exports.group = require_constructs.group;
725
+ exports.inheritParentAnnotationsKey = inheritParentAnnotationsKey;
578
726
  exports.longestMatch = require_constructs.longestMatch;
579
727
  exports.map = require_modifiers.map;
580
728
  exports.merge = require_constructs.merge;
@@ -592,4 +740,5 @@ exports.suggest = suggest;
592
740
  exports.suggestAsync = suggestAsync;
593
741
  exports.suggestSync = suggestSync;
594
742
  exports.tuple = require_constructs.tuple;
743
+ exports.unmatchedNonCliDependencySourceStateMarker = unmatchedNonCliDependencySourceStateMarker;
595
744
  exports.withDefault = require_modifiers.withDefault;
package/dist/parser.d.cts CHANGED
@@ -5,7 +5,8 @@ import { DocFragments, DocPage } from "./doc.cjs";
5
5
  import { DependencyRegistryLike } from "./registry-types.cjs";
6
6
  import { DeferredMap, ValueParserResult } from "./valueparser.cjs";
7
7
  import { ParserDependencyMetadata } from "./dependency-metadata.cjs";
8
- import { DependencyRuntimeContext } from "./dependency-runtime.cjs";
8
+ import { DependencyRuntimeContext, RuntimeNode } from "./dependency-runtime.cjs";
9
+ import { InputTrace } from "./input-trace.cjs";
9
10
  import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, GroupOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.cjs";
10
11
  import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.cjs";
11
12
  import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, option, passThrough } from "./primitives.cjs";
@@ -150,6 +151,14 @@ interface Parser<M extends Mode = "sync", TValue = unknown, TState = unknown> {
150
151
  * state when parsing starts.
151
152
  */
152
153
  readonly initialState: TState;
154
+ /**
155
+ * Internal marker for wrappers whose `{ hasCliValue: false }` states should
156
+ * be treated as unmatched dependency-source states during completion-time
157
+ * Phase 1.
158
+ *
159
+ * @internal
160
+ */
161
+ readonly [unmatchedNonCliDependencySourceStateMarker]?: true;
153
162
  /**
154
163
  * Parses the input context and returns a result indicating
155
164
  * whether the parsing was successful or not.
@@ -258,9 +267,22 @@ interface Parser<M extends Mode = "sync", TValue = unknown, TState = unknown> {
258
267
  * capabilities. Used by the dependency runtime to resolve dependencies
259
268
  * without relying on state-shape protocols.
260
269
  * @internal
261
- * @since 1.0.0
262
270
  */
263
271
  readonly dependencyMetadata?: ParserDependencyMetadata;
272
+ /**
273
+ * Internal hook for top-level suggest-time dependency seeding.
274
+ *
275
+ * Wrapper parsers can expose the active parser/state pairs that should be
276
+ * scanned when `suggestSync()` or `suggestAsync()` builds a fresh dependency
277
+ * runtime. When omitted, only this parser's own dependency source metadata
278
+ * is considered.
279
+ *
280
+ * @param state The current parser state.
281
+ * @param path The path to this parser within the parse tree.
282
+ * @returns Runtime nodes to seed into the suggestion-time dependency runtime.
283
+ * @internal
284
+ */
285
+ getSuggestRuntimeNodes?(state: TState, path: readonly PropertyKey[]): readonly RuntimeNode[];
264
286
  }
265
287
  /**
266
288
  * Parser-local frame data containing the input buffer and parser state.
@@ -312,6 +334,16 @@ interface ExecutionContext {
312
334
  * resolution and completion.
313
335
  */
314
336
  readonly path: readonly PropertyKey[];
337
+ /**
338
+ * Immutable trace of raw primitive inputs recorded during parsing.
339
+ *
340
+ * Primitives append trace entries keyed by {@link path}, allowing later
341
+ * completion phases to replay derived parsers with the resolved
342
+ * dependency values.
343
+ *
344
+ * @internal
345
+ */
346
+ readonly trace?: InputTrace;
315
347
  /**
316
348
  * A registry containing resolved dependency values from DependencySource
317
349
  * parsers.
@@ -322,7 +354,6 @@ interface ExecutionContext {
322
354
  * The dependency runtime context for dependency resolution.
323
355
  * Coexists with `dependencyRegistry` during the transition period.
324
356
  * @internal
325
- * @since 1.0.0
326
357
  */
327
358
  readonly dependencyRuntime?: DependencyRuntimeContext;
328
359
  /**
@@ -341,10 +372,53 @@ interface ExecutionContext {
341
372
  *
342
373
  * @see https://github.com/dahlia/optique/issues/762
343
374
  * @internal
344
- * @since 1.0.0
345
375
  */
346
376
  readonly preCompletedByParser?: ReadonlyMap<string | symbol, unknown>;
377
+ /**
378
+ * Field names that should be ignored when a construct seeds dependency
379
+ * sources from child state during completion.
380
+ *
381
+ * Used by outer `merge()` completions to suppress ambiguous duplicate
382
+ * keys while still allowing the child parser to finish its own value
383
+ * completion.
384
+ *
385
+ * @internal
386
+ */
387
+ readonly excludedSourceFields?: ReadonlySet<string | symbol>;
347
388
  }
389
+ /**
390
+ * Internal marker for wrappers whose `{ hasCliValue: false }` states should
391
+ * be treated as unmatched dependency-source states during completion-time
392
+ * Phase 1.
393
+ *
394
+ * Wrappers like `bindEnv()` and `bindConfig()` opt in because their missing
395
+ * CLI states still carry enough fallback context to pre-complete exactly
396
+ * once. Wrappers like `prompt()` intentionally do not opt in because
397
+ * prompted values are not yet registered as dependency sources.
398
+ *
399
+ * @internal
400
+ */
401
+ declare const unmatchedNonCliDependencySourceStateMarker: unique symbol;
402
+ /**
403
+ * Internal marker for parsers that want parent-state annotations injected
404
+ * directly into rebuilt child states instead of relying on structural
405
+ * inheritance.
406
+ *
407
+ * Wrappers like `bindConfig()`, `bindEnv()`, and `prompt()` opt in because
408
+ * their fallback contracts depend on carrying annotations through wrapper
409
+ * state objects during parse, complete, and suggest.
410
+ *
411
+ * @internal
412
+ */
413
+ declare const inheritParentAnnotationsKey: unique symbol;
414
+ /**
415
+ * Internal marker for wrapper parsers that should only treat annotation-only
416
+ * primitive wrapper states as completable when a nested source-binding wrapper
417
+ * produced them.
418
+ *
419
+ * @internal
420
+ */
421
+ declare const annotationWrapperRequiresSourceBindingKey: unique symbol;
348
422
  /**
349
423
  * The context of the parser, which includes the input buffer and the state.
350
424
  *
@@ -364,6 +438,15 @@ interface ParserContext<TState> {
364
438
  * @since 1.0.0
365
439
  */
366
440
  readonly exec?: ExecutionContext;
441
+ /**
442
+ * Immutable trace of raw primitive inputs recorded during parsing.
443
+ *
444
+ * Preserved as a flat compatibility field so wrapper parsers can forward
445
+ * trace data even when they rebuild the parser context without {@link exec}.
446
+ *
447
+ * @since 1.0.0
448
+ */
449
+ readonly trace?: InputTrace;
367
450
  /**
368
451
  * The array of input strings that the parser is currently processing.
369
452
  */
@@ -557,6 +640,8 @@ type Result<T> = {
557
640
  * successful or not. If successful, it contains the parsed value of
558
641
  * type `T`. If not, it contains an error message describing the
559
642
  * failure.
643
+ * @throws {TypeError} When a synchronous dependency source extractor returns a
644
+ * thenable during completion-time dependency seeding.
560
645
  * @since 0.9.0 Renamed from the original `parse` function which now delegates
561
646
  * to this for sync parsers.
562
647
  * @since 0.10.0 Added optional `options` parameter for annotations support.
@@ -602,6 +687,8 @@ declare function parseAsync<T>(parser: Parser<Mode, T, unknown>, args: readonly
602
687
  * @param options Optional {@link ParseOptions} for customizing parsing behavior.
603
688
  * @returns A {@link Result} object (for sync) or Promise thereof (for async)
604
689
  * indicating whether the parsing was successful or not.
690
+ * @throws {TypeError} When a synchronous dependency source extractor returns a
691
+ * thenable during completion-time dependency seeding.
605
692
  * @since 0.10.0 Added optional `options` parameter for annotations support.
606
693
  */
607
694
  declare function parse<M extends Mode, T>(parser: Parser<M, T, unknown>, args: readonly string[], options?: ParseOptions): ModeValue<M, Result<T>>;
@@ -637,11 +724,57 @@ declare function parse<M extends Mode, T>(parser: Parser<M, T, unknown>, args: r
637
724
  * const suggestions2 = suggestSync(parser, ["-v", "--format="]);
638
725
  * // Returns: [{ text: "--format=json" }, { text: "--format=yaml" }]
639
726
  * ```
727
+ * @throws {TypeError} When a synchronous dependency source extractor returns a
728
+ * thenable during suggestion seeding.
640
729
  * @since 0.6.0
641
730
  * @since 0.9.0 Renamed from the original `suggest` function.
642
731
  * @since 0.10.0 Added optional `options` parameter for annotations support.
643
732
  */
644
733
  declare function suggestSync<T>(parser: Parser<"sync", T, unknown>, args: readonly [string, ...readonly string[]], options?: ParseOptions): readonly Suggestion[];
734
+ /**
735
+ * Returns suggest-time runtime nodes for a parser, falling back to the
736
+ * parser's own source metadata when it does not expose a custom hook.
737
+ *
738
+ * @param parser The parser whose suggest-time runtime nodes should be resolved.
739
+ * @param state The current parser state.
740
+ * @param path The path to this parser within the parse tree.
741
+ * @returns The runtime nodes used to seed suggest-time dependency resolution.
742
+ * @internal
743
+ */
744
+ declare function getParserSuggestRuntimeNodes<TState>(parser: Parser<Mode, unknown, TState>, state: TState, path: readonly PropertyKey[]): readonly RuntimeNode[];
745
+ /**
746
+ * Returns wrapper-aware suggest-time runtime nodes for parsers that delegate
747
+ * to an inner parser while also exposing their own source metadata.
748
+ *
749
+ * The inner parser's nodes are always preserved so nested wrappers and
750
+ * constructs can continue to seed the dependency runtime recursively. When
751
+ * the outer parser itself owns source metadata, its `(path, parser, state)`
752
+ * node is appended so outer precedence rules still apply.
753
+ *
754
+ * @internal
755
+ */
756
+ declare function getDelegatingSuggestRuntimeNodes<TInnerState>(innerParser: Parser<Mode, unknown, TInnerState>, outerParser: Parser<Mode, unknown, unknown>, state: unknown, path: readonly PropertyKey[], innerState: TInnerState, outerPosition?: "append" | "prepend"): readonly RuntimeNode[];
757
+ /**
758
+ * Composes source metadata for a wrapper parser while preserving any derived
759
+ * or transform capabilities from the inner parser unchanged.
760
+ *
761
+ * @internal
762
+ */
763
+ declare function composeWrappedSourceMetadata(dependencyMetadata: ParserDependencyMetadata | undefined, wrapSource: (source: NonNullable<ParserDependencyMetadata["source"]>) => NonNullable<ParserDependencyMetadata["source"]>): ParserDependencyMetadata | undefined;
764
+ /**
765
+ * Marks a parser as inheriting parent-state annotations through wrapper-state
766
+ * reconstruction.
767
+ *
768
+ * @internal
769
+ */
770
+ declare function defineInheritedAnnotationParser(parser: object): void;
771
+ /**
772
+ * Marks a wrapper parser as requiring a real source-binding state before
773
+ * annotation-only primitive wrappers should trigger completion.
774
+ *
775
+ * @internal
776
+ */
777
+ declare function defineSourceBindingOnlyAnnotationCompletionParser(parser: object): void;
645
778
  /**
646
779
  * Generates command-line suggestions based on current parsing state.
647
780
  * This function processes the input arguments up to the last argument,
@@ -683,6 +816,8 @@ declare function suggestAsync<T>(parser: Parser<Mode, T, unknown>, args: readonl
683
816
  * @param options Optional {@link ParseOptions} for customizing parsing behavior.
684
817
  * @returns An array of {@link Suggestion} objects (for sync) or Promise thereof
685
818
  * (for async) containing completion candidates.
819
+ * @throws {TypeError} When a synchronous dependency source extractor returns a
820
+ * thenable during suggestion seeding.
686
821
  * @since 0.6.0
687
822
  * @since 0.10.0 Added optional `options` parameter for annotations support.
688
823
  */
@@ -774,4 +909,4 @@ declare function getDocPage(parser: Parser<"sync", unknown, unknown>, argsOrOpti
774
909
  declare function getDocPage(parser: Parser<"async", unknown, unknown>, argsOrOptions?: readonly string[] | ParseOptions, options?: ParseOptions): Promise<DocPage | undefined>;
775
910
  declare function getDocPage<M extends Mode>(parser: Parser<M, unknown, unknown>, argsOrOptions?: readonly string[] | ParseOptions, options?: ParseOptions): ModeValue<M, DocPage | undefined>;
776
911
  //#endregion
777
- export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, ExecutionContext, ExecutionPhase, FlagErrorOptions, FlagOptions, GroupOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, createParserContext, fail, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
912
+ export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, ExecutionContext, ExecutionPhase, FlagErrorOptions, FlagOptions, GroupOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, annotationWrapperRequiresSourceBindingKey, argument, command, composeWrappedSourceMetadata, concat, conditional, constant, createParserContext, defineInheritedAnnotationParser, defineSourceBindingOnlyAnnotationCompletionParser, fail, flag, getDelegatingSuggestRuntimeNodes, getDocPage, getDocPageAsync, getDocPageSync, getParserSuggestRuntimeNodes, group, inheritParentAnnotationsKey, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, unmatchedNonCliDependencySourceStateMarker, withDefault };