@hop-top/kit 0.5.0-alpha.1 → 0.5.0-alpha.11
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/CHANGELOG.md +275 -0
- package/LICENSE +1 -1
- package/LICENSE-cobra.txt +174 -0
- package/NOTICE +15 -0
- package/README.md +55 -259
- package/dist/aim-DZHwwiIc.d.ts +139 -0
- package/dist/aim.d.ts +1 -116
- package/dist/aim.js +13 -414
- package/dist/alias-D9_qFlyP.d.ts +174 -0
- package/dist/alias.d.ts +2 -73
- package/dist/alias.js +27 -207
- package/dist/api-DAexsu2H.d.ts +77 -0
- package/dist/api.d.ts +1 -62
- package/dist/api.js +10 -164
- package/dist/auth-2-jfgiHn.d.ts +34 -0
- package/dist/auth.d.ts +1 -26
- package/dist/auth.js +6 -40
- package/dist/chunk-3FIKGFKI.js +54 -0
- package/dist/chunk-4FMALWYB.js +669 -0
- package/dist/chunk-4GPCWBBA.js +143 -0
- package/dist/chunk-4UE5TCMQ.js +104 -0
- package/dist/chunk-65VPWMPV.js +1134 -0
- package/dist/chunk-6HFAEZ52.js +29 -0
- package/dist/chunk-6SVOHNIC.js +17 -0
- package/dist/chunk-BDNNPRX6.js +41 -0
- package/dist/chunk-BRNEKPWX.js +37 -0
- package/dist/chunk-BXJ2J27B.js +219 -0
- package/dist/chunk-CSJWB6D3.js +151 -0
- package/dist/chunk-CXBZTONY.js +65 -0
- package/dist/chunk-EE4M2UOF.js +818 -0
- package/dist/chunk-GFRAYYRD.js +817 -0
- package/dist/chunk-IVQHLI56.js +1890 -0
- package/dist/chunk-IZ6Q4SE3.js +178 -0
- package/dist/chunk-JKMQSAJP.js +174 -0
- package/dist/chunk-K7E34Q3A.js +1445 -0
- package/dist/chunk-KVG7YCTS.js +115 -0
- package/dist/chunk-L23O2FFE.js +51 -0
- package/dist/chunk-MFVUENZR.js +1549 -0
- package/dist/chunk-ML7D5DWY.js +263 -0
- package/dist/chunk-MQXYDYRD.js +968 -0
- package/dist/chunk-POR5L2DG.js +247 -0
- package/dist/chunk-QJVSKKRQ.js +369 -0
- package/dist/chunk-QQQYCWSC.js +240 -0
- package/dist/chunk-R5U7XKVJ.js +16 -0
- package/dist/chunk-RYKLVOVK.js +309 -0
- package/dist/chunk-SNVGDYX7.js +187 -0
- package/dist/chunk-T6OZMPPV.js +68 -0
- package/dist/chunk-UKZIAQA7.js +26 -0
- package/dist/chunk-VGOA5Y7S.js +251 -0
- package/dist/chunk-VWGP4NVJ.js +513 -0
- package/dist/chunk-WBVO43HU.js +355 -0
- package/dist/chunk-WUOAQVOA.js +86 -0
- package/dist/chunk-XJTRY453.js +868 -0
- package/dist/chunk-YOBAUCVN.js +583 -0
- package/dist/cli-RSRk1M36.d.ts +707 -0
- package/dist/cli.d.ts +7 -309
- package/dist/cli.js +125 -945
- package/dist/completion-csVun6SP.d.ts +112 -0
- package/dist/completion-values-By-mnjNt.d.ts +142 -0
- package/dist/completion-values.d.ts +1 -0
- package/dist/completion-values.js +29 -0
- package/dist/completion.d.ts +3 -0
- package/dist/completion.js +34 -0
- package/dist/compliance-AxFf-uMy.d.ts +60 -0
- package/dist/compliance.d.ts +1 -0
- package/dist/compliance.js +17 -0
- package/dist/config-CaK60ByQ.d.ts +241 -0
- package/dist/config.d.ts +1 -97
- package/dist/config.js +8 -78
- package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
- package/dist/errcorrect.d.ts +1 -37
- package/dist/errcorrect.js +8 -68
- package/dist/error-Do8Qji43.d.ts +231 -0
- package/dist/id/index.d.ts +2 -83
- package/dist/id/index.js +14 -65
- package/dist/index-BKJZClJx.d.ts +1486 -0
- package/dist/index-C3Zw4wDJ.d.ts +359 -0
- package/dist/index-CGE5yLBj.d.ts +328 -0
- package/dist/index-VLDcI5NF.d.ts +95 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +132 -0
- package/dist/llm-DYuR7_uX.d.ts +1069 -0
- package/dist/llm-anthropic-Cd_I2xXB.d.ts +67 -0
- package/dist/llm-anthropic.d.ts +2 -0
- package/dist/llm-anthropic.js +13 -0
- package/dist/llm-openai-DyFrucmV.d.ts +87 -0
- package/dist/llm-openai.d.ts +2 -0
- package/dist/llm-openai.js +19 -0
- package/dist/llm.d.ts +1 -188
- package/dist/llm.js +101 -356
- package/dist/log-CkaxMX3U.d.ts +115 -0
- package/dist/log.d.ts +2 -0
- package/dist/log.js +14 -0
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/index.js +185 -0
- package/dist/netpolicy-Brx5XZUB.d.ts +151 -0
- package/dist/netpolicy.d.ts +1 -0
- package/dist/netpolicy.js +25 -0
- package/dist/output-CjZWmL8s.d.ts +420 -0
- package/dist/output.d.ts +3 -213
- package/dist/output.js +135 -447
- package/dist/parity-CvMuYcVI.d.ts +61 -0
- package/dist/progress-CAzyxeWl.d.ts +38 -0
- package/dist/progress.d.ts +1 -30
- package/dist/progress.js +6 -55
- package/dist/provenance-SMFHm5gx.d.ts +30 -0
- package/dist/provenance.d.ts +1 -24
- package/dist/provenance.js +6 -31
- package/dist/routellm-B0nv59mH.d.ts +111 -0
- package/dist/routellm.d.ts +2 -64
- package/dist/routellm.js +13 -255
- package/dist/rpc-D31Lg0Kc.d.ts +32 -0
- package/dist/rpc.d.ts +2 -25
- package/dist/rpc.js +4 -98
- package/dist/safety-CUaYEjZc.d.ts +30 -0
- package/dist/safety.d.ts +1 -24
- package/dist/safety.js +6 -43
- package/dist/scope-BrhYB4ij.d.ts +141 -0
- package/dist/scope.d.ts +1 -121
- package/dist/scope.js +20 -377
- package/dist/serve-D8yWMrTc.d.ts +646 -0
- package/dist/serve.d.ts +3 -0
- package/dist/serve.js +75 -0
- package/dist/sqlstore.js +6 -39
- package/dist/stream-CrjeCp0M.d.ts +44 -0
- package/dist/stream.d.ts +1 -35
- package/dist/stream.js +8 -51
- package/dist/telemetry/index.d.ts +1 -315
- package/dist/telemetry/index.js +26 -599
- package/dist/toolspec-DcPwwoAZ.d.ts +368 -0
- package/dist/toolspec.d.ts +2 -0
- package/dist/toolspec.js +37 -0
- package/dist/tui/index.d.ts +6 -298
- package/dist/tui/index.js +17 -381
- package/dist/upgrade-C3RWGwRi.d.ts +125 -0
- package/dist/upgrade.d.ts +1 -95
- package/dist/upgrade.js +6 -114
- package/dist/xdg-DB7Shoib.d.ts +179 -0
- package/dist/xdg.d.ts +1 -169
- package/dist/xdg.js +14 -128
- package/package.json +192 -24
- package/src/README.md +15 -0
- package/src/alias.conformance.test.ts +250 -0
- package/src/alias.test.ts +206 -2
- package/src/alias.ts +196 -21
- package/src/cli.help-command.test.ts +105 -0
- package/src/cli.offline.test.ts +93 -0
- package/src/cli.parity.test.ts +192 -0
- package/src/cli.root.conformance.test.ts +166 -0
- package/src/cli.test.ts +95 -1
- package/src/cli.ts +234 -25
- package/src/completion-scripts.ts +16 -0
- package/src/completion-values.test.ts +76 -16
- package/src/completion-values.ts +170 -66
- package/src/completion.conformance.test.ts +298 -0
- package/src/completion.test.ts +268 -145
- package/src/completion.ts +772 -121
- package/src/compliance.test.ts +196 -2
- package/src/compliance.ts +440 -20
- package/src/config-merge.test.ts +425 -0
- package/src/config.test.ts +228 -1
- package/src/config.ts +429 -16
- package/src/delegation.test.ts +299 -0
- package/src/delegation.ts +807 -0
- package/src/gen/crud_pb.ts +7 -7
- package/src/id/README.md +38 -0
- package/src/id/contract.test.ts +1 -1
- package/src/id/index.test.ts +1 -1
- package/src/id/index.ts +3 -2
- package/src/index.test.ts +71 -0
- package/src/index.ts +46 -0
- package/src/llm-anthropic.conformance.test.ts +1135 -0
- package/src/llm-anthropic.test.ts +152 -0
- package/src/llm-anthropic.ts +940 -0
- package/src/llm-choice-hermetic.test.ts +335 -0
- package/src/llm-config.test.ts +232 -0
- package/src/llm-config.ts +106 -0
- package/src/llm-endpoint.ts +254 -0
- package/src/llm-error.ts +17 -0
- package/src/llm-errors.ts +152 -0
- package/src/llm-file.ts +126 -0
- package/src/llm-http.ts +317 -0
- package/src/llm-keys.ts +167 -0
- package/src/llm-media.conformance.test.ts +87 -0
- package/src/llm-media.test.ts +279 -0
- package/src/llm-media.ts +322 -0
- package/src/llm-openai.conformance.test.ts +407 -0
- package/src/llm-openai.test.ts +510 -0
- package/src/llm-openai.ts +708 -0
- package/src/llm-payload.ts +155 -0
- package/src/llm-quote.ts +46 -0
- package/src/llm-routellm.conformance.test.ts +44 -0
- package/src/llm-toolnames.conformance.test.ts +112 -0
- package/src/llm-toolnames.test.ts +132 -0
- package/src/llm-toolnames.ts +298 -0
- package/src/llm-uri.ts +99 -0
- package/src/llm.test.ts +43 -15
- package/src/llm.toolcall.test.ts +175 -0
- package/src/llm.ts +602 -190
- package/src/log.parity.test.ts +105 -0
- package/src/log.test.ts +270 -1
- package/src/log.ts +228 -49
- package/src/mcp/README.md +63 -0
- package/src/mcp/args-separator.test.ts +164 -0
- package/src/mcp/args.test.ts +223 -0
- package/src/mcp/args.ts +160 -0
- package/src/mcp/audit.test.ts +520 -0
- package/src/mcp/audit.ts +70 -0
- package/src/mcp/bridge.test.ts +250 -0
- package/src/mcp/bridge.ts +286 -0
- package/src/mcp/conformance.test.ts +357 -0
- package/src/mcp/dispatch.ts +359 -0
- package/src/mcp/identity.test.ts +166 -0
- package/src/mcp/identity.ts +72 -0
- package/src/mcp/index.ts +176 -0
- package/src/mcp/legacy-notify.test.ts +59 -0
- package/src/mcp/legacy.ts +367 -0
- package/src/mcp/mcp.test.ts +707 -0
- package/src/mcp/modern-confirm.test.ts +520 -0
- package/src/mcp/modern-confirm.ts +484 -0
- package/src/mcp/modern.ts +788 -0
- package/src/mcp/stdio.test.ts +313 -0
- package/src/mcp/stdio.ts +254 -0
- package/src/mcp/tasks.ts +82 -0
- package/src/mcp/testtree.ts +250 -0
- package/src/mcp/toolname.test.ts +147 -0
- package/src/mcp/types.ts +689 -0
- package/src/netpolicy.test.ts +280 -0
- package/src/netpolicy.ts +256 -0
- package/src/output/README.md +46 -0
- package/src/output/builtins.ts +5 -5
- package/src/output/dispatch.ts +10 -2
- package/src/output/error.ts +459 -0
- package/src/output/formatter.ts +29 -5
- package/src/output/formatters/README.md +50 -0
- package/src/output/formatters/csv.ts +48 -12
- package/src/output/formatters/json.ts +4 -25
- package/src/output/formatters/project.ts +34 -0
- package/src/output/formatters/table.ts +8 -6
- package/src/output/formatters/text.ts +7 -3
- package/src/output/formatters/yaml.ts +5 -22
- package/src/output/projection.test.ts +298 -0
- package/src/output/projection.ts +33 -59
- package/src/output/template.ts +11 -21
- package/src/output.surface.test.ts +41 -0
- package/src/output.ts +64 -3
- package/src/plan.ts +89 -0
- package/src/policy.ts +472 -0
- package/src/published-types.test.ts +133 -0
- package/src/routellm.test.ts +209 -28
- package/src/routellm.toolcall.test.ts +521 -0
- package/src/routellm.ts +213 -177
- package/src/router/README.md +44 -0
- package/src/router/server.test.ts +41 -0
- package/src/router/server.ts +11 -0
- package/src/safety.test.ts +19 -9
- package/src/scope-defaults.json +29 -29
- package/src/serve.test.ts +1257 -0
- package/src/serve.ts +1665 -0
- package/src/sideeffect.ts +105 -0
- package/src/telemetry/README.md +48 -0
- package/src/telemetry/client.test.ts +31 -0
- package/src/telemetry/client.ts +12 -6
- package/src/telemetry/offline.test.ts +64 -0
- package/src/toolspec-internal.ts +279 -0
- package/src/toolspec-manifest.test.ts +167 -0
- package/src/toolspec-manifest.ts +415 -0
- package/src/toolspec-spec-schemas.ts +12 -0
- package/src/toolspec-spec.test.ts +273 -0
- package/src/toolspec-spec.ts +458 -0
- package/src/toolspec.from-command.test.ts +350 -0
- package/src/toolspec.test.ts +2 -2
- package/src/toolspec.ts +222 -0
- package/src/triton/README.md +34 -0
- package/src/tui/README.md +42 -0
- package/src/tui/parity.test.ts +120 -31
- package/src/tui/parity.ts +58 -7
- package/src/upgrade.test.ts +291 -0
- package/src/upgrade.ts +116 -7
- package/src/wizard.test.ts +7 -7
- package/test/llm/conformance-helpers.ts +100 -0
- package/test/output/csv.test.ts +164 -0
- package/test/output/dispatch.test.ts +1 -2
- package/test/output/error.test.ts +277 -0
- package/test/output/smoke-capture.ts +2 -2
- package/test/output/smoke.test.ts +2 -2
- package/test/output/taxonomy-contract.test.ts +148 -0
- package/test/setup-env.ts +16 -0
- package/test/toolspec/fixture.ts +79 -0
- package/tsconfig.json +3 -1
- package/tsconfig.test.json +10 -0
- package/vitest.config.ts +9 -0
- package/src/tui/parity.json +0 -74
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { C as Completer } from './completion-values-By-mnjNt.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @module completion
|
|
6
|
+
* @package @hop-top/kit
|
|
7
|
+
*
|
|
8
|
+
* Shell completion for Commander-based CLIs, in cobra's protocol so a
|
|
9
|
+
* TS kit CLI completes like a Go or Rust one
|
|
10
|
+
* (`contracts/completion-v1`, Go canonical):
|
|
11
|
+
*
|
|
12
|
+
* - `completion bash|zsh|fish|powershell [--no-descriptions]` writes
|
|
13
|
+
* cobra v1.10.2's scripts byte for byte ({@link completionCommand}).
|
|
14
|
+
* - The scripts call back into the hidden `__complete` /
|
|
15
|
+
* `__completeNoDesc` entry point. {@link installCompletionRequest}
|
|
16
|
+
* (done by `createCLI` and {@link completionCommand}) answers it
|
|
17
|
+
* before commander parses, so no hook or action runs on tab. It walks
|
|
18
|
+
* the live command tree: subcommands, aliases, each command's own and
|
|
19
|
+
* inherited flags, choices and the completers bound with
|
|
20
|
+
* {@link bindFlag} / {@link bindArgs}.
|
|
21
|
+
*
|
|
22
|
+
* Wire format: one completion per line (`value`, or
|
|
23
|
+
* `value<TAB>description`), then `:<directive>`; stderr carries
|
|
24
|
+
* `Completion ended with directive: <name>`. Exit code 0.
|
|
25
|
+
*
|
|
26
|
+
* Commander has no public accessor for a few facts read here; they are
|
|
27
|
+
* typed locally in {@link CommanderInternals} (commander 15).
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/** Name of the hidden command a shell script calls for completions. */
|
|
31
|
+
declare const REQUEST_CMD = "__complete";
|
|
32
|
+
/** Name of the hidden command that returns completions without descriptions. */
|
|
33
|
+
declare const NO_DESC_REQUEST_CMD = "__completeNoDesc";
|
|
34
|
+
/** A shell `completion` writes a script for. */
|
|
35
|
+
type Shell = 'bash' | 'zsh' | 'fish' | 'powershell';
|
|
36
|
+
/** Every shell, in the order the `completion` command lists them. */
|
|
37
|
+
declare const SHELLS: readonly Shell[];
|
|
38
|
+
/** The `completion <shell>` script for program `name`, cobra's byte for byte. */
|
|
39
|
+
declare function renderCompletionScript(shell: Shell, name: string, includeDescriptions?: boolean): string;
|
|
40
|
+
/** Generate a bash completion script (cobra V2; needs bash-completion). */
|
|
41
|
+
declare function generateBashCompletion(program: Command, includeDescriptions?: boolean): string;
|
|
42
|
+
/** Generate a zsh completion script for the given program. */
|
|
43
|
+
declare function generateZshCompletion(program: Command, includeDescriptions?: boolean): string;
|
|
44
|
+
/** Generate a fish completion script for the given program. */
|
|
45
|
+
declare function generateFishCompletion(program: Command, includeDescriptions?: boolean): string;
|
|
46
|
+
/** Generate a PowerShell completion script for the given program. */
|
|
47
|
+
declare function generatePowerShellCompletion(program: Command, includeDescriptions?: boolean): string;
|
|
48
|
+
/**
|
|
49
|
+
* cobra's `completion` command: `completion bash|zsh|fish|powershell
|
|
50
|
+
* [--no-descriptions]`, each printing the script to stdout. Add it to
|
|
51
|
+
* the program (kit puts it in the hidden `management` group). It also
|
|
52
|
+
* installs the `__complete` entry point on `program`.
|
|
53
|
+
*/
|
|
54
|
+
declare function completionCommand(program: Command): Command;
|
|
55
|
+
/**
|
|
56
|
+
* Binds `completer` as the value completion of `cmd`'s own flag `flag`
|
|
57
|
+
* (long name, with or without `--`). An unknown flag is silent and the
|
|
58
|
+
* first binding wins, as with cobra's `RegisterFlagCompletionFunc`. A
|
|
59
|
+
* flag subcommands inherit is bound on the command declaring it.
|
|
60
|
+
*/
|
|
61
|
+
declare function bindFlag(cmd: Command, flag: string, completer: Completer): void;
|
|
62
|
+
/** Binds `completer` as the completion of `cmd`'s positional arguments; replaces an earlier binding. */
|
|
63
|
+
declare function bindArgs(cmd: Command, completer: Completer): void;
|
|
64
|
+
/**
|
|
65
|
+
* Records `name` as a root-level alias of the command at `target` (a
|
|
66
|
+
* space-separated path), so root argument completion offers it as
|
|
67
|
+
* `name<TAB>alias for <target>`, and a root subcommand named `name`
|
|
68
|
+
* completes as a flagless stand-in. `bridgeAliases` calls this for
|
|
69
|
+
* every alias but a visible or custom-dispatch proxy, which completes
|
|
70
|
+
* as an ordinary subcommand.
|
|
71
|
+
*/
|
|
72
|
+
declare function registerRootAlias(root: Command, name: string, target: string): void;
|
|
73
|
+
/** Where a request writes. */
|
|
74
|
+
interface CompletionIO {
|
|
75
|
+
out(s: string): void;
|
|
76
|
+
err(s: string): void;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Makes `program.parse` / `parseAsync` answer `__complete` and
|
|
80
|
+
* `__completeNoDesc` requests themselves, before commander parses, so
|
|
81
|
+
* no hook, option handler or action runs on tab. Idempotent.
|
|
82
|
+
*/
|
|
83
|
+
declare function installCompletionRequest(program: Command): void;
|
|
84
|
+
/**
|
|
85
|
+
* Answers a completion request: `words` are the words after
|
|
86
|
+
* `__complete` (the last is the word being completed). Writes one
|
|
87
|
+
* completion per line, then `:<directive>`, to `io.out`, and the
|
|
88
|
+
* directive's name to `io.err`, in cobra's format.
|
|
89
|
+
*/
|
|
90
|
+
declare function completeRequest(program: Command, words: string[], noDesc?: boolean, io?: CompletionIO): Promise<void>;
|
|
91
|
+
|
|
92
|
+
type completion_CompletionIO = CompletionIO;
|
|
93
|
+
declare const completion_NO_DESC_REQUEST_CMD: typeof NO_DESC_REQUEST_CMD;
|
|
94
|
+
declare const completion_REQUEST_CMD: typeof REQUEST_CMD;
|
|
95
|
+
declare const completion_SHELLS: typeof SHELLS;
|
|
96
|
+
type completion_Shell = Shell;
|
|
97
|
+
declare const completion_bindArgs: typeof bindArgs;
|
|
98
|
+
declare const completion_bindFlag: typeof bindFlag;
|
|
99
|
+
declare const completion_completeRequest: typeof completeRequest;
|
|
100
|
+
declare const completion_completionCommand: typeof completionCommand;
|
|
101
|
+
declare const completion_generateBashCompletion: typeof generateBashCompletion;
|
|
102
|
+
declare const completion_generateFishCompletion: typeof generateFishCompletion;
|
|
103
|
+
declare const completion_generatePowerShellCompletion: typeof generatePowerShellCompletion;
|
|
104
|
+
declare const completion_generateZshCompletion: typeof generateZshCompletion;
|
|
105
|
+
declare const completion_installCompletionRequest: typeof installCompletionRequest;
|
|
106
|
+
declare const completion_registerRootAlias: typeof registerRootAlias;
|
|
107
|
+
declare const completion_renderCompletionScript: typeof renderCompletionScript;
|
|
108
|
+
declare namespace completion {
|
|
109
|
+
export { type completion_CompletionIO as CompletionIO, completion_NO_DESC_REQUEST_CMD as NO_DESC_REQUEST_CMD, completion_REQUEST_CMD as REQUEST_CMD, completion_SHELLS as SHELLS, type completion_Shell as Shell, completion_bindArgs as bindArgs, completion_bindFlag as bindFlag, completion_completeRequest as completeRequest, completion_completionCommand as completionCommand, completion_generateBashCompletion as generateBashCompletion, completion_generateFishCompletion as generateFishCompletion, completion_generatePowerShellCompletion as generatePowerShellCompletion, completion_generateZshCompletion as generateZshCompletion, completion_installCompletionRequest as installCompletionRequest, completion_registerRootAlias as registerRootAlias, completion_renderCompletionScript as renderCompletionScript };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export { type CompletionIO as C, NO_DESC_REQUEST_CMD as N, REQUEST_CMD as R, SHELLS as S, type Shell as a, bindArgs as b, completion as c, bindFlag as d, completeRequest as e, completionCommand as f, generateBashCompletion as g, generateFishCompletion as h, generatePowerShellCompletion as i, generateZshCompletion as j, installCompletionRequest as k, renderCompletionScript as l, registerRootAlias as r };
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module completion-values
|
|
3
|
+
* @package @hop-top/kit
|
|
4
|
+
*
|
|
5
|
+
* Dynamic value completion for Commander-based CLIs. Ports Go
|
|
6
|
+
* `console/cli/completion`; behaviour is pinned by
|
|
7
|
+
* `contracts/completion-v1/completers.json`.
|
|
8
|
+
*
|
|
9
|
+
* A {@link Completer} turns the word being completed into
|
|
10
|
+
* {@link CompletionItem}s. `bindFlag` / `bindArgs` (in `completion`)
|
|
11
|
+
* attach one to a flag or to a command's positional arguments; the
|
|
12
|
+
* scripts `completion <shell>` writes call back into the program's
|
|
13
|
+
* hidden `__complete` entry point, which runs the bound completer and
|
|
14
|
+
* prints the result through {@link resolveCompletions} in cobra's wire
|
|
15
|
+
* format.
|
|
16
|
+
*
|
|
17
|
+
* Contract:
|
|
18
|
+
* - Prefix matching in static, config-key and the dimension half of
|
|
19
|
+
* prefixed completers is case-insensitive; an empty prefix returns
|
|
20
|
+
* every item. {@link funcCompleter} sees the raw prefix, unfiltered.
|
|
21
|
+
* - A completer fails by throwing (or rejecting); the bridge turns that
|
|
22
|
+
* into {@link ShellCompDirective.Error}.
|
|
23
|
+
* - {@link fileCompleter} and {@link dirCompleter} yield a directive,
|
|
24
|
+
* not suggestions: filter by extension (the extensions travel as the
|
|
25
|
+
* completions), directories only, or plain file completion when no
|
|
26
|
+
* extension is given.
|
|
27
|
+
*/
|
|
28
|
+
interface CompletionItem {
|
|
29
|
+
value: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
}
|
|
32
|
+
/** What a completer knows about the command line it completes. */
|
|
33
|
+
interface CompletionContext {
|
|
34
|
+
/** Space-separated path of the command below the root; empty for the root. */
|
|
35
|
+
commandPath: string;
|
|
36
|
+
/** Positional arguments already given, flags removed. */
|
|
37
|
+
args: string[];
|
|
38
|
+
}
|
|
39
|
+
/** What a file completer asks the shell for. */
|
|
40
|
+
type FileFilter = {
|
|
41
|
+
kind: 'extensions';
|
|
42
|
+
extensions: string[];
|
|
43
|
+
} | {
|
|
44
|
+
kind: 'dirs';
|
|
45
|
+
};
|
|
46
|
+
interface Completer {
|
|
47
|
+
complete(prefix: string, ctx?: CompletionContext): CompletionItem[] | Promise<CompletionItem[]>;
|
|
48
|
+
/** Set by {@link fileCompleter} and {@link dirCompleter}. */
|
|
49
|
+
readonly fileFilter?: FileFilter;
|
|
50
|
+
}
|
|
51
|
+
/** cobra's shell directive bits, read by the scripts from the `:<n>` line. */
|
|
52
|
+
declare const ShellCompDirective: {
|
|
53
|
+
readonly Default: 0;
|
|
54
|
+
readonly Error: 1;
|
|
55
|
+
readonly NoSpace: 2;
|
|
56
|
+
readonly NoFileComp: 4;
|
|
57
|
+
readonly FilterFileExt: 8;
|
|
58
|
+
readonly FilterDirs: 16;
|
|
59
|
+
readonly KeepOrder: 32;
|
|
60
|
+
};
|
|
61
|
+
/** cobra's name for a directive, as printed on stderr after a request. */
|
|
62
|
+
declare function directiveName(d: number): string;
|
|
63
|
+
/** Completions in wire form plus the directive. */
|
|
64
|
+
interface ResolvedCompletions {
|
|
65
|
+
/** `value`, or `value\tdescription` when there is one. */
|
|
66
|
+
completions: string[];
|
|
67
|
+
directive: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Runs `c` for `toComplete` and converts the result to the shell wire
|
|
71
|
+
* format: values with any description joined by a tab, plus the
|
|
72
|
+
* directive (no file completion on success, error when `c` fails).
|
|
73
|
+
*/
|
|
74
|
+
declare function resolveCompletions(c: Completer, toComplete: string, ctx?: CompletionContext): Promise<ResolvedCompletions>;
|
|
75
|
+
/** `value`, or `value\tdescription` when there is one. */
|
|
76
|
+
declare function withDescription(i: CompletionItem): string;
|
|
77
|
+
/**
|
|
78
|
+
* Maps flag names and argument positions to completers, for sharing
|
|
79
|
+
* completers across a command tree (Go `Registry`). A lookup table
|
|
80
|
+
* only: `bindFlag` / `bindArgs` wire a completer into completion.
|
|
81
|
+
*/
|
|
82
|
+
declare class CompletionRegistry {
|
|
83
|
+
private flags;
|
|
84
|
+
private args;
|
|
85
|
+
register(flag: string, completer: Completer): void;
|
|
86
|
+
registerArg(cmd: string, pos: number, completer: Completer): void;
|
|
87
|
+
forFlag(flag: string): Completer | undefined;
|
|
88
|
+
forArg(cmd: string, pos: number): Completer | undefined;
|
|
89
|
+
}
|
|
90
|
+
/** Completer from pre-defined CompletionItems. */
|
|
91
|
+
declare function staticCompleter(...items: CompletionItem[]): Completer;
|
|
92
|
+
/** Completer from plain string values. */
|
|
93
|
+
declare function staticValues(...values: string[]): Completer;
|
|
94
|
+
/**
|
|
95
|
+
* Completer backed by a callback. The callback sees the raw prefix;
|
|
96
|
+
* nothing is filtered for it. Throw (or reject) to fail.
|
|
97
|
+
*/
|
|
98
|
+
declare function funcCompleter(fn: (prefix: string, ctx: CompletionContext) => CompletionItem[] | Promise<CompletionItem[]>): Completer;
|
|
99
|
+
/**
|
|
100
|
+
* Completer for dimensioned values like `env:prod`. While no colon is
|
|
101
|
+
* typed it suggests `dimension:` (matched case-insensitively); after
|
|
102
|
+
* the first colon it delegates the rest to `values` and re-prepends
|
|
103
|
+
* the declared `dimension:`.
|
|
104
|
+
*/
|
|
105
|
+
declare function prefixedCompleter(dimension: string, values: Completer): Completer;
|
|
106
|
+
/**
|
|
107
|
+
* Completer that suggests config keys: the dotted leaf keys of
|
|
108
|
+
* `config`, lowercased, matched case-insensitively.
|
|
109
|
+
*/
|
|
110
|
+
declare function configKeysCompleter(config: Record<string, unknown>): Completer;
|
|
111
|
+
/**
|
|
112
|
+
* Completer that asks the shell for files with these extensions (e.g.
|
|
113
|
+
* `.yaml`); none means any file. Its items are the extensions, which
|
|
114
|
+
* travel as the completions of a filter-by-extension directive.
|
|
115
|
+
*/
|
|
116
|
+
declare function fileCompleter(...extensions: string[]): Completer;
|
|
117
|
+
/** Completer that asks the shell for directories only. */
|
|
118
|
+
declare function dirCompleter(): Completer;
|
|
119
|
+
|
|
120
|
+
type completionValues_Completer = Completer;
|
|
121
|
+
type completionValues_CompletionContext = CompletionContext;
|
|
122
|
+
type completionValues_CompletionItem = CompletionItem;
|
|
123
|
+
type completionValues_CompletionRegistry = CompletionRegistry;
|
|
124
|
+
declare const completionValues_CompletionRegistry: typeof CompletionRegistry;
|
|
125
|
+
type completionValues_FileFilter = FileFilter;
|
|
126
|
+
type completionValues_ResolvedCompletions = ResolvedCompletions;
|
|
127
|
+
declare const completionValues_ShellCompDirective: typeof ShellCompDirective;
|
|
128
|
+
declare const completionValues_configKeysCompleter: typeof configKeysCompleter;
|
|
129
|
+
declare const completionValues_dirCompleter: typeof dirCompleter;
|
|
130
|
+
declare const completionValues_directiveName: typeof directiveName;
|
|
131
|
+
declare const completionValues_fileCompleter: typeof fileCompleter;
|
|
132
|
+
declare const completionValues_funcCompleter: typeof funcCompleter;
|
|
133
|
+
declare const completionValues_prefixedCompleter: typeof prefixedCompleter;
|
|
134
|
+
declare const completionValues_resolveCompletions: typeof resolveCompletions;
|
|
135
|
+
declare const completionValues_staticCompleter: typeof staticCompleter;
|
|
136
|
+
declare const completionValues_staticValues: typeof staticValues;
|
|
137
|
+
declare const completionValues_withDescription: typeof withDescription;
|
|
138
|
+
declare namespace completionValues {
|
|
139
|
+
export { type completionValues_Completer as Completer, type completionValues_CompletionContext as CompletionContext, type completionValues_CompletionItem as CompletionItem, completionValues_CompletionRegistry as CompletionRegistry, type completionValues_FileFilter as FileFilter, type completionValues_ResolvedCompletions as ResolvedCompletions, completionValues_ShellCompDirective as ShellCompDirective, completionValues_configKeysCompleter as configKeysCompleter, completionValues_dirCompleter as dirCompleter, completionValues_directiveName as directiveName, completionValues_fileCompleter as fileCompleter, completionValues_funcCompleter as funcCompleter, completionValues_prefixedCompleter as prefixedCompleter, completionValues_resolveCompletions as resolveCompletions, completionValues_staticCompleter as staticCompleter, completionValues_staticValues as staticValues, completionValues_withDescription as withDescription };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { type Completer as C, type FileFilter as F, type ResolvedCompletions as R, ShellCompDirective as S, type CompletionContext as a, type CompletionItem as b, completionValues as c, CompletionRegistry as d, configKeysCompleter as e, dirCompleter as f, directiveName as g, fileCompleter as h, funcCompleter as i, staticValues as j, prefixedCompleter as p, resolveCompletions as r, staticCompleter as s, withDescription as w };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { C as Completer, a as CompletionContext, b as CompletionItem, d as CompletionRegistry, F as FileFilter, R as ResolvedCompletions, S as ShellCompDirective, e as configKeysCompleter, f as dirCompleter, g as directiveName, h as fileCompleter, i as funcCompleter, p as prefixedCompleter, r as resolveCompletions, s as staticCompleter, j as staticValues, w as withDescription } from './completion-values-By-mnjNt.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _chunkJKMQSAJPjs = require('./chunk-JKMQSAJP.js');
|
|
15
|
+
require('./chunk-R5U7XKVJ.js');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
exports.CompletionRegistry = _chunkJKMQSAJPjs.CompletionRegistry; exports.ShellCompDirective = _chunkJKMQSAJPjs.ShellCompDirective; exports.configKeysCompleter = _chunkJKMQSAJPjs.configKeysCompleter; exports.dirCompleter = _chunkJKMQSAJPjs.dirCompleter; exports.directiveName = _chunkJKMQSAJPjs.directiveName; exports.fileCompleter = _chunkJKMQSAJPjs.fileCompleter; exports.funcCompleter = _chunkJKMQSAJPjs.funcCompleter; exports.prefixedCompleter = _chunkJKMQSAJPjs.prefixedCompleter; exports.resolveCompletions = _chunkJKMQSAJPjs.resolveCompletions; exports.staticCompleter = _chunkJKMQSAJPjs.staticCompleter; exports.staticValues = _chunkJKMQSAJPjs.staticValues; exports.withDescription = _chunkJKMQSAJPjs.withDescription;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import 'commander';
|
|
2
|
+
import './completion-values-By-mnjNt.js';
|
|
3
|
+
export { C as CompletionIO, N as NO_DESC_REQUEST_CMD, R as REQUEST_CMD, S as SHELLS, a as Shell, b as bindArgs, d as bindFlag, e as completeRequest, f as completionCommand, g as generateBashCompletion, h as generateFishCompletion, i as generatePowerShellCompletion, j as generateZshCompletion, k as installCompletionRequest, r as registerRootAlias, l as renderCompletionScript } from './completion-csVun6SP.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var _chunk65VPWMPVjs = require('./chunk-65VPWMPV.js');
|
|
17
|
+
require('./chunk-JKMQSAJP.js');
|
|
18
|
+
require('./chunk-R5U7XKVJ.js');
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
exports.NO_DESC_REQUEST_CMD = _chunk65VPWMPVjs.NO_DESC_REQUEST_CMD; exports.REQUEST_CMD = _chunk65VPWMPVjs.REQUEST_CMD; exports.SHELLS = _chunk65VPWMPVjs.SHELLS; exports.bindArgs = _chunk65VPWMPVjs.bindArgs; exports.bindFlag = _chunk65VPWMPVjs.bindFlag; exports.completeRequest = _chunk65VPWMPVjs.completeRequest; exports.completionCommand = _chunk65VPWMPVjs.completionCommand; exports.generateBashCompletion = _chunk65VPWMPVjs.generateBashCompletion; exports.generateFishCompletion = _chunk65VPWMPVjs.generateFishCompletion; exports.generatePowerShellCompletion = _chunk65VPWMPVjs.generatePowerShellCompletion; exports.generateZshCompletion = _chunk65VPWMPVjs.generateZshCompletion; exports.installCompletionRequest = _chunk65VPWMPVjs.installCompletionRequest; exports.registerRootAlias = _chunk65VPWMPVjs.registerRootAlias; exports.renderCompletionScript = _chunk65VPWMPVjs.renderCompletionScript;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* compliance.ts — 12-factor AI CLI compliance checker.
|
|
3
|
+
*
|
|
4
|
+
* Static checks analyse a toolspec YAML. Runtime checks execute
|
|
5
|
+
* the binary. Port of Go hop.top/kit/compliance.
|
|
6
|
+
*/
|
|
7
|
+
declare enum Factor {
|
|
8
|
+
SelfDescribing = 1,
|
|
9
|
+
StructuredIO = 2,
|
|
10
|
+
StreamDiscipline = 3,
|
|
11
|
+
ContractsErrors = 4,
|
|
12
|
+
Preview = 5,
|
|
13
|
+
Idempotency = 6,
|
|
14
|
+
StateTransparency = 7,
|
|
15
|
+
SafeDelegation = 8,
|
|
16
|
+
ObservableOps = 9,
|
|
17
|
+
Provenance = 10,
|
|
18
|
+
Evolution = 11,
|
|
19
|
+
AuthLifecycle = 12,
|
|
20
|
+
ConsentingTelemetry = 13
|
|
21
|
+
}
|
|
22
|
+
declare function factorName(f: Factor): string;
|
|
23
|
+
interface CheckResult {
|
|
24
|
+
factor: Factor;
|
|
25
|
+
name: string;
|
|
26
|
+
status: "pass" | "fail" | "skip" | "warn";
|
|
27
|
+
details?: string;
|
|
28
|
+
suggestion?: string;
|
|
29
|
+
}
|
|
30
|
+
interface Report {
|
|
31
|
+
binary: string;
|
|
32
|
+
toolspec: string;
|
|
33
|
+
results: CheckResult[];
|
|
34
|
+
score: number;
|
|
35
|
+
total: number;
|
|
36
|
+
}
|
|
37
|
+
/** Run static checks against a toolspec YAML file. */
|
|
38
|
+
declare function runStatic(toolspecPath: string): CheckResult[];
|
|
39
|
+
/** Run runtime checks against a binary + toolspec. */
|
|
40
|
+
declare function runRuntime(binaryPath: string, toolspecPath: string): CheckResult[];
|
|
41
|
+
/** Run both static + runtime checks. If binaryPath is empty,
|
|
42
|
+
* only static checks run. */
|
|
43
|
+
declare function run(binaryPath: string, toolspecPath: string): Report;
|
|
44
|
+
/** Render report as text or JSON string. */
|
|
45
|
+
declare function formatReport(r: Report, format?: string): string;
|
|
46
|
+
|
|
47
|
+
type compliance_CheckResult = CheckResult;
|
|
48
|
+
type compliance_Factor = Factor;
|
|
49
|
+
declare const compliance_Factor: typeof Factor;
|
|
50
|
+
type compliance_Report = Report;
|
|
51
|
+
declare const compliance_factorName: typeof factorName;
|
|
52
|
+
declare const compliance_formatReport: typeof formatReport;
|
|
53
|
+
declare const compliance_run: typeof run;
|
|
54
|
+
declare const compliance_runRuntime: typeof runRuntime;
|
|
55
|
+
declare const compliance_runStatic: typeof runStatic;
|
|
56
|
+
declare namespace compliance {
|
|
57
|
+
export { type compliance_CheckResult as CheckResult, compliance_Factor as Factor, type compliance_Report as Report, compliance_factorName as factorName, compliance_formatReport as formatReport, compliance_run as run, compliance_runRuntime as runRuntime, compliance_runStatic as runStatic };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { type CheckResult as C, Factor as F, type Report as R, formatReport as a, runRuntime as b, compliance as c, runStatic as d, factorName as f, run as r };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { C as CheckResult, F as Factor, R as Report, f as factorName, a as formatReport, r as run, b as runRuntime, d as runStatic } from './compliance-AxFf-uMy.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkXJTRY453js = require('./chunk-XJTRY453.js');
|
|
9
|
+
require('./chunk-R5U7XKVJ.js');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
exports.Factor = _chunkXJTRY453js.Factor; exports.factorName = _chunkXJTRY453js.factorName; exports.formatReport = _chunkXJTRY453js.formatReport; exports.run = _chunkXJTRY453js.run; exports.runRuntime = _chunkXJTRY453js.runRuntime; exports.runStatic = _chunkXJTRY453js.runStatic;
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* Layered configuration loader (YAML by default) — TypeScript port of
|
|
5
|
+
* hop.top/kit/config.
|
|
6
|
+
*
|
|
7
|
+
* Merges configuration from up to three file layers in priority order:
|
|
8
|
+
* system → user → project → envOverride
|
|
9
|
+
*
|
|
10
|
+
* Each layer merges into `dst` with these rules:
|
|
11
|
+
*
|
|
12
|
+
* - Plain objects merge recursively, key by key, so a later layer only
|
|
13
|
+
* overrides the keys it sets (`db: {port: 2}` keeps an earlier `db.host`).
|
|
14
|
+
* - Arrays and scalars are replaced wholesale.
|
|
15
|
+
* - `null` clears an object or array; it leaves a scalar untouched.
|
|
16
|
+
* - On a type conflict (object vs non-object) the later value replaces the
|
|
17
|
+
* earlier one.
|
|
18
|
+
* - Non-plain objects (`Date`, `Map`, class instances) are never merged
|
|
19
|
+
* into; a later value replaces them.
|
|
20
|
+
*
|
|
21
|
+
* {@link mergeLayers} applies the same rules to objects you already parsed,
|
|
22
|
+
* and {@link MergeOptions} (also accepted by {@link load} as `merge`) can
|
|
23
|
+
* relax them: `null` keeps the lower value, objects merge only to a set depth,
|
|
24
|
+
* arrays concatenate or union, globally or per dotted key path. A file in
|
|
25
|
+
* another format goes through {@link Options.parse}.
|
|
26
|
+
*
|
|
27
|
+
* The defaults match Go's `kit/core/config` for struct fields. Go differs where its
|
|
28
|
+
* target type differs: a `map[...]` value or an `any` field is replaced
|
|
29
|
+
* whole rather than merged, and a type conflict on a typed field is a decode
|
|
30
|
+
* error rather than a replacement.
|
|
31
|
+
*
|
|
32
|
+
* Missing files are silently skipped. A file that exists but contains invalid
|
|
33
|
+
* YAML causes {@link load} to throw. A document whose root is not a mapping
|
|
34
|
+
* is ignored.
|
|
35
|
+
*
|
|
36
|
+
* Each file is checked before it merges, with aliases expanded, and
|
|
37
|
+
* {@link load} throws `config: failed to parse <path>: <reason>` when:
|
|
38
|
+
*
|
|
39
|
+
* - its aliases expand past Go yaml.v3's budget: more than 100 nodes inside
|
|
40
|
+
* alias expansions and more than 1000 in total, with the share inside
|
|
41
|
+
* aliases above 0.99 (up to 400k nodes), falling linearly to 0.10 at 4M
|
|
42
|
+
* (`document contains excessive aliasing`). Go counts only the keys its
|
|
43
|
+
* target struct reads; TS has no target, so it counts every key, and a
|
|
44
|
+
* file Go accepts because the aliases sit under ignored keys fails here.
|
|
45
|
+
* - collections nest deeper than 100, counted through aliases
|
|
46
|
+
* (`nesting exceeded maxDepth (100)`). Go allows 10000 levels of text
|
|
47
|
+
* nesting and caps alias chains only through the budget above.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { load } from "@hop-top/kit/config";
|
|
52
|
+
*
|
|
53
|
+
* interface AppConfig {
|
|
54
|
+
* host: string;
|
|
55
|
+
* port: number;
|
|
56
|
+
* debug: boolean;
|
|
57
|
+
* token: string;
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
* const cfg: AppConfig = { host: "localhost", port: 3000, debug: false, token: "" };
|
|
61
|
+
*
|
|
62
|
+
* load(cfg, {
|
|
63
|
+
* systemConfigPath: "/etc/mytool/config.yaml",
|
|
64
|
+
* userConfigPath: `${process.env.HOME}/.config/mytool/config.yaml`,
|
|
65
|
+
* projectConfigPath: ".mytool.yaml",
|
|
66
|
+
* envOverride(c) {
|
|
67
|
+
* if (process.env.HOST) c.host = process.env.HOST;
|
|
68
|
+
* if (process.env.PORT) c.port = Number(process.env.PORT);
|
|
69
|
+
* if (process.env.TOKEN) c.token = process.env.TOKEN;
|
|
70
|
+
* },
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
/**
|
|
75
|
+
* Configuration sources for {@link load}.
|
|
76
|
+
*
|
|
77
|
+
* All path fields are optional; an empty or omitted path is silently skipped.
|
|
78
|
+
* {@link Options.envOverride} is called last, after all file layers, so it can
|
|
79
|
+
* apply environment-variable overrides on top of file values.
|
|
80
|
+
*/
|
|
81
|
+
interface Options<T extends object = object> {
|
|
82
|
+
/**
|
|
83
|
+
* Path to the system-wide config file, e.g. `/etc/mytool/config.yaml`.
|
|
84
|
+
* Applied first (lowest priority).
|
|
85
|
+
*/
|
|
86
|
+
systemConfigPath?: string;
|
|
87
|
+
/**
|
|
88
|
+
* Path to the per-user config file, e.g. `~/.config/mytool/config.yaml`.
|
|
89
|
+
* Applied second; merges over system values (see the module merge rules).
|
|
90
|
+
*/
|
|
91
|
+
userConfigPath?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Path to the project-level config file, e.g. `.mytool.yaml`.
|
|
94
|
+
* Applied third; merges over system and user values.
|
|
95
|
+
*/
|
|
96
|
+
projectConfigPath?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Optional callback invoked after all file layers have been merged.
|
|
99
|
+
* Receives the fully-merged `dst` object so the caller can apply
|
|
100
|
+
* environment-variable overrides last (highest priority).
|
|
101
|
+
*
|
|
102
|
+
* @param cfg - The merged config object (same reference as `dst`).
|
|
103
|
+
*/
|
|
104
|
+
envOverride?: (cfg: T) => void;
|
|
105
|
+
/**
|
|
106
|
+
* Parser for file contents; YAML when omitted. A function parses every
|
|
107
|
+
* file. A record maps a lowercased extension with its dot (`".json"`;
|
|
108
|
+
* `""` for an extensionless file such as `.toolrc`) to a parser, and files
|
|
109
|
+
* whose extension has no entry parse as YAML. The parser gets the text and
|
|
110
|
+
* the path (so a `.js` parser can `require` the path instead); a throw
|
|
111
|
+
* fails the load like a YAML error, and a result that is not a plain
|
|
112
|
+
* object is ignored. Without a parser a `.js` file parses as YAML text
|
|
113
|
+
* and is never executed.
|
|
114
|
+
*/
|
|
115
|
+
parse?: ConfigParser | Record<string, ConfigParser>;
|
|
116
|
+
/**
|
|
117
|
+
* Merge policies for the file layers, `dst` being the lowest layer. They
|
|
118
|
+
* do not touch {@link envOverride}, which assigns whatever it sets.
|
|
119
|
+
* Defaults are the module merge rules.
|
|
120
|
+
*/
|
|
121
|
+
merge?: MergeOptions;
|
|
122
|
+
}
|
|
123
|
+
/** Parses one config file's text; see {@link Options.parse}. */
|
|
124
|
+
type ConfigParser = (text: string, filePath: string) => unknown;
|
|
125
|
+
/** What a `null` in a higher layer does; see {@link MergeOptions.nullPolicy}. */
|
|
126
|
+
type NullPolicy = "clear" | "keep-lower";
|
|
127
|
+
/** How two arrays at one key combine; see {@link MergeOptions.arrayPolicy}. */
|
|
128
|
+
type ArrayPolicy = "replace" | "concat" | "union";
|
|
129
|
+
/**
|
|
130
|
+
* Custom array merge for one path: gets the lower array (already in the
|
|
131
|
+
* result), a copy of the higher array and the dotted path; returns the value
|
|
132
|
+
* to store.
|
|
133
|
+
*/
|
|
134
|
+
type ArrayMergeFn = (lower: unknown[], higher: unknown[], path: string) => unknown;
|
|
135
|
+
/**
|
|
136
|
+
* Merge policies for {@link mergeLayers} and {@link Options.merge}. All
|
|
137
|
+
* policies act only where a higher layer's key meets a key already in the
|
|
138
|
+
* result; a value with nothing under it (a new key, a type conflict, an
|
|
139
|
+
* object past `maxDepth`) is copied whole, as is.
|
|
140
|
+
*/
|
|
141
|
+
interface MergeOptions {
|
|
142
|
+
/**
|
|
143
|
+
* `"clear"` (default): `null` clears an object or array, sets a key that
|
|
144
|
+
* is absent or already `null`, and leaves a scalar untouched.
|
|
145
|
+
* `"keep-lower"`: `null` is skipped, so the lower value stays and an
|
|
146
|
+
* absent key stays absent.
|
|
147
|
+
*/
|
|
148
|
+
nullPolicy?: NullPolicy;
|
|
149
|
+
/**
|
|
150
|
+
* How many object levels below the root merge key by key; deeper objects
|
|
151
|
+
* replace whole. `Infinity` (default) merges at every depth, `1` merges the
|
|
152
|
+
* root and the objects directly under it (`{db: {opts: {...}}}` merges
|
|
153
|
+
* `db` but replaces `db.opts`), `0` assigns root keys only, like
|
|
154
|
+
* `Object.assign`. Must be a non-negative integer or `Infinity`.
|
|
155
|
+
*/
|
|
156
|
+
maxDepth?: number;
|
|
157
|
+
/**
|
|
158
|
+
* How two arrays at one key combine. `"replace"` (default): the higher
|
|
159
|
+
* array wins. `"concat"`: lower items, then higher items. `"union"`: lower
|
|
160
|
+
* then higher items, keeping the first of equal items, where plain objects
|
|
161
|
+
* and arrays compare structurally (object key order ignored) and other
|
|
162
|
+
* values by SameValueZero. A policy acts only when both sides are arrays;
|
|
163
|
+
* otherwise the higher value replaces.
|
|
164
|
+
*/
|
|
165
|
+
arrayPolicy?: ArrayPolicy;
|
|
166
|
+
/**
|
|
167
|
+
* Per-path override of {@link arrayPolicy}: dotted key path from the root
|
|
168
|
+
* (`"scope.hints"`, split on every `.` like the Go SDK's dotted keys, so a
|
|
169
|
+
* key containing a dot cannot be named) to a policy or an
|
|
170
|
+
* {@link ArrayMergeFn}, which gets the concrete path. A segment that is
|
|
171
|
+
* exactly `*` matches any one key (`"scopes.*.hints"`, never zero or
|
|
172
|
+
* several; `a*` is literal, `**` throws). When several entries match, the
|
|
173
|
+
* exact path wins, then the pattern with the fewest `*`, then the
|
|
174
|
+
* lexically smallest pattern (UTF-16 order, so `*.b.c` beats `a.*.c`).
|
|
175
|
+
*/
|
|
176
|
+
arrayPolicyByPath?: Record<string, ArrayPolicy | ArrayMergeFn>;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Merges already-parsed layers, lowest priority first, into a new object and
|
|
180
|
+
* returns it. Layers that are not plain objects (`null`, arrays, scalars)
|
|
181
|
+
* are skipped; the layers are never mutated or shared with the result.
|
|
182
|
+
* Defaults follow the module merge rules; {@link MergeOptions} relaxes them.
|
|
183
|
+
*
|
|
184
|
+
* @throws {Error} `config: layer <i>: <reason>` when a layer nests deeper
|
|
185
|
+
* than 100 levels or contains a cycle, and on an invalid option.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```ts
|
|
189
|
+
* const cfg = mergeLayers([globalRc, projectRc], {
|
|
190
|
+
* nullPolicy: "keep-lower",
|
|
191
|
+
* maxDepth: 1,
|
|
192
|
+
* arrayPolicyByPath: { hints: "union" },
|
|
193
|
+
* });
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
declare function mergeLayers<T extends object = Record<string, unknown>>(layers: readonly unknown[], opts?: MergeOptions): T;
|
|
197
|
+
/**
|
|
198
|
+
* Merges layered YAML configuration into `dst` and returns it.
|
|
199
|
+
*
|
|
200
|
+
* Merge order: `systemConfigPath` → `userConfigPath` → `projectConfigPath` →
|
|
201
|
+
* `envOverride`.
|
|
202
|
+
*
|
|
203
|
+
* - Objects merge recursively; arrays and scalars replace; `null` clears
|
|
204
|
+
* objects and arrays but not scalars (see the module docs for details),
|
|
205
|
+
* unless {@link Options.merge} says otherwise.
|
|
206
|
+
* - Files parse as YAML unless {@link Options.parse} supplies a parser.
|
|
207
|
+
* - Missing files (ENOENT) are silently skipped.
|
|
208
|
+
* - A file that exists but is not valid YAML causes this function to throw
|
|
209
|
+
* a descriptive error wrapping the parse failure.
|
|
210
|
+
* - `envOverride`, when provided, is called last with the merged `dst`.
|
|
211
|
+
* - Returns `dst` (the same object reference passed in).
|
|
212
|
+
*
|
|
213
|
+
* @param dst - Destination object to merge config into. Must be a non-null
|
|
214
|
+
* object; mutated in place.
|
|
215
|
+
* @param opts - Config sources. All fields are optional.
|
|
216
|
+
* @returns The mutated `dst` object.
|
|
217
|
+
* @throws {Error} When a file exists but cannot be parsed, or on an
|
|
218
|
+
* invalid {@link Options.merge}.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* const cfg = { host: "localhost", port: 8080 };
|
|
223
|
+
* load(cfg, { projectConfigPath: ".tool.yaml" });
|
|
224
|
+
* console.log(cfg.host); // value from .tool.yaml, or "localhost" if file missing
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
declare function load<T extends object>(dst: T, opts?: Options<T>): T;
|
|
228
|
+
|
|
229
|
+
type config_ArrayMergeFn = ArrayMergeFn;
|
|
230
|
+
type config_ArrayPolicy = ArrayPolicy;
|
|
231
|
+
type config_ConfigParser = ConfigParser;
|
|
232
|
+
type config_MergeOptions = MergeOptions;
|
|
233
|
+
type config_NullPolicy = NullPolicy;
|
|
234
|
+
type config_Options<T extends object = object> = Options<T>;
|
|
235
|
+
declare const config_load: typeof load;
|
|
236
|
+
declare const config_mergeLayers: typeof mergeLayers;
|
|
237
|
+
declare namespace config {
|
|
238
|
+
export { type config_ArrayMergeFn as ArrayMergeFn, type config_ArrayPolicy as ArrayPolicy, type config_ConfigParser as ConfigParser, type config_MergeOptions as MergeOptions, type config_NullPolicy as NullPolicy, type config_Options as Options, config_load as load, config_mergeLayers as mergeLayers };
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export { type ArrayMergeFn as A, type ConfigParser as C, type MergeOptions as M, type NullPolicy as N, type Options as O, type ArrayPolicy as a, config as c, load as l, mergeLayers as m };
|