@hop-top/kit 0.4.0-alpha.1
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 +86 -0
- package/LICENSE +25 -0
- package/README.md +189 -0
- package/dist/aim.d.ts +116 -0
- package/dist/aim.js +417 -0
- package/dist/alias.d.ts +73 -0
- package/dist/alias.js +207 -0
- package/dist/api.d.ts +62 -0
- package/dist/api.js +165 -0
- package/dist/auth.d.ts +26 -0
- package/dist/auth.js +41 -0
- package/dist/cli.d.ts +309 -0
- package/dist/cli.js +885 -0
- package/dist/config.d.ts +97 -0
- package/dist/config.js +79 -0
- package/dist/errcorrect.d.ts +37 -0
- package/dist/errcorrect.js +69 -0
- package/dist/llm.d.ts +188 -0
- package/dist/llm.js +356 -0
- package/dist/output.d.ts +213 -0
- package/dist/output.js +447 -0
- package/dist/progress.d.ts +30 -0
- package/dist/progress.js +56 -0
- package/dist/provenance.d.ts +24 -0
- package/dist/provenance.js +32 -0
- package/dist/routellm.d.ts +64 -0
- package/dist/routellm.js +258 -0
- package/dist/rpc.d.ts +25 -0
- package/dist/rpc.js +101 -0
- package/dist/safety.d.ts +24 -0
- package/dist/safety.js +44 -0
- package/dist/scope.d.ts +121 -0
- package/dist/scope.js +380 -0
- package/dist/sqlstore.d.ts +84 -0
- package/dist/sqlstore.js +85 -0
- package/dist/stream.d.ts +35 -0
- package/dist/stream.js +52 -0
- package/dist/tui/index.d.ts +300 -0
- package/dist/tui/index.js +332 -0
- package/dist/upgrade.d.ts +95 -0
- package/dist/upgrade.js +115 -0
- package/dist/xdg.d.ts +169 -0
- package/dist/xdg.js +129 -0
- package/eslint.config.mjs +17 -0
- package/package.json +133 -0
- package/src/README.md +3 -0
- package/src/aim.test.ts +331 -0
- package/src/aim.ts +388 -0
- package/src/alias.test.ts +423 -0
- package/src/alias.ts +256 -0
- package/src/api.test.ts +190 -0
- package/src/api.ts +214 -0
- package/src/auth.test.ts +24 -0
- package/src/auth.ts +37 -0
- package/src/bus.test.ts +178 -0
- package/src/bus.ts +114 -0
- package/src/cli.test.ts +690 -0
- package/src/cli.ts +741 -0
- package/src/completion-values.test.ts +202 -0
- package/src/completion-values.ts +173 -0
- package/src/completion.test.ts +212 -0
- package/src/completion.ts +158 -0
- package/src/compliance.test.ts +134 -0
- package/src/compliance.ts +669 -0
- package/src/config.test.ts +110 -0
- package/src/config.ts +164 -0
- package/src/errcorrect.test.ts +134 -0
- package/src/errcorrect.ts +84 -0
- package/src/flagregister.test.ts +103 -0
- package/src/flagregister.ts +78 -0
- package/src/gen/crud_connect.ts +76 -0
- package/src/gen/crud_pb.ts +269 -0
- package/src/hint.test.ts +315 -0
- package/src/hint.ts +178 -0
- package/src/llm.test.ts +612 -0
- package/src/llm.ts +577 -0
- package/src/log.test.ts +145 -0
- package/src/log.ts +155 -0
- package/src/output/builtins.ts +34 -0
- package/src/output/dispatch.ts +195 -0
- package/src/output/flags.ts +151 -0
- package/src/output/format_help.ts +80 -0
- package/src/output/formatter.ts +167 -0
- package/src/output/formatters/csv.ts +72 -0
- package/src/output/formatters/json.ts +44 -0
- package/src/output/formatters/table.ts +44 -0
- package/src/output/formatters/text.ts +109 -0
- package/src/output/formatters/yaml.ts +47 -0
- package/src/output/projection.ts +126 -0
- package/src/output/registry.ts +88 -0
- package/src/output/template.ts +63 -0
- package/src/output.test.ts +117 -0
- package/src/output.ts +90 -0
- package/src/progress.test.ts +93 -0
- package/src/progress.ts +58 -0
- package/src/provenance.test.ts +59 -0
- package/src/provenance.ts +26 -0
- package/src/routellm.test.ts +179 -0
- package/src/routellm.ts +365 -0
- package/src/router/bert.test.ts +180 -0
- package/src/router/bert.ts +145 -0
- package/src/router/controller.test.ts +183 -0
- package/src/router/controller.ts +165 -0
- package/src/router/integration.test.ts +309 -0
- package/src/router/intent.test.ts +187 -0
- package/src/router/intent.ts +208 -0
- package/src/router/mf.test.ts +66 -0
- package/src/router/mf.ts +52 -0
- package/src/router/random.test.ts +23 -0
- package/src/router/random.ts +13 -0
- package/src/router/router.test.ts +31 -0
- package/src/router/router.ts +62 -0
- package/src/router/server.test.ts +193 -0
- package/src/router/server.ts +134 -0
- package/src/router/sw.test.ts +199 -0
- package/src/router/sw.ts +232 -0
- package/src/rpc.test.ts +47 -0
- package/src/rpc.ts +91 -0
- package/src/safety.test.ts +53 -0
- package/src/safety.ts +42 -0
- package/src/scope-defaults.json +72 -0
- package/src/scope.test.ts +177 -0
- package/src/scope.ts +382 -0
- package/src/setflag.test.ts +110 -0
- package/src/setflag.ts +102 -0
- package/src/sqlstore.test.ts +110 -0
- package/src/sqlstore.ts +144 -0
- package/src/stream.test.ts +69 -0
- package/src/stream.ts +47 -0
- package/src/textflag.test.ts +105 -0
- package/src/textflag.ts +68 -0
- package/src/toolspec.test.ts +187 -0
- package/src/toolspec.ts +279 -0
- package/src/triton/client.test.ts +205 -0
- package/src/triton/client.ts +261 -0
- package/src/tui/anim.test.ts +146 -0
- package/src/tui/anim.ts +134 -0
- package/src/tui/badge.test.ts +41 -0
- package/src/tui/badge.ts +55 -0
- package/src/tui/confirm.test.ts +68 -0
- package/src/tui/confirm.ts +49 -0
- package/src/tui/index.ts +29 -0
- package/src/tui/list.test.ts +84 -0
- package/src/tui/list.ts +72 -0
- package/src/tui/parity.ts +41 -0
- package/src/tui/pills.test.ts +40 -0
- package/src/tui/pills.ts +43 -0
- package/src/tui/progress.test.ts +164 -0
- package/src/tui/progress.ts +120 -0
- package/src/tui/spinner.test.ts +111 -0
- package/src/tui/spinner.ts +96 -0
- package/src/tui/status.test.ts +68 -0
- package/src/tui/status.ts +66 -0
- package/src/upgrade.test.ts +298 -0
- package/src/upgrade.ts +205 -0
- package/src/uri.ts +199 -0
- package/src/wizard.test.ts +441 -0
- package/src/wizard.ts +662 -0
- package/src/xdg.test.ts +202 -0
- package/src/xdg.ts +280 -0
- package/test/output/cols.test.ts +148 -0
- package/test/output/csv.test.ts +129 -0
- package/test/output/dispatch.test.ts +194 -0
- package/test/output/format_help.test.ts +131 -0
- package/test/output/formatter.test.ts +137 -0
- package/test/output/output_flag.test.ts +124 -0
- package/test/output/registry.test.ts +127 -0
- package/test/output/smoke-capture.ts +83 -0
- package/test/output/smoke.test.ts +142 -0
- package/test/output/template.test.ts +95 -0
- package/test/output/text.test.ts +75 -0
- package/test/testdata/api-fixture.json +115 -0
- package/test/testdata/query-vectors.json +187 -0
- package/tsconfig.json +12 -0
package/src/hint.ts
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module hint
|
|
3
|
+
* @package @hop-top/kit
|
|
4
|
+
*
|
|
5
|
+
* Contextual next-step hints — mirrors Go's output/hint.go contract.
|
|
6
|
+
*
|
|
7
|
+
* Hints guide users (and agents) toward the logical next action without
|
|
8
|
+
* burying them in a wall of text. They are suppressed when output is
|
|
9
|
+
* machine-formatted (JSON/YAML), piped (non-TTY), or explicitly disabled
|
|
10
|
+
* via flag/env.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { Writable } from 'node:stream';
|
|
14
|
+
import type { Format } from './output.js';
|
|
15
|
+
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// Types
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
/** A single next-step suggestion attached to a command. */
|
|
21
|
+
export interface Hint {
|
|
22
|
+
/** Human-readable hint text (e.g. `"Run \`hop version\` to verify."`). */
|
|
23
|
+
message: string;
|
|
24
|
+
/**
|
|
25
|
+
* When provided, the hint is only rendered if this returns true.
|
|
26
|
+
* Omit (or set to undefined) for hints that always apply.
|
|
27
|
+
*/
|
|
28
|
+
condition?: () => boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Options read by {@link hintsEnabled} — subset of parsed CLI opts. */
|
|
32
|
+
export interface HintOptions {
|
|
33
|
+
/** Value of --no-hints flag. */
|
|
34
|
+
noHints?: boolean;
|
|
35
|
+
/** Value of --quiet flag. */
|
|
36
|
+
quiet?: boolean;
|
|
37
|
+
/** Value of hints.enabled config key (false = disabled). */
|
|
38
|
+
hintsEnabled?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
// HintSet
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Concurrency-safe registry mapping command names to hints.
|
|
47
|
+
* Mirrors Go's `output.HintSet`.
|
|
48
|
+
*/
|
|
49
|
+
export class HintSet {
|
|
50
|
+
private readonly m: Map<string, Hint[]> = new Map();
|
|
51
|
+
|
|
52
|
+
/** Add one or more hints for the given command name. */
|
|
53
|
+
register(cmd: string, ...hints: Hint[]): void {
|
|
54
|
+
const existing = this.m.get(cmd) ?? [];
|
|
55
|
+
this.m.set(cmd, [...existing, ...hints]);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Return a copy of the hints registered for cmd.
|
|
60
|
+
* Returns an empty array when none are registered.
|
|
61
|
+
*/
|
|
62
|
+
lookup(cmd: string): Hint[] {
|
|
63
|
+
return [...(this.m.get(cmd) ?? [])];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
// Helpers
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
|
|
71
|
+
/** Return only the hints whose condition is undefined or returns true. */
|
|
72
|
+
export function active(hints: Hint[]): Hint[] {
|
|
73
|
+
return hints.filter(h => h.condition === undefined || h.condition());
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Report whether hints should be rendered given the current options.
|
|
78
|
+
* Mirrors Go's `output.HintsEnabled`.
|
|
79
|
+
*
|
|
80
|
+
* Hints are disabled when any of:
|
|
81
|
+
* - `opts.noHints` is true
|
|
82
|
+
* - `opts.hintsEnabled` is explicitly false
|
|
83
|
+
* - `opts.quiet` is true
|
|
84
|
+
* - `HOP_QUIET_HINTS` env var is set to `"1"`, `"true"`, or `"yes"`
|
|
85
|
+
*/
|
|
86
|
+
export function hintsEnabled(opts: HintOptions): boolean {
|
|
87
|
+
if (opts.noHints) return false;
|
|
88
|
+
if (opts.hintsEnabled === false) return false;
|
|
89
|
+
if (opts.quiet) return false;
|
|
90
|
+
const env = process.env['HOP_QUIET_HINTS'];
|
|
91
|
+
if (env === '1' || env === 'true' || env === 'yes') return false;
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Write active hints to `w` with dimmed styling.
|
|
97
|
+
* No-op when format is not `"table"`, stdout is not a TTY, or hints disabled.
|
|
98
|
+
* Mirrors Go's `output.RenderHints`.
|
|
99
|
+
*
|
|
100
|
+
* @param w Writable stream (typically `process.stdout`).
|
|
101
|
+
* @param hints Hints to consider (pass `hintSet.lookup(cmdName)`).
|
|
102
|
+
* @param format Current output format.
|
|
103
|
+
* @param opts Parsed CLI options (noHints, quiet, hintsEnabled).
|
|
104
|
+
* @param muted Hex color for the hint prefix/text (e.g. `"#858183"`).
|
|
105
|
+
* Ignored when NO_COLOR env var is set or stdout is not a TTY.
|
|
106
|
+
*/
|
|
107
|
+
export function renderHints(
|
|
108
|
+
w: Writable,
|
|
109
|
+
hints: Hint[],
|
|
110
|
+
format: Format,
|
|
111
|
+
opts: HintOptions,
|
|
112
|
+
muted: string,
|
|
113
|
+
): void {
|
|
114
|
+
if (format !== 'table') return;
|
|
115
|
+
if (!hintsEnabled(opts)) return;
|
|
116
|
+
|
|
117
|
+
// TTY check — only render to an actual terminal.
|
|
118
|
+
const isTTY = (w as NodeJS.WriteStream).isTTY === true;
|
|
119
|
+
if (!isTTY) return;
|
|
120
|
+
|
|
121
|
+
const visible = active(hints);
|
|
122
|
+
if (visible.length === 0) return;
|
|
123
|
+
|
|
124
|
+
const noColor =
|
|
125
|
+
process.env['NO_COLOR'] !== undefined ||
|
|
126
|
+
process.argv.includes('--no-color');
|
|
127
|
+
|
|
128
|
+
w.write('\n');
|
|
129
|
+
for (const h of visible) {
|
|
130
|
+
const text = `→ ${h.message}`;
|
|
131
|
+
if (noColor) {
|
|
132
|
+
w.write(text + '\n');
|
|
133
|
+
} else {
|
|
134
|
+
// ANSI 24-bit foreground SGR from hex muted color.
|
|
135
|
+
const hex = muted.replace('#', '');
|
|
136
|
+
const r = parseInt(hex.slice(0, 2), 16);
|
|
137
|
+
const g = parseInt(hex.slice(2, 4), 16);
|
|
138
|
+
const b = parseInt(hex.slice(4, 6), 16);
|
|
139
|
+
w.write(`\x1b[38;2;${r};${g};${b}m${text}\x1b[0m\n`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ---------------------------------------------------------------------------
|
|
145
|
+
// Standard hint factories
|
|
146
|
+
// ---------------------------------------------------------------------------
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Add a standard upgrade hint: `"Run \`<binary> version\` to verify."`
|
|
150
|
+
* Active only when `upgraded` returns true.
|
|
151
|
+
* Mirrors Go's `output.RegisterUpgradeHints`.
|
|
152
|
+
*/
|
|
153
|
+
export function registerUpgradeHints(
|
|
154
|
+
hints: HintSet,
|
|
155
|
+
binary: string,
|
|
156
|
+
upgraded: () => boolean,
|
|
157
|
+
): void {
|
|
158
|
+
hints.register('upgrade', {
|
|
159
|
+
message: `Run \`${binary} version\` to verify.`,
|
|
160
|
+
condition: upgraded,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Add a standard version hint: `"Run \`<binary> upgrade\` to get latest."`
|
|
166
|
+
* Active only when `updateAvail` returns true.
|
|
167
|
+
* Mirrors Go's `output.RegisterVersionHints`.
|
|
168
|
+
*/
|
|
169
|
+
export function registerVersionHints(
|
|
170
|
+
hints: HintSet,
|
|
171
|
+
binary: string,
|
|
172
|
+
updateAvail: () => boolean,
|
|
173
|
+
): void {
|
|
174
|
+
hints.register('version', {
|
|
175
|
+
message: `Run \`${binary} upgrade\` to get latest.`,
|
|
176
|
+
condition: updateAvail,
|
|
177
|
+
});
|
|
178
|
+
}
|