@hop-top/kit 0.5.0-alpha.0 → 0.5.0-alpha.2
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 +98 -0
- package/README.md +237 -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-DgOEOsPB.d.ts +450 -0
- package/dist/cli.d.ts +5 -309
- package/dist/cli.js +250 -62
- 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/id/index.d.ts +2 -83
- package/dist/index--C7Mtsmm.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 +26 -0
- package/dist/index.js +5863 -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-VFFLqor9.d.ts +521 -0
- package/dist/output.d.ts +2 -213
- package/dist/output.js +554 -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/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 +4 -298
- package/dist/tui/index.js +61 -9
- 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 +65 -25
- 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 +36 -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 +293 -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 +39 -3
- 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 +142 -0
- package/src/tui/parity.ts +59 -13
- package/test/output/csv.test.ts +164 -0
- package/test/output/error.test.ts +241 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* XDG Base Directory path resolution with OS-native fallbacks.
|
|
5
|
+
*
|
|
6
|
+
* Each function checks the corresponding XDG environment variable first
|
|
7
|
+
* (`XDG_CONFIG_HOME`, `XDG_DATA_HOME`, `XDG_CACHE_HOME`, `XDG_STATE_HOME`).
|
|
8
|
+
* When the variable is unset or empty it falls back to the platform-native
|
|
9
|
+
* directory:
|
|
10
|
+
*
|
|
11
|
+
* - macOS (`darwin`): `~/Library/Application Support/<tool>` for data/state;
|
|
12
|
+
* `~/Library/Preferences` for config;
|
|
13
|
+
* `~/Library/Caches` for cache.
|
|
14
|
+
* - Windows (`win32`): `%LocalAppData%\<tool>` for data/state;
|
|
15
|
+
* `%APPDATA%\<tool>` for config/cache.
|
|
16
|
+
* - Linux / other: `~/.config`, `~/.local/share`,
|
|
17
|
+
* `~/.cache`, `~/.local/state`.
|
|
18
|
+
*
|
|
19
|
+
* All functions are pure (no side effects). Use {@link mustEnsure} to create
|
|
20
|
+
* the directory on disk.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { configDir, mustEnsure } from '@hop-top/kit/xdg';
|
|
25
|
+
*
|
|
26
|
+
* const cfg = mustEnsure(configDir('mytool'));
|
|
27
|
+
* // cfg is guaranteed to exist on disk
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* All four canonical XDG-style directories for a single tool, resolved in one
|
|
32
|
+
* shot.
|
|
33
|
+
*/
|
|
34
|
+
interface Dirs {
|
|
35
|
+
/** Resolved configuration directory. */
|
|
36
|
+
config: string;
|
|
37
|
+
/** Resolved data directory. */
|
|
38
|
+
data: string;
|
|
39
|
+
/** Resolved cache directory. */
|
|
40
|
+
cache: string;
|
|
41
|
+
/** Resolved state directory. */
|
|
42
|
+
state: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Returns the configuration directory for the named tool.
|
|
46
|
+
*
|
|
47
|
+
* Resolution order:
|
|
48
|
+
* 1. `$XDG_CONFIG_HOME/<tool>` — when the variable is set and non-empty.
|
|
49
|
+
* 2. OS-native fallback:
|
|
50
|
+
* - macOS: `~/Library/Preferences/<tool>`
|
|
51
|
+
* - Windows: `%APPDATA%\<tool>` (throws if `APPDATA` is unset)
|
|
52
|
+
* - Linux/other: `~/.config/<tool>`
|
|
53
|
+
*
|
|
54
|
+
* The returned path is **not** guaranteed to exist; call {@link mustEnsure} to
|
|
55
|
+
* create it.
|
|
56
|
+
*
|
|
57
|
+
* @param tool - Tool name appended as the final path segment.
|
|
58
|
+
* @returns Absolute path to the configuration directory.
|
|
59
|
+
* @throws {Error} When the OS-native root cannot be determined
|
|
60
|
+
* (e.g. `%APPDATA%` is unset on Windows).
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const dir = configDir('myapp');
|
|
65
|
+
* // macOS → /Users/alice/Library/Preferences/myapp
|
|
66
|
+
* // Linux → /home/alice/.config/myapp
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare function configDir(tool: string, plt?: NodeJS.Platform): string;
|
|
70
|
+
/**
|
|
71
|
+
* Returns the data directory for the named tool.
|
|
72
|
+
*
|
|
73
|
+
* Resolution order:
|
|
74
|
+
* 1. `$XDG_DATA_HOME/<tool>` — when the variable is set and non-empty.
|
|
75
|
+
* 2. OS-native fallback:
|
|
76
|
+
* - macOS: `~/Library/Application Support/<tool>`
|
|
77
|
+
* - Windows: `%LocalAppData%\<tool>` (throws if `LocalAppData` is unset)
|
|
78
|
+
* - Linux/other: `~/.local/share/<tool>`
|
|
79
|
+
*
|
|
80
|
+
* @param tool - Tool name appended as the final path segment.
|
|
81
|
+
* @param plt - Optional platform override (defaults to `process.platform`).
|
|
82
|
+
* @returns Absolute path to the data directory.
|
|
83
|
+
* @throws {Error} When the OS-native root cannot be determined.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* const dir = dataDir('myapp');
|
|
88
|
+
* // macOS → /Users/alice/Library/Application Support/myapp
|
|
89
|
+
* // Linux → /home/alice/.local/share/myapp
|
|
90
|
+
* // Windows → C:\Users\alice\AppData\Local\myapp
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
declare function dataDir(tool: string, plt?: NodeJS.Platform): string;
|
|
94
|
+
/**
|
|
95
|
+
* Returns the cache directory for the named tool.
|
|
96
|
+
*
|
|
97
|
+
* Resolution order:
|
|
98
|
+
* 1. `$XDG_CACHE_HOME/<tool>` — when the variable is set and non-empty.
|
|
99
|
+
* 2. OS-native fallback:
|
|
100
|
+
* - macOS: `~/Library/Caches/<tool>`
|
|
101
|
+
* - Windows: `%LocalAppData%\<tool>\cache` (throws if `LocalAppData` unset)
|
|
102
|
+
* - Linux/other: `~/.cache/<tool>`
|
|
103
|
+
*
|
|
104
|
+
* @param tool - Tool name appended as the final path segment.
|
|
105
|
+
* @param plt - Optional platform override (defaults to `process.platform`).
|
|
106
|
+
* @returns Absolute path to the cache directory.
|
|
107
|
+
* @throws {Error} When the OS-native root cannot be determined.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* const dir = cacheDir('myapp');
|
|
112
|
+
* // macOS → /Users/alice/Library/Caches/myapp
|
|
113
|
+
* // Linux → /home/alice/.cache/myapp
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
declare function cacheDir(tool: string, plt?: NodeJS.Platform): string;
|
|
117
|
+
/**
|
|
118
|
+
* Returns the state directory for the named tool.
|
|
119
|
+
*
|
|
120
|
+
* State stores runtime artefacts that should persist across restarts but are
|
|
121
|
+
* not user-facing configuration (e.g. lock files, history, socket paths).
|
|
122
|
+
*
|
|
123
|
+
* Resolution order:
|
|
124
|
+
* 1. `$XDG_STATE_HOME/<tool>` — when the variable is set and non-empty.
|
|
125
|
+
* 2. OS-native fallback:
|
|
126
|
+
* - macOS: `~/Library/Application Support/<tool>/state`
|
|
127
|
+
* (the `/state` suffix avoids collision with {@link dataDir})
|
|
128
|
+
* - Windows: `%LocalAppData%\<tool>\state`
|
|
129
|
+
* (throws if `LocalAppData` is unset)
|
|
130
|
+
* - Linux/other: `~/.local/state/<tool>`
|
|
131
|
+
*
|
|
132
|
+
* @param tool - Tool name appended as the final path segment.
|
|
133
|
+
* @param plt - Optional platform override (defaults to `process.platform`).
|
|
134
|
+
* @returns Absolute path to the state directory.
|
|
135
|
+
* @throws {Error} When the OS-native root cannot be determined.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* const dir = stateDir('myapp');
|
|
140
|
+
* // macOS → /Users/alice/Library/Application Support/myapp/state
|
|
141
|
+
* // Linux → /home/alice/.local/state/myapp
|
|
142
|
+
* // Windows → C:\Users\alice\AppData\Local\myapp\state
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
declare function stateDir(tool: string, plt?: NodeJS.Platform): string;
|
|
146
|
+
/**
|
|
147
|
+
* Creates `dir` (and any parents) with mode `0o750`, then returns `dir`.
|
|
148
|
+
*
|
|
149
|
+
* Throws an `Error` if `fs.mkdirSync` fails — for example when `dir` is an
|
|
150
|
+
* existing regular file or a permission error prevents directory creation.
|
|
151
|
+
*
|
|
152
|
+
* Intended for startup-time path resolution where a missing directory is
|
|
153
|
+
* unrecoverable:
|
|
154
|
+
*
|
|
155
|
+
* @param dir - Absolute path to the directory to create.
|
|
156
|
+
* @returns The same `dir` value, now guaranteed to exist on disk.
|
|
157
|
+
* @throws {Error} On any filesystem error (file-exists-as-non-dir, EPERM, …).
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* import { dataDir, mustEnsure } from '@hop-top/kit/xdg';
|
|
162
|
+
*
|
|
163
|
+
* const data = mustEnsure(dataDir('mytool'));
|
|
164
|
+
* // data directory now exists on disk
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
declare function mustEnsure(dir: string): string;
|
|
168
|
+
|
|
169
|
+
type xdg_Dirs = Dirs;
|
|
170
|
+
declare const xdg_cacheDir: typeof cacheDir;
|
|
171
|
+
declare const xdg_configDir: typeof configDir;
|
|
172
|
+
declare const xdg_dataDir: typeof dataDir;
|
|
173
|
+
declare const xdg_mustEnsure: typeof mustEnsure;
|
|
174
|
+
declare const xdg_stateDir: typeof stateDir;
|
|
175
|
+
declare namespace xdg {
|
|
176
|
+
export { type xdg_Dirs as Dirs, xdg_cacheDir as cacheDir, xdg_configDir as configDir, xdg_dataDir as dataDir, xdg_mustEnsure as mustEnsure, xdg_stateDir as stateDir };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export { type Dirs as D, configDir as a, cacheDir as c, dataDir as d, mustEnsure as m, stateDir as s, xdg as x };
|
package/dist/xdg.d.ts
CHANGED
|
@@ -1,169 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
*
|
|
4
|
-
* XDG Base Directory path resolution with OS-native fallbacks.
|
|
5
|
-
*
|
|
6
|
-
* Each function checks the corresponding XDG environment variable first
|
|
7
|
-
* (`XDG_CONFIG_HOME`, `XDG_DATA_HOME`, `XDG_CACHE_HOME`, `XDG_STATE_HOME`).
|
|
8
|
-
* When the variable is unset or empty it falls back to the platform-native
|
|
9
|
-
* directory:
|
|
10
|
-
*
|
|
11
|
-
* - macOS (`darwin`): `~/Library/Application Support/<tool>` for data/state;
|
|
12
|
-
* `~/Library/Preferences` for config;
|
|
13
|
-
* `~/Library/Caches` for cache.
|
|
14
|
-
* - Windows (`win32`): `%LocalAppData%\<tool>` for data/state;
|
|
15
|
-
* `%APPDATA%\<tool>` for config/cache.
|
|
16
|
-
* - Linux / other: `~/.config`, `~/.local/share`,
|
|
17
|
-
* `~/.cache`, `~/.local/state`.
|
|
18
|
-
*
|
|
19
|
-
* All functions are pure (no side effects). Use {@link mustEnsure} to create
|
|
20
|
-
* the directory on disk.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* import { configDir, mustEnsure } from '@hop-top/kit/xdg';
|
|
25
|
-
*
|
|
26
|
-
* const cfg = mustEnsure(configDir('mytool'));
|
|
27
|
-
* // cfg is guaranteed to exist on disk
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
/**
|
|
31
|
-
* All four canonical XDG-style directories for a single tool, resolved in one
|
|
32
|
-
* shot.
|
|
33
|
-
*/
|
|
34
|
-
interface Dirs {
|
|
35
|
-
/** Resolved configuration directory. */
|
|
36
|
-
config: string;
|
|
37
|
-
/** Resolved data directory. */
|
|
38
|
-
data: string;
|
|
39
|
-
/** Resolved cache directory. */
|
|
40
|
-
cache: string;
|
|
41
|
-
/** Resolved state directory. */
|
|
42
|
-
state: string;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Returns the configuration directory for the named tool.
|
|
46
|
-
*
|
|
47
|
-
* Resolution order:
|
|
48
|
-
* 1. `$XDG_CONFIG_HOME/<tool>` — when the variable is set and non-empty.
|
|
49
|
-
* 2. OS-native fallback:
|
|
50
|
-
* - macOS: `~/Library/Preferences/<tool>`
|
|
51
|
-
* - Windows: `%APPDATA%\<tool>` (throws if `APPDATA` is unset)
|
|
52
|
-
* - Linux/other: `~/.config/<tool>`
|
|
53
|
-
*
|
|
54
|
-
* The returned path is **not** guaranteed to exist; call {@link mustEnsure} to
|
|
55
|
-
* create it.
|
|
56
|
-
*
|
|
57
|
-
* @param tool - Tool name appended as the final path segment.
|
|
58
|
-
* @returns Absolute path to the configuration directory.
|
|
59
|
-
* @throws {Error} When the OS-native root cannot be determined
|
|
60
|
-
* (e.g. `%APPDATA%` is unset on Windows).
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```ts
|
|
64
|
-
* const dir = configDir('myapp');
|
|
65
|
-
* // macOS → /Users/alice/Library/Preferences/myapp
|
|
66
|
-
* // Linux → /home/alice/.config/myapp
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
declare function configDir(tool: string, plt?: NodeJS.Platform): string;
|
|
70
|
-
/**
|
|
71
|
-
* Returns the data directory for the named tool.
|
|
72
|
-
*
|
|
73
|
-
* Resolution order:
|
|
74
|
-
* 1. `$XDG_DATA_HOME/<tool>` — when the variable is set and non-empty.
|
|
75
|
-
* 2. OS-native fallback:
|
|
76
|
-
* - macOS: `~/Library/Application Support/<tool>`
|
|
77
|
-
* - Windows: `%LocalAppData%\<tool>` (throws if `LocalAppData` is unset)
|
|
78
|
-
* - Linux/other: `~/.local/share/<tool>`
|
|
79
|
-
*
|
|
80
|
-
* @param tool - Tool name appended as the final path segment.
|
|
81
|
-
* @param plt - Optional platform override (defaults to `process.platform`).
|
|
82
|
-
* @returns Absolute path to the data directory.
|
|
83
|
-
* @throws {Error} When the OS-native root cannot be determined.
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```ts
|
|
87
|
-
* const dir = dataDir('myapp');
|
|
88
|
-
* // macOS → /Users/alice/Library/Application Support/myapp
|
|
89
|
-
* // Linux → /home/alice/.local/share/myapp
|
|
90
|
-
* // Windows → C:\Users\alice\AppData\Local\myapp
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
declare function dataDir(tool: string, plt?: NodeJS.Platform): string;
|
|
94
|
-
/**
|
|
95
|
-
* Returns the cache directory for the named tool.
|
|
96
|
-
*
|
|
97
|
-
* Resolution order:
|
|
98
|
-
* 1. `$XDG_CACHE_HOME/<tool>` — when the variable is set and non-empty.
|
|
99
|
-
* 2. OS-native fallback:
|
|
100
|
-
* - macOS: `~/Library/Caches/<tool>`
|
|
101
|
-
* - Windows: `%LocalAppData%\<tool>\cache` (throws if `LocalAppData` unset)
|
|
102
|
-
* - Linux/other: `~/.cache/<tool>`
|
|
103
|
-
*
|
|
104
|
-
* @param tool - Tool name appended as the final path segment.
|
|
105
|
-
* @param plt - Optional platform override (defaults to `process.platform`).
|
|
106
|
-
* @returns Absolute path to the cache directory.
|
|
107
|
-
* @throws {Error} When the OS-native root cannot be determined.
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* ```ts
|
|
111
|
-
* const dir = cacheDir('myapp');
|
|
112
|
-
* // macOS → /Users/alice/Library/Caches/myapp
|
|
113
|
-
* // Linux → /home/alice/.cache/myapp
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
declare function cacheDir(tool: string, plt?: NodeJS.Platform): string;
|
|
117
|
-
/**
|
|
118
|
-
* Returns the state directory for the named tool.
|
|
119
|
-
*
|
|
120
|
-
* State stores runtime artefacts that should persist across restarts but are
|
|
121
|
-
* not user-facing configuration (e.g. lock files, history, socket paths).
|
|
122
|
-
*
|
|
123
|
-
* Resolution order:
|
|
124
|
-
* 1. `$XDG_STATE_HOME/<tool>` — when the variable is set and non-empty.
|
|
125
|
-
* 2. OS-native fallback:
|
|
126
|
-
* - macOS: `~/Library/Application Support/<tool>/state`
|
|
127
|
-
* (the `/state` suffix avoids collision with {@link dataDir})
|
|
128
|
-
* - Windows: `%LocalAppData%\<tool>\state`
|
|
129
|
-
* (throws if `LocalAppData` is unset)
|
|
130
|
-
* - Linux/other: `~/.local/state/<tool>`
|
|
131
|
-
*
|
|
132
|
-
* @param tool - Tool name appended as the final path segment.
|
|
133
|
-
* @param plt - Optional platform override (defaults to `process.platform`).
|
|
134
|
-
* @returns Absolute path to the state directory.
|
|
135
|
-
* @throws {Error} When the OS-native root cannot be determined.
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* ```ts
|
|
139
|
-
* const dir = stateDir('myapp');
|
|
140
|
-
* // macOS → /Users/alice/Library/Application Support/myapp/state
|
|
141
|
-
* // Linux → /home/alice/.local/state/myapp
|
|
142
|
-
* // Windows → C:\Users\alice\AppData\Local\myapp\state
|
|
143
|
-
* ```
|
|
144
|
-
*/
|
|
145
|
-
declare function stateDir(tool: string, plt?: NodeJS.Platform): string;
|
|
146
|
-
/**
|
|
147
|
-
* Creates `dir` (and any parents) with mode `0o750`, then returns `dir`.
|
|
148
|
-
*
|
|
149
|
-
* Throws an `Error` if `fs.mkdirSync` fails — for example when `dir` is an
|
|
150
|
-
* existing regular file or a permission error prevents directory creation.
|
|
151
|
-
*
|
|
152
|
-
* Intended for startup-time path resolution where a missing directory is
|
|
153
|
-
* unrecoverable:
|
|
154
|
-
*
|
|
155
|
-
* @param dir - Absolute path to the directory to create.
|
|
156
|
-
* @returns The same `dir` value, now guaranteed to exist on disk.
|
|
157
|
-
* @throws {Error} On any filesystem error (file-exists-as-non-dir, EPERM, …).
|
|
158
|
-
*
|
|
159
|
-
* @example
|
|
160
|
-
* ```ts
|
|
161
|
-
* import { dataDir, mustEnsure } from '@hop-top/kit/xdg';
|
|
162
|
-
*
|
|
163
|
-
* const data = mustEnsure(dataDir('mytool'));
|
|
164
|
-
* // data directory now exists on disk
|
|
165
|
-
* ```
|
|
166
|
-
*/
|
|
167
|
-
declare function mustEnsure(dir: string): string;
|
|
168
|
-
|
|
169
|
-
export { type Dirs, cacheDir, configDir, dataDir, mustEnsure, stateDir };
|
|
1
|
+
export { D as Dirs, c as cacheDir, a as configDir, d as dataDir, m as mustEnsure, s as stateDir } from './xdg-DB7Shoib.js';
|
package/package.json
CHANGED
|
@@ -1,102 +1,140 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hop-top/kit",
|
|
3
|
-
"version": "0.5.0-alpha.
|
|
3
|
+
"version": "0.5.0-alpha.2",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/hop-top/poly-kit.git",
|
|
7
|
+
"directory": "sdk/ts"
|
|
8
|
+
},
|
|
4
9
|
"description": "Shared CLI utilities for hop-top tools — TypeScript/CJS edition",
|
|
5
10
|
"type": "commonjs",
|
|
6
11
|
"main": "./dist/index.js",
|
|
7
12
|
"types": "./dist/index.d.ts",
|
|
8
13
|
"exports": {
|
|
9
14
|
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
10
16
|
"require": "./dist/index.js",
|
|
11
|
-
"
|
|
17
|
+
"default": "./dist/index.js"
|
|
12
18
|
},
|
|
13
19
|
"./cli": {
|
|
20
|
+
"types": "./dist/cli.d.ts",
|
|
14
21
|
"require": "./dist/cli.js",
|
|
15
|
-
"
|
|
22
|
+
"default": "./dist/cli.js"
|
|
16
23
|
},
|
|
17
24
|
"./output": {
|
|
25
|
+
"types": "./dist/output.d.ts",
|
|
18
26
|
"require": "./dist/output.js",
|
|
19
|
-
"
|
|
27
|
+
"default": "./dist/output.js"
|
|
20
28
|
},
|
|
21
29
|
"./xdg": {
|
|
30
|
+
"types": "./dist/xdg.d.ts",
|
|
22
31
|
"require": "./dist/xdg.js",
|
|
23
|
-
"
|
|
32
|
+
"default": "./dist/xdg.js"
|
|
24
33
|
},
|
|
25
34
|
"./config": {
|
|
35
|
+
"types": "./dist/config.d.ts",
|
|
26
36
|
"require": "./dist/config.js",
|
|
27
|
-
"
|
|
37
|
+
"default": "./dist/config.js"
|
|
28
38
|
},
|
|
29
39
|
"./sqlstore": {
|
|
40
|
+
"types": "./dist/sqlstore.d.ts",
|
|
30
41
|
"require": "./dist/sqlstore.js",
|
|
31
|
-
"
|
|
42
|
+
"default": "./dist/sqlstore.js"
|
|
32
43
|
},
|
|
33
44
|
"./upgrade": {
|
|
45
|
+
"types": "./dist/upgrade.d.ts",
|
|
34
46
|
"require": "./dist/upgrade.js",
|
|
35
|
-
"
|
|
47
|
+
"default": "./dist/upgrade.js"
|
|
36
48
|
},
|
|
37
49
|
"./llm": {
|
|
50
|
+
"types": "./dist/llm.d.ts",
|
|
38
51
|
"require": "./dist/llm.js",
|
|
39
|
-
"
|
|
52
|
+
"default": "./dist/llm.js"
|
|
40
53
|
},
|
|
41
54
|
"./routellm": {
|
|
55
|
+
"types": "./dist/routellm.d.ts",
|
|
42
56
|
"require": "./dist/routellm.js",
|
|
43
|
-
"
|
|
57
|
+
"default": "./dist/routellm.js"
|
|
44
58
|
},
|
|
45
59
|
"./alias": {
|
|
60
|
+
"types": "./dist/alias.d.ts",
|
|
46
61
|
"require": "./dist/alias.js",
|
|
47
|
-
"
|
|
62
|
+
"default": "./dist/alias.js"
|
|
48
63
|
},
|
|
49
64
|
"./tui": {
|
|
65
|
+
"types": "./dist/tui/index.d.ts",
|
|
50
66
|
"require": "./dist/tui/index.js",
|
|
51
|
-
"
|
|
67
|
+
"default": "./dist/tui/index.js"
|
|
52
68
|
},
|
|
53
69
|
"./errcorrect": {
|
|
70
|
+
"types": "./dist/errcorrect.d.ts",
|
|
54
71
|
"require": "./dist/errcorrect.js",
|
|
55
|
-
"
|
|
72
|
+
"default": "./dist/errcorrect.js"
|
|
56
73
|
},
|
|
57
74
|
"./safety": {
|
|
75
|
+
"types": "./dist/safety.d.ts",
|
|
58
76
|
"require": "./dist/safety.js",
|
|
59
|
-
"
|
|
77
|
+
"default": "./dist/safety.js"
|
|
60
78
|
},
|
|
61
79
|
"./provenance": {
|
|
80
|
+
"types": "./dist/provenance.d.ts",
|
|
62
81
|
"require": "./dist/provenance.js",
|
|
63
|
-
"
|
|
82
|
+
"default": "./dist/provenance.js"
|
|
64
83
|
},
|
|
65
84
|
"./stream": {
|
|
85
|
+
"types": "./dist/stream.d.ts",
|
|
66
86
|
"require": "./dist/stream.js",
|
|
67
|
-
"
|
|
87
|
+
"default": "./dist/stream.js"
|
|
68
88
|
},
|
|
69
89
|
"./progress": {
|
|
90
|
+
"types": "./dist/progress.d.ts",
|
|
70
91
|
"require": "./dist/progress.js",
|
|
71
|
-
"
|
|
92
|
+
"default": "./dist/progress.js"
|
|
72
93
|
},
|
|
73
94
|
"./auth": {
|
|
95
|
+
"types": "./dist/auth.d.ts",
|
|
74
96
|
"require": "./dist/auth.js",
|
|
75
|
-
"
|
|
97
|
+
"default": "./dist/auth.js"
|
|
76
98
|
},
|
|
77
99
|
"./api": {
|
|
100
|
+
"types": "./dist/api.d.ts",
|
|
78
101
|
"require": "./dist/api.js",
|
|
79
|
-
"
|
|
102
|
+
"default": "./dist/api.js"
|
|
80
103
|
},
|
|
81
104
|
"./rpc": {
|
|
105
|
+
"types": "./dist/rpc.d.ts",
|
|
82
106
|
"require": "./dist/rpc.js",
|
|
83
|
-
"
|
|
107
|
+
"default": "./dist/rpc.js"
|
|
84
108
|
},
|
|
85
109
|
"./aim": {
|
|
110
|
+
"types": "./dist/aim.d.ts",
|
|
86
111
|
"require": "./dist/aim.js",
|
|
87
|
-
"
|
|
112
|
+
"default": "./dist/aim.js"
|
|
113
|
+
},
|
|
114
|
+
"./netpolicy": {
|
|
115
|
+
"types": "./dist/netpolicy.d.ts",
|
|
116
|
+
"require": "./dist/netpolicy.js",
|
|
117
|
+
"default": "./dist/netpolicy.js"
|
|
88
118
|
},
|
|
89
119
|
"./scope": {
|
|
120
|
+
"types": "./dist/scope.d.ts",
|
|
90
121
|
"require": "./dist/scope.js",
|
|
91
|
-
"
|
|
122
|
+
"default": "./dist/scope.js"
|
|
92
123
|
},
|
|
93
124
|
"./telemetry": {
|
|
125
|
+
"types": "./dist/telemetry/index.d.ts",
|
|
94
126
|
"require": "./dist/telemetry/index.js",
|
|
95
|
-
"
|
|
127
|
+
"default": "./dist/telemetry/index.js"
|
|
96
128
|
},
|
|
97
129
|
"./id": {
|
|
130
|
+
"types": "./dist/id/index.d.ts",
|
|
98
131
|
"require": "./dist/id/index.js",
|
|
99
|
-
"
|
|
132
|
+
"default": "./dist/id/index.js"
|
|
133
|
+
},
|
|
134
|
+
"./mcp": {
|
|
135
|
+
"types": "./dist/mcp/index.d.ts",
|
|
136
|
+
"require": "./dist/mcp/index.js",
|
|
137
|
+
"default": "./dist/mcp/index.js"
|
|
100
138
|
}
|
|
101
139
|
},
|
|
102
140
|
"dependencies": {
|
|
@@ -105,6 +143,8 @@
|
|
|
105
143
|
"@connectrpc/connect": "^2.1.1",
|
|
106
144
|
"@connectrpc/connect-web": "^2.1.1",
|
|
107
145
|
"@hop-top/cite": "^0.1.0",
|
|
146
|
+
"@modelcontextprotocol/core": "2.0.0",
|
|
147
|
+
"@modelcontextprotocol/server": "2.0.0",
|
|
108
148
|
"better-sqlite3": "^12.8.0",
|
|
109
149
|
"commander": "^14.0.3",
|
|
110
150
|
"csv-stringify": "^6.7.0",
|
|
@@ -135,7 +175,7 @@
|
|
|
135
175
|
},
|
|
136
176
|
"license": "MIT",
|
|
137
177
|
"scripts": {
|
|
138
|
-
"build": "tsup src/alias.ts src/cli.ts src/output.ts src/xdg.ts src/config.ts src/sqlstore.ts src/upgrade.ts src/llm.ts src/routellm.ts src/tui/index.ts src/errcorrect.ts src/safety.ts src/provenance.ts src/stream.ts src/progress.ts src/auth.ts src/api.ts src/rpc.ts src/aim.ts src/scope.ts src/telemetry/index.ts src/id/index.ts --format cjs --dts",
|
|
178
|
+
"build": "tsup src/index.ts src/alias.ts src/cli.ts src/output.ts src/xdg.ts src/config.ts src/sqlstore.ts src/upgrade.ts src/llm.ts src/routellm.ts src/tui/index.ts src/errcorrect.ts src/safety.ts src/provenance.ts src/stream.ts src/progress.ts src/auth.ts src/api.ts src/rpc.ts src/aim.ts src/netpolicy.ts src/scope.ts src/telemetry/index.ts src/id/index.ts src/mcp/index.ts --format cjs --dts",
|
|
139
179
|
"lint": "eslint src/",
|
|
140
180
|
"lint:fix": "eslint src/ --fix",
|
|
141
181
|
"test": "vitest run"
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* End-to-end guarantee for the `--offline` global, mirroring
|
|
3
|
+
* `go/console/cli/offline_e2e_test.go`.
|
|
4
|
+
*
|
|
5
|
+
* A leaf that naively calls `fetch` — an adopter who never heard of the
|
|
6
|
+
* offline marker — must still be refused when the user passes `--offline`.
|
|
7
|
+
* Registering the flag alone would be advisory only; this test is what
|
|
8
|
+
* makes the enforcement load-bearing.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
12
|
+
|
|
13
|
+
import { createCLI } from './cli';
|
|
14
|
+
import { isOffline, isOfflineError } from './netpolicy';
|
|
15
|
+
|
|
16
|
+
describe('--offline is enforced end to end', () => {
|
|
17
|
+
const orig = globalThis.fetch;
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
globalThis.fetch = orig;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('refuses a naive leaf that uses globalThis.fetch', async () => {
|
|
23
|
+
const reached = vi.fn(async () => new Response(null, { status: 204 }));
|
|
24
|
+
globalThis.fetch = reached as unknown as typeof globalThis.fetch;
|
|
25
|
+
|
|
26
|
+
let gotErr: unknown = null;
|
|
27
|
+
const { program } = createCLI({ name: 'probe', version: '0.0.0', description: 'd' });
|
|
28
|
+
program.command('fetch').action(async () => {
|
|
29
|
+
try {
|
|
30
|
+
// naive: no offline check whatsoever
|
|
31
|
+
await fetch('https://example.invalid/x');
|
|
32
|
+
} catch (e) {
|
|
33
|
+
gotErr = e;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
await program.parseAsync(['node', 'probe', 'fetch', '--offline']);
|
|
38
|
+
|
|
39
|
+
expect(isOfflineError(gotErr),
|
|
40
|
+
`naive leaf reached the network under --offline: ${gotErr}`).toBe(true);
|
|
41
|
+
expect(reached, 'the underlying fetch was invoked').not.toHaveBeenCalled();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('leaves a leaf untouched without --offline', async () => {
|
|
45
|
+
const reached = vi.fn(async () => new Response(null, { status: 204 }));
|
|
46
|
+
globalThis.fetch = reached as unknown as typeof globalThis.fetch;
|
|
47
|
+
|
|
48
|
+
let status = 0;
|
|
49
|
+
const { program } = createCLI({ name: 'probe', version: '0.0.0', description: 'd' });
|
|
50
|
+
program.command('fetch').action(async () => {
|
|
51
|
+
status = (await fetch('https://example.invalid/x')).status;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
await program.parseAsync(['node', 'probe', 'fetch']);
|
|
55
|
+
|
|
56
|
+
expect(status).toBe(204);
|
|
57
|
+
expect(reached).toHaveBeenCalledOnce();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('exposes the marker to leaves that do consult it', async () => {
|
|
61
|
+
let seen: boolean | null = null;
|
|
62
|
+
const { program } = createCLI({ name: 'probe', version: '0.0.0', description: 'd' });
|
|
63
|
+
program.command('check').action(() => {
|
|
64
|
+
seen = isOffline();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
await program.parseAsync(['node', 'probe', 'check', '--offline']);
|
|
68
|
+
expect(seen).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('registers --offline on the program', () => {
|
|
72
|
+
const { program } = createCLI({ name: 'probe', version: '0.0.0', description: 'd' });
|
|
73
|
+
expect(program.options.map((o) => o.flags)).toContain('--offline');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// --offline forces per-command network opt-outs ON, but must never
|
|
77
|
+
// un-set an explicitly passed --no-* flag.
|
|
78
|
+
it('forces opt-outs on without un-setting explicit --no-* flags', async () => {
|
|
79
|
+
const { program } = createCLI({ name: 'probe', version: '0.0.0', description: 'd' });
|
|
80
|
+
const sub = program.command('deploy')
|
|
81
|
+
.option('--push', 'push after build', false)
|
|
82
|
+
.option('--no-sync', 'skip sync');
|
|
83
|
+
let opts: Record<string, unknown> = {};
|
|
84
|
+
sub.action(() => { opts = sub.opts(); });
|
|
85
|
+
|
|
86
|
+
await program.parseAsync(['node', 'probe', 'deploy', '--push', '--no-sync', '--offline']);
|
|
87
|
+
|
|
88
|
+
// The explicit --no-sync stays off; --offline does not flip it back on.
|
|
89
|
+
expect(opts['sync']).toBe(false);
|
|
90
|
+
// The marker is what leaves consult to know the opt-in must not run.
|
|
91
|
+
expect(program.opts()['offline']).toBe(true);
|
|
92
|
+
});
|
|
93
|
+
});
|