@cnc-tools/storm 0.9.0 → 0.10.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/bin/storm.js +11 -13
- package/dist/application.d.ts +18 -10
- package/dist/application.js +13 -12
- package/dist/bin/storm.js +102 -42
- package/dist/build-info.js +1 -1
- package/dist/chunks/chunk-AGWW3HDT.js +2559 -0
- package/dist/chunks/chunk-AKKNF3WZ.js +2023 -0
- package/dist/chunks/chunk-H2VCSNVU.js +351 -0
- package/dist/chunks/chunk-I5GZLOLQ.js +38 -0
- package/dist/chunks/chunk-J6ZNYUDV.js +21 -0
- package/dist/chunks/chunk-JQ2HK4RN.js +425 -0
- package/dist/chunks/chunk-OVXD7GES.js +841 -0
- package/dist/chunks/chunk-VJQLMGOH.js +4716 -0
- package/dist/chunks/chunk-WF4KJ7YG.js +431 -0
- package/dist/chunks/chunk-XHJGHJBW.js +1509 -0
- package/dist/chunks/chunk-YF3ICDBY.js +10 -0
- package/dist/chunks/chunk-ZJ2USLAT.js +4420 -0
- package/dist/chunks/live-app-RIJM3QFD.js +97 -0
- package/dist/chunks/version-X7RMSKZI.js +12 -0
- package/dist/command-tree.d.ts +3 -0
- package/dist/command-tree.js +3 -0
- package/dist/commands/dashboard.d.ts +1 -1
- package/dist/commands/dashboard.js +1 -1
- package/dist/commands/exec/cleanup.d.ts +27 -43
- package/dist/commands/exec/cleanup.js +20 -54
- package/dist/commands/exec/command.d.ts +72 -544
- package/dist/commands/exec/command.js +69 -22
- package/dist/commands/exec/job-summary.d.ts +2 -2
- package/dist/commands/exec/job-summary.js +3 -3
- package/dist/commands/exec/live-view.d.ts +9 -9
- package/dist/commands/exec/live-view.js +48 -41
- package/dist/commands/exec/metadata.d.ts +0 -65
- package/dist/commands/exec/metadata.js +7 -58
- package/dist/commands/exec/mint-failed.d.ts +1 -1
- package/dist/commands/exec/mint-failed.js +8 -8
- package/dist/commands/exec/outcomes.d.ts +63 -468
- package/dist/commands/exec/outcomes.js +42 -69
- package/dist/commands/exec/plan-run.d.ts +150 -0
- package/dist/commands/exec/plan-run.js +121 -0
- package/dist/commands/exec/progress.d.ts +25 -15
- package/dist/commands/exec/progress.js +61 -40
- package/dist/commands/exec/redaction.d.ts +3 -3
- package/dist/commands/exec/redaction.js +4 -4
- package/dist/commands/exec/resource-flags.d.ts +50 -0
- package/dist/commands/exec/resource-flags.js +125 -0
- package/dist/commands/exec/resource-refusals.d.ts +64 -0
- package/dist/commands/exec/resource-refusals.js +58 -0
- package/dist/commands/exec/run-collector.d.ts +15 -10
- package/dist/commands/exec/run-collector.js +5 -5
- package/dist/commands/exec/run-command.d.ts +80 -165
- package/dist/commands/exec/run-command.js +264 -275
- package/dist/commands/exec/run-metadata.d.ts +20 -43
- package/dist/commands/exec/run-metadata.js +18 -37
- package/dist/commands/exec/run-record.d.ts +67 -58
- package/dist/commands/exec/run-record.js +15 -32
- package/dist/commands/exec/test-plan.d.ts +45 -0
- package/dist/commands/exec/test-plan.js +59 -0
- package/dist/commands/exec/tests-summary.d.ts +5 -5
- package/dist/commands/exec/tests-summary.js +2 -2
- package/dist/commands/exec/text.d.ts +8 -2
- package/dist/commands/exec/text.js +8 -0
- package/dist/commands/exec/timeline-facts.d.ts +57 -0
- package/dist/commands/exec/timeline-facts.js +92 -0
- package/dist/commands/exec/view.d.ts +5 -7
- package/dist/commands/exec/view.js +21 -13
- package/dist/commands/exec/waterfall.d.ts +2 -9
- package/dist/commands/exec/waterfall.js +9 -30
- package/dist/commands/exec/worker-chart.d.ts +1 -1
- package/dist/commands/ext/metadata.d.ts +4 -0
- package/dist/commands/ext/metadata.js +8 -0
- package/dist/commands/runs/facts.d.ts +9 -5
- package/dist/commands/runs/facts.js +26 -14
- package/dist/commands/runs/list/command.d.ts +15 -8
- package/dist/commands/runs/list/command.js +142 -33
- package/dist/commands/runs/list/metadata.d.ts +16 -14
- package/dist/commands/runs/list/metadata.js +21 -15
- package/dist/commands/runs/list/outcomes.d.ts +6 -2
- package/dist/commands/runs/logs/command.d.ts +3 -4
- package/dist/commands/runs/logs/command.js +135 -49
- package/dist/commands/runs/logs/metadata.d.ts +17 -15
- package/dist/commands/runs/logs/metadata.js +23 -17
- package/dist/commands/runs/metadata.js +6 -2
- package/dist/commands/runs/past-run.d.ts +3 -9
- package/dist/commands/runs/past-run.js +2 -17
- package/dist/commands/runs/show/command.d.ts +57 -42
- package/dist/commands/runs/show/command.js +404 -74
- package/dist/commands/runs/show/metadata.d.ts +20 -18
- package/dist/commands/runs/show/metadata.js +23 -17
- package/dist/commands/runs/show/outcomes.d.ts +27 -19
- package/dist/commands/runs/show/outcomes.js +8 -6
- package/dist/commands/vitest/command.d.ts +94 -559
- package/dist/commands/vitest/command.js +176 -132
- package/dist/commands/vitest/metadata.d.ts +0 -65
- package/dist/commands/vitest/metadata.js +7 -38
- package/dist/commands/vitest/outcomes.d.ts +44 -274
- package/dist/commands/vitest/outcomes.js +7 -14
- package/dist/config/credential-resolver.d.ts +131 -0
- package/dist/config/credential-resolver.js +69 -0
- package/dist/{credential/settle.d.ts → config/credential-settle.d.ts} +1 -2
- package/dist/config/errors.d.ts +1 -1
- package/dist/config/errors.js +5 -5
- package/dist/config/index.d.ts +7 -6
- package/dist/config/index.js +13 -9
- package/dist/config/load.d.ts +16 -13
- package/dist/config/load.js +55 -40
- package/dist/config/recipe-run.d.ts +26 -0
- package/dist/config/recipe-run.js +27 -0
- package/dist/config/resolve.d.ts +103 -15
- package/dist/config/resolve.js +137 -47
- package/dist/config/resolver.d.ts +40 -0
- package/dist/config/resolver.js +31 -0
- package/dist/config/schema.d.ts +13 -17
- package/dist/config/schema.js +14 -35
- package/dist/config/settings-file.d.ts +28 -16
- package/dist/config/settings-file.js +39 -24
- package/dist/config/typed-options.d.ts +21 -0
- package/dist/config/typed-options.js +28 -0
- package/dist/config-file/define.d.ts +33 -31
- package/dist/config-file/define.js +14 -4
- package/dist/config-file/toolchain.d.ts +1 -1
- package/dist/context.d.ts +37 -24
- package/dist/context.js +16 -8
- package/dist/core/before-run.d.ts +37 -0
- package/dist/core/before-run.js +44 -0
- package/dist/core/events.d.ts +55 -46
- package/dist/core/gateways.d.ts +17 -18
- package/dist/core/index.d.ts +12 -12
- package/dist/core/index.js +12 -8
- package/dist/core/launcher-supplies.d.ts +11 -0
- package/dist/core/launcher-supplies.js +28 -0
- package/dist/core/mint.js +2 -2
- package/dist/core/payload.d.ts +13 -14
- package/dist/core/payload.js +9 -8
- package/dist/core/presentations.d.ts +37 -37
- package/dist/core/presentations.js +49 -56
- package/dist/core/reports.d.ts +5 -0
- package/dist/core/reports.js +13 -0
- package/dist/core/resource-registry.d.ts +54 -0
- package/dist/core/resource-registry.js +57 -0
- package/dist/core/resource-reports.d.ts +36 -0
- package/dist/core/resource-reports.js +38 -0
- package/dist/core/resource.d.ts +135 -243
- package/dist/core/resource.js +7 -5
- package/dist/core/resources-of.d.ts +16 -0
- package/dist/core/resources-of.js +8 -0
- package/dist/core/resources.d.ts +96 -84
- package/dist/core/resources.js +168 -165
- package/dist/core/run-directory.d.ts +10 -11
- package/dist/core/run-directory.js +9 -9
- package/dist/core/run-state.d.ts +29 -41
- package/dist/core/run-state.js +56 -60
- package/dist/core/run.d.ts +77 -66
- package/dist/core/run.js +83 -74
- package/dist/core/state-directory.js +4 -3
- package/dist/core/timeline.d.ts +42 -24
- package/dist/core/timeline.js +45 -27
- package/dist/core/timing.d.ts +3 -3
- package/dist/core/timing.js +1 -1
- package/dist/credential/gateways.d.ts +1 -80
- package/dist/credential/index.d.ts +3 -5
- package/dist/credential/index.js +7 -5
- package/dist/credential/live/github-actions-token-response.js +1 -1
- package/dist/credential/live/vercel-cli-gateway.d.ts +2 -1
- package/dist/credential/live/vercel-cli-gateway.js +1 -1
- package/dist/credential/live/vercel-output.d.ts +1 -1
- package/dist/credential/source.d.ts +16 -59
- package/dist/credential/source.js +21 -7
- package/dist/credential/target.d.ts +1 -1
- package/dist/extension-commands.d.ts +14 -0
- package/dist/extension-commands.js +20 -0
- package/dist/extensions/github/definition.d.ts +26 -0
- package/dist/extensions/github/definition.js +29 -0
- package/dist/extensions/github/extension.d.ts +18 -0
- package/dist/extensions/github/extension.js +6 -0
- package/dist/{resources → extensions}/github/fixture-repo.d.ts +11 -8
- package/dist/{resources → extensions}/github/fixture-repo.js +8 -4
- package/dist/extensions/github/index.d.ts +13 -0
- package/dist/extensions/github/index.js +17 -0
- package/dist/extensions/github/lifecycle.d.ts +30 -0
- package/dist/extensions/github/lifecycle.js +69 -0
- package/dist/extensions/github/live/world.d.ts +6 -0
- package/dist/extensions/github/live/world.js +16 -0
- package/dist/extensions/github/options.d.ts +36 -0
- package/dist/extensions/github/options.js +36 -0
- package/dist/extensions/github/refusals.d.ts +32 -0
- package/dist/extensions/github/refusals.js +43 -0
- package/dist/extensions/github/release.d.ts +17 -0
- package/dist/extensions/github/release.js +34 -0
- package/dist/extensions/github/resource.d.ts +36 -0
- package/dist/extensions/github/resource.js +21 -0
- package/dist/extensions/github/run/payload.d.ts +27 -0
- package/dist/extensions/github/run/payload.js +42 -0
- package/dist/extensions/github/world.d.ts +15 -0
- package/dist/extensions/github/world.js +3 -0
- package/dist/extensions/testserver/canceled.d.ts +7 -0
- package/dist/extensions/testserver/canceled.js +27 -0
- package/dist/extensions/testserver/command-tree.d.ts +6 -0
- package/dist/extensions/testserver/command-tree.js +21 -0
- package/dist/extensions/testserver/commands/app.d.ts +22 -0
- package/dist/extensions/testserver/commands/app.js +5 -0
- package/dist/{resources/testserver/commands → extensions/testserver/commands/pool}/create/command.d.ts +277 -237
- package/dist/extensions/testserver/commands/pool/create/command.js +352 -0
- package/dist/extensions/testserver/commands/pool/create/metadata.d.ts +33 -0
- package/dist/extensions/testserver/commands/pool/create/metadata.js +55 -0
- package/dist/{resources/testserver/commands → extensions/testserver/commands/pool}/create/outcomes.d.ts +132 -112
- package/dist/{resources/testserver/commands → extensions/testserver/commands/pool}/create/outcomes.js +6 -24
- package/dist/{resources/testserver/commands → extensions/testserver/commands/pool}/list/command.d.ts +3 -4
- package/dist/extensions/testserver/commands/pool/list/command.js +203 -0
- package/dist/extensions/testserver/commands/pool/list/metadata.d.ts +11 -0
- package/dist/extensions/testserver/commands/pool/list/metadata.js +15 -0
- package/dist/{resources/testserver/commands → extensions/testserver/commands/pool}/list/outcomes.js +1 -1
- package/dist/extensions/testserver/commands/pool/metadata.d.ts +3 -0
- package/dist/extensions/testserver/commands/pool/metadata.js +7 -0
- package/dist/extensions/testserver/commands/tree.d.ts +2 -0
- package/dist/extensions/testserver/commands/tree.js +6 -0
- package/dist/{resources → extensions}/testserver/credential-facts.d.ts +6 -40
- package/dist/{resources → extensions}/testserver/credential-facts.js +13 -35
- package/dist/extensions/testserver/definition.d.ts +57 -0
- package/dist/extensions/testserver/definition.js +71 -0
- package/dist/{resources → extensions}/testserver/events.d.ts +5 -4
- package/dist/extensions/testserver/events.js +4 -0
- package/dist/extensions/testserver/extension.d.ts +46 -0
- package/dist/extensions/testserver/extension.js +68 -0
- package/dist/extensions/testserver/index.d.ts +20 -0
- package/dist/extensions/testserver/index.js +31 -0
- package/dist/extensions/testserver/lifecycle.d.ts +24 -0
- package/dist/extensions/testserver/lifecycle.js +116 -0
- package/dist/{core → extensions/testserver}/limit.js +1 -0
- package/dist/extensions/testserver/live/world.d.ts +8 -0
- package/dist/extensions/testserver/live/world.js +38 -0
- package/dist/{resources/testserver/sandbox → extensions/testserver/options}/channels.d.ts +1 -1
- package/dist/extensions/testserver/options/index.d.ts +5 -0
- package/dist/extensions/testserver/options/index.js +11 -0
- package/dist/extensions/testserver/options/rules.d.ts +69 -0
- package/dist/extensions/testserver/options/rules.js +92 -0
- package/dist/extensions/testserver/options/sandboxes.d.ts +29 -0
- package/dist/extensions/testserver/options/sandboxes.js +33 -0
- package/dist/extensions/testserver/options/ttl.d.ts +23 -0
- package/dist/extensions/testserver/options/ttl.js +42 -0
- package/dist/{resources → extensions}/testserver/pool/channels.d.ts +3 -3
- package/dist/{resources → extensions}/testserver/pool/channels.js +2 -2
- package/dist/{resources → extensions}/testserver/pool/create.d.ts +1 -2
- package/dist/{resources → extensions}/testserver/pool/create.js +2 -1
- package/dist/{resources → extensions}/testserver/pool/index.d.ts +0 -1
- package/dist/{resources → extensions}/testserver/pool/index.js +2 -3
- package/dist/{resources → extensions}/testserver/pool/inspect.d.ts +1 -1
- package/dist/{resources → extensions}/testserver/pool/lease.d.ts +1 -1
- package/dist/extensions/testserver/pool/live/pool-store-gateway.d.ts +12 -0
- package/dist/{resources → extensions}/testserver/pool/live/pool-store-gateway.js +4 -4
- package/dist/{resources → extensions}/testserver/pool/pull-request.d.ts +8 -5
- package/dist/{resources → extensions}/testserver/pool/pull-request.js +2 -2
- package/dist/extensions/testserver/pr-build-facts.d.ts +156 -0
- package/dist/extensions/testserver/pr-build-facts.js +309 -0
- package/dist/extensions/testserver/presentation.d.ts +11 -0
- package/dist/{resources → extensions}/testserver/presentation.js +35 -56
- package/dist/{resources/testserver/lane.d.ts → extensions/testserver/progress.d.ts} +10 -6
- package/dist/{resources/testserver/lane.js → extensions/testserver/progress.js} +21 -16
- package/dist/extensions/testserver/provision.d.ts +160 -0
- package/dist/{resources/testserver/provider.js → extensions/testserver/provision.js} +80 -108
- package/dist/{resources → extensions}/testserver/pull-request/gateways.d.ts +1 -1
- package/dist/extensions/testserver/pull-request/gateways.js +5 -0
- package/dist/{resources → extensions}/testserver/pull-request/index.js +2 -2
- package/dist/{resources → extensions}/testserver/pull-request/live/github-token-gateway.d.ts +4 -4
- package/dist/{resources → extensions}/testserver/pull-request/live/github-token-gateway.js +4 -4
- package/dist/extensions/testserver/refusals.d.ts +72 -0
- package/dist/extensions/testserver/refusals.js +117 -0
- package/dist/extensions/testserver/release.d.ts +14 -0
- package/dist/extensions/testserver/release.js +26 -0
- package/dist/extensions/testserver/resource.d.ts +57 -0
- package/dist/extensions/testserver/resource.js +19 -0
- package/dist/extensions/testserver/result.d.ts +55 -0
- package/dist/extensions/testserver/result.js +98 -0
- package/dist/extensions/testserver/run/connection.d.ts +21 -0
- package/dist/extensions/testserver/run/connection.js +39 -0
- package/dist/extensions/testserver/run-sandbox.d.ts +16 -0
- package/dist/extensions/testserver/run-sandbox.js +11 -0
- package/dist/{resources → extensions}/testserver/sandbox/create.d.ts +1 -11
- package/dist/{resources → extensions}/testserver/sandbox/create.js +0 -15
- package/dist/{resources → extensions}/testserver/sandbox/gateways.d.ts +1 -1
- package/dist/{resources → extensions}/testserver/sandbox/index.d.ts +1 -3
- package/dist/extensions/testserver/sandbox/index.js +6 -0
- package/dist/extensions/testserver/testserver-sdk.d.ts +1 -0
- package/dist/extensions/testserver/testserver-sdk.js +4 -0
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/arguments.js +1 -1
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/context.js +1 -1
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/driver.d.ts +1 -1
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/gateways.js +1 -1
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/index.js +4 -4
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/invocation.d.ts +1 -1
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/invocation.js +1 -1
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/redaction.js +1 -1
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/report.d.ts +1 -1
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/report.js +1 -1
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/verbose.js +1 -1
- package/dist/extensions/testserver/vitest/config.d.ts +28 -0
- package/dist/extensions/testserver/vitest/config.js +39 -0
- package/dist/{vitest → extensions/testserver/vitest}/container-scope.d.ts +33 -15
- package/dist/{vitest → extensions/testserver/vitest}/container-scope.js +75 -14
- package/dist/extensions/testserver/vitest/container-start.d.ts +19 -0
- package/dist/extensions/testserver/vitest/container-start.js +31 -0
- package/dist/{vitest → extensions/testserver/vitest}/diagnostics.d.ts +72 -29
- package/dist/{vitest → extensions/testserver/vitest}/diagnostics.js +151 -52
- package/dist/{vitest → extensions/testserver/vitest}/fixtures.d.ts +8 -5
- package/dist/{vitest → extensions/testserver/vitest}/fixtures.js +45 -22
- package/dist/extensions/testserver/vitest/index.d.ts +3 -0
- package/dist/extensions/testserver/vitest/index.js +10 -0
- package/dist/extensions/testserver/vitest/sandbox.d.ts +25 -0
- package/dist/extensions/testserver/vitest/sandbox.js +43 -0
- package/dist/{vitest → extensions/testserver/vitest}/types.d.ts +1 -1
- package/dist/extensions/testserver/world.d.ts +25 -0
- package/dist/extensions/testserver/world.js +4 -0
- package/dist/extensions.d.ts +153 -0
- package/dist/extensions.js +53 -0
- package/dist/help-logo.js +5 -5
- package/dist/launch.js +46 -0
- package/dist/launcher-resolvers/index.d.ts +1 -0
- package/dist/launcher-resolvers/index.js +7 -0
- package/dist/live-app.d.ts +9 -0
- package/dist/live-app.js +25 -0
- package/dist/presentation.js +2 -2
- package/dist/runner/base.js +1 -1
- package/dist/runner/context.js +1 -1
- package/dist/runner/events.js +1 -1
- package/dist/runner/gateways.d.ts +11 -11
- package/dist/runner/gateways.js +1 -1
- package/dist/runner/index.d.ts +4 -4
- package/dist/runner/index.js +1 -1
- package/dist/runner/live/sandbox-gateway.js +4 -4
- package/dist/runner/live/terminal.d.ts +1 -1
- package/dist/runner/live/terminal.js +1 -1
- package/dist/runner/prepare.d.ts +13 -12
- package/dist/runner/prepare.js +3 -3
- package/dist/runner/ready.js +2 -2
- package/dist/runner/recipe.d.ts +24 -20
- package/dist/runner/recipe.js +19 -17
- package/dist/runner/{remote-command.d.ts → sandboxed-command.d.ts} +18 -19
- package/dist/runner/{remote-command.js → sandboxed-command.js} +21 -22
- package/dist/runner/scope.d.ts +3 -3
- package/dist/runner/secrets.js +1 -1
- package/dist/runner/snapshot-key.d.ts +1 -1
- package/dist/runner/snapshot-key.js +4 -4
- package/dist/runner/snapshot-save.js +3 -3
- package/dist/sdk/extension/commands.d.ts +71 -0
- package/dist/sdk/extension/commands.js +31 -0
- package/dist/{credential/diagnosis.d.ts → sdk/extension/credential-diagnosis.d.ts} +1 -7
- package/dist/{credential/diagnosis.js → sdk/extension/credential-diagnosis.js} +2 -11
- package/dist/sdk/extension/credential-source.d.ts +132 -0
- package/dist/sdk/extension/credential-source.js +5 -0
- package/dist/{credential → sdk/extension}/credential.d.ts +8 -7
- package/dist/{credential → sdk/extension}/credential.js +9 -6
- package/dist/sdk/extension/index.d.ts +15 -0
- package/dist/sdk/extension/index.js +39 -0
- package/dist/sdk/extension/launcher-supplies.d.ts +24 -0
- package/dist/sdk/extension/launcher-supplies.js +3 -0
- package/dist/sdk/extension/lifecycle.d.ts +211 -0
- package/dist/sdk/extension/lifecycle.js +9 -0
- package/dist/sdk/extension/presentation.d.ts +31 -0
- package/dist/sdk/extension/presentation.js +7 -0
- package/dist/sdk/extension/progress.d.ts +75 -0
- package/dist/sdk/extension/progress.js +8 -0
- package/dist/sdk/extension/reports.d.ts +15 -0
- package/dist/sdk/extension/reports.js +5 -0
- package/dist/sdk/extension/resource-definition.d.ts +204 -0
- package/dist/sdk/extension/resource-definition.js +24 -0
- package/dist/sdk/extension/resource-factory.d.ts +10 -0
- package/dist/sdk/extension/resource-factory.js +15 -0
- package/dist/sdk/extension/resource.d.ts +60 -0
- package/dist/sdk/extension/resource.js +42 -0
- package/dist/sdk/extension/rules.d.ts +16 -0
- package/dist/sdk/extension/rules.js +30 -0
- package/dist/sdk/extension/span.d.ts +8 -0
- package/dist/sdk/extension/span.js +4 -0
- package/dist/sdk/extension/time.d.ts +11 -0
- package/dist/sdk/extension/time.js +4 -0
- package/dist/sdk/extension/token-request-facts.d.ts +39 -0
- package/dist/sdk/extension/token-request-facts.js +35 -0
- package/dist/sdk/index.d.ts +4 -7
- package/dist/sdk/index.js +7 -15
- package/dist/sdk/run/contract.d.ts +32 -0
- package/dist/sdk/run/contract.js +12 -0
- package/dist/sdk/run/launcher.d.ts +5 -0
- package/dist/sdk/run/launcher.js +6 -0
- package/dist/sdk/run/payload.d.ts +58 -0
- package/dist/sdk/run/payload.js +73 -0
- package/dist/sdk/run/present.d.ts +11 -0
- package/dist/sdk/run/present.js +4 -0
- package/dist/sdk/run/redact.d.ts +5 -0
- package/dist/sdk/run/redact.js +12 -0
- package/dist/time/duration.js +2 -2
- package/dist/time/index.js +2 -1
- package/dist/time/time.d.ts +2 -11
- package/dist/time/time.js +2 -2
- package/dist/{sdk → vendor/testserver-sdk}/container/api-request.d.ts +14 -2
- package/dist/vendor/testserver-sdk/container/api-request.js +68 -0
- package/dist/{sdk → vendor/testserver-sdk}/container/container.d.ts +74 -24
- package/dist/{sdk → vendor/testserver-sdk}/container/container.js +180 -90
- package/dist/vendor/testserver-sdk/container/external.d.ts +111 -0
- package/dist/vendor/testserver-sdk/container/external.js +76 -0
- package/dist/vendor/testserver-sdk/container/gateways.d.ts +156 -0
- package/dist/{sdk → vendor/testserver-sdk}/container/index.d.ts +2 -1
- package/dist/{sdk → vendor/testserver-sdk}/container/index.js +2 -1
- package/dist/vendor/testserver-sdk/container/live/container-gateway.d.ts +22 -0
- package/dist/vendor/testserver-sdk/container/live/container-gateway.js +165 -0
- package/dist/vendor/testserver-sdk/container/recorder.d.ts +69 -0
- package/dist/vendor/testserver-sdk/container/recorder.js +121 -0
- package/dist/{sdk → vendor/testserver-sdk}/factories/build.d.ts +33 -12
- package/dist/{sdk → vendor/testserver-sdk}/factories/build.js +36 -14
- package/dist/vendor/testserver-sdk/factories/definition.d.ts +39 -0
- package/dist/{sdk → vendor/testserver-sdk}/factories/definition.js +1 -1
- package/dist/{sdk → vendor/testserver-sdk}/factories/definitions.d.ts +7 -4
- package/dist/{sdk → vendor/testserver-sdk}/factories/definitions.js +10 -0
- package/dist/vendor/testserver-sdk/factories/gateways.d.ts +31 -0
- package/dist/vendor/testserver-sdk/factories/index.d.ts +4 -0
- package/dist/{sdk → vendor/testserver-sdk}/factories/index.js +3 -3
- package/dist/vendor/testserver-sdk/index.d.ts +6 -0
- package/dist/vendor/testserver-sdk/index.js +11 -0
- package/dist/{sdk → vendor/testserver-sdk}/proxy/exchange.d.ts +2 -1
- package/dist/{sdk → vendor/testserver-sdk}/proxy/exchange.js +8 -4
- package/dist/{sdk → vendor/testserver-sdk}/proxy/faulted-exchange.js +7 -2
- package/dist/{sdk → vendor/testserver-sdk}/proxy/faults.d.ts +2 -1
- package/dist/{sdk → vendor/testserver-sdk}/proxy/records.d.ts +10 -1
- package/dist/{sdk → vendor/testserver-sdk}/proxy/records.js +13 -0
- package/dist/{sdk → vendor/testserver-sdk}/records/index.d.ts +1 -1
- package/dist/{sdk → vendor/testserver-sdk}/records/records.d.ts +17 -1
- package/dist/vendor/testserver-sdk/testserver/external-ids.d.ts +38 -0
- package/dist/vendor/testserver-sdk/testserver/external-ids.js +46 -0
- package/dist/vendor/testserver-sdk/testserver/failure.d.ts +101 -0
- package/dist/vendor/testserver-sdk/testserver/failure.js +108 -0
- package/dist/vendor/testserver-sdk/testserver/index.d.ts +7 -0
- package/dist/vendor/testserver-sdk/testserver/index.js +11 -0
- package/dist/{sdk → vendor/testserver-sdk}/testserver/live/request.d.ts +8 -10
- package/dist/{sdk → vendor/testserver-sdk}/testserver/live/request.js +8 -6
- package/dist/vendor/testserver-sdk/testserver/routes.d.ts +60 -0
- package/dist/vendor/testserver-sdk/testserver/routes.js +84 -0
- package/dist/vendor/testserver-sdk/testserver/service-ids.d.ts +31 -0
- package/dist/{sdk → vendor/testserver-sdk}/testserver/service-ids.js +27 -4
- package/dist/version.d.ts +2 -2
- package/dist/version.js +10 -11
- package/dist/vitest/config.d.ts +2 -32
- package/dist/vitest/config.js +6 -40
- package/dist/vitest/gateways.js +1 -1
- package/dist/vitest/index.d.ts +2 -3
- package/dist/vitest/index.js +5 -9
- package/dist/vitest/plan.d.ts +1 -16
- package/dist/vitest/plan.js +4 -36
- package/dist/vitest/test-events.d.ts +1 -18
- package/dist/vitest/test-events.js +2 -31
- package/package.json +53 -23
- package/skills/overview.md +9 -9
- package/skills/read-run-output.md +25 -2
- package/skills/testserver-builds.md +8 -8
- package/bin/node-version.js +0 -24
- package/dist/closed-terminal.d.ts +0 -7
- package/dist/closed-terminal.js +0 -18
- package/dist/combine-errors.d.ts +0 -11
- package/dist/combine-errors.js +0 -19
- package/dist/commands/exec/testserver-flags.d.ts +0 -48
- package/dist/commands/exec/testserver-flags.js +0 -80
- package/dist/config/by-name.d.ts +0 -24
- package/dist/config/by-name.js +0 -26
- package/dist/config/resource-config.d.ts +0 -132
- package/dist/config/resource-config.js +0 -19
- package/dist/config/set.d.ts +0 -27
- package/dist/config/set.js +0 -71
- package/dist/core/command-provider.d.ts +0 -126
- package/dist/core/command-provider.js +0 -13
- package/dist/core/command-slots.d.ts +0 -73
- package/dist/core/command-slots.js +0 -140
- package/dist/core/keyed.d.ts +0 -12
- package/dist/core/keyed.js +0 -24
- package/dist/core/lane.d.ts +0 -46
- package/dist/core/lane.js +0 -5
- package/dist/core/presentation.d.ts +0 -87
- package/dist/core/presentation.js +0 -5
- package/dist/core/provider.d.ts +0 -69
- package/dist/core/provider.js +0 -5
- package/dist/resources/github/cleanup.d.ts +0 -23
- package/dist/resources/github/cleanup.js +0 -39
- package/dist/resources/github/command.d.ts +0 -126
- package/dist/resources/github/command.js +0 -117
- package/dist/resources/github/config.d.ts +0 -16
- package/dist/resources/github/config.js +0 -37
- package/dist/resources/github/events.d.ts +0 -26
- package/dist/resources/github/events.js +0 -2
- package/dist/resources/github/index.d.ts +0 -12
- package/dist/resources/github/index.js +0 -15
- package/dist/resources/github/live/gateways.d.ts +0 -6
- package/dist/resources/github/live/gateways.js +0 -13
- package/dist/resources/github/presentation.d.ts +0 -13
- package/dist/resources/github/presentation.js +0 -43
- package/dist/resources/github/provider.d.ts +0 -66
- package/dist/resources/github/provider.js +0 -58
- package/dist/resources/github/resource-provider.d.ts +0 -6
- package/dist/resources/github/resource-provider.js +0 -20
- package/dist/resources/github/resource.d.ts +0 -33
- package/dist/resources/github/resource.js +0 -12
- package/dist/resources/testserver/cleanup.d.ts +0 -14
- package/dist/resources/testserver/cleanup.js +0 -22
- package/dist/resources/testserver/command.d.ts +0 -520
- package/dist/resources/testserver/command.js +0 -252
- package/dist/resources/testserver/commands/app.d.ts +0 -18
- package/dist/resources/testserver/commands/app.js +0 -3
- package/dist/resources/testserver/commands/create/command.js +0 -208
- package/dist/resources/testserver/commands/create/metadata.d.ts +0 -31
- package/dist/resources/testserver/commands/create/metadata.js +0 -49
- package/dist/resources/testserver/commands/list/command.js +0 -56
- package/dist/resources/testserver/commands/list/metadata.d.ts +0 -9
- package/dist/resources/testserver/commands/list/metadata.js +0 -9
- package/dist/resources/testserver/config.d.ts +0 -18
- package/dist/resources/testserver/config.js +0 -88
- package/dist/resources/testserver/events.js +0 -4
- package/dist/resources/testserver/index.d.ts +0 -16
- package/dist/resources/testserver/index.js +0 -25
- package/dist/resources/testserver/live/gateways.d.ts +0 -8
- package/dist/resources/testserver/live/gateways.js +0 -39
- package/dist/resources/testserver/options.d.ts +0 -5
- package/dist/resources/testserver/options.js +0 -5
- package/dist/resources/testserver/pool/directory.d.ts +0 -4
- package/dist/resources/testserver/pool/directory.js +0 -5
- package/dist/resources/testserver/pool/live/pool-store-gateway.d.ts +0 -12
- package/dist/resources/testserver/pr-build-facts.d.ts +0 -130
- package/dist/resources/testserver/pr-build-facts.js +0 -261
- package/dist/resources/testserver/presentation.d.ts +0 -9
- package/dist/resources/testserver/provider.d.ts +0 -187
- package/dist/resources/testserver/pull-request/gateways.js +0 -5
- package/dist/resources/testserver/ran.d.ts +0 -92
- package/dist/resources/testserver/ran.js +0 -156
- package/dist/resources/testserver/resource-provider.d.ts +0 -12
- package/dist/resources/testserver/resource-provider.js +0 -38
- package/dist/resources/testserver/resource.d.ts +0 -36
- package/dist/resources/testserver/resource.js +0 -10
- package/dist/resources/testserver/run-sandbox.d.ts +0 -13
- package/dist/resources/testserver/run-sandbox.js +0 -6
- package/dist/resources/testserver/sandbox/index.js +0 -8
- package/dist/resources.d.ts +0 -705
- package/dist/resources.js +0 -88
- package/dist/sdk/container/api-request.js +0 -46
- package/dist/sdk/container/gateways.d.ts +0 -108
- package/dist/sdk/container/live/container-gateway.d.ts +0 -17
- package/dist/sdk/container/live/container-gateway.js +0 -114
- package/dist/sdk/factories/definition.d.ts +0 -28
- package/dist/sdk/factories/gateways.d.ts +0 -25
- package/dist/sdk/factories/index.d.ts +0 -5
- package/dist/sdk/factories/live/factory-gateway.d.ts +0 -10
- package/dist/sdk/factories/live/factory-gateway.js +0 -29
- package/dist/sdk/payload/index.d.ts +0 -2
- package/dist/sdk/payload/index.js +0 -4
- package/dist/sdk/payload/payload.d.ts +0 -47
- package/dist/sdk/payload/payload.js +0 -74
- package/dist/sdk/testserver/failure.d.ts +0 -73
- package/dist/sdk/testserver/failure.js +0 -61
- package/dist/sdk/testserver/index.d.ts +0 -5
- package/dist/sdk/testserver/index.js +0 -8
- package/dist/sdk/testserver/service-ids.d.ts +0 -19
- package/dist/vitest/sandbox.d.ts +0 -16
- package/dist/vitest/sandbox.js +0 -35
- /package/dist/{credential/settle.js → config/credential-settle.js} +0 -0
- /package/dist/{resources → extensions}/github/gateways.d.ts +0 -0
- /package/dist/{resources → extensions}/github/gateways.js +0 -0
- /package/dist/{resources → extensions}/github/live/fixture-repo-gateway.d.ts +0 -0
- /package/dist/{resources → extensions}/github/live/fixture-repo-gateway.js +0 -0
- /package/dist/{resources/testserver/commands → extensions/testserver/commands/pool}/list/outcomes.d.ts +0 -0
- /package/dist/{core → extensions/testserver}/limit.d.ts +0 -0
- /package/dist/{resources/testserver/sandbox → extensions/testserver/options}/build-reference.d.ts +0 -0
- /package/dist/{resources/testserver/sandbox → extensions/testserver/options}/build-reference.js +0 -0
- /package/dist/{resources/testserver/sandbox → extensions/testserver/options}/channels.js +0 -0
- /package/dist/{resources → extensions}/testserver/pool/gateways.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/pool/gateways.js +0 -0
- /package/dist/{resources → extensions}/testserver/pool/host.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/pool/host.js +0 -0
- /package/dist/{resources → extensions}/testserver/pool/inspect.js +0 -0
- /package/dist/{resources → extensions}/testserver/pool/lease.js +0 -0
- /package/dist/{resources → extensions}/testserver/pool/live/pool-records.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/pool/live/pool-records.js +0 -0
- /package/dist/{resources → extensions}/testserver/pool/staleness.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/pool/staleness.js +0 -0
- /package/dist/{resources → extensions}/testserver/pull-request/index.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/pull-request/live/github-rest.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/pull-request/live/github-rest.js +0 -0
- /package/dist/{resources → extensions}/testserver/pull-request/live/pull-request-gateway.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/pull-request/live/pull-request-gateway.js +0 -0
- /package/dist/{resources → extensions}/testserver/pull-request/live/testserver-workflow-gateway.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/pull-request/live/testserver-workflow-gateway.js +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/create-failure.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/create-failure.js +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/gateways.js +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/builds-response.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/builds-response.js +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/control-plane-gateway.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/control-plane-gateway.js +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/create-response.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/create-response.js +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/fetch-failure.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/fetch-failure.js +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/health-check-gateway.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/health-check-gateway.js +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/sse.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/sse.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/ansi.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/ansi.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/arguments.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/auth-config.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/auth-config.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/clock.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/clock.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/config-files.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/config-files.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/context.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/driver.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/entry.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/entry.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/environment.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/environment.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/errors.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/errors.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/gateways.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/index.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/keys.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/keys.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/live/config-files.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/live/config-files.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/live/process-gateway.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/live/process-gateway.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/redaction.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/verbose.d.ts +0 -0
- /package/dist/{vitest → extensions/testserver/vitest}/types.js +0 -0
- /package/dist/sdk/{payload → run}/test-events.d.ts +0 -0
- /package/dist/sdk/{payload → run}/test-events.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/container/feature-flags.d.ts +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/container/feature-flags.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/container/gateways.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/factories/gateways.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/proxy/faulted-exchange.d.ts +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/proxy/faults.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/proxy/index.d.ts +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/proxy/index.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/proxy/proxy.d.ts +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/proxy/proxy.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/records/body.d.ts +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/records/body.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/records/index.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/records/records.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/seed/index.d.ts +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/seed/index.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/seed/seed.d.ts +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/seed/seed.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/testserver/clock.d.ts +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/testserver/clock.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/testserver/live/connect-failure.d.ts +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/testserver/live/connect-failure.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/testserver/test-id.d.ts +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/testserver/test-id.js +0 -0
|
@@ -0,0 +1,4420 @@
|
|
|
1
|
+
// ../../../libs/clinkr/ts/dist/outcomes/refusals.js
|
|
2
|
+
function refused(error) {
|
|
3
|
+
return { ok: false, refusal: error };
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// ../../../libs/clinkr/ts/dist/outcomes/confirmation.js
|
|
7
|
+
import { z as z2 } from "zod";
|
|
8
|
+
|
|
9
|
+
// ../../../libs/clinkr/ts/dist/outcomes/clinkr-errors.js
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
var CLINKR_REASONS = Object.freeze([
|
|
12
|
+
"invalid_arguments",
|
|
13
|
+
"internal_error",
|
|
14
|
+
"canceled",
|
|
15
|
+
"confirmation_required"
|
|
16
|
+
]);
|
|
17
|
+
function invalidArguments(message, issues) {
|
|
18
|
+
const content = issues === void 0 ? { message } : {
|
|
19
|
+
message,
|
|
20
|
+
rows: issues.map(({ field, message: issue }) => [field, issue]),
|
|
21
|
+
data: { issues: issues.map(({ field, message: issue }) => ({ field, message: issue })) }
|
|
22
|
+
};
|
|
23
|
+
return Object.freeze({ kind: "error", reason: "invalid_arguments", exitCode: 2, content });
|
|
24
|
+
}
|
|
25
|
+
function invalidRequest(issues) {
|
|
26
|
+
return invalidArguments("Invalid arguments.", issues.map((issue) => ({ field: issueField(issue.path), message: issue.message })));
|
|
27
|
+
}
|
|
28
|
+
function internalError(cause) {
|
|
29
|
+
const detail = cause instanceof Error ? cause.message : typeof cause === "string" ? cause : "";
|
|
30
|
+
return Object.freeze({
|
|
31
|
+
kind: "error",
|
|
32
|
+
reason: "internal_error",
|
|
33
|
+
exitCode: 2,
|
|
34
|
+
content: { message: detail === "" ? "Internal error." : `Internal error: ${detail}` },
|
|
35
|
+
cause
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function canceledBy(cause) {
|
|
39
|
+
return Object.freeze({ kind: "error", reason: "canceled", exitCode: 130, content: { message: "Canceled." }, cause });
|
|
40
|
+
}
|
|
41
|
+
function canceledWith(changed) {
|
|
42
|
+
if (typeof changed !== "string" || changed.trim() === "")
|
|
43
|
+
throw new TypeError("canceled needs changed: what changed before the invocation stopped");
|
|
44
|
+
return Object.freeze({
|
|
45
|
+
kind: "error",
|
|
46
|
+
reason: "canceled",
|
|
47
|
+
exitCode: 130,
|
|
48
|
+
content: { message: "Canceled." },
|
|
49
|
+
changed
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function confirmationRequired(message, next, data) {
|
|
53
|
+
return Object.freeze({
|
|
54
|
+
kind: "error",
|
|
55
|
+
reason: "confirmation_required",
|
|
56
|
+
exitCode: 2,
|
|
57
|
+
content: { message, status: "action_required", next, ...data === void 0 ? {} : { data } }
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
var CLINKR_ERROR_ENTRIES = Object.freeze([
|
|
61
|
+
{
|
|
62
|
+
name: "invalid_arguments",
|
|
63
|
+
exitCode: 2,
|
|
64
|
+
description: "The command line or request doesn't fit the command: an unknown option, a missing argument, or a value the command refuses.",
|
|
65
|
+
// `invalidArguments` carries data only with issues.
|
|
66
|
+
schema: z.object({ issues: z.array(z.object({ field: z.string(), message: z.string() })).optional() })
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "internal_error",
|
|
70
|
+
exitCode: 2,
|
|
71
|
+
description: "The command hit a defect: it threw, or built an outcome its schema refused."
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: "canceled",
|
|
75
|
+
exitCode: 130,
|
|
76
|
+
description: "A person or the host stopped the invocation before it finished: a declined confirmation, a dismissed prompt, or a signal. When a signal stops it, the exit status is 128 + the signal's number."
|
|
77
|
+
}
|
|
78
|
+
]);
|
|
79
|
+
var CONFIRMATION_REQUIRED_ENTRY = Object.freeze({
|
|
80
|
+
name: "confirmation_required",
|
|
81
|
+
exitCode: 2,
|
|
82
|
+
status: "action_required",
|
|
83
|
+
description: "The command needs a human to confirm it, and no one could answer a prompt: rerun it with --yes only after a human approves.",
|
|
84
|
+
// The command decides what `data` carries.
|
|
85
|
+
schema: z.looseObject({})
|
|
86
|
+
});
|
|
87
|
+
function issueField(path) {
|
|
88
|
+
return path.length === 0 ? "request" : path.map(String).join(".");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ../../../libs/clinkr/ts/dist/outcomes/confirmation.js
|
|
92
|
+
var YES_FIELD = z2.boolean().default(false);
|
|
93
|
+
var ConfirmationEndedError = class extends Error {
|
|
94
|
+
name = "ConfirmationEndedError";
|
|
95
|
+
answer;
|
|
96
|
+
outcome;
|
|
97
|
+
constructor(answer, outcome) {
|
|
98
|
+
super(answer === "declined" ? "A person declined the confirmation" : "No one could answer the confirmation");
|
|
99
|
+
this.answer = answer;
|
|
100
|
+
this.outcome = outcome;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var requestSchema = z2.strictObject({
|
|
104
|
+
message: z2.string(),
|
|
105
|
+
defaultAnswer: z2.enum(["yes", "no"]),
|
|
106
|
+
unavailable: z2.strictObject({
|
|
107
|
+
message: z2.string().trim().min(1),
|
|
108
|
+
data: z2.record(z2.string(), z2.unknown()).optional()
|
|
109
|
+
}),
|
|
110
|
+
declined: z2.strictObject({ changed: z2.string().trim().min(1) }).optional()
|
|
111
|
+
});
|
|
112
|
+
function createConfirm(options) {
|
|
113
|
+
let asked = false;
|
|
114
|
+
return async (request) => {
|
|
115
|
+
if (asked)
|
|
116
|
+
throw new Error("ui.confirm was already called; a command confirms once per invocation");
|
|
117
|
+
asked = true;
|
|
118
|
+
const parsed = requestSchema.safeParse(request);
|
|
119
|
+
if (!parsed.success)
|
|
120
|
+
throw new TypeError(`Invalid confirmation: ${parsed.error.issues.map((issue) => `${issue.path.join(".") || "request"}: ${issue.message}`).join("; ")}`);
|
|
121
|
+
if (options.yes)
|
|
122
|
+
return;
|
|
123
|
+
const { message, defaultAnswer, unavailable, declined } = request;
|
|
124
|
+
if (options.askYesNo === void 0)
|
|
125
|
+
throw new ConfirmationEndedError("unavailable", confirmationRequired(unavailable.message, [approvalStep(options.invocation)], unavailable.data));
|
|
126
|
+
if (await options.askYesNo(message, defaultAnswer))
|
|
127
|
+
return;
|
|
128
|
+
throw new ConfirmationEndedError("declined", declined === void 0 ? canceledBy(void 0) : canceledWith(declined.changed));
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function approvalStep(invocation) {
|
|
132
|
+
if (invocation === void 0)
|
|
133
|
+
return { type: "text", text: 'Set "yes": true in the request only after a human approves.' };
|
|
134
|
+
const argv = [...invocation.argv];
|
|
135
|
+
const separator = argv.indexOf("--");
|
|
136
|
+
argv.splice(separator === -1 ? argv.length : separator, 0, "--yes", ...invocation.json ? ["--json"] : []);
|
|
137
|
+
return { type: "command", argv, label: "Run it after a human approves", when: "Only after a human approves." };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ../../../libs/clinkr/ts/dist/outcomes/names.js
|
|
141
|
+
var CAMEL_CASE = /^[a-z][a-zA-Z0-9]*$/u;
|
|
142
|
+
var SNAKE_CASE = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/u;
|
|
143
|
+
function isSnakeCase(name) {
|
|
144
|
+
return typeof name === "string" && SNAKE_CASE.test(name);
|
|
145
|
+
}
|
|
146
|
+
function snakeCase(key) {
|
|
147
|
+
return key.replace(/[A-Z]/gu, (letter) => `_${letter.toLowerCase()}`);
|
|
148
|
+
}
|
|
149
|
+
var CLINKR_REASON_KEYS = ["invalidArguments", "internalError", "canceled", "confirmationRequired"];
|
|
150
|
+
function checkKeys(subject, keys, reserved) {
|
|
151
|
+
for (const key of keys) {
|
|
152
|
+
if (!CAMEL_CASE.test(key))
|
|
153
|
+
throw new TypeError(`${subject} key ${JSON.stringify(key)} is not camelCase`);
|
|
154
|
+
if (reserved.includes(key))
|
|
155
|
+
throw new TypeError(`${subject} key ${JSON.stringify(key)} is reserved`);
|
|
156
|
+
if (CLINKR_REASON_KEYS.includes(key))
|
|
157
|
+
throw new TypeError(`${subject} key ${JSON.stringify(key)} is reserved: ${snakeCase(key)} is Clinkr's own reason`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// ../../../libs/clinkr/ts/dist/outcomes/schema-code.js
|
|
162
|
+
import { z as z3 } from "zod";
|
|
163
|
+
var RULE = [
|
|
164
|
+
"Command schemas check only shape: types, built-in checks such as min(1) and formats such as z.email(), defaults,",
|
|
165
|
+
"enums, positionals, and overwrite normalizers such as trim().",
|
|
166
|
+
"Move the logic out of the schema: refuse a request that makes no sense in the command's validate, and have the",
|
|
167
|
+
"handler build outcome values that already have their final shape."
|
|
168
|
+
].join(" ");
|
|
169
|
+
function isSchema(value) {
|
|
170
|
+
if (typeof value !== "object" || value === null || !("_zod" in value))
|
|
171
|
+
return false;
|
|
172
|
+
const { def } = value._zod;
|
|
173
|
+
return typeof def === "object" && typeof def.type === "string";
|
|
174
|
+
}
|
|
175
|
+
function codeIn(def) {
|
|
176
|
+
if (def["type"] === "custom")
|
|
177
|
+
return "z.custom or z.instanceof";
|
|
178
|
+
if (def["type"] === "catch")
|
|
179
|
+
return "a catch (.catch)";
|
|
180
|
+
if (def["type"] === "transform")
|
|
181
|
+
return "a transform (.transform or z.preprocess)";
|
|
182
|
+
if (def["type"] !== "pipe")
|
|
183
|
+
return void 0;
|
|
184
|
+
if ("transform" in def)
|
|
185
|
+
return "a codec (z.codec or z.stringbool)";
|
|
186
|
+
const ends = [def["in"], def["out"]];
|
|
187
|
+
return ends.some((end) => isSchema(end) && end._zod.def.type === "transform") ? void 0 : "a pipe (.pipe)";
|
|
188
|
+
}
|
|
189
|
+
function children(schema) {
|
|
190
|
+
const def = schema._zod.def;
|
|
191
|
+
if (def["type"] === "lazy")
|
|
192
|
+
return [["", def["getter"]()]];
|
|
193
|
+
const keys = Object.keys(def).filter((key) => key !== "checks" && key !== "defaultValue");
|
|
194
|
+
return keys.flatMap((key) => {
|
|
195
|
+
const value = def[key];
|
|
196
|
+
if (isSchema(value))
|
|
197
|
+
return [[key === "element" ? "[]" : "", value]];
|
|
198
|
+
if (Array.isArray(value))
|
|
199
|
+
return value.filter(isSchema).map((item) => ["", item]);
|
|
200
|
+
if (typeof value === "object" && value !== null)
|
|
201
|
+
return Object.entries(value).flatMap(([field, item]) => isSchema(item) ? [[`.${field}`, item]] : []);
|
|
202
|
+
return [];
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
function schemaCodeProblems(label, schema, ancestors = /* @__PURE__ */ new Set()) {
|
|
206
|
+
if (ancestors.has(schema))
|
|
207
|
+
return [];
|
|
208
|
+
const def = schema._zod.def;
|
|
209
|
+
const checks = schema._zod.def.checks ?? [];
|
|
210
|
+
const customFormat = schema instanceof z3.ZodCustomStringFormat || checks.some((check) => check instanceof z3.ZodCustomStringFormat);
|
|
211
|
+
const found = [
|
|
212
|
+
...checks.some((check) => check._zod.def.check === "custom") ? ["a refinement (.refine, .superRefine, or .check)"] : [],
|
|
213
|
+
...customFormat ? ["a custom string format (z.stringFormat)"] : [],
|
|
214
|
+
...[codeIn(def)].filter((what) => what !== void 0)
|
|
215
|
+
].map((what) => `${label} uses ${what}`);
|
|
216
|
+
const inside = /* @__PURE__ */ new Set([...ancestors, schema]);
|
|
217
|
+
return [
|
|
218
|
+
...found,
|
|
219
|
+
...children(schema).flatMap(([segment, child]) => schemaCodeProblems(`${label}${segment}`, child, inside))
|
|
220
|
+
];
|
|
221
|
+
}
|
|
222
|
+
function inputSchemaCoercion(schema, path = "", ancestors = /* @__PURE__ */ new Set()) {
|
|
223
|
+
if (ancestors.has(schema))
|
|
224
|
+
return void 0;
|
|
225
|
+
const def = schema._zod.def;
|
|
226
|
+
const type = def["type"];
|
|
227
|
+
if (def["coerce"] === true && (type === "string" || type === "number" || type === "boolean"))
|
|
228
|
+
return { path, type };
|
|
229
|
+
const inside = /* @__PURE__ */ new Set([...ancestors, schema]);
|
|
230
|
+
const inputChildren = type === "pipe" && isSchema(def["in"]) ? [["", def["in"]]] : children(schema);
|
|
231
|
+
for (const [segment, child] of inputChildren) {
|
|
232
|
+
const found = inputSchemaCoercion(child, `${path}${segment}`, inside);
|
|
233
|
+
if (found !== void 0)
|
|
234
|
+
return found;
|
|
235
|
+
}
|
|
236
|
+
return void 0;
|
|
237
|
+
}
|
|
238
|
+
function assertNoSchemaCode(problems) {
|
|
239
|
+
const found = [...new Set(problems)];
|
|
240
|
+
if (found.length > 0)
|
|
241
|
+
throw new TypeError(`${found.join("; ")}. ${RULE}`);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// ../../../libs/clinkr/ts/dist/outcomes/values.js
|
|
245
|
+
import { z as z4 } from "zod";
|
|
246
|
+
var OutcomeValueError = class extends Error {
|
|
247
|
+
constructor(name, cause) {
|
|
248
|
+
super(`Outcome ${name} value does not match its schema:
|
|
249
|
+
${z4.prettifyError(cause)}`, { cause });
|
|
250
|
+
this.name = "OutcomeValueError";
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
function parseOutcomeValue(name, schema, value) {
|
|
254
|
+
const parsed = schema.safeParse(value);
|
|
255
|
+
if (!parsed.success)
|
|
256
|
+
throw new OutcomeValueError(name, parsed.error);
|
|
257
|
+
return parsed.data;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// ../../../libs/clinkr/ts/dist/outcomes/errors.js
|
|
261
|
+
function checkDescription(subject, description) {
|
|
262
|
+
if (description === void 0)
|
|
263
|
+
return;
|
|
264
|
+
if (typeof description !== "string" || description.trim() === "" || description.includes("\n"))
|
|
265
|
+
throw new TypeError(`${subject} description must be one non-empty line`);
|
|
266
|
+
}
|
|
267
|
+
function isObjectSchema(value) {
|
|
268
|
+
if (typeof value !== "object" || value === null || !("_zod" in value))
|
|
269
|
+
return false;
|
|
270
|
+
const { def } = value._zod;
|
|
271
|
+
return typeof def === "object" && def.type === "object";
|
|
272
|
+
}
|
|
273
|
+
function declareError(reason, value) {
|
|
274
|
+
if (typeof value !== "object" || value === null)
|
|
275
|
+
throw new TypeError(`Error ${reason} is not an error definition`);
|
|
276
|
+
const { exitCode, status, description, schema, render } = value;
|
|
277
|
+
if (exitCode !== 1 && exitCode !== 2)
|
|
278
|
+
throw new TypeError(`Error ${reason} exit code must be 1 or 2`);
|
|
279
|
+
if (status !== void 0 && status !== "action_required" && status !== "error")
|
|
280
|
+
throw new TypeError(`Error ${reason} status must be action_required or error`);
|
|
281
|
+
checkDescription(`Error ${reason}`, description);
|
|
282
|
+
if (schema !== void 0 && !isObjectSchema(schema))
|
|
283
|
+
throw new TypeError(`Error ${reason} schema must be an object schema`);
|
|
284
|
+
if (render === void 0) {
|
|
285
|
+
if (schema !== void 0)
|
|
286
|
+
throw new TypeError(`Error ${reason} has a schema, so it needs a render function`);
|
|
287
|
+
if (description === void 0)
|
|
288
|
+
throw new TypeError(`Error ${reason} needs a render function, or a description to show as its message`);
|
|
289
|
+
} else if (typeof render !== "function")
|
|
290
|
+
throw new TypeError(`Error ${reason} needs a render function`);
|
|
291
|
+
return Object.freeze({
|
|
292
|
+
exitCode,
|
|
293
|
+
...status === void 0 ? {} : { status },
|
|
294
|
+
...description === void 0 ? {} : { description },
|
|
295
|
+
...schema === void 0 ? {} : { schema },
|
|
296
|
+
render: render === void 0 ? () => ({ message: description }) : render
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
function buildError(reason, definition, facts) {
|
|
300
|
+
const { schema, status } = definition;
|
|
301
|
+
const data = schema === void 0 ? void 0 : parseOutcomeValue(reason, schema, facts[0]);
|
|
302
|
+
const render = definition.render;
|
|
303
|
+
const { message, next, rows } = data === void 0 ? render(...facts) : render(data, ...facts.slice(1));
|
|
304
|
+
const content = {
|
|
305
|
+
message,
|
|
306
|
+
...next === void 0 ? {} : { next },
|
|
307
|
+
...status === void 0 ? {} : { status },
|
|
308
|
+
// Only an error with a schema shows rows, and they come from its data.
|
|
309
|
+
...data === void 0 ? {} : { ...rows === void 0 ? {} : { rows }, data }
|
|
310
|
+
};
|
|
311
|
+
return { kind: "error", reason, exitCode: definition.exitCode, content };
|
|
312
|
+
}
|
|
313
|
+
function defineErrors(definitions) {
|
|
314
|
+
const keys = Object.keys(definitions);
|
|
315
|
+
checkKeys("Error", keys, []);
|
|
316
|
+
const named = keys.map((key) => {
|
|
317
|
+
const reason = snakeCase(key);
|
|
318
|
+
const definition = declareError(reason, definitions[key]);
|
|
319
|
+
const { schema } = definition;
|
|
320
|
+
if (schema !== void 0)
|
|
321
|
+
assertNoSchemaCode(schemaCodeProblems(`${reason} error data`, schema));
|
|
322
|
+
const build = (...facts) => buildError(reason, definition, facts);
|
|
323
|
+
return [key, Object.freeze(Object.assign(build, { reason, definition }))];
|
|
324
|
+
});
|
|
325
|
+
return Object.freeze(Object.fromEntries(named));
|
|
326
|
+
}
|
|
327
|
+
function isSharedError(value) {
|
|
328
|
+
if (typeof value !== "function")
|
|
329
|
+
return false;
|
|
330
|
+
const { reason, definition } = value;
|
|
331
|
+
if (typeof reason !== "string" || typeof definition !== "object" || definition === null)
|
|
332
|
+
return false;
|
|
333
|
+
const { exitCode } = definition;
|
|
334
|
+
return exitCode === 1 || exitCode === 2;
|
|
335
|
+
}
|
|
336
|
+
function isCommandError(value) {
|
|
337
|
+
return typeof value === "object" && value !== null && value.kind === "error";
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// ../../../libs/clinkr/ts/dist/outcomes/outcomes.js
|
|
341
|
+
import { z as z6 } from "zod";
|
|
342
|
+
|
|
343
|
+
// ../../../libs/clinkr/ts/dist/outcomes/steps.js
|
|
344
|
+
import { z as z5 } from "zod";
|
|
345
|
+
var stepDocumentSchema = z5.discriminatedUnion("type", [
|
|
346
|
+
z5.object({
|
|
347
|
+
type: z5.enum(["command", "external"]),
|
|
348
|
+
command: z5.string(),
|
|
349
|
+
argv: z5.array(z5.string()),
|
|
350
|
+
when: z5.string().optional()
|
|
351
|
+
}),
|
|
352
|
+
z5.object({ type: z5.literal("url"), url: z5.string() }),
|
|
353
|
+
z5.object({ type: z5.literal("text"), text: z5.string() })
|
|
354
|
+
]);
|
|
355
|
+
var SHELL_SAFE = /^[A-Za-z0-9_@%+=:,./-]+$/u;
|
|
356
|
+
function commandLine(argv) {
|
|
357
|
+
return argv.map((argument) => SHELL_SAFE.test(argument) ? argument : `'${argument.replaceAll("'", `'"'"'`)}'`).join(" ");
|
|
358
|
+
}
|
|
359
|
+
function stepDocument(step) {
|
|
360
|
+
switch (step.type) {
|
|
361
|
+
case "command":
|
|
362
|
+
case "external":
|
|
363
|
+
return {
|
|
364
|
+
type: step.type,
|
|
365
|
+
command: commandLine(step.argv),
|
|
366
|
+
argv: [...step.argv],
|
|
367
|
+
...step.when === void 0 ? {} : { when: step.when }
|
|
368
|
+
};
|
|
369
|
+
case "url":
|
|
370
|
+
return { type: "url", url: step.url };
|
|
371
|
+
case "text":
|
|
372
|
+
return { type: "text", text: step.text };
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// ../../../libs/clinkr/ts/dist/outcomes/present.js
|
|
377
|
+
var LABEL_WIDTH = 16;
|
|
378
|
+
var MAXIMUM_LIST_ITEMS = 5;
|
|
379
|
+
var MAXIMUM_RECOVERY_STEPS = 2;
|
|
380
|
+
function presentContent(content, options) {
|
|
381
|
+
const { done, rows = [], sections = [], table, text, message, warnings = [], next = [] } = content;
|
|
382
|
+
const report = [];
|
|
383
|
+
let stdout = "";
|
|
384
|
+
if (text !== void 0) {
|
|
385
|
+
stdout = text;
|
|
386
|
+
} else if (done === void 0) {
|
|
387
|
+
const answer = [
|
|
388
|
+
formatRows(printable(rows)).join("\n"),
|
|
389
|
+
...sections.map((section2) => [` ${section2.heading}`, ...formatRows(printable(section2.rows))].join("\n")),
|
|
390
|
+
table === void 0 ? "" : formatTable(table, {
|
|
391
|
+
padded: options.stdoutTerminal,
|
|
392
|
+
links: options.stdoutTerminal && options.stdoutLinks === true
|
|
393
|
+
})
|
|
394
|
+
];
|
|
395
|
+
stdout = answer.filter((part) => part !== "").join("\n\n");
|
|
396
|
+
} else {
|
|
397
|
+
if (options.doneOnStdout)
|
|
398
|
+
stdout = typeof done[1] === "string" ? done[1] : done[1].join("\n");
|
|
399
|
+
const [doneLine = "", ...rowLines] = formatRows([done, ...printable(rows)]);
|
|
400
|
+
const lines = [`\u2713${doneLine.slice(1)}`, ...rowLines];
|
|
401
|
+
if (table !== void 0)
|
|
402
|
+
lines.push("", formatTable(table, { padded: true, links: options.stderrLinks === true }));
|
|
403
|
+
report.push(lines.join("\n"));
|
|
404
|
+
}
|
|
405
|
+
if (message !== void 0)
|
|
406
|
+
report.push(` ${indent(message, 2)}`);
|
|
407
|
+
if (warnings.length > 0)
|
|
408
|
+
report.push(warnings.map((warning) => `! ${indent(warning.message, 2)}`).join("\n"));
|
|
409
|
+
if (next.length > 0)
|
|
410
|
+
report.push(formatSteps(next).join("\n"));
|
|
411
|
+
return { stdout, stderr: report.join("\n\n") };
|
|
412
|
+
}
|
|
413
|
+
function presentError({ message, rows, next, rowLimit }) {
|
|
414
|
+
const shown = printable(rows);
|
|
415
|
+
const more = rowLimit === void 0 ? 0 : shown.length - rowLimit;
|
|
416
|
+
const lines = [`\u2717 ${indent(message, 2)}`, ...formatRows(more > 0 ? shown.slice(0, rowLimit) : shown)];
|
|
417
|
+
if (more > 0)
|
|
418
|
+
lines.push(` and ${more} more`);
|
|
419
|
+
if (next.length > 0)
|
|
420
|
+
lines.push("", ...formatSteps(next.slice(0, MAXIMUM_RECOVERY_STEPS)));
|
|
421
|
+
return lines.join("\n");
|
|
422
|
+
}
|
|
423
|
+
function presentCanceled({ message, changed }) {
|
|
424
|
+
const lines = [` ${indent(message, 2)}`];
|
|
425
|
+
if (changed !== void 0)
|
|
426
|
+
lines.push(` ${indent(changed, 2)}`);
|
|
427
|
+
return lines.join("\n");
|
|
428
|
+
}
|
|
429
|
+
function documentFrom(outcome, content) {
|
|
430
|
+
const { warnings = [], next = [] } = content;
|
|
431
|
+
return {
|
|
432
|
+
...outcome.value,
|
|
433
|
+
outcome: outcome.name,
|
|
434
|
+
...warnings.length === 0 ? {} : { warnings: warnings.map(({ reason, message }) => ({ reason, message })) },
|
|
435
|
+
...next.length === 0 ? {} : { next: next.map(stepDocument) }
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
function errorDocument(error) {
|
|
439
|
+
const { message, data, next = [], status = "error" } = error.content;
|
|
440
|
+
return {
|
|
441
|
+
status,
|
|
442
|
+
reason: error.reason,
|
|
443
|
+
message,
|
|
444
|
+
...next.length === 0 ? {} : { next: next.map(stepDocument) },
|
|
445
|
+
...data === void 0 ? {} : { data }
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
function indent(text, column) {
|
|
449
|
+
return text.split("\n").join(`
|
|
450
|
+
${" ".repeat(column)}`);
|
|
451
|
+
}
|
|
452
|
+
function listLines(items) {
|
|
453
|
+
const more = items.length - MAXIMUM_LIST_ITEMS;
|
|
454
|
+
return [...items.slice(0, MAXIMUM_LIST_ITEMS), ...more > 0 ? [`and ${more} more`] : []];
|
|
455
|
+
}
|
|
456
|
+
function printable(rows) {
|
|
457
|
+
return rows.filter(([, value]) => value.length > 0);
|
|
458
|
+
}
|
|
459
|
+
function formatRows(rows) {
|
|
460
|
+
const width = Math.max(LABEL_WIDTH, ...rows.map(([label]) => label.length + 2));
|
|
461
|
+
return rows.map(([label, value]) => {
|
|
462
|
+
const text = typeof value === "string" ? value : listLines(value).join("\n");
|
|
463
|
+
return ` ${label.padEnd(width)}${indent(text, 2 + width)}`;
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
function formatSteps(steps) {
|
|
467
|
+
const lines = [];
|
|
468
|
+
let previous;
|
|
469
|
+
for (const step of steps) {
|
|
470
|
+
if (step.type === "text") {
|
|
471
|
+
lines.push(` ${indent(step.text, 2)}`);
|
|
472
|
+
previous = void 0;
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
if (step.label !== previous)
|
|
476
|
+
lines.push(` ${step.label}:`);
|
|
477
|
+
previous = step.label;
|
|
478
|
+
lines.push(` ${step.type === "url" ? step.url : commandLine(step.argv)}`);
|
|
479
|
+
}
|
|
480
|
+
return lines;
|
|
481
|
+
}
|
|
482
|
+
function formatTable(table, options) {
|
|
483
|
+
const lines = [table.columns, ...table.rows];
|
|
484
|
+
if (!options.padded)
|
|
485
|
+
return lines.map((row) => row.map(cellText).join(" ")).join("\n");
|
|
486
|
+
const widths = table.columns.map((column, index) => Math.max(column.length, ...table.rows.map((row) => cellText(row[index] ?? "").length)));
|
|
487
|
+
return lines.map((row) => {
|
|
488
|
+
const cells = row.map((cell, index) => {
|
|
489
|
+
const drawn = drawnCell(cell, options.links);
|
|
490
|
+
return index === row.length - 1 ? drawn : drawn + " ".repeat(widths[index] + 2 - cellText(cell).length);
|
|
491
|
+
});
|
|
492
|
+
return ` ${cells.join("")}`;
|
|
493
|
+
}).join("\n");
|
|
494
|
+
}
|
|
495
|
+
function cellText(cell) {
|
|
496
|
+
return typeof cell === "string" ? cell : cell.text;
|
|
497
|
+
}
|
|
498
|
+
function hasControlCharacter(text) {
|
|
499
|
+
for (const char of text) {
|
|
500
|
+
const code2 = char.codePointAt(0) ?? 0;
|
|
501
|
+
if (code2 < 32 || code2 >= 127 && code2 <= 159)
|
|
502
|
+
return true;
|
|
503
|
+
}
|
|
504
|
+
return false;
|
|
505
|
+
}
|
|
506
|
+
function drawnCell(cell, links) {
|
|
507
|
+
if (typeof cell === "string")
|
|
508
|
+
return cell;
|
|
509
|
+
if (!links || hasControlCharacter(cell.url))
|
|
510
|
+
return cell.text;
|
|
511
|
+
return `\x1B]8;;${cell.url}\x1B\\${cell.text}\x1B]8;;\x1B\\`;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// ../../../libs/clinkr/ts/dist/outcomes/rendered.js
|
|
515
|
+
function createOutcomeRenderer() {
|
|
516
|
+
return (content) => Object.freeze({
|
|
517
|
+
content,
|
|
518
|
+
draw: (terminal) => {
|
|
519
|
+
const { stdout, stderr } = presentContent(content, {
|
|
520
|
+
stdoutTerminal: terminal.stdout.tty,
|
|
521
|
+
doneOnStdout: false,
|
|
522
|
+
stdoutLinks: takesLinks(terminal.stdout),
|
|
523
|
+
stderrLinks: takesLinks(terminal.stderr)
|
|
524
|
+
});
|
|
525
|
+
return stdout === "" ? { report: stderr } : { report: stderr, answer: stdout };
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
function takesLinks(stream) {
|
|
530
|
+
return stream.tty && stream.color !== "none";
|
|
531
|
+
}
|
|
532
|
+
var renderOutcome = createOutcomeRenderer();
|
|
533
|
+
var plainUi = Object.freeze({
|
|
534
|
+
error: (view) => [presentError(view), view.usage, view.stack].filter((block) => block !== void 0).join("\n\n"),
|
|
535
|
+
canceled: presentCanceled
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
// ../../../libs/clinkr/ts/dist/outcomes/outcomes.js
|
|
539
|
+
function isResultSchema(value) {
|
|
540
|
+
if (isObjectSchema(value))
|
|
541
|
+
return true;
|
|
542
|
+
if (typeof value !== "object" || value === null || !("_zod" in value))
|
|
543
|
+
return false;
|
|
544
|
+
const { def } = value._zod;
|
|
545
|
+
return def.type === "union" && def.options.length > 0 && def.options.every(isObjectSchema);
|
|
546
|
+
}
|
|
547
|
+
function defineOutcomes(definitions) {
|
|
548
|
+
if (typeof definitions !== "object" || definitions === null)
|
|
549
|
+
throw new TypeError("Outcomes need a results section");
|
|
550
|
+
const sections = definitions;
|
|
551
|
+
const { results: declaredResults, errors: declaredErrors, definition: outcomesDefinition } = declareOutcomes(section("results", sections.results), sections.errors === void 0 ? {} : section("errors", sections.errors), declareRenderedResult);
|
|
552
|
+
const resultBuilders = declaredResults.map(({ key, name, schema, exitCode, render }) => {
|
|
553
|
+
const result = (value) => ({
|
|
554
|
+
kind: "result",
|
|
555
|
+
name,
|
|
556
|
+
value,
|
|
557
|
+
exitCode,
|
|
558
|
+
render: (context) => {
|
|
559
|
+
const rendered = render(value, context);
|
|
560
|
+
const content = checkContent(name, rendered.content);
|
|
561
|
+
if (exitCode === 1 && content.done !== void 0)
|
|
562
|
+
throw new TypeError(`Exit-1 result ${name} has a done row; an exit-1 result answers a question`);
|
|
563
|
+
return rendered;
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
const build = (value) => {
|
|
567
|
+
checkValue(name, value);
|
|
568
|
+
return result(parseOutcomeValue(name, schema, value));
|
|
569
|
+
};
|
|
570
|
+
return [key, build];
|
|
571
|
+
});
|
|
572
|
+
const errorBuilders = declaredErrors.map(({ key, name, definition, shared }) => [key, shared ?? ((...facts) => buildError(name, definition, facts))]);
|
|
573
|
+
return {
|
|
574
|
+
...Object.fromEntries([...resultBuilders, ...errorBuilders]),
|
|
575
|
+
canceled: canceledFrom,
|
|
576
|
+
definition: outcomesDefinition
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
function responseOutcomes(schema, errors) {
|
|
580
|
+
if (!isResultSchema(schema))
|
|
581
|
+
throw new TypeError("response.schema: a Response needs an object schema, or a union of object schemas");
|
|
582
|
+
const { definition } = declareOutcomes({
|
|
583
|
+
response: { schema, description: "The command finished." },
|
|
584
|
+
failed: {
|
|
585
|
+
schema,
|
|
586
|
+
exitCode: 1,
|
|
587
|
+
description: "The command finished in a state a script branches on, such as a check that failed."
|
|
588
|
+
}
|
|
589
|
+
}, errors, declareResult);
|
|
590
|
+
const name = (exitCode) => exitCode === 1 ? "failed" : "response";
|
|
591
|
+
return {
|
|
592
|
+
outcomes: { definition },
|
|
593
|
+
parse: (exitCode, value) => {
|
|
594
|
+
checkValue(name(exitCode), value);
|
|
595
|
+
return parseOutcomeValue(name(exitCode), schema, value);
|
|
596
|
+
},
|
|
597
|
+
rendered: (exitCode, value, text) => {
|
|
598
|
+
if (typeof text !== "string")
|
|
599
|
+
throw new TypeError("A Response's render must return a string");
|
|
600
|
+
const rendered = renderOutcome({ text });
|
|
601
|
+
return { kind: "result", name: name(exitCode), value, exitCode, render: () => rendered };
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
function canceledFrom(facts) {
|
|
606
|
+
if (typeof facts !== "object" || facts === null)
|
|
607
|
+
throw new TypeError("canceled needs { changed }");
|
|
608
|
+
return canceledWith(facts.changed);
|
|
609
|
+
}
|
|
610
|
+
function section(name, value) {
|
|
611
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
612
|
+
throw new TypeError(`Outcomes ${name} must be an object`);
|
|
613
|
+
return value;
|
|
614
|
+
}
|
|
615
|
+
function declareOutcomes(results, errors, declare) {
|
|
616
|
+
const resultKeys = Object.keys(results);
|
|
617
|
+
const errorKeys = Object.keys(errors);
|
|
618
|
+
checkKeys("Outcome", [...resultKeys, ...errorKeys], ["definition"]);
|
|
619
|
+
for (const key of errorKeys)
|
|
620
|
+
if (Object.hasOwn(results, key))
|
|
621
|
+
throw new TypeError(`Outcome key ${JSON.stringify(key)} names both a result and an error`);
|
|
622
|
+
const declaredResults = resultKeys.map((key) => declare(key, results[key]));
|
|
623
|
+
const declaredErrors = errorKeys.map((key) => {
|
|
624
|
+
const name = snakeCase(key);
|
|
625
|
+
const value = errors[key];
|
|
626
|
+
if (isSharedError(value)) {
|
|
627
|
+
if (value.reason !== name)
|
|
628
|
+
throw new TypeError(`Outcome key ${JSON.stringify(key)} names ${name}, but its error is ${value.reason}`);
|
|
629
|
+
return { key, name, definition: value.definition, shared: value };
|
|
630
|
+
}
|
|
631
|
+
return { key, name, definition: declareError(name, value) };
|
|
632
|
+
});
|
|
633
|
+
for (const { name, schema } of declaredResults)
|
|
634
|
+
checkResultFields(name, schema);
|
|
635
|
+
const outcomes = [
|
|
636
|
+
...declaredResults.map(({ key, name, schema, exitCode, description }) => ({
|
|
637
|
+
key,
|
|
638
|
+
name,
|
|
639
|
+
kind: "result",
|
|
640
|
+
exitCode,
|
|
641
|
+
schema,
|
|
642
|
+
...description === void 0 ? {} : { description }
|
|
643
|
+
})),
|
|
644
|
+
...declaredErrors.map(({ key, name, definition: { exitCode, schema, status, description } }) => ({
|
|
645
|
+
key,
|
|
646
|
+
name,
|
|
647
|
+
kind: "error",
|
|
648
|
+
exitCode,
|
|
649
|
+
...schema === void 0 ? {} : { schema },
|
|
650
|
+
...status === void 0 ? {} : { status },
|
|
651
|
+
...description === void 0 ? {} : { description }
|
|
652
|
+
}))
|
|
653
|
+
];
|
|
654
|
+
return {
|
|
655
|
+
results: declaredResults,
|
|
656
|
+
errors: declaredErrors,
|
|
657
|
+
definition: {
|
|
658
|
+
outcomes,
|
|
659
|
+
documentSchema: documentSchema(outcomes),
|
|
660
|
+
errorDocumentSchema: errorDocumentUnionSchema(outcomes)
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
function declareResult(key, value) {
|
|
665
|
+
const name = snakeCase(key);
|
|
666
|
+
if (typeof value !== "object" || value === null || isSharedError(value))
|
|
667
|
+
throw new TypeError(`Result ${name} is not a result definition`);
|
|
668
|
+
const { schema, exitCode = 0, description } = value;
|
|
669
|
+
if (!isResultSchema(schema))
|
|
670
|
+
throw new TypeError(`Result ${name} needs an object schema, or a union of object schemas`);
|
|
671
|
+
if (exitCode !== 0 && exitCode !== 1)
|
|
672
|
+
throw new TypeError(`Result ${name} exit code must be 0 or 1`);
|
|
673
|
+
checkDescription(`Result ${name}`, description);
|
|
674
|
+
return { key, name, schema, exitCode, ...description === void 0 ? {} : { description } };
|
|
675
|
+
}
|
|
676
|
+
function declareRenderedResult(key, value) {
|
|
677
|
+
const declared = declareResult(key, value);
|
|
678
|
+
const { render } = value;
|
|
679
|
+
if (typeof render !== "function")
|
|
680
|
+
throw new TypeError(`Result ${declared.name} needs a render function`);
|
|
681
|
+
return { ...declared, render };
|
|
682
|
+
}
|
|
683
|
+
var ADDED_FIELDS = ["outcome", "warnings", "next"];
|
|
684
|
+
function checkResultFields(name, schema) {
|
|
685
|
+
const options = isObjectSchema(schema) ? [schema] : schema.options;
|
|
686
|
+
options.forEach((option, index) => {
|
|
687
|
+
const where = options.length === 1 ? "schema" : `schema union option ${index + 1}`;
|
|
688
|
+
for (const field of ADDED_FIELDS)
|
|
689
|
+
if (Object.hasOwn(option.shape, field))
|
|
690
|
+
throw new TypeError(`Result ${name} ${where} declares ${field}, which the framework adds`);
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
function addedFieldsSchema(outcome) {
|
|
694
|
+
return z6.object({
|
|
695
|
+
outcome,
|
|
696
|
+
warnings: z6.array(z6.object({ reason: z6.string(), message: z6.string() })).optional(),
|
|
697
|
+
next: z6.array(stepDocumentSchema).optional()
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
function resultDocumentSchema(schema, outcome) {
|
|
701
|
+
const added = addedFieldsSchema(outcome).shape;
|
|
702
|
+
if (isObjectSchema(schema))
|
|
703
|
+
return schema.extend(added);
|
|
704
|
+
return z6.union(schema.options.map((option) => option.extend(added)));
|
|
705
|
+
}
|
|
706
|
+
function documentSchema(outcomes) {
|
|
707
|
+
const groups = /* @__PURE__ */ new Map();
|
|
708
|
+
for (const entry of outcomes) {
|
|
709
|
+
if (entry.kind !== "result")
|
|
710
|
+
continue;
|
|
711
|
+
const { name, schema } = entry;
|
|
712
|
+
const names = groups.get(schema);
|
|
713
|
+
if (names === void 0)
|
|
714
|
+
groups.set(schema, [name]);
|
|
715
|
+
else
|
|
716
|
+
names.push(name);
|
|
717
|
+
}
|
|
718
|
+
const branches = [...groups].map(([schema, [first = "", ...rest]]) => resultDocumentSchema(schema, rest.length === 0 ? z6.literal(first) : z6.enum([first, ...rest])));
|
|
719
|
+
const [only, ...others] = branches;
|
|
720
|
+
if (only === void 0)
|
|
721
|
+
return z6.never();
|
|
722
|
+
return others.length === 0 ? only : z6.union(branches);
|
|
723
|
+
}
|
|
724
|
+
function errorDocumentUnionSchema(outcomes) {
|
|
725
|
+
const branches = outcomes.filter((entry) => entry.kind === "error").map(({ name, schema }) => errorDocumentObject(z6.literal(name), schema === void 0 ? {} : { data: schema }));
|
|
726
|
+
const [first, ...rest] = branches;
|
|
727
|
+
return first === void 0 ? z6.never() : z6.discriminatedUnion("reason", [first, ...rest]);
|
|
728
|
+
}
|
|
729
|
+
var errorDocumentSchema = errorDocumentObject(z6.string(), {
|
|
730
|
+
data: z6.record(z6.string(), z6.unknown()).optional()
|
|
731
|
+
});
|
|
732
|
+
function errorDocumentObject(reason, data) {
|
|
733
|
+
return z6.object({
|
|
734
|
+
status: z6.enum(["action_required", "error"]),
|
|
735
|
+
reason,
|
|
736
|
+
message: z6.string(),
|
|
737
|
+
next: z6.array(stepDocumentSchema).optional(),
|
|
738
|
+
...data
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
function checkValue(name, value) {
|
|
742
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
743
|
+
throw new TypeError(`Outcome ${name} value must be an object`);
|
|
744
|
+
for (const field of ADDED_FIELDS)
|
|
745
|
+
if (Object.hasOwn(value, field))
|
|
746
|
+
throw new TypeError(`Outcome ${name} value sets ${field}, which the framework adds`);
|
|
747
|
+
}
|
|
748
|
+
function checkContent(name, content) {
|
|
749
|
+
if (content.text !== void 0) {
|
|
750
|
+
const beside = [
|
|
751
|
+
["a done row", content.done],
|
|
752
|
+
["rows", content.rows],
|
|
753
|
+
["sections", content.sections],
|
|
754
|
+
["a table", content.table]
|
|
755
|
+
].filter(([, value]) => value !== void 0);
|
|
756
|
+
if (beside.length > 0)
|
|
757
|
+
throw new TypeError(`Outcome ${name} has text beside ${beside.map(([what]) => what).join(" and ")}; text is the whole answer`);
|
|
758
|
+
}
|
|
759
|
+
if (content.done !== void 0) {
|
|
760
|
+
const [, value] = content.done;
|
|
761
|
+
const identifiers = typeof value === "string" ? [value] : value;
|
|
762
|
+
if (identifiers.length === 0 || identifiers.some((identifier) => identifier === ""))
|
|
763
|
+
throw new TypeError(`Outcome ${name} done row has an empty value; it identifies what the command changed`);
|
|
764
|
+
if (content.sections !== void 0)
|
|
765
|
+
throw new TypeError(`Outcome ${name} has sections and a done row; sections answer a question`);
|
|
766
|
+
}
|
|
767
|
+
for (const section2 of content.sections ?? [])
|
|
768
|
+
if (section2.heading === "")
|
|
769
|
+
throw new TypeError(`Outcome ${name} has a section with an empty heading`);
|
|
770
|
+
for (const warning of content.warnings ?? [])
|
|
771
|
+
if (!isSnakeCase(warning.reason))
|
|
772
|
+
throw new TypeError(`Outcome ${name} warning reason ${JSON.stringify(warning.reason)} is not snake_case`);
|
|
773
|
+
return content;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// ../../../libs/clinkr/ts/dist/command-tree.js
|
|
777
|
+
import { isAbsolute } from "node:path";
|
|
778
|
+
|
|
779
|
+
// ../../../libs/clinkr/ts/dist/command-metadata.js
|
|
780
|
+
import { z as z9 } from "zod";
|
|
781
|
+
|
|
782
|
+
// ../../../libs/clinkr/ts/dist/command-help.js
|
|
783
|
+
import { z as z8 } from "zod";
|
|
784
|
+
|
|
785
|
+
// ../../../libs/clinkr/ts/dist/single-line-text.js
|
|
786
|
+
import { z as z7 } from "zod";
|
|
787
|
+
function isSingleLineWithoutControlCharacters(text) {
|
|
788
|
+
return !/[\p{Cc}\p{Zl}\p{Zp}]/u.test(text);
|
|
789
|
+
}
|
|
790
|
+
function isSingleLineText(text) {
|
|
791
|
+
return text.trim().length > 0 && isSingleLineWithoutControlCharacters(text);
|
|
792
|
+
}
|
|
793
|
+
function singleLineTextSchema(subject) {
|
|
794
|
+
return z7.string().refine(isSingleLineText, {
|
|
795
|
+
message: `${subject} must be nonempty single-line strings without control characters`
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
// ../../../libs/clinkr/ts/dist/command-help.js
|
|
800
|
+
var exampleArgvSchema = z8.string().refine(isSingleLineWithoutControlCharacters, {
|
|
801
|
+
message: "Example argv must be single-line strings without control characters"
|
|
802
|
+
});
|
|
803
|
+
var describedExampleSchema = z8.strictObject({ argv: exampleArgvSchema, description: singleLineTextSchema("Example descriptions").optional() }).readonly();
|
|
804
|
+
var exampleSchema = z8.union([exampleArgvSchema, describedExampleSchema]).transform((example) => typeof example === "string" ? Object.freeze({ argv: example }) : example);
|
|
805
|
+
var commandHelpSchema = z8.strictObject({
|
|
806
|
+
fields: z8.record(z8.string(), z8.strictObject({
|
|
807
|
+
description: z8.string().optional(),
|
|
808
|
+
valueLabel: z8.string().min(1).refine(isBareValueLabel, "Value labels must be bare atoms without whitespace, brackets, or a ... suffix").optional()
|
|
809
|
+
}).readonly()).readonly().optional(),
|
|
810
|
+
examples: z8.array(exampleSchema).readonly().optional(),
|
|
811
|
+
usages: z8.array(z8.string().refine(isSingleLineWithoutControlCharacters, {
|
|
812
|
+
message: "Usages must be single-line strings without control characters"
|
|
813
|
+
})).readonly().optional()
|
|
814
|
+
});
|
|
815
|
+
function isBareValueLabel(label) {
|
|
816
|
+
return !/[\s\p{Cc}<>[\]]/u.test(label) && !label.endsWith("...");
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
// ../../../libs/clinkr/ts/dist/command-metadata.js
|
|
820
|
+
var commandMetadataSchema = z9.strictObject({
|
|
821
|
+
description: z9.string().min(1),
|
|
822
|
+
summary: singleLineTextSchema("Summaries").optional(),
|
|
823
|
+
helpSection: singleLineTextSchema("Help section names").optional(),
|
|
824
|
+
hidden: z9.boolean().optional(),
|
|
825
|
+
default: z9.boolean().optional(),
|
|
826
|
+
aliases: z9.array(z9.string().refine(isCommandNameSegment, {
|
|
827
|
+
message: "Aliases must be nonempty names without whitespace, control characters, or separators, and cannot be . or .. or begin with -"
|
|
828
|
+
})).readonly().superRefine((aliases, context) => {
|
|
829
|
+
const seen = /* @__PURE__ */ new Set();
|
|
830
|
+
for (const alias of aliases) {
|
|
831
|
+
if (seen.has(alias))
|
|
832
|
+
context.addIssue({ code: "custom", message: `Duplicate alias ${JSON.stringify(alias)}` });
|
|
833
|
+
seen.add(alias);
|
|
834
|
+
}
|
|
835
|
+
}).optional(),
|
|
836
|
+
help: commandHelpSchema.readonly().optional()
|
|
837
|
+
});
|
|
838
|
+
function isCommandNameSegment(segment) {
|
|
839
|
+
return /^[^\s\p{Cc}/\\]+$/u.test(segment) && segment !== "." && segment !== ".." && !segment.startsWith("-");
|
|
840
|
+
}
|
|
841
|
+
var NAVIGATION_KEYS = ["description", "summary", "helpSection", "hidden", "default", "aliases"];
|
|
842
|
+
var navigationSchema = commandMetadataSchema.omit({ help: true }).partial({ description: true });
|
|
843
|
+
var GROUP_NAVIGATION_KEYS = ["description", "summary", "helpSection", "hidden"];
|
|
844
|
+
var groupNavigationSchema = navigationSchema.pick({
|
|
845
|
+
description: true,
|
|
846
|
+
summary: true,
|
|
847
|
+
helpSection: true,
|
|
848
|
+
hidden: true
|
|
849
|
+
});
|
|
850
|
+
function navigationIssues(error, fallback) {
|
|
851
|
+
return error.issues.map((issue) => `${issue.path.join(".") || fallback}: ${issue.message}`).join("; ");
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
// ../../../libs/clinkr/ts/dist/outcomes/command.js
|
|
855
|
+
import { z as z15 } from "zod";
|
|
856
|
+
|
|
857
|
+
// ../../../libs/clinkr/ts/dist/cli-spec.js
|
|
858
|
+
import { z as z10 } from "zod";
|
|
859
|
+
var cliSpecSchema = z10.strictObject({
|
|
860
|
+
positionals: z10.array(z10.string()).readonly().exactOptional(),
|
|
861
|
+
options: z10.record(z10.string(), z10.strictObject({
|
|
862
|
+
short: z10.string().exactOptional(),
|
|
863
|
+
aliases: z10.array(z10.string()).readonly().exactOptional()
|
|
864
|
+
})).exactOptional()
|
|
865
|
+
});
|
|
866
|
+
function snapshotCliSpec(cli) {
|
|
867
|
+
const options = {};
|
|
868
|
+
for (const key in cli.options) {
|
|
869
|
+
if (!Object.hasOwn(cli.options, key))
|
|
870
|
+
continue;
|
|
871
|
+
const option = cli.options[key];
|
|
872
|
+
if (option === void 0)
|
|
873
|
+
continue;
|
|
874
|
+
options[key] = Object.freeze({
|
|
875
|
+
...option,
|
|
876
|
+
...option.aliases === void 0 ? {} : { aliases: Object.freeze([...option.aliases]) }
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
return Object.freeze({
|
|
880
|
+
...cli.positionals === void 0 ? {} : { positionals: Object.freeze([...cli.positionals]) },
|
|
881
|
+
...cli.options === void 0 ? {} : { options: Object.freeze(options) }
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
// ../../../libs/clinkr/ts/dist/command-result.js
|
|
886
|
+
function checkResult(returned) {
|
|
887
|
+
if (typeof returned !== "object" || returned === null || Array.isArray(returned))
|
|
888
|
+
throw new Error(`Handler must return a { value, exitCode? } result object; received ${describe(returned)}`);
|
|
889
|
+
const unknown = Object.keys(returned).filter((key) => key !== "value" && key !== "exitCode");
|
|
890
|
+
if (unknown.length > 0)
|
|
891
|
+
throw new Error(`Handler returned a result with unknown fields: ${unknown.join(", ")}`);
|
|
892
|
+
const { value, exitCode } = returned;
|
|
893
|
+
if (exitCode !== void 0 && exitCode !== 0 && exitCode !== 1)
|
|
894
|
+
throw new Error(`Handler returned exitCode ${describe(exitCode)}; expected 0 or 1`);
|
|
895
|
+
return { value, exitCode: exitCode ?? 0 };
|
|
896
|
+
}
|
|
897
|
+
function describe(value) {
|
|
898
|
+
if (value === void 0)
|
|
899
|
+
return "undefined";
|
|
900
|
+
if (typeof value === "string")
|
|
901
|
+
return JSON.stringify(value);
|
|
902
|
+
if (typeof value === "number")
|
|
903
|
+
return String(value);
|
|
904
|
+
if (Array.isArray(value))
|
|
905
|
+
return "an array";
|
|
906
|
+
return value === null ? "null" : typeof value;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
// ../../../libs/clinkr/ts/dist/field-descriptions.js
|
|
910
|
+
import { z as z11 } from "zod";
|
|
911
|
+
function hasDescription(schema) {
|
|
912
|
+
const seen = /* @__PURE__ */ new Set();
|
|
913
|
+
for (let current = schema; current !== void 0 && !seen.has(current); ) {
|
|
914
|
+
seen.add(current);
|
|
915
|
+
if (z11.globalRegistry.get(current)?.description !== void 0)
|
|
916
|
+
return true;
|
|
917
|
+
const def = current._zod.def;
|
|
918
|
+
current = def.innerType ?? (def.type === "pipe" ? def.in : def.type === "lazy" && def.getter !== void 0 ? def.getter() : void 0);
|
|
919
|
+
}
|
|
920
|
+
return false;
|
|
921
|
+
}
|
|
922
|
+
function describedRequestFields(requestSchema2) {
|
|
923
|
+
return Object.entries(requestSchema2.shape).filter(([, field]) => hasDescription(field)).map(([key]) => key);
|
|
924
|
+
}
|
|
925
|
+
function assertNoRequestFieldDescriptions(requestSchema2) {
|
|
926
|
+
const described = describedRequestFields(requestSchema2);
|
|
927
|
+
if (described.length === 0)
|
|
928
|
+
return;
|
|
929
|
+
const fields = described.map((key) => JSON.stringify(key)).join(", ");
|
|
930
|
+
throw new TypeError(`request field ${fields} ${described.length === 1 ? "has" : "have"} a schema description (.describe or .meta). Describe request fields in help.fields, which leaf help and --json-schema both read.`);
|
|
931
|
+
}
|
|
932
|
+
function withFieldDescriptions(schema, fields) {
|
|
933
|
+
const { properties } = schema;
|
|
934
|
+
if (properties === void 0 || fields === void 0)
|
|
935
|
+
return schema;
|
|
936
|
+
const described = Object.fromEntries(Object.entries(properties).map(([key, property]) => {
|
|
937
|
+
const description = fields[key]?.description;
|
|
938
|
+
if (description === void 0 || description === "" || typeof property !== "object")
|
|
939
|
+
return [key, property];
|
|
940
|
+
return [key, { ...property, description }];
|
|
941
|
+
}));
|
|
942
|
+
return { ...schema, properties: described };
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
// ../../../libs/clinkr/ts/dist/elicitation.js
|
|
946
|
+
import { z as z14 } from "zod";
|
|
947
|
+
|
|
948
|
+
// ../../../libs/clinkr/ts/dist/execution-error.js
|
|
949
|
+
import { z as z12 } from "zod";
|
|
950
|
+
var ClinkrExecutionError = class _ClinkrExecutionError extends Error {
|
|
951
|
+
reason;
|
|
952
|
+
next;
|
|
953
|
+
data;
|
|
954
|
+
cause;
|
|
955
|
+
constructor(parts) {
|
|
956
|
+
const { reason, message, next, data, cause } = parts;
|
|
957
|
+
super(message, { cause });
|
|
958
|
+
this.name = "ClinkrExecutionError";
|
|
959
|
+
this.reason = reason;
|
|
960
|
+
this.next = next;
|
|
961
|
+
this.data = data;
|
|
962
|
+
this.cause = cause;
|
|
963
|
+
if (cause instanceof Error && cause.stack !== void 0) {
|
|
964
|
+
this.stack = cause.stack;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
/** `invalid_arguments`: the request failed its schema. Each issue is `{ field, message }` in `data.issues`. */
|
|
968
|
+
static invalidRequest(cause) {
|
|
969
|
+
const issues = cause.issues.map((issue) => ({ field: issueField(issue.path), message: issue.message }));
|
|
970
|
+
return new _ClinkrExecutionError({
|
|
971
|
+
reason: "invalid_arguments",
|
|
972
|
+
message: "Invalid arguments.",
|
|
973
|
+
next: void 0,
|
|
974
|
+
data: { issues },
|
|
975
|
+
cause
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* `internal_error`: a defect. `subject` names what was wrong, such as `invalid response`; the message adds the
|
|
980
|
+
* cause's own message, unless the cause is a validation failure, whose issues would not fit one line.
|
|
981
|
+
*/
|
|
982
|
+
static internalError(cause, subject) {
|
|
983
|
+
const detail = cause instanceof z12.ZodError ? "" : messageOf(cause);
|
|
984
|
+
const parts = [subject ?? "", detail].filter((part) => part !== "");
|
|
985
|
+
const message = parts.length === 0 ? "Internal error." : `Internal error: ${parts.join(": ")}`;
|
|
986
|
+
return new _ClinkrExecutionError({ reason: "internal_error", message, next: void 0, data: void 0, cause });
|
|
987
|
+
}
|
|
988
|
+
/** `canceled`: the host aborted the invocation, or a person dismissed a prompt. */
|
|
989
|
+
static canceled(cause) {
|
|
990
|
+
return new _ClinkrExecutionError({
|
|
991
|
+
reason: "canceled",
|
|
992
|
+
message: "Canceled.",
|
|
993
|
+
next: void 0,
|
|
994
|
+
data: void 0,
|
|
995
|
+
cause
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
};
|
|
999
|
+
function messageOf(cause) {
|
|
1000
|
+
return cause instanceof Error ? cause.message : typeof cause === "string" ? cause : "";
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
// ../../../libs/clinkr/ts/dist/schema-policy.js
|
|
1004
|
+
import { z as z13 } from "zod";
|
|
1005
|
+
|
|
1006
|
+
// ../../../libs/clinkr/ts/dist/global-options.js
|
|
1007
|
+
var FRAMEWORK_OPTIONS = [
|
|
1008
|
+
{ long: "--help", short: "-h", parsedGlobally: false, inRootHelp: true },
|
|
1009
|
+
{ long: "--json", parsedGlobally: true, inRootHelp: true },
|
|
1010
|
+
{ long: "--input-json", parsedGlobally: true, inRootHelp: true },
|
|
1011
|
+
{ long: "--no-color", parsedGlobally: true, inRootHelp: true },
|
|
1012
|
+
{ long: "--json-schema", parsedGlobally: false, inRootHelp: false }
|
|
1013
|
+
];
|
|
1014
|
+
var GLOBALLY_PARSED_FLAGS = FRAMEWORK_OPTIONS.flatMap((option) => option.parsedGlobally ? [option.long] : []);
|
|
1015
|
+
var RESERVED_LONG_NAMES = new Set(FRAMEWORK_OPTIONS.map(({ long }) => long.slice(2)));
|
|
1016
|
+
var RESERVED_SHORT_NAMES = new Set(FRAMEWORK_OPTIONS.flatMap((option) => "short" in option ? [option.short.slice(1)] : []));
|
|
1017
|
+
var COMPLETION_FRAMEWORK_FLAGS = FRAMEWORK_OPTIONS.flatMap((option) => "short" in option ? [option.short, option.long] : [option.long]);
|
|
1018
|
+
var FRAMEWORK_CONTROL_TOKENS = [...COMPLETION_FRAMEWORK_FLAGS, "--"];
|
|
1019
|
+
var VERSION_FLAG = "--version";
|
|
1020
|
+
function isGloballyParsedFlag(token) {
|
|
1021
|
+
return GLOBALLY_PARSED_FLAGS.includes(token);
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
// ../../../libs/clinkr/ts/dist/schema-policy.js
|
|
1025
|
+
var ArgvProjectionError = class extends Error {
|
|
1026
|
+
name = "ArgvProjectionError";
|
|
1027
|
+
};
|
|
1028
|
+
function unwrapField(field) {
|
|
1029
|
+
const wrappers = [];
|
|
1030
|
+
let schema = field;
|
|
1031
|
+
while (schema instanceof z13.ZodOptional || schema instanceof z13.ZodDefault) {
|
|
1032
|
+
wrappers.push(schema);
|
|
1033
|
+
schema = schema.unwrap();
|
|
1034
|
+
}
|
|
1035
|
+
return { wrappers, schema };
|
|
1036
|
+
}
|
|
1037
|
+
function describeRequestFields(command) {
|
|
1038
|
+
const { requestSchema: requestSchema2, cli } = command;
|
|
1039
|
+
const shape = requestSchema2.shape;
|
|
1040
|
+
const positionals = cli?.positionals ?? [];
|
|
1041
|
+
const options = cli?.options ?? {};
|
|
1042
|
+
for (const key of positionals) {
|
|
1043
|
+
if (!Object.hasOwn(shape, key))
|
|
1044
|
+
throw new ArgvProjectionError(`cli.positionals names ${key}, which is not a request-schema field`);
|
|
1045
|
+
}
|
|
1046
|
+
for (const [index, key] of positionals.entries()) {
|
|
1047
|
+
if (positionals.indexOf(key) !== index)
|
|
1048
|
+
throw new ArgvProjectionError(`cli.positionals lists ${key} more than once`);
|
|
1049
|
+
}
|
|
1050
|
+
for (const key of Object.keys(options)) {
|
|
1051
|
+
if (!Object.hasOwn(shape, key))
|
|
1052
|
+
throw new ArgvProjectionError(`cli.options names ${key}, which is not a request-schema field`);
|
|
1053
|
+
if (positionals.includes(key))
|
|
1054
|
+
throw new ArgvProjectionError(`Field ${key} cannot be both a positional argument and an option`);
|
|
1055
|
+
}
|
|
1056
|
+
return Object.entries(shape).map(([key, field]) => {
|
|
1057
|
+
const position = positionals.indexOf(key);
|
|
1058
|
+
return describeRequestField(key, field, position === -1 ? void 0 : position, Object.hasOwn(options, key) ? options[key] : void 0);
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
function describeRequestField(key, field, position, option) {
|
|
1062
|
+
if (!/^[a-z][A-Za-z0-9]*$/.test(key))
|
|
1063
|
+
throw new ArgvProjectionError(`Field ${key} cannot be mapped safely to a CLI option`);
|
|
1064
|
+
const { schema, wrappers } = unwrapField(field);
|
|
1065
|
+
const required = wrappers.length === 0;
|
|
1066
|
+
let defaultValue;
|
|
1067
|
+
for (const wrapper of wrappers) {
|
|
1068
|
+
if (wrapper instanceof z13.ZodDefault && defaultValue === void 0)
|
|
1069
|
+
defaultValue = wrapper.def.defaultValue;
|
|
1070
|
+
}
|
|
1071
|
+
const aliases = option?.aliases ?? [];
|
|
1072
|
+
if (option !== void 0) {
|
|
1073
|
+
if (option.short !== void 0 && !/^[A-Za-z]$/.test(option.short))
|
|
1074
|
+
throw new ArgvProjectionError(`Field ${key} has an invalid short flag: ${JSON.stringify(option.short)}; use one ASCII letter`);
|
|
1075
|
+
if (option.short !== void 0 && RESERVED_SHORT_NAMES.has(option.short))
|
|
1076
|
+
throw new ArgvProjectionError(`Field ${key} cannot use -h, which is reserved for help`);
|
|
1077
|
+
for (const alias of aliases) {
|
|
1078
|
+
if (typeof alias !== "string" || !/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(alias))
|
|
1079
|
+
throw new ArgvProjectionError(`Field ${key} has an invalid alias: ${JSON.stringify(alias)}; use a kebab-case name without leading dashes`);
|
|
1080
|
+
if (RESERVED_LONG_NAMES.has(alias))
|
|
1081
|
+
throw new ArgvProjectionError(`Field ${key} cannot use alias --${alias}, which is reserved by Clinkr`);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
const coercion = inputSchemaCoercion(field);
|
|
1085
|
+
if (coercion !== void 0)
|
|
1086
|
+
throw new ArgvProjectionError(`Field ${key}${coercion.path} cannot use z.coerce.${coercion.type}(); use z.${coercion.type}(), which argv projection already converts`);
|
|
1087
|
+
const input = pipeInput(schema);
|
|
1088
|
+
const kind = classifyRequestField(key, input);
|
|
1089
|
+
if (position !== void 0 && (kind === "boolean" || kind === "json"))
|
|
1090
|
+
throw new ArgvProjectionError(`Field ${key} cannot use ${kind} as a positional argument`);
|
|
1091
|
+
if (kind === "boolean" && required)
|
|
1092
|
+
throw new ArgvProjectionError(`Field ${key} must be optional or have a boolean schema default to map to a CLI switch`);
|
|
1093
|
+
if (kind === "boolean" && defaultValue !== void 0 && typeof defaultValue !== "boolean")
|
|
1094
|
+
throw new ArgvProjectionError(`Field ${key} must have a boolean schema default`);
|
|
1095
|
+
return {
|
|
1096
|
+
key,
|
|
1097
|
+
kind,
|
|
1098
|
+
required,
|
|
1099
|
+
nonemptyRequired: required && kind === "string-array" ? hasPositiveMinimum(input) : required,
|
|
1100
|
+
...position === void 0 ? {} : { position },
|
|
1101
|
+
...kind === "boolean" && typeof defaultValue === "boolean" ? { booleanDefault: defaultValue } : {},
|
|
1102
|
+
...input instanceof z13.ZodEnum ? { values: enumValues(input) } : {},
|
|
1103
|
+
...option?.short === void 0 ? {} : { short: option.short },
|
|
1104
|
+
...aliases.length === 0 ? {} : { aliases }
|
|
1105
|
+
};
|
|
1106
|
+
}
|
|
1107
|
+
function pipeInput(schema) {
|
|
1108
|
+
let input = schema;
|
|
1109
|
+
while (input instanceof z13.ZodPipe)
|
|
1110
|
+
input = input.in;
|
|
1111
|
+
return input;
|
|
1112
|
+
}
|
|
1113
|
+
function classifyRequestField(key, schema) {
|
|
1114
|
+
if (schema instanceof z13.ZodString)
|
|
1115
|
+
return "string";
|
|
1116
|
+
if (schema instanceof z13.ZodEnum)
|
|
1117
|
+
return "enum";
|
|
1118
|
+
if (schema instanceof z13.ZodNumber)
|
|
1119
|
+
return schema.isInt ? "integer" : "number";
|
|
1120
|
+
if (schema instanceof z13.ZodBoolean)
|
|
1121
|
+
return "boolean";
|
|
1122
|
+
if (schema instanceof z13.ZodArray) {
|
|
1123
|
+
if (schema.element instanceof z13.ZodString)
|
|
1124
|
+
return "string-array";
|
|
1125
|
+
throw new ArgvProjectionError(`Field ${key} has an unsupported array element schema`);
|
|
1126
|
+
}
|
|
1127
|
+
if (schema instanceof z13.ZodObject || schema instanceof z13.ZodRecord)
|
|
1128
|
+
return "json";
|
|
1129
|
+
throw new ArgvProjectionError(`Field ${key} has an unsupported CLI schema: ${schema.type}`);
|
|
1130
|
+
}
|
|
1131
|
+
function hasPositiveMinimum(schema) {
|
|
1132
|
+
const checks = schema.def.checks ?? [];
|
|
1133
|
+
return checks.some((check) => {
|
|
1134
|
+
const definition = check._zod.def;
|
|
1135
|
+
if (definition.check === "min_length" && "minimum" in definition)
|
|
1136
|
+
return typeof definition.minimum === "number" && definition.minimum > 0;
|
|
1137
|
+
if (definition.check === "length_equals" && "length" in definition)
|
|
1138
|
+
return typeof definition.length === "number" && definition.length > 0;
|
|
1139
|
+
return false;
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
var ElicitationFormError = class extends Error {
|
|
1143
|
+
name = "ElicitationFormError";
|
|
1144
|
+
};
|
|
1145
|
+
var elicitationStringFormats = /* @__PURE__ */ new Set(["email", "url", "date", "datetime"]);
|
|
1146
|
+
var elicitationStringChecks = /* @__PURE__ */ new Set(["min_length", "max_length"]);
|
|
1147
|
+
function assertElicitationForm(form) {
|
|
1148
|
+
if (!(form instanceof z13.ZodObject))
|
|
1149
|
+
throw new ElicitationFormError("Elicitation form must be a flat z.object()");
|
|
1150
|
+
if (form.def.catchall !== void 0)
|
|
1151
|
+
throw new ElicitationFormError("Elicitation form must be a plain z.object(); strict, loose, and catchall objects are not supported");
|
|
1152
|
+
if ((form.def.checks ?? []).length > 0)
|
|
1153
|
+
throw new ElicitationFormError("Elicitation form cannot use refinements or checks");
|
|
1154
|
+
for (const [key, field] of Object.entries(form.shape))
|
|
1155
|
+
assertElicitationField(key, field);
|
|
1156
|
+
}
|
|
1157
|
+
function assertElicitationField(key, field) {
|
|
1158
|
+
const { schema, wrappers } = unwrapField(field);
|
|
1159
|
+
if (wrappers.some((wrapper) => (wrapper.def.checks ?? []).length > 0))
|
|
1160
|
+
throw new ElicitationFormError(`Field ${key} cannot use refinements or checks on wrappers in an elicitation form`);
|
|
1161
|
+
if (wrappers.length > 1)
|
|
1162
|
+
throw new ElicitationFormError(`Field ${key} stacks .optional()/.default() wrappers; use at most one`);
|
|
1163
|
+
const kind = classifyElicitationField(schema);
|
|
1164
|
+
if (kind === void 0)
|
|
1165
|
+
throw new ElicitationFormError(`Field ${key} has an unsupported elicitation form schema: ${schema.type}`);
|
|
1166
|
+
if (schema instanceof z13.ZodCustomStringFormat)
|
|
1167
|
+
throw new ElicitationFormError(`Field ${key} cannot use a custom string format in an elicitation form`);
|
|
1168
|
+
if (schema instanceof z13.ZodStringFormat) {
|
|
1169
|
+
const format = schema.def.format;
|
|
1170
|
+
if (!elicitationStringFormats.has(format))
|
|
1171
|
+
throw new ElicitationFormError(`Field ${key} has an unsupported elicitation string format: ${format}`);
|
|
1172
|
+
}
|
|
1173
|
+
if (kind === "number") {
|
|
1174
|
+
const format = schema.format;
|
|
1175
|
+
if (format !== null && format !== "safeint")
|
|
1176
|
+
throw new ElicitationFormError(`Field ${key} has an unsupported elicitation number format: ${format}`);
|
|
1177
|
+
}
|
|
1178
|
+
if (kind === "enum" && !enumHasOnlyStrings(schema))
|
|
1179
|
+
throw new ElicitationFormError(`Field ${key} must use a z.enum of strings`);
|
|
1180
|
+
for (const check of schema.def.checks ?? []) {
|
|
1181
|
+
if (check instanceof z13.ZodCustomStringFormat)
|
|
1182
|
+
throw new ElicitationFormError(`Field ${key} cannot use a custom string format in an elicitation form`);
|
|
1183
|
+
const definition = check._zod.def;
|
|
1184
|
+
if (isAllowedElicitationCheck(kind, definition))
|
|
1185
|
+
continue;
|
|
1186
|
+
const label = definition.check === "custom" ? "refinements" : "format" in definition && typeof definition.format === "string" ? `the ${definition.format} check` : `the ${definition.check} check`;
|
|
1187
|
+
throw new ElicitationFormError(`Field ${key} cannot use ${label} in an elicitation form`);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
function classifyElicitationField(schema) {
|
|
1191
|
+
if (schema instanceof z13.ZodString || schema instanceof z13.ZodStringFormat)
|
|
1192
|
+
return "string";
|
|
1193
|
+
if (schema instanceof z13.ZodNumber)
|
|
1194
|
+
return "number";
|
|
1195
|
+
if (schema instanceof z13.ZodBoolean)
|
|
1196
|
+
return "boolean";
|
|
1197
|
+
if (schema instanceof z13.ZodEnum)
|
|
1198
|
+
return "enum";
|
|
1199
|
+
return void 0;
|
|
1200
|
+
}
|
|
1201
|
+
function isAllowedElicitationCheck(kind, definition) {
|
|
1202
|
+
switch (kind) {
|
|
1203
|
+
case "string":
|
|
1204
|
+
if (elicitationStringChecks.has(definition.check))
|
|
1205
|
+
return true;
|
|
1206
|
+
if (definition.check !== "string_format" || !("format" in definition))
|
|
1207
|
+
return false;
|
|
1208
|
+
return definition.format === "regex" || typeof definition.format === "string" && elicitationStringFormats.has(definition.format);
|
|
1209
|
+
case "number":
|
|
1210
|
+
if (definition.check === "number_format")
|
|
1211
|
+
return "format" in definition && definition.format === "safeint";
|
|
1212
|
+
return definition.check === "greater_than" || definition.check === "less_than";
|
|
1213
|
+
case "boolean":
|
|
1214
|
+
case "enum":
|
|
1215
|
+
return false;
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
function enumHasOnlyStrings(schema) {
|
|
1219
|
+
return Object.values(schema.enum).every((value) => typeof value === "string");
|
|
1220
|
+
}
|
|
1221
|
+
function enumValues(schema) {
|
|
1222
|
+
return Object.values(schema.enum).filter((value) => typeof value === "string");
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
// ../../../libs/clinkr/ts/dist/elicitation.js
|
|
1226
|
+
var ElicitationCancelledError = class extends Error {
|
|
1227
|
+
name = "ElicitationCancelledError";
|
|
1228
|
+
constructor(message = "Prompt dismissed without a choice") {
|
|
1229
|
+
super(message);
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
var ElicitorError = class extends Error {
|
|
1233
|
+
name = "ElicitorError";
|
|
1234
|
+
};
|
|
1235
|
+
function createElicitationUi(elicitor, signal) {
|
|
1236
|
+
let pending = false;
|
|
1237
|
+
async function ask(request) {
|
|
1238
|
+
if (pending)
|
|
1239
|
+
throw new Error("ui.elicit or ui.confirm is already pending; await one prompt before starting another");
|
|
1240
|
+
if (signal.aborted)
|
|
1241
|
+
throw ClinkrExecutionError.canceled(signal.reason);
|
|
1242
|
+
pending = true;
|
|
1243
|
+
try {
|
|
1244
|
+
const response = await releaseOnAbort(askHost(elicitor, request, signal), signal);
|
|
1245
|
+
switch (response?.action) {
|
|
1246
|
+
case "accept":
|
|
1247
|
+
case "decline":
|
|
1248
|
+
return response;
|
|
1249
|
+
case "cancel":
|
|
1250
|
+
throw new ElicitationCancelledError();
|
|
1251
|
+
default:
|
|
1252
|
+
throw new ElicitorError("Elicitor returned an invalid outcome; expected accept, decline, or cancel");
|
|
1253
|
+
}
|
|
1254
|
+
} finally {
|
|
1255
|
+
pending = false;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
async function elicit(request) {
|
|
1259
|
+
if (pending)
|
|
1260
|
+
throw new Error("ui.elicit or ui.confirm is already pending; await one prompt before starting another");
|
|
1261
|
+
if (request.mode !== void 0 && request.mode !== "form")
|
|
1262
|
+
throw new Error(`Unsupported elicitation mode: ${String(request.mode)}`);
|
|
1263
|
+
if (typeof request.message !== "string")
|
|
1264
|
+
throw new Error("Elicitation message must be a string");
|
|
1265
|
+
assertElicitationForm(request.form);
|
|
1266
|
+
const response = await ask({ kind: "form", message: request.message, form: request.form });
|
|
1267
|
+
if (response.action === "decline")
|
|
1268
|
+
return { action: "decline" };
|
|
1269
|
+
const parsed = request.form.safeParse(response.content);
|
|
1270
|
+
if (!parsed.success)
|
|
1271
|
+
throw ClinkrExecutionError.internalError(parsed.error, "invalid elicitation response");
|
|
1272
|
+
return { action: "accept", content: parsed.data };
|
|
1273
|
+
}
|
|
1274
|
+
async function askYesNo(message, defaultAnswer) {
|
|
1275
|
+
const response = await ask({ kind: "confirm", message, defaultAnswer });
|
|
1276
|
+
if (response.action === "decline")
|
|
1277
|
+
return false;
|
|
1278
|
+
const parsed = z14.boolean().safeParse(response.content);
|
|
1279
|
+
if (!parsed.success)
|
|
1280
|
+
throw ClinkrExecutionError.internalError(parsed.error, "invalid elicitation response");
|
|
1281
|
+
return parsed.data;
|
|
1282
|
+
}
|
|
1283
|
+
return { elicit, askYesNo };
|
|
1284
|
+
}
|
|
1285
|
+
async function askHost(elicitor, request, signal) {
|
|
1286
|
+
try {
|
|
1287
|
+
return await elicitor(request, { signal });
|
|
1288
|
+
} catch (cause) {
|
|
1289
|
+
const detail = cause instanceof Error ? cause.message : String(cause);
|
|
1290
|
+
throw new ElicitorError(`Elicitor failed: ${detail}`, { cause });
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
async function releaseOnAbort(promise, signal) {
|
|
1294
|
+
let onAbort;
|
|
1295
|
+
const aborted = new Promise((_, reject) => {
|
|
1296
|
+
onAbort = () => reject(ClinkrExecutionError.canceled(signal.reason));
|
|
1297
|
+
if (signal.aborted)
|
|
1298
|
+
onAbort();
|
|
1299
|
+
else
|
|
1300
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
1301
|
+
});
|
|
1302
|
+
try {
|
|
1303
|
+
return await Promise.race([aborted, promise]);
|
|
1304
|
+
} finally {
|
|
1305
|
+
signal.removeEventListener("abort", onAbort);
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
// ../../../libs/clinkr/ts/dist/outcomes/thrown.js
|
|
1310
|
+
var ResponseDefect = class extends Error {
|
|
1311
|
+
cause;
|
|
1312
|
+
constructor(cause) {
|
|
1313
|
+
super(cause instanceof Error ? cause.message : String(cause), { cause });
|
|
1314
|
+
this.name = "ResponseDefect";
|
|
1315
|
+
this.cause = cause;
|
|
1316
|
+
}
|
|
1317
|
+
};
|
|
1318
|
+
function recognizedThrow(cause, options) {
|
|
1319
|
+
if (options.aborted)
|
|
1320
|
+
return canceledBy(cause);
|
|
1321
|
+
if (cause instanceof ConfirmationEndedError)
|
|
1322
|
+
return cause.outcome;
|
|
1323
|
+
if (cause instanceof ElicitationCancelledError)
|
|
1324
|
+
return canceledBy(cause);
|
|
1325
|
+
if (cause instanceof ResponseDefect)
|
|
1326
|
+
return internalError(cause.cause);
|
|
1327
|
+
if (cause instanceof ClinkrExecutionError) {
|
|
1328
|
+
if (cause.reason === "canceled")
|
|
1329
|
+
return canceledBy(cause);
|
|
1330
|
+
if (cause.reason === "internal_error")
|
|
1331
|
+
return Object.freeze({ ...internalError(cause.cause), content: { message: cause.message } });
|
|
1332
|
+
}
|
|
1333
|
+
return void 0;
|
|
1334
|
+
}
|
|
1335
|
+
function clinkrErrorFrom(cause, options) {
|
|
1336
|
+
return recognizedThrow(cause, options) ?? internalError(cause);
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
// ../../../libs/clinkr/ts/dist/outcomes/command.js
|
|
1340
|
+
function defineCommand(options) {
|
|
1341
|
+
try {
|
|
1342
|
+
const { navigation, definition } = splitNavigation(options);
|
|
1343
|
+
return Object.freeze({ ...checkCommandDefinition(canonicalOptions(definition)), navigation });
|
|
1344
|
+
} catch (error) {
|
|
1345
|
+
throw new TypeError(`Invalid command: ${error instanceof Error ? error.message : String(error)}`, {
|
|
1346
|
+
cause: error
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
var DEFINE_KEYS = [
|
|
1351
|
+
...NAVIGATION_KEYS,
|
|
1352
|
+
"requestSchema",
|
|
1353
|
+
"cli",
|
|
1354
|
+
"response",
|
|
1355
|
+
"confirms",
|
|
1356
|
+
"validate",
|
|
1357
|
+
"handler",
|
|
1358
|
+
"completionProvider",
|
|
1359
|
+
"help"
|
|
1360
|
+
];
|
|
1361
|
+
function splitNavigation(options) {
|
|
1362
|
+
if (typeof options !== "object" || options === null)
|
|
1363
|
+
return { navigation: Object.freeze({}), definition: options };
|
|
1364
|
+
const navigation = {};
|
|
1365
|
+
const definition = {};
|
|
1366
|
+
for (const [key, value] of Object.entries(options))
|
|
1367
|
+
if (NAVIGATION_KEYS.includes(key))
|
|
1368
|
+
navigation[key] = value;
|
|
1369
|
+
else
|
|
1370
|
+
definition[key] = value;
|
|
1371
|
+
const parsed = navigationSchema.safeParse(navigation);
|
|
1372
|
+
if (!parsed.success)
|
|
1373
|
+
throw new TypeError(navigationIssues(parsed.error, "definition"));
|
|
1374
|
+
return { navigation: Object.freeze(parsed.data), definition };
|
|
1375
|
+
}
|
|
1376
|
+
function canonicalOptions(options) {
|
|
1377
|
+
if (typeof options !== "object" || options === null)
|
|
1378
|
+
return options;
|
|
1379
|
+
const unknown = Object.keys(options).filter((key) => !DEFINE_KEYS.includes(key));
|
|
1380
|
+
if (unknown.length > 0)
|
|
1381
|
+
throw new TypeError(`define takes ${DEFINE_KEYS.join(", ")}, not ${unknown.join(", ")}`);
|
|
1382
|
+
const { response, ...rest } = options;
|
|
1383
|
+
if (isOutcomes(response))
|
|
1384
|
+
return { ...rest, outcomes: response };
|
|
1385
|
+
if (typeof response !== "object" || response === null || isSharedError(response))
|
|
1386
|
+
throw new TypeError("response: Expected a Response, { schema, render, throws? }, or the outcomes defineOutcomes returns");
|
|
1387
|
+
return { ...rest, ...responseCommand(response, rest["handler"]) };
|
|
1388
|
+
}
|
|
1389
|
+
function responseCommand(spec, handler) {
|
|
1390
|
+
const unknown = Object.keys(spec).filter((key) => !["schema", "render", "throws"].includes(key));
|
|
1391
|
+
if (unknown.length > 0)
|
|
1392
|
+
throw new TypeError(`response: a Response has schema, render, and throws, not ${unknown.join(", ")}`);
|
|
1393
|
+
const { schema, render, throws } = spec;
|
|
1394
|
+
if (typeof render !== "function")
|
|
1395
|
+
throw new TypeError("response.render: Expected a function");
|
|
1396
|
+
const { errors, catch: catchThrown } = checkThrows(throws);
|
|
1397
|
+
const generated = responseOutcomes(schema, errors);
|
|
1398
|
+
const renderResponse = render;
|
|
1399
|
+
const wrapped = typeof handler !== "function" ? handler : async (context, request) => {
|
|
1400
|
+
const returned = await handler(context, request);
|
|
1401
|
+
try {
|
|
1402
|
+
const { value, exitCode } = checkResult(returned);
|
|
1403
|
+
const parsed = generated.parse(exitCode, value);
|
|
1404
|
+
const text = await renderResponse(parsed, Object.freeze({ app: context.app }));
|
|
1405
|
+
return generated.rendered(exitCode, parsed, text);
|
|
1406
|
+
} catch (cause) {
|
|
1407
|
+
throw new ResponseDefect(cause);
|
|
1408
|
+
}
|
|
1409
|
+
};
|
|
1410
|
+
return {
|
|
1411
|
+
outcomes: generated.outcomes,
|
|
1412
|
+
handler: wrapped,
|
|
1413
|
+
...catchThrown === void 0 ? {} : { catch: catchThrown }
|
|
1414
|
+
};
|
|
1415
|
+
}
|
|
1416
|
+
function checkThrows(throws) {
|
|
1417
|
+
if (throws === void 0)
|
|
1418
|
+
return { errors: {} };
|
|
1419
|
+
if (typeof throws !== "object" || throws === null)
|
|
1420
|
+
throw new TypeError("response.throws: Expected { errors, catch }");
|
|
1421
|
+
const { errors, catch: catchThrown, ...rest } = throws;
|
|
1422
|
+
const unknown = Object.keys(rest);
|
|
1423
|
+
if (unknown.length > 0)
|
|
1424
|
+
throw new TypeError(`response.throws: throws has errors and catch, not ${unknown.join(", ")}`);
|
|
1425
|
+
if (typeof errors !== "object" || errors === null || Array.isArray(errors))
|
|
1426
|
+
throw new TypeError("response.throws.errors: Expected named errors from defineErrors");
|
|
1427
|
+
for (const [key, error] of Object.entries(errors))
|
|
1428
|
+
if (!isSharedError(error))
|
|
1429
|
+
throw new TypeError(`response.throws.errors.${key}: Expected a named error from defineErrors`);
|
|
1430
|
+
if (typeof catchThrown !== "function")
|
|
1431
|
+
throw new TypeError("response.throws.catch: Expected a function");
|
|
1432
|
+
return { errors, catch: catchThrown };
|
|
1433
|
+
}
|
|
1434
|
+
function checkCommandDefinition(value) {
|
|
1435
|
+
const parsed = optionsSchema.safeParse(value);
|
|
1436
|
+
if (!parsed.success)
|
|
1437
|
+
throw new TypeError(parsed.error.issues.map((issue) => `${issue.path.join(".") || "definition"}: ${issue.message}`).join("; "));
|
|
1438
|
+
const { cli: declaredCli, outcomes, validate, handler, completionProvider, help } = parsed.data;
|
|
1439
|
+
const catchThrown = parsed.data.catch;
|
|
1440
|
+
const confirms2 = parsed.data.confirms === true;
|
|
1441
|
+
const requestSchema2 = confirms2 ? withYes(parsed.data.requestSchema) : parsed.data.requestSchema;
|
|
1442
|
+
const cli = confirms2 ? withShortYes(declaredCli) : declaredCli;
|
|
1443
|
+
const checked = /* @__PURE__ */ new Set();
|
|
1444
|
+
assertNoSchemaCode([
|
|
1445
|
+
...schemaCodeProblems("request", requestSchema2),
|
|
1446
|
+
...outcomes.definition.outcomes.flatMap(({ name, kind, schema }) => {
|
|
1447
|
+
if (schema === void 0 || checked.has(schema))
|
|
1448
|
+
return [];
|
|
1449
|
+
checked.add(schema);
|
|
1450
|
+
return schemaCodeProblems(kind === "result" ? `${name} result` : `${name} error data`, schema);
|
|
1451
|
+
})
|
|
1452
|
+
]);
|
|
1453
|
+
assertNoRequestFieldDescriptions(requestSchema2);
|
|
1454
|
+
return Object.freeze({
|
|
1455
|
+
kind: "outcome",
|
|
1456
|
+
requestSchema: requestSchema2,
|
|
1457
|
+
...cli === void 0 ? {} : { cli: snapshotCliSpec(cli) },
|
|
1458
|
+
outcomes,
|
|
1459
|
+
...confirms2 ? { confirms: true } : {},
|
|
1460
|
+
...validate === void 0 ? {} : { validate },
|
|
1461
|
+
handler,
|
|
1462
|
+
...catchThrown === void 0 ? {} : { catch: catchThrown },
|
|
1463
|
+
...completionProvider === void 0 ? {} : { completionProvider },
|
|
1464
|
+
...help === void 0 ? {} : { help: Object.freeze(help) }
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
function withYes(requestSchema2) {
|
|
1468
|
+
const { yes } = requestSchema2.shape;
|
|
1469
|
+
if (yes === YES_FIELD)
|
|
1470
|
+
return requestSchema2;
|
|
1471
|
+
if (yes !== void 0)
|
|
1472
|
+
throw new TypeError("requestSchema: a command with confirms: true gets yes from Clinkr; remove its own yes field");
|
|
1473
|
+
return requestSchema2.extend({ yes: YES_FIELD });
|
|
1474
|
+
}
|
|
1475
|
+
function withShortYes(cli) {
|
|
1476
|
+
const options = cli?.options ?? {};
|
|
1477
|
+
for (const [key, option] of Object.entries(options))
|
|
1478
|
+
if (key !== "yes" && option?.short === "y")
|
|
1479
|
+
throw new TypeError(`cli.options.${key}: -y is --yes on a command with confirms: true`);
|
|
1480
|
+
const own = options["yes"];
|
|
1481
|
+
if (own !== void 0 && (own.short !== "y" || own.aliases !== void 0))
|
|
1482
|
+
throw new TypeError("cli.options.yes: a command with confirms: true gets --yes and -y from Clinkr");
|
|
1483
|
+
return { ...cli, options: { ...options, yes: { short: "y" } } };
|
|
1484
|
+
}
|
|
1485
|
+
function isOutcomeCommandDefinition(value) {
|
|
1486
|
+
return typeof value === "object" && value !== null && value.kind === "outcome";
|
|
1487
|
+
}
|
|
1488
|
+
var optionsSchema = z15.strictObject({
|
|
1489
|
+
kind: z15.literal("outcome").optional(),
|
|
1490
|
+
// A defined command's navigation parts, which `define` checked; the caller attaches the command's own.
|
|
1491
|
+
navigation: z15.unknown().optional(),
|
|
1492
|
+
requestSchema: z15.custom((value) => hasParse(value) && typeof value.shape === "object", "Expected an object schema"),
|
|
1493
|
+
cli: cliSpecSchema.optional(),
|
|
1494
|
+
outcomes: z15.custom(isOutcomes, "Expected the outcomes defineOutcomes returns"),
|
|
1495
|
+
confirms: z15.boolean().optional(),
|
|
1496
|
+
validate: z15.custom((value) => typeof value === "function", "Expected a function").optional(),
|
|
1497
|
+
handler: z15.custom((value) => typeof value === "function", "Expected a function"),
|
|
1498
|
+
catch: z15.custom((value) => typeof value === "function", "Expected a function").optional(),
|
|
1499
|
+
completionProvider: z15.custom((value) => typeof value === "function", "Expected a function").optional(),
|
|
1500
|
+
help: commandHelpSchema.readonly().optional()
|
|
1501
|
+
});
|
|
1502
|
+
function hasParse(value) {
|
|
1503
|
+
return typeof value === "object" && value !== null && "parse" in value && typeof value.parse === "function";
|
|
1504
|
+
}
|
|
1505
|
+
function isOutcomes(value) {
|
|
1506
|
+
if (typeof value !== "object" || value === null)
|
|
1507
|
+
return false;
|
|
1508
|
+
const { definition } = value;
|
|
1509
|
+
return typeof definition === "object" && definition !== null && Array.isArray(definition.outcomes) && hasParse(definition.documentSchema);
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
// ../../../libs/clinkr/ts/dist/command-tree.js
|
|
1513
|
+
var COMMAND_TREE_TAG = /* @__PURE__ */ Symbol.for("clinkr.commandTree");
|
|
1514
|
+
function commandTree(tree) {
|
|
1515
|
+
if (typeof tree?.id !== "string" || tree.id.trim().length === 0)
|
|
1516
|
+
throw new Error("Command tree requires a nonempty id");
|
|
1517
|
+
const tag = Object.freeze({ id: tree.id });
|
|
1518
|
+
const define = (definition) => {
|
|
1519
|
+
const defined = defineCommand(definition);
|
|
1520
|
+
return Object.freeze(Object.defineProperty({ ...defined }, COMMAND_TREE_TAG, { value: tag }));
|
|
1521
|
+
};
|
|
1522
|
+
return Object.freeze({
|
|
1523
|
+
id: tag.id,
|
|
1524
|
+
define,
|
|
1525
|
+
group: (group) => {
|
|
1526
|
+
if (typeof group !== "object" || group === null)
|
|
1527
|
+
throw new TypeError(`Command tree ${tag.id}: group takes { commands, description?, \u2026 }`);
|
|
1528
|
+
const { commands, ...navigation } = group;
|
|
1529
|
+
if (typeof commands !== "object" || commands === null || Array.isArray(commands))
|
|
1530
|
+
throw new TypeError(`Command tree ${tag.id}: group takes commands, a record of names to commands and groups`);
|
|
1531
|
+
return Object.freeze({
|
|
1532
|
+
kind: "inline-group",
|
|
1533
|
+
tree: tag.id,
|
|
1534
|
+
navigation: groupNavigation(tag.id, navigation),
|
|
1535
|
+
commands: Object.freeze({ ...commands })
|
|
1536
|
+
});
|
|
1537
|
+
},
|
|
1538
|
+
directory: (directory) => {
|
|
1539
|
+
if (typeof directory !== "string" || !isAbsolute(directory))
|
|
1540
|
+
throw new Error(`Command tree ${tag.id}: directory takes an absolute path`);
|
|
1541
|
+
return Object.freeze({ kind: "directory", tree: tag.id, directory });
|
|
1542
|
+
}
|
|
1543
|
+
});
|
|
1544
|
+
}
|
|
1545
|
+
var GROUP_KEYS = ["commands", ...GROUP_NAVIGATION_KEYS];
|
|
1546
|
+
function groupNavigation(treeId, navigation) {
|
|
1547
|
+
const unknown = Object.keys(navigation).filter((key) => !GROUP_KEYS.includes(key));
|
|
1548
|
+
if (unknown.length > 0)
|
|
1549
|
+
throw new TypeError(`Command tree ${treeId}: group takes ${GROUP_KEYS.join(", ")}, not ${unknown.join(", ")}`);
|
|
1550
|
+
const parsed = groupNavigationSchema.safeParse(navigation);
|
|
1551
|
+
if (!parsed.success)
|
|
1552
|
+
throw new TypeError(`Command tree ${treeId}: group ${navigationIssues(parsed.error, "group")}`);
|
|
1553
|
+
return Object.freeze(parsed.data);
|
|
1554
|
+
}
|
|
1555
|
+
function treeTagOf(command) {
|
|
1556
|
+
const tag = command[COMMAND_TREE_TAG];
|
|
1557
|
+
return tag === void 0 ? void 0 : tag;
|
|
1558
|
+
}
|
|
1559
|
+
function isTreeGroup(value) {
|
|
1560
|
+
if (typeof value !== "object" || value === null)
|
|
1561
|
+
return false;
|
|
1562
|
+
const { kind, tree, navigation } = value;
|
|
1563
|
+
if (typeof tree !== "string")
|
|
1564
|
+
return false;
|
|
1565
|
+
return kind === "directory" || kind === "inline-group" && typeof navigation === "object" && navigation !== null;
|
|
1566
|
+
}
|
|
1567
|
+
function mount(group, options) {
|
|
1568
|
+
if (!isTreeGroup(group))
|
|
1569
|
+
throw new TypeError("mount takes a group from a command tree's group or directory");
|
|
1570
|
+
return Object.freeze({ ...options, group });
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
// ../../../libs/clinkr/ts/dist/create-application.js
|
|
1574
|
+
import { readdir as readdir3, stat as stat2 } from "node:fs/promises";
|
|
1575
|
+
import { join as join4 } from "node:path";
|
|
1576
|
+
|
|
1577
|
+
// ../../../libs/clinkr/ts/dist/discovery.js
|
|
1578
|
+
import { readdir, stat } from "node:fs/promises";
|
|
1579
|
+
import { basename, join } from "node:path";
|
|
1580
|
+
import { pathToFileURL } from "node:url";
|
|
1581
|
+
|
|
1582
|
+
// ../../../libs/clinkr/ts/dist/is-listed.js
|
|
1583
|
+
function isListed(node) {
|
|
1584
|
+
return node.metadata.hidden !== true;
|
|
1585
|
+
}
|
|
1586
|
+
function commandAliases(node) {
|
|
1587
|
+
return node.kind === "command" ? node.metadata.aliases ?? [] : [];
|
|
1588
|
+
}
|
|
1589
|
+
function isDefaultCommand(node) {
|
|
1590
|
+
return node.kind === "command" && node.metadata.default === true;
|
|
1591
|
+
}
|
|
1592
|
+
function defaultCommandOf(nodes) {
|
|
1593
|
+
return nodes.find((node) => isDefaultCommand(node) && isListed(node));
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
// ../../../libs/clinkr/ts/dist/discovery.js
|
|
1597
|
+
function isGroup(node) {
|
|
1598
|
+
return node.description.kind === "group";
|
|
1599
|
+
}
|
|
1600
|
+
function sourceOf(group) {
|
|
1601
|
+
return group.kind === "directory" ? { id: group.tree, directory: group.directory } : { id: group.tree };
|
|
1602
|
+
}
|
|
1603
|
+
function matchesName(node, segment) {
|
|
1604
|
+
return node.description.name === segment || commandAliases(node.description).includes(segment);
|
|
1605
|
+
}
|
|
1606
|
+
function compareCodeUnits(left, right) {
|
|
1607
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
1608
|
+
}
|
|
1609
|
+
function undeclaredSection(section2, declared) {
|
|
1610
|
+
if (section2 === void 0 || declared === void 0 || declared.has(section2))
|
|
1611
|
+
return void 0;
|
|
1612
|
+
const names = [...declared].map((name) => JSON.stringify(name)).join(", ");
|
|
1613
|
+
return `Undeclared help section ${JSON.stringify(section2)}; declared help sections: ${names || "none"}`;
|
|
1614
|
+
}
|
|
1615
|
+
function emptyGroupError(where, mountable) {
|
|
1616
|
+
return new Error(`Command group must contain child commands${mountable ? " or a mount" : ""}: ${where}`);
|
|
1617
|
+
}
|
|
1618
|
+
var SourceDiscoveryError = class extends Error {
|
|
1619
|
+
constructor(source, path, cause) {
|
|
1620
|
+
super(`Command source ${source.id} at ${path.join(" ") || "<root>"}${source.directory === void 0 ? "" : ` (${source.directory})`}: ${cause instanceof Error ? cause.message : String(cause)}`, {
|
|
1621
|
+
cause
|
|
1622
|
+
});
|
|
1623
|
+
}
|
|
1624
|
+
};
|
|
1625
|
+
function discoverGroup(group, scope, prefix = []) {
|
|
1626
|
+
return group.kind === "directory" ? discoverChildren(scope, prefix, group.directory) : inlineChildren(scope, group, prefix);
|
|
1627
|
+
}
|
|
1628
|
+
async function atLocation(source, location, read) {
|
|
1629
|
+
try {
|
|
1630
|
+
return await read();
|
|
1631
|
+
} catch (error) {
|
|
1632
|
+
if (error instanceof SourceDiscoveryError)
|
|
1633
|
+
throw error;
|
|
1634
|
+
throw new SourceDiscoveryError(source, location, error);
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
function checkedSiblings(scope, prefix, read) {
|
|
1638
|
+
return atLocation(scope.source, prefix, async () => {
|
|
1639
|
+
const nodes = await read();
|
|
1640
|
+
checkAliasConflicts(nodes, prefix);
|
|
1641
|
+
checkDefaultConflicts(nodes, prefix);
|
|
1642
|
+
return Object.freeze(nodes);
|
|
1643
|
+
});
|
|
1644
|
+
}
|
|
1645
|
+
function checkNode(scope, { name, metadata, metadataPath }, leaf) {
|
|
1646
|
+
const undeclared2 = undeclaredSection(metadata.helpSection, scope.declaredSections);
|
|
1647
|
+
if (undeclared2 !== void 0)
|
|
1648
|
+
throw new Error(`${undeclared2}${metadataPath === void 0 ? "" : ` in ${metadataPath}`}`);
|
|
1649
|
+
const at = metadataPath === void 0 ? "" : ` (${metadataPath})`;
|
|
1650
|
+
if (leaf) {
|
|
1651
|
+
if (metadata.default === true && metadata.hidden === true)
|
|
1652
|
+
throw new Error(`Command ${name} cannot be both default and hidden${at}`);
|
|
1653
|
+
return;
|
|
1654
|
+
}
|
|
1655
|
+
if (metadata.aliases !== void 0)
|
|
1656
|
+
throw new Error(`Group ${name} cannot declare aliases; only leaf commands can${at}`);
|
|
1657
|
+
if (metadata.default !== void 0)
|
|
1658
|
+
throw new Error(`Group ${name} cannot declare default; only leaf commands can${at}`);
|
|
1659
|
+
if (metadata.help !== void 0)
|
|
1660
|
+
throw new Error(`Group ${name} cannot declare help; only leaf commands can${at}`);
|
|
1661
|
+
}
|
|
1662
|
+
function leafNode(scope, found, location, loadCommand) {
|
|
1663
|
+
checkNode(scope, found, true);
|
|
1664
|
+
return Object.freeze({
|
|
1665
|
+
description: Object.freeze({ kind: "command", name: found.name, metadata: found.metadata }),
|
|
1666
|
+
source: scope.source,
|
|
1667
|
+
binding: scope.binding,
|
|
1668
|
+
location,
|
|
1669
|
+
loadCommand
|
|
1670
|
+
});
|
|
1671
|
+
}
|
|
1672
|
+
async function groupNode(scope, found, children2) {
|
|
1673
|
+
checkNode(scope, found, false);
|
|
1674
|
+
const nodes = await children2();
|
|
1675
|
+
if (nodes.length === 0 && !scope.mountPoints)
|
|
1676
|
+
throw emptyGroupError(found.where, false);
|
|
1677
|
+
return Object.freeze({
|
|
1678
|
+
description: Object.freeze({ kind: "group", name: found.name, metadata: found.metadata }),
|
|
1679
|
+
children: async () => nodes
|
|
1680
|
+
});
|
|
1681
|
+
}
|
|
1682
|
+
function inlineChildren(scope, group, prefix) {
|
|
1683
|
+
return checkedSiblings(scope, prefix, () => Promise.all(Object.keys(group.commands).toSorted(compareCodeUnits).map((name) => inlineNode(scope, name, group.commands[name], prefix))));
|
|
1684
|
+
}
|
|
1685
|
+
function inlineNode(scope, name, member, prefix) {
|
|
1686
|
+
const location = [...prefix, name];
|
|
1687
|
+
return atLocation(scope.source, location, async () => {
|
|
1688
|
+
if (!isCommandNameSegment(name))
|
|
1689
|
+
throw new Error(`Invalid command name ${JSON.stringify(name)}: names are nonempty, without whitespace, control characters, or separators, and are not . or .. or begin with -`);
|
|
1690
|
+
const value = member;
|
|
1691
|
+
if (isTreeGroup(value) && value.kind === "directory")
|
|
1692
|
+
throw new Error("A group's commands hold commands and inline groups; mount a directory group with mount");
|
|
1693
|
+
if (isTreeGroup(member)) {
|
|
1694
|
+
const group = member;
|
|
1695
|
+
return groupNode(scope, inlineFound(name, member.navigation, location), () => inlineChildren(scope, group, location));
|
|
1696
|
+
}
|
|
1697
|
+
if (!isOutcomeCommandDefinition(member) || treeTagOf(member) === void 0)
|
|
1698
|
+
throw new Error("Expected a command from a tree's define or a group from a tree's group");
|
|
1699
|
+
const command = member;
|
|
1700
|
+
return leafNode(scope, inlineFound(name, command.navigation, location), location, async () => command);
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1703
|
+
function inlineFound(name, navigation, location) {
|
|
1704
|
+
const { description } = navigation;
|
|
1705
|
+
if (description === void 0)
|
|
1706
|
+
throw new Error("A group's commands and nested groups each need a description in their definition");
|
|
1707
|
+
return { name, metadata: Object.freeze({ ...navigation, description }), where: location.join(" ") };
|
|
1708
|
+
}
|
|
1709
|
+
async function discoverChildren(scope, prefix, directory) {
|
|
1710
|
+
return checkedSiblings(scope, prefix, async () => {
|
|
1711
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
1712
|
+
const directories = entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name).toSorted(compareCodeUnits);
|
|
1713
|
+
return Promise.all(directories.map((name) => discoverNode(scope, name, prefix, directory)));
|
|
1714
|
+
});
|
|
1715
|
+
}
|
|
1716
|
+
function discoverNode(scope, name, prefix, parentDirectory) {
|
|
1717
|
+
const directory = join(parentDirectory, name);
|
|
1718
|
+
const location = [...prefix, name];
|
|
1719
|
+
return atLocation(scope.source, location, async () => {
|
|
1720
|
+
const metadataPath = await findModule(directory, "metadata");
|
|
1721
|
+
if (metadataPath === void 0)
|
|
1722
|
+
throw new Error(`Missing metadata.ts or metadata.js for command node: ${directory}`);
|
|
1723
|
+
const metadata = await loadMetadata(metadataPath);
|
|
1724
|
+
const found = { name, metadata, metadataPath, where: directory };
|
|
1725
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
1726
|
+
const hasChildDirectories = entries.some((entry) => entry.isDirectory());
|
|
1727
|
+
const commandModule = await findModule(directory, "command");
|
|
1728
|
+
if (commandModule === void 0)
|
|
1729
|
+
return groupNode(scope, found, () => discoverChildren(scope, location, directory));
|
|
1730
|
+
if (hasChildDirectories)
|
|
1731
|
+
throw new Error(`Command node cannot contain ${basename(commandModule)} and child commands: ${directory}`);
|
|
1732
|
+
const treeId = scope.source.id;
|
|
1733
|
+
const root = scope.source.directory ?? directory;
|
|
1734
|
+
return leafNode(scope, found, location, () => importCommand(treeId, root, metadata, metadataPath, commandModule));
|
|
1735
|
+
});
|
|
1736
|
+
}
|
|
1737
|
+
function checkAliasConflicts(nodes, prefix) {
|
|
1738
|
+
const owners = /* @__PURE__ */ new Map();
|
|
1739
|
+
for (const { description } of nodes)
|
|
1740
|
+
owners.set(description.name, description.name);
|
|
1741
|
+
for (const { description } of nodes) {
|
|
1742
|
+
for (const alias of commandAliases(description)) {
|
|
1743
|
+
const at = [...prefix, alias].join(" ");
|
|
1744
|
+
if (alias === description.name)
|
|
1745
|
+
throw new Error(`Command alias conflict at ${at}: ${description.name} declares its own name as an alias`);
|
|
1746
|
+
const owner = owners.get(alias);
|
|
1747
|
+
if (owner !== void 0) {
|
|
1748
|
+
const [first, second] = [owner, description.name].toSorted(compareCodeUnits);
|
|
1749
|
+
throw new Error(`Command alias conflict at ${at}: ${first} and ${second}`);
|
|
1750
|
+
}
|
|
1751
|
+
owners.set(alias, description.name);
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
function checkDefaultConflicts(nodes, prefix) {
|
|
1756
|
+
const defaults = nodes.filter((node) => isDefaultCommand(node.description));
|
|
1757
|
+
if (defaults.length > 1) {
|
|
1758
|
+
const [first, second] = defaults;
|
|
1759
|
+
throw new Error(`Default command conflict at ${prefix.join(" ") || "<root>"}: ${first.description.name} and ${second.description.name}`);
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
async function loadMetadata(path) {
|
|
1763
|
+
const module = await import(pathToFileURL(path).href);
|
|
1764
|
+
const result = commandMetadataSchema.safeParse(module.metadata);
|
|
1765
|
+
if (!result.success)
|
|
1766
|
+
throw new Error(`Invalid metadata export in ${path}: ${navigationIssues(result.error, "metadata")}`);
|
|
1767
|
+
return Object.freeze(result.data);
|
|
1768
|
+
}
|
|
1769
|
+
async function importCommand(treeId, directory, metadata, metadataPath, modulePath) {
|
|
1770
|
+
const module = await import(pathToFileURL(modulePath).href);
|
|
1771
|
+
return commandOfModule({ treeId, directory, metadata, metadataPath, modulePath, exported: module.default });
|
|
1772
|
+
}
|
|
1773
|
+
function commandOfModule(module) {
|
|
1774
|
+
const { treeId, metadata, exported, metadataPath, modulePath, directory } = module;
|
|
1775
|
+
if (!isOutcomeCommandDefinition(exported))
|
|
1776
|
+
throw new Error(`Invalid command export in ${modulePath}: export default ${treeId}.define({ \u2026 })`);
|
|
1777
|
+
const tag = treeTagOf(exported);
|
|
1778
|
+
if (tag === void 0)
|
|
1779
|
+
throw new Error(`Invalid command export in ${modulePath}: define it with command tree ${treeId}'s define`);
|
|
1780
|
+
if (tag.id !== treeId)
|
|
1781
|
+
throw new Error(`Invalid command export in ${modulePath}: it belongs to command tree ${tag.id}, not to command tree ${treeId}${directory === void 0 ? "" : ` (${directory})`}`);
|
|
1782
|
+
const own = typeof exported.navigation === "object" && exported.navigation !== null ? Object.keys(exported.navigation) : [];
|
|
1783
|
+
if (own.length > 0)
|
|
1784
|
+
throw new Error(`Invalid command export in ${modulePath}: navigation parts go in ${basename(metadataPath)}, not ${own.join(", ")}`);
|
|
1785
|
+
let checked;
|
|
1786
|
+
try {
|
|
1787
|
+
checked = checkCommandDefinition(exported);
|
|
1788
|
+
} catch (error) {
|
|
1789
|
+
throw new Error(`Invalid command definition exported by ${modulePath}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
1790
|
+
}
|
|
1791
|
+
const { help, ...navigation } = metadata;
|
|
1792
|
+
if (help !== void 0 && checked.help !== void 0)
|
|
1793
|
+
throw new Error(`Command help is set in both ${metadataPath} and ${modulePath}; set it in one of them`);
|
|
1794
|
+
return Object.freeze({ ...checked, navigation: Object.freeze(navigation), ...help === void 0 ? {} : { help } });
|
|
1795
|
+
}
|
|
1796
|
+
async function findModule(directory, stem) {
|
|
1797
|
+
const typescript = join(directory, `${stem}.ts`);
|
|
1798
|
+
if (await isFile(typescript))
|
|
1799
|
+
return typescript;
|
|
1800
|
+
const javascript = join(directory, `${stem}.js`);
|
|
1801
|
+
if (await isFile(javascript))
|
|
1802
|
+
return javascript;
|
|
1803
|
+
return void 0;
|
|
1804
|
+
}
|
|
1805
|
+
async function isFile(path) {
|
|
1806
|
+
try {
|
|
1807
|
+
return (await stat(path)).isFile();
|
|
1808
|
+
} catch (error) {
|
|
1809
|
+
if (isMissing(error))
|
|
1810
|
+
return false;
|
|
1811
|
+
throw error;
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
function isMissing(error) {
|
|
1815
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
1816
|
+
}
|
|
1817
|
+
|
|
1818
|
+
// ../../../libs/clinkr/ts/dist/mounts.js
|
|
1819
|
+
import { join as join2, resolve } from "node:path";
|
|
1820
|
+
var PLAIN = Object.freeze({ kind: "plain" });
|
|
1821
|
+
function checkProjectedTreeIds(mounts) {
|
|
1822
|
+
const directories = /* @__PURE__ */ new Map();
|
|
1823
|
+
for (const { source, binding } of mounts) {
|
|
1824
|
+
if (binding.kind !== "projected" || source.directory === void 0)
|
|
1825
|
+
continue;
|
|
1826
|
+
const directory = resolve(source.directory);
|
|
1827
|
+
const prior = directories.get(source.id);
|
|
1828
|
+
if (prior !== void 0 && prior !== directory)
|
|
1829
|
+
throw new Error(`Projected mounts of command tree ${source.id} name two directories: ${prior} and ${directory}`);
|
|
1830
|
+
directories.set(source.id, directory);
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
async function mountAll(builtIn, mounts, host, declaredSections) {
|
|
1834
|
+
for (const mount2 of mounts) {
|
|
1835
|
+
if (typeof mount2.description !== "string" || mount2.description.trim().length === 0)
|
|
1836
|
+
throw new Error(`Mount from ${mount2.source.id} requires a nonempty description`);
|
|
1837
|
+
for (const [field, value] of [
|
|
1838
|
+
["summary", mount2.summary],
|
|
1839
|
+
["helpSection", mount2.helpSection]
|
|
1840
|
+
]) {
|
|
1841
|
+
if (value !== void 0 && (typeof value !== "string" || !isSingleLineText(value)))
|
|
1842
|
+
throw new Error(`Mount from ${mount2.source.id} requires ${field} to be a nonempty single-line string without control characters`);
|
|
1843
|
+
}
|
|
1844
|
+
if (mount2.hidden !== void 0 && typeof mount2.hidden !== "boolean")
|
|
1845
|
+
throw new Error(`Mount from ${mount2.source.id} requires hidden to be a boolean`);
|
|
1846
|
+
const undeclared2 = undeclaredSection(mount2.helpSection, declaredSections);
|
|
1847
|
+
if (undeclared2 !== void 0)
|
|
1848
|
+
throw new Error(`Mount from ${mount2.source.id}: ${undeclared2}`);
|
|
1849
|
+
if (!Array.isArray(mount2.path) || mount2.path.length === 0)
|
|
1850
|
+
throw new Error(`Mount from ${mount2.source.id} requires a nonempty path`);
|
|
1851
|
+
for (const segment of mount2.path) {
|
|
1852
|
+
if (typeof segment !== "string" || !isCommandNameSegment(segment)) {
|
|
1853
|
+
throw new Error(`Invalid mount path segment ${JSON.stringify(segment)} from ${mount2.source.id}`);
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
const ordered = [...mounts].toSorted((a, b) => compareCodeUnits(a.path.join("/"), b.path.join("/")) || compareCodeUnits(a.source.id, b.source.id));
|
|
1858
|
+
let root = builtIn;
|
|
1859
|
+
for (const [index, mount2] of ordered.entries()) {
|
|
1860
|
+
const path = mount2.path.join(" ");
|
|
1861
|
+
for (const prior of ordered.slice(0, index)) {
|
|
1862
|
+
if (prior.path.every((segment, offset) => mount2.path[offset] === segment) || mount2.path.every((segment, offset) => prior.path[offset] === segment)) {
|
|
1863
|
+
const conflictPath = prior.path.length > mount2.path.length ? prior.path.join(" ") : path;
|
|
1864
|
+
throw new Error(`Mount conflict at ${conflictPath}: ${prior.source.id} and ${mount2.source.id}`);
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
root = await insertMount(root, mount2, host, declaredSections);
|
|
1868
|
+
}
|
|
1869
|
+
return root;
|
|
1870
|
+
}
|
|
1871
|
+
async function insertMount(siblings, mount2, host, declaredSections, offset = 0) {
|
|
1872
|
+
const path = mount2.path.join(" ");
|
|
1873
|
+
const segment = mount2.path[offset];
|
|
1874
|
+
const node = siblings.find((candidate) => matchesName(candidate, segment));
|
|
1875
|
+
if (offset === mount2.path.length - 1) {
|
|
1876
|
+
if (node !== void 0) {
|
|
1877
|
+
const owner = node.description.name === segment ? host.id : `${host.id} (alias of ${node.description.name})`;
|
|
1878
|
+
throw new Error(`Mount conflict at ${path}: ${owner} and ${mount2.source.id}`);
|
|
1879
|
+
}
|
|
1880
|
+
return Object.freeze([...siblings, mountGroup(mount2, declaredSections)].toSorted((a, b) => compareCodeUnits(a.description.name, b.description.name)));
|
|
1881
|
+
}
|
|
1882
|
+
if (node === void 0 || !isGroup(node)) {
|
|
1883
|
+
throw new Error(`Mount conflict at ${path}: ${host.id} and ${mount2.source.id} (missing group or leaf at ${mount2.path.slice(0, offset + 1).join(" ")})`);
|
|
1884
|
+
}
|
|
1885
|
+
const children2 = await insertMount(await node.children(), mount2, host, declaredSections, offset + 1);
|
|
1886
|
+
const replacement = Object.freeze({ description: node.description, children: async () => children2 });
|
|
1887
|
+
return Object.freeze(siblings.map((sibling) => sibling === node ? replacement : sibling));
|
|
1888
|
+
}
|
|
1889
|
+
function mountGroup(mount2, declaredSections) {
|
|
1890
|
+
const description = Object.freeze({
|
|
1891
|
+
kind: "group",
|
|
1892
|
+
name: mount2.path[mount2.path.length - 1],
|
|
1893
|
+
metadata: Object.freeze({
|
|
1894
|
+
description: mount2.description,
|
|
1895
|
+
...mount2.summary === void 0 ? {} : { summary: mount2.summary },
|
|
1896
|
+
...mount2.helpSection === void 0 ? {} : { helpSection: mount2.helpSection },
|
|
1897
|
+
...mount2.hidden === void 0 ? {} : { hidden: mount2.hidden }
|
|
1898
|
+
})
|
|
1899
|
+
});
|
|
1900
|
+
let pending;
|
|
1901
|
+
return Object.freeze({
|
|
1902
|
+
description,
|
|
1903
|
+
children: () => {
|
|
1904
|
+
pending ??= discoverGroup(mount2.group, { source: mount2.source, declaredSections, binding: mount2.binding, mountPoints: false }, mount2.path);
|
|
1905
|
+
return pending;
|
|
1906
|
+
},
|
|
1907
|
+
mounted: true
|
|
1908
|
+
});
|
|
1909
|
+
}
|
|
1910
|
+
async function checkGroupsFilled(nodes, host, prefix = []) {
|
|
1911
|
+
for (const node of nodes) {
|
|
1912
|
+
if (!isGroup(node) || node.mounted === true)
|
|
1913
|
+
continue;
|
|
1914
|
+
const path = [...prefix, node.description.name];
|
|
1915
|
+
const children2 = await node.children();
|
|
1916
|
+
if (children2.length === 0)
|
|
1917
|
+
throw new SourceDiscoveryError(host, path, emptyGroupError(host.directory === void 0 ? path.join(" ") : join2(host.directory, ...path), true));
|
|
1918
|
+
await checkGroupsFilled(children2, host, path);
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
function projectCommand(command, app) {
|
|
1922
|
+
const { handler, completionProvider } = command;
|
|
1923
|
+
return Object.freeze({
|
|
1924
|
+
...command,
|
|
1925
|
+
handler: async (context, request) => {
|
|
1926
|
+
const child = app(context.app);
|
|
1927
|
+
const returned = await handler(Object.freeze({ ...context, app: child }), request);
|
|
1928
|
+
return isResult(returned) ? { ...returned, render: () => returned.render({ app: child }) } : returned;
|
|
1929
|
+
},
|
|
1930
|
+
...completionProvider === void 0 ? {} : {
|
|
1931
|
+
completionProvider: (request) => completionProvider({ ...request, app: app(request.app) })
|
|
1932
|
+
}
|
|
1933
|
+
});
|
|
1934
|
+
}
|
|
1935
|
+
function isResult(value) {
|
|
1936
|
+
return typeof value === "object" && value !== null && value.kind === "result" && typeof value.render === "function";
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
// ../../../libs/clinkr/ts/dist/skills/read-skills.js
|
|
1940
|
+
import { readFile, readdir as readdir2 } from "node:fs/promises";
|
|
1941
|
+
import { isAbsolute as isAbsolute2, join as join3 } from "node:path";
|
|
1942
|
+
|
|
1943
|
+
// ../../../libs/clinkr/ts/dist/skills/skill-file.js
|
|
1944
|
+
var COMMANDS_SKILL_NAME = "commands";
|
|
1945
|
+
var OVERVIEW_SKILL_NAME = "overview";
|
|
1946
|
+
var KEYS = /* @__PURE__ */ new Set(["name", "description", "commands"]);
|
|
1947
|
+
function isSkillName(name) {
|
|
1948
|
+
return /^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(name);
|
|
1949
|
+
}
|
|
1950
|
+
function parseSkillFile(path, text) {
|
|
1951
|
+
const fail = (problem) => {
|
|
1952
|
+
throw new Error(`Invalid skill file ${path}: ${problem}`);
|
|
1953
|
+
};
|
|
1954
|
+
const lines = text.replace(/^\uFEFF/u, "").replace(/\r\n/gu, "\n").split("\n");
|
|
1955
|
+
if (lines[0] !== "---")
|
|
1956
|
+
return fail("the first line must be --- to start the frontmatter");
|
|
1957
|
+
const end = lines.indexOf("---", 1);
|
|
1958
|
+
if (end === -1)
|
|
1959
|
+
return fail("the frontmatter has no closing --- line");
|
|
1960
|
+
const values = /* @__PURE__ */ new Map();
|
|
1961
|
+
let commands;
|
|
1962
|
+
let blockList;
|
|
1963
|
+
for (let index = 1; index < end; index += 1) {
|
|
1964
|
+
const line = lines[index];
|
|
1965
|
+
const lineNumber = index + 1;
|
|
1966
|
+
if (line.trim() === "")
|
|
1967
|
+
continue;
|
|
1968
|
+
const item = /^\s*- (.*)$/u.exec(line);
|
|
1969
|
+
if (item !== null) {
|
|
1970
|
+
if (blockList === void 0)
|
|
1971
|
+
return fail(`line ${lineNumber}: a list item must follow commands:`);
|
|
1972
|
+
blockList.push(scalar(item[1].trim(), lineNumber, fail));
|
|
1973
|
+
continue;
|
|
1974
|
+
}
|
|
1975
|
+
blockList = void 0;
|
|
1976
|
+
const entry = /^([A-Za-z_][\w-]*):(?:[ \t]+(.*))?$/u.exec(line);
|
|
1977
|
+
if (entry === null)
|
|
1978
|
+
return fail(`line ${lineNumber}: expected key: value`);
|
|
1979
|
+
const key = entry[1];
|
|
1980
|
+
const value = (entry[2] ?? "").trim();
|
|
1981
|
+
if (!KEYS.has(key))
|
|
1982
|
+
return fail(`line ${lineNumber}: unknown key ${key}; the keys are name, description, and commands`);
|
|
1983
|
+
if (values.has(key) || key === "commands" && commands !== void 0)
|
|
1984
|
+
return fail(`line ${lineNumber}: ${key} appears twice`);
|
|
1985
|
+
if (key !== "commands") {
|
|
1986
|
+
values.set(key, scalar(value, lineNumber, fail));
|
|
1987
|
+
continue;
|
|
1988
|
+
}
|
|
1989
|
+
if (value === "") {
|
|
1990
|
+
blockList = [];
|
|
1991
|
+
commands = blockList;
|
|
1992
|
+
continue;
|
|
1993
|
+
}
|
|
1994
|
+
if (value === "all") {
|
|
1995
|
+
commands = "all";
|
|
1996
|
+
continue;
|
|
1997
|
+
}
|
|
1998
|
+
if (!value.startsWith("[") || !value.endsWith("]"))
|
|
1999
|
+
return fail(`line ${lineNumber}: commands must be all, a [a, b] list, or a list of - items`);
|
|
2000
|
+
const inner = value.slice(1, -1).trim();
|
|
2001
|
+
commands = inner === "" ? [] : inner.split(",").map((part) => scalar(part.trim(), lineNumber, fail));
|
|
2002
|
+
}
|
|
2003
|
+
const name = values.get("name");
|
|
2004
|
+
if (name === void 0)
|
|
2005
|
+
return fail("the frontmatter has no name");
|
|
2006
|
+
const description = values.get("description");
|
|
2007
|
+
if (description === void 0)
|
|
2008
|
+
return fail("the frontmatter has no description");
|
|
2009
|
+
if (!isSkillName(name))
|
|
2010
|
+
return fail(`name ${JSON.stringify(name)} must be hyphen-case, such as deploy-a-preview`);
|
|
2011
|
+
const stem = fileStem(path);
|
|
2012
|
+
if (name !== stem)
|
|
2013
|
+
return fail(`name ${name} must match the file name ${stem}.md`);
|
|
2014
|
+
if (name === COMMANDS_SKILL_NAME)
|
|
2015
|
+
return fail(`the name ${COMMANDS_SKILL_NAME} is reserved for the generated command index`);
|
|
2016
|
+
if (!isSingleLineText(description))
|
|
2017
|
+
return fail("description must be one nonempty line");
|
|
2018
|
+
const paths = commands === void 0 ? [] : commands === "all" ? "all" : commandPaths(commands, fail);
|
|
2019
|
+
const body = lines.slice(end + 1).join("\n").replace(/^(?:[ \t]*\n)+/u, "").trimEnd();
|
|
2020
|
+
if (body === "" && paths !== "all" && paths.length === 0)
|
|
2021
|
+
return fail("the file has no body and no commands");
|
|
2022
|
+
return Object.freeze({ path, name, description, commands: paths, body });
|
|
2023
|
+
}
|
|
2024
|
+
function scalar(value, lineNumber, fail) {
|
|
2025
|
+
if (value.startsWith('"')) {
|
|
2026
|
+
try {
|
|
2027
|
+
const parsed = JSON.parse(value);
|
|
2028
|
+
if (typeof parsed === "string")
|
|
2029
|
+
return parsed;
|
|
2030
|
+
} catch {
|
|
2031
|
+
}
|
|
2032
|
+
return fail(`line ${lineNumber}: malformed double-quoted value`);
|
|
2033
|
+
}
|
|
2034
|
+
if (value.startsWith("'")) {
|
|
2035
|
+
const inner = value.slice(1, -1);
|
|
2036
|
+
if (value.length < 2 || !value.endsWith("'") || inner.replaceAll("''", "").includes("'"))
|
|
2037
|
+
return fail(`line ${lineNumber}: malformed single-quoted value`);
|
|
2038
|
+
return inner.replaceAll("''", "'");
|
|
2039
|
+
}
|
|
2040
|
+
if (/^[[\]{}&*!|>%@`,#?:-]/u.test(value) || value.includes(": ") || value.includes(" #") || value.endsWith(":"))
|
|
2041
|
+
return fail(`line ${lineNumber}: quote the value ${JSON.stringify(value)}`);
|
|
2042
|
+
return value;
|
|
2043
|
+
}
|
|
2044
|
+
function commandPaths(listed, fail) {
|
|
2045
|
+
if (listed.length === 0)
|
|
2046
|
+
return fail("commands lists no command; leave it out or list one");
|
|
2047
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2048
|
+
return Object.freeze(listed.map((path) => {
|
|
2049
|
+
if (path === "all")
|
|
2050
|
+
return fail("commands: all must stand alone, not in a list");
|
|
2051
|
+
const names = path.split(" ");
|
|
2052
|
+
if (!names.every(isCommandNameSegment))
|
|
2053
|
+
return fail(`commands: ${JSON.stringify(path)} must be command names joined by single spaces`);
|
|
2054
|
+
if (seen.has(path))
|
|
2055
|
+
return fail(`commands lists ${path} twice`);
|
|
2056
|
+
seen.add(path);
|
|
2057
|
+
return Object.freeze(names);
|
|
2058
|
+
}));
|
|
2059
|
+
}
|
|
2060
|
+
function fileStem(path) {
|
|
2061
|
+
const name = path.split(/[\\/]/u).at(-1) ?? path;
|
|
2062
|
+
return name.endsWith(".md") ? name.slice(0, -3) : name;
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2065
|
+
// ../../../libs/clinkr/ts/dist/skills/read-skills.js
|
|
2066
|
+
async function readSkillFiles(directory) {
|
|
2067
|
+
if (typeof directory !== "string" || !isAbsolute2(directory))
|
|
2068
|
+
throw new Error(`skills must be an absolute directory path; received ${JSON.stringify(directory)}`);
|
|
2069
|
+
let entries;
|
|
2070
|
+
try {
|
|
2071
|
+
entries = await readdir2(directory, { withFileTypes: true });
|
|
2072
|
+
} catch (cause) {
|
|
2073
|
+
throw new Error(`Unable to read the skills directory ${directory}: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
|
|
2074
|
+
}
|
|
2075
|
+
const names = entries.filter((entry) => entry.isFile() && entry.name.endsWith(".md") && !entry.name.startsWith(".")).map((entry) => entry.name).toSorted((left, right) => left < right ? -1 : left > right ? 1 : 0);
|
|
2076
|
+
return Promise.all(names.map(async (name) => {
|
|
2077
|
+
const path = join3(directory, name);
|
|
2078
|
+
return parseSkillFile(path, await readFile(path, "utf8"));
|
|
2079
|
+
}));
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
// ../../../libs/clinkr/ts/dist/skills/skills-group.js
|
|
2083
|
+
import { z as z17 } from "zod";
|
|
2084
|
+
|
|
2085
|
+
// ../../../libs/clinkr/ts/dist/help-layout.js
|
|
2086
|
+
var DEFAULT_HELP_WIDTH = 100;
|
|
2087
|
+
var MINIMUM_TEXT_WIDTH = 20;
|
|
2088
|
+
function formatUsageBlock(prefix, tails) {
|
|
2089
|
+
return tails.map((tail, index) => `${index === 0 ? "Usage: " : USAGE_INDENT}${prefix}${tail === "" ? "" : ` ${tail}`}`).join("\n");
|
|
2090
|
+
}
|
|
2091
|
+
var USAGE_INDENT = " ".repeat("Usage: ".length);
|
|
2092
|
+
function wrapParagraph(text, width, indent2) {
|
|
2093
|
+
const padding = " ".repeat(indent2);
|
|
2094
|
+
return wrapLines(text, Math.max(width - indent2, MINIMUM_TEXT_WIDTH)).map((line, index) => index === 0 || line === "" ? line : `${padding}${line}`).join("\n");
|
|
2095
|
+
}
|
|
2096
|
+
function formatRows2(rows, width) {
|
|
2097
|
+
const labelWidth = Math.max(0, ...rows.map((row) => row.label.length));
|
|
2098
|
+
const lines = [];
|
|
2099
|
+
for (const row of rows) {
|
|
2100
|
+
if (row.text === "") {
|
|
2101
|
+
lines.push(` ${row.label}`);
|
|
2102
|
+
continue;
|
|
2103
|
+
}
|
|
2104
|
+
const text = wrapParagraph(row.text, width, labelWidth + 4);
|
|
2105
|
+
lines.push(...` ${row.label.padEnd(labelWidth)} ${text}`.split("\n"));
|
|
2106
|
+
}
|
|
2107
|
+
return lines;
|
|
2108
|
+
}
|
|
2109
|
+
function wrapLines(text, width) {
|
|
2110
|
+
const lines = [];
|
|
2111
|
+
for (const authored of text.split(/\r\n|\r|\n/u)) {
|
|
2112
|
+
if (authored.length <= width) {
|
|
2113
|
+
lines.push(authored);
|
|
2114
|
+
continue;
|
|
2115
|
+
}
|
|
2116
|
+
const parts = authored.split(/([^\S\u00a0\u2007\u202f]+)/u);
|
|
2117
|
+
let current = parts[0];
|
|
2118
|
+
for (let index = 1; index < parts.length; index += 2) {
|
|
2119
|
+
const separator = parts[index];
|
|
2120
|
+
const word = parts[index + 1];
|
|
2121
|
+
if (word === "")
|
|
2122
|
+
continue;
|
|
2123
|
+
if (current === "" || current.length + separator.length + word.length <= width) {
|
|
2124
|
+
current = `${current}${separator}${word}`;
|
|
2125
|
+
} else {
|
|
2126
|
+
lines.push(current);
|
|
2127
|
+
current = word;
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
lines.push(current);
|
|
2131
|
+
}
|
|
2132
|
+
return lines;
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
// ../../../libs/clinkr/ts/dist/project-argv.js
|
|
2136
|
+
function formatArgvUsageUnits(command, annotations = {}) {
|
|
2137
|
+
return deriveArgvHelp(command, annotations).units;
|
|
2138
|
+
}
|
|
2139
|
+
function deriveArgvHelp(command, annotations = {}) {
|
|
2140
|
+
const fields = deriveProjectionFields(command);
|
|
2141
|
+
for (const [key, annotation] of Object.entries(annotations)) {
|
|
2142
|
+
const field = fields.find((candidate) => candidate.key === key);
|
|
2143
|
+
if (field === void 0)
|
|
2144
|
+
throw new Error(`fields.${key}: Unknown request-schema field`);
|
|
2145
|
+
if (annotation.valueLabel !== void 0 && field.kind === "boolean")
|
|
2146
|
+
throw new Error(`fields.${key}.valueLabel: Boolean switches cannot have value labels`);
|
|
2147
|
+
}
|
|
2148
|
+
const positionals = fields.filter((field) => field.position !== void 0).toSorted((left, right) => left.position - right.position);
|
|
2149
|
+
const options = fields.filter((field) => field.position === void 0);
|
|
2150
|
+
const units = [];
|
|
2151
|
+
const argumentRows = [];
|
|
2152
|
+
const optionRows = [];
|
|
2153
|
+
for (const field of [...positionals, ...options]) {
|
|
2154
|
+
const annotation = Object.hasOwn(annotations, field.key) ? annotations[field.key] : void 0;
|
|
2155
|
+
const description = annotation?.description ?? "";
|
|
2156
|
+
if (field.position !== void 0) {
|
|
2157
|
+
const label2 = `${annotation?.valueLabel ?? field.flag.slice(2)}${field.kind === "string-array" ? "..." : ""}`;
|
|
2158
|
+
const syntax2 = field.positionalNonemptyRequired ? `<${label2}>` : `[${label2}]`;
|
|
2159
|
+
units.push(syntax2);
|
|
2160
|
+
argumentRows.push({ key: field.key, syntax: syntax2, description });
|
|
2161
|
+
continue;
|
|
2162
|
+
}
|
|
2163
|
+
const label = annotation?.valueLabel ?? (field.kind === "number" || field.kind === "integer" || field.kind === "json" ? field.kind : "value");
|
|
2164
|
+
const valueSyntax = field.kind === "boolean" ? field.booleanDefault === true ? "=false" : "" : ` <${label}>${field.kind === "string-array" ? "..." : ""}`;
|
|
2165
|
+
const syntax = `${field.flag}${valueSyntax}`;
|
|
2166
|
+
units.push(field.required ? syntax : `[${syntax}]`);
|
|
2167
|
+
optionRows.push({ key: field.key, syntax: `${optionSpellings(field).join(", ")}${valueSyntax}`, description });
|
|
2168
|
+
}
|
|
2169
|
+
return {
|
|
2170
|
+
units,
|
|
2171
|
+
arguments: argumentRows,
|
|
2172
|
+
options: optionRows,
|
|
2173
|
+
flags: options.flatMap(optionSpellings)
|
|
2174
|
+
};
|
|
2175
|
+
}
|
|
2176
|
+
function projectArgv(command, argv) {
|
|
2177
|
+
const fields = deriveProjectionFields(command);
|
|
2178
|
+
return scanArgv(fields, argv, false).result;
|
|
2179
|
+
}
|
|
2180
|
+
function scanArgvForCompletion(command, argv) {
|
|
2181
|
+
const fields = deriveProjectionFields(command);
|
|
2182
|
+
const scan = scanArgv(fields, argv, true);
|
|
2183
|
+
const options = fields.filter((field) => field.position === void 0 && (field.kind === "string-array" || scan.result[field.key] === void 0));
|
|
2184
|
+
const positional = scan.positionals[scan.positionalIndex];
|
|
2185
|
+
return {
|
|
2186
|
+
options,
|
|
2187
|
+
...positional === void 0 ? {} : { positional },
|
|
2188
|
+
...scan.pending === void 0 ? {} : { pending: scan.pending },
|
|
2189
|
+
afterDelimiter: scan.afterDelimiter
|
|
2190
|
+
};
|
|
2191
|
+
}
|
|
2192
|
+
function optionSpellings(field) {
|
|
2193
|
+
return [...field.short === void 0 ? [] : [field.short], field.flag, ...field.aliases];
|
|
2194
|
+
}
|
|
2195
|
+
function isOptionToken(token) {
|
|
2196
|
+
return token.startsWith("--") || /^-[A-Za-z]/.test(token);
|
|
2197
|
+
}
|
|
2198
|
+
function scanArgv(fields, argv, partial) {
|
|
2199
|
+
const positionals = fields.filter((field) => field.position !== void 0).toSorted((left, right) => left.position - right.position);
|
|
2200
|
+
const options = new Map(fields.filter((field) => field.position === void 0).flatMap((field) => optionSpellings(field).map((spelling) => [spelling, field])));
|
|
2201
|
+
const result = {};
|
|
2202
|
+
const variadic = positionals.find((field) => field.kind === "string-array");
|
|
2203
|
+
if (variadic !== void 0)
|
|
2204
|
+
result[variadic.key] = [];
|
|
2205
|
+
let positionalIndex = 0;
|
|
2206
|
+
let afterDelimiter = false;
|
|
2207
|
+
let pending;
|
|
2208
|
+
let index = 0;
|
|
2209
|
+
for (; index < argv.length; index += 1) {
|
|
2210
|
+
const token = argv[index];
|
|
2211
|
+
if (!afterDelimiter && token === "--") {
|
|
2212
|
+
afterDelimiter = true;
|
|
2213
|
+
continue;
|
|
2214
|
+
}
|
|
2215
|
+
if (afterDelimiter || !isOptionToken(token)) {
|
|
2216
|
+
const field = positionals[positionalIndex];
|
|
2217
|
+
if (field === void 0)
|
|
2218
|
+
throw new ArgvProjectionError(`Unexpected positional argument: ${token}`);
|
|
2219
|
+
if (partial && field.kind === "enum" && !field.values?.includes(token))
|
|
2220
|
+
throw new ArgvProjectionError(`Invalid value for ${field.flag}: ${token}`);
|
|
2221
|
+
if (field.kind === "string-array") {
|
|
2222
|
+
const existing = result[field.key];
|
|
2223
|
+
result[field.key] = [...existing, token];
|
|
2224
|
+
} else {
|
|
2225
|
+
result[field.key] = coerce(field, field.flag, token);
|
|
2226
|
+
positionalIndex += 1;
|
|
2227
|
+
}
|
|
2228
|
+
continue;
|
|
2229
|
+
}
|
|
2230
|
+
if (token.startsWith("--")) {
|
|
2231
|
+
const equalsIndex = token.indexOf("=");
|
|
2232
|
+
const rawFlag = equalsIndex === -1 ? token : token.slice(0, equalsIndex);
|
|
2233
|
+
const field = options.get(rawFlag);
|
|
2234
|
+
if (field === void 0)
|
|
2235
|
+
throw new ArgvProjectionError(`Unknown option: ${rawFlag}`);
|
|
2236
|
+
if (!assign(field, rawFlag, equalsIndex === -1 ? void 0 : token.slice(equalsIndex + 1)))
|
|
2237
|
+
break;
|
|
2238
|
+
continue;
|
|
2239
|
+
}
|
|
2240
|
+
let complete = true;
|
|
2241
|
+
for (let position = 1; position < token.length; position += 1) {
|
|
2242
|
+
const character = token[position];
|
|
2243
|
+
if (!/^[A-Za-z]$/.test(character))
|
|
2244
|
+
throw new ArgvProjectionError(`Invalid character ${JSON.stringify(character)} in short option cluster ${token}`);
|
|
2245
|
+
const spelling = `-${character}`;
|
|
2246
|
+
const field = options.get(spelling);
|
|
2247
|
+
if (field === void 0)
|
|
2248
|
+
throw new ArgvProjectionError(`Unknown option: ${spelling}`);
|
|
2249
|
+
if (field.kind === "boolean") {
|
|
2250
|
+
if (token[position + 1] === "=") {
|
|
2251
|
+
assign(field, spelling, token.slice(position + 2));
|
|
2252
|
+
break;
|
|
2253
|
+
}
|
|
2254
|
+
assign(field, spelling, void 0);
|
|
2255
|
+
continue;
|
|
2256
|
+
}
|
|
2257
|
+
const rest = token.slice(position + 1);
|
|
2258
|
+
complete = assign(field, spelling, rest === "" ? void 0 : rest.replace(/^=/u, ""));
|
|
2259
|
+
break;
|
|
2260
|
+
}
|
|
2261
|
+
if (!complete)
|
|
2262
|
+
break;
|
|
2263
|
+
}
|
|
2264
|
+
function assign(field, spelling, inlineValue) {
|
|
2265
|
+
if (field.kind === "boolean") {
|
|
2266
|
+
if (result[field.key] !== void 0)
|
|
2267
|
+
throw new ArgvProjectionError(`Duplicate option: ${spelling}`);
|
|
2268
|
+
result[field.key] = coerce(field, spelling, inlineValue ?? "true");
|
|
2269
|
+
return true;
|
|
2270
|
+
}
|
|
2271
|
+
if (field.kind !== "string-array" && result[field.key] !== void 0)
|
|
2272
|
+
throw new ArgvProjectionError(`Duplicate option: ${spelling}`);
|
|
2273
|
+
let value = inlineValue;
|
|
2274
|
+
if (value === void 0) {
|
|
2275
|
+
value = argv[index + 1];
|
|
2276
|
+
if (value === void 0 || isOptionToken(value)) {
|
|
2277
|
+
if (partial && value === void 0) {
|
|
2278
|
+
pending = field;
|
|
2279
|
+
return false;
|
|
2280
|
+
}
|
|
2281
|
+
throw new ArgvProjectionError(`Missing value for ${spelling}`);
|
|
2282
|
+
}
|
|
2283
|
+
index += 1;
|
|
2284
|
+
}
|
|
2285
|
+
if (partial && field.kind === "enum" && !field.values?.includes(value))
|
|
2286
|
+
throw new ArgvProjectionError(`Invalid value for ${spelling}: ${value}`);
|
|
2287
|
+
const coerced = coerce(field, spelling, value);
|
|
2288
|
+
if (field.kind === "string-array") {
|
|
2289
|
+
const existing = result[field.key];
|
|
2290
|
+
result[field.key] = [...existing ?? [], coerced];
|
|
2291
|
+
} else {
|
|
2292
|
+
result[field.key] = coerced;
|
|
2293
|
+
}
|
|
2294
|
+
return true;
|
|
2295
|
+
}
|
|
2296
|
+
for (const field of fields) {
|
|
2297
|
+
if (!partial && field.required && result[field.key] === void 0) {
|
|
2298
|
+
const argument = field.position === void 0 ? field.flag : `positional ${field.position} (${field.key})`;
|
|
2299
|
+
throw new ArgvProjectionError(`Missing required argument: ${argument}`);
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
2302
|
+
return { result, positionals, positionalIndex, pending, afterDelimiter };
|
|
2303
|
+
}
|
|
2304
|
+
function deriveProjectionFields(command) {
|
|
2305
|
+
const fields = describeRequestFields(command).map((field) => {
|
|
2306
|
+
return {
|
|
2307
|
+
key: field.key,
|
|
2308
|
+
flag: `--${toKebabCase(field.key)}`,
|
|
2309
|
+
kind: field.kind,
|
|
2310
|
+
required: field.required,
|
|
2311
|
+
positionalNonemptyRequired: field.nonemptyRequired,
|
|
2312
|
+
...field.booleanDefault === void 0 ? {} : { booleanDefault: field.booleanDefault },
|
|
2313
|
+
...field.values === void 0 ? {} : { values: field.values },
|
|
2314
|
+
...field.position === void 0 ? {} : { position: field.position },
|
|
2315
|
+
...field.short === void 0 ? {} : { short: `-${field.short}` },
|
|
2316
|
+
aliases: (field.aliases ?? []).map((alias) => `--${alias}`)
|
|
2317
|
+
};
|
|
2318
|
+
});
|
|
2319
|
+
const spellings = /* @__PURE__ */ new Set();
|
|
2320
|
+
for (const field of fields.filter((candidate) => candidate.position === void 0)) {
|
|
2321
|
+
for (const spelling of optionSpellings(field)) {
|
|
2322
|
+
if (spellings.has(spelling))
|
|
2323
|
+
throw new ArgvProjectionError(`Multiple fields map to the same CLI option: ${spelling}`);
|
|
2324
|
+
spellings.add(spelling);
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
const positionalFields = fields.filter((field) => field.position !== void 0).toSorted((left, right) => left.position - right.position);
|
|
2328
|
+
for (let index = 0; index < positionalFields.length; index += 1) {
|
|
2329
|
+
if (positionalFields[index].kind === "string-array" && index < positionalFields.length - 1)
|
|
2330
|
+
throw new ArgvProjectionError(`Variadic positional field ${positionalFields[index].key} must be the last positional argument`);
|
|
2331
|
+
if (!positionalFields[index].positionalNonemptyRequired && positionalFields.slice(index + 1).some((field) => field.positionalNonemptyRequired))
|
|
2332
|
+
throw new ArgvProjectionError("Optional or defaulted positional arguments cannot precede required positionals");
|
|
2333
|
+
}
|
|
2334
|
+
return fields;
|
|
2335
|
+
}
|
|
2336
|
+
function coerce(field, flag, value) {
|
|
2337
|
+
switch (field.kind) {
|
|
2338
|
+
case "string":
|
|
2339
|
+
case "enum":
|
|
2340
|
+
case "string-array":
|
|
2341
|
+
return value;
|
|
2342
|
+
case "number": {
|
|
2343
|
+
if (!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(value))
|
|
2344
|
+
throw new ArgvProjectionError(`${flag} must be a valid number`);
|
|
2345
|
+
const parsed = Number(value);
|
|
2346
|
+
if (!Number.isFinite(parsed))
|
|
2347
|
+
throw new ArgvProjectionError(`${flag} must be a valid number`);
|
|
2348
|
+
return parsed;
|
|
2349
|
+
}
|
|
2350
|
+
case "integer": {
|
|
2351
|
+
if (!/^[+-]?\d+$/.test(value))
|
|
2352
|
+
throw new ArgvProjectionError(`${flag} must be a valid integer`);
|
|
2353
|
+
const parsed = Number(value);
|
|
2354
|
+
if (!Number.isSafeInteger(parsed))
|
|
2355
|
+
throw new ArgvProjectionError(`${flag} must be a valid integer`);
|
|
2356
|
+
return parsed;
|
|
2357
|
+
}
|
|
2358
|
+
case "boolean":
|
|
2359
|
+
if (value === "true")
|
|
2360
|
+
return true;
|
|
2361
|
+
if (value === "false")
|
|
2362
|
+
return false;
|
|
2363
|
+
throw new ArgvProjectionError(`${flag} takes true or false, not ${JSON.stringify(value)}`);
|
|
2364
|
+
case "json":
|
|
2365
|
+
try {
|
|
2366
|
+
return JSON.parse(value);
|
|
2367
|
+
} catch {
|
|
2368
|
+
throw new ArgvProjectionError(`${flag} must be valid JSON`);
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
function toKebabCase(key) {
|
|
2373
|
+
return key.replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
2374
|
+
}
|
|
2375
|
+
|
|
2376
|
+
// ../../../libs/clinkr/ts/dist/leaf-help.js
|
|
2377
|
+
function formatLeafHelp(prefix, description, command, width) {
|
|
2378
|
+
const plan = derivePlan(prefix, command);
|
|
2379
|
+
const sections = [
|
|
2380
|
+
formatUsageBlock(prefix, leafUsageTails(command, plan.units)),
|
|
2381
|
+
wrapParagraph(description, width, 0)
|
|
2382
|
+
];
|
|
2383
|
+
if (plan.arguments.length > 0)
|
|
2384
|
+
sections.push(formatTable2("Arguments", plan.arguments, width));
|
|
2385
|
+
if (plan.options.length > 0)
|
|
2386
|
+
sections.push(formatTable2("Options", plan.options, width));
|
|
2387
|
+
sections.push(leafGlobalOptionsBlock(width).join("\n"));
|
|
2388
|
+
const examples = command.help?.examples;
|
|
2389
|
+
if (examples !== void 0 && examples.length > 0)
|
|
2390
|
+
sections.push(formatExamples(prefix, examples, width));
|
|
2391
|
+
return sections.join("\n\n");
|
|
2392
|
+
}
|
|
2393
|
+
function formatLeafUsage(prefix, command) {
|
|
2394
|
+
return formatUsageBlock(prefix, formatLeafUsageTails(prefix, command));
|
|
2395
|
+
}
|
|
2396
|
+
function formatLeafUsageTails(prefix, command) {
|
|
2397
|
+
return leafUsageTails(command, derivePlan(prefix, command).units);
|
|
2398
|
+
}
|
|
2399
|
+
function derivePlan(prefix, command) {
|
|
2400
|
+
try {
|
|
2401
|
+
return deriveArgvHelp(command, command.help?.fields);
|
|
2402
|
+
} catch (cause) {
|
|
2403
|
+
throw new Error(`Invalid help for ${prefix}: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
function leafUsageTails(command, units) {
|
|
2407
|
+
const usages = command.help?.usages;
|
|
2408
|
+
return usages !== void 0 && usages.length > 0 ? usages : [units.join(" ")];
|
|
2409
|
+
}
|
|
2410
|
+
function formatExamples(prefix, examples, width) {
|
|
2411
|
+
const described = examples.some((example) => example.description !== void 0);
|
|
2412
|
+
const blocks = examples.map((example) => {
|
|
2413
|
+
const command = ` ${prefix}${example.argv === "" ? "" : ` ${example.argv}`}`;
|
|
2414
|
+
if (example.description === void 0)
|
|
2415
|
+
return command;
|
|
2416
|
+
const comment = wrapParagraph(example.description, width, 4).split("\n").map((line, index) => ` # ${index === 0 ? line : line.slice(4)}`).join("\n");
|
|
2417
|
+
return `${comment}
|
|
2418
|
+
${command}`;
|
|
2419
|
+
});
|
|
2420
|
+
return `Examples:
|
|
2421
|
+
${blocks.join(described ? "\n\n" : "\n")}`;
|
|
2422
|
+
}
|
|
2423
|
+
var LEAF_GLOBAL_OPTIONS = [
|
|
2424
|
+
{ syntax: "-h, --help", description: "Show command help." },
|
|
2425
|
+
{ syntax: "--help --outcomes", description: "List every way the command can end." },
|
|
2426
|
+
{ syntax: "--json", description: "Print the response as JSON." },
|
|
2427
|
+
{ syntax: "--input-json", description: "Read the request as one JSON object from stdin." },
|
|
2428
|
+
{ syntax: "--no-color", description: "Print without color." },
|
|
2429
|
+
{ syntax: "--json-schema", description: "Print the request and response JSON Schemas." }
|
|
2430
|
+
];
|
|
2431
|
+
function leafGlobalOptionsBlock(width) {
|
|
2432
|
+
return tableLines("Global options", LEAF_GLOBAL_OPTIONS, width);
|
|
2433
|
+
}
|
|
2434
|
+
function formatTable2(title, rows, width) {
|
|
2435
|
+
return tableLines(title, rows, width).join("\n");
|
|
2436
|
+
}
|
|
2437
|
+
function tableLines(title, rows, width) {
|
|
2438
|
+
const layout = rows.map((row) => ({ label: row.syntax, text: row.description }));
|
|
2439
|
+
return [`${title}:`, ...formatRows2(layout, width)];
|
|
2440
|
+
}
|
|
2441
|
+
|
|
2442
|
+
// ../../../libs/clinkr/ts/dist/list-commands.js
|
|
2443
|
+
import { z as z16 } from "zod";
|
|
2444
|
+
var commandListingDocumentSchema = z16.object({
|
|
2445
|
+
application: z16.object({ name: z16.string(), description: z16.string().optional() }),
|
|
2446
|
+
path: z16.array(z16.string()),
|
|
2447
|
+
commands: z16.array(z16.object({
|
|
2448
|
+
kind: z16.enum(["group", "command"]),
|
|
2449
|
+
name: z16.string(),
|
|
2450
|
+
path: z16.array(z16.string()),
|
|
2451
|
+
description: z16.string(),
|
|
2452
|
+
aliases: z16.array(z16.string()).optional(),
|
|
2453
|
+
default: z16.literal(true).optional(),
|
|
2454
|
+
summary: z16.string().optional(),
|
|
2455
|
+
section: z16.string().optional()
|
|
2456
|
+
}))
|
|
2457
|
+
});
|
|
2458
|
+
async function listCommands(application, path = []) {
|
|
2459
|
+
const commands = [];
|
|
2460
|
+
const visit = async (groupPath, nodes) => {
|
|
2461
|
+
const defaultCommand = defaultCommandOf(nodes);
|
|
2462
|
+
for (const node of nodes.filter(isListed)) {
|
|
2463
|
+
const nodePath = [...groupPath, node.name];
|
|
2464
|
+
const { description: description2, summary, helpSection } = node.metadata;
|
|
2465
|
+
const aliases = commandAliases(node);
|
|
2466
|
+
commands.push({
|
|
2467
|
+
kind: node.kind,
|
|
2468
|
+
name: node.name,
|
|
2469
|
+
path: nodePath,
|
|
2470
|
+
description: description2,
|
|
2471
|
+
...aliases.length === 0 ? {} : { aliases: [...aliases] },
|
|
2472
|
+
...node === defaultCommand ? { default: true } : {},
|
|
2473
|
+
...summary === void 0 ? {} : { summary },
|
|
2474
|
+
...helpSection === void 0 ? {} : { section: helpSection }
|
|
2475
|
+
});
|
|
2476
|
+
if (node.kind === "group")
|
|
2477
|
+
await visit(nodePath, await groupChildren(application, nodePath));
|
|
2478
|
+
}
|
|
2479
|
+
};
|
|
2480
|
+
const root = path.length === 0 ? application.commands : await groupChildren(application, [...path]);
|
|
2481
|
+
await visit([...path], root);
|
|
2482
|
+
const { name, description } = application;
|
|
2483
|
+
return {
|
|
2484
|
+
application: { name, ...description === void 0 ? {} : { description } },
|
|
2485
|
+
path: [...path],
|
|
2486
|
+
commands
|
|
2487
|
+
};
|
|
2488
|
+
}
|
|
2489
|
+
async function groupChildren(application, path) {
|
|
2490
|
+
const selection = await application.select(path);
|
|
2491
|
+
if (selection.kind !== "group")
|
|
2492
|
+
throw new Error(`Command path ${JSON.stringify(path.join(" "))} does not select a group`);
|
|
2493
|
+
return selection.available;
|
|
2494
|
+
}
|
|
2495
|
+
|
|
2496
|
+
// ../../../libs/clinkr/ts/dist/skills/command-index.js
|
|
2497
|
+
async function listedCommands(application) {
|
|
2498
|
+
const { commands } = await listCommands(application);
|
|
2499
|
+
const sections = new Map(commands.filter((entry) => entry.path.length === 1).map((entry) => [entry.name, entry.section]));
|
|
2500
|
+
return commands.filter((entry) => entry.kind === "command").map(({ path }) => {
|
|
2501
|
+
const section2 = sections.get(path[0] ?? "");
|
|
2502
|
+
return section2 === void 0 ? { path } : { path, section: section2 };
|
|
2503
|
+
});
|
|
2504
|
+
}
|
|
2505
|
+
async function listedCommandPaths(application) {
|
|
2506
|
+
return (await listedCommands(application)).map(({ path }) => path);
|
|
2507
|
+
}
|
|
2508
|
+
async function commandIndex(application, commands, options) {
|
|
2509
|
+
const listed = commands === "all" ? await listedCommands(application) : commands.map((path) => ({ path }));
|
|
2510
|
+
const loaded = await Promise.all(listed.map(async ({ path, section: section3 }) => {
|
|
2511
|
+
const selection = await selectCommand(application, path);
|
|
2512
|
+
return { selection, command: await selection.load(), section: section3 };
|
|
2513
|
+
}));
|
|
2514
|
+
const heading = (level, text) => `${"#".repeat(level)} ${text}`;
|
|
2515
|
+
const section2 = options.level + 1;
|
|
2516
|
+
const blocks = [heading(options.level, options.title)];
|
|
2517
|
+
if (options.level === 1 && application.description !== void 0)
|
|
2518
|
+
blocks.push(application.description);
|
|
2519
|
+
blocks.push(heading(section2, "Global options"), globalOptions(application).join("\n"));
|
|
2520
|
+
blocks.push(heading(section2, "Output"), bullets(outputNotes(loaded.map(({ command }) => command))));
|
|
2521
|
+
blocks.push(heading(section2, "Commands"));
|
|
2522
|
+
const unsectioned = loaded.filter((entry) => entry.section === void 0);
|
|
2523
|
+
if (unsectioned.length > 0)
|
|
2524
|
+
blocks.push(indexLines(application.name, unsectioned));
|
|
2525
|
+
for (const name of application.helpSections ?? []) {
|
|
2526
|
+
const entries = loaded.filter((entry) => entry.section === name);
|
|
2527
|
+
if (entries.length > 0)
|
|
2528
|
+
blocks.push(`${name}:`, indexLines(application.name, entries));
|
|
2529
|
+
}
|
|
2530
|
+
blocks.push(helpPointer(application.name));
|
|
2531
|
+
return blocks.join("\n\n");
|
|
2532
|
+
}
|
|
2533
|
+
async function selectCommand(application, path) {
|
|
2534
|
+
const selection = await application.select(path);
|
|
2535
|
+
if (selection.kind !== "command" || selection.path.join(" ") !== path.join(" ") || selection.argv.length > 0)
|
|
2536
|
+
throw new Error(`Command path ${JSON.stringify(path.join(" "))} does not select a command`);
|
|
2537
|
+
return selection;
|
|
2538
|
+
}
|
|
2539
|
+
function globalOptions(application) {
|
|
2540
|
+
return globalOptionBulletLines(application.version !== void 0);
|
|
2541
|
+
}
|
|
2542
|
+
function globalOptionBulletLines(hasVersion) {
|
|
2543
|
+
const rows = LEAF_GLOBAL_OPTIONS.map(({ syntax, description }) => `${code(syntax)}: ${description}`);
|
|
2544
|
+
if (hasVersion)
|
|
2545
|
+
rows.push(`${code("--version")}: Print the version. Use it alone.`);
|
|
2546
|
+
return rows.map((row) => `- ${row}`);
|
|
2547
|
+
}
|
|
2548
|
+
function outputNotes(commands) {
|
|
2549
|
+
const notes = [
|
|
2550
|
+
"With `--json`, a command writes one JSON document. A result goes to stdout. An error goes to stderr.",
|
|
2551
|
+
"A result document has the fields of its type and `outcome`, the result name. It can also have `warnings` and `next`.",
|
|
2552
|
+
"An error document has `status`, `reason`, and `message`. It can also have `next` and `data`.",
|
|
2553
|
+
"Every command can also end with `invalid_arguments` (exit 2), `internal_error` (exit 2), or `canceled` (exit 130)."
|
|
2554
|
+
];
|
|
2555
|
+
if (commands.some(confirms))
|
|
2556
|
+
notes.push("A command marked `(confirms)` asks a person before it does work that they can't undo. When no person can answer, it ends with `confirmation_required` (exit 2, action required). Add `--yes` only after a person approves.");
|
|
2557
|
+
return notes;
|
|
2558
|
+
}
|
|
2559
|
+
function indexLines(applicationName, entries) {
|
|
2560
|
+
return entries.map(({ selection, command }) => {
|
|
2561
|
+
const { metadata } = selection.command;
|
|
2562
|
+
const prefix = [applicationName, ...selection.path].join(" ");
|
|
2563
|
+
const { units } = deriveArgvHelp(command, command.help?.fields);
|
|
2564
|
+
const usages = leafUsageTails(command, units).map((tail) => code(tail === "" ? prefix : `${prefix} ${tail}`));
|
|
2565
|
+
const aliases = commandAliases(selection.command);
|
|
2566
|
+
const marks = [];
|
|
2567
|
+
if (aliases.length > 0)
|
|
2568
|
+
marks.push(`(${aliases.length === 1 ? "alias" : "aliases"} ${aliases.map(code).join(", ")})`);
|
|
2569
|
+
if (isDefaultCommand(selection.command))
|
|
2570
|
+
marks.push("(default)");
|
|
2571
|
+
if (confirms(command))
|
|
2572
|
+
marks.push("(confirms)");
|
|
2573
|
+
return `- ${[usages.join(" or "), ...marks].join(" ")}: ${metadata.summary ?? metadata.description}`;
|
|
2574
|
+
}).join("\n");
|
|
2575
|
+
}
|
|
2576
|
+
function helpPointer(applicationName) {
|
|
2577
|
+
return [
|
|
2578
|
+
`Before you run a command, run ${code(`${applicationName} <command> --help`)}.`,
|
|
2579
|
+
`To see every way a command can end, run ${code(`${applicationName} <command> --help --outcomes`)}.`,
|
|
2580
|
+
`To get the request and response types of a command, run ${code(`${applicationName} <command> --json-schema`)}.`
|
|
2581
|
+
].join(" ");
|
|
2582
|
+
}
|
|
2583
|
+
function confirms(command) {
|
|
2584
|
+
return command.confirms === true;
|
|
2585
|
+
}
|
|
2586
|
+
function bullets(lines) {
|
|
2587
|
+
return lines.map((line) => `- ${line}`).join("\n");
|
|
2588
|
+
}
|
|
2589
|
+
function code(text) {
|
|
2590
|
+
const longest = Math.max(0, ...(text.match(/`+/gu) ?? []).map((run2) => run2.length));
|
|
2591
|
+
const fence = "`".repeat(longest + 1);
|
|
2592
|
+
return longest === 0 ? `${fence}${text}${fence}` : `${fence} ${text} ${fence}`;
|
|
2593
|
+
}
|
|
2594
|
+
|
|
2595
|
+
// ../../../libs/clinkr/ts/dist/skills/skills-group.js
|
|
2596
|
+
var SKILLS_GROUP_NAME = "skills";
|
|
2597
|
+
var skillSummarySchema = z17.object({
|
|
2598
|
+
name: z17.string(),
|
|
2599
|
+
description: z17.string(),
|
|
2600
|
+
commands: z17.array(z17.string())
|
|
2601
|
+
});
|
|
2602
|
+
async function checkSkillCommands(skills, kindAt) {
|
|
2603
|
+
for (const skill of skills) {
|
|
2604
|
+
if (skill.commands === "all")
|
|
2605
|
+
continue;
|
|
2606
|
+
for (const path of skill.commands) {
|
|
2607
|
+
const kind = await kindAt(path);
|
|
2608
|
+
const named = path.join(" ");
|
|
2609
|
+
if (kind === "group")
|
|
2610
|
+
throw new Error(`Invalid skill file ${skill.path}: commands lists ${named}, a group; list its commands instead`);
|
|
2611
|
+
if (kind === void 0)
|
|
2612
|
+
throw new Error(`Invalid skill file ${skill.path}: commands lists ${named}, which names no command`);
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
async function withSkills(application, skills, kindAt) {
|
|
2617
|
+
await checkSkillCommands(skills, kindAt);
|
|
2618
|
+
const ordered = [...skills].toSorted((left, right) => Number(right.name === OVERVIEW_SKILL_NAME) - Number(left.name === OVERVIEW_SKILL_NAME) || compareCodeUnits2(left.name, right.name));
|
|
2619
|
+
const leaves = skillsCommands(application, ordered);
|
|
2620
|
+
const group = Object.freeze({
|
|
2621
|
+
kind: "group",
|
|
2622
|
+
name: SKILLS_GROUP_NAME,
|
|
2623
|
+
metadata: Object.freeze({ description: `Print guides for agents that use ${application.name}.` })
|
|
2624
|
+
});
|
|
2625
|
+
const children2 = Object.freeze(leaves.map(({ node }) => node));
|
|
2626
|
+
const commands = Object.freeze(insertInOrder(application.commands, group));
|
|
2627
|
+
const select = async (argv) => {
|
|
2628
|
+
if (argv[0] !== SKILLS_GROUP_NAME) {
|
|
2629
|
+
const selection = await application.select(argv);
|
|
2630
|
+
if (selection.kind === "group" && selection.path.length === 0)
|
|
2631
|
+
return { ...selection, available: commands };
|
|
2632
|
+
if (selection.kind === "not-found" && selection.path.length === 1)
|
|
2633
|
+
return { ...selection, available: commands };
|
|
2634
|
+
return selection;
|
|
2635
|
+
}
|
|
2636
|
+
const [word, ...rest] = argv.slice(1);
|
|
2637
|
+
if (word === void 0 || word === "-h" || word === "--help")
|
|
2638
|
+
return { kind: "group", path: Object.freeze([SKILLS_GROUP_NAME]), group, available: children2 };
|
|
2639
|
+
const leaf = leaves.find(({ node }) => node.name === word);
|
|
2640
|
+
if (leaf === void 0)
|
|
2641
|
+
return { kind: "not-found", path: Object.freeze([SKILLS_GROUP_NAME, word]), available: children2 };
|
|
2642
|
+
return {
|
|
2643
|
+
kind: "command",
|
|
2644
|
+
path: Object.freeze([SKILLS_GROUP_NAME, leaf.node.name]),
|
|
2645
|
+
command: leaf.node,
|
|
2646
|
+
argv: Object.freeze([...rest]),
|
|
2647
|
+
load: async () => leaf.command
|
|
2648
|
+
};
|
|
2649
|
+
};
|
|
2650
|
+
return Object.freeze({ ...application, commands, select });
|
|
2651
|
+
}
|
|
2652
|
+
function skillsCommands(application, skills) {
|
|
2653
|
+
const cmd = commandTree({ id: "clinkr" });
|
|
2654
|
+
const appName = application.name;
|
|
2655
|
+
const commandsDescription = `Index of every \`${appName}\` command.`;
|
|
2656
|
+
const names = [...skills.map(({ name }) => name), COMMANDS_SKILL_NAME];
|
|
2657
|
+
const defaultName = skills.some(({ name }) => name === OVERVIEW_SKILL_NAME) ? OVERVIEW_SKILL_NAME : COMMANDS_SKILL_NAME;
|
|
2658
|
+
const seeSkills = { type: "command", argv: [appName, SKILLS_GROUP_NAME, "list"], label: "See the skills" };
|
|
2659
|
+
const listOutcomes = defineOutcomes({
|
|
2660
|
+
results: {
|
|
2661
|
+
listed: {
|
|
2662
|
+
schema: z17.object({ skills: z17.array(skillSummarySchema) }),
|
|
2663
|
+
description: "Lists every skill: the overview first, the commands skill last.",
|
|
2664
|
+
render: ({ skills: listed }) => renderOutcome({
|
|
2665
|
+
table: {
|
|
2666
|
+
columns: ["Name", "Description"],
|
|
2667
|
+
rows: listed.map(({ name, description }) => [name, description])
|
|
2668
|
+
}
|
|
2669
|
+
})
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
});
|
|
2673
|
+
const getOutcomes = defineOutcomes({
|
|
2674
|
+
results: {
|
|
2675
|
+
shown: {
|
|
2676
|
+
schema: z17.object({ name: z17.string(), description: z17.string(), markdown: z17.string() }),
|
|
2677
|
+
description: "Prints the skill as Markdown.",
|
|
2678
|
+
render: ({ markdown }) => renderOutcome({ text: markdown })
|
|
2679
|
+
}
|
|
2680
|
+
},
|
|
2681
|
+
errors: {
|
|
2682
|
+
skillNotFound: {
|
|
2683
|
+
exitCode: 1,
|
|
2684
|
+
description: "No skill has that name.",
|
|
2685
|
+
schema: z17.object({ name: z17.string(), skills: z17.array(z17.string()) }),
|
|
2686
|
+
render: ({ name, skills: known }) => ({
|
|
2687
|
+
message: `Couldn't find skill ${isSkillName(name) ? name : JSON.stringify(name)}. The skills are: ${known.join(", ")}.`,
|
|
2688
|
+
next: [seeSkills]
|
|
2689
|
+
})
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2692
|
+
});
|
|
2693
|
+
const list = cmd.define({
|
|
2694
|
+
requestSchema: z17.object({}).strict(),
|
|
2695
|
+
response: listOutcomes,
|
|
2696
|
+
handler: async () => {
|
|
2697
|
+
let listed;
|
|
2698
|
+
const allPaths = async () => (listed ??= await listedCommandPaths(application)).map((path) => path.join(" "));
|
|
2699
|
+
const summaries = [];
|
|
2700
|
+
for (const skill of skills) {
|
|
2701
|
+
const commands = skill.commands === "all" ? await allPaths() : skill.commands.map((path) => path.join(" "));
|
|
2702
|
+
summaries.push({ name: skill.name, description: skill.description, commands });
|
|
2703
|
+
}
|
|
2704
|
+
summaries.push({ name: COMMANDS_SKILL_NAME, description: commandsDescription, commands: await allPaths() });
|
|
2705
|
+
return listOutcomes.listed({ skills: summaries });
|
|
2706
|
+
}
|
|
2707
|
+
});
|
|
2708
|
+
const get = cmd.define({
|
|
2709
|
+
requestSchema: z17.object({ name: z17.string().min(1).optional() }),
|
|
2710
|
+
cli: { positionals: ["name"] },
|
|
2711
|
+
help: {
|
|
2712
|
+
fields: {
|
|
2713
|
+
name: {
|
|
2714
|
+
valueLabel: "name",
|
|
2715
|
+
description: "Skill to print, as skills list shows it. Defaults to overview, or to commands."
|
|
2716
|
+
}
|
|
2717
|
+
},
|
|
2718
|
+
examples: [
|
|
2719
|
+
{ argv: "", description: "Print the skill to start with." },
|
|
2720
|
+
{ argv: COMMANDS_SKILL_NAME, description: "Print the index of every command." }
|
|
2721
|
+
]
|
|
2722
|
+
},
|
|
2723
|
+
response: getOutcomes,
|
|
2724
|
+
handler: async (_context, request) => {
|
|
2725
|
+
const name = request.name ?? defaultName;
|
|
2726
|
+
if (name === COMMANDS_SKILL_NAME) {
|
|
2727
|
+
const markdown2 = await commandIndex(application, "all", { title: `\`${appName}\` commands`, level: 1 });
|
|
2728
|
+
return getOutcomes.shown({ name, description: commandsDescription, markdown: markdown2 });
|
|
2729
|
+
}
|
|
2730
|
+
const skill = skills.find((candidate) => candidate.name === name);
|
|
2731
|
+
if (skill === void 0)
|
|
2732
|
+
return getOutcomes.skillNotFound({ name, skills: names });
|
|
2733
|
+
const covers = skill.commands === "all" || skill.commands.length > 0;
|
|
2734
|
+
const index = covers ? await commandIndex(application, skill.commands, { title: "Command index", level: 2 }) : "";
|
|
2735
|
+
const markdown = [skill.body, index].filter((part) => part !== "").join("\n\n");
|
|
2736
|
+
return getOutcomes.shown({ name, description: skill.description, markdown });
|
|
2737
|
+
},
|
|
2738
|
+
completionProvider: async ({ field, prefix }) => field === "name" ? names.filter((candidate) => candidate.startsWith(prefix)) : []
|
|
2739
|
+
});
|
|
2740
|
+
return [
|
|
2741
|
+
{
|
|
2742
|
+
node: Object.freeze({
|
|
2743
|
+
kind: "command",
|
|
2744
|
+
name: "get",
|
|
2745
|
+
metadata: Object.freeze({
|
|
2746
|
+
description: "Print a skill as Markdown: its guide, then an index of the commands it covers. Without a name, print the overview skill, or the commands skill when there is no overview.",
|
|
2747
|
+
summary: "Print a skill as Markdown."
|
|
2748
|
+
})
|
|
2749
|
+
}),
|
|
2750
|
+
command: get
|
|
2751
|
+
},
|
|
2752
|
+
{
|
|
2753
|
+
node: Object.freeze({
|
|
2754
|
+
kind: "command",
|
|
2755
|
+
name: "list",
|
|
2756
|
+
metadata: Object.freeze({ description: "List the skills: the overview first, the commands skill last." })
|
|
2757
|
+
}),
|
|
2758
|
+
command: list
|
|
2759
|
+
}
|
|
2760
|
+
];
|
|
2761
|
+
}
|
|
2762
|
+
function insertInOrder(nodes, node) {
|
|
2763
|
+
const index = nodes.findIndex((candidate) => compareCodeUnits2(candidate.name, node.name) > 0);
|
|
2764
|
+
return index === -1 ? [...nodes, node] : [...nodes.slice(0, index), node, ...nodes.slice(index)];
|
|
2765
|
+
}
|
|
2766
|
+
function compareCodeUnits2(left, right) {
|
|
2767
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
2768
|
+
}
|
|
2769
|
+
|
|
2770
|
+
// ../../../libs/clinkr/ts/dist/create-application.js
|
|
2771
|
+
async function createApplication(name, options) {
|
|
2772
|
+
const description = options.description;
|
|
2773
|
+
if (description !== void 0 && (typeof description !== "string" || description.trim() === ""))
|
|
2774
|
+
throw new Error("Application description must be a nonempty string");
|
|
2775
|
+
const version = options.version;
|
|
2776
|
+
if (version !== void 0 && typeof version !== "function" && (typeof version !== "string" || !isSingleLineText(version)))
|
|
2777
|
+
throw new Error("Application version must be a nonempty single-line string without control characters, or a function that returns one");
|
|
2778
|
+
const helpSections = validateHelpSections(options.helpSections ?? []);
|
|
2779
|
+
const ui = options.ui;
|
|
2780
|
+
if (ui !== void 0 && typeof ui !== "function")
|
|
2781
|
+
throw new Error("Application ui must be a function");
|
|
2782
|
+
const helpLogo = options.helpLogo;
|
|
2783
|
+
if (helpLogo !== void 0 && typeof helpLogo !== "function")
|
|
2784
|
+
throw new Error("Application helpLogo must be a function");
|
|
2785
|
+
const declaredSections = new Set(helpSections);
|
|
2786
|
+
const group = options.commands;
|
|
2787
|
+
if (!isTreeGroup(group))
|
|
2788
|
+
throw new Error("createApplication requires commands, a group from a command tree's directory or group");
|
|
2789
|
+
checkNoGroupNavigation(group, "createApplication's commands take no navigation parts; root help takes description");
|
|
2790
|
+
const builtIn = sourceOf(group);
|
|
2791
|
+
const commands = await discoverBuiltIn(group, declaredSections);
|
|
2792
|
+
checkReservedBuiltInNames(commands);
|
|
2793
|
+
const mounts = (options.mounts ?? []).map((mount2) => {
|
|
2794
|
+
if (!isTreeGroup(mount2?.group))
|
|
2795
|
+
throw new Error("A mount requires a group; make it with mount(group, \u2026)");
|
|
2796
|
+
const source = sourceOf(mount2.group);
|
|
2797
|
+
if (!isArray(mount2.path))
|
|
2798
|
+
throw new Error(`Mount from ${source.id} requires a nonempty path`);
|
|
2799
|
+
checkNoGroupNavigation(mount2.group, `Mount from ${source.id}: a mounted group takes its navigation parts from mount`);
|
|
2800
|
+
const app = mount2.app;
|
|
2801
|
+
if (app !== void 0 && typeof app !== "function")
|
|
2802
|
+
throw new Error(`Mount from ${source.id} requires app to be a function`);
|
|
2803
|
+
return {
|
|
2804
|
+
group: mount2.group,
|
|
2805
|
+
source,
|
|
2806
|
+
path: [...mount2.path],
|
|
2807
|
+
description: mount2.description,
|
|
2808
|
+
...mount2.summary === void 0 ? {} : { summary: mount2.summary },
|
|
2809
|
+
...mount2.helpSection === void 0 ? {} : { helpSection: mount2.helpSection },
|
|
2810
|
+
...mount2.hidden === void 0 ? {} : { hidden: mount2.hidden },
|
|
2811
|
+
// `mounts` types each projection's parameter as `TAppContext`, the app `runCli` gives every leaf.
|
|
2812
|
+
binding: app === void 0 ? PLAIN : { kind: "projected", app }
|
|
2813
|
+
};
|
|
2814
|
+
});
|
|
2815
|
+
checkReservedMountNames(mounts);
|
|
2816
|
+
checkProjectedTreeIds(mounts);
|
|
2817
|
+
const root = await mountAll(commands, mounts, builtIn, declaredSections);
|
|
2818
|
+
await checkGroupsFilled(root, builtIn);
|
|
2819
|
+
const skills = options.skills === void 0 ? [] : await readSkillFiles(options.skills);
|
|
2820
|
+
const application = Object.freeze({
|
|
2821
|
+
name,
|
|
2822
|
+
...description === void 0 ? {} : { description },
|
|
2823
|
+
...version === void 0 ? {} : { version },
|
|
2824
|
+
commands: describe2(root),
|
|
2825
|
+
helpSections,
|
|
2826
|
+
...ui === void 0 ? {} : { ui },
|
|
2827
|
+
...helpLogo === void 0 ? {} : { helpLogo },
|
|
2828
|
+
select: (argv) => selectCommandPath(root, argv)
|
|
2829
|
+
});
|
|
2830
|
+
return withSkills(application, skills, (path) => builtInKindAt(commands, path));
|
|
2831
|
+
}
|
|
2832
|
+
var RESERVED_ROOT_NAMES = {
|
|
2833
|
+
sys: "Clinkr completion",
|
|
2834
|
+
[SKILLS_GROUP_NAME]: "Clinkr skills"
|
|
2835
|
+
};
|
|
2836
|
+
function checkReservedBuiltInNames(commands) {
|
|
2837
|
+
const named = commands.find(({ description }) => Object.hasOwn(RESERVED_ROOT_NAMES, description.name));
|
|
2838
|
+
if (named !== void 0)
|
|
2839
|
+
throw reservedRootName(named.description.name, "");
|
|
2840
|
+
for (const { description } of commands) {
|
|
2841
|
+
const alias = commandAliases(description).find((candidate) => Object.hasOwn(RESERVED_ROOT_NAMES, candidate));
|
|
2842
|
+
if (alias !== void 0)
|
|
2843
|
+
throw reservedRootName(alias, ` (alias of ${description.name})`);
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
function checkNoGroupNavigation(group, message) {
|
|
2847
|
+
if (group.kind !== "inline-group")
|
|
2848
|
+
return;
|
|
2849
|
+
const own = Object.keys(group.navigation);
|
|
2850
|
+
if (own.length > 0)
|
|
2851
|
+
throw new Error(`${message}, not ${own.join(", ")}`);
|
|
2852
|
+
}
|
|
2853
|
+
function checkReservedMountNames(mounts) {
|
|
2854
|
+
const reserved = mounts.find(({ path }) => path[0] !== void 0 && Object.hasOwn(RESERVED_ROOT_NAMES, path[0]));
|
|
2855
|
+
if (reserved?.path[0] !== void 0)
|
|
2856
|
+
throw reservedRootName(reserved.path[0], " (mount)");
|
|
2857
|
+
}
|
|
2858
|
+
function reservedRootName(name, suffix) {
|
|
2859
|
+
return new Error(`Root command namespace ${name} is reserved for ${RESERVED_ROOT_NAMES[name]}${suffix}`);
|
|
2860
|
+
}
|
|
2861
|
+
async function builtInKindAt(nodes, path) {
|
|
2862
|
+
let level = nodes;
|
|
2863
|
+
for (const [index, name] of path.entries()) {
|
|
2864
|
+
const node = level.find((candidate) => candidate.description.name === name);
|
|
2865
|
+
if (node === void 0)
|
|
2866
|
+
return void 0;
|
|
2867
|
+
if (!isGroup(node))
|
|
2868
|
+
return index === path.length - 1 ? "command" : void 0;
|
|
2869
|
+
if (index === path.length - 1)
|
|
2870
|
+
return "group";
|
|
2871
|
+
level = await node.children();
|
|
2872
|
+
}
|
|
2873
|
+
return void 0;
|
|
2874
|
+
}
|
|
2875
|
+
function isArray(value) {
|
|
2876
|
+
return Array.isArray(value);
|
|
2877
|
+
}
|
|
2878
|
+
function validateHelpSections(sections) {
|
|
2879
|
+
if (!isArray(sections))
|
|
2880
|
+
throw new Error("helpSections must be an array of section names");
|
|
2881
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2882
|
+
for (const section2 of sections) {
|
|
2883
|
+
if (typeof section2 !== "string" || !isSingleLineText(section2))
|
|
2884
|
+
throw new Error(`Invalid help section ${JSON.stringify(section2)}: names must be nonempty single-line strings without control characters`);
|
|
2885
|
+
if (section2.trim() === "Commands")
|
|
2886
|
+
throw new Error("Help section Commands is reserved for rows without a helpSection");
|
|
2887
|
+
if (seen.has(section2))
|
|
2888
|
+
throw new Error(`Duplicate help section ${JSON.stringify(section2)}`);
|
|
2889
|
+
seen.add(section2);
|
|
2890
|
+
}
|
|
2891
|
+
return Object.freeze([...sections]);
|
|
2892
|
+
}
|
|
2893
|
+
function describe2(nodes) {
|
|
2894
|
+
return Object.freeze(nodes.map((node) => node.description));
|
|
2895
|
+
}
|
|
2896
|
+
async function discoverBuiltIn(group, declaredSections) {
|
|
2897
|
+
if (group.kind === "directory") {
|
|
2898
|
+
try {
|
|
2899
|
+
await stat2(group.directory);
|
|
2900
|
+
} catch (error) {
|
|
2901
|
+
if (isMissing(error))
|
|
2902
|
+
return Object.freeze([]);
|
|
2903
|
+
}
|
|
2904
|
+
}
|
|
2905
|
+
return discoverGroup(group, { source: sourceOf(group), declaredSections, binding: PLAIN, mountPoints: true });
|
|
2906
|
+
}
|
|
2907
|
+
async function selectCommandPath(root, argv) {
|
|
2908
|
+
let nodes = root;
|
|
2909
|
+
let group;
|
|
2910
|
+
const path = [];
|
|
2911
|
+
for (const [index, segment] of argv.entries()) {
|
|
2912
|
+
if (segment === "-h" || segment === "--help")
|
|
2913
|
+
return { kind: "group", path: Object.freeze(path), group, available: describe2(nodes) };
|
|
2914
|
+
const node = nodes.find((candidate) => matchesName(candidate, segment));
|
|
2915
|
+
if (node === void 0) {
|
|
2916
|
+
const defaultCommand = nodes.find((candidate) => !isGroup(candidate) && isDefaultCommand(candidate.description));
|
|
2917
|
+
if (defaultCommand !== void 0)
|
|
2918
|
+
return leafSelection(defaultCommand, [...path, defaultCommand.description.name], argv.slice(index));
|
|
2919
|
+
return {
|
|
2920
|
+
kind: "not-found",
|
|
2921
|
+
path: Object.freeze([...path, segment]),
|
|
2922
|
+
available: describe2(nodes)
|
|
2923
|
+
};
|
|
2924
|
+
}
|
|
2925
|
+
path.push(node.description.name);
|
|
2926
|
+
if (!isGroup(node))
|
|
2927
|
+
return leafSelection(node, path, argv.slice(index + 1));
|
|
2928
|
+
group = node.description;
|
|
2929
|
+
nodes = await node.children();
|
|
2930
|
+
}
|
|
2931
|
+
return { kind: "group", path: Object.freeze(path), group, available: describe2(nodes) };
|
|
2932
|
+
}
|
|
2933
|
+
function leafSelection(leaf, path, argv) {
|
|
2934
|
+
let loading;
|
|
2935
|
+
return {
|
|
2936
|
+
kind: "command",
|
|
2937
|
+
path: Object.freeze([...path]),
|
|
2938
|
+
command: leaf.description,
|
|
2939
|
+
argv: Object.freeze([...argv]),
|
|
2940
|
+
// One selection loads its command once, however many times an invocation asks.
|
|
2941
|
+
load: () => {
|
|
2942
|
+
loading ??= leaf.loadCommand().then((command) => (
|
|
2943
|
+
// Under a plain mount or in the host's tree, the command takes the host's app, as its tree's type says.
|
|
2944
|
+
leaf.binding.kind === "projected" ? projectCommand(command, leaf.binding.app) : command
|
|
2945
|
+
)).catch((error) => {
|
|
2946
|
+
throw new SourceDiscoveryError(leaf.source, leaf.location, error);
|
|
2947
|
+
});
|
|
2948
|
+
return loading;
|
|
2949
|
+
}
|
|
2950
|
+
};
|
|
2951
|
+
}
|
|
2952
|
+
|
|
2953
|
+
// ../../../libs/clinkr/ts/dist/outcomes/execute.js
|
|
2954
|
+
import { z as z19 } from "zod";
|
|
2955
|
+
|
|
2956
|
+
// ../../../libs/clinkr/ts/dist/execution-context.js
|
|
2957
|
+
function appSourceOf(value) {
|
|
2958
|
+
const built = Promise.resolve(value);
|
|
2959
|
+
return () => built;
|
|
2960
|
+
}
|
|
2961
|
+
function lazyAppSource(factory) {
|
|
2962
|
+
let built;
|
|
2963
|
+
return () => built ??= Promise.resolve().then(factory);
|
|
2964
|
+
}
|
|
2965
|
+
|
|
2966
|
+
// ../../../libs/clinkr/ts/dist/text-writer.js
|
|
2967
|
+
function frame(text) {
|
|
2968
|
+
return `${text.replace(/[\r\n]+$/u, "")}
|
|
2969
|
+
`;
|
|
2970
|
+
}
|
|
2971
|
+
|
|
2972
|
+
// ../../../libs/clinkr/ts/dist/outcomes/issue-messages.js
|
|
2973
|
+
var INVALID_VALUE = "Invalid value";
|
|
2974
|
+
function issueMessage(issue) {
|
|
2975
|
+
switch (issue.code) {
|
|
2976
|
+
case "invalid_type":
|
|
2977
|
+
return invalidType(issue.expected, issue.input);
|
|
2978
|
+
case "invalid_value":
|
|
2979
|
+
return expectedValues(issue.values);
|
|
2980
|
+
case "too_small":
|
|
2981
|
+
return bound(issue.origin, "min", issue.minimum, issue.inclusive !== false, issue.exact === true);
|
|
2982
|
+
case "too_big":
|
|
2983
|
+
return bound(issue.origin, "max", issue.maximum, issue.inclusive !== false, issue.exact === true);
|
|
2984
|
+
case "invalid_format":
|
|
2985
|
+
return invalidFormat(issue);
|
|
2986
|
+
case "not_multiple_of":
|
|
2987
|
+
return `Expected a multiple of ${String(issue.divisor)}`;
|
|
2988
|
+
case "unrecognized_keys":
|
|
2989
|
+
return `${issue.keys.length === 1 ? "Unknown field" : "Unknown fields"}: ${issue.keys.join(", ")}`;
|
|
2990
|
+
case "invalid_union":
|
|
2991
|
+
return "options" in issue && Array.isArray(issue.options) && issue.options.length > 0 ? expectedValues(issue.options) : INVALID_VALUE;
|
|
2992
|
+
// A `refine` or `z.custom` without its author's message, a record key or a map or set member Zod reports as a
|
|
2993
|
+
// whole, and any code Clinkr doesn't know.
|
|
2994
|
+
case "invalid_key":
|
|
2995
|
+
case "invalid_element":
|
|
2996
|
+
case "custom":
|
|
2997
|
+
default:
|
|
2998
|
+
return INVALID_VALUE;
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
var CLINKR_PARSE_PARAMS = Object.freeze({ error: issueMessage });
|
|
3002
|
+
function reportedIssues(issues) {
|
|
3003
|
+
const mistyped = /* @__PURE__ */ new Set();
|
|
3004
|
+
return issues.filter((issue) => {
|
|
3005
|
+
const key = JSON.stringify(issue.path.map(String));
|
|
3006
|
+
if (mistyped.has(key))
|
|
3007
|
+
return false;
|
|
3008
|
+
if (issue.code === "invalid_type")
|
|
3009
|
+
mistyped.add(key);
|
|
3010
|
+
return true;
|
|
3011
|
+
});
|
|
3012
|
+
}
|
|
3013
|
+
var EXPECTED_TYPES = {
|
|
3014
|
+
string: "a string",
|
|
3015
|
+
number: "a number",
|
|
3016
|
+
int: "an integer",
|
|
3017
|
+
boolean: "a boolean",
|
|
3018
|
+
array: "an array",
|
|
3019
|
+
tuple: "an array",
|
|
3020
|
+
object: "an object",
|
|
3021
|
+
record: "an object",
|
|
3022
|
+
null: "null"
|
|
3023
|
+
};
|
|
3024
|
+
function invalidType(expected, input) {
|
|
3025
|
+
if (input === void 0)
|
|
3026
|
+
return "Required";
|
|
3027
|
+
if (expected === "int" && typeof input === "number" && Number.isFinite(input))
|
|
3028
|
+
return "Expected an integer";
|
|
3029
|
+
const noun = Object.hasOwn(EXPECTED_TYPES, expected) ? EXPECTED_TYPES[expected] : void 0;
|
|
3030
|
+
if (noun === void 0)
|
|
3031
|
+
return INVALID_VALUE;
|
|
3032
|
+
return `Expected ${noun}, got ${received(input)}`;
|
|
3033
|
+
}
|
|
3034
|
+
var RECEIVED_TYPES = {
|
|
3035
|
+
string: "a string",
|
|
3036
|
+
number: "a number",
|
|
3037
|
+
boolean: "a boolean",
|
|
3038
|
+
bigint: "a bigint",
|
|
3039
|
+
object: "an object",
|
|
3040
|
+
function: "a function",
|
|
3041
|
+
symbol: "a symbol"
|
|
3042
|
+
};
|
|
3043
|
+
function received(input) {
|
|
3044
|
+
if (input === null)
|
|
3045
|
+
return "null";
|
|
3046
|
+
if (Array.isArray(input))
|
|
3047
|
+
return "an array";
|
|
3048
|
+
if (typeof input === "number" && !Number.isFinite(input))
|
|
3049
|
+
return String(input);
|
|
3050
|
+
return RECEIVED_TYPES[typeof input] ?? typeof input;
|
|
3051
|
+
}
|
|
3052
|
+
function expectedValues(values) {
|
|
3053
|
+
const listed = values.map(String);
|
|
3054
|
+
return listed.length === 1 ? `Expected ${listed[0]}` : `Expected one of: ${listed.join(", ")}`;
|
|
3055
|
+
}
|
|
3056
|
+
var SIZE_UNITS = {
|
|
3057
|
+
string: ["character", "characters"],
|
|
3058
|
+
array: ["item", "items"]
|
|
3059
|
+
};
|
|
3060
|
+
var NUMBER_NOUNS = { number: "a number", int: "an integer" };
|
|
3061
|
+
function bound(origin, side, limit, inclusive, exact) {
|
|
3062
|
+
const amount = typeof limit === "number" || typeof limit === "bigint" ? limit : void 0;
|
|
3063
|
+
if (amount === void 0)
|
|
3064
|
+
return INVALID_VALUE;
|
|
3065
|
+
const units = Object.hasOwn(SIZE_UNITS, origin) ? SIZE_UNITS[origin] : void 0;
|
|
3066
|
+
if (units !== void 0) {
|
|
3067
|
+
const unit = amount === 1 || amount === 1n ? units[0] : units[1];
|
|
3068
|
+
const qualifier = exact ? "exactly" : side === "min" ? inclusive ? "at least" : "more than" : inclusive ? "at most" : "fewer than";
|
|
3069
|
+
return `Expected ${qualifier} ${String(amount)} ${unit}`;
|
|
3070
|
+
}
|
|
3071
|
+
const noun = Object.hasOwn(NUMBER_NOUNS, origin) ? NUMBER_NOUNS[origin] : void 0;
|
|
3072
|
+
if (noun === void 0)
|
|
3073
|
+
return INVALID_VALUE;
|
|
3074
|
+
const operator = side === "min" ? inclusive ? ">=" : ">" : inclusive ? "<=" : "<";
|
|
3075
|
+
return `Expected ${noun} ${operator} ${String(amount)}`;
|
|
3076
|
+
}
|
|
3077
|
+
function invalidFormat(issue) {
|
|
3078
|
+
const { format } = issue;
|
|
3079
|
+
if (format === "regex")
|
|
3080
|
+
return issue.pattern === void 0 ? INVALID_VALUE : `Expected a string matching ${issue.pattern}`;
|
|
3081
|
+
if (format === "starts_with")
|
|
3082
|
+
return "prefix" in issue ? `Expected a string starting with "${String(issue.prefix)}"` : INVALID_VALUE;
|
|
3083
|
+
if (format === "ends_with")
|
|
3084
|
+
return "suffix" in issue ? `Expected a string ending with "${String(issue.suffix)}"` : INVALID_VALUE;
|
|
3085
|
+
if (format === "includes")
|
|
3086
|
+
return "includes" in issue ? `Expected a string containing "${String(issue.includes)}"` : INVALID_VALUE;
|
|
3087
|
+
return `Expected a string in ${format} format`;
|
|
3088
|
+
}
|
|
3089
|
+
|
|
3090
|
+
// ../../../libs/clinkr/ts/dist/outcomes/validate-request.js
|
|
3091
|
+
import { z as z18 } from "zod";
|
|
3092
|
+
var issuesSchema = z18.array(z18.object({ field: z18.string(), message: z18.string() }));
|
|
3093
|
+
function validateRequest(validate, request) {
|
|
3094
|
+
let returned;
|
|
3095
|
+
try {
|
|
3096
|
+
returned = validate(request);
|
|
3097
|
+
} catch (cause) {
|
|
3098
|
+
return { kind: "threw", cause };
|
|
3099
|
+
}
|
|
3100
|
+
const issues = issuesSchema.safeParse(returned);
|
|
3101
|
+
if (!issues.success)
|
|
3102
|
+
return {
|
|
3103
|
+
kind: "defect",
|
|
3104
|
+
cause: new Error("validate returned something other than an array of { field, message } issues.")
|
|
3105
|
+
};
|
|
3106
|
+
return issues.data.length === 0 ? { kind: "valid" } : { kind: "invalid", issues: issues.data };
|
|
3107
|
+
}
|
|
3108
|
+
|
|
3109
|
+
// ../../../libs/clinkr/ts/dist/outcomes/execute.js
|
|
3110
|
+
var resultEnvelopeSchema = z19.object({
|
|
3111
|
+
kind: z19.literal("result"),
|
|
3112
|
+
name: z19.string(),
|
|
3113
|
+
exitCode: z19.union([z19.literal(0), z19.literal(1)]),
|
|
3114
|
+
value: z19.looseObject({}),
|
|
3115
|
+
render: z19.custom((value) => typeof value === "function")
|
|
3116
|
+
});
|
|
3117
|
+
var errorEnvelopeSchema = z19.object({
|
|
3118
|
+
kind: z19.literal("error"),
|
|
3119
|
+
reason: z19.string(),
|
|
3120
|
+
exitCode: z19.union([z19.literal(1), z19.literal(2), z19.literal(130)]),
|
|
3121
|
+
content: z19.looseObject({ message: z19.string() })
|
|
3122
|
+
});
|
|
3123
|
+
async function executeResolved(command, input, options) {
|
|
3124
|
+
let parsed;
|
|
3125
|
+
try {
|
|
3126
|
+
parsed = command.requestSchema.safeParse(input, CLINKR_PARSE_PARAMS);
|
|
3127
|
+
} catch (cause) {
|
|
3128
|
+
return beforeHandlerThrow(command, cause, options.signal?.aborted === true);
|
|
3129
|
+
}
|
|
3130
|
+
if (!parsed.success)
|
|
3131
|
+
return invalidRequest(reportedIssues(parsed.error.issues));
|
|
3132
|
+
if (command.validate !== void 0) {
|
|
3133
|
+
const validation = validateRequest(command.validate, parsed.data);
|
|
3134
|
+
if (validation.kind === "threw")
|
|
3135
|
+
return beforeHandlerThrow(command, validation.cause, options.signal?.aborted === true);
|
|
3136
|
+
if (validation.kind === "defect")
|
|
3137
|
+
return internalError(validation.cause);
|
|
3138
|
+
if (validation.kind === "invalid")
|
|
3139
|
+
return invalidArguments("Invalid arguments.", validation.issues);
|
|
3140
|
+
}
|
|
3141
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
3142
|
+
if (signal.aborted)
|
|
3143
|
+
return canceledBy(signal.reason);
|
|
3144
|
+
let app;
|
|
3145
|
+
try {
|
|
3146
|
+
app = await options.app();
|
|
3147
|
+
} catch (cause) {
|
|
3148
|
+
return signal.aborted ? canceledBy(cause) : internalError(cause);
|
|
3149
|
+
}
|
|
3150
|
+
if (signal.aborted)
|
|
3151
|
+
return canceledBy(signal.reason);
|
|
3152
|
+
const elicitation = options.elicitor === void 0 ? void 0 : createElicitationUi(options.elicitor, signal);
|
|
3153
|
+
const { yes } = parsed.data;
|
|
3154
|
+
const ui = {
|
|
3155
|
+
...elicitation === void 0 ? {} : { elicit: elicitation.elicit },
|
|
3156
|
+
...command.confirms === true ? {
|
|
3157
|
+
confirm: createConfirm({
|
|
3158
|
+
yes: yes === true,
|
|
3159
|
+
askYesNo: elicitation?.askYesNo,
|
|
3160
|
+
invocation: options.invocation
|
|
3161
|
+
})
|
|
3162
|
+
} : {},
|
|
3163
|
+
...options.progress === void 0 ? {} : { progress: createProgress(options.progress) }
|
|
3164
|
+
};
|
|
3165
|
+
const context = Object.freeze({
|
|
3166
|
+
signal,
|
|
3167
|
+
ui: Object.freeze(ui),
|
|
3168
|
+
app,
|
|
3169
|
+
...options.invocation === void 0 ? {} : { invocation: options.invocation }
|
|
3170
|
+
});
|
|
3171
|
+
let returned;
|
|
3172
|
+
try {
|
|
3173
|
+
returned = await command.handler(context, parsed.data);
|
|
3174
|
+
} catch (cause) {
|
|
3175
|
+
return recognizedThrow(cause, { aborted: signal.aborted }) ?? caught(command, cause);
|
|
3176
|
+
}
|
|
3177
|
+
return checkReturned(command, returned);
|
|
3178
|
+
}
|
|
3179
|
+
function beforeHandlerThrow(command, cause, aborted) {
|
|
3180
|
+
return aborted ? canceledBy(cause) : caught(command, cause);
|
|
3181
|
+
}
|
|
3182
|
+
function caught(command, cause) {
|
|
3183
|
+
if (command.catch === void 0)
|
|
3184
|
+
return internalError(cause);
|
|
3185
|
+
let mapped;
|
|
3186
|
+
try {
|
|
3187
|
+
mapped = command.catch(cause);
|
|
3188
|
+
} catch (thrown) {
|
|
3189
|
+
return internalError(thrown);
|
|
3190
|
+
}
|
|
3191
|
+
if (mapped === void 0)
|
|
3192
|
+
return internalError(cause);
|
|
3193
|
+
if (!isCommandError(mapped) || !errorEnvelopeSchema.safeParse(mapped).success)
|
|
3194
|
+
return internalError(new Error("throws.catch returned something that is not an error.", { cause: mapped }));
|
|
3195
|
+
if (!declaresError(command, mapped))
|
|
3196
|
+
return internalError(new Error(`throws.catch returned ${mapped.reason}, which its command doesn't declare.`, { cause: mapped }));
|
|
3197
|
+
return mapped;
|
|
3198
|
+
}
|
|
3199
|
+
function checkReturned(command, returned) {
|
|
3200
|
+
if (isCommandError(returned)) {
|
|
3201
|
+
if (!errorEnvelopeSchema.safeParse(returned).success)
|
|
3202
|
+
return internalError(new Error("The handler returned an error with an invalid envelope.", { cause: returned }));
|
|
3203
|
+
return declaresError(command, returned) ? returned : undeclared(returned);
|
|
3204
|
+
}
|
|
3205
|
+
if (declaresResult(command, returned))
|
|
3206
|
+
return returned;
|
|
3207
|
+
const name = typeof returned === "object" && returned !== null ? returned.name : void 0;
|
|
3208
|
+
return internalError(new Error(typeof name === "string" ? `The handler returned result ${name}, which its command doesn't declare.` : "The handler returned something that is not one of its command's outcomes"));
|
|
3209
|
+
}
|
|
3210
|
+
function declaresError(command, error) {
|
|
3211
|
+
if (error.reason === "canceled" && error.exitCode === 130)
|
|
3212
|
+
return true;
|
|
3213
|
+
return command.outcomes.definition.outcomes.some(({ kind, name, exitCode }) => kind === "error" && name === error.reason && exitCode === error.exitCode);
|
|
3214
|
+
}
|
|
3215
|
+
function declaresResult(command, value) {
|
|
3216
|
+
const parsed = resultEnvelopeSchema.safeParse(value);
|
|
3217
|
+
if (!parsed.success)
|
|
3218
|
+
return false;
|
|
3219
|
+
const { name, exitCode } = parsed.data;
|
|
3220
|
+
return command.outcomes.definition.outcomes.some((entry) => entry.kind === "result" && entry.name === name && entry.exitCode === exitCode);
|
|
3221
|
+
}
|
|
3222
|
+
function undeclared(error) {
|
|
3223
|
+
const reason = typeof error.reason === "string" ? error.reason : "an error";
|
|
3224
|
+
return internalError(new Error(`The handler returned ${reason}, which its command doesn't declare.`, { cause: error }));
|
|
3225
|
+
}
|
|
3226
|
+
function createProgress(writer) {
|
|
3227
|
+
return async (text) => {
|
|
3228
|
+
if (typeof text !== "string")
|
|
3229
|
+
throw new TypeError("ui.progress text must be a string");
|
|
3230
|
+
await writer.write(frame(text));
|
|
3231
|
+
};
|
|
3232
|
+
}
|
|
3233
|
+
|
|
3234
|
+
// ../../../libs/clinkr/ts/dist/introspect-command.js
|
|
3235
|
+
import { z as z20 } from "zod";
|
|
3236
|
+
var JSON_SCHEMA_OPTIONS = { target: "draft-2020-12", unrepresentable: "throw" };
|
|
3237
|
+
var jsonSchemaSchema = z20.record(z20.string(), z20.unknown());
|
|
3238
|
+
var commandIntrospectionDocumentSchema = z20.object({
|
|
3239
|
+
command: z20.object({ path: z20.array(z20.string()) }),
|
|
3240
|
+
requestSchema: jsonSchemaSchema,
|
|
3241
|
+
responseSchema: jsonSchemaSchema,
|
|
3242
|
+
/** The JSON error document of each error the command lists. */
|
|
3243
|
+
errorSchema: jsonSchemaSchema
|
|
3244
|
+
});
|
|
3245
|
+
function describeCommand(path, command) {
|
|
3246
|
+
return {
|
|
3247
|
+
command: { path: [...path] },
|
|
3248
|
+
requestSchema: withFieldDescriptions(z20.toJSONSchema(command.requestSchema, { ...JSON_SCHEMA_OPTIONS, io: "input" }), command.help?.fields),
|
|
3249
|
+
responseSchema: publishedOutputSchema(responseDocumentSchema(command)),
|
|
3250
|
+
errorSchema: publishedOutputSchema(command.outcomes.definition.errorDocumentSchema)
|
|
3251
|
+
};
|
|
3252
|
+
}
|
|
3253
|
+
function publishedOutputSchema(schema) {
|
|
3254
|
+
return z20.toJSONSchema(schema, { ...JSON_SCHEMA_OPTIONS, io: "output" });
|
|
3255
|
+
}
|
|
3256
|
+
function responseDocumentSchema(command) {
|
|
3257
|
+
return command.outcomes.definition.documentSchema;
|
|
3258
|
+
}
|
|
3259
|
+
|
|
3260
|
+
// ../../../libs/clinkr/ts/dist/default-command.js
|
|
3261
|
+
async function selectDefaultCommand(application, path, available) {
|
|
3262
|
+
const defaultCommand = defaultCommandOf(available);
|
|
3263
|
+
if (defaultCommand === void 0)
|
|
3264
|
+
return void 0;
|
|
3265
|
+
const defaultPath = [...path, defaultCommand.name];
|
|
3266
|
+
const selection = await application.select(defaultPath);
|
|
3267
|
+
if (selection.kind !== "command")
|
|
3268
|
+
throw new Error(`Default command ${JSON.stringify(defaultPath.join(" "))} does not select a command`);
|
|
3269
|
+
return selection;
|
|
3270
|
+
}
|
|
3271
|
+
|
|
3272
|
+
// ../../../libs/clinkr/ts/dist/resolve-completion.js
|
|
3273
|
+
function isCandidateValue(value) {
|
|
3274
|
+
return value.length > 0 && Array.from(value).every((character) => {
|
|
3275
|
+
const code2 = character.codePointAt(0);
|
|
3276
|
+
return code2 > 31 && code2 !== 127;
|
|
3277
|
+
});
|
|
3278
|
+
}
|
|
3279
|
+
function valueCandidates(field, prefix) {
|
|
3280
|
+
return (field?.values ?? []).filter((value) => value.startsWith(prefix));
|
|
3281
|
+
}
|
|
3282
|
+
async function queryProvider({ provider, field, prefix, path, argv, app, budgetMs, signal }) {
|
|
3283
|
+
const controller = new AbortController();
|
|
3284
|
+
if (signal?.aborted)
|
|
3285
|
+
return { values: [], diagnostics: ["Completion provider cancelled"] };
|
|
3286
|
+
let cancel;
|
|
3287
|
+
const cancelled = new Promise((_resolve, reject) => {
|
|
3288
|
+
cancel = () => {
|
|
3289
|
+
controller.abort();
|
|
3290
|
+
reject(new Error("Completion provider cancelled"));
|
|
3291
|
+
};
|
|
3292
|
+
signal?.addEventListener("abort", cancel, { once: true });
|
|
3293
|
+
});
|
|
3294
|
+
let timer;
|
|
3295
|
+
try {
|
|
3296
|
+
const timed = new Promise((_resolve, reject) => {
|
|
3297
|
+
timer = setTimeout(() => {
|
|
3298
|
+
controller.abort();
|
|
3299
|
+
reject(new Error("Completion provider timed out"));
|
|
3300
|
+
}, budgetMs);
|
|
3301
|
+
});
|
|
3302
|
+
const values = await Promise.race([
|
|
3303
|
+
Promise.resolve().then(async () => provider({ field: field.key, prefix, path, argv, signal: controller.signal, app: await app() })),
|
|
3304
|
+
timed,
|
|
3305
|
+
cancelled
|
|
3306
|
+
]);
|
|
3307
|
+
if (!Array.isArray(values) || values.some((value) => typeof value !== "string"))
|
|
3308
|
+
throw new Error("Completion provider must return string values");
|
|
3309
|
+
return { values, diagnostics: [] };
|
|
3310
|
+
} catch (error) {
|
|
3311
|
+
return { values: [], diagnostics: [error instanceof Error ? error.message : String(error)] };
|
|
3312
|
+
} finally {
|
|
3313
|
+
if (timer !== void 0)
|
|
3314
|
+
clearTimeout(timer);
|
|
3315
|
+
if (cancel !== void 0)
|
|
3316
|
+
signal?.removeEventListener("abort", cancel);
|
|
3317
|
+
}
|
|
3318
|
+
}
|
|
3319
|
+
function isCompletionWords(words) {
|
|
3320
|
+
return Array.isArray(words) && words.length > 0 && words.every((word) => typeof word === "string");
|
|
3321
|
+
}
|
|
3322
|
+
async function resolveCompletionResolved(application, request) {
|
|
3323
|
+
const { words } = request;
|
|
3324
|
+
if (!isCompletionWords(words)) {
|
|
3325
|
+
return { candidates: [], diagnostics: ["Completion words must contain a final string prefix"] };
|
|
3326
|
+
}
|
|
3327
|
+
const prefix = words[words.length - 1];
|
|
3328
|
+
const preceding = [];
|
|
3329
|
+
let afterDelimiter = false;
|
|
3330
|
+
for (const word of words.slice(0, -1)) {
|
|
3331
|
+
if (word === "--")
|
|
3332
|
+
afterDelimiter = true;
|
|
3333
|
+
if (!afterDelimiter && isGloballyParsedFlag(word))
|
|
3334
|
+
continue;
|
|
3335
|
+
preceding.push(word);
|
|
3336
|
+
}
|
|
3337
|
+
try {
|
|
3338
|
+
if (preceding[0] === "sys") {
|
|
3339
|
+
if (preceding.length === 1) {
|
|
3340
|
+
return {
|
|
3341
|
+
candidates: prefix.startsWith("-") ? COMPLETION_FRAMEWORK_FLAGS.filter((flag) => flag.startsWith(prefix)) : ["completion"].filter((name) => name.startsWith(prefix)),
|
|
3342
|
+
diagnostics: []
|
|
3343
|
+
};
|
|
3344
|
+
}
|
|
3345
|
+
if (preceding.length === 2 && preceding[1] === "completion") {
|
|
3346
|
+
return {
|
|
3347
|
+
candidates: ["bash", "zsh", "fish"].filter((shell) => shell.startsWith(prefix)),
|
|
3348
|
+
diagnostics: []
|
|
3349
|
+
};
|
|
3350
|
+
}
|
|
3351
|
+
return {
|
|
3352
|
+
candidates: [],
|
|
3353
|
+
diagnostics: [`Unknown sys command: ${preceding.slice(1).join(" ")}`]
|
|
3354
|
+
};
|
|
3355
|
+
}
|
|
3356
|
+
const selection = await application.select(preceding);
|
|
3357
|
+
if (selection.kind === "not-found") {
|
|
3358
|
+
return { candidates: [], diagnostics: [`Unknown command: ${selection.path.join(" ")}`] };
|
|
3359
|
+
}
|
|
3360
|
+
if (selection.kind === "group") {
|
|
3361
|
+
const names = selection.available.filter(isListed).map((node) => node.name);
|
|
3362
|
+
const flags2 = selection.path.length === 0 && application.version !== void 0 ? [...COMPLETION_FRAMEWORK_FLAGS, VERSION_FLAG] : COMPLETION_FRAMEWORK_FLAGS;
|
|
3363
|
+
if (!prefix.startsWith("-"))
|
|
3364
|
+
return { candidates: names.filter((name) => name.startsWith(prefix)), diagnostics: [] };
|
|
3365
|
+
const defaultCommand = await selectDefaultCommand(application, selection.path, selection.available);
|
|
3366
|
+
const defaultFlags = defaultCommand === void 0 ? [] : scanArgvForCompletion(await defaultCommand.load(), []).options.map((option) => option.flag);
|
|
3367
|
+
return {
|
|
3368
|
+
candidates: [.../* @__PURE__ */ new Set([...defaultFlags, ...flags2])].filter((flag) => flag.startsWith(prefix)),
|
|
3369
|
+
diagnostics: []
|
|
3370
|
+
};
|
|
3371
|
+
}
|
|
3372
|
+
const command = await selection.load();
|
|
3373
|
+
const state = scanArgvForCompletion(command, selection.argv);
|
|
3374
|
+
let field;
|
|
3375
|
+
let valuePrefix = prefix;
|
|
3376
|
+
let replacement = "";
|
|
3377
|
+
let flags = [];
|
|
3378
|
+
if (state.pending !== void 0) {
|
|
3379
|
+
field = state.pending;
|
|
3380
|
+
} else if (state.afterDelimiter) {
|
|
3381
|
+
field = state.positional;
|
|
3382
|
+
} else if (prefix.startsWith("--") && prefix.includes("=")) {
|
|
3383
|
+
const index = prefix.indexOf("=");
|
|
3384
|
+
const flag = prefix.slice(0, index);
|
|
3385
|
+
field = state.options.find((option) => (option.flag === flag || option.aliases.includes(flag)) && option.kind !== "boolean");
|
|
3386
|
+
valuePrefix = prefix.slice(index + 1);
|
|
3387
|
+
replacement = `${flag}=`;
|
|
3388
|
+
} else if (prefix.startsWith("-")) {
|
|
3389
|
+
flags = [...state.options.map((option) => option.flag), ...COMPLETION_FRAMEWORK_FLAGS].filter((flag) => flag.startsWith(prefix));
|
|
3390
|
+
} else {
|
|
3391
|
+
field = state.positional;
|
|
3392
|
+
if (prefix === "")
|
|
3393
|
+
flags = [...state.options.map((option) => option.flag), ...COMPLETION_FRAMEWORK_FLAGS];
|
|
3394
|
+
}
|
|
3395
|
+
let values = valueCandidates(field, valuePrefix);
|
|
3396
|
+
let providerDiagnostics = [];
|
|
3397
|
+
if (field !== void 0 && command.completionProvider !== void 0) {
|
|
3398
|
+
const budgetMs = request.providerBudgetMs ?? 300;
|
|
3399
|
+
if (!Number.isFinite(budgetMs) || budgetMs < 0) {
|
|
3400
|
+
return { candidates: [], diagnostics: ["Invalid completion provider budget"] };
|
|
3401
|
+
}
|
|
3402
|
+
const result = await queryProvider({
|
|
3403
|
+
provider: command.completionProvider,
|
|
3404
|
+
field,
|
|
3405
|
+
prefix: valuePrefix,
|
|
3406
|
+
path: selection.path,
|
|
3407
|
+
argv: selection.argv,
|
|
3408
|
+
app: request.app,
|
|
3409
|
+
budgetMs,
|
|
3410
|
+
signal: request.signal
|
|
3411
|
+
});
|
|
3412
|
+
providerDiagnostics = result.diagnostics;
|
|
3413
|
+
values = [
|
|
3414
|
+
...values,
|
|
3415
|
+
...result.values.filter((value) => value.startsWith(valuePrefix) && (field.values === void 0 || field.values.includes(value)))
|
|
3416
|
+
];
|
|
3417
|
+
}
|
|
3418
|
+
const candidates = [...values.filter(isCandidateValue).map((value) => `${replacement}${value}`), ...flags];
|
|
3419
|
+
return {
|
|
3420
|
+
candidates: [...new Set(candidates.filter(isCandidateValue))],
|
|
3421
|
+
diagnostics: [],
|
|
3422
|
+
...providerDiagnostics.length === 0 ? {} : { providerDiagnostics }
|
|
3423
|
+
};
|
|
3424
|
+
} catch (error) {
|
|
3425
|
+
return {
|
|
3426
|
+
candidates: [],
|
|
3427
|
+
diagnostics: [error instanceof Error ? error.message : String(error)]
|
|
3428
|
+
};
|
|
3429
|
+
}
|
|
3430
|
+
}
|
|
3431
|
+
|
|
3432
|
+
// ../../../libs/clinkr/ts/dist/render-completion-script.js
|
|
3433
|
+
function quote(value) {
|
|
3434
|
+
return `'${value.replaceAll("'", `'\\''`)}'`;
|
|
3435
|
+
}
|
|
3436
|
+
function functionNameSuffix(commandName) {
|
|
3437
|
+
let suffix = "";
|
|
3438
|
+
for (const byte of new TextEncoder().encode(commandName)) {
|
|
3439
|
+
const char = String.fromCharCode(byte);
|
|
3440
|
+
suffix += /[A-Za-z0-9]/.test(char) ? char : `_${byte.toString(16).padStart(2, "0")}`;
|
|
3441
|
+
}
|
|
3442
|
+
return suffix;
|
|
3443
|
+
}
|
|
3444
|
+
function renderCompletionScript({ commandName, shell }) {
|
|
3445
|
+
if (!commandName || /[\p{Cc}\p{Cf}]/u.test(commandName)) {
|
|
3446
|
+
throw new Error("Completion command name must be nonempty and contain no control characters");
|
|
3447
|
+
}
|
|
3448
|
+
const executable = quote(commandName);
|
|
3449
|
+
const suffix = functionNameSuffix(commandName);
|
|
3450
|
+
switch (shell) {
|
|
3451
|
+
case "bash":
|
|
3452
|
+
return `# Source this file in bash to enable ${commandName} completion.
|
|
3453
|
+
_clinkr_complete_${suffix}() {
|
|
3454
|
+
local -a words candidates
|
|
3455
|
+
local candidate
|
|
3456
|
+
words=("\${COMP_WORDS[@]:1:COMP_CWORD-1}")
|
|
3457
|
+
words+=("\${COMP_WORDS[COMP_CWORD]}")
|
|
3458
|
+
mapfile -t candidates < <(${executable} sys __complete -- "\${words[@]}" 2>/dev/null)
|
|
3459
|
+
COMPREPLY=()
|
|
3460
|
+
for candidate in "\${candidates[@]}"; do
|
|
3461
|
+
printf -v candidate '%q' "$candidate"
|
|
3462
|
+
COMPREPLY+=("$candidate")
|
|
3463
|
+
done
|
|
3464
|
+
}
|
|
3465
|
+
complete -F _clinkr_complete_${suffix} -- ${executable}
|
|
3466
|
+
`;
|
|
3467
|
+
case "zsh":
|
|
3468
|
+
return `#compdef ${commandName}
|
|
3469
|
+
_clinkr_complete_${suffix}() {
|
|
3470
|
+
local -a candidates
|
|
3471
|
+
local output
|
|
3472
|
+
output=$( ${executable} sys __complete -- "\${(@)words[2,CURRENT-1]}" "\${words[CURRENT]}" 2>/dev/null )
|
|
3473
|
+
[[ -n $output ]] || return
|
|
3474
|
+
candidates=(\${(f)output})
|
|
3475
|
+
compadd -S '' -- "\${candidates[@]}"
|
|
3476
|
+
}
|
|
3477
|
+
compdef _clinkr_complete_${suffix} ${executable}
|
|
3478
|
+
`;
|
|
3479
|
+
case "fish":
|
|
3480
|
+
return `# Source this file in fish to enable ${commandName} completion.
|
|
3481
|
+
function __clinkr_complete_${suffix}
|
|
3482
|
+
set -l words (commandline -opc)
|
|
3483
|
+
set -e words[1]
|
|
3484
|
+
set -l prefix (commandline -ct | string collect -N)
|
|
3485
|
+
${executable} sys __complete -- $words "$prefix" 2>/dev/null
|
|
3486
|
+
end
|
|
3487
|
+
complete -c ${executable} -f -a '(__clinkr_complete_${suffix})'
|
|
3488
|
+
`;
|
|
3489
|
+
}
|
|
3490
|
+
}
|
|
3491
|
+
|
|
3492
|
+
// ../../../libs/clinkr/ts/dist/json-output.js
|
|
3493
|
+
function formatJsonOutput(value, terminal) {
|
|
3494
|
+
const serialized = JSON.stringify(value, void 0, terminal ? 2 : void 0);
|
|
3495
|
+
if (typeof serialized !== "string")
|
|
3496
|
+
throw new Error("JSON serialization did not produce text");
|
|
3497
|
+
return serialized;
|
|
3498
|
+
}
|
|
3499
|
+
|
|
3500
|
+
// ../../../libs/clinkr/ts/dist/suggest.js
|
|
3501
|
+
var MAXIMUM_SUGGESTION_DISTANCE = 2;
|
|
3502
|
+
function suggestCommandNames(unknown, candidates) {
|
|
3503
|
+
let best = Math.min(MAXIMUM_SUGGESTION_DISTANCE, unknown.length - 1);
|
|
3504
|
+
let suggestions = [];
|
|
3505
|
+
for (const candidate of candidates) {
|
|
3506
|
+
const distance = editDistance(unknown, candidate);
|
|
3507
|
+
if (distance > best)
|
|
3508
|
+
continue;
|
|
3509
|
+
if (distance < best) {
|
|
3510
|
+
best = distance;
|
|
3511
|
+
suggestions = [];
|
|
3512
|
+
}
|
|
3513
|
+
suggestions.push(candidate);
|
|
3514
|
+
}
|
|
3515
|
+
return suggestions;
|
|
3516
|
+
}
|
|
3517
|
+
function joinAlternatives(names) {
|
|
3518
|
+
if (names.length <= 1)
|
|
3519
|
+
return names.join("");
|
|
3520
|
+
return `${names.slice(0, -1).join(", ")} or ${names[names.length - 1]}`;
|
|
3521
|
+
}
|
|
3522
|
+
function editDistance(left, right) {
|
|
3523
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
3524
|
+
for (let row = 1; row <= left.length; row += 1) {
|
|
3525
|
+
const current = [row];
|
|
3526
|
+
for (let column = 1; column <= right.length; column += 1) {
|
|
3527
|
+
const substitution = left[row - 1] === right[column - 1] ? 0 : 1;
|
|
3528
|
+
current.push(Math.min(previous[column] + 1, current[column - 1] + 1, previous[column - 1] + substitution));
|
|
3529
|
+
}
|
|
3530
|
+
previous = current;
|
|
3531
|
+
}
|
|
3532
|
+
return previous[right.length];
|
|
3533
|
+
}
|
|
3534
|
+
|
|
3535
|
+
// ../../../libs/clinkr/ts/dist/outcomes/present-error.js
|
|
3536
|
+
var MAXIMUM_ISSUE_ROWS = 5;
|
|
3537
|
+
function presentErrorOutput(error, options) {
|
|
3538
|
+
const status = error.exitCode;
|
|
3539
|
+
if (options.json) {
|
|
3540
|
+
const shown = error.reason === "invalid_arguments" ? withUsageStep(error, options.helpPath) : error;
|
|
3541
|
+
return { stderr: JSON.stringify(errorDocument(shown)), status };
|
|
3542
|
+
}
|
|
3543
|
+
const { ui } = options;
|
|
3544
|
+
if (error.reason === "canceled") {
|
|
3545
|
+
const view2 = { message: error.content.message, changed: "changed" in error ? error.changed : void 0 };
|
|
3546
|
+
return { stderr: drawSafely(() => ui.canceled(view2)) ?? plainUi.canceled(view2), status };
|
|
3547
|
+
}
|
|
3548
|
+
const view = errorViewOf(error, options);
|
|
3549
|
+
return { stderr: drawSafely(() => ui.error(view)) ?? plainUi.error(view), status };
|
|
3550
|
+
}
|
|
3551
|
+
function errorViewOf(error, { helpPath, usage }) {
|
|
3552
|
+
const invalid = error.reason === "invalid_arguments";
|
|
3553
|
+
const shownUsage = invalid ? usage : void 0;
|
|
3554
|
+
const shown = invalid && shownUsage === void 0 ? withUsageStep(error, helpPath) : error;
|
|
3555
|
+
return {
|
|
3556
|
+
reason: error.reason,
|
|
3557
|
+
message: error.content.message,
|
|
3558
|
+
rows: error.content.rows ?? [],
|
|
3559
|
+
rowLimit: invalid ? MAXIMUM_ISSUE_ROWS : void 0,
|
|
3560
|
+
next: shown.content.next ?? [],
|
|
3561
|
+
usage: shownUsage,
|
|
3562
|
+
stack: error.reason === "internal_error" ? stackOf("cause" in error ? error.cause : void 0) : void 0
|
|
3563
|
+
};
|
|
3564
|
+
}
|
|
3565
|
+
function drawSafely(draw) {
|
|
3566
|
+
try {
|
|
3567
|
+
return draw();
|
|
3568
|
+
} catch {
|
|
3569
|
+
return void 0;
|
|
3570
|
+
}
|
|
3571
|
+
}
|
|
3572
|
+
function withUsageStep(error, helpPath) {
|
|
3573
|
+
const step = { type: "command", argv: [...helpPath, "--help"], label: "See usage" };
|
|
3574
|
+
return { ...error, content: { ...error.content, next: [...error.content.next ?? [], step] } };
|
|
3575
|
+
}
|
|
3576
|
+
function stackOf(cause) {
|
|
3577
|
+
const stacks = [];
|
|
3578
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3579
|
+
for (let current = cause; current instanceof Error && !seen.has(current); current = current.cause) {
|
|
3580
|
+
seen.add(current);
|
|
3581
|
+
if (current.stack !== void 0)
|
|
3582
|
+
stacks.push(current.stack);
|
|
3583
|
+
}
|
|
3584
|
+
return stacks.length === 0 ? void 0 : stacks.join("\nCaused by: ");
|
|
3585
|
+
}
|
|
3586
|
+
|
|
3587
|
+
// ../../../libs/clinkr/ts/dist/leaf-request.js
|
|
3588
|
+
async function prepareLeafRequest(command, argv, options) {
|
|
3589
|
+
const delimiter = argv.indexOf("--");
|
|
3590
|
+
const active = delimiter === -1 ? argv : argv.slice(0, delimiter);
|
|
3591
|
+
if (active.includes("-h") || active.includes("--help"))
|
|
3592
|
+
return { kind: "help", outcomes: active.includes("--outcomes") };
|
|
3593
|
+
if (options.inputJson && argv.length > 0)
|
|
3594
|
+
return failure({ kind: "input-json-with-arguments" });
|
|
3595
|
+
const schemaCount = active.filter((token) => token === "--json-schema").length;
|
|
3596
|
+
if (schemaCount > 0) {
|
|
3597
|
+
if (active.length !== 1 || argv.length !== 1 || schemaCount !== 1)
|
|
3598
|
+
return failure({ kind: "schema-not-alone" });
|
|
3599
|
+
return { kind: "schema" };
|
|
3600
|
+
}
|
|
3601
|
+
if (options.inputJson)
|
|
3602
|
+
return readRequest(command, options);
|
|
3603
|
+
try {
|
|
3604
|
+
return { kind: "request", candidate: projectArgv(command, argv) };
|
|
3605
|
+
} catch (error) {
|
|
3606
|
+
if (error instanceof ArgvProjectionError)
|
|
3607
|
+
return failure({ kind: "argv-projection", error });
|
|
3608
|
+
throw error;
|
|
3609
|
+
}
|
|
3610
|
+
}
|
|
3611
|
+
function failure(failure2) {
|
|
3612
|
+
return { kind: "failure", failure: failure2 };
|
|
3613
|
+
}
|
|
3614
|
+
async function readRequest(command, options) {
|
|
3615
|
+
const { signal, inputReader } = options;
|
|
3616
|
+
if (signal?.aborted)
|
|
3617
|
+
return failure({ kind: "canceled", signal, cause: signal.reason });
|
|
3618
|
+
if (inputReader === void 0)
|
|
3619
|
+
return failure({ kind: "missing-input-reader" });
|
|
3620
|
+
let text;
|
|
3621
|
+
try {
|
|
3622
|
+
text = await inputReader();
|
|
3623
|
+
} catch (cause) {
|
|
3624
|
+
if (signal?.aborted)
|
|
3625
|
+
return failure({ kind: "canceled", signal, cause });
|
|
3626
|
+
return failure({ kind: "unreadable-input" });
|
|
3627
|
+
}
|
|
3628
|
+
if (signal?.aborted)
|
|
3629
|
+
return failure({ kind: "canceled", signal, cause: signal.reason });
|
|
3630
|
+
let candidate;
|
|
3631
|
+
try {
|
|
3632
|
+
candidate = JSON.parse(text.replace(/^\uFEFF/u, ""));
|
|
3633
|
+
} catch {
|
|
3634
|
+
return failure({ kind: "not-json-object" });
|
|
3635
|
+
}
|
|
3636
|
+
if (candidate === null || typeof candidate !== "object" || Array.isArray(candidate))
|
|
3637
|
+
return failure({ kind: "not-json-object" });
|
|
3638
|
+
const fields = Object.keys(candidate).filter((key) => !Object.hasOwn(command.requestSchema.shape, key));
|
|
3639
|
+
if (fields.length > 0)
|
|
3640
|
+
return failure({ kind: "unknown-fields", fields });
|
|
3641
|
+
return { kind: "request", candidate };
|
|
3642
|
+
}
|
|
3643
|
+
|
|
3644
|
+
// ../../../libs/clinkr/ts/dist/outcomes/catalog.js
|
|
3645
|
+
import { z as z21 } from "zod";
|
|
3646
|
+
var ADDED_FIELD_SET = new Set(ADDED_FIELDS);
|
|
3647
|
+
var JSON_SCHEMA_OPTIONS2 = { target: "draft-2020-12", unrepresentable: "throw", io: "output" };
|
|
3648
|
+
function outcomeCatalog(path, outcomes, options = {}) {
|
|
3649
|
+
const { outcomes: entries } = outcomes.definition;
|
|
3650
|
+
const firstResultOf = /* @__PURE__ */ new Map();
|
|
3651
|
+
const sameDocumentAs = /* @__PURE__ */ new Map();
|
|
3652
|
+
const listed = entries.map((entry) => {
|
|
3653
|
+
const { name, kind, exitCode, schema, description } = entry;
|
|
3654
|
+
const described = description === void 0 ? {} : { description };
|
|
3655
|
+
if (kind === "error")
|
|
3656
|
+
return {
|
|
3657
|
+
name,
|
|
3658
|
+
kind,
|
|
3659
|
+
exitCode,
|
|
3660
|
+
stream: "stderr",
|
|
3661
|
+
status: entry.status ?? "error",
|
|
3662
|
+
...described,
|
|
3663
|
+
...schema === void 0 ? {} : { schema: z21.toJSONSchema(schema, JSON_SCHEMA_OPTIONS2) }
|
|
3664
|
+
};
|
|
3665
|
+
const first = firstResultOf.get(schema);
|
|
3666
|
+
if (first === void 0)
|
|
3667
|
+
firstResultOf.set(schema, name);
|
|
3668
|
+
else
|
|
3669
|
+
sameDocumentAs.set(name, first);
|
|
3670
|
+
const document = resultDocumentSchema(schema, z21.literal(name));
|
|
3671
|
+
return {
|
|
3672
|
+
name,
|
|
3673
|
+
kind,
|
|
3674
|
+
exitCode,
|
|
3675
|
+
stream: "stdout",
|
|
3676
|
+
...described,
|
|
3677
|
+
schema: z21.toJSONSchema(document, JSON_SCHEMA_OPTIONS2)
|
|
3678
|
+
};
|
|
3679
|
+
});
|
|
3680
|
+
const clinkrEntries = options.confirms === true ? [...CLINKR_ERROR_ENTRIES, CONFIRMATION_REQUIRED_ENTRY] : CLINKR_ERROR_ENTRIES;
|
|
3681
|
+
const clinkr = clinkrEntries.map(({ name, exitCode, status, description, schema }) => ({
|
|
3682
|
+
name,
|
|
3683
|
+
kind: "error",
|
|
3684
|
+
exitCode,
|
|
3685
|
+
stream: "stderr",
|
|
3686
|
+
status: status ?? "error",
|
|
3687
|
+
description,
|
|
3688
|
+
...schema === void 0 ? {} : { schema: z21.toJSONSchema(schema, JSON_SCHEMA_OPTIONS2) }
|
|
3689
|
+
}));
|
|
3690
|
+
return {
|
|
3691
|
+
document: { command: { path: [...path] }, outcomes: [...listed, ...clinkr] },
|
|
3692
|
+
sameDocumentAs
|
|
3693
|
+
};
|
|
3694
|
+
}
|
|
3695
|
+
var EXIT_CODE_MEANINGS = {
|
|
3696
|
+
0: "Success.",
|
|
3697
|
+
1: {
|
|
3698
|
+
result: "The check's answer is no (a result on stdout).",
|
|
3699
|
+
error: "The same command could succeed once something changes (an error on stderr).",
|
|
3700
|
+
both: "The check's answer is no (a result on stdout), or the same command could succeed once something changes (an error on stderr)."
|
|
3701
|
+
},
|
|
3702
|
+
2: "Running it again unchanged won't help: the request is wrong, or the command is broken.",
|
|
3703
|
+
130: "A person or the host stopped the invocation before it finished (128 + n when signal n stopped it)."
|
|
3704
|
+
};
|
|
3705
|
+
var FIELD_INDENT = 6;
|
|
3706
|
+
function formatOutcomeCatalog(catalog, usage, width) {
|
|
3707
|
+
const columns = Math.min(width, DEFAULT_HELP_WIDTH);
|
|
3708
|
+
const { outcomes } = catalog.document;
|
|
3709
|
+
const results = outcomes.filter(({ kind }) => kind === "result");
|
|
3710
|
+
const errors = outcomes.filter(({ kind }) => kind === "error");
|
|
3711
|
+
const section2 = (heading, blocks) => `${heading}
|
|
3712
|
+
${blocks.map((lines) => lines.join("\n")).join("\n\n")}`;
|
|
3713
|
+
const sections = [usage];
|
|
3714
|
+
if (results.length > 0)
|
|
3715
|
+
sections.push(section2("Results:", results.map((outcome) => outcomeLines(outcome, catalog.sameDocumentAs.get(outcome.name), columns))));
|
|
3716
|
+
if (errors.length > 0)
|
|
3717
|
+
sections.push(section2("Errors:", errors.map((outcome) => outcomeLines(outcome, void 0, columns))));
|
|
3718
|
+
sections.push(exitCodeLegend(outcomes, columns));
|
|
3719
|
+
return sections.join("\n\n");
|
|
3720
|
+
}
|
|
3721
|
+
function outcomeLines(outcome, sameDocumentAs, width) {
|
|
3722
|
+
const actionRequired = outcome.kind === "error" && outcome.status === "action_required" ? ", action required" : "";
|
|
3723
|
+
const lines = [
|
|
3724
|
+
` ${outcome.name} exit ${outcome.exitCode}${actionRequired}`,
|
|
3725
|
+
` ${wrapParagraph(outcome.description ?? "(no description)", width, 4)}`
|
|
3726
|
+
];
|
|
3727
|
+
if (sameDocumentAs !== void 0) {
|
|
3728
|
+
lines.push(` ${wrapParagraph(`Same document as ${sameDocumentAs}.`, width, 4)}`);
|
|
3729
|
+
return lines;
|
|
3730
|
+
}
|
|
3731
|
+
if (outcome.schema === void 0)
|
|
3732
|
+
return lines;
|
|
3733
|
+
const rows = outcome.kind === "result" ? fieldRows(outcome.schema, ADDED_FIELD_SET) : dataRows(outcome.schema);
|
|
3734
|
+
lines.push(...fieldTreeLines(rows, width));
|
|
3735
|
+
return lines;
|
|
3736
|
+
}
|
|
3737
|
+
function dataRows(schema) {
|
|
3738
|
+
const rows = fieldRows(schema);
|
|
3739
|
+
if (rows.length === 0)
|
|
3740
|
+
return [];
|
|
3741
|
+
return [{ depth: 0, label: "data", types: [] }, ...rows.map((row) => ({ ...row, depth: row.depth + 1 }))];
|
|
3742
|
+
}
|
|
3743
|
+
function fieldTreeLines(rows, width) {
|
|
3744
|
+
const labelOf = (row) => `${" ".repeat(row.depth)}${row.label}`;
|
|
3745
|
+
const labelWidth = Math.max(0, ...rows.map((row) => labelOf(row).length));
|
|
3746
|
+
const textColumn = FIELD_INDENT + labelWidth + 2;
|
|
3747
|
+
const textWidth = Math.max(width - textColumn, MINIMUM_TEXT_WIDTH);
|
|
3748
|
+
const indent2 = " ".repeat(FIELD_INDENT);
|
|
3749
|
+
const hanging = " ".repeat(textColumn);
|
|
3750
|
+
return rows.flatMap((row) => {
|
|
3751
|
+
const label = labelOf(row);
|
|
3752
|
+
const [first, ...rest] = fieldTextLines(row, textWidth);
|
|
3753
|
+
if (first === void 0)
|
|
3754
|
+
return [`${indent2}${label}`];
|
|
3755
|
+
return [`${indent2}${label.padEnd(labelWidth)} ${first}`, ...rest.map((line) => `${hanging}${line}`)];
|
|
3756
|
+
});
|
|
3757
|
+
}
|
|
3758
|
+
function fieldTextLines(row, width) {
|
|
3759
|
+
if (row.types.length === 0)
|
|
3760
|
+
return [];
|
|
3761
|
+
const types = [...row.types];
|
|
3762
|
+
const last = types.length - 1;
|
|
3763
|
+
if (row.default !== void 0)
|
|
3764
|
+
types[last] = `${types[last]}, default ${row.default}`;
|
|
3765
|
+
if (row.description !== void 0)
|
|
3766
|
+
types[last] = `${types[last]}.`;
|
|
3767
|
+
const lines = [];
|
|
3768
|
+
appendPieces(lines, types, " | ", "| ", width);
|
|
3769
|
+
if (row.description !== void 0)
|
|
3770
|
+
appendPieces(lines, row.description.split(/\s+/u).filter(Boolean), " ", "", width);
|
|
3771
|
+
return lines;
|
|
3772
|
+
}
|
|
3773
|
+
function appendPieces(lines, pieces, separator, continuation, width) {
|
|
3774
|
+
for (const piece of pieces) {
|
|
3775
|
+
const current = lines.at(-1);
|
|
3776
|
+
if (current === void 0)
|
|
3777
|
+
lines.push(piece);
|
|
3778
|
+
else if (current.length + separator.length + piece.length <= width)
|
|
3779
|
+
lines[lines.length - 1] = current + separator + piece;
|
|
3780
|
+
else
|
|
3781
|
+
lines.push(`${continuation}${piece}`);
|
|
3782
|
+
}
|
|
3783
|
+
}
|
|
3784
|
+
function exitCodeLegend(outcomes, width) {
|
|
3785
|
+
const kindsOf = (exitCode) => new Set(outcomes.filter((outcome) => outcome.exitCode === exitCode).map(({ kind }) => kind));
|
|
3786
|
+
const rows = [];
|
|
3787
|
+
if (kindsOf(0).size > 0)
|
|
3788
|
+
rows.push({ label: "0", text: EXIT_CODE_MEANINGS[0] });
|
|
3789
|
+
const one = kindsOf(1);
|
|
3790
|
+
if (one.size > 0)
|
|
3791
|
+
rows.push({
|
|
3792
|
+
label: "1",
|
|
3793
|
+
text: EXIT_CODE_MEANINGS[1][one.size === 2 ? "both" : one.has("result") ? "result" : "error"]
|
|
3794
|
+
});
|
|
3795
|
+
if (kindsOf(2).size > 0)
|
|
3796
|
+
rows.push({ label: "2", text: EXIT_CODE_MEANINGS[2] });
|
|
3797
|
+
if (kindsOf(130).size > 0)
|
|
3798
|
+
rows.push({ label: "130", text: EXIT_CODE_MEANINGS[130] });
|
|
3799
|
+
return ["Exit codes:", ...formatRows2(rows, width)].join("\n");
|
|
3800
|
+
}
|
|
3801
|
+
function fieldRows(schema, skipped = /* @__PURE__ */ new Set()) {
|
|
3802
|
+
return (objectFields(schema) ?? []).filter(({ name }) => !skipped.has(name)).flatMap((field) => {
|
|
3803
|
+
const items = arrayItems(field.schema);
|
|
3804
|
+
const children2 = objectFields(field.schema) ?? (items === void 0 ? void 0 : objectFields(items));
|
|
3805
|
+
return [fieldRow(field, 0), ...(children2 ?? []).map((child) => fieldRow(child, 1))];
|
|
3806
|
+
});
|
|
3807
|
+
}
|
|
3808
|
+
function fieldRow({ name, schema, required }, depth) {
|
|
3809
|
+
return {
|
|
3810
|
+
depth,
|
|
3811
|
+
label: required ? name : `${name}?`,
|
|
3812
|
+
types: typeMembers(schema),
|
|
3813
|
+
...Object.hasOwn(schema, "default") ? { default: JSON.stringify(schema.default) } : {},
|
|
3814
|
+
...typeof schema.description === "string" ? { description: schema.description } : {}
|
|
3815
|
+
};
|
|
3816
|
+
}
|
|
3817
|
+
function objectFields(schema) {
|
|
3818
|
+
const members = unionMembers(schema).filter((member) => member.type !== "null");
|
|
3819
|
+
const objects = members.flatMap((member) => {
|
|
3820
|
+
const properties = member.properties;
|
|
3821
|
+
return member.type === "object" && isSchema2(properties) ? [{ member, properties }] : [];
|
|
3822
|
+
});
|
|
3823
|
+
if (objects.length === 0 || objects.length !== members.length)
|
|
3824
|
+
return void 0;
|
|
3825
|
+
const names = [...new Set(objects.flatMap(({ properties }) => Object.keys(properties)))];
|
|
3826
|
+
return names.map((name) => {
|
|
3827
|
+
const variants = distinct(objects.flatMap(({ properties }) => {
|
|
3828
|
+
const property = properties[name];
|
|
3829
|
+
return isSchema2(property) ? [property] : [];
|
|
3830
|
+
}));
|
|
3831
|
+
const [only] = variants;
|
|
3832
|
+
return {
|
|
3833
|
+
name,
|
|
3834
|
+
schema: variants.length === 1 && only !== void 0 ? only : { anyOf: variants },
|
|
3835
|
+
required: objects.every(({ member }) => Array.isArray(member.required) && member.required.includes(name))
|
|
3836
|
+
};
|
|
3837
|
+
});
|
|
3838
|
+
}
|
|
3839
|
+
function unionMembers(schema) {
|
|
3840
|
+
const members = schema.anyOf ?? schema.oneOf;
|
|
3841
|
+
return Array.isArray(members) ? members.filter(isSchema2).flatMap(unionMembers) : [schema];
|
|
3842
|
+
}
|
|
3843
|
+
function arrayItems(schema) {
|
|
3844
|
+
return schema.type === "array" && isSchema2(schema.items) ? schema.items : void 0;
|
|
3845
|
+
}
|
|
3846
|
+
function typeMembers(schema) {
|
|
3847
|
+
if (typeof schema.$ref === "string")
|
|
3848
|
+
return ["object"];
|
|
3849
|
+
if (Object.hasOwn(schema, "const"))
|
|
3850
|
+
return [JSON.stringify(schema.const)];
|
|
3851
|
+
if (Array.isArray(schema.enum))
|
|
3852
|
+
return schema.enum.map((value) => JSON.stringify(value));
|
|
3853
|
+
const members = schema.anyOf ?? schema.oneOf;
|
|
3854
|
+
if (Array.isArray(members))
|
|
3855
|
+
return [...new Set(members.filter(isSchema2).flatMap(typeMembers))];
|
|
3856
|
+
const types = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
3857
|
+
return [...new Set(types.map((type) => typeName(type, schema)))];
|
|
3858
|
+
}
|
|
3859
|
+
function typeSummary(schema) {
|
|
3860
|
+
return typeMembers(schema).join(" | ");
|
|
3861
|
+
}
|
|
3862
|
+
function typeName(type, schema) {
|
|
3863
|
+
switch (type) {
|
|
3864
|
+
case "string":
|
|
3865
|
+
case "number":
|
|
3866
|
+
case "integer":
|
|
3867
|
+
case "boolean":
|
|
3868
|
+
case "null":
|
|
3869
|
+
case "object":
|
|
3870
|
+
return type;
|
|
3871
|
+
case "array": {
|
|
3872
|
+
if (Array.isArray(schema.prefixItems)) {
|
|
3873
|
+
const elements = schema.prefixItems.filter(isSchema2).map(typeSummary);
|
|
3874
|
+
if (isSchema2(schema.items))
|
|
3875
|
+
elements.push(`...${typeSummary(schema.items)}[]`);
|
|
3876
|
+
return `[${elements.join(", ")}]`;
|
|
3877
|
+
}
|
|
3878
|
+
const items = arrayItems(schema);
|
|
3879
|
+
if (items === void 0)
|
|
3880
|
+
return "array";
|
|
3881
|
+
const item = typeSummary(items);
|
|
3882
|
+
return item.includes(" | ") && !(item.startsWith("[") && Array.isArray(items.prefixItems)) ? `(${item})[]` : `${item}[]`;
|
|
3883
|
+
}
|
|
3884
|
+
default:
|
|
3885
|
+
return "unknown";
|
|
3886
|
+
}
|
|
3887
|
+
}
|
|
3888
|
+
function isSchema2(value) {
|
|
3889
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3890
|
+
}
|
|
3891
|
+
function distinct(schemas) {
|
|
3892
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3893
|
+
return schemas.filter((schema) => {
|
|
3894
|
+
const key = JSON.stringify(schema);
|
|
3895
|
+
if (seen.has(key))
|
|
3896
|
+
return false;
|
|
3897
|
+
seen.add(key);
|
|
3898
|
+
return true;
|
|
3899
|
+
});
|
|
3900
|
+
}
|
|
3901
|
+
|
|
3902
|
+
// ../../../libs/clinkr/ts/dist/terminal.js
|
|
3903
|
+
var PIPE = Object.freeze({ tty: false, columns: void 0, color: "none" });
|
|
3904
|
+
function createTerminal(facts = {}) {
|
|
3905
|
+
return Object.freeze({
|
|
3906
|
+
interactive: facts.interactive ?? false,
|
|
3907
|
+
unicode: facts.unicode ?? true,
|
|
3908
|
+
stdout: Object.freeze({ ...PIPE, ...facts.stdout }),
|
|
3909
|
+
stderr: Object.freeze({ ...PIPE, ...facts.stderr })
|
|
3910
|
+
});
|
|
3911
|
+
}
|
|
3912
|
+
function withoutColor(terminal) {
|
|
3913
|
+
return Object.freeze({
|
|
3914
|
+
...terminal,
|
|
3915
|
+
stdout: Object.freeze({ ...terminal.stdout, color: "none" }),
|
|
3916
|
+
stderr: Object.freeze({ ...terminal.stderr, color: "none" })
|
|
3917
|
+
});
|
|
3918
|
+
}
|
|
3919
|
+
function scriptReadsStdout(terminal) {
|
|
3920
|
+
return !terminal.stdout.tty || !terminal.interactive;
|
|
3921
|
+
}
|
|
3922
|
+
function resolveColorDepth(facts) {
|
|
3923
|
+
const { env } = facts;
|
|
3924
|
+
const noColor = env["NO_COLOR"];
|
|
3925
|
+
if (noColor !== void 0 && noColor !== "")
|
|
3926
|
+
return "none";
|
|
3927
|
+
const forced = env["FORCE_COLOR"];
|
|
3928
|
+
if (forced !== void 0 && forced !== "") {
|
|
3929
|
+
if (forced === "0" || forced === "false")
|
|
3930
|
+
return "none";
|
|
3931
|
+
if (forced === "2")
|
|
3932
|
+
return "ansi256";
|
|
3933
|
+
if (forced === "3")
|
|
3934
|
+
return "truecolor";
|
|
3935
|
+
return "ansi16";
|
|
3936
|
+
}
|
|
3937
|
+
const term = env["TERM"];
|
|
3938
|
+
if (!facts.tty || term === "dumb")
|
|
3939
|
+
return "none";
|
|
3940
|
+
const colorterm = env["COLORTERM"];
|
|
3941
|
+
if (colorterm === "truecolor" || colorterm === "24bit")
|
|
3942
|
+
return "truecolor";
|
|
3943
|
+
if (term !== void 0 && term.includes("256color"))
|
|
3944
|
+
return "ansi256";
|
|
3945
|
+
return "ansi16";
|
|
3946
|
+
}
|
|
3947
|
+
function resolveUnicode(env) {
|
|
3948
|
+
const locale = [env["LC_ALL"], env["LC_CTYPE"], env["LANG"]].find((value) => value !== void 0 && value !== "");
|
|
3949
|
+
if (locale === void 0)
|
|
3950
|
+
return true;
|
|
3951
|
+
return /utf-?8/iu.test(locale);
|
|
3952
|
+
}
|
|
3953
|
+
|
|
3954
|
+
// ../../../libs/clinkr/ts/dist/outcomes/run.js
|
|
3955
|
+
async function runOutcomeCommand(selection, command, options) {
|
|
3956
|
+
let outcome;
|
|
3957
|
+
try {
|
|
3958
|
+
const ran = await run(selection, command, options);
|
|
3959
|
+
if (typeof ran === "string")
|
|
3960
|
+
return { stdout: ran, stderr: "", status: 0 };
|
|
3961
|
+
outcome = ran;
|
|
3962
|
+
} catch (cause) {
|
|
3963
|
+
outcome = internalError(cause);
|
|
3964
|
+
}
|
|
3965
|
+
const commandPath = [options.applicationName, ...selection.path];
|
|
3966
|
+
try {
|
|
3967
|
+
return await present(outcome, commandPath, options);
|
|
3968
|
+
} catch (cause) {
|
|
3969
|
+
return await present(internalError(cause), commandPath, { ...options, ui: plainUi });
|
|
3970
|
+
}
|
|
3971
|
+
}
|
|
3972
|
+
async function run(selection, command, options) {
|
|
3973
|
+
const prepared = await prepareLeafRequest(command, selection.argv, options);
|
|
3974
|
+
switch (prepared.kind) {
|
|
3975
|
+
case "help": {
|
|
3976
|
+
const prefix = [options.applicationName, ...selection.path].join(" ");
|
|
3977
|
+
const { description } = selection.command.metadata;
|
|
3978
|
+
if (prepared.outcomes) {
|
|
3979
|
+
const catalog = outcomeCatalog(selection.path, command.outcomes, { confirms: command.confirms === true });
|
|
3980
|
+
if (options.json)
|
|
3981
|
+
return formatJsonOutput(catalog.document, options.terminal.stdout.tty);
|
|
3982
|
+
return formatOutcomeCatalog(catalog, formatLeafUsage(prefix, command), options.helpWidth);
|
|
3983
|
+
}
|
|
3984
|
+
return formatLeafHelp(prefix, description, command, options.helpWidth);
|
|
3985
|
+
}
|
|
3986
|
+
case "schema":
|
|
3987
|
+
return formatJsonOutput(describeCommand(selection.path, command), options.terminal.stdout.tty);
|
|
3988
|
+
case "failure":
|
|
3989
|
+
return refusal(prepared.failure);
|
|
3990
|
+
case "request":
|
|
3991
|
+
return executeResolved(command, prepared.candidate, {
|
|
3992
|
+
signal: options.signal,
|
|
3993
|
+
elicitor: options.inputJson || options.json ? void 0 : options.elicitor,
|
|
3994
|
+
progress: options.json ? void 0 : options.stderr,
|
|
3995
|
+
app: options.app,
|
|
3996
|
+
invocation: options.invocation
|
|
3997
|
+
});
|
|
3998
|
+
}
|
|
3999
|
+
}
|
|
4000
|
+
function refusal(failure2) {
|
|
4001
|
+
switch (failure2.kind) {
|
|
4002
|
+
case "input-json-with-arguments":
|
|
4003
|
+
return invalidArguments("--input-json cannot be combined with command arguments or --json-schema.");
|
|
4004
|
+
case "schema-not-alone":
|
|
4005
|
+
return invalidArguments("--json-schema must be the only command argument.");
|
|
4006
|
+
case "canceled":
|
|
4007
|
+
return canceledBy(failure2.cause);
|
|
4008
|
+
case "missing-input-reader":
|
|
4009
|
+
return invalidArguments("--input-json needs a host stdin reader.");
|
|
4010
|
+
case "unreadable-input":
|
|
4011
|
+
return invalidArguments("Unable to read JSON input from stdin.");
|
|
4012
|
+
case "not-json-object":
|
|
4013
|
+
return invalidArguments("--input-json needs one JSON object on stdin.");
|
|
4014
|
+
case "unknown-fields":
|
|
4015
|
+
return invalidArguments("Invalid arguments.", failure2.fields.map((field) => ({ field, message: "Unknown request field" })));
|
|
4016
|
+
case "argv-projection":
|
|
4017
|
+
return invalidArguments(sentence(failure2.error.message));
|
|
4018
|
+
}
|
|
4019
|
+
}
|
|
4020
|
+
async function present(outcome, commandPath, options) {
|
|
4021
|
+
if (outcome.kind === "result") {
|
|
4022
|
+
const status = outcome.exitCode;
|
|
4023
|
+
const rendered = outcome.render({ app: await options.app() });
|
|
4024
|
+
if (options.json)
|
|
4025
|
+
return {
|
|
4026
|
+
stdout: formatJsonOutput(documentFrom(outcome, rendered.content), options.terminal.stdout.tty),
|
|
4027
|
+
stderr: "",
|
|
4028
|
+
status
|
|
4029
|
+
};
|
|
4030
|
+
const { terminal } = options;
|
|
4031
|
+
const drawn = rendered.draw(terminal);
|
|
4032
|
+
const stdout = scriptReadsStdout(terminal) ? presentContent(rendered.content, { stdoutTerminal: terminal.stdout.tty, doneOnStdout: true }).stdout : drawn.answer ?? "";
|
|
4033
|
+
return { stdout, stderr: drawn.report, status };
|
|
4034
|
+
}
|
|
4035
|
+
return {
|
|
4036
|
+
stdout: "",
|
|
4037
|
+
...presentErrorOutput(outcome, { json: options.json, helpPath: commandPath, ui: options.ui })
|
|
4038
|
+
};
|
|
4039
|
+
}
|
|
4040
|
+
function sentence(message) {
|
|
4041
|
+
return /[.!?]$/u.test(message) ? message : `${message}.`;
|
|
4042
|
+
}
|
|
4043
|
+
|
|
4044
|
+
// ../../../libs/clinkr/ts/dist/run-cli.js
|
|
4045
|
+
var InvocationError = class extends Error {
|
|
4046
|
+
error;
|
|
4047
|
+
selection;
|
|
4048
|
+
constructor(error, selection) {
|
|
4049
|
+
super(error.content.message);
|
|
4050
|
+
this.name = "InvocationError";
|
|
4051
|
+
this.error = error;
|
|
4052
|
+
this.selection = selection;
|
|
4053
|
+
}
|
|
4054
|
+
};
|
|
4055
|
+
function invalidInvocation(message, selection) {
|
|
4056
|
+
return new InvocationError(invalidArguments(sentence2(message)), selection);
|
|
4057
|
+
}
|
|
4058
|
+
async function runCliWith(application, argv, stdout, stderr, options) {
|
|
4059
|
+
const helpWidth = options.helpWidth ?? DEFAULT_HELP_WIDTH;
|
|
4060
|
+
if (typeof helpWidth !== "number" || !Number.isSafeInteger(helpWidth) || helpWidth <= 0) {
|
|
4061
|
+
throw new TypeError(`helpWidth must be a positive safe integer; received ${String(helpWidth)}`);
|
|
4062
|
+
}
|
|
4063
|
+
if (argv[0] === "sys" && argv[1] === "__complete") {
|
|
4064
|
+
return runCompletion(application, argv.slice(2), stdout, stderr, { app: options.app, signal: options.signal });
|
|
4065
|
+
}
|
|
4066
|
+
const output = await runInvocation(application, argv, {
|
|
4067
|
+
signal: options.signal,
|
|
4068
|
+
elicitor: options.elicitor,
|
|
4069
|
+
inputReader: options.inputReader,
|
|
4070
|
+
app: options.app,
|
|
4071
|
+
helpWidth,
|
|
4072
|
+
terminal: options.terminal ?? createTerminal(),
|
|
4073
|
+
stderr
|
|
4074
|
+
});
|
|
4075
|
+
if (output.channel === "both") {
|
|
4076
|
+
await writeMessage(stdout, output.stdout);
|
|
4077
|
+
await writeMessage(stderr, output.stderr);
|
|
4078
|
+
return output.status;
|
|
4079
|
+
}
|
|
4080
|
+
await writeMessage(output.channel === "stdout" ? stdout : stderr, output.text);
|
|
4081
|
+
return output.status;
|
|
4082
|
+
}
|
|
4083
|
+
async function writeMessage(writer, text) {
|
|
4084
|
+
if (text.replace(/[\r\n]+$/u, "") !== "")
|
|
4085
|
+
await writer.write(frame(text));
|
|
4086
|
+
}
|
|
4087
|
+
async function runInvocation(application, argv, host) {
|
|
4088
|
+
const machine = hasGlobalFlag(argv, "--json");
|
|
4089
|
+
const terminal = hasGlobalFlag(argv, "--no-color") ? withoutColor(host.terminal) : host.terminal;
|
|
4090
|
+
let ui = plainUi;
|
|
4091
|
+
try {
|
|
4092
|
+
ui = { ...plainUi, ...application.ui?.(terminal) };
|
|
4093
|
+
const options = { ...host, terminal, ui };
|
|
4094
|
+
const parsed = parseGlobalArgv(argv);
|
|
4095
|
+
if (application.version !== void 0 && parsed.argv[0] === VERSION_FLAG) {
|
|
4096
|
+
return await runRootVersion(application, application.version, parsed, options);
|
|
4097
|
+
}
|
|
4098
|
+
if (parsed.argv[0] === "sys")
|
|
4099
|
+
return runSystemCommand(application, parsed.argv.slice(1));
|
|
4100
|
+
const selection = await application.select(parsed.argv);
|
|
4101
|
+
return await runSelection(application, selection, parsed, options);
|
|
4102
|
+
} catch (error) {
|
|
4103
|
+
return await presentInvocationError(application, error, { machine, width: host.helpWidth, ui });
|
|
4104
|
+
}
|
|
4105
|
+
}
|
|
4106
|
+
async function runRootVersion(application, version, parsed, options) {
|
|
4107
|
+
const rest = parsed.argv.slice(1);
|
|
4108
|
+
const delimiter = rest.indexOf("--");
|
|
4109
|
+
const active = delimiter === -1 ? rest : rest.slice(0, delimiter);
|
|
4110
|
+
if (active.includes("-h") || active.includes("--help")) {
|
|
4111
|
+
const root = { kind: "group", path: [], group: void 0, available: application.commands };
|
|
4112
|
+
return runSelection(application, root, parsed, options);
|
|
4113
|
+
}
|
|
4114
|
+
if (parsed.inputJson)
|
|
4115
|
+
throw invalidInvocation("--input-json cannot be combined with --version");
|
|
4116
|
+
if (rest.length > 0)
|
|
4117
|
+
throw invalidInvocation("--version takes no arguments");
|
|
4118
|
+
const text = await versionText(version);
|
|
4119
|
+
return success(parsed.json ? formatJsonOutput({ version: text }, options.terminal.stdout.tty) : text);
|
|
4120
|
+
}
|
|
4121
|
+
async function versionText(version) {
|
|
4122
|
+
if (typeof version === "string")
|
|
4123
|
+
return version;
|
|
4124
|
+
const text = await version();
|
|
4125
|
+
if (typeof text !== "string" || !isSingleLineText(text))
|
|
4126
|
+
throw new Error("Application version function must return a nonempty single-line string without control characters");
|
|
4127
|
+
return text;
|
|
4128
|
+
}
|
|
4129
|
+
async function runSelection(application, selection, parsed, options) {
|
|
4130
|
+
const machine = parsed.json;
|
|
4131
|
+
switch (selection.kind) {
|
|
4132
|
+
case "group": {
|
|
4133
|
+
if (parsed.helpOutcomes)
|
|
4134
|
+
throw invalidInvocation("--outcomes applies to a command", selection);
|
|
4135
|
+
if (parsed.inputJson && !parsed.help) {
|
|
4136
|
+
const defaultCommand = await selectDefaultCommand(application, selection.path, selection.available);
|
|
4137
|
+
if (defaultCommand !== void 0)
|
|
4138
|
+
return runCommand(defaultCommand, machine, parsed.inputJson, application, options);
|
|
4139
|
+
}
|
|
4140
|
+
if (machine)
|
|
4141
|
+
return success(formatJsonOutput(await listCommands(application, selection.path), options.terminal.stdout.tty));
|
|
4142
|
+
const usage = await groupUsage(application, selection.path, selection.available, options.helpWidth, groupDescription(application, selection), "help");
|
|
4143
|
+
const logo = selection.path.length === 0 && !scriptReadsStdout(options.terminal) ? helpLogoOf(application, options.terminal) : void 0;
|
|
4144
|
+
return success(logo === void 0 ? usage : `${logo}
|
|
4145
|
+
|
|
4146
|
+
${usage}`);
|
|
4147
|
+
}
|
|
4148
|
+
case "not-found":
|
|
4149
|
+
throw invalidInvocation(unknownCommandMessage(selection, machine), selection);
|
|
4150
|
+
case "command":
|
|
4151
|
+
return runCommand(selection, machine, parsed.inputJson, application, options);
|
|
4152
|
+
}
|
|
4153
|
+
}
|
|
4154
|
+
function helpLogoOf(application, terminal) {
|
|
4155
|
+
if (application.helpLogo === void 0)
|
|
4156
|
+
return void 0;
|
|
4157
|
+
let logo;
|
|
4158
|
+
try {
|
|
4159
|
+
logo = application.helpLogo(terminal);
|
|
4160
|
+
} catch {
|
|
4161
|
+
return void 0;
|
|
4162
|
+
}
|
|
4163
|
+
if (typeof logo !== "string" || logo.trim() === "")
|
|
4164
|
+
return void 0;
|
|
4165
|
+
return logo.replace(/(?:\r?\n)+$/u, "");
|
|
4166
|
+
}
|
|
4167
|
+
function unknownCommandMessage(selection, machine) {
|
|
4168
|
+
const message = `Unknown command: ${selection.path.join(" ")}`;
|
|
4169
|
+
if (machine)
|
|
4170
|
+
return message;
|
|
4171
|
+
const unknown = selection.path[selection.path.length - 1];
|
|
4172
|
+
const suggestions = suggestCommandNames(unknown, selection.available.filter(isListed).map((node) => node.name));
|
|
4173
|
+
return suggestions.length === 0 ? message : `${message}; did you mean ${joinAlternatives(suggestions)}?`;
|
|
4174
|
+
}
|
|
4175
|
+
async function runCommand(selection, machine, inputJson, application, options) {
|
|
4176
|
+
const loaded = await selection.load();
|
|
4177
|
+
const invocation = inputJson ? void 0 : Object.freeze({
|
|
4178
|
+
argv: Object.freeze([application.name, ...selection.path, ...selection.argv]),
|
|
4179
|
+
json: machine
|
|
4180
|
+
});
|
|
4181
|
+
const output = await runOutcomeCommand(selection, loaded, {
|
|
4182
|
+
applicationName: application.name,
|
|
4183
|
+
json: machine,
|
|
4184
|
+
inputJson,
|
|
4185
|
+
helpWidth: options.helpWidth,
|
|
4186
|
+
terminal: options.terminal,
|
|
4187
|
+
ui: options.ui,
|
|
4188
|
+
signal: options.signal,
|
|
4189
|
+
elicitor: options.elicitor,
|
|
4190
|
+
invocation,
|
|
4191
|
+
inputReader: options.inputReader,
|
|
4192
|
+
app: options.app,
|
|
4193
|
+
stderr: options.stderr
|
|
4194
|
+
});
|
|
4195
|
+
return { channel: "both", ...output };
|
|
4196
|
+
}
|
|
4197
|
+
function runSystemCommand(application, argv) {
|
|
4198
|
+
if (argv.length === 0 || argv.length === 1 && argv[0] === "--help") {
|
|
4199
|
+
return success(`Usage: ${application.name} sys completion <bash|zsh|fish>
|
|
4200
|
+
|
|
4201
|
+
Print a shell completion setup script.`);
|
|
4202
|
+
}
|
|
4203
|
+
if (argv[0] !== "completion" || argv.length !== 2 || !["bash", "zsh", "fish"].includes(argv[1])) {
|
|
4204
|
+
throw invalidInvocation(`Unknown sys command: ${argv.join(" ")}`);
|
|
4205
|
+
}
|
|
4206
|
+
return success(renderCompletionScript({
|
|
4207
|
+
commandName: application.name,
|
|
4208
|
+
shell: argv[1]
|
|
4209
|
+
}));
|
|
4210
|
+
}
|
|
4211
|
+
async function runCompletion(application, argv, stdout, stderr, host) {
|
|
4212
|
+
if (argv[0] !== "--" || argv.length < 2) {
|
|
4213
|
+
await stderr.write(`${presentError({ message: "Usage: sys __complete -- <words...>", rows: [], next: [], rowLimit: void 0 })}
|
|
4214
|
+
`);
|
|
4215
|
+
return 2;
|
|
4216
|
+
}
|
|
4217
|
+
const result = await resolveCompletionResolved(application, {
|
|
4218
|
+
words: argv.slice(1),
|
|
4219
|
+
app: host.app,
|
|
4220
|
+
signal: host.signal
|
|
4221
|
+
});
|
|
4222
|
+
if (result.candidates.length > 0)
|
|
4223
|
+
await stdout.write(`${result.candidates.join("\n")}
|
|
4224
|
+
`);
|
|
4225
|
+
if (result.diagnostics.length > 0) {
|
|
4226
|
+
await stderr.write(`${result.diagnostics.join("\n")}
|
|
4227
|
+
`);
|
|
4228
|
+
return 2;
|
|
4229
|
+
}
|
|
4230
|
+
if (result.providerDiagnostics?.length) {
|
|
4231
|
+
await stderr.write(`${result.providerDiagnostics.join("\n")}
|
|
4232
|
+
`);
|
|
4233
|
+
}
|
|
4234
|
+
return 0;
|
|
4235
|
+
}
|
|
4236
|
+
function success(text) {
|
|
4237
|
+
return { channel: "stdout", text, status: 0 };
|
|
4238
|
+
}
|
|
4239
|
+
function hasGlobalFlag(argv, flag) {
|
|
4240
|
+
for (const token of argv) {
|
|
4241
|
+
if (token === "--")
|
|
4242
|
+
return false;
|
|
4243
|
+
if (token === flag)
|
|
4244
|
+
return true;
|
|
4245
|
+
}
|
|
4246
|
+
return false;
|
|
4247
|
+
}
|
|
4248
|
+
function parseGlobalArgv(argv) {
|
|
4249
|
+
const commandArgv = [];
|
|
4250
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4251
|
+
let beforeDelimiter = true;
|
|
4252
|
+
for (const token of argv) {
|
|
4253
|
+
if (beforeDelimiter && token === "--") {
|
|
4254
|
+
beforeDelimiter = false;
|
|
4255
|
+
commandArgv.push(token);
|
|
4256
|
+
continue;
|
|
4257
|
+
}
|
|
4258
|
+
if (beforeDelimiter && isGloballyParsedFlag(token)) {
|
|
4259
|
+
if (seen.has(token))
|
|
4260
|
+
throw invalidInvocation(`Duplicate global option: ${token}`);
|
|
4261
|
+
seen.add(token);
|
|
4262
|
+
continue;
|
|
4263
|
+
}
|
|
4264
|
+
commandArgv.push(token);
|
|
4265
|
+
}
|
|
4266
|
+
const delimiter = commandArgv.indexOf("--");
|
|
4267
|
+
const active = delimiter === -1 ? commandArgv : commandArgv.slice(0, delimiter);
|
|
4268
|
+
const help = active.includes("-h") || active.includes("--help");
|
|
4269
|
+
const helpOutcomes = help && active.includes("--outcomes");
|
|
4270
|
+
return { argv: commandArgv, json: seen.has("--json"), inputJson: seen.has("--input-json"), help, helpOutcomes };
|
|
4271
|
+
}
|
|
4272
|
+
async function presentInvocationError(application, thrown, { machine, width, ui }) {
|
|
4273
|
+
const failure2 = thrown instanceof InvocationError ? thrown : new InvocationError(clinkrErrorFrom(thrown, { aborted: false }));
|
|
4274
|
+
const { error, selection } = failure2;
|
|
4275
|
+
const helpPath = [application.name, ...helpPathOf(selection)];
|
|
4276
|
+
let usage;
|
|
4277
|
+
if (!machine && error.reason === "invalid_arguments") {
|
|
4278
|
+
try {
|
|
4279
|
+
usage = await contextualUsage(application, selection, width);
|
|
4280
|
+
} catch (usageError) {
|
|
4281
|
+
return errorOutput(clinkrErrorFrom(usageError, { aborted: false }), { json: false, helpPath, ui: plainUi });
|
|
4282
|
+
}
|
|
4283
|
+
}
|
|
4284
|
+
return errorOutput(error, { json: machine, helpPath, usage, ui });
|
|
4285
|
+
}
|
|
4286
|
+
function errorOutput(error, options) {
|
|
4287
|
+
const { stderr, status } = presentErrorOutput(error, options);
|
|
4288
|
+
return { channel: "stderr", text: stderr, status };
|
|
4289
|
+
}
|
|
4290
|
+
function helpPathOf(selection) {
|
|
4291
|
+
if (selection === void 0)
|
|
4292
|
+
return [];
|
|
4293
|
+
return selection.kind === "not-found" ? selection.path.slice(0, -1) : selection.path;
|
|
4294
|
+
}
|
|
4295
|
+
function sentence2(message) {
|
|
4296
|
+
return /[.!?]$/u.test(message) ? message : `${message}.`;
|
|
4297
|
+
}
|
|
4298
|
+
async function contextualUsage(application, selection, width) {
|
|
4299
|
+
if (selection === void 0) {
|
|
4300
|
+
return groupUsage(application, [], application.commands, width, application.description, "diagnostic");
|
|
4301
|
+
}
|
|
4302
|
+
if (selection.kind === "not-found") {
|
|
4303
|
+
const path = selection.path.slice(0, -1);
|
|
4304
|
+
const description2 = path.length === 0 ? application.description : void 0;
|
|
4305
|
+
return groupUsage(application, path, selection.available, width, description2, "diagnostic");
|
|
4306
|
+
}
|
|
4307
|
+
const description = groupDescription(application, selection);
|
|
4308
|
+
return groupUsage(application, selection.path, selection.available, width, description, "diagnostic");
|
|
4309
|
+
}
|
|
4310
|
+
async function defaultUsageTails(application, path, commands, purpose) {
|
|
4311
|
+
const loading = loadDefaultCommand(application, path, commands);
|
|
4312
|
+
const loaded = purpose === "help" ? await loading : await loading.catch(() => void 0);
|
|
4313
|
+
if (loaded === void 0)
|
|
4314
|
+
return [];
|
|
4315
|
+
const { selection, command } = loaded;
|
|
4316
|
+
const { name } = selection.command;
|
|
4317
|
+
const tails = purpose === "help" ? formatLeafUsageTails([application.name, ...selection.path].join(" "), command) : leafUsageTails(command, argvUsageUnits(command));
|
|
4318
|
+
return tails.map((tail) => `[${name}]${tail === "" ? "" : ` ${tail}`}`);
|
|
4319
|
+
}
|
|
4320
|
+
function argvUsageUnits(command) {
|
|
4321
|
+
try {
|
|
4322
|
+
return formatArgvUsageUnits(command, command.help?.fields);
|
|
4323
|
+
} catch {
|
|
4324
|
+
return formatArgvUsageUnits(command);
|
|
4325
|
+
}
|
|
4326
|
+
}
|
|
4327
|
+
async function loadDefaultCommand(application, path, commands) {
|
|
4328
|
+
const selection = await selectDefaultCommand(application, path, commands);
|
|
4329
|
+
return selection === void 0 ? void 0 : { selection, command: await selection.load() };
|
|
4330
|
+
}
|
|
4331
|
+
function groupDescription(application, selection) {
|
|
4332
|
+
return selection.group?.metadata.description ?? (selection.path.length === 0 ? application.description : void 0);
|
|
4333
|
+
}
|
|
4334
|
+
async function groupUsage(application, path, commands, width, description, purpose) {
|
|
4335
|
+
const defaultTails = await defaultUsageTails(application, path, commands, purpose);
|
|
4336
|
+
const blocks = [formatUsageBlock([application.name, ...path].join(" "), ["<command>", ...defaultTails])];
|
|
4337
|
+
if (description !== void 0)
|
|
4338
|
+
blocks.push(wrapParagraph(description, width, 0));
|
|
4339
|
+
for (const [section2, rows] of groupListing(application, commands)) {
|
|
4340
|
+
blocks.push([`${section2}:`, ...formatRows2(rows, width)].join("\n"));
|
|
4341
|
+
}
|
|
4342
|
+
if (path.length === 0) {
|
|
4343
|
+
blocks.push(rootGlobalOptionsBlock(application.version !== void 0, width).join("\n"));
|
|
4344
|
+
if (commands.some((node) => node.kind === "group" && node.name === SKILLS_GROUP_NAME))
|
|
4345
|
+
blocks.push(wrapParagraph(`Agents: run \`${application.name} ${SKILLS_GROUP_NAME} get\`.`, width, 0));
|
|
4346
|
+
}
|
|
4347
|
+
return blocks.join("\n\n");
|
|
4348
|
+
}
|
|
4349
|
+
var ROOT_GLOBAL_OPTIONS = [
|
|
4350
|
+
{ label: "-h, --help", text: "Show help." },
|
|
4351
|
+
{ label: "--json", text: "Print JSON output; with help, list commands as JSON." },
|
|
4352
|
+
{ label: "--input-json", text: "Read a command's request as one JSON object from stdin." },
|
|
4353
|
+
{ label: "--no-color", text: "Print without color." }
|
|
4354
|
+
];
|
|
4355
|
+
var VERSION_OPTION = { label: VERSION_FLAG, text: "Print the version." };
|
|
4356
|
+
function rootGlobalOptionsBlock(hasVersion, width) {
|
|
4357
|
+
const rows = hasVersion ? [...ROOT_GLOBAL_OPTIONS, VERSION_OPTION] : ROOT_GLOBAL_OPTIONS;
|
|
4358
|
+
return ["Global options:", ...formatRows2(rows, width)];
|
|
4359
|
+
}
|
|
4360
|
+
function groupListing(application, commands) {
|
|
4361
|
+
const unsectioned = [];
|
|
4362
|
+
const sectioned = new Map((application.helpSections ?? []).map((section2) => [section2, []]));
|
|
4363
|
+
const defaultCommand = defaultCommandOf(commands);
|
|
4364
|
+
for (const command of commands.filter(isListed)) {
|
|
4365
|
+
const row = {
|
|
4366
|
+
label: `${[command.name, ...commandAliases(command)].join(", ")}${command === defaultCommand ? " (default)" : ""}`,
|
|
4367
|
+
text: command.metadata.summary ?? command.metadata.description
|
|
4368
|
+
};
|
|
4369
|
+
const section2 = command.metadata.helpSection;
|
|
4370
|
+
if (section2 === void 0) {
|
|
4371
|
+
unsectioned.push(row);
|
|
4372
|
+
continue;
|
|
4373
|
+
}
|
|
4374
|
+
const rows = sectioned.get(section2);
|
|
4375
|
+
if (rows === void 0)
|
|
4376
|
+
throw new Error(`Command ${command.name} uses undeclared help section ${JSON.stringify(section2)}`);
|
|
4377
|
+
rows.push(row);
|
|
4378
|
+
}
|
|
4379
|
+
const listing = [["Commands", unsectioned], ...sectioned];
|
|
4380
|
+
return listing.filter(([, rows]) => rows.length > 0);
|
|
4381
|
+
}
|
|
4382
|
+
|
|
4383
|
+
// src/sdk/extension/commands.ts
|
|
4384
|
+
import { join as join5 } from "node:path";
|
|
4385
|
+
function defineExtensionCommands(definition) {
|
|
4386
|
+
const { extension, description, tree, directory, app } = definition;
|
|
4387
|
+
return {
|
|
4388
|
+
extension,
|
|
4389
|
+
description,
|
|
4390
|
+
directory,
|
|
4391
|
+
mount: ({ path, root }) => mount(tree.directory(join5(root, directory)), { path, description, app })
|
|
4392
|
+
};
|
|
4393
|
+
}
|
|
4394
|
+
function defineExtension(extension) {
|
|
4395
|
+
return extension;
|
|
4396
|
+
}
|
|
4397
|
+
|
|
4398
|
+
// src/extensions/testserver/commands/tree.ts
|
|
4399
|
+
var testserverCommands = commandTree({ id: "testserver" });
|
|
4400
|
+
|
|
4401
|
+
export {
|
|
4402
|
+
appSourceOf,
|
|
4403
|
+
lazyAppSource,
|
|
4404
|
+
stepDocument,
|
|
4405
|
+
renderOutcome,
|
|
4406
|
+
defineErrors,
|
|
4407
|
+
defineOutcomes,
|
|
4408
|
+
INVALID_VALUE,
|
|
4409
|
+
CLINKR_PARSE_PARAMS,
|
|
4410
|
+
createTerminal,
|
|
4411
|
+
resolveColorDepth,
|
|
4412
|
+
resolveUnicode,
|
|
4413
|
+
commandTree,
|
|
4414
|
+
runCliWith,
|
|
4415
|
+
createApplication,
|
|
4416
|
+
refused,
|
|
4417
|
+
defineExtensionCommands,
|
|
4418
|
+
defineExtension,
|
|
4419
|
+
testserverCommands
|
|
4420
|
+
};
|