@kjanat/dreamcli 3.0.0-rc.1 → 3.0.0-rc.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/CHANGELOG.md +217 -1
  2. package/dist/core/cli/dispatch.d.mts +6 -5
  3. package/dist/core/cli/dispatch.mjs +205 -1
  4. package/dist/core/cli/help-links.d.mts +0 -1
  5. package/dist/core/cli/help-links.mjs +41 -1
  6. package/dist/core/cli/index.d.mts +81 -8
  7. package/dist/core/cli/index.mjs +945 -1
  8. package/dist/core/cli/planner.d.mts +5 -1
  9. package/dist/core/cli/planner.mjs +300 -1
  10. package/dist/core/cli/plugin.d.mts +1 -1
  11. package/dist/core/cli/plugin.mjs +41 -1
  12. package/dist/core/cli/propagate.d.mts +1 -1
  13. package/dist/core/cli/propagate.mjs +57 -1
  14. package/dist/core/cli/root-help.d.mts +2 -1
  15. package/dist/core/cli/root-help.mjs +226 -4
  16. package/dist/core/cli/root-surface.d.mts +12 -1
  17. package/dist/core/cli/root-surface.mjs +28 -1
  18. package/dist/core/cli/runtime-preflight.d.mts +14 -2
  19. package/dist/core/cli/runtime-preflight.mjs +169 -1
  20. package/dist/core/completion/index.d.mts +0 -1
  21. package/dist/core/completion/index.mjs +90 -1
  22. package/dist/core/completion/shells/bash.d.mts +0 -1
  23. package/dist/core/completion/shells/bash.mjs +308 -3
  24. package/dist/core/completion/shells/fish.d.mts +0 -1
  25. package/dist/core/completion/shells/fish.mjs +162 -2
  26. package/dist/core/completion/shells/powershell.d.mts +0 -1
  27. package/dist/core/completion/shells/powershell.mjs +358 -2
  28. package/dist/core/completion/shells/shared.d.mts +13 -2
  29. package/dist/core/completion/shells/shared.mjs +176 -1
  30. package/dist/core/completion/shells/zsh.d.mts +0 -1
  31. package/dist/core/completion/shells/zsh.mjs +251 -2
  32. package/dist/core/config/index.d.mts +2 -3
  33. package/dist/core/config/index.mjs +246 -1
  34. package/dist/core/config/package-json.d.mts +27 -4
  35. package/dist/core/config/package-json.mjs +386 -3
  36. package/dist/core/errors/index.d.mts +3 -3
  37. package/dist/core/errors/index.mjs +87 -1
  38. package/dist/core/execution/index.d.mts +0 -1
  39. package/dist/core/execution/index.mjs +201 -1
  40. package/dist/core/help/ansi.d.mts +11 -5
  41. package/dist/core/help/ansi.mjs +121 -2
  42. package/dist/core/help/index.d.mts +22 -3
  43. package/dist/core/help/index.mjs +341 -7
  44. package/dist/core/help/theme.d.mts +68 -0
  45. package/dist/core/help/theme.mjs +46 -0
  46. package/dist/core/json-schema/index.d.mts +15 -2
  47. package/dist/core/json-schema/index.mjs +536 -12
  48. package/dist/core/json-schema/meta-descriptions.generated.d.mts +55 -38
  49. package/dist/core/json-schema/meta-descriptions.generated.mjs +102 -28
  50. package/dist/core/output/activity.d.mts +0 -1
  51. package/dist/core/output/activity.mjs +452 -1
  52. package/dist/core/output/bind.mjs +56 -1
  53. package/dist/core/output/contracts.d.mts +4 -5
  54. package/dist/core/output/contracts.mjs +57 -1
  55. package/dist/core/output/display-value.mjs +32 -1
  56. package/dist/core/output/index.d.mts +21 -1
  57. package/dist/core/output/index.mjs +442 -2
  58. package/dist/core/output/renderers.d.mts +0 -1
  59. package/dist/core/output/renderers.mjs +46 -1
  60. package/dist/core/output/writer.mjs +12 -1
  61. package/dist/core/parse/index.d.mts +40 -7
  62. package/dist/core/parse/index.mjs +727 -1
  63. package/dist/core/prompt/index.d.mts +1 -1
  64. package/dist/core/prompt/index.mjs +348 -6
  65. package/dist/core/resolve/args.d.mts +1 -1
  66. package/dist/core/resolve/args.mjs +105 -1
  67. package/dist/core/resolve/coerce.d.mts +1 -1
  68. package/dist/core/resolve/coerce.mjs +336 -1
  69. package/dist/core/resolve/config.mjs +19 -1
  70. package/dist/core/resolve/contracts.d.mts +9 -4
  71. package/dist/core/resolve/errors.d.mts +0 -1
  72. package/dist/core/resolve/errors.mjs +140 -2
  73. package/dist/core/resolve/flags.d.mts +7 -2
  74. package/dist/core/resolve/flags.mjs +251 -1
  75. package/dist/core/resolve/index.d.mts +2 -2
  76. package/dist/core/resolve/index.mjs +85 -1
  77. package/dist/core/resolve/property.d.mts +4 -2
  78. package/dist/core/resolve/property.mjs +53 -1
  79. package/dist/core/schema/activity.d.mts +31 -11
  80. package/dist/core/schema/arg.d.mts +3 -4
  81. package/dist/core/schema/arg.mjs +463 -1
  82. package/dist/core/schema/command.d.mts +26 -6
  83. package/dist/core/schema/command.mjs +726 -1
  84. package/dist/core/schema/flag.d.mts +485 -19
  85. package/dist/core/schema/flag.mjs +705 -1
  86. package/dist/core/schema/index.d.mts +4 -2
  87. package/dist/core/schema/middleware.d.mts +4 -3
  88. package/dist/core/schema/middleware.mjs +41 -1
  89. package/dist/core/schema/number-constraints.mjs +60 -1
  90. package/dist/core/schema/prompt.d.mts +6 -3
  91. package/dist/core/schema/run.d.mts +20 -1
  92. package/dist/core/schema/string-constraints.d.mts +97 -0
  93. package/dist/core/schema/string-constraints.mjs +69 -0
  94. package/dist/core/schema/value-parsers.d.mts +78 -0
  95. package/dist/core/schema/value-parsers.mjs +142 -0
  96. package/dist/core/schema-dsl/runtime.mjs +271 -2
  97. package/dist/core/schema-dsl/to-json-schema.d.mts +0 -1
  98. package/dist/core/schema-dsl/to-json-schema.mjs +74 -1
  99. package/dist/core/testkit/index.d.mts +0 -31
  100. package/dist/core/testkit/index.mjs +83 -1
  101. package/dist/index.d.mts +11 -6
  102. package/dist/index.mjs +22 -1
  103. package/dist/runtime/adapter.d.mts +38 -2
  104. package/dist/runtime/adapter.mjs +87 -1
  105. package/dist/runtime/auto.d.mts +2 -3
  106. package/dist/runtime/auto.mjs +45 -1
  107. package/dist/runtime/deno.d.mts +24 -5
  108. package/dist/runtime/deno.mjs +262 -2
  109. package/dist/runtime/detect.mjs +45 -1
  110. package/dist/runtime/index.d.mts +3 -4
  111. package/dist/runtime/node.d.mts +8 -2
  112. package/dist/runtime/node.mjs +220 -2
  113. package/dist/runtime/paths.mjs +48 -1
  114. package/dist/runtime.d.mts +4 -4
  115. package/dist/runtime.mjs +6 -1
  116. package/dist/strings.mjs +22 -1
  117. package/dist/testkit.d.mts +1 -0
  118. package/dist/testkit.mjs +5 -1
  119. package/dist/version.d.mts +7 -3
  120. package/dist/version.mjs +7 -1
  121. package/dreamcli.schema.json +36 -7
  122. package/package.json +45 -42
  123. package/dist/runtime/bun.d.mts +0 -28
  124. package/dist/runtime/bun.mjs +0 -1
  125. package/src/core/cli/dispatch.ts +0 -355
  126. package/src/core/cli/help-links.ts +0 -82
  127. package/src/core/cli/index.ts +0 -1614
  128. package/src/core/cli/planner.ts +0 -656
  129. package/src/core/cli/plugin.ts +0 -117
  130. package/src/core/cli/propagate.ts +0 -97
  131. package/src/core/cli/root-help.ts +0 -342
  132. package/src/core/cli/root-surface.ts +0 -87
  133. package/src/core/cli/runtime-preflight.ts +0 -456
  134. package/src/core/completion/index.ts +0 -138
  135. package/src/core/completion/shells/bash.ts +0 -459
  136. package/src/core/completion/shells/fish.ts +0 -259
  137. package/src/core/completion/shells/powershell.ts +0 -439
  138. package/src/core/completion/shells/shared.ts +0 -310
  139. package/src/core/completion/shells/zsh.ts +0 -381
  140. package/src/core/config/index.ts +0 -417
  141. package/src/core/config/package-json.ts +0 -560
  142. package/src/core/errors/index.ts +0 -193
  143. package/src/core/execution/index.ts +0 -265
  144. package/src/core/help/ansi.ts +0 -144
  145. package/src/core/help/index.ts +0 -563
  146. package/src/core/json-schema/index.ts +0 -910
  147. package/src/core/json-schema/meta-descriptions.generated.ts +0 -202
  148. package/src/core/output/activity.ts +0 -575
  149. package/src/core/output/bind.ts +0 -59
  150. package/src/core/output/contracts.ts +0 -194
  151. package/src/core/output/display-value.ts +0 -48
  152. package/src/core/output/index.ts +0 -704
  153. package/src/core/output/renderers.ts +0 -125
  154. package/src/core/output/writer.ts +0 -46
  155. package/src/core/parse/index.ts +0 -742
  156. package/src/core/prompt/index.ts +0 -623
  157. package/src/core/resolve/args.ts +0 -144
  158. package/src/core/resolve/coerce.ts +0 -500
  159. package/src/core/resolve/config.ts +0 -26
  160. package/src/core/resolve/contracts.ts +0 -135
  161. package/src/core/resolve/errors.ts +0 -227
  162. package/src/core/resolve/flags.ts +0 -269
  163. package/src/core/resolve/index.ts +0 -108
  164. package/src/core/resolve/property.ts +0 -99
  165. package/src/core/schema/activity.ts +0 -240
  166. package/src/core/schema/arg.ts +0 -841
  167. package/src/core/schema/command.ts +0 -1500
  168. package/src/core/schema/flag.ts +0 -917
  169. package/src/core/schema/index.ts +0 -96
  170. package/src/core/schema/middleware.ts +0 -171
  171. package/src/core/schema/number-constraints.ts +0 -153
  172. package/src/core/schema/prompt.ts +0 -171
  173. package/src/core/schema/run.ts +0 -198
  174. package/src/core/schema-dsl/index.ts +0 -109
  175. package/src/core/schema-dsl/parse.ts +0 -262
  176. package/src/core/schema-dsl/runtime.ts +0 -609
  177. package/src/core/schema-dsl/to-json-schema.ts +0 -102
  178. package/src/core/testkit/index.ts +0 -147
  179. package/src/index.ts +0 -181
  180. package/src/runtime/adapter.ts +0 -303
  181. package/src/runtime/auto.ts +0 -86
  182. package/src/runtime/bun.ts +0 -48
  183. package/src/runtime/deno.ts +0 -367
  184. package/src/runtime/detect.ts +0 -105
  185. package/src/runtime/index.ts +0 -21
  186. package/src/runtime/node-builtins.d.ts +0 -27
  187. package/src/runtime/node.ts +0 -289
  188. package/src/runtime/paths.ts +0 -64
  189. package/src/runtime/support.ts +0 -77
  190. package/src/runtime.ts +0 -31
  191. package/src/schema.ts +0 -16
  192. package/src/strings.ts +0 -34
  193. package/src/testkit.ts +0 -25
  194. package/src/version.ts +0 -20
@@ -1,2 +1,358 @@
1
- import{getFlagAliasNames as e}from"../../schema/flag.mjs";import{resolveRootCompletionSurface as t,sanitizeShellIdentifier as n,versionTag as r,walkCommandTree as i}from"./shared.mjs";function a(e,a){let s=`__${n(a?.functionPrefix??e.name)}_completions`,u=`${s}_paths`,d=t(e,a?.rootMode),f=d.visibleCommands,p=i(f),m=[];return m.push(`# PowerShell completion for ${e.name}`),m.push(`# Generated by ${r()}`),m.push(`#`),m.push(`# Install for the current session:`),m.push(`# ${e.name} completions powershell | Out-String | Invoke-Expression`),m.push(`#`),m.push(`# Install permanently:`),m.push(`# ${e.name} completions powershell > $PROFILE.CurrentUserCurrentHost`),m.push(``),m.push(`using namespace System.Management.Automation`),m.push(`using namespace System.Management.Automation.Language`),m.push(``),o(m,u,d,p),m.push(``),c(m,s,u),m.push(``),m.push(`Register-ArgumentCompleter -Native -CommandName ${l(e.name)} -ScriptBlock {`),m.push(` param($wordToComplete, $commandAst, $cursorPosition)`),m.push(`\t$state = ${s}_GetState -CommandAst $commandAst -CursorPosition $cursorPosition`),m.push(` if ($null -eq $state.PathData) {`),m.push(` return`),m.push(` }`),m.push(``),m.push(` $results = [System.Collections.Generic.List[CompletionResult]]::new()`),m.push(` if ($state.AfterSeparator) {`),m.push(` return $results`),m.push(` }`),m.push(``),m.push(` $wordPrefix = if ([string]::IsNullOrEmpty($wordToComplete)) { '' } else { $wordToComplete }`),m.push(``),m.push(` if ($state.ExpectingValue) {`),m.push(`\t\t${s}_AddEnumResults -Results $results -Flag $state.ValueFlag -WordToComplete $wordPrefix`),m.push(` return $results`),m.push(` }`),m.push(``),m.push(`\t$inlineValue = ${s}_ResolveInlineValueCompletion -PathData $state.PathData -WordToComplete $wordPrefix`),m.push(` if ($null -ne $inlineValue) {`),m.push(`\t\t${s}_AddInlineEnumResults -Results $results -InlineValue $inlineValue -WordToComplete $wordPrefix`),m.push(` return $results`),m.push(` }`),m.push(``),m.push(` if ($wordPrefix.StartsWith('-')) {`),m.push(`\t\t${s}_AddFlagResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix`),m.push(` return $results`),m.push(` }`),m.push(``),m.push(`\t${s}_AddCommandResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix`),m.push(`\t${s}_AddFlagResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix`),m.push(` return $results`),m.push(`}`),m.join(`
2
- `)}function o(e,t,n,r){e.push(`$script:${t} = @{`),s(e,``,n.visibleCommands,{...n.rootFlags,...n.includeDefaultFlags?n.defaultFlags:{}});for(let t of r)s(e,t.path.join(` `),t.children,t.mergedFlags);e.push(`}`)}function s(t,n,r,i){t.push(`\t${l(n)} = @{`),t.push(` Commands = @(`);for(let e of r)t.push(` @{`),t.push(`\t\t\t\tCanonicalName = ${l(e.name)}`),t.push(`\t\t\t\tNames = ${u([e.name,...e.aliases])}`),t.push(`\t\t\t\tDescription = ${l(e.description??e.name)}`),t.push(` }`);t.push(` )`),t.push(` Flags = @(`);for(let[n,r]of Object.entries(i)){let i=d([`--${n}`,...e(r,{kind:`short`}).map(e=>`-${e}`),...e(r,{kind:`long`}).map(e=>`--${e}`)]),a=d([`--${n}`,...e(r,{kind:`short`,includeHidden:!0}).map(e=>`-${e}`),...e(r,{kind:`long`,includeHidden:!0}).map(e=>`--${e}`)]);t.push(` @{`),t.push(`\t\t\t\tCanonicalName = ${l(n)}`),t.push(`\t\t\t\tForms = ${u(i)}`),t.push(`\t\t\t\tParseForms = ${u(a)}`),t.push(`\t\t\t\tRequiresValue = ${r.kind===`boolean`?`$false`:`$true`}`),t.push(`\t\t\t\tDescription = ${l(r.description??n)}`),t.push(`\t\t\t\tEnumValues = ${u(r.enumValues??[])}`),t.push(` }`)}t.push(` )`),t.push(` }`)}function c(e,t,n){e.push(`function ${t}_UnquoteToken {`),e.push(` param([string]$TokenText)`),e.push(` if ($TokenText.Length -lt 2) {`),e.push(` return $TokenText`),e.push(` }`),e.push(``),e.push(` if (($TokenText.StartsWith("'") -and $TokenText.EndsWith("'")) -or`),e.push(` ($TokenText.StartsWith('"') -and $TokenText.EndsWith('"'))) {`),e.push(` return $TokenText.Substring(1, $TokenText.Length - 2)`),e.push(` }`),e.push(``),e.push(` return $TokenText`),e.push(`}`),e.push(``),e.push(`function ${t}_FindCommand {`),e.push(` param($PathData, [string]$Token)`),e.push(` foreach ($command in $PathData.Commands) {`),e.push(` foreach ($name in $command.Names) {`),e.push(` if ($name -eq $Token) {`),e.push(` return $command`),e.push(` }`),e.push(` }`),e.push(` }`),e.push(` return $null`),e.push(`}`),e.push(``),e.push(`function ${t}_ResolveFlagToken {`),e.push(` param($PathData, [string]$Token)`),e.push(` foreach ($flag in $PathData.Flags) {`),e.push(` foreach ($form in $flag.ParseForms) {`),e.push(` if ($Token -eq $form) {`),e.push(` return @{ Flag = $flag; InlinePrefix = $null }`),e.push(` }`),e.push(``),e.push(` if (-not $flag.RequiresValue) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` if ($form.StartsWith('--') -and $Token.StartsWith("$form=")) {`),e.push(` return @{ Flag = $flag; InlinePrefix = "$form=" }`),e.push(` }`),e.push(``),e.push(` if ($form.StartsWith('-') -and -not $form.StartsWith('--') -and $Token.StartsWith($form) -and $Token.Length -gt $form.Length) {`),e.push(` return @{ Flag = $flag; InlinePrefix = $form }`),e.push(` }`),e.push(` }`),e.push(` }`),e.push(` return $null`),e.push(`}`),e.push(``),e.push(`function ${t}_GetState {`),e.push(` param([CommandAst]$CommandAst, [int]$CursorPosition)`),e.push(`\t$pathData = $script:${n}[${l(``)}]`),e.push(` $path = ""`),e.push(` $afterSeparator = $false`),e.push(` $expectingValue = $false`),e.push(` $valueFlag = $null`),e.push(` $tokens = [System.Collections.Generic.List[string]]::new()`),e.push(``),e.push(` foreach ($element in $CommandAst.CommandElements | Select-Object -Skip 1) {`),e.push(` if ($element.Extent.EndOffset -ge $CursorPosition) {`),e.push(` break`),e.push(` }`),e.push(`\t\t$tokenText = ${t}_UnquoteToken $element.Extent.Text`),e.push(` [void]$tokens.Add($tokenText)`),e.push(` }`),e.push(``),e.push(` foreach ($token in $tokens) {`),e.push(` if ($expectingValue) {`),e.push(` $expectingValue = $false`),e.push(` $valueFlag = $null`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` if ($token -eq '--') {`),e.push(` $afterSeparator = $true`),e.push(` break`),e.push(` }`),e.push(``),e.push(`\t\t$flagMatch = ${t}_ResolveFlagToken -PathData $pathData -Token $token`),e.push(` if ($null -ne $flagMatch) {`),e.push(` if ($flagMatch.InlinePrefix -eq $null -and $flagMatch.Flag.RequiresValue) {`),e.push(` $expectingValue = $true`),e.push(` $valueFlag = $flagMatch.Flag`),e.push(` }`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` if ($token.StartsWith('-')) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(`\t\t$command = ${t}_FindCommand -PathData $pathData -Token $token`),e.push(` if ($null -eq $command) {`),e.push(` break`),e.push(` }`),e.push(``),e.push(` $path = if ([string]::IsNullOrEmpty($path)) {`),e.push(` $command.CanonicalName`),e.push(` } else {`),e.push(` "$path $($command.CanonicalName)"`),e.push(` }`),e.push(`\t\t$nextPathData = $script:${n}[$path]`),e.push(` if ($null -eq $nextPathData) {`),e.push(` break`),e.push(` }`),e.push(` $pathData = $nextPathData`),e.push(` }`),e.push(``),e.push(` return @{`),e.push(` Path = $path`),e.push(` PathData = $pathData`),e.push(` AfterSeparator = $afterSeparator`),e.push(` ExpectingValue = $expectingValue`),e.push(` ValueFlag = $valueFlag`),e.push(` }`),e.push(`}`),e.push(``),e.push(`function ${t}_ResolveInlineValueCompletion {`),e.push(` param($PathData, [string]$WordToComplete)`),e.push(`\t$flagMatch = ${t}_ResolveFlagToken -PathData $PathData -Token $WordToComplete`),e.push(` if ($null -eq $flagMatch -or $flagMatch.InlinePrefix -eq $null) {`),e.push(` return $null`),e.push(` }`),e.push(` return $flagMatch`),e.push(`}`),e.push(``),e.push(`function ${t}_FormatCompletionValue {`),e.push(` param([string]$Value)`),e.push(` if ($Value.Length -eq 0) {`),e.push(` return "''"`),e.push(` }`),e.push(``),e.push(` if ($Value -match '^[a-zA-Z0-9_./:\\\\-]+$') {`),e.push(` return $Value`),e.push(` }`),e.push(``),e.push(` return "'$([CodeGeneration]::EscapeSingleQuotedStringContent($Value))'"`),e.push(`}`),e.push(``),e.push(`function ${t}_MatchesCompletionPrefix {`),e.push(` param([string]$WordToComplete, [string]$RawText, [string]$CompletionText)`),e.push(` if ([string]::IsNullOrEmpty($WordToComplete)) {`),e.push(` return $true`),e.push(` }`),e.push(``),e.push(` return $RawText.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase) -or $CompletionText.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase)`),e.push(`}`),e.push(``),e.push(`function ${t}_AddCommandResults {`),e.push(` param($Results, $PathData, [string]$WordToComplete)`),e.push(` foreach ($command in $PathData.Commands) {`),e.push(` foreach ($name in $command.Names) {`),e.push(` if (-not [string]::IsNullOrEmpty($WordToComplete) -and -not $name.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase)) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` $Results.Add([CompletionResult]::new(`),e.push(` $name,`),e.push(` $name,`),e.push(` [CompletionResultType]::Command,`),e.push(` $command.Description`),e.push(` ))`),e.push(` }`),e.push(` }`),e.push(`}`),e.push(``),e.push(`function ${t}_AddFlagResults {`),e.push(` param($Results, $PathData, [string]$WordToComplete)`),e.push(` foreach ($flag in $PathData.Flags) {`),e.push(` foreach ($form in $flag.Forms) {`),e.push(` if (-not [string]::IsNullOrEmpty($WordToComplete) -and -not $form.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase)) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` $Results.Add([CompletionResult]::new(`),e.push(` $form,`),e.push(` $form,`),e.push(` [CompletionResultType]::ParameterName,`),e.push(` $flag.Description`),e.push(` ))`),e.push(` }`),e.push(` }`),e.push(`}`),e.push(``),e.push(`function ${t}_AddEnumResults {`),e.push(` param($Results, $Flag, [string]$WordToComplete)`),e.push(` foreach ($value in $Flag.EnumValues) {`),e.push(`\t\t$completionText = ${t}_FormatCompletionValue -Value $value`),e.push(`\t\tif (-not (${t}_MatchesCompletionPrefix -WordToComplete $WordToComplete -RawText $value -CompletionText $completionText)) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` $Results.Add([CompletionResult]::new(`),e.push(` $completionText,`),e.push(` $value,`),e.push(` [CompletionResultType]::ParameterValue,`),e.push(` $Flag.Description`),e.push(` ))`),e.push(` }`),e.push(`}`),e.push(``),e.push(`function ${t}_AddInlineEnumResults {`),e.push(` param($Results, $InlineValue, [string]$WordToComplete)`),e.push(` foreach ($value in $InlineValue.Flag.EnumValues) {`),e.push(` $rawCompletion = "$($InlineValue.InlinePrefix)$value"`),e.push(`\t\t$formattedValue = ${t}_FormatCompletionValue -Value $value`),e.push(` $completionText = "$($InlineValue.InlinePrefix)$formattedValue"`),e.push(`\t\tif (-not (${t}_MatchesCompletionPrefix -WordToComplete $WordToComplete -RawText $rawCompletion -CompletionText $completionText)) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` $Results.Add([CompletionResult]::new(`),e.push(` $completionText,`),e.push(` $value,`),e.push(` [CompletionResultType]::ParameterValue,`),e.push(` $InlineValue.Flag.Description`),e.push(` ))`),e.push(` }`),e.push(`}`)}function l(e){return`'${e.replace(/'/g,`''`)}'`}function u(e){return e.length===0?`@()`:`@(${e.map(l).join(`, `)})`}function d(e){return[...new Set(e)]}export{a as generatePowerShellCompletion};
1
+ import { getFlagAliasNames, getFlagNegatedName } from "../../schema/flag.mjs";
2
+ import { flagExpectsValue } from "../../parse/index.mjs";
3
+ import { getVisibleNegatedName, resolveRootCompletionSurface, sanitizeShellIdentifier, versionTag, walkCommandTree } from "./shared.mjs";
4
+ //#region src/core/completion/shells/powershell.ts
5
+ /**
6
+ * Generate a PowerShell completion script for the CLI.
7
+ *
8
+ * @param schema - The CLI schema.
9
+ * @param options - Optional generator configuration.
10
+ * @returns A complete PowerShell completion script.
11
+ */
12
+ function generatePowerShellCompletion(schema, options) {
13
+ const helperPrefix = `__${sanitizeShellIdentifier(options?.functionPrefix ?? schema.name)}_completions`;
14
+ const dataVarName = `${helperPrefix}_paths`;
15
+ const rootSurface = resolveRootCompletionSurface(schema, options?.rootMode);
16
+ const visibleCommands = rootSurface.visibleCommands;
17
+ const nodes = walkCommandTree(visibleCommands);
18
+ const lines = [];
19
+ lines.push(`# PowerShell completion for ${schema.name}`);
20
+ lines.push(`# Generated by ${versionTag()}`);
21
+ lines.push("#");
22
+ lines.push("# Install for the current session:");
23
+ lines.push(`# ${schema.name} completions powershell | Out-String | Invoke-Expression`);
24
+ lines.push("#");
25
+ lines.push("# Install permanently:");
26
+ lines.push(`# ${schema.name} completions powershell > $PROFILE.CurrentUserCurrentHost`);
27
+ lines.push("");
28
+ lines.push("using namespace System.Management.Automation");
29
+ lines.push("using namespace System.Management.Automation.Language");
30
+ lines.push("");
31
+ emitPowerShellPathTable(lines, dataVarName, rootSurface, nodes);
32
+ lines.push("");
33
+ emitPowerShellHelpers(lines, helperPrefix, dataVarName);
34
+ lines.push("");
35
+ lines.push(`Register-ArgumentCompleter -Native -CommandName ${quotePowerShellString(schema.name)} -ScriptBlock {`);
36
+ lines.push(" param($wordToComplete, $commandAst, $cursorPosition)");
37
+ lines.push(`\t$state = ${helperPrefix}_GetState -CommandAst $commandAst -CursorPosition $cursorPosition`);
38
+ lines.push(" if ($null -eq $state.PathData) {");
39
+ lines.push(" return");
40
+ lines.push(" }");
41
+ lines.push("");
42
+ lines.push(" $results = [System.Collections.Generic.List[CompletionResult]]::new()");
43
+ lines.push(" if ($state.AfterSeparator) {");
44
+ lines.push(" return $results");
45
+ lines.push(" }");
46
+ lines.push("");
47
+ lines.push(`\t$wordPrefix = if ([string]::IsNullOrEmpty($wordToComplete)) { '' } else { $wordToComplete }`);
48
+ lines.push("");
49
+ lines.push(" if ($state.ExpectingValue) {");
50
+ lines.push(`\t\t${helperPrefix}_AddEnumResults -Results $results -Flag $state.ValueFlag -WordToComplete $wordPrefix`);
51
+ lines.push(" return $results");
52
+ lines.push(" }");
53
+ lines.push("");
54
+ lines.push(`\t$inlineValue = ${helperPrefix}_ResolveInlineValueCompletion -PathData $state.PathData -WordToComplete $wordPrefix`);
55
+ lines.push(" if ($null -ne $inlineValue) {");
56
+ lines.push(`\t\t${helperPrefix}_AddInlineEnumResults -Results $results -InlineValue $inlineValue -WordToComplete $wordPrefix`);
57
+ lines.push(" return $results");
58
+ lines.push(" }");
59
+ lines.push("");
60
+ lines.push(" if ($wordPrefix.StartsWith('-')) {");
61
+ lines.push(`\t\t${helperPrefix}_AddFlagResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix`);
62
+ lines.push(" return $results");
63
+ lines.push(" }");
64
+ lines.push("");
65
+ lines.push(`\t${helperPrefix}_AddCommandResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix`);
66
+ lines.push(`\t${helperPrefix}_AddFlagResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix`);
67
+ lines.push(" return $results");
68
+ lines.push("}");
69
+ return lines.join("\n");
70
+ }
71
+ function emitPowerShellPathTable(lines, dataVarName, rootSurface, nodes) {
72
+ lines.push(`$script:${dataVarName} = @{`);
73
+ appendPowerShellPathEntry(lines, "", rootSurface.visibleCommands, {
74
+ ...rootSurface.rootFlags,
75
+ ...rootSurface.includeDefaultFlags ? rootSurface.defaultFlags : {}
76
+ });
77
+ for (const node of nodes) appendPowerShellPathEntry(lines, node.path.join(" "), node.children, node.mergedFlags);
78
+ lines.push("}");
79
+ }
80
+ function appendPowerShellPathEntry(lines, path, commands, flags) {
81
+ lines.push(`\t${quotePowerShellString(path)} = @{`);
82
+ lines.push(" Commands = @(");
83
+ for (const command of commands) {
84
+ lines.push(" @{");
85
+ lines.push(`\t\t\t\tCanonicalName = ${quotePowerShellString(command.name)}`);
86
+ lines.push(`\t\t\t\tNames = ${formatPowerShellArray([command.name, ...command.aliases])}`);
87
+ lines.push(`\t\t\t\tDescription = ${quotePowerShellString(command.description ?? command.name)}`);
88
+ lines.push(" }");
89
+ }
90
+ lines.push(" )");
91
+ lines.push(" Flags = @(");
92
+ for (const [name, schema] of Object.entries(flags)) {
93
+ const visibleNegated = getVisibleNegatedName(name, schema);
94
+ const parseNegated = getFlagNegatedName(name, schema);
95
+ const forms = dedupeValues([
96
+ `--${name}`,
97
+ ...getFlagAliasNames(schema, { kind: "short" }).map((alias) => `-${alias}`),
98
+ ...getFlagAliasNames(schema, { kind: "long" }).map((alias) => `--${alias}`),
99
+ ...visibleNegated !== void 0 ? [`--${visibleNegated}`] : []
100
+ ]);
101
+ const parseForms = dedupeValues([
102
+ `--${name}`,
103
+ ...getFlagAliasNames(schema, {
104
+ kind: "short",
105
+ includeHidden: true
106
+ }).map((alias) => `-${alias}`),
107
+ ...getFlagAliasNames(schema, {
108
+ kind: "long",
109
+ includeHidden: true
110
+ }).map((alias) => `--${alias}`),
111
+ ...parseNegated !== void 0 ? [`--${parseNegated}`] : []
112
+ ]);
113
+ lines.push(" @{");
114
+ lines.push(`\t\t\t\tCanonicalName = ${quotePowerShellString(name)}`);
115
+ lines.push(`\t\t\t\tForms = ${formatPowerShellArray(forms)}`);
116
+ lines.push(`\t\t\t\tParseForms = ${formatPowerShellArray(parseForms)}`);
117
+ lines.push(`\t\t\t\tRequiresValue = ${flagExpectsValue(schema) ? "$true" : "$false"}`);
118
+ lines.push(`\t\t\t\tDescription = ${quotePowerShellString(schema.description ?? name)}`);
119
+ lines.push(`\t\t\t\tEnumValues = ${formatPowerShellArray(schema.enumValues ?? [])}`);
120
+ lines.push(" }");
121
+ }
122
+ lines.push(" )");
123
+ lines.push(" }");
124
+ }
125
+ function emitPowerShellHelpers(lines, helperPrefix, dataVarName) {
126
+ lines.push(`function ${helperPrefix}_UnquoteToken {`);
127
+ lines.push(" param([string]$TokenText)");
128
+ lines.push(" if ($TokenText.Length -lt 2) {");
129
+ lines.push(" return $TokenText");
130
+ lines.push(" }");
131
+ lines.push("");
132
+ lines.push(" if (($TokenText.StartsWith(\"'\") -and $TokenText.EndsWith(\"'\")) -or");
133
+ lines.push(" ($TokenText.StartsWith('\"') -and $TokenText.EndsWith('\"'))) {");
134
+ lines.push(" return $TokenText.Substring(1, $TokenText.Length - 2)");
135
+ lines.push(" }");
136
+ lines.push("");
137
+ lines.push(" return $TokenText");
138
+ lines.push("}");
139
+ lines.push("");
140
+ lines.push(`function ${helperPrefix}_FindCommand {`);
141
+ lines.push(" param($PathData, [string]$Token)");
142
+ lines.push(" foreach ($command in $PathData.Commands) {");
143
+ lines.push(" foreach ($name in $command.Names) {");
144
+ lines.push(" if ($name -eq $Token) {");
145
+ lines.push(" return $command");
146
+ lines.push(" }");
147
+ lines.push(" }");
148
+ lines.push(" }");
149
+ lines.push(" return $null");
150
+ lines.push("}");
151
+ lines.push("");
152
+ lines.push(`function ${helperPrefix}_ResolveFlagToken {`);
153
+ lines.push(" param($PathData, [string]$Token)");
154
+ lines.push(" foreach ($flag in $PathData.Flags) {");
155
+ lines.push(" foreach ($form in $flag.ParseForms) {");
156
+ lines.push(" if ($Token -eq $form) {");
157
+ lines.push(" return @{ Flag = $flag; InlinePrefix = $null }");
158
+ lines.push(" }");
159
+ lines.push("");
160
+ lines.push(" if (-not $flag.RequiresValue) {");
161
+ lines.push(" continue");
162
+ lines.push(" }");
163
+ lines.push("");
164
+ lines.push(" if ($form.StartsWith('--') -and $Token.StartsWith(\"$form=\")) {");
165
+ lines.push(" return @{ Flag = $flag; InlinePrefix = \"$form=\" }");
166
+ lines.push(" }");
167
+ lines.push("");
168
+ lines.push(" if ($form.StartsWith('-') -and -not $form.StartsWith('--') -and $Token.StartsWith($form) -and $Token.Length -gt $form.Length) {");
169
+ lines.push(" return @{ Flag = $flag; InlinePrefix = $form }");
170
+ lines.push(" }");
171
+ lines.push(" }");
172
+ lines.push(" }");
173
+ lines.push(" return $null");
174
+ lines.push("}");
175
+ lines.push("");
176
+ lines.push(`function ${helperPrefix}_GetState {`);
177
+ lines.push(" param([CommandAst]$CommandAst, [int]$CursorPosition)");
178
+ lines.push(`\t$pathData = $script:${dataVarName}[${quotePowerShellString("")}]`);
179
+ lines.push(" $path = \"\"");
180
+ lines.push(" $afterSeparator = $false");
181
+ lines.push(" $expectingValue = $false");
182
+ lines.push(" $valueFlag = $null");
183
+ lines.push(" $tokens = [System.Collections.Generic.List[string]]::new()");
184
+ lines.push("");
185
+ lines.push(" foreach ($element in $CommandAst.CommandElements | Select-Object -Skip 1) {");
186
+ lines.push(" if ($element.Extent.EndOffset -ge $CursorPosition) {");
187
+ lines.push(" break");
188
+ lines.push(" }");
189
+ lines.push(`\t\t$tokenText = ${helperPrefix}_UnquoteToken $element.Extent.Text`);
190
+ lines.push(" [void]$tokens.Add($tokenText)");
191
+ lines.push(" }");
192
+ lines.push("");
193
+ lines.push(" foreach ($token in $tokens) {");
194
+ lines.push(" if ($expectingValue) {");
195
+ lines.push(" $expectingValue = $false");
196
+ lines.push(" $valueFlag = $null");
197
+ lines.push(" continue");
198
+ lines.push(" }");
199
+ lines.push("");
200
+ lines.push(" if ($token -eq '--') {");
201
+ lines.push(" $afterSeparator = $true");
202
+ lines.push(" break");
203
+ lines.push(" }");
204
+ lines.push("");
205
+ lines.push(`\t\t$flagMatch = ${helperPrefix}_ResolveFlagToken -PathData $pathData -Token $token`);
206
+ lines.push(" if ($null -ne $flagMatch) {");
207
+ lines.push(" if ($flagMatch.InlinePrefix -eq $null -and $flagMatch.Flag.RequiresValue) {");
208
+ lines.push(" $expectingValue = $true");
209
+ lines.push(" $valueFlag = $flagMatch.Flag");
210
+ lines.push(" }");
211
+ lines.push(" continue");
212
+ lines.push(" }");
213
+ lines.push("");
214
+ lines.push(" if ($token.StartsWith('-')) {");
215
+ lines.push(" continue");
216
+ lines.push(" }");
217
+ lines.push("");
218
+ lines.push(`\t\t$command = ${helperPrefix}_FindCommand -PathData $pathData -Token $token`);
219
+ lines.push(" if ($null -eq $command) {");
220
+ lines.push(" break");
221
+ lines.push(" }");
222
+ lines.push("");
223
+ lines.push(" $path = if ([string]::IsNullOrEmpty($path)) {");
224
+ lines.push(" $command.CanonicalName");
225
+ lines.push(" } else {");
226
+ lines.push(" \"$path $($command.CanonicalName)\"");
227
+ lines.push(" }");
228
+ lines.push(`\t\t$nextPathData = $script:${dataVarName}[$path]`);
229
+ lines.push(" if ($null -eq $nextPathData) {");
230
+ lines.push(" break");
231
+ lines.push(" }");
232
+ lines.push(" $pathData = $nextPathData");
233
+ lines.push(" }");
234
+ lines.push("");
235
+ lines.push(" return @{");
236
+ lines.push(" Path = $path");
237
+ lines.push(" PathData = $pathData");
238
+ lines.push(" AfterSeparator = $afterSeparator");
239
+ lines.push(" ExpectingValue = $expectingValue");
240
+ lines.push(" ValueFlag = $valueFlag");
241
+ lines.push(" }");
242
+ lines.push("}");
243
+ lines.push("");
244
+ lines.push(`function ${helperPrefix}_ResolveInlineValueCompletion {`);
245
+ lines.push(" param($PathData, [string]$WordToComplete)");
246
+ lines.push(`\t$flagMatch = ${helperPrefix}_ResolveFlagToken -PathData $PathData -Token $WordToComplete`);
247
+ lines.push(" if ($null -eq $flagMatch -or $flagMatch.InlinePrefix -eq $null) {");
248
+ lines.push(" return $null");
249
+ lines.push(" }");
250
+ lines.push(" return $flagMatch");
251
+ lines.push("}");
252
+ lines.push("");
253
+ lines.push(`function ${helperPrefix}_FormatCompletionValue {`);
254
+ lines.push(" param([string]$Value)");
255
+ lines.push(" if ($Value.Length -eq 0) {");
256
+ lines.push(" return \"''\"");
257
+ lines.push(" }");
258
+ lines.push("");
259
+ lines.push(" if ($Value -match '^[a-zA-Z0-9_./:\\\\-]+$') {");
260
+ lines.push(" return $Value");
261
+ lines.push(" }");
262
+ lines.push("");
263
+ lines.push(" return \"'$([CodeGeneration]::EscapeSingleQuotedStringContent($Value))'\"");
264
+ lines.push("}");
265
+ lines.push("");
266
+ lines.push(`function ${helperPrefix}_MatchesCompletionPrefix {`);
267
+ lines.push(" param([string]$WordToComplete, [string]$RawText, [string]$CompletionText)");
268
+ lines.push(" if ([string]::IsNullOrEmpty($WordToComplete)) {");
269
+ lines.push(" return $true");
270
+ lines.push(" }");
271
+ lines.push("");
272
+ lines.push(" return $RawText.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase) -or $CompletionText.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase)");
273
+ lines.push("}");
274
+ lines.push("");
275
+ lines.push(`function ${helperPrefix}_AddCommandResults {`);
276
+ lines.push(" param($Results, $PathData, [string]$WordToComplete)");
277
+ lines.push(" foreach ($command in $PathData.Commands) {");
278
+ lines.push(" foreach ($name in $command.Names) {");
279
+ lines.push(" if (-not [string]::IsNullOrEmpty($WordToComplete) -and -not $name.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase)) {");
280
+ lines.push(" continue");
281
+ lines.push(" }");
282
+ lines.push("");
283
+ lines.push(" $Results.Add([CompletionResult]::new(");
284
+ lines.push(" $name,");
285
+ lines.push(" $name,");
286
+ lines.push(" [CompletionResultType]::Command,");
287
+ lines.push(" $command.Description");
288
+ lines.push(" ))");
289
+ lines.push(" }");
290
+ lines.push(" }");
291
+ lines.push("}");
292
+ lines.push("");
293
+ lines.push(`function ${helperPrefix}_AddFlagResults {`);
294
+ lines.push(" param($Results, $PathData, [string]$WordToComplete)");
295
+ lines.push(" foreach ($flag in $PathData.Flags) {");
296
+ lines.push(" foreach ($form in $flag.Forms) {");
297
+ lines.push(" if (-not [string]::IsNullOrEmpty($WordToComplete) -and -not $form.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase)) {");
298
+ lines.push(" continue");
299
+ lines.push(" }");
300
+ lines.push("");
301
+ lines.push(" $Results.Add([CompletionResult]::new(");
302
+ lines.push(" $form,");
303
+ lines.push(" $form,");
304
+ lines.push(" [CompletionResultType]::ParameterName,");
305
+ lines.push(" $flag.Description");
306
+ lines.push(" ))");
307
+ lines.push(" }");
308
+ lines.push(" }");
309
+ lines.push("}");
310
+ lines.push("");
311
+ lines.push(`function ${helperPrefix}_AddEnumResults {`);
312
+ lines.push(" param($Results, $Flag, [string]$WordToComplete)");
313
+ lines.push(" foreach ($value in $Flag.EnumValues) {");
314
+ lines.push(`\t\t$completionText = ${helperPrefix}_FormatCompletionValue -Value $value`);
315
+ lines.push(`\t\tif (-not (${helperPrefix}_MatchesCompletionPrefix -WordToComplete $WordToComplete -RawText $value -CompletionText $completionText)) {`);
316
+ lines.push(" continue");
317
+ lines.push(" }");
318
+ lines.push("");
319
+ lines.push(" $Results.Add([CompletionResult]::new(");
320
+ lines.push(" $completionText,");
321
+ lines.push(" $value,");
322
+ lines.push(" [CompletionResultType]::ParameterValue,");
323
+ lines.push(" $Flag.Description");
324
+ lines.push(" ))");
325
+ lines.push(" }");
326
+ lines.push("}");
327
+ lines.push("");
328
+ lines.push(`function ${helperPrefix}_AddInlineEnumResults {`);
329
+ lines.push(" param($Results, $InlineValue, [string]$WordToComplete)");
330
+ lines.push(" foreach ($value in $InlineValue.Flag.EnumValues) {");
331
+ lines.push(" $rawCompletion = \"$($InlineValue.InlinePrefix)$value\"");
332
+ lines.push(`\t\t$formattedValue = ${helperPrefix}_FormatCompletionValue -Value $value`);
333
+ lines.push(" $completionText = \"$($InlineValue.InlinePrefix)$formattedValue\"");
334
+ lines.push(`\t\tif (-not (${helperPrefix}_MatchesCompletionPrefix -WordToComplete $WordToComplete -RawText $rawCompletion -CompletionText $completionText)) {`);
335
+ lines.push(" continue");
336
+ lines.push(" }");
337
+ lines.push("");
338
+ lines.push(" $Results.Add([CompletionResult]::new(");
339
+ lines.push(" $completionText,");
340
+ lines.push(" $value,");
341
+ lines.push(" [CompletionResultType]::ParameterValue,");
342
+ lines.push(" $InlineValue.Flag.Description");
343
+ lines.push(" ))");
344
+ lines.push(" }");
345
+ lines.push("}");
346
+ }
347
+ function quotePowerShellString(value) {
348
+ return `'${value.replace(/'/g, "''")}'`;
349
+ }
350
+ function formatPowerShellArray(values) {
351
+ if (values.length === 0) return "@()";
352
+ return `@(${values.map(quotePowerShellString).join(", ")})`;
353
+ }
354
+ function dedupeValues(values) {
355
+ return [...new Set(values)];
356
+ }
357
+ //#endregion
358
+ export { generatePowerShellCompletion };
@@ -1,6 +1,6 @@
1
1
  import { FlagSchema } from "../../schema/flag.mjs";
2
2
  import { CommandSchema } from "../../schema/command.mjs";
3
-
3
+ import "../../schema/index.mjs";
4
4
  //#region src/core/completion/shells/shared.d.ts
5
5
  /**
6
6
  * Format a version tag for generated completion script headers.
@@ -120,6 +120,17 @@ interface CommandNode {
120
120
  * @internal
121
121
  */
122
122
  declare function walkCommandTree(topLevel: readonly CommandSchema[], ancestorSchemas?: readonly CommandSchema[]): readonly CommandNode[];
123
+ /**
124
+ * Effective negated long-form spelling for user-facing suggestion lists.
125
+ *
126
+ * Returns the negated spelling without the `--` prefix (e.g. `no-verbose`)
127
+ * when the flag is negatable and the negation is not hidden; `undefined`
128
+ * otherwise. Negated spellings are long-only and take no value, so they only
129
+ * belong in suggestion lists — never in value-flag (operand-skip) patterns.
130
+ *
131
+ * @internal
132
+ */
133
+ declare function getVisibleNegatedName(name: string, schema: FlagSchema): string | undefined;
123
134
  /**
124
135
  * Sanitize a string for use as a shell function identifier.
125
136
  * Replaces non-alphanumeric/underscore characters with underscores.
@@ -146,4 +157,4 @@ declare function sanitizeShellIdentifier(name: string): string;
146
157
  */
147
158
  declare function quoteShellArg(value: string): string;
148
159
  //#endregion
149
- export { type CommandNode, type CompletionOptions, type RootCompletionSurface, quoteShellArg, resolveRootCompletionSurface, sanitizeShellIdentifier, versionTag, walkCommandTree };
160
+ export { type CommandNode, type CompletionOptions, type RootCompletionSurface, getVisibleNegatedName, quoteShellArg, resolveRootCompletionSurface, sanitizeShellIdentifier, versionTag, walkCommandTree };
@@ -1 +1,176 @@
1
- import{collectPropagatedFlags as e}from"../../cli/propagate.mjs";import{resolveRootSurface as t}from"../../cli/root-surface.mjs";import{DREAMCLI_REVISION as n,DREAMCLI_VERSION as r}from"../../../version.mjs";function i(){return`@kjanat/dreamcli v${r}${` (${n})`}`}function a(e,n=`subcommands`){let r=t(e),i=o(e.version!==void 0),a=r.visibleDefaultCommand?.flags??{},s=n===`surface`?r.hasVisibleDefault:r.hasVisibleDefault&&!r.hasVisibleSubcommands,c=r.visibleDefaultCommand,l=c!==void 0&&r.visibleCommands.some(e=>e.name===c.name);return{visibleCommands:c!==void 0&&!l?[c,...r.visibleCommands]:r.visibleCommands,visibleDefaultCommand:r.visibleDefaultCommand,rootFlags:i,defaultFlags:a,includeDefaultFlags:s}}function o(e){return{help:s(`Show help text`),...e?{version:s(`Show version`)}:{}}}function s(e){return{kind:`boolean`,presence:`optional`,defaultValue:void 0,aliases:[],envVar:void 0,configPath:void 0,description:e,enumValues:void 0,numberConstraints:void 0,elementSchema:void 0,prompt:void 0,parseFn:void 0,deprecated:void 0,propagate:!1}}function c(t,n=[]){let r=[];for(let i of t){if(i.hidden)continue;let t=[...n,i],a=e(t),o={...a,...i.flags},s=i.commands.filter(e=>!e.hidden);r.push({path:t.map(e=>e.name),schema:i,propagatedFlags:a,mergedFlags:o,children:s}),s.length>0&&r.push(...c(s,t))}return r}function l(e){let t=e.replace(/[^a-zA-Z0-9_]/g,`_`);if(t===e)return t;let n=2166136261;for(let t=0;t<e.length;t+=1)n^=e.charCodeAt(t),n=Math.imul(n,16777619);return`${t}_${(n>>>0).toString(16).padStart(8,`0`)}`}function u(e){return/^[a-zA-Z0-9_\-.]+$/.test(e)?e:`'${e.replace(/'/g,`'\\''`)}'`}export{u as quoteShellArg,a as resolveRootCompletionSurface,l as sanitizeShellIdentifier,i as versionTag,c as walkCommandTree};
1
+ import { getFlagNegatedName } from "../../schema/flag.mjs";
2
+ import { collectPropagatedFlags } from "../../cli/propagate.mjs";
3
+ import { resolveRootSurface } from "../../cli/root-surface.mjs";
4
+ import { DREAMCLI_REVISION, DREAMCLI_VERSION } from "../../../version.mjs";
5
+ //#region src/core/completion/shells/shared.ts
6
+ /**
7
+ * Shared infrastructure for shell completion generators.
8
+ *
9
+ * Provides the command tree walker, shell escaping utilities, and
10
+ * the version tag used in generated script headers. Consumed by
11
+ * the per-shell generators in sibling files.
12
+ *
13
+ * @module dreamcli/core/completion/shells/shared
14
+ * @internal
15
+ */
16
+ /**
17
+ * Format a version tag for generated completion script headers.
18
+ *
19
+ * Produces e.g. `"@kjanat/dreamcli v0.9.1 (f9b5f1a)"` when built, or
20
+ * `"@kjanat/dreamcli"` when running unbundled in development.
21
+ *
22
+ * @internal
23
+ */
24
+ function versionTag() {
25
+ return `@kjanat/dreamcli v${DREAMCLI_VERSION}${` (${DREAMCLI_REVISION})`}`;
26
+ }
27
+ /**
28
+ * Resolve the root-level completion surface from the CLI schema and policy.
29
+ *
30
+ * @internal
31
+ */
32
+ function resolveRootCompletionSurface(schema, rootMode = "subcommands") {
33
+ const rootSurface = resolveRootSurface(schema);
34
+ const rootFlags = createRootFlags(schema.version !== void 0);
35
+ const defaultFlags = rootSurface.visibleDefaultCommand?.flags ?? {};
36
+ const includeDefaultFlags = rootMode === "surface" ? rootSurface.hasVisibleDefault : rootSurface.hasVisibleDefault && !rootSurface.hasVisibleSubcommands;
37
+ const defaultCommand = rootSurface.visibleDefaultCommand;
38
+ const alreadyListed = defaultCommand !== void 0 && rootSurface.visibleCommands.some((c) => c.name === defaultCommand.name);
39
+ return {
40
+ visibleCommands: defaultCommand !== void 0 && !alreadyListed ? [defaultCommand, ...rootSurface.visibleCommands] : rootSurface.visibleCommands,
41
+ visibleDefaultCommand: rootSurface.visibleDefaultCommand,
42
+ rootFlags,
43
+ defaultFlags,
44
+ includeDefaultFlags
45
+ };
46
+ }
47
+ /**
48
+ * Build the synthetic root-level flags (`--help`, optionally `--version`).
49
+ *
50
+ * @param hasVersion - Whether to include a `--version` flag.
51
+ * @returns A record of root flag schemas.
52
+ * @internal
53
+ */
54
+ function createRootFlags(hasVersion) {
55
+ return {
56
+ help: createSyntheticRootFlag("Show help text"),
57
+ ...hasVersion ? { version: createSyntheticRootFlag("Show version") } : {}
58
+ };
59
+ }
60
+ /**
61
+ * Create a minimal boolean {@link FlagSchema} for a synthetic root flag.
62
+ *
63
+ * @param description - Help text for the flag.
64
+ * @returns A complete flag schema with all optional fields defaulted.
65
+ * @internal
66
+ */
67
+ function createSyntheticRootFlag(description) {
68
+ return {
69
+ kind: "boolean",
70
+ presence: "optional",
71
+ defaultValue: void 0,
72
+ aliases: [],
73
+ envVar: void 0,
74
+ configPath: void 0,
75
+ description,
76
+ enumValues: void 0,
77
+ numberConstraints: void 0,
78
+ stringConstraints: void 0,
79
+ elementSchema: void 0,
80
+ separator: void 0,
81
+ unique: false,
82
+ pathChecks: void 0,
83
+ valueHint: void 0,
84
+ prompt: void 0,
85
+ parseFn: void 0,
86
+ deprecated: void 0,
87
+ propagate: false,
88
+ negation: void 0,
89
+ duplicates: "last"
90
+ };
91
+ }
92
+ /**
93
+ * Walk the command tree depth-first, producing a flat list of
94
+ * {@link CommandNode}s with propagated flag context.
95
+ *
96
+ * @param topLevel - Top-level visible command schemas.
97
+ * @param ancestorSchemas - Schema path from root (for propagation calculation).
98
+ * @returns Flat list of all visible nodes in the tree.
99
+ *
100
+ * @internal
101
+ */
102
+ function walkCommandTree(topLevel, ancestorSchemas = []) {
103
+ const nodes = [];
104
+ for (const schema of topLevel) {
105
+ if (schema.hidden) continue;
106
+ const fullPath = [...ancestorSchemas, schema];
107
+ const propagatedFlags = collectPropagatedFlags(fullPath);
108
+ const mergedFlags = {
109
+ ...propagatedFlags,
110
+ ...schema.flags
111
+ };
112
+ const children = schema.commands.filter((c) => !c.hidden);
113
+ nodes.push({
114
+ path: fullPath.map((s) => s.name),
115
+ schema,
116
+ propagatedFlags,
117
+ mergedFlags,
118
+ children
119
+ });
120
+ if (children.length > 0) nodes.push(...walkCommandTree(children, fullPath));
121
+ }
122
+ return nodes;
123
+ }
124
+ /**
125
+ * Effective negated long-form spelling for user-facing suggestion lists.
126
+ *
127
+ * Returns the negated spelling without the `--` prefix (e.g. `no-verbose`)
128
+ * when the flag is negatable and the negation is not hidden; `undefined`
129
+ * otherwise. Negated spellings are long-only and take no value, so they only
130
+ * belong in suggestion lists — never in value-flag (operand-skip) patterns.
131
+ *
132
+ * @internal
133
+ */
134
+ function getVisibleNegatedName(name, schema) {
135
+ if (schema.negation === void 0 || schema.negation.hidden) return void 0;
136
+ return getFlagNegatedName(name, schema);
137
+ }
138
+ /**
139
+ * Sanitize a string for use as a shell function identifier.
140
+ * Replaces non-alphanumeric/underscore characters with underscores.
141
+ * When sanitization changes the name, appends a short stable hash suffix so
142
+ * distinct originals cannot collide on the same helper identifier.
143
+ * Used by both bash and zsh generators.
144
+ *
145
+ * @internal
146
+ */
147
+ function sanitizeShellIdentifier(name) {
148
+ const sanitized = name.replace(/[^a-zA-Z0-9_]/g, "_");
149
+ if (sanitized === name) return sanitized;
150
+ let hash = 2166136261;
151
+ for (let i = 0; i < name.length; i += 1) {
152
+ hash ^= name.charCodeAt(i);
153
+ hash = Math.imul(hash, 16777619);
154
+ }
155
+ return `${sanitized}_${(hash >>> 0).toString(16).padStart(8, "0")}`;
156
+ }
157
+ /**
158
+ * Quote a string for safe interpolation into a shell script.
159
+ *
160
+ * Uses single-quote wrapping with the standard `'\''` idiom for
161
+ * embedded single quotes. This prevents shell injection from CLI
162
+ * names containing spaces, semicolons, backticks, or other
163
+ * special characters.
164
+ *
165
+ * Returns the input unquoted if it consists only of shell-safe
166
+ * characters (`[a-zA-Z0-9_\-.]`), avoiding unnecessary noise
167
+ * in generated scripts for common CLI names like `my-cli` or `app.v2`.
168
+ *
169
+ * @internal
170
+ */
171
+ function quoteShellArg(value) {
172
+ if (/^[a-zA-Z0-9_\-.]+$/.test(value)) return value;
173
+ return `'${value.replace(/'/g, "'\\''")}'`;
174
+ }
175
+ //#endregion
176
+ export { getVisibleNegatedName, quoteShellArg, resolveRootCompletionSurface, sanitizeShellIdentifier, versionTag, walkCommandTree };
@@ -1,6 +1,5 @@
1
1
  import { CompletionOptions } from "./shared.mjs";
2
2
  import { CLISchema } from "../../cli/index.mjs";
3
-
4
3
  //#region src/core/completion/shells/zsh.d.ts
5
4
  /**
6
5
  * Generate a zsh completion script for the CLI.