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/README.md +123 -92
- package/dist/command-CfWrbHLN.d.ts +378 -0
- package/dist/index.d.ts +17 -402
- package/dist/index.js +139 -1146
- package/dist/index.js.map +1 -1
- package/dist/pretty-BFub611x.js +1012 -0
- package/dist/pretty-BFub611x.js.map +1 -0
- package/dist/printer-api.d.ts +13 -0
- package/dist/printer-api.js +2 -0
- package/package.json +5 -1
|
@@ -0,0 +1,378 @@
|
|
|
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/logger.d.ts
|
|
60
|
+
type LogLevel = "trace" | "debug" | "info" | "warning" | "error" | "fatal";
|
|
61
|
+
type LogKind = "message" | "step" | "success";
|
|
62
|
+
type LogProperties = Record<string, unknown>;
|
|
63
|
+
/** A structured message emitted by a command's logger. */
|
|
64
|
+
interface LogRecord {
|
|
65
|
+
level: LogLevel;
|
|
66
|
+
kind: LogKind;
|
|
67
|
+
category: readonly string[];
|
|
68
|
+
message: string;
|
|
69
|
+
rawMessage: string;
|
|
70
|
+
properties: LogProperties;
|
|
71
|
+
timestamp: number;
|
|
72
|
+
}
|
|
73
|
+
interface Logger {
|
|
74
|
+
readonly category: readonly string[];
|
|
75
|
+
trace(message: string, properties?: LogProperties): void;
|
|
76
|
+
debug(message: string, properties?: LogProperties): void;
|
|
77
|
+
info(message: string, properties?: LogProperties): void;
|
|
78
|
+
warn(message: string, properties?: LogProperties): void;
|
|
79
|
+
error(message: string | Error, properties?: LogProperties): void;
|
|
80
|
+
fatal(message: string | Error, properties?: LogProperties): void;
|
|
81
|
+
step(message: string, properties?: LogProperties): void;
|
|
82
|
+
success(message: string, properties?: LogProperties): void;
|
|
83
|
+
with(properties: LogProperties): Logger;
|
|
84
|
+
getChild(category: string): Logger;
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/usage.d.ts
|
|
88
|
+
interface UsageArgumentSummary {
|
|
89
|
+
name: string;
|
|
90
|
+
required: boolean;
|
|
91
|
+
variadic: boolean;
|
|
92
|
+
description?: string;
|
|
93
|
+
choices?: readonly string[];
|
|
94
|
+
defaultValue?: unknown;
|
|
95
|
+
}
|
|
96
|
+
interface UsageOptionSummary {
|
|
97
|
+
name: string;
|
|
98
|
+
flags: readonly string[];
|
|
99
|
+
takesValue: boolean;
|
|
100
|
+
/** Whether the long flag also accepts a `--no-` prefixed form. */
|
|
101
|
+
negatable: boolean;
|
|
102
|
+
valueName?: string;
|
|
103
|
+
required: boolean;
|
|
104
|
+
description?: string;
|
|
105
|
+
choices?: readonly string[];
|
|
106
|
+
defaultValue?: unknown;
|
|
107
|
+
env?: string;
|
|
108
|
+
}
|
|
109
|
+
interface UsageCommandSummary {
|
|
110
|
+
name: string;
|
|
111
|
+
description?: string;
|
|
112
|
+
}
|
|
113
|
+
/** A schema-free description of the useful help metadata for a command. */
|
|
114
|
+
interface UsageSummary {
|
|
115
|
+
name: string;
|
|
116
|
+
heading?: string;
|
|
117
|
+
version?: string;
|
|
118
|
+
description?: string;
|
|
119
|
+
synopsis: string;
|
|
120
|
+
arguments: readonly UsageArgumentSummary[];
|
|
121
|
+
options: readonly UsageOptionSummary[];
|
|
122
|
+
commands: readonly UsageCommandSummary[];
|
|
123
|
+
}
|
|
124
|
+
/** Build a serializable help summary without retaining command or schema objects. */
|
|
125
|
+
declare function summarizeUsage(command: AnyCommandDef): UsageSummary;
|
|
126
|
+
interface ShowUsageOptions {
|
|
127
|
+
printer: Printer;
|
|
128
|
+
stream?: PrintStream;
|
|
129
|
+
}
|
|
130
|
+
/** Generate usage text without writing to stdout or stderr. */
|
|
131
|
+
declare function renderUsage(command: AnyCommandDef): string;
|
|
132
|
+
/** Generate a usage event and await its printer. */
|
|
133
|
+
declare function showUsage(command: AnyCommandDef, options: ShowUsageOptions): Promise<void>;
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/printer.d.ts
|
|
136
|
+
type PrintStream = "stdout" | "stderr";
|
|
137
|
+
type OutputPreference = "auto" | "pretty" | "json";
|
|
138
|
+
type OutputFormat = Exclude<OutputPreference, "auto">;
|
|
139
|
+
interface OutputMode {
|
|
140
|
+
format: OutputFormat;
|
|
141
|
+
interactive: boolean;
|
|
142
|
+
color: boolean;
|
|
143
|
+
}
|
|
144
|
+
interface ResolveOutputModeOptions {
|
|
145
|
+
output?: OutputPreference;
|
|
146
|
+
env?: Readonly<Record<string, string | undefined>>;
|
|
147
|
+
inputIsTTY?: boolean;
|
|
148
|
+
outputIsTTY?: boolean;
|
|
149
|
+
}
|
|
150
|
+
/** Resolve output behavior once, before command routing or argument parsing. */
|
|
151
|
+
declare function resolveOutputMode(options?: ResolveOutputModeOptions): OutputMode;
|
|
152
|
+
interface UsagePrintEvent {
|
|
153
|
+
type: "usage";
|
|
154
|
+
usage: UsageSummary;
|
|
155
|
+
text: string;
|
|
156
|
+
stream: PrintStream;
|
|
157
|
+
}
|
|
158
|
+
interface VersionPrintEvent {
|
|
159
|
+
type: "version";
|
|
160
|
+
version: string;
|
|
161
|
+
}
|
|
162
|
+
interface ErrorPrintEvent {
|
|
163
|
+
type: "error";
|
|
164
|
+
error: HackshErrorSummary;
|
|
165
|
+
}
|
|
166
|
+
interface LogPrintEvent {
|
|
167
|
+
type: "log";
|
|
168
|
+
record: LogRecord;
|
|
169
|
+
}
|
|
170
|
+
interface PromptChoiceState {
|
|
171
|
+
value: string;
|
|
172
|
+
label: string;
|
|
173
|
+
hint?: string;
|
|
174
|
+
selected: boolean;
|
|
175
|
+
}
|
|
176
|
+
type PromptStatus = "active" | "error" | "submitted" | "closed";
|
|
177
|
+
interface PromptStateBase {
|
|
178
|
+
message: string;
|
|
179
|
+
status: PromptStatus;
|
|
180
|
+
error?: string;
|
|
181
|
+
}
|
|
182
|
+
interface SelectPromptState extends PromptStateBase {
|
|
183
|
+
kind: "select";
|
|
184
|
+
choices: readonly PromptChoiceState[];
|
|
185
|
+
value: string;
|
|
186
|
+
}
|
|
187
|
+
interface ConfirmPromptState extends PromptStateBase {
|
|
188
|
+
kind: "confirm";
|
|
189
|
+
value: boolean;
|
|
190
|
+
defaultValue?: boolean;
|
|
191
|
+
}
|
|
192
|
+
interface TextPromptState extends PromptStateBase {
|
|
193
|
+
kind: "text";
|
|
194
|
+
value: string;
|
|
195
|
+
placeholder?: string;
|
|
196
|
+
}
|
|
197
|
+
type PromptState = SelectPromptState | ConfirmPromptState | TextPromptState;
|
|
198
|
+
interface PromptPrintEvent {
|
|
199
|
+
type: "prompt";
|
|
200
|
+
prompt: PromptState;
|
|
201
|
+
}
|
|
202
|
+
interface ExecPrintEvent {
|
|
203
|
+
type: "exec";
|
|
204
|
+
phase: "start" | "skip";
|
|
205
|
+
command: Omit<ExecCommand, "cwd"> & {
|
|
206
|
+
cwd?: string;
|
|
207
|
+
};
|
|
208
|
+
stdio: {
|
|
209
|
+
stdin: "ignore" | "input" | "inherit";
|
|
210
|
+
stdout: "pipe" | "inherit";
|
|
211
|
+
stderr: "pipe" | "inherit";
|
|
212
|
+
};
|
|
213
|
+
interactive: boolean;
|
|
214
|
+
}
|
|
215
|
+
/** A semantic, command- and schema-free output value emitted by hacksh. */
|
|
216
|
+
type PrintEvent = UsagePrintEvent | VersionPrintEvent | ErrorPrintEvent | LogPrintEvent | PromptPrintEvent | ExecPrintEvent;
|
|
217
|
+
/** Receives every output event produced by one command invocation. */
|
|
218
|
+
interface Printer {
|
|
219
|
+
print(event: PrintEvent): void | Promise<void>;
|
|
220
|
+
}
|
|
221
|
+
interface OutputWriter {
|
|
222
|
+
write(text: string): unknown;
|
|
223
|
+
}
|
|
224
|
+
interface TerminalInput {
|
|
225
|
+
readonly isTTY?: boolean;
|
|
226
|
+
readonly isRaw?: boolean;
|
|
227
|
+
readonly readableFlowing?: boolean | null;
|
|
228
|
+
setRawMode?(mode: boolean): unknown;
|
|
229
|
+
resume(): unknown;
|
|
230
|
+
pause(): unknown;
|
|
231
|
+
on(event: string, listener: (...args: never[]) => void): unknown;
|
|
232
|
+
removeListener(event: string, listener: (...args: never[]) => void): unknown;
|
|
233
|
+
}
|
|
234
|
+
interface TerminalOutput extends OutputWriter {
|
|
235
|
+
readonly isTTY?: boolean;
|
|
236
|
+
readonly columns?: number;
|
|
237
|
+
}
|
|
238
|
+
interface JsonPrinterOptions {
|
|
239
|
+
stdout?: OutputWriter;
|
|
240
|
+
stderr?: OutputWriter;
|
|
241
|
+
}
|
|
242
|
+
/** Create a one-semantic-event-per-line JSON printer. */
|
|
243
|
+
declare function createJsonPrinter(options?: JsonPrinterOptions): Printer;
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region src/exec.d.ts
|
|
246
|
+
type Environment = Readonly<Record<string, string | undefined>>;
|
|
247
|
+
interface ExecOptions {
|
|
248
|
+
cwd?: string;
|
|
249
|
+
env?: Environment;
|
|
250
|
+
input?: string;
|
|
251
|
+
reject?: boolean;
|
|
252
|
+
timeout?: number;
|
|
253
|
+
signal?: AbortSignal;
|
|
254
|
+
maxBuffer?: number;
|
|
255
|
+
forceKillAfterDelay?: number;
|
|
256
|
+
stdin?: "pipe" | "inherit";
|
|
257
|
+
stdout?: "pipe" | "inherit";
|
|
258
|
+
stderr?: "pipe" | "inherit";
|
|
259
|
+
interactive?: boolean;
|
|
260
|
+
display?: boolean;
|
|
261
|
+
redact?: readonly string[];
|
|
262
|
+
dryRun?: boolean;
|
|
263
|
+
}
|
|
264
|
+
interface ExecCommand {
|
|
265
|
+
file: string;
|
|
266
|
+
args: readonly string[];
|
|
267
|
+
cwd: string | undefined;
|
|
268
|
+
}
|
|
269
|
+
interface ExecSuccess {
|
|
270
|
+
status: "succeeded";
|
|
271
|
+
command: ExecCommand;
|
|
272
|
+
stdout: string;
|
|
273
|
+
stderr: string;
|
|
274
|
+
exitCode: 0;
|
|
275
|
+
}
|
|
276
|
+
type ExecFailure = {
|
|
277
|
+
status: "failed";
|
|
278
|
+
command: ExecCommand;
|
|
279
|
+
stdout: string;
|
|
280
|
+
stderr: string;
|
|
281
|
+
} & ({
|
|
282
|
+
reason: "exit-code";
|
|
283
|
+
exitCode: number;
|
|
284
|
+
} | {
|
|
285
|
+
reason: "signal";
|
|
286
|
+
signal: string;
|
|
287
|
+
} | {
|
|
288
|
+
reason: "spawn";
|
|
289
|
+
error: Error;
|
|
290
|
+
} | {
|
|
291
|
+
reason: "timeout" | "aborted" | "output-limit";
|
|
292
|
+
} | {
|
|
293
|
+
reason: "json-output" | "non-interactive" | "overlapping";
|
|
294
|
+
});
|
|
295
|
+
type ExecFailureReason = ExecFailure["reason"];
|
|
296
|
+
type ExecResult = ExecSuccess | ExecFailure;
|
|
297
|
+
interface ExecSkipped {
|
|
298
|
+
status: "skipped";
|
|
299
|
+
command: ExecCommand;
|
|
300
|
+
}
|
|
301
|
+
type ExecOutcome<O extends ExecOptions> = "reject" extends keyof O ? false extends O["reject"] ? ExecResult : ExecSuccess : ExecSuccess;
|
|
302
|
+
type SpecifiedDryRun<O> = "dryRun" extends keyof O ? O["dryRun"] : false;
|
|
303
|
+
type ReturnsFailure<O extends ExecOptions> = "reject" extends keyof O ? false extends O["reject"] ? true : false : false;
|
|
304
|
+
type AbortedFailure = {
|
|
305
|
+
status: "failed";
|
|
306
|
+
command: ExecCommand;
|
|
307
|
+
stdout: string;
|
|
308
|
+
stderr: string;
|
|
309
|
+
reason: "aborted";
|
|
310
|
+
};
|
|
311
|
+
type DefiniteSkip<O extends ExecOptions> = ReturnsFailure<O> extends true ? ExecSkipped | AbortedFailure : ExecSkipped;
|
|
312
|
+
type ExecReturn<O extends ExecOptions> = true extends SpecifiedDryRun<O> ? false extends SpecifiedDryRun<O> ? ExecSkipped | ExecOutcome<O> : undefined extends SpecifiedDryRun<O> ? ExecSkipped | ExecOutcome<O> : DefiniteSkip<O> : ExecOutcome<O>;
|
|
313
|
+
type RejectInheritedInput<O> = O extends {
|
|
314
|
+
input: string;
|
|
315
|
+
stdin: "inherit";
|
|
316
|
+
} ? never : unknown;
|
|
317
|
+
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>>;
|
|
318
|
+
//#endregion
|
|
319
|
+
//#region src/prompts.d.ts
|
|
320
|
+
interface SelectOption<T extends string> {
|
|
321
|
+
value: T;
|
|
322
|
+
label?: string;
|
|
323
|
+
hint?: string;
|
|
324
|
+
}
|
|
325
|
+
interface SelectOptions<T extends string> {
|
|
326
|
+
message: string;
|
|
327
|
+
options: readonly SelectOption<T>[];
|
|
328
|
+
initialValue?: T;
|
|
329
|
+
}
|
|
330
|
+
interface ConfirmOptions {
|
|
331
|
+
message: string;
|
|
332
|
+
initialValue?: boolean;
|
|
333
|
+
}
|
|
334
|
+
interface TextOptions {
|
|
335
|
+
message: string;
|
|
336
|
+
placeholder?: string;
|
|
337
|
+
validate?(value: string): string | undefined;
|
|
338
|
+
}
|
|
339
|
+
interface Prompter {
|
|
340
|
+
select<const T extends string>(options: SelectOptions<T>): Promise<T>;
|
|
341
|
+
confirm(options: ConfirmOptions): Promise<boolean>;
|
|
342
|
+
text(options: TextOptions): Promise<string>;
|
|
343
|
+
}
|
|
344
|
+
//#endregion
|
|
345
|
+
//#region src/schema.d.ts
|
|
346
|
+
type ArgsSchema = $ZodObject;
|
|
347
|
+
type EmptyArgs = $ZodObject<{}>;
|
|
348
|
+
//#endregion
|
|
349
|
+
//#region src/command.d.ts
|
|
350
|
+
interface CommandContext<S extends ArgsSchema> {
|
|
351
|
+
command: CommandDef<S>;
|
|
352
|
+
args: output<S>;
|
|
353
|
+
input: {
|
|
354
|
+
argv: string[];
|
|
355
|
+
unknown: string[];
|
|
356
|
+
passthrough: string[];
|
|
357
|
+
};
|
|
358
|
+
logger: Logger;
|
|
359
|
+
prompt: Prompter;
|
|
360
|
+
exec: Exec;
|
|
361
|
+
signal: AbortSignal;
|
|
362
|
+
}
|
|
363
|
+
interface CommandDef<S extends ArgsSchema = EmptyArgs, R = unknown, Children extends Record<string, AnyCommandDef> = Record<string, AnyCommandDef>> {
|
|
364
|
+
name?: string;
|
|
365
|
+
version?: string;
|
|
366
|
+
description?: string;
|
|
367
|
+
hidden?: boolean;
|
|
368
|
+
/** Keep unknown options and excess positionals in input.unknown. Inherits from the parent; defaults to false. */
|
|
369
|
+
allowUnknownArgs?: boolean;
|
|
370
|
+
args?: S;
|
|
371
|
+
subCommands?: Children;
|
|
372
|
+
run?(context: CommandContext<S>): R;
|
|
373
|
+
}
|
|
374
|
+
type AnyCommandDef = CommandDef<ArgsSchema>;
|
|
375
|
+
declare function defineCommand<S extends ArgsSchema = EmptyArgs, R = never, Children extends Record<string, AnyCommandDef> = {}>(def: CommandDef<S, R, Children>): CommandDef<S, NoInfer<R>, NoInfer<Children>>;
|
|
376
|
+
//#endregion
|
|
377
|
+
export { LogKind as $, PrintStream as A, TextPromptState as B, JsonPrinterOptions as C, OutputPreference as D, OutputMode as E, PromptStatus as F, ShowUsageOptions as G, VersionPrintEvent as H, ResolveOutputModeOptions as I, UsageOptionSummary as J, UsageArgumentSummary as K, SelectPromptState as L, PromptChoiceState as M, PromptPrintEvent as N, OutputWriter as O, PromptState as P, summarizeUsage as Q, TerminalInput as R, ExecPrintEvent as S, OutputFormat as T, createJsonPrinter as U, UsagePrintEvent as V, resolveOutputMode as W, renderUsage as X, UsageSummary as Y, showUsage as Z, ExecReturn as _, ArgsSchema as a, HackshErrorSummary as at, ConfirmPromptState as b, SelectOption as c, HackshIssue as ct, Exec as d, HackshUsageError as dt, LogLevel as et, ExecCommand as f, HackshValidationError as ft, ExecResult as g, ExecOptions as h, ValidationIssueSummary as ht, defineCommand as i, HackshErrorKind as it, Printer as j, PrintEvent as k, SelectOptions as l, HackshPromptError as lt, ExecFailureReason as m, PromptKind as mt, CommandContext as n, LogRecord as nt, ConfirmOptions as o, HackshExecError as ot, ExecFailure as p, PromptErrorDetails as pt, UsageCommandSummary as q, CommandDef as r, Logger as rt, Prompter as s, HackshExitError as st, AnyCommandDef as t, LogProperties as tt, TextOptions as u, HackshPromptErrorReason as ut, ExecSkipped as v, LogPrintEvent as w, ErrorPrintEvent as x, ExecSuccess as y, TerminalOutput as z };
|
|
378
|
+
//# sourceMappingURL=command-CfWrbHLN.d.ts.map
|