@pi-chamber/web 0.8.1 → 0.9.0

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 (81) hide show
  1. package/bin/cli.js +5 -2
  2. package/bin/cli.test.js +44 -0
  3. package/bin/lib/DOCUMENTATION.md +5 -5
  4. package/bin/lib/cli-args.js +19 -4
  5. package/bin/lib/commands-lifecycle.js +14 -0
  6. package/bin/lib/commands-logs.js +2 -1
  7. package/bin/lib/commands-serve.js +166 -2
  8. package/bin/lib/commands-tunnel.js +21 -0
  9. package/bin/lib/commands-update.js +97 -33
  10. package/bin/lib/commands-update.test.js +96 -1
  11. package/dist/assets/{DiagramEditor-D_3eJVSw.js → DiagramEditor-CcbnMl1H.js} +1 -1
  12. package/dist/assets/{DiagramView-pGYm0-DR.js → DiagramView-DTW5jwK3.js} +1 -1
  13. package/dist/assets/DiffView-CZyHHAOB.js +18 -0
  14. package/dist/assets/FilesView-BJYLFR3H.js +6 -0
  15. package/dist/assets/GitView-Cg_5UU7E.js +8 -0
  16. package/dist/assets/{JsonTreeView-CpgqCk9_.js → JsonTreeView-GTdKGEdy.js} +1 -1
  17. package/dist/assets/{MarkdownRendererImpl-fI6n3kqT.js → MarkdownRendererImpl-WqBwxlso.js} +1 -1
  18. package/dist/assets/{PatchDiff-BRloGXPs.js → PatchDiff-BRi23N1l.js} +1 -1
  19. package/dist/assets/{SessionSwitcherContent-BQc-vW4s.js → SessionSwitcherContent-7VAU5pwZ.js} +1 -1
  20. package/dist/assets/{SessionSwitcherDropdown-v_8TaIZm.js → SessionSwitcherDropdown-BslRtccE.js} +2 -2
  21. package/dist/assets/{SessionUnreadDot-A7vSfll2.js → SessionUnreadDot-1nV0Z2ZA.js} +1 -1
  22. package/dist/assets/SettingsView-UIaAyjTo.js +2 -0
  23. package/dist/assets/{SettingsWindow-D7UDhYd4.js → SettingsWindow-D4jZHl8X.js} +1 -1
  24. package/dist/assets/{ToolOutputDialog-wpU0ylYS.js → ToolOutputDialog-BoeJONiR.js} +1 -1
  25. package/dist/assets/{ToolPartDiffPreview-BvoQK5Gm.js → ToolPartDiffPreview-9FLv2fWD.js} +1 -1
  26. package/dist/assets/{VirtualizedFileDiff-DdPbLdh7.js → VirtualizedFileDiff-ywmPBXAG.js} +4 -4
  27. package/dist/assets/{collapsible-BO6FIjvn.js → collapsible-6mCYf7Ky.js} +1 -1
  28. package/dist/assets/{computeVirtualFileMetrics-DMvXzUJh.js → computeVirtualFileMetrics-3H6mg13G.js} +1 -1
  29. package/dist/assets/{contextFileOpenGuard-BwXQVjtS.js → contextFileOpenGuard-CKyf-TZ7.js} +1 -1
  30. package/dist/assets/gitStatusPredicates-UsytDMy_.js +134 -0
  31. package/dist/assets/index-C8NYcA8-.css +1 -0
  32. package/dist/assets/{index-C3SyF-cA.js → index-D1IaU-Q7.js} +1 -1
  33. package/dist/assets/index-yWgKW2Fx.js +8 -0
  34. package/dist/assets/{isDiffPlainText-BboRbmcm.js → isDiffPlainText-DPCilEx_.js} +1 -1
  35. package/dist/assets/{isFilePlainText-BpTnLRyI.js → isFilePlainText-XdCAgm8R.js} +1 -1
  36. package/dist/assets/main-DcAMXRSi.js +135 -0
  37. package/dist/assets/{main-xLwCWLu-.js → main-DhvLreEl.js} +2 -2
  38. package/dist/assets/{markdownCore-CmFv4H-w.js → markdownCore-BF0Dqwm4.js} +1 -1
  39. package/dist/assets/{miniChat-Vwo4K1IK.js → miniChat-DsCx0dsW.js} +2 -2
  40. package/dist/assets/{mobile-BRaxtEoC.js → mobile-C-IN49xX.js} +2 -2
  41. package/dist/assets/{renderElectronMiniChatApp-DM4rRUUz.js → renderElectronMiniChatApp-C13HXGZL.js} +2 -2
  42. package/dist/assets/renderMobileApp-xCdVzvyf.js +11 -0
  43. package/dist/assets/runtimeEndpointReset-CT3WShpj.js +54 -0
  44. package/dist/assets/{runtimeSurface-SmPSdfop.js → runtimeSurface-C_3mcJ01.js} +1 -1
  45. package/dist/assets/{useAppFontEffects-Bg-8jtrQ.js → useAppFontEffects-BgK55NDM.js} +105 -105
  46. package/dist/assets/{useFilesViewSearch-GLcYNIUV.js → useFilesViewSearch-CWx24PZg.js} +1 -1
  47. package/dist/assets/{usePushVisibilityBeacon-VSYBfNoY.js → usePushVisibilityBeacon-swMQLm-i.js} +1 -1
  48. package/dist/assets/{useSwitcherItems-BkEt9K-N.js → useSwitcherItems-CrS-F6DY.js} +1 -1
  49. package/dist/assets/{vendor-codemirror-language-data-B5cJDWBR.js → vendor-codemirror-language-data-BzeePAPn.js} +2 -2
  50. package/dist/assets/{vendor-dnd-kit-core-CP8ck10N.js → vendor-dnd-kit-core-C9qcAm_1.js} +1 -1
  51. package/dist/assets/{vendor-dnd-kit-sortable-B-Icjoj4.js → vendor-dnd-kit-sortable-D8ozj8M-.js} +1 -1
  52. package/dist/assets/vendor-xterm-addon-fit-DX4qG4td.js +1 -0
  53. package/dist/assets/vendor-xterm-xterm-CrXqRur4.js +16 -0
  54. package/dist/assets/vendor-xterm-xterm-DDGTF8rc.css +1 -0
  55. package/dist/assets/{web-components-0H9kvZwn.js → web-components-DAkBDXRk.js} +3 -3
  56. package/dist/index.html +4 -4
  57. package/dist/mini-chat.html +3 -3
  58. package/dist/mobile.html +3 -3
  59. package/package.json +1 -2
  60. package/server/lib/pi/routes.test.js +39 -0
  61. package/server/lib/pi/session-daemon/DOCUMENTATION.md +1 -1
  62. package/server/lib/pi/session-daemon/extension-bridge.js +14 -11
  63. package/server/lib/pi/session-daemon/prompt-operations.test.js +73 -6
  64. package/server/lib/pi/session-daemon/session-daemon.js +163 -21
  65. package/server/lib/relay/host-client.test.js +3 -1
  66. package/server/lib/stt/DOCUMENTATION.md +1 -1
  67. package/server/lib/terminal/DOCUMENTATION.md +2 -2
  68. package/server/lib/ui-auth/DOCUMENTATION.md +1 -1
  69. package/server/lib/ui-auth/ui-auth.js +23 -26
  70. package/server/lib/ui-auth/ui-auth.test.js +27 -0
  71. package/dist/assets/DiffView-BApPTLGp.js +0 -18
  72. package/dist/assets/FilesView-CiPpuGiF.js +0 -6
  73. package/dist/assets/GitView-uW3w_LlQ.js +0 -8
  74. package/dist/assets/SettingsView-CphlZvfd.js +0 -2
  75. package/dist/assets/gitStatusPredicates-CgNk6M2_.js +0 -134
  76. package/dist/assets/index-BebQicw3.css +0 -1
  77. package/dist/assets/index-Bkz23mZq.js +0 -8
  78. package/dist/assets/main-CMOAwZnJ.js +0 -135
  79. package/dist/assets/renderMobileApp-DWWewNhc.js +0 -11
  80. package/dist/assets/runtimeEndpointReset-BF60eHSx.js +0 -54
  81. package/dist/assets/vendor-ghostty-web-CrxinGGH.js +0 -13
package/bin/cli.js CHANGED
@@ -192,7 +192,10 @@ commands.update = createUpdateCommand({
192
192
 
193
193
  async function main() {
194
194
  const parsed = parseArgs();
195
- const { command, subcommand, tunnelAction, startupAction, options, removedFlagErrors, helpRequested, versionRequested } = parsed;
195
+ const { command, explicitCommand, subcommand, tunnelAction, startupAction, options, removedFlagErrors, helpRequested, versionRequested } = parsed;
196
+ if (command === 'serve' && explicitCommand) {
197
+ options.offerInteractiveSetup = true;
198
+ }
196
199
  activeCommandOptions = options;
197
200
 
198
201
  if (versionRequested || command === 'version') {
@@ -245,7 +248,7 @@ async function main() {
245
248
  }
246
249
 
247
250
  if (!commands[command]) {
248
- const knownCommands = ['serve', 'stop', 'restart', 'status', 'tunnel', 'startup', 'logs', 'update', 'version'];
251
+ const knownCommands = ['serve', 'stop', 'restart', 'status', 'tunnel', 'startup', 'logs', 'connect-url', 'update', 'version'];
249
252
  const suggestion = findClosestMatch(command, knownCommands);
250
253
  const hint = suggestion ? ` Did you mean '${suggestion}'?` : '';
251
254
  if (isJsonMode(options)) {
package/bin/cli.test.js CHANGED
@@ -316,6 +316,13 @@ 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
+
319
326
  it('supports --hostname as top-level bind alias', () => {
320
327
  const parsed = parseArgs(['serve', '--hostname', '0.0.0.0']);
321
328
 
@@ -330,6 +337,43 @@ describe('cli args', () => {
330
337
  });
331
338
  });
332
339
 
340
+ describe('serve command helper', () => {
341
+ it('collects a reviewed LAN server configuration', async () => {
342
+ const { collectInteractiveServeOptions } = await import('./lib/commands-serve.js');
343
+ const answers = ['lan', '8080', 'generate', 'api', 'daemon', true];
344
+ const prompts = {
345
+ select: async () => answers.shift(),
346
+ text: async () => answers.shift(),
347
+ password: async () => answers.shift(),
348
+ confirm: async () => answers.shift(),
349
+ isCancel: () => false,
350
+ cancel: () => {},
351
+ };
352
+
353
+ const result = await collectInteractiveServeOptions({ port: 3000 }, prompts);
354
+
355
+ expect(result).toMatchObject({
356
+ host: '0.0.0.0',
357
+ lan: true,
358
+ port: 8080,
359
+ explicitPort: true,
360
+ uiPassword: '',
361
+ explicitUiPassword: true,
362
+ apiOnly: true,
363
+ foreground: false,
364
+ });
365
+ });
366
+
367
+ it('detects flags that suppress interactive server setup', async () => {
368
+ const { hasExplicitServeConfiguration } = await import('./lib/commands-serve.js');
369
+
370
+ expect(hasExplicitServeConfiguration({ explicitPort: true })).toBe(true);
371
+ expect(hasExplicitServeConfiguration({ foreground: true })).toBe(true);
372
+ expect(hasExplicitServeConfiguration({ apiOnly: true })).toBe(true);
373
+ expect(hasExplicitServeConfiguration({ port: 3000 })).toBe(false);
374
+ });
375
+ });
376
+
333
377
  describe('startup enable command helper', () => {
334
378
  it('collects LAN, port, and generated-password choices interactively', async () => {
335
379
  const { collectInteractiveStartupOptions } = await import('./lib/commands-startup.js');
@@ -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
12
  - `commands-connect-url.js`: authenticated direct/relay pairing links.
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. Results distinguish the previous, installed, and latest versions and report partial restart failures. 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.
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 = [];
@@ -403,6 +404,10 @@ function parseArgs(argv = process.argv.slice(2)) {
403
404
  case 'q':
404
405
  options.quiet = true;
405
406
  break;
407
+ case 'yes':
408
+ case 'y':
409
+ options.yes = true;
410
+ break;
406
411
  case 'help':
407
412
  case 'h':
408
413
  helpRequested = true;
@@ -450,6 +455,7 @@ function parseArgs(argv = process.argv.slice(2)) {
450
455
  }
451
456
  }
452
457
 
458
+ const explicitCommand = positional.length > 0;
453
459
  const command = positional[0] || 'serve';
454
460
  const subcommand = command === 'tunnel' ? (positional[1] || 'help') : null;
455
461
  const tunnelAction = command === 'tunnel' ? (positional[2] || null) : null;
@@ -465,6 +471,7 @@ function parseArgs(argv = process.argv.slice(2)) {
465
471
 
466
472
  return {
467
473
  command,
474
+ explicitCommand,
468
475
  subcommand,
469
476
  tunnelAction,
470
477
  startupAction,
@@ -483,7 +490,7 @@ USAGE:
483
490
  pichamber [COMMAND] [OPTIONS]
484
491
 
485
492
  COMMANDS:
486
- serve Start the web server (daemon default)
493
+ serve Configure and start the web server (guided in interactive terminals)
487
494
  stop Stop running instance(s)
488
495
  restart Stop and start the server
489
496
  status Show server status
@@ -505,6 +512,7 @@ OPTIONS:
505
512
  --api-only Start API routes only, without serving browser UI assets
506
513
  --foreground Run server in foreground (use with systemd/process managers)
507
514
  --no-daemon Alias for --foreground
515
+ -y, --yes Confirm update without prompting
508
516
  -h, --help Show help
509
517
  -v, --version Show version
510
518
 
@@ -520,7 +528,8 @@ EXAMPLES:
520
528
  pichamber # Start in daemon mode on default port 3000 (or free port)
521
529
  pichamber --port 8080 # Start on port 8080 (daemon)
522
530
  pichamber --lan --port 3002 # Start on LAN at 0.0.0.0:3002
523
- pichamber serve --foreground # Start in foreground (for systemd Type=simple)
531
+ pichamber serve # Walk through interactive server setup
532
+ pichamber serve --foreground # Start in foreground without setup prompts
524
533
  pichamber connect-url --port 3000 --qr
525
534
  pichamber connect-url --server https://pichamber.example.com
526
535
  pichamber startup enable --lan --port 3002 --ui-password
@@ -719,10 +728,10 @@ _pichamber_tunnel() {
719
728
  cur="\${COMP_WORDS[COMP_CWORD]}"
720
729
  prev="\${COMP_WORDS[COMP_CWORD-1]}"
721
730
 
722
- commands="serve stop restart status tunnel logs update"},{
731
+ commands="serve stop restart status tunnel startup logs connect-url update version"
723
732
  tunnel_commands="help providers ready doctor status start stop profile completion"
724
733
  profile_commands="list show add remove"
725
- common_flags="--port --foreground --no-daemon --json --all --help --version --plain --quiet"
734
+ common_flags="--port --host --lan --ui-password --api-only --foreground --no-daemon --json --all --help --version --plain --quiet --yes"
726
735
  start_flags="--provider --mode --profile --config --token --token-file --token-stdin --hostname --connect-ttl --session-ttl --qr --no-qr --dry-run --show-secrets"
727
736
 
728
737
  if [[ \${COMP_CWORD} -eq 1 ]]; then
@@ -772,8 +781,11 @@ _pichamber() {
772
781
  'restart:Stop and start the server'
773
782
  'status:Show server status'
774
783
  'tunnel:Tunnel lifecycle commands'
784
+ 'startup:Manage launch at system startup'
775
785
  'logs:Tail PiChamber logs'
786
+ 'connect-url:Generate a client pairing URL'
776
787
  'update:Check for and install updates'
788
+ 'version:Show the installed version'
777
789
  )
778
790
 
779
791
  tunnel_commands=(
@@ -834,8 +846,11 @@ complete -c pichamber -n '__fish_use_subcommand' -a 'stop' -d 'Stop running inst
834
846
  complete -c pichamber -n '__fish_use_subcommand' -a 'restart' -d 'Stop and start the server'
835
847
  complete -c pichamber -n '__fish_use_subcommand' -a 'status' -d 'Show server status'
836
848
  complete -c pichamber -n '__fish_use_subcommand' -a 'tunnel' -d 'Tunnel lifecycle commands'
849
+ complete -c pichamber -n '__fish_use_subcommand' -a 'startup' -d 'Manage launch at system startup'
837
850
  complete -c pichamber -n '__fish_use_subcommand' -a 'logs' -d 'Tail logs'
851
+ complete -c pichamber -n '__fish_use_subcommand' -a 'connect-url' -d 'Generate a client pairing URL'
838
852
  complete -c pichamber -n '__fish_use_subcommand' -a 'update' -d 'Check for updates'
853
+ complete -c pichamber -n '__fish_use_subcommand' -a 'version' -d 'Show installed version'
839
854
 
840
855
  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
856
  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'
@@ -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);
@@ -5,6 +5,7 @@ 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
 
@@ -13,6 +13,13 @@ import { isNetworkExposedBindHost } from '../../server/lib/security/bind-host.js
13
13
  import {
14
14
  intro as clackIntro,
15
15
  outro as clackOutro,
16
+ cancel as clackCancel,
17
+ isCancel,
18
+ select,
19
+ text,
20
+ password as passwordPrompt,
21
+ confirm,
22
+ canPrompt,
16
23
  isJsonMode,
17
24
  isQuietMode,
18
25
  shouldRenderHumanOutput,
@@ -22,6 +29,145 @@ import {
22
29
  } from '../cli-output.js';
23
30
 
24
31
  const DAEMON_READY_TIMEOUT_MS = 30000;
32
+ const servePromptApi = { select, text, password: passwordPrompt, confirm, isCancel, cancel: clackCancel };
33
+
34
+ function hasExplicitServeConfiguration(options) {
35
+ return options.explicitPort === true
36
+ || options.lan === true
37
+ || typeof options.host === 'string'
38
+ || options.explicitUiPassword === true
39
+ || options.apiOnly === true
40
+ || options.foreground === true;
41
+ }
42
+
43
+ async function collectInteractiveServeOptions(options, prompts = servePromptApi) {
44
+ const ask = async (method, config) => {
45
+ const answer = await prompts[method](config);
46
+ if (prompts.isCancel(answer)) {
47
+ prompts.cancel('Server setup cancelled.');
48
+ return { cancelled: true };
49
+ }
50
+ return { answer };
51
+ };
52
+
53
+ const accessResult = await ask('select', {
54
+ message: 'Where should PiChamber be accessible?',
55
+ options: [
56
+ { value: 'local', label: 'This machine only', hint: 'recommended' },
57
+ { value: 'lan', label: 'Local network', hint: 'other devices on your LAN or Wi-Fi' },
58
+ { value: 'custom', label: 'Custom bind address' },
59
+ ],
60
+ initialValue: 'local',
61
+ });
62
+ if (accessResult.cancelled) return null;
63
+
64
+ let host = '127.0.0.1';
65
+ let lan = false;
66
+ if (accessResult.answer === 'lan') {
67
+ host = '0.0.0.0';
68
+ lan = true;
69
+ } else if (accessResult.answer === 'custom') {
70
+ const hostResult = await ask('text', {
71
+ message: 'Bind address',
72
+ initialValue: '127.0.0.1',
73
+ validate: (value) => String(value ?? '').trim() ? undefined : 'Enter a bind address.',
74
+ });
75
+ if (hostResult.cancelled) return null;
76
+ host = String(hostResult.answer).trim();
77
+ }
78
+
79
+ const portResult = await ask('text', {
80
+ message: 'Port',
81
+ initialValue: String(options.port),
82
+ validate: (value) => {
83
+ const normalized = String(value ?? '').trim();
84
+ if (!/^\d+$/.test(normalized)) return 'Enter a port from 0 to 65535.';
85
+ const port = Number(normalized);
86
+ return port >= 0 && port <= 65535 ? undefined : 'Enter a port from 0 to 65535.';
87
+ },
88
+ });
89
+ if (portResult.cancelled) return null;
90
+ const port = Number(String(portResult.answer).trim());
91
+
92
+ const networkExposed = accessResult.answer !== 'local';
93
+ const authResult = await ask('select', {
94
+ message: networkExposed ? 'Choose a required UI password' : 'Protect the UI with a password?',
95
+ options: [
96
+ { value: 'enter', label: 'Enter a password' },
97
+ { value: 'generate', label: 'Generate a secure password' },
98
+ ...(!networkExposed ? [{ value: 'none', label: 'No password', hint: 'local access only' }] : []),
99
+ ],
100
+ initialValue: networkExposed ? 'generate' : 'none',
101
+ });
102
+ if (authResult.cancelled) return null;
103
+
104
+ let uiPassword;
105
+ let explicitUiPassword = false;
106
+ if (authResult.answer === 'enter') {
107
+ const passwordResult = await ask('password', {
108
+ message: 'UI password',
109
+ validate: (value) => String(value ?? '').length ? undefined : 'Enter a password.',
110
+ });
111
+ if (passwordResult.cancelled) return null;
112
+ uiPassword = String(passwordResult.answer);
113
+ const confirmationResult = await ask('password', {
114
+ message: 'Confirm UI password',
115
+ validate: (value) => value === uiPassword ? undefined : 'Passwords do not match.',
116
+ });
117
+ if (confirmationResult.cancelled) return null;
118
+ explicitUiPassword = true;
119
+ } else if (authResult.answer === 'generate') {
120
+ uiPassword = '';
121
+ explicitUiPassword = true;
122
+ }
123
+
124
+ const contentResult = await ask('select', {
125
+ message: 'What should this server provide?',
126
+ options: [
127
+ { value: 'ui', label: 'Browser UI and API', hint: 'recommended' },
128
+ { value: 'api', label: 'API only', hint: 'for paired clients' },
129
+ ],
130
+ initialValue: 'ui',
131
+ });
132
+ if (contentResult.cancelled) return null;
133
+
134
+ const processResult = await ask('select', {
135
+ message: 'How should the server run?',
136
+ options: [
137
+ { value: 'daemon', label: 'In the background', hint: 'recommended' },
138
+ { value: 'foreground', label: 'In the foreground', hint: 'for process managers' },
139
+ ],
140
+ initialValue: 'daemon',
141
+ });
142
+ if (processResult.cancelled) return null;
143
+
144
+ logStatus('info', 'Review server', [
145
+ `Access: ${accessResult.answer === 'local' ? 'this machine only' : host}`,
146
+ `Port: ${port === 0 ? 'automatic' : port}`,
147
+ `Authentication: ${authResult.answer === 'none' ? 'disabled' : authResult.answer === 'generate' ? 'generated password' : 'enabled'}`,
148
+ `Content: ${contentResult.answer === 'api' ? 'API only' : 'browser UI and API'}`,
149
+ `Process: ${processResult.answer === 'foreground' ? 'foreground' : 'background'}`,
150
+ ].join('\n'));
151
+
152
+ const confirmResult = await ask('confirm', { message: 'Start this server?', initialValue: true });
153
+ if (confirmResult.cancelled) return null;
154
+ if (confirmResult.answer !== true) {
155
+ prompts.cancel('Server setup cancelled.');
156
+ return null;
157
+ }
158
+
159
+ return {
160
+ ...options,
161
+ host,
162
+ lan,
163
+ port,
164
+ explicitPort: true,
165
+ uiPassword,
166
+ explicitUiPassword,
167
+ apiOnly: contentResult.answer === 'api',
168
+ foreground: processResult.answer === 'foreground',
169
+ };
170
+ }
25
171
 
26
172
  function createServeCommand({
27
173
  serverPath,
@@ -31,6 +177,15 @@ function createServeCommand({
31
177
  setForegroundShutdown,
32
178
  }) {
33
179
  async function serveCommand(options) {
180
+ let usedInteractiveSetup = false;
181
+ if (options.offerInteractiveSetup === true && canPrompt(options) && !hasExplicitServeConfiguration(options)) {
182
+ clackIntro('PiChamber Server Setup');
183
+ const resolvedOptions = await collectInteractiveServeOptions(options);
184
+ if (!resolvedOptions) return;
185
+ options = resolvedOptions;
186
+ usedInteractiveSetup = true;
187
+ }
188
+
34
189
  const showOutput = shouldRenderHumanOutput(options);
35
190
  const jsonMessages = [];
36
191
  const emitNotice = (notice) => {
@@ -221,6 +376,15 @@ async function serveCommand(options) {
221
376
  : `${resolvedPort}\n`
222
377
  );
223
378
  }
379
+ } else if (usedInteractiveSetup && showOutput && !options.suppressStartupSummary) {
380
+ logStatus('success', `port ${resolvedPort} (foreground)`);
381
+ if (autoGeneratedUiPassword) {
382
+ logStatus('success', 'UI password', effectiveUiPassword);
383
+ logStatus('warning', 'save this password', 'it is not shown again');
384
+ }
385
+ logStatus('info', `visit: ${buildLocalUrl(resolvedPort, '/')}`);
386
+ logStatus('info', `logs: pichamber logs -p ${resolvedPort}`);
387
+ clackOutro('server running; press Ctrl+C to stop');
224
388
  } else if (autoGeneratedUiPassword && showOutput && !options.suppressStartupSummary) {
225
389
  console.log(`Generated UI password: ${effectiveUiPassword}`);
226
390
  console.log('Save this password — it is not shown again.');
@@ -399,7 +563,7 @@ async function serveCommand(options) {
399
563
  serveSpin?.clear();
400
564
 
401
565
  if (!options.suppressStartupSummary && showOutput) {
402
- clackIntro('PiChamber Started');
566
+ if (!usedInteractiveSetup) clackIntro('PiChamber Started');
403
567
  logStatus('success', `port ${serveResult.port} (PID: ${serveResult.pid})`);
404
568
  if (autoGeneratedUiPassword) {
405
569
  logStatus('success', 'UI password', effectiveUiPassword);
@@ -416,4 +580,4 @@ async function serveCommand(options) {
416
580
  return serveCommand;
417
581
  }
418
582
 
419
- export { createServeCommand };
583
+ export { createServeCommand, collectInteractiveServeOptions, hasExplicitServeConfiguration };
@@ -1125,6 +1125,9 @@ async function tunnelCommand(options, subcommand, action, deps) {
1125
1125
  return;
1126
1126
  }
1127
1127
  case 'start': {
1128
+ const interactiveWizard = canPrompt(options)
1129
+ && !(typeof options.profile === 'string' && options.profile.trim().length > 0)
1130
+ && !(typeof options.mode === 'string' && options.mode.trim().length > 0);
1128
1131
  let provider = typeof options.provider === 'string' && options.provider.trim().length > 0
1129
1132
  ? options.provider.trim().toLowerCase()
1130
1133
  : '';
@@ -1474,6 +1477,24 @@ async function tunnelCommand(options, subcommand, action, deps) {
1474
1477
  }
1475
1478
  }
1476
1479
 
1480
+ if (interactiveWizard) {
1481
+ logStatus('info', 'Review tunnel', [
1482
+ `Provider: ${provider}`,
1483
+ `Mode: ${mode}`,
1484
+ `Target: ${options.explicitPort ? `port ${options.port}` : 'running or auto-started server'}`,
1485
+ `Hostname: ${hostname || 'ephemeral URL'}`,
1486
+ `Profile: ${selectedProfile?.name || 'none'}`,
1487
+ ].join('\n'));
1488
+ const approved = await clackConfirm({
1489
+ message: 'Start this tunnel?',
1490
+ initialValue: true,
1491
+ });
1492
+ if (clackIsCancel(approved) || approved !== true) {
1493
+ clackCancel('Tunnel start cancelled.');
1494
+ return;
1495
+ }
1496
+ }
1497
+
1477
1498
  const instance = await resolveTargetInstance({ options, serveCommand, allowAutoStart: true, rejectDesktopRuntime: true });
1478
1499
  if (instance?.autoStarted && shouldRenderHumanOutput(options)) {
1479
1500
  logStatus(