@octane-xplat/devtools 0.0.0-nightly.g1b95ef7 → 0.0.1

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 (64) hide show
  1. package/README.md +1 -3
  2. package/package.json +9 -86
  3. package/dist/app.d.ts +0 -28
  4. package/dist/app.js +0 -66
  5. package/dist/backend.d.ts +0 -31
  6. package/dist/backend.js +0 -182
  7. package/dist/client.d.ts +0 -49
  8. package/dist/client.js +0 -168
  9. package/dist/host/desktop.d.ts +0 -15
  10. package/dist/host/desktop.js +0 -133
  11. package/dist/host/panels.d.ts +0 -14
  12. package/dist/host/panels.js +0 -156
  13. package/dist/host/records.d.ts +0 -5
  14. package/dist/host/records.js +0 -46
  15. package/dist/host/server.d.ts +0 -8
  16. package/dist/host/server.js +0 -67
  17. package/dist/host/web.d.ts +0 -5
  18. package/dist/host/web.js +0 -74
  19. package/dist/macos/index.macos.d.ts +0 -3
  20. package/dist/macos/index.macos.js +0 -5
  21. package/dist/macos/servers.macos.d.ts +0 -4
  22. package/dist/macos/servers.macos.js +0 -57
  23. package/dist/macos/socket.macos.d.ts +0 -2
  24. package/dist/macos/socket.macos.js +0 -152
  25. package/dist/macos/ws-frames.d.ts +0 -24
  26. package/dist/macos/ws-frames.js +0 -205
  27. package/dist/node.d.ts +0 -12
  28. package/dist/node.js +0 -51
  29. package/dist/record.d.ts +0 -9
  30. package/dist/record.js +0 -38
  31. package/dist/types.d.ts +0 -128
  32. package/dist/types.js +0 -25
  33. package/src/app.ts +0 -105
  34. package/src/assets.d.ts +0 -2
  35. package/src/backend.ts +0 -278
  36. package/src/client.ts +0 -248
  37. package/src/desktop/Shell.macos.tsrx +0 -158
  38. package/src/desktop/Shell.ts +0 -16
  39. package/src/desktop/index.macos.ts +0 -7
  40. package/src/desktop/main.macos.ts +0 -130
  41. package/src/desktop/panels.d.ts +0 -10
  42. package/src/desktop/target.ts +0 -34
  43. package/src/host/desktop.ts +0 -176
  44. package/src/host/panels.ts +0 -193
  45. package/src/host/records.ts +0 -62
  46. package/src/host/server.ts +0 -92
  47. package/src/host/web.ts +0 -68
  48. package/src/macos/index.macos.ts +0 -7
  49. package/src/macos/servers.macos.ts +0 -83
  50. package/src/macos/socket.macos.ts +0 -218
  51. package/src/macos/ws-frames.ts +0 -249
  52. package/src/node.ts +0 -60
  53. package/src/panel/App.tsrx +0 -288
  54. package/src/panel/index.html +0 -12
  55. package/src/panel/index.ts +0 -24
  56. package/src/panel/main.tsrx +0 -2
  57. package/src/panel/main.web.tsrx +0 -89
  58. package/src/panel/model.ts +0 -216
  59. package/src/panel/panel.css +0 -189
  60. package/src/panel/plugin.ts +0 -65
  61. package/src/panel/styles.ts +0 -5
  62. package/src/panel/tsconfig.browser.json +0 -9
  63. package/src/record.ts +0 -66
  64. package/src/types.ts +0 -129
@@ -1,218 +0,0 @@
1
- // DevSocket over Network.framework (NWConnection). The JSC host has no
2
- // WebSocket, and NSURLSessionWebSocketTask is unreachable through the bundled
3
- // node-api metadata — webSocketTaskWithURL returns an object whose prototype is
4
- // plain NSURLSessionTask (no ws selectors). C functions are bridged, so the
5
- // connection is opened by hand and frames are codec'd by ./ws-frames.ts.
6
- // Local ws:// only — no TLS.
7
- import { interop, NSData, NSOperationQueue, type NSObject } from '@octane-xplat/platform/macos'
8
- import {
9
- _nw_content_context_default_message,
10
- _nw_parameters_configure_protocol_default_configuration,
11
- _nw_parameters_configure_protocol_disable,
12
- dispatch_data_create,
13
- dispatch_queue_create,
14
- nw_connection_cancel,
15
- nw_connection_create,
16
- nw_connection_receive,
17
- nw_connection_send,
18
- nw_connection_set_queue,
19
- nw_connection_set_state_changed_handler,
20
- nw_connection_start,
21
- nw_endpoint_create_host,
22
- nw_parameters_create_secure_tcp,
23
- } from '@octane-xplat/platform/macos'
24
-
25
- import {
26
- encodeFrame,
27
- FrameDecoder,
28
- handshakeAccept,
29
- handshakeRequest,
30
- utf8Encode,
31
- } from './ws-frames.ts'
32
-
33
- import type { DevSocket } from '../types.ts'
34
-
35
- export function nwDevSocket(url: string): DevSocket | undefined {
36
- const m = /^ws:\/\/([^:/]+):(\d+)(\/.*)$/.exec(url)
37
-
38
- if (!m) {
39
- return undefined
40
- }
41
-
42
- const [, host, port, path] = m
43
-
44
- const queue =
45
- (NSOperationQueue.mainQueue as { underlyingQueue?: NSObject }).underlyingQueue ??
46
- dispatch_queue_create('devtools.ws', null as unknown as NSObject)
47
-
48
- const sendQueue = dispatch_queue_create('devtools.ws.send', null as unknown as NSObject)
49
- const endpoint = nw_endpoint_create_host(host, port)
50
- const params = nw_parameters_create_secure_tcp(
51
- // _disable as the TLS configure block → plain TCP.
52
- _nw_parameters_configure_protocol_disable,
53
- _nw_parameters_configure_protocol_default_configuration,
54
- )
55
-
56
- const conn = nw_connection_create(endpoint, params)
57
-
58
- let closed = false
59
- let ready = false
60
- let handshaken = false
61
-
62
- const socket: DevSocket = {
63
- get readyState() {
64
- // WebSocket constants: 0 CONNECTING, 1 OPEN, 3 CLOSED (no CLOSING — the
65
- // transport has no half-close state to report).
66
- if (closed) {
67
- return 3
68
- }
69
-
70
- return ready ? 1 : 0
71
- },
72
- onopen: null,
73
- onmessage: null,
74
- onerror: null,
75
- onclose: null,
76
- send: () => {},
77
- close: () => {},
78
- }
79
-
80
- const decoder = new FrameDecoder()
81
-
82
- const fail = () => {
83
- if (closed) {
84
- return
85
- }
86
-
87
- closed = true
88
- socket.onerror?.()
89
- socket.onclose?.({ code: 1006, reason: '' })
90
- }
91
-
92
- // dispatch_data_t toll-free bridges with NSData.
93
- function sendBytes(bytes: Uint8Array) {
94
- const data = NSData.dataWithBytesLength(bytes, bytes.length)
95
- const d = dispatch_data_create(
96
- (data as unknown as { bytes: NSObject }).bytes,
97
- bytes.length,
98
- sendQueue,
99
- () => {},
100
- )
101
-
102
- nw_connection_send(conn, d, _nw_content_context_default_message, false, (error: unknown) => {
103
- if (error) {
104
- fail()
105
- }
106
- })
107
- }
108
-
109
- socket.send = (data) => {
110
- if (!ready || closed) {
111
- return
112
- }
113
-
114
- sendBytes(encodeFrame(1, utf8Encode(data)))
115
- }
116
-
117
- socket.close = () => {
118
- if (closed) {
119
- return
120
- }
121
-
122
- closed = true
123
- try {
124
- sendBytes(encodeFrame(8, new Uint8Array(0)))
125
- } catch {}
126
-
127
- nw_connection_cancel(conn)
128
- socket.onclose?.({ code: 1000, reason: '' })
129
- }
130
-
131
- function pump() {
132
- nw_connection_receive(
133
- conn,
134
- 1,
135
- 1 << 20,
136
- (data: NSObject, _ctx: unknown, _complete: boolean, error: unknown) => {
137
- if (error || closed) {
138
- if (!closed) {
139
- fail()
140
- }
141
-
142
- return
143
- }
144
-
145
- try {
146
- if (data) {
147
- if (!handshaken) {
148
- handshakeBuffer = concat(
149
- handshakeBuffer,
150
- new Uint8Array(interop.bufferFromData(data as unknown as NSData)),
151
- )
152
-
153
- const end = handshakeAccept(handshakeBuffer)
154
-
155
- if (end >= 0) {
156
- handshaken = true
157
- ready = true
158
- socket.onopen?.()
159
- for (const ev of decoder.push(handshakeBuffer.subarray(end))) {
160
- deliver(ev)
161
- }
162
- }
163
- } else {
164
- for (const ev of decoder.push(
165
- new Uint8Array(interop.bufferFromData(data as unknown as NSData)),
166
- )) {
167
- deliver(ev)
168
- }
169
- }
170
- }
171
- } catch (e) {
172
- console.error('[devtools socket]', e)
173
- fail()
174
- return
175
- }
176
-
177
- if (!closed) {
178
- pump()
179
- }
180
- },
181
- )
182
- }
183
-
184
- let handshakeBuffer = new Uint8Array(0)
185
- function concat(a: Uint8Array, b: Uint8Array) {
186
- const out = new Uint8Array(a.length + b.length)
187
-
188
- out.set(a, 0)
189
- out.set(b, a.length)
190
- return out
191
- }
192
-
193
- function deliver(ev: ReturnType<FrameDecoder['push']>[number]) {
194
- if (ev.type === 'text') {
195
- socket.onmessage?.({ data: ev.data })
196
- } else if (ev.type === 'close') {
197
- closed = true
198
- nw_connection_cancel(conn)
199
- socket.onclose?.({ code: 1000, reason: '' })
200
- } else if (ev.type === 'ping') {
201
- sendBytes(encodeFrame(10, ev.payload))
202
- }
203
- }
204
-
205
- nw_connection_set_state_changed_handler(conn, (state: number, error: unknown) => {
206
- // nw_connection_state_ready = 3
207
- if (state === 3 && !handshaken) {
208
- sendBytes(handshakeRequest(host, port, path))
209
- } else if (state === 4 || state === 5 || error) {
210
- fail()
211
- }
212
- })
213
-
214
- nw_connection_set_queue(conn, queue)
215
- nw_connection_start(conn)
216
- pump()
217
- return socket
218
- }
@@ -1,249 +0,0 @@
1
- // Pure WebSocket framing: handshake request/accept, masked client frame
2
- // encoding, and an incremental decoder (chunked input, fragmented
3
- // continuation frames, 16/64-bit lengths). No host APIs — node --test-able.
4
-
5
- export function utf8Encode(s: string): Uint8Array {
6
- const out = new Uint8Array(s.length * 4)
7
- let n = 0
8
-
9
- for (let i = 0; i < s.length; i++) {
10
- let c = s.charCodeAt(i)
11
-
12
- if (c >= 0xd800 && c < 0xdc00 && i + 1 < s.length) {
13
- c = 0x10000 + ((c - 0xd800) << 10) + (s.charCodeAt(++i) - 0xdc00)
14
- }
15
-
16
- if (c < 0x80) {
17
- out[n++] = c
18
- } else if (c < 0x800) {
19
- out[n++] = 0xc0 | (c >> 6)
20
- out[n++] = 0x80 | (c & 0x3f)
21
- } else if (c < 0x10000) {
22
- out[n++] = 0xe0 | (c >> 12)
23
- out[n++] = 0x80 | ((c >> 6) & 0x3f)
24
- out[n++] = 0x80 | (c & 0x3f)
25
- } else {
26
- out[n++] = 0xf0 | (c >> 18)
27
- out[n++] = 0x80 | ((c >> 12) & 0x3f)
28
- out[n++] = 0x80 | ((c >> 6) & 0x3f)
29
- out[n++] = 0x80 | (c & 0x3f)
30
- }
31
- }
32
-
33
- return out.subarray(0, n)
34
- }
35
-
36
- export function utf8Decode(bytes: Uint8Array): string {
37
- let s = ''
38
-
39
- for (let i = 0; i < bytes.length; i++) {
40
- const b = bytes[i]
41
-
42
- if (b < 0x80) {
43
- s += String.fromCharCode(b)
44
- } else if (b < 0xe0) {
45
- s += String.fromCharCode(((b & 0x1f) << 6) | (bytes[++i] & 0x3f))
46
- } else if (b < 0xf0) {
47
- s += String.fromCharCode(
48
- ((b & 0x0f) << 12) | ((bytes[++i] & 0x3f) << 6) | (bytes[++i] & 0x3f),
49
- )
50
- } else {
51
- const cp =
52
- ((b & 0x07) << 18) |
53
- ((bytes[++i] & 0x3f) << 12) |
54
- ((bytes[++i] & 0x3f) << 6) |
55
- (bytes[++i] & 0x3f)
56
-
57
- s += String.fromCharCode(0xd800 + ((cp - 0x10000) >> 10), 0xdc00 + ((cp - 0x10000) & 0x3ff))
58
- }
59
- }
60
-
61
- return s
62
- }
63
-
64
- const B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
65
-
66
- export function base64Encode(bytes: Uint8Array): string {
67
- let out = ''
68
-
69
- for (let i = 0; i < bytes.length; i += 3) {
70
- const a = bytes[i],
71
- b = bytes[i + 1],
72
- c = bytes[i + 2]
73
-
74
- out +=
75
- B64[a >> 2] +
76
- B64[((a & 3) << 4) | ((b ?? 0) >> 4)] +
77
- (b === undefined ? '=' : B64[((b & 15) << 2) | ((c ?? 0) >> 6)]) +
78
- (c === undefined ? '=' : B64[c & 63])
79
- }
80
-
81
- return out
82
- }
83
-
84
- export function handshakeRequest(host: string, port: string, path: string): Uint8Array {
85
- const key = base64Encode(utf8Encode(`${Date.now()}${Math.random()}`).subarray(0, 16))
86
- const request =
87
- `GET ${path} HTTP/1.1\r\nHost: ${host}:${port}\r\nUpgrade: websocket\r\n` +
88
- `Connection: Upgrade\r\nSec-WebSocket-Key: ${key}\r\nSec-WebSocket-Version: 13\r\n\r\n`
89
-
90
- return utf8Encode(request)
91
- }
92
-
93
- // Returns the byte offset past the headers on 101, or -1 when incomplete,
94
- // or throws on a rejected upgrade.
95
- export function handshakeAccept(buffer: Uint8Array): number {
96
- const text = utf8Decode(buffer)
97
- const end = text.indexOf('\r\n\r\n')
98
-
99
- if (end < 0) {
100
- return -1
101
- }
102
-
103
- const status = /^HTTP\/[\d.]+ (\d+)/.exec(text)?.[1]
104
-
105
- if (status !== '101') {
106
- throw new Error(`websocket upgrade rejected: ${text.slice(0, end)}`)
107
- }
108
-
109
- return end + 4
110
- }
111
-
112
- export type FrameEvent =
113
- | { type: 'text'; data: string }
114
- | { type: 'close' }
115
- | { type: 'ping'; payload: Uint8Array }
116
- | { type: 'pong'; payload: Uint8Array }
117
-
118
- export function encodeFrame(opcode: number, payload: Uint8Array, maskKey?: Uint8Array): Uint8Array {
119
- const mask = maskKey ?? new Uint8Array(4)
120
-
121
- if (!maskKey) {
122
- for (let i = 0; i < 4; i++) {
123
- mask[i] = (Math.random() * 256) | 0
124
- }
125
- }
126
-
127
- const len = payload.length
128
- const header: number[] = [0x80 | opcode]
129
-
130
- if (len < 126) {
131
- header.push(0x80 | len)
132
- } else if (len < 65536) {
133
- header.push(0x80 | 126, len >> 8, len & 0xff)
134
- } else {
135
- header.push(0x80 | 127)
136
- for (let s = 56; s >= 0; s -= 8) {
137
- header.push(((len / 2 ** s) | 0) & 0xff)
138
- }
139
- }
140
-
141
- const out = new Uint8Array(header.length + 4 + len)
142
-
143
- out.set(header, 0)
144
- out.set(mask, header.length)
145
- for (let i = 0; i < len; i++) {
146
- out[header.length + 4 + i] = payload[i] ^ mask[i & 3]
147
- }
148
-
149
- return out
150
- }
151
-
152
- // Incremental server→client decoder. Server frames arrive unmasked; control
153
- // frames are never fragmented; data frames may fragment — continuation
154
- // payloads accumulate until FIN.
155
- export class FrameDecoder {
156
- private buffer = new Uint8Array(0)
157
- private fragments: Uint8Array[] = []
158
- private fragmentOpcode = -1
159
-
160
- push(chunk: Uint8Array): FrameEvent[] {
161
- const merged = new Uint8Array(this.buffer.length + chunk.length)
162
-
163
- merged.set(this.buffer, 0)
164
- merged.set(chunk, this.buffer.length)
165
- this.buffer = merged
166
-
167
- const events: FrameEvent[] = []
168
-
169
- for (;;) {
170
- if (this.buffer.length < 2) {
171
- return events
172
- }
173
-
174
- const b = this.buffer
175
- const fin = (b[0] & 0x80) !== 0
176
- const opcode = b[0] & 0x0f
177
-
178
- if (b[1] & 0x80) {
179
- throw new Error('masked server frame')
180
- }
181
-
182
- const len0 = b[1] & 0x7f
183
- const off = len0 < 126 ? 2 : len0 === 126 ? 4 : 10
184
- let len = len0
185
-
186
- if (len0 === 126) {
187
- len = (b[2] << 8) | b[3]
188
- } else if (len0 === 127) {
189
- const n =
190
- (BigInt(b[2]) << 56n) |
191
- (BigInt(b[3]) << 48n) |
192
- (BigInt(b[4]) << 40n) |
193
- (BigInt(b[5]) << 32n) |
194
- (BigInt(b[6]) << 24n) |
195
- (BigInt(b[7]) << 16n) |
196
- (BigInt(b[8]) << 8n) |
197
- BigInt(b[9])
198
-
199
- len = Number(n)
200
- }
201
-
202
- if (this.buffer.length < off + len) {
203
- return events
204
- }
205
-
206
- const payload = b.subarray(off, off + len)
207
-
208
- this.buffer = b.subarray(off + len)
209
-
210
- if (opcode === 0) {
211
- if (this.fragmentOpcode < 0) {
212
- throw new Error('continuation without start')
213
- }
214
-
215
- this.fragments.push(payload)
216
- if (fin) {
217
- const total = this.fragments.reduce((n, f) => n + f.length, 0)
218
- const joined = new Uint8Array(total)
219
- let o = 0
220
-
221
- for (const f of this.fragments) {
222
- joined.set(f, o)
223
- o += f.length
224
- }
225
-
226
- this.fragments = []
227
- if (this.fragmentOpcode === 1) {
228
- events.push({ type: 'text', data: utf8Decode(joined) })
229
- }
230
-
231
- this.fragmentOpcode = -1
232
- }
233
- } else if (opcode === 1) {
234
- if (fin) {
235
- events.push({ type: 'text', data: utf8Decode(payload) })
236
- } else {
237
- this.fragmentOpcode = 1
238
- this.fragments = [payload]
239
- }
240
- } else if (opcode === 8) {
241
- events.push({ type: 'close' })
242
- } else if (opcode === 9) {
243
- events.push({ type: 'ping', payload })
244
- } else if (opcode === 10) {
245
- events.push({ type: 'pong', payload })
246
- }
247
- }
248
- }
249
- }
package/src/node.ts DELETED
@@ -1,60 +0,0 @@
1
- // Node-side devtools host entry — `@octane-xplat/devtools/node`.
2
- // The Go `xplat devtools` command (or a direct `node dist/node.js --serve`)
3
- // launches this module; it serves the panel over loopback and prints the
4
- // endpoint as a single JSON line for the launching process.
5
-
6
- import { serveDevtools, type DevtoolsHost } from './host/server.ts'
7
- import { listDevtoolsServers } from './host/records.ts'
8
-
9
- export { serveDevtools, listDevtoolsServers }
10
- export type { DevtoolsHost } from './host/server.ts'
11
- export type { ListedDevtoolsServer } from './host/records.ts'
12
-
13
- /**
14
- * Starts the panel host. `--port N` pins a port (default 0 = ephemeral);
15
- * `--json` reports the endpoint as JSON for launchers, otherwise a URL line
16
- * is printed. Resolves once the server is listening and stays alive until
17
- * SIGINT/SIGTERM.
18
- */
19
- export async function devtoolsHostMain(argv: string[] = process.argv.slice(2)): Promise<void> {
20
- let port = 0
21
- let json = false
22
-
23
- for (let i = 0; i < argv.length; i++) {
24
- if (argv[i] === '--json') {
25
- json = true
26
- } else if (argv[i] === '--port') {
27
- port = Number.parseInt(argv[++i] ?? '', 10)
28
- if (!Number.isInteger(port) || port < 0 || port > 65535) {
29
- throw new Error('devtools host port must be an integer from 0 to 65535')
30
- }
31
- } else {
32
- throw new Error(`Unknown devtools host argument: ${argv[i]}`)
33
- }
34
- }
35
-
36
- const host = await serveDevtools({ port })
37
-
38
- if (json) {
39
- process.stdout.write(`${JSON.stringify({ endpoint: host.endpoint })}\n`)
40
- } else {
41
- process.stdout.write(`Octane Xplat devtools: ${host.endpoint}\n`)
42
- }
43
-
44
- const close = async () => {
45
- await host.close()
46
- process.exit(0)
47
- }
48
-
49
- process.once('SIGINT', close)
50
- process.once('SIGTERM', close)
51
- }
52
-
53
- const invoked = process.argv[1]
54
-
55
- if (invoked && import.meta.url === new URL(`file://${invoked}`).href) {
56
- devtoolsHostMain().catch((error) => {
57
- process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`)
58
- process.exit(1)
59
- })
60
- }