@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,138 @@
1
+ /**
2
+ * @module netpolicy
3
+ * @package @hop-top/kit
4
+ *
5
+ * Owns the process-wide network policy marker and the `fetch` wrapper that
6
+ * enforces it.
7
+ *
8
+ * The `--offline` global (cli-parity-guide, "Global Flags") promises that
9
+ * network access is disabled. Marking a scope alone cannot keep that
10
+ * promise: it is advisory, so any caller that forgets to consult it still
11
+ * reaches the wire. {@link guardFetch} closes that gap by refusing the
12
+ * request inside the fetch implementation, beneath every caller, where no
13
+ * naive leaf can route around it.
14
+ *
15
+ * The marker lives in its own module rather than in `cli` so library code
16
+ * can enforce the policy without importing the CLI factory back.
17
+ *
18
+ * Loopback is deliberately exempt. `--offline` means "do not talk to the
19
+ * network", not "do not talk to myself": a local `kit serve` peer, a dev
20
+ * backend on 127.0.0.1 and unix sockets stay reachable so offline
21
+ * workflows remain usable.
22
+ *
23
+ * ## Scope
24
+ *
25
+ * {@link install} wraps `globalThis.fetch`, so it covers HTTP and HTTPS
26
+ * through the fetch API — which is every network client in kit today
27
+ * (`api`, `aim`, `upgrade`, `routellm`, `triton`, `telemetry`, and the
28
+ * ConnectRPC transport, which resolves `globalThis.fetch` lazily per
29
+ * call). undici's `setGlobalDispatcher` is not used: undici is not a
30
+ * dependency of this package, so the dispatcher hook is unavailable
31
+ * without adding one, and it would not cover callers that inject their
32
+ * own `fetch` anyway.
33
+ *
34
+ * It does NOT cover code that opens a socket directly: `node:net`,
35
+ * `node:http`/`node:https` (`http.request`), `node:dgram`, database
36
+ * drivers, or raw TLS. Nor does it cover a caller that captured a
37
+ * reference to the unguarded `fetch` before {@link install} ran, or one
38
+ * that injects its own transport (`APIClient({ fetch })`). For those,
39
+ * `--offline` remains advisory and the call site must consult
40
+ * {@link isOffline} itself, or wrap its own transport with
41
+ * {@link guardFetch}. Closing that gap needs a guarded dialer threaded
42
+ * through each such client; it is deliberately not attempted here.
43
+ */
44
+ /**
45
+ * Name carried by the error {@link guardFetch} rejects with when a request
46
+ * is attempted in an offline-marked scope. JavaScript has no `errors.Is`,
47
+ * so the name is the matchable analogue of Go's sentinel `ErrOffline`;
48
+ * prefer {@link isOfflineError} over comparing it by hand.
49
+ */
50
+ declare const ErrOffline = "OfflineError";
51
+ /** Error rejected by {@link guardFetch}. Matchable via {@link isOfflineError}. */
52
+ declare class OfflineError extends Error {
53
+ readonly name = "OfflineError";
54
+ constructor(method: string, url: string);
55
+ }
56
+ /**
57
+ * Report whether err is the refusal raised by the offline guard. Matches on
58
+ * the error name rather than `instanceof` so a copy of this module loaded
59
+ * through a different resolution path (bundled adopter, dual dist/src
60
+ * graph) still matches — the JS analogue of `errors.Is`.
61
+ */
62
+ declare function isOfflineError(err: unknown): boolean;
63
+ /**
64
+ * Run fn in a scope marked offline. Passing false runs fn unchanged so an
65
+ * unmarked scope stays clean, mirroring Go's `WithOffline(ctx, false)`.
66
+ */
67
+ declare function withOffline<T>(offline: boolean, fn: () => T): T;
68
+ /**
69
+ * Mark the whole process offline. The CLI uses this rather than
70
+ * {@link withOffline} because commander dispatches an action handler
71
+ * without giving the framework a scope to wrap around it, and because a
72
+ * detached callback (a timer, an unawaited promise) must stay refused.
73
+ * Mirrors the process-global reach of Go's `netpolicy.Install`.
74
+ */
75
+ declare function setProcessOffline(offline: boolean): void;
76
+ /**
77
+ * Report whether the caller is running under the offline marker — either
78
+ * an enclosing {@link withOffline} scope or a process-wide
79
+ * {@link setProcessOffline}.
80
+ */
81
+ declare function isOffline(): boolean;
82
+ /**
83
+ * Wrap base so requests made in an offline-marked scope reject with an
84
+ * {@link OfflineError} instead of reaching the network. Wrapping is
85
+ * idempotent: guarding an already guarded fetch returns it unchanged.
86
+ *
87
+ * A URL that does not parse is refused when offline: an unparseable target
88
+ * cannot be shown to be loopback, and the policy fails closed.
89
+ */
90
+ declare function guardFetch(base: typeof globalThis.fetch): typeof globalThis.fetch;
91
+ /**
92
+ * Wrap `globalThis.fetch` with {@link guardFetch}, so every caller that
93
+ * does not inject its own transport — the common case across kit and
94
+ * adopter code — enforces the policy without a per-site change.
95
+ *
96
+ * Idempotent and safe to call more than once. Call it once during process
97
+ * start-up (`createCLI` does this) and never concurrently with in-flight
98
+ * requests: it mutates a process-global.
99
+ *
100
+ * Callers that DO inject their own fetch must wrap it themselves with
101
+ * {@link guardFetch}; install cannot reach them.
102
+ */
103
+ declare function install(): void;
104
+ /**
105
+ * Fetch for logging-class egress — telemetry, and any future
106
+ * remote-logging or crash-reporting sink.
107
+ *
108
+ * `--offline` means "do not talk to the network on the user's behalf". It
109
+ * does not silence diagnostics, the same way a remote syslog target is
110
+ * not muted by an offline flag. Consent and the telemetry mode already
111
+ * govern whether those sinks emit at all; `--offline` is not a second
112
+ * consent gate.
113
+ *
114
+ * Resolved lazily, per call: it reads the *current* `globalThis.fetch`
115
+ * and unwraps the guard if {@link install} has wrapped it. Capturing a
116
+ * reference at module load instead would freeze out later stubbing —
117
+ * breaking both test fakes and adopters who swap the global transport.
118
+ *
119
+ * Never use this for anything the user asked for — that is exactly the
120
+ * traffic `--offline` exists to stop.
121
+ */
122
+ declare function observabilityFetch(): typeof globalThis.fetch;
123
+
124
+ declare const netpolicy_ErrOffline: typeof ErrOffline;
125
+ type netpolicy_OfflineError = OfflineError;
126
+ declare const netpolicy_OfflineError: typeof OfflineError;
127
+ declare const netpolicy_guardFetch: typeof guardFetch;
128
+ declare const netpolicy_install: typeof install;
129
+ declare const netpolicy_isOffline: typeof isOffline;
130
+ declare const netpolicy_isOfflineError: typeof isOfflineError;
131
+ declare const netpolicy_observabilityFetch: typeof observabilityFetch;
132
+ declare const netpolicy_setProcessOffline: typeof setProcessOffline;
133
+ declare const netpolicy_withOffline: typeof withOffline;
134
+ declare namespace netpolicy {
135
+ export { netpolicy_ErrOffline as ErrOffline, netpolicy_OfflineError as OfflineError, netpolicy_guardFetch as guardFetch, netpolicy_install as install, netpolicy_isOffline as isOffline, netpolicy_isOfflineError as isOfflineError, netpolicy_observabilityFetch as observabilityFetch, netpolicy_setProcessOffline as setProcessOffline, netpolicy_withOffline as withOffline };
136
+ }
137
+
138
+ export { ErrOffline as E, OfflineError as O, isOffline as a, isOfflineError as b, guardFetch as g, install as i, netpolicy as n, observabilityFetch as o, setProcessOffline as s, withOffline as w };
@@ -0,0 +1 @@
1
+ export { E as ErrOffline, O as OfflineError, g as guardFetch, i as install, a as isOffline, b as isOfflineError, o as observabilityFetch, s as setProcessOffline, w as withOffline } from './netpolicy-asvCfwi8.js';
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target2, all) => {
7
+ for (var name in all)
8
+ __defProp(target2, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/netpolicy.ts
21
+ var netpolicy_exports = {};
22
+ __export(netpolicy_exports, {
23
+ ErrOffline: () => ErrOffline,
24
+ OfflineError: () => OfflineError,
25
+ guardFetch: () => guardFetch,
26
+ install: () => install,
27
+ isOffline: () => isOffline,
28
+ isOfflineError: () => isOfflineError,
29
+ observabilityFetch: () => observabilityFetch,
30
+ setProcessOffline: () => setProcessOffline,
31
+ withOffline: () => withOffline
32
+ });
33
+ module.exports = __toCommonJS(netpolicy_exports);
34
+ var import_node_async_hooks = require("async_hooks");
35
+ var ErrOffline = "OfflineError";
36
+ var OfflineError = class extends Error {
37
+ constructor(method, url) {
38
+ super(`${method} ${url}: network disabled by --offline`);
39
+ this.name = ErrOffline;
40
+ }
41
+ };
42
+ function isOfflineError(err) {
43
+ return err instanceof Error && err.name === ErrOffline;
44
+ }
45
+ var store = new import_node_async_hooks.AsyncLocalStorage();
46
+ var processOffline = false;
47
+ function withOffline(offline, fn) {
48
+ if (!offline) return fn();
49
+ return store.run(true, fn);
50
+ }
51
+ function setProcessOffline(offline) {
52
+ processOffline = offline;
53
+ }
54
+ function isOffline() {
55
+ return processOffline || store.getStore() === true;
56
+ }
57
+ function isLoopback(hostname) {
58
+ const h = hostname.replace(/^\[|\]$/g, "");
59
+ if (h === "localhost") return true;
60
+ if (h === "::1") return true;
61
+ const v4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(h);
62
+ if (v4) {
63
+ return v4.slice(1).every((o) => Number(o) <= 255) && Number(v4[1]) === 127;
64
+ }
65
+ const mapped = /^::ffff:(.+)$/i.exec(h);
66
+ if (mapped) {
67
+ const inner = mapped[1] ?? "";
68
+ if (/^7f00:1$/i.test(inner)) return true;
69
+ return isLoopback(inner);
70
+ }
71
+ return false;
72
+ }
73
+ function target(input, init) {
74
+ if (typeof Request !== "undefined" && input instanceof Request) {
75
+ return { method: init?.method ?? input.method, url: input.url };
76
+ }
77
+ return { method: init?.method ?? "GET", url: String(input) };
78
+ }
79
+ var guarded = /* @__PURE__ */ Symbol.for("hop.top/kit/netpolicy.guarded");
80
+ var unguardedBase = /* @__PURE__ */ Symbol.for("hop.top/kit/netpolicy.unguardedBase");
81
+ function guardFetch(base) {
82
+ if (base[guarded]) return base;
83
+ const wrapper = async (input, init) => {
84
+ if (isOffline()) {
85
+ const { method, url } = target(input, init);
86
+ let loopback = false;
87
+ try {
88
+ loopback = isLoopback(new URL(url).hostname);
89
+ } catch {
90
+ loopback = false;
91
+ }
92
+ if (!loopback) throw new OfflineError(method, url);
93
+ }
94
+ return base(input, init);
95
+ };
96
+ wrapper[guarded] = true;
97
+ wrapper[unguardedBase] = base;
98
+ return wrapper;
99
+ }
100
+ function install() {
101
+ globalThis.fetch = guardFetch(globalThis.fetch);
102
+ }
103
+ function observabilityFetch() {
104
+ const current = globalThis.fetch;
105
+ return current?.[unguardedBase] ?? globalThis.fetch;
106
+ }
107
+ // Annotate the CommonJS export names for ESM import in node:
108
+ 0 && (module.exports = {
109
+ ErrOffline,
110
+ OfflineError,
111
+ guardFetch,
112
+ install,
113
+ isOffline,
114
+ isOfflineError,
115
+ observabilityFetch,
116
+ setProcessOffline,
117
+ withOffline
118
+ });