@hop-top/kit 0.5.0-alpha.12 → 0.5.0-alpha.14

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 (125) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +5 -5
  3. package/dist/bus-D2bAOPYz.d.ts +55 -0
  4. package/dist/bus.d.ts +1 -0
  5. package/dist/bus.js +13 -0
  6. package/dist/chunk-74E6RNOI.js +82 -0
  7. package/dist/chunk-B7XTFDBB.js +17 -0
  8. package/dist/chunk-CAONBSPO.js +497 -0
  9. package/dist/chunk-F7RSL4N4.js +88 -0
  10. package/dist/chunk-I6XDPSXQ.js +75 -0
  11. package/dist/chunk-IDM6YZXN.js +204 -0
  12. package/dist/{chunk-BXJ2J27B.js → chunk-IGKBRNEW.js} +10 -10
  13. package/dist/{chunk-VWGP4NVJ.js → chunk-MDVGMOZO.js} +45 -39
  14. package/dist/{chunk-4FMALWYB.js → chunk-MEF7W3MG.js} +45 -45
  15. package/dist/{chunk-VGOA5Y7S.js → chunk-Q547MHNB.js} +11 -11
  16. package/dist/{chunk-K7E34Q3A.js → chunk-TUU2BY5I.js} +136 -47
  17. package/dist/chunk-VKQCOVKI.js +880 -0
  18. package/dist/cli.js +3 -3
  19. package/dist/index-BqZ7WGQf.d.ts +731 -0
  20. package/dist/index.d.ts +8 -5
  21. package/dist/index.js +32 -18
  22. package/dist/{llm-DYuR7_uX.d.ts → llm-BazFKc_2.d.ts} +95 -9
  23. package/dist/{llm-anthropic-Cd_I2xXB.d.ts → llm-anthropic-BcAitoDV.d.ts} +1 -1
  24. package/dist/llm-anthropic.d.ts +2 -2
  25. package/dist/llm-anthropic.js +4 -4
  26. package/dist/{llm-openai-DyFrucmV.d.ts → llm-openai-CSDvuRH6.d.ts} +1 -1
  27. package/dist/llm-openai.d.ts +2 -2
  28. package/dist/llm-openai.js +4 -4
  29. package/dist/llm.d.ts +1 -1
  30. package/dist/llm.js +8 -2
  31. package/dist/{routellm-B0nv59mH.d.ts → routellm-B9UrONPr.d.ts} +1 -1
  32. package/dist/routellm.d.ts +2 -2
  33. package/dist/routellm.js +5 -5
  34. package/dist/upgrade/drivers/configfile.d.ts +45 -0
  35. package/dist/upgrade/drivers/configfile.js +78 -0
  36. package/dist/upgrade/drivers/fsdir.d.ts +61 -0
  37. package/dist/upgrade/drivers/fsdir.js +170 -0
  38. package/dist/upgrade/drivers/postgres.d.ts +121 -0
  39. package/dist/upgrade/drivers/postgres.js +195 -0
  40. package/dist/upgrade/drivers/sqlite.d.ts +101 -0
  41. package/dist/upgrade/drivers/sqlite.js +241 -0
  42. package/dist/upgrade/index.d.ts +2 -0
  43. package/dist/upgrade/index.js +73 -0
  44. package/dist/uri-IJ_AoY3d.d.ts +144 -0
  45. package/dist/uri.d.ts +1 -0
  46. package/dist/uri.js +37 -0
  47. package/dist/version-DEJ3pbiO.d.ts +10 -0
  48. package/dist/wizard-Bf_qHc31.d.ts +159 -0
  49. package/dist/wizard.d.ts +1 -0
  50. package/dist/wizard.js +39 -0
  51. package/package.json +76 -17
  52. package/skills/hop-top-kit-ts/.claude-plugin/plugin.json +19 -0
  53. package/skills/hop-top-kit-ts/SKILL.md +117 -0
  54. package/skills/hop-top-kit-ts/assets/snippets/mcp/mcp.expected +2 -0
  55. package/skills/hop-top-kit-ts/assets/snippets/mcp/mcp.ts +20 -0
  56. package/skills/hop-top-kit-ts/assets/snippets/quickstart/quickstart.expected +13 -0
  57. package/skills/hop-top-kit-ts/assets/snippets/quickstart/quickstart.ts +26 -0
  58. package/skills/hop-top-kit-ts/gym.json +5 -0
  59. package/skills/hop-top-kit-ts/references/ai-and-agents.md +45 -0
  60. package/skills/hop-top-kit-ts/references/cli-and-console.md +63 -0
  61. package/skills/hop-top-kit-ts/references/coverage.md +56 -0
  62. package/skills/hop-top-kit-ts/references/guardrails-and-trust.md +60 -0
  63. package/skills/hop-top-kit-ts/references/other-ports.md +31 -0
  64. package/skills/hop-top-kit-ts/references/serving-and-transports.md +49 -0
  65. package/skills/hop-top-kit-ts/scripts/detect-port.sh +168 -0
  66. package/src/index.test.ts +48 -2
  67. package/src/index.ts +6 -1
  68. package/src/llm-anthropic.conformance.test.ts +7 -0
  69. package/src/llm-boundkey.test.ts +260 -0
  70. package/src/llm-choice-hermetic.test.ts +1 -1
  71. package/src/llm-config.test.ts +2 -4
  72. package/src/llm-config.ts +5 -1
  73. package/src/llm-endpoint.ts +25 -5
  74. package/src/llm-keys.ts +47 -15
  75. package/src/llm-openai.test.ts +10 -4
  76. package/src/llm-openai.ts +7 -1
  77. package/src/llm-spec.test.ts +347 -0
  78. package/src/llm-spec.ts +80 -0
  79. package/src/llm-uri.ts +96 -12
  80. package/src/llm.test.ts +2 -2
  81. package/src/llm.ts +10 -0
  82. package/src/published-types.test.ts +8 -0
  83. package/src/serve.stopped-order.test.ts +156 -0
  84. package/src/upgrade/README.md +42 -0
  85. package/src/upgrade/backup.ts +174 -0
  86. package/src/upgrade/conformance.test.ts +310 -0
  87. package/src/upgrade/document.ts +229 -0
  88. package/src/upgrade/driver.ts +66 -0
  89. package/src/upgrade/drivers/README.md +47 -0
  90. package/src/upgrade/drivers/configfile.test.ts +112 -0
  91. package/src/upgrade/drivers/configfile.ts +107 -0
  92. package/src/upgrade/drivers/fsdir.test.ts +188 -0
  93. package/src/upgrade/drivers/fsdir.ts +216 -0
  94. package/src/upgrade/drivers/isolation.test.ts +18 -0
  95. package/src/upgrade/drivers/postgres.integration.test.ts +395 -0
  96. package/src/upgrade/drivers/postgres.test.ts +272 -0
  97. package/src/upgrade/drivers/postgres.ts +284 -0
  98. package/src/upgrade/drivers/sqlite.integration.test.ts +492 -0
  99. package/src/upgrade/drivers/sqlite.ts +300 -0
  100. package/src/upgrade/drivers/version.ts +21 -0
  101. package/src/upgrade/errors.ts +117 -0
  102. package/src/upgrade/events.ts +117 -0
  103. package/src/{upgrade.test.ts → upgrade/index.test.ts} +1 -1
  104. package/src/{upgrade.ts → upgrade/index.ts} +20 -0
  105. package/src/upgrade/migration.ts +89 -0
  106. package/src/upgrade/migrator.test.ts +391 -0
  107. package/src/upgrade/migrator.ts +527 -0
  108. package/src/upgrade/options.ts +59 -0
  109. package/src/upgrade/semver.ts +90 -0
  110. package/test/llm/conformance-helpers.ts +3 -0
  111. package/test/skill-snippets.test.ts +60 -0
  112. package/test/upgrade/conformance-migrator.ts +439 -0
  113. package/test/upgrade/conformance-support.ts +44 -0
  114. package/test/upgrade/driver-support.ts +44 -0
  115. package/test/upgrade/pg-container.ts +64 -0
  116. package/test/upgrade/pg-race-worker.ts +48 -0
  117. package/test/upgrade/race-helper.ts +36 -0
  118. package/test/upgrade/sqlite-support.ts +41 -0
  119. package/test/upgrade/testdata/go-fsdir-mydata.tar.gz +0 -0
  120. package/vitest.config.ts +26 -0
  121. package/dist/chunk-X4E5QGEB.js +0 -171
  122. package/dist/upgrade-BJ2z6Oqf.d.ts +0 -156
  123. package/dist/upgrade.d.ts +0 -1
  124. package/dist/upgrade.js +0 -9
  125. package/dist/{chunk-MFVUENZR.js → chunk-KV7FYEAF.js} +2 -2
@@ -0,0 +1,31 @@
1
+ # Other ports
2
+
3
+ Generated by `make skills-sync` from the capability parity page. Do not edit by hand.
4
+
5
+ This file is a snapshot taken at the `metadata.version` recorded in this skill's SKILL.md. The current matrix is [capability-matrix](https://github.com/hop-top/kit/blob/main/skills/hop-top-kit/references/capability-matrix.md); its source is [capability parity](https://github.com/hop-top/poly-kit/blob/next/docs/adopters/reference/capability-parity.md).
6
+
7
+ ## Ports
8
+
9
+ | Port | Skill | Package | Install | Tier | Needs | Status counts |
10
+ |---|---|---|---|---|---|---|
11
+ | Go | [`hop-top-kit-go`](https://github.com/hop-top/kit/blob/main/skills/hop-top-kit-go/SKILL.md) | `hop.top/kit` | `go get hop.top/kit` | reference | Go 1.27 | 74 done |
12
+ | TypeScript | [`hop-top-kit-ts`](https://github.com/hop-top/kit-ts/blob/main/skills/hop-top-kit-ts/SKILL.md) | `@hop-top/kit` | `pnpm add @hop-top/kit` | supported | Node 22.12+ | 11 done, 9 partial, 17 unverified, 36 none, 1 n/a |
13
+ | Python | [`hop-top-kit-py`](https://github.com/hop-top/kit-py/blob/main/skills/hop-top-kit-py/SKILL.md) | `hop-top-kit` | `pip install hop-top-kit` | supported | Python 3.11+ | 9 done, 9 partial, 19 unverified, 36 none, 1 n/a |
14
+ | Rust | [`hop-top-kit-rs`](https://github.com/hop-top/kit-rs/blob/main/skills/hop-top-kit-rs/SKILL.md) | `hop-top-kit` | `cargo add hop-top-kit` | experimental | Rust 1.89+ | 13 done, 19 partial, 12 unverified, 29 none, 1 n/a |
15
+ | PHP | [`hop-top-kit-php`](https://github.com/hop-top/kit-php/blob/main/skills/hop-top-kit-php/SKILL.md) | `hop-top/kit` | `composer require hop-top/kit` | experimental | PHP 8.4+ | 4 done, 7 partial, 5 unverified, 57 none, 1 n/a |
16
+
17
+ ## Router
18
+
19
+ To choose between ports, use [`hop-top-kit`](https://github.com/hop-top/kit/blob/main/skills/hop-top-kit/SKILL.md).
20
+
21
+ ## Go only
22
+
23
+ No other port has these (status `none` or `n/a`); use Go or run the `kit` binary as a sidecar.
24
+
25
+ - CLI and console: Markdown rendering, Command annotations, Config path commands, Fuzzy matching, Process status
26
+ - Config, storage and secrets: Project registry, Secrets
27
+ - Serving and transports: Service command group, Transport service seam, Served observability, Bridge payloads
28
+ - Events, jobs and runtime: Job queue, Peer mesh
29
+ - Guardrails and trust: Operating mode, Audit log, Avatars
30
+ - AI and agents: Command reflection, Agent CLI invocation, Extensions
31
+ - Conformance and integrations: Conformance assertions, Conformance harness, Scenario and story DSL, Cassettes and grading client, Repo host drivers
@@ -0,0 +1,49 @@
1
+ # Serving and transports
2
+
3
+ Open when running a service lifecycle, serving a command tree over MCP, or calling REST or
4
+ ConnectRPC from TypeScript. Status per capability: [coverage](coverage.md). Depth:
5
+ [TypeScript API reference](https://github.com/hop-top/poly-kit/blob/next/docs/adopters/reference/ts-api-reference.md)
6
+ (sections Serve and MCP surface).
7
+
8
+ ## This port ships no server
9
+
10
+ kit-ts supervises services and mounts MCP as a plain handler; it opens no HTTP or socket
11
+ listener. Your service's `start` binds the port. The REST projection of a command tree, the Unix
12
+ socket service and served authentication are Go-only (coverage lists them as lacking).
13
+
14
+ ## Modules
15
+
16
+ | Import | Use for | Cue |
17
+ |--------|---------|-----|
18
+ | `@hop-top/kit/serve` | `<tool> serve [service]` lifecycle | `ServiceRegistry`, `registerServe(program, { registry, configs })` |
19
+ | `@hop-top/kit/mcp` | command tree as MCP tools | `commanderBridge`, `createMcpHandler`, `serveStdio`, `defaultPolicy` |
20
+ | `@hop-top/kit/api` | REST client for kit entity APIs | `APIClient`, `WSClient`; a client, not a server |
21
+ | `@hop-top/kit/rpc` | ConnectRPC client | `RPCClient` |
22
+
23
+ Matrix cell `unverified`: `@hop-top/kit/api`, `@hop-top/kit/rpc`, and served middleware (the MCP
24
+ audit and safety slice only). Check coverage, tell the user, test the calls you depend on.
25
+
26
+ ## Serve
27
+
28
+ - `serve <service>` starts that service even when its `enabled` is false; a supervisor run that
29
+ resolves to zero services exits 2. Exit codes: 0 clean, 1 failure, 2 usage, 3 unknown service,
30
+ 5 policy denied.
31
+ - This port does not resolve dotted config keys: pass the resolved blocks as `configs`.
32
+ - Contract and parity: serve lifecycle corpus is shared with Go; see the
33
+ [serve lifecycle contract](https://github.com/hop-top/poly-kit/blob/next/docs/contracts/serve-lifecycle.md).
34
+
35
+ ## MCP
36
+
37
+ - `assets/snippets/mcp/` lists tools from a one-leaf tree; its expected output is checked in.
38
+ - `commanderBridge` requires `run` (kit does not capture command output for you). Tools are named
39
+ by the leaf path joined with `toolNameSeparator` (default `.`; use `_` for hosts that refuse dots).
40
+ - Default policy blocks every destructive leaf on remote surfaces, including an unannotated leaf
41
+ named `delete`, `remove`, `rm`, `destroy`, `purge` or `drop`.
42
+ - One mount answers the `2024-11-05` and `2026-07-28` protocol eras per request. The protocol
43
+ layer is `@modelcontextprotocol/server` and `@modelcontextprotocol/core` (v2). The legacy
44
+ `@modelcontextprotocol/sdk` package cannot serve the newer era: do not add it.
45
+ - Host it on any stack: the handler is `(McpHttpRequest) => Promise<McpHttpResponse>`; stdio via
46
+ `serveStdio` for a host that spawns the tool.
47
+ - Confirmation on the modern era: `headerConfirmationGate` or `ElicitationConfirmGate`; the
48
+ `audit` option records every refusal.
49
+ - Guide: [serve MCP from any SDK](https://github.com/hop-top/poly-kit/blob/next/docs/adopters/guides/serve-mcp-from-any-sdk.md).
@@ -0,0 +1,168 @@
1
+ #!/bin/sh
2
+ # detect-port.sh - report which kit port(s) a project directory already uses.
3
+ #
4
+ # Usage: detect-port.sh [dir] dir defaults to the current directory.
5
+ #
6
+ # Reads manifest files directly inside dir (no recursion). Writes nothing,
7
+ # touches no network, runs no package manager.
8
+ #
9
+ # Manifests, in the order they are reported:
10
+ # go.mod module hop.top/kit
11
+ # package.json @hop-top/kit
12
+ # pyproject.toml hop-top-kit
13
+ # requirements*.txt hop-top-kit
14
+ # uv.lock hop-top-kit
15
+ # Cargo.toml hop-top-kit
16
+ # composer.json hop-top/kit
17
+ #
18
+ # Output: one line per manifest found, fields separated by single spaces,
19
+ # key=value, no value contains a space:
20
+ # port=<go|ts|py|rs|php> manifest=<file> kit=<spec> skill=<name> url=<url>
21
+ # kit=<spec> is the version or range as the manifest writes it (spaces
22
+ # removed), "unpinned" when kit is listed without one, "absent" when the
23
+ # manifest does not list kit, "unreadable" when the file cannot be read.
24
+ # url is the port skill's SKILL.md. A directory with no manifest prints
25
+ # nothing on stdout and one note on stderr.
26
+ #
27
+ # Exit codes:
28
+ # 0 dir is readable (whether or not any manifest was found)
29
+ # 2 usage error, or dir is not a readable directory
30
+
31
+ LC_ALL=C
32
+ export LC_ALL
33
+
34
+ usage() {
35
+ echo "usage: detect-port.sh [dir]" >&2
36
+ exit 2
37
+ }
38
+
39
+ case ${1-} in
40
+ -h | --help)
41
+ echo "usage: detect-port.sh [dir]"
42
+ exit 0
43
+ ;;
44
+ -*) usage ;;
45
+ esac
46
+ [ $# -le 1 ] || usage
47
+ dir=${1:-.}
48
+ if [ ! -d "$dir" ] || [ ! -r "$dir" ] || [ ! -x "$dir" ]; then
49
+ echo "detect-port: not a readable directory: $dir" >&2
50
+ exit 2
51
+ fi
52
+
53
+ found=0
54
+
55
+ # report <port> <file> <spec>
56
+ report() {
57
+ case $1 in
58
+ go) skill=hop-top-kit-go mirror=kit ;;
59
+ ts) skill=hop-top-kit-ts mirror=kit-ts ;;
60
+ py) skill=hop-top-kit-py mirror=kit-py ;;
61
+ rs) skill=hop-top-kit-rs mirror=kit-rs ;;
62
+ php) skill=hop-top-kit-php mirror=kit-php ;;
63
+ esac
64
+ printf 'port=%s manifest=%s kit=%s skill=%s url=https://github.com/hop-top/%s/blob/main/skills/%s/SKILL.md\n' \
65
+ "$1" "$2" "$3" "$skill" "$mirror" "$skill"
66
+ found=1
67
+ }
68
+
69
+ # check <port> <name> <extractor> [path]: report when the manifest exists.
70
+ check() {
71
+ path=${4:-$dir/$2}
72
+ [ -f "$path" ] || return 0
73
+ if [ -r "$path" ]; then
74
+ spec=$(extract "$3" "$path" | tr -d ' \t')
75
+ else
76
+ spec=unreadable
77
+ fi
78
+ report "$1" "$2" "${spec:-unpinned}"
79
+ }
80
+
81
+ # Extractors print the spec, "absent", or nothing for an unpinned entry.
82
+
83
+ extract() {
84
+ case $1 in
85
+ gomod) ex_gomod "$2" ;;
86
+ package) ex_package "$2" ;;
87
+ python) ex_python "$2" ;;
88
+ uvlock) ex_uvlock "$2" ;;
89
+ cargo) ex_cargo "$2" ;;
90
+ composer) ex_composer "$2" ;;
91
+ esac
92
+ }
93
+
94
+ # json_dep <key> <file>: the value of "<key>": "<value>".
95
+ json_dep() {
96
+ v=$(sed -n 's|.*"'"$1"'"[[:space:]]*:[[:space:]]*"\([^"]*\)".*|\1|p' "$2" | head -n 1)
97
+ [ -n "$v" ] && echo "$v" || echo absent
98
+ }
99
+ ex_package() { json_dep '@hop-top/kit' "$1"; }
100
+ ex_composer() { json_dep 'hop-top/kit' "$1"; }
101
+
102
+ ex_gomod() {
103
+ awk '
104
+ $1 == "require" && $2 == "hop.top/kit" && $3 ~ /^v[0-9]/ { print $3; f = 1; exit }
105
+ $1 == "hop.top/kit" && $2 ~ /^v[0-9]/ { print $2; f = 1; exit }
106
+ END { if (!f) print "absent" }' "$1"
107
+ }
108
+
109
+ # Python: requirement lines and TOML dependency entries, name normalised.
110
+ ex_python() {
111
+ awk '
112
+ /^[ \t]*#/ || /^[ \t]*name[ \t]*=/ { next }
113
+ {
114
+ low = tolower($0); gsub(/[_.]/, "-", low)
115
+ for (off = 0; (i = index(substr(low, off + 1), "hop-top-kit")) > 0; off += i) {
116
+ p = off + i
117
+ if (p > 1 && substr(low, p - 1, 1) ~ /[a-z0-9-]/) continue
118
+ if (substr(low, p + 11, 1) ~ /[a-z0-9-]/) continue
119
+ f = 1; rest = substr($0, p + 11)
120
+ sub(/^\[[^]]*\]/, "", rest)
121
+ if (match(rest, /^[ \t]*=[ \t]*["'"'"'][^"'"'"']*["'"'"']/)) {
122
+ v = substr(rest, RSTART, RLENGTH); sub(/^[ \t]*=[ \t]*["'"'"']/, "", v); sub(/["'"'"']$/, "", v)
123
+ } else if (match(rest, /^[ \t]*[<>=!~]+[ \t]*[^"'"'"';# \t,]*([ \t]*,[ \t]*[<>=!~]+[ \t]*[^"'"'"';# \t,]*)*/)) {
124
+ v = substr(rest, RSTART, RLENGTH); sub(/^[ \t]+/, "", v)
125
+ }
126
+ print v; exit
127
+ }
128
+ }
129
+ END { if (!f) print "absent" }' "$1"
130
+ }
131
+
132
+ ex_uvlock() {
133
+ awk '
134
+ tolower($0) ~ /^name[ \t]*=[ \t]*"hop[-_.]top[-_.]kit"/ { hit = 1; next }
135
+ hit && /^version[ \t]*=/ { v = $0; sub(/^[^"]*"/, "", v); sub(/".*/, "", v); print v; f = 1; exit }
136
+ /^\[\[package\]\]/ { hit = 0 }
137
+ END { if (!f) print (hit ? "" : "absent") }' "$1"
138
+ }
139
+
140
+ ex_cargo() {
141
+ awk '
142
+ /^[ \t]*#/ { next }
143
+ /^\[/ { tbl = ($0 ~ /dependencies\.hop-top-kit[ \t]*\]/); if (tbl) f = 1; next }
144
+ tbl && /^version[ \t]*=/ { v = $0; sub(/^[^"]*"/, "", v); sub(/".*/, "", v); print v; exit }
145
+ /^hop-top-kit[ \t]*=/ {
146
+ f = 1; v = $0; sub(/^[^=]*=[ \t]*/, "", v)
147
+ if (v ~ /^"/) { sub(/^"/, "", v); sub(/".*/, "", v) }
148
+ else if (match(v, /version[ \t]*=[ \t]*"[^"]*"/)) {
149
+ v = substr(v, RSTART, RLENGTH); sub(/^[^"]*"/, "", v); sub(/"$/, "", v)
150
+ } else v = ""
151
+ print v; exit
152
+ }
153
+ END { if (!f) print "absent" }' "$1"
154
+ }
155
+
156
+ check go go.mod gomod
157
+ check ts package.json package
158
+ check py pyproject.toml python
159
+ for req in "$dir"/requirements*.txt; do
160
+ [ -f "$req" ] || continue
161
+ check py "${req##*/}" python "$req"
162
+ done
163
+ check py uv.lock uvlock
164
+ check rs Cargo.toml cargo
165
+ check php composer.json composer
166
+
167
+ [ "$found" -eq 1 ] || echo "detect-port: no kit-relevant manifest in $dir" >&2
168
+ exit 0
package/src/index.test.ts CHANGED
@@ -53,11 +53,51 @@ describe('exports map contract', () => {
53
53
  });
54
54
  });
55
55
 
56
+ describe('documented subpaths', () => {
57
+ const docs = ['README.md', '../../docs/adopters/reference/ts-api-reference.md'];
58
+
59
+ it.each(docs)('%s names only subpaths the exports map declares', (doc) => {
60
+ const text = readFileSync(join(pkgDir, doc), 'utf8');
61
+ const named = new Set(
62
+ [...text.matchAll(/@hop-top\/kit\/([a-z][a-z0-9/-]*[a-z0-9])/g)]
63
+ // `upgrade/drivers/{a,b}` is brace shorthand, not a subpath.
64
+ .filter((m) => !text.startsWith('/{', m.index + m[0].length))
65
+ .map((m) => `./${m[1]}`),
66
+ );
67
+ expect(named.size).toBeGreaterThan(0);
68
+ for (const sub of named) {
69
+ expect(pkg.exports, `${doc}: ${sub}`).toHaveProperty([sub]);
70
+ }
71
+ });
72
+
73
+ // Adopter-facing modules (README, API reference, capability parity page).
74
+ it.each(['uri', 'wizard', 'bus'])('%s is importable as a subpath', (name) => {
75
+ expect(pkg.exports).toHaveProperty([`./${name}`]);
76
+ });
77
+
78
+ // Documented as internal: router would load hono from the root import; triton is only router's transport.
79
+ it.each(['router', 'triton'])('%s is intentionally not exported', (name) => {
80
+ expect(pkg.exports).not.toHaveProperty([`./${name}`]);
81
+ });
82
+
83
+ it.each(docs)('%s never presents router or triton as importable', (doc) => {
84
+ const text = readFileSync(join(pkgDir, doc), 'utf8');
85
+ expect(text).not.toMatch(/@hop-top\/kit\/(router|triton)\b/);
86
+ });
87
+
88
+ // Plumbing behind the cli factory: its public names are re-exported from `./cli`.
89
+ it.each(['delegation', 'sideeffect', 'policy'])('%s stays internal (reached through ./cli)', (name) => {
90
+ expect(pkg.exports).not.toHaveProperty([`./${name}`]);
91
+ });
92
+ });
93
+
56
94
  describe('root barrel', () => {
57
- it('re-exports every public subpath except sqlstore as a namespace', () => {
95
+ it('re-exports every public subpath except sqlstore and the upgrade drivers as a namespace', () => {
58
96
  // Kebab-case subpaths become camelCase namespaces (completion-values -> completionValues).
59
97
  const expected = Object.keys(pkg.exports)
60
- .filter((p) => p !== '.' && p !== './sqlstore')
98
+ // Driver subpaths (`upgrade/drivers/<name>`) are opt-in entries (a caller-provided
99
+ // client, or a native or heavy module); they are nested, so they have no namespace.
100
+ .filter((p) => p !== '.' && p !== './sqlstore' && !p.startsWith('./upgrade/drivers/'))
61
101
  .map((p) => p.replace(/^\.\//, '').replace(/-([a-z])/g, (_, c: string) => c.toUpperCase()));
62
102
  for (const name of expected) {
63
103
  expect(kit, name).toHaveProperty(name);
@@ -68,4 +108,10 @@ describe('root barrel', () => {
68
108
  it('does not eagerly expose sqlstore (native deps stay behind the subpath)', () => {
69
109
  expect(kit).not.toHaveProperty('sqlstore');
70
110
  });
111
+
112
+ it('does not expose the upgrade drivers (better-sqlite3 and tar stay behind their subpaths)', () => {
113
+ expect(kit.upgrade).not.toHaveProperty('SqliteDriver');
114
+ expect(kit.upgrade).not.toHaveProperty('FsDirDriver');
115
+ expect(kit.upgrade).not.toHaveProperty('ConfigFileDriver');
116
+ });
71
117
  });
package/src/index.ts CHANGED
@@ -11,6 +11,8 @@
11
11
  * `sqlstore` is intentionally NOT re-exported here: an eager re-export
12
12
  * would load better-sqlite3 native bindings on every bare import of the
13
13
  * package. Use the dedicated subpath instead: `@hop-top/kit/sqlstore`.
14
+ * The upgrade drivers (`@hop-top/kit/upgrade/drivers/{configfile,fsdir,sqlite}`)
15
+ * stay out for the same reason: `sqlite` loads better-sqlite3, `fsdir` loads `tar`.
14
16
  */
15
17
 
16
18
  export * as aim from './aim.js';
@@ -18,6 +20,7 @@ export * as alias from './alias.js';
18
20
  export * as anthropic from './llm-anthropic.js';
19
21
  export * as api from './api.js';
20
22
  export * as auth from './auth.js';
23
+ export * as bus from './bus.js';
21
24
  export * as cli from './cli.js';
22
25
  export * as completion from './completion.js';
23
26
  export * as completionValues from './completion-values.js';
@@ -42,5 +45,7 @@ export * as stream from './stream.js';
42
45
  export * as telemetry from './telemetry/index.js';
43
46
  export * as toolspec from './toolspec.js';
44
47
  export * as tui from './tui/index.js';
45
- export * as upgrade from './upgrade.js';
48
+ export * as upgrade from './upgrade/index.js';
49
+ export * as uri from './uri.js';
50
+ export * as wizard from './wizard.js';
46
51
  export * as xdg from './xdg.js';
@@ -49,6 +49,8 @@ import {
49
49
  type Usage,
50
50
  } from "./llm";
51
51
  import { AnthropicAdapter } from "./llm-anthropic";
52
+ // Registers the openai-family schemes the key_endpoint vectors name.
53
+ import "./llm-openai";
52
54
  import {
53
55
  fakeServer,
54
56
  isolateEnv,
@@ -373,6 +375,11 @@ describe("llm-v1 conformance: key_endpoint", () => {
373
375
  it(v.name, () => {
374
376
  strictKeys(v, ["name", "op", "uri", "yaml", "env", "want_uri", "refused"], v.name);
375
377
  useLLMYaml(v.yaml);
378
+ // Whatever a vector sets is cleared first and restored after, so
379
+ // a variable outside the isolated list (api_key_env names) never
380
+ // leaks between vectors.
381
+ const restoreVec = isolateEnv(Object.keys(v.env));
382
+ cleanups.push(restoreVec);
376
383
  Object.assign(process.env, v.env);
377
384
  let got: string | undefined;
378
385
  let err: unknown;
@@ -0,0 +1,260 @@
1
+ /**
2
+ * A scheme declaring keyBoundToDefault keeps its ambient key (provider
3
+ * variable, LLM_API_KEY) for its default endpoint; a custom endpoint,
4
+ * loopback included, gets only a key set for it. Go `llm`
5
+ * (boundkey_test.go) is canonical; the llm-v1 key_endpoint vectors pin
6
+ * the shared cases.
7
+ */
8
+
9
+ import { mkdirSync, writeFileSync } from "node:fs";
10
+ import { join } from "node:path";
11
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
12
+
13
+ import {
14
+ KeyEndpointError,
15
+ applyAPIKey,
16
+ createLLM,
17
+ loadConfig,
18
+ register,
19
+ type Provider,
20
+ } from "./llm";
21
+ import { OPENAI_SCHEMES } from "./llm-openai";
22
+ import { declarationOf } from "./llm-endpoint";
23
+ import { fakeServer, isolateEnv, type FakeServer } from "../test/llm/conformance-helpers";
24
+
25
+ const HOSTED = "fake-bound-hosted-key-must-not-leak";
26
+ const OWN = "fake-bound-endpoint-key";
27
+ const ENV = [
28
+ "LLM_API_KEY", "LLM_BASE_URL", "LLM_PROVIDER", "LLM_FALLBACK",
29
+ "BOUNDKEY_API_KEY", "PLAINKEY_API_KEY", "MY_COMPAT_KEY",
30
+ "OPENAI_API_KEY", "OPENROUTER_API_KEY", "LMSTUDIO_API_KEY",
31
+ ];
32
+
33
+ let restoreEnv: () => void;
34
+ const servers: FakeServer[] = [];
35
+
36
+ function stub(): Provider {
37
+ return { close: () => undefined };
38
+ }
39
+
40
+ // Registered once: the openai schemes register on import and must stay.
41
+ // boundkey keeps its hosted key (BOUNDKEY_API_KEY, LLM_API_KEY) for its
42
+ // default endpoint; plainkey, declared alike but not bound, does not.
43
+ register("boundkey", stub, {
44
+ baseURL: "https://api.boundkey.test/v1",
45
+ keyBoundToDefault: true,
46
+ });
47
+ register("plainkey", stub, { baseURL: "https://api.plainkey.test/v1" });
48
+ register("unbound", stub);
49
+
50
+ beforeEach(() => {
51
+ restoreEnv = isolateEnv(ENV);
52
+ });
53
+ afterEach(async () => {
54
+ restoreEnv();
55
+ writeYaml("");
56
+ await Promise.all(servers.splice(0).map((s) => s.close()));
57
+ });
58
+
59
+ function writeYaml(yaml: string): void {
60
+ const dir = join(process.env["XDG_CONFIG_HOME"]!, "hop");
61
+ mkdirSync(dir, { recursive: true });
62
+ writeFileSync(join(dir, "llm.yaml"), yaml);
63
+ }
64
+
65
+ function setup(yaml: string): void {
66
+ writeYaml(yaml);
67
+ process.env["BOUNDKEY_API_KEY"] = HOSTED;
68
+ process.env["PLAINKEY_API_KEY"] = HOSTED;
69
+ process.env["MY_COMPAT_KEY"] = OWN;
70
+ process.env["LLM_API_KEY"] = HOSTED;
71
+ }
72
+
73
+ describe("hosted key only on the default endpoint", () => {
74
+ const cases: { name: string; yaml?: string; envBase?: string; uri: string; want?: string }[] = [
75
+ { name: "no endpoint", uri: "boundkey://m", want: HOSTED },
76
+ { name: "default as base_url", uri: "boundkey://m?base_url=https://api.boundkey.test/v1", want: HOSTED },
77
+ { name: "same origin, other path", uri: "boundkey://m?base_url=https://API.boundkey.test:443/other", want: HOSTED },
78
+ { name: "LLM_BASE_URL same origin", envBase: "https://api.boundkey.test", uri: "boundkey://m", want: HOSTED },
79
+ {
80
+ name: "llm.yaml base_url same origin",
81
+ yaml: "providers:\n boundkey:\n base_url: https://api.boundkey.test/v1\n",
82
+ uri: "boundkey://m",
83
+ want: HOSTED,
84
+ },
85
+
86
+ { name: "URI base_url loopback", uri: "boundkey://m?base_url=http://127.0.0.1:9/v1" },
87
+ { name: "URI host loopback", uri: "boundkey://localhost:8000/m" },
88
+ { name: "LLM_BASE_URL loopback", envBase: "http://127.0.0.1:9/v1", uri: "boundkey://m" },
89
+ {
90
+ name: "llm.yaml base_url loopback",
91
+ yaml: "providers:\n boundkey:\n base_url: http://127.0.0.1:9/v1\n",
92
+ uri: "boundkey://m",
93
+ },
94
+ {
95
+ name: "llm.yaml base_url remote",
96
+ yaml: "providers:\n boundkey:\n base_url: https://llm.corp.test/v1\n",
97
+ uri: "boundkey://m",
98
+ },
99
+ { name: "URI base_url remote https", uri: "boundkey://m?base_url=https://llm.corp.test/v1" },
100
+ { name: "unparseable base_url is custom", uri: "boundkey://m?base_url=nonsense" },
101
+
102
+ {
103
+ name: "api_key_env on custom endpoint",
104
+ yaml: "providers:\n boundkey:\n api_key_env: MY_COMPAT_KEY\n",
105
+ uri: "boundkey://m?base_url=http://127.0.0.1:9/v1",
106
+ want: OWN,
107
+ },
108
+ {
109
+ name: "llm.yaml api_key on custom endpoint",
110
+ yaml: `providers:\n boundkey:\n api_key: ${OWN}\n`,
111
+ uri: "boundkey://m?base_url=http://127.0.0.1:9/v1",
112
+ want: OWN,
113
+ },
114
+
115
+ { name: "non-bound scheme, loopback base_url", uri: "plainkey://m?base_url=http://127.0.0.1:9/v1", want: HOSTED },
116
+ { name: "non-bound scheme, LLM_BASE_URL", envBase: "http://127.0.0.1:9/v1", uri: "plainkey://m", want: HOSTED },
117
+ ];
118
+ for (const tc of cases) {
119
+ it(tc.name, () => {
120
+ setup(tc.yaml ?? "");
121
+ if (tc.envBase) process.env["LLM_BASE_URL"] = tc.envBase;
122
+ // "nonsense" is no endpoint a key may go to; it never carries one.
123
+ const cfg = loadConfig(tc.uri);
124
+ expect(cfg.provider.apiKey, "no key for a custom endpoint is no error").toBe(tc.want);
125
+
126
+ const got = applyAPIKey(tc.uri);
127
+ if (tc.want === undefined) expect(got).toBe(tc.uri);
128
+ else expect(got).toContain(`api_key=${tc.want}`);
129
+ expect(got).not.toContain(`${HOSTED}&`);
130
+ });
131
+ }
132
+
133
+ it("a key in the URI outranks everything on a custom endpoint", () => {
134
+ setup("");
135
+ const uri = `boundkey://m?api_key=${OWN}&base_url=http://127.0.0.1:9/v1`;
136
+ expect(applyAPIKey(uri)).toBe(uri);
137
+ expect(loadConfig(uri).provider.apiKey).toBe(OWN);
138
+ });
139
+
140
+ it("a key set for a custom endpoint still obeys the endpoint guard", () => {
141
+ setup(`providers:\n boundkey:\n api_key: ${OWN}\n`);
142
+ expect(() => loadConfig("boundkey://m?base_url=https://llm.corp.test/v1")).toThrow(
143
+ KeyEndpointError
144
+ );
145
+ });
146
+
147
+ it("a scheme with no declaration is never bound", () => {
148
+ setup("");
149
+ expect(loadConfig("unbound://m?base_url=http://127.0.0.1:9/v1").provider.apiKey).toBe(HOSTED);
150
+ });
151
+ });
152
+
153
+ describe("the openai-family schemes are bound to their default endpoints", () => {
154
+ const DEFAULTS: Record<string, string> = {
155
+ openai: "https://api.openai.com/v1",
156
+ openrouter: "https://openrouter.ai/api/v1",
157
+ xai: "https://api.x.ai/v1",
158
+ lmstudio: "http://localhost:1234/v1",
159
+ groq: "https://api.groq.com/openai/v1",
160
+ together: "https://api.together.xyz/v1",
161
+ fireworks: "https://api.fireworks.ai/inference/v1",
162
+ deepseek: "https://api.deepseek.com",
163
+ mistral: "https://api.mistral.ai/v1",
164
+ };
165
+
166
+ it("declares each scheme bound, with Go's default endpoint", () => {
167
+ expect([...OPENAI_SCHEMES].sort()).toEqual(Object.keys(DEFAULTS).sort());
168
+ for (const s of OPENAI_SCHEMES) {
169
+ // The module registered them on import; clearRegistry has not run.
170
+ const d = declarationOf(s);
171
+ expect(d?.keyBoundToDefault, s).toBe(true);
172
+ expect(d?.baseURL, s).toBe(DEFAULTS[s]);
173
+ }
174
+ });
175
+
176
+ it("OPENAI_API_KEY stays off a self-hosted server and on api.openai.com", () => {
177
+ process.env["OPENAI_API_KEY"] = HOSTED;
178
+ process.env["LLM_API_KEY"] = HOSTED;
179
+ expect(loadConfig("openai://m?base_url=http://127.0.0.1:9/v1").provider.apiKey).toBeUndefined();
180
+ expect(loadConfig("openai://localhost:8000/m").provider.apiKey).toBeUndefined();
181
+ expect(loadConfig("openai://m").provider.apiKey).toBe(HOSTED);
182
+ expect(loadConfig("openai://m?base_url=https://api.openai.com/v1").provider.apiKey).toBe(HOSTED);
183
+ process.env["LLM_BASE_URL"] = "http://127.0.0.1:9/v1";
184
+ expect(loadConfig("openai://m").provider.apiKey).toBeUndefined();
185
+ });
186
+
187
+ it("openrouter's own key goes only to openrouter.ai", () => {
188
+ process.env["OPENROUTER_API_KEY"] = HOSTED;
189
+ expect(loadConfig("openrouter://a/b").provider.apiKey).toBe(HOSTED);
190
+ expect(loadConfig("openrouter://a/b?base_url=http://127.0.0.1:9").provider.apiKey).toBeUndefined();
191
+ });
192
+
193
+ it("lmstudio takes no key", () => {
194
+ process.env["LMSTUDIO_API_KEY"] = HOSTED;
195
+ process.env["LLM_API_KEY"] = HOSTED;
196
+ expect(loadConfig("lmstudio://m").provider.apiKey).toBeUndefined();
197
+ });
198
+ });
199
+
200
+ describe("on the wire", () => {
201
+ async function recorder(): Promise<FakeServer> {
202
+ const s = await fakeServer((_h, res) => {
203
+ res.setHeader("content-type", "application/json");
204
+ res.end(JSON.stringify({ choices: [{ message: { role: "assistant", content: "ok" }, finish_reason: "stop" }] }));
205
+ });
206
+ servers.push(s);
207
+ return s;
208
+ }
209
+
210
+ async function call(uri: string): Promise<void> {
211
+ const c = createLLM(uri);
212
+ try {
213
+ await c.complete({ messages: [{ role: "user", content: "hi" }] });
214
+ } finally {
215
+ c.close();
216
+ }
217
+ }
218
+
219
+ it("a self-hosted server gets no Authorization from the hosted key", async () => {
220
+ const srv = await recorder();
221
+ process.env["OPENAI_API_KEY"] = HOSTED;
222
+ process.env["LLM_API_KEY"] = HOSTED;
223
+ await call(`openai://m?base_url=${srv.url}/v1`);
224
+ expect(srv.hits).toHaveLength(1);
225
+ expect(srv.hits[0]!.headers["authorization"]).toBeUndefined();
226
+ });
227
+
228
+ it("LLM_BASE_URL does not redirect the hosted key either", async () => {
229
+ const srv = await recorder();
230
+ process.env["OPENAI_API_KEY"] = HOSTED;
231
+ process.env["LLM_BASE_URL"] = `${srv.url}/v1`;
232
+ await call("openai://m");
233
+ expect(srv.hits).toHaveLength(1);
234
+ expect(srv.hits[0]!.headers["authorization"]).toBeUndefined();
235
+ });
236
+
237
+ it("the URI's own key reaches it", async () => {
238
+ const srv = await recorder();
239
+ process.env["OPENAI_API_KEY"] = HOSTED;
240
+ await call(`openai://m?api_key=${OWN}&base_url=${srv.url}/v1`);
241
+ expect(srv.hits[0]!.headers["authorization"]).toBe(`Bearer ${OWN}`);
242
+ });
243
+
244
+ it("llm.yaml api_key_env reaches it", async () => {
245
+ const srv = await recorder();
246
+ process.env["OPENAI_API_KEY"] = HOSTED;
247
+ process.env["MY_COMPAT_KEY"] = OWN;
248
+ writeYaml("providers:\n openai:\n api_key_env: MY_COMPAT_KEY\n");
249
+ await call(`openai://m?base_url=${srv.url}/v1`);
250
+ expect(srv.hits[0]!.headers["authorization"]).toBe(`Bearer ${OWN}`);
251
+ });
252
+
253
+ it("llm.yaml api_key reaches it", async () => {
254
+ const srv = await recorder();
255
+ process.env["OPENAI_API_KEY"] = HOSTED;
256
+ writeYaml(`providers:\n openai:\n api_key: ${OWN}\n`);
257
+ await call(`openai://m?base_url=${srv.url}/v1`);
258
+ expect(srv.hits[0]!.headers["authorization"]).toBe(`Bearer ${OWN}`);
259
+ });
260
+ });
@@ -214,7 +214,7 @@ describe("local runtimes' keys", () => {
214
214
 
215
215
  describe("hermetic", () => {
216
216
  it("loadConfig reads no LLM_* variable", () => {
217
- process.env["LLM_PROVIDER"] = "openai://ambient";
217
+ process.env["LLM_PROVIDER"] = "anthropic://ambient";
218
218
  process.env["LLM_FALLBACK"] = "openai://fb";
219
219
  process.env["LLM_API_KEY"] = "env-key";
220
220
  process.env["LLM_BASE_URL"] = "https://gw.corp.test";
@@ -217,11 +217,9 @@ describe("applyAPIKey", () => {
217
217
  );
218
218
  });
219
219
 
220
- it("refuses a key a URI cannot carry", () => {
220
+ it("carries a key holding separators escaped", () => {
221
221
  process.env["KITA_API_KEY"] = "k&x";
222
- expect(() => applyAPIKey("kita://m")).toThrow(
223
- "llm: kita API key contains a character a provider URI cannot carry (& ? #)"
224
- );
222
+ expect(applyAPIKey("kita://m")).toBe("kita://m?api_key=k%26x");
225
223
  });
226
224
 
227
225
  it("never quotes its input on a parse error", () => {
package/src/llm-config.ts CHANGED
@@ -36,7 +36,11 @@ export interface LoadOptions {
36
36
  * variables (`<SCHEME>_API_KEY` unless its adapter declares others);
37
37
  * `LLM_API_KEY` for a registered scheme that requires a key. Blank is
38
38
  * unset everywhere; a blank `api_key` param is dropped. Found
39
- * nowhere, it is left unset: the adapter reports it.
39
+ * nowhere, it is left unset: the adapter reports it. A scheme
40
+ * declaring `keyBoundToDefault` (the openai family) lends the last
41
+ * two only on its default endpoint: on any other, only the URI's
42
+ * `api_key`, llm.yaml `api_key` and `api_key_env` apply, and no key
43
+ * is no error.
40
44
  * - baseURL: the URI's `base_url`; its host (`http://host:port`);
41
45
  * `LLM_BASE_URL`; llm.yaml `base_url`.
42
46
  * - model: the URI's; llm.yaml `model`. extras: the block's other keys.