@hop-top/kit 0.5.0-alpha.1 → 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.
Files changed (101) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/README.md +237 -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-DgOEOsPB.d.ts +450 -0
  12. package/dist/cli.d.ts +5 -309
  13. package/dist/cli.js +190 -62
  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/id/index.d.ts +2 -83
  19. package/dist/index--C7Mtsmm.d.ts +328 -0
  20. package/dist/index-C3Zw4wDJ.d.ts +359 -0
  21. package/dist/index-MLrRDvEG.d.ts +1073 -0
  22. package/dist/index-QSffbLnj.d.ts +94 -0
  23. package/dist/index.d.ts +26 -0
  24. package/dist/index.js +5863 -0
  25. package/dist/llm-B5XUWH8T.d.ts +231 -0
  26. package/dist/llm.d.ts +1 -188
  27. package/dist/mcp/index.d.ts +2 -0
  28. package/dist/mcp/index.js +1453 -0
  29. package/dist/netpolicy-asvCfwi8.d.ts +138 -0
  30. package/dist/netpolicy.d.ts +1 -0
  31. package/dist/netpolicy.js +118 -0
  32. package/dist/output-VFFLqor9.d.ts +521 -0
  33. package/dist/output.d.ts +2 -213
  34. package/dist/output.js +554 -43
  35. package/dist/progress-CAzyxeWl.d.ts +38 -0
  36. package/dist/progress.d.ts +1 -30
  37. package/dist/provenance-SMFHm5gx.d.ts +30 -0
  38. package/dist/provenance.d.ts +1 -24
  39. package/dist/routellm-PGSt2D1y.d.ts +75 -0
  40. package/dist/routellm.d.ts +2 -64
  41. package/dist/rpc-D5xLEf8V.d.ts +32 -0
  42. package/dist/rpc.d.ts +2 -25
  43. package/dist/safety-CUaYEjZc.d.ts +30 -0
  44. package/dist/safety.d.ts +1 -24
  45. package/dist/scope-BrhYB4ij.d.ts +141 -0
  46. package/dist/scope.d.ts +1 -121
  47. package/dist/stream-CrjeCp0M.d.ts +44 -0
  48. package/dist/stream.d.ts +1 -35
  49. package/dist/telemetry/index.d.ts +1 -315
  50. package/dist/telemetry/index.js +12 -1
  51. package/dist/tui/index.d.ts +4 -298
  52. package/dist/tui/index.js +1 -9
  53. package/dist/upgrade-p_zh3pvV.d.ts +102 -0
  54. package/dist/upgrade.d.ts +1 -95
  55. package/dist/xdg-DB7Shoib.d.ts +179 -0
  56. package/dist/xdg.d.ts +1 -169
  57. package/package.json +21 -3
  58. package/src/cli.offline.test.ts +93 -0
  59. package/src/cli.parity.test.ts +192 -0
  60. package/src/cli.ts +112 -12
  61. package/src/index.test.ts +58 -0
  62. package/src/index.ts +36 -0
  63. package/src/log.parity.test.ts +105 -0
  64. package/src/log.ts +64 -13
  65. package/src/mcp/bridge.test.ts +150 -0
  66. package/src/mcp/bridge.ts +246 -0
  67. package/src/mcp/conformance.test.ts +336 -0
  68. package/src/mcp/dispatch.ts +313 -0
  69. package/src/mcp/index.ts +138 -0
  70. package/src/mcp/legacy.ts +314 -0
  71. package/src/mcp/mcp.test.ts +697 -0
  72. package/src/mcp/modern-confirm.test.ts +520 -0
  73. package/src/mcp/modern-confirm.ts +452 -0
  74. package/src/mcp/modern.ts +723 -0
  75. package/src/mcp/tasks.ts +82 -0
  76. package/src/mcp/testtree.ts +250 -0
  77. package/src/mcp/types.ts +504 -0
  78. package/src/netpolicy.test.ts +202 -0
  79. package/src/netpolicy.ts +231 -0
  80. package/src/output/dispatch.ts +10 -2
  81. package/src/output/error.ts +293 -0
  82. package/src/output/formatter.ts +29 -5
  83. package/src/output/formatters/csv.ts +48 -12
  84. package/src/output/formatters/json.ts +4 -25
  85. package/src/output/formatters/project.ts +34 -0
  86. package/src/output/formatters/table.ts +8 -6
  87. package/src/output/formatters/text.ts +7 -3
  88. package/src/output/formatters/yaml.ts +5 -22
  89. package/src/output/projection.test.ts +298 -0
  90. package/src/output/projection.ts +33 -59
  91. package/src/output/template.ts +11 -21
  92. package/src/output.surface.test.ts +41 -0
  93. package/src/output.ts +39 -3
  94. package/src/telemetry/client.test.ts +31 -0
  95. package/src/telemetry/client.ts +7 -1
  96. package/src/telemetry/offline.test.ts +64 -0
  97. package/src/tui/parity.test.ts +120 -31
  98. package/src/tui/parity.ts +58 -7
  99. package/test/output/csv.test.ts +164 -0
  100. package/test/output/error.test.ts +241 -0
  101. package/src/tui/parity.json +0 -74
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @module mcp/tasks
3
+ * @package @hop-top/kit
4
+ *
5
+ * The `io.modelcontextprotocol/tasks` extension slot.
6
+ *
7
+ * kit does not implement the tasks extension (ADR 0042 gap matrix:
8
+ * "Not implemented. capabilities.extensions omitted from
9
+ * server/discover (= unsupported); tasks/* → -32601 @ 404"). This
10
+ * module makes that decision explicit and testable rather than
11
+ * implicit in a `default:` branch, and marks the designated slot if
12
+ * the extension is ever added.
13
+ *
14
+ * The negotiation contract matters for parity: because
15
+ * server/discover omits `capabilities.extensions` entirely, a
16
+ * conforming client never negotiates the extension and never sends
17
+ * `tasks/*`. A client that sends it anyway gets the same
18
+ * method-not-found response any other unknown modern method gets —
19
+ * NOT a distinct "extension unsupported" error, which would be a wire
20
+ * behavior the Go reference does not produce.
21
+ */
22
+
23
+ import { MCP_ERR_METHOD_NOT_FOUND } from './types.js';
24
+
25
+ /** The reserved extension identifier, as named by the spec. */
26
+ export const TASKS_EXTENSION = 'io.modelcontextprotocol/tasks';
27
+
28
+ /**
29
+ * The task-extension methods. Listed so the surface can recognize
30
+ * them for documentation and testing purposes; recognizing one does
31
+ * NOT change its response.
32
+ */
33
+ export const TASK_METHODS = [
34
+ 'tasks/get',
35
+ 'tasks/update',
36
+ 'tasks/list',
37
+ 'tasks/result',
38
+ 'tasks/cancel',
39
+ ] as const;
40
+
41
+ export type TaskMethod = (typeof TASK_METHODS)[number];
42
+
43
+ /** Reports whether a method name belongs to the tasks extension. */
44
+ export function isTaskMethod(method: string): method is TaskMethod {
45
+ return (TASK_METHODS as readonly string[]).includes(method);
46
+ }
47
+
48
+ /**
49
+ * Whether this mount supports the tasks extension. Always false: the
50
+ * extension is a non-goal, and `server/discover` therefore omits the
51
+ * `capabilities.extensions` map entirely (an empty map would
52
+ * advertise the *ability* to carry extensions, which is a different
53
+ * claim than making none).
54
+ */
55
+ export const TASKS_SUPPORTED = false as const;
56
+
57
+ /**
58
+ * The response for an unsupported tasks method: identical to the
59
+ * generic modern method-not-found (-32601 @ 404). Kept as a named
60
+ * function so the "tasks are unsupported" decision has one call site
61
+ * a reviewer can find, and so a future implementation replaces this
62
+ * rather than editing a catch-all branch.
63
+ */
64
+ export function taskMethodNotFound(method: string): {
65
+ code: number;
66
+ msg: string;
67
+ status: number;
68
+ } {
69
+ return {
70
+ code: MCP_ERR_METHOD_NOT_FOUND,
71
+ msg: `method not found: ${method}`,
72
+ status: 404,
73
+ };
74
+ }
75
+
76
+ /**
77
+ * The `capabilities` object `server/discover` reports. The extensions
78
+ * map is omitted rather than emitted empty — see TASKS_SUPPORTED.
79
+ */
80
+ export function discoverCapabilities(): Record<string, unknown> {
81
+ return { tools: {} };
82
+ }
@@ -0,0 +1,250 @@
1
+ /**
2
+ * Test command trees mirroring the Go lock trees that generated the
3
+ * cross-language wire fixtures.
4
+ *
5
+ * The Go generator (surface_mcp_fixtures_gen_test.go) drives TWO
6
+ * trees: `legacyLockTree` for the legacy cases and `modernLockTree`
7
+ * for the modern ones. They are deliberately different — the legacy
8
+ * tree's `widget add` carries extra `force`/`tag` flags that the
9
+ * modern tree omits — so the fixtures cannot be served from one
10
+ * shared tree. Both are reproduced here.
11
+ *
12
+ * This module is test scaffolding, not part of the published surface.
13
+ */
14
+
15
+ import {
16
+ DestructiveBlockedError,
17
+ defaultPolicy,
18
+ policyAllowed,
19
+ SURFACE_MCP,
20
+ UnknownCommandError,
21
+ type FlagSchema,
22
+ type Invocation,
23
+ type InvokeResult,
24
+ type Leaf,
25
+ type McpBridge,
26
+ } from './types.js';
27
+
28
+ interface TreeLeaf extends Leaf {
29
+ /** Text the leaf prints on stdout when invoked. */
30
+ stdout?: string;
31
+ }
32
+
33
+ const str = (description: string): FlagSchema => ({
34
+ type: 'string',
35
+ description,
36
+ });
37
+ const int = (description: string): FlagSchema => ({
38
+ type: 'integer',
39
+ description,
40
+ });
41
+ const bool = (description: string): FlagSchema => ({
42
+ type: 'boolean',
43
+ description,
44
+ });
45
+ const strArray = (description: string): FlagSchema => ({
46
+ type: 'array',
47
+ description,
48
+ items: { type: 'string' },
49
+ });
50
+
51
+ /**
52
+ * The Go legacy lock tree:
53
+ *
54
+ * root
55
+ * ├── widget
56
+ * │ ├── add (write; name str required, count int, force bool,
57
+ * │ │ tag []str; hidden/deprecated flags excluded)
58
+ * │ └── delete (destructive)
59
+ * ├── secret (auth-required)
60
+ * ├── deploy (requires-confirmation)
61
+ * └── ping (read; the happy-path exec target)
62
+ *
63
+ * Leaf order matches Go's `Bridge.Leaves()` enumeration, which sorts
64
+ * by dotted tool name — the order the fixture's `tools` array pins.
65
+ */
66
+ function legacyLeaves(): TreeLeaf[] {
67
+ return [
68
+ { path: ['deploy'], description: 'Deploy', properties: {}, class: { requiresConfirmation: true } },
69
+ { path: ['ping'], description: 'Ping the server', properties: {}, stdout: 'pong\n' },
70
+ { path: ['secret'], description: 'Locked', properties: {}, class: { authRequired: true } },
71
+ {
72
+ path: ['widget', 'add'],
73
+ description: 'Add a widget',
74
+ properties: {
75
+ name: str('widget name'),
76
+ count: int('widget count'),
77
+ force: bool('force flag'),
78
+ tag: strArray('tag list'),
79
+ },
80
+ required: ['name'],
81
+ stdout: 'added\n',
82
+ },
83
+ {
84
+ path: ['widget', 'delete'],
85
+ description: 'Delete a widget',
86
+ properties: {},
87
+ class: { destructive: true },
88
+ stdout: 'deleted\n',
89
+ },
90
+ ];
91
+ }
92
+
93
+ /**
94
+ * The Go modern lock tree: same shape, but `widget add` declares only
95
+ * `name` (required) and `count`.
96
+ */
97
+ function modernLeaves(): TreeLeaf[] {
98
+ return [
99
+ { path: ['deploy'], description: 'Deploy', properties: {}, class: { requiresConfirmation: true } },
100
+ { path: ['ping'], description: 'Ping the server', properties: {}, stdout: 'pong\n' },
101
+ { path: ['secret'], description: 'Locked', properties: {}, class: { authRequired: true } },
102
+ {
103
+ path: ['widget', 'add'],
104
+ description: 'Add a widget',
105
+ properties: { name: str('widget name'), count: int('widget count') },
106
+ required: ['name'],
107
+ stdout: 'added\n',
108
+ },
109
+ {
110
+ path: ['widget', 'delete'],
111
+ description: 'Delete a widget',
112
+ properties: {},
113
+ class: { destructive: true },
114
+ stdout: 'deleted\n',
115
+ },
116
+ ];
117
+ }
118
+
119
+ /**
120
+ * Builds a bridge over a fixed leaf set, applying the default policy
121
+ * on invoke so the destructive ceiling is exercised exactly as the Go
122
+ * bridge exercises it.
123
+ *
124
+ * The bridge models cobra's lazy help-flag attachment, which is real
125
+ * observable behavior of the Go reference rather than a fixture
126
+ * artifact: cobra attaches a command's `--help` flag on that
127
+ * command's FIRST execution, so a leaf's schema legitimately gains a
128
+ * `help` property once it has been invoked. On a long-lived mount the
129
+ * same `tools/list` bytes therefore produce different responses
130
+ * before and after a `tools/call` — which is what adopters serving
131
+ * from a persistent process actually observe.
132
+ *
133
+ * The rule is applied generically to whichever leaf was executed, not
134
+ * special-cased to `ping` or to any expected fixture bytes: a bridge
135
+ * that hardcoded the answer would pass the sequence while still
136
+ * misrepresenting the mechanism.
137
+ *
138
+ * `leaves()` recomputes from the mutable execution set on every call,
139
+ * which is what lets the surface observe the change — the library
140
+ * re-reads `bridge.leaves()` per request, so a snapshot taken once at
141
+ * construction would hide this behavior.
142
+ */
143
+ function makeBridge(source: () => TreeLeaf[]): McpBridge {
144
+ const leaves = source();
145
+ const policy = defaultPolicy();
146
+ // Leaf keys whose command has been executed at least once, and has
147
+ // therefore had its help flag attached by cobra.
148
+ const executed = new Set<string>();
149
+
150
+ return {
151
+ leaves: (): Leaf[] =>
152
+ leaves.map((l) => {
153
+ const key = l.path.join('.');
154
+ if (!executed.has(key)) return l;
155
+ return {
156
+ ...l,
157
+ properties: {
158
+ ...l.properties,
159
+ help: bool(`help for ${l.path[l.path.length - 1]}`),
160
+ },
161
+ };
162
+ }),
163
+ invoke(inv: Invocation): InvokeResult {
164
+ const key = inv.path.join('.');
165
+ const leaf = leaves.find((l) => l.path.join('.') === key);
166
+ if (leaf === undefined) {
167
+ throw new UnknownCommandError(`unknown command: ${key}`);
168
+ }
169
+ if (!policyAllowed(policy, leaf.class ?? {}, inv.meta.surface)) {
170
+ throw new DestructiveBlockedError(leaf.path.join(' '), inv.meta.surface);
171
+ }
172
+ // Cobra attaches the help flag as part of executing the command,
173
+ // so this happens only once the policy gate has let it through:
174
+ // a blocked invocation never runs, and never attaches the flag.
175
+ executed.add(key);
176
+ return { stdout: leaf.stdout ?? '', exitCode: 0 };
177
+ },
178
+ };
179
+ }
180
+
181
+ /**
182
+ * The Go MRTR lock tree (`mrtrLockTree`): a single
183
+ * requires-confirmation leaf, isolated from every other fixture tree.
184
+ * `purge` echoes its `--target` flag, so the accepted round-2 response
185
+ * proves the leaf ran with the arguments the state was bound to rather
186
+ * than merely that it ran.
187
+ */
188
+ function mrtrLeaves(): TreeLeaf[] {
189
+ return [
190
+ {
191
+ path: ['purge'],
192
+ description: 'Purge a target',
193
+ properties: { target: str('what to purge') },
194
+ class: { requiresConfirmation: true },
195
+ },
196
+ // Go's `vault burn`: destructive AND requires-confirmation, so a
197
+ // fully accepted MRTR exchange still meets the policy gate behind
198
+ // it. The fixture tree has no such leaf, and a leaf that is merely
199
+ // destructive never enters the confirmation gate at all — which
200
+ // would make the ceiling assertion vacuous.
201
+ {
202
+ path: ['vault', 'burn'],
203
+ description: 'Burn the vault',
204
+ properties: {},
205
+ class: { requiresConfirmation: true, destructive: true },
206
+ stdout: 'burned\n',
207
+ },
208
+ ];
209
+ }
210
+
211
+ /** A bridge over the Go legacy lock tree. */
212
+ export function legacyLockBridge(): McpBridge {
213
+ return makeBridge(legacyLeaves);
214
+ }
215
+
216
+ /**
217
+ * A bridge over the Go MRTR lock tree, plus the execution counter the
218
+ * Go tests assert on: the whole point of the first round is that the
219
+ * leaf does NOT run, which only an execution count can prove.
220
+ */
221
+ export function mrtrLockBridge(): {
222
+ bridge: McpBridge;
223
+ executions: () => number;
224
+ } {
225
+ let executions = 0;
226
+ const inner = makeBridge(mrtrLeaves);
227
+ const bridge: McpBridge = {
228
+ leaves: () => inner.leaves(),
229
+ invoke(inv: Invocation): InvokeResult {
230
+ // The policy gate runs inside `inner.invoke` and throws before
231
+ // returning, so a blocked leaf is never counted as executed.
232
+ const res = inner.invoke(inv) as InvokeResult;
233
+ executions += 1;
234
+ if (inv.path.join('.') !== 'purge') return res;
235
+ const target = inv.flags?.target;
236
+ return {
237
+ ...res,
238
+ stdout: `purged ${typeof target === 'string' ? target : ''}\n`,
239
+ };
240
+ },
241
+ };
242
+ return { bridge, executions: () => executions };
243
+ }
244
+
245
+ /** A bridge over the Go modern lock tree. */
246
+ export function modernLockBridge(): McpBridge {
247
+ return makeBridge(modernLeaves);
248
+ }
249
+
250
+ export { SURFACE_MCP };