@pi-chamber/web 0.8.2 → 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.
- package/bin/cli.js +5 -2
- package/bin/cli.test.js +44 -0
- package/bin/lib/DOCUMENTATION.md +5 -5
- package/bin/lib/cli-args.js +19 -4
- package/bin/lib/commands-lifecycle.js +14 -0
- package/bin/lib/commands-logs.js +2 -1
- package/bin/lib/commands-serve.js +166 -2
- package/bin/lib/commands-tunnel.js +21 -0
- package/bin/lib/commands-update.js +97 -33
- package/bin/lib/commands-update.test.js +96 -1
- package/dist/assets/{DiagramEditor-DerMrS6m.js → DiagramEditor-CcbnMl1H.js} +1 -1
- package/dist/assets/{DiagramView-DdipXAq8.js → DiagramView-DTW5jwK3.js} +1 -1
- package/dist/assets/DiffView-CZyHHAOB.js +18 -0
- package/dist/assets/{FilesView-BXp0yc0j.js → FilesView-BJYLFR3H.js} +3 -3
- package/dist/assets/GitView-Cg_5UU7E.js +8 -0
- package/dist/assets/{JsonTreeView-CxXRXXzk.js → JsonTreeView-GTdKGEdy.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-DNZQgQua.js → MarkdownRendererImpl-WqBwxlso.js} +1 -1
- package/dist/assets/{PatchDiff-B_NFEIX7.js → PatchDiff-BRi23N1l.js} +1 -1
- package/dist/assets/{SessionSwitcherContent-Q4P2TGBr.js → SessionSwitcherContent-7VAU5pwZ.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-Cgw2mQIO.js → SessionSwitcherDropdown-BslRtccE.js} +2 -2
- package/dist/assets/{SessionUnreadDot-BxtTkvHB.js → SessionUnreadDot-1nV0Z2ZA.js} +1 -1
- package/dist/assets/SettingsView-UIaAyjTo.js +2 -0
- package/dist/assets/{SettingsWindow-BEjHL1ET.js → SettingsWindow-D4jZHl8X.js} +1 -1
- package/dist/assets/{ToolOutputDialog-C_7vJLEq.js → ToolOutputDialog-BoeJONiR.js} +1 -1
- package/dist/assets/{ToolPartDiffPreview-ClV785zX.js → ToolPartDiffPreview-9FLv2fWD.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-DrxkW2WQ.js → VirtualizedFileDiff-ywmPBXAG.js} +4 -4
- package/dist/assets/{collapsible-CR3-hRMy.js → collapsible-6mCYf7Ky.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-D0mQcleY.js → computeVirtualFileMetrics-3H6mg13G.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-BRc5Z0g-.js → contextFileOpenGuard-CKyf-TZ7.js} +1 -1
- package/dist/assets/gitStatusPredicates-UsytDMy_.js +134 -0
- package/dist/assets/index-C8NYcA8-.css +1 -0
- package/dist/assets/{index-CMfiVUIr.js → index-D1IaU-Q7.js} +1 -1
- package/dist/assets/index-yWgKW2Fx.js +8 -0
- package/dist/assets/{isDiffPlainText-MmBA1REG.js → isDiffPlainText-DPCilEx_.js} +1 -1
- package/dist/assets/{isFilePlainText-bQAPxqO9.js → isFilePlainText-XdCAgm8R.js} +1 -1
- package/dist/assets/main-DcAMXRSi.js +135 -0
- package/dist/assets/{main-zZrKd3hZ.js → main-DhvLreEl.js} +2 -2
- package/dist/assets/{markdownCore-B9jXCPry.js → markdownCore-BF0Dqwm4.js} +1 -1
- package/dist/assets/{miniChat-Di2oVS5o.js → miniChat-DsCx0dsW.js} +2 -2
- package/dist/assets/{mobile-VU_G_SgX.js → mobile-C-IN49xX.js} +2 -2
- package/dist/assets/{renderElectronMiniChatApp-Bi1927c8.js → renderElectronMiniChatApp-C13HXGZL.js} +2 -2
- package/dist/assets/renderMobileApp-xCdVzvyf.js +11 -0
- package/dist/assets/runtimeEndpointReset-CT3WShpj.js +54 -0
- package/dist/assets/{runtimeSurface-CBaS2Ank.js → runtimeSurface-C_3mcJ01.js} +1 -1
- package/dist/assets/{useAppFontEffects-8ZU-TTIW.js → useAppFontEffects-BgK55NDM.js} +80 -80
- package/dist/assets/{useFilesViewSearch-COow9O9x.js → useFilesViewSearch-CWx24PZg.js} +1 -1
- package/dist/assets/{usePushVisibilityBeacon-zYd3ppNh.js → usePushVisibilityBeacon-swMQLm-i.js} +1 -1
- package/dist/assets/{useSwitcherItems-DOQqhi-e.js → useSwitcherItems-CrS-F6DY.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-B_0wrsbo.js → vendor-codemirror-language-data-BzeePAPn.js} +2 -2
- package/dist/assets/{vendor-dnd-kit-core-CP8ck10N.js → vendor-dnd-kit-core-C9qcAm_1.js} +1 -1
- package/dist/assets/{vendor-dnd-kit-sortable-B-Icjoj4.js → vendor-dnd-kit-sortable-D8ozj8M-.js} +1 -1
- package/dist/assets/vendor-xterm-addon-fit-DX4qG4td.js +1 -0
- package/dist/assets/vendor-xterm-xterm-CrXqRur4.js +16 -0
- package/dist/assets/vendor-xterm-xterm-DDGTF8rc.css +1 -0
- package/dist/assets/{web-components-C9ENH49P.js → web-components-DAkBDXRk.js} +3 -3
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -2
- package/server/lib/stt/DOCUMENTATION.md +1 -1
- package/server/lib/terminal/DOCUMENTATION.md +2 -2
- package/dist/assets/DiffView-Gh9wjthp.js +0 -18
- package/dist/assets/GitView-BmNCkkoC.js +0 -8
- package/dist/assets/SettingsView-CFzxRzUq.js +0 -2
- package/dist/assets/gitStatusPredicates-DBGDfr1K.js +0 -134
- package/dist/assets/index-CzO3ooje.css +0 -1
- package/dist/assets/index-ivrh3jfy.js +0 -8
- package/dist/assets/main-BoVfUG73.js +0 -135
- package/dist/assets/renderMobileApp-D9mxhuaM.js +0 -11
- package/dist/assets/runtimeEndpointReset-DImT35Ug.js +0 -54
- package/dist/assets/vendor-ghostty-web-CrxinGGH.js +0 -13
|
@@ -13,6 +13,10 @@ import {
|
|
|
13
13
|
import {
|
|
14
14
|
intro as clackIntro,
|
|
15
15
|
outro as clackOutro,
|
|
16
|
+
cancel as clackCancel,
|
|
17
|
+
confirm,
|
|
18
|
+
isCancel,
|
|
19
|
+
canPrompt,
|
|
16
20
|
isJsonMode,
|
|
17
21
|
isQuietMode,
|
|
18
22
|
shouldRenderHumanOutput,
|
|
@@ -37,6 +41,9 @@ function createUpdateCommand({
|
|
|
37
41
|
isInsideSystemdService = () => Boolean(process.env.INVOCATION_ID) || Boolean(process.env.PICHAMBER_SYSTEMD_UNIT),
|
|
38
42
|
isUserStartupServiceActive = defaultIsUserStartupServiceActive,
|
|
39
43
|
restartUserStartupService = defaultRestartUserStartupService,
|
|
44
|
+
discoverInstances = discoverRunningInstances,
|
|
45
|
+
requestShutdown = requestServerShutdown,
|
|
46
|
+
stopProcess = stopInstanceProcess,
|
|
40
47
|
}) {
|
|
41
48
|
return async function updateCommand(options = {}) {
|
|
42
49
|
const showOutput = shouldRenderHumanOutput(options);
|
|
@@ -150,10 +157,33 @@ function createUpdateCommand({
|
|
|
150
157
|
throw new Error(UNOWNED_INSTALL_MESSAGE);
|
|
151
158
|
}
|
|
152
159
|
|
|
160
|
+
const latestVersion = updateInfo.version || 'latest';
|
|
161
|
+
const startupServiceActive = isUserStartupServiceActive();
|
|
162
|
+
const runningInstances = startupServiceActive ? [] : await discoverInstances();
|
|
163
|
+
|
|
164
|
+
if (canPrompt(options) && options.yes !== true) {
|
|
165
|
+
updateSpin?.clear();
|
|
166
|
+
logStatus('info', 'Review update', [
|
|
167
|
+
`Version: ${currentVersion} -> ${latestVersion}`,
|
|
168
|
+
`Package manager: ${pm}`,
|
|
169
|
+
startupServiceActive
|
|
170
|
+
? 'Restart: startup service'
|
|
171
|
+
: `Restart: ${runningInstances.length} running instance(s)`,
|
|
172
|
+
].join('\n'));
|
|
173
|
+
const approved = await confirm({
|
|
174
|
+
message: `Install PiChamber ${latestVersion}?`,
|
|
175
|
+
initialValue: true,
|
|
176
|
+
});
|
|
177
|
+
if (isCancel(approved) || approved !== true) {
|
|
178
|
+
clackCancel('Update cancelled.');
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
153
183
|
if (showOutput && !updateSpin) {
|
|
154
|
-
logStatus('info', `updating ${
|
|
184
|
+
logStatus('info', `updating ${currentVersion} -> ${latestVersion} with ${pm}`);
|
|
155
185
|
}
|
|
156
|
-
updateSpin?.
|
|
186
|
+
updateSpin?.start(`Updating ${currentVersion} -> ${latestVersion}...`);
|
|
157
187
|
|
|
158
188
|
const result = executeUpdate(pm, { silent: isJsonMode(options) || isQuietMode(options) });
|
|
159
189
|
if (!result.success) {
|
|
@@ -164,10 +194,11 @@ function createUpdateCommand({
|
|
|
164
194
|
throw new Error(`Update failed with exit code ${result.exitCode}`);
|
|
165
195
|
}
|
|
166
196
|
|
|
167
|
-
|
|
197
|
+
const installedVersion = getCurrentVersion();
|
|
198
|
+
const restartResults = [];
|
|
168
199
|
let startupServiceRestarted = false;
|
|
169
200
|
|
|
170
|
-
if (
|
|
201
|
+
if (startupServiceActive) {
|
|
171
202
|
updateSpin?.message('Restarting systemd user service...');
|
|
172
203
|
try {
|
|
173
204
|
restartUserStartupService();
|
|
@@ -181,59 +212,92 @@ function createUpdateCommand({
|
|
|
181
212
|
}
|
|
182
213
|
throw new Error(msg);
|
|
183
214
|
}
|
|
184
|
-
} else {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
await stopInstanceProcess(instance.pid, {
|
|
192
|
-
shutdownWaitMs: requested ? 5000 : 0,
|
|
193
|
-
gracefulTimeoutMs: 2500,
|
|
194
|
-
forceTimeoutMs: 3000,
|
|
195
|
-
});
|
|
196
|
-
removePidFile(instance.pidFilePath);
|
|
197
|
-
} catch {
|
|
198
|
-
}
|
|
215
|
+
} else if (runningInstances.length > 0) {
|
|
216
|
+
updateSpin?.message(`Restarting ${runningInstances.length} running instance(s)...`);
|
|
217
|
+
for (const instance of runningInstances) {
|
|
218
|
+
const storedOptions = readInstanceOptions(instance.instanceFilePath) || { port: instance.port };
|
|
219
|
+
if (storedOptions.launchMode === 'foreground') {
|
|
220
|
+
restartResults.push({ port: instance.port, ok: false, reason: 'foreground-restart-required' });
|
|
221
|
+
continue;
|
|
199
222
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
223
|
+
try {
|
|
224
|
+
const requested = await requestShutdown(instance.port, instance.host);
|
|
225
|
+
const stopped = await stopProcess(instance.pid, {
|
|
226
|
+
shutdownWaitMs: requested ? 5000 : 0,
|
|
227
|
+
gracefulTimeoutMs: 2500,
|
|
228
|
+
forceTimeoutMs: 3000,
|
|
229
|
+
});
|
|
230
|
+
if (!stopped) {
|
|
231
|
+
restartResults.push({ port: instance.port, ok: false, reason: 'stop-failed' });
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
removePidFile(instance.pidFilePath);
|
|
235
|
+
const restartedPort = await serveCommand({
|
|
205
236
|
port: storedOptions.port || instance.port,
|
|
206
237
|
host: storedOptions.host,
|
|
207
238
|
explicitPort: true,
|
|
208
239
|
uiPassword: storedOptions.uiPassword,
|
|
240
|
+
apiOnly: storedOptions.apiOnly === true,
|
|
209
241
|
suppressStartupSummary: true,
|
|
210
242
|
suppressUiPasswordWarning: true,
|
|
243
|
+
suppressQuietOutput: true,
|
|
211
244
|
quiet: true,
|
|
212
245
|
});
|
|
246
|
+
restartResults.push({ port: instance.port, restartedPort, ok: true });
|
|
247
|
+
} catch (error) {
|
|
248
|
+
restartResults.push({
|
|
249
|
+
port: instance.port,
|
|
250
|
+
ok: false,
|
|
251
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
252
|
+
});
|
|
213
253
|
}
|
|
214
|
-
restartedCount = runningInstances.length;
|
|
215
254
|
}
|
|
216
255
|
}
|
|
217
256
|
|
|
218
|
-
|
|
219
|
-
|
|
257
|
+
const restartedCount = restartResults.filter((entry) => entry.ok).length;
|
|
258
|
+
const failedRestartCount = restartResults.length - restartedCount;
|
|
259
|
+
const versionVerified = latestVersion === 'latest' || installedVersion === latestVersion;
|
|
260
|
+
const messages = [];
|
|
261
|
+
if (!versionVerified) {
|
|
262
|
+
messages.push({
|
|
263
|
+
level: 'warning',
|
|
264
|
+
code: 'VERSION_MISMATCH',
|
|
265
|
+
message: `Package manager completed, but this install reports ${installedVersion} instead of ${latestVersion}.`,
|
|
266
|
+
});
|
|
220
267
|
}
|
|
221
|
-
|
|
268
|
+
if (failedRestartCount > 0) {
|
|
269
|
+
messages.push({
|
|
270
|
+
level: 'warning',
|
|
271
|
+
code: 'RESTART_PARTIAL',
|
|
272
|
+
message: `${failedRestartCount} running instance(s) require manual restart.`,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
updateSpin?.clear();
|
|
222
277
|
if (isJsonMode(options)) {
|
|
223
278
|
printJson({
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
279
|
+
status: messages.length > 0 ? 'warning' : 'ok',
|
|
280
|
+
previousVersion: currentVersion,
|
|
281
|
+
currentVersion: installedVersion,
|
|
282
|
+
latestVersion,
|
|
283
|
+
versionVerified,
|
|
284
|
+
updated: installedVersion !== currentVersion || versionVerified,
|
|
227
285
|
packageManager: pm,
|
|
228
286
|
restartedCount,
|
|
229
287
|
startupServiceRestarted,
|
|
288
|
+
restartResults,
|
|
289
|
+
messages,
|
|
230
290
|
});
|
|
231
291
|
return;
|
|
232
292
|
}
|
|
233
293
|
if (showOutput) {
|
|
234
|
-
|
|
294
|
+
logStatus(versionVerified ? 'success' : 'warning', `version ${currentVersion} -> ${installedVersion}`);
|
|
295
|
+
for (const message of messages) {
|
|
296
|
+
logStatus('warning', `[${message.code}]`, message.message);
|
|
297
|
+
}
|
|
298
|
+
clackOutro(messages.length > 0 ? 'update complete with warnings' : 'update complete');
|
|
235
299
|
} else if (isQuietMode(options)) {
|
|
236
|
-
process.stdout.write(`updated ${
|
|
300
|
+
process.stdout.write(`updated ${currentVersion} -> ${installedVersion} restarted:${restartedCount} failed:${failedRestartCount}\n`);
|
|
237
301
|
}
|
|
238
302
|
};
|
|
239
303
|
}
|
|
@@ -23,6 +23,9 @@ async function withTempPiChamberDataDir(fn) {
|
|
|
23
23
|
|
|
24
24
|
function createTestUpdateCommand(overrides = {}) {
|
|
25
25
|
const executeUpdate = overrides.executeUpdate || vi.fn(() => ({ success: true, exitCode: 0 }));
|
|
26
|
+
const getCurrentVersion = overrides.getCurrentVersion || vi.fn()
|
|
27
|
+
.mockReturnValueOnce('1.0.0')
|
|
28
|
+
.mockReturnValue('9.9.9');
|
|
26
29
|
const serveCommand = overrides.serveCommand || vi.fn();
|
|
27
30
|
const restartUserStartupService = overrides.restartUserStartupService || vi.fn();
|
|
28
31
|
const updateCommand = createUpdateCommand({
|
|
@@ -31,11 +34,14 @@ function createTestUpdateCommand(overrides = {}) {
|
|
|
31
34
|
isInsideSystemdService: overrides.isInsideSystemdService || (() => false),
|
|
32
35
|
isUserStartupServiceActive: overrides.isUserStartupServiceActive || (() => false),
|
|
33
36
|
restartUserStartupService,
|
|
37
|
+
discoverInstances: overrides.discoverInstances,
|
|
38
|
+
requestShutdown: overrides.requestShutdown,
|
|
39
|
+
stopProcess: overrides.stopProcess,
|
|
34
40
|
importFromFilePath: vi.fn(async () => ({
|
|
35
41
|
checkForUpdates: overrides.checkForUpdates || vi.fn(async () => ({ available: true, version: '9.9.9' })),
|
|
36
42
|
resolveTrustedUpdatePackageManager: overrides.resolveTrustedUpdatePackageManager || vi.fn(() => 'npm'),
|
|
37
43
|
executeUpdate,
|
|
38
|
-
getCurrentVersion
|
|
44
|
+
getCurrentVersion,
|
|
39
45
|
})),
|
|
40
46
|
});
|
|
41
47
|
return { updateCommand, executeUpdate, serveCommand, restartUserStartupService };
|
|
@@ -58,6 +64,95 @@ describe('update command', () => {
|
|
|
58
64
|
});
|
|
59
65
|
});
|
|
60
66
|
|
|
67
|
+
it('reports the version before and after a successful update', async () => {
|
|
68
|
+
await withTempPiChamberDataDir(async () => {
|
|
69
|
+
const output = [];
|
|
70
|
+
const originalWrite = process.stdout.write;
|
|
71
|
+
process.stdout.write = vi.fn((chunk) => {
|
|
72
|
+
output.push(String(chunk));
|
|
73
|
+
return true;
|
|
74
|
+
});
|
|
75
|
+
const { updateCommand } = createTestUpdateCommand();
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
await updateCommand({ json: true });
|
|
79
|
+
expect(JSON.parse(output.join(''))).toMatchObject({
|
|
80
|
+
status: 'ok',
|
|
81
|
+
previousVersion: '1.0.0',
|
|
82
|
+
currentVersion: '9.9.9',
|
|
83
|
+
latestVersion: '9.9.9',
|
|
84
|
+
versionVerified: true,
|
|
85
|
+
updated: true,
|
|
86
|
+
});
|
|
87
|
+
} finally {
|
|
88
|
+
process.stdout.write = originalWrite;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('reports a version mismatch as a warning', async () => {
|
|
94
|
+
await withTempPiChamberDataDir(async () => {
|
|
95
|
+
const output = [];
|
|
96
|
+
const originalWrite = process.stdout.write;
|
|
97
|
+
process.stdout.write = vi.fn((chunk) => {
|
|
98
|
+
output.push(String(chunk));
|
|
99
|
+
return true;
|
|
100
|
+
});
|
|
101
|
+
const { updateCommand } = createTestUpdateCommand({
|
|
102
|
+
getCurrentVersion: vi.fn().mockReturnValueOnce('1.0.0').mockReturnValue('1.0.0'),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
await updateCommand({ json: true });
|
|
107
|
+
expect(JSON.parse(output.join(''))).toMatchObject({
|
|
108
|
+
status: 'warning',
|
|
109
|
+
previousVersion: '1.0.0',
|
|
110
|
+
currentVersion: '1.0.0',
|
|
111
|
+
versionVerified: false,
|
|
112
|
+
});
|
|
113
|
+
} finally {
|
|
114
|
+
process.stdout.write = originalWrite;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('reports partial instance restart failures without losing successful results', async () => {
|
|
120
|
+
await withTempPiChamberDataDir(async (dir) => {
|
|
121
|
+
const firstOptions = path.join(dir, 'first.json');
|
|
122
|
+
const secondOptions = path.join(dir, 'second.json');
|
|
123
|
+
fs.writeFileSync(firstOptions, JSON.stringify({ port: 3001, launchMode: 'daemon', apiOnly: true }));
|
|
124
|
+
fs.writeFileSync(secondOptions, JSON.stringify({ port: 3002, launchMode: 'daemon' }));
|
|
125
|
+
const output = [];
|
|
126
|
+
const originalWrite = process.stdout.write;
|
|
127
|
+
process.stdout.write = vi.fn((chunk) => {
|
|
128
|
+
output.push(String(chunk));
|
|
129
|
+
return true;
|
|
130
|
+
});
|
|
131
|
+
const { updateCommand, serveCommand } = createTestUpdateCommand({
|
|
132
|
+
discoverInstances: async () => [
|
|
133
|
+
{ port: 3001, pid: 101, instanceFilePath: firstOptions, pidFilePath: path.join(dir, 'first.pid') },
|
|
134
|
+
{ port: 3002, pid: 102, instanceFilePath: secondOptions, pidFilePath: path.join(dir, 'second.pid') },
|
|
135
|
+
],
|
|
136
|
+
requestShutdown: async () => true,
|
|
137
|
+
stopProcess: async (pid) => pid === 101,
|
|
138
|
+
serveCommand: vi.fn(async (options) => options.port),
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
await updateCommand({ json: true });
|
|
143
|
+
const payload = JSON.parse(output.join(''));
|
|
144
|
+
expect(payload).toMatchObject({ status: 'warning', restartedCount: 1 });
|
|
145
|
+
expect(payload.restartResults).toEqual([
|
|
146
|
+
expect.objectContaining({ port: 3001, restartedPort: 3001, ok: true }),
|
|
147
|
+
expect.objectContaining({ port: 3002, ok: false, reason: 'stop-failed' }),
|
|
148
|
+
]);
|
|
149
|
+
expect(serveCommand).toHaveBeenCalledWith(expect.objectContaining({ port: 3001, apiOnly: true }));
|
|
150
|
+
} finally {
|
|
151
|
+
process.stdout.write = originalWrite;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
61
156
|
it('handles failed update execution safely without touching instances', async () => {
|
|
62
157
|
await withTempPiChamberDataDir(async () => {
|
|
63
158
|
const { updateCommand, executeUpdate, serveCommand, restartUserStartupService } = createTestUpdateCommand({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{R as e,j as h}from"./vendor-react-B5Z1Mdn3.js";import{D as E}from"./vendor-react-drawio-BYDptOsj.js";import{c as x}from"./index-
|
|
1
|
+
import{R as e,j as h}from"./vendor-react-B5Z1Mdn3.js";import{D as E}from"./vendor-react-drawio-BYDptOsj.js";import{c as x}from"./index-yWgKW2Fx.js";const D='<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 g(){if(typeof document>"u")return!1;const o=document.documentElement.getAttribute("data-theme");return o==="dark"||!o&&window.matchMedia("(prefers-color-scheme: dark)").matches}const X=e.forwardRef(function({xml:t,readOnly:a,className:R,onChange:c},v){const s=e.useRef(t),i=e.useRef(null),m=e.useRef(!1),[n,k]=e.useState(g),u=e.useRef(t),d=e.useRef(t);d.current!==t&&(d.current=t,u.current=t,s.current=t);const f=e.useRef(n);f.current!==n&&(f.current=n,u.current=s.current);const l=e.useRef(null);e.useEffect(()=>{const r=()=>k(g());r();const p=new MutationObserver(r);return p.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>p.disconnect()},[]),e.useEffect(()=>{const r=setTimeout(()=>{l.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(r)},[]),e.useImperativeHandle(v,()=>({getXml:()=>s.current}));const b=e.useCallback(()=>{!t&&!m.current&&(m.current=!0,setTimeout(()=>{i.current?.template({})},500))},[t]),w=e.useCallback(r=>{s.current=r.xml,c?.(r.xml)},[c]);return h.jsx("div",{ref:l,className:x("h-full w-full",R),children:h.jsx(E,{ref:i,xml:u.current||D,autosave:!0,urlParameters:{ui:a?"simple":n?"dark":"kennedy",spin:!0,libraries:!a,chrome:a,nav:a,layers:a,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:b,onAutoSave:w},n?"dark":"light")})});export{X as D};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{R as r,j as t}from"./vendor-react-B5Z1Mdn3.js";import{u as a}from"./index-
|
|
1
|
+
import{R as r,j as t}from"./vendor-react-B5Z1Mdn3.js";import{u as a}from"./index-yWgKW2Fx.js";import{j as v,I as m}from"./useAppFontEffects-BgK55NDM.js";import{D as j}from"./DiagramEditor-CcbnMl1H.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-vkqQ2P9o.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-BZOGXAGe.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.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-C_3mcJ01.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-BzeePAPn.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-DYppkHEk.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-react-drawio-BYDptOsj.js";function Kt(){const{files:o}=v(),[e,d]=r.useState(null),[s,p]=r.useState(""),[x,n]=r.useState(!0),l=r.useRef(null),c=a(i=>i.pendingDiagramFile),u=r.useCallback(async i=>{n(!0),d(i);try{const f=await o?.readFile?.(i);f&&p(f.content)}catch{p("")}finally{n(!1)}},[o]);r.useEffect(()=>{if(!c)return;const i=a.getState().consumePendingDiagramFile();i&&u(i)},[u,c]);const g=r.useCallback(async()=>{const i=l.current?.getXml();e&&o?.writeFile&&i&&i!==s&&(await o.writeFile(e,i),p(i))},[e,o,s]),h=e?e.split("/").pop()||e:"";return e?x?t.jsx("div",{className:"flex h-full items-center justify-center p-3",children:t.jsx(m,{name:"loader-4",className:"size-4 animate-spin"})}):t.jsxs("div",{className:"flex h-full flex-col",children:[t.jsxs("div",{className:"flex items-center gap-2 border-b border-border/30 px-3 py-1.5",children:[t.jsx(m,{name:"file",className:"size-4 shrink-0 text-muted-foreground"}),t.jsx("span",{className:"typography-ui text-muted-foreground truncate flex-1",children:h}),t.jsx("button",{type:"button",onClick:()=>{g()},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:t.jsx(m,{name:"save-3",className:"size-4"})}),t.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:t.jsx(m,{name:"close",className:"size-4"})})]}),t.jsx("div",{className:"flex-1 min-h-0",children:t.jsx(j,{ref:l,xml:s,className:"h-full"})})]}):t.jsx("div",{className:"flex h-full items-center justify-center p-3",children:t.jsx("div",{className:"typography-ui text-muted-foreground",children:"Pick a file from the tree."})})}export{Kt as DiagramView};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import{j as n,R as r,b as St}from"./vendor-react-B5Z1Mdn3.js";import{c as te,u as Y,w as Ze,n as ze}from"./index-yWgKW2Fx.js";import{b1 as vt,b2 as Ct,aa as jt,aq as et,b3 as tt,aR as Nt,p as Ne,U as Le,I as q,j as nt,Q as re,t as st,aU as it,aC as Lt,b4 as Dt,b5 as kt,aD as Rt,b6 as Et,b7 as At,b8 as Tt,b9 as Mt,k as It,ba as $t,bb as Pt,E as _t,F as Wt,G as Bt}from"./useAppFontEffects-BgK55NDM.js";import{d as rt,P as Ot,i as Ge,a as He,b as zt,C as Gt}from"./gitStatusPredicates-UsytDMy_.js";import{p as Ht}from"./VirtualizedFileDiff-ywmPBXAG.js";import{v as Ut,g as Vt}from"./contextFileOpenGuard-CKyf-TZ7.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-vkqQ2P9o.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-BZOGXAGe.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.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-C_3mcJ01.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-BzeePAPn.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-DYppkHEk.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-DAkBDXRk.js";import"./computeVirtualFileMetrics-3H6mg13G.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-CT3WShpj.js";import"./SessionUnreadDot-1nV0Z2ZA.js";import"./vendor-xterm-xterm-CrXqRur4.js";import"./permissionStore-iKN1K2_x.js";import"./appThemeRegistry-gegrE2dq.js";import"./registerCustomTheme-DmolaWWZ.js";import"./isDiffPlainText-DPCilEx_.js";import"./vendor-diff-C3JhlQdm.js";function Kt(t,s=10){const e=[];let i;for(const l of t.split(`
|
|
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
|
+
`);return t.endsWith(`
|
|
4
|
+
`)?`${a}
|
|
5
|
+
`:a}function Re(t,s,e){if(e==="leading"&&t.contextLines.length>s){const i=t.contextLines.length-s;t.contextLines.splice(0,i),t.additionStart+=i,t.deletionStart+=i}return e==="trailing"&&t.contextLines.length>s&&(t.contextLines.length=s),t.contextLines.length>0&&(t.hunkLines.push(...t.contextLines),t.additionCount+=t.contextLines.length,t.deletionCount+=t.contextLines.length,t.contextLines.length=0),t}function Ie(t,s){s.push(`@@ -${Ue(t.deletionStart,t.deletionCount)} +${Ue(t.additionStart,t.additionCount)} @@`),s.push(...t.hunkLines)}function Ue(t,s){return s===1?`${t}`:`${t},${s}`}const qt=64,Xt=3,de=new Map,Qt=(t,s,e=Xt)=>{const i=`${t}\0${e}\0${s}`,a=de.get(i);if(a)return de.delete(i),de.set(i,a),a;const l=Jt(s),p=l?Ct(Kt(s,e),{oldFile:{name:t,contents:l.before},newFile:{name:t,contents:l.after}})??Ke(t):jt(Yt(t,s))[0]?.files[0]??Ke(t);for(de.set(i,p);de.size>qt;){const u=de.keys().next().value;if(!u)break;de.delete(u)}return p},Yt=(t,s)=>!s.trim()||s.startsWith("diff --git ")||/^--- [^\n]*\r?\n\+\+\+ /m.test(s)?s:`Index: ${t}
|
|
6
|
+
===================================================================
|
|
7
|
+
--- ${t}
|
|
8
|
+
+++ ${t}
|
|
9
|
+
${s}`,Jt=t=>{if(!t.startsWith("diff --git ")&&!/^--- [^\n]*\t?\r?\n\+\+\+ [^\n]*\t?(?:\r?\n|$)/m.test(t))return;const s=[...t.matchAll(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@[^\n]*(?:\r?\n|$)/gm)];if(s.length!==1)return;const e=s[0],i=Number.parseInt(e[1]??"",10),a=Number.parseInt(e[2]??"",10);if(i>1||a>1||!Number.isFinite(i)||!Number.isFinite(a))return;const l=(e.index??0)+e[0].length,p=t.slice(l),u=[],b=[];let h;for(const c of p.split(/\r?\n/)){if(c.startsWith("diff --git ")||c.startsWith("@@ "))break;if(c.startsWith("\\")){if(h==="-"||h===" "){const m=u.at(-1);m&&(m.newline=!1)}if(h==="+"||h===" "){const m=b.at(-1);m&&(m.newline=!1)}continue}if(c.startsWith("-")){u.push({text:c.slice(1),newline:!0}),h="-";continue}if(c.startsWith("+")){b.push({text:c.slice(1),newline:!0}),h="+";continue}c.startsWith(" ")&&(u.push({text:c.slice(1),newline:!0}),b.push({text:c.slice(1),newline:!0}),h=" ")}return{before:Ve(u),after:Ve(b)}},Ve=t=>t.map(s=>s.text+(s.newline?`
|
|
10
|
+
`:"")).join(""),Ke=t=>Ht({name:t,contents:""},{name:t,contents:""}),Zt=t=>/^Binary files .+ differ$/m.test(t)||/^GIT binary patch$/m.test(t),Pe=(t,s,e)=>Zt(s)?{original:"",modified:"",isBinary:!0,patch:s,contextMode:e}:{original:"",modified:"",patch:s,fileDiff:Qt(t,s),contextMode:e},ot=(t,s,e)=>{const i=t??0,a=s??0;return!i&&!a?null:n.jsxs("span",{className:te("typography-meta flex items-center gap-1 text-xs whitespace-nowrap","flex-shrink-0",e?.className),children:[i?n.jsxs("span",{style:{color:"var(--status-success)"},children:["+",i]}):null,a?n.jsxs("span",{style:{color:"var(--status-error)"},children:["-",a]}):null]})},en=r.memo(function({changedFiles:s,selectedFile:e,onSelectFile:i}){return s.length===0?null:n.jsx(et,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:n.jsx("ul",{className:"flex flex-col gap-1",children:s.map(a=>{const l=rt(a),p=e===a.path;return n.jsx("li",{children:n.jsxs("button",{type:"button",onClick:()=>i(a.path),className:te("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",p?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[n.jsx(tt,{filePath:a.path,className:"h-3.5 w-3.5 flex-shrink-0"}),n.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:l.color},title:l.description,"aria-label":l.description,children:l.code}),n.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:a.path,children:a.path}),ot(a.insertions,a.deletions)]})},a.path)})})})}),tn=r.memo(function(){return n.jsx("div",{className:"rounded-lg border border-border/60 bg-background px-3 py-2",children:n.jsx("div",{className:"typography-meta text-muted-foreground",children:"Content of this file cannot be viewed."})})}),nn=r.memo(function({filePath:s,diff:e,renderSideBySide:i}){const a=e.original.length>0,l=e.modified.length>0,p=i?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",u=i?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";return n.jsx("div",{className:"w-full overflow-auto p-4",style:{contain:"layout"},children:n.jsxs("div",{className:p,children:[a&&n.jsxs("div",{className:u,children:[n.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:"Original"}),n.jsx("img",{src:e.original,alt:`Original: ${s}`,className:i?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),l&&n.jsxs("div",{className:u,children:[n.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:a?"Modified":"New"}),n.jsx("img",{src:e.modified,alt:`Modified: ${s}`,className:i?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]})]})})}),sn=r.memo(function({filePath:s,diff:e,renderSideBySide:i,wrapLines:a}){const l=r.useMemo(()=>Nt(s)||"text",[s]);return e.isBinary?n.jsx(tn,{}):Ne(s)?n.jsx(nn,{filePath:s,diff:e,renderSideBySide:i}):n.jsx("div",{className:"w-full",style:{contain:"layout"},children:n.jsx(Ot,{original:e.original,modified:e.modified,fileDiff:e.fileDiff,language:l,fileName:s,renderSideBySide:i,wrapLines:a,layout:"inline"})})}),$e=({label:t,icon:s,loading:e,disabled:i,tone:a,onClick:l})=>n.jsx(Le,{variant:"ghost",size:"sm",className:te("h-6 w-6 rounded-none bg-transparent p-0 text-muted-foreground opacity-70 hover:bg-transparent hover:text-foreground hover:opacity-100",a==="failure"&&"text-[var(--status-error)] hover:text-[var(--status-error)]",a==="success"&&"text-[var(--status-success)] hover:text-[var(--status-success)]"),disabled:i,title:t,"aria-label":t,onClick:p=>{p.stopPropagation(),l()},children:e?n.jsx(q,{name:"loader-4",className:"size-3.5 animate-spin"}):n.jsx(q,{name:s,className:s==="add"?"size-4":"size-3.5"})}),rn=r.memo(function({filePath:s,staged:e,busyAction:i,disabled:a,onAction:l}){return n.jsx("div",{className:"flex items-center gap-0.5 rounded-full border border-[var(--interactive-border)]/45 bg-[var(--surface-background)]/95 px-1 py-0.5 shadow-sm backdrop-blur-md",children:e?n.jsx($e,{label:`Unstage ${s}`,icon:"arrow-go-back",loading:i==="unstage",disabled:a,onClick:()=>l("unstage")}):n.jsxs(n.Fragment,{children:[n.jsx($e,{label:`Revert changes in ${s}`,icon:"arrow-go-back",loading:i==="discard",disabled:a,tone:"failure",onClick:()=>l("discard")}),n.jsx($e,{label:`Stage ${s}`,icon:"add",loading:i==="stage",disabled:a,tone:"success",onClick:()=>l("stage")})]})})}),at=3,on=1e6,an=15e3,qe=500,ln=r.memo(function({directory:s,file:e,layout:i,wrapLines:a,isSelected:l,isExpanded:p,isMounted:u,onSelect:b,onExpandedChange:h,registerSectionRef:c,showOpenInEditorAction:m=!1,isOpeningInEditor:F=!1,onOpenInEditor:k,staged:x=!1,showFileActions:C=!0,loadFullFiles:g=!1,initialDiffData:d=null}){const{git:_}=nt(),R=re(r.useCallback(f=>f.directories.get(s)?.diffCache.get(e.path)??null,[s,e.path])),X=re(f=>f.setDiff),S=re(f=>f.fetchStatus),y=Y(f=>f.setDiffFileLayout),[w,j]=r.useState(0),[A,E]=r.useState(null),[z,N]=r.useState(!1),[I,W]=r.useState(null),[ne,oe]=r.useState(!1),[se,fe]=r.useState(null),[T,$]=r.useState(null),G=r.useRef(null),pe=r.useRef(null),B=r.useMemo(()=>rt(e),[e]),ae=i==="side-by-side",K=g?"full":"patch",U=`${e.index}:${e.working_dir}:${e.insertions}:${e.deletions}`,V=r.useMemo(()=>d||(x?T:se||(R?{original:R.original,modified:R.modified,isBinary:R.isBinary,contextMode:"full"}:null)),[R,d,se,x,T]),me=V?.contextMode===K,ve=r.useCallback(f=>{pe.current=f,c(e.path,f)},[e.path,c]),ie=r.useCallback(f=>{h(e.path,f)},[e.path,h]),he=r.useCallback(()=>{b(e.path)},[e.path,b]);r.useEffect(()=>{x?$(null):fe(null),E(null),G.current=null},[U,x]),r.useEffect(()=>{if(!p||!u)return;if(!s||d||V&&me){G.current=null,N(!1);return}const f=`${s}::${e.path}::${x?"staged":"unstaged"}::${U}::${K}::${w}`;if(G.current===f)return;G.current=f,E(null),N(!0);let P=!1;const J=Ze(),xe=g?on:at,ce=Ne(e.path)?_.getGitFileDiff(s,{path:e.path,staged:x}):_.getGitDiff(s,{path:e.path,staged:x,contextLines:xe}),Z=an,be=new Promise((H,O)=>{setTimeout(()=>O(new Error(`Timed out after ${Z}ms`)),Z)});return Promise.race([ce,be]).then(H=>{if(!P){if("diff"in H){const O=Pe(e.path,H.diff,K);x?$(O):fe(O)}else{const O={original:H.original??"",modified:H.modified??"",isBinary:H.isBinary,contextMode:"full"};x?$(O):X(s,e.path,O,J)}N(!1)}}).catch(H=>{if(P)return;const O=H instanceof Error?H.message:String(H);E(O),N(!1)}),()=>{P=!0,G.current===f&&(G.current=null)}},[K,V,me,w,s,e.path,U,_,d,p,u,g,X,x]);const ge=r.useCallback(()=>{ie(!p),he()},[ie,he,p]),le=r.useCallback(async f=>{if(!(!s||I!==null)){W(f);try{f==="stage"?await _.stageGitFile(s,e.path):f==="unstage"?await _.unstageGitFile(s,e.path):await _.revertGitFile(s,e.path,{scope:"working"}),j(P=>P+1),await S(s,_)}catch(P){const J=f==="unstage"?"Failed to unstage changes":f==="stage"?"Failed to stage changes":"Failed to revert changes";st.error(P instanceof Error?P.message:J)}finally{W(P=>P===f?null:P)}}},[s,S,e.path,I,_]);return n.jsxs("div",{ref:ve,className:te("scroll-mt-9 border-b border-[var(--interactive-border)]/40 last:border-b-0"),children:[n.jsx("div",{className:te("z-30 border-b border-[var(--interactive-border)]/35 bg-[var(--surface-elevated)]/90 backdrop-blur-md supports-[backdrop-filter]:bg-[var(--surface-elevated)]/80","sticky top-0"),children:n.jsxs("div",{role:"button",tabIndex:0,onClick:ge,onKeyDown:f=>{f.target===f.currentTarget&&(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),ge())},className:te("cursor-pointer","group/header relative grid min-h-9 w-full min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2 overflow-hidden px-3 py-2","bg-transparent","text-muted-foreground hover:text-foreground",l?"bg-[var(--interactive-selection)]/35":null),children:[n.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-[var(--interactive-hover)]/50"}),n.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[n.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:p?n.jsx(q,{name:"arrow-down-s",className:"size-4"}):n.jsx(q,{name:"arrow-right-s",className:"size-4"})}),n.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:{color:B.color},title:B.description,"aria-label":B.description,children:B.code}),n.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:e.path,children:n.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[n.jsx(tt,{filePath:e.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),(()=>{const f=e.path.lastIndexOf("/");if(f===-1)return n.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:e.path});const P=e.path.slice(0,f),J=e.path.slice(f+1);return n.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[n.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:P}),n.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[n.jsx("span",{className:"text-muted-foreground",children:"/"}),n.jsx("span",{className:"text-foreground",children:J})]})]})})()]})})]}),n.jsxs("div",{className:"relative flex shrink-0 items-center justify-self-end gap-2",children:[ot(e.insertions,e.deletions),m&&k?n.jsx(Le,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:"Open this file in editor at change",onClick:f=>{f.stopPropagation(),k(e.path,V)},disabled:F,children:F?n.jsx(q,{name:"loader-4",className:"size-3.5 animate-spin"}):n.jsx(q,{name:"edit",className:"size-3.5"})}):null,n.jsx(it,{mode:ae?"side-by-side":"unified",onModeChange:f=>{const P=f==="side-by-side"?"side-by-side":"inline";y(e.path,P)},className:"opacity-70"})]})]})}),p&&n.jsxs("div",{className:"relative overflow-hidden bg-background",children:[!u&&!A?n.jsx("div",{className:"h-40 border border-border/40 bg-background/40"}):null,A?n.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:"Failed to load diff"}),n.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:A}),n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>j(f=>f+1),children:"Retry"})]}):null,u&&z&&!V&&!A?n.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx(q,{name:"loader-4",className:"size-4 animate-spin"}),"Loading diff..."]}):null,u&&V&&!ne&&e.insertions+e.deletions>qe?n.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:`Large diff (${e.insertions+e.deletions} changed lines)`}),n.jsx("div",{className:"typography-meta text-muted-foreground",children:"Rendering may be slow. You can still view the diff by clicking below."}),n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>oe(!0),children:"Render anyway"})]}):null,u&&V&&(ne||e.insertions+e.deletions<=qe)?n.jsxs(n.Fragment,{children:[n.jsx(sn,{filePath:e.path,diff:V,renderSideBySide:ae,wrapLines:a}),C?n.jsx("div",{className:"pointer-events-none absolute bottom-3 right-3 z-20",children:n.jsx("div",{className:"pointer-events-auto",children:n.jsx(rn,{filePath:e.path,staged:x,busyAction:I,disabled:I!==null,onAction:le})})}):null]}):null]})]})}),cn=1100,Xe=300,un=t=>t<=6?t:t<=12?6:t<=25?4:2,dn=(t,s)=>Lt(t,s),Qe=(t,s)=>{const e=t.split(`
|
|
11
|
+
`),i=s.split(`
|
|
12
|
+
`),a=Math.min(e.length,i.length);for(let l=0;l<a;l+=1)if(e[l]!==i[l])return l+1;return i.length>e.length?e.length+1:e.length>i.length?Math.max(1,i.length):1},fn=t=>Array.isArray(t)?t.filter(s=>!s||typeof s!="object"?!1:typeof s.file=="string"):[],pn=t=>t.split(/^diff --git /m).slice(1).flatMap(e=>{const[i=""]=e.split(`
|
|
13
|
+
`,1),a=i.lastIndexOf(" b/");if(a<=2)return[];const l=i.slice(2,a),p=i.slice(a+3).trim(),u=`diff --git ${e}`,b=u.includes(`
|
|
14
|
+
new file mode `)?"added":u.includes(`
|
|
15
|
+
deleted file mode `)?"deleted":u.includes(`
|
|
16
|
+
rename from `)?"renamed":"modified";let h=0,c=0;for(const m of u.split(`
|
|
17
|
+
`))m.startsWith("+")&&!m.startsWith("+++")&&(h+=1),m.startsWith("-")&&!m.startsWith("---")&&(c+=1);return[{file:b==="deleted"?l:p,status:b,additions:h,deletions:c,patch:u}]}),mn=t=>t==="added"?"A":t==="deleted"?"D":"M";function hn({activeDiffScope:t,effectiveDirectory:s,branchBase:e,branchHead:i,git:a,sessionMessageRecords:l}){const[p,u]=r.useState([]),[b,h]=r.useState(null),[c,m]=r.useState(!1),F=r.useMemo(()=>{const C=Dt(l,{showTextJustificationActivity:!1,showTurnChangedFiles:!0,mergeHiddenUserTurns:!0});for(let g=C.turns.length-1;g>=0;g-=1){const d=C.turns[g];if(!d)continue;const _=d.activityParts.map(S=>S.part).filter(S=>S.type==="tool"),R=kt(_);if(R.length>0)return R.map(S=>({file:S.path,status:"modified",additions:S.additions,deletions:S.deletions,patch:S.patch}));const X=fn(d.userMessage.info?.summary?.diffs);if(X.length>0)return X}return[]},[l]);r.useEffect(()=>{if(t!=="branch"||!s||!e||!i||!a.getGitRangeDiff){u([]),h(null),m(!1);return}let C=!1;return m(!0),h(null),a.getGitRangeDiff(s,{base:e,head:i,contextLines:at}).then(g=>{C||(u(pn(g.diff??"")),m(!1))}).catch(g=>{C||(u([]),m(!1),h(g instanceof Error?g.message:String(g)))}),()=>{C=!0}},[t,e,i,s,a]);const k=r.useMemo(()=>{const C=new Map;for(const g of F)if(g.file){if(typeof g.patch=="string"){C.set(g.file,Pe(g.file,g.patch,"patch"));continue}C.set(g.file,{original:g.before??"",modified:g.after??"",contextMode:"full"})}return C},[F]),x=r.useMemo(()=>{const C=new Map;for(const g of p)!g.file||typeof g.patch!="string"||C.set(g.file,Pe(g.file,g.patch,"patch"));return C},[p]);return{branchDiffs:p,branchDiffError:b,branchDiffLoading:c,lastTurnDiffs:F,lastTurnDiffData:k,branchDiffData:x}}const Ye=(t,s)=>{if(s.length===0)return null;let e=null,i=null;for(const l of s)l.top<=t?(!e||l.top>e.top)&&(e=l):(!i||l.top<i.top)&&(i=l);const a=e??i;return a?{path:a.path,topOffset:a.top-t}:null},gn=(t,s,e,i)=>Math.min(Math.max(0,i),Math.max(0,t+e-s));function xn({pinSelectedFileHeaderToTopOnNavigate:t,scrollRequestNonce:s,changedFiles:e,expandedFiles:i,setMountedStackedFiles:a,fileDiffRefreshNonce:l}){const p=r.useRef(null),u=r.useRef(new Map),[b,h]=r.useState(null),c=r.useRef(null),m=r.useRef(null),F=r.useRef(!1),k=r.useRef(null),x=r.useRef(null),C=r.useRef(null),g=r.useCallback(()=>{const y=p.current;if(!y)return null;const w=y.getBoundingClientRect().top,j=[];for(const[A,E]of u.current)E&&j.push({path:A,top:E.getBoundingClientRect().top});return Ye(w,j)},[]),d=r.useCallback(()=>{c.current=null,F.current=!1,h(null),m.current!==null&&(window.cancelAnimationFrame(m.current),m.current=null)},[]),_=r.useCallback(()=>{k.current=null;const y=p.current;if(!y)return;const w=y.getBoundingClientRect(),j=w.top-Xe,A=w.bottom+Xe,E={},z=[];for(const[N,I]of u.current){if(!I)continue;const W=I.getBoundingClientRect();z.push({path:N,top:W.top}),i.has(N)&&(W.bottom<j||W.top>A||(E[N]=!0))}x.current=Ye(w.top,z),a(N=>{let I=!1;const W=new Set(N);for(const ne of Object.keys(E))W.has(ne)||(W.add(ne),I=!0);return I?W:N})},[i,a]),R=r.useCallback(()=>{typeof window>"u"||k.current===null&&(k.current=window.requestAnimationFrame(_))},[_]);r.useEffect(()=>{const y=p.current;if(y)return R(),y.addEventListener("scroll",R,{passive:!0}),window.addEventListener("resize",R),()=>{y.removeEventListener("scroll",R),window.removeEventListener("resize",R),k.current!==null&&(window.cancelAnimationFrame(k.current),k.current=null)}},[e,i,R]),r.useLayoutEffect(()=>{const y=C.current;if(!y)return;C.current=null;const w=p.current,j=u.current.get(y.path);if(!w||!j)return;const A=w.getBoundingClientRect().top,E=j.getBoundingClientRect().top-A;w.scrollTop=gn(w.scrollTop,y.topOffset,E,w.scrollHeight-w.clientHeight),x.current=y},[l]);const X=r.useCallback((y,w)=>{const j=u.current;w?j.set(y,w):j.delete(y),R()},[R]),S=r.useCallback(y=>{const w=u.current.get(y),j=p.current;if(!w||!j)return!1;const A=w.getBoundingClientRect().top-j.getBoundingClientRect().top;return j.scrollTo({top:j.scrollTop+A,behavior:"auto"}),!0},[]);return r.useEffect(()=>{if(!c.current)return;let w=0;const j=20;let A=!1;const E=(N=!0)=>{A||(A=!0,c.current=null,F.current=!1,N&&h(null),m.current!==null&&(window.cancelAnimationFrame(m.current),m.current=null))},z=()=>{if(A){m.current=null;return}const N=c.current;if(!N){E(),m.current=null;return}if(!S(N)){w+=1,w<j?m.current=window.requestAnimationFrame(z):(E(),m.current=null);return}if(t&&F.current){h(N),E(!1);return}E()};return m.current=window.requestAnimationFrame(z),()=>{A=!0,m.current!==null&&(window.cancelAnimationFrame(m.current),m.current=null)}},[t,s,S]),{diffScrollRef:p,fileSectionRefs:u,pinnedStackedTarget:b,pendingScrollTargetRef:c,shouldPinAfterAlignRef:F,pendingScrollAnchorRestoreRef:C,lastScrollAnchorRef:x,captureScrollAnchor:g,cancelPendingScrollAlignment:d,queueVisibleStackedFilesSync:R,registerSectionRef:X,scrollToFile:S}}const Je=t=>{if(!t)return null;const s=t.split(`
|
|
18
|
+
`);let e=null;for(const i of s){const a=i.match(/^@@\s*-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s*@@/);if(a){const l=Number.parseInt(a[1]??"",10);e=Number.isFinite(l)&&l>=1?l:null;continue}if(e!==null){if(i.startsWith(" ")){e+=1;continue}if(i.startsWith("+"))return e;if(i.startsWith("-"))return Math.max(1,e)}}return null};function bn({effectiveDirectory:t,activeDiffStaged:s,git:e,files:i,setDiff:a,openContextFileAtLine:l}){const[p,u]=r.useState(null),b=r.useCallback(async(h,c)=>{if(!t||!h)return;u(h);const m=Ze();try{let F=null;if(c?.patch&&!c.isBinary&&!Ne(h)?F=Je(c.patch):c&&c.contextMode==="full"&&!c.isBinary&&!Ne(h)&&(F=Qe(c.original,c.modified)),F===null)try{const d=await e.getGitDiff(t,{path:h,staged:s,contextLines:3});F=Je(d.diff)}catch{F=null}let k=c;if(F===null||!k){const d=await e.getGitFileDiff(t,{path:h,staged:s});k={original:d.original??"",modified:d.modified??"",isBinary:d.isBinary},s||a(t,h,k,m??void 0)}const x=F??(k.isBinary||Ne(h)?1:Qe(k.original,k.modified)),C=dn(t,h),g=await Ut(i,C,{directory:t});if(!g.ok){st.error(Vt(g.reason));return}l(t,C,x,1)}finally{u(F=>F===h?null:F)}},[s,t,i,e,l,a]);return{openingEditorFilePath:p,openFileInEditorAtChange:b}}function yn(t){const{hideStackedFileSidebar:s=!1,stackedDefaultCollapsedAll:e=!1,pinSelectedFileHeaderToTopOnNavigate:i=!1,diffScope:a="all",branchBase:l=null,branchHead:p=null,targetFilePath:u=null}=t,{git:b,files:h}=nt(),c=Rt(),{screenWidth:m,isMobile:F}=Et(),k=At(c??null),x=Tt(c??null),C=Mt(c??null),g=re(o=>o.setActiveDirectory),d=re(o=>o.ensureStatus),_=re(o=>o.fetchStatus),R=re(o=>o.clearDiffCache),X=re(o=>o.setDiff),[S,y]=r.useState(null),[w,j]=r.useState(!1),[A,E]=r.useState(()=>new Set),[z,N]=r.useState(()=>new Set),[I,W]=r.useState(!1),[ne,oe]=r.useState(0),[se,fe]=r.useState(()=>new Map),[T,$]=r.useState(a);r.useEffect(()=>{$(a)},[a]);const G=Y(o=>o.pendingDiffFile),pe=Y(o=>o.pendingDiffStaged),B=Y(o=>o.pendingDiffScope),ae=Y(o=>o.setPendingDiffFile),K=Y(o=>o.diffLayoutPreference),U=Y(o=>o.diffFileLayout),V=Y(o=>o.setDiffFileLayout),me=Y(o=>o.diffWrapLines),ve=Y(o=>o.setDiffWrapLines),ie=Y(o=>o.openContextFileAtLine),he=It(o=>o.currentSessionId),ge=$t(he??""),le=me,f=T==="staged"?!0:T==="working"?!1:null,P=f??w,J=F||m<=768,xe=!s&&!J&&m>=1024,ce=r.useRef(null),{branchDiffs:Z,branchDiffError:be,branchDiffLoading:H,lastTurnDiffs:O,lastTurnDiffData:De,branchDiffData:ee}=hn({activeDiffScope:T,effectiveDirectory:c,branchBase:l,branchHead:p,git:b,sessionMessageRecords:ge}),L=r.useMemo(()=>{if(T==="turn"||T==="branch")return(T==="branch"?Z:O).map(M=>({path:M.file??"",index:"",working_dir:mn(M.status),insertions:M.additions??0,deletions:M.deletions??0,isNew:M.status==="added"})).filter(M=>M.path).sort((M,Q)=>M.path.localeCompare(Q.path));if(!x?.files)return[];const o=x.diffStats??{},D=T==="staged"?Ge:T==="working"?He:()=>!0;return x.files.filter(D).map(v=>({...v,insertions:o[v.path]?.insertions??0,deletions:o[v.path]?.deletions??0,isNew:zt(v)})).sort((v,M)=>v.path.localeCompare(M.path))},[T,Z,O,x]),Ee=r.useMemo(()=>x?.files?x.files.filter(He).length:0,[x]),Ae=r.useMemo(()=>x?.files?x.files.filter(Ge).length:0,[x]),lt=O.length,ct=x?.files?.length??0,ut=Z.length,{diffScrollRef:dt,pinnedStackedTarget:ft,pendingScrollTargetRef:ye,shouldPinAfterAlignRef:we,pendingScrollAnchorRestoreRef:_e,lastScrollAnchorRef:We,captureScrollAnchor:Be,cancelPendingScrollAlignment:Fe,queueVisibleStackedFilesSync:ke,registerSectionRef:pt,scrollToFile:Oe}=xn({pinSelectedFileHeaderToTopOnNavigate:i,scrollRequestNonce:ne,changedFiles:L,expandedFiles:A,setMountedStackedFiles:N,fileDiffRefreshNonce:se}),Se=r.useCallback(o=>{E(D=>{if(D.has(o))return D;const v=new Set(D);return v.add(o),v})},[]),Te=r.useMemo(()=>L.map(o=>o.path).join("\0"),[L]);r.useEffect(()=>{const o=Te?Te.split("\0"):[],D=new Set(o),v=`${c??""}:${T}:${e?"collapsed":"default"}`,M=ce.current!==v;ce.current=v,E(Q=>{if(M){const ue=e?0:un(o.length);return new Set(o.slice(0,ue))}let Ce=!1;const je=new Set;for(const ue of Q){if(!D.has(ue)){Ce=!0;continue}je.add(ue)}return Ce?je:Q}),N(Q=>{if(M)return new Set;let Ce=!1;const je=new Set;for(const ue of Q){if(!D.has(ue)){Ce=!0;continue}je.add(ue)}return Ce?je:Q})},[T,Te,c,N,e]);const Me=r.useCallback(o=>{const D=U[o.path];if(D)return D;if(K==="inline")return"inline";if(K==="side-by-side")return"side-by-side";const v=m<cn;return o.isNew||v?"inline":"side-by-side"},[U,K,m]),mt=r.useMemo(()=>L.length===0?null:L.every(o=>Me(o)==="side-by-side")?"side-by-side":"inline",[L,Me]);r.useEffect(()=>{c&&(g(c),d(c,b))},[c,g,d,b]),r.useEffect(()=>{if(c)return Pt.onGitRefreshHint(o=>{ze(o.directory)===ze(c)&&(o.paths?.length&&(_e.current=Be()??We.current,R(c,o.paths),fe(D=>{const v=new Map(D);for(const M of o.paths??[])v.set(M,(v.get(M)??0)+1);return v})),_(c,b,{silent:!0}))})},[Be,R,c,_,b,We,_e]),r.useEffect(()=>{T!=="all"&&!B||G&&(B&&$(B),y(G),j(B==="staged"||!B&&pe),ae(null),we.current=!0,ye.current=G,Se(G),oe(o=>o+1))},[T,Se,G,B,pe,ye,ae,we]),r.useEffect(()=>{if(T==="all")return;const o=u?.trim();o&&(y(o),j(T==="staged"),we.current=!0,ye.current=o,Se(o),oe(D=>D+1))},[T,Se,ye,we,u]),r.useEffect(()=>{if(!S)return;L.some(D=>D.path===S)||(y(null),j(!1))},[L,S]);const ht=r.useCallback((o,D)=>{Fe(),E(v=>{const M=v.has(o);if(D===M)return v;const Q=new Set(v);return D?Q.add(o):Q.delete(o),Q}),D||N(v=>{if(!v.has(o))return v;const M=new Set(v);return M.delete(o),M}),ke()},[Fe,ke,N]),gt=r.useCallback(()=>{Fe(),E(o=>o.size>0?new Set:new Set(L.map(D=>D.path))),N(new Set),ke()},[Fe,L,ke,N]),xt=r.useCallback(o=>{},[]),bt=r.useCallback(o=>{Fe(),y(o),j(!1),we.current=!0,ye.current=o,Se(o),oe(D=>D+1),Oe(o)},[Fe,Se,ye,Oe,we]),yt=r.useCallback(o=>{const D=o==="side-by-side"?"side-by-side":"inline";L.forEach(v=>{V(v.path,D)})},[L,V]),{openingEditorFilePath:wt,openFileInEditorAtChange:Ft}=bn({effectiveDirectory:c,activeDiffStaged:P,git:b,files:h,setDiff:X,openContextFileAtLine:ie});return{git:b,files:h,effectiveDirectory:c,screenWidth:m,isMobile:F,isGitRepo:k,status:x,isLoadingStatus:C,activeDiffScope:T,setActiveDiffScope:$,branchDiffs:Z,branchDiffError:be,branchDiffLoading:H,diffWrapLines:le,setDiffWrapLines:ve,forcedStaged:f,displayFileStaged:w,displayFile:S,pinnedStackedTarget:ft,expandedFiles:A,mountedStackedFiles:z,loadFullFiles:I,setLoadFullFiles:W,fileDiffRefreshNonce:se,showFileSidebar:xe,diffScrollRef:dt,lastTurnDiffData:De,branchDiffData:ee,changedFiles:L,workingFileCount:Ee,stagedFileCount:Ae,turnFileCount:lt,allFileCount:ct,branchFileCount:ut,currentLayoutForAllFiles:mt,openingEditorFilePath:wt,registerSectionRef:pt,handleStackedEntryExpandedChange:ht,handleExpandOrCollapseAll:gt,handleSelectFile:xt,handleSelectFileAndScroll:bt,handleHeaderLayoutChange:yt,openFileInEditorAtChange:Ft,getLayoutForFile:Me}}const Di=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:s=!1,pinSelectedFileHeaderToTopOnNavigate:e=!1,showOpenInEditorAction:i=!1,diffScope:a="all",onDiffScopeChange:l,branchBase:p=null,branchHead:u=null,targetFilePath:b=null,flushContent:h=!1,hideToolbar:c=!1,onHeaderControlsStateChange:m,toolbarSlot:F=null})=>{const{effectiveDirectory:k,isGitRepo:x,status:C,isLoadingStatus:g,activeDiffScope:d,setActiveDiffScope:_,branchDiffError:R,branchDiffLoading:X,diffWrapLines:S,setDiffWrapLines:y,forcedStaged:w,displayFileStaged:j,displayFile:A,pinnedStackedTarget:E,expandedFiles:z,mountedStackedFiles:N,loadFullFiles:I,setLoadFullFiles:W,fileDiffRefreshNonce:ne,showFileSidebar:oe,diffScrollRef:se,lastTurnDiffData:fe,branchDiffData:T,changedFiles:$,workingFileCount:G,stagedFileCount:pe,turnFileCount:B,allFileCount:ae,branchFileCount:K,currentLayoutForAllFiles:U,openingEditorFilePath:V,registerSectionRef:me,handleStackedEntryExpandedChange:ve,handleExpandOrCollapseAll:ie,handleSelectFile:he,handleSelectFileAndScroll:ge,handleHeaderLayoutChange:le,openFileInEditorAtChange:f,getLayoutForFile:P}=yn({hideStackedFileSidebar:t,stackedDefaultCollapsedAll:s,pinSelectedFileHeaderToTopOnNavigate:e,diffScope:a,branchBase:p,branchHead:u,targetFilePath:b});r.useEffect(()=>{c&&l?.(d)},[d,c,l]);const J=r.useCallback(()=>{W(ee=>!ee)},[W]),xe=r.useCallback(()=>{y(!S)},[S,y]),ce=r.useCallback(()=>{le(U==="side-by-side"?"unified":"side-by-side")},[U,le]),Z=z.size,be=r.useMemo(()=>({turnCount:B,branchCount:K,expandedCount:Z,totalCount:$.length,loadFullFiles:I,wrapLines:S,layoutMode:U,onExpandOrCollapseAll:ie,onToggleLoadFullFiles:J,onToggleWrapLines:xe,onToggleLayout:ce}),[B,K,Z,$.length,I,S,U,ie,J,xe,ce]);r.useEffect(()=>{c&&m?.(be)},[c,be,m]);const H=()=>{if(!k)return null;const ee=L=>w!==null?w:j&&L===A;return n.jsxs("div",{className:te("flex min-w-0 flex-1 min-h-0 h-full",h?"gap-0":"gap-3 px-3 pb-3 pt-2"),children:[oe&&n.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[n.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[n.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:"Files"}),n.jsx("span",{className:"typography-meta text-muted-foreground",children:$.length})]}),n.jsx(en,{changedFiles:$,selectedFile:null,onSelectFile:ge})]}),n.jsx("div",{className:"relative flex-1 min-w-0 min-h-0 h-full",children:n.jsx(et,{ref:se,outerClassName:"min-h-0 h-full",className:"[overflow-anchor:none] pb-16",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,children:n.jsx("div",{className:"flex flex-col [overflow-anchor:none]","data-diff-virtual-content":!0,children:$.map(L=>n.jsx(ln,{directory:k,file:L,layout:P(L),wrapLines:S,isSelected:!1,isExpanded:z.has(L.path),isMounted:N.has(L.path)||L.path===E,onSelect:he,onExpandedChange:ve,registerSectionRef:me,showOpenInEditorAction:i&&d!=="turn"&&d!=="branch",isOpeningInEditor:V===L.path,onOpenInEditor:(Ee,Ae)=>{f(Ee,Ae)},staged:ee(L.path),showFileActions:d!=="turn"&&d!=="branch",loadFullFiles:I,initialDiffData:d==="turn"?fe.get(L.path)??null:d==="branch"?T.get(L.path)??null:null},`${L.path}:${ne.get(L.path)??0}`))})})})]})},O=()=>k?d!=="turn"&&g&&!C?n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(q,{name:"loader-4",className:"size-4 animate-spin"}),"Loading repository status..."]}):d!=="turn"&&d!=="branch"&&x===!1?n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:"Not a git repository. Use the Git tab to initialize or change directories."}):d==="branch"&&X?n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(q,{name:"loader-4",className:"size-4 animate-spin"}),"Loading branch changes..."]}):d==="branch"&&R?n.jsx("div",{className:"flex flex-1 items-center justify-center px-4 text-center text-sm text-muted-foreground",children:`Failed to load branch changes: ${R}`}):$.length===0?n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:d==="turn"?"No last turn changes to display":"Working tree clean, no changes to display"}):H():n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:"Select a session directory to view diffs"}),De=n.jsxs("div",{className:F?"flex min-w-0 flex-1 items-center gap-1.5":"@container/diff-toolbar flex min-w-0 items-center gap-2 px-3 py-2 bg-background",children:[(x!==!1||d==="turn")&&(d==="all"||d==="working"||d==="staged"||d==="turn"||d==="branch")?n.jsx(Gt,{scope:d,isGitRepo:x,branchAvailable:!!(p&&u),allCount:ae,workingCount:G,stagedCount:pe,turnCount:B,branchCount:K,onScopeChange:ee=>{_(ee),l?.(ee)}}):n.jsx("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:n.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:g&&!C?"Loading changes...":$.length===1?`${$.length} file changed`:`${$.length} files changed`})}),$.length>0&&n.jsxs(Le,{variant:"ghost",size:"sm",onClick:ie,className:te("diff-toolbar__expand-button h-7 flex-shrink-0 gap-1 px-1.5 text-muted-foreground hover:text-foreground","ml-auto"),title:z.size>0?"Collapse all":"Expand all",children:[n.jsx(q,{name:"expand-up-down",className:"size-4"}),n.jsx("span",{className:"diff-toolbar__expand-label typography-ui-label",children:z.size>0?"Collapse all":"Expand all"})]}),$.length>0&&d!=="turn"&&d!=="branch"&&n.jsxs(_t,{children:[n.jsx(Wt,{asChild:!0,children:n.jsx(Le,{variant:"ghost",size:"sm",onClick:()=>W(ee=>!ee),"aria-pressed":I,"aria-label":I?"Unload full files":"Load full files",className:te("h-7 w-7 flex-shrink-0 p-0 text-muted-foreground hover:text-foreground",I&&"bg-interactive-selection text-interactive-selection-foreground"),children:n.jsx(q,{name:"file-download",className:"size-4"})})}),n.jsx(Bt,{children:n.jsx("p",{children:I?"Unload full files":"Load full files"})})]}),$.length>0&&n.jsx(Le,{variant:"ghost",size:"sm",onClick:()=>y(!S),className:te("h-5 w-5 p-0 transition-opacity",S?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:S?"Disable line wrap":"Enable line wrap",children:n.jsx(q,{name:"text-wrap",className:"size-4"})}),U&&n.jsx(it,{mode:U==="side-by-side"?"side-by-side":"unified",onModeChange:le})]});return n.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[F?St.createPortal(De,F):c?null:De,O()]})};export{Di as DiffView};
|