hacksh 0.14.0 → 0.16.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.
@@ -1,4 +1,78 @@
1
- import { $ZodIssue, $ZodObject, output } from "zod/v4/core";
1
+ import { $ZodIssue, $ZodObject, JSONSchemaMeta, output } from "zod/v4/core";
2
+ //#region src/exec.d.ts
3
+ type Environment = Readonly<Record<string, string | undefined>>;
4
+ interface ExecOptions {
5
+ cwd?: string;
6
+ env?: Environment;
7
+ input?: string;
8
+ reject?: boolean;
9
+ timeout?: number;
10
+ signal?: AbortSignal;
11
+ maxBuffer?: number;
12
+ forceKillAfterDelay?: number;
13
+ stdin?: "pipe" | "inherit";
14
+ stdout?: "pipe" | "inherit";
15
+ stderr?: "pipe" | "inherit";
16
+ interactive?: boolean;
17
+ display?: boolean;
18
+ redact?: readonly string[];
19
+ dryRun?: boolean;
20
+ }
21
+ interface ExecCommand {
22
+ file: string;
23
+ args: readonly string[];
24
+ cwd: string | undefined;
25
+ }
26
+ interface ExecSuccess {
27
+ status: "succeeded";
28
+ command: ExecCommand;
29
+ stdout: string;
30
+ stderr: string;
31
+ exitCode: 0;
32
+ }
33
+ type ExecFailure = {
34
+ status: "failed";
35
+ command: ExecCommand;
36
+ stdout: string;
37
+ stderr: string;
38
+ } & ({
39
+ reason: "exit-code";
40
+ exitCode: number;
41
+ } | {
42
+ reason: "signal";
43
+ signal: string;
44
+ } | {
45
+ reason: "spawn";
46
+ error: Error;
47
+ } | {
48
+ reason: "timeout" | "aborted" | "output-limit";
49
+ } | {
50
+ reason: "json-output" | "non-interactive" | "overlapping";
51
+ });
52
+ type ExecFailureReason = ExecFailure["reason"];
53
+ type ExecResult = ExecSuccess | ExecFailure;
54
+ interface ExecSkipped {
55
+ status: "skipped";
56
+ command: ExecCommand;
57
+ }
58
+ type ExecOutcome<O extends ExecOptions> = "reject" extends keyof O ? false extends O["reject"] ? ExecResult : ExecSuccess : ExecSuccess;
59
+ type SpecifiedDryRun<O> = "dryRun" extends keyof O ? O["dryRun"] : false;
60
+ type ReturnsFailure<O extends ExecOptions> = "reject" extends keyof O ? false extends O["reject"] ? true : false : false;
61
+ type AbortedFailure = {
62
+ status: "failed";
63
+ command: ExecCommand;
64
+ stdout: string;
65
+ stderr: string;
66
+ reason: "aborted";
67
+ };
68
+ type DefiniteSkip<O extends ExecOptions> = ReturnsFailure<O> extends true ? ExecSkipped | AbortedFailure : ExecSkipped;
69
+ 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>;
70
+ type RejectInheritedInput<O> = O extends {
71
+ input: string;
72
+ stdin: "inherit";
73
+ } ? never : unknown;
74
+ 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>>;
75
+ //#endregion
2
76
  //#region src/errors.d.ts
3
77
  interface HackshIssue {
4
78
  arg: string;
@@ -136,16 +210,21 @@ declare function showUsage(command: AnyCommandDef, options: ShowUsageOptions): P
136
210
  type PrintStream = "stdout" | "stderr";
137
211
  type OutputPreference = "auto" | "pretty" | "json";
138
212
  type OutputFormat = Exclude<OutputPreference, "auto">;
213
+ interface StreamColors {
214
+ stdout: boolean;
215
+ stderr: boolean;
216
+ }
139
217
  interface OutputMode {
140
218
  format: OutputFormat;
141
219
  interactive: boolean;
142
- color: boolean;
220
+ color: StreamColors;
143
221
  }
144
222
  interface ResolveOutputModeOptions {
145
223
  output?: OutputPreference;
146
224
  env?: Readonly<Record<string, string | undefined>>;
147
225
  inputIsTTY?: boolean;
148
226
  outputIsTTY?: boolean;
227
+ errorOutputIsTTY?: boolean;
149
228
  }
150
229
  /** Resolve output behavior once, before command routing or argument parsing. */
151
230
  declare function resolveOutputMode(options?: ResolveOutputModeOptions): OutputMode;
@@ -199,6 +278,16 @@ interface PromptPrintEvent {
199
278
  type: "prompt";
200
279
  prompt: PromptState;
201
280
  }
281
+ /** Command output: exact text written to stdout, or a JSON value. */
282
+ type OutputPrintEvent = {
283
+ type: "output";
284
+ kind: "text";
285
+ text: string;
286
+ } | {
287
+ type: "output";
288
+ kind: "json";
289
+ data: unknown;
290
+ };
202
291
  interface ExecPrintEvent {
203
292
  type: "exec";
204
293
  phase: "start" | "skip";
@@ -213,7 +302,7 @@ interface ExecPrintEvent {
213
302
  interactive: boolean;
214
303
  }
215
304
  /** A semantic, command- and schema-free output value emitted by hacksh. */
216
- type PrintEvent = UsagePrintEvent | VersionPrintEvent | ErrorPrintEvent | LogPrintEvent | PromptPrintEvent | ExecPrintEvent;
305
+ type PrintEvent = UsagePrintEvent | VersionPrintEvent | ErrorPrintEvent | LogPrintEvent | PromptPrintEvent | OutputPrintEvent | ExecPrintEvent;
217
306
  /** Receives every output event produced by one command invocation. */
218
307
  interface Printer {
219
308
  print(event: PrintEvent): void | Promise<void>;
@@ -242,79 +331,16 @@ interface JsonPrinterOptions {
242
331
  /** Create a one-semantic-event-per-line JSON printer. */
243
332
  declare function createJsonPrinter(options?: JsonPrinterOptions): Printer;
244
333
  //#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;
334
+ //#region src/command-output.d.ts
335
+ /** Writes a command's results to stdout, separately from logs. */
336
+ interface Output {
337
+ /** Write text exactly as given. */
338
+ print(text: string): void;
339
+ /** Write text followed by a newline. */
340
+ println(text?: string): void;
341
+ /** Write a JSON value. */
342
+ json(value: unknown): void;
263
343
  }
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
344
  //#endregion
319
345
  //#region src/prompts.d.ts
320
346
  interface SelectOption<T extends string> {
@@ -343,6 +369,17 @@ interface Prompter {
343
369
  }
344
370
  //#endregion
345
371
  //#region src/schema.d.ts
372
+ interface ArgumentMeta extends JSONSchemaMeta {
373
+ alias?: string | readonly string[];
374
+ env?: string | false;
375
+ valueName?: string;
376
+ }
377
+ declare module "zod" {
378
+ interface GlobalMeta extends ArgumentMeta {}
379
+ }
380
+ declare module "zod/v4" {
381
+ interface GlobalMeta extends ArgumentMeta {}
382
+ }
346
383
  type ArgsSchema = $ZodObject;
347
384
  type EmptyArgs = $ZodObject<{}>;
348
385
  //#endregion
@@ -355,6 +392,7 @@ interface CommandContext<S extends ArgsSchema> {
355
392
  unknown: string[];
356
393
  passthrough: string[];
357
394
  };
395
+ output: Output;
358
396
  logger: Logger;
359
397
  prompt: Prompter;
360
398
  exec: Exec;
@@ -374,5 +412,5 @@ interface CommandDef<S extends ArgsSchema = EmptyArgs, R = unknown, Children ext
374
412
  type AnyCommandDef = CommandDef<ArgsSchema>;
375
413
  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
414
  //#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
415
+ export { HackshErrorSummary as $, SelectPromptState as A, UsageArgumentSummary as B, PrintStream as C, PromptState as D, PromptPrintEvent as E, UsagePrintEvent as F, showUsage as G, UsageOptionSummary as H, VersionPrintEvent as I, LogLevel as J, summarizeUsage as K, createJsonPrinter as L, TerminalInput as M, TerminalOutput as N, PromptStatus as O, TextPromptState as P, HackshErrorKind as Q, resolveOutputMode as R, PrintEvent as S, PromptChoiceState as T, UsageSummary as U, UsageCommandSummary as V, renderUsage as W, LogRecord as X, LogProperties as Y, Logger as Z, OutputFormat as _, ExecSkipped as _t, ArgsSchema as a, HackshUsageError as at, OutputPrintEvent as b, SelectOption as c, PromptKind as ct, Output as d, ExecCommand as dt, HackshExecError as et, ConfirmPromptState as f, ExecFailure as ft, LogPrintEvent as g, ExecReturn as gt, JsonPrinterOptions as h, ExecResult as ht, defineCommand as i, HackshPromptErrorReason as it, StreamColors as j, ResolveOutputModeOptions as k, SelectOptions as l, ValidationIssueSummary as lt, ExecPrintEvent as m, ExecOptions as mt, CommandContext as n, HackshIssue as nt, ConfirmOptions as o, HackshValidationError as ot, ErrorPrintEvent as p, ExecFailureReason as pt, LogKind as q, CommandDef as r, HackshPromptError as rt, Prompter as s, PromptErrorDetails as st, AnyCommandDef as t, HackshExitError as tt, TextOptions as u, Exec as ut, OutputMode as v, ExecSuccess as vt, Printer as w, OutputWriter as x, OutputPreference as y, ShowUsageOptions as z };
416
+ //# sourceMappingURL=command-B-Ok_6KW.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
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";
1
+ import { G as showUsage, K as summarizeUsage, M as TerminalInput, N as TerminalOutput, W as renderUsage, Z as Logger, _t as ExecSkipped, a as ArgsSchema, at as HackshUsageError, c as SelectOption, ct as PromptKind, d as Output, dt as ExecCommand, et as HackshExecError, ft as ExecFailure, gt as ExecReturn, ht as ExecResult, i as defineCommand, it as HackshPromptErrorReason, l as SelectOptions, mt as ExecOptions, n as CommandContext, nt as HackshIssue, o as ConfirmOptions, ot as HackshValidationError, pt as ExecFailureReason, r as CommandDef, rt as HackshPromptError, s as Prompter, st as PromptErrorDetails, t as AnyCommandDef, tt as HackshExitError, u as TextOptions, ut as Exec, vt as ExecSuccess, w as Printer, y as OutputPreference, z as ShowUsageOptions } from "./command-B-Ok_6KW.js";
2
2
  import { output } from "zod/v4/core";
3
3
  //#region src/parser.d.ts
4
4
  /**
@@ -17,7 +17,7 @@ interface OutputOptions {
17
17
  env?: Readonly<Record<string, string | undefined>>;
18
18
  stdin?: TerminalInput;
19
19
  stdout?: TerminalOutput;
20
- stderr?: OutputWriter;
20
+ stderr?: TerminalOutput;
21
21
  }
22
22
  //#endregion
23
23
  //#region src/run.d.ts
@@ -39,5 +39,5 @@ interface RunMainOptions extends OutputOptions {
39
39
  }
40
40
  declare function runMain<S extends ArgsSchema>(command: CommandDef<S>, options?: RunMainOptions): Promise<void>;
41
41
  //#endregion
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 };
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 Output, 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 };
43
43
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as createExec, c as HackshPromptError, d as summarizeError, f as summarizeErrors, i as resolveOutputMode, l as HackshUsageError, n as createJsonPrinter, o as HackshExecError, r as createPrintQueue, s as HackshExitError, t as createPrettyPrinter, u as HackshValidationError } from "./pretty-BFub611x.js";
1
+ import { a as createExec, c as HackshPromptError, d as summarizeError, f as summarizeErrors, i as resolveOutputMode, l as HackshUsageError, n as createJsonPrinter, o as HackshExecError, r as createPrintQueue, s as HackshExitError, t as createPrettyPrinter, u as HackshValidationError } from "./pretty-DJ2CE6TU.js";
2
2
  import { globalRegistry, safeParseAsync } from "zod/v4/core";
3
3
  import { parseArgs as parseArgs$1 } from "node:util";
4
4
  import { readFile, realpath } from "node:fs/promises";
@@ -475,6 +475,27 @@ async function parseArgs(command, argv, options) {
475
475
  return (await parseCommandArgs(command, argv, tokenizeCommandArgs(command, argv), options?.env, envPath)).args;
476
476
  }
477
477
  //#endregion
478
+ //#region src/command-output.ts
479
+ /** Create the output for one command invocation. */
480
+ function createOutput(printer) {
481
+ function print(text) {
482
+ printer.print({
483
+ type: "output",
484
+ kind: "text",
485
+ text
486
+ });
487
+ }
488
+ return {
489
+ print,
490
+ println: (text = "") => print(`${text}\n`),
491
+ json: (data) => void printer.print({
492
+ type: "output",
493
+ kind: "json",
494
+ data
495
+ })
496
+ };
497
+ }
498
+ //#endregion
478
499
  //#region src/terminal.ts
479
500
  var TerminalLock = class {
480
501
  #owner;
@@ -885,7 +906,8 @@ function selectOutputPrinter(options, override, resolvedMode) {
885
906
  output: options.output,
886
907
  env: options.env,
887
908
  inputIsTTY: stdin.isTTY,
888
- outputIsTTY: stdout.isTTY
909
+ outputIsTTY: stdout.isTTY,
910
+ errorOutputIsTTY: stderr.isTTY
889
911
  });
890
912
  if (override) return override;
891
913
  if (mode.format === "json") return createJsonPrinter({
@@ -1109,6 +1131,7 @@ async function executeCommand(root, argv, output, env, signal, fallbackVersion =
1109
1131
  unknown: parsed.extraArgs,
1110
1132
  passthrough: parsed.passthrough
1111
1133
  },
1134
+ output: createOutput(printer),
1112
1135
  logger: createLogger(printer, category),
1113
1136
  prompt: new PromptController({
1114
1137
  interactive: output.interactive,
@@ -1136,7 +1159,8 @@ function prepareOutput(options, env) {
1136
1159
  output: options.output,
1137
1160
  env,
1138
1161
  inputIsTTY: input.isTTY,
1139
- outputIsTTY: (options.stdout ?? process.stdout).isTTY
1162
+ outputIsTTY: (options.stdout ?? process.stdout).isTTY,
1163
+ errorOutputIsTTY: (options.stderr ?? process.stderr).isTTY
1140
1164
  });
1141
1165
  return {
1142
1166
  ...createPrintQueue(selectOutputPrinter(options, options.printer, mode)),