@pi-chamber/web 0.9.9 → 1.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 (69) hide show
  1. package/README.md +72 -67
  2. package/bin/cli.js +7 -32
  3. package/bin/dev-server.js +185 -0
  4. package/bin/dev-server.test.js +252 -0
  5. package/bin/lib/DOCUMENTATION.md +19 -0
  6. package/bin/lib/cli-startup.js +9 -1
  7. package/bin/lib/cli-startup.test.js +30 -0
  8. package/bin/lib/commands-serve.js +9 -5
  9. package/bin/lib/server-runtime.js +6 -0
  10. package/bin/lib/server-runtime.test.js +313 -0
  11. package/dist/assets/{DiagramView-YPcSEyVl.js → DiagramView-COHSzZ9Z.js} +1 -1
  12. package/dist/assets/{DiffView-IrM_w65M.js → DiffView-BA4LWExp.js} +1 -1
  13. package/dist/assets/{FileSaveConflictDialog-CtDwDmHo.js → FileSaveConflictDialog-hRumcJ2e.js} +1 -1
  14. package/dist/assets/{FilesView-EUL5SZDG.js → FilesView-CIx6Bq8l.js} +1 -1
  15. package/dist/assets/{GitView-7K4eJ1V3.js → GitView-3Hgk_pVS.js} +3 -3
  16. package/dist/assets/{JsonTreeView-Qz0QeRmI.js → JsonTreeView-CVLGj7jk.js} +1 -1
  17. package/dist/assets/{MarkdownRendererImpl-CsJfFWDC.js → MarkdownRendererImpl-CWeQW9_O.js} +2 -2
  18. package/dist/assets/{PatchDiff-DNhojsLA.js → PatchDiff-367QPDDL.js} +1 -1
  19. package/dist/assets/{SessionSwitcherContent-l1fTUann.js → SessionSwitcherContent-CbgywSHr.js} +1 -1
  20. package/dist/assets/{SessionSwitcherDropdown-CUyTFUnd.js → SessionSwitcherDropdown-BAHhqkBZ.js} +2 -2
  21. package/dist/assets/{SessionUnreadDot-CY3rTilj.js → SessionUnreadDot-CvIWGgIi.js} +1 -1
  22. package/dist/assets/SettingsView-BpGtnBKt.js +2 -0
  23. package/dist/assets/{SettingsWindow-9FD4QY3p.js → SettingsWindow-CN0wm-Fv.js} +1 -1
  24. package/dist/assets/{ToolOutputDialog-0uj3Kf5J.js → ToolOutputDialog-Bkh0DWJn.js} +3 -3
  25. package/dist/assets/{ToolPartDiffPreview-B29vAjqI.js → ToolPartDiffPreview-C_V9k2ob.js} +1 -1
  26. package/dist/assets/{VirtualizedFileDiff-B1Jii7gu.js → VirtualizedFileDiff-CFToyUp4.js} +4 -4
  27. package/dist/assets/{collapsible-B6bVtxgp.js → collapsible-BXBoS1M4.js} +1 -1
  28. package/dist/assets/{computeVirtualFileMetrics-B6RnDAuP.js → computeVirtualFileMetrics-BpbB2xiE.js} +2 -2
  29. package/dist/assets/{contextFileOpenGuard-DIpJPFxL.js → contextFileOpenGuard-DsdrIBIY.js} +1 -1
  30. package/dist/assets/{gitStatusPredicates-lhIrHyDw.js → gitStatusPredicates-KYx0Vs9h.js} +1 -1
  31. package/dist/assets/{index-BUxQG4Eq.js → index-CVZfC79h.js} +1 -1
  32. package/dist/assets/{index-BXgR2dKM.css → index-Ci9OMaKW.css} +1 -1
  33. package/dist/assets/{index-BOtRfXre.js → index-DyeT2dc_.js} +7 -7
  34. package/dist/assets/{isDiffPlainText-r5sF6_KV.js → isDiffPlainText-dBQiDlRy.js} +1 -1
  35. package/dist/assets/{isFilePlainText-B4e2b2Bv.js → isFilePlainText-DWMzO-Ms.js} +1 -1
  36. package/dist/assets/{main-DSfSGm2f.js → main-DkXvFwTR.js} +3 -3
  37. package/dist/assets/{main-DMYsDuaV.js → main-DukaBOy3.js} +2 -2
  38. package/dist/assets/{markdownCore-0ygaCYcc.js → markdownCore-BH61OrJ2.js} +1 -1
  39. package/dist/assets/{miniChat-DUMRG1q5.js → miniChat-B1uBoxSn.js} +2 -2
  40. package/dist/assets/{mobile-DUcoCNyj.js → mobile-DV_RYy3x.js} +2 -2
  41. package/dist/assets/{renderElectronMiniChatApp-BNmJJQdl.js → renderElectronMiniChatApp-CA6co_Lh.js} +2 -2
  42. package/dist/assets/renderMobileApp-CyhFZ_4g.js +11 -0
  43. package/dist/assets/runtimeEndpointReset-CVoKFaRw.js +53 -0
  44. package/dist/assets/{runtimeSurface-CPm7KWaN.js → runtimeSurface-CxbVCK7k.js} +1 -1
  45. package/dist/assets/{useAppFontEffects-CDmJGQlK.js → useAppFontEffects-HCEusnq7.js} +86 -86
  46. package/dist/assets/{useFilesViewSearch-DDMI---4.js → useFilesViewSearch-Cq7IOB7l.js} +1 -1
  47. package/dist/assets/{usePushVisibilityBeacon-i8sRCEtS.js → usePushVisibilityBeacon-Tvi9uL7v.js} +1 -1
  48. package/dist/assets/{useSwitcherItems-BT_toOh9.js → useSwitcherItems-DLA7kskG.js} +1 -1
  49. package/dist/assets/{vendor-codemirror-language-data-D09wcguI.js → vendor-codemirror-language-data-zF3O85ti.js} +2 -2
  50. package/dist/assets/{web-components-Cb0vnR_a.js → web-components-C7g3Hi85.js} +3 -3
  51. package/dist/index.html +4 -4
  52. package/dist/mini-chat.html +3 -3
  53. package/dist/mobile.html +3 -3
  54. package/package.json +8 -3
  55. package/server/index.js +40 -6
  56. package/server/lib/notifications/DOCUMENTATION.md +39 -0
  57. package/server/lib/notifications/delivery-runtime.js +314 -0
  58. package/server/lib/notifications/delivery-runtime.test.js +85 -0
  59. package/server/lib/notifications/pi-notification-watcher.js +154 -0
  60. package/server/lib/notifications/pi-notification-watcher.test.js +84 -0
  61. package/server/lib/notifications/routes.js +74 -0
  62. package/server/lib/pi/session-daemon/DOCUMENTATION.md +1 -0
  63. package/server/lib/pi/session-daemon/pi-runtime-smoke.test.js +466 -0
  64. package/server/lib/pi/ui-settings-store.js +3 -2
  65. package/server/lib/server/runtime-requirements.js +193 -0
  66. package/server/lib/server/runtime-requirements.test.js +295 -0
  67. package/dist/assets/SettingsView-Cm4cKNof.js +0 -2
  68. package/dist/assets/renderMobileApp-DnhfWGEW.js +0 -11
  69. package/dist/assets/runtimeEndpointReset-B0SWG9Uo.js +0 -53
@@ -13,6 +13,25 @@ This directory contains non-entrypoint PiChamber CLI implementation. `../cli.js`
13
13
  - `pichamber version` and `pichamber --version`: print the installed package version; `--json` returns the same value as JSON.
14
14
  - `commands-update.js`: package update and restart coordination. Interactive updates review the old and target versions, selected server channel, and restart impact before installation; `--yes` skips confirmation. The host-local default channel is `stable`; `--channel stable|rc` overrides it for one run, and RC subscribers receive the highest available version across stable and numbered RC releases. Updates only a writable global install owned by the running CLI. Deployment preflight reports stable reason codes and instructions for containers, source checkouts, custom systemd units, ownership mismatches, and unsupported installs before changing files. 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. An update requested from the managed PiChamber systemd service, including its browser terminal, moves into a transient systemd unit before replacing the package and restarting `pichamber.service`. Update jobs persist non-secret progress, channel, and an exact registry-validated target version in the PiChamber run directory so clients can resume status polling after restart without a moving dist-tag changing the installation target. Installation must verify that exact version before any managed service or instance restart. Terminal job state is persisted before JSON, quiet, or interactive output, and status reads mark dead workers or workers that miss the startup grace period as failed.
15
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
+ - `server-runtime.js`: thin bridge over `../../server/lib/server/runtime-requirements.js`. `dev-server.js` uses the same helper for dev servers.
17
+
18
+ ## Server runtime
19
+
20
+ Server needs Node.js 22.19 or newer (24 recommended) or Bun 1.4 or newer (1.4.2 recommended). `runtime-requirements.js` owns version rules and probing. `server-runtime.js` only re-exports it.
21
+
22
+ Background `serve` picks Node first. It reuses the current executable when the CLI runs on supported Node, else probes `node` on PATH, else uses the configured Bun binary. Each probe runs `bin --version` with a 5s timeout. Only stable `X.Y.Z` counts. Prerelease and build metadata fail. Old Bun that emulates a new Node version still fails on its Bun version.
23
+
24
+ `BUN_BINARY` beats `BUN_INSTALL/bin/bun` beats `bun` on PATH. A configured value is validated and fails when unsupported instead of falling through. Without config, a supported current Bun works even off PATH before PATH is probed.
25
+
26
+ Foreground `serve --foreground`, `startup enable`, and `startWebUiServer` validate the current executable only. They never probe PATH and never switch runtimes. The `startWebUiServer` gate covers direct CLI and Electron in-process startup. `startup enable` validates before it writes any service file and pins `process.execPath`, not the package manager.
27
+
28
+ Dev `dev:server` and `dev:server:watch` use the same Node-first order through `../dev-server.js`. Builds and package management stay on Bun. Docker images launch from pinned Bun 1.4.2, but background selection still prefers supported Node when present.
29
+
30
+ Upgrade note: if your system still runs Bun 1.3.14, update Bun before you restart a Bun-pinned service. The source `packageManager` pin does not replace the installed binary. Node 22.0 through 22.18 is unsupported. No session migration is needed.
31
+
32
+ Smoke: `bun run test:runtime` at the root runs `vitest run server/lib/pi/session-daemon/pi-runtime-smoke.test.js` in `packages/web`. It defaults to `process.execPath` (Vitest runs under Node). Set `PICHAMBER_TEST_RUNTIME` to an absolute server binary to run the same probes under another runtime. The file checks the bundled SDK import with pinned version parity, bundled `bin.pi --help`, credential-free `rpc get_state` to success, and a credential-free foreground `serve --foreground --api-only` that polls `/api/pi/runtime` to ready and checks parent and daemon `execPath`. It is not provider E2E. Children run with isolated dirs, an allowlisted env, and bounded timeouts.
33
+
34
+ PR checks and release call the reusable `runtime-smoke.yml` workflow on Linux across Node 22.19, Node 24, Bun 1.4.0, and Bun 1.4.2.
16
35
 
17
36
  ## Rules
18
37
 
@@ -6,6 +6,7 @@ import { DEFAULT_PORT } from './cli-args.js';
6
6
  import { EXIT_CODE, TunnelCliError } from './cli-errors.js';
7
7
  import { getDataDir } from './cli-paths.js';
8
8
  import { assertAuthenticatedNetworkExposure, hasUiPasswordConfigured, resolveServeUiPassword } from './cli-network.js';
9
+ import { assertCurrentRuntimeSupported as defaultAssertCurrentRuntimeSupported } from './server-runtime.js';
9
10
 
10
11
  const STARTUP_SERVICE_ID = 'dev.pichamber.web';
11
12
 
@@ -364,7 +365,14 @@ function getStartupStatus() {
364
365
  };
365
366
  }
366
367
 
367
- function enableStartupService(options = {}) {
368
+ function enableStartupService(options = {}, deps = {}) {
369
+ const assertCurrentRuntime = typeof deps.assertCurrentRuntime === 'function'
370
+ ? deps.assertCurrentRuntime
371
+ : defaultAssertCurrentRuntimeSupported;
372
+ // Startup services reuse the current executable (`process.execPath`) inline
373
+ // under the service manager. Validate the current runtime before
374
+ // persisting any service files so an unsupported runtime never enables.
375
+ assertCurrentRuntime();
368
376
  const paths = getStartupServicePaths();
369
377
  if (!paths.servicePath) {
370
378
  throw new TunnelCliError(`Startup integration is not supported on ${paths.platform}.`, EXIT_CODE.USAGE_ERROR);
@@ -32,6 +32,36 @@ describe('systemd startup activation', () => {
32
32
  });
33
33
  });
34
34
 
35
+ describe('startup runtime validation', () => {
36
+ it('rejects enable on unsupported current runtime before persisting', async () => {
37
+ const { enableStartupService } = await import('./cli-startup.js');
38
+ const assertCurrentRuntime = () => {
39
+ throw new Error('Unsupported server runtime: Node.js v20.19.0 is not supported. Install Node.js 22.19.0 or newer, or Bun 1.4.0 or newer.');
40
+ };
41
+ expect(() => enableStartupService(
42
+ { port: 3000, host: '127.0.0.1' },
43
+ { assertCurrentRuntime },
44
+ )).toThrow(/Unsupported server runtime/);
45
+ });
46
+
47
+ it('rejects old Bun enable even when emulated Node looks new', async () => {
48
+ const { assertCurrentRuntimeSupported } = await import('./server-runtime.js');
49
+ expect(() => assertCurrentRuntimeSupported({
50
+ isBun: true,
51
+ nodeVersion: 'v26.3.0',
52
+ bunVersion: '1.3.14',
53
+ execPath: '/mock/old-bun',
54
+ })).toThrow(/Bun 1\.3\.14/);
55
+ });
56
+
57
+ it('keeps status usable on old runtimes (no current validation)', async () => {
58
+ const { getStartupStatus } = await import('./cli-startup.js');
59
+ // Status never validates the current runtime so help/status/stop stay
60
+ // usable when serve/startup enable would fail.
61
+ expect(() => getStartupStatus()).not.toThrow(/Unsupported server runtime/);
62
+ });
63
+ });
64
+
35
65
  describe('startup service paths', () => {
36
66
  const originalPlatform = process.platform;
37
67
  const originalGetuid = process.getuid;
@@ -9,6 +9,7 @@ import { ensureLogsDir, getLogFilePath } from './cli-paths.js';
9
9
  import { rotateLogFile } from './cli-log-files.js';
10
10
  import { discoverPiChamberInstanceOnPort, isDesktopRuntimeForPort } from './cli-lifecycle.js';
11
11
  import { getPidFilePath, getInstanceFilePath, writePidFile, writeInstanceOptions, removePidFile, removeInstanceFile, isProcessRunning, terminateProcessTree } from './cli-process.js';
12
+ import { resolveServerExecutable as defaultResolveServerExecutable, assertCurrentRuntimeSupported as defaultAssertCurrentRuntimeSupported } from './server-runtime.js';
12
13
  import { isNetworkExposedBindHost } from '../../server/lib/security/bind-host.js';
13
14
  import {
14
15
  intro as clackIntro,
@@ -171,8 +172,9 @@ async function collectInteractiveServeOptions(options, prompts = servePromptApi)
171
172
 
172
173
  function createServeCommand({
173
174
  serverPath,
174
- bunBin,
175
- getPreferredServerRuntime,
175
+ resolveServerExecutable = defaultResolveServerExecutable,
176
+ assertCurrentRuntime = defaultAssertCurrentRuntimeSupported,
177
+ spawnFn = spawn,
176
178
  setForegroundServerActive,
177
179
  setForegroundShutdown,
178
180
  }) {
@@ -254,8 +256,10 @@ async function serveCommand(options) {
254
256
  }
255
257
  }
256
258
 
257
- const preferredRuntime = getPreferredServerRuntime();
258
- const runtimeBin = preferredRuntime === 'bun' ? bunBin : process.execPath;
259
+ // Foreground validates its own executable without probing or switching.
260
+ const runtimeBin = options.foreground
261
+ ? assertCurrentRuntime().executable
262
+ : resolveServerExecutable().executable;
259
263
 
260
264
  ensureLogsDir();
261
265
  const initialLogPort = targetPort === 0 ? 'auto' : String(targetPort);
@@ -439,7 +443,7 @@ async function serveCommand(options) {
439
443
 
440
444
  const serveSpin = showOutput ? createSpinner(options) : null;
441
445
 
442
- const child = spawn(runtimeBin, serverArgs, {
446
+ const child = spawnFn(runtimeBin, serverArgs, {
443
447
  detached: true,
444
448
  windowsHide: true,
445
449
  stdio: ['ignore', logFd, logFd, 'ipc'],
@@ -0,0 +1,6 @@
1
+ export {
2
+ getBunBinary,
3
+ isSupportedNodeVersion,
4
+ resolveServerExecutable,
5
+ assertCurrentRuntimeSupported,
6
+ } from '../../server/lib/server/runtime-requirements.js';
@@ -0,0 +1,313 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import fs from 'fs';
3
+ import net from 'net';
4
+ import os from 'os';
5
+ import path from 'path';
6
+ import {
7
+ assertCurrentRuntimeSupported,
8
+ isSupportedNodeVersion,
9
+ resolveServerExecutable,
10
+ } from './server-runtime.js';
11
+
12
+ function fakeSpawnSync({ nodeVersion = null, nodeStatus = 0, bunVersion = '1.4.2', bunStatus = 0 } = {}) {
13
+ return (bin) => {
14
+ const normalized = String(bin);
15
+ if (normalized === 'node' || normalized.endsWith('/node') || normalized === '/mock/node') {
16
+ if (nodeVersion === null || nodeStatus !== 0) return { status: 1, stdout: '' };
17
+ return { status: 0, stdout: `${nodeVersion}\n` };
18
+ }
19
+ if (normalized.includes('bun')) {
20
+ if (bunStatus !== 0 || bunVersion === null) return { status: 1, stdout: '' };
21
+ return { status: 0, stdout: `${bunVersion}\n` };
22
+ }
23
+ return { status: 1, stdout: '' };
24
+ };
25
+ }
26
+
27
+ async function withTempPiChamberDataDir(fn) {
28
+ const previous = process.env.PICHAMBER_DATA_DIR;
29
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'pichamber-runtime-test-'));
30
+ process.env.PICHAMBER_DATA_DIR = dir;
31
+ try {
32
+ return await fn(dir);
33
+ } finally {
34
+ if (typeof previous === 'string') {
35
+ process.env.PICHAMBER_DATA_DIR = previous;
36
+ } else {
37
+ delete process.env.PICHAMBER_DATA_DIR;
38
+ }
39
+ fs.rmSync(dir, { recursive: true, force: true });
40
+ }
41
+ }
42
+
43
+ async function allocateLoopbackPort() {
44
+ const server = net.createServer();
45
+ await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
46
+ const address = server.address();
47
+ const port = typeof address === 'object' && address ? address.port : 0;
48
+ await new Promise((resolve) => server.close(resolve));
49
+ return port;
50
+ }
51
+
52
+ function createReadyChild(pid, readyPort, delayMs = 10) {
53
+ const handlers = new Map();
54
+ const child = {
55
+ pid,
56
+ connected: true,
57
+ disconnect() {
58
+ child.connected = false;
59
+ },
60
+ unref() {},
61
+ on(event, callback) {
62
+ if (!handlers.has(event)) handlers.set(event, []);
63
+ handlers.get(event).push(callback);
64
+ return child;
65
+ },
66
+ };
67
+ setTimeout(() => {
68
+ for (const callback of handlers.get('message') || []) {
69
+ callback({ type: 'pichamber:ready', port: readyPort });
70
+ }
71
+ }, delayMs);
72
+ return child;
73
+ }
74
+
75
+ describe('stable version checks', () => {
76
+ it('accepts stable Node 22.19.0 and newer', () => {
77
+ expect(isSupportedNodeVersion('v22.19.0')).toBe(true);
78
+ expect(isSupportedNodeVersion('v22.19.1')).toBe(true);
79
+ expect(isSupportedNodeVersion('v24.14.1')).toBe(true);
80
+ expect(isSupportedNodeVersion('v22.18.9')).toBe(false);
81
+ expect(isSupportedNodeVersion('v22.14.0')).toBe(false);
82
+ expect(isSupportedNodeVersion('v20.19.0')).toBe(false);
83
+ });
84
+
85
+ it('rejects malformed and prerelease shapes', () => {
86
+ expect(isSupportedNodeVersion('v22')).toBe(false);
87
+ expect(isSupportedNodeVersion('not-a-version')).toBe(false);
88
+ expect(isSupportedNodeVersion('v22.19.0-rc.1')).toBe(false);
89
+ });
90
+ });
91
+
92
+ describe('background runtime selection', () => {
93
+ it('prefers the current Node executable without probing PATH', () => {
94
+ const spawnSyncFn = () => {
95
+ throw new Error('should not probe when current Node is supported');
96
+ };
97
+ expect(resolveServerExecutable({
98
+ isBun: false,
99
+ nodeVersion: 'v24.14.1',
100
+ execPath: '/usr/bin/node',
101
+ spawnSyncFn,
102
+ env: {},
103
+ })).toEqual({ runtime: 'node', executable: '/usr/bin/node' });
104
+ });
105
+
106
+ it('selects PATH Node under a Bun parent when Node is available', () => {
107
+ const spawnSyncFn = fakeSpawnSync({ nodeVersion: 'v22.19.0', bunVersion: '1.4.2', bunStatus: 0 });
108
+ const resolved = resolveServerExecutable({
109
+ isBun: true,
110
+ nodeVersion: 'v26.3.0',
111
+ bunVersion: '1.4.2',
112
+ execPath: '/mock/bun',
113
+ bunBin: '/mock/bun',
114
+ spawnSyncFn,
115
+ env: {},
116
+ });
117
+ expect(resolved).toEqual({ runtime: 'node', executable: 'node' });
118
+ expect(resolved.executable).not.toContain('bun');
119
+ });
120
+
121
+ it('falls back to current Bun with no runtimes on PATH', () => {
122
+ const spawnSyncFn = () => ({ status: 1, stdout: '' });
123
+ expect(resolveServerExecutable({
124
+ isBun: true,
125
+ nodeVersion: 'v26.3.0',
126
+ bunVersion: '1.4.2',
127
+ execPath: '/mock/current-bun',
128
+ spawnSyncFn,
129
+ env: {},
130
+ })).toEqual({ runtime: 'bun', executable: '/mock/current-bun' });
131
+ });
132
+
133
+ it('falls back to Bun when Node is older than 22.19.0', () => {
134
+ const spawnSyncFn = fakeSpawnSync({ nodeVersion: 'v20.19.0', bunVersion: '1.4.2', bunStatus: 0 });
135
+ expect(resolveServerExecutable({
136
+ isBun: false,
137
+ nodeVersion: 'v20.19.0',
138
+ execPath: '/usr/bin/node',
139
+ bunBin: 'bun',
140
+ spawnSyncFn,
141
+ env: {},
142
+ })).toEqual({ runtime: 'bun', executable: 'bun' });
143
+ });
144
+
145
+ it('fails deterministically when neither runtime is usable', () => {
146
+ const spawnSyncFn = fakeSpawnSync({ nodeVersion: null, bunStatus: 1, bunVersion: null });
147
+ expect(() => resolveServerExecutable({
148
+ isBun: false,
149
+ nodeVersion: 'v20.19.0',
150
+ execPath: '/usr/bin/node',
151
+ bunBin: '/mock/bun',
152
+ spawnSyncFn,
153
+ env: {},
154
+ })).toThrow(/No supported server runtime/);
155
+ });
156
+
157
+ it('rejects old Bun even when it emulates new Node', () => {
158
+ expect(() => assertCurrentRuntimeSupported({
159
+ isBun: true,
160
+ nodeVersion: 'v26.3.0',
161
+ bunVersion: '1.3.14',
162
+ execPath: '/mock/bun',
163
+ })).toThrow(/Bun 1\.3\.14/);
164
+ });
165
+ });
166
+
167
+ describe('serve executable selection', () => {
168
+ it('spawns the resolved Node executable in background mode', async () => {
169
+ await withTempPiChamberDataDir(async () => {
170
+ const { createServeCommand } = await import('./commands-serve.js');
171
+ const port = await allocateLoopbackPort();
172
+ let spawnedBin = null;
173
+ let spawnedArgs = null;
174
+ const spawnFn = (bin, args) => {
175
+ spawnedBin = bin;
176
+ spawnedArgs = args;
177
+ return createReadyChild(process.pid, port);
178
+ };
179
+ const serve = createServeCommand({
180
+ serverPath: path.join(os.tmpdir(), 'fake-server-index.js'),
181
+ resolveServerExecutable: () => ({ runtime: 'node', executable: '/mock/node' }),
182
+ spawnFn,
183
+ setForegroundServerActive() {},
184
+ setForegroundShutdown() {},
185
+ });
186
+ const result = await serve({
187
+ explicitPort: true,
188
+ port,
189
+ host: '127.0.0.1',
190
+ quiet: true,
191
+ suppressQuietOutput: true,
192
+ suppressUiPasswordWarning: true,
193
+ suppressStartupSummary: true,
194
+ });
195
+ expect(result).toBe(port);
196
+ expect(spawnedBin).toBe('/mock/node');
197
+ expect(spawnedArgs[0]).toContain('fake-server-index.js');
198
+ });
199
+ });
200
+
201
+ it('spawns the Bun fallback executable when Node is unavailable', async () => {
202
+ await withTempPiChamberDataDir(async () => {
203
+ const { createServeCommand } = await import('./commands-serve.js');
204
+ const port = await allocateLoopbackPort();
205
+ let spawnedBin = null;
206
+ const spawnFn = (bin) => {
207
+ spawnedBin = bin;
208
+ return createReadyChild(process.pid, port);
209
+ };
210
+ const serve = createServeCommand({
211
+ serverPath: path.join(os.tmpdir(), 'fake-server-index.js'),
212
+ resolveServerExecutable: () => ({ runtime: 'bun', executable: '/mock/bun' }),
213
+ spawnFn,
214
+ setForegroundServerActive() {},
215
+ setForegroundShutdown() {},
216
+ });
217
+ await serve({
218
+ explicitPort: true,
219
+ port,
220
+ host: '127.0.0.1',
221
+ quiet: true,
222
+ suppressQuietOutput: true,
223
+ suppressUiPasswordWarning: true,
224
+ suppressStartupSummary: true,
225
+ });
226
+ expect(spawnedBin).toBe('/mock/bun');
227
+ });
228
+ });
229
+
230
+ it('surfaces the deterministic error when neither runtime is usable', async () => {
231
+ await withTempPiChamberDataDir(async () => {
232
+ const { createServeCommand } = await import('./commands-serve.js');
233
+ const port = await allocateLoopbackPort();
234
+ const serve = createServeCommand({
235
+ serverPath: path.join(os.tmpdir(), 'fake-server-index.js'),
236
+ resolveServerExecutable: () => {
237
+ throw new Error('No supported server runtime found. Install Node.js 22.19.0 or newer, or Bun 1.4.0 or newer.');
238
+ },
239
+ spawnFn: () => {
240
+ throw new Error('should not spawn without a runtime');
241
+ },
242
+ setForegroundServerActive() {},
243
+ setForegroundShutdown() {},
244
+ });
245
+ await expect(serve({
246
+ explicitPort: true,
247
+ port,
248
+ host: '127.0.0.1',
249
+ quiet: true,
250
+ suppressQuietOutput: true,
251
+ suppressUiPasswordWarning: true,
252
+ suppressStartupSummary: true,
253
+ })).rejects.toThrow(/No supported server runtime/);
254
+ });
255
+ });
256
+ });
257
+
258
+ describe('foreground current-runtime validation', () => {
259
+ it('rejects unsupported current runtime without probing PATH', async () => {
260
+ await withTempPiChamberDataDir(async () => {
261
+ const { createServeCommand } = await import('./commands-serve.js');
262
+ const port = await allocateLoopbackPort();
263
+ let resolveCalls = 0;
264
+ let spawnCalls = 0;
265
+ const serve = createServeCommand({
266
+ serverPath: path.join(os.tmpdir(), 'fake-server-index.js'),
267
+ resolveServerExecutable: () => {
268
+ resolveCalls += 1;
269
+ throw new Error('foreground must not probe PATH runtimes');
270
+ },
271
+ assertCurrentRuntime: () => {
272
+ throw new Error('Unsupported server runtime: Node.js v20.19.0 is not supported. Install Node.js 22.19.0 or newer, or Bun 1.4.0 or newer.');
273
+ },
274
+ spawnFn: () => {
275
+ spawnCalls += 1;
276
+ throw new Error('foreground must stay inline and never spawn');
277
+ },
278
+ setForegroundServerActive() {},
279
+ setForegroundShutdown() {},
280
+ });
281
+ await expect(serve({
282
+ explicitPort: true,
283
+ port,
284
+ host: '127.0.0.1',
285
+ foreground: true,
286
+ quiet: true,
287
+ suppressQuietOutput: true,
288
+ suppressUiPasswordWarning: true,
289
+ suppressStartupSummary: true,
290
+ })).rejects.toThrow(/Unsupported server runtime/);
291
+ expect(resolveCalls).toBe(0);
292
+ expect(spawnCalls).toBe(0);
293
+ });
294
+ });
295
+
296
+ it('validates supported absolute Bun exec without PATH runtimes', () => {
297
+ expect(assertCurrentRuntimeSupported({
298
+ isBun: true,
299
+ nodeVersion: 'v26.3.0',
300
+ bunVersion: '1.4.2',
301
+ execPath: '/mock/current-bun',
302
+ })).toEqual({ runtime: 'bun', executable: '/mock/current-bun' });
303
+ });
304
+
305
+ it('rejects old Bun foreground even when emulated Node looks new', () => {
306
+ expect(() => assertCurrentRuntimeSupported({
307
+ isBun: true,
308
+ nodeVersion: 'v26.3.0',
309
+ bunVersion: '1.3.14',
310
+ execPath: '/mock/old-bun',
311
+ })).toThrow(/Bun 1\.3\.14/);
312
+ });
313
+ });
@@ -1 +1 @@
1
- import{R as t,j as c}from"./vendor-react-B5Z1Mdn3.js";import{aa as $,t as m,I as V}from"./useAppFontEffects-CDmJGQlK.js";import{u as A,a as G,z as ee,bV as W}from"./index-BOtRfXre.js";import{b as te,D as re,F as ie}from"./FileSaveConflictDialog-CtDwDmHo.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-base-ui-DXSHfszQ.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-BZOGXAGe.js";import"./vendor-use-sync-external-store-D0AXkdQC.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-sonner-BDtm25td.js";import"./vendor-codemirror-view-Ct4T37Ue.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-zustand-GVb4H8HE.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./runtimeSurface-CPm7KWaN.js";import"./vendor-dnd-kit-core-C9qcAm_1.js";import"./vendor-dnd-kit-utilities-DTY1C6ST.js";import"./vendor-dnd-kit-accessibility-DZKKhs9S.js";import"./vendor-dnd-kit-sortable-D8ozj8M-.js";import"./vendor-cmdk-zXx6sGnS.js";import"./vendor-radix-ui-react-dialog-D2yhEu2p.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-8xy6TJML.js";import"./vendor-radix-ui-react-context-CFsX-AUC.js";import"./vendor-radix-ui-react-id-D2kS9K1j.js";import"./vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js";import"./vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js";import"./vendor-radix-ui-react-dismissable-layer-DrorBNg9.js";import"./vendor-radix-ui-react-primitive-DkH8dMOR.js";import"./vendor-radix-ui-react-slot-BIDFZX0-.js";import"./vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js";import"./vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js";import"./vendor-radix-ui-react-focus-scope-D2BkImwt.js";import"./vendor-radix-ui-react-portal-YgCRIyi7.js";import"./vendor-radix-ui-react-presence-D432pCMB.js";import"./vendor-radix-ui-react-focus-guards-BfdFmL7c.js";import"./vendor-react-remove-scroll-vR1dy1aP.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-CSAHp1YF.js";import"./vendor-react-style-singleton-Ctw6HnYx.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-Vv4V8Nd1.js";import"./vendor-use-callback-ref-CVVuCyLj.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BByA_dGF.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-DuOEwJ3f.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-wd6iRebq.js";import"./vendor-codemirror-lang-json-CZ07HmNC.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-djiuoTi8.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CKHqhW5R.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-DtcZDGqe.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-D09wcguI.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-CNlncqrr.js";import"./vendor-tanstack-react-virtual-2skouoFw.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CfplGuM0.js";import"./vendor-motion-dom-DhJ-sYS5.js";import"./vendor-motion-utils-CKEGc_YG.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-react-drawio-BYDptOsj.js";const ne=l=>l.split("/").pop()||l;function Dt(){const{files:l}=$(),[x,k]=t.useState(null),[L,R]=t.useState(""),[M,E]=t.useState(!0),[b,h]=t.useState(null),[p,F]=t.useState(!1),[U,v]=t.useState(!1),[j,P]=t.useState(!1),[q,H]=t.useState(0),g=t.useRef(void 0),C=t.useRef(""),d=t.useRef(0),S=t.useRef(0),y=t.useRef(0),D=t.useRef(null),I=t.useRef(!0),w=t.useRef(null),T=A(e=>e.pendingDiagramFile);t.useEffect(()=>(I.current=!0,()=>{I.current=!1}),[]);const o=t.useCallback((e,i,n)=>I.current&&d.current===e&&G()===i&&w.current===n,[]),z=t.useCallback(async e=>{const i=d.current+1;d.current=i;const n=G(),u=l?.readFile;S.current+=1,y.current+=1,E(!0),k(e),w.current=e,h(null),v(!1),P(!1),F(!1);try{const r=await u?.(e);if(!o(i,n,e))return;if(!r){m.error("Failed to read file"),k(null),w.current=null,C.current="",R(""),g.current=void 0,E(!1);return}C.current=r.content,R(r.content),g.current=r.revision}catch(r){if(!o(i,n,e))return;m.error(r instanceof Error?r.message:"Failed to read file"),k(null),w.current=null,C.current="",R(""),g.current=void 0,E(!1);return}finally{o(i,n,e)&&E(!1)}},[l,o]);t.useEffect(()=>ee(()=>{if(d.current+=1,g.current=void 0,S.current+=1,y.current+=1,!I.current)return;h(null),v(!1),P(!1),F(!1);const e=w.current;e&&z(e)}),[z]),t.useEffect(()=>{if(!T)return;const e=A.getState().consumePendingDiagramFile();e&&z(e)},[z,T]);const K=t.useCallback(async(e,i,n,u,r,s)=>{let a=null,f=n,B=u;try{if(B){const N=await l?.readFile?.(e);if(!o(r,s,e))return;N&&(a=N.content??null,typeof N.revision=="string"&&(f=N.revision),B=N.exists!==!1)}}catch{if(!o(r,s,e))return}o(r,s,e)&&(h({path:e,displayPath:ne(e),exists:B,currentRevision:f,currentContent:a,dirtyContent:i,runtimeKey:s}),v(!1))},[l,o]),X=t.useCallback(async(e,i,n,u,r)=>{const s=await l?.writeFile?.(e,i,te(g.current,n?!0:void 0));return o(u,r,e)?{stale:!1,success:!!s?.success,revision:s?.revision}:{stale:!0}},[l,o]),O=t.useCallback((e,i)=>{C.current=e,typeof i<"u"&&(g.current=i),D.current?.getXml()===e&&R(e)},[]),J=t.useCallback(async()=>{const e=D.current?.getXml();if(!x||!l?.writeFile||!e||e===C.current||j||p)return;const i=d.current,n=G(),u=x,r=e,s=S.current+1;S.current=s,P(!0);try{const a=await X(u,r,!1,i,n);if(a.stale)return;if(!a.success){m.error("Failed to write file");return}O(r,a.revision)}catch(a){if(!o(i,n,u))return;if(W(a)){await K(u,r,a.currentRevision??null,a.exists,i,n);return}m.error(a instanceof Error?a.message:"Save failed")}finally{S.current===s&&P(!1)}},[O,x,l,o,p,j,K,X]),Q=t.useCallback(async()=>{const e=b;if(!e||p||!o(d.current,e.runtimeKey,e.path))return;const i=d.current,n=e.runtimeKey;if(!e.exists){k(null),w.current=null,C.current="",R(""),g.current=void 0,h(null),v(!1);return}const u=y.current+1;y.current=u,F(!0);try{const r=await l?.readFile?.(e.path);if(!o(i,n,e.path))return;if(!r){m.error("Failed to read file");return}C.current=r.content??"",R(r.content??""),g.current=r.revision,H(s=>s+1),h(null),v(!1)}catch(r){if(!o(i,n,e.path))return;m.error(r instanceof Error?r.message:"Failed to read file")}finally{y.current===u&&F(!1)}},[l,o,p,b]),Y=t.useCallback(async()=>{const e=b;if(!e||p||!o(d.current,e.runtimeKey,e.path))return;const i=d.current,n=e.runtimeKey;if(!l?.writeFile){m.error("Saving not supported");return}const s=D.current?.getXml()??e.dirtyContent;if(!s){m.error("Failed to write file");return}const a=y.current+1;y.current=a,F(!0);try{const f=await X(e.path,s,!0,i,n);if(f.stale)return;if(!f.success){m.error("Failed to write file");return}O(s,f.revision),h(null),v(!1)}catch(f){if(!o(i,n,e.path))return;if(W(f)){await K(e.path,s,f.currentRevision??e.currentRevision,f.exists,i,n);return}m.error(f instanceof Error?f.message:"Save failed")}finally{y.current===a&&F(!1)}},[O,l,o,p,K,X,b]),Z=t.useCallback(()=>{p||j||(h(null),v(!1))},[p,j]),_=x?x.split("/").pop()||x:"";return x?M?c.jsx("div",{className:"flex h-full items-center justify-center p-3",children:c.jsx(V,{name:"loader-4",className:"size-4 animate-spin"})}):c.jsxs("div",{className:"flex h-full flex-col",children:[c.jsxs("div",{className:"flex items-center gap-2 border-b border-border/30 px-3 py-1.5",children:[c.jsx(V,{name:"file",className:"size-4 shrink-0 text-muted-foreground"}),c.jsx("span",{className:"typography-ui text-muted-foreground truncate flex-1",children:_}),c.jsx("button",{type:"button",onClick:()=>{J()},className:"size-6 flex items-center justify-center rounded-md text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",title:"Save diagram",children:c.jsx(V,{name:"save-3",className:"size-4"})}),c.jsx("button",{type:"button",onClick:()=>A.getState().setActiveMainTab("chat"),className:"size-6 flex items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",title:"Close diagram view",children:c.jsx(V,{name:"close",className:"size-4"})})]}),c.jsx("div",{className:"flex-1 min-h-0",children:c.jsx(re,{ref:D,xml:L,className:"h-full"},q)}),c.jsx(ie,{open:!!b,conflict:b,isResolving:p||j,showCompare:U,onToggleCompare:()=>v(e=>!e),onReload:()=>{Q()},onOverwrite:()=>{Y()},onClose:Z})]}):c.jsx("div",{className:"flex h-full items-center justify-center p-3",children:c.jsx("div",{className:"typography-ui text-muted-foreground",children:"Pick a file from the tree."})})}export{Dt as DiagramView};
1
+ import{R as t,j as c}from"./vendor-react-B5Z1Mdn3.js";import{ab as $,t as m,I as B}from"./useAppFontEffects-HCEusnq7.js";import{t as W,a as A,z as ee,bW as T}from"./index-DyeT2dc_.js";import{b as te,D as re,F as ie}from"./FileSaveConflictDialog-hRumcJ2e.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-base-ui-DXSHfszQ.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-BZOGXAGe.js";import"./vendor-use-sync-external-store-D0AXkdQC.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-sonner-BDtm25td.js";import"./vendor-codemirror-view-Ct4T37Ue.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-zustand-GVb4H8HE.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./runtimeSurface-CxbVCK7k.js";import"./vendor-dnd-kit-core-C9qcAm_1.js";import"./vendor-dnd-kit-utilities-DTY1C6ST.js";import"./vendor-dnd-kit-accessibility-DZKKhs9S.js";import"./vendor-dnd-kit-sortable-D8ozj8M-.js";import"./vendor-cmdk-zXx6sGnS.js";import"./vendor-radix-ui-react-dialog-D2yhEu2p.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-8xy6TJML.js";import"./vendor-radix-ui-react-context-CFsX-AUC.js";import"./vendor-radix-ui-react-id-D2kS9K1j.js";import"./vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js";import"./vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js";import"./vendor-radix-ui-react-dismissable-layer-DrorBNg9.js";import"./vendor-radix-ui-react-primitive-DkH8dMOR.js";import"./vendor-radix-ui-react-slot-BIDFZX0-.js";import"./vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js";import"./vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js";import"./vendor-radix-ui-react-focus-scope-D2BkImwt.js";import"./vendor-radix-ui-react-portal-YgCRIyi7.js";import"./vendor-radix-ui-react-presence-D432pCMB.js";import"./vendor-radix-ui-react-focus-guards-BfdFmL7c.js";import"./vendor-react-remove-scroll-vR1dy1aP.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-CSAHp1YF.js";import"./vendor-react-style-singleton-Ctw6HnYx.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-Vv4V8Nd1.js";import"./vendor-use-callback-ref-CVVuCyLj.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BByA_dGF.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-DuOEwJ3f.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-wd6iRebq.js";import"./vendor-codemirror-lang-json-CZ07HmNC.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-djiuoTi8.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CKHqhW5R.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-DtcZDGqe.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-zF3O85ti.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-CNlncqrr.js";import"./vendor-tanstack-react-virtual-2skouoFw.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CfplGuM0.js";import"./vendor-motion-dom-DhJ-sYS5.js";import"./vendor-motion-utils-CKEGc_YG.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-react-drawio-BYDptOsj.js";const ne=l=>l.split("/").pop()||l;function Dt(){const{files:l}=$(),[x,k]=t.useState(null),[L,R]=t.useState(""),[M,E]=t.useState(!0),[b,h]=t.useState(null),[p,F]=t.useState(!1),[U,v]=t.useState(!1),[j,P]=t.useState(!1),[q,H]=t.useState(0),g=t.useRef(void 0),C=t.useRef(""),d=t.useRef(0),S=t.useRef(0),y=t.useRef(0),D=t.useRef(null),I=t.useRef(!0),w=t.useRef(null),G=W(e=>e.pendingDiagramFile);t.useEffect(()=>(I.current=!0,()=>{I.current=!1}),[]);const o=t.useCallback((e,i,n)=>I.current&&d.current===e&&A()===i&&w.current===n,[]),z=t.useCallback(async e=>{const i=d.current+1;d.current=i;const n=A(),u=l?.readFile;S.current+=1,y.current+=1,E(!0),k(e),w.current=e,h(null),v(!1),P(!1),F(!1);try{const r=await u?.(e);if(!o(i,n,e))return;if(!r){m.error("Failed to read file"),k(null),w.current=null,C.current="",R(""),g.current=void 0,E(!1);return}C.current=r.content,R(r.content),g.current=r.revision}catch(r){if(!o(i,n,e))return;m.error(r instanceof Error?r.message:"Failed to read file"),k(null),w.current=null,C.current="",R(""),g.current=void 0,E(!1);return}finally{o(i,n,e)&&E(!1)}},[l,o]);t.useEffect(()=>ee(()=>{if(d.current+=1,g.current=void 0,S.current+=1,y.current+=1,!I.current)return;h(null),v(!1),P(!1),F(!1);const e=w.current;e&&z(e)}),[z]),t.useEffect(()=>{if(!G)return;const e=W.getState().consumePendingDiagramFile();e&&z(e)},[z,G]);const K=t.useCallback(async(e,i,n,u,r,s)=>{let a=null,f=n,V=u;try{if(V){const N=await l?.readFile?.(e);if(!o(r,s,e))return;N&&(a=N.content??null,typeof N.revision=="string"&&(f=N.revision),V=N.exists!==!1)}}catch{if(!o(r,s,e))return}o(r,s,e)&&(h({path:e,displayPath:ne(e),exists:V,currentRevision:f,currentContent:a,dirtyContent:i,runtimeKey:s}),v(!1))},[l,o]),X=t.useCallback(async(e,i,n,u,r)=>{const s=await l?.writeFile?.(e,i,te(g.current,n?!0:void 0));return o(u,r,e)?{stale:!1,success:!!s?.success,revision:s?.revision}:{stale:!0}},[l,o]),O=t.useCallback((e,i)=>{C.current=e,typeof i<"u"&&(g.current=i),D.current?.getXml()===e&&R(e)},[]),J=t.useCallback(async()=>{const e=D.current?.getXml();if(!x||!l?.writeFile||!e||e===C.current||j||p)return;const i=d.current,n=A(),u=x,r=e,s=S.current+1;S.current=s,P(!0);try{const a=await X(u,r,!1,i,n);if(a.stale)return;if(!a.success){m.error("Failed to write file");return}O(r,a.revision)}catch(a){if(!o(i,n,u))return;if(T(a)){await K(u,r,a.currentRevision??null,a.exists,i,n);return}m.error(a instanceof Error?a.message:"Save failed")}finally{S.current===s&&P(!1)}},[O,x,l,o,p,j,K,X]),Q=t.useCallback(async()=>{const e=b;if(!e||p||!o(d.current,e.runtimeKey,e.path))return;const i=d.current,n=e.runtimeKey;if(!e.exists){k(null),w.current=null,C.current="",R(""),g.current=void 0,h(null),v(!1);return}const u=y.current+1;y.current=u,F(!0);try{const r=await l?.readFile?.(e.path);if(!o(i,n,e.path))return;if(!r){m.error("Failed to read file");return}C.current=r.content??"",R(r.content??""),g.current=r.revision,H(s=>s+1),h(null),v(!1)}catch(r){if(!o(i,n,e.path))return;m.error(r instanceof Error?r.message:"Failed to read file")}finally{y.current===u&&F(!1)}},[l,o,p,b]),Y=t.useCallback(async()=>{const e=b;if(!e||p||!o(d.current,e.runtimeKey,e.path))return;const i=d.current,n=e.runtimeKey;if(!l?.writeFile){m.error("Saving not supported");return}const s=D.current?.getXml()??e.dirtyContent;if(!s){m.error("Failed to write file");return}const a=y.current+1;y.current=a,F(!0);try{const f=await X(e.path,s,!0,i,n);if(f.stale)return;if(!f.success){m.error("Failed to write file");return}O(s,f.revision),h(null),v(!1)}catch(f){if(!o(i,n,e.path))return;if(T(f)){await K(e.path,s,f.currentRevision??e.currentRevision,f.exists,i,n);return}m.error(f instanceof Error?f.message:"Save failed")}finally{y.current===a&&F(!1)}},[O,l,o,p,K,X,b]),Z=t.useCallback(()=>{p||j||(h(null),v(!1))},[p,j]),_=x?x.split("/").pop()||x:"";return x?M?c.jsx("div",{className:"flex h-full items-center justify-center p-3",children:c.jsx(B,{name:"loader-4",className:"size-4 animate-spin"})}):c.jsxs("div",{className:"flex h-full flex-col",children:[c.jsxs("div",{className:"flex items-center gap-2 border-b border-border/30 px-3 py-1.5",children:[c.jsx(B,{name:"file",className:"size-4 shrink-0 text-muted-foreground"}),c.jsx("span",{className:"typography-ui text-muted-foreground truncate flex-1",children:_}),c.jsx("button",{type:"button",onClick:()=>{J()},className:"size-6 flex items-center justify-center rounded-md text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",title:"Save diagram",children:c.jsx(B,{name:"save-3",className:"size-4"})}),c.jsx("button",{type:"button",onClick:()=>W.getState().setActiveMainTab("chat"),className:"size-6 flex items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",title:"Close diagram view",children:c.jsx(B,{name:"close",className:"size-4"})})]}),c.jsx("div",{className:"flex-1 min-h-0",children:c.jsx(re,{ref:D,xml:L,className:"h-full"},q)}),c.jsx(ie,{open:!!b,conflict:b,isResolving:p||j,showCompare:U,onToggleCompare:()=>v(e=>!e),onReload:()=>{Q()},onOverwrite:()=>{Y()},onClose:Z})]}):c.jsx("div",{className:"flex h-full items-center justify-center p-3",children:c.jsx("div",{className:"typography-ui text-muted-foreground",children:"Pick a file from the tree."})})}export{Dt as DiagramView};
@@ -1,4 +1,4 @@
1
- import{j as n,R as r,b as St}from"./vendor-react-B5Z1Mdn3.js";import{o as te,u as J,a as Ze,B as ze}from"./index-BOtRfXre.js";import{ds as vt,dl as Ct,dq as jt,ae as et,a0 as tt,c5 as Nt,c6 as Ne,B as Le,I as q,aa as nt,ax as re,t as st,cv as it,b$ as Lt,dt as Dt,du as kt,ab as Rt,Z as Et,at as At,ac as Tt,cp as Mt,e as It,ao as $t,aF as Pt,a2 as _t,a3 as Wt,a5 as Bt}from"./useAppFontEffects-CDmJGQlK.js";import{d as rt,P as Ot,i as Ge,a as He,b as zt,C as Gt}from"./gitStatusPredicates-lhIrHyDw.js";import{p as Ht}from"./VirtualizedFileDiff-B1Jii7gu.js";import{v as Ut,g as Vt}from"./contextFileOpenGuard-DIpJPFxL.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zustand-GVb4H8HE.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-base-ui-DXSHfszQ.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-BZOGXAGe.js";import"./vendor-use-sync-external-store-D0AXkdQC.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-sonner-BDtm25td.js";import"./vendor-codemirror-view-Ct4T37Ue.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./runtimeSurface-CPm7KWaN.js";import"./vendor-dnd-kit-core-C9qcAm_1.js";import"./vendor-dnd-kit-utilities-DTY1C6ST.js";import"./vendor-dnd-kit-accessibility-DZKKhs9S.js";import"./vendor-dnd-kit-sortable-D8ozj8M-.js";import"./vendor-cmdk-zXx6sGnS.js";import"./vendor-radix-ui-react-dialog-D2yhEu2p.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-8xy6TJML.js";import"./vendor-radix-ui-react-context-CFsX-AUC.js";import"./vendor-radix-ui-react-id-D2kS9K1j.js";import"./vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js";import"./vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js";import"./vendor-radix-ui-react-dismissable-layer-DrorBNg9.js";import"./vendor-radix-ui-react-primitive-DkH8dMOR.js";import"./vendor-radix-ui-react-slot-BIDFZX0-.js";import"./vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js";import"./vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js";import"./vendor-radix-ui-react-focus-scope-D2BkImwt.js";import"./vendor-radix-ui-react-portal-YgCRIyi7.js";import"./vendor-radix-ui-react-presence-D432pCMB.js";import"./vendor-radix-ui-react-focus-guards-BfdFmL7c.js";import"./vendor-react-remove-scroll-vR1dy1aP.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-CSAHp1YF.js";import"./vendor-react-style-singleton-Ctw6HnYx.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-Vv4V8Nd1.js";import"./vendor-use-callback-ref-CVVuCyLj.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BByA_dGF.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-DuOEwJ3f.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-wd6iRebq.js";import"./vendor-codemirror-lang-json-CZ07HmNC.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-djiuoTi8.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CKHqhW5R.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-DtcZDGqe.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-D09wcguI.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-CNlncqrr.js";import"./vendor-tanstack-react-virtual-2skouoFw.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CfplGuM0.js";import"./vendor-motion-dom-DhJ-sYS5.js";import"./vendor-motion-utils-CKEGc_YG.js";import"./web-components-Cb0vnR_a.js";import"./computeVirtualFileMetrics-B6RnDAuP.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-yJ9XpNMI.js";import"./vendor-pierre-theming-Dgp7B_O4.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./runtimeEndpointReset-B0SWG9Uo.js";import"./SessionUnreadDot-CY3rTilj.js";import"./vendor-xterm-xterm-CrXqRur4.js";import"./permissionStore-iKN1K2_x.js";import"./appThemeRegistry-gegrE2dq.js";import"./registerCustomTheme-DmolaWWZ.js";import"./isDiffPlainText-r5sF6_KV.js";import"./vendor-diff-C3JhlQdm.js";function Kt(t,s=10){const e=[];let i;for(const l of t.split(`
1
+ import{j as n,R as r,b as St}from"./vendor-react-B5Z1Mdn3.js";import{o as te,t as J,a as Ze,B as ze}from"./index-DyeT2dc_.js";import{dt as vt,dm as Ct,dr as jt,af as et,a1 as tt,c6 as Nt,c7 as Ne,B as Le,I as q,ab as nt,ay as re,t as st,cw as it,c0 as Lt,du as Dt,dv as kt,ac as Rt,_ as Et,au as At,ad as Tt,cq as Mt,f as It,ap as $t,aG as Pt,a3 as _t,a4 as Wt,a6 as Bt}from"./useAppFontEffects-HCEusnq7.js";import{d as rt,P as Ot,i as Ge,a as He,b as zt,C as Gt}from"./gitStatusPredicates-KYx0Vs9h.js";import{p as Ht}from"./VirtualizedFileDiff-CFToyUp4.js";import{v as Ut,g as Vt}from"./contextFileOpenGuard-DsdrIBIY.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zustand-GVb4H8HE.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-base-ui-DXSHfszQ.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-BZOGXAGe.js";import"./vendor-use-sync-external-store-D0AXkdQC.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-sonner-BDtm25td.js";import"./vendor-codemirror-view-Ct4T37Ue.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./runtimeSurface-CxbVCK7k.js";import"./vendor-dnd-kit-core-C9qcAm_1.js";import"./vendor-dnd-kit-utilities-DTY1C6ST.js";import"./vendor-dnd-kit-accessibility-DZKKhs9S.js";import"./vendor-dnd-kit-sortable-D8ozj8M-.js";import"./vendor-cmdk-zXx6sGnS.js";import"./vendor-radix-ui-react-dialog-D2yhEu2p.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-8xy6TJML.js";import"./vendor-radix-ui-react-context-CFsX-AUC.js";import"./vendor-radix-ui-react-id-D2kS9K1j.js";import"./vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js";import"./vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js";import"./vendor-radix-ui-react-dismissable-layer-DrorBNg9.js";import"./vendor-radix-ui-react-primitive-DkH8dMOR.js";import"./vendor-radix-ui-react-slot-BIDFZX0-.js";import"./vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js";import"./vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js";import"./vendor-radix-ui-react-focus-scope-D2BkImwt.js";import"./vendor-radix-ui-react-portal-YgCRIyi7.js";import"./vendor-radix-ui-react-presence-D432pCMB.js";import"./vendor-radix-ui-react-focus-guards-BfdFmL7c.js";import"./vendor-react-remove-scroll-vR1dy1aP.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-CSAHp1YF.js";import"./vendor-react-style-singleton-Ctw6HnYx.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-Vv4V8Nd1.js";import"./vendor-use-callback-ref-CVVuCyLj.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BByA_dGF.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-DuOEwJ3f.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-wd6iRebq.js";import"./vendor-codemirror-lang-json-CZ07HmNC.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-djiuoTi8.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CKHqhW5R.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-DtcZDGqe.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-zF3O85ti.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-CNlncqrr.js";import"./vendor-tanstack-react-virtual-2skouoFw.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CfplGuM0.js";import"./vendor-motion-dom-DhJ-sYS5.js";import"./vendor-motion-utils-CKEGc_YG.js";import"./web-components-C7g3Hi85.js";import"./computeVirtualFileMetrics-BpbB2xiE.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-yJ9XpNMI.js";import"./vendor-pierre-theming-Dgp7B_O4.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./runtimeEndpointReset-CVoKFaRw.js";import"./SessionUnreadDot-CvIWGgIi.js";import"./vendor-xterm-xterm-CrXqRur4.js";import"./permissionStore-iKN1K2_x.js";import"./appThemeRegistry-gegrE2dq.js";import"./registerCustomTheme-DmolaWWZ.js";import"./isDiffPlainText-dBQiDlRy.js";import"./vendor-diff-C3JhlQdm.js";function Kt(t,s=10){const e=[];let i;for(const l of t.split(`
2
2
  `)){const p=l.match(vt);if(p!=null){i!=null&&(i.hunkLines.length>0&&(Re(i,s,"trailing"),Ie(i,e)),i=void 0);const u=parseInt(p[3]),b=parseInt(p[1]),h=parseInt(p[4]??"1"),c=parseInt(p[2]??"1");isNaN(u)||isNaN(b)||isNaN(h)||isNaN(c)?e.push(l):i={additionStart:u,deletionStart:b,additionCount:0,deletionCount:0,hunkLines:[],contextLines:[]};continue}if(i==null){e.push(l);continue}if(l.startsWith(" "))i.contextLines.push(l);else if(l!==""){if(i.hunkLines.length>0&&i.contextLines.length>s*2){const u=i.contextLines.length-s*2,b=i.contextLines.slice(-s);Re(i,s,"trailing");const{additionCount:h,deletionCount:c}=i;Ie(i,e),i={additionStart:i.additionStart+h+u,deletionStart:i.deletionStart+c+u,deletionCount:0,additionCount:0,contextLines:b,hunkLines:[]}}Re(i,s,i.hunkLines.length===0?"leading":"before-change"),i.hunkLines.push(l),l.startsWith("+")?i.additionCount+=1:l.startsWith("-")&&(i.deletionCount+=1)}}i!=null&&i.hunkLines.length>0&&(Re(i,s,"trailing"),Ie(i,e));const a=e.join(`
3
3
  `);return t.endsWith(`
4
4
  `)?`${a}
@@ -1,3 +1,3 @@
1
- import{R as a,j as r}from"./vendor-react-B5Z1Mdn3.js";import{D}from"./vendor-react-drawio-BYDptOsj.js";import{o as C}from"./index-BOtRfXre.js";import{af as E,ag as S,ah as N,ai as B,aj as F,ak as H,B as h}from"./useAppFontEffects-CDmJGQlK.js";const A='<mxfile><diagram id="new" name="Page-1"><mxGraphModel dx="0" dy="0" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>';function w(){if(typeof document>"u")return!1;const t=document.documentElement.getAttribute("data-theme");return t==="dark"||!t&&window.matchMedia("(prefers-color-scheme: dark)").matches}const P=a.forwardRef(function({xml:e,readOnly:s,className:d,onChange:u},m){const l=a.useRef(e),c=a.useRef(null),i=a.useRef(!1),[o,j]=a.useState(w),f=a.useRef(e),p=a.useRef(e);p.current!==e&&(p.current=e,f.current=e,l.current=e);const v=a.useRef(o);v.current!==o&&(v.current=o,f.current=l.current);const g=a.useRef(null);a.useEffect(()=>{const n=()=>j(w());n();const x=new MutationObserver(n);return x.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>x.disconnect()},[]),a.useEffect(()=>{const n=setTimeout(()=>{g.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(n)},[]),a.useImperativeHandle(m,()=>({getXml:()=>l.current}));const y=a.useCallback(()=>{!e&&!i.current&&(i.current=!0,setTimeout(()=>{c.current?.template({})},500))},[e]),R=a.useCallback(n=>{l.current=n.xml,u?.(n.xml)},[u]);return r.jsx("div",{ref:g,className:C("h-full w-full",d),children:r.jsx(D,{ref:c,xml:f.current||A,autosave:!0,urlParameters:{ui:s?"simple":o?"dark":"kennedy",spin:!0,libraries:!s,chrome:s,nav:s,layers:s,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:y,onAutoSave:R},o?"dark":"light")})}),T=(t,e)=>!t||t.runtimeKey!==e.runtimeKey||t.root!==e.root||t.path!==e.path||t.generation!==e.generation,b=t=>{if(typeof t=="string")return t;if(t===null)return null},X=(t,e)=>{if(e===!0)return t!==void 0?{expectedRevision:b(t),overwrite:!0}:{overwrite:!0};if(t!==void 0)return{expectedRevision:b(t)}},G=(t,e)=>!!(t&&e&&t.runtimeKey===e.runtimeKey&&t.root===e.root&&t.path===e.path&&t.generation===e.generation),k=(t,e=4e3)=>t.length>e?`${t.slice(0,e)}
1
+ import{R as a,j as r}from"./vendor-react-B5Z1Mdn3.js";import{D}from"./vendor-react-drawio-BYDptOsj.js";import{o as C}from"./index-DyeT2dc_.js";import{ag as E,ah as S,ai as N,aj as B,ak as F,al as H,B as h}from"./useAppFontEffects-HCEusnq7.js";const A='<mxfile><diagram id="new" name="Page-1"><mxGraphModel dx="0" dy="0" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>';function w(){if(typeof document>"u")return!1;const t=document.documentElement.getAttribute("data-theme");return t==="dark"||!t&&window.matchMedia("(prefers-color-scheme: dark)").matches}const P=a.forwardRef(function({xml:e,readOnly:s,className:d,onChange:u},m){const l=a.useRef(e),c=a.useRef(null),i=a.useRef(!1),[o,j]=a.useState(w),f=a.useRef(e),p=a.useRef(e);p.current!==e&&(p.current=e,f.current=e,l.current=e);const v=a.useRef(o);v.current!==o&&(v.current=o,f.current=l.current);const g=a.useRef(null);a.useEffect(()=>{const n=()=>j(w());n();const x=new MutationObserver(n);return x.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>x.disconnect()},[]),a.useEffect(()=>{const n=setTimeout(()=>{g.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(n)},[]),a.useImperativeHandle(m,()=>({getXml:()=>l.current}));const y=a.useCallback(()=>{!e&&!i.current&&(i.current=!0,setTimeout(()=>{c.current?.template({})},500))},[e]),R=a.useCallback(n=>{l.current=n.xml,u?.(n.xml)},[u]);return r.jsx("div",{ref:g,className:C("h-full w-full",d),children:r.jsx(D,{ref:c,xml:f.current||A,autosave:!0,urlParameters:{ui:s?"simple":o?"dark":"kennedy",spin:!0,libraries:!s,chrome:s,nav:s,layers:s,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:y,onAutoSave:R},o?"dark":"light")})}),T=(t,e)=>!t||t.runtimeKey!==e.runtimeKey||t.root!==e.root||t.path!==e.path||t.generation!==e.generation,b=t=>{if(typeof t=="string")return t;if(t===null)return null},X=(t,e)=>{if(e===!0)return t!==void 0?{expectedRevision:b(t),overwrite:!0}:{overwrite:!0};if(t!==void 0)return{expectedRevision:b(t)}},G=(t,e)=>!!(t&&e&&t.runtimeKey===e.runtimeKey&&t.root===e.root&&t.path===e.path&&t.generation===e.generation),k=(t,e=4e3)=>t.length>e?`${t.slice(0,e)}
2
2
 
3
3
  … truncated …`:t,W=({open:t,conflict:e,isResolving:s,showCompare:d,onToggleCompare:u,onReload:m,onOverwrite:l,onClose:c})=>{if(!e)return null;const i=!e.exists;return r.jsx(E,{open:t,onOpenChange:o=>{o||c()},children:r.jsxs(S,{showCloseButton:!1,className:"max-w-lg",children:[r.jsxs(N,{children:[r.jsx(B,{children:i?"File deleted on disk":"File changed on disk"}),r.jsx(F,{children:i?`“${e.displayPath}” was deleted since you opened it. Your edits are preserved. Reload to discard them, or overwrite to recreate the file.`:`“${e.displayPath}” changed since you opened it. Your edits are preserved. Reload to discard them and load the current version, or overwrite to keep your edits.`})]}),d&&!i?r.jsxs("div",{className:"grid max-h-64 grid-cols-1 gap-2 overflow-auto py-2",children:[r.jsxs("div",{children:[r.jsx("div",{className:"typography-meta text-muted-foreground",children:"Current version on disk"}),r.jsx("pre",{className:"mt-1 max-h-28 overflow-auto rounded-md bg-[var(--surface-subtle)] p-2 text-xs whitespace-pre-wrap break-words",children:k(e.currentContent??"")})]}),r.jsxs("div",{children:[r.jsx("div",{className:"typography-meta text-muted-foreground",children:"Your edits"}),r.jsx("pre",{className:"mt-1 max-h-28 overflow-auto rounded-md bg-[var(--surface-subtle)] p-2 text-xs whitespace-pre-wrap break-words",children:k(e.dirtyContent)})]})]}):null,r.jsxs(H,{className:"flex flex-wrap gap-2",children:[i?null:r.jsx(h,{variant:"outline",onClick:u,disabled:s,"aria-label":d?"Hide version comparison":"Compare versions",title:d?"Hide version comparison":"Compare versions",children:d?"Hide compare":"Compare"}),r.jsx(h,{variant:"outline",onClick:m,disabled:s,"aria-label":i?"Discard edits and close":"Reload current version",title:i?"Discard edits and close":"Reload current version",children:i?"Discard edits":"Reload"}),r.jsx(h,{variant:"destructive",onClick:l,disabled:s,"aria-label":i?"Recreate file with my edits":"Overwrite with my edits",title:i?"Recreate file with my edits":"Overwrite with my edits",children:s?"Working…":"Overwrite"})]})]})})};export{P as D,W as F,X as b,G as i,T as s};