@kjanat/dreamcli 4.1.0 → 4.2.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/{adapter-YM5QGi3M.d.mts → adapter-DsmEc0WO.d.mts} +5 -1
- package/dist/{completion-CUMeOnAz.mjs → completion-BYhuYn2Q.mjs} +4 -4
- package/dist/completion.d.mts +1 -1
- package/dist/completion.mjs +1 -1
- package/dist/config-BgJZ-X4r.mjs +1 -0
- package/dist/config.d.mts +1 -1
- package/dist/config.mjs +1 -1
- package/dist/core-B4Twhd48.mjs +18 -0
- package/dist/index-B3_9MlHz.d.mts +131 -0
- package/dist/{index-BziI2aKc.d.mts → index-B6oD4_8b.d.mts} +74 -12
- package/dist/{index-DWsnGZlx.d.mts → index-B_1Dmsdq.d.mts} +12 -136
- package/dist/{index-3l8uj16E.d.mts → index-C5CYWtxn.d.mts} +9 -6
- package/dist/{index-Cap0MA2V.d.mts → index-CaRNJH2R.d.mts} +5 -1
- package/dist/{index-Cp9kt2t-.d.mts → index-Cj7kXwQH.d.mts} +1 -1
- package/dist/{index-BAj2y70U.d.mts → index-eF7SkQzQ.d.mts} +4 -4
- package/dist/index.d.mts +8 -7
- package/dist/index.mjs +1 -1
- package/dist/json-schema-DVyfq4bA.mjs +52 -0
- package/dist/json-schema.d.mts +1 -1
- package/dist/json-schema.mjs +1 -1
- package/dist/package-json-fYhxDdWD.mjs +3 -0
- package/dist/prompt.d.mts +36 -3
- package/dist/prompt.mjs +1 -1
- package/dist/runtime.d.mts +2 -2
- package/dist/runtime.mjs +1 -1
- package/dist/session-CQsnVijE.mjs +1 -0
- package/dist/terminal-cbye9mKF.mjs +7 -0
- package/dist/test-prompter-Ddkt9n5A.mjs +1 -0
- package/dist/testkit.d.mts +4 -4
- package/dist/testkit.mjs +1 -1
- package/dist/version.mjs +1 -1
- package/dreamcli.schema.json +15 -1
- package/package.json +20 -20
- package/skills/cli-creation/SKILL.md +1 -1
- package/skills/cli-creation/scripts/scaffold_cli.py +12 -4
- package/dist/config-CrlScpYX.mjs +0 -1
- package/dist/core-DvXUolc_.mjs +0 -17
- package/dist/json-schema-DRlrz_IV.mjs +0 -52
- package/dist/package-json-BgE9YjjQ.mjs +0 -3
- package/dist/terminal-C8KTXjv5.mjs +0 -6
- package/dist/test-prompter-v__jT2yG.mjs +0 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import{t as __exportAll}from"./rolldown-runtime-G4Kt5YOX.mjs";import{I as resolvePlainHelpDescription,Q as DUPLICATE_KEYS,U as resolveExampleCommand,a as DEFINITION_SCHEMA_URL,q as getFlagAliasNames}from"./core-B4Twhd48.mjs";const definitionMetaSchemaDescriptions={root:{description:`Runtime descriptor for the CLI program.
|
|
2
|
+
|
|
3
|
+
Stores the program name, version, description, and registered command schemas.\\
|
|
4
|
+
Sealed by createCLISchema and rebuilt by each CLIBuilder step.`,properties:{name:{description:`Program name (used in help text, usage lines, and completion scripts).`},version:{description:"Program version (shown by `--version`)."},description:{description:`Program description (shown in root help).`},defaultCommand:{description:`Schema of the default command dispatched when no subcommand matches.
|
|
5
|
+
|
|
6
|
+
When set, the CLI root behaves like a hybrid command group: subcommands
|
|
7
|
+
dispatch by name as usual, but empty argv or flags-only argv falls
|
|
8
|
+
through to this command instead of showing root help.
|
|
9
|
+
|
|
10
|
+
Set via the .default() builder method
|
|
11
|
+
or the \`defaultCommand\` field of CLIDefinition.`},commands:{description:`Schemas of the registered commands, in registration order.`}}},defs:{command:{description:`Runtime descriptor produced by CommandBuilder.
|
|
12
|
+
|
|
13
|
+
Consumers (parser, help generator, CLI dispatcher) read this to
|
|
14
|
+
understand the command's shape — flags, args, aliases, subcommands,
|
|
15
|
+
and interactive resolver.`,properties:{name:{description:"The command name (used for dispatch, e.g. `'deploy'`)."},description:{description:`Human-readable description for help text.`},aliases:{description:`Alternative names for this command.`},hidden:{description:`Whether this command is hidden from help listings.`},examples:{description:`Usage examples for help text.`},flags:{description:`Named flag schemas, keyed by flag name.`},args:{description:`Ordered positional arg entries (name + schema).`},commands:{description:"Nested subcommand schemas (for help rendering and completion).\n\nPure data — no execution closures. Populated by `.command()` on\n`CommandBuilder`. Empty for leaf commands."}}},commandDocument:{description:`A single-command definition document, version 1.
|
|
16
|
+
|
|
17
|
+
Produced by generateCommandSchema. Same shape as a
|
|
18
|
+
CommandDefinitionFragmentV1 plus the \`schemaVersion\` every standalone
|
|
19
|
+
document carries.`,properties:{schemaVersion:{description:"Version of the definition document format emitted by `generateSchema()`\nand `generateCommandSchema()` from `@kjanat/dreamcli/json-schema`."},name:{description:`The command name used for dispatch.`},description:{description:`Human-readable description for help text.`},aliases:{description:`Alternative names accepted for this command.`},hidden:{description:`Whether the command is omitted from help listings.`},examples:{description:`Usage examples attached to the command.`},flags:{description:`Named flag definitions keyed by flag name.`},args:{description:`Positional argument definitions in CLI order.`},commands:{description:`Nested subcommand definitions.`}}},flag:{description:`The runtime descriptor stored inside every FlagBuilder. Consumers (parser,
|
|
20
|
+
help generator, resolution chain) read this to understand the flag's shape
|
|
21
|
+
without touching generics.`,properties:{kind:{description:`What kind of value this flag accepts.`},presence:{description:"Presence describes whether a flag value is guaranteed to exist when the\naction handler runs:\n\n- `'optional'` — not required; unresolved value follows the kind-specific\n optional fallback (`undefined` for most flags, `[]` for arrays)\n- `'required'` — must be supplied; error if missing\n- `'defaulted'` — always present (falls back to default value)"},defaultValue:{description:`Runtime default value (if any).`},aliases:{description:"Short/long aliases (e.g. `[{ name: 'f', hidden: false }]` for `--force`)."},stdin:{description:"Stdin binding set by `.stdin()` (`undefined` when the flag never reads\nstdin). See StdinBinding."},envVar:{description:`Environment variable name for v0.2+ resolution.`},configPath:{description:"Dotted config path for v0.2+ resolution (e.g. `'deploy.region'`)."},description:{description:`Human-readable description for help text.`},enumValues:{description:"Allowed literal values when `kind === 'enum'`."},elementSchema:{description:"Element schema when `kind === 'array'` or `kind === 'keyValue'`."},prompt:{description:`Interactive prompt configuration for v0.3+ resolution.`},deprecated:{description:"Deprecation marker.\n\n- `undefined` — not deprecated (default)\n- `true` — deprecated with no migration message\n- `string` — deprecated with a reason/migration message\n\nWhen a deprecated flag is used, a warning is emitted to stderr.\nHelp text shows `[deprecated]` or `[deprecated: <reason>]`."},propagate:{description:`Whether this flag propagates to subcommands in nested command trees.
|
|
22
|
+
|
|
23
|
+
When \`true\`, the flag is automatically available to all descendant
|
|
24
|
+
commands. A child command that defines a flag with the same name
|
|
25
|
+
shadows the propagated parent flag.
|
|
26
|
+
|
|
27
|
+
Default: \`false\``},negation:{description:"Negation settings when `kind === 'boolean'` and `.negatable()` was\ncalled (`undefined` otherwise). See FlagNegation."},duplicates:{description:"How repeated CLI occurrences of a singleton flag combine.\n\n- `'last'` — last occurrence wins (matches historic behavior)\n- `'first'` — first occurrence wins; later ones parse but are ignored\n- `'error'` — a second occurrence is a `ParseError` (`DUPLICATE_FLAG`)\n\nApplies to CLI token occurrences only — env/config/prompt/default\nresolution keeps its precedence semantics and never raises duplicates.\nOccurrences are counted per *logical* flag: aliases and the negated\nspelling all count toward the same flag.\n\nDefault: `'last'`"},defaultDescription:{description:"Human-readable replacement for the default value in help, or `false` to\nomit the default annotation."},sensitive:{description:`Whether values from this input must be kept out of user-facing projections.`}}},flagElement:{description:"Element schema when `kind === 'array'` or `kind === 'keyValue'`.",properties:{kind:{description:`What kind of value this flag accepts.`},presence:{description:"Presence describes whether a flag value is guaranteed to exist when the\naction handler runs:\n\n- `'optional'` — not required; unresolved value follows the kind-specific\n optional fallback (`undefined` for most flags, `[]` for arrays)\n- `'required'` — must be supplied; error if missing\n- `'defaulted'` — always present (falls back to default value)"},defaultValue:{description:`Runtime default value (if any).`},aliases:{description:"Short/long aliases (e.g. `[{ name: 'f', hidden: false }]` for `--force`)."},stdin:{description:"Stdin binding set by `.stdin()` (`undefined` when the flag never reads\nstdin). See StdinBinding."},envVar:{description:`Environment variable name for v0.2+ resolution.`},configPath:{description:"Dotted config path for v0.2+ resolution (e.g. `'deploy.region'`)."},description:{description:`Human-readable description for help text.`},enumValues:{description:"Allowed literal values when `kind === 'enum'`."},elementSchema:{description:"Element schema when `kind === 'array'` or `kind === 'keyValue'`."},prompt:{description:`Interactive prompt configuration for v0.3+ resolution.`},deprecated:{description:"Deprecation marker.\n\n- `undefined` — not deprecated (default)\n- `true` — deprecated with no migration message\n- `string` — deprecated with a reason/migration message\n\nWhen a deprecated flag is used, a warning is emitted to stderr.\nHelp text shows `[deprecated]` or `[deprecated: <reason>]`."},propagate:{description:`Whether this flag propagates to subcommands in nested command trees.
|
|
28
|
+
|
|
29
|
+
When \`true\`, the flag is automatically available to all descendant
|
|
30
|
+
commands. A child command that defines a flag with the same name
|
|
31
|
+
shadows the propagated parent flag.
|
|
32
|
+
|
|
33
|
+
Default: \`false\``},negation:{description:"Negation settings when `kind === 'boolean'` and `.negatable()` was\ncalled (`undefined` otherwise). See FlagNegation."},duplicates:{description:"How repeated CLI occurrences of a singleton flag combine.\n\n- `'last'` — last occurrence wins (matches historic behavior)\n- `'first'` — first occurrence wins; later ones parse but are ignored\n- `'error'` — a second occurrence is a `ParseError` (`DUPLICATE_FLAG`)\n\nApplies to CLI token occurrences only — env/config/prompt/default\nresolution keeps its precedence semantics and never raises duplicates.\nOccurrences are counted per *logical* flag: aliases and the negated\nspelling all count toward the same flag.\n\nDefault: `'last'`"}}},stdin:{description:`The normalized stdin axis of a flag or an arg.`,properties:{when:{description:`When this input reads the stdin stream.`},consume:{description:`Whether this input consumes the stream alone.`},trim:{description:`Whether one trailing line terminator is dropped from a single value.`}}},negation:{description:`Negation settings for a boolean flag (set by \`.negatable()\`).
|
|
34
|
+
|
|
35
|
+
The negated spelling and the positive form are two spellings of ONE
|
|
36
|
+
logical flag: they share duplicate policy, and the last CLI occurrence
|
|
37
|
+
wins across both. The negated spelling is presence-only — \`--no-foo=x\`
|
|
38
|
+
is rejected.`,properties:{alias:{description:"Explicit negated spelling without the `--` prefix (e.g. `'no-sandbox'`).\n`undefined` synthesizes `no-<flagName>` wherever the flag name is known."},hidden:{description:`Hide the negated spelling from help, completions, and suggestions.`}}},arg:{description:`The runtime descriptor stored inside every ArgBuilder. Consumers (parser,
|
|
39
|
+
help generator) read this to understand the arg's shape without touching
|
|
40
|
+
generics.`,properties:{name:{description:`A named positional argument entry in the command schema.
|
|
41
|
+
|
|
42
|
+
Pairs a user-facing arg name with its ArgSchema descriptor.
|
|
43
|
+
The array ordering in CommandSchema.args determines CLI position.`},kind:{description:`What kind of value this arg accepts.`},presence:{description:"Presence describes whether a positional arg is guaranteed to exist when the\naction handler runs:\n\n- `'required'` — must be supplied; error if missing (default)\n- `'optional'` — may be `undefined` if not supplied\n- `'defaulted'` — always present (falls back to default value)"},variadic:{description:`Whether this arg consumes all remaining positionals.`},stdin:{description:"Stdin binding set by `.stdin()` (`undefined` when the arg never reads\nstdin). See StdinBinding."},defaultValue:{description:`Runtime default value (if any).`},defaultDescription:{description:"Human-readable replacement for the default value in help, or `false` to\nomit the default annotation."},sensitive:{description:`Whether values from this input must be kept out of user-facing projections.`},description:{description:`Human-readable description for help text.`},envVar:{description:`Environment variable name for env resolution.
|
|
44
|
+
|
|
45
|
+
When set and the CLI value is absent, the resolver reads this env var
|
|
46
|
+
and coerces the string to the arg's declared kind.`},configPath:{description:"Dotted config path for config resolution (e.g. `'deploy.region'`)."},prompt:{description:`Interactive prompt configuration.`},enumValues:{description:"Allowed literal values when `kind === 'enum'`."},elementSchema:{description:"Element schema when `kind === 'keyValue'`.\n\nDescribes the value of each entry, so `arg.keyValue(arg.number())` decodes\n`A=1` to the number `1`. `undefined` leaves entry values as strings."},deprecated:{description:"Deprecation marker.\n\n- `undefined` — not deprecated (default)\n- `true` — deprecated with no migration message\n- `string` — deprecated with a reason/migration message\n\nWhen a deprecated arg is used, a warning is emitted to stderr.\nHelp text shows `[deprecated]` or `[deprecated: <reason>]`."}}},argElement:{description:"Element schema when `kind === 'keyValue'`.\n\nDescribes the value of each entry, so `arg.keyValue(arg.number())` decodes\n`A=1` to the number `1`. `undefined` leaves entry values as strings.",properties:{kind:{description:`What kind of value this arg accepts.`},presence:{description:`Entry values are required once their containing key-value argument is present.`},enumValues:{description:"Allowed literal values when `kind === 'enum'`."}}},prompt:{description:"Discriminated union of all prompt configurations.\n\nUse the `kind` field to narrow:\n```ts\nif (config.kind === 'select') {\n config.choices // readonly SelectChoice[] | undefined\n}\n```",properties:{kind:{description:"The kind of interactive prompt to present.\n\n- `'confirm'` — yes/no boolean question\n- `'input'` — free-text string input\n- `'password'` — hidden text input, preserving whitespace\n- `'select'` — single selection from a list\n- `'multiselect'` — multiple selections from a list"},message:{description:`The question displayed to the user.`},placeholder:{description:`Placeholder text shown before user types (informational only).`},choices:{description:"Available choices. When omitted for `enum` flags, the enum values\nfrom the flag schema are used automatically."},min:{description:`Minimum number of selections required.
|
|
47
|
+
|
|
48
|
+
Default: \`0\``},max:{description:`Maximum number of selections allowed.
|
|
49
|
+
|
|
50
|
+
Default: \`Infinity\``}}},choice:{description:`A selectable option for SelectPromptConfig and MultiselectPromptConfig prompts.`,properties:{value:{description:`The value returned when this choice is selected.`},label:{description:`Display label shown to the user.
|
|
51
|
+
|
|
52
|
+
Default: value`},description:{description:`Optional description shown alongside the choice.`}}},example:{description:`A single usage example shown in help text.`,properties:{command:{description:"The command invocation (e.g. `'deploy production --force'`)."},description:{description:`Optional description of what this example does.`}}}}};var json_schema_exports=/* @__PURE__ */ __exportAll({DEFINITION_SCHEMA_URL:()=>DEFINITION_SCHEMA_URL,DEFINITION_SCHEMA_VERSION:()=>1,definitionMetaSchema:()=>definitionMetaSchema,generateCommandSchema:()=>generateCommandSchema,generateInputSchema:()=>generateInputSchema,generateSchema:()=>generateSchema});function resolveOptions(e){return{includeHidden:e?.includeHidden??!0,includePrompts:e?.includePrompts??!0}}const JSON_SCHEMA_DRAFT=`https://json-schema.org/draft/2020-12/schema`;function generateSchema(e,t,n){let r=resolveOptions(t),i=n??{name:e.name,version:e.version},a=e.defaultCommand!==void 0&&(r.includeHidden||!e.defaultCommand.hidden)?serializeCommand(e.defaultCommand,r,i):void 0;return{$schema:DEFINITION_SCHEMA_URL,schemaVersion:1,name:e.name,...e.version===void 0?{}:{version:e.version},...e.description===void 0?{}:{description:resolvePlainHelpDescription(e.description)},...a===void 0?{}:{defaultCommand:a},commands:e.commands.filter(e=>r.includeHidden||!e.hidden).map(e=>serializeCommand(e,r,i))}}function generateCommandSchema(e,t,n){let r=n??{name:e.name,version:void 0};return{schemaVersion:1,...serializeCommand(e,resolveOptions(t),r)}}function serializeCommand(e,t,n){let r={};for(let[n,i]of Object.entries(e.flags))r[n]=serializeFlag(i,t);return{name:e.name,...e.description===void 0?{}:{description:resolvePlainHelpDescription(e.description)},...e.aliases.length>0?{aliases:[...e.aliases]}:{},...e.hidden?{hidden:!0}:{},...e.examples.length>0?{examples:e.examples.map(e=>serializeExample(e,n))}:{},flags:r,args:e.args.map(e=>serializeArgEntry(e,t)),commands:e.commands.filter(e=>t.includeHidden||!e.hidden).map(e=>serializeCommand(e,t,n))}}function serializeFlag(e,t,n=!1){let r=getFlagAliasNames(e),i=e.stringConstraints,a=e.pathChecks,o=e.negation,s=n||e.sensitive;return{kind:e.kind,presence:e.presence,...!s&&isJsonSerializable(e.defaultValue)?{defaultValue:e.defaultValue}:{},...e.defaultDescription===void 0?{}:{defaultDescription:e.defaultDescription},...e.sensitive?{sensitive:!0}:{},...r.length>0?{aliases:[...r]}:{},...e.stdin===void 0?{}:{stdin:serializeStdin(e.stdin)},...e.envVar===void 0?{}:{envVar:e.envVar},...e.configPath===void 0?{}:{configPath:e.configPath},...e.description===void 0?{}:{description:resolvePlainHelpDescription(e.description)},...e.enumValues===void 0?{}:{enumValues:[...e.enumValues]},...e.numberConstraints===void 0?{}:{numberConstraints:{...e.numberConstraints}},...i===void 0?{}:{stringConstraints:serializeStringConstraints(i)},...e.elementSchema===void 0?{}:{elementSchema:serializeFlag(e.elementSchema,t,s)},...e.separator===void 0?{}:{separator:e.separator},...e.split===void 0?{}:{split:serializeSplit(e.split)},...e.duplicateKeys===`last`?{}:{duplicateKeys:e.duplicateKeys},...e.unique?{unique:!0}:{},...a===void 0?{}:{pathChecks:serializePathChecks(a)},...e.valueHint===void 0?{}:{valueHint:e.valueHint},...t.includePrompts&&e.prompt!==void 0?{prompt:serializePrompt(e.prompt)}:{},...e.deprecated===void 0?{}:{deprecated:e.deprecated},...e.propagate?{propagate:!0}:{},...o===void 0?{}:{negation:{...o.alias===void 0?{}:{alias:o.alias},...o.hidden?{hidden:!0}:{}}},...e.duplicates===`last`?{}:{duplicates:e.duplicates}}}function serializeStringConstraints(e){let t=e.pattern;return{...e.nonEmpty===void 0?{}:{nonEmpty:e.nonEmpty},...e.minLength===void 0?{}:{minLength:e.minLength},...e.maxLength===void 0?{}:{maxLength:e.maxLength},...t===void 0?{}:{pattern:{source:t.source,flags:t.flags}}}}function serializePathChecks(e){return{mustExist:e.mustExist,...e.type===void 0?{}:{type:e.type},...e.create?{create:!0}:{}}}function serializeArgEntry(e,t){return{name:e.name,...serializeArgValue(e.schema,t)}}function serializeArgValue(e,t){let n=e.stringConstraints,r=e.pathChecks;return{kind:e.kind,presence:e.presence,...e.variadic?{variadic:!0}:{},...e.stdin===void 0?{}:{stdin:serializeStdin(e.stdin)},...!e.sensitive&&isJsonSerializable(e.defaultValue)?{defaultValue:e.defaultValue}:{},...e.defaultDescription===void 0?{}:{defaultDescription:e.defaultDescription},...e.sensitive?{sensitive:!0}:{},...e.description===void 0?{}:{description:resolvePlainHelpDescription(e.description)},...e.envVar===void 0?{}:{envVar:e.envVar},...e.configPath===void 0?{}:{configPath:e.configPath},...e.enumValues===void 0?{}:{enumValues:[...e.enumValues]},...e.elementSchema===void 0?{}:{elementSchema:serializeArgElementValue(e.elementSchema)},...e.numberConstraints===void 0?{}:{numberConstraints:{...e.numberConstraints}},...n===void 0?{}:{stringConstraints:serializeStringConstraints(n)},...r===void 0?{}:{pathChecks:serializePathChecks(r)},...e.valueHint===void 0?{}:{valueHint:e.valueHint},...e.separator===void 0?{}:{separator:e.separator},...e.split===void 0?{}:{split:serializeSplit(e.split)},...e.duplicateKeys===`last`?{}:{duplicateKeys:e.duplicateKeys},...e.unique?{unique:!0}:{},...t.includePrompts&&e.prompt!==void 0?{prompt:serializePrompt(e.prompt)}:{},...e.deprecated===void 0?{}:{deprecated:e.deprecated}}}function serializeArgElementValue(e){if(e.kind===`keyValue`)throw TypeError(`Arg element schema kind 'keyValue' is not supported`);return{kind:e.kind,presence:`required`,...e.enumValues===void 0?{}:{enumValues:[...e.enumValues]},...e.numberConstraints===void 0?{}:{numberConstraints:{...e.numberConstraints}},...e.stringConstraints===void 0?{}:{stringConstraints:serializeStringConstraints(e.stringConstraints)},...e.pathChecks===void 0?{}:{pathChecks:serializePathChecks(e.pathChecks)},...e.valueHint===void 0?{}:{valueHint:e.valueHint}}}function serializeSplit(e){return{...e.env===void 0?{}:{env:{...e.env}},...e.stdin===void 0?{}:{stdin:{...e.stdin}}}}function serializeStdin(e){return{when:e.when,consume:e.consume,trim:e.trim}}function serializePrompt(e){let t={...e.sensitive===!0||e.kind===`password`?{sensitive:!0}:{}};switch(e.kind){case`input`:return{kind:e.kind,message:e.message,...t,...e.empty===void 0?{}:{empty:e.empty},...e.trim===void 0?{}:{trim:e.trim},...e.placeholder===void 0?{}:{placeholder:e.placeholder}};case`password`:return{kind:e.kind,message:e.message,...t,...e.empty===void 0?{}:{empty:e.empty}};case`select`:return{kind:e.kind,message:e.message,...t,...e.choices===void 0?{}:{choices:e.choices.map(serializeChoice)}};case`multiselect`:return{kind:e.kind,message:e.message,...t,...e.choices===void 0?{}:{choices:e.choices.map(serializeChoice)},...e.min===void 0?{}:{min:e.min},...e.max===void 0?{}:{max:e.max}};case`confirm`:return{kind:e.kind,message:e.message,...t}}}function serializeChoice(e){return{value:e.value,...e.label===void 0?{}:{label:e.label},...e.description===void 0?{}:{description:e.description}}}function serializeExample(e,t){return{command:resolveExampleCommand(e.command,t),...e.description===void 0?{}:{description:e.description}}}function generateInputSchema(e,t){let n=resolveOptions(t);if(isCommandSchema(e))return{$schema:JSON_SCHEMA_DRAFT,...commandToInputSchema(e)};let r=[];e.defaultCommand!==void 0&&(n.includeHidden||!e.defaultCommand.hidden)&&collectInputBranches(e.defaultCommand,``,r,n);for(let t of e.commands)t!==e.defaultCommand&&t.name!==e.defaultCommand?.name&&(n.includeHidden||!t.hidden)&&collectInputBranches(t,``,r,n);let[i]=r;if(r.length===1&&i!==void 0)return{$schema:JSON_SCHEMA_DRAFT,...stripCommandDiscriminator(i)};if(r.length>0){let t=e.defaultCommand!==void 0&&(n.includeHidden||!e.defaultCommand.hidden)?e.defaultCommand.name:void 0,i=t===void 0?r:r.map(e=>getBranchCommandDiscriminator(e)===t?stripCommandDiscriminator(e):e);return{$schema:JSON_SCHEMA_DRAFT,oneOf:i}}return{$schema:JSON_SCHEMA_DRAFT,type:`object`}}function isCommandSchema(e){return`flags`in e&&`args`in e&&`hasAction`in e}function collectInputBranches(e,t,n,r){let i=t?`${t}.${e.name}`:e.name;e.hasAction&&n.push(commandToInputSchema(e,i));for(let t of e.commands)(r.includeHidden||!t.hidden)&&collectInputBranches(t,i,n,r)}function commandToInputSchema(e,t){let n={},r=[];t!==void 0&&(n.command={const:t},r.push(`command`));for(let[t,i]of Object.entries(e.flags))n[t]=flagToJsonSchemaType(i),i.presence===`required`&&r.push(t);for(let t of e.args)n[t.name]=argToJsonSchemaType(t.schema),t.schema.presence===`required`&&r.push(t.name);return{type:`object`,properties:n,additionalProperties:!1,...r.length>0?{required:r}:{}}}function stripCommandDiscriminator(e){let{command:t,...n}=e.properties,r=e.required?.filter(e=>e!==`command`);return{type:e.type,properties:n,additionalProperties:e.additionalProperties,...r!==void 0&&r.length>0?{required:r}:{}}}function getBranchCommandDiscriminator(e){let t=e.properties.command;if(t===void 0)return;let n=t.const;return typeof n==`string`?n:void 0}function stringConstraintsToJsonSchemaProperties(e){let t={},n=e?.nonEmpty===!0?Math.max(e.minLength??1,1):e?.minLength;return n!==void 0&&(t.minLength=n),e?.maxLength!==void 0&&(t.maxLength=e.maxLength),e?.pattern!==void 0&&(t.pattern=e.pattern.source),t}function flagToJsonSchemaType(e,t=!1){let n={},r=t||e.sensitive;switch(e.kind){case`string`:n.type=`string`,Object.assign(n,stringConstraintsToJsonSchemaProperties(e.stringConstraints));break;case`number`:{let t=e.numberConstraints;n.type=t?.int===!0?`integer`:`number`,t?.min!==void 0&&(n.minimum=t.min),t?.max!==void 0&&(n.maximum=t.max);break}case`boolean`:n.type=`boolean`;break;case`enum`:n.type=`string`,e.enumValues!==void 0&&(n.enum=[...e.enumValues]);break;case`array`:n.type=`array`,e.elementSchema!==void 0&&(n.items=flagToJsonSchemaType(e.elementSchema,r));break;case`custom`:break;case`count`:n.type=`integer`,n.minimum=0;break;case`keyValue`:n.type=`object`,n.additionalProperties=e.elementSchema===void 0?{type:`string`}:flagToJsonSchemaType(e.elementSchema,r)}return e.description!==void 0&&(n.description=resolvePlainHelpDescription(e.description)),e.sensitive&&(n.writeOnly=!0),!r&&isJsonSerializable(e.defaultValue)&&(n.default=e.defaultValue),e.deprecated!==void 0&&(n.deprecated=e.deprecated),n}function argToJsonSchemaType(e){let t=argKindToType(e),n=e.variadic&&e.kind!==`keyValue`?{type:`array`,items:t}:{...t};return e.description!==void 0&&(n.description=resolvePlainHelpDescription(e.description)),e.sensitive&&(n.writeOnly=!0),!e.sensitive&&isJsonSerializable(e.defaultValue)&&(n.default=e.defaultValue),e.deprecated!==void 0&&(n.deprecated=e.deprecated),n}function argKindToType(e){switch(e.kind){case`string`:return{type:`string`,...stringConstraintsToJsonSchemaProperties(e.stringConstraints)};case`number`:{let t=e.numberConstraints,n={type:t?.int===!0?`integer`:`number`};return t?.min!==void 0&&(n.minimum=t.min),t?.max!==void 0&&(n.maximum=t.max),n}case`enum`:{let t={type:`string`};return e.enumValues!==void 0&&(t.enum=[...e.enumValues]),t}case`boolean`:return{type:`boolean`};case`keyValue`:return{type:`object`,additionalProperties:e.elementSchema===void 0?{type:`string`}:argKindToType(e.elementSchema)};case`custom`:return{}}}function isJsonSerializable(e,t=/* @__PURE__ */ new WeakSet){if(e===void 0)return!1;if(e===null)return!0;let n=typeof e;if(n===`string`||n===`boolean`)return!0;if(n===`number`)return Number.isFinite(e);if(n===`function`||n===`symbol`||n===`bigint`)return!1;if(Array.isArray(e)){if(t.has(e))return!1;t.add(e);try{return e.every(e=>isJsonSerializable(e,t))}finally{t.delete(e)}}if(n===`object`){let n=e;if(!isPlainJsonObject(n)||t.has(n))return!1;t.add(n);try{return Object.values(n).every(e=>isJsonSerializable(e,t))}finally{t.delete(n)}}return!1}function isPlainJsonObject(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function withDefinitionDescriptions(e,t){let n=e.properties,r=typeof n==`object`&&n&&isPlainJsonObject(n)&&t.properties!==void 0?Object.fromEntries(Object.entries(n).map(([e,n])=>{let r=t.properties?.[e];return r===void 0||typeof n!=`object`||!n||!isPlainJsonObject(n)?[e,n]:[e,withDefinitionDescriptions(n,r)]})):void 0;return{...e,...t.description===void 0?{}:{description:t.description},...r===void 0?{}:{properties:r}}}function withDefinitionMetaSchemaDescriptions(e,t){let n=withDefinitionDescriptions(e,t.root),r=n.$defs;return typeof r!=`object`||!r||!isPlainJsonObject(r)?n:{...n,$defs:Object.fromEntries(Object.entries(r).map(([e,n])=>{let r=t.defs[e];return r===void 0||typeof n!=`object`||!n||!isPlainJsonObject(n)?[e,n]:[e,withDefinitionDescriptions(n,r)]}))}}const commandFragmentProperties={name:{type:`string`},description:{type:`string`},aliases:{type:`array`,items:{type:`string`}},hidden:{const:!0},examples:{type:`array`,items:{$ref:`#/$defs/example`}},flags:{type:`object`,additionalProperties:{$ref:`#/$defs/flag`}},args:{type:`array`,items:{$ref:`#/$defs/arg`}},commands:{type:`array`,items:{$ref:`#/$defs/command`}}},argValueFragmentProperties={kind:{enum:[`string`,`number`,`boolean`,`enum`,`custom`,`keyValue`]},presence:{enum:[`required`,`optional`,`defaulted`]},variadic:{const:!0},stdin:{$ref:`#/$defs/stdin`},defaultValue:{},defaultDescription:{oneOf:[{type:`string`},{const:!1}]},sensitive:{const:!0},description:{type:`string`},envVar:{type:`string`},configPath:{type:`string`},enumValues:{type:`array`,items:{type:`string`}},elementSchema:{$ref:`#/$defs/argElement`},numberConstraints:{$ref:`#/$defs/numberConstraints`},stringConstraints:{$ref:`#/$defs/stringConstraints`},pathChecks:{$ref:`#/$defs/pathChecks`},valueHint:{type:`string`},separator:{type:`string`,minLength:1},split:{$ref:`#/$defs/split`},duplicateKeys:{enum:[...DUPLICATE_KEYS]},unique:{const:!0},prompt:{$ref:`#/$defs/prompt`},deprecated:{oneOf:[{type:`string`},{const:!0}]}},argElementFragmentProperties={kind:{enum:[`string`,`number`,`boolean`,`enum`,`custom`]},presence:{const:`required`},enumValues:{type:`array`,items:{type:`string`}},numberConstraints:{$ref:`#/$defs/numberConstraints`},stringConstraints:{$ref:`#/$defs/stringConstraints`},pathChecks:{$ref:`#/$defs/pathChecks`},valueHint:{type:`string`}},flagElementFragmentProperties={kind:{enum:[`string`,`number`,`boolean`,`enum`,`array`,`custom`,`count`,`keyValue`]},presence:{enum:[`optional`,`required`,`defaulted`]},defaultValue:{},aliases:{type:`array`,items:{type:`string`}},stdin:{$ref:`#/$defs/stdin`},envVar:{type:`string`},configPath:{type:`string`},description:{type:`string`},enumValues:{type:`array`,items:{type:`string`}},numberConstraints:{$ref:`#/$defs/numberConstraints`},stringConstraints:{$ref:`#/$defs/stringConstraints`},elementSchema:{$ref:`#/$defs/flagElement`},separator:{type:`string`,minLength:1},split:{$ref:`#/$defs/split`},duplicateKeys:{enum:[...DUPLICATE_KEYS]},unique:{const:!0},pathChecks:{$ref:`#/$defs/pathChecks`},valueHint:{type:`string`},prompt:{$ref:`#/$defs/prompt`},deprecated:{oneOf:[{type:`string`},{const:!0}]},propagate:{const:!0},negation:{$ref:`#/$defs/negation`},duplicates:{enum:[`last`,`first`,`error`]}},flagFragmentProperties={...flagElementFragmentProperties,defaultDescription:{oneOf:[{type:`string`},{const:!1}]},sensitive:{const:!0}},definitionMetaSchema=withDefinitionMetaSchemaDescriptions({$schema:JSON_SCHEMA_DRAFT,$id:DEFINITION_SCHEMA_URL,title:`@kjanat/dreamcli definition schema`,description:`Describes the structure of a CLI built with dreamcli — commands, flags, args, types, constraints, env bindings, and prompts.`,type:`object`,additionalProperties:!1,properties:{$schema:{const:DEFINITION_SCHEMA_URL},schemaVersion:{const:1},name:{type:`string`},version:{type:`string`},description:{type:`string`},defaultCommand:{$ref:`#/$defs/command`},commands:{type:`array`,items:{$ref:`#/$defs/command`}}},required:[`$schema`,`schemaVersion`,`name`,`commands`],$defs:{command:{type:`object`,additionalProperties:!1,properties:commandFragmentProperties,required:[`name`,`flags`,`args`,`commands`]},commandDocument:{type:`object`,additionalProperties:!1,properties:{schemaVersion:{const:1},...commandFragmentProperties},required:[`schemaVersion`,`name`,`flags`,`args`,`commands`]},flag:{type:`object`,additionalProperties:!1,properties:flagFragmentProperties,required:[`kind`,`presence`]},flagElement:{type:`object`,additionalProperties:!1,properties:flagElementFragmentProperties,required:[`kind`,`presence`]},stdin:{type:`object`,additionalProperties:!1,properties:{when:{enum:[`dash`,`missing`,`dash-or-missing`]},consume:{enum:[`exclusive`,`broadcast`]},trim:{type:`boolean`}},required:[`when`,`consume`]},split:{type:`object`,additionalProperties:!1,properties:{env:{$ref:`#/$defs/splitPolicy`},stdin:{$ref:`#/$defs/splitPolicy`}}},splitPolicy:{type:`object`,additionalProperties:!1,properties:{format:{enum:[`whole`,`delimiter`,`lines`,`json`]},delimiter:{type:`string`,minLength:1}},required:[`format`],oneOf:[{properties:{format:{const:`delimiter`}},required:[`format`,`delimiter`]},{properties:{format:{enum:[`whole`,`lines`,`json`]}},not:{required:[`delimiter`]}}]},negation:{type:`object`,additionalProperties:!1,properties:{alias:{type:`string`},hidden:{const:!0}}},numberConstraints:{type:`object`,additionalProperties:!1,properties:{min:{type:`number`},max:{type:`number`},int:{type:`boolean`},finite:{type:`boolean`}}},stringConstraints:{type:`object`,additionalProperties:!1,properties:{nonEmpty:{type:`boolean`},minLength:{type:`integer`,minimum:0},maxLength:{type:`integer`,minimum:0},pattern:{type:`object`,additionalProperties:!1,properties:{source:{type:`string`},flags:{type:`string`}},required:[`source`,`flags`]}}},pathChecks:{type:`object`,additionalProperties:!1,properties:{mustExist:{type:`boolean`},type:{enum:[`file`,`directory`]},create:{const:!0}},required:[`mustExist`]},argElement:{type:`object`,additionalProperties:!1,properties:argElementFragmentProperties,required:[`kind`,`presence`]},arg:{type:`object`,additionalProperties:!1,properties:{name:{type:`string`},...argValueFragmentProperties},required:[`name`,`kind`,`presence`],anyOf:[{not:{required:[`elementSchema`]}},{properties:{kind:{const:`keyValue`}},required:[`kind`]}]},prompt:{type:`object`,additionalProperties:!1,properties:{kind:{enum:[`confirm`,`input`,`password`,`select`,`multiselect`]},message:{type:`string`},placeholder:{type:`string`},trim:{type:`boolean`},empty:{enum:[`skip`,`accept`,`retry`]},sensitive:{const:!0},choices:{type:`array`,items:{$ref:`#/$defs/choice`}},min:{type:`integer`},max:{type:`integer`}},required:[`kind`,`message`]},choice:{type:`object`,additionalProperties:!1,properties:{value:{type:`string`},label:{type:`string`},description:{type:`string`}},required:[`value`]},example:{type:`object`,additionalProperties:!1,properties:{command:{type:`string`},description:{type:`string`}},required:[`command`]}}},definitionMetaSchemaDescriptions);export{json_schema_exports as a,generateSchema as i,generateCommandSchema as n,generateInputSchema as r,definitionMetaSchema as t};
|
package/dist/json-schema.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as definitionMetaSchema, D as DEFINITION_SCHEMA_URL, E as generateSchema, O as DEFINITION_SCHEMA_VERSION, S as StdinBindingFragmentV1, T as generateInputSchema, _ as JsonSchemaOptions, a as CommandDefinitionFragmentV1, b as SourceSplitFragmentV1, c as ExampleDefinitionFragmentV1, d as FlagNegationFragmentV1, f as FlagPathChecksFragmentV1, g as InputSchemaProperty, h as InputSchemaDocument, i as CommandDefinitionDocumentV1, l as FlagDefinitionFragmentV1, m as InputSchemaBranch, n as ArgElementFragmentV1, o as DefinitionDocument, p as FlagStringConstraintsFragmentV1, r as CommandDefinitionDocument, s as DefinitionDocumentV1, t as ArgDefinitionFragmentV1, u as FlagElementFragmentV1, v as PromptChoiceFragmentV1, w as generateCommandSchema, x as SplitPolicyFragmentV1, y as PromptDefinitionFragmentV1 } from "./index-
|
|
1
|
+
import { C as definitionMetaSchema, D as DEFINITION_SCHEMA_URL, E as generateSchema, O as DEFINITION_SCHEMA_VERSION, S as StdinBindingFragmentV1, T as generateInputSchema, _ as JsonSchemaOptions, a as CommandDefinitionFragmentV1, b as SourceSplitFragmentV1, c as ExampleDefinitionFragmentV1, d as FlagNegationFragmentV1, f as FlagPathChecksFragmentV1, g as InputSchemaProperty, h as InputSchemaDocument, i as CommandDefinitionDocumentV1, l as FlagDefinitionFragmentV1, m as InputSchemaBranch, n as ArgElementFragmentV1, o as DefinitionDocument, p as FlagStringConstraintsFragmentV1, r as CommandDefinitionDocument, s as DefinitionDocumentV1, t as ArgDefinitionFragmentV1, u as FlagElementFragmentV1, v as PromptChoiceFragmentV1, w as generateCommandSchema, x as SplitPolicyFragmentV1, y as PromptDefinitionFragmentV1 } from "./index-C5CYWtxn.mjs";
|
|
2
2
|
export { type ArgDefinitionFragmentV1, type ArgElementFragmentV1, type CommandDefinitionDocument, type CommandDefinitionDocumentV1, type CommandDefinitionFragmentV1, DEFINITION_SCHEMA_URL, DEFINITION_SCHEMA_VERSION, type DefinitionDocument, type DefinitionDocumentV1, type ExampleDefinitionFragmentV1, type FlagDefinitionFragmentV1, type FlagElementFragmentV1, type FlagNegationFragmentV1, type FlagPathChecksFragmentV1, type FlagStringConstraintsFragmentV1, type InputSchemaBranch, type InputSchemaDocument, type InputSchemaProperty, type JsonSchemaOptions, type PromptChoiceFragmentV1, type PromptDefinitionFragmentV1, type SourceSplitFragmentV1, type SplitPolicyFragmentV1, type StdinBindingFragmentV1, definitionMetaSchema, generateCommandSchema, generateInputSchema, generateSchema };
|
package/dist/json-schema.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{a as DEFINITION_SCHEMA_URL,o as DEFINITION_SCHEMA_VERSION}from"./core-B4Twhd48.mjs";import{i as generateSchema,n as generateCommandSchema,r as generateInputSchema,t as definitionMetaSchema}from"./json-schema-DVyfq4bA.mjs";export{DEFINITION_SCHEMA_URL,DEFINITION_SCHEMA_VERSION,definitionMetaSchema,generateCommandSchema,generateInputSchema,generateSchema};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{t as __exportAll}from"./rolldown-runtime-G4Kt5YOX.mjs";var package_json_exports=/* @__PURE__ */ __exportAll({discoverManifest:()=>discoverManifest,inferCliName:()=>inferCliName});function isPlainObject(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function parentDir(e){let t=e.lastIndexOf(`/`),n=e.lastIndexOf(`\\`),r=Math.max(t,n),i=n>t?`\\`:`/`;if(r<0)return;if(r===0)return e.length>1?i:void 0;let a=e.slice(0,r);if(a.length===2&&a[1]===`:`){let t=`${a}${i}`;return t===e?void 0:t}return a}function joinPath(e,t){let n=e.includes(`\\`)?`\\`:`/`;return e.endsWith(n)?`${e}${t}`:`${e}${n}${t}`}const DEFAULT_MANIFEST_FILES=[`package.json`];function manifestHasMetadata(e){return e.name!==void 0||e.version!==void 0||e.description!==void 0||e.bin!==void 0||e.homepage!==void 0||e.repository!==void 0}async function discoverManifest(e,t={}){let n=t.files??DEFAULT_MANIFEST_FILES,r=t.startDir??e.cwd;for(;r!==void 0;){for(let t of n){let n=null;try{n=await e.readFile(joinPath(r,t))}catch{}if(n!==null){let e=parsePackageJson(n);if(e!==null&&manifestHasMetadata(e))return e}}r=parentDir(r)}return null}function isJsonWhitespace(e){return e===` `||e===` `||e===`
|
|
2
|
+
`||e===`\r`}function stripJsonc(e){let t=``,n=!1,r=!1;for(let i=0;i<e.length;i+=1){let a=e[i]??``;if(n)t+=a,r?r=!1:a===`\\`?r=!0:a===`"`&&(n=!1);else if(a===`"`)n=!0,t+=a;else if(a===`/`&&e[i+1]===`/`){for(i+=2;i<e.length&&e[i]!==`
|
|
3
|
+
`;)i+=1;--i}else if(a===`/`&&e[i+1]===`*`){for(i+=2;i<e.length&&(e[i]!==`*`||e[i+1]!==`/`);)i+=1;i+=1}else t+=a}let i=``;n=!1,r=!1;for(let e=0;e<t.length;e+=1){let a=t[e]??``;if(n)i+=a,r?r=!1:a===`\\`?r=!0:a===`"`&&(n=!1);else if(a===`"`)n=!0,i+=a;else{if(a===`,`){let n=e+1;for(;n<t.length&&isJsonWhitespace(t[n]??``);)n+=1;let r=t[n];if(r===`}`||r===`]`)continue}i+=a}}return i}function parsePackageJson(e){let t;try{t=JSON.parse(e)}catch{try{t=JSON.parse(stripJsonc(e))}catch{return null}}try{if(!isPlainObject(t))return null;let e=typeof t.name==`string`?t.name:void 0,n=typeof t.version==`string`?t.version:void 0,r=typeof t.description==`string`?t.description:void 0,i=parseBinField(t.bin),a=typeof t.homepage==`string`?t.homepage:void 0,o=parseRepositoryField(t.repository);return{...e===void 0?{}:{name:e},...n===void 0?{}:{version:n},...r===void 0?{}:{description:r},...i===void 0?{}:{bin:i},...a===void 0?{}:{homepage:a},...o===void 0?{}:{repository:o}}}catch{return null}}function parseBinField(e){if(typeof e==`string`)return e;if(!isPlainObject(e))return;let t={};for(let[n,r]of Object.entries(e)){if(typeof r!=`string`)return;t[n]=r}return t}function parseRepositoryField(e){if(typeof e==`string`)return e;if(!isPlainObject(e))return;let t=typeof e.type==`string`?e.type:void 0,n=typeof e.url==`string`?e.url:void 0,r=typeof e.directory==`string`?e.directory:void 0;if(t!==void 0||n!==void 0||r!==void 0)return{...t===void 0?{}:{type:t},...n===void 0?{}:{url:n},...r===void 0?{}:{directory:r}}}function inferCliName(e,t={}){if(typeof e.bin==`object`){let t=Object.keys(e.bin);if(t.length>0&&t[0]!==void 0)return t[0]}if(e.name!==void 0){if(t.stripScope===!1)return e.name;let n=e.name.indexOf(`/`);return n>=0?e.name.slice(n+1):e.name}}export{inferCliName as n,package_json_exports as r,discoverManifest as t};
|
package/dist/prompt.d.mts
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
|
-
import { a as WriteFn, c as ResolvedMultiselectPromptConfig, d as resolvePromptConfig, l as ResolvedPromptConfig, o as PromptEngine, s as ReadFn, u as ResolvedSelectPromptConfig } from "./index-
|
|
1
|
+
import { An as PasswordPromptConfig, G as prompt, U as Ask, W as InferPrompt, a as WriteFn, c as ResolvedMultiselectPromptConfig, d as resolvePromptConfig, l as ResolvedPromptConfig, o as PromptEngine, s as ReadFn, u as ResolvedSelectPromptConfig } from "./index-B6oD4_8b.mjs";
|
|
2
|
+
import { t as CLIError } from "./index-B3_9MlHz.mjs";
|
|
3
|
+
//#region src/core/prompt/errors.d.ts
|
|
4
|
+
/** The user stopped an interaction. Unlike a skipped schema prompt, this aborts execution. */
|
|
5
|
+
export declare class PromptCancelledError extends CLIError {
|
|
6
|
+
/** Structured error class name. */
|
|
7
|
+
readonly name = "PromptCancelledError";
|
|
8
|
+
/** Cancellation source, when available from the engine. */
|
|
9
|
+
readonly reason: 'interrupt' | 'escape' | 'eof' | 'cancel';
|
|
10
|
+
/** Create an interaction cancellation with the conventional interrupt exit code. */
|
|
11
|
+
constructor(reason?: PromptCancelledError['reason']);
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/core/prompt/session.d.ts
|
|
15
|
+
/** Injectable host for a standalone interaction. No host is opened implicitly. */
|
|
16
|
+
interface PromptSessionOptions {
|
|
17
|
+
/** Engine also used for schema-bound prompts in a command invocation. */
|
|
18
|
+
readonly prompter?: PromptEngine;
|
|
19
|
+
/** Validation feedback writer; CLI sessions use stderr. */
|
|
20
|
+
readonly write?: WriteFn;
|
|
21
|
+
}
|
|
22
|
+
/** Reusable typed interaction entry point. */
|
|
23
|
+
interface PromptSession {
|
|
24
|
+
/** Ask one question, rejecting on cancellation or unavailable interaction. */
|
|
25
|
+
readonly ask: Ask;
|
|
26
|
+
}
|
|
27
|
+
/** Create an isolated interaction session over a custom, terminal, or scripted engine. */
|
|
28
|
+
export declare function createPromptSession(options: PromptSessionOptions): PromptSession;
|
|
29
|
+
//#endregion
|
|
2
30
|
//#region src/core/prompt/terminal.d.ts
|
|
31
|
+
/** Optional terminal capabilities. Hidden input must never fall back to an ordinary reader. */
|
|
32
|
+
interface TerminalPrompterOptions {
|
|
33
|
+
/** Read without terminal echo; restore terminal state before settling. */
|
|
34
|
+
readonly readSecret?: ReadFn;
|
|
35
|
+
}
|
|
3
36
|
/**
|
|
4
37
|
* Create a prompt engine backed by line-based terminal I/O.
|
|
5
38
|
*
|
|
@@ -43,6 +76,6 @@ import { a as WriteFn, c as ResolvedMultiselectPromptConfig, d as resolvePromptC
|
|
|
43
76
|
* const prompter = createTerminalPrompter(read, write);
|
|
44
77
|
* ```
|
|
45
78
|
*/
|
|
46
|
-
declare function createTerminalPrompter(read: ReadFn, write: WriteFn): PromptEngine;
|
|
79
|
+
declare function createTerminalPrompter(read: ReadFn, write: WriteFn, options?: TerminalPrompterOptions): PromptEngine;
|
|
47
80
|
//#endregion
|
|
48
|
-
export { type PromptEngine, type ReadFn, type ResolvedMultiselectPromptConfig, type ResolvedPromptConfig, type ResolvedSelectPromptConfig, createTerminalPrompter, resolvePromptConfig };
|
|
81
|
+
export { type Ask, type InferPrompt, type PasswordPromptConfig, type PromptEngine, type PromptSession, type PromptSessionOptions, type ReadFn, type ResolvedMultiselectPromptConfig, type ResolvedPromptConfig, type ResolvedSelectPromptConfig, type TerminalPrompterOptions, createTerminalPrompter, prompt, resolvePromptConfig };
|
package/dist/prompt.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{T as PromptCancelledError,r as prompt,w as resolvePromptConfig}from"./core-B4Twhd48.mjs";import{t as createPromptSession}from"./session-CQsnVijE.mjs";import{t as createTerminalPrompter}from"./terminal-cbye9mKF.mjs";export{PromptCancelledError,createPromptSession,createTerminalPrompter,prompt,resolvePromptConfig};
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as RuntimeAdapter, r as TerminalSize, t as ExitError } from "./adapter-
|
|
2
|
-
import { a as createAdapter, c as Runtime, i as createDenoAdapter, l as detectRuntime, n as createNodeAdapter, o as GlobalForDetect, r as DenoNamespace, s as RUNTIMES, t as NodeProcess } from "./index-
|
|
1
|
+
import { n as RuntimeAdapter, r as TerminalSize, t as ExitError } from "./adapter-DsmEc0WO.mjs";
|
|
2
|
+
import { a as createAdapter, c as Runtime, i as createDenoAdapter, l as detectRuntime, n as createNodeAdapter, o as GlobalForDetect, r as DenoNamespace, s as RUNTIMES, t as NodeProcess } from "./index-CaRNJH2R.mjs";
|
|
3
3
|
export { type DenoNamespace, ExitError, type GlobalForDetect, type NodeProcess, RUNTIMES, type Runtime, type RuntimeAdapter, type TerminalSize, createAdapter, createDenoAdapter, createNodeAdapter, detectRuntime };
|
package/dist/runtime.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export{x as ExitError,v as RUNTIMES,g as createAdapter,b as createDenoAdapter,_ as createNodeAdapter,y as detectRuntime}from"./core-B4Twhd48.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as __exportAll}from"./rolldown-runtime-G4Kt5YOX.mjs";import{T as PromptCancelledError,n as prepareTextAnswer,tt as CLIError,w as resolvePromptConfig}from"./core-B4Twhd48.mjs";var session_exports=/* @__PURE__ */ __exportAll({createPromptSession:()=>createPromptSession});function createPromptSession(e){let t=!1;return{ask:async n=>{if(t)throw new CLIError(`A prompt is already active in this session`,{code:`PROMPT_BUSY`});if(e.prompter===void 0)throw new CLIError(`Interactive input is unavailable`,{code:`PROMPT_UNAVAILABLE`,suggest:`Supply credentials through command arguments, environment, or config, or run in an interactive terminal`});t=!0;try{let t=resolvePromptConfig(n,void 0),r={...t};(r.kind===`input`||r.kind===`password`)&&(delete r.validate,r.empty=`accept`,r.kind===`input`&&(r.trim=!1,r.default!==void 0&&(r.sensitive||(r.placeholder=[r.placeholder,`default: ${r.default}`].filter(e=>e!==void 0).join(`, `)),delete r.default)));for(let i=0;i<10;i++){let i=await e.prompter.promptOne(r);if(!i.answered)throw i.reason===`invalid`?new CLIError(`Too many invalid prompt answers`,{code:`PROMPT_INVALID`,exitCode:2}):new PromptCancelledError;let a=i.value,o;if(n.kind===`input`||n.kind===`password`){if(typeof a!=`string`)o=`Please enter text.`;else{let e=await prepareTextAnswer(n,a);e.ok?a=e.value:o=e.message}}else if(n.kind===`confirm`)typeof a!=`boolean`&&(o=`Please answer yes or no.`);else{let e=t.kind===`select`||t.kind===`multiselect`?t.choices:[];if(n.kind===`select`)e.some(e=>e.value===a)||(o=`Please select an available choice.`);else if(!Array.isArray(a)||!a.every(t=>e.some(e=>e.value===t)))o=`Please select available choices.`;else{let e=[...new Set(a)];a=e,n.min!==void 0&&e.length<n.min&&(o=`Please select at least ${n.min}.`),n.max!==void 0&&e.length>n.max&&(o=`Please select at most ${n.max}.`)}}if(o===void 0)return a;e.write?.(`${o}\n`)}throw new CLIError(`Too many invalid prompt answers`,{code:`PROMPT_INVALID`,exitCode:2})}finally{t=!1}}}}export{session_exports as n,createPromptSession as t};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{t as __exportAll}from"./rolldown-runtime-G4Kt5YOX.mjs";import{T as PromptCancelledError,n as prepareTextAnswer,tt as CLIError}from"./core-B4Twhd48.mjs";var terminal_exports=/* @__PURE__ */ __exportAll({createTerminalPrompter:()=>createTerminalPrompter});function createTerminalPrompter(e,t,n){return{promptOne(r){switch(r.kind){case`confirm`:return promptConfirm(r,e,t);case`input`:return promptInput(r,e,t);case`password`:{let e=n?.readSecret;return e===void 0?Promise.reject(new CLIError(`Hidden password input is unavailable`,{code:`PROMPT_UNSUPPORTED`,suggest:`Use a runtime adapter or prompt engine with hidden-input support`})):promptInput(r,async()=>{try{let t=await e();if(t===null)throw new PromptCancelledError(`eof`);return t}finally{t(`
|
|
2
|
+
`)}},t)}case`select`:return promptSelect(r,e,t);case`multiselect`:return promptMultiselect(r,e,t)}}}}async function promptConfirm(e,t,n){let r=e.default??!0,i=0;for(;i<10;){let a=e.sensitive?`(y/n)`:r?`(Y/n)`:`(y/N)`;n(`${e.message} ${a} `);let o=await t();if(o===null)return{answered:!1};let s=o.trim().toLowerCase();if(s===``)return{answered:!0,value:r};if(s===`y`||s===`yes`)return{answered:!0,value:!0};if(s===`n`||s===`no`)return{answered:!0,value:!1};n(`Please answer y or n.
|
|
3
|
+
`),i+=1}return n(`Too many invalid attempts.
|
|
4
|
+
`),{answered:!1,reason:`invalid`}}async function promptInput(e,t,n){let r=0,i=[];e.kind===`input`&&e.placeholder!==void 0&&i.push(e.placeholder),e.kind===`input`&&e.default!==void 0&&!e.sensitive&&i.push(`default: ${e.default}`);let a=i.length>0?` (${i.join(`, `)})`:``;for(;r<10;){n(`${e.message}${a}: `);let i=await t();if(i===null)return{answered:!1};let o=await prepareTextAnswer(e,i);if(o.ok)return{answered:!0,value:o.value};n(`${o.message}\n`),r+=1}if(e.kind===`password`)throw new CLIError(`Too many invalid prompt answers`,{code:`PROMPT_INVALID`,exitCode:2});return n(`Too many invalid attempts.
|
|
5
|
+
`),{answered:!1,reason:`invalid`}}async function promptSelect(e,t,n){let r=0;for(;r<10;){n(`${e.message}\n`);for(let t=0;t<e.choices.length;t+=1){let r=e.choices[t];if(r===void 0)continue;let i=r.label??r.value,a=r.description===void 0?``:` - ${r.description}`;n(` ${t+1}) ${i}${a}\n`)}n(`Enter number: `);let i=await t();if(i===null)return{answered:!1};let a=Number(i.trim());if(Number.isNaN(a)||!Number.isInteger(a)||a<1||a>e.choices.length){n(`Please enter a number between 1 and ${e.choices.length}.\n`),r+=1;continue}let o=e.choices[a-1];if(o===void 0)r+=1;else return{answered:!0,value:o.value}}return n(`Too many invalid attempts.
|
|
6
|
+
`),{answered:!1,reason:`invalid`}}async function promptMultiselect(e,t,n){let r=0;for(;r<10;){n(`${e.message}\n`);for(let t=0;t<e.choices.length;t+=1){let r=e.choices[t];if(r===void 0)continue;let i=r.label??r.value,a=r.description===void 0?``:` - ${r.description}`;n(` ${t+1}) ${i}${a}\n`)}n(`Enter numbers separated by commas (e.g. 1,3${e.min===void 0?``:`, min: ${e.min}`}${e.max===void 0?``:`, max: ${e.max}`}): `);let i=await t();if(i===null)return{answered:!1};let a=i.trim();if(a===``){if(e.min!==void 0&&e.min>0){n(`Please select at least ${e.min}.\n`),r+=1;continue}return{answered:!0,value:[]}}let o=a.split(`,`).map(e=>e.trim()),s=[],c=!0;for(let t of o){let r=Number(t);if(Number.isNaN(r)||!Number.isInteger(r)||r<1||r>e.choices.length){n(`Invalid selection '${t}'. Use numbers between 1 and ${e.choices.length}.\n`),c=!1;break}s.push(r)}if(!c){r+=1;continue}let l=[...new Set(s)];if(e.min!==void 0&&l.length<e.min)n(`Please select at least ${e.min}.\n`),r+=1;else if(e.max!==void 0&&l.length>e.max)n(`Please select at most ${e.max}.\n`),r+=1;else return{answered:!0,value:l.map(t=>e.choices[t-1]?.value??``)}}return n(`Too many invalid attempts.
|
|
7
|
+
`),{answered:!1,reason:`invalid`}}export{terminal_exports as n,createTerminalPrompter as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as __exportAll}from"./rolldown-runtime-G4Kt5YOX.mjs";import{T as PromptCancelledError,n as prepareTextAnswer,tt as CLIError}from"./core-B4Twhd48.mjs";var test_prompter_exports=/* @__PURE__ */ __exportAll({PROMPT_CANCEL:()=>PROMPT_CANCEL,createTestPrompter:()=>createTestPrompter});const PROMPT_CANCEL=Symbol.for(`dreamcli.prompt.cancel`);function createTestPrompter(e,t){let n=0;return{async promptOne(r){for(let i=0;i<10;i++){if(n>=e.length)return t?.onExhausted===`cancel`?Promise.resolve({answered:!1}):Promise.reject(/* @__PURE__ */ Error(`Test prompter exhausted: expected at most ${e.length} prompts, got prompt #${n+1}`));let i=e[n];if(n+=1,i===PROMPT_CANCEL){if(r.kind===`password`)throw new PromptCancelledError;return Promise.resolve({answered:!1})}if((r.kind===`input`||r.kind===`password`)&&typeof i==`string`){let e=await prepareTextAnswer(r,i);if(!e.ok&&(r.kind===`password`||e.reason===`empty`))continue;return e.ok?{answered:!0,value:e.value}:{answered:!1}}return Promise.resolve({answered:!0,value:i})}if(r.kind!==`password`)return{answered:!1,reason:`invalid`};throw new CLIError(`Too many invalid prompt answers`,{code:`PROMPT_INVALID`,exitCode:2})}}}export{createTestPrompter as n,test_prompter_exports as r,PROMPT_CANCEL as t};
|
package/dist/testkit.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { a as createTestAdapter, i as TestAdapterOptions } from "./adapter-
|
|
4
|
-
import "./index-
|
|
1
|
+
import { It as FlagBuilder, J as ArgConfig, Lt as FlagConfig, g as CommandBuilder, q as ArgBuilder, r as createCaptureOutput, t as CapturedOutput } from "./index-B6oD4_8b.mjs";
|
|
2
|
+
import { A as BuiltinsConfig, a as TestPrompterOptions, i as TestAnswer, n as RunResult, o as createTestPrompter, r as PROMPT_CANCEL, t as RunOptions } from "./index-B_1Dmsdq.mjs";
|
|
3
|
+
import { a as createTestAdapter, i as TestAdapterOptions } from "./adapter-DsmEc0WO.mjs";
|
|
4
|
+
import "./index-CaRNJH2R.mjs";
|
|
5
5
|
//#region src/core/testkit/index.d.ts
|
|
6
6
|
/**
|
|
7
7
|
* Options for {@linkcode runCommand}.
|
package/dist/testkit.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{N as createCaptureOutput,S as createTestAdapter,t as runCommand}from"./core-B4Twhd48.mjs";import{n as createTestPrompter,t as PROMPT_CANCEL}from"./test-prompter-Ddkt9n5A.mjs";export{PROMPT_CANCEL,createCaptureOutput,createTestAdapter,createTestPrompter,runCommand};
|
package/dist/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const DREAMCLI_VERSION=`4.
|
|
1
|
+
const DREAMCLI_VERSION=`4.2.0`,DREAMCLI_REVISION=`14ab8d1`;export{DREAMCLI_REVISION,DREAMCLI_VERSION};
|
package/dreamcli.schema.json
CHANGED
|
@@ -700,11 +700,19 @@
|
|
|
700
700
|
"$ref": "#/$defs/choice"
|
|
701
701
|
}
|
|
702
702
|
},
|
|
703
|
+
"empty": {
|
|
704
|
+
"enum": [
|
|
705
|
+
"skip",
|
|
706
|
+
"accept",
|
|
707
|
+
"retry"
|
|
708
|
+
]
|
|
709
|
+
},
|
|
703
710
|
"kind": {
|
|
704
|
-
"description": "The kind of interactive prompt to present.\n\n- `'confirm'` — yes/no boolean question\n- `'input'` — free-text string input\n- `'select'` — single selection from a list\n- `'multiselect'` — multiple selections from a list",
|
|
711
|
+
"description": "The kind of interactive prompt to present.\n\n- `'confirm'` — yes/no boolean question\n- `'input'` — free-text string input\n- `'password'` — hidden text input, preserving whitespace\n- `'select'` — single selection from a list\n- `'multiselect'` — multiple selections from a list",
|
|
705
712
|
"enum": [
|
|
706
713
|
"confirm",
|
|
707
714
|
"input",
|
|
715
|
+
"password",
|
|
708
716
|
"select",
|
|
709
717
|
"multiselect"
|
|
710
718
|
]
|
|
@@ -724,6 +732,12 @@
|
|
|
724
732
|
"placeholder": {
|
|
725
733
|
"description": "Placeholder text shown before user types (informational only).",
|
|
726
734
|
"type": "string"
|
|
735
|
+
},
|
|
736
|
+
"sensitive": {
|
|
737
|
+
"const": true
|
|
738
|
+
},
|
|
739
|
+
"trim": {
|
|
740
|
+
"type": "boolean"
|
|
727
741
|
}
|
|
728
742
|
},
|
|
729
743
|
"additionalProperties": false
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kjanat/dreamcli",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Schema-first, fully typed TypeScript CLI framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dreamcli",
|
|
@@ -140,23 +140,23 @@
|
|
|
140
140
|
"devDependencies": {
|
|
141
141
|
"@arethetypeswrong/core": "^0.18.5",
|
|
142
142
|
"@iarna/toml": "^2.2.5",
|
|
143
|
-
"@types/bun": "^1.3
|
|
143
|
+
"@types/bun": "^1.4.3",
|
|
144
144
|
"@types/deno": "^2.7.0",
|
|
145
|
-
"@types/node": ">=26.
|
|
146
|
-
"@typescript/native": "npm:typescript@^7",
|
|
147
|
-
"@vitest/coverage-v8": "5.0.
|
|
148
|
-
"biome": "npm:@biomejs/biome@^2.5.
|
|
149
|
-
"dprint": "0.
|
|
145
|
+
"@types/node": ">=26.6.5",
|
|
146
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
147
|
+
"@vitest/coverage-v8": "5.0.5",
|
|
148
|
+
"biome": "npm:@biomejs/biome@^2.5.15",
|
|
149
|
+
"dprint": "0.64.1",
|
|
150
150
|
"importmapify": "1.7.0",
|
|
151
|
-
"knip": "^6.
|
|
152
|
-
"publint": "^0.3.
|
|
153
|
-
"runner-run": "0.
|
|
154
|
-
"tsdown": "0.23.
|
|
155
|
-
"typescript": ">=6,<7",
|
|
156
|
-
"vitest": "^5.0.
|
|
157
|
-
"yaml": "^2.9.
|
|
151
|
+
"knip": "^6.42.1",
|
|
152
|
+
"publint": "^0.3.25",
|
|
153
|
+
"runner-run": "0.28.0",
|
|
154
|
+
"tsdown": "0.23.1",
|
|
155
|
+
"typescript": ">=6.0.3,<7",
|
|
156
|
+
"vitest": "^5.0.5",
|
|
157
|
+
"yaml": "^2.9.1"
|
|
158
158
|
},
|
|
159
|
-
"packageManager": "bun@1.4.
|
|
159
|
+
"packageManager": "bun@1.4.3",
|
|
160
160
|
"engines": {
|
|
161
161
|
"bun": ">=1.3",
|
|
162
162
|
"deno": ">=2.6.0",
|
|
@@ -180,10 +180,10 @@
|
|
|
180
180
|
"access": "public"
|
|
181
181
|
},
|
|
182
182
|
"catalog": {
|
|
183
|
-
"@types/bun": "^1.3
|
|
184
|
-
"@types/node": ">=26.
|
|
185
|
-
"@typescript/native": "npm:typescript@^7",
|
|
186
|
-
"typescript": ">=6,<7",
|
|
187
|
-
"vitest": "^5.0.
|
|
183
|
+
"@types/bun": "^1.4.3",
|
|
184
|
+
"@types/node": ">=26.6.5",
|
|
185
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
186
|
+
"typescript": ">=6.0.3,<7",
|
|
187
|
+
"vitest": "^5.0.5"
|
|
188
188
|
}
|
|
189
189
|
}
|
|
@@ -52,7 +52,7 @@ deno doc --filter=CLIBuilder jsr:@kjanat/dreamcli 2>/dev/null # one symbol
|
|
|
52
52
|
`2>/dev/null` matters: deno writes download and type-check progress to stderr,
|
|
53
53
|
which otherwise swamps the documentation output.
|
|
54
54
|
|
|
55
|
-
Pin a version with `jsr:@kjanat/dreamcli@4.
|
|
55
|
+
Pin a version with `jsr:@kjanat/dreamcli@4.2.0` when the project is not on
|
|
56
56
|
latest. `--filter` takes a declaration name; it prints nothing for a name that
|
|
57
57
|
does not exist, which is itself a useful signal.
|
|
58
58
|
|
|
@@ -58,7 +58,9 @@ def render_template(template: str, replacements: dict[str, str]) -> str:
|
|
|
58
58
|
|
|
59
59
|
def write_file(path: Path, content: str, force: bool) -> None:
|
|
60
60
|
if path.exists() and not force:
|
|
61
|
-
raise FileExistsError(
|
|
61
|
+
raise FileExistsError(
|
|
62
|
+
f"Refusing to overwrite existing file: {path}. Use --force to overwrite."
|
|
63
|
+
)
|
|
62
64
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
63
65
|
path.write_text(content)
|
|
64
66
|
|
|
@@ -246,7 +248,9 @@ def detect_vitest_usage_in_project(project_root: Path, manager_root: Path | None
|
|
|
246
248
|
return False
|
|
247
249
|
|
|
248
250
|
|
|
249
|
-
def choose_test_template(
|
|
251
|
+
def choose_test_template(
|
|
252
|
+
mode: str, package_manager: str | None, uses_vitest: bool
|
|
253
|
+
) -> tuple[str, str]:
|
|
250
254
|
if package_manager == "bun" and not uses_vitest:
|
|
251
255
|
return (f"{mode}-command.bun-test.ts.tpl", "bun:test")
|
|
252
256
|
return (f"{mode}-command.test.ts.tpl", "vitest")
|
|
@@ -275,7 +279,9 @@ def format_run_path(path: Path, cwd: Path) -> str:
|
|
|
275
279
|
|
|
276
280
|
|
|
277
281
|
def main() -> int:
|
|
278
|
-
parser = argparse.ArgumentParser(
|
|
282
|
+
parser = argparse.ArgumentParser(
|
|
283
|
+
description="Scaffold Bun-first DreamCLI starter files from templates."
|
|
284
|
+
)
|
|
279
285
|
parser.add_argument("--name", required=True, help="CLI name (e.g. mycli)")
|
|
280
286
|
parser.add_argument(
|
|
281
287
|
"--mode",
|
|
@@ -331,7 +337,9 @@ def main() -> int:
|
|
|
331
337
|
print(f"[OK] Wrote {entry_path}")
|
|
332
338
|
|
|
333
339
|
if include_test:
|
|
334
|
-
test_template_name, test_framework = choose_test_template(
|
|
340
|
+
test_template_name, test_framework = choose_test_template(
|
|
341
|
+
args.mode, package_manager, uses_vitest
|
|
342
|
+
)
|
|
335
343
|
test_template_path = templates_dir / test_template_name
|
|
336
344
|
test_template = read_template(test_template_path)
|
|
337
345
|
test_content = render_template(test_template, replacements)
|
package/dist/config-CrlScpYX.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as __exportAll}from"./rolldown-runtime-G4Kt5YOX.mjs";import{Q as CLIError}from"./core-DvXUolc_.mjs";var config_exports=__exportAll({buildConfigSearchPaths:()=>buildConfigSearchPaths,configFormat:()=>configFormat,discoverConfig:()=>discoverConfig});function isPlainObject(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}const jsonLoader={extensions:[`json`],parse:e=>{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))throw Error(`Config must be a JSON object`);return t}};function joinPath(e,...t){let n=e.includes(`\\`)?`\\`:`/`;return[e.endsWith(n)?e.slice(0,-1):e,...t].join(n)}function ancestorDirs(e){let t=e.includes(`\\`)?`\\`:`/`,n=e;for(;n.length>1&&n.endsWith(t)&&!n.endsWith(`:${t}`);)n=n.slice(0,-1);let r=[n];for(;;){let e=n.lastIndexOf(t);if(e<0)break;let i=n.slice(0,e);if(i===``?i=t:/^[A-Za-z]:$/.test(i)&&(i=`${i}${t}`),i===n)break;r.push(i),n=i}return r}function getExtension(e){let t=e.lastIndexOf(`.`);return t<=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`))?``:e.slice(t+1).toLowerCase()}function buildConfigSearchPaths(e,t){let n=buildExtensionList(t.loaders),r=[];for(let i of ancestorDirs(t.baseDir)){for(let t of n)r.push(joinPath(i,`.${e}.${t}`));for(let t of n)r.push(joinPath(i,`${e}.config.${t}`));for(let t of n)r.push(joinPath(i,`.config`,`${e}.${t}`))}for(let i of t.userConfigDirs)for(let t of n)r.push(joinPath(i,e,`config.${t}`));for(let i of t.systemConfigDirs??[])for(let t of n)r.push(joinPath(i,e,`config.${t}`));return r}function buildExtensionList(e){let t=new Set,n=[];for(let e of jsonLoader.extensions){let r=e.toLowerCase();t.has(r)||(t.add(r),n.push(r))}if(e!==void 0)for(let r of e)for(let e of r.extensions){let r=e.toLowerCase();t.has(r)||(t.add(r),n.push(r))}return n}function buildLoaderMap(e){let t=new Map;for(let e of jsonLoader.extensions)t.set(e.toLowerCase(),jsonLoader);if(e!==void 0)for(let n of e)for(let e of n.extensions)t.set(e.toLowerCase(),n);return t}async function discoverConfig(e,t,n){let r=buildLoaderMap(n?.loaders),i=n?.configPath===void 0?n?.searchPaths??buildConfigSearchPaths(e,{baseDir:n?.baseDir??t.cwd,userConfigDirs:t.userConfigDirs??[t.configDir],systemConfigDirs:t.systemConfigDirs??[],...n?.loaders===void 0?{}:{loaders:n.loaders}}):[n.configPath];for(let e of i){let i=await t.readFile(e);if(i===null){if(n?.configPath!==void 0)throw new CLIError(`Config file not found: ${e}`,{code:`CONFIG_NOT_FOUND`,details:{path:e},suggest:`Create the config file or remove the --config flag`});continue}let a=getExtension(e),o=r.get(a);if(o===void 0)throw new CLIError(`No loader registered for config format: .${a}`,{code:`CONFIG_UNKNOWN_FORMAT`,details:{path:e,extension:a},suggest:`Supported formats: ${[...r.keys()].join(`, `)}`});try{let t=o.parse(i);if(!isPlainObject(t))throw Error(`Config loader must return a plain object`);return{found:!0,path:e,data:t,format:a}}catch(t){throw new CLIError(`Failed to parse config file: ${e}`,{code:`CONFIG_PARSE_ERROR`,cause:t,details:{path:e,format:a,message:t instanceof Error?t.message:String(t)},suggest:`Check the config file for syntax errors`})}}return{found:!1}}function configFormat(e,t){return{extensions:e,parse:t}}export{discoverConfig as i,configFormat as n,config_exports as r,buildConfigSearchPaths as t};
|