@pi-chamber/web 0.8.2 → 0.9.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 (117) hide show
  1. package/README.md +22 -6
  2. package/bin/cli.js +16 -3
  3. package/bin/cli.test.js +62 -0
  4. package/bin/lib/DOCUMENTATION.md +6 -6
  5. package/bin/lib/cli-args.js +26 -7
  6. package/bin/lib/cli-lifecycle.js +3 -0
  7. package/bin/lib/cli-paths.js +6 -0
  8. package/bin/lib/cli-process.js +1 -0
  9. package/bin/lib/cli-tunnel-profiles.js +15 -10
  10. package/bin/lib/commands-connect-url.js +9 -1
  11. package/bin/lib/commands-lifecycle.js +14 -0
  12. package/bin/lib/commands-logs.js +24 -5
  13. package/bin/lib/commands-serve.js +176 -4
  14. package/bin/lib/commands-tunnel.js +35 -0
  15. package/bin/lib/commands-update.js +107 -39
  16. package/bin/lib/commands-update.test.js +97 -1
  17. package/dist/assets/{DiagramEditor-DerMrS6m.js → DiagramEditor-DoEOH0hY.js} +1 -1
  18. package/dist/assets/{DiagramView-DdipXAq8.js → DiagramView-y9Ystuhv.js} +1 -1
  19. package/dist/assets/DiffView-ScM4XoqZ.js +18 -0
  20. package/dist/assets/{FilesView-BXp0yc0j.js → FilesView-CjkhMFqJ.js} +3 -3
  21. package/dist/assets/GitView-Bqi6H8I-.js +8 -0
  22. package/dist/assets/JsonTreeView-DWhlH6NK.js +1 -0
  23. package/dist/assets/{MarkdownRendererImpl-DNZQgQua.js → MarkdownRendererImpl-CEOKZ1qH.js} +1 -1
  24. package/dist/assets/{PatchDiff-B_NFEIX7.js → PatchDiff-ClnfJJ2J.js} +1 -1
  25. package/dist/assets/{SessionSwitcherContent-Q4P2TGBr.js → SessionSwitcherContent-e6JzUXD_.js} +1 -1
  26. package/dist/assets/{SessionSwitcherDropdown-Cgw2mQIO.js → SessionSwitcherDropdown-C4etG8dv.js} +2 -2
  27. package/dist/assets/{SessionUnreadDot-BxtTkvHB.js → SessionUnreadDot-BVTSwRiG.js} +1 -1
  28. package/dist/assets/SettingsView-C0S0Sx-S.js +2 -0
  29. package/dist/assets/{SettingsWindow-BEjHL1ET.js → SettingsWindow-Cy9tmnMg.js} +1 -1
  30. package/dist/assets/ToolOutputDialog-Csrc0Uk2.js +8 -0
  31. package/dist/assets/{ToolPartDiffPreview-ClV785zX.js → ToolPartDiffPreview-6oH6KD44.js} +1 -1
  32. package/dist/assets/{VirtualizedFileDiff-DrxkW2WQ.js → VirtualizedFileDiff-DJNcTQNp.js} +4 -4
  33. package/dist/assets/{collapsible-CR3-hRMy.js → collapsible-DxgVLhi9.js} +1 -1
  34. package/dist/assets/computeVirtualFileMetrics-B-WoeBMW.js +3 -0
  35. package/dist/assets/{contextFileOpenGuard-BRc5Z0g-.js → contextFileOpenGuard-DQ4U9xRH.js} +1 -1
  36. package/dist/assets/gitStatusPredicates-CIFSGjJs.js +134 -0
  37. package/dist/assets/index-D2C3q2xD.js +8 -0
  38. package/dist/assets/index-DNoEeZ2U.css +1 -0
  39. package/dist/assets/{index-CMfiVUIr.js → index-DmNPBaSo.js} +1 -1
  40. package/dist/assets/{isDiffPlainText-MmBA1REG.js → isDiffPlainText-CrvpUauF.js} +1 -1
  41. package/dist/assets/{isFilePlainText-bQAPxqO9.js → isFilePlainText-CKvhS32g.js} +1 -1
  42. package/dist/assets/{main-zZrKd3hZ.js → main-BFv8slLp.js} +2 -2
  43. package/dist/assets/main-CjM7g4Gq.js +135 -0
  44. package/dist/assets/{markdownCore-B9jXCPry.js → markdownCore-DKrraAqT.js} +1 -1
  45. package/dist/assets/{miniChat-Di2oVS5o.js → miniChat-hQnLS5mt.js} +2 -2
  46. package/dist/assets/{mobile-VU_G_SgX.js → mobile-DuXOBGs_.js} +2 -2
  47. package/dist/assets/renderElectronMiniChatApp-ClJBZVGy.js +2 -0
  48. package/dist/assets/renderMobileApp-DofX2wjB.js +11 -0
  49. package/dist/assets/runtimeEndpointReset-BZeYg6eN.js +54 -0
  50. package/dist/assets/{runtimeSurface-CBaS2Ank.js → runtimeSurface-C7CBxDbh.js} +1 -1
  51. package/dist/assets/{useAppFontEffects-8ZU-TTIW.js → useAppFontEffects-Cs0f1dKn.js} +102 -102
  52. package/dist/assets/{useFilesViewSearch-COow9O9x.js → useFilesViewSearch-D1hcbBEc.js} +1 -1
  53. package/dist/assets/usePushVisibilityBeacon-DqHkuVS5.js +10 -0
  54. package/dist/assets/{useSwitcherItems-DOQqhi-e.js → useSwitcherItems-BEoW7LlC.js} +1 -1
  55. package/dist/assets/{vendor-codemirror-language-data-B_0wrsbo.js → vendor-codemirror-language-data-B8Ac62S_.js} +2 -2
  56. package/dist/assets/{vendor-dnd-kit-core-CP8ck10N.js → vendor-dnd-kit-core-C9qcAm_1.js} +1 -1
  57. package/dist/assets/{vendor-dnd-kit-sortable-B-Icjoj4.js → vendor-dnd-kit-sortable-D8ozj8M-.js} +1 -1
  58. package/dist/assets/vendor-xterm-addon-fit-DX4qG4td.js +1 -0
  59. package/dist/assets/vendor-xterm-xterm-CrXqRur4.js +16 -0
  60. package/dist/assets/vendor-xterm-xterm-DDGTF8rc.css +1 -0
  61. package/dist/assets/{web-components-C9ENH49P.js → web-components-Dy-Tz_LJ.js} +3 -3
  62. package/dist/index.html +4 -4
  63. package/dist/mini-chat.html +3 -3
  64. package/dist/mobile.html +3 -3
  65. package/package.json +3 -4
  66. package/server/index.js +26 -7
  67. package/server/lib/client-auth/pairing.js +13 -2
  68. package/server/lib/client-auth/remote-clients.js +13 -2
  69. package/server/lib/fs/DOCUMENTATION.md +3 -1
  70. package/server/lib/fs/routes.test.js +74 -0
  71. package/server/lib/git/DOCUMENTATION.md +1 -1
  72. package/server/lib/git/identity-storage.js +10 -1
  73. package/server/lib/package-manager.js +1 -1
  74. package/server/lib/package-manager.test.js +11 -0
  75. package/server/lib/pi/archive-store.js +3 -2
  76. package/server/lib/pi/model-config-store.js +6 -2
  77. package/server/lib/pi/routes.js +11 -2
  78. package/server/lib/pi/session-daemon/DOCUMENTATION.md +12 -6
  79. package/server/lib/pi/session-daemon/daemon-process.js +48 -13
  80. package/server/lib/pi/session-daemon/session-daemon.js +226 -40
  81. package/server/lib/pi/session-daemon/session-daemon.test.js +207 -0
  82. package/server/lib/pi/session-daemon/session-lease.js +151 -0
  83. package/server/lib/pi/session-daemon/session-lease.test.js +108 -0
  84. package/server/lib/pi/session-daemon/supervisor.js +244 -54
  85. package/server/lib/pi/session-daemon/supervisor.test.js +202 -6
  86. package/server/lib/pi/session-folders-store.js +20 -2
  87. package/server/lib/pi/session-folders-store.test.js +17 -0
  88. package/server/lib/pi/settings-store.js +3 -2
  89. package/server/lib/pi/snippets-store.js +4 -1
  90. package/server/lib/pi/ui-settings-store.js +3 -2
  91. package/server/lib/server/cross-process-lock.js +112 -0
  92. package/server/lib/server/cross-process-lock.test.js +70 -0
  93. package/server/lib/server/server-profile.js +110 -0
  94. package/server/lib/server/server-profile.test.js +58 -0
  95. package/server/lib/server/tunnel-service.DOCUMENTATION.md +7 -8
  96. package/server/lib/server/tunnel-service.js +8 -1
  97. package/server/lib/stt/DOCUMENTATION.md +1 -1
  98. package/server/lib/stt/config-store.js +3 -2
  99. package/server/lib/terminal/DOCUMENTATION.md +3 -3
  100. package/server/lib/tunnels/DOCUMENTATION.md +38 -18
  101. package/server/lib/ui-auth/ui-auth.js +9 -2
  102. package/server/lib/ui-auth/ui-passkeys.js +9 -1
  103. package/dist/assets/DiffView-Gh9wjthp.js +0 -18
  104. package/dist/assets/GitView-BmNCkkoC.js +0 -8
  105. package/dist/assets/JsonTreeView-CxXRXXzk.js +0 -1
  106. package/dist/assets/SettingsView-CFzxRzUq.js +0 -2
  107. package/dist/assets/ToolOutputDialog-C_7vJLEq.js +0 -8
  108. package/dist/assets/computeVirtualFileMetrics-D0mQcleY.js +0 -3
  109. package/dist/assets/gitStatusPredicates-DBGDfr1K.js +0 -134
  110. package/dist/assets/index-CzO3ooje.css +0 -1
  111. package/dist/assets/index-ivrh3jfy.js +0 -8
  112. package/dist/assets/main-BoVfUG73.js +0 -135
  113. package/dist/assets/renderElectronMiniChatApp-Bi1927c8.js +0 -2
  114. package/dist/assets/renderMobileApp-D9mxhuaM.js +0 -11
  115. package/dist/assets/runtimeEndpointReset-DImT35Ug.js +0 -54
  116. package/dist/assets/usePushVisibilityBeacon-zYd3ppNh.js +0 -10
  117. package/dist/assets/vendor-ghostty-web-CrxinGGH.js +0 -13
package/README.md CHANGED
@@ -5,20 +5,36 @@ PiChamber's web server and browser UI for the Pi coding-agent runtime.
5
5
  ## Run
6
6
 
7
7
  ```bash
8
- pichamber serve --port 3000
8
+ pichamber serve
9
9
  ```
10
10
 
11
- The server starts warming the local Pi session daemon as soon as HTTP is listening, serves the browser UI, and exposes authenticated Pi routes under `/api/pi/*`. HTTP readiness does not wait for Pi provider/model initialization; early Pi requests share the supervisor's in-flight startup.
11
+ In an interactive terminal, `pichamber serve` guides you through access, port,
12
+ authentication, browser UI versus API-only content, and background versus
13
+ foreground process mode. It shows a review before starting. The server starts
14
+ warming the local Pi session daemon as soon as HTTP is listening, serves the
15
+ browser UI, and exposes authenticated Pi routes under `/api/pi/*`. HTTP
16
+ readiness does not wait for Pi provider/model initialization; early Pi requests
17
+ share the supervisor's in-flight startup.
18
+
19
+ For scripts and non-interactive shells, pass the setup flags explicitly:
12
20
 
13
21
  ```bash
14
- pichamber serve --port 8080
15
- pichamber serve --lan --ui-password <password>
22
+ pichamber serve --port 3000 --ui-password <password>
23
+ pichamber serve --port 8080 --lan --ui-password <password>
24
+ pichamber serve --port 3000 --api-only --ui-password <password>
16
25
  pichamber connect-url --port 3000 --qr
17
- pichamber stop
26
+ pichamber stop --port 3000
18
27
  ```
19
28
 
29
+ `--quiet` and `--json` never prompt. Use `pichamber stop --force` when a broad
30
+ stop should skip confirmation, and `pichamber logs --no-follow` for a one-time
31
+ log tail. Use `pichamber update --yes` to update without the interactive review.
32
+
20
33
  Use `--api-only` for a host intended to be paired from a PiChamber desktop or mobile client. LAN-bound servers require a UI password unless the explicit unsafe-development override is set.
21
34
 
35
+ See the [CLI guide](../docs/content/docs/cli.mdx) for guided startup, updates,
36
+ tunnels, logs, pairing, and machine-readable output.
37
+
22
38
  ## Runtime contract
23
39
 
24
40
  - Pi session state and actions are served only through `/api/pi/*`.
@@ -27,7 +43,7 @@ Use `--api-only` for a host intended to be paired from a PiChamber desktop or mo
27
43
  - Final-only speech-to-text uses authenticated `/api/stt/*` routes and `/api/stt/ws`. Local model inference runs in a forked worker, while remote provider credentials remain in server configuration.
28
44
  - Browser and paired clients authenticate with UI sessions or scoped client credentials.
29
45
  - `connect-url` creates a one-time pairing link; credentials are not written to URLs or logs.
30
- - The server owns the Pi daemon lifecycle and stops its locally managed daemon during shutdown.
46
+ - The server owns its per-profile Pi daemon lifecycle (installed web, development web, and desktop use separate namespaces) and stops only its own daemon during shutdown.
31
47
 
32
48
  ## Development
33
49
 
package/bin/cli.js CHANGED
@@ -191,8 +191,18 @@ commands.update = createUpdateCommand({
191
191
  });
192
192
 
193
193
  async function main() {
194
+ // Seed output mode before parsing so syntax errors such as a missing option
195
+ // value still honor the strict --json contract.
196
+ const rawArgs = process.argv.slice(2);
197
+ activeCommandOptions = {
198
+ json: rawArgs.some((arg) => arg === '--json' || arg.startsWith('--json=')),
199
+ quiet: rawArgs.some((arg) => arg === '--quiet' || arg === '-q'),
200
+ };
194
201
  const parsed = parseArgs();
195
- const { command, subcommand, tunnelAction, startupAction, options, removedFlagErrors, helpRequested, versionRequested } = parsed;
202
+ const { command, explicitCommand, subcommand, tunnelAction, startupAction, options, removedFlagErrors, helpRequested, versionRequested } = parsed;
203
+ if (command === 'serve' && explicitCommand) {
204
+ options.offerInteractiveSetup = true;
205
+ }
196
206
  activeCommandOptions = options;
197
207
 
198
208
  if (versionRequested || command === 'version') {
@@ -245,7 +255,7 @@ async function main() {
245
255
  }
246
256
 
247
257
  if (!commands[command]) {
248
- const knownCommands = ['serve', 'stop', 'restart', 'status', 'tunnel', 'startup', 'logs', 'update', 'version'];
258
+ const knownCommands = ['serve', 'stop', 'restart', 'status', 'tunnel', 'startup', 'logs', 'connect-url', 'update', 'version'];
249
259
  const suggestion = findClosestMatch(command, knownCommands);
250
260
  const hint = suggestion ? ` Did you mean '${suggestion}'?` : '';
251
261
  if (isJsonMode(options)) {
@@ -263,7 +273,10 @@ async function main() {
263
273
  process.exit(EXIT_CODE.USAGE_ERROR);
264
274
  }
265
275
 
266
- await commands[command](options);
276
+ const commandResult = await commands[command](options);
277
+ if (commandResult && Number.isInteger(commandResult.exitCode)) {
278
+ process.exitCode = commandResult.exitCode;
279
+ }
267
280
  }
268
281
 
269
282
  const isCliExecution = isModuleCliExecution(process.argv[1], import.meta.url, fs.realpathSync, 'pichamber');
package/bin/cli.test.js CHANGED
@@ -316,6 +316,18 @@ describe('cli args', () => {
316
316
  expect(parsed.options.lan).toBe(true);
317
317
  });
318
318
 
319
+ it('tracks explicit serve commands and update confirmation flags', () => {
320
+ expect(parseArgs(['serve']).explicitCommand).toBe(true);
321
+ expect(parseArgs([]).explicitCommand).toBe(false);
322
+ expect(parseArgs(['update', '--yes']).options.yes).toBe(true);
323
+ expect(parseArgs(['update', '-y']).options.yes).toBe(true);
324
+ });
325
+
326
+ it('rejects invalid log line counts instead of silently using the default', () => {
327
+ expect(() => parseArgs(['logs', '--lines', 'not-a-number'])).toThrow(/Invalid lines value/);
328
+ expect(() => parseArgs(['logs', '--lines', '0'])).toThrow(/Invalid lines value/);
329
+ });
330
+
319
331
  it('supports --hostname as top-level bind alias', () => {
320
332
  const parsed = parseArgs(['serve', '--hostname', '0.0.0.0']);
321
333
 
@@ -330,6 +342,43 @@ describe('cli args', () => {
330
342
  });
331
343
  });
332
344
 
345
+ describe('serve command helper', () => {
346
+ it('collects a reviewed LAN server configuration', async () => {
347
+ const { collectInteractiveServeOptions } = await import('./lib/commands-serve.js');
348
+ const answers = ['lan', '8080', 'generate', 'api', 'daemon', true];
349
+ const prompts = {
350
+ select: async () => answers.shift(),
351
+ text: async () => answers.shift(),
352
+ password: async () => answers.shift(),
353
+ confirm: async () => answers.shift(),
354
+ isCancel: () => false,
355
+ cancel: () => {},
356
+ };
357
+
358
+ const result = await collectInteractiveServeOptions({ port: 3000 }, prompts);
359
+
360
+ expect(result).toMatchObject({
361
+ host: '0.0.0.0',
362
+ lan: true,
363
+ port: 8080,
364
+ explicitPort: true,
365
+ uiPassword: '',
366
+ explicitUiPassword: true,
367
+ apiOnly: true,
368
+ foreground: false,
369
+ });
370
+ });
371
+
372
+ it('detects flags that suppress interactive server setup', async () => {
373
+ const { hasExplicitServeConfiguration } = await import('./lib/commands-serve.js');
374
+
375
+ expect(hasExplicitServeConfiguration({ explicitPort: true })).toBe(true);
376
+ expect(hasExplicitServeConfiguration({ foreground: true })).toBe(true);
377
+ expect(hasExplicitServeConfiguration({ apiOnly: true })).toBe(true);
378
+ expect(hasExplicitServeConfiguration({ port: 3000 })).toBe(false);
379
+ });
380
+ });
381
+
333
382
  describe('startup enable command helper', () => {
334
383
  it('collects LAN, port, and generated-password choices interactively', async () => {
335
384
  const { collectInteractiveStartupOptions } = await import('./lib/commands-startup.js');
@@ -441,6 +490,19 @@ describe('startup enable command helper', () => {
441
490
  });
442
491
 
443
492
  describe('version command', () => {
493
+ it('keeps JSON output strict when argument parsing fails', () => {
494
+ const result = spawnSync(process.execPath, [new URL('./cli.js', import.meta.url).pathname, '--json', '--port'], {
495
+ encoding: 'utf8',
496
+ });
497
+
498
+ expect(result.status).toBe(2);
499
+ expect(result.stderr).toBe('');
500
+ expect(JSON.parse(result.stdout)).toMatchObject({
501
+ status: 'error',
502
+ error: { message: 'Missing value for --port.' },
503
+ });
504
+ });
505
+
444
506
  it('prints the installed package version', () => {
445
507
  const packageJson = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
446
508
  const result = spawnSync(process.execPath, [new URL('./cli.js', import.meta.url).pathname, 'version'], {
@@ -4,15 +4,15 @@ This directory contains non-entrypoint PiChamber CLI implementation. `../cli.js`
4
4
 
5
5
  ## Commands
6
6
 
7
- - `commands-serve.js`: server startup, PID/instance registry, and foreground/background lifecycle.
8
- - `commands-lifecycle.js`: stop and restart behavior.
7
+ - `commands-serve.js`: server startup, PID/instance registry, and foreground/background lifecycle. Explicit `pichamber serve` with no setup flags opens an interactive access, port, authentication, content, and process-mode wizard. Bare `pichamber`, flag-driven runs, non-TTY, `--quiet`, and `--json` remain non-interactive.
8
+ - `commands-lifecycle.js`: stop and restart behavior. Interactive broad stops require confirmation when more than one instance will be affected; `--force` skips it.
9
9
  - `commands-status.js`: running-instance and tunnel status presentation.
10
- - `commands-logs.js`: log discovery, tailing, and follow behavior.
10
+ - `commands-logs.js`: log discovery, tailing, and follow behavior. Quiet mode emits raw log lines, while multi-instance output retains port prefixes.
11
11
  - `commands-startup.js`: native startup service management. Interactive `startup enable` walks through access, port, authentication, and confirmation when no setup flags are supplied. Flag-driven, non-TTY, `--quiet`, and `--json` runs remain non-interactive. The command stores serve flags (`--port`, `--lan`/`--host`, `--ui-password`, `--api-only`) in the native service. Re-running enable rewrites and restarts a systemd unit so the new settings take effect immediately. LAN binds require a UI password, matching `pichamber serve`.
12
- - `commands-connect-url.js`: authenticated direct/relay pairing links.
12
+ - `commands-connect-url.js`: authenticated direct/relay pairing links. Auto-started servers run silently inside the command; `--json` and non-TTY output contain only the requested machine-readable/link result, and QR art is interactive-terminal-only.
13
13
  - `pichamber version` and `pichamber --version`: print the installed package version; `--json` returns the same value as JSON.
14
- - `commands-update.js`: package update and restart coordination. Updates only a global install owned by the running CLI. A Linux user systemd unit is restarted in place; the command does not spawn a replacement server on the same port.
15
- - `commands-tunnel.js`: tunnel lifecycle and profile management.
14
+ - `commands-update.js`: package update and restart coordination. Interactive updates review the old and target versions and restart impact before installation; `--yes` skips confirmation. Updates only a global install owned by the running CLI. Package-manager output is suppressed for `--quiet`/`--json`; results distinguish the previous, installed, and latest versions and report partial restart failures with a non-zero CLI exit. A Linux user systemd unit is restarted in place; the command does not spawn a replacement server on the same port.
15
+ - `commands-tunnel.js`: tunnel lifecycle and profile management. Interactive tunnel setup ends with a review and confirmation; fully specified flag and profile runs remain direct. Auto-started servers never write nested output into the parent command's `--quiet` or `--json` result.
16
16
 
17
17
  ## Rules
18
18
 
@@ -104,6 +104,7 @@ function parseArgs(argv = process.argv.slice(2)) {
104
104
  timeout: undefined,
105
105
  lastAssistant: false,
106
106
  withStatus: false,
107
+ yes: false,
107
108
  };
108
109
 
109
110
  const removedFlagErrors = [];
@@ -360,10 +361,14 @@ function parseArgs(argv = process.argv.slice(2)) {
360
361
  case 'lines': {
361
362
  const { value, nextIndex } = consumeValue(i, inlineValue);
362
363
  i = nextIndex;
363
- const parsed = parseInt(value ?? '', 10);
364
- if (Number.isFinite(parsed) && parsed > 0) {
365
- options.lines = parsed;
364
+ if (typeof value !== 'string' || !/^\d+$/.test(value.trim())) {
365
+ throw new TunnelCliError('Invalid lines value. Provide a positive integer.', EXIT_CODE.USAGE_ERROR);
366
+ }
367
+ const parsed = Number(value);
368
+ if (!Number.isSafeInteger(parsed) || parsed < 1) {
369
+ throw new TunnelCliError('Invalid lines value. Provide a positive integer.', EXIT_CODE.USAGE_ERROR);
366
370
  }
371
+ options.lines = parsed;
367
372
  break;
368
373
  }
369
374
  case 'limit': {
@@ -403,6 +408,10 @@ function parseArgs(argv = process.argv.slice(2)) {
403
408
  case 'q':
404
409
  options.quiet = true;
405
410
  break;
411
+ case 'yes':
412
+ case 'y':
413
+ options.yes = true;
414
+ break;
406
415
  case 'help':
407
416
  case 'h':
408
417
  helpRequested = true;
@@ -450,6 +459,7 @@ function parseArgs(argv = process.argv.slice(2)) {
450
459
  }
451
460
  }
452
461
 
462
+ const explicitCommand = positional.length > 0;
453
463
  const command = positional[0] || 'serve';
454
464
  const subcommand = command === 'tunnel' ? (positional[1] || 'help') : null;
455
465
  const tunnelAction = command === 'tunnel' ? (positional[2] || null) : null;
@@ -465,6 +475,7 @@ function parseArgs(argv = process.argv.slice(2)) {
465
475
 
466
476
  return {
467
477
  command,
478
+ explicitCommand,
468
479
  subcommand,
469
480
  tunnelAction,
470
481
  startupAction,
@@ -483,7 +494,7 @@ USAGE:
483
494
  pichamber [COMMAND] [OPTIONS]
484
495
 
485
496
  COMMANDS:
486
- serve Start the web server (daemon default)
497
+ serve Configure and start the web server (guided in interactive terminals)
487
498
  stop Stop running instance(s)
488
499
  restart Stop and start the server
489
500
  status Show server status
@@ -505,6 +516,7 @@ OPTIONS:
505
516
  --api-only Start API routes only, without serving browser UI assets
506
517
  --foreground Run server in foreground (use with systemd/process managers)
507
518
  --no-daemon Alias for --foreground
519
+ -y, --yes Confirm update without prompting
508
520
  -h, --help Show help
509
521
  -v, --version Show version
510
522
 
@@ -520,7 +532,8 @@ EXAMPLES:
520
532
  pichamber # Start in daemon mode on default port 3000 (or free port)
521
533
  pichamber --port 8080 # Start on port 8080 (daemon)
522
534
  pichamber --lan --port 3002 # Start on LAN at 0.0.0.0:3002
523
- pichamber serve --foreground # Start in foreground (for systemd Type=simple)
535
+ pichamber serve # Walk through interactive server setup
536
+ pichamber serve --foreground # Start in foreground without setup prompts
524
537
  pichamber connect-url --port 3000 --qr
525
538
  pichamber connect-url --server https://pichamber.example.com
526
539
  pichamber startup enable --lan --port 3002 --ui-password
@@ -719,10 +732,10 @@ _pichamber_tunnel() {
719
732
  cur="\${COMP_WORDS[COMP_CWORD]}"
720
733
  prev="\${COMP_WORDS[COMP_CWORD-1]}"
721
734
 
722
- commands="serve stop restart status tunnel logs update"},{
735
+ commands="serve stop restart status tunnel startup logs connect-url update version"
723
736
  tunnel_commands="help providers ready doctor status start stop profile completion"
724
737
  profile_commands="list show add remove"
725
- common_flags="--port --foreground --no-daemon --json --all --help --version --plain --quiet"
738
+ common_flags="--port --host --lan --ui-password --api-only --foreground --no-daemon --json --all --help --version --plain --quiet --yes"
726
739
  start_flags="--provider --mode --profile --config --token --token-file --token-stdin --hostname --connect-ttl --session-ttl --qr --no-qr --dry-run --show-secrets"
727
740
 
728
741
  if [[ \${COMP_CWORD} -eq 1 ]]; then
@@ -772,8 +785,11 @@ _pichamber() {
772
785
  'restart:Stop and start the server'
773
786
  'status:Show server status'
774
787
  'tunnel:Tunnel lifecycle commands'
788
+ 'startup:Manage launch at system startup'
775
789
  'logs:Tail PiChamber logs'
790
+ 'connect-url:Generate a client pairing URL'
776
791
  'update:Check for and install updates'
792
+ 'version:Show the installed version'
777
793
  )
778
794
 
779
795
  tunnel_commands=(
@@ -834,8 +850,11 @@ complete -c pichamber -n '__fish_use_subcommand' -a 'stop' -d 'Stop running inst
834
850
  complete -c pichamber -n '__fish_use_subcommand' -a 'restart' -d 'Stop and start the server'
835
851
  complete -c pichamber -n '__fish_use_subcommand' -a 'status' -d 'Show server status'
836
852
  complete -c pichamber -n '__fish_use_subcommand' -a 'tunnel' -d 'Tunnel lifecycle commands'
853
+ complete -c pichamber -n '__fish_use_subcommand' -a 'startup' -d 'Manage launch at system startup'
837
854
  complete -c pichamber -n '__fish_use_subcommand' -a 'logs' -d 'Tail logs'
855
+ complete -c pichamber -n '__fish_use_subcommand' -a 'connect-url' -d 'Generate a client pairing URL'
838
856
  complete -c pichamber -n '__fish_use_subcommand' -a 'update' -d 'Check for updates'
857
+ complete -c pichamber -n '__fish_use_subcommand' -a 'version' -d 'Show installed version'
839
858
 
840
859
  complete -c pichamber -n '__fish_seen_subcommand_from tunnel; and not __fish_seen_subcommand_from help providers ready doctor status start stop profile completion' -a 'help' -d 'Show tunnel help'
841
860
  complete -c pichamber -n '__fish_seen_subcommand_from tunnel; and not __fish_seen_subcommand_from help providers ready doctor status start stop profile completion' -a 'providers' -d 'Show providers'
@@ -236,6 +236,9 @@ async function discoverRunningInstances(options = {}) {
236
236
  launchMode,
237
237
  runtime: liveInfo.runtime,
238
238
  source: 'registry+probe',
239
+ profileKey: typeof storedOptions?.profileKey === 'string' && storedOptions.profileKey.length > 0
240
+ ? storedOptions.profileKey
241
+ : undefined,
239
242
  host: typeof confirmedHost === 'string' && confirmedHost.length > 0
240
243
  ? confirmedHost
241
244
  : (typeof storedOptions?.host === 'string' && storedOptions.host.length > 0 ? storedOptions.host : undefined),
@@ -56,6 +56,11 @@ function getLogFilePath(port) {
56
56
  return path.join(getLogsDir(), `pichamber-${port}.log`);
57
57
  }
58
58
 
59
+ function getDaemonLogFilePath(profileKey) {
60
+ if (typeof profileKey !== 'string' || !/^[a-z0-9][a-z0-9-]{0,63}$/.test(profileKey)) return null;
61
+ return path.join(getLogsDir(), `pi-daemon-${profileKey}.log`);
62
+ }
63
+
59
64
  function getTunnelProfilesFilePath() {
60
65
  return path.join(getDataDir(), TUNNEL_PROFILES_FILE_NAME);
61
66
  }
@@ -120,6 +125,7 @@ export {
120
125
  readDesktopLocalClientTokenFromSettings,
121
126
  ensureLogsDir,
122
127
  getLogFilePath,
128
+ getDaemonLogFilePath,
123
129
  getTunnelProfilesFilePath,
124
130
  getLegacyCloudflareManagedRemoteFilePath,
125
131
  readLastManagedLocalConfigPath,
@@ -60,6 +60,7 @@ function writeInstanceOptions(instanceFilePath, options, onNotice) {
60
60
  uiPassword: typeof options.uiPassword === 'string' ? options.uiPassword : undefined,
61
61
  hasUiPassword: typeof options.uiPassword === 'string',
62
62
  apiOnly: options.apiOnly === true,
63
+ ...(typeof options.profileKey === 'string' && options.profileKey.length > 0 ? { profileKey: options.profileKey } : {}),
63
64
  startedAt: Number.isFinite(options.startedAt) ? options.startedAt : Date.now(),
64
65
  };
65
66
  fs.writeFileSync(instanceFilePath, JSON.stringify(toStore, null, 2), { mode: 0o600 });
@@ -111,18 +111,23 @@ function resolveToken(options) {
111
111
  }
112
112
 
113
113
  if (options.tokenStdin) {
114
- const fd = fs.openSync('/dev/stdin', 'r');
115
- try {
116
- const buf = Buffer.alloc(65536);
117
- const bytesRead = fs.readSync(fd, buf, 0, buf.length, null);
118
- const value = buf.slice(0, bytesRead).toString('utf8').trim();
119
- if (!value) {
120
- throw new Error('No token received from stdin.');
114
+ const chunks = [];
115
+ let totalBytes = 0;
116
+ const buffer = Buffer.alloc(8192);
117
+ while (true) {
118
+ const bytesRead = fs.readSync(0, buffer, 0, buffer.length, null);
119
+ if (bytesRead === 0) break;
120
+ totalBytes += bytesRead;
121
+ if (totalBytes > 65536) {
122
+ throw new Error('Token received from stdin is too large (max 65536 bytes).');
121
123
  }
122
- return value;
123
- } finally {
124
- fs.closeSync(fd);
124
+ chunks.push(Buffer.from(buffer.subarray(0, bytesRead)));
125
125
  }
126
+ const value = Buffer.concat(chunks).toString('utf8').trim();
127
+ if (!value) {
128
+ throw new Error('No token received from stdin.');
129
+ }
130
+ return value;
126
131
  }
127
132
 
128
133
  if (options.tokenFile) {
@@ -24,6 +24,7 @@ import {
24
24
  log as clackLog,
25
25
  isJsonMode,
26
26
  isQuietMode,
27
+ canPrompt,
27
28
  printJson,
28
29
  logStatus,
29
30
  } from '../cli-output.js';
@@ -238,8 +239,13 @@ function createConnectUrlCommand({ serveCommand }) {
238
239
  port: options.port,
239
240
  explicitPort: true,
240
241
  host: options.host,
242
+ lan: options.lan,
241
243
  uiPassword: options.uiPassword,
244
+ explicitUiPassword: options.explicitUiPassword === true,
242
245
  apiOnly: options.apiOnly,
246
+ foreground: false,
247
+ json: false,
248
+ quiet: true,
243
249
  suppressUnsafePortWarning: true,
244
250
  suppressUiPasswordWarning: true,
245
251
  suppressStartupSummary: true,
@@ -319,7 +325,9 @@ function createConnectUrlCommand({ serveCommand }) {
319
325
  }
320
326
  }
321
327
  clackLog.info('Scan or paste this link into another PiChamber client. It is single-use and expires.');
322
- if (options.qr === true) {
328
+ // QR art is terminal UI. Keep non-TTY stdout limited to the pairing link so
329
+ // agents can capture it even when they pass --qr defensively.
330
+ if (options.qr === true && canPrompt(options)) {
323
331
  await displayTunnelQrCode(connectUrl);
324
332
  }
325
333
  clackOutro('pairing link generated');
@@ -15,6 +15,10 @@ import {
15
15
  import {
16
16
  intro as clackIntro,
17
17
  outro as clackOutro,
18
+ cancel as clackCancel,
19
+ confirm,
20
+ isCancel,
21
+ canPrompt,
18
22
  isJsonMode,
19
23
  isQuietMode,
20
24
  shouldRenderHumanOutput,
@@ -53,6 +57,16 @@ async function stopCommand(options) {
53
57
  }
54
58
 
55
59
  let runningInstances = await discoverLifecycleInstances(options);
60
+ if (!options.explicitPort && runningInstances.length > 1 && !options.force && canPrompt(options)) {
61
+ const approved = await confirm({
62
+ message: `Stop all ${runningInstances.length} PiChamber instances?`,
63
+ initialValue: false,
64
+ });
65
+ if (isCancel(approved) || approved !== true) {
66
+ clackCancel('Stop cancelled.');
67
+ return;
68
+ }
69
+ }
56
70
  if (options.explicitPort) {
57
71
  if (runningInstances.length === 0) {
58
72
  const unconfirmedInstance = await discoverUnconfirmedRegistryInstanceOnPort(options.port, options);
@@ -1,10 +1,11 @@
1
- import { getLogFilePath } from './cli-paths.js';
1
+ import { getDaemonLogFilePath, getLogFilePath } from './cli-paths.js';
2
2
  import { readTailLines, followFile } from './cli-log-files.js';
3
3
  import { discoverRunningInstances, getLatestInstance } from './cli-lifecycle.js';
4
4
  import {
5
5
  intro as clackIntro,
6
6
  outro as clackOutro,
7
7
  isJsonMode,
8
+ isQuietMode,
8
9
  shouldRenderHumanOutput,
9
10
  printJson,
10
11
  logStatus,
@@ -12,7 +13,7 @@ import {
12
13
 
13
14
  async function logsCommand(options) {
14
15
  const showFrames = shouldRenderHumanOutput(options);
15
- const shouldPrefixLines = options.all || !showFrames;
16
+ const shouldPrefixLines = options.all || (!showFrames && !isQuietMode(options));
16
17
  let targets = [];
17
18
  const running = await discoverRunningInstances();
18
19
 
@@ -44,10 +45,15 @@ async function logsCommand(options) {
44
45
  }
45
46
  const entries = targets.map((target) => {
46
47
  const logPath = getLogFilePath(target.port);
48
+ const daemonLogPath = getDaemonLogFilePath(target.profileKey);
47
49
  return {
48
50
  port: target.port,
49
51
  logPath,
50
52
  lines: readTailLines(logPath, options.lines),
53
+ ...(daemonLogPath ? {
54
+ daemonLogPath,
55
+ daemonLines: readTailLines(daemonLogPath, options.lines),
56
+ } : {}),
51
57
  };
52
58
  });
53
59
  printJson({ entries });
@@ -60,9 +66,12 @@ async function logsCommand(options) {
60
66
 
61
67
  for (const target of targets) {
62
68
  const logPath = getLogFilePath(target.port);
69
+ const daemonLogPath = getDaemonLogFilePath(target.profileKey);
63
70
  const lines = readTailLines(logPath, options.lines);
71
+ const daemonLines = daemonLogPath ? readTailLines(daemonLogPath, options.lines) : [];
64
72
  if (showFrames) {
65
73
  logStatus('info', `port ${target.port}`, logPath);
74
+ if (daemonLogPath) logStatus('info', 'Pi daemon', daemonLogPath);
66
75
  }
67
76
 
68
77
  for (const line of lines) {
@@ -72,6 +81,9 @@ async function logsCommand(options) {
72
81
  console.log(line);
73
82
  }
74
83
  }
84
+ for (const line of daemonLines) {
85
+ console.log(shouldPrefixLines ? `[${target.port} daemon] ${line}` : `[daemon] ${line}`);
86
+ }
75
87
  }
76
88
 
77
89
  if (showFrames) {
@@ -82,15 +94,22 @@ async function logsCommand(options) {
82
94
  return;
83
95
  }
84
96
 
85
- const unsubs = targets.map((target) => {
97
+ const unsubs = targets.flatMap((target) => {
86
98
  const logPath = getLogFilePath(target.port);
87
- return followFile(logPath, (line) => {
99
+ const daemonLogPath = getDaemonLogFilePath(target.profileKey);
100
+ const followers = [followFile(logPath, (line) => {
88
101
  if (shouldPrefixLines) {
89
102
  console.log(`[${target.port}] ${line}`);
90
103
  } else {
91
104
  console.log(line);
92
105
  }
93
- });
106
+ })];
107
+ if (daemonLogPath) {
108
+ followers.push(followFile(daemonLogPath, (line) => {
109
+ console.log(shouldPrefixLines ? `[${target.port} daemon] ${line}` : `[daemon] ${line}`);
110
+ }));
111
+ }
112
+ return followers;
94
113
  });
95
114
 
96
115
  await new Promise((resolve) => {