@alpacakit/channels 0.1.0-beta.37 → 0.1.0-beta.39

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 (99) hide show
  1. package/README.md +204 -723
  2. package/dist/binding-compiler.d.ts +12 -2
  3. package/dist/binding-compiler.d.ts.map +1 -1
  4. package/dist/binding-compiler.js +25 -0
  5. package/dist/cli-coercion.d.ts +1 -1
  6. package/dist/cli-coercion.d.ts.map +1 -1
  7. package/dist/cli-coercion.js +14 -29
  8. package/dist/cli-compiler.d.ts +4 -17
  9. package/dist/cli-compiler.d.ts.map +1 -1
  10. package/dist/cli-compiler.js +78 -39
  11. package/dist/cli-help-projection.d.ts.map +1 -1
  12. package/dist/cli-help-projection.js +41 -36
  13. package/dist/cli-model.d.ts +50 -65
  14. package/dist/cli-model.d.ts.map +1 -1
  15. package/dist/cli-model.js +26 -34
  16. package/dist/cli-tree.d.ts +6 -3
  17. package/dist/cli-tree.d.ts.map +1 -1
  18. package/dist/cli-tree.js +161 -387
  19. package/dist/cli.d.ts +1 -5
  20. package/dist/cli.d.ts.map +1 -1
  21. package/dist/cli.js +1 -5
  22. package/dist/codecs.d.ts +20 -18
  23. package/dist/codecs.d.ts.map +1 -1
  24. package/dist/codecs.js +21 -31
  25. package/dist/contract.d.ts.map +1 -1
  26. package/dist/contract.js +8 -3
  27. package/dist/definition-error.d.ts +5 -0
  28. package/dist/definition-error.d.ts.map +1 -0
  29. package/dist/definition-error.js +8 -0
  30. package/dist/factory.d.ts +25 -11
  31. package/dist/factory.d.ts.map +1 -1
  32. package/dist/factory.js +28 -18
  33. package/dist/http-compiler.d.ts +15 -0
  34. package/dist/http-compiler.d.ts.map +1 -0
  35. package/dist/http-compiler.js +37 -0
  36. package/dist/http-model.d.ts +42 -0
  37. package/dist/http-model.d.ts.map +1 -0
  38. package/dist/http-model.js +20 -0
  39. package/dist/http-tree.d.ts +7 -0
  40. package/dist/http-tree.d.ts.map +1 -0
  41. package/dist/http-tree.js +181 -0
  42. package/dist/http.d.ts +3 -0
  43. package/dist/http.d.ts.map +1 -0
  44. package/dist/http.js +2 -0
  45. package/dist/index.d.ts +2 -1
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +1 -1
  48. package/dist/input-compiler.d.ts +13 -0
  49. package/dist/input-compiler.d.ts.map +1 -0
  50. package/dist/input-compiler.js +122 -0
  51. package/dist/introspection.d.ts +1 -1
  52. package/dist/introspection.d.ts.map +1 -1
  53. package/dist/introspection.js +30 -16
  54. package/dist/mcp.d.ts +25 -24
  55. package/dist/mcp.d.ts.map +1 -1
  56. package/dist/mcp.js +87 -65
  57. package/dist/model.d.ts +44 -42
  58. package/dist/model.d.ts.map +1 -1
  59. package/dist/model.js +44 -9
  60. package/dist/owned.d.ts +12 -0
  61. package/dist/owned.d.ts.map +1 -0
  62. package/dist/owned.js +61 -0
  63. package/dist/registration.d.ts +41 -0
  64. package/dist/registration.d.ts.map +1 -0
  65. package/dist/registration.js +14 -0
  66. package/dist/runtime.d.ts +2 -35
  67. package/dist/runtime.d.ts.map +1 -1
  68. package/dist/runtime.js +2 -127
  69. package/dist/schema.d.ts +11 -8
  70. package/dist/schema.d.ts.map +1 -1
  71. package/dist/schema.js +110 -47
  72. package/dist/string-coercion.d.ts +4 -0
  73. package/dist/string-coercion.d.ts.map +1 -0
  74. package/dist/string-coercion.js +24 -0
  75. package/dist/tree-internal.d.ts +4 -2
  76. package/dist/tree-internal.d.ts.map +1 -1
  77. package/dist/tree-internal.js +5 -2
  78. package/dist/values.d.ts +1 -6
  79. package/dist/values.d.ts.map +1 -1
  80. package/dist/values.js +1 -6
  81. package/examples/README.md +28 -0
  82. package/examples/book-search.ts +151 -0
  83. package/examples/greeting.ts +193 -0
  84. package/package.json +9 -4
  85. package/dist/cli-application.d.ts +0 -40
  86. package/dist/cli-application.d.ts.map +0 -1
  87. package/dist/cli-application.js +0 -90
  88. package/dist/cli-executor.d.ts +0 -25
  89. package/dist/cli-executor.d.ts.map +0 -1
  90. package/dist/cli-executor.js +0 -44
  91. package/dist/cli-presentation.d.ts +0 -38
  92. package/dist/cli-presentation.d.ts.map +0 -1
  93. package/dist/cli-presentation.js +0 -301
  94. package/dist/cli-result-envelope.d.ts +0 -104
  95. package/dist/cli-result-envelope.d.ts.map +0 -1
  96. package/dist/cli-result-envelope.js +0 -137
  97. package/dist/cli-schema.d.ts +0 -4
  98. package/dist/cli-schema.d.ts.map +0 -1
  99. package/dist/cli-schema.js +0 -7
@@ -1,301 +0,0 @@
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
- const TRAILING_NEWLINES_PATTERN = /\n+$/u;
44
- export function findCliHelpSurface(root, commandPath) {
45
- return findCliHelpSurfaceLocation(root, commandPath)?.surface ?? null;
46
- }
47
- export function findCliHelpSurfaceLocation(root, commandPath) {
48
- let current = root;
49
- const path = [];
50
- for (const token of commandPath) {
51
- const child = current.children.find((candidate) => candidate.token === token);
52
- if (!child) {
53
- return null;
54
- }
55
- current = child;
56
- path.push(child.token ?? child.name);
57
- }
58
- return { surface: current, path };
59
- }
60
- /**
61
- * Rendered help always ends with exactly one newline. Help is written to a
62
- * terminal, so the terminating newline belongs to the renderer: leaving it out
63
- * makes every caller append the same one, and each one of them a place to
64
- * forget it or to append two.
65
- */
66
- export function renderCliHelp(surface, context) {
67
- const body = joinCliHelpSections([
68
- createCliHelpSummarySection(surface, context.programName),
69
- createCliHelpCommandsSection(surface),
70
- createCliHelpArgumentsSection(surface),
71
- createCliHelpOptionsSection(surface),
72
- createCliHelpRemarksSection(surface),
73
- createCliHelpExamplesSection(surface, context.executableName),
74
- createCliHelpDocumentationSection(surface),
75
- createCliHelpNextStepsSection(surface, context.programName),
76
- ]);
77
- return `${body.replace(TRAILING_NEWLINES_PATTERN, "")}${CLI_HELP_LAYOUT.lineSeparator}`;
78
- }
79
- export function listCliHelpSurfaces(root) {
80
- const locations = [];
81
- const pending = [{ surface: root, path: [] }];
82
- for (const current of pending) {
83
- locations.push(current);
84
- pending.push(...current.surface.children.map((child) => ({
85
- surface: child,
86
- path: [...current.path, child.token ?? child.name],
87
- })));
88
- }
89
- return locations;
90
- }
91
- /**
92
- * Projects one immutable help tree without recreating its structural fields.
93
- * The root is always retained; `include` and `compare` are applied to children.
94
- */
95
- export function projectCliHelpSurface(root, projection) {
96
- const projected = new Map();
97
- const pending = [...listCliHelpSurfaces(root)].reverse();
98
- for (const location of pending) {
99
- const children = location.surface.children.flatMap((child) => {
100
- const childPath = [...location.path, child.token ?? child.name];
101
- const childLocation = { surface: child, path: childPath };
102
- if (!projection.include(childLocation))
103
- return [];
104
- const projectedChild = projected.get(child);
105
- return projectedChild === undefined
106
- ? []
107
- : [{ surface: projectedChild, path: childPath }];
108
- });
109
- if (projection.compare !== undefined) {
110
- children.sort(projection.compare);
111
- }
112
- projected.set(location.surface, {
113
- ...location.surface,
114
- children: children.map((child) => child.surface),
115
- });
116
- }
117
- return projected.get(root) ?? { ...root, children: [] };
118
- }
119
- function joinCliHelpSections(sections) {
120
- return sections
121
- .flatMap((section) => (section === null ? [] : [section]))
122
- .map((section) => section.join(CLI_HELP_LAYOUT.lineSeparator))
123
- .join(CLI_HELP_LAYOUT.sectionSeparator);
124
- }
125
- function createCliHelpSummarySection(surface, programName) {
126
- return [
127
- ...surface.usages.map((usage) => `${CLI_HELP_TEXT.usageHeading} ${appendCliCommandPart(programName, usage)}`),
128
- CLI_HELP_LAYOUT.emptyLine,
129
- surface.description,
130
- ];
131
- }
132
- function createCliHelpCommandsSection(surface) {
133
- if (surface.children.length === 0) {
134
- return null;
135
- }
136
- return [
137
- CLI_HELP_TEXT.commandsHeading,
138
- ...surface.children.map((child) => {
139
- const name = child.token ?? child.name;
140
- return `${CLI_HELP_LAYOUT.itemIndent}${name}${CLI_HELP_LAYOUT.columnSeparator}${child.description}`;
141
- }),
142
- ];
143
- }
144
- function createCliHelpArgumentsSection(surface) {
145
- if (surface.positionals.length === 0) {
146
- return null;
147
- }
148
- return [
149
- CLI_HELP_TEXT.argumentsHeading,
150
- ...surface.positionals.map((positional) => `${CLI_HELP_LAYOUT.itemIndent}${positional.valueName}${CLI_HELP_LAYOUT.columnSeparator}${formatCliHelpParameterDescription({
151
- description: positional.description,
152
- requirement: positional.requirement,
153
- additionalDetails: [],
154
- })}`),
155
- ];
156
- }
157
- function createCliHelpOptionsSection(surface) {
158
- if (surface.optionGroups.length === 0) {
159
- return null;
160
- }
161
- return [CLI_HELP_TEXT.optionsHeading, ...renderCliHelpOptions(surface)];
162
- }
163
- function createCliHelpRemarksSection(surface) {
164
- if (surface.remarks.length === 0) {
165
- return null;
166
- }
167
- return [
168
- CLI_HELP_TEXT.remarksHeading,
169
- ...surface.remarks.map((remark) => `${CLI_HELP_LAYOUT.itemIndent}${remark}`),
170
- ];
171
- }
172
- function createCliHelpExamplesSection(surface, programName) {
173
- if (surface.examples.length === 0) {
174
- return null;
175
- }
176
- return [
177
- CLI_HELP_TEXT.examplesHeading,
178
- ...renderCliHelpExamples(surface.examples, programName),
179
- ];
180
- }
181
- function createCliHelpDocumentationSection(surface) {
182
- if (surface.relatedDocs.length === 0) {
183
- return null;
184
- }
185
- return [
186
- CLI_HELP_TEXT.relatedDocumentationHeading,
187
- ...surface.relatedDocs.map((documentId) => `${CLI_HELP_LAYOUT.itemIndent}${documentId}`),
188
- ];
189
- }
190
- function createCliHelpNextStepsSection(surface, programName) {
191
- if (surface.children.length === 0) {
192
- return null;
193
- }
194
- return [
195
- CLI_HELP_TEXT.nextStepsHeading,
196
- `${CLI_HELP_LAYOUT.itemIndent}${surface.subcommandHint ?? formatDefaultCliSubcommandHint(programName)}`,
197
- ];
198
- }
199
- function renderCliHelpOptions(surface) {
200
- return surface.optionGroups.flatMap((group) => {
201
- const indent = group.heading === null
202
- ? CLI_HELP_LAYOUT.itemIndent
203
- : CLI_HELP_LAYOUT.nestedItemIndent;
204
- return [
205
- ...(group.heading === null
206
- ? []
207
- : [`${CLI_HELP_LAYOUT.itemIndent}${group.heading}`]),
208
- ...(group.description === null
209
- ? []
210
- : [`${CLI_HELP_LAYOUT.nestedItemIndent}${group.description}`]),
211
- ...group.options.map((option) => renderCliHelpOption(option, indent)),
212
- ];
213
- });
214
- }
215
- function renderCliHelpOption(option, indent) {
216
- const description = describeCliHelpOption(option);
217
- return `${indent}${description.names}${CLI_HELP_LAYOUT.columnSeparator}${description.description}`;
218
- }
219
- export function describeCliHelpOption(option) {
220
- switch (option.kind) {
221
- case CLI_OPTION_KIND.booleanFlag:
222
- return {
223
- names: [...option.flags, ...option.negativeFlags].join(CLI_HELP_LAYOUT.detailSeparator),
224
- description: formatCliHelpParameterDescription({
225
- description: option.description,
226
- requirement: option.requirement,
227
- additionalDetails: [],
228
- }),
229
- };
230
- case CLI_OPTION_KIND.value:
231
- return {
232
- names: `${option.flags.join(CLI_HELP_LAYOUT.detailSeparator)} <${option.valueName}>`,
233
- description: formatCliHelpParameterDescription({
234
- description: option.description,
235
- requirement: option.requirement,
236
- additionalDetails: CLI_OPTION_VALUE_MODE_DETAILS[option.valueMode],
237
- }),
238
- };
239
- }
240
- }
241
- export function appendCliCommandPart(command, part) {
242
- return part.length === 0
243
- ? command
244
- : `${command}${CLI_HELP_LAYOUT.commandPartSeparator}${part}`;
245
- }
246
- export function formatDefaultCliSubcommandHint(programName) {
247
- return `Run \`${programName} ${CLI_HELP_TEXT.commandArgument} --help\` for subcommand details.`;
248
- }
249
- export function formatCliRouterError(result) {
250
- switch (result.kind) {
251
- case CLI_ROUTER_RESULT_KIND.unknownCommand:
252
- return `${CLI_HELP_TEXT.unknownCommandPrefix} ${[
253
- ...result.path,
254
- result.token,
255
- ].join(CLI_HELP_LAYOUT.commandPartSeparator)}.`;
256
- case CLI_ROUTER_RESULT_KIND.incompleteCommand:
257
- return `${CLI_HELP_TEXT.incompleteCommandPrefix} ${result.path.join(CLI_HELP_LAYOUT.commandPartSeparator)}.`;
258
- case CLI_ROUTER_RESULT_KIND.invalidInput:
259
- return `${CLI_HELP_TEXT.invalidInputLabel}: ${result.issues.join(CLI_HELP_LAYOUT.issueSeparator)}`;
260
- case CLI_ROUTER_RESULT_KIND.invalidParameter:
261
- return `${CLI_HELP_TEXT.invalidParameterPrefix} ${result.parameterName}: ${result.issues.join(CLI_HELP_LAYOUT.issueSeparator)}`;
262
- }
263
- }
264
- export function formatCliHelpParameterDescription(input) {
265
- const [presenceDetail, ...defaultDetails] = formatParameterRequirementDetails(input.requirement);
266
- const details = [
267
- presenceDetail,
268
- ...input.additionalDetails,
269
- ...defaultDetails,
270
- ];
271
- return `${input.description} (${details.join(CLI_HELP_LAYOUT.detailSeparator)})`;
272
- }
273
- export function renderCliHelpExamples(examples, executableName) {
274
- return examples.flatMap((example, index) => [
275
- ...(index === 0 ? [] : [CLI_HELP_LAYOUT.emptyLine]),
276
- `${CLI_HELP_LAYOUT.itemIndent}${example.title}:`,
277
- `${CLI_HELP_LAYOUT.nestedItemIndent}${CLI_HELP_TEXT.useWhenPrefix} ${example.useWhen}`,
278
- CLI_HELP_LAYOUT.emptyLine,
279
- `${CLI_HELP_LAYOUT.nestedItemIndent}${appendCliCommandPart(executableName, example.command)}`,
280
- ...(example.expectedResult.length === 0
281
- ? []
282
- : [
283
- CLI_HELP_LAYOUT.emptyLine,
284
- `${CLI_HELP_LAYOUT.nestedItemIndent}${CLI_HELP_TEXT.expectedResultHeading}`,
285
- ...example.expectedResult.map((line) => `${CLI_HELP_LAYOUT.resultIndent}${line}`),
286
- ]),
287
- ]);
288
- }
289
- function formatParameterRequirementDetails(requirement) {
290
- switch (requirement.kind) {
291
- case PARAMETER_REQUIREMENT_KIND.required:
292
- return [CLI_HELP_TEXT.requiredDetail];
293
- case PARAMETER_REQUIREMENT_KIND.optional:
294
- return [CLI_HELP_TEXT.optionalDetail];
295
- case PARAMETER_REQUIREMENT_KIND.optionalWithDefault:
296
- return [
297
- CLI_HELP_TEXT.optionalDetail,
298
- `${CLI_HELP_TEXT.defaultDetailPrefix} ${JSON.stringify(requirement.defaultValue)}`,
299
- ];
300
- }
301
- }
@@ -1,104 +0,0 @@
1
- import { type JsonValue } from "@alpacakit/core";
2
- import { z } from "zod";
3
- export declare const CLI_RESULT_STATUS: {
4
- readonly completed: "completed";
5
- readonly rejected: "rejected";
6
- readonly partial: "partial";
7
- };
8
- export declare const CLI_RESULT_CODE: {
9
- readonly ok: "ok";
10
- };
11
- /**
12
- * Process exit classes for commands that produced a typed result. Unexpected
13
- * process faults sit outside this contract and are projected by the host.
14
- */
15
- export declare const CLI_COMMAND_EXIT_CODE: {
16
- readonly success: 0;
17
- readonly rejected: 1;
18
- readonly syntax: 2;
19
- };
20
- export declare const CLI_OUTPUT_FORMAT: {
21
- readonly text: "text";
22
- readonly json: "json";
23
- };
24
- export type CliOutputFormat = (typeof CLI_OUTPUT_FORMAT)[keyof typeof CLI_OUTPUT_FORMAT];
25
- export type CliResultStatus = (typeof CLI_RESULT_STATUS)[keyof typeof CLI_RESULT_STATUS];
26
- export type CliCommandExitCode = (typeof CLI_COMMAND_EXIT_CODE)[keyof typeof CLI_COMMAND_EXIT_CODE];
27
- export type CliDataVersion = `${string}/v${number}`;
28
- export type CliNextAction = {
29
- readonly label: string;
30
- readonly command: string;
31
- };
32
- export type CliResultEnvelope<Data extends JsonValue = JsonValue> = {
33
- readonly envelopeVersion: 1;
34
- readonly dataVersion: CliDataVersion;
35
- readonly command: string;
36
- readonly status: CliResultStatus;
37
- readonly code: string;
38
- readonly data: Data;
39
- readonly nextActions: readonly CliNextAction[];
40
- };
41
- /** One typed command result from which text and the JSON envelope are projected. */
42
- export type CliResultProjection<Data extends JsonValue = JsonValue> = {
43
- readonly status: CliResultStatus;
44
- readonly code: string;
45
- readonly data: Data;
46
- readonly nextActions: readonly CliNextAction[];
47
- readonly text: string;
48
- };
49
- /** A command's typed result paired with its process exit classification. */
50
- export type CliCommandExecutionResult<Data extends JsonValue = JsonValue> = {
51
- readonly exitCode: CliCommandExitCode;
52
- readonly result: CliResultProjection<Data>;
53
- };
54
- export declare const cliCommandExecutionResultSchema: z.ZodReadonly<z.ZodObject<{
55
- exitCode: z.ZodEnum<{
56
- readonly success: 0;
57
- readonly rejected: 1;
58
- readonly syntax: 2;
59
- }>;
60
- result: z.ZodReadonly<z.ZodObject<{
61
- status: z.ZodEnum<{
62
- completed: "completed";
63
- rejected: "rejected";
64
- partial: "partial";
65
- }>;
66
- code: z.ZodString;
67
- data: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
68
- nextActions: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
69
- label: z.ZodString;
70
- command: z.ZodString;
71
- }, z.core.$strict>>>>;
72
- text: z.ZodString;
73
- }, z.core.$strict>>;
74
- }, z.core.$strict>>;
75
- export declare function createCliResultEnvelope<Data extends JsonValue>(input: {
76
- readonly dataVersion: CliDataVersion;
77
- readonly command: string;
78
- readonly status: CliResultStatus;
79
- readonly code: string;
80
- readonly data: Data;
81
- readonly nextActions?: readonly CliNextAction[];
82
- }): CliResultEnvelope<Data>;
83
- export declare function createCliResultProjection<Data extends JsonValue>(input: {
84
- readonly status: CliResultStatus;
85
- readonly code: string;
86
- readonly data: Data;
87
- readonly nextActions?: readonly CliNextAction[];
88
- readonly text: string;
89
- }): CliResultProjection<Data>;
90
- export declare function createCliCommandExecutionResult<Data extends JsonValue>(input: {
91
- readonly exitCode: CliCommandExitCode;
92
- readonly status: CliResultStatus;
93
- readonly code: string;
94
- readonly data: Data;
95
- readonly nextActions?: readonly CliNextAction[];
96
- readonly text: string;
97
- }): CliCommandExecutionResult<Data>;
98
- export declare function projectCliResultEnvelope<Data extends JsonValue>(input: {
99
- readonly dataVersion: CliDataVersion;
100
- readonly command: string;
101
- readonly result: CliResultProjection<Data>;
102
- }): CliResultEnvelope<Data>;
103
- export declare function verifyCliResultEnvelope(input: unknown): CliResultEnvelope;
104
- //# sourceMappingURL=cli-result-envelope.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli-result-envelope.d.ts","sourceRoot":"","sources":["../src/cli-result-envelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAmB,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,iBAAiB;;;;CAIpB,CAAC;AAEX,eAAO,MAAM,eAAe;;CAElB,CAAC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,eAAe,CAAC;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;IAChD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,GAAG,yBAAyB,CAAC,IAAI,CAAC,CAalC;AAED,wBAAgB,wBAAwB,CAAC,IAAI,SAAS,SAAS,EAAE,KAAK,EAAE;IACtE,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;CAC5C,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAS1B;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,iBAAiB,CAEzE"}
@@ -1,137 +0,0 @@
1
- import { jsonValueSchema } from "@alpacakit/core";
2
- import { z } from "zod";
3
- export const CLI_RESULT_STATUS = {
4
- completed: "completed",
5
- rejected: "rejected",
6
- partial: "partial",
7
- };
8
- export const CLI_RESULT_CODE = {
9
- ok: "ok",
10
- };
11
- /**
12
- * Process exit classes for commands that produced a typed result. Unexpected
13
- * process faults sit outside this contract and are projected by the host.
14
- */
15
- export const CLI_COMMAND_EXIT_CODE = {
16
- success: 0,
17
- rejected: 1,
18
- syntax: 2,
19
- };
20
- export const CLI_OUTPUT_FORMAT = {
21
- text: "text",
22
- json: "json",
23
- };
24
- const cliNextActionSchema = z
25
- .object({ label: z.string(), command: z.string() })
26
- .strict()
27
- .readonly();
28
- const cliResultProjectionSchema = z
29
- .object({
30
- status: z.enum(Object.values(CLI_RESULT_STATUS)),
31
- code: z.string().min(1),
32
- data: jsonValueSchema,
33
- nextActions: z.array(cliNextActionSchema).readonly(),
34
- text: z.string(),
35
- })
36
- .strict()
37
- .readonly();
38
- export const cliCommandExecutionResultSchema = z
39
- .object({
40
- exitCode: z.enum(CLI_COMMAND_EXIT_CODE),
41
- result: cliResultProjectionSchema,
42
- })
43
- .strict()
44
- .superRefine((execution, context) => {
45
- const expectedExitCode = execution.result.status === CLI_RESULT_STATUS.completed
46
- ? CLI_COMMAND_EXIT_CODE.success
47
- : CLI_COMMAND_EXIT_CODE.rejected;
48
- const valid = execution.result.status === CLI_RESULT_STATUS.rejected
49
- ? execution.exitCode === CLI_COMMAND_EXIT_CODE.rejected ||
50
- execution.exitCode === CLI_COMMAND_EXIT_CODE.syntax
51
- : execution.exitCode === expectedExitCode;
52
- if (!valid) {
53
- context.addIssue({
54
- code: "custom",
55
- message: "Completed results require exit 0, partial results require exit 1, and rejected results require exit 1 or 2.",
56
- });
57
- }
58
- })
59
- .readonly();
60
- const cliResultEnvelopeSchema = z
61
- .object({
62
- envelopeVersion: z.literal(1),
63
- dataVersion: z.string().regex(/^[a-z0-9-]+\/v[1-9][0-9]*$/u),
64
- command: z.string(),
65
- status: z.enum(Object.values(CLI_RESULT_STATUS)),
66
- code: z.string().min(1),
67
- data: jsonValueSchema,
68
- nextActions: z.array(cliNextActionSchema).readonly(),
69
- })
70
- .strict()
71
- .superRefine((document, context) => {
72
- const completed = document.status === CLI_RESULT_STATUS.completed;
73
- if (completed !== (document.code === CLI_RESULT_CODE.ok)) {
74
- context.addIssue({
75
- code: "custom",
76
- message: "Completed results require code=ok and failures forbid it.",
77
- });
78
- }
79
- })
80
- .readonly();
81
- export function createCliResultEnvelope(input) {
82
- return verifyCliResultEnvelope({
83
- envelopeVersion: 1,
84
- dataVersion: input.dataVersion,
85
- command: input.command,
86
- status: input.status,
87
- code: input.code,
88
- data: input.data,
89
- nextActions: input.nextActions ?? [],
90
- });
91
- }
92
- export function createCliResultProjection(input) {
93
- const verified = createCliResultEnvelope({
94
- dataVersion: "projection/v1",
95
- command: "projection",
96
- status: input.status,
97
- code: input.code,
98
- data: input.data,
99
- ...(input.nextActions === undefined
100
- ? {}
101
- : { nextActions: input.nextActions }),
102
- });
103
- return Object.freeze({
104
- status: verified.status,
105
- code: verified.code,
106
- data: verified.data,
107
- nextActions: verified.nextActions,
108
- text: input.text,
109
- });
110
- }
111
- export function createCliCommandExecutionResult(input) {
112
- return cliCommandExecutionResultSchema.parse({
113
- exitCode: input.exitCode,
114
- result: createCliResultProjection({
115
- status: input.status,
116
- code: input.code,
117
- data: input.data,
118
- ...(input.nextActions === undefined
119
- ? {}
120
- : { nextActions: input.nextActions }),
121
- text: input.text,
122
- }),
123
- });
124
- }
125
- export function projectCliResultEnvelope(input) {
126
- return createCliResultEnvelope({
127
- dataVersion: input.dataVersion,
128
- command: input.command,
129
- status: input.result.status,
130
- code: input.result.code,
131
- data: input.result.data,
132
- nextActions: input.result.nextActions,
133
- });
134
- }
135
- export function verifyCliResultEnvelope(input) {
136
- return cliResultEnvelopeSchema.parse(input);
137
- }
@@ -1,4 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,7 +0,0 @@
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
- }