centralu 0.1.0-beta.56 → 0.1.0-beta.58

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.
@@ -109,7 +109,7 @@ function systemdQuote(value, { dollars = false } = {}) {
109
109
  }
110
110
 
111
111
  /**
112
- * The `systemd --user` unit (docs/agent-host.md §4.7 has the hand-written one this follows).
112
+ * The `systemd --user` unit (docs/agent-host/remote/serve.md has the hand-written one this follows).
113
113
  *
114
114
  * - `serve` in the foreground: systemd is what keeps it outside any session.
115
115
  * - `KillMode=mixed`: a stop sends SIGTERM to the launcher only, which passes one to the host, which
@@ -7,7 +7,7 @@ import { existsSync, openSync, rmSync, writeFileSync, writeSync } from 'node:fs'
7
7
  import { userInfo } from 'node:os'
8
8
  import { join } from 'node:path'
9
9
  import { answerLine, isAlive, say, sayTo, runCaptured, tail, sleep } from './serve-util.mjs'
10
- import { SERVE_LOG_FILE, serveDataDir, ensureServeState, markStopped, rotateServeLog, markStarting, clearStarting, liveStarts, lockHolder, isWriter, readServePid } from './serve-files.mjs'
10
+ import { SERVE_LOG_FILE, serveDataDir, ensureServeState, markStopped, rotateServeLog, markStarting, clearStarting, liveStarts, lockHolder, isWriterWithin, isWriter, readServePid, STARTING_MAX_MS } from './serve-files.mjs'
11
11
  import { askPowershell, detachHow, windowsArg, wmiScript, parseWmiAnswer, wmiBlockedMessage, windowsPowershell, windowsTool, wslCommandLine } from './serve-windows.mjs'
12
12
  import { CHILD_FLAG } from './serve-args.mjs'
13
13
  import { startInSignIn } from './serve-autostart.mjs'
@@ -100,7 +100,7 @@ export async function startDetached({ how, execPath, args, env, cwd }) {
100
100
  * `hostRunning: true` and `detach: { ok: true, how, already }`, or `{ v: 1, detach: { ok: false,
101
101
  * how, reason, message } }`. `reason` is `wmi_blocked` when WMI created nothing or created something
102
102
  * that never ran, which the hub answers with a link-bound start; `exited` and `timeout` quote the
103
- * end of serve.log. Exit codes do not survive Windows' ssh (agent-host.md §4.8), so the line is
103
+ * end of serve.log. Exit codes do not survive Windows' ssh (agent-host/remote/hub-links.md), so the line is
104
104
  * what counts; the exit code is 0 or 1 for a person at a prompt.
105
105
  *
106
106
  * `start` and the two waits are parameters so tests can stand in for WMI.
@@ -291,6 +291,7 @@ export async function runStop({
291
291
  graceMs = 10_000,
292
292
  kill = (pid, sig) => process.kill(pid, sig),
293
293
  write = (line) => process.stdout.write(line),
294
+ writer = isWriter,
294
295
  }) {
295
296
  const dataDir = serveDataDir(env, home)
296
297
  const deadline = Date.now() + budgetMs
@@ -311,13 +312,14 @@ export async function runStop({
311
312
  const tookTheFolder = () => {
312
313
  const h = lockHolder(dataDir)
313
314
  const key = h ? `lock:${h.pid}:${h.started}:${h.at}` : null
314
- if (key && !known.has(key)) known.set(key, isWriter(h) === true)
315
+ // A host started in another logon (its creation unreadable) took the folder too: counted for as long as a start takes
316
+ if (key && !known.has(key)) known.set(key, isWriterWithin(h, STARTING_MAX_MS, writer))
315
317
  if (!key || !known.get(key) || !isAlive(h.pid)) return (heldSince = null), false
316
318
  heldSince ??= Date.now()
317
319
  return Date.now() - heldSince > LOCK_GRACE_MS
318
320
  }
319
321
  let waiting = false
320
- for (let starts = liveStarts(dataDir, known); starts.length > 0 && !tookTheFolder(); starts = liveStarts(dataDir, known)) {
322
+ for (let starts = liveStarts(dataDir, known, { writer }); starts.length > 0 && !tookTheFolder(); starts = liveStarts(dataDir, known, { writer })) {
321
323
  if (!waiting) say(`centralu serve is starting a host for ${dataDir}; waiting for it, to stop it`)
322
324
  waiting = true
323
325
  if (Date.now() < deadline - STOP_RESERVE_MS) {
@@ -184,11 +184,12 @@ export function readStarting(dataDir) {
184
184
  * what was learnt of a record between calls (a Windows creation time costs a PowerShell), so a caller that asks again and
185
185
  * again pays it once per record.
186
186
  */
187
- export function liveStarts(dataDir, known = new Map(), { maxAgeMs = STARTING_MAX_MS, now = Date.now(), startOf = processStartTime, createdAt = processCreatedAt } = {}) {
187
+ export function liveStarts(dataDir, known = new Map(), { maxAgeMs = STARTING_MAX_MS, now = Date.now(), startOf = processStartTime, createdAt = processCreatedAt, writer = (r) => isWriter(r, startOf, createdAt) } = {}) {
188
188
  return readStarting(dataDir).filter((r) => {
189
189
  if (typeof r.at === 'number' && now - r.at > maxAgeMs) return false
190
190
  const key = `${r.pid}:${r.started}:${r.at}`
191
- if (!known.has(key)) known.set(key, isWriter(r, startOf, createdAt) === true)
191
+ // A launcher of another logon (creation unreadable) is a live start for as long as a start takes, as records here are
192
+ if (!known.has(key)) known.set(key, isWriterWithin(r, maxAgeMs, writer))
192
193
  return known.get(key) === true && isAlive(r.pid)
193
194
  })
194
195
  }
@@ -484,7 +485,7 @@ export const PAIRED_VIA = ['pair', 'window', 'handover']
484
485
  * same pairer as before and are not marked: marked at every routine pairing, the flag meant nothing. A `--pair window`
485
486
  * taking the window's place, or the window's next start taking that one's, is marked. What this cannot tell is two
486
487
  * askers of the same way: a program's `--pair hub:<name>-<key>` against that hub's own. The hub's row tells that one
487
- * by itself (`hubsName`, and its own credential gone), docs/security-boundaries.md.
488
+ * by itself (`hubsName`, and its own credential gone), docs/security-boundaries/remote-host.md.
488
489
  */
489
490
  export function pairServe(dataDir, label, platform = process.platform, now = Date.now(), via = 'pair') {
490
491
  ensureServeState(dataDir, platform, now)
@@ -694,6 +695,17 @@ export function isWriter(holder, startOf = processStartTime, createdAt = process
694
695
  return created === null ? null : created <= holder.at + CLOCK_TICK_MS
695
696
  }
696
697
 
698
+ /**
699
+ * `isWriter` with its third answer settled: a process that lives but whose creation Windows will not tell (another logon's,
700
+ * `null`) counts as the writer while its record is younger than `maxAgeMs`, by the `at` it wrote. Asking for more
701
+ * (an elevated read, a prompt) is not an option for a launcher; the cost is a stranger that took a dead writer's pid
702
+ * within that time counting as the writer for the rest of it.
703
+ */
704
+ export function isWriterWithin(holder, maxAgeMs, writer = isWriter) {
705
+ const w = writer(holder)
706
+ return w === null ? typeof holder?.at === 'number' && Date.now() - holder.at < maxAgeMs : w
707
+ }
708
+
697
709
  /** One tick of the Windows clock */
698
710
  const CLOCK_TICK_MS = 16
699
711
 
@@ -31,7 +31,7 @@ export function protocolVersionOf(entry) {
31
31
  }
32
32
 
33
33
  /**
34
- * The `--connection` answer. The shape is the client's interface (docs/agent-host.md §4.7).
34
+ * The `--connection` answer. The shape is the client's interface (docs/agent-host/remote/serve.md).
35
35
  * `install` (additive, the line stays `v: 1`) says what runs this command (`installInfo`); `detach`
36
36
  * is added by `--detach` only.
37
37
  */
@@ -18,7 +18,7 @@ import { closeSync, cpSync, existsSync, mkdirSync, openSync, readdirSync, readFi
18
18
  import { randomBytes } from 'node:crypto'
19
19
  import { join } from 'node:path'
20
20
  import { answerLine, replaceFile, runCaptured, say, sleep, tail, waitUntil } from './serve-util.mjs'
21
- import { isWriter, processStartTime, serveDataDir } from './serve-files.mjs'
21
+ import { isWriter, isWriterWithin, processStartTime, serveDataDir } from './serve-files.mjs'
22
22
  import { POINTER_WORD, managedLauncherScript, parsePointer, remoteLayout } from './serve-install.mjs'
23
23
  import { detachHow } from './serve-windows.mjs'
24
24
 
@@ -97,8 +97,7 @@ function readPointerFile(file) {
97
97
  /** Whether `switch.lock` names a live switcher (`isWriter`), a Windows pid of another logon counting for a while */
98
98
  export function lockIsLive(holder, writer = isWriter) {
99
99
  if (!holder || !Number.isInteger(holder.pid)) return false
100
- const w = writer(holder)
101
- return w === null ? Date.now() - holder.at < UNREADABLE_ALIVE_MS : w
100
+ return isWriterWithin(holder, UNREADABLE_ALIVE_MS, writer)
102
101
  }
103
102
 
104
103
  /**
package/bin/serve.mjs CHANGED
@@ -5,7 +5,7 @@
5
5
  * same bundled host the app runs (`resources/host/main.mjs`, on the system Node), with no window
6
6
  * and no keeper, bound to 127.0.0.1 only. The app on the person's own computer reaches it through
7
7
  * an SSH local forward, so nothing ever listens on a public interface. The design and its limits
8
- * are in docs/agent-host.md §4.7; the trust argument in docs/security-boundaries.md.
8
+ * are in docs/agent-host/remote/serve.md; the trust argument in docs/security-boundaries/remote-host.md.
9
9
  *
10
10
  * `centralu serve --connection` is the one question the client asks over `ssh <target>`: where to
11
11
  * forward and how to authenticate. It answers with one JSON line on stdout and nothing else.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "centralu",
3
- "version": "0.1.0-beta.56",
3
+ "version": "0.1.0-beta.58",
4
4
  "description": "Run, watch and steer several Claude Code and Codex CLI sessions from one window",
5
5
  "license": "MIT",
6
6
  "author": "ijun17",
@@ -38,9 +38,9 @@
38
38
  "win32"
39
39
  ],
40
40
  "optionalDependencies": {
41
- "@centralu/darwin-arm64": "0.1.0-beta.56",
42
- "@centralu/linux-arm64": "0.1.0-beta.56",
43
- "@centralu/linux-x64": "0.1.0-beta.56",
44
- "@centralu/win32-x64": "0.1.0-beta.56"
41
+ "@centralu/darwin-arm64": "0.1.0-beta.58",
42
+ "@centralu/linux-arm64": "0.1.0-beta.58",
43
+ "@centralu/linux-x64": "0.1.0-beta.58",
44
+ "@centralu/win32-x64": "0.1.0-beta.58"
45
45
  }
46
46
  }