@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.
Files changed (107) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/README.md +333 -9
  3. package/dist/aim-CTp-kJW2.d.ts +139 -0
  4. package/dist/aim.d.ts +1 -116
  5. package/dist/alias-dhhr08Ei.d.ts +88 -0
  6. package/dist/alias.d.ts +2 -73
  7. package/dist/api-miiso81x.d.ts +77 -0
  8. package/dist/api.d.ts +1 -62
  9. package/dist/auth-2-jfgiHn.d.ts +34 -0
  10. package/dist/auth.d.ts +1 -26
  11. package/dist/cli-DLygZLi9.d.ts +450 -0
  12. package/dist/cli.d.ts +6 -309
  13. package/dist/cli.js +192 -63
  14. package/dist/config-BUY7_W2n.d.ts +103 -0
  15. package/dist/config.d.ts +1 -97
  16. package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
  17. package/dist/errcorrect.d.ts +1 -37
  18. package/dist/error-DISJKeDu.d.ts +144 -0
  19. package/dist/id/index.d.ts +2 -83
  20. package/dist/index-Bc5c7Ty5.d.ts +328 -0
  21. package/dist/index-C3Zw4wDJ.d.ts +359 -0
  22. package/dist/index-MLrRDvEG.d.ts +1073 -0
  23. package/dist/index-QSffbLnj.d.ts +94 -0
  24. package/dist/index.d.ts +28 -0
  25. package/dist/index.js +6794 -0
  26. package/dist/llm-B5XUWH8T.d.ts +231 -0
  27. package/dist/llm.d.ts +1 -188
  28. package/dist/mcp/index.d.ts +2 -0
  29. package/dist/mcp/index.js +1453 -0
  30. package/dist/netpolicy-asvCfwi8.d.ts +138 -0
  31. package/dist/netpolicy.d.ts +1 -0
  32. package/dist/netpolicy.js +118 -0
  33. package/dist/output-4aXs91GY.d.ts +396 -0
  34. package/dist/output.d.ts +3 -213
  35. package/dist/output.js +567 -43
  36. package/dist/progress-CAzyxeWl.d.ts +38 -0
  37. package/dist/progress.d.ts +1 -30
  38. package/dist/provenance-SMFHm5gx.d.ts +30 -0
  39. package/dist/provenance.d.ts +1 -24
  40. package/dist/routellm-PGSt2D1y.d.ts +75 -0
  41. package/dist/routellm.d.ts +2 -64
  42. package/dist/rpc-D5xLEf8V.d.ts +32 -0
  43. package/dist/rpc.d.ts +2 -25
  44. package/dist/safety-CUaYEjZc.d.ts +30 -0
  45. package/dist/safety.d.ts +1 -24
  46. package/dist/scope-BrhYB4ij.d.ts +141 -0
  47. package/dist/scope.d.ts +1 -121
  48. package/dist/serve-DE-jscpb.d.ts +646 -0
  49. package/dist/serve.d.ts +3 -0
  50. package/dist/serve.js +1019 -0
  51. package/dist/stream-CrjeCp0M.d.ts +44 -0
  52. package/dist/stream.d.ts +1 -35
  53. package/dist/telemetry/index.d.ts +1 -315
  54. package/dist/telemetry/index.js +12 -1
  55. package/dist/tui/index.d.ts +5 -298
  56. package/dist/tui/index.js +3 -10
  57. package/dist/upgrade-p_zh3pvV.d.ts +102 -0
  58. package/dist/upgrade.d.ts +1 -95
  59. package/dist/xdg-DB7Shoib.d.ts +179 -0
  60. package/dist/xdg.d.ts +1 -169
  61. package/package.json +26 -3
  62. package/src/cli.offline.test.ts +93 -0
  63. package/src/cli.parity.test.ts +192 -0
  64. package/src/cli.ts +112 -12
  65. package/src/index.test.ts +58 -0
  66. package/src/index.ts +37 -0
  67. package/src/log.parity.test.ts +105 -0
  68. package/src/log.ts +64 -13
  69. package/src/mcp/bridge.test.ts +150 -0
  70. package/src/mcp/bridge.ts +246 -0
  71. package/src/mcp/conformance.test.ts +336 -0
  72. package/src/mcp/dispatch.ts +313 -0
  73. package/src/mcp/index.ts +138 -0
  74. package/src/mcp/legacy.ts +314 -0
  75. package/src/mcp/mcp.test.ts +697 -0
  76. package/src/mcp/modern-confirm.test.ts +520 -0
  77. package/src/mcp/modern-confirm.ts +452 -0
  78. package/src/mcp/modern.ts +723 -0
  79. package/src/mcp/tasks.ts +82 -0
  80. package/src/mcp/testtree.ts +250 -0
  81. package/src/mcp/types.ts +504 -0
  82. package/src/netpolicy.test.ts +202 -0
  83. package/src/netpolicy.ts +231 -0
  84. package/src/output/dispatch.ts +10 -2
  85. package/src/output/error.ts +316 -0
  86. package/src/output/formatter.ts +29 -5
  87. package/src/output/formatters/csv.ts +48 -12
  88. package/src/output/formatters/json.ts +4 -25
  89. package/src/output/formatters/project.ts +34 -0
  90. package/src/output/formatters/table.ts +8 -6
  91. package/src/output/formatters/text.ts +7 -3
  92. package/src/output/formatters/yaml.ts +5 -22
  93. package/src/output/projection.test.ts +298 -0
  94. package/src/output/projection.ts +33 -59
  95. package/src/output/template.ts +11 -21
  96. package/src/output.surface.test.ts +41 -0
  97. package/src/output.ts +41 -3
  98. package/src/serve.test.ts +1257 -0
  99. package/src/serve.ts +1665 -0
  100. package/src/telemetry/client.test.ts +31 -0
  101. package/src/telemetry/client.ts +7 -1
  102. package/src/telemetry/offline.test.ts +64 -0
  103. package/src/tui/parity.test.ts +120 -31
  104. package/src/tui/parity.ts +58 -7
  105. package/test/output/csv.test.ts +164 -0
  106. package/test/output/error.test.ts +246 -0
  107. package/src/tui/parity.json +0 -74
@@ -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,6 +1,11 @@
1
1
  {
2
2
  "name": "@hop-top/kit",
3
- "version": "0.5.0-alpha.1",
3
+ "version": "0.5.0-alpha.3",
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",
@@ -8,7 +13,8 @@
8
13
  "exports": {
9
14
  ".": {
10
15
  "types": "./dist/index.d.ts",
11
- "require": "./dist/index.js"
16
+ "require": "./dist/index.js",
17
+ "default": "./dist/index.js"
12
18
  },
13
19
  "./cli": {
14
20
  "types": "./dist/cli.d.ts",
@@ -105,11 +111,21 @@
105
111
  "require": "./dist/aim.js",
106
112
  "default": "./dist/aim.js"
107
113
  },
114
+ "./netpolicy": {
115
+ "types": "./dist/netpolicy.d.ts",
116
+ "require": "./dist/netpolicy.js",
117
+ "default": "./dist/netpolicy.js"
118
+ },
108
119
  "./scope": {
109
120
  "types": "./dist/scope.d.ts",
110
121
  "require": "./dist/scope.js",
111
122
  "default": "./dist/scope.js"
112
123
  },
124
+ "./serve": {
125
+ "types": "./dist/serve.d.ts",
126
+ "require": "./dist/serve.js",
127
+ "default": "./dist/serve.js"
128
+ },
113
129
  "./telemetry": {
114
130
  "types": "./dist/telemetry/index.d.ts",
115
131
  "require": "./dist/telemetry/index.js",
@@ -119,6 +135,11 @@
119
135
  "types": "./dist/id/index.d.ts",
120
136
  "require": "./dist/id/index.js",
121
137
  "default": "./dist/id/index.js"
138
+ },
139
+ "./mcp": {
140
+ "types": "./dist/mcp/index.d.ts",
141
+ "require": "./dist/mcp/index.js",
142
+ "default": "./dist/mcp/index.js"
122
143
  }
123
144
  },
124
145
  "dependencies": {
@@ -127,6 +148,8 @@
127
148
  "@connectrpc/connect": "^2.1.1",
128
149
  "@connectrpc/connect-web": "^2.1.1",
129
150
  "@hop-top/cite": "^0.1.0",
151
+ "@modelcontextprotocol/core": "2.0.0",
152
+ "@modelcontextprotocol/server": "2.0.0",
130
153
  "better-sqlite3": "^12.8.0",
131
154
  "commander": "^14.0.3",
132
155
  "csv-stringify": "^6.7.0",
@@ -157,7 +180,7 @@
157
180
  },
158
181
  "license": "MIT",
159
182
  "scripts": {
160
- "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",
183
+ "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/serve.ts src/telemetry/index.ts src/id/index.ts src/mcp/index.ts --format cjs --dts",
161
184
  "lint": "eslint src/",
162
185
  "lint:fix": "eslint src/ --fix",
163
186
  "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
+ });