@openchamber/web 1.18.2 → 1.18.3
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/bin/lib/commands-models.js +1 -1
- package/dist/assets/{CodeMirrorCommentWidgets-CxcJ5x9h.js → CodeMirrorCommentWidgets-DbUi6I9s.js} +1 -1
- package/dist/assets/{CommitSection-C9sBBYAJ.js → CommitSection-Jc2_hNPE.js} +1 -1
- package/dist/assets/{DiagramEditor-C7nUw7p3.js → DiagramEditor-PCrYHBko.js} +1 -1
- package/dist/assets/{DiagramView-cYxZP-HS.js → DiagramView-CndEcZNu.js} +1 -1
- package/dist/assets/{DiffView-1zd0slLu.js → DiffView-DEGlNjMH.js} +2 -2
- package/dist/assets/FilesView-CzUgIvUm.js +14 -0
- package/dist/assets/{GitView-OSVIn5V1.js → GitView-C-n17voy.js} +1 -1
- package/dist/assets/{JsonTreeView-Kgepz4pR.js → JsonTreeView-BYcgdTOQ.js} +1 -1
- package/dist/assets/MarkdownImageGallery-DzHwkVIH.js +1 -0
- package/dist/assets/MarkdownRendererImpl-DUcIcWgs.js +12 -0
- package/dist/assets/OnboardingScreen-BmN0lhk4.js +1 -0
- package/dist/assets/{PatchDiff-Cddz02Ya.js → PatchDiff-Bn7bfgUv.js} +1 -1
- package/dist/assets/{PierreDiffViewer-B5k0KvPW.js → PierreDiffViewer-D1fWvrUn.js} +2 -2
- package/dist/assets/{PlanView-BYgHBHDt.js → PlanView-CWM0iyFk.js} +3 -3
- package/dist/assets/{SessionSwitcherDropdown-ig2OT22Z.js → SessionSwitcherDropdown-Cez-9xRh.js} +1 -1
- package/dist/assets/SettingsView-Bl1drwPw.js +28 -0
- package/dist/assets/{SettingsWindow-CNHM8ifT.js → SettingsWindow-DL5axjDZ.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DrGeYq2p.js → ToolOutputDialog-BtIJkFno.js} +7 -7
- package/dist/assets/{ToolPartDiffPreview-BRmPpe94.js → ToolPartDiffPreview-i3PQo6_0.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-Dcu8Q-5P.js → VirtualizedFileDiff-DkcusvMa.js} +1 -1
- package/dist/assets/{WalkthroughView-HStEYdD2.js → WalkthroughView-Cc5Hd6P5.js} +2 -2
- package/dist/assets/{computeVirtualFileMetrics-DQE7R9IY.js → computeVirtualFileMetrics-xPena3W2.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-tQekJUAF.js +1 -0
- package/dist/assets/de-u7gSnqWs.js +9 -0
- package/dist/assets/es-T9O7aAOr.js +15 -0
- package/dist/assets/fr-Oor7ewbE.js +13 -0
- package/dist/assets/index-CVNuER6G.css +1 -0
- package/dist/assets/{index-BgQEgA2a.js → index-Crz1YOFl.js} +1 -1
- package/dist/assets/index-iFY_N5aO.js +7 -0
- package/dist/assets/{isDiffPlainText-XyBCe4eD.js → isDiffPlainText-Dudf-dWx.js} +1 -1
- package/dist/assets/{isFilePlainText-JbqDfa3n.js → isFilePlainText-DS4QV1dd.js} +1 -1
- package/dist/assets/ja-DHpqbVmr.js +15 -0
- package/dist/assets/ko-CwLkS3nx.js +15 -0
- package/dist/assets/{main-LfcbGv7C.js → main-C0DyIwTb.js} +2 -2
- package/dist/assets/main-CAxX6DAN.js +915 -0
- package/dist/assets/markdownCore-DhfzuGXu.js +2 -0
- package/dist/assets/markdownImageAssets-BTNlRyjd.js +1 -0
- package/dist/assets/{miniChat-CUp_elRz.js → miniChat-CGfrxKpJ.js} +2 -2
- package/dist/assets/{mobile-CBSN7BsH.js → mobile-DEmhwNcV.js} +2 -2
- package/dist/assets/{patchFileDiff-DCIXUHRJ.js → patchFileDiff-C5D1OPCa.js} +2 -2
- package/dist/assets/{pl-tHTP6XQx.js → pl-CcZILN8q.js} +4 -4
- package/dist/assets/pt-BR-DYHhVK6o.js +15 -0
- package/dist/assets/{renderElectronMiniChatApp-eZl-5STF.js → renderElectronMiniChatApp-Dpbswpom.js} +2 -2
- package/dist/assets/renderMobileApp-B5HA4qbi.js +25 -0
- package/dist/assets/runtimeEndpointReset-cbahJ3hD.js +13 -0
- package/dist/assets/scheduledTasksApi-BxgGWTL8.js +1 -0
- package/dist/assets/{shikiHighlight-eU8abJ3T.js → shikiHighlight-CmanopUB.js} +1 -1
- package/dist/assets/uk-BA2kZR38.js +15 -0
- package/dist/assets/{useAppFontEffects-Bbpz77To.js → useAppFontEffects-sHmU5b8u.js} +137 -137
- package/dist/assets/useInlineCommentController-gt56WkxJ.js +2 -0
- package/dist/assets/{vendor-codemirror-language-data-Dzt9rWZZ.js → vendor-codemirror-language-data-Dihw9MtL.js} +2 -2
- package/dist/assets/{vendor-marked-i_gIkIP3.js → vendor-marked-CX41MkDF.js} +1 -1
- package/dist/assets/{web-components-DGvnI0zx.js → web-components-BL-Ur2Tb.js} +1 -1
- package/dist/assets/zh-CN-dlOQK6v9.js +15 -0
- package/dist/assets/zh-TW-BnqQ-WL5.js +15 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +2 -2
- package/server/index.js +65 -19
- package/server/lib/agent-tool/DOCUMENTATION.md +21 -6
- package/server/lib/agent-tool/runtime.js +90 -16
- package/server/lib/agent-tool/runtime.test.js +86 -0
- package/server/lib/browser-control/DOCUMENTATION.md +50 -0
- package/server/lib/browser-control/broker.js +154 -0
- package/server/lib/browser-control/broker.test.js +191 -0
- package/server/lib/browser-control/routes.js +48 -0
- package/server/lib/browser-control/routes.test.js +108 -0
- package/server/lib/dev-servers/parse.js +203 -0
- package/server/lib/dev-servers/parse.test.js +174 -0
- package/server/lib/dev-servers/routes.js +135 -0
- package/server/lib/dev-tunnel/DOCUMENTATION.md +57 -0
- package/server/lib/dev-tunnel/client.js +174 -0
- package/server/lib/dev-tunnel/runtime.js +189 -0
- package/server/lib/dev-tunnel/tunnel.test.js +282 -0
- package/server/lib/git/credentials.js +0 -33
- package/server/lib/github/DOCUMENTATION.md +1 -1
- package/server/lib/openchamber-control/DOCUMENTATION.md +9 -0
- package/server/lib/openchamber-control/actions.js +33 -1
- package/server/lib/openchamber-control/screenshots.js +83 -0
- package/server/lib/openchamber-control/screenshots.test.js +84 -0
- package/server/lib/openchamber-control/service.js +141 -2
- package/server/lib/openchamber-control/service.test.js +55 -0
- package/server/lib/opencode/core-routes.js +31 -52
- package/server/lib/opencode/core-routes.test.js +37 -9
- package/server/lib/opencode/feature-routes-runtime.js +4 -0
- package/server/lib/opencode/settings-helpers.js +3 -9
- package/server/lib/projects/project-config.js +181 -2
- package/server/lib/projects/project-config.test.js +295 -0
- package/server/lib/quota/DOCUMENTATION.md +4 -2
- package/server/lib/quota/credentials/providers.js +0 -7
- package/server/lib/quota/credentials/store.js +11 -1
- package/server/lib/quota/credentials/store.test.js +9 -1
- package/server/lib/quota/providers/opencode-go.js +35 -35
- package/server/lib/quota/providers/opencode-go.test.js +52 -7
- package/server/lib/quota/routes.js +0 -2
- package/server/lib/relay/DOCUMENTATION.md +2 -0
- package/server/lib/relay/tunnel-host.js +157 -33
- package/server/lib/relay/tunnel-host.test.js +147 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +49 -0
- package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +488 -0
- package/server/lib/scheduled-tasks/routes.js +6 -0
- package/server/lib/scheduled-tasks/runtime.js +369 -108
- package/server/lib/scheduled-tasks/service.js +7 -1
- package/server/lib/scheduled-tasks/service.test.js +20 -0
- package/server/lib/walkthrough/index.js +0 -2
- package/server/sse-routes.test.js +3 -0
- package/dist/assets/FilesView-WkxsWHBE.js +0 -14
- package/dist/assets/MarkdownRendererImpl-CKAsRfIk.js +0 -12
- package/dist/assets/OnboardingScreen-BCgYA7J5.js +0 -1
- package/dist/assets/SettingsView-e7Fmxnz8.js +0 -28
- package/dist/assets/contextPanelEmbeddedChat-5VGWIT_J.js +0 -1
- package/dist/assets/de-B6t6T54h.js +0 -9
- package/dist/assets/es-DH9NUKge.js +0 -15
- package/dist/assets/fr-Do4t2KmA.js +0 -13
- package/dist/assets/index-B45s9aAX.css +0 -1
- package/dist/assets/index-CNrN5qDs.js +0 -7
- package/dist/assets/ja-DJT9EM80.js +0 -15
- package/dist/assets/ko-CfWRq2p4.js +0 -15
- package/dist/assets/main-B4oBRI9u.js +0 -193
- package/dist/assets/markdownCore-A3_L34oS.js +0 -2
- package/dist/assets/pt-BR-BDEzzltP.js +0 -15
- package/dist/assets/renderMobileApp-DA7wpIBi.js +0 -23
- package/dist/assets/runtimeEndpointReset-D5izT-u5.js +0 -13
- package/dist/assets/scheduledTasksApi-CTJdfSWc.js +0 -1
- package/dist/assets/uk-B6Q32nyk.js +0 -15
- package/dist/assets/useInlineCommentController-D7zs7-BQ.js +0 -2
- package/dist/assets/vendor-zumer-snapdom-Btyu_Xi2.js +0 -8
- package/dist/assets/zh-CN-7MGcwGaC.js +0 -15
- package/dist/assets/zh-TW-CFPfqxlL.js +0 -15
- package/server/lib/preview/proxy-runtime.js +0 -1604
- package/server/lib/preview/proxy-runtime.test.js +0 -528
- package/server/lib/quota/opencode-go-credentials.js +0 -11
- package/server/lib/quota/opencode-go-credentials.test.js +0 -32
- package/server/lib/quota/routes.test.js +0 -40
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local end of the dev-server tunnel.
|
|
3
|
+
*
|
|
4
|
+
* Binds a loopback listener on this machine and pipes every connection to a
|
|
5
|
+
* dev server on the OpenChamber host. The point of binding a real local port —
|
|
6
|
+
* rather than serving the remote page under a path on some other origin — is
|
|
7
|
+
* that the page then has its own origin at the root of its own host. Absolute
|
|
8
|
+
* URLs resolve, cookies scope correctly, HMR sockets connect, and nothing has
|
|
9
|
+
* to be rewritten.
|
|
10
|
+
*
|
|
11
|
+
* Lives in the web package because it needs a WebSocket client, which this
|
|
12
|
+
* package already depends on; the desktop shell drives it over IPC.
|
|
13
|
+
*/
|
|
14
|
+
import net from 'node:net';
|
|
15
|
+
import { WebSocket } from 'ws';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* What one connection may buffer while its WebSocket is still connecting.
|
|
19
|
+
*
|
|
20
|
+
* Enough for a request with generous headers, far short of a body worth
|
|
21
|
+
* holding: a local process could otherwise keep writing into a stalled
|
|
22
|
+
* handshake and grow the desktop app's memory without limit.
|
|
23
|
+
*/
|
|
24
|
+
const MAX_PENDING_BYTES = 256 * 1024;
|
|
25
|
+
/** A handshake that has not completed by now is not going to. */
|
|
26
|
+
const HANDSHAKE_TIMEOUT_MS = 15_000;
|
|
27
|
+
|
|
28
|
+
const toWebSocketUrl = (baseUrl, port) => {
|
|
29
|
+
const parsed = new URL('/api/dev-tunnel', baseUrl);
|
|
30
|
+
parsed.protocol = parsed.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
31
|
+
parsed.searchParams.set('port', String(port));
|
|
32
|
+
return parsed.toString();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const createDevTunnelClient = ({
|
|
36
|
+
logger = console,
|
|
37
|
+
handshakeTimeoutMs = HANDSHAKE_TIMEOUT_MS,
|
|
38
|
+
maxPendingBytes = MAX_PENDING_BYTES,
|
|
39
|
+
} = {}) => {
|
|
40
|
+
/** Keyed by `${baseUrl}|${remotePort}` so repeat opens reuse one listener. */
|
|
41
|
+
const tunnels = new Map();
|
|
42
|
+
|
|
43
|
+
const closeTunnel = (key) => {
|
|
44
|
+
const tunnel = tunnels.get(key);
|
|
45
|
+
if (!tunnel) return false;
|
|
46
|
+
tunnels.delete(key);
|
|
47
|
+
for (const socket of tunnel.sockets) {
|
|
48
|
+
try { socket.destroy(); } catch { /* already gone */ }
|
|
49
|
+
}
|
|
50
|
+
try { tunnel.server.close(); } catch { /* already closing */ }
|
|
51
|
+
return true;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
/**
|
|
56
|
+
* Opens (or reuses) a tunnel and resolves with the local port to browse.
|
|
57
|
+
* Rejects if the listener cannot bind; per-connection failures close only
|
|
58
|
+
* that connection, so one failed request cannot take the tunnel down.
|
|
59
|
+
*/
|
|
60
|
+
async open({ baseUrl, port, headers = {} }) {
|
|
61
|
+
const remotePort = Number.parseInt(String(port), 10);
|
|
62
|
+
if (!Number.isInteger(remotePort) || remotePort <= 0 || remotePort > 65535) {
|
|
63
|
+
throw new Error('A valid remote port is required');
|
|
64
|
+
}
|
|
65
|
+
const base = String(baseUrl || '').trim();
|
|
66
|
+
if (!base) throw new Error('A remote base URL is required');
|
|
67
|
+
|
|
68
|
+
const key = `${base}|${remotePort}`;
|
|
69
|
+
const existing = tunnels.get(key);
|
|
70
|
+
if (existing) return { localPort: existing.localPort, reused: true };
|
|
71
|
+
|
|
72
|
+
const target = toWebSocketUrl(base, remotePort);
|
|
73
|
+
const sockets = new Set();
|
|
74
|
+
|
|
75
|
+
const server = net.createServer((socket) => {
|
|
76
|
+
socket.setNoDelay(true);
|
|
77
|
+
sockets.add(socket);
|
|
78
|
+
|
|
79
|
+
const upstream = new WebSocket(target, { headers, perMessageDeflate: false });
|
|
80
|
+
upstream.binaryType = 'nodebuffer';
|
|
81
|
+
let pendingWrites = [];
|
|
82
|
+
let pendingBytes = 0;
|
|
83
|
+
|
|
84
|
+
const handshakeTimer = setTimeout(() => {
|
|
85
|
+
logger.warn?.(`[dev-tunnel] handshake timed out for port ${remotePort}`);
|
|
86
|
+
teardown();
|
|
87
|
+
}, handshakeTimeoutMs);
|
|
88
|
+
|
|
89
|
+
function teardown() {
|
|
90
|
+
clearTimeout(handshakeTimer);
|
|
91
|
+
pendingWrites = [];
|
|
92
|
+
pendingBytes = 0;
|
|
93
|
+
sockets.delete(socket);
|
|
94
|
+
try { socket.destroy(); } catch { /* already gone */ }
|
|
95
|
+
try { upstream.close(); } catch { /* already closing */ }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
upstream.on('open', () => {
|
|
99
|
+
clearTimeout(handshakeTimer);
|
|
100
|
+
for (const chunk of pendingWrites) upstream.send(chunk);
|
|
101
|
+
pendingWrites = [];
|
|
102
|
+
pendingBytes = 0;
|
|
103
|
+
// The local end was held back while there was nowhere to put its
|
|
104
|
+
// bytes; there is somewhere now.
|
|
105
|
+
socket.resume();
|
|
106
|
+
});
|
|
107
|
+
upstream.on('message', (data) => {
|
|
108
|
+
if (socket.destroyed) return;
|
|
109
|
+
socket.write(data);
|
|
110
|
+
});
|
|
111
|
+
upstream.on('error', (error) => {
|
|
112
|
+
logger.warn?.(`[dev-tunnel] upstream failed for port ${remotePort}: ${error?.message || error}`);
|
|
113
|
+
teardown();
|
|
114
|
+
});
|
|
115
|
+
upstream.on('close', teardown);
|
|
116
|
+
|
|
117
|
+
socket.on('data', (chunk) => {
|
|
118
|
+
// Bytes can arrive before the WebSocket handshake completes; buffering
|
|
119
|
+
// them is what keeps the first HTTP request intact. The buffer is
|
|
120
|
+
// bounded, and the local end is paused rather than trusted to stop.
|
|
121
|
+
if (upstream.readyState === WebSocket.OPEN) {
|
|
122
|
+
upstream.send(chunk);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (upstream.readyState !== WebSocket.CONNECTING) return;
|
|
126
|
+
|
|
127
|
+
pendingWrites.push(chunk);
|
|
128
|
+
pendingBytes += chunk.length;
|
|
129
|
+
if (pendingBytes > maxPendingBytes) {
|
|
130
|
+
logger.warn?.(`[dev-tunnel] dropped a connection that buffered too much for port ${remotePort}`);
|
|
131
|
+
teardown();
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
socket.pause();
|
|
135
|
+
});
|
|
136
|
+
socket.on('error', teardown);
|
|
137
|
+
socket.on('close', teardown);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const localPort = await new Promise((resolve, reject) => {
|
|
141
|
+
server.once('error', reject);
|
|
142
|
+
server.listen(0, '127.0.0.1', () => {
|
|
143
|
+
server.off('error', reject);
|
|
144
|
+
const address = server.address();
|
|
145
|
+
if (!address || typeof address === 'string') {
|
|
146
|
+
reject(new Error('Failed to bind a local tunnel port'));
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
resolve(address.port);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
server.on('error', (error) => {
|
|
154
|
+
logger.warn?.(`[dev-tunnel] listener error for port ${remotePort}: ${error?.message || error}`);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
tunnels.set(key, { server, sockets, localPort, remotePort, baseUrl: base });
|
|
158
|
+
return { localPort, reused: false };
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
close({ baseUrl, port }) {
|
|
162
|
+
return closeTunnel(`${String(baseUrl || '').trim()}|${Number.parseInt(String(port), 10)}`);
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
/** Closes every tunnel; used when the desktop switches runtime or quits. */
|
|
166
|
+
closeAll() {
|
|
167
|
+
for (const key of [...tunnels.keys()]) closeTunnel(key);
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
list() {
|
|
171
|
+
return [...tunnels.values()].map(({ localPort, remotePort, baseUrl }) => ({ localPort, remotePort, baseUrl }));
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
};
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw byte tunnel to a dev server running on the OpenChamber host.
|
|
3
|
+
*
|
|
4
|
+
* This is what lets a desktop client preview a dev server that lives on another
|
|
5
|
+
* machine without rewriting anything. The client binds its own local port and
|
|
6
|
+
* pipes it here; the page is then served from a real origin at the root of its
|
|
7
|
+
* own host, so absolute URLs, cookies, HMR sockets, and DevTools all behave
|
|
8
|
+
* exactly as they do locally. No HTML is inspected or modified.
|
|
9
|
+
*
|
|
10
|
+
* Security posture: the reachable set is the same list dev-server discovery
|
|
11
|
+
* offers the user, not "any loopback port". Without that restriction an
|
|
12
|
+
* authenticated client could dial arbitrary local services on the host —
|
|
13
|
+
* databases, admin panels, the OpenCode API — through this socket.
|
|
14
|
+
*
|
|
15
|
+
* Authentication differs from the browser-facing sockets on purpose. Those
|
|
16
|
+
* demand an allowed `Origin`, which is a CSRF defence: a hostile page can make
|
|
17
|
+
* a browser open a WebSocket carrying the user's ambient cookies, and the
|
|
18
|
+
* origin is what exposes it. This tunnel's client is the desktop shell, not a
|
|
19
|
+
* browser, and it authenticates with an explicit bearer token. So:
|
|
20
|
+
*
|
|
21
|
+
* - With an `Origin` header, the request came from a browser context and the
|
|
22
|
+
* usual origin check applies unchanged.
|
|
23
|
+
* - With no `Origin`, the request must carry client-token auth. A browser
|
|
24
|
+
* cannot reach this path: the WebSocket API always sends an origin and never
|
|
25
|
+
* lets a page set an `Authorization` header.
|
|
26
|
+
*/
|
|
27
|
+
import net from 'node:net';
|
|
28
|
+
import { WebSocketServer } from 'ws';
|
|
29
|
+
|
|
30
|
+
const DEV_TUNNEL_WS_PATH = '/api/dev-tunnel';
|
|
31
|
+
/** One page load opens many sockets; the cap is per host, not per page. */
|
|
32
|
+
const MAX_CONCURRENT_SOCKETS = 64;
|
|
33
|
+
const CONNECT_TIMEOUT_MS = 5_000;
|
|
34
|
+
|
|
35
|
+
const parseRequestedPort = (url) => {
|
|
36
|
+
try {
|
|
37
|
+
const parsed = new URL(String(url || ''), 'http://localhost');
|
|
38
|
+
if (parsed.pathname !== DEV_TUNNEL_WS_PATH) return null;
|
|
39
|
+
const port = Number.parseInt(parsed.searchParams.get('port') || '', 10);
|
|
40
|
+
return Number.isInteger(port) && port > 0 && port <= 65535 ? port : null;
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const isDevTunnelPath = (url) => {
|
|
47
|
+
try {
|
|
48
|
+
return new URL(String(url || ''), 'http://localhost').pathname === DEV_TUNNEL_WS_PATH;
|
|
49
|
+
} catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export function createDevTunnelRuntime({
|
|
55
|
+
server,
|
|
56
|
+
discoverDevServers,
|
|
57
|
+
uiAuthController,
|
|
58
|
+
isRequestOriginAllowed,
|
|
59
|
+
rejectWebSocketUpgrade,
|
|
60
|
+
logger = console,
|
|
61
|
+
}) {
|
|
62
|
+
const wsServer = new WebSocketServer({ noServer: true });
|
|
63
|
+
let openSockets = 0;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A port is reachable only while discovery still reports it. Re-checked on
|
|
67
|
+
* every upgrade rather than cached, so a dev server that stops listening
|
|
68
|
+
* stops being reachable.
|
|
69
|
+
*/
|
|
70
|
+
const isAllowedPort = async (port) => {
|
|
71
|
+
const result = await discoverDevServers();
|
|
72
|
+
if (!result?.ok) return false;
|
|
73
|
+
return result.servers.some((entry) => entry.port === port);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
wsServer.on('connection', (socket, req) => {
|
|
77
|
+
const port = parseRequestedPort(req.url);
|
|
78
|
+
if (port === null) {
|
|
79
|
+
socket.close(1008, 'Invalid port');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
openSockets += 1;
|
|
84
|
+
const upstream = net.connect({ host: '127.0.0.1', port });
|
|
85
|
+
upstream.setNoDelay(true);
|
|
86
|
+
|
|
87
|
+
let settled = false;
|
|
88
|
+
const teardown = () => {
|
|
89
|
+
if (settled) return;
|
|
90
|
+
settled = true;
|
|
91
|
+
openSockets -= 1;
|
|
92
|
+
try { upstream.destroy(); } catch { /* already gone */ }
|
|
93
|
+
try { socket.close(); } catch { /* already closing */ }
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const connectTimer = setTimeout(() => {
|
|
97
|
+
if (!upstream.connecting) return;
|
|
98
|
+
logger.warn?.(`[dev-tunnel] timed out connecting to 127.0.0.1:${port}`);
|
|
99
|
+
teardown();
|
|
100
|
+
}, CONNECT_TIMEOUT_MS);
|
|
101
|
+
|
|
102
|
+
upstream.on('connect', () => clearTimeout(connectTimer));
|
|
103
|
+
upstream.on('data', (chunk) => {
|
|
104
|
+
if (socket.readyState !== socket.OPEN) return;
|
|
105
|
+
socket.send(chunk);
|
|
106
|
+
// Stop reading from the dev server while the socket drains, otherwise a
|
|
107
|
+
// fast response against a slow client buffers the whole body in memory.
|
|
108
|
+
if (socket.bufferedAmount > 1_000_000) {
|
|
109
|
+
upstream.pause();
|
|
110
|
+
const resume = () => {
|
|
111
|
+
if (socket.bufferedAmount > 1_000_000) {
|
|
112
|
+
setTimeout(resume, 20);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
upstream.resume();
|
|
116
|
+
};
|
|
117
|
+
setTimeout(resume, 20);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
upstream.on('error', () => { clearTimeout(connectTimer); teardown(); });
|
|
121
|
+
upstream.on('close', () => { clearTimeout(connectTimer); teardown(); });
|
|
122
|
+
|
|
123
|
+
socket.on('message', (data) => {
|
|
124
|
+
if (upstream.destroyed) return;
|
|
125
|
+
upstream.write(data);
|
|
126
|
+
});
|
|
127
|
+
socket.on('close', teardown);
|
|
128
|
+
socket.on('error', teardown);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const upgradeHandler = (req, socket, head) => {
|
|
132
|
+
if (!isDevTunnelPath(req.url)) return;
|
|
133
|
+
void (async () => {
|
|
134
|
+
try {
|
|
135
|
+
if (uiAuthController?.enabled) {
|
|
136
|
+
const auth = await uiAuthController.resolveAuthContext(req, null, { allowUrlToken: false });
|
|
137
|
+
if (!auth) {
|
|
138
|
+
rejectWebSocketUpgrade(socket, 401, 'UI authentication required');
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const hasOrigin = typeof req.headers?.origin === 'string' && req.headers.origin.trim() !== '';
|
|
142
|
+
if (hasOrigin) {
|
|
143
|
+
if (!await isRequestOriginAllowed(req)) {
|
|
144
|
+
rejectWebSocketUpgrade(socket, 403, 'Invalid origin');
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
} else if (auth.type !== 'client') {
|
|
148
|
+
rejectWebSocketUpgrade(socket, 403, 'Client authentication required');
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const port = parseRequestedPort(req.url);
|
|
154
|
+
if (port === null) {
|
|
155
|
+
rejectWebSocketUpgrade(socket, 400, 'Invalid port');
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (openSockets >= MAX_CONCURRENT_SOCKETS) {
|
|
159
|
+
rejectWebSocketUpgrade(socket, 503, 'Too many tunnel connections');
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (!await isAllowedPort(port)) {
|
|
163
|
+
// Says which port, because the alternative is an empty response in
|
|
164
|
+
// the panel with nothing anywhere explaining why.
|
|
165
|
+
logger.warn?.(`[dev-tunnel] refused port ${port}: not reported by dev-server discovery`);
|
|
166
|
+
rejectWebSocketUpgrade(socket, 403, 'That port is not an available dev server');
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
wsServer.handleUpgrade(req, socket, head, (ws) => wsServer.emit('connection', ws, req));
|
|
171
|
+
} catch {
|
|
172
|
+
rejectWebSocketUpgrade(socket, 500, 'Upgrade failed');
|
|
173
|
+
}
|
|
174
|
+
})();
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
server.on('upgrade', upgradeHandler);
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
path: DEV_TUNNEL_WS_PATH,
|
|
181
|
+
get openSocketCount() {
|
|
182
|
+
return openSockets;
|
|
183
|
+
},
|
|
184
|
+
dispose() {
|
|
185
|
+
server.off('upgrade', upgradeHandler);
|
|
186
|
+
wsServer.close();
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
2
|
+
import http from 'node:http';
|
|
3
|
+
import net from 'node:net';
|
|
4
|
+
|
|
5
|
+
import { createDevTunnelClient } from './client.js';
|
|
6
|
+
import { createDevTunnelRuntime, isDevTunnelPath } from './runtime.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* These exercise the real socket path end to end: a dev server, an OpenChamber
|
|
10
|
+
* host tunnelling to it, and a client binding a local port. Anything less would
|
|
11
|
+
* not prove the thing that matters — that a page loads over the tunnel exactly
|
|
12
|
+
* as it does locally.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const started = [];
|
|
16
|
+
|
|
17
|
+
const listen = (server, host = '127.0.0.1') => new Promise((resolve) => {
|
|
18
|
+
server.listen(0, host, () => resolve(server.address().port));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const trackSockets = (server) => {
|
|
22
|
+
const sockets = new Set();
|
|
23
|
+
server.on('connection', (socket) => {
|
|
24
|
+
sockets.add(socket);
|
|
25
|
+
socket.on('close', () => sockets.delete(socket));
|
|
26
|
+
});
|
|
27
|
+
return sockets;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const stopServer = (server, sockets) => async () => {
|
|
31
|
+
for (const socket of sockets) {
|
|
32
|
+
socket.destroy();
|
|
33
|
+
}
|
|
34
|
+
await new Promise((resolve) => server.close(resolve));
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const startDevServer = async (handler) => {
|
|
38
|
+
const server = http.createServer(handler);
|
|
39
|
+
const sockets = trackSockets(server);
|
|
40
|
+
const port = await listen(server);
|
|
41
|
+
started.push(stopServer(server, sockets));
|
|
42
|
+
return port;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const startHost = async ({ allowedPorts, auth = null, discoveryOk = true }) => {
|
|
46
|
+
const server = http.createServer((_req, res) => res.end('host'));
|
|
47
|
+
const sockets = trackSockets(server);
|
|
48
|
+
const port = await listen(server);
|
|
49
|
+
const runtime = createDevTunnelRuntime({
|
|
50
|
+
server,
|
|
51
|
+
discoverDevServers: async () => (discoveryOk
|
|
52
|
+
? {
|
|
53
|
+
ok: true,
|
|
54
|
+
servers: allowedPorts.map((value) => ({ port: value, url: `http://localhost:${value}/`, command: 'node', pid: 1 })),
|
|
55
|
+
}
|
|
56
|
+
: { ok: false, reason: 'no-listener-source' }),
|
|
57
|
+
uiAuthController: auth ?? { enabled: false },
|
|
58
|
+
isRequestOriginAllowed: async (req) => req.headers.origin === 'http://allowed.example',
|
|
59
|
+
rejectWebSocketUpgrade: (socket, status, message) => {
|
|
60
|
+
socket.write(`HTTP/1.1 ${status} ${message}\r\n\r\n`);
|
|
61
|
+
socket.destroy();
|
|
62
|
+
},
|
|
63
|
+
logger: { warn: () => {} },
|
|
64
|
+
});
|
|
65
|
+
started.push(async () => {
|
|
66
|
+
runtime.dispose();
|
|
67
|
+
await stopServer(server, sockets)();
|
|
68
|
+
});
|
|
69
|
+
return { port, baseUrl: `http://127.0.0.1:${port}`, runtime, sockets };
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const httpGet = (port, path = '/') => new Promise((resolve, reject) => {
|
|
73
|
+
const request = http.get({ host: '127.0.0.1', port, path }, (response) => {
|
|
74
|
+
let body = '';
|
|
75
|
+
response.on('data', (chunk) => { body += chunk; });
|
|
76
|
+
response.on('end', () => resolve({ status: response.statusCode, body, headers: response.headers }));
|
|
77
|
+
});
|
|
78
|
+
request.on('error', reject);
|
|
79
|
+
request.setTimeout(5_000, () => request.destroy(new Error('timeout')));
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
afterEach(async () => {
|
|
83
|
+
while (started.length) {
|
|
84
|
+
const stop = started.pop();
|
|
85
|
+
await stop();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('dev tunnel path matching', () => {
|
|
90
|
+
test('only claims its own upgrade path', () => {
|
|
91
|
+
expect(isDevTunnelPath('/api/dev-tunnel?port=5173')).toBe(true);
|
|
92
|
+
expect(isDevTunnelPath('/api/terminal/ws')).toBe(false);
|
|
93
|
+
expect(isDevTunnelPath('')).toBe(false);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe('dev tunnel end to end', () => {
|
|
98
|
+
test('serves the dev server through a local port, unmodified', async () => {
|
|
99
|
+
const devPort = await startDevServer((req, res) => {
|
|
100
|
+
res.setHeader('content-type', 'text/html');
|
|
101
|
+
res.setHeader('x-dev-header', 'kept');
|
|
102
|
+
res.end(`<html><body>path:${req.url}</body></html>`);
|
|
103
|
+
});
|
|
104
|
+
const host = await startHost({ allowedPorts: [devPort] });
|
|
105
|
+
|
|
106
|
+
const client = createDevTunnelClient({ logger: { warn: () => {} } });
|
|
107
|
+
started.push(() => client.closeAll());
|
|
108
|
+
const { localPort } = await client.open({ baseUrl: host.baseUrl, port: devPort });
|
|
109
|
+
|
|
110
|
+
const response = await httpGet(localPort, '/some/page?q=1');
|
|
111
|
+
expect(response.status).toBe(200);
|
|
112
|
+
expect(response.body).toBe('<html><body>path:/some/page?q=1</body></html>');
|
|
113
|
+
expect(response.headers['x-dev-header']).toBe('kept');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('drops a connection that floods a handshake that never completes', async () => {
|
|
117
|
+
// A host that accepts the TCP connection and then says nothing: the
|
|
118
|
+
// WebSocket handshake hangs, which is when buffering could run away.
|
|
119
|
+
const stalled = net.createServer(() => {});
|
|
120
|
+
const stalledSockets = trackSockets(stalled);
|
|
121
|
+
const stalledPort = await listen(stalled);
|
|
122
|
+
started.push(stopServer(stalled, stalledSockets));
|
|
123
|
+
|
|
124
|
+
const client = createDevTunnelClient({
|
|
125
|
+
logger: { warn: () => {} },
|
|
126
|
+
handshakeTimeoutMs: 300,
|
|
127
|
+
});
|
|
128
|
+
started.push(() => client.closeAll());
|
|
129
|
+
const { localPort } = await client.open({ baseUrl: `http://127.0.0.1:${stalledPort}`, port: 4321 });
|
|
130
|
+
|
|
131
|
+
const closed = await new Promise((resolve) => {
|
|
132
|
+
const socket = net.createConnection({ port: localPort, host: '127.0.0.1' }, () => {
|
|
133
|
+
const chunk = Buffer.alloc(64 * 1024, 0x61);
|
|
134
|
+
const write = () => {
|
|
135
|
+
// Keep writing while the handshake hangs; the tunnel must stop this
|
|
136
|
+
// rather than hold every byte in the desktop app's memory.
|
|
137
|
+
if (socket.destroyed) return;
|
|
138
|
+
socket.write(chunk, () => setTimeout(write, 1));
|
|
139
|
+
};
|
|
140
|
+
write();
|
|
141
|
+
});
|
|
142
|
+
socket.on('close', () => resolve(true));
|
|
143
|
+
socket.on('error', () => resolve(true));
|
|
144
|
+
setTimeout(() => resolve(false), 3_000);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
expect(closed).toBe(true);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('reuses one listener for repeat opens of the same target', async () => {
|
|
151
|
+
const devPort = await startDevServer((_req, res) => res.end('ok'));
|
|
152
|
+
const host = await startHost({ allowedPorts: [devPort] });
|
|
153
|
+
const client = createDevTunnelClient({ logger: { warn: () => {} } });
|
|
154
|
+
started.push(() => client.closeAll());
|
|
155
|
+
|
|
156
|
+
const first = await client.open({ baseUrl: host.baseUrl, port: devPort });
|
|
157
|
+
const second = await client.open({ baseUrl: host.baseUrl, port: devPort });
|
|
158
|
+
|
|
159
|
+
expect(second.localPort).toBe(first.localPort);
|
|
160
|
+
expect(second.reused).toBe(true);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test('refuses a port discovery does not report, so it is not a loopback proxy', async () => {
|
|
164
|
+
const secret = await startDevServer((_req, res) => res.end('secret service'));
|
|
165
|
+
const host = await startHost({ allowedPorts: [] });
|
|
166
|
+
const client = createDevTunnelClient({ logger: { warn: () => {} } });
|
|
167
|
+
started.push(() => client.closeAll());
|
|
168
|
+
|
|
169
|
+
const { localPort } = await client.open({ baseUrl: host.baseUrl, port: secret });
|
|
170
|
+
await expect(httpGet(localPort, '/')).rejects.toThrow();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('closing a tunnel frees its local port', async () => {
|
|
174
|
+
const devPort = await startDevServer((_req, res) => res.end('ok'));
|
|
175
|
+
const host = await startHost({ allowedPorts: [devPort] });
|
|
176
|
+
const client = createDevTunnelClient({ logger: { warn: () => {} } });
|
|
177
|
+
|
|
178
|
+
const { localPort } = await client.open({ baseUrl: host.baseUrl, port: devPort });
|
|
179
|
+
expect(client.close({ baseUrl: host.baseUrl, port: devPort })).toBe(true);
|
|
180
|
+
expect(client.list()).toEqual([]);
|
|
181
|
+
|
|
182
|
+
// The port is free again: binding it back succeeds.
|
|
183
|
+
const probe = net.createServer();
|
|
184
|
+
await new Promise((resolve, reject) => {
|
|
185
|
+
probe.once('error', reject);
|
|
186
|
+
probe.listen(localPort, '127.0.0.1', resolve);
|
|
187
|
+
});
|
|
188
|
+
await new Promise((resolve) => probe.close(resolve));
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('rejects an invalid remote port before binding anything', async () => {
|
|
192
|
+
const client = createDevTunnelClient({ logger: { warn: () => {} } });
|
|
193
|
+
await expect(client.open({ baseUrl: 'http://127.0.0.1:1', port: 0 })).rejects.toThrow('valid remote port');
|
|
194
|
+
await expect(client.open({ baseUrl: '', port: 5173 })).rejects.toThrow('base URL');
|
|
195
|
+
expect(client.list()).toEqual([]);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// Not covered here: recovery after a request the dev server kills mid-flight.
|
|
199
|
+
// The behaviour is real (each connection tears down independently), but the
|
|
200
|
+
// abandoned socket makes this harness's teardown unreliable, and a flaky test
|
|
201
|
+
// is worse than a documented gap. Verify it by hand against a restarting dev
|
|
202
|
+
// server.
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* The desktop shell dials this from the main process, where there is no browser
|
|
207
|
+
* and therefore no Origin header. Requiring one — as the browser-facing sockets
|
|
208
|
+
* rightly do — silently rejected every tunnel and surfaced as an empty response
|
|
209
|
+
* in the panel, with nothing to connect it back to authentication.
|
|
210
|
+
*/
|
|
211
|
+
describe('dev tunnel authentication', () => {
|
|
212
|
+
const clientAuth = {
|
|
213
|
+
enabled: true,
|
|
214
|
+
resolveAuthContext: async (req) => (
|
|
215
|
+
req.headers.authorization === 'Bearer good' ? { type: 'client' } : null
|
|
216
|
+
),
|
|
217
|
+
};
|
|
218
|
+
const sessionAuth = {
|
|
219
|
+
enabled: true,
|
|
220
|
+
resolveAuthContext: async () => ({ type: 'session' }),
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
test('accepts a bearer-authenticated client that sends no origin', async () => {
|
|
224
|
+
const devPort = await startDevServer((_req, res) => res.end('ok'));
|
|
225
|
+
const host = await startHost({ allowedPorts: [devPort], auth: clientAuth });
|
|
226
|
+
const client = createDevTunnelClient({ logger: { warn: () => {} } });
|
|
227
|
+
started.push(() => client.closeAll());
|
|
228
|
+
|
|
229
|
+
const { localPort } = await client.open({
|
|
230
|
+
baseUrl: host.baseUrl,
|
|
231
|
+
port: devPort,
|
|
232
|
+
headers: { Authorization: 'Bearer good' },
|
|
233
|
+
});
|
|
234
|
+
expect((await httpGet(localPort, '/')).body).toBe('ok');
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test('rejects a client with no credentials', async () => {
|
|
238
|
+
const devPort = await startDevServer((_req, res) => res.end('ok'));
|
|
239
|
+
const host = await startHost({ allowedPorts: [devPort], auth: clientAuth });
|
|
240
|
+
const client = createDevTunnelClient({ logger: { warn: () => {} } });
|
|
241
|
+
started.push(() => client.closeAll());
|
|
242
|
+
|
|
243
|
+
const { localPort } = await client.open({ baseUrl: host.baseUrl, port: devPort });
|
|
244
|
+
await expect(httpGet(localPort, '/')).rejects.toThrow();
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test('still refuses a session-authenticated request that sends no origin', async () => {
|
|
248
|
+
// Only an explicit bearer may skip the origin check; ambient session
|
|
249
|
+
// credentials are exactly what the origin check exists to protect.
|
|
250
|
+
const devPort = await startDevServer((_req, res) => res.end('ok'));
|
|
251
|
+
const host = await startHost({ allowedPorts: [devPort], auth: sessionAuth });
|
|
252
|
+
const client = createDevTunnelClient({ logger: { warn: () => {} } });
|
|
253
|
+
started.push(() => client.closeAll());
|
|
254
|
+
|
|
255
|
+
const { localPort } = await client.open({ baseUrl: host.baseUrl, port: devPort });
|
|
256
|
+
await expect(httpGet(localPort, '/')).rejects.toThrow();
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test('rejects a disallowed origin even with valid credentials', async () => {
|
|
260
|
+
const devPort = await startDevServer((_req, res) => res.end('ok'));
|
|
261
|
+
const host = await startHost({ allowedPorts: [devPort], auth: clientAuth });
|
|
262
|
+
const client = createDevTunnelClient({ logger: { warn: () => {} } });
|
|
263
|
+
started.push(() => client.closeAll());
|
|
264
|
+
|
|
265
|
+
const { localPort } = await client.open({
|
|
266
|
+
baseUrl: host.baseUrl,
|
|
267
|
+
port: devPort,
|
|
268
|
+
headers: { Authorization: 'Bearer good', Origin: 'http://evil.example' },
|
|
269
|
+
});
|
|
270
|
+
await expect(httpGet(localPort, '/')).rejects.toThrow();
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test('refuses every port when discovery itself is unavailable', async () => {
|
|
274
|
+
const devPort = await startDevServer((_req, res) => res.end('ok'));
|
|
275
|
+
const host = await startHost({ allowedPorts: [devPort], discoveryOk: false });
|
|
276
|
+
const client = createDevTunnelClient({ logger: { warn: () => {} } });
|
|
277
|
+
started.push(() => client.closeAll());
|
|
278
|
+
|
|
279
|
+
const { localPort } = await client.open({ baseUrl: host.baseUrl, port: devPort });
|
|
280
|
+
await expect(httpGet(localPort, '/')).rejects.toThrow();
|
|
281
|
+
});
|
|
282
|
+
});
|
|
@@ -39,36 +39,3 @@ export function discoverGitCredentials() {
|
|
|
39
39
|
|
|
40
40
|
return credentials;
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
export function getCredentialForHost(host) {
|
|
44
|
-
if (!fs.existsSync(GIT_CREDENTIALS_PATH)) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
const content = fs.readFileSync(GIT_CREDENTIALS_PATH, 'utf8');
|
|
50
|
-
const lines = content.split('\n').filter(line => line.trim());
|
|
51
|
-
|
|
52
|
-
for (const line of lines) {
|
|
53
|
-
try {
|
|
54
|
-
const url = new URL(line.trim());
|
|
55
|
-
const hostname = url.hostname;
|
|
56
|
-
const pathname = url.pathname && url.pathname !== '/' ? url.pathname : '';
|
|
57
|
-
const credHost = hostname + pathname;
|
|
58
|
-
|
|
59
|
-
if (credHost === host) {
|
|
60
|
-
return {
|
|
61
|
-
username: url.username || '',
|
|
62
|
-
token: url.password || ''
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
} catch {
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
} catch (error) {
|
|
70
|
-
console.error('Failed to read .git-credentials for host lookup:', error);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
## Entrypoints and structure
|
|
9
9
|
|
|
10
|
-
- `packages/web/server/lib/github/index.js`: public server entrypoint.
|
|
10
|
+
- `packages/web/server/lib/github/index.js`: public server entrypoint. `routes.js` loads it lazily with `await import('./index.js')` and destructures the handler it needs, so a re-export removed from here breaks a route at request time rather than at build time. Static "unused export" reports do not see these consumers.
|
|
11
11
|
- `packages/web/server/lib/github/routes.js`: Express route registration for `/api/github/*` endpoints.
|
|
12
12
|
- `packages/web/server/lib/github/auth.js`: auth storage, multi-account support, client id, scope config.
|
|
13
13
|
- `packages/web/server/lib/github/device-flow.js`: OAuth device flow.
|