@hop-top/kit 0.5.0-alpha.1 → 0.5.0-alpha.3
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 +107 -0
- package/README.md +333 -9
- package/dist/aim-CTp-kJW2.d.ts +139 -0
- package/dist/aim.d.ts +1 -116
- package/dist/alias-dhhr08Ei.d.ts +88 -0
- package/dist/alias.d.ts +2 -73
- package/dist/api-miiso81x.d.ts +77 -0
- package/dist/api.d.ts +1 -62
- package/dist/auth-2-jfgiHn.d.ts +34 -0
- package/dist/auth.d.ts +1 -26
- package/dist/cli-DLygZLi9.d.ts +450 -0
- package/dist/cli.d.ts +6 -309
- package/dist/cli.js +192 -63
- package/dist/config-BUY7_W2n.d.ts +103 -0
- package/dist/config.d.ts +1 -97
- package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
- package/dist/errcorrect.d.ts +1 -37
- package/dist/error-DISJKeDu.d.ts +144 -0
- package/dist/id/index.d.ts +2 -83
- package/dist/index-Bc5c7Ty5.d.ts +328 -0
- package/dist/index-C3Zw4wDJ.d.ts +359 -0
- package/dist/index-MLrRDvEG.d.ts +1073 -0
- package/dist/index-QSffbLnj.d.ts +94 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +6794 -0
- package/dist/llm-B5XUWH8T.d.ts +231 -0
- package/dist/llm.d.ts +1 -188
- package/dist/mcp/index.d.ts +2 -0
- package/dist/mcp/index.js +1453 -0
- package/dist/netpolicy-asvCfwi8.d.ts +138 -0
- package/dist/netpolicy.d.ts +1 -0
- package/dist/netpolicy.js +118 -0
- package/dist/output-4aXs91GY.d.ts +396 -0
- package/dist/output.d.ts +3 -213
- package/dist/output.js +567 -43
- package/dist/progress-CAzyxeWl.d.ts +38 -0
- package/dist/progress.d.ts +1 -30
- package/dist/provenance-SMFHm5gx.d.ts +30 -0
- package/dist/provenance.d.ts +1 -24
- package/dist/routellm-PGSt2D1y.d.ts +75 -0
- package/dist/routellm.d.ts +2 -64
- package/dist/rpc-D5xLEf8V.d.ts +32 -0
- package/dist/rpc.d.ts +2 -25
- package/dist/safety-CUaYEjZc.d.ts +30 -0
- package/dist/safety.d.ts +1 -24
- package/dist/scope-BrhYB4ij.d.ts +141 -0
- package/dist/scope.d.ts +1 -121
- package/dist/serve-DE-jscpb.d.ts +646 -0
- package/dist/serve.d.ts +3 -0
- package/dist/serve.js +1019 -0
- package/dist/stream-CrjeCp0M.d.ts +44 -0
- package/dist/stream.d.ts +1 -35
- package/dist/telemetry/index.d.ts +1 -315
- package/dist/telemetry/index.js +12 -1
- package/dist/tui/index.d.ts +5 -298
- package/dist/tui/index.js +3 -10
- package/dist/upgrade-p_zh3pvV.d.ts +102 -0
- package/dist/upgrade.d.ts +1 -95
- package/dist/xdg-DB7Shoib.d.ts +179 -0
- package/dist/xdg.d.ts +1 -169
- package/package.json +26 -3
- package/src/cli.offline.test.ts +93 -0
- package/src/cli.parity.test.ts +192 -0
- package/src/cli.ts +112 -12
- package/src/index.test.ts +58 -0
- package/src/index.ts +37 -0
- package/src/log.parity.test.ts +105 -0
- package/src/log.ts +64 -13
- package/src/mcp/bridge.test.ts +150 -0
- package/src/mcp/bridge.ts +246 -0
- package/src/mcp/conformance.test.ts +336 -0
- package/src/mcp/dispatch.ts +313 -0
- package/src/mcp/index.ts +138 -0
- package/src/mcp/legacy.ts +314 -0
- package/src/mcp/mcp.test.ts +697 -0
- package/src/mcp/modern-confirm.test.ts +520 -0
- package/src/mcp/modern-confirm.ts +452 -0
- package/src/mcp/modern.ts +723 -0
- package/src/mcp/tasks.ts +82 -0
- package/src/mcp/testtree.ts +250 -0
- package/src/mcp/types.ts +504 -0
- package/src/netpolicy.test.ts +202 -0
- package/src/netpolicy.ts +231 -0
- package/src/output/dispatch.ts +10 -2
- package/src/output/error.ts +316 -0
- package/src/output/formatter.ts +29 -5
- 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 +41 -3
- package/src/serve.test.ts +1257 -0
- package/src/serve.ts +1665 -0
- package/src/telemetry/client.test.ts +31 -0
- package/src/telemetry/client.ts +7 -1
- package/src/telemetry/offline.test.ts +64 -0
- package/src/tui/parity.test.ts +120 -31
- package/src/tui/parity.ts +58 -7
- package/test/output/csv.test.ts +164 -0
- package/test/output/error.test.ts +246 -0
- package/src/tui/parity.json +0 -74
package/dist/tui/index.d.ts
CHANGED
|
@@ -1,300 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
export { A as Anim, a as AnimOpts, B as BadgeOpts, C as ConfirmOpts, L as ListItem, b as ListOpts, P as Progress, S as Spinner, c as StatusKind, d as anim, e as badge, f as clamp01, g as confirm, l as list, m as makeGradient, p as pills, h as progress, r as renderBarPlain, s as spinner, j as status } from '../index-Bc5c7Ty5.js';
|
|
2
|
+
import '../cli-DLygZLi9.js';
|
|
2
3
|
import 'commander';
|
|
4
|
+
import '../netpolicy-asvCfwi8.js';
|
|
3
5
|
import 'node:stream';
|
|
4
|
-
import '../output.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @module tui/badge
|
|
8
|
-
* @package @hop-top/kit
|
|
9
|
-
*
|
|
10
|
-
* Renders a styled badge/pill string.
|
|
11
|
-
* Mirrors Go's badge concept from hop.top/kit/tui — pure string, no bubbletea dep.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
interface BadgeOpts {
|
|
15
|
-
/** Override background color (hex, e.g. "#FF0000"). Defaults to theme.accent. */
|
|
16
|
-
color?: string;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Renders a styled inline badge.
|
|
20
|
-
*
|
|
21
|
-
* Background defaults to `theme.accent`; text is rendered in white for contrast.
|
|
22
|
-
* Padding of one space is added on each side (mirrors lipgloss Padding(0, 1)).
|
|
23
|
-
*
|
|
24
|
-
* @param theme - Active CLI theme.
|
|
25
|
-
* @param text - Badge label text.
|
|
26
|
-
* @param opts - Optional overrides.
|
|
27
|
-
* @returns ANSI-styled badge string.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```ts
|
|
31
|
-
* import { buildTheme } from '@hop-top/kit/cli';
|
|
32
|
-
* import { badge } from '@hop-top/kit/tui';
|
|
33
|
-
* console.log(badge(buildTheme(), '^ UPDATE'));
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
declare function badge(theme: Theme, text: string, opts?: BadgeOpts): string;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @module tui/status
|
|
40
|
-
* @package @hop-top/kit
|
|
41
|
-
*
|
|
42
|
-
* Renders a prefixed status line with kind-derived symbol + color.
|
|
43
|
-
* Mirrors Go's InfoType/Status concept from hop.top/kit/tui.
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
/** Classification of a status message — maps to indicator symbol and color. */
|
|
47
|
-
type StatusKind = 'info' | 'success' | 'error' | 'warn';
|
|
48
|
-
/**
|
|
49
|
-
* Renders a prefixed status line.
|
|
50
|
-
*
|
|
51
|
-
* Indicator symbols and colors mirror Go's InfoType constants:
|
|
52
|
-
* - info → ℹ accent
|
|
53
|
-
* - success → ✓ success
|
|
54
|
-
* - error → ● error
|
|
55
|
-
* - warn → ▲ secondary
|
|
56
|
-
*
|
|
57
|
-
* @param theme - Active CLI theme.
|
|
58
|
-
* @param text - Status message text.
|
|
59
|
-
* @param kind - Message classification (default: `'info'`).
|
|
60
|
-
* @returns ANSI-styled status string with indicator prefix.
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```ts
|
|
64
|
-
* import { buildTheme } from '@hop-top/kit/cli';
|
|
65
|
-
* import { status } from '@hop-top/kit/tui';
|
|
66
|
-
* console.log(status(buildTheme(), 'Operation complete', 'success'));
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
declare function status(theme: Theme, text: string, kind?: StatusKind): string;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* @module tui/pills
|
|
73
|
-
* @package @hop-top/kit
|
|
74
|
-
*
|
|
75
|
-
* Renders a horizontal list of styled pills.
|
|
76
|
-
* Mirrors Go's Pill/PillBar concept from hop.top/kit/tui — pure string output.
|
|
77
|
-
*/
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Renders a space-separated row of styled pills.
|
|
81
|
-
*
|
|
82
|
-
* Each item is wrapped in `theme.secondary` foreground color with one space of
|
|
83
|
-
* padding on each side, mirroring lipgloss Padding(0, 1) on a blurred pill.
|
|
84
|
-
*
|
|
85
|
-
* @param theme - Active CLI theme.
|
|
86
|
-
* @param items - Labels to render as pills.
|
|
87
|
-
* @returns Space-joined ANSI-styled pill string. Empty string when no items.
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* ```ts
|
|
91
|
-
* import { buildTheme } from '@hop-top/kit/cli';
|
|
92
|
-
* import { pills } from '@hop-top/kit/tui';
|
|
93
|
-
* console.log(pills(buildTheme(), ['branch: main', 'env: prod']));
|
|
94
|
-
* ```
|
|
95
|
-
*/
|
|
96
|
-
declare function pills(theme: Theme, items: string[]): string;
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* @module tui/spinner
|
|
100
|
-
* @package @hop-top/kit
|
|
101
|
-
*
|
|
102
|
-
* Terminal spinner component.
|
|
103
|
-
* Mirrors Go's NewSpinner from hop.top/kit/tui — pure ANSI, no bubbletea dep.
|
|
104
|
-
*/
|
|
105
|
-
|
|
106
|
-
interface Spinner {
|
|
107
|
-
/** Start spinning with optional message. */
|
|
108
|
-
start(msg?: string): void;
|
|
109
|
-
/** Stop spinner, print optional final message. */
|
|
110
|
-
stop(msg?: string): void;
|
|
111
|
-
/** Update the spinner message while running. */
|
|
112
|
-
message(msg: string): void;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Creates a terminal spinner styled with theme.accent.
|
|
116
|
-
*
|
|
117
|
-
* Renders to stderr; uses \r to overwrite the current line each frame.
|
|
118
|
-
*
|
|
119
|
-
* @param theme - Active CLI theme.
|
|
120
|
-
* @returns Spinner control object.
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* ```ts
|
|
124
|
-
* import { buildTheme } from '@hop-top/kit/cli';
|
|
125
|
-
* import { spinner } from '@hop-top/kit/tui';
|
|
126
|
-
* const s = spinner(buildTheme());
|
|
127
|
-
* s.start('Loading…');
|
|
128
|
-
* // await work
|
|
129
|
-
* s.stop('Done');
|
|
130
|
-
* ```
|
|
131
|
-
*/
|
|
132
|
-
declare function spinner(theme: Theme): Spinner;
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* @module tui/progress
|
|
136
|
-
* @package @hop-top/kit
|
|
137
|
-
*
|
|
138
|
-
* Terminal progress bar component.
|
|
139
|
-
* Mirrors Go's Progress from hop.top/kit/tui — pure ANSI, no bubbletea dep.
|
|
140
|
-
*
|
|
141
|
-
* Renders a 30-char ASCII bar: filled chars in theme.accent, empty in theme.muted.
|
|
142
|
-
*/
|
|
143
|
-
|
|
144
|
-
interface Progress {
|
|
145
|
-
/** Start the progress bar with optional message. */
|
|
146
|
-
start(msg?: string): void;
|
|
147
|
-
/** Update progress value (0.0–1.0) with optional message. */
|
|
148
|
-
update(value: number, msg?: string): void;
|
|
149
|
-
/** Stop the progress bar with optional final message. */
|
|
150
|
-
stop(msg?: string): void;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Creates a terminal progress bar styled with theme colors.
|
|
154
|
-
*
|
|
155
|
-
* Fill chars rendered in theme.accent; empty track in theme.muted.
|
|
156
|
-
* Renders to stderr using \r to overwrite the current line.
|
|
157
|
-
*
|
|
158
|
-
* @param theme - Active CLI theme.
|
|
159
|
-
* @param total - Optional total units (unused — value is always 0.0–1.0 ratio).
|
|
160
|
-
* @returns Progress control object.
|
|
161
|
-
*
|
|
162
|
-
* @example
|
|
163
|
-
* ```ts
|
|
164
|
-
* import { buildTheme } from '@hop-top/kit/cli';
|
|
165
|
-
* import { progress } from '@hop-top/kit/tui';
|
|
166
|
-
* const p = progress(buildTheme());
|
|
167
|
-
* p.start('Downloading…');
|
|
168
|
-
* p.update(0.5, 'Half done');
|
|
169
|
-
* p.stop('Complete');
|
|
170
|
-
* ```
|
|
171
|
-
*/
|
|
172
|
-
declare function progress(theme: Theme, _total?: number): Progress;
|
|
173
|
-
declare function clamp01(v: number): number;
|
|
174
|
-
/** Render a plain bar string (no ANSI) for testing. */
|
|
175
|
-
declare function renderBarPlain(value: number): string;
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* @module tui/anim
|
|
179
|
-
* @package @hop-top/kit
|
|
180
|
-
*
|
|
181
|
-
* Gradient animation component — cycling character scramble.
|
|
182
|
-
* Mirrors Go's Anim from hop.top/kit/tui — pure ANSI, no bubbletea dep.
|
|
183
|
-
*
|
|
184
|
-
* Cycles random chars through a gradient from theme.accent → theme.secondary
|
|
185
|
-
* at ~100ms per frame. Uses \r to overwrite the current line.
|
|
186
|
-
*/
|
|
187
|
-
|
|
188
|
-
interface AnimOpts {
|
|
189
|
-
/** Number of animated characters (default: 10). */
|
|
190
|
-
width?: number;
|
|
191
|
-
/** Optional label rendered after the animation. */
|
|
192
|
-
label?: string;
|
|
193
|
-
}
|
|
194
|
-
interface Anim {
|
|
195
|
-
/** Start the animation loop. */
|
|
196
|
-
start(): void;
|
|
197
|
-
/** Stop the animation loop and clear the line. */
|
|
198
|
-
stop(): void;
|
|
199
|
-
/** Update the label shown after the animated chars. */
|
|
200
|
-
setLabel(label: string): void;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Creates a gradient-cycling character scramble animation.
|
|
204
|
-
*
|
|
205
|
-
* Colors cycle from theme.accent to theme.secondary across the width.
|
|
206
|
-
* Renders to stderr; uses \r to overwrite the current line each tick.
|
|
207
|
-
*
|
|
208
|
-
* @param theme - Active CLI theme.
|
|
209
|
-
* @param opts - Optional width and initial label.
|
|
210
|
-
* @returns Anim control object.
|
|
211
|
-
*
|
|
212
|
-
* @example
|
|
213
|
-
* ```ts
|
|
214
|
-
* import { buildTheme } from '@hop-top/kit/cli';
|
|
215
|
-
* import { anim } from '@hop-top/kit/tui';
|
|
216
|
-
* const a = anim(buildTheme(), { label: 'processing' });
|
|
217
|
-
* a.start();
|
|
218
|
-
* // await work
|
|
219
|
-
* a.stop();
|
|
220
|
-
* ```
|
|
221
|
-
*/
|
|
222
|
-
declare function anim(theme: Theme, opts?: AnimOpts): Anim;
|
|
223
|
-
/** Linear RGB blend from hexA → hexB across `steps` positions. */
|
|
224
|
-
declare function makeGradient(hexA: string, hexB: string, steps: number): Array<[number, number, number]>;
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* @module tui/confirm
|
|
228
|
-
* @package @hop-top/kit
|
|
229
|
-
*
|
|
230
|
-
* Interactive yes/no confirmation prompt.
|
|
231
|
-
* Wraps @clack/prompts confirm(); throws on cancel (Ctrl-C).
|
|
232
|
-
* Mirrors Go's NewConfirm from hop.top/kit/tui.
|
|
233
|
-
*/
|
|
234
|
-
|
|
235
|
-
interface ConfirmOpts {
|
|
236
|
-
/** Default selection when user presses Enter without input. */
|
|
237
|
-
initial?: boolean;
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Prompt the user with a yes/no question.
|
|
241
|
-
*
|
|
242
|
-
* @param _theme - Active CLI theme (reserved for future accent styling).
|
|
243
|
-
* @param message - Question to display.
|
|
244
|
-
* @param opts - Optional config; `initial` sets the default selection.
|
|
245
|
-
* @returns `true` if accepted, `false` if denied.
|
|
246
|
-
* @throws Error('cancelled') if user presses Ctrl-C.
|
|
247
|
-
*
|
|
248
|
-
* @example
|
|
249
|
-
* ```ts
|
|
250
|
-
* import { buildTheme } from '@hop-top/kit/cli';
|
|
251
|
-
* import { confirm } from '@hop-top/kit/tui';
|
|
252
|
-
* const ok = await confirm(buildTheme(), 'Deploy now?');
|
|
253
|
-
* ```
|
|
254
|
-
*/
|
|
255
|
-
declare function confirm(_theme: Theme, message: string, opts?: ConfirmOpts): Promise<boolean>;
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* @module tui/list
|
|
259
|
-
* @package @hop-top/kit
|
|
260
|
-
*
|
|
261
|
-
* Interactive selection list prompt.
|
|
262
|
-
* Wraps @clack/prompts select(); throws on cancel (Ctrl-C).
|
|
263
|
-
* Mirrors Go's NewList from hop.top/kit/tui (selection variant).
|
|
264
|
-
*/
|
|
265
|
-
|
|
266
|
-
interface ListItem {
|
|
267
|
-
/** Display label shown in the prompt. */
|
|
268
|
-
label: string;
|
|
269
|
-
/** Value returned when this item is selected. */
|
|
270
|
-
value: string;
|
|
271
|
-
/** Optional hint shown alongside the label. */
|
|
272
|
-
hint?: string;
|
|
273
|
-
}
|
|
274
|
-
interface ListOpts {
|
|
275
|
-
/** Value of the initially highlighted item. */
|
|
276
|
-
initial?: string;
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Prompt the user to pick one item from a list.
|
|
280
|
-
*
|
|
281
|
-
* @param _theme - Active CLI theme (reserved for future accent styling).
|
|
282
|
-
* @param message - Prompt label shown above the list.
|
|
283
|
-
* @param items - Selectable options.
|
|
284
|
-
* @param opts - Optional config; `initial` sets the pre-selected value.
|
|
285
|
-
* @returns The `value` of the selected item.
|
|
286
|
-
* @throws Error('cancelled') if user presses Ctrl-C.
|
|
287
|
-
*
|
|
288
|
-
* @example
|
|
289
|
-
* ```ts
|
|
290
|
-
* import { buildTheme } from '@hop-top/kit/cli';
|
|
291
|
-
* import { list } from '@hop-top/kit/tui';
|
|
292
|
-
* const env = await list(buildTheme(), 'Pick environment', [
|
|
293
|
-
* { label: 'Production', value: 'prod' },
|
|
294
|
-
* { label: 'Staging', value: 'staging', hint: 'default' },
|
|
295
|
-
* ]);
|
|
296
|
-
* ```
|
|
297
|
-
*/
|
|
298
|
-
declare function list(_theme: Theme, message: string, items: ListItem[], opts?: ListOpts): Promise<string>;
|
|
299
|
-
|
|
300
|
-
export { type Anim, type AnimOpts, type BadgeOpts, type ConfirmOpts, type ListItem, type ListOpts, type Progress, type Spinner, type StatusKind, anim, badge, clamp01, confirm, list, makeGradient, pills, progress, renderBarPlain, spinner, status };
|
|
6
|
+
import '../output-4aXs91GY.js';
|
|
7
|
+
import '../error-DISJKeDu.js';
|
package/dist/tui/index.js
CHANGED
|
@@ -52,7 +52,7 @@ function hexToRgb(hex) {
|
|
|
52
52
|
];
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
//
|
|
55
|
+
// ../../contracts/parity/parity.json
|
|
56
56
|
var parity_default = {
|
|
57
57
|
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
58
58
|
$id: "https://hop.top/kit/go/console/tui/parity.json",
|
|
@@ -107,16 +107,9 @@ var parity_default = {
|
|
|
107
107
|
label_format: "[{name}]",
|
|
108
108
|
output: "stderr"
|
|
109
109
|
},
|
|
110
|
-
table: {
|
|
111
|
-
description: "Styled-table contract for the output package. Plain tabwriter is the default; callers opt in to the lipgloss-backed renderer via WithTableStyle. The styled path is gated on writer-is-TTY so non-TTY writers (pipes, files, tests) always emit ANSI-free, diff-friendly output.",
|
|
112
|
-
render_option: "WithTableStyle",
|
|
113
|
-
tty_only: true,
|
|
114
|
-
row_emphasis_kinds: ["none", "primary", "secondary", "muted"],
|
|
115
|
-
row_emphasis_option: "RowEmphasis",
|
|
116
|
-
border_default: "normal"
|
|
117
|
-
},
|
|
118
110
|
extends: [
|
|
119
|
-
"scope-defaults.json"
|
|
111
|
+
"scope-defaults.json",
|
|
112
|
+
"serve.json"
|
|
120
113
|
]
|
|
121
114
|
};
|
|
122
115
|
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* Version check and notify — compares the running tool version against the
|
|
5
|
+
* latest GitHub release and writes a human-readable upgrade notice to any
|
|
6
|
+
* {@link https://nodejs.org/api/stream.html#class-streamwritable | Writable}
|
|
7
|
+
* stream when a newer release is available.
|
|
8
|
+
*
|
|
9
|
+
* ### Cache behaviour
|
|
10
|
+
* Results are persisted to `{stateDir}/.upgrade-{name}-cache.json`.
|
|
11
|
+
* The cache stores `{ version, checkedAt }`. On the next call within `cacheTTL`
|
|
12
|
+
* milliseconds the remote API is not contacted; the cached version is used
|
|
13
|
+
* directly. After the TTL expires the cache is refreshed on the next call.
|
|
14
|
+
* Cache I/O errors are swallowed — a stale or missing cache simply causes a
|
|
15
|
+
* fresh fetch.
|
|
16
|
+
*
|
|
17
|
+
* ### Error handling philosophy
|
|
18
|
+
* Version checking is a best-effort, non-critical operation. Any failure —
|
|
19
|
+
* network error, bad JSON, HTTP error, filesystem error, invalid semver — is
|
|
20
|
+
* silently discarded. The function always resolves without throwing. If
|
|
21
|
+
* something goes wrong the user sees neither a notice nor an error.
|
|
22
|
+
*
|
|
23
|
+
* ### Notice format
|
|
24
|
+
* ```
|
|
25
|
+
* \nA new release of {name} is available: v{current} → v{latest}\nhttps://github.com/{owner}/{repo}/releases/latest\n
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* ### Usage example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { createChecker } from '@hop-top/kit/upgrade';
|
|
31
|
+
*
|
|
32
|
+
* const checker = createChecker({
|
|
33
|
+
* name: 'my-cli',
|
|
34
|
+
* currentVersion: '1.2.3',
|
|
35
|
+
* owner: 'myorg',
|
|
36
|
+
* repo: 'my-cli',
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* // At the end of your CLI command:
|
|
40
|
+
* await checker.notifyIfAvailable(process.stderr);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
/**
|
|
44
|
+
* Static configuration for a version {@link Checker}.
|
|
45
|
+
*/
|
|
46
|
+
interface CheckerOptions {
|
|
47
|
+
/** Human-readable tool name shown in the upgrade notice. */
|
|
48
|
+
name: string;
|
|
49
|
+
/** Currently running version string (semver, without leading `v`). */
|
|
50
|
+
currentVersion: string;
|
|
51
|
+
/** GitHub organisation or username that owns the repository. */
|
|
52
|
+
owner: string;
|
|
53
|
+
/** GitHub repository name. */
|
|
54
|
+
repo: string;
|
|
55
|
+
/**
|
|
56
|
+
* How long (ms) a cached result stays valid before a fresh fetch is made.
|
|
57
|
+
* @defaultValue 86_400_000 (24 hours)
|
|
58
|
+
*/
|
|
59
|
+
cacheTTL?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Directory used to store the cache file.
|
|
62
|
+
* @defaultValue `os.tmpdir()`
|
|
63
|
+
*/
|
|
64
|
+
stateDir?: string;
|
|
65
|
+
/**
|
|
66
|
+
* HTTP request timeout in milliseconds.
|
|
67
|
+
* @defaultValue 10_000
|
|
68
|
+
*/
|
|
69
|
+
timeout?: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Returned by {@link createChecker}. Call {@link Checker.notifyIfAvailable}
|
|
73
|
+
* at the end of a CLI command to surface upgrade notices non-intrusively.
|
|
74
|
+
*/
|
|
75
|
+
interface Checker {
|
|
76
|
+
/**
|
|
77
|
+
* Checks for a newer GitHub release and writes a one-line notice to `out`
|
|
78
|
+
* if one is available. Silently swallows all errors.
|
|
79
|
+
*
|
|
80
|
+
* @param out - Any Node.js writable stream (e.g. `process.stderr`).
|
|
81
|
+
*/
|
|
82
|
+
notifyIfAvailable(out: NodeJS.WritableStream): Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Creates a {@link Checker} configured with the provided options.
|
|
86
|
+
*
|
|
87
|
+
* The checker is stateless beyond what is persisted in the cache file; it is
|
|
88
|
+
* safe to create multiple instances with the same options.
|
|
89
|
+
*
|
|
90
|
+
* @param opts - Configuration options; see {@link CheckerOptions}.
|
|
91
|
+
* @returns A {@link Checker} ready to call.
|
|
92
|
+
*/
|
|
93
|
+
declare function createChecker(opts: CheckerOptions): Checker;
|
|
94
|
+
|
|
95
|
+
type upgrade_Checker = Checker;
|
|
96
|
+
type upgrade_CheckerOptions = CheckerOptions;
|
|
97
|
+
declare const upgrade_createChecker: typeof createChecker;
|
|
98
|
+
declare namespace upgrade {
|
|
99
|
+
export { type upgrade_Checker as Checker, type upgrade_CheckerOptions as CheckerOptions, upgrade_createChecker as createChecker };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export { type Checker as C, type CheckerOptions as a, createChecker as c, upgrade as u };
|
package/dist/upgrade.d.ts
CHANGED
|
@@ -1,95 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
*
|
|
4
|
-
* Version check and notify — compares the running tool version against the
|
|
5
|
-
* latest GitHub release and writes a human-readable upgrade notice to any
|
|
6
|
-
* {@link https://nodejs.org/api/stream.html#class-streamwritable | Writable}
|
|
7
|
-
* stream when a newer release is available.
|
|
8
|
-
*
|
|
9
|
-
* ### Cache behaviour
|
|
10
|
-
* Results are persisted to `{stateDir}/.upgrade-{name}-cache.json`.
|
|
11
|
-
* The cache stores `{ version, checkedAt }`. On the next call within `cacheTTL`
|
|
12
|
-
* milliseconds the remote API is not contacted; the cached version is used
|
|
13
|
-
* directly. After the TTL expires the cache is refreshed on the next call.
|
|
14
|
-
* Cache I/O errors are swallowed — a stale or missing cache simply causes a
|
|
15
|
-
* fresh fetch.
|
|
16
|
-
*
|
|
17
|
-
* ### Error handling philosophy
|
|
18
|
-
* Version checking is a best-effort, non-critical operation. Any failure —
|
|
19
|
-
* network error, bad JSON, HTTP error, filesystem error, invalid semver — is
|
|
20
|
-
* silently discarded. The function always resolves without throwing. If
|
|
21
|
-
* something goes wrong the user sees neither a notice nor an error.
|
|
22
|
-
*
|
|
23
|
-
* ### Notice format
|
|
24
|
-
* ```
|
|
25
|
-
* \nA new release of {name} is available: v{current} → v{latest}\nhttps://github.com/{owner}/{repo}/releases/latest\n
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* ### Usage example
|
|
29
|
-
* ```ts
|
|
30
|
-
* import { createChecker } from '@hop-top/kit/upgrade';
|
|
31
|
-
*
|
|
32
|
-
* const checker = createChecker({
|
|
33
|
-
* name: 'my-cli',
|
|
34
|
-
* currentVersion: '1.2.3',
|
|
35
|
-
* owner: 'myorg',
|
|
36
|
-
* repo: 'my-cli',
|
|
37
|
-
* });
|
|
38
|
-
*
|
|
39
|
-
* // At the end of your CLI command:
|
|
40
|
-
* await checker.notifyIfAvailable(process.stderr);
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
/**
|
|
44
|
-
* Static configuration for a version {@link Checker}.
|
|
45
|
-
*/
|
|
46
|
-
interface CheckerOptions {
|
|
47
|
-
/** Human-readable tool name shown in the upgrade notice. */
|
|
48
|
-
name: string;
|
|
49
|
-
/** Currently running version string (semver, without leading `v`). */
|
|
50
|
-
currentVersion: string;
|
|
51
|
-
/** GitHub organisation or username that owns the repository. */
|
|
52
|
-
owner: string;
|
|
53
|
-
/** GitHub repository name. */
|
|
54
|
-
repo: string;
|
|
55
|
-
/**
|
|
56
|
-
* How long (ms) a cached result stays valid before a fresh fetch is made.
|
|
57
|
-
* @defaultValue 86_400_000 (24 hours)
|
|
58
|
-
*/
|
|
59
|
-
cacheTTL?: number;
|
|
60
|
-
/**
|
|
61
|
-
* Directory used to store the cache file.
|
|
62
|
-
* @defaultValue `os.tmpdir()`
|
|
63
|
-
*/
|
|
64
|
-
stateDir?: string;
|
|
65
|
-
/**
|
|
66
|
-
* HTTP request timeout in milliseconds.
|
|
67
|
-
* @defaultValue 10_000
|
|
68
|
-
*/
|
|
69
|
-
timeout?: number;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Returned by {@link createChecker}. Call {@link Checker.notifyIfAvailable}
|
|
73
|
-
* at the end of a CLI command to surface upgrade notices non-intrusively.
|
|
74
|
-
*/
|
|
75
|
-
interface Checker {
|
|
76
|
-
/**
|
|
77
|
-
* Checks for a newer GitHub release and writes a one-line notice to `out`
|
|
78
|
-
* if one is available. Silently swallows all errors.
|
|
79
|
-
*
|
|
80
|
-
* @param out - Any Node.js writable stream (e.g. `process.stderr`).
|
|
81
|
-
*/
|
|
82
|
-
notifyIfAvailable(out: NodeJS.WritableStream): Promise<void>;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Creates a {@link Checker} configured with the provided options.
|
|
86
|
-
*
|
|
87
|
-
* The checker is stateless beyond what is persisted in the cache file; it is
|
|
88
|
-
* safe to create multiple instances with the same options.
|
|
89
|
-
*
|
|
90
|
-
* @param opts - Configuration options; see {@link CheckerOptions}.
|
|
91
|
-
* @returns A {@link Checker} ready to call.
|
|
92
|
-
*/
|
|
93
|
-
declare function createChecker(opts: CheckerOptions): Checker;
|
|
94
|
-
|
|
95
|
-
export { type Checker, type CheckerOptions, createChecker };
|
|
1
|
+
export { C as Checker, a as CheckerOptions, c as createChecker } from './upgrade-p_zh3pvV.js';
|