@centralu/host-linux-x64 0.1.0-beta.42 → 0.1.0-beta.44

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.
@@ -11,18 +11,20 @@
11
11
  * what the terminals do on stdout.
12
12
  *
13
13
  * - in: `{op:'spawn', id, file, args, cwd, env, cols, rows}` · `{op:'write', id, data}` · `{op:'resize', id, cols, rows}`
14
- * · `{op:'kill', id}`
14
+ * · `{op:'kill', id}` · `{op:'open', url}` (an `https` address in the person's browser, review of #1685)
15
15
  * - out: `{ev:'ready'}` once · `{ev:'spawned', id, pid}` · `{ev:'error', id, message}` · `{ev:'data', id, data}` ·
16
16
  * `{ev:'exit', id, exitCode, signal}`
17
17
  *
18
18
  * Its stdin closing means the host is gone: it exits, which closes every pseudoconsole and so ends each shell as the
19
19
  * host's own would have. What a shell started outside its console stays.
20
20
  */
21
+ import { spawn } from 'node:child_process'
21
22
  import { createRequire } from 'node:module'
22
23
  import { createInterface } from 'node:readline'
23
24
 
24
25
  const require = createRequire(import.meta.url)
25
- const pty = require('node-pty')
26
+ /** node-pty, loaded as the broker starts (`main`); a test that imports this file for `handle` loads none */
27
+ let pty
26
28
 
27
29
  /** @type {Map<number, any>} */
28
30
  const ptys = new Map()
@@ -48,7 +50,25 @@ function spawnPty(m) {
48
50
  }
49
51
  }
50
52
 
51
- function handle(m) {
53
+ /**
54
+ * The person's browser at an address (Antigravity's sign-in page): started from here, outside the host's job, so it
55
+ * outlives the sign-in and the host. `detached`, so libuv puts it in no job of this process's either (it ends with this
56
+ * one otherwise); never through a shell, and only an `https` address. `start` is `spawn` (a test gives its own)
57
+ */
58
+ function open(url, start) {
59
+ if (typeof url !== 'string' || !/^https:\/\//i.test(url)) return
60
+ try {
61
+ const child = start('rundll32', ['url.dll,FileProtocolHandler', url], { detached: true, stdio: 'ignore', windowsHide: true })
62
+ child.on('error', () => {})
63
+ child.unref()
64
+ } catch {
65
+ // The sign-in times out, which says the browser did not open
66
+ }
67
+ }
68
+
69
+ /** One request from the host. `start` starts what `open` opens: `spawn`, or a test's stand-in so no browser opens */
70
+ export function handle(m, start = spawn) {
71
+ if (m.op === 'open') return open(m.url, start)
52
72
  if (m.op === 'spawn') {
53
73
  let p
54
74
  try {
@@ -81,16 +101,22 @@ function handle(m) {
81
101
  }
82
102
  }
83
103
 
84
- const lines = createInterface({ input: process.stdin })
85
- lines.on('line', (line) => {
86
- let m
87
- try {
88
- m = JSON.parse(line)
89
- } catch {
90
- return
91
- }
92
- handle(m)
93
- })
94
- // The host is gone (closed, crashed, killed): every pseudoconsole closes with this process
95
- lines.on('close', () => process.exit(0))
96
- send({ ev: 'ready' })
104
+ function main() {
105
+ pty = require('node-pty')
106
+ const lines = createInterface({ input: process.stdin })
107
+ lines.on('line', (line) => {
108
+ let m
109
+ try {
110
+ m = JSON.parse(line)
111
+ } catch {
112
+ return
113
+ }
114
+ handle(m)
115
+ })
116
+ // The host is gone (closed, crashed, killed): every pseudoconsole closes with this process
117
+ lines.on('close', () => process.exit(0))
118
+ send({ ev: 'ready' })
119
+ }
120
+
121
+ // Started as the broker (`node pty-broker.mjs`, which every start is); a test imports it with this flag set to read `handle`
122
+ if (!globalThis.__ccPtyBrokerImported) main()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centralu/host-linux-x64",
3
- "version": "0.1.0-beta.42",
3
+ "version": "0.1.0-beta.44",
4
4
  "description": "Centralu's host without the window, for Linux on x86-64: what a hub installs on a linked machine",
5
5
  "license": "MIT",
6
6
  "author": "ijun17",
@@ -16,6 +16,7 @@
16
16
  "x64"
17
17
  ],
18
18
  "files": [
19
- "host"
19
+ "host",
20
+ "centralu-keeper"
20
21
  ]
21
22
  }