super-dsh 0.1.6 → 0.1.9
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.
- package/client/index.js +741 -256
- package/cordis.patch.yml +16 -0
- package/package.json +7 -2
- package/superd-hub/dist/a2a-delivery.d.ts +189 -0
- package/superd-hub/dist/a2a-delivery.js +240 -0
- package/superd-hub/dist/a2a-host.d.ts +76 -0
- package/superd-hub/dist/a2a-host.js +145 -0
- package/superd-hub/dist/a2a-ingest.d.ts +31 -0
- package/superd-hub/dist/a2a-ingest.js +636 -0
- package/superd-hub/dist/a2a-log.d.ts +17 -0
- package/superd-hub/dist/a2a-log.js +42 -0
- package/superd-hub/dist/a2a-row.d.ts +65 -0
- package/superd-hub/dist/a2a-row.js +162 -0
- package/superd-hub/dist/a2a-service.d.ts +357 -0
- package/superd-hub/dist/a2a-service.js +980 -0
- package/superd-hub/dist/a2a-wire.d.ts +220 -0
- package/superd-hub/dist/a2a-wire.js +305 -0
- package/superd-hub/dist/agent-ids.d.ts +10 -0
- package/superd-hub/dist/agent-ids.js +68 -0
- package/superd-hub/dist/agent-roster.d.ts +29 -18
- package/superd-hub/dist/agent-roster.js +54 -15
- package/superd-hub/dist/agent-status.d.ts +119 -0
- package/superd-hub/dist/agent-status.js +386 -0
- package/superd-hub/dist/client/mesh-api.d.ts +134 -0
- package/superd-hub/dist/client/mesh-api.js +219 -0
- package/superd-hub/dist/client/mesh-groups.d.ts +63 -0
- package/superd-hub/dist/client/mesh-groups.js +66 -0
- package/superd-hub/dist/client/roster.d.ts +48 -0
- package/superd-hub/dist/client/roster.js +96 -0
- package/superd-hub/dist/exec-pty-channel.d.ts +58 -0
- package/superd-hub/dist/exec-pty-channel.js +162 -0
- package/superd-hub/dist/exec-pty-framing.d.ts +32 -0
- package/superd-hub/dist/exec-pty-framing.js +81 -0
- package/superd-hub/dist/exec-pty-rpc.d.ts +21 -0
- package/superd-hub/dist/exec-pty-rpc.js +128 -0
- package/superd-hub/dist/exec-pty-session.d.ts +76 -0
- package/superd-hub/dist/exec-pty-session.js +234 -0
- package/superd-hub/dist/exec.d.ts +56 -0
- package/superd-hub/dist/exec.js +225 -0
- package/superd-hub/dist/gateway.d.ts +39 -2
- package/superd-hub/dist/gateway.js +62 -3
- package/superd-hub/dist/hub-tool.d.ts +174 -0
- package/superd-hub/dist/hub-tool.js +464 -0
- package/superd-hub/dist/index.d.ts +15 -1
- package/superd-hub/dist/index.js +16 -0
- package/superd-hub/dist/machines.d.ts +45 -0
- package/superd-hub/dist/machines.js +125 -0
- package/superd-hub/dist/mesh-federate.d.ts +138 -0
- package/superd-hub/dist/mesh-federate.js +223 -0
- package/superd-hub/dist/mesh-gateway.d.ts +67 -0
- package/superd-hub/dist/mesh-gateway.js +408 -0
- package/superd-hub/dist/mesh-link.d.ts +274 -0
- package/superd-hub/dist/mesh-link.js +441 -0
- package/superd-hub/dist/mesh-rpc.d.ts +123 -0
- package/superd-hub/dist/mesh-rpc.js +250 -0
- package/superd-hub/dist/mux-client.d.ts +71 -0
- package/superd-hub/dist/mux-client.js +281 -0
- package/superd-hub/dist/pack-version.d.ts +2 -0
- package/superd-hub/dist/pack-version.js +30 -0
- package/superd-hub/dist/roster.d.ts +6 -0
- package/superd-hub/dist/rpc.d.ts +18 -2
- package/superd-hub/dist/rpc.js +34 -4
- package/superd-hub/dist/spawn-world.js +3 -1
- package/superd-hub/dist/switch-core.d.ts +62 -25
- package/superd-hub/dist/switch-core.js +53 -30
- package/superd-hub/dist/system-head.d.ts +22 -12
- package/superd-hub/dist/system-head.js +100 -84
- package/superd-hub/dist/wire-endpoints.d.ts +264 -0
- package/superd-hub/dist/wire-endpoints.js +180 -0
- package/superd-hub/lib/client/index.js +741 -256
- package/superd-hub/package.json +11 -2
- package/agent-agy/dist/agent-preset-projection.d.ts +0 -31
- package/agent-agy/dist/agent-preset-projection.js +0 -33
- package/agent-claude/dist/agent-preset-projection.js +0 -30
- package/agent-codex/dist/agent-preset-projection.js +0 -37
- package/agent-codex/dist/app-home.js +0 -65
- package/agent-codex/dist/spike.js +0 -46
- package/agent-hermes/dist/agent-preset-projection.js +0 -34
- package/agent-omp/dist/agent-preset-projection.js +0 -36
- package/agent-omp/dist/app-home.js +0 -86
- package/agent-pi/dist/agent-preset-projection.js +0 -29
- package/superd-hub/dist/client-shim.d.ts +0 -28
- package/superd-hub/dist/client-shim.js +0 -251
- package/superd-hub/dist/index-pass.d.ts +0 -22
- package/superd-hub/dist/index-pass.js +0 -47
- package/superd-hub/dist/labels.d.ts +0 -45
- package/superd-hub/dist/labels.js +0 -83
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Client mount shim (AW-B DL8).
|
|
3
|
-
*
|
|
4
|
-
* ONE head script installs every client-side break point:
|
|
5
|
-
* - `__DSH_TRANSPORT__.fetch` → the Connection RPC fetch (URL object input)
|
|
6
|
-
* - `WebSocket` / `EventSource` / `XMLHttpRequest` constructors → path rewrite
|
|
7
|
-
* - `__DSH_FILE_UPLOAD__` → uploads bypass the blob worker + its XHR
|
|
8
|
-
* - Storage.prototype get/set/remove → per-world key namespace
|
|
9
|
-
* - `globalThis.fetch` → global-fetch calls asking for ctx0-root `/api`
|
|
10
|
-
* URLs (2026-09-17 H1: upstream session-log-export resolves the GLOBAL
|
|
11
|
-
* fetch at call time; narrow `/api`-only rule, query + hash preserved)
|
|
12
|
-
* - `HTMLAnchorElement.prototype.click` → download-anchor clicks re-rooted
|
|
13
|
-
* (2026-09-18 H1 r2: upstream hands the UNREWRITTEN absolute URL to a
|
|
14
|
-
* DETACHED `<a download>` and clicks it — detached clicks never reach
|
|
15
|
-
* document, so a document-level listener cannot see them, and a blanket
|
|
16
|
-
* rewrite breaks the runtime selector's root-absolute anchors
|
|
17
|
-
* (live-found 2026-09-18). Narrow rule: ONLY anchors carrying a
|
|
18
|
-
* `download` attribute AND a same-authority root-absolute `/api` href.)
|
|
19
|
-
* The rule is namespace-agnostic: a same-origin root-absolute URL is re-rooted
|
|
20
|
-
* under the mount (`/omp`), nothing else is touched. That covers every prefix
|
|
21
|
-
* a plugin may declare later — no list to keep in sync.
|
|
22
|
-
*/
|
|
23
|
-
/** Escape a label for embedding in generated JavaScript. */
|
|
24
|
-
function js(value) {
|
|
25
|
-
return JSON.stringify(value);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Render the shim as a classic script (parser-blocking head injection).
|
|
29
|
-
* @param labelPath - mount root, e.g. `/omp`.
|
|
30
|
-
* @returns JavaScript source.
|
|
31
|
-
*/
|
|
32
|
-
export function renderClientShim(labelPath) {
|
|
33
|
-
if (typeof labelPath !== 'string' || !labelPath.startsWith('/') || labelPath === '/' || labelPath.endsWith('/')) {
|
|
34
|
-
throw new Error(`client-shim: labelPath must start with "/" and carry no trailing slash, got ${JSON.stringify(labelPath)}`);
|
|
35
|
-
}
|
|
36
|
-
const prefix = `${labelPath}/`;
|
|
37
|
-
return `(() => {
|
|
38
|
-
const LABEL = ${js(labelPath)}
|
|
39
|
-
const PREFIX = ${js(prefix)}
|
|
40
|
-
|
|
41
|
-
/** Re-root one pathname when it is same-origin root-absolute and not mounted yet. */
|
|
42
|
-
const rewritePath = (path) => {
|
|
43
|
-
if (typeof path !== 'string' || !path.startsWith('/') || path.startsWith('//')) return path
|
|
44
|
-
if (path === LABEL || path.startsWith(PREFIX)) return path
|
|
45
|
-
return PREFIX + path.slice(1)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const origin = () => {
|
|
49
|
-
const loc = globalThis.location
|
|
50
|
-
if (loc !== undefined && typeof loc.origin === 'string' && loc.origin !== 'null') return loc.origin
|
|
51
|
-
return 'http://dsh.internal'
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** Same authority as the page (scheme-agnostic: ws/wss/http/https share host). */
|
|
55
|
-
const sameAuthority = (url) => {
|
|
56
|
-
try {
|
|
57
|
-
return url.host === new URL(origin()).host
|
|
58
|
-
} catch {
|
|
59
|
-
return false
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** Rewrite a full URL (absolute or relative); other authorities are untouched. */
|
|
64
|
-
const rewriteUrl = (input) => {
|
|
65
|
-
if (typeof input === 'string') {
|
|
66
|
-
if (input.startsWith('/')) return rewritePath(input)
|
|
67
|
-
try {
|
|
68
|
-
const url = new URL(input, origin())
|
|
69
|
-
if (!sameAuthority(url)) return input
|
|
70
|
-
const next = rewritePath(url.pathname)
|
|
71
|
-
if (next === url.pathname) return input
|
|
72
|
-
url.pathname = next
|
|
73
|
-
return url.href
|
|
74
|
-
} catch {
|
|
75
|
-
return input
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (input !== null && typeof input === 'object' && typeof input.href === 'string') {
|
|
79
|
-
try {
|
|
80
|
-
const url = new URL(input.href)
|
|
81
|
-
if (!sameAuthority(url)) return input
|
|
82
|
-
const next = rewritePath(url.pathname)
|
|
83
|
-
if (next === url.pathname) return input
|
|
84
|
-
url.pathname = next
|
|
85
|
-
return url
|
|
86
|
-
} catch {
|
|
87
|
-
return input
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return input
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const nativeFetch = globalThis.fetch
|
|
94
|
-
const shimFetch = (input, init) => {
|
|
95
|
-
if (typeof nativeFetch !== 'function') throw new Error('client-shim: fetch is unavailable')
|
|
96
|
-
if (typeof Request === 'function' && input instanceof Request) {
|
|
97
|
-
const url = rewriteUrl(input.url)
|
|
98
|
-
return nativeFetch(url === input.url ? input : new Request(url, input), init)
|
|
99
|
-
}
|
|
100
|
-
return nativeFetch(rewriteUrl(input), init)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const transport = (globalThis.__DSH_TRANSPORT__ = globalThis.__DSH_TRANSPORT__ || {})
|
|
104
|
-
transport.rewrite = rewritePath
|
|
105
|
-
transport.fetch = shimFetch
|
|
106
|
-
|
|
107
|
-
// Construct through a Proxy, never a hand-rolled wrapper function: the
|
|
108
|
-
// upstream client compares socket.readyState against WebSocket.OPEN, so the
|
|
109
|
-
// native statics (CONNECTING/OPEN/CLOSING/CLOSED), prototype and instanceof
|
|
110
|
-
// must survive the interception.
|
|
111
|
-
const NativeWebSocket = globalThis.WebSocket
|
|
112
|
-
if (typeof NativeWebSocket === 'function') {
|
|
113
|
-
globalThis.WebSocket = new Proxy(NativeWebSocket, {
|
|
114
|
-
construct: (Target, args) => new Target(rewriteUrl(args[0]), ...args.slice(1)),
|
|
115
|
-
})
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const NativeEventSource = globalThis.EventSource
|
|
119
|
-
|
|
120
|
-
if (typeof NativeEventSource === 'function') {
|
|
121
|
-
globalThis.EventSource = new Proxy(NativeEventSource, {
|
|
122
|
-
construct: (Target, args) => new Target(rewriteUrl(args[0]), ...args.slice(1)),
|
|
123
|
-
})
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const NativeXhr = globalThis.XMLHttpRequest
|
|
127
|
-
if (typeof NativeXhr === 'function' && NativeXhr.prototype !== undefined && typeof NativeXhr.prototype.open === 'function') {
|
|
128
|
-
const nativeOpen = NativeXhr.prototype.open
|
|
129
|
-
NativeXhr.prototype.open = function (method, url, ...rest) {
|
|
130
|
-
return nativeOpen.call(this, method, rewriteUrl(url), ...rest)
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Read by the file-upload service at construction time: present ⇒ the page
|
|
135
|
-
// fetch carries uploads (no blob worker, and therefore no worker-scope XHR).
|
|
136
|
-
globalThis.__DSH_FILE_UPLOAD__ = { fetch: shimFetch }
|
|
137
|
-
|
|
138
|
-
// Narrow '/api' re-root helpers (2026-09-17 session-log 404, H1): upstream
|
|
139
|
-
// client code (session-log-export) resolves the GLOBAL fetch at call time
|
|
140
|
-
// and hands absolute ctx0-root URLs both to fetch and to a DETACHED
|
|
141
|
-
// download anchor — neither is visible to the transport faces above.
|
|
142
|
-
// Narrow rule: only root-absolute '/api' paths move under the mount;
|
|
143
|
-
// relative, same-mount, and foreign URLs pass through untouched. Query and
|
|
144
|
-
// hash survive because only the pathname is rewritten. The mount root comes
|
|
145
|
-
// from this shim's argument, never from location.pathname. NOTE: the '/api'
|
|
146
|
-
// literals below stay SINGLE-quoted on purpose — index-pass.ts rewrites
|
|
147
|
-
// every DOUBLE-quoted root-absolute string in the served HTML, and a
|
|
148
|
-
// doubled literal would silently disable these rewrites (regression tests
|
|
149
|
-
// survive the mount HTML pass).
|
|
150
|
-
const rewriteApiPath = (path) => {
|
|
151
|
-
if (path === '/api' || path.startsWith('/api/')) return PREFIX + path.slice(1)
|
|
152
|
-
return path
|
|
153
|
-
}
|
|
154
|
-
const rewriteApiUrl = (input) => {
|
|
155
|
-
if (typeof input === 'string') {
|
|
156
|
-
if (input.startsWith('/') && !input.startsWith('//')) return rewriteApiPath(input)
|
|
157
|
-
try {
|
|
158
|
-
const url = new URL(input, origin())
|
|
159
|
-
if (!sameAuthority(url)) return input
|
|
160
|
-
const next = rewriteApiPath(url.pathname)
|
|
161
|
-
if (next === url.pathname) return input
|
|
162
|
-
url.pathname = next
|
|
163
|
-
return url.href
|
|
164
|
-
} catch {
|
|
165
|
-
return input
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (input !== null && typeof input === 'object' && typeof input.href === 'string') {
|
|
169
|
-
try {
|
|
170
|
-
const url = new URL(input.href)
|
|
171
|
-
if (!sameAuthority(url)) return input
|
|
172
|
-
const next = rewriteApiPath(url.pathname)
|
|
173
|
-
if (next === url.pathname) return input
|
|
174
|
-
url.pathname = next
|
|
175
|
-
return url
|
|
176
|
-
} catch {
|
|
177
|
-
return input
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return input
|
|
181
|
-
}
|
|
182
|
-
if (typeof nativeFetch === 'function' && globalThis.__DSH_FETCH_REWRITE__ !== true) {
|
|
183
|
-
globalThis.__DSH_FETCH_REWRITE__ = true
|
|
184
|
-
globalThis.fetch = (input, init) => nativeFetch(rewriteApiUrl(input), init)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// Download anchors (2026-09-18 H1 r2): upstream session-log-export hands
|
|
188
|
-
// the UNREWRITTEN absolute URL to a DETACHED '<a download>' element and
|
|
189
|
-
// calls .click() — detached clicks never propagate to document, so the r1
|
|
190
|
-
// document-level capture listener could not see them, while its BLANKET
|
|
191
|
-
// rewrite re-rooted the runtime selector's root-absolute anchors and broke
|
|
192
|
-
// cross-world navigation (live-found 2026-09-18). Narrow seam: wrap
|
|
193
|
-
// HTMLAnchorElement.prototype.click itself and rewrite ONLY anchors that
|
|
194
|
-
// carry a 'download' attribute AND a same-authority root-absolute '/api'
|
|
195
|
-
// href. Everything else — the runtime selector's links included — passes
|
|
196
|
-
// through untouched.
|
|
197
|
-
if (globalThis.HTMLAnchorElement !== undefined
|
|
198
|
-
&& globalThis.HTMLAnchorElement.prototype !== undefined
|
|
199
|
-
&& typeof globalThis.HTMLAnchorElement.prototype.click === 'function'
|
|
200
|
-
&& globalThis.__DSH_ANCHOR_CLICK_REWRITE__ !== true) {
|
|
201
|
-
globalThis.__DSH_ANCHOR_CLICK_REWRITE__ = true
|
|
202
|
-
const nativeAnchorClick = globalThis.HTMLAnchorElement.prototype.click
|
|
203
|
-
globalThis.HTMLAnchorElement.prototype.click = function (...args) {
|
|
204
|
-
try {
|
|
205
|
-
if (this.hasAttribute('download')) {
|
|
206
|
-
const current = this.getAttribute('href')
|
|
207
|
-
if (typeof current === 'string' && current !== '') {
|
|
208
|
-
const next = rewriteApiUrl(current)
|
|
209
|
-
if (typeof next === 'string' && next !== current) this.setAttribute('href', next)
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
} catch {
|
|
213
|
-
/* best-effort: never break the click itself */
|
|
214
|
-
}
|
|
215
|
-
return nativeAnchorClick.apply(this, args)
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Storage namespace (2026-09-16 storage findings P1): all worlds share one
|
|
220
|
-
|
|
221
|
-
// origin, so bare localStorage keys would overwrite each other across
|
|
222
|
-
// mounts. Prefix every key with the label; root '/' never injects this
|
|
223
|
-
// shim and keeps bare keys. Never throws: attachPersistence only
|
|
224
|
-
// console-errors on failure, so a throwing shim would silently disable
|
|
225
|
-
// persistence.
|
|
226
|
-
try {
|
|
227
|
-
const StorageProto = globalThis.Storage && globalThis.Storage.prototype
|
|
228
|
-
if (globalThis.localStorage !== undefined && StorageProto !== undefined
|
|
229
|
-
&& !globalThis.__DSH_STORAGE_NS__
|
|
230
|
-
&& typeof StorageProto.getItem === 'function'
|
|
231
|
-
&& typeof StorageProto.setItem === 'function'
|
|
232
|
-
&& typeof StorageProto.removeItem === 'function') {
|
|
233
|
-
// NS derives from PREFIX, never LABEL: the mount HTML pass (index-pass)
|
|
234
|
-
// rewrites every quoted root-absolute string EXCEPT "<label>/"-prefixed
|
|
235
|
-
// ones, so the shim's LABEL="/omp" literal doubles to "/omp/omp" while
|
|
236
|
-
// PREFIX="/omp/" is immune (live-found 2026-09-17, acceptance A2/A5).
|
|
237
|
-
// The NS-from-PREFIX coupling is DELIBERATE: index-pass.ts rewrites double-quoted root-absolute strings except "<label>/"-prefixed ones, so LABEL="/omp" doubles while PREFIX="/omp/" survives; do NOT derive NS from LABEL.
|
|
238
|
-
const NS = PREFIX.slice(1, -1) + ':'
|
|
239
|
-
globalThis.__DSH_STORAGE_NS__ = NS
|
|
240
|
-
const nativeGetItem = StorageProto.getItem
|
|
241
|
-
const nativeSetItem = StorageProto.setItem
|
|
242
|
-
const nativeRemoveItem = StorageProto.removeItem
|
|
243
|
-
StorageProto.getItem = function (name) { return nativeGetItem.call(this, NS + name) }
|
|
244
|
-
StorageProto.setItem = function (name, value) { return nativeSetItem.call(this, NS + name, value) }
|
|
245
|
-
StorageProto.removeItem = function (name) { return nativeRemoveItem.call(this, NS + name) }
|
|
246
|
-
}
|
|
247
|
-
} catch {
|
|
248
|
-
/* storage namespace is best-effort: never break the shim */
|
|
249
|
-
}
|
|
250
|
-
})()`;
|
|
251
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mount HTML pass (AW-B DL1/DL8 server half).
|
|
3
|
-
*
|
|
4
|
-
* The world dist is built with RELATIVE asset URLs (`./assets/...`), so a
|
|
5
|
-
* `<base>` pointing at the mount makes every relative reference resolve under
|
|
6
|
-
* `/<label>/`. Root-absolute strings (the boot graph's `/plugins/...` URLs,
|
|
7
|
-
* injected script sources, `href="/"`-style anchors) do NOT follow `<base>`,
|
|
8
|
-
* so they are re-rooted explicitly — one generic rule, no namespace list.
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Rewrite a world index for serving under `<labelPath>/`.
|
|
12
|
-
*
|
|
13
|
-
* - pins `<base>` at the mount (inserting one after `<head>` when absent);
|
|
14
|
-
* - prefixes every double-quoted root-absolute string that is not already
|
|
15
|
-
* mounted and not protocol-relative (`//host/...`);
|
|
16
|
-
* - idempotent (a second pass changes nothing).
|
|
17
|
-
*
|
|
18
|
-
* @param html - the world's index.html (already rendered with its own rows).
|
|
19
|
-
* @param labelPath - mount root, e.g. `/omp`.
|
|
20
|
-
* @returns the mount-ready HTML.
|
|
21
|
-
*/
|
|
22
|
-
export declare function rewriteIndexHtml(html: string, labelPath: string): string;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mount HTML pass (AW-B DL1/DL8 server half).
|
|
3
|
-
*
|
|
4
|
-
* The world dist is built with RELATIVE asset URLs (`./assets/...`), so a
|
|
5
|
-
* `<base>` pointing at the mount makes every relative reference resolve under
|
|
6
|
-
* `/<label>/`. Root-absolute strings (the boot graph's `/plugins/...` URLs,
|
|
7
|
-
* injected script sources, `href="/"`-style anchors) do NOT follow `<base>`,
|
|
8
|
-
* so they are re-rooted explicitly — one generic rule, no namespace list.
|
|
9
|
-
*/
|
|
10
|
-
/** Root of the mount including the trailing slash (`/omp` → `/omp/`). */
|
|
11
|
-
function mountPrefix(labelPath) {
|
|
12
|
-
return labelPath.endsWith('/') ? labelPath : `${labelPath}/`;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Rewrite a world index for serving under `<labelPath>/`.
|
|
16
|
-
*
|
|
17
|
-
* - pins `<base>` at the mount (inserting one after `<head>` when absent);
|
|
18
|
-
* - prefixes every double-quoted root-absolute string that is not already
|
|
19
|
-
* mounted and not protocol-relative (`//host/...`);
|
|
20
|
-
* - idempotent (a second pass changes nothing).
|
|
21
|
-
*
|
|
22
|
-
* @param html - the world's index.html (already rendered with its own rows).
|
|
23
|
-
* @param labelPath - mount root, e.g. `/omp`.
|
|
24
|
-
* @returns the mount-ready HTML.
|
|
25
|
-
*/
|
|
26
|
-
export function rewriteIndexHtml(html, labelPath) {
|
|
27
|
-
if (typeof labelPath !== 'string' || !labelPath.startsWith('/') || labelPath === '/' || labelPath.endsWith('/')) {
|
|
28
|
-
throw new Error(`index-pass: labelPath must start with "/" and carry no trailing slash, got ${JSON.stringify(labelPath)}`);
|
|
29
|
-
}
|
|
30
|
-
const prefix = mountPrefix(labelPath);
|
|
31
|
-
let out = html;
|
|
32
|
-
if (/<base\b[^>]*>/i.test(out)) {
|
|
33
|
-
out = out.replace(/<base\b[^>]*>/i, `<base href="${prefix}">`);
|
|
34
|
-
}
|
|
35
|
-
else if (/<head(?:\s[^>]*)?>/i.test(out)) {
|
|
36
|
-
out = out.replace(/<head(?:\s[^>]*)?>/i, open => `${open}<base href="${prefix}">`);
|
|
37
|
-
}
|
|
38
|
-
out = out.replace(/"(\/[^"]*)"/g, (whole, path) => {
|
|
39
|
-
if (path.startsWith('//'))
|
|
40
|
-
return whole;
|
|
41
|
-
// Load-bearing contract: client-shim.ts derives its storage NS from the surviving "<label>/" literal (regression test: the storage NS survives the mount HTML pass). Changing this exclusion breaks that coupling.
|
|
42
|
-
if (path.startsWith(prefix))
|
|
43
|
-
return whole;
|
|
44
|
-
return `"${prefix}${path.slice(1)}"`;
|
|
45
|
-
});
|
|
46
|
-
return out;
|
|
47
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Label table (AW-B DL2/DL4): one world ↔ one mount path under the ctx0 origin.
|
|
3
|
-
*
|
|
4
|
-
* The addressed world is the request's path (`/<label>/...`), so the label is
|
|
5
|
-
* the ONLY routing key. Reserving it must be atomic against the real
|
|
6
|
-
* webServer's duplicate-registration throw — that throw is the only collision
|
|
7
|
-
* signal the framework offers (the route tables are private and there is no
|
|
8
|
-
* query API), so it is used here as the probe.
|
|
9
|
-
*
|
|
10
|
-
* A collision is a composition-level conflict and must be loud; an optional
|
|
11
|
-
* alternate root lets a deployment re-home instead of failing to boot.
|
|
12
|
-
*/
|
|
13
|
-
/** One reserved mount path. */
|
|
14
|
-
export interface LabelClaim {
|
|
15
|
-
/** Runtime key (`omp`, `codex`, …). */
|
|
16
|
-
readonly key: string;
|
|
17
|
-
/** Reserved mount root, e.g. `/omp` or `/_agents/omp` (no trailing slash). */
|
|
18
|
-
readonly path: string;
|
|
19
|
-
/** Release the claim (idempotent). */
|
|
20
|
-
release(): void;
|
|
21
|
-
}
|
|
22
|
-
/** How to reserve a path: the injected real-webServer registration. */
|
|
23
|
-
export interface ClaimOptions {
|
|
24
|
-
/** Attempt a prefix registration; throws when `(kind, path)` is already taken. */
|
|
25
|
-
register(path: string): () => void;
|
|
26
|
-
/** Optional root prefix (default: the origin root). */
|
|
27
|
-
root?: string;
|
|
28
|
-
/** Candidate roots to try, in order, when the clean path is taken. */
|
|
29
|
-
alternateRoots?: readonly string[];
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Reserve the mount path for `key`.
|
|
33
|
-
* @param key - runtime key (one path segment).
|
|
34
|
-
* @param opts - registration probe plus optional roots.
|
|
35
|
-
* @returns the live claim.
|
|
36
|
-
*/
|
|
37
|
-
export declare function claimLabel(key: string, opts: ClaimOptions): LabelClaim;
|
|
38
|
-
/** The reserved mount root for a key, or undefined when unclaimed. */
|
|
39
|
-
export declare function labelOf(key: string): string | undefined;
|
|
40
|
-
/** Release a key's claim; unknown keys are a no-op. */
|
|
41
|
-
export declare function releaseLabel(key: string): void;
|
|
42
|
-
/** Claimed keys, registration order. */
|
|
43
|
-
export declare function listLabels(): string[];
|
|
44
|
-
/** Test/introspection helper: is this object a claim? */
|
|
45
|
-
export declare function isLabelClaim(value: unknown): value is LabelClaim;
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Label table (AW-B DL2/DL4): one world ↔ one mount path under the ctx0 origin.
|
|
3
|
-
*
|
|
4
|
-
* The addressed world is the request's path (`/<label>/...`), so the label is
|
|
5
|
-
* the ONLY routing key. Reserving it must be atomic against the real
|
|
6
|
-
* webServer's duplicate-registration throw — that throw is the only collision
|
|
7
|
-
* signal the framework offers (the route tables are private and there is no
|
|
8
|
-
* query API), so it is used here as the probe.
|
|
9
|
-
*
|
|
10
|
-
* A collision is a composition-level conflict and must be loud; an optional
|
|
11
|
-
* alternate root lets a deployment re-home instead of failing to boot.
|
|
12
|
-
*/
|
|
13
|
-
const claims = new Map();
|
|
14
|
-
function isRecordLike(value) {
|
|
15
|
-
return typeof value === 'object' && value !== null;
|
|
16
|
-
}
|
|
17
|
-
/** Reject keys that cannot be a single path segment. */
|
|
18
|
-
function assertKey(key) {
|
|
19
|
-
if (typeof key !== 'string' || key === '' || key.includes('/') || key.includes('?')) {
|
|
20
|
-
throw new Error(`labels: invalid label key ${JSON.stringify(key)} (one non-empty path segment required)`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function joinRoot(root, key) {
|
|
24
|
-
const trimmed = root.replace(/\/+$/, '');
|
|
25
|
-
return trimmed === '' ? `/${key}` : `${trimmed}/${key}`;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Reserve the mount path for `key`.
|
|
29
|
-
* @param key - runtime key (one path segment).
|
|
30
|
-
* @param opts - registration probe plus optional roots.
|
|
31
|
-
* @returns the live claim.
|
|
32
|
-
*/
|
|
33
|
-
export function claimLabel(key, opts) {
|
|
34
|
-
assertKey(key);
|
|
35
|
-
const existing = claims.get(key);
|
|
36
|
-
if (existing !== undefined) {
|
|
37
|
-
throw new Error(`labels: key ${JSON.stringify(key)} already claimed at "${existing.path}"`);
|
|
38
|
-
}
|
|
39
|
-
const roots = [opts.root ?? '', ...(opts.alternateRoots ?? [])];
|
|
40
|
-
const tried = [];
|
|
41
|
-
for (const root of roots) {
|
|
42
|
-
const path = joinRoot(root, key);
|
|
43
|
-
if (tried.includes(path))
|
|
44
|
-
continue;
|
|
45
|
-
tried.push(path);
|
|
46
|
-
let dispose;
|
|
47
|
-
try {
|
|
48
|
-
dispose = opts.register(path);
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
const claim = {
|
|
54
|
-
key,
|
|
55
|
-
path,
|
|
56
|
-
release: () => {
|
|
57
|
-
if (claims.get(key)?.path !== path)
|
|
58
|
-
return;
|
|
59
|
-
claims.delete(key);
|
|
60
|
-
dispose?.();
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
claims.set(key, claim);
|
|
64
|
-
return claim;
|
|
65
|
-
}
|
|
66
|
-
throw new Error(`labels: no free mount path for ${JSON.stringify(key)} (tried ${tried.map(p => `"${p}"`).join(', ')})`);
|
|
67
|
-
}
|
|
68
|
-
/** The reserved mount root for a key, or undefined when unclaimed. */
|
|
69
|
-
export function labelOf(key) {
|
|
70
|
-
return claims.get(key)?.path;
|
|
71
|
-
}
|
|
72
|
-
/** Release a key's claim; unknown keys are a no-op. */
|
|
73
|
-
export function releaseLabel(key) {
|
|
74
|
-
claims.get(key)?.release();
|
|
75
|
-
}
|
|
76
|
-
/** Claimed keys, registration order. */
|
|
77
|
-
export function listLabels() {
|
|
78
|
-
return [...claims.keys()];
|
|
79
|
-
}
|
|
80
|
-
/** Test/introspection helper: is this object a claim? */
|
|
81
|
-
export function isLabelClaim(value) {
|
|
82
|
-
return isRecordLike(value) && typeof value['key'] === 'string' && typeof value['path'] === 'string';
|
|
83
|
-
}
|