hacksh 0.12.0 → 0.14.0

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/index.d.ts CHANGED
@@ -1,394 +1,5 @@
1
- import { $ZodIssue, $ZodObject, output } from "zod/v4/core";
2
- //#region src/errors.d.ts
3
- interface HackshIssue {
4
- arg: string;
5
- message: string;
6
- issue?: $ZodIssue;
7
- }
8
- declare class HackshUsageError extends Error {
9
- readonly command: AnyCommandDef;
10
- constructor(message: string, command: AnyCommandDef, options?: ErrorOptions);
11
- }
12
- declare class HackshValidationError extends HackshUsageError {
13
- readonly issues: ReadonlyArray<HackshIssue>;
14
- constructor(command: AnyCommandDef, issues: ReadonlyArray<HackshIssue>);
15
- }
16
- type PromptKind = "select" | "confirm" | "text";
17
- type HackshPromptErrorReason = "non-interactive" | "cancelled" | "aborted" | "eof" | "overlapping" | "invalid-options" | "input-error" | "printer-error";
18
- interface PromptErrorDetails {
19
- kind: PromptKind;
20
- message: string;
21
- choices?: readonly string[];
22
- }
23
- /** An input request that could not be completed safely. */
24
- declare class HackshPromptError extends Error {
25
- readonly reason: HackshPromptErrorReason;
26
- readonly prompt: PromptErrorDetails;
27
- constructor(reason: HackshPromptErrorReason, prompt: PromptErrorDetails, message: string, options?: ErrorOptions);
28
- }
29
- /** An external command that did not succeed; `result` is not enumerable so error summaries omit child output. */
30
- declare class HackshExecError extends Error {
31
- #private;
32
- constructor(message: string, result: ExecFailure, options?: ErrorOptions);
33
- get result(): ExecFailure;
34
- }
35
- /** A requested process exit status; `runMain` exits with it and reports only a non-empty message. */
36
- declare class HackshExitError extends Error {
37
- readonly exitCode: number;
38
- constructor(exitCode: number, message?: string, options?: ErrorOptions);
39
- }
40
- type HackshErrorKind = "error" | "prompt" | "usage" | "validation" | "thrown";
41
- interface ValidationIssueSummary {
42
- arg: string;
43
- message: string;
44
- code?: string;
45
- path?: readonly PropertyKey[];
46
- details?: Readonly<Record<string, unknown>>;
47
- }
48
- interface HackshErrorSummary {
49
- kind: HackshErrorKind;
50
- name: string;
51
- message: string;
52
- stack?: string;
53
- cause?: unknown;
54
- issues?: readonly ValidationIssueSummary[];
55
- properties?: Readonly<Record<string, unknown>>;
56
- value?: unknown;
57
- }
58
- //#endregion
59
- //#region src/prompts.d.ts
60
- interface SelectOption<T extends string> {
61
- value: T;
62
- label?: string;
63
- hint?: string;
64
- }
65
- interface SelectOptions<T extends string> {
66
- message: string;
67
- options: readonly SelectOption<T>[];
68
- initialValue?: T;
69
- }
70
- interface ConfirmOptions {
71
- message: string;
72
- initialValue?: boolean;
73
- }
74
- interface TextOptions {
75
- message: string;
76
- placeholder?: string;
77
- validate?(value: string): string | undefined;
78
- }
79
- interface Prompter {
80
- select<const T extends string>(options: SelectOptions<T>): Promise<T>;
81
- confirm(options: ConfirmOptions): Promise<boolean>;
82
- text(options: TextOptions): Promise<string>;
83
- }
84
- //#endregion
85
- //#region src/logger.d.ts
86
- type LogLevel = "trace" | "debug" | "info" | "warning" | "error" | "fatal";
87
- type LogKind = "message" | "step" | "success";
88
- type LogProperties = Record<string, unknown>;
89
- /** A structured message emitted by a command's logger. */
90
- interface LogRecord {
91
- level: LogLevel;
92
- kind: LogKind;
93
- category: readonly string[];
94
- message: string;
95
- rawMessage: string;
96
- properties: LogProperties;
97
- timestamp: number;
98
- }
99
- interface Logger extends Prompter {
100
- readonly category: readonly string[];
101
- trace(message: string, properties?: LogProperties): void;
102
- debug(message: string, properties?: LogProperties): void;
103
- info(message: string, properties?: LogProperties): void;
104
- warn(message: string, properties?: LogProperties): void;
105
- error(message: string | Error, properties?: LogProperties): void;
106
- fatal(message: string | Error, properties?: LogProperties): void;
107
- step(message: string, properties?: LogProperties): void;
108
- success(message: string, properties?: LogProperties): void;
109
- with(properties: LogProperties): Logger;
110
- getChild(category: string): Logger;
111
- }
112
- //#endregion
113
- //#region src/output.d.ts
114
- interface OutputOptions {
115
- output?: OutputPreference;
116
- /** Use Unicode presentation symbols in pretty output. Defaults to true. */
117
- unicode?: boolean;
118
- env?: Readonly<Record<string, string | undefined>>;
119
- stdin?: TerminalInput;
120
- stdout?: TerminalOutput;
121
- stderr?: OutputWriter;
122
- }
123
- //#endregion
124
- //#region src/usage.d.ts
125
- interface UsageArgumentSummary {
126
- name: string;
127
- required: boolean;
128
- variadic: boolean;
129
- description?: string;
130
- choices?: readonly string[];
131
- defaultValue?: unknown;
132
- }
133
- interface UsageOptionSummary {
134
- name: string;
135
- flags: readonly string[];
136
- takesValue: boolean;
137
- /** Whether the long flag also accepts a `--no-` prefixed form. */
138
- negatable: boolean;
139
- valueName?: string;
140
- required: boolean;
141
- description?: string;
142
- choices?: readonly string[];
143
- defaultValue?: unknown;
144
- env?: string;
145
- }
146
- interface UsageCommandSummary {
147
- name: string;
148
- description?: string;
149
- }
150
- /** A schema-free description of the useful help metadata for a command. */
151
- interface UsageSummary {
152
- name: string;
153
- heading?: string;
154
- version?: string;
155
- description?: string;
156
- synopsis: string;
157
- arguments: readonly UsageArgumentSummary[];
158
- options: readonly UsageOptionSummary[];
159
- commands: readonly UsageCommandSummary[];
160
- }
161
- /** Build a serializable help summary without retaining command or schema objects. */
162
- declare function summarizeUsage(command: AnyCommandDef): UsageSummary;
163
- type UsageWriter = (text: string) => void | Promise<void>;
164
- interface ShowUsageOptions extends OutputOptions {
165
- write?: UsageWriter;
166
- printer?: Printer;
167
- stream?: PrintStream;
168
- }
169
- type UsageOutput = Required<Pick<ShowUsageOptions, "write">>;
170
- type ShowUsageCallback = (command: AnyCommandDef, output: UsageOutput) => void | Promise<void>;
171
- /** Generate usage text without writing to stdout or stderr. */
172
- declare function renderUsage(command: AnyCommandDef): Promise<string>;
173
- /** Generate and write usage text, awaiting asynchronous writers. */
174
- declare function showUsage(command: AnyCommandDef, options?: ShowUsageOptions): Promise<void>;
175
- //#endregion
176
- //#region src/printer.d.ts
177
- type PrintStream = "stdout" | "stderr";
178
- type OutputPreference = "auto" | "pretty" | "json";
179
- type OutputFormat = Exclude<OutputPreference, "auto">;
180
- interface OutputMode {
181
- format: OutputFormat;
182
- interactive: boolean;
183
- color: boolean;
184
- }
185
- interface ResolveOutputModeOptions {
186
- output?: OutputPreference;
187
- env?: Readonly<Record<string, string | undefined>>;
188
- inputIsTTY?: boolean;
189
- outputIsTTY?: boolean;
190
- }
191
- /** Resolve output behavior once, before command routing or argument parsing. */
192
- declare function resolveOutputMode(options?: ResolveOutputModeOptions): OutputMode;
193
- interface UsagePrintEvent {
194
- type: "usage";
195
- usage: UsageSummary;
196
- text: string;
197
- stream: PrintStream;
198
- }
199
- interface VersionPrintEvent {
200
- type: "version";
201
- version: string;
202
- }
203
- interface ErrorPrintEvent {
204
- type: "error";
205
- error: HackshErrorSummary;
206
- }
207
- interface LogPrintEvent {
208
- type: "log";
209
- record: LogRecord;
210
- }
211
- interface PromptChoiceState {
212
- value: string;
213
- label: string;
214
- hint?: string;
215
- selected: boolean;
216
- }
217
- type PromptStatus = "active" | "error" | "submitted" | "closed";
218
- interface PromptStateBase {
219
- message: string;
220
- status: PromptStatus;
221
- error?: string;
222
- }
223
- interface SelectPromptState extends PromptStateBase {
224
- kind: "select";
225
- choices: readonly PromptChoiceState[];
226
- value: string;
227
- }
228
- interface ConfirmPromptState extends PromptStateBase {
229
- kind: "confirm";
230
- value: boolean;
231
- defaultValue?: boolean;
232
- }
233
- interface TextPromptState extends PromptStateBase {
234
- kind: "text";
235
- value: string;
236
- placeholder?: string;
237
- }
238
- type PromptState = SelectPromptState | ConfirmPromptState | TextPromptState;
239
- interface PromptPrintEvent {
240
- type: "prompt";
241
- prompt: PromptState;
242
- }
243
- interface ExecPrintEvent {
244
- type: "exec";
245
- phase: "start";
246
- command: Omit<ExecCommand, "cwd"> & {
247
- cwd?: string;
248
- };
249
- stdio: {
250
- stdin: "ignore" | "input" | "inherit";
251
- stdout: "pipe" | "inherit";
252
- stderr: "pipe" | "inherit";
253
- };
254
- interactive: boolean;
255
- }
256
- /** A semantic, command- and schema-free output value emitted by hacksh. */
257
- type PrintEvent = UsagePrintEvent | VersionPrintEvent | ErrorPrintEvent | LogPrintEvent | PromptPrintEvent | ExecPrintEvent;
258
- /** Receives every output event produced by one command invocation. */
259
- interface Printer {
260
- print(event: PrintEvent): void | Promise<void>;
261
- }
262
- /** Undecorated console compatibility adapter; automatic output uses the selected format printer. */
263
- declare const consolePrinter: Printer;
264
- interface OutputWriter {
265
- write(text: string): unknown;
266
- }
267
- interface TerminalInput {
268
- readonly isTTY?: boolean;
269
- readonly isRaw?: boolean;
270
- readonly readableFlowing?: boolean | null;
271
- setRawMode?(mode: boolean): unknown;
272
- resume(): unknown;
273
- pause(): unknown;
274
- on(event: string, listener: (...args: never[]) => void): unknown;
275
- removeListener(event: string, listener: (...args: never[]) => void): unknown;
276
- }
277
- interface TerminalOutput extends OutputWriter {
278
- readonly isTTY?: boolean;
279
- readonly columns?: number;
280
- }
281
- interface JsonPrinterOptions {
282
- stdout?: OutputWriter;
283
- stderr?: OutputWriter;
284
- }
285
- interface StreamPrinterOptions {
286
- stdout: OutputWriter;
287
- stderr: OutputWriter;
288
- }
289
- /** Create an undecorated stream-backed compatibility adapter. */
290
- declare function createStreamPrinter(options: StreamPrinterOptions): Printer;
291
- /** Create a one-semantic-event-per-line JSON printer. */
292
- declare function createJsonPrinter(options?: JsonPrinterOptions): Printer;
293
- //#endregion
294
- //#region src/exec.d.ts
295
- type Environment = Readonly<Record<string, string | undefined>>;
296
- interface ExecOptions {
297
- cwd?: string;
298
- env?: Environment;
299
- input?: string;
300
- reject?: boolean;
301
- timeout?: number;
302
- signal?: AbortSignal;
303
- maxBuffer?: number;
304
- forceKillAfterDelay?: number;
305
- stdin?: "pipe" | "inherit";
306
- stdout?: "pipe" | "inherit";
307
- stderr?: "pipe" | "inherit";
308
- interactive?: boolean;
309
- display?: boolean;
310
- redact?: readonly string[];
311
- }
312
- interface ExecCommand {
313
- file: string;
314
- args: readonly string[];
315
- cwd: string | undefined;
316
- }
317
- interface ExecSuccess {
318
- status: "succeeded";
319
- command: ExecCommand;
320
- stdout: string;
321
- stderr: string;
322
- exitCode: 0;
323
- }
324
- type ExecFailure = {
325
- status: "failed";
326
- command: ExecCommand;
327
- stdout: string;
328
- stderr: string;
329
- } & ({
330
- reason: "exit-code";
331
- exitCode: number;
332
- } | {
333
- reason: "signal";
334
- signal: string;
335
- } | {
336
- reason: "spawn";
337
- error: Error;
338
- } | {
339
- reason: "timeout" | "aborted" | "output-limit";
340
- } | {
341
- reason: "json-output" | "non-interactive" | "overlapping";
342
- });
343
- type ExecFailureReason = ExecFailure["reason"];
344
- type ExecResult = ExecSuccess | ExecFailure;
345
- type ExecReturn<O extends ExecOptions> = "reject" extends keyof O ? false extends O["reject"] ? ExecResult : ExecSuccess : ExecSuccess;
346
- type RejectInheritedInput<O> = O extends {
347
- input: string;
348
- stdin: "inherit";
349
- } ? never : unknown;
350
- type Exec = <const O extends ExecOptions = {}>(file: string, args?: readonly string[], options?: O & { [K in Exclude<keyof O, keyof ExecOptions>]: never; } & RejectInheritedInput<O>) => Promise<ExecReturn<O>>;
351
- //#endregion
352
- //#region src/schema.d.ts
353
- type ArgsSchema = $ZodObject;
354
- type EmptyArgs = $ZodObject<{}>;
355
- type ShapeOf<S extends ArgsSchema> = S["_zod"]["def"]["shape"];
356
- type ArgKey<S extends ArgsSchema> = Extract<keyof ShapeOf<S>, string>;
357
- type OptionKey<S extends ArgsSchema> = Exclude<ArgKey<S>, typeof POSITIONALS_KEY>;
358
- declare const POSITIONALS_KEY = "_";
359
- //#endregion
360
- //#region src/command.d.ts
361
- interface ArgOptions {
362
- alias?: string | readonly string[];
363
- valueName?: string;
364
- env?: string | false;
365
- }
366
- type ArgOptionsMap<S extends ArgsSchema> = Partial<Record<OptionKey<S>, ArgOptions>>;
367
- interface CommandContext<S extends ArgsSchema> {
368
- cmd: CommandDef<S>;
369
- args: output<S>;
370
- rawArgs: string[];
371
- passthrough: string[];
372
- extraArgs: string[];
373
- logger: Logger;
374
- exec: Exec;
375
- signal: AbortSignal;
376
- }
377
- interface CommandDef<S extends ArgsSchema = EmptyArgs> {
378
- name?: string;
379
- version?: string;
380
- description?: string;
381
- hidden?: boolean;
382
- /** Keep unknown options and excess positionals in extraArgs. Inherits from the parent; defaults to false. */
383
- allowUnknownArgs?: boolean;
384
- args?: S;
385
- argOptions?: ArgOptionsMap<S>;
386
- subCommands?: Record<string, CommandDef<ArgsSchema>>;
387
- run?(context: CommandContext<S>): unknown;
388
- }
389
- type AnyCommandDef = CommandDef<ArgsSchema>;
390
- declare function defineCommand<S extends ArgsSchema = EmptyArgs>(def: CommandDef<S>): CommandDef<S>;
391
- //#endregion
1
+ import { D as OutputPreference, G as ShowUsageOptions, O as OutputWriter, Q as summarizeUsage, R as TerminalInput, X as renderUsage, Z as showUsage, _ as ExecReturn, a as ArgsSchema, c as SelectOption, ct as HackshIssue, d as Exec, dt as HackshUsageError, f as ExecCommand, ft as HackshValidationError, g as ExecResult, h as ExecOptions, i as defineCommand, j as Printer, l as SelectOptions, lt as HackshPromptError, m as ExecFailureReason, mt as PromptKind, n as CommandContext, o as ConfirmOptions, ot as HackshExecError, p as ExecFailure, pt as PromptErrorDetails, r as CommandDef, rt as Logger, s as Prompter, st as HackshExitError, t as AnyCommandDef, u as TextOptions, ut as HackshPromptErrorReason, v as ExecSkipped, y as ExecSuccess, z as TerminalOutput } from "./command-CfWrbHLN.js";
2
+ import { output } from "zod/v4/core";
392
3
  //#region src/parser.d.ts
393
4
  /**
394
5
  * Parse and validate one command segment without routing, builtin handling, or output.
@@ -398,31 +9,35 @@ declare function parseArgs<S extends ArgsSchema>(command: CommandDef<S>, argv: s
398
9
  readonly env?: Readonly<Record<string, string | undefined>>;
399
10
  }): Promise<output<S>>;
400
11
  //#endregion
401
- //#region src/pretty.d.ts
402
- interface PrettyPrinterOptions {
403
- color: boolean;
404
- unicode: boolean;
12
+ //#region src/output.d.ts
13
+ interface OutputOptions {
14
+ output?: OutputPreference;
15
+ /** Use Unicode presentation symbols in pretty output. Defaults to true. */
16
+ unicode?: boolean;
17
+ env?: Readonly<Record<string, string | undefined>>;
18
+ stdin?: TerminalInput;
405
19
  stdout?: TerminalOutput;
406
20
  stderr?: OutputWriter;
407
21
  }
408
- /** Create the fixed human-readable renderer used for pretty output. */
409
- declare function createPrettyPrinter(options: PrettyPrinterOptions): Printer;
410
22
  //#endregion
411
23
  //#region src/run.d.ts
412
24
  interface RunCommandOptions extends OutputOptions {
413
25
  printer?: Printer;
414
26
  signal?: AbortSignal;
415
- showUsage?: ShowUsageCallback;
416
27
  }
417
- declare function runCommand<S extends ArgsSchema>(root: CommandDef<S>, argv: string[], options?: RunCommandOptions): Promise<unknown>;
28
+ type HandlerResult<C> = C extends {
29
+ run?: infer Handler;
30
+ } ? Handler extends ((...args: never[]) => infer R) ? Awaited<R> : never : never;
31
+ type CommandResult<C> = HandlerResult<C> | (C extends {
32
+ subCommands?: infer Children;
33
+ } ? Children extends Record<string, AnyCommandDef> ? string extends keyof Children ? unknown : CommandResult<Children[keyof Children]> : never : never);
34
+ declare function runCommand<C extends AnyCommandDef>(root: C, argv: string[], options?: RunCommandOptions): Promise<CommandResult<C> | undefined>;
418
35
  interface RunMainOptions extends OutputOptions {
419
36
  onError?: (error: unknown) => void | Promise<void>;
420
37
  argv?: string[];
421
38
  printer?: Printer;
422
- showUsage?: ShowUsageCallback;
423
39
  }
424
40
  declare function runMain<S extends ArgsSchema>(command: CommandDef<S>, options?: RunMainOptions): Promise<void>;
425
- declare function createMain<S extends ArgsSchema>(command: CommandDef<S>, options?: RunMainOptions): (argv?: string[]) => Promise<void>;
426
41
  //#endregion
427
- export { type ArgOptions, type ArgOptionsMap, type CommandContext, type CommandDef, type ConfirmOptions, type ConfirmPromptState, type ErrorPrintEvent, type Exec, type ExecCommand, type ExecFailure, type ExecFailureReason, type ExecOptions, type ExecPrintEvent, type ExecResult, type ExecReturn, type ExecSuccess, type HackshErrorKind, type HackshErrorSummary, HackshExecError, HackshExitError, type HackshIssue, HackshPromptError, type HackshPromptErrorReason, HackshUsageError, HackshValidationError, type JsonPrinterOptions, type LogKind, type LogLevel, type LogPrintEvent, type LogProperties, type LogRecord, type Logger, type OutputFormat, type OutputMode, type OutputOptions, type OutputPreference, type OutputWriter, type PrettyPrinterOptions, type PrintEvent, type PrintStream, type Printer, type PromptChoiceState, type PromptErrorDetails, type PromptKind, type PromptPrintEvent, type PromptState, type PromptStatus, type Prompter, type ResolveOutputModeOptions, type RunCommandOptions, type RunMainOptions, type SelectOption, type SelectOptions, type SelectPromptState, type ShowUsageCallback, type ShowUsageOptions, type StreamPrinterOptions, type TerminalInput, type TerminalOutput, type TextOptions, type TextPromptState, type UsageArgumentSummary, type UsageCommandSummary, type UsageOptionSummary, type UsageOutput, type UsagePrintEvent, type UsageSummary, type UsageWriter, type ValidationIssueSummary, type VersionPrintEvent, consolePrinter, createJsonPrinter, createMain, createPrettyPrinter, createStreamPrinter, defineCommand, parseArgs, renderUsage, resolveOutputMode, runCommand, runMain, showUsage, summarizeUsage };
42
+ export { type CommandContext, type CommandDef, type ConfirmOptions, type Exec, type ExecCommand, type ExecFailure, type ExecFailureReason, type ExecOptions, type ExecResult, type ExecReturn, type ExecSkipped, type ExecSuccess, HackshExecError, HackshExitError, type HackshIssue, HackshPromptError, type HackshPromptErrorReason, HackshUsageError, HackshValidationError, type Logger, type OutputOptions, type PromptErrorDetails, type PromptKind, type Prompter, type RunCommandOptions, type RunMainOptions, type SelectOption, type SelectOptions, type ShowUsageOptions, type TextOptions, defineCommand, parseArgs, renderUsage, runCommand, runMain, showUsage, summarizeUsage };
428
43
  //# sourceMappingURL=index.d.ts.map