@volter/twin-tunnel 0.1.36 → 1.0.0

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 (63) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +11 -121
  3. package/dist/generated/pack-facts.json +54 -0
  4. package/dist/spec/SOURCE.md +14 -0
  5. package/dist/spec/openapi.json +18 -0
  6. package/dist/src/cli.js +15 -53
  7. package/dist/src/fetch.d.ts +2 -0
  8. package/dist/src/fetch.js +19 -0
  9. package/dist/src/generated/surface.gen.json +1 -0
  10. package/dist/src/generated/ui.gen.json +1 -0
  11. package/dist/src/index.d.ts +5 -7
  12. package/dist/src/index.js +8 -42
  13. package/dist/src/manifest.d.ts +2 -0
  14. package/dist/src/manifest.js +42 -0
  15. package/dist/src/semantics/around.d.ts +2 -0
  16. package/dist/src/semantics/around.js +39 -0
  17. package/dist/src/semantics/doors.d.ts +3 -0
  18. package/dist/src/semantics/doors.js +18 -0
  19. package/dist/src/semantics/index.d.ts +2 -0
  20. package/dist/src/semantics/index.js +1 -0
  21. package/dist/src/semantics/shared.d.ts +17 -0
  22. package/dist/src/semantics/shared.js +15 -0
  23. package/dist/src/semantics/sockets.d.ts +2 -0
  24. package/dist/src/semantics/sockets.js +80 -0
  25. package/dist/src/semantics/states.d.ts +1 -0
  26. package/dist/src/semantics/states.js +3 -0
  27. package/dist/src/server.d.ts +7 -0
  28. package/dist/src/server.js +9 -0
  29. package/generated/pack-facts.json +54 -0
  30. package/package.json +16 -32
  31. package/spec/SOURCE.md +14 -0
  32. package/spec/openapi.json +18 -0
  33. package/src/cli.ts +15 -41
  34. package/src/fetch.ts +20 -0
  35. package/src/generated/surface.gen.json +1 -0
  36. package/src/generated/ui.gen.json +1 -0
  37. package/src/index.ts +9 -52
  38. package/src/manifest.ts +47 -0
  39. package/src/semantics/around.ts +41 -0
  40. package/src/semantics/doors.ts +21 -0
  41. package/src/semantics/index.ts +6 -0
  42. package/src/semantics/shared.ts +26 -0
  43. package/src/semantics/sockets.ts +69 -0
  44. package/src/semantics/states.ts +3 -0
  45. package/src/server.ts +10 -0
  46. package/dist/src/tunnel-budget.d.ts +0 -21
  47. package/dist/src/tunnel-budget.js +0 -26
  48. package/dist/src/tunnel-capabilities.d.ts +0 -4
  49. package/dist/src/tunnel-capabilities.js +0 -2091
  50. package/dist/src/tunnel-conformance.d.ts +0 -10
  51. package/dist/src/tunnel-conformance.js +0 -63
  52. package/dist/src/tunnel-connector.d.ts +0 -21
  53. package/dist/src/tunnel-connector.js +0 -68
  54. package/dist/src/tunnel-server.d.ts +0 -109
  55. package/dist/src/tunnel-server.js +0 -1197
  56. package/dist/src/tunnel-twin.d.ts +0 -175
  57. package/dist/src/tunnel-twin.js +0 -236
  58. package/src/tunnel-budget.ts +0 -34
  59. package/src/tunnel-capabilities.ts +0 -1770
  60. package/src/tunnel-conformance.ts +0 -62
  61. package/src/tunnel-connector.ts +0 -64
  62. package/src/tunnel-server.ts +0 -1194
  63. package/src/tunnel-twin.ts +0 -339
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,123 +1,13 @@
1
1
  # @volter/twin-tunnel
2
2
 
3
- > **Legacy connector helpers:** this package still has callable helpers using the retired v1
4
- > `syncPull` API. Those paths require migration before use on the current kernel;
5
- > older helper descriptions below do not establish current compatibility. Check the
6
- > [generated index](../../../generated/INDEX.md) for protocol standing and use the
7
- > [shared model](../../../docs/concepts/the-model.md) for current state semantics.
8
-
9
- A local twin of two tunnel surfaces used by Volter worlds:
10
-
11
- - Cloudflare Quick Tunnel allocation (`POST /tunnel`) using the first-party `cloudflared`
12
- quick-service field envelope. Generated field values are independent twin-local facts; the twin
13
- does not assert undocumented relationships among `id`, `name`, `hostname`, or `account_tag`.
14
- - The owned `@volter/tunnel` WebSocket control protocol and HTTP relay path.
15
-
16
- The boundary is deliberate. The control plane is twinned; payload transport is real loopback
17
- HTTP. `world-tunnel quick --url ...` prints the machine-readable
18
- `VOLTER_SHARE_URL=http://127.0.0.1:...` handshake and genuinely forwards through that loopback
19
- ingress. It does not claim Cloudflare edge QUIC, public DNS, TLS, reachability, or an SLA. Those
20
- remain real deployment concerns. `quick --url` accepts a credential-free loopback HTTP(S) origin
21
- only; path/query/fragment and backslash-normalized inputs are rejected rather than silently
22
- discarded while forwarding.
23
-
24
- ```bash
25
- # Local share rehearsal used by world cookbooks
26
- world-tunnel quick --url http://127.0.0.1:3000
27
-
28
- # Standalone quick API + Volter relay
29
- world-tunnel serve --port 8787 --root .volter/world/tunnel
30
- world-tunnel conformance
31
- # Cloudflare control URL: http://127.0.0.1:8787/tunnel
32
- # @volter/tunnel host: http://127.0.0.1:8787
33
- ```
34
-
35
- An unmodified `@volter/tunnel` client registers against the `serve` URL and forwards requests to
36
- its configured local port. Its normal default (`authRequired: true`) is preserved: anonymous
37
- requests receive 401, and the server's `mintToken(tunnelId)` helper creates a fake-local,
38
- tunnel-bound HS256 token for Bearer/query/cookie rehearsal. Matching the owned relay default, a
39
- valid signed token without `tid` is shared SSO while a present `tid` must match; start `serve` with
40
- `--require-tid` to select the owned `REQUIRE_TID=true` policy. Basic-auth values remain only in the
41
- live socket session; the append-only kernel stores a SHA-256 digest and configured bit, never the
42
- plaintext. As upstream does, Basic auth is configured only when both user and password are
43
- non-empty; an SDK-emitted empty value leaves that gate disabled. The twin accepts any non-empty
44
- fake relay credential and rejects a missing one.
45
-
46
- **Browser WebSockets relay for real.** A `ws://<relay>/__twin/tunnels/<id>/<path>` upgrade passes
47
- the same Basic/JWT gates the HTTP path does, then bridges: the relay sends `ws-upgrade` with a
48
- fresh `connId`, the tunnelled path and the browser’s own handshake headers; the client answers
49
- `ws-ready` (or `ws-error`, which closes the browser socket with 1011 and the client’s own reason);
50
- `ws-message` carries base64 payloads with the `binary` flag in both directions; `ws-close` bridges
51
- either way with the vendor’s own code clamping. Frames a browser sends before `ws-ready` are
52
- QUEUED and delivered in order rather than dropped, a control socket may only drive the `connId`s
53
- it owns, and a control socket closing takes its bridges with it. `request-abort` is now sent from
54
- ONE place for every way a request can end badly — timeout, visitor hang-up, malformed frame, owner
55
- disconnect — so the client always stops producing for a request the relay has forgotten.
56
-
57
- Still explicit capability todos: reliable end-to-end incremental delivery and its
58
- backpressure/cancellation (see "the streaming trade" below), account/reservation management,
59
- usage metering, inspector/replay, and Cloudflare managed tunnels.
60
-
61
- There is no UI mirror. Both products' relevant surface is a CLI/control protocol; their hosted
62
- dashboards are incidental account and operations tooling, not an agent navigation target.
63
-
64
- ## Coverage
65
-
66
- The capability manifest in `src/tunnel-capabilities.ts` is the honest denominator for both the
67
- Cloudflare Quick Tunnel allocation surface and the owned Volter relay. Run
68
- `bun scripts/twin-capabilities.ts tunnel` for the current counts. Every capability is classified
69
- as done or planned; nothing disappears behind a broad feature label.
70
-
71
- ### Done (proven, verifiable)
72
-
73
- - Cloudflare Quick Tunnel allocation envelope, unique ephemeral allocations, persistence,
74
- read-only refusal, and bounded reserved-route/loopback-origin handling.
75
- - Real loopback forwarding through both the quick adapter and the owned relay, including method,
76
- path, body, status, the owned cache/privacy response-header rules, CORS preflight,
77
- malformed-frame containment, and single durable/live ownership under overlapping claims.
78
- - Relay registration, replacement, disconnect, authentication, JWT bootstrap/cookie behavior,
79
- session-only Basic-auth plaintext, persistence ordering, and live status.
80
- - An authoritative 15-discriminator census imported from `@volter/tunnel-core`, with one explicit
81
- capability row per frame; implemented frames have transport proofs and unimplemented frames
82
- remain planned. Fourteen of the fifteen now carry transport proofs — everything but `quota` —
83
- driven over a genuine loopback WebSocket against a real local server, with the pretend client
84
- a harness shaped after the owned client's `handleWsUpgrade` — it dials with the offered
85
- subprotocols, strips the hop-by-hop handshake headers, and reports a real local failure as
86
- `ws-error`; it does not reproduce the client's `x-forwarded-*` re-stamping, its 15s dial
87
- timeout or `safeClose`'s teardown, none of which any assertion depends on.
88
- - Visitor-disconnect abort: a browser hang-up before `response-start` sends `request-abort`, and
89
- the request is genuinely FORGOTTEN — a late response frame naming it is refused.
90
- - Read-only connector pull, mapping, idempotence, refusal-state survival, conformance, and the
91
- fail-closed persistent live-call budget.
92
-
93
- ### The streaming trade, measured
94
-
95
- The relay BUFFERS a streamed response to `response-end` before answering the visitor, and that is
96
- a measured choice rather than an unfinished one. On this runtime a response body that has begun
97
- cannot be failed THROUGH `Bun.serve`'s response surface: erroring the `ReadableStream` behind a
98
- `Response` ends the chunked body cleanly,
99
- so a visitor reads a truncated payload as a successful 200 and cannot tell it from a complete one
100
- — and a `content-length` that would have made the truncation detectable is dropped the moment the
101
- body is a stream. `node:http` on the SAME runtime CAN signal it (`src/tunnel-stream-boundary.test.ts`
102
- measures that too) — so this is a trade with a named alternative, not an impossibility: re-hosting
103
- the HTTP plane would mean giving up `server.upgrade`, which the entire WebSocket bridge is built
104
- on. The first two measurements go RED the day `Bun.serve` gains the ability; that is the signal to build
105
- `tunnel.volter.http.streaming`, `…stream_backpressure` and `…stream_cancel_abort` and revisit the
106
- trade. Committing the head today would buy latency and sell the ability to fail a response
107
- honestly — which is what keeps the malformed-sequence 502 reachable at all.
108
- `stream_backpressure` has a second, independent blocker: the owned protocol's fifteen
109
- discriminators contain no pause frame, so a relay cannot ask a client to slow down.
110
-
111
- ### Planned (todo — covered by default, not yet built)
112
-
113
- - Reliable incremental streaming, backpressure and cancellation (blocked as above).
114
- - Reconnect/backoff, quota frames, forwarded/response-header rules, rate limiting, and
115
- constant-time shared-secret comparison.
116
- - Managed tunnel/account/reservation/usage/signup/inspector surfaces and confirmed public push.
117
- - Cloudflare Quick Tunnel concurrency and SSE limitations, plus Cloudflare managed tunnels.
118
-
119
- ### No UI mirror
120
-
121
- The modeled products expose a CLI, HTTP API, and WebSocket control protocol. Their hosted account
122
- dashboards are operations tooling rather than an agent workflow, so this package deliberately has
123
- no React mirror and no UI capabilities. Coverage is API + connector.
3
+ The tunnel relay twin (Protocol 3): Volter's volter-tunnel relay as Volter Harness's remote access uses it
4
+ ([journeys/demand.json](./journeys/demand.json)). A client opens the control socket (`/ws?id=<tunnelId>`) and
5
+ registers with its account's token; it is told its tunnel's URL (`https://<tunnelId>.voltertest.xyz`). A request to
6
+ that host (or `?__tunnel=<id>` on the relay's direct host) is sent down the socket as a `request` frame and answered with
7
+ what the client sends back: a whole `response`, or `response-start`, `response-chunk`s and `response-end` (the kernel's
8
+ request answered by a session). No client holding the tunnel is 502 "Tunnel not connected"; no answer in 30 s is 504; a
9
+ body over 750000 bytes is 413. A second registration of a live id needs `replace` (the first is closed 4001); another
10
+ account's id and a bad token are refused. Browser WebSocket bridging, quotas and the inspector are not served.
11
+
12
+ The World's door: `POST /_twin/accounts` ({ slug }: an account and its token). The credential door answers TUNNEL_SECRET
13
+ and the relay URL (TUNNEL_SERVER_URL, SUPERCODE_TUNNEL_SERVER_URL).
@@ -0,0 +1,54 @@
1
+ {
2
+ "//": "GENERATED by scripts/pack-facts.ts — current pack descriptors and explicit world-runtime server backings; no prior-artifact entries are retained.",
3
+ "packs": {
4
+ "tunnel": {
5
+ "adoption": {
6
+ "sdks": [
7
+ "@volter/tunnel"
8
+ ],
9
+ "envStems": [
10
+ "TUNNEL",
11
+ "VOLTERTUNNEL"
12
+ ]
13
+ },
14
+ "hosts": [
15
+ {
16
+ "host": "voltertest.xyz"
17
+ },
18
+ {
19
+ "suffix": ".voltertest.xyz"
20
+ },
21
+ {
22
+ "host": "www.voltertest.xyz",
23
+ "exclude": true
24
+ },
25
+ {
26
+ "host": "twins.voltertest.xyz",
27
+ "exclude": true
28
+ }
29
+ ],
30
+ "archetype": "proxy",
31
+ "protocol": {
32
+ "declared": "3",
33
+ "major": 3,
34
+ "standing": "current"
35
+ },
36
+ "transport": "rest",
37
+ "resources": [],
38
+ "endpointEnvNone": "the relay URL is the credential door's (TUNNEL_SERVER_URL, SUPERCODE_TUNNEL_SERVER_URL), the World claiming voltertest.xyz",
39
+ "credentialDoor": {
40
+ "path": "/_twin/accounts",
41
+ "body": {
42
+ "slug": "world"
43
+ },
44
+ "fill": {
45
+ "TUNNEL_SECRET": "token",
46
+ "TUNNEL_SERVER_URL": "server",
47
+ "SUPERCODE_TUNNEL_SERVER_URL": "server"
48
+ }
49
+ },
50
+ "serveExport": "createTunnelTwinServer"
51
+ }
52
+ },
53
+ "undeclared": []
54
+ }
@@ -0,0 +1,14 @@
1
+ # volter-tunnel relay spec — provenance
2
+
3
+ - **Why this document:** the relay publishes no OpenAPI document. Its contract is volter-ai/volter-tunnel at
4
+ `c14b6e3` (2026-09-28): `packages/core/src/protocol.ts` (the control channel's frames, "the single source of truth
5
+ for the messages exchanged over the control WebSocket between a client and the relay") and the Cloudflare relay,
6
+ `server-cf/src/worker.ts` (routing: the control channel at `/ws?id=<tunnelId>`; a tunnel at `<tunnelId>.<domain>`,
7
+ or `?__tunnel=<id>` on a direct host such as localhost; `/api/status` at the apex) and `server-cf/src/tunnel-do.ts`
8
+ (registration: `registered` with `url: https://<tunnelId>.<domain>`, a rejected credential `{type:"error"}` then
9
+ close 4003, a replaced client closed 4001 "Replaced by new client"; a public request: 502 "Tunnel not connected",
10
+ 504 "Tunnel timeout" after 30 s, 413 over 750000 bytes of body; the reply frames `response`, `response-start`,
11
+ `response-chunk`, `response-end`). The domain is `voltertest.xyz` (`server-cf/wrangler.jsonc`, `TUNNEL_DOMAIN`).
12
+ - **Corrections:** none.
13
+ - **Read by:** the twin orchestrator, 2026-09-30.
14
+ - **Vendored bytes (sha256):** `openapi.json` `b4fcdc3d599026bef687c946cea3c8837c63ff982e5d899df1425e585832aebd`.
@@ -0,0 +1,18 @@
1
+ {
2
+ "openapi": "3.0.2",
3
+ "info": {
4
+ "title": "volter-tunnel relay",
5
+ "version": "2",
6
+ "description": "The volter-tunnel relay's HTTP surface at its apex: its status. A client's control channel (a WebSocket at /ws?id=<tunnelId>) and the public requests it answers (every path of <tunnelId>.<domain>) are the relay's protocol, recorded in spec/SOURCE.md. Written from volter-ai/volter-tunnel (spec/SOURCE.md)."
7
+ },
8
+ "servers": [{ "url": "https://voltertest.xyz" }],
9
+ "paths": {
10
+ "/api/status": {
11
+ "get": {
12
+ "operationId": "getStatus",
13
+ "summary": "The relay's status.",
14
+ "responses": { "200": { "description": "The relay is up.", "content": { "application/json": { "schema": { "type": "object", "properties": { "ok": { "type": "boolean" }, "relay": { "type": "string", "example": "cloudflare-do" } } } } } } }
15
+ }
16
+ }
17
+ }
18
+ }
package/dist/src/cli.js CHANGED
@@ -1,59 +1,21 @@
1
1
  #!/usr/bin/env node
2
- import { keepProcessAlive } from '@volter/world-core/lifecycle';
2
+ // world-tunnel: serve the tunnel twin.
3
3
  import { hasFlag, optionValue } from '@volter/world-core/args';
4
- import { createTunnelTwinServer, parseTunnelLoopbackOrigin } from "./tunnel-server.js";
5
- const [command, ...args] = process.argv.slice(2);
6
- const rawPort = optionValue(args, '--port');
7
- const port = rawPort === undefined ? undefined : Number(rawPort);
8
- if (port !== undefined && (!Number.isInteger(port) || port < 0 || port > 65535)) {
9
- process.stderr.write(`world-tunnel: --port must be an integer 0-65535 (got ${JSON.stringify(rawPort)})\n`);
10
- process.exit(2);
11
- }
12
- const root = optionValue(args, '--root') || undefined;
13
- if (command === 'serve') {
14
- const server = createTunnelTwinServer({
15
- ...(port ? { port } : {}),
16
- ...(root ? { root } : {}),
17
- readOnly: hasFlag(args, '--read-only'),
18
- requireTid: hasFlag(args, '--require-tid'),
19
- });
20
- process.stdout.write(`tunnel twin listening on ${server.url}\n`);
21
- process.stdout.write(`Volter SDK host=${server.url}; Cloudflare quick service=${server.url}\n`);
22
- await keepProcessAlive();
23
- }
24
- else if (command === 'quick' || command === 'tunnel') {
25
- const origin = optionValue(args, '--url');
26
- if (!origin) {
27
- process.stderr.write('world-tunnel quick requires --url http://127.0.0.1:<port>\n');
28
- process.exit(2);
29
- }
30
- try {
31
- parseTunnelLoopbackOrigin(origin);
32
- }
33
- catch (error) {
34
- process.stderr.write(`world-tunnel quick: ${error instanceof Error ? error.message : String(error)}\n`);
35
- process.exit(2);
36
- }
37
- const server = createTunnelTwinServer({ ...(port ? { port } : {}), ...(root ? { root } : {}) });
38
- const allocation = await fetch(`${server.url}/tunnel`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}' });
39
- const body = await allocation.json();
40
- if (!allocation.ok || !body.success || !body.result)
41
- throw new Error('quick-tunnel allocation failed');
42
- server.registerQuickOrigin(body.result.id, origin);
43
- // The world runtime discovers the first URL in stdout. This is deliberately a loopback URL:
44
- // the twin proves the control plane and genuine HTTP forwarding, not Cloudflare edge/DNS/TLS.
45
- process.stdout.write(`VOLTER_SHARE_URL=${server.url}\n`);
4
+ import { keepProcessAlive } from '@volter/world-core/lifecycle';
5
+ import { createTunnelTwinServer } from "./server.js";
6
+ const [cmd, ...rest] = process.argv.slice(2);
7
+ const port = Number(optionValue(rest, '--port', '0')) || undefined;
8
+ const root = optionValue(rest, '--root') || undefined;
9
+ const readOnly = hasFlag(rest, '--read-only');
10
+ // the World's managed Postgres, which the runtime binds a pack declaring managedDatabase to
11
+ const database = optionValue(rest, '--database') || undefined;
12
+ // the World's scenario file, for a model vendor's turns
13
+ const scenarioPath = optionValue(rest, '--scenario') || undefined;
14
+ if (cmd === 'serve' || cmd === undefined) {
15
+ const s = await createTunnelTwinServer({ readOnly, ...(root ? { root } : {}), ...(port ? { port } : {}), ...(database ? { database } : {}), ...(scenarioPath ? { scenarioPath } : {}) });
16
+ process.stdout.write(`tunnel twin${readOnly ? ' [read-only]' : ''} at http://127.0.0.1:${s.port}\n`);
46
17
  await keepProcessAlive();
47
18
  }
48
- else if (command === 'conformance') {
49
- // Dev-only and lazy: the runtime entrypoint does not pull conformance into normal serve/share.
50
- const { checkTunnelConformance } = await import("./tunnel-conformance.js");
51
- const report = await checkTunnelConformance({ ...(root ? { root } : {}) });
52
- process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
53
- if (!report.ok)
54
- process.exitCode = 1;
55
- }
56
19
  else {
57
- process.stdout.write('Usage: world-tunnel serve|conformance [--port N] [--root DIR] [--read-only] [--require-tid]\n');
58
- process.stdout.write(' world-tunnel quick --url http://127.0.0.1:<port> [--port N] [--root DIR]\n');
20
+ process.stdout.write('Usage: world-tunnel serve [--port N] [--root DIR] [--read-only] [--database URL] [--scenario FILE]\n');
59
21
  }
@@ -0,0 +1,2 @@
1
+ import { type DerivedFetch, type PackFetchOptions } from '@volter/world-core';
2
+ export declare function createTunnelFetch(options?: PackFetchOptions): DerivedFetch;
@@ -0,0 +1,19 @@
1
+ // GENERATED by scripts/create-pack.ts (--init, --index): a fixed file. The kernel serves the discovery door, the clock,
2
+ // the World's doors, the vendor's screens and the API from the pack's parts (architecture, "The pack contract").
3
+ import { createPackFetch } from '@volter/world-core';
4
+ import surface from './generated/surface.gen.json' with { type: 'json' };
5
+ import { manifest } from "./manifest.js";
6
+ import { around } from "./semantics/around.js";
7
+ import * as sockets from "./semantics/sockets.js";
8
+ import * as doors from "./semantics/doors.js";
9
+ import { tunnelSemantics } from "./semantics/index.js";
10
+ export function createTunnelFetch(options = {}) {
11
+ return createPackFetch({
12
+ manifest,
13
+ surface: surface,
14
+ handlers: tunnelSemantics,
15
+ doors,
16
+ around,
17
+ sockets,
18
+ }, options);
19
+ }
@@ -0,0 +1 @@
1
+ {"generatedBy":"scripts/derive-pack.ts","spec":"openapi.json","format":"openapi","version":"2","resources":[],"operations":[{"id":"getStatus","method":"get","path":"/api/status","pathParams":[],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"computed"}]}
@@ -0,0 +1 @@
1
+ {"generatedBy":"scripts/derive-pack.ts","resources":{"_account":{"actions":[],"states":{},"embeds":{}},"_tunnel":{"actions":[],"states":{},"embeds":{}}}}
@@ -1,7 +1,5 @@
1
- export { createTunnelTwinFetch, createTunnelTwinHandler, createTunnelTwinServer } from './tunnel-server.js';
2
- export { handleTunnelRelayMessage, handleTunnelTwinRequest } from './tunnel-twin.js';
3
- export { liveTunnelExecute, mapTunnelRelay, pullTunnelRelay, syncTunnelFromReal } from './tunnel-connector.js';
4
- export { TunnelBudget, TunnelBudgetError, TUNNEL_RATE_BUDGET, TUNNEL_BUDGET_CEILING, TUNNEL_BUDGET_WINDOW_MS, TUNNEL_CALL_WEIGHTS, } from './tunnel-budget.js';
5
- export type { RelayControlMessage, RelaySession, TunnelRequest, TunnelResponse } from './tunnel-twin.js';
6
- import type { TwinPack } from '@volter/world-core';
7
- export declare const pack: TwinPack;
1
+ import { manifest } from './manifest.js';
2
+ export { createTunnelFetch } from './fetch.js';
3
+ export { createTunnelTwinServer } from './server.js';
4
+ export { manifest };
5
+ export declare const pack: import("@volter/world-core").PackDescriptor;
package/dist/src/index.js CHANGED
@@ -1,42 +1,8 @@
1
- export { createTunnelTwinFetch, createTunnelTwinHandler, createTunnelTwinServer } from "./tunnel-server.js";
2
- export { handleTunnelRelayMessage, handleTunnelTwinRequest } from "./tunnel-twin.js";
3
- export { liveTunnelExecute, mapTunnelRelay, pullTunnelRelay, syncTunnelFromReal } from "./tunnel-connector.js";
4
- export { TunnelBudget, TunnelBudgetError, TUNNEL_RATE_BUDGET, TUNNEL_BUDGET_CEILING, TUNNEL_BUDGET_WINDOW_MS, TUNNEL_CALL_WEIGHTS, } from "./tunnel-budget.js";
5
- import { TUNNEL_RATE_BUDGET as RATE_BUDGET } from "./tunnel-budget.js";
6
- export const pack = {
7
- vendor: 'tunnel',
8
- // The SAME object tunnel-budget.ts declares at module load — one source of truth, so
9
- // registering the pack and importing the connector can never arm two different ceilings.
10
- rateBudget: RATE_BUDGET,
11
- // The CONTROL plane is HTTP/REST (POST /tunnel, GET /api/status). The relay's control link is a
12
- // WebSocket and its data path is real loopback HTTP — neither is a raw line protocol, so this is
13
- // not the `raw-tcp` class; the split is described in the README and spec-sources.json.
14
- transport: 'rest',
15
- archetype: 'proxy',
16
- bin: 'world-tunnel',
17
- // The subject types the twin stores: `quick_tunnel`/`relay_tunnel` written by tunnel-twin.ts,
18
- // and `relay` folded by the connector's status pull (mapTunnelRelay).
19
- resources: ['quick_tunnel', 'relay_tunnel', 'relay'],
20
- specSource: 'No single first-party machine-readable spec spans this combined pack. The Cloudflare Quick Tunnel ' +
21
- 'half is pinned to first-party cloudflared commit 733bfb939963e150dcf5c4faddb1603f744fbc98 (POST ' +
22
- '/tunnel and its {success,result,errors} envelope) plus Cloudflare\'s own Quick Tunnels docs; the ' +
23
- 'owned Volter relay half is pinned to volter-ai/volter-tunnel commit ' +
24
- 'a5abc6287384429d32cde200d8ecd042814e6619 (@volter/tunnel 2.0.5, @volter/tunnel-core\'s 15 control ' +
25
- 'frames). See spec-sources.json.',
26
- description: 'Cloudflare Quick Tunnel control-plane and owned Volter relay twin — POST /tunnel allocation and the ' +
27
- '@volter/tunnel WebSocket control protocol, with a genuine loopback HTTP data path (no Cloudflare ' +
28
- 'edge, DNS, TLS or SLA claimed).',
29
- // INTERCEPTION RULING — hostsNone, the pack's own home for it: no injector entry by design:
30
- // native cloudflared is an external binary, while @volter/tunnel opens a configurable
31
- // WebSocket control channel and the CLI reads TUNNEL_SERVER_URL. Worlds wire that app-read
32
- // endpoint directly; claiming api.trycloudflare.com in the Node injector would not redirect
33
- // cloudflared and would falsely imply the Cloudflare edge data plane was twinned.
34
- hostsNone: "no injector entry by design: native cloudflared is an external binary, while @volter/tunnel opens a configurable WebSocket control channel and the CLI reads TUNNEL_SERVER_URL. Worlds wire that app-read endpoint directly; claiming api.trycloudflare.com in the Node injector would not redirect cloudflared and would falsely imply the Cloudflare edge data plane was twinned",
35
- // Adoption, moved off the central maps unchanged (descriptor-first back-migration, adding-a-twin.md §3,
36
- // 2026-08-31).
37
- adoption: {
38
- // Internal Volter tunnel; the client is `@volter/tunnel` and there is no Python distribution.
39
- pypi: [],
40
- sdks: ['@volter/tunnel'], envStems: ['TUNNEL', 'VOLTERTUNNEL'],
41
- },
42
- };
1
+ // @volter/twin-tunnel — the tunnel twin (Protocol 3). A fixed file: the descriptor is the manifest's.
2
+ import { packOf, registerPack } from '@volter/world-core';
3
+ import { manifest } from "./manifest.js";
4
+ export { createTunnelFetch } from "./fetch.js";
5
+ export { createTunnelTwinServer } from "./server.js";
6
+ export { manifest };
7
+ // The descriptor: twin-world's architecture, "The descriptor"; declared in manifest.ts.
8
+ export const pack = registerPack(packOf(manifest));
@@ -0,0 +1,2 @@
1
+ import type { DerivedManifest } from '@volter/world-core';
2
+ export declare const manifest: DerivedManifest;