@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,707 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { P as ParityData } from './parity-CvMuYcVI.js';
|
|
3
|
+
import { E as ErrOffline, O as OfflineError, g as guardFetch, i as isOffline, a as isOfflineError, w as withOffline } from './netpolicy-Brx5XZUB.js';
|
|
4
|
+
import { Writable } from 'node:stream';
|
|
5
|
+
import { F as Format } from './output-CjZWmL8s.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @module policy
|
|
9
|
+
* @package @hop-top/kit
|
|
10
|
+
*
|
|
11
|
+
* The delegation-safety policy: which side-effect classes a named policy
|
|
12
|
+
* lets run, how many mutating operations one invocation may perform, and
|
|
13
|
+
* which commands always ask for confirmation. Ports Go
|
|
14
|
+
* `console/cli/policy` (policy, engine, loader, the shipped `kit-default`).
|
|
15
|
+
*
|
|
16
|
+
* `permissions:` rules are carried and shape-validated but never
|
|
17
|
+
* evaluated (the expression evaluator is Go's `celpermission`), and the
|
|
18
|
+
* `callers:` section is carried and validated but unused: the CLI has no
|
|
19
|
+
* transport-established caller, so only the policy's own rules answer.
|
|
20
|
+
*/
|
|
21
|
+
/** Name of the policy kit ships; reserved, never a file. */
|
|
22
|
+
declare const KIT_DEFAULT_NAME = "kit-default";
|
|
23
|
+
/** One `permissions:` entry; carried and shape-validated, not evaluated. */
|
|
24
|
+
interface PermissionRule {
|
|
25
|
+
name: string;
|
|
26
|
+
when: string;
|
|
27
|
+
effect: string;
|
|
28
|
+
otherwise: string;
|
|
29
|
+
message?: string;
|
|
30
|
+
}
|
|
31
|
+
/** One `callers:` entry; carried and validated, unused on the CLI. */
|
|
32
|
+
interface CallerRule {
|
|
33
|
+
principal?: string;
|
|
34
|
+
tenant?: string;
|
|
35
|
+
scope?: string;
|
|
36
|
+
allow?: Record<string, string[]>;
|
|
37
|
+
max_ops?: number;
|
|
38
|
+
window?: string;
|
|
39
|
+
require_declared_scope?: string[];
|
|
40
|
+
}
|
|
41
|
+
interface Policy {
|
|
42
|
+
name: string;
|
|
43
|
+
/** Per-class verb glob lists. An empty list refuses the class. */
|
|
44
|
+
allow?: Record<string, string[]>;
|
|
45
|
+
/** Per-invocation cap on mutating ops; 0 means unlimited. */
|
|
46
|
+
max_ops: number;
|
|
47
|
+
/** Command-path globs that always require confirmation. */
|
|
48
|
+
require_confirm: string[];
|
|
49
|
+
permissions: PermissionRule[];
|
|
50
|
+
/** Class a command declaring no side-effect is authorized as. */
|
|
51
|
+
unannotated?: string;
|
|
52
|
+
callers: CallerRule[];
|
|
53
|
+
/** Appended to every refusal; set by shipped policies only. */
|
|
54
|
+
remedy?: string;
|
|
55
|
+
}
|
|
56
|
+
/** Thrown by {@link Engine.recordOp} once the budget is hit. */
|
|
57
|
+
declare class MaxOpsExceededError extends Error {
|
|
58
|
+
constructor();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The policy kit ships: a command declaring no side effect is a write; a
|
|
62
|
+
* caller nobody established reads only; an established principal reads and
|
|
63
|
+
* writes and runs a destructive command that declares a permissions scope.
|
|
64
|
+
*/
|
|
65
|
+
declare function kitDefault(): Policy;
|
|
66
|
+
/** What the engine reads about the command being authorized. */
|
|
67
|
+
interface CommandRef {
|
|
68
|
+
/** The command path minus the root name (`widget add`). */
|
|
69
|
+
verb: string;
|
|
70
|
+
/** The resolved tier (declared or inferred); undefined when untagged. */
|
|
71
|
+
sideEffect?: string;
|
|
72
|
+
}
|
|
73
|
+
interface Verdict {
|
|
74
|
+
allowed: boolean;
|
|
75
|
+
requireConfirm: boolean;
|
|
76
|
+
reason: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Per-invocation enforcement state: {@link Engine.authorize} each command
|
|
80
|
+
* before it runs, {@link Engine.recordOp} after a successful mutating run.
|
|
81
|
+
*/
|
|
82
|
+
declare class Engine {
|
|
83
|
+
readonly policy: Policy;
|
|
84
|
+
private ops;
|
|
85
|
+
private readonly max;
|
|
86
|
+
/** `maxOpsOverride > 0` takes precedence over the policy's `max_ops`. */
|
|
87
|
+
constructor(policy: Policy, maxOpsOverride?: number);
|
|
88
|
+
maxOps(): number;
|
|
89
|
+
opsCount(): number;
|
|
90
|
+
authorize(cmd: CommandRef): Verdict;
|
|
91
|
+
/** Accounts a successful mutating op; throws once the budget is hit. */
|
|
92
|
+
recordOp(): void;
|
|
93
|
+
private refusal;
|
|
94
|
+
}
|
|
95
|
+
/** Resolves a policy name to a Policy; adopters supply one to the CLI. */
|
|
96
|
+
type PolicyLoader = (name: string) => Policy;
|
|
97
|
+
/**
|
|
98
|
+
* The canonical path of a named policy:
|
|
99
|
+
* `$XDG_CONFIG_HOME/<tool>/policies/<name>.yaml`. A name is a file stem,
|
|
100
|
+
* never a path: anything outside `[A-Za-z0-9_-]{1,64}` is refused before
|
|
101
|
+
* any filesystem access.
|
|
102
|
+
*/
|
|
103
|
+
declare function resolvePolicyPath(tool: string, name: string): string;
|
|
104
|
+
/**
|
|
105
|
+
* Reads a YAML policy file. A missing `name:` defaults to the file stem so
|
|
106
|
+
* audit output has a handle.
|
|
107
|
+
*/
|
|
108
|
+
declare function loadPolicy(file: string): Policy;
|
|
109
|
+
/**
|
|
110
|
+
* Resolves and loads a named policy. {@link KIT_DEFAULT_NAME} is reserved:
|
|
111
|
+
* it always returns {@link kitDefault} and no file is read.
|
|
112
|
+
*/
|
|
113
|
+
declare function loadNamedPolicy(tool: string, name: string): Policy;
|
|
114
|
+
/** A loader resolving names against `$XDG_CONFIG_HOME/<tool>/policies/`. */
|
|
115
|
+
declare function defaultPolicyLoader(tool: string): PolicyLoader;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @module delegation
|
|
119
|
+
* @package @hop-top/kit
|
|
120
|
+
*
|
|
121
|
+
* The delegation gates a leaf passes before its handler runs, in Go's
|
|
122
|
+
* order (`policy_runE.go`, `global_dryrun.go`): `--dry-run` enforcement,
|
|
123
|
+
* the named `--policy`, the `--confirm` matrix with the typed
|
|
124
|
+
* `--confirm-token`, and the `--max-ops` budget accounted after a
|
|
125
|
+
* successful mutating run.
|
|
126
|
+
*
|
|
127
|
+
* `createCLI` installs the root flags and the hooks; adopters declare
|
|
128
|
+
* `kit/side-effect` on a leaf and the gates follow.
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
type Annotations = Readonly<Record<string, string>>;
|
|
132
|
+
/** The terminal an interactive prompt asks on. */
|
|
133
|
+
interface Prompter {
|
|
134
|
+
/**
|
|
135
|
+
* Writes `question` and reads one line of answer, lowercased and
|
|
136
|
+
* trimmed; `null` on end of input.
|
|
137
|
+
*/
|
|
138
|
+
ask(question: string): string | null;
|
|
139
|
+
}
|
|
140
|
+
/** Supplies the prompt terminal: `null` means nobody to ask. */
|
|
141
|
+
type PromptSource = () => Prompter | null;
|
|
142
|
+
/** No terminal: every prompt is refused and an unset `--confirm` is `no`. */
|
|
143
|
+
declare const noPrompt: PromptSource;
|
|
144
|
+
/** A scripted terminal answering from `answers`, one per question. */
|
|
145
|
+
declare function scriptedPrompt(answers: readonly string[]): PromptSource;
|
|
146
|
+
/**
|
|
147
|
+
* The process's controlling terminal (`/dev/tty`), opened once; none
|
|
148
|
+
* where there is no such terminal. The default. Both halves go to the
|
|
149
|
+
* terminal, never to stdin or stderr: reading stdin would consume the
|
|
150
|
+
* command's payload, and writing a redirected stderr would put the
|
|
151
|
+
* question where the operator cannot see it.
|
|
152
|
+
*/
|
|
153
|
+
declare const controllingTTY: PromptSource;
|
|
154
|
+
type ConfirmMode = 'auto' | 'yes' | 'no' | 'prompt';
|
|
155
|
+
/**
|
|
156
|
+
* Parses `--confirm`: empty or unknown defaults to `prompt` when there is
|
|
157
|
+
* a terminal to ask on and `no` otherwise. Interactivity is the
|
|
158
|
+
* terminal's availability, not isatty on stdin.
|
|
159
|
+
*/
|
|
160
|
+
declare function resolveConfirmMode(src: PromptSource, raw: string): ConfirmMode;
|
|
161
|
+
/**
|
|
162
|
+
* The token a typed-confirmation command demands: the first 12 hex
|
|
163
|
+
* characters of the sha256 of its full command path.
|
|
164
|
+
*/
|
|
165
|
+
declare function destructiveToken(commandPath: string): string;
|
|
166
|
+
/** What `--dry-run` does on a leaf, by its annotations. */
|
|
167
|
+
type DryRunPolicy = 'allow' | 'noop' | 'reject-interactive' | 'reject-opt-out' | 'reject-untagged' | 'reject-malformed';
|
|
168
|
+
/**
|
|
169
|
+
* The dry-run table: opted-out refuses; legacy `supported` allows; write
|
|
170
|
+
* and destructive tiers allow; read is a silent no-op; interactive
|
|
171
|
+
* refuses; malformed values refuse. An unannotated command with a
|
|
172
|
+
* destructive name is the inferred destructive tier, so it previews like a
|
|
173
|
+
* declared one; any other untagged command refuses.
|
|
174
|
+
*/
|
|
175
|
+
declare function resolveDryRunPolicy(name: string, ann: Annotations): DryRunPolicy;
|
|
176
|
+
/** True when kit applied `--dry-run` to the running leaf (it previews). */
|
|
177
|
+
declare function dryRunApplied(cmd: Command): boolean;
|
|
178
|
+
/**
|
|
179
|
+
* True when the command runs as a dry run: kit applied `--dry-run`, or the
|
|
180
|
+
* flag was given (a read command accepts it and still runs). Handlers call
|
|
181
|
+
* this and build a {@link Plan} instead of acting.
|
|
182
|
+
*/
|
|
183
|
+
declare function isDryRun(cmd: Command): boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Registers `--confirm-token` on every runnable leaf opting in via the
|
|
186
|
+
* `kit/destructive-token` annotation. Idempotent.
|
|
187
|
+
*/
|
|
188
|
+
declare function installConfirmTokenFlag(program: Command): void;
|
|
189
|
+
|
|
190
|
+
/** The closed set of declarable tiers (legacy 4-tier plus the 6-tier ladder). */
|
|
191
|
+
declare const SIDE_EFFECT_TIERS: readonly ["read", "write", "write-local", "write-shared", "destructive", "destructive-local", "destructive-shared", "interactive"];
|
|
192
|
+
type SideEffect = (typeof SIDE_EFFECT_TIERS)[number];
|
|
193
|
+
/** The tier an unannotated command with a destructive leaf name is gated as. */
|
|
194
|
+
declare const INFERRED_TIER: SideEffect;
|
|
195
|
+
/** True for any tier that mutates state without irreversible loss. */
|
|
196
|
+
declare function isWriteLike(tier: string): boolean;
|
|
197
|
+
/** True for any tier that performs an irreversible mutation. */
|
|
198
|
+
declare function isDestructiveLike(tier: string): boolean;
|
|
199
|
+
/** True when `name` is in the destructive-name table. */
|
|
200
|
+
declare function isDestructiveName(name: string): boolean;
|
|
201
|
+
/** The table's names, sorted. */
|
|
202
|
+
declare function destructiveNames(): string[];
|
|
203
|
+
/**
|
|
204
|
+
* True when a command is destructive by name alone: its annotation is
|
|
205
|
+
* absent or empty and its leaf name is in the table. An explicit
|
|
206
|
+
* annotation, valid or not, always wins: a malformed value is a
|
|
207
|
+
* declaration defect, never inferred over.
|
|
208
|
+
*/
|
|
209
|
+
declare function inferredDestructive(name: string, annotations: Readonly<Record<string, string>> | undefined): boolean;
|
|
210
|
+
/**
|
|
211
|
+
* The tier the delegation gates act on: the declared `kit/side-effect`,
|
|
212
|
+
* else {@link INFERRED_TIER} for a destructive-named command. Undefined
|
|
213
|
+
* when neither says anything. A declared value, valid or malformed, is
|
|
214
|
+
* never replaced.
|
|
215
|
+
*/
|
|
216
|
+
declare function gateSideEffect(name: string, annotations: Readonly<Record<string, string>> | undefined): string | undefined;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @module plan
|
|
220
|
+
* @package @hop-top/kit
|
|
221
|
+
*
|
|
222
|
+
* The structured dry-run output of a write or destructive command. Ports
|
|
223
|
+
* Go `cli.Plan` / `cli.RenderPlan`: a handler that sees `isDryRun(cmd)`
|
|
224
|
+
* builds a {@link Plan} of what it would change and renders it instead of
|
|
225
|
+
* acting.
|
|
226
|
+
*/
|
|
227
|
+
/** One declared state change a {@link Plan} would apply. */
|
|
228
|
+
interface Effect {
|
|
229
|
+
/** A short verb: `create`, `update`, `delete`. */
|
|
230
|
+
kind: string;
|
|
231
|
+
/** The addressable resource (`alias:foo`, `/etc/hosts`). */
|
|
232
|
+
target: string;
|
|
233
|
+
/** Whether the inverse command restores prior state losslessly. */
|
|
234
|
+
reversible: boolean;
|
|
235
|
+
/** A free-form one-line note. */
|
|
236
|
+
detail?: string;
|
|
237
|
+
}
|
|
238
|
+
/** What a command would do if re-issued without `--dry-run`. */
|
|
239
|
+
interface Plan {
|
|
240
|
+
/** The full command path; filled in by {@link renderPlan} when empty. */
|
|
241
|
+
command?: string;
|
|
242
|
+
/** The resolved arguments. */
|
|
243
|
+
args?: Record<string, unknown>;
|
|
244
|
+
/** The ordered changes. */
|
|
245
|
+
effects?: Effect[];
|
|
246
|
+
/** Pre-flight checks that passed while planning. */
|
|
247
|
+
prerequisites_checked?: string[];
|
|
248
|
+
/** Non-fatal advisories for the operator. */
|
|
249
|
+
warnings?: string[];
|
|
250
|
+
/** RFC 3339 UTC time of assembly; stamped when empty. */
|
|
251
|
+
generated_at?: string;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Writes `plan` as the command's dry-run output in `format`: `json` and
|
|
255
|
+
* `yaml` serialize it, anything else prints the plan table. An empty
|
|
256
|
+
* `command` defaults to `commandPath` and an empty `generated_at` to now.
|
|
257
|
+
*/
|
|
258
|
+
declare function renderPlan(w: {
|
|
259
|
+
write(chunk: string): unknown;
|
|
260
|
+
}, format: string, plan: Plan, commandPath?: string): void;
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* @module hint
|
|
264
|
+
* @package @hop-top/kit
|
|
265
|
+
*
|
|
266
|
+
* Contextual next-step hints — mirrors Go's output/hint.go contract.
|
|
267
|
+
*
|
|
268
|
+
* Hints guide users (and agents) toward the logical next action without
|
|
269
|
+
* burying them in a wall of text. They are suppressed when output is
|
|
270
|
+
* machine-formatted (JSON/YAML), piped (non-TTY), or explicitly disabled
|
|
271
|
+
* via flag/env.
|
|
272
|
+
*/
|
|
273
|
+
|
|
274
|
+
/** A single next-step suggestion attached to a command. */
|
|
275
|
+
interface Hint {
|
|
276
|
+
/** Human-readable hint text (e.g. `"Run \`hop version\` to verify."`). */
|
|
277
|
+
message: string;
|
|
278
|
+
/**
|
|
279
|
+
* When provided, the hint is only rendered if this returns true.
|
|
280
|
+
* Omit (or set to undefined) for hints that always apply.
|
|
281
|
+
*/
|
|
282
|
+
condition?: () => boolean;
|
|
283
|
+
}
|
|
284
|
+
/** Options read by {@link hintsEnabled} — subset of parsed CLI opts. */
|
|
285
|
+
interface HintOptions {
|
|
286
|
+
/** Value of --no-hints flag. */
|
|
287
|
+
noHints?: boolean;
|
|
288
|
+
/** Value of --quiet flag. */
|
|
289
|
+
quiet?: boolean;
|
|
290
|
+
/** Value of hints.enabled config key (false = disabled). */
|
|
291
|
+
hintsEnabled?: boolean;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Concurrency-safe registry mapping command names to hints.
|
|
295
|
+
* Mirrors Go's `output.HintSet`.
|
|
296
|
+
*/
|
|
297
|
+
declare class HintSet {
|
|
298
|
+
private readonly m;
|
|
299
|
+
/** Add one or more hints for the given command name. */
|
|
300
|
+
register(cmd: string, ...hints: Hint[]): void;
|
|
301
|
+
/**
|
|
302
|
+
* Return a copy of the hints registered for cmd.
|
|
303
|
+
* Returns an empty array when none are registered.
|
|
304
|
+
*/
|
|
305
|
+
lookup(cmd: string): Hint[];
|
|
306
|
+
}
|
|
307
|
+
/** Return only the hints whose condition is undefined or returns true. */
|
|
308
|
+
declare function active(hints: Hint[]): Hint[];
|
|
309
|
+
/**
|
|
310
|
+
* Report whether hints should be rendered given the current options.
|
|
311
|
+
* Mirrors Go's `output.HintsEnabled`.
|
|
312
|
+
*
|
|
313
|
+
* Hints are disabled when any of:
|
|
314
|
+
* - `opts.noHints` is true
|
|
315
|
+
* - `opts.hintsEnabled` is explicitly false
|
|
316
|
+
* - `opts.quiet` is true
|
|
317
|
+
* - `HOP_QUIET_HINTS` env var is set to `"1"`, `"true"`, or `"yes"`
|
|
318
|
+
*/
|
|
319
|
+
declare function hintsEnabled(opts: HintOptions): boolean;
|
|
320
|
+
/**
|
|
321
|
+
* Write active hints to `w` with dimmed styling.
|
|
322
|
+
* No-op when format is not `"table"`, stdout is not a TTY, or hints disabled.
|
|
323
|
+
* Mirrors Go's `output.RenderHints`.
|
|
324
|
+
*
|
|
325
|
+
* @param w Writable stream (typically `process.stdout`).
|
|
326
|
+
* @param hints Hints to consider (pass `hintSet.lookup(cmdName)`).
|
|
327
|
+
* @param format Current output format.
|
|
328
|
+
* @param opts Parsed CLI options (noHints, quiet, hintsEnabled).
|
|
329
|
+
* @param muted Hex color for the hint prefix/text (e.g. `"#858183"`).
|
|
330
|
+
* Ignored when NO_COLOR env var is set or stdout is not a TTY.
|
|
331
|
+
*/
|
|
332
|
+
declare function renderHints(w: Writable, hints: Hint[], format: Format, opts: HintOptions, muted: string): void;
|
|
333
|
+
/**
|
|
334
|
+
* Add a standard upgrade hint: `"Run \`<binary> version\` to verify."`
|
|
335
|
+
* Active only when `upgraded` returns true.
|
|
336
|
+
* Mirrors Go's `output.RegisterUpgradeHints`.
|
|
337
|
+
*/
|
|
338
|
+
declare function registerUpgradeHints(hints: HintSet, binary: string, upgraded: () => boolean): void;
|
|
339
|
+
/**
|
|
340
|
+
* Add a standard version hint: `"Run \`<binary> upgrade\` to get latest."`
|
|
341
|
+
* Active only when `updateAvail` returns true.
|
|
342
|
+
* Mirrors Go's `output.RegisterVersionHints`.
|
|
343
|
+
*/
|
|
344
|
+
declare function registerVersionHints(hints: HintSet, binary: string, updateAvail: () => boolean): void;
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* @module cli
|
|
348
|
+
* @package @hop-top/kit
|
|
349
|
+
*
|
|
350
|
+
* Commander-based CLI factory that enforces the hop-top CLI contract.
|
|
351
|
+
*
|
|
352
|
+
* The hop-top CLI contract:
|
|
353
|
+
* - No `help` subcommand; help is exposed only as -h/--help flag.
|
|
354
|
+
* - `completion` is a management-group command (hidden from default help).
|
|
355
|
+
* - Version is a root-level option (-v/--version), NOT a subcommand.
|
|
356
|
+
* - All hop-top CLIs expose three global options on the root command:
|
|
357
|
+
* --format <fmt> table | json | yaml (default: "table")
|
|
358
|
+
* --quiet suppress non-essential output
|
|
359
|
+
* --no-color disable ANSI colour
|
|
360
|
+
* - Errors are printed to stderr in error color (unless --no-color is set).
|
|
361
|
+
*
|
|
362
|
+
* Requirements: Node >= 20, commander ^14.
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```ts
|
|
366
|
+
* import { createCLI } from '@hop-top/kit/cli';
|
|
367
|
+
* const { program, theme } = createCLI({ name: 'mytool', version: '1.0.0', description: 'My tool' });
|
|
368
|
+
* program.command('run').action(() => { ... });
|
|
369
|
+
* program.parse();
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Return the single-character shorthand declared by the parity contract's
|
|
375
|
+
* `verbosity.flag`, with leading dashes stripped. A contract value that is
|
|
376
|
+
* not a single character after stripping falls back to `V`.
|
|
377
|
+
*
|
|
378
|
+
* Taking the contract as a parameter (rather than reading the module-level
|
|
379
|
+
* `parity`) keeps the mapping testable against a constructed `ParityData`
|
|
380
|
+
* without mutating the shared `parity.json`.
|
|
381
|
+
*/
|
|
382
|
+
declare function verbosityShorthand(d: ParityData): string;
|
|
383
|
+
/**
|
|
384
|
+
* Render the `-V` option spec commander registers, e.g. `-V, --verbose`.
|
|
385
|
+
* The shorthand comes from the parity contract; the long name is
|
|
386
|
+
* kit-local (the contract declares only the shorthand).
|
|
387
|
+
*/
|
|
388
|
+
declare function verbosityFlagSpec(d: ParityData): string;
|
|
389
|
+
/** Read the accumulated -V count for a parsed command tree. */
|
|
390
|
+
declare function verboseCount(cmd: Command): number;
|
|
391
|
+
/**
|
|
392
|
+
* Report whether `--quiet` is in effect for a parsed command tree.
|
|
393
|
+
*
|
|
394
|
+
* `--quiet` wins over `-V`: when set, `verboseCount` reads 0 and the
|
|
395
|
+
* logger level is the contract's `verbosity.quiet_override`. False before
|
|
396
|
+
* parsing and when `disable.quiet` drops the flag.
|
|
397
|
+
*/
|
|
398
|
+
declare function isQuiet(cmd: Command): boolean;
|
|
399
|
+
interface StreamDef {
|
|
400
|
+
name: string;
|
|
401
|
+
description: string;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Return the long flag name declared by the parity contract's
|
|
405
|
+
* `streams.flag`, with leading dashes stripped (commander's parsed option
|
|
406
|
+
* key is the undashed camelCase name). Falls back to `stream`.
|
|
407
|
+
*
|
|
408
|
+
* Taking the contract as a parameter (rather than reading the module-level
|
|
409
|
+
* `parity`) keeps the mapping testable against a constructed `ParityData`
|
|
410
|
+
* without mutating the shared `parity.json`.
|
|
411
|
+
*/
|
|
412
|
+
declare function streamFlagName(d: ParityData): string;
|
|
413
|
+
/**
|
|
414
|
+
* Render a stream's prefix from the parity contract's
|
|
415
|
+
* `streams.label_format` template. The template's `{name}` placeholder is
|
|
416
|
+
* substituted with the stream name; a trailing space separates the label
|
|
417
|
+
* from the payload.
|
|
418
|
+
*/
|
|
419
|
+
declare function streamLabel(d: ParityData, name: string): string;
|
|
420
|
+
/**
|
|
421
|
+
* Resolve the parity contract's `streams.output` destination to a stream.
|
|
422
|
+
* Anything other than `stdout` resolves to stderr, which is the contract's
|
|
423
|
+
* declared destination.
|
|
424
|
+
*/
|
|
425
|
+
declare function streamOutput(d: ParityData): NodeJS.WritableStream;
|
|
426
|
+
/**
|
|
427
|
+
* Register a named diagnostic stream on a command.
|
|
428
|
+
* Adds the parity contract's stream option (comma-separated) on first call.
|
|
429
|
+
*
|
|
430
|
+
* Parity note: Go uses StringSlice (repeatable --stream); TS and Python
|
|
431
|
+
* use a single comma-separated string value.
|
|
432
|
+
*/
|
|
433
|
+
declare function registerStream(cmd: Command, name: string, description: string): void;
|
|
434
|
+
/** Return registered stream definitions for a command. */
|
|
435
|
+
declare function getStreamDefs(cmd: Command): StreamDef[];
|
|
436
|
+
/**
|
|
437
|
+
* Return a writer for a named stream. When the stream is enabled via the
|
|
438
|
+
* parity contract's stream flag, writes go to the contract's
|
|
439
|
+
* `streams.output` destination, prefixed with its `streams.label_format`
|
|
440
|
+
* label. Otherwise writes are discarded.
|
|
441
|
+
*/
|
|
442
|
+
declare function channel(cmd: Command, name: string): {
|
|
443
|
+
write(s: string): boolean;
|
|
444
|
+
};
|
|
445
|
+
/**
|
|
446
|
+
* Brand color pair used across a theme.
|
|
447
|
+
* Hex strings (e.g. `"#7ED957"`).
|
|
448
|
+
*/
|
|
449
|
+
interface Palette {
|
|
450
|
+
/** Commands / primary accent. */
|
|
451
|
+
command: string;
|
|
452
|
+
/** Flags / secondary accent. */
|
|
453
|
+
flag: string;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Built-in Neon palette — vivid grass green + neon pink.
|
|
457
|
+
* Mirrors Go's `Neon` palette in `kit/cli/theme.go`.
|
|
458
|
+
*/
|
|
459
|
+
declare const Neon: Palette;
|
|
460
|
+
/**
|
|
461
|
+
* Built-in Dark palette — softer lime + pink.
|
|
462
|
+
* Mirrors Go's `Dark` palette in `kit/cli/theme.go`.
|
|
463
|
+
*/
|
|
464
|
+
declare const Dark: Palette;
|
|
465
|
+
/**
|
|
466
|
+
* Semantic color theme for CLI output.
|
|
467
|
+
* Mirrors Go's `Theme` struct in `kit/cli/theme.go`.
|
|
468
|
+
*/
|
|
469
|
+
interface Theme {
|
|
470
|
+
palette: Palette;
|
|
471
|
+
/** Primary accent — same as `palette.command`. */
|
|
472
|
+
accent: string;
|
|
473
|
+
/** Secondary accent — same as `palette.flag`. */
|
|
474
|
+
secondary: string;
|
|
475
|
+
/** Muted/dim color (CharmTone Squid). */
|
|
476
|
+
muted: string;
|
|
477
|
+
/** Error color (CharmTone Cherry). */
|
|
478
|
+
error: string;
|
|
479
|
+
/** Success color (CharmTone Guac). */
|
|
480
|
+
success: string;
|
|
481
|
+
/** Title/header color — mirrors fang's ColorScheme.Title (#FFFFFF). */
|
|
482
|
+
title: string;
|
|
483
|
+
/** Argument placeholder color — mirrors fang's ColorScheme.Argument (#B5E89B). */
|
|
484
|
+
argument: string;
|
|
485
|
+
/** Dimmed argument color — mirrors fang's ColorScheme.DimmedArgument (#8ABF6E). */
|
|
486
|
+
dimmedArgument: string;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Build a Theme from an optional accent override.
|
|
490
|
+
* When `accent` is provided it replaces `palette.command`; otherwise
|
|
491
|
+
* the Neon palette is used. Mirrors Go's `buildTheme` function.
|
|
492
|
+
*/
|
|
493
|
+
declare function buildTheme(accent?: string): Theme;
|
|
494
|
+
/**
|
|
495
|
+
* Configuration passed to {@link createCLI} to identify the program.
|
|
496
|
+
*/
|
|
497
|
+
interface CLIConfig {
|
|
498
|
+
/**
|
|
499
|
+
* Binary name as invoked by the user (e.g. `"mytool"`).
|
|
500
|
+
* Used as the Commander program name and in the version string output.
|
|
501
|
+
*/
|
|
502
|
+
name: string;
|
|
503
|
+
/**
|
|
504
|
+
* Semver version string (e.g. `"1.2.3"`).
|
|
505
|
+
* Exposed via `-v / --version`; do NOT include a leading `v`.
|
|
506
|
+
*/
|
|
507
|
+
version: string;
|
|
508
|
+
/**
|
|
509
|
+
* One-line description shown in help output.
|
|
510
|
+
*/
|
|
511
|
+
description: string;
|
|
512
|
+
/**
|
|
513
|
+
* Optional hex color string (e.g. `"#FF0000"`) used as the theme accent.
|
|
514
|
+
* Omit to use the Neon palette default.
|
|
515
|
+
*/
|
|
516
|
+
accent?: string;
|
|
517
|
+
/** Opt-out built-in global flags. Zero value = all enabled. */
|
|
518
|
+
disable?: {
|
|
519
|
+
format?: boolean;
|
|
520
|
+
quiet?: boolean;
|
|
521
|
+
noColor?: boolean;
|
|
522
|
+
hints?: boolean;
|
|
523
|
+
offline?: boolean;
|
|
524
|
+
/** Drop the root `--dry-run` flag; it is then never applied. */
|
|
525
|
+
dryRun?: boolean;
|
|
526
|
+
};
|
|
527
|
+
/**
|
|
528
|
+
* Resolves a named root `--policy <name>`; see {@link defaultPolicyLoader}
|
|
529
|
+
* for the `$XDG_CONFIG_HOME/<name>/policies/<policy>.yaml` loader. Unset
|
|
530
|
+
* wires none: only the reserved `kit-default` policy resolves.
|
|
531
|
+
*/
|
|
532
|
+
policy?: PolicyLoader;
|
|
533
|
+
/**
|
|
534
|
+
* The terminal the `--confirm` prompt asks on. Defaults to the
|
|
535
|
+
* controlling terminal (`/dev/tty`); with none, an unset `--confirm`
|
|
536
|
+
* resolves to `no`.
|
|
537
|
+
*/
|
|
538
|
+
promptSource?: PromptSource;
|
|
539
|
+
/** Command groups for partitioned help (e.g. COMMANDS vs MANAGEMENT). */
|
|
540
|
+
groups?: Array<{
|
|
541
|
+
id: string;
|
|
542
|
+
title: string;
|
|
543
|
+
hidden?: boolean;
|
|
544
|
+
}>;
|
|
545
|
+
/** Extra tool-specific persistent flags on root command. */
|
|
546
|
+
globals?: Array<{
|
|
547
|
+
name: string;
|
|
548
|
+
short?: string;
|
|
549
|
+
usage: string;
|
|
550
|
+
default?: string;
|
|
551
|
+
}>;
|
|
552
|
+
/**
|
|
553
|
+
* Root --help layout overrides.
|
|
554
|
+
* Defaults are loaded from contracts/parity/parity.json.
|
|
555
|
+
*/
|
|
556
|
+
help?: {
|
|
557
|
+
/**
|
|
558
|
+
* Appended to `description` as a separate paragraph when non-empty.
|
|
559
|
+
* Empty = no extra block.
|
|
560
|
+
*/
|
|
561
|
+
disclaimer?: string;
|
|
562
|
+
/**
|
|
563
|
+
* Section rendering order using fang vocabulary
|
|
564
|
+
* (e.g. `["commands", "flags"]`). Omit to use parity.json default.
|
|
565
|
+
*/
|
|
566
|
+
sectionOrder?: string[];
|
|
567
|
+
showAliases?: boolean;
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Result of {@link createCLI}.
|
|
572
|
+
*/
|
|
573
|
+
interface CLIResult {
|
|
574
|
+
/** Configured Commander root program. */
|
|
575
|
+
program: Command;
|
|
576
|
+
/** Theme derived from the config accent (or Neon default). */
|
|
577
|
+
theme: Theme;
|
|
578
|
+
}
|
|
579
|
+
/** Assign a command to a named group (used in formatHelp partitioning). */
|
|
580
|
+
declare function setCommandGroup(cmd: Command, groupId: string): void;
|
|
581
|
+
/** Retrieve the group ID for a command (undefined = default group). */
|
|
582
|
+
declare function getCommandGroup(cmd: Command): string | undefined;
|
|
583
|
+
/**
|
|
584
|
+
* Apply hop-top brand colors to Commander's help output.
|
|
585
|
+
*
|
|
586
|
+
* Uses Commander's structured Help API (optionTerm, subcommandTerm, etc.)
|
|
587
|
+
* to color each element independently — no regex post-processing on
|
|
588
|
+
* description text.
|
|
589
|
+
*
|
|
590
|
+
* Color mapping (mirrors Go's brandColorScheme):
|
|
591
|
+
* - Section headers: #FFFFFF bold
|
|
592
|
+
* - Flag names: theme.secondary (#FF00FF)
|
|
593
|
+
* - Command names: theme.accent (#7ED957)
|
|
594
|
+
* - Arguments (<angle>): theme.argument (#B5E89B)
|
|
595
|
+
* - Dimmed args ([optional]): theme.dimmedArgument (#8ABF6E)
|
|
596
|
+
* - Descriptions: theme.muted (#858183)
|
|
597
|
+
* - Usage program name: theme.accent
|
|
598
|
+
*/
|
|
599
|
+
declare function applyHelpTheme(program: Command, theme: Theme, noColor: boolean, sectionOrder?: string[], showAliases?: boolean, groups?: CLIConfig['groups']): void;
|
|
600
|
+
/**
|
|
601
|
+
* Creates a Commander `Command` (root program) pre-configured to the hop-top CLI contract.
|
|
602
|
+
*
|
|
603
|
+
* Contract enforced by this factory (callers must NOT override these):
|
|
604
|
+
* - No `help` subcommand; -h/--help flag only.
|
|
605
|
+
* - `completion` available as management-group command (hidden by default).
|
|
606
|
+
* - `-v, --version` is a root option (not a subcommand); prints `<name> v<version>` and exits.
|
|
607
|
+
* - Global options added to the returned program:
|
|
608
|
+
* `--format <fmt>` Output format — `"table"` | `"json"` | `"yaml"` (default `"table"`)
|
|
609
|
+
* `--quiet` Suppress non-essential output (boolean, default `false`)
|
|
610
|
+
* `--no-color` Disable ANSI colour (boolean, default `false`)
|
|
611
|
+
* - `showHelpAfterError` is enabled; unknown commands print help to stderr.
|
|
612
|
+
* - Errors are written to stderr in `theme.error` color unless `--no-color` is active.
|
|
613
|
+
*
|
|
614
|
+
* Requires commander ^14. Do not add `-v/--version`, `--format`, `--quiet`, or
|
|
615
|
+
* `--no-color` again on the returned program — they are already registered.
|
|
616
|
+
*
|
|
617
|
+
* @param cfg - Program identity (name, version, description, optional accent). See {@link CLIConfig}.
|
|
618
|
+
* @returns `{ program, theme }` — program ready for sub-commands; theme for TUI components.
|
|
619
|
+
*
|
|
620
|
+
* @example
|
|
621
|
+
* ```ts
|
|
622
|
+
* const { program, theme } = createCLI({ name: 'hop', version: '2.0.0', description: 'hop CLI' });
|
|
623
|
+
* program.command('deploy').action(() => { ... });
|
|
624
|
+
* program.parse();
|
|
625
|
+
* ```
|
|
626
|
+
*/
|
|
627
|
+
declare function createCLI(cfg: CLIConfig): CLIResult;
|
|
628
|
+
|
|
629
|
+
type cli_CLIConfig = CLIConfig;
|
|
630
|
+
type cli_CLIResult = CLIResult;
|
|
631
|
+
type cli_ConfirmMode = ConfirmMode;
|
|
632
|
+
declare const cli_Dark: typeof Dark;
|
|
633
|
+
type cli_DryRunPolicy = DryRunPolicy;
|
|
634
|
+
type cli_Effect = Effect;
|
|
635
|
+
type cli_Engine = Engine;
|
|
636
|
+
declare const cli_Engine: typeof Engine;
|
|
637
|
+
declare const cli_ErrOffline: typeof ErrOffline;
|
|
638
|
+
type cli_Hint = Hint;
|
|
639
|
+
type cli_HintOptions = HintOptions;
|
|
640
|
+
type cli_HintSet = HintSet;
|
|
641
|
+
declare const cli_HintSet: typeof HintSet;
|
|
642
|
+
declare const cli_INFERRED_TIER: typeof INFERRED_TIER;
|
|
643
|
+
declare const cli_KIT_DEFAULT_NAME: typeof KIT_DEFAULT_NAME;
|
|
644
|
+
type cli_MaxOpsExceededError = MaxOpsExceededError;
|
|
645
|
+
declare const cli_MaxOpsExceededError: typeof MaxOpsExceededError;
|
|
646
|
+
declare const cli_Neon: typeof Neon;
|
|
647
|
+
declare const cli_OfflineError: typeof OfflineError;
|
|
648
|
+
type cli_Palette = Palette;
|
|
649
|
+
type cli_Plan = Plan;
|
|
650
|
+
type cli_Policy = Policy;
|
|
651
|
+
type cli_PolicyLoader = PolicyLoader;
|
|
652
|
+
type cli_PromptSource = PromptSource;
|
|
653
|
+
type cli_Prompter = Prompter;
|
|
654
|
+
declare const cli_SIDE_EFFECT_TIERS: typeof SIDE_EFFECT_TIERS;
|
|
655
|
+
type cli_SideEffect = SideEffect;
|
|
656
|
+
type cli_Theme = Theme;
|
|
657
|
+
type cli_Verdict = Verdict;
|
|
658
|
+
declare const cli_active: typeof active;
|
|
659
|
+
declare const cli_applyHelpTheme: typeof applyHelpTheme;
|
|
660
|
+
declare const cli_buildTheme: typeof buildTheme;
|
|
661
|
+
declare const cli_channel: typeof channel;
|
|
662
|
+
declare const cli_controllingTTY: typeof controllingTTY;
|
|
663
|
+
declare const cli_createCLI: typeof createCLI;
|
|
664
|
+
declare const cli_defaultPolicyLoader: typeof defaultPolicyLoader;
|
|
665
|
+
declare const cli_destructiveNames: typeof destructiveNames;
|
|
666
|
+
declare const cli_destructiveToken: typeof destructiveToken;
|
|
667
|
+
declare const cli_dryRunApplied: typeof dryRunApplied;
|
|
668
|
+
declare const cli_gateSideEffect: typeof gateSideEffect;
|
|
669
|
+
declare const cli_getCommandGroup: typeof getCommandGroup;
|
|
670
|
+
declare const cli_getStreamDefs: typeof getStreamDefs;
|
|
671
|
+
declare const cli_guardFetch: typeof guardFetch;
|
|
672
|
+
declare const cli_hintsEnabled: typeof hintsEnabled;
|
|
673
|
+
declare const cli_inferredDestructive: typeof inferredDestructive;
|
|
674
|
+
declare const cli_installConfirmTokenFlag: typeof installConfirmTokenFlag;
|
|
675
|
+
declare const cli_isDestructiveLike: typeof isDestructiveLike;
|
|
676
|
+
declare const cli_isDestructiveName: typeof isDestructiveName;
|
|
677
|
+
declare const cli_isDryRun: typeof isDryRun;
|
|
678
|
+
declare const cli_isOffline: typeof isOffline;
|
|
679
|
+
declare const cli_isOfflineError: typeof isOfflineError;
|
|
680
|
+
declare const cli_isQuiet: typeof isQuiet;
|
|
681
|
+
declare const cli_isWriteLike: typeof isWriteLike;
|
|
682
|
+
declare const cli_kitDefault: typeof kitDefault;
|
|
683
|
+
declare const cli_loadNamedPolicy: typeof loadNamedPolicy;
|
|
684
|
+
declare const cli_loadPolicy: typeof loadPolicy;
|
|
685
|
+
declare const cli_noPrompt: typeof noPrompt;
|
|
686
|
+
declare const cli_registerStream: typeof registerStream;
|
|
687
|
+
declare const cli_registerUpgradeHints: typeof registerUpgradeHints;
|
|
688
|
+
declare const cli_registerVersionHints: typeof registerVersionHints;
|
|
689
|
+
declare const cli_renderHints: typeof renderHints;
|
|
690
|
+
declare const cli_renderPlan: typeof renderPlan;
|
|
691
|
+
declare const cli_resolveConfirmMode: typeof resolveConfirmMode;
|
|
692
|
+
declare const cli_resolveDryRunPolicy: typeof resolveDryRunPolicy;
|
|
693
|
+
declare const cli_resolvePolicyPath: typeof resolvePolicyPath;
|
|
694
|
+
declare const cli_scriptedPrompt: typeof scriptedPrompt;
|
|
695
|
+
declare const cli_setCommandGroup: typeof setCommandGroup;
|
|
696
|
+
declare const cli_streamFlagName: typeof streamFlagName;
|
|
697
|
+
declare const cli_streamLabel: typeof streamLabel;
|
|
698
|
+
declare const cli_streamOutput: typeof streamOutput;
|
|
699
|
+
declare const cli_verboseCount: typeof verboseCount;
|
|
700
|
+
declare const cli_verbosityFlagSpec: typeof verbosityFlagSpec;
|
|
701
|
+
declare const cli_verbosityShorthand: typeof verbosityShorthand;
|
|
702
|
+
declare const cli_withOffline: typeof withOffline;
|
|
703
|
+
declare namespace cli {
|
|
704
|
+
export { type cli_CLIConfig as CLIConfig, type cli_CLIResult as CLIResult, type cli_ConfirmMode as ConfirmMode, cli_Dark as Dark, type cli_DryRunPolicy as DryRunPolicy, type cli_Effect as Effect, cli_Engine as Engine, cli_ErrOffline as ErrOffline, type cli_Hint as Hint, type cli_HintOptions as HintOptions, cli_HintSet as HintSet, cli_INFERRED_TIER as INFERRED_TIER, cli_KIT_DEFAULT_NAME as KIT_DEFAULT_NAME, cli_MaxOpsExceededError as MaxOpsExceededError, cli_Neon as Neon, cli_OfflineError as OfflineError, type cli_Palette as Palette, type cli_Plan as Plan, type cli_Policy as Policy, type cli_PolicyLoader as PolicyLoader, type cli_PromptSource as PromptSource, type cli_Prompter as Prompter, cli_SIDE_EFFECT_TIERS as SIDE_EFFECT_TIERS, type cli_SideEffect as SideEffect, type cli_Theme as Theme, type cli_Verdict as Verdict, cli_active as active, cli_applyHelpTheme as applyHelpTheme, cli_buildTheme as buildTheme, cli_channel as channel, cli_controllingTTY as controllingTTY, cli_createCLI as createCLI, cli_defaultPolicyLoader as defaultPolicyLoader, cli_destructiveNames as destructiveNames, cli_destructiveToken as destructiveToken, cli_dryRunApplied as dryRunApplied, cli_gateSideEffect as gateSideEffect, cli_getCommandGroup as getCommandGroup, cli_getStreamDefs as getStreamDefs, cli_guardFetch as guardFetch, cli_hintsEnabled as hintsEnabled, cli_inferredDestructive as inferredDestructive, cli_installConfirmTokenFlag as installConfirmTokenFlag, cli_isDestructiveLike as isDestructiveLike, cli_isDestructiveName as isDestructiveName, cli_isDryRun as isDryRun, cli_isOffline as isOffline, cli_isOfflineError as isOfflineError, cli_isQuiet as isQuiet, cli_isWriteLike as isWriteLike, cli_kitDefault as kitDefault, cli_loadNamedPolicy as loadNamedPolicy, cli_loadPolicy as loadPolicy, cli_noPrompt as noPrompt, cli_registerStream as registerStream, cli_registerUpgradeHints as registerUpgradeHints, cli_registerVersionHints as registerVersionHints, cli_renderHints as renderHints, cli_renderPlan as renderPlan, cli_resolveConfirmMode as resolveConfirmMode, cli_resolveDryRunPolicy as resolveDryRunPolicy, cli_resolvePolicyPath as resolvePolicyPath, cli_scriptedPrompt as scriptedPrompt, cli_setCommandGroup as setCommandGroup, cli_streamFlagName as streamFlagName, cli_streamLabel as streamLabel, cli_streamOutput as streamOutput, cli_verboseCount as verboseCount, cli_verbosityFlagSpec as verbosityFlagSpec, cli_verbosityShorthand as verbosityShorthand, cli_withOffline as withOffline };
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
export { renderHints as $, hintsEnabled as A, inferredDestructive as B, type CLIConfig as C, Dark as D, type Effect as E, installConfirmTokenFlag as F, isDestructiveLike as G, type Hint as H, INFERRED_TIER as I, isDestructiveName as J, KIT_DEFAULT_NAME as K, isDryRun as L, MaxOpsExceededError as M, Neon as N, isQuiet as O, type Palette as P, isWriteLike as Q, kitDefault as R, SIDE_EFFECT_TIERS as S, type Theme as T, loadNamedPolicy as U, type Verdict as V, loadPolicy as W, noPrompt as X, registerStream as Y, registerUpgradeHints as Z, registerVersionHints as _, type CLIResult as a, renderPlan as a0, resolveConfirmMode as a1, resolveDryRunPolicy as a2, resolvePolicyPath as a3, scriptedPrompt as a4, setCommandGroup as a5, streamFlagName as a6, streamLabel as a7, streamOutput as a8, verboseCount as a9, verbosityFlagSpec as aa, verbosityShorthand as ab, type ConfirmMode as b, cli as c, type DryRunPolicy as d, Engine as e, type HintOptions as f, HintSet as g, type Plan as h, type Policy as i, type PolicyLoader as j, type PromptSource as k, type Prompter as l, type SideEffect as m, active as n, applyHelpTheme as o, buildTheme as p, channel as q, controllingTTY as r, createCLI as s, defaultPolicyLoader as t, destructiveNames as u, destructiveToken as v, dryRunApplied as w, gateSideEffect as x, getCommandGroup as y, getStreamDefs as z };
|