@alpacakit/channels 0.1.0-beta.19

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.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +772 -0
  3. package/dist/binding-compiler.d.ts +29 -0
  4. package/dist/binding-compiler.d.ts.map +1 -0
  5. package/dist/binding-compiler.js +40 -0
  6. package/dist/cli-coercion.d.ts +5 -0
  7. package/dist/cli-coercion.d.ts.map +1 -0
  8. package/dist/cli-coercion.js +51 -0
  9. package/dist/cli-compiler.d.ts +46 -0
  10. package/dist/cli-compiler.d.ts.map +1 -0
  11. package/dist/cli-compiler.js +213 -0
  12. package/dist/cli-executor.d.ts +25 -0
  13. package/dist/cli-executor.d.ts.map +1 -0
  14. package/dist/cli-executor.js +44 -0
  15. package/dist/cli-help-projection.d.ts +13 -0
  16. package/dist/cli-help-projection.d.ts.map +1 -0
  17. package/dist/cli-help-projection.js +159 -0
  18. package/dist/cli-model.d.ts +240 -0
  19. package/dist/cli-model.d.ts.map +1 -0
  20. package/dist/cli-model.js +89 -0
  21. package/dist/cli-presentation.d.ts +23 -0
  22. package/dist/cli-presentation.d.ts.map +1 -0
  23. package/dist/cli-presentation.js +265 -0
  24. package/dist/cli-schema.d.ts +4 -0
  25. package/dist/cli-schema.d.ts.map +1 -0
  26. package/dist/cli-schema.js +7 -0
  27. package/dist/cli-tree.d.ts +4 -0
  28. package/dist/cli-tree.d.ts.map +1 -0
  29. package/dist/cli-tree.js +421 -0
  30. package/dist/cli-values.d.ts +24 -0
  31. package/dist/cli-values.d.ts.map +1 -0
  32. package/dist/cli-values.js +40 -0
  33. package/dist/cli.d.ts +6 -0
  34. package/dist/cli.d.ts.map +1 -0
  35. package/dist/cli.js +5 -0
  36. package/dist/codecs.d.ts +25 -0
  37. package/dist/codecs.d.ts.map +1 -0
  38. package/dist/codecs.js +74 -0
  39. package/dist/contract.d.ts +12 -0
  40. package/dist/contract.d.ts.map +1 -0
  41. package/dist/contract.js +28 -0
  42. package/dist/factory.d.ts +16 -0
  43. package/dist/factory.d.ts.map +1 -0
  44. package/dist/factory.js +188 -0
  45. package/dist/index.d.ts +9 -0
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +8 -0
  48. package/dist/internal.d.ts +3 -0
  49. package/dist/internal.d.ts.map +1 -0
  50. package/dist/internal.js +3 -0
  51. package/dist/introspection.d.ts +40 -0
  52. package/dist/introspection.d.ts.map +1 -0
  53. package/dist/introspection.js +56 -0
  54. package/dist/mcp.d.ts +26 -0
  55. package/dist/mcp.d.ts.map +1 -0
  56. package/dist/mcp.js +84 -0
  57. package/dist/model.d.ts +166 -0
  58. package/dist/model.d.ts.map +1 -0
  59. package/dist/model.js +22 -0
  60. package/dist/runtime.d.ts +47 -0
  61. package/dist/runtime.d.ts.map +1 -0
  62. package/dist/runtime.js +140 -0
  63. package/dist/schema.d.ts +14 -0
  64. package/dist/schema.d.ts.map +1 -0
  65. package/dist/schema.js +70 -0
  66. package/dist/tree-internal.d.ts +14 -0
  67. package/dist/tree-internal.d.ts.map +1 -0
  68. package/dist/tree-internal.js +20 -0
  69. package/dist/values.d.ts +32 -0
  70. package/dist/values.d.ts.map +1 -0
  71. package/dist/values.js +30 -0
  72. package/package.json +47 -0
@@ -0,0 +1,240 @@
1
+ import { type CLI_BOOLEAN_MODE, CLI_HELP_USAGE_KIND, type CLI_OPTION_KIND, CLI_OPTION_VALUE_MODE } from "./cli-values.js";
2
+ import type { ParameterRequirementDescription } from "./introspection.js";
3
+ import type { ChannelSegmentOverride, EntryChannelBinding, EntryTreeEndpoint } from "./model.js";
4
+ import { CHANNEL } from "./values.js";
5
+ export declare const CLI_ARG_KIND: {
6
+ readonly option: "option";
7
+ readonly positional: "positional";
8
+ };
9
+ export declare const CLI_VALUE_COERCION: {
10
+ readonly json: "json";
11
+ readonly jsonOrString: "json_or_string";
12
+ };
13
+ export declare const CLI_ROUTER_RESULT_KIND: {
14
+ readonly resolved: "resolved";
15
+ readonly unknownCommand: "unknown_command";
16
+ readonly incompleteCommand: "incomplete_command";
17
+ readonly invalidInput: "invalid_input";
18
+ readonly invalidParameter: "invalid_parameter";
19
+ readonly internalError: "internal_error";
20
+ };
21
+ export type CliBooleanMode = (typeof CLI_BOOLEAN_MODE)[keyof typeof CLI_BOOLEAN_MODE];
22
+ export type CliOptionValueMode = (typeof CLI_OPTION_VALUE_MODE)[keyof typeof CLI_OPTION_VALUE_MODE];
23
+ export type CliValueCoercion = (typeof CLI_VALUE_COERCION)[keyof typeof CLI_VALUE_COERCION];
24
+ export type CliLongOptionFlag = `--${string}`;
25
+ export type CliOptionFlag = `-${string}`;
26
+ /** CLI segment-token path. Surface locations always use canonical tokens. */
27
+ export type CliCommandPath = readonly string[];
28
+ export type CliArgBindingInput<Name extends string = string> = {
29
+ readonly kind: typeof CLI_ARG_KIND.option;
30
+ readonly parameterName: Name;
31
+ /** Defaults to `--<kebab-case parameter name>` when omitted. */
32
+ readonly flags?: readonly CliOptionFlag[];
33
+ /** Displayed after the option flag. Defaults from `parameterName`. */
34
+ readonly valueName?: string;
35
+ /** Overrides the default scalar coercion performed for CLI strings. */
36
+ readonly coercion?: CliValueCoercion;
37
+ readonly booleanMode?: CliBooleanMode;
38
+ readonly negated?: true;
39
+ readonly repeatMode?: typeof CLI_OPTION_VALUE_MODE.commaOrRepeat;
40
+ } | {
41
+ readonly kind: typeof CLI_ARG_KIND.positional;
42
+ readonly parameterName: Name;
43
+ /** Defaults to the upper snake-cased parameter name when omitted. */
44
+ readonly valueName?: string;
45
+ /** Overrides the default scalar coercion performed for CLI strings. */
46
+ readonly coercion?: CliValueCoercion;
47
+ /** Defaults to `false` when omitted. */
48
+ readonly variadic?: boolean;
49
+ };
50
+ export type CliArgBinding<Name extends string = string> = {
51
+ readonly kind: typeof CLI_ARG_KIND.option;
52
+ readonly parameterName: Name;
53
+ readonly flags: readonly CliOptionFlag[];
54
+ readonly valueName: string;
55
+ /**
56
+ * Whether `valueName` was authored rather than derived. Boolean-flag
57
+ * options reject an authored value name at compile time, so the
58
+ * provenance must survive normalization instead of being inferred from
59
+ * the (always-populated) `valueName`.
60
+ */
61
+ readonly valueNameAuthored: boolean;
62
+ readonly coercion: CliValueCoercion | null;
63
+ readonly booleanMode: CliBooleanMode | null;
64
+ readonly negated: boolean;
65
+ readonly repeatable: boolean;
66
+ } | {
67
+ readonly kind: typeof CLI_ARG_KIND.positional;
68
+ readonly parameterName: Name;
69
+ readonly valueName: string;
70
+ readonly coercion: CliValueCoercion | null;
71
+ readonly variadic: boolean;
72
+ };
73
+ export type CliEntryBinding<Name extends string = string> = {
74
+ readonly parameters: readonly CliArgBinding<Name>[];
75
+ readonly help: CliCommandHelp;
76
+ };
77
+ export type CliSegment = {
78
+ readonly token: string;
79
+ readonly aliases: readonly string[];
80
+ readonly help: CliGroupHelp;
81
+ };
82
+ export type CliHelpExample = {
83
+ readonly title: string;
84
+ readonly useWhen: string;
85
+ readonly command: string;
86
+ readonly expectedResult: readonly string[];
87
+ };
88
+ export type CliHelpExampleInput = {
89
+ readonly title: string;
90
+ readonly useWhen: string;
91
+ readonly command: string;
92
+ readonly expectedResult?: readonly string[];
93
+ };
94
+ export type CliHelpOptionSection = {
95
+ readonly heading: string;
96
+ readonly description: string | null;
97
+ readonly parameterNames: readonly string[];
98
+ };
99
+ export type CliHelpOptionSectionInput<ParameterName extends string = string> = {
100
+ readonly heading: string;
101
+ readonly description?: string;
102
+ readonly parameterNames: readonly ParameterName[];
103
+ };
104
+ export type CliHelpUsageList = readonly [string, ...string[]];
105
+ export type CliHelpUsage = {
106
+ readonly kind: typeof CLI_HELP_USAGE_KIND.derived;
107
+ } | {
108
+ readonly kind: typeof CLI_HELP_USAGE_KIND.authored;
109
+ readonly values: CliHelpUsageList;
110
+ };
111
+ export type CliCommandHelp = {
112
+ readonly usage: CliHelpUsage;
113
+ readonly examples: readonly CliHelpExample[];
114
+ readonly optionSections: readonly CliHelpOptionSection[];
115
+ };
116
+ export type CliCommandHelpInput<OptionParameterName extends string = string> = {
117
+ readonly usages?: CliHelpUsageList;
118
+ readonly examples?: readonly CliHelpExampleInput[];
119
+ readonly optionSections?: readonly CliHelpOptionSectionInput<OptionParameterName>[];
120
+ };
121
+ export type CliGroupHelp = {
122
+ readonly subcommandHint: string | null;
123
+ readonly examples: readonly CliHelpExample[];
124
+ };
125
+ export type CliGroupHelpInput = {
126
+ readonly subcommandHint?: string;
127
+ readonly examples?: readonly CliHelpExampleInput[];
128
+ };
129
+ type CliOptionParameterName<Bindings extends readonly CliArgBindingInput[]> = Extract<Bindings[number], {
130
+ readonly kind: typeof CLI_ARG_KIND.option;
131
+ }>["parameterName"];
132
+ export declare function bindCliEntry<const Bindings extends readonly CliArgBindingInput[]>(binding: {
133
+ readonly parameters: Bindings;
134
+ readonly help?: CliCommandHelpInput<CliOptionParameterName<Bindings>>;
135
+ }): EntryChannelBinding<typeof CHANNEL.cli, Bindings[number]["parameterName"]>;
136
+ export declare function overrideCliSegment(segment: {
137
+ readonly token: string;
138
+ readonly aliases?: readonly string[];
139
+ readonly help?: CliGroupHelpInput;
140
+ }): ChannelSegmentOverride;
141
+ type CliHelpOptionBase = {
142
+ readonly parameterName: string;
143
+ readonly flags: readonly CliOptionFlag[];
144
+ readonly description: string;
145
+ readonly requirement: ParameterRequirementDescription;
146
+ };
147
+ export type CliHelpOption = CliHelpOptionBase & ({
148
+ readonly kind: typeof CLI_OPTION_KIND.booleanFlag;
149
+ readonly negativeFlags: readonly CliLongOptionFlag[];
150
+ } | {
151
+ readonly kind: typeof CLI_OPTION_KIND.value;
152
+ readonly valueName: string;
153
+ readonly valueMode: CliOptionValueMode;
154
+ });
155
+ /**
156
+ * Render-ready option grouping. Unlike `CliHelpOptionSection`, this projected
157
+ * read model contains the referenced options themselves, so renderers never
158
+ * need to join authored parameter names back to the flat option list.
159
+ */
160
+ export type CliHelpOptionGroup = {
161
+ /** `null` identifies the unsectioned option group. */
162
+ readonly heading: string | null;
163
+ readonly description: string | null;
164
+ readonly options: readonly CliHelpOption[];
165
+ };
166
+ export type CliHelpPositional = {
167
+ readonly parameterName: string;
168
+ readonly valueName: string;
169
+ readonly description: string;
170
+ readonly requirement: ParameterRequirementDescription;
171
+ readonly variadic: boolean;
172
+ };
173
+ export type CliHelpSurface = {
174
+ readonly name: string;
175
+ readonly token: string | null;
176
+ readonly aliases: readonly string[];
177
+ readonly description: string;
178
+ readonly optionGroups: readonly CliHelpOptionGroup[];
179
+ readonly positionals: readonly CliHelpPositional[];
180
+ readonly children: readonly CliHelpSurface[];
181
+ readonly remarks: readonly string[];
182
+ readonly relatedDocs: readonly string[];
183
+ readonly usages: CliHelpUsageList;
184
+ readonly examples: readonly CliHelpExample[];
185
+ readonly subcommandHint: string | null;
186
+ };
187
+ export type CliHelpRenderContext = {
188
+ /** Full selected command name, including the executable and command path. */
189
+ readonly programName: string;
190
+ /** Root executable name used to prefix authored invocation examples. */
191
+ readonly executableName: string;
192
+ /** Canonical CLI segment-token path for the supplied surface. */
193
+ readonly path: CliCommandPath;
194
+ readonly withDescription: boolean;
195
+ };
196
+ export type CliHelpRender = (surface: CliHelpSurface, context: CliHelpRenderContext) => string;
197
+ export type CliHelpSurfaceLocation = {
198
+ readonly surface: CliHelpSurface;
199
+ readonly path: CliCommandPath;
200
+ };
201
+ export type CliRouterResult = {
202
+ readonly kind: typeof CLI_ROUTER_RESULT_KIND.resolved;
203
+ readonly path: readonly string[];
204
+ readonly endpoint: EntryTreeEndpoint;
205
+ readonly projection: unknown;
206
+ } | {
207
+ readonly kind: typeof CLI_ROUTER_RESULT_KIND.unknownCommand;
208
+ readonly path: readonly string[];
209
+ readonly token: string;
210
+ } | {
211
+ readonly kind: typeof CLI_ROUTER_RESULT_KIND.incompleteCommand;
212
+ readonly path: readonly string[];
213
+ } | {
214
+ readonly kind: typeof CLI_ROUTER_RESULT_KIND.invalidInput;
215
+ readonly path: readonly string[];
216
+ readonly issues: readonly string[];
217
+ } | {
218
+ readonly kind: typeof CLI_ROUTER_RESULT_KIND.invalidParameter;
219
+ readonly path: readonly string[];
220
+ readonly parameterName: string;
221
+ readonly issues: readonly string[];
222
+ } | {
223
+ readonly kind: typeof CLI_ROUTER_RESULT_KIND.internalError;
224
+ readonly path: readonly string[];
225
+ readonly error: unknown;
226
+ };
227
+ export type CliResolvedEndpointResult<Endpoint extends EntryTreeEndpoint> = Omit<Extract<CliRouterResult, {
228
+ readonly kind: typeof CLI_ROUTER_RESULT_KIND.resolved;
229
+ }>, "endpoint" | "projection"> & {
230
+ readonly endpoint: Endpoint;
231
+ readonly projection: ReturnType<Endpoint["entry"]["project"]>;
232
+ };
233
+ export declare function isCliResolvedEndpoint<const Endpoint extends EntryTreeEndpoint>(result: CliRouterResult, endpoint: Endpoint): result is CliResolvedEndpointResult<Endpoint>;
234
+ export interface CliRouter {
235
+ readonly help: CliHelpSurface;
236
+ readonly endpoints: readonly EntryTreeEndpoint[];
237
+ resolve(argv: readonly string[]): CliRouterResult;
238
+ }
239
+ export {};
240
+ //# sourceMappingURL=cli-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-model.d.ts","sourceRoot":"","sources":["../src/cli-model.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EACrB,mBAAmB,EACnB,KAAK,eAAe,EACpB,qBAAqB,EAGtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,KAAK,EACV,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAOpB,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,eAAO,MAAM,YAAY;;;CAGf,CAAC;AAEX,eAAO,MAAM,kBAAkB;;;CAGrB,CAAC;AAEX,eAAO,MAAM,sBAAsB;;;;;;;CAOzB,CAAC;AAEX,MAAM,MAAM,cAAc,GACxB,CAAC,OAAO,gBAAgB,CAAC,CAAC,MA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EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB,CAAC;AAEN,MAAM,MAAM,yBAAyB,CAAC,QAAQ,SAAS,iBAAiB,IACtE,IAAI,CACF,OAAO,CACL,eAAe,EACf;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,sBAAsB,CAAC,QAAQ,CAAA;CAAE,CAC1D,EACD,UAAU,GAAG,YAAY,CAC1B,GAAG;IACF,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;CAC/D,CAAC;AAEJ,wBAAgB,qBAAqB,CAAC,KAAK,CAAC,QAAQ,SAAS,iBAAiB,EAC5E,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,QAAQ,GACjB,MAAM,IAAI,yBAAyB,CAAC,QAAQ,CAAC,CAK/C;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACjD,OAAO,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,eAAe,CAAC;CACnD"}
@@ -0,0 +1,89 @@
1
+ import { CLI_HELP_USAGE_KIND, CLI_OPTION_VALUE_MODE, defaultCliOptionFlag, defaultCliValueName, } from "./cli-values.js";
2
+ import { createChannelSegmentOverride, createEntryChannelBinding, PAYLOAD_KIND, registerChannelPayload, } from "./tree-internal.js";
3
+ import { CHANNEL } from "./values.js";
4
+ export const CLI_ARG_KIND = {
5
+ option: "option",
6
+ positional: "positional",
7
+ };
8
+ export const CLI_VALUE_COERCION = {
9
+ json: "json",
10
+ jsonOrString: "json_or_string",
11
+ };
12
+ export const CLI_ROUTER_RESULT_KIND = {
13
+ resolved: "resolved",
14
+ unknownCommand: "unknown_command",
15
+ incompleteCommand: "incomplete_command",
16
+ invalidInput: "invalid_input",
17
+ invalidParameter: "invalid_parameter",
18
+ internalError: "internal_error",
19
+ };
20
+ export function bindCliEntry(binding) {
21
+ const payload = {
22
+ parameters: binding.parameters.map(normalizeCliArgBinding),
23
+ help: normalizeCliCommandHelp(binding.help),
24
+ };
25
+ registerChannelPayload(PAYLOAD_KIND.cliBinding, payload);
26
+ return createEntryChannelBinding(CHANNEL.cli, payload);
27
+ }
28
+ export function overrideCliSegment(segment) {
29
+ const payload = {
30
+ token: segment.token,
31
+ aliases: segment.aliases ?? [],
32
+ help: normalizeCliGroupHelp(segment.help),
33
+ };
34
+ registerChannelPayload(PAYLOAD_KIND.cliSegment, payload);
35
+ return createChannelSegmentOverride(CHANNEL.cli, payload);
36
+ }
37
+ function normalizeCliArgBinding(input) {
38
+ if (input.kind === CLI_ARG_KIND.option) {
39
+ return {
40
+ kind: input.kind,
41
+ parameterName: input.parameterName,
42
+ flags: input.flags ?? [defaultCliOptionFlag(input.parameterName)],
43
+ valueName: input.valueName ?? defaultCliValueName(input.parameterName),
44
+ valueNameAuthored: input.valueName !== undefined,
45
+ coercion: input.coercion ?? null,
46
+ booleanMode: input.booleanMode ?? null,
47
+ negated: input.negated ?? false,
48
+ repeatable: input.repeatMode === CLI_OPTION_VALUE_MODE.commaOrRepeat,
49
+ };
50
+ }
51
+ return {
52
+ kind: input.kind,
53
+ parameterName: input.parameterName,
54
+ valueName: input.valueName ?? defaultCliValueName(input.parameterName),
55
+ coercion: input.coercion ?? null,
56
+ variadic: input.variadic ?? false,
57
+ };
58
+ }
59
+ function normalizeCliCommandHelp(input) {
60
+ return {
61
+ usage: input?.usages === undefined
62
+ ? { kind: CLI_HELP_USAGE_KIND.derived }
63
+ : { kind: CLI_HELP_USAGE_KIND.authored, values: input.usages },
64
+ examples: normalizeCliHelpExamples(input?.examples),
65
+ optionSections: (input?.optionSections ?? []).map((section) => ({
66
+ heading: section.heading,
67
+ description: section.description ?? null,
68
+ parameterNames: section.parameterNames,
69
+ })),
70
+ };
71
+ }
72
+ function normalizeCliGroupHelp(input) {
73
+ return {
74
+ subcommandHint: input?.subcommandHint ?? null,
75
+ examples: normalizeCliHelpExamples(input?.examples),
76
+ };
77
+ }
78
+ function normalizeCliHelpExamples(examples) {
79
+ return (examples ?? []).map((example) => ({
80
+ title: example.title,
81
+ useWhen: example.useWhen,
82
+ command: example.command,
83
+ expectedResult: example.expectedResult ?? [],
84
+ }));
85
+ }
86
+ export function isCliResolvedEndpoint(result, endpoint) {
87
+ return (result.kind === CLI_ROUTER_RESULT_KIND.resolved &&
88
+ result.endpoint === endpoint);
89
+ }
@@ -0,0 +1,23 @@
1
+ import { CLI_ROUTER_RESULT_KIND, type CliCommandPath, type CliHelpExample, type CliHelpOption, type CliHelpRenderContext, type CliHelpSurface, type CliHelpSurfaceLocation, type CliRouterResult } from "./cli-model.js";
2
+ import type { ParameterRequirementDescription } from "./introspection.js";
3
+ export type CliHelpOptionDescription = {
4
+ readonly names: string;
5
+ readonly description: string;
6
+ };
7
+ export declare function findCliHelpSurface(root: CliHelpSurface, commandPath: CliCommandPath): CliHelpSurface | null;
8
+ export declare function findCliHelpSurfaceLocation(root: CliHelpSurface, commandPath: CliCommandPath): CliHelpSurfaceLocation | null;
9
+ export declare function renderCliHelp(surface: CliHelpSurface, context: CliHelpRenderContext): string;
10
+ export declare function listCliHelpSurfaces(root: CliHelpSurface): readonly CliHelpSurfaceLocation[];
11
+ export declare function describeCliHelpOption(option: CliHelpOption): CliHelpOptionDescription;
12
+ export declare function appendCliCommandPart(command: string, part: string): string;
13
+ export declare function formatDefaultCliSubcommandHint(programName: string): string;
14
+ export declare function formatCliRouterError(result: Extract<CliRouterResult, {
15
+ readonly kind: typeof CLI_ROUTER_RESULT_KIND.unknownCommand | typeof CLI_ROUTER_RESULT_KIND.incompleteCommand | typeof CLI_ROUTER_RESULT_KIND.invalidInput | typeof CLI_ROUTER_RESULT_KIND.invalidParameter;
16
+ }>): string;
17
+ export declare function formatCliHelpParameterDescription(input: {
18
+ readonly description: string;
19
+ readonly requirement: ParameterRequirementDescription;
20
+ readonly additionalDetails: readonly string[];
21
+ }): string;
22
+ export declare function renderCliHelpExamples(examples: readonly CliHelpExample[], executableName: string): readonly string[];
23
+ //# sourceMappingURL=cli-presentation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-presentation.d.ts","sourceRoot":"","sources":["../src/cli-presentation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAE3B,KAAK,eAAe,EACrB,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AAiD1E,MAAM,MAAM,wBAAwB,GAAG;IACrC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,cAAc,EACpB,WAAW,EAAE,cAAc,GAC1B,cAAc,GAAG,IAAI,CAEvB;AAED,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,cAAc,EACpB,WAAW,EAAE,cAAc,GAC1B,sBAAsB,GAAG,IAAI,CAe/B;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,oBAAoB,GAC5B,MAAM,CAWR;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,cAAc,GACnB,SAAS,sBAAsB,EAAE,CAanC;AAqJD,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,aAAa,GACpB,wBAAwB,CAuB1B;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI1E;AAED,wBAAgB,8BAA8B,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE1E;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,OAAO,CACb,eAAe,EACf;IACE,QAAQ,CAAC,IAAI,EACT,OAAO,sBAAsB,CAAC,cAAc,GAC5C,OAAO,sBAAsB,CAAC,iBAAiB,GAC/C,OAAO,sBAAsB,CAAC,YAAY,GAC1C,OAAO,sBAAsB,CAAC,gBAAgB,CAAC;CACpD,CACF,GACA,MAAM,CAcR;AAED,wBAAgB,iCAAiC,CAAC,KAAK,EAAE;IACvD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,+BAA+B,CAAC;IACtD,QAAQ,CAAC,iBAAiB,EAAE,SAAS,MAAM,EAAE,CAAC;CAC/C,GAAG,MAAM,CAUT;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,SAAS,cAAc,EAAE,EACnC,cAAc,EAAE,MAAM,GACrB,SAAS,MAAM,EAAE,CAiBnB"}
@@ -0,0 +1,265 @@
1
+ import { CLI_ROUTER_RESULT_KIND, } from "./cli-model.js";
2
+ import { CLI_OPTION_KIND, CLI_OPTION_VALUE_MODE } from "./cli-values.js";
3
+ import { PARAMETER_REQUIREMENT_KIND } from "./values.js";
4
+ const CLI_HELP_TEXT = {
5
+ argumentsHeading: "Arguments:",
6
+ commandArgument: "<command>",
7
+ commandsHeading: "Commands:",
8
+ commaOrRepeatDetail: "comma-separated or repeatable",
9
+ defaultDetailPrefix: "default:",
10
+ examplesHeading: "Examples:",
11
+ expectedResultHeading: "Expected result:",
12
+ incompleteCommandPrefix: "Incomplete command:",
13
+ invalidInputLabel: "Invalid input",
14
+ invalidParameterPrefix: "Invalid",
15
+ nextStepsHeading: "Next steps:",
16
+ optionsHeading: "Options:",
17
+ optionalDetail: "optional",
18
+ relatedDocumentationHeading: "Related documentation:",
19
+ remarksHeading: "Remarks:",
20
+ repeatableDetail: "repeatable",
21
+ requiredDetail: "required",
22
+ unknownCommandPrefix: "Unknown command:",
23
+ usageHeading: "Usage:",
24
+ useWhenPrefix: "Use when",
25
+ };
26
+ const CLI_OPTION_VALUE_MODE_DETAILS = {
27
+ [CLI_OPTION_VALUE_MODE.replace]: [],
28
+ [CLI_OPTION_VALUE_MODE.repeat]: [CLI_HELP_TEXT.repeatableDetail],
29
+ [CLI_OPTION_VALUE_MODE.commaOrRepeat]: [CLI_HELP_TEXT.commaOrRepeatDetail],
30
+ };
31
+ const CLI_HELP_LAYOUT = {
32
+ columnSeparator: "\t",
33
+ commandPartSeparator: " ",
34
+ detailSeparator: ", ",
35
+ emptyLine: "",
36
+ issueSeparator: "; ",
37
+ itemIndent: " ",
38
+ lineSeparator: "\n",
39
+ nestedItemIndent: " ",
40
+ resultIndent: " ",
41
+ sectionSeparator: "\n\n",
42
+ };
43
+ export function findCliHelpSurface(root, commandPath) {
44
+ return findCliHelpSurfaceLocation(root, commandPath)?.surface ?? null;
45
+ }
46
+ export function findCliHelpSurfaceLocation(root, commandPath) {
47
+ let current = root;
48
+ const path = [];
49
+ for (const token of commandPath) {
50
+ const child = current.children.find((candidate) => candidate.token === token || candidate.aliases.includes(token));
51
+ if (!child) {
52
+ return null;
53
+ }
54
+ current = child;
55
+ path.push(child.token ?? child.name);
56
+ }
57
+ return { surface: current, path };
58
+ }
59
+ export function renderCliHelp(surface, context) {
60
+ return joinCliHelpSections([
61
+ createCliHelpSummarySection(surface, context.programName),
62
+ createCliHelpCommandsSection(surface),
63
+ createCliHelpArgumentsSection(surface),
64
+ createCliHelpOptionsSection(surface),
65
+ createCliHelpRemarksSection(surface),
66
+ createCliHelpExamplesSection(surface, context.executableName),
67
+ createCliHelpDocumentationSection(surface),
68
+ createCliHelpNextStepsSection(surface, context.programName),
69
+ ]);
70
+ }
71
+ export function listCliHelpSurfaces(root) {
72
+ const locations = [];
73
+ const pending = [{ surface: root, path: [] }];
74
+ for (const current of pending) {
75
+ locations.push(current);
76
+ pending.push(...current.surface.children.map((child) => ({
77
+ surface: child,
78
+ path: [...current.path, child.token ?? child.name],
79
+ })));
80
+ }
81
+ return locations;
82
+ }
83
+ function joinCliHelpSections(sections) {
84
+ return sections
85
+ .flatMap((section) => (section === null ? [] : [section]))
86
+ .map((section) => section.join(CLI_HELP_LAYOUT.lineSeparator))
87
+ .join(CLI_HELP_LAYOUT.sectionSeparator);
88
+ }
89
+ function createCliHelpSummarySection(surface, programName) {
90
+ return [
91
+ ...surface.usages.map((usage) => `${CLI_HELP_TEXT.usageHeading} ${appendCliCommandPart(programName, usage)}`),
92
+ CLI_HELP_LAYOUT.emptyLine,
93
+ surface.description,
94
+ ];
95
+ }
96
+ function createCliHelpCommandsSection(surface) {
97
+ if (surface.children.length === 0) {
98
+ return null;
99
+ }
100
+ return [
101
+ CLI_HELP_TEXT.commandsHeading,
102
+ ...surface.children.map((child) => {
103
+ const names = [child.token ?? child.name, ...child.aliases].join(CLI_HELP_LAYOUT.detailSeparator);
104
+ return `${CLI_HELP_LAYOUT.itemIndent}${names}${CLI_HELP_LAYOUT.columnSeparator}${child.description}`;
105
+ }),
106
+ ];
107
+ }
108
+ function createCliHelpArgumentsSection(surface) {
109
+ if (surface.positionals.length === 0) {
110
+ return null;
111
+ }
112
+ return [
113
+ CLI_HELP_TEXT.argumentsHeading,
114
+ ...surface.positionals.map((positional) => `${CLI_HELP_LAYOUT.itemIndent}${positional.valueName}${CLI_HELP_LAYOUT.columnSeparator}${formatCliHelpParameterDescription({
115
+ description: positional.description,
116
+ requirement: positional.requirement,
117
+ additionalDetails: [],
118
+ })}`),
119
+ ];
120
+ }
121
+ function createCliHelpOptionsSection(surface) {
122
+ if (surface.optionGroups.length === 0) {
123
+ return null;
124
+ }
125
+ return [CLI_HELP_TEXT.optionsHeading, ...renderCliHelpOptions(surface)];
126
+ }
127
+ function createCliHelpRemarksSection(surface) {
128
+ if (surface.remarks.length === 0) {
129
+ return null;
130
+ }
131
+ return [
132
+ CLI_HELP_TEXT.remarksHeading,
133
+ ...surface.remarks.map((remark) => `${CLI_HELP_LAYOUT.itemIndent}${remark}`),
134
+ ];
135
+ }
136
+ function createCliHelpExamplesSection(surface, programName) {
137
+ if (surface.examples.length === 0) {
138
+ return null;
139
+ }
140
+ return [
141
+ CLI_HELP_TEXT.examplesHeading,
142
+ ...renderCliHelpExamples(surface.examples, programName),
143
+ ];
144
+ }
145
+ function createCliHelpDocumentationSection(surface) {
146
+ if (surface.relatedDocs.length === 0) {
147
+ return null;
148
+ }
149
+ return [
150
+ CLI_HELP_TEXT.relatedDocumentationHeading,
151
+ ...surface.relatedDocs.map((documentId) => `${CLI_HELP_LAYOUT.itemIndent}${documentId}`),
152
+ ];
153
+ }
154
+ function createCliHelpNextStepsSection(surface, programName) {
155
+ if (surface.children.length === 0) {
156
+ return null;
157
+ }
158
+ return [
159
+ CLI_HELP_TEXT.nextStepsHeading,
160
+ `${CLI_HELP_LAYOUT.itemIndent}${surface.subcommandHint ?? formatDefaultCliSubcommandHint(programName)}`,
161
+ ];
162
+ }
163
+ function renderCliHelpOptions(surface) {
164
+ return surface.optionGroups.flatMap((group) => {
165
+ const indent = group.heading === null
166
+ ? CLI_HELP_LAYOUT.itemIndent
167
+ : CLI_HELP_LAYOUT.nestedItemIndent;
168
+ return [
169
+ ...(group.heading === null
170
+ ? []
171
+ : [`${CLI_HELP_LAYOUT.itemIndent}${group.heading}`]),
172
+ ...(group.description === null
173
+ ? []
174
+ : [`${CLI_HELP_LAYOUT.nestedItemIndent}${group.description}`]),
175
+ ...group.options.map((option) => renderCliHelpOption(option, indent)),
176
+ ];
177
+ });
178
+ }
179
+ function renderCliHelpOption(option, indent) {
180
+ const description = describeCliHelpOption(option);
181
+ return `${indent}${description.names}${CLI_HELP_LAYOUT.columnSeparator}${description.description}`;
182
+ }
183
+ export function describeCliHelpOption(option) {
184
+ switch (option.kind) {
185
+ case CLI_OPTION_KIND.booleanFlag:
186
+ return {
187
+ names: [...option.flags, ...option.negativeFlags].join(CLI_HELP_LAYOUT.detailSeparator),
188
+ description: formatCliHelpParameterDescription({
189
+ description: option.description,
190
+ requirement: option.requirement,
191
+ additionalDetails: [],
192
+ }),
193
+ };
194
+ case CLI_OPTION_KIND.value:
195
+ return {
196
+ names: `${option.flags.join(CLI_HELP_LAYOUT.detailSeparator)} <${option.valueName}>`,
197
+ description: formatCliHelpParameterDescription({
198
+ description: option.description,
199
+ requirement: option.requirement,
200
+ additionalDetails: CLI_OPTION_VALUE_MODE_DETAILS[option.valueMode],
201
+ }),
202
+ };
203
+ }
204
+ }
205
+ export function appendCliCommandPart(command, part) {
206
+ return part.length === 0
207
+ ? command
208
+ : `${command}${CLI_HELP_LAYOUT.commandPartSeparator}${part}`;
209
+ }
210
+ export function formatDefaultCliSubcommandHint(programName) {
211
+ return `Run \`${programName} ${CLI_HELP_TEXT.commandArgument} --help\` for subcommand details.`;
212
+ }
213
+ export function formatCliRouterError(result) {
214
+ switch (result.kind) {
215
+ case CLI_ROUTER_RESULT_KIND.unknownCommand:
216
+ return `${CLI_HELP_TEXT.unknownCommandPrefix} ${[
217
+ ...result.path,
218
+ result.token,
219
+ ].join(CLI_HELP_LAYOUT.commandPartSeparator)}.`;
220
+ case CLI_ROUTER_RESULT_KIND.incompleteCommand:
221
+ return `${CLI_HELP_TEXT.incompleteCommandPrefix} ${result.path.join(CLI_HELP_LAYOUT.commandPartSeparator)}.`;
222
+ case CLI_ROUTER_RESULT_KIND.invalidInput:
223
+ return `${CLI_HELP_TEXT.invalidInputLabel}: ${result.issues.join(CLI_HELP_LAYOUT.issueSeparator)}`;
224
+ case CLI_ROUTER_RESULT_KIND.invalidParameter:
225
+ return `${CLI_HELP_TEXT.invalidParameterPrefix} ${result.parameterName}: ${result.issues.join(CLI_HELP_LAYOUT.issueSeparator)}`;
226
+ }
227
+ }
228
+ export function formatCliHelpParameterDescription(input) {
229
+ const [presenceDetail, ...defaultDetails] = formatParameterRequirementDetails(input.requirement);
230
+ const details = [
231
+ presenceDetail,
232
+ ...input.additionalDetails,
233
+ ...defaultDetails,
234
+ ];
235
+ return `${input.description} (${details.join(CLI_HELP_LAYOUT.detailSeparator)})`;
236
+ }
237
+ export function renderCliHelpExamples(examples, executableName) {
238
+ return examples.flatMap((example, index) => [
239
+ ...(index === 0 ? [] : [CLI_HELP_LAYOUT.emptyLine]),
240
+ `${CLI_HELP_LAYOUT.itemIndent}${example.title}:`,
241
+ `${CLI_HELP_LAYOUT.nestedItemIndent}${CLI_HELP_TEXT.useWhenPrefix} ${example.useWhen}`,
242
+ CLI_HELP_LAYOUT.emptyLine,
243
+ `${CLI_HELP_LAYOUT.nestedItemIndent}${appendCliCommandPart(executableName, example.command)}`,
244
+ ...(example.expectedResult.length === 0
245
+ ? []
246
+ : [
247
+ CLI_HELP_LAYOUT.emptyLine,
248
+ `${CLI_HELP_LAYOUT.nestedItemIndent}${CLI_HELP_TEXT.expectedResultHeading}`,
249
+ ...example.expectedResult.map((line) => `${CLI_HELP_LAYOUT.resultIndent}${line}`),
250
+ ]),
251
+ ]);
252
+ }
253
+ function formatParameterRequirementDetails(requirement) {
254
+ switch (requirement.kind) {
255
+ case PARAMETER_REQUIREMENT_KIND.required:
256
+ return [CLI_HELP_TEXT.requiredDetail];
257
+ case PARAMETER_REQUIREMENT_KIND.optional:
258
+ return [CLI_HELP_TEXT.optionalDetail];
259
+ case PARAMETER_REQUIREMENT_KIND.optionalWithDefault:
260
+ return [
261
+ CLI_HELP_TEXT.optionalDetail,
262
+ `${CLI_HELP_TEXT.defaultDetailPrefix} ${JSON.stringify(requirement.defaultValue)}`,
263
+ ];
264
+ }
265
+ }
@@ -0,0 +1,4 @@
1
+ import type { CliEntryBinding, CliSegment } from "./cli-model.js";
2
+ export declare function isCliSegment(value: unknown): value is CliSegment;
3
+ export declare function isCliEntryBinding(value: unknown): value is CliEntryBinding;
4
+ //# sourceMappingURL=cli-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-schema.d.ts","sourceRoot":"","sources":["../src/cli-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGlE,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAEhE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,eAAe,CAE1E"}
@@ -0,0 +1,7 @@
1
+ import { isChannelPayload, PAYLOAD_KIND } from "./tree-internal.js";
2
+ export function isCliSegment(value) {
3
+ return isChannelPayload(PAYLOAD_KIND.cliSegment, value);
4
+ }
5
+ export function isCliEntryBinding(value) {
6
+ return isChannelPayload(PAYLOAD_KIND.cliBinding, value);
7
+ }
@@ -0,0 +1,4 @@
1
+ import { type CliRouter } from "./cli-model.js";
2
+ import type { EntryTreeDefinition } from "./model.js";
3
+ export declare function createCliRouter(tree: EntryTreeDefinition): CliRouter;
4
+ //# sourceMappingURL=cli-tree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-tree.d.ts","sourceRoot":"","sources":["../src/cli-tree.ts"],"names":[],"mappings":"AAaA,OAAO,EAIL,KAAK,SAAS,EAIf,MAAM,gBAAgB,CAAC;AAOxB,OAAO,KAAK,EACV,mBAAmB,EAIpB,MAAM,YAAY,CAAC;AAuDpB,wBAAgB,eAAe,CAAC,IAAI,EAAE,mBAAmB,GAAG,SAAS,CAOpE"}