@aiworker/web 1.22.2 → 1.23.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 +7 -0
- package/dist/assets/{CodeMirrorCommentWidgets-CSICpWQD.js → CodeMirrorCommentWidgets-B1Gizi3a.js} +1 -1
- package/dist/assets/DiffView-DXjVsEOw.js +4 -0
- package/dist/assets/{DirtyBranchSwitchDialog-C22HdWj4.js → DirtyBranchSwitchDialog-aig6zJjg.js} +1 -1
- package/dist/assets/FilesView-CJdG0-wk.js +17 -0
- package/dist/assets/{GitView-VQQkYuUw.js → GitView-BXsS3jG6.js} +4 -4
- package/dist/assets/{JsonTreeView-6lrhwD3q.js → JsonTreeView-D_hpXBnF.js} +1 -1
- package/dist/assets/{LinearIssuesView-Ba6Q9569.js → LinearIssuesView-BoUiLQG1.js} +1 -1
- package/dist/assets/MarkdownImageGallery-B_B_a9KS.js +1 -0
- package/dist/assets/MarkdownRendererImpl-xgyyLiBM.js +12 -0
- package/dist/assets/OnboardingScreen-DIp84OWt.js +1 -0
- package/dist/assets/{PatchDiff-BzcZPlOq.js → PatchDiff-8p6nLJaU.js} +1 -1
- package/dist/assets/PierreDiffViewer-DjC8nTk9.js +161 -0
- package/dist/assets/{PlanView-DyDt_nZ_.js → PlanView-CJTmOF6I.js} +2 -2
- package/dist/assets/SettingsView-DD-JqIJx.js +28 -0
- package/dist/assets/{SettingsWindow-DDQYaKWQ.js → SettingsWindow-Cpb4hM6q.js} +1 -1
- package/dist/assets/SymbolsNerdFontMono-Regular-aK5vsLov.woff2 +0 -0
- package/dist/assets/{ToolOutputDialog-iYF8Y2bz.js → ToolOutputDialog-DfaKZXNU.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-CdjbOVMM.js → ToolPartDiffPreview-DtZLzrSK.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-fFFm2QgH.js → VirtualizedFileDiff-C8i9HpTB.js} +1 -1
- package/dist/assets/WalkthroughView-DeKMvZlL.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-CzgLum_K.js → computeVirtualFileMetrics-BBI7ZwrC.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-BdA6bdky.js +1 -0
- package/dist/assets/de-DCrsQ5zS.js +10 -0
- package/dist/assets/es-Dwv4YfH6.js +16 -0
- package/dist/assets/fr-BCWg4Cnx.js +14 -0
- package/dist/assets/ghostty-vt-DdA0Zryv.wasm +0 -0
- package/dist/assets/index-B68h5S5B.css +1 -0
- package/dist/assets/index-DVwMarHI.js +39 -0
- package/dist/assets/{index-Bl3LSbjn.js → index-jXSK5RrB.js} +1 -1
- package/dist/assets/{isDiffPlainText-Dx-dB_8l.js → isDiffPlainText-B_x_rVon.js} +1 -1
- package/dist/assets/{isFilePlainText-CWFPwmnU.js → isFilePlainText-DW_xMer1.js} +1 -1
- package/dist/assets/ja-Bruw3RYC.js +16 -0
- package/dist/assets/ko-idhXGF8j.js +16 -0
- package/dist/assets/main-BkyaQhJX.js +930 -0
- package/dist/assets/{main-DnBAoktx.js → main-CzdPuL0s.js} +2 -2
- package/dist/assets/markdownCore-Cn4Tyejo.js +5 -0
- package/dist/assets/{miniChat-BKyvLseN.js → miniChat-CCkqKOLp.js} +2 -2
- package/dist/assets/{mobile-DKjeFgMN.js → mobile-mvxTo055.js} +2 -2
- package/dist/assets/patchFileDiff-Csk4iNUi.js +13 -0
- package/dist/assets/pl-CGZWUqZJ.js +16 -0
- package/dist/assets/pt-BR-B8V7u7tA.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-BxoyujA5.js +2 -0
- package/dist/assets/renderMobileApp-B48CsP4r.js +25 -0
- package/dist/assets/runtimeEndpointReset-Bg5gx18H.js +17 -0
- package/dist/assets/scheduledTasksApi-BW0Etzwz.js +1 -0
- package/dist/assets/{shikiHighlight-TEQCmzW8.js → shikiHighlight-CRl0SUC9.js} +1 -1
- package/dist/assets/surface-oMvhsog3.js +1 -0
- package/dist/assets/tr-BK_KiO2V.js +7 -0
- package/dist/assets/uk-CG74xV8N.js +16 -0
- package/dist/assets/{useAppFontEffects-D7sNpuL2.js → useAppFontEffects-CPKeOpUo.js} +160 -157
- package/dist/assets/useGitComparison-DH220WmO.js +1 -0
- package/dist/assets/useInlineCommentController-BiWz4AVb.js +2 -0
- package/dist/assets/useRootScrollLock-BS4-kr7P.js +1 -0
- package/dist/assets/{vendor-base-ui-BeMD8X_w.js → vendor-base-ui-DdV8vhHn.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-Dp3KMRQG.js → vendor-codemirror-language-data-Bg4AEeCr.js} +2 -2
- package/dist/assets/vendor-zod-BPAANqvH.js +39 -0
- package/dist/assets/{web-components-_mNEMjFY.js → web-components-z7hfnS8n.js} +1 -1
- package/dist/assets/zh-CN-T4AXofZI.js +16 -0
- package/dist/assets/zh-TW-Dte40sxp.js +16 -0
- package/dist/index.html +5 -43
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +2 -3
- package/server/index.d.ts +15 -0
- package/server/index.js +45 -9
- package/server/lib/data-dir-migration.js +40 -0
- package/server/lib/data-dir-migration.test.js +59 -0
- package/server/lib/event-stream/runtime.test.js +12 -12
- package/server/lib/fs/DOCUMENTATION.md +3 -0
- package/server/lib/fs/routes.js +31 -0
- package/server/lib/fs/routes.test.js +110 -1
- package/server/lib/git/DOCUMENTATION.md +29 -5
- package/server/lib/git/routes.js +24 -4
- package/server/lib/git/service.js +184 -198
- package/server/lib/git/service.test.js +422 -25
- package/server/lib/inherited-env.js +16 -9
- package/server/lib/inherited-env.test.js +8 -9
- package/server/lib/message-queue/DOCUMENTATION.md +4 -1
- package/server/lib/network-defaults.js +23 -0
- package/server/lib/network-defaults.test.js +52 -0
- package/server/lib/opencode/DOCUMENTATION.md +17 -1
- package/server/lib/opencode/bootstrap-runtime.js +2 -0
- package/server/lib/opencode/feature-routes-runtime.js +2 -0
- package/server/lib/opencode/openchamber-routes.js +64 -4
- package/server/lib/opencode/openchamber-routes.test.js +128 -1
- package/server/lib/opencode/routes.js +5 -3
- package/server/lib/opencode/settings-files.js +214 -0
- package/server/lib/opencode/settings-helpers.js +85 -41
- package/server/lib/opencode/settings-helpers.test.js +166 -1
- package/server/lib/opencode/settings-registry.json +747 -0
- package/server/lib/opencode/settings-runtime.js +139 -18
- package/server/lib/opencode/settings-runtime.test.js +163 -5
- package/server/lib/project-context/DOCUMENTATION.md +25 -1
- package/server/lib/project-context/routes.http.test.js +18 -0
- package/server/lib/project-context/routes.js +15 -0
- package/server/lib/project-context/runtime.js +248 -23
- package/server/lib/project-context/runtime.test.js +106 -3
- package/server/lib/projects/DOCUMENTATION.md +76 -0
- package/server/lib/projects/project-config.js +142 -9
- package/server/lib/projects/project-id.js +17 -0
- package/server/lib/projects/project-setup.js +409 -0
- package/server/lib/projects/project-setup.test.js +557 -0
- package/server/lib/projects/routes.js +59 -0
- package/server/lib/quota/DOCUMENTATION.md +31 -1
- package/server/lib/quota/providers/cline-pass.js +125 -0
- package/server/lib/quota/providers/cline-pass.test.js +103 -0
- package/server/lib/quota/providers/index.js +7 -0
- package/server/lib/quota/providers/neuralwatt.js +3 -6
- package/server/lib/quota/providers/neuralwatt.test.js +7 -7
- package/server/lib/quota/providers/ollama-cloud.js +31 -0
- package/server/lib/quota/providers/ollama-cloud.test.js +33 -1
- package/server/lib/quota/providers/opencode-go.js +1 -1
- package/server/lib/quota/providers/opencode-go.test.js +26 -1
- package/server/lib/quota/providers/openrouter.js +119 -24
- package/server/lib/quota/providers/openrouter.test.js +330 -0
- package/server/lib/relay/DOCUMENTATION.md +55 -0
- package/server/lib/relay/cross-compat.test.js +26 -0
- package/server/lib/relay/downstream-scheduler.js +154 -0
- package/server/lib/relay/downstream-scheduler.test.js +162 -0
- package/server/lib/relay/e2ee.js +10 -8
- package/server/lib/relay/flow-control.test.js +177 -0
- package/server/lib/relay/host-client.js +37 -8
- package/server/lib/relay/tunnel-codec.js +9 -0
- package/server/lib/relay/tunnel-host.js +66 -17
- package/server/lib/session-assist/runtime.js +6 -10
- package/server/lib/session-goal/runtime.js +4 -9
- package/server/lib/small-model/DOCUMENTATION.md +3 -2
- package/server/lib/small-model/call.js +9 -4
- package/server/lib/small-model/call.test.js +29 -0
- package/server/lib/small-model/index.js +5 -10
- package/server/lib/small-model/runtime-providers.js +15 -7
- package/server/lib/small-model/runtime-providers.test.js +7 -1
- package/server/lib/terminal/DOCUMENTATION.md +4 -4
- package/server/lib/terminal/runtime.js +11 -6
- package/server/lib/terminal/runtime.test.js +20 -13
- package/server/lib/walkthrough/DOCUMENTATION.md +33 -14
- package/server/lib/walkthrough/model-settings.js +8 -12
- package/server/lib/walkthrough/prompt.js +3 -1
- package/server/lib/walkthrough/sources.js +23 -2
- package/dist/assets/DiffView-hDBKesA_.js +0 -4
- package/dist/assets/FilesView-CdWzeOp9.js +0 -17
- package/dist/assets/MarkdownImageGallery-Czv_mhvS.js +0 -1
- package/dist/assets/MarkdownRendererImpl-BrMcswiy.js +0 -12
- package/dist/assets/OnboardingScreen-ChxQoAkx.js +0 -1
- package/dist/assets/PierreDiffViewer-BchBtZlp.js +0 -157
- package/dist/assets/SettingsView-BKf5xBsP.js +0 -28
- package/dist/assets/WalkthroughView-DOeCsMju.js +0 -4
- package/dist/assets/contextPanelEmbeddedChat-C0ZLAepL.js +0 -1
- package/dist/assets/de-B5JaA3SA.js +0 -10
- package/dist/assets/es-EPIH88ii.js +0 -16
- package/dist/assets/fr-CAMfxUdZ.js +0 -14
- package/dist/assets/index-DF5kMP-i.js +0 -39
- package/dist/assets/index-Dl3xbAB_.css +0 -1
- package/dist/assets/ja-CifOE1VN.js +0 -16
- package/dist/assets/ko-BBDyAyYQ.js +0 -16
- package/dist/assets/main-MhSaOZoB.js +0 -930
- package/dist/assets/markdownCore-BrBwOOMn.js +0 -3
- package/dist/assets/patchFileDiff-o8ms1me8.js +0 -10
- package/dist/assets/pl-DgEHYfFM.js +0 -16
- package/dist/assets/pt-BR-DuWHojUw.js +0 -16
- package/dist/assets/renderElectronMiniChatApp-CDgBwwCS.js +0 -2
- package/dist/assets/renderMobileApp-DJIKIK1r.js +0 -25
- package/dist/assets/runtimeEndpointReset-CYJ9O_xX.js +0 -17
- package/dist/assets/scheduledTasksApi-D8yamh1b.js +0 -1
- package/dist/assets/tr-D5m2yIWL.js +0 -7
- package/dist/assets/uk-D_q60oog.js +0 -16
- package/dist/assets/useInlineCommentController-Brz_cLcQ.js +0 -2
- package/dist/assets/useRootScrollLock-lXEnWlaU.js +0 -1
- package/dist/assets/vendor-ghostty-web-CrxinGGH.js +0 -13
- package/dist/assets/vendor-zod-CK21ihK-.js +0 -39
- package/dist/assets/zh-CN-D8QvsVeg.js +0 -16
- package/dist/assets/zh-TW-B9t7rQQO.js +0 -16
|
@@ -52,20 +52,39 @@ written against staged code never silently re-anchors onto an unstaged edit.
|
|
|
52
52
|
| Kind | Sections | Notes |
|
|
53
53
|
|---|---|---|
|
|
54
54
|
| `working-tree` (`all` \| `staged` \| `working`) | `staged`, `working` | Untracked files are fetched individually because `git diff` omits them |
|
|
55
|
-
| `branch` | `branch` | `getRangeDiff`
|
|
56
|
-
| `
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
the current branch's
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
| `branch` | `branch` | `getRangeDiff` with `includeWorkingTree: true` compares the selected merge base with current files, including committed and local work in one net diff |
|
|
56
|
+
| `commit` | `commit` | `getCommitDiff` compares the full selected commit hash with its first parent; root commits compare with an empty tree |
|
|
57
|
+
| `pr` | `pr:<number>` | GitHub's committed pull-request diff, without local working-tree changes |
|
|
58
|
+
|
|
59
|
+
Changes and walkthrough resolve the current branch's base through
|
|
60
|
+
`packages/ui/src/hooks/useBranchComparisonBase.ts`. An explicit choice in Changes
|
|
61
|
+
outranks reflog detection. Both toolbars use
|
|
62
|
+
`packages/ui/src/components/views/git/BranchComparisonSelector.tsx` to select or
|
|
63
|
+
change the base directly. Walkthrough allows selecting Branch before a base is
|
|
64
|
+
known and waits for a valid choice before loading or generating. Opening
|
|
65
|
+
walkthrough from Changes carries the selected base and head; later selections
|
|
66
|
+
in either toolbar update both comparisons.
|
|
67
|
+
|
|
68
|
+
Commit mode uses the shared `CommitComparisonSelector` in both toolbars. It
|
|
69
|
+
lists the latest 50 commits reachable from the checked-out branch, with subject,
|
|
70
|
+
author, date, and short hash. Opening the picker refreshes that list; selecting a
|
|
71
|
+
commit changes the comparison, not the checkout. Changes hands the selected full
|
|
72
|
+
hash to walkthrough. The server accepts full object IDs for commit sources and
|
|
73
|
+
keys their cache entries and generation jobs as `commit:<hash>`, so reviews of
|
|
74
|
+
different commits cannot overwrite each other. Existing source keys keep their
|
|
75
|
+
format. Commit reads have no working-tree freshness dependency, and selecting a
|
|
76
|
+
commit never starts model generation.
|
|
77
|
+
|
|
78
|
+
The Git module owns exact-ref and working-tree comparison semantics. Local and
|
|
79
|
+
remote bases remain distinct, and a checkout during a branch review requires
|
|
80
|
+
the source to be resolved for the new branch rather than including another
|
|
81
|
+
branch's local files.
|
|
82
|
+
|
|
83
|
+
Successful status refreshes invalidate the visible branch comparison even when
|
|
84
|
+
file names and insertion/deletion counts stay the same. Walkthrough refreshes
|
|
85
|
+
its current hunk index while visible; regeneration remains user-initiated. The
|
|
86
|
+
content-addressed cache continues to reuse an old review only when its hunks
|
|
87
|
+
match, and otherwise reports stale anchors and uncovered current hunks.
|
|
69
88
|
|
|
70
89
|
The panel offers the current branch's pull request on its own: it registers with
|
|
71
90
|
the shared GitHub PR status store (`useGitHubPrStatusStore`) rather than waiting
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import os from 'os';
|
|
3
3
|
import path from 'path';
|
|
4
|
+
import { readMergedSettingsSync } from '../opencode/settings-files.js';
|
|
4
5
|
|
|
5
6
|
// The walkthrough may run on a different model than the rest of the small-model
|
|
6
7
|
// callers. Those callers want cheap and fast; this one needs structured output
|
|
@@ -23,16 +24,11 @@ const SETTINGS_FILE = path.join(
|
|
|
23
24
|
* not use the small model" with nothing to use instead.
|
|
24
25
|
*/
|
|
25
26
|
export function readWalkthroughModelOverride() {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
} catch {
|
|
34
|
-
// No settings file, unreadable, or malformed all mean the same thing: no
|
|
35
|
-
// override, use the small model.
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
27
|
+
// No settings file, unreadable, or malformed all mean the same thing: no
|
|
28
|
+
// override, use the small model.
|
|
29
|
+
const settings = readMergedSettingsSync({ fs, path, settingsFilePath: SETTINGS_FILE });
|
|
30
|
+
const override = typeof settings.walkthroughModelOverride === 'string'
|
|
31
|
+
? settings.walkthroughModelOverride.trim()
|
|
32
|
+
: '';
|
|
33
|
+
return override || null;
|
|
38
34
|
}
|
|
@@ -86,7 +86,9 @@ export function buildPrompt({ digest, fileCount, hunkCount, source, previousWalk
|
|
|
86
86
|
? `Uncommitted local changes (${source.scope === 'all' ? 'staged and unstaged' : source.scope}).`
|
|
87
87
|
: source.kind === 'branch'
|
|
88
88
|
? `All work on branch "${source.headRef}" that is not in "${source.baseRef}". Changes merged in from ${source.baseRef} are already excluded.`
|
|
89
|
-
:
|
|
89
|
+
: source.kind === 'commit'
|
|
90
|
+
? `Only the changes introduced by commit ${source.hash}, relative to its first parent (or the empty tree for a root commit).`
|
|
91
|
+
: `Pull request #${source.number}.`;
|
|
90
92
|
|
|
91
93
|
const prompt = `Reviewing: ${sourceLine}
|
|
92
94
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getDiff, getRangeDiff, getUntrackedDiffs, listUntrackedPaths } from '../git/service.js';
|
|
1
|
+
import { getDiff, getRangeDiff, getCommitDiff, getUntrackedDiffs, listUntrackedPaths } from '../git/service.js';
|
|
2
2
|
|
|
3
3
|
// A walkthrough source resolves to one or more diff *sections*. A section is a
|
|
4
4
|
// patch plus the scope its hunk ids live in; keeping staged and working-tree
|
|
@@ -48,6 +48,18 @@ export function parseSource(raw) {
|
|
|
48
48
|
return { kind: 'pr', number };
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
if (raw.kind === 'commit') {
|
|
52
|
+
// Sources are content-addressed: accept a full object id, never a moving ref.
|
|
53
|
+
if (!/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i.test(raw.hash)) {
|
|
54
|
+
throw new WalkthroughSourceError('commit sources require a full commit hash');
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
return { kind: 'commit', hash: raw.hash.toLowerCase() };
|
|
58
|
+
} catch {
|
|
59
|
+
throw new WalkthroughSourceError('commit sources require a full commit hash');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
51
63
|
throw new WalkthroughSourceError(`Unknown source kind "${String(raw.kind)}"`);
|
|
52
64
|
}
|
|
53
65
|
|
|
@@ -58,6 +70,7 @@ export function parseSource(raw) {
|
|
|
58
70
|
export function sourceKey(source) {
|
|
59
71
|
if (source.kind === 'working-tree') return `working-tree:${source.scope}`;
|
|
60
72
|
if (source.kind === 'branch') return `branch:${source.baseRef}...${source.headRef}`;
|
|
73
|
+
if (source.kind === 'commit') return `commit:${source.hash}`;
|
|
61
74
|
return `pr:${source.number}`;
|
|
62
75
|
}
|
|
63
76
|
|
|
@@ -97,13 +110,21 @@ export async function loadSourceSections(directory, source, { getPullRequestDiff
|
|
|
97
110
|
}
|
|
98
111
|
|
|
99
112
|
if (source.kind === 'branch') {
|
|
100
|
-
const patch = await getRangeDiff(directory, { base: source.baseRef, head: source.headRef });
|
|
113
|
+
const patch = await getRangeDiff(directory, { base: source.baseRef, head: source.headRef, includeWorkingTree: true });
|
|
101
114
|
return {
|
|
102
115
|
sections: patch && patch.trim() ? [{ scope: 'branch', patch }] : [],
|
|
103
116
|
meta: { baseRef: source.baseRef, headRef: source.headRef },
|
|
104
117
|
};
|
|
105
118
|
}
|
|
106
119
|
|
|
120
|
+
if (source.kind === 'commit') {
|
|
121
|
+
const patch = await getCommitDiff(directory, { hash: source.hash });
|
|
122
|
+
return {
|
|
123
|
+
sections: patch.trim() ? [{ scope: 'commit', patch }] : [],
|
|
124
|
+
meta: { hash: source.hash },
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
107
128
|
if (typeof getPullRequestDiff !== 'function') {
|
|
108
129
|
throw new WalkthroughSourceError('Pull request diffs are unavailable', 500);
|
|
109
130
|
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{R as o,j as n,f as he}from"./vendor-react-BUCujlKS.js";import{a0 as wn,a as ct,u as Y,G as Pe}from"./index-DF5kMP-i.js";import{f as ge,W as Tt,ac as yn,ad as vn,b7 as jn,ag as Sn,ae as Nn,ah as Fn,ai as Z,y as Ft,k as kn,hQ as Cn,hR as Rn,hS as Dn,cD as An,t as Ke,hT as En,ap as Ve,B as pe,I as A,h as ue,a7 as Bn,a8 as Vn,a9 as Ln,hD as Mt,hU as Tn,fF as Mn,fK as Ge,a1 as _n,c0 as at,ar as _t,ao as In,b3 as On,b5 as zn,fL as Pn,b6 as Gn}from"./useAppFontEffects-D7sNpuL2.js";import{b as Kn}from"./runtimeEndpointReset-CYJ9O_xX.js";import{c as $n,p as Wn}from"./vendor-zustand-BAGL70zf.js";import{P as Hn}from"./PierreDiffViewer-BchBtZlp.js";import{u as Un,v as qn,g as Xn,W as Jn}from"./main-MhSaOZoB.js";import{f as Qn}from"./patchFileDiff-o8ms1me8.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zod-CK21ihK-.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-C0ZLAepL.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Dp3KMRQG.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./web-components-_mNEMjFY.js";import"./computeVirtualFileMetrics-CzgLum_K.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-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.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"./VirtualizedFileDiff-fFFm2QgH.js";import"./isDiffPlainText-Dx-dB_8l.js";import"./vendor-diff-C3JhlQdm.js";import"./Virtualizer-D_a8gKmg.js";import"./useInlineCommentController-Brz_cLcQ.js";import"./appThemeRegistry-BK0dHKa6.js";import"./registerCustomTheme-BBXUCRnG.js";import"./useRootScrollLock-lXEnWlaU.js";import"./scheduledTasksApi-D8yamh1b.js";import"./vendor-cron-parser-CUcP7OfX.js";import"./vendor-luxon-BZ0puJYg.js";const Yn="aiworker.git-base-branch",Zn=100,$e=(s,e)=>JSON.stringify([ct(),s,e]),kt=$n()(Wn((s,e)=>({overrides:{},getOverride:(i,a)=>!i||!a?null:e().overrides[$e(i,a)]??null,setOverride:(i,a,d)=>{!i||!a||!d||s(f=>{const h=$e(i,a),x=Object.entries({...f.overrides,[h]:d});for(;x.length>Zn;)x.shift();return{overrides:Object.fromEntries(x)}})},clearOverride:(i,a)=>{!i||!a||s(d=>{const f=$e(i,a);if(!(f in d.overrides))return d;const h={...d.overrides};return delete h[f],{overrides:h}})}}),{name:Yn,storage:wn(),partialize:s=>({overrides:s.overrides})})),es=(s,e)=>!!s&&e!==null&&s!==e,ts=(s,e,i,a)=>i?s===null||a&&e===null?!0:e!==null&&s===e:!1,ns=(s,e)=>s==="branch"&&!e?"working":s,ss=(s,e,i)=>JSON.stringify([s,e,i]),rs=(s,e,i,a,d,f)=>{const h=o.useRef({directory:"",attempts:0}),[x,u]=o.useState(()=>({directory:"",exhausted:!1})),p=o.useRef(d);p.current=d;const b=!!s&&x.directory===s&&x.exhausted;return o.useEffect(()=>{if(!s||!e||a||i)return;const w=h.current.directory===s?h.current.attempts:0;if(w>=f){x.directory===s&&x.exhausted||u({directory:s,exhausted:!0});return}h.current={directory:s,attempts:w+1},p.current()},[s,x,a,e,i,f]),b},is=(s,e,i,a)=>{const[d,f]=o.useState(()=>new Map),h=o.useRef(d);h.current=d;const x=o.useRef(i);x.current=i;const u=o.useCallback((p,b)=>{const w=new Map(h.current);if(b===null){if(!w.delete(p))return}else w.set(p,b);h.current=w,f(w)},[]);return o.useEffect(()=>{s&&(h.current=new Map,f(h.current))},[s]),o.useEffect(()=>{const p=x.current;if(!s||!p||!e)return;let b=!1;const w=new Set;for(const y of e.split("\0"))h.current.has(y)||(w.add(y),u(y,a),p(y).then(j=>{b||(w.delete(y),u(y,j))}).catch(()=>{b||(w.delete(y),u(y,null))}));return()=>{b=!0;for(const y of w)u(y,null)}},[e,a,s,u]),d},Ct=(s,e)=>{if(e.length===0)return null;let i=null,a=null;for(const f of e)f.top<=s?(!i||f.top>i.top)&&(i=f):(!a||f.top<a.top)&&(a=f);const d=i??a;return d?{path:d.path,topOffset:d.top-s}:null},os=(s,e,i,a)=>Math.min(Math.max(0,a),Math.max(0,s+i-e)),Rt=s=>{if(!s)return null;const e=s.split(`
|
|
2
|
-
`);let i=null;for(const a of e){const d=a.match(/^@@\s*-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s*@@/);if(d){const f=Number.parseInt(d[1]??"",10);i=Number.isFinite(f)&&f>=1?f:null;continue}if(i!==null){if(a.startsWith(" ")){i+=1;continue}if(a.startsWith("+"))return i;if(a.startsWith("-"))return Math.max(1,i)}}return null},as=1100,ls=15e3,Dt=500,At=300,cs=1e6,us=3,fs=s=>s<=6?s:s<=12?6:s<=25?4:2,ds={original:"",modified:"",isBinary:!1,contextMode:"patch"},ps=3,ms=o.memo(()=>{const s=he.c(4),{t:e}=ge();let i;s[0]!==e?(i=e("diffView.binary.unavailable"),s[0]=e,s[1]=i):i=s[1];let a;return s[2]!==i?(a=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:i})}),s[2]=i,s[3]=a):a=s[3],a}),It={"?":{code:"?",color:"var(--status-info)",descriptionKey:"diffView.change.untracked"},A:{code:"A",color:"var(--status-success)",descriptionKey:"diffView.change.new"},D:{code:"D",color:"var(--status-error)",descriptionKey:"diffView.change.deleted"},R:{code:"R",color:"var(--status-info)",descriptionKey:"diffView.change.renamed"},C:{code:"C",color:"var(--status-info)",descriptionKey:"diffView.change.copied"},M:{code:"M",color:"var(--status-warning)",descriptionKey:"diffView.change.modified"}},hs=It.M,gs=s=>{const e=s.index?.trim(),i=s.working_dir?.trim();return e&&e!=="?"?e.charAt(0):i?i.charAt(0):e?.charAt(0)||i?.charAt(0)||"M"},Ot=s=>{const e=gs(s);return It[e]??hs},xs=s=>{const{index:e,working_dir:i}=s;return e==="A"||i==="A"||e==="?"||i==="?"},Et=s=>{const e=s.index?.trim();return!!(e&&e!=="?")},Bt=s=>!!s.working_dir?.trim()||s.index==="?",bs=(s,e)=>Mn(s,e),Vt=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/,""),Lt=(s,e)=>{const i=s.split(`
|
|
3
|
-
`),a=e.split(`
|
|
4
|
-
`),d=Math.min(i.length,a.length);for(let f=0;f<d;f+=1)if(i[f]!==a[f])return f+1;return a.length>i.length?i.length+1:i.length>a.length?Math.max(1,a.length):1},ws=s=>/^Binary files .+ differ$/m.test(s)||/^GIT binary patch$/m.test(s),ys=s=>Array.isArray(s)?s.filter(e=>!e||typeof e!="object"?!1:typeof e.file=="string"):[],vs=s=>s==="added"?"A":s==="deleted"?"D":"M",lt=(s,e,i)=>ws(e)?{original:"",modified:"",isBinary:!0,patch:e,contextMode:i}:{original:"",modified:"",patch:e,fileDiff:Qn(s,e),contextMode:i},zt=(s,e,i)=>{const a=s??0,d=e??0;return!a&&!d?null:n.jsxs("span",{className:ue("typography-meta flex items-center gap-1 text-xs whitespace-nowrap","flex-shrink-0",i?.className),children:[a?n.jsxs("span",{style:{color:"var(--status-success)"},children:["+",a]}):null,d?n.jsxs("span",{style:{color:"var(--status-error)"},children:["-",d]}):null]})},js=o.memo(s=>{const e=he.c(58),{scope:i,workingCount:a,stagedCount:d,turnCount:f,branchCount:h,showBranchOption:x,onScopeChange:u}=s,{t:p}=ge(),[b,w]=o.useState(!1),y=i==="staged"?d:i==="turn"?f:i==="branch"?h??0:a;let j;e[0]!==i||e[1]!==p?(j=p(i==="staged"?"diffView.scope.staged":i==="turn"?"diffView.scope.lastTurn":i==="branch"?"diffView.scope.branch":"diffView.scope.changed"),e[0]=i,e[1]=p,e[2]=j):j=e[2];const P=j;let m;e[3]!==p?(m=p("diffView.scope.selectorAria"),e[3]=p,e[4]=m):m=e[4];let le;e[5]!==y?(le=n.jsxs("span",{className:"diff-toolbar__scope-count",children:[": ",y]}),e[5]=y,e[6]=le):le=e[6];let k;e[7]!==P||e[8]!==le?(k=n.jsxs("span",{className:"whitespace-nowrap",children:[P,le]}),e[7]=P,e[8]=le,e[9]=k):k=e[9];let E;e[10]===Symbol.for("react.memo_cache_sentinel")?(E=n.jsx(A,{name:"arrow-down-s",className:"size-4 flex-shrink-0 opacity-60"}),e[10]=E):E=e[10];let L;e[11]!==m||e[12]!==k?(L=n.jsx(On,{asChild:!0,children:n.jsxs("button",{type:"button",className:"flex h-7 flex-shrink-0 items-center gap-1.5 rounded-md px-2 typography-ui-label font-semibold text-foreground outline-none hover:bg-interactive-hover focus-visible:ring-2 focus-visible:ring-ring","aria-label":m,children:[k,E]})}),e[11]=m,e[12]=k,e[13]=L):L=e[13];let H;e[14]!==u?(H=B=>{(B==="working"||B==="staged"||B==="turn"||B==="branch")&&(u?.(B),w(!1))},e[14]=u,e[15]=H):H=e[15];let N;e[16]!==p?(N=p("diffView.scope.changed"),e[16]=p,e[17]=N):N=e[17];let ee;e[18]!==N?(ee=n.jsx("span",{children:N}),e[18]=N,e[19]=ee):ee=e[19];let U;e[20]!==a?(U=n.jsx("span",{className:"typography-meta text-muted-foreground",children:a}),e[20]=a,e[21]=U):U=e[21];let q;e[22]!==U||e[23]!==ee?(q=n.jsx(Ge,{value:"working",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[ee,U]})}),e[22]=U,e[23]=ee,e[24]=q):q=e[24];let G;e[25]!==p?(G=p("diffView.scope.staged"),e[25]=p,e[26]=G):G=e[26];let K;e[27]!==G?(K=n.jsx("span",{children:G}),e[27]=G,e[28]=K):K=e[28];let te;e[29]!==d?(te=n.jsx("span",{className:"typography-meta text-muted-foreground",children:d}),e[29]=d,e[30]=te):te=e[30];let _;e[31]!==K||e[32]!==te?(_=n.jsx(Ge,{value:"staged",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[K,te]})}),e[31]=K,e[32]=te,e[33]=_):_=e[33];let I;e[34]!==p?(I=p("diffView.scope.lastTurn"),e[34]=p,e[35]=I):I=e[35];let V;e[36]!==I?(V=n.jsx("span",{children:I}),e[36]=I,e[37]=V):V=e[37];let O;e[38]!==f?(O=n.jsx("span",{className:"typography-meta text-muted-foreground",children:f}),e[38]=f,e[39]=O):O=e[39];let ne;e[40]!==V||e[41]!==O?(ne=n.jsx(Ge,{value:"turn",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[V,O]})}),e[40]=V,e[41]=O,e[42]=ne):ne=e[42];let T;e[43]!==h||e[44]!==x||e[45]!==p?(T=x?n.jsx(Ge,{value:"branch",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[n.jsx("span",{children:p("diffView.scope.branch")}),n.jsx("span",{className:"typography-meta text-muted-foreground",children:h??"…"})]})}):null,e[43]=h,e[44]=x,e[45]=p,e[46]=T):T=e[46];let se;e[47]!==i||e[48]!==q||e[49]!==_||e[50]!==ne||e[51]!==T||e[52]!==H?(se=n.jsx(zn,{align:"start",className:"w-40",children:n.jsxs(Pn,{value:i,onValueChange:H,children:[q,_,ne,T]})}),e[47]=i,e[48]=q,e[49]=_,e[50]=ne,e[51]=T,e[52]=H,e[53]=se):se=e[53];let re;return e[54]!==b||e[55]!==se||e[56]!==L?(re=n.jsxs(Gn,{open:b,onOpenChange:w,children:[L,se]}),e[54]=b,e[55]=se,e[56]=L,e[57]=re):re=e[57],re}),Ss=o.memo(s=>{const e=he.c(11),{changedFiles:i,selectedFile:a,onSelectFile:d}=s,{t:f}=ge();if(i.length===0)return null;let h;if(e[0]!==i||e[1]!==d||e[2]!==a||e[3]!==f){let u;e[5]!==d||e[6]!==a||e[7]!==f?(u=p=>{const b=Ot(p),w=a===p.path;return n.jsx("li",{children:n.jsxs("button",{type:"button",onClick:()=>d(p.path),className:ue("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",w?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[n.jsx(_t,{filePath:p.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:b.color},title:f(b.descriptionKey),"aria-label":f(b.descriptionKey),children:b.code}),n.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:p.path,children:p.path}),zt(p.insertions,p.deletions)]})},p.path)},e[5]=d,e[6]=a,e[7]=f,e[8]=u):u=e[8],h=i.map(u),e[0]=i,e[1]=d,e[2]=a,e[3]=f,e[4]=h}else h=e[4];let x;return e[9]!==h?(x=n.jsx(at,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:n.jsx("ul",{className:"flex flex-col gap-1",children:h})}),e[9]=h,e[10]=x):x=e[10],x}),Ns=o.memo(s=>{const e=he.c(20),{filePath:i,diff:a,renderSideBySide:d}=s,{t:f}=ge(),h=a.original.length>0,x=a.modified.length>0,u=d?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",p=d?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b={contain:"layout"},e[0]=b):b=e[0];let w;e[1]!==a.original||e[2]!==i||e[3]!==h||e[4]!==p||e[5]!==d||e[6]!==f?(w=h&&n.jsxs("div",{className:p,children:[n.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:f("diffView.image.original")}),n.jsx("img",{src:a.original,alt:f("diffView.image.originalAlt",{path:i}),className:d?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[1]=a.original,e[2]=i,e[3]=h,e[4]=p,e[5]=d,e[6]=f,e[7]=w):w=e[7];let y;e[8]!==a.modified||e[9]!==i||e[10]!==x||e[11]!==h||e[12]!==p||e[13]!==d||e[14]!==f?(y=x&&n.jsxs("div",{className:p,children:[n.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:f(h?"diffView.image.modified":"diffView.image.new")}),n.jsx("img",{src:a.modified,alt:f("diffView.image.modifiedAlt",{path:i}),className:d?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[8]=a.modified,e[9]=i,e[10]=x,e[11]=h,e[12]=p,e[13]=d,e[14]=f,e[15]=y):y=e[15];let j;return e[16]!==u||e[17]!==w||e[18]!==y?(j=n.jsx("div",{className:"w-full overflow-auto p-4",style:b,children:n.jsxs("div",{className:u,children:[w,y]})}),e[16]=u,e[17]=w,e[18]=y,e[19]=j):j=e[19],j}),Fs=o.memo(s=>{const e=he.c(16),{filePath:i,diff:a,renderSideBySide:d,wrapLines:f}=s;let h;e[0]!==i?(h=In(i)||"text",e[0]=i,e[1]=h):h=e[1];const x=h;if(a.isBinary){let b;return e[2]===Symbol.for("react.memo_cache_sentinel")?(b=n.jsx(ms,{}),e[2]=b):b=e[2],b}if(Ve(i)){let b;return e[3]!==a||e[4]!==i||e[5]!==d?(b=n.jsx(Ns,{filePath:i,diff:a,renderSideBySide:d}),e[3]=a,e[4]=i,e[5]=d,e[6]=b):b=e[6],b}let u;e[7]===Symbol.for("react.memo_cache_sentinel")?(u={contain:"layout"},e[7]=u):u=e[7];let p;return e[8]!==a.fileDiff||e[9]!==a.modified||e[10]!==a.original||e[11]!==i||e[12]!==x||e[13]!==d||e[14]!==f?(p=n.jsx("div",{className:"w-full",style:u,children:n.jsx(Hn,{original:a.original,modified:a.modified,fileDiff:a.fileDiff,language:x,fileName:i,renderSideBySide:d,wrapLines:f,layout:"inline"})}),e[8]=a.fileDiff,e[9]=a.modified,e[10]=a.original,e[11]=i,e[12]=x,e[13]=d,e[14]=f,e[15]=p):p=e[15],p}),ks=o.memo(s=>{const e=he.c(7),{filePath:i,staged:a,busyAction:d,disabled:f,onAction:h}=s,{t:x}=ge();let u;return e[0]!==d||e[1]!==f||e[2]!==i||e[3]!==h||e[4]!==a||e[5]!==x?(u=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:a?n.jsx(ot,{label:x("gitView.changes.unstageFileAria",{path:i}),icon:"arrow-go-back",loading:d==="unstage",disabled:f,onClick:()=>h("unstage")}):n.jsxs(n.Fragment,{children:[n.jsx(ot,{label:x("gitView.changes.revertFileAria",{path:i}),icon:"arrow-go-back",loading:d==="discard",disabled:f,tone:"failure",onClick:()=>h("discard")}),n.jsx(ot,{label:x("gitView.changes.stageFileAria",{path:i}),icon:"add",loading:d==="stage",disabled:f,tone:"success",onClick:()=>h("stage")})]})}),e[0]=d,e[1]=f,e[2]=i,e[3]=h,e[4]=a,e[5]=x,e[6]=u):u=e[6],u}),ot=s=>{const e=he.c(14),{label:i,icon:a,loading:d,disabled:f,tone:h,onClick:x}=s,u=h==="failure"&&"text-[var(--status-error)] hover:text-[var(--status-error)]",p=h==="success"&&"text-[var(--status-success)] hover:text-[var(--status-success)]";let b;e[0]!==u||e[1]!==p?(b=ue("h-6 w-6 rounded-none bg-transparent p-0 text-muted-foreground opacity-70 hover:bg-transparent hover:text-foreground hover:opacity-100",u,p),e[0]=u,e[1]=p,e[2]=b):b=e[2];let w;e[3]!==x?(w=P=>{P.stopPropagation(),x()},e[3]=x,e[4]=w):w=e[4];let y;e[5]!==a||e[6]!==d?(y=d?n.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):n.jsx(A,{name:a,className:a==="add"?"size-4":"size-3.5"}),e[5]=a,e[6]=d,e[7]=y):y=e[7];let j;return e[8]!==f||e[9]!==i||e[10]!==b||e[11]!==w||e[12]!==y?(j=n.jsx(pe,{variant:"ghost",size:"sm",className:b,disabled:f,title:i,"aria-label":i,onClick:w,children:y}),e[8]=f,e[9]=i,e[10]=b,e[11]=w,e[12]=y,e[13]=j):j=e[13],j},Cs=o.memo(({directory:s,file:e,layout:i,wrapLines:a,isSelected:d,isExpanded:f,isMounted:h,onSelect:x,onExpandedChange:u,registerSectionRef:p,showOpenInEditorAction:b=!1,isOpeningInEditor:w=!1,onOpenInEditor:y,staged:j=!1,loadFullFiles:P=!1,initialDiffData:m=null,readOnlyActions:le=!1})=>{const{t:k}=ge(),{git:E}=Tt(),L=Z(o.useCallback(c=>c.directories.get(s)?.diffCache.get(e.path)??null,[s,e.path])),H=Z(c=>c.setDiff),N=Z(c=>c.fetchStatus),ee=Y(c=>c.setDiffFileLayout),[U,q]=o.useState(0),[G,K]=o.useState(null),[te,_]=o.useState(!1),[I,V]=o.useState(null),[O,ne]=o.useState(!1),[T,se]=o.useState(null),[re,B]=o.useState(null),ie=o.useRef(null),We=o.useRef(null),ce=o.useMemo(()=>Ot(e),[e]),fe=i==="side-by-side",xe=P?"full":"patch",Ce=`${e.index}:${e.working_dir}:${e.insertions}:${e.deletions}`,X=o.useMemo(()=>m||(j?re:T||(L?{original:L.original,modified:L.modified,isBinary:L.isBinary,contextMode:"full"}:null)),[L,m,T,j,re]),Re=X?.contextMode===xe,He=o.useCallback(c=>{We.current=c,p(e.path,c)},[e.path,p]),Le=o.useCallback(c=>{u(e.path,c)},[e.path,u]),be=o.useCallback(()=>{x(e.path)},[e.path,x]);o.useEffect(()=>{j?B(null):se(null),K(null),ie.current=null},[Ce,j]),o.useEffect(()=>{if(!f||!h)return;if(!s||m||X&&Re){ie.current=null,_(!1);return}const c=`${s}::${e.path}::${j?"staged":"unstaged"}::${Ce}::${xe}::${U}`;if(ie.current===c)return;ie.current=c,K(null),_(!0);let C=!1;const oe=ct(),Me=P?cs:us,de=Ve(e.path)?E.getGitFileDiff(s,{path:e.path,staged:j}):E.getGitDiff(s,{path:e.path,staged:j,contextLines:Me}),De=ls,Ae=new Promise(($,J)=>{setTimeout(()=>J(new Error(`Timed out after ${De}ms`)),De)});return Promise.race([de,Ae]).then($=>{if(!C){if("diff"in $){const J=lt(e.path,$.diff,xe);j?B(J):se(J)}else{const J={original:$.original??"",modified:$.modified??"",isBinary:$.isBinary,contextMode:"full"};j?B(J):H(s,e.path,J,oe)}_(!1)}}).catch($=>{if(C)return;const J=$ instanceof Error?$.message:String($);K(J),_(!1)}),()=>{C=!0,ie.current===c&&(ie.current=null)}},[xe,X,Re,U,s,e.path,Ce,E,m,f,h,P,H,j]);const we=o.useCallback(()=>{Le(!f),be()},[Le,be,f]),Te=o.useCallback(async c=>{if(!(!s||I!==null)){V(c);try{c==="stage"?await E.stageGitFile(s,e.path):c==="unstage"?await E.unstageGitFile(s,e.path):await E.revertGitFile(s,e.path,{scope:"working"}),q(C=>C+1),await N(s,E)}catch(C){const oe=c==="unstage"?"gitView.toast.unstageFileFailed":c==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.revertFailed";Ke.error(C instanceof Error?C.message:k(oe))}finally{V(C=>C===c?null:C)}}},[s,N,e.path,I,E,k]);return n.jsxs("div",{ref:He,className:"scroll-mt-9 border-b border-[var(--interactive-border)]/40 last:border-b-0",children:[n.jsx("div",{className:"sticky top-0 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",children:n.jsxs("div",{role:"button",tabIndex:0,onClick:we,onKeyDown:c=>{c.target===c.currentTarget&&(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),we())},className:ue("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",d?"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:f?n.jsx(A,{name:"arrow-down-s",className:"size-4"}):n.jsx(A,{name:"arrow-right-s",className:"size-4"})}),n.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:{color:ce.color},title:k(ce.descriptionKey),"aria-label":k(ce.descriptionKey),children:ce.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(_t,{filePath:e.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),(()=>{const c=e.path.lastIndexOf("/");if(c===-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 C=e.path.slice(0,c),oe=e.path.slice(c+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:C}),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:oe})]})]})})()]})})]}),n.jsxs("div",{className:"relative flex shrink-0 items-center justify-self-end gap-2",children:[zt(e.insertions,e.deletions),b&&y?n.jsx(pe,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:k("diffView.actions.openFileInEditorAtChange"),onClick:c=>{c.stopPropagation(),y(e.path,X)},disabled:w,children:w?n.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):n.jsx(A,{name:"edit",className:"size-3.5"})}):null,n.jsx(Mt,{mode:fe?"side-by-side":"unified",onModeChange:c=>{const C=c==="side-by-side"?"side-by-side":"inline";ee(e.path,C)},className:"opacity-70"})]})]})}),f&&n.jsxs("div",{className:"relative bg-background overflow-hidden",children:[!h&&!G?n.jsx("div",{className:"h-40 border border-border/40 bg-background/40"}):null,G?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:k("diffView.state.failedToLoadDiff")}),n.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:G}),n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>q(c=>c+1),children:k("diffView.actions.retry")})]}):null,h&&te&&!X&&!G?n.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),k("diffView.state.loadingDiff")]}):null,h&&X&&!O&&e.insertions+e.deletions>Dt?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:k("diffView.state.largeDiff",{count:e.insertions+e.deletions})}),n.jsx("div",{className:"typography-meta text-muted-foreground",children:k("diffView.state.largeDiffDescription")}),n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>ne(!0),children:k("diffView.actions.renderAnyway")})]}):null,h&&X&&(O||e.insertions+e.deletions<=Dt)?n.jsxs(n.Fragment,{children:[n.jsx(Fs,{filePath:e.path,diff:X,renderSideBySide:fe,wrapLines:a}),n.jsx("div",{className:"pointer-events-none absolute bottom-3 right-3 z-20",children:n.jsx("div",{className:"pointer-events-auto",children:le?null:n.jsx(ks,{filePath:e.path,staged:j,busyAction:I,disabled:I!==null,onAction:Te})})})]}):null]})]})}),Ki=({hideStackedFileSidebar:s=!1,stackedDefaultCollapsedAll:e=!1,pinSelectedFileHeaderToTopOnNavigate:i=!1,showOpenInEditorAction:a=!1,diffScope:d="all",onDiffScopeChange:f,targetFilePath:h=null,flushContent:x=!1})=>{const{t:u}=ge(),{git:p,files:b}=Tt(),w=yn(),{rootIsGitRepo:y,gitDirectory:j,nestedRepos:P}=vn(w??null),m=j??w,le=Y(t=>t.openContextSurface),k=Un(t=>t.requestSource),{screenWidth:E,isMobile:L}=jn(),H=Sn(m??null),N=Nn(m??null),ee=Fn(m??null),U=Z(t=>t.setActiveDirectory),q=Z(t=>t.ensureStatus),G=Z(t=>t.selectNestedRepo),K=Z(t=>t.fetchStatus),te=Z(t=>t.fetchBranches),_=Z(t=>t.clearDiffCache),I=Z(t=>t.setDiff),[V,O]=o.useState(null),[ne,T]=o.useState(!1),[se,re]=o.useState(null),[B,ie]=o.useState(()=>new Set),[We,ce]=o.useState(()=>new Set),[fe,xe]=o.useState(!1),[Ce,X]=o.useState(0),[Re,He]=o.useState(()=>new Map),[Le,be]=o.useState(!1),[we,Te]=o.useState(!1),[c,C]=o.useState(d);o.useEffect(()=>{C(d)},[d]);const oe=Y(t=>t.pendingDiffFile),Me=Y(t=>t.pendingDiffStaged),de=Y(t=>t.pendingDiffScope),De=Y(t=>t.setPendingDiffFile),Ae=Y(t=>t.diffLayoutPreference),$=Y(t=>t.diffFileLayout),J=Y(t=>t.setDiffFileLayout),ut=Y(t=>t.diffWrapLines),Pt=Y(t=>t.setDiffWrapLines),ft=Y(t=>t.openContextFileAtLine),ye=Ft(t=>t.currentSessionId),Ue=kn(ye??"",w??void 0),qe=ut,Xe=c==="staged"?!0:c==="working"?!1:null,_e=Xe??ne,Je=L||E<=768,Gt=!!ye&&c!=="turn"&&!Je&&!Pe(),Kt=c!=="turn"&&!Je&&!Pe(),$t=!s&&!Je&&E>=1024,ve=o.useRef(null),Ee=o.useRef(new Map),me=o.useRef(null),z=o.useRef(null),je=o.useRef(!1),Se=o.useRef(null),dt=o.useRef(null),Qe=o.useRef(null),Ye=o.useRef(null),pt=o.useCallback(()=>{const t=ve.current;if(!t)return null;const r=t.getBoundingClientRect().top,l=[];for(const[g,v]of Ee.current)v&&l.push({path:g,top:v.getBoundingClientRect().top});return Ct(r,l)},[]),Ne=o.useCallback(()=>{me.current=null,je.current=!1,re(null),z.current!==null&&(window.cancelAnimationFrame(z.current),z.current=null)},[]),Fe=o.useCallback(t=>{ie(r=>{if(r.has(t))return r;const l=new Set(r);return l.add(t),l})},[]),Be=o.useMemo(()=>{for(let t=Ue.length-1;t>=0;t-=1){const r=Ue[t];if(r.role==="user")return ys(r.summary?.diffs)}return[]},[Ue]),Wt=o.useMemo(()=>{const t=new Map;for(const r of Be)if(r.file){if(typeof r.patch=="string"){t.set(r.file,lt(r.file,r.patch,"patch"));continue}t.set(r.file,{original:r.before??"",modified:r.after??"",contextMode:"full"})}return t},[Be]),Ht=o.useMemo(()=>N?.files?N.files.filter(Bt).length:0,[N]),Ut=o.useMemo(()=>N?.files?N.files.filter(Et).length:0,[N]),qt=Be.length,R=N?.current??null,ke=Z(t=>m?t.directories.get(m)?.branches??null:null),Xt=Z(t=>m?t.directories.get(m)?.isLoadingBranches??!1:!1),Jt=o.useCallback(()=>{m&&te(m,p)},[m,te,p]),Qt=rs(m??null,H!==!1,Xt,!!ke,Jt,ps),mt=o.useMemo(()=>{const t=N?.tracking?.trim().split("/")[0];return(t&&ke?.defaultBranches?.[t])??ke?.defaultBranches?.origin??null},[ke,N?.tracking]),Ze=!Pe()&&es(R,mt),Yt=N!==null,ht=Pe()||Qt||ts(R,mt,Yt,ke!==null),Zt=kt(t=>t.setOverride),en=kt(o.useCallback(t=>m&&R?t.overrides[$e(m,R)]??null:null,[R,m])),[tn,et]=o.useState(null),[nn,tt]=o.useState(!1),[gt,sn]=o.useState("");o.useEffect(()=>{const t=ns(c,!ht);t!==c&&(C(t),t==="working"&&f?.("working"))},[c,ht,f]),o.useEffect(()=>{if(!Ze||!m||!R){et(null),tt(!1);return}let t=!1;return tt(!1),Cn(m,R).then(r=>{t||et(r.base)}).catch(()=>{t||et(null)}).finally(()=>{t||tt(!0)}),()=>{t=!0}},[R,m,Ze]);const ae=en??tn,[Ie,xt]=o.useState(null),[bt,wt]=o.useState(null),Oe=o.useRef(0),nt=o.useCallback(()=>{if(!m||!R||!ae)return;const t=Oe.current+1;Oe.current=t,xt(null),wt(null),Rn(m,{base:ae,head:R}).then(r=>{Oe.current===t&&xt(r)}).catch(r=>{Oe.current===t&&wt(r instanceof Error?r.message:u("diffView.branch.loadError"))})},[ae,R,m,u]);o.useEffect(()=>{c==="branch"&&nt()},[c,nt]);const yt=c==="branch"&&m&&R&&ae?ss(m,ae,R):null,rn=o.useMemo(()=>c==="branch"?Array.from(B).sort().join("\0"):"",[c,B]),on=o.useCallback(t=>!m||!ae||!R?Promise.reject(new Error("branch range is unavailable")):Dn(m,{base:ae,head:R,path:t}).then(r=>lt(t,r.diff,"patch")),[ae,R,m]),an=is(yt,rn,yt?on:null,ds),ln=Ie?.length??null,S=o.useMemo(()=>{if(c==="branch")return(Ie??[]).map(l=>({path:l.path,index:"",working_dir:l.status,insertions:0,deletions:0,isNew:l.status==="A"})).sort((l,g)=>l.path.localeCompare(g.path));if(c==="turn")return Be.map(l=>({path:l.file??"",index:"",working_dir:vs(l.status),insertions:l.additions??0,deletions:l.deletions??0,isNew:l.status==="added"})).filter(l=>l.path).sort((l,g)=>l.path.localeCompare(g.path));if(!N?.files)return[];const t=N.diffStats??{},r=c==="staged"?Et:c==="working"?Bt:()=>!0;return N.files.filter(r).map(l=>({...l,insertions:t[l.path]?.insertions??0,deletions:t[l.path]?.deletions??0,isNew:xs(l)})).sort((l,g)=>l.path.localeCompare(g.path))},[c,Ie,Be,N]),st=o.useMemo(()=>S.map(t=>t.path).join("\0"),[S]);o.useEffect(()=>{const t=st?st.split("\0"):[],r=new Set(t),l=`${m??""}:${c}:${e?"collapsed":"default"}`,g=dt.current!==l;dt.current=l,ie(v=>{if(g){const D=e?0:fs(t.length);return new Set(t.slice(0,D))}let M=!1;const F=new Set;for(const D of v){if(!r.has(D)){M=!0;continue}F.add(D)}return M?F:v}),ce(v=>{if(g)return new Set;let M=!1;const F=new Set;for(const D of v){if(!r.has(D)){M=!0;continue}F.add(D)}return M?F:v})},[c,st,m,e]);const vt=o.useCallback(()=>{Se.current=null;const t=ve.current;if(!t)return;const r=t.getBoundingClientRect(),l=r.top-At,g=r.bottom+At,v={},M=[];for(const[F,D]of Ee.current){if(!D)continue;const W=D.getBoundingClientRect();M.push({path:F,top:W.top}),B.has(F)&&(W.bottom<l||W.top>g||(v[F]=!0))}Qe.current=Ct(r.top,M),ce(F=>{let D=!1;const W=new Set(F);for(const Nt of Object.keys(v))W.has(Nt)||(W.add(Nt),D=!0);return D?W:F})},[B]),Q=o.useCallback(()=>{typeof window>"u"||Se.current===null&&(Se.current=window.requestAnimationFrame(vt))},[vt]);o.useEffect(()=>{const t=ve.current;if(t)return Q(),t.addEventListener("scroll",Q,{passive:!0}),window.addEventListener("resize",Q),()=>{t.removeEventListener("scroll",Q),window.removeEventListener("resize",Q),Se.current!==null&&(window.cancelAnimationFrame(Se.current),Se.current=null)}},[S,B,Q]);const rt=o.useCallback(t=>{const r=$[t.path];if(r)return r;if(Ae==="inline")return"inline";if(Ae==="side-by-side")return"side-by-side";const l=E<as;return t.isNew||l?"inline":"side-by-side"},[$,Ae,E]),jt=o.useMemo(()=>S.length===0?null:S.every(t=>rt(t)==="side-by-side")?"side-by-side":"inline",[S,rt]);o.useEffect(()=>{m&&(U(m),q(m,p))},[m,U,q,p]),o.useEffect(()=>{if(m)return An.onGitRefreshHint(t=>{Vt(t.directory)===Vt(m)&&(t.paths?.length&&(Ye.current=pt()??Qe.current,_(m,t.paths),He(r=>{const l=new Map(r);for(const g of t.paths??[])l.set(g,(l.get(g)??0)+1);return l})),K(m,p,{silent:!0}))})},[pt,_,m,K,p]),o.useLayoutEffect(()=>{const t=Ye.current;if(!t)return;Ye.current=null;const r=ve.current,l=Ee.current.get(t.path);if(!r||!l)return;const g=r.getBoundingClientRect().top,v=l.getBoundingClientRect().top-g;r.scrollTop=os(r.scrollTop,t.topOffset,v,r.scrollHeight-r.clientHeight),Qe.current=t},[Re]),o.useEffect(()=>{c!=="all"&&!de||oe&&(de&&C(de),O(oe),T(de==="staged"||!de&&Me),De(null),je.current=!0,me.current=oe,Fe(oe),X(t=>t+1))},[c,Fe,oe,de,Me,De]),o.useEffect(()=>{if(c==="all")return;const t=h?.trim();t&&(O(t),T(c==="staged"),je.current=!0,me.current=t,Fe(t),X(r=>r+1))},[c,Fe,h]),o.useEffect(()=>{if(!V)return;S.some(r=>r.path===V)||(O(null),T(!1))},[S,V]);const cn=o.useCallback((t,r)=>{const l=Ee.current;r?l.set(t,r):l.delete(t),Q()},[Q]),un=o.useCallback((t,r)=>{Ne(),ie(l=>{const g=l.has(t);if(r===g)return l;const v=new Set(l);return r?v.add(t):v.delete(t),v}),r||ce(l=>{if(!l.has(t))return l;const g=new Set(l);return g.delete(t),g}),Q()},[Ne,Q]),fn=o.useCallback(()=>{Ne(),ie(t=>t.size>0?new Set:new Set(S.map(r=>r.path))),ce(new Set),Q()},[Ne,S,Q]),dn=o.useCallback(async t=>{if(!ye)return;const r=Ft.getState().getDirectoryForSession(ye)||w||"";if(!r){Ke.error(u("diffView.reviewDialog.toast.noSessionDirectory"));return}Te(!0);try{await En({originalSessionID:ye,directory:r,providerID:t.providerID,modelID:t.modelID,agent:t.agent||void 0,variant:t.variant||void 0,generateHandoff:t.generateHandoff,returnAfterHandoffRequest:t.generateHandoff,autoReview:t.autoReview}),be(!1)}catch(l){console.error("[review-flow] failed to start review flow",l),Ke.error(l instanceof Error?l.message:u("diffView.reviewDialog.toast.startFailed"))}finally{Te(!1)}},[ye,w,u]),ze=o.useCallback(t=>{const r=Ee.current.get(t),l=ve.current;if(!r||!l)return!1;const g=r.getBoundingClientRect().top-l.getBoundingClientRect().top;return l.scrollTo({top:l.scrollTop+g,behavior:"auto"}),!0},[]);o.useEffect(()=>{if(!me.current)return;let r=0;const l=20;let g=!1;const v=(F=!0)=>{g||(g=!0,me.current=null,je.current=!1,F&&re(null),z.current!==null&&(window.cancelAnimationFrame(z.current),z.current=null))},M=()=>{if(g){z.current=null;return}const F=me.current;if(!F){v(),z.current=null;return}if(!ze(F)){r+=1,r<l?z.current=window.requestAnimationFrame(M):(v(),z.current=null);return}if(i&&je.current){re(F),v(!1);return}v()};return z.current=window.requestAnimationFrame(M),()=>{g=!0,z.current!==null&&(window.cancelAnimationFrame(z.current),z.current=null)}},[i,Ce,ze]);const pn=o.useCallback(t=>{},[]),it=o.useCallback(t=>{Ne(),O(t),T(!1),je.current=!0,me.current=t,Fe(t),X(r=>r+1),ze(t)},[Ne,Fe,ze]);o.useEffect(()=>{const t=r=>{if(!r.altKey||r.metaKey||r.ctrlKey||r.shiftKey||r.key!=="ArrowDown"&&r.key!=="ArrowUp")return;const l=r.target;if(l instanceof HTMLElement&&(l.isContentEditable||l.tagName==="INPUT"||l.tagName==="TEXTAREA"||l.closest('[role="dialog"]'))||S.length===0)return;const g=r.key==="ArrowDown"?1:-1,v=V?S.findIndex(D=>D.path===V):-1,M=v===-1?g>0?0:S.length-1:v+g,F=S[M];F&&(r.preventDefault(),it(F.path))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[S,V,it]);const mn=o.useCallback(t=>{const r=t==="side-by-side"?"side-by-side":"inline";S.forEach(l=>{J(l.path,r)})},[S,J]),[hn,St]=o.useState(null),gn=o.useCallback(async(t,r)=>{if(!m||!t)return;St(t);const l=ct();try{let g=null;if(r?.patch&&!r.isBinary&&!Ve(t)?g=Rt(r.patch):r&&r.contextMode==="full"&&!r.isBinary&&!Ve(t)&&(g=Lt(r.original,r.modified)),g===null)try{const W=await p.getGitDiff(m,{path:t,staged:_e,contextLines:3});g=Rt(W.diff)}catch{g=null}let v=r;if(g===null||!v){const W=await p.getGitFileDiff(m,{path:t,staged:_e});v={original:W.original??"",modified:W.modified??"",isBinary:W.isBinary},_e||I(m,t,v,l)}const M=g??(v.isBinary||Ve(t)?1:Lt(v.original,v.modified)),F=bs(m,t),D=await qn(b,F,{directory:m});if(!D.ok){Ke.error(Xn(D.reason));return}ft(m,F,M,1)}finally{St(g=>g===t?null:g)}},[_e,m,b,p,ft,I]),xn=()=>{if(!m)return null;const t=r=>Xe!==null?Xe:ne&&r===V;return n.jsxs("div",{className:ue("flex min-w-0 flex-1 min-h-0 h-full",x?"gap-0":"gap-3 px-3 pb-3 pt-2"),children:[$t&&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:u("diffView.section.files")}),n.jsx("span",{className:"typography-meta text-muted-foreground",children:S.length})]}),n.jsx(Ss,{changedFiles:S,selectedFile:null,onSelectFile:it})]}),n.jsx("div",{className:"relative flex-1 min-w-0 min-h-0 h-full",children:n.jsx(at,{ref:ve,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:S.map(r=>n.jsx(Cs,{directory:m,file:r,layout:rt(r),wrapLines:qe,isSelected:!1,isExpanded:B.has(r.path),isMounted:We.has(r.path)||r.path===se,onSelect:pn,onExpandedChange:un,registerSectionRef:cn,showOpenInEditorAction:a&&c!=="turn",isOpeningInEditor:hn===r.path,onOpenInEditor:(l,g)=>{gn(l,g)},staged:t(r.path),loadFullFiles:fe,readOnlyActions:c==="branch",initialDiffData:c==="turn"?Wt.get(r.path)??null:c==="branch"?an.get(r.path)??null:null},`${r.path}:${Re.get(r.path)??0}`))})})})]})},bn=()=>{if(!m)return n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:u("diffView.state.selectSessionDirectory")});if(c!=="turn"&&ee&&!N)return n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),u("diffView.state.loadingRepositoryStatus")]});if(c!=="turn"&&H===!1)return n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:u("diffView.state.notGitRepository")});if(c==="branch"){if(!nn)return n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),u("diffView.branch.resolvingBase")]});if(!ae){const t=(ke?.all??[]).map(l=>l.replace(/^remotes\//,"")).filter(l=>l!==R&&!l.endsWith(`/${R}`)).sort(),r=_n(t,gt,l=>[l]);return n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 text-center",children:[n.jsx(A,{name:"git-branch",className:"size-6 text-muted-foreground"}),n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:u("diffView.branch.noBaseTitle")}),n.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:u("diffView.branch.noBaseDescription")}),n.jsx("input",{type:"text",value:gt,onChange:l=>sn(l.target.value),placeholder:u("gitView.branch.searchPlaceholder"),"aria-label":u("gitView.branch.searchPlaceholder"),className:"w-full max-w-sm rounded-md border border-border/60 bg-[var(--surface-elevated)] px-2.5 py-1.5 typography-meta text-foreground outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]"}),n.jsx(at,{outerClassName:"max-h-48 w-full max-w-sm min-h-0",className:"px-1 py-1",children:r.length===0?n.jsx("div",{className:"px-2 py-3 typography-meta text-muted-foreground",children:u("gitView.branch.empty")}):n.jsx("div",{className:"flex flex-col gap-0.5",children:r.map(l=>n.jsxs("button",{type:"button",onClick:()=>m&&R&&Zt(m,R,l),className:"flex items-center gap-2 rounded-md px-2 py-1.5 text-left hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",children:[n.jsx(A,{name:"git-branch",className:"size-3.5 text-primary"}),n.jsx("span",{className:"truncate typography-ui-label text-foreground",title:l,children:l})]},l))})})]})}if(bt)return n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 text-center",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:u("diffView.branch.loadError")}),n.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:bt}),n.jsx(pe,{variant:"outline",size:"sm",onClick:()=>nt(),children:u("diffView.actions.retry")})]});if(Ie===null)return n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),u("diffView.branch.loadingFiles")]})}return S.length===0?n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:c==="turn"?u("diffView.state.noLastTurnChanges"):c==="branch"&&ae?u("diffView.branch.empty",{base:ae}):u("diffView.state.cleanWorkingTree")}):xn()};return n.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[n.jsxs("div",{className:"@container/diff-toolbar flex min-w-0 items-center gap-2 px-3 py-2 bg-background",children:[y===!1&&Array.isArray(P)&&P.length>0?n.jsx(Kn,{repositories:P,selectedRepository:j??null,onSelectRepository:t=>{w&&G(w,t)},repositoryRoot:w??void 0}):null,!L&&(c==="working"||c==="staged"||c==="turn"||c==="branch"?n.jsx(js,{scope:c,workingCount:Ht,stagedCount:Ut,turnCount:qt,branchCount:ln,showBranchOption:Ze,onScopeChange:t=>{C(t),f?.(t)}}):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:ee&&!N?u("diffView.state.loadingChanges"):S.length===1?u("diffView.summary.changedFilesSingle",{count:S.length}):u("diffView.summary.changedFilesPlural",{count:S.length})})})),S.length>0&&n.jsxs(pe,{variant:"ghost",size:"sm",onClick:fn,className:ue("diff-toolbar__expand-button h-7 flex-shrink-0 gap-1 px-1.5 text-muted-foreground hover:text-foreground","ml-auto"),title:B.size>0?u("diffView.actions.collapseAll"):u("diffView.actions.expandAll"),children:[n.jsx(A,{name:"expand-up-down",className:"size-4"}),n.jsx("span",{className:"diff-toolbar__expand-label typography-ui-label",children:B.size>0?u("diffView.actions.collapseAll"):u("diffView.actions.expandAll")})]}),S.length>0&&Gt&&n.jsxs(pe,{variant:"default",size:"sm",onClick:()=>be(!0),disabled:we,className:"diff-toolbar__review-button h-7 flex-shrink-0 gap-1.5 px-2","aria-label":u("diffView.actions.reviewAria"),children:[we?n.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):n.jsx(A,{name:"search-eye",className:"size-4"}),n.jsx("span",{className:"diff-toolbar__review-label typography-ui-label",children:u("diffView.actions.review")})]}),S.length>0&&Kt&&n.jsxs(pe,{variant:"outline",size:"sm",onClick:()=>{const t=m??"";k(t,{kind:"working-tree",scope:c==="staged"||c==="working"?c:"all"}),le(t,"walkthrough")},className:ue("diff-toolbar__walkthrough-button h-7 flex-shrink-0 gap-1.5 px-2",Jn),"aria-label":u("walkthrough.action.open"),children:[n.jsx(A,{name:"route",className:"size-4"}),n.jsx("span",{className:"diff-toolbar__walkthrough-label typography-ui-label",children:u("walkthrough.action.open")})]}),S.length>0&&n.jsxs(Bn,{children:[n.jsx(Vn,{asChild:!0,children:n.jsx(pe,{variant:"ghost",size:"sm",onClick:()=>xe(t=>!t),"aria-pressed":fe,"aria-label":u(fe?"diffView.actions.disableFullFiles":"diffView.actions.loadFullFiles"),className:ue("h-7 w-7 flex-shrink-0 p-0 text-muted-foreground hover:text-foreground",fe&&"bg-interactive-selection text-interactive-selection-foreground"),children:n.jsx(A,{name:"file-download",className:"size-4"})})}),n.jsx(Ln,{children:n.jsx("p",{children:u(fe?"diffView.actions.disableFullFiles":"diffView.actions.loadFullFiles")})})]}),S.length>0&&n.jsx(pe,{variant:"ghost",size:"sm",onClick:()=>Pt(!ut),className:ue("h-5 w-5 p-0 transition-opacity",qe?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:u(qe?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:n.jsx(A,{name:"text-wrap",className:"size-4"})}),jt&&n.jsx(Mt,{mode:jt==="side-by-side"?"side-by-side":"unified",onModeChange:mn})]}),n.jsx(Tn,{open:Le,onOpenChange:be,projectDirectory:m??null,submitting:we,onConfirm:dn}),bn()]})};export{Ki as DiffView};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import{f as pt,R as n,c as Vn,j as r,r as us}from"./vendor-react-BUCujlKS.js";import{W as fa,X as ma,Y as ha,Z as pa,n as Ge,u as ht,dy as ga,C as En,w as xa,r as Dn,$ as Pn,e as va,dw as wa,a2 as ba,dx as ya,a as ja}from"./index-DF5kMP-i.js";import{f as $t,y as Mn,ac as ri,bR as Fa,h as G,ht as Na,fm as Ca,T as nr,B as z,I as y,W as Sa,N as ka,b7 as Ra,ae as Ta,c6 as Va,eb as zn,hu as Ln,hv as Ea,g_ as Da,fn as Pa,t as Y,l as An,ao as ds,c1 as sr,cD as Ma,b as za,hw as Tr,bE as La,ap as fs,hx as In,c2 as On,c3 as Bn,ge as Aa,hy as Ia,hz as Oa,hA as Ba,bF as si,bG as ni,bH as ii,bI as ai,bJ as oi,bK as li,b6 as vs,b3 as ws,ar as Er,b5 as bs,b2 as Dr,c0 as ms,aq as hs,bZ as $n,a7 as Lt,a8 as At,a9 as It,bC as $a,bD as Wa,g as Mr,b4 as _a,bf as Ua}from"./useAppFontEffects-D7sNpuL2.js";import{a6 as Ka,G as Ha,H as Ga,I as qa,J as Xa,K as Ja}from"./runtimeEndpointReset-CYJ9O_xX.js";import{c as Wn,s as Ya,C as _n,P as ps}from"./shikiHighlight-TEQCmzW8.js";import{a as Za}from"./vendor-codemirror-state-C9awkmn-.js";import{E as jt}from"./vendor-codemirror-view-CiLROUVV.js";import{J as Qa,F as eo}from"./JsonTreeView-6lrhwD3q.js";import{ensurePierreThemeRegistered as Un,getResolvedShikiTheme as to}from"./appThemeRegistry-BK0dHKa6.js";import{V as ro,W as so}from"./Virtualizer-CZlLSacm.js";import{V as no}from"./Virtualizer-D_a8gKmg.js";import{u as Vr,c as io,e as ao}from"./scheduledTasksApi-D8yamh1b.js";import{D as oo}from"./vendor-react-drawio-Ct3Q0DsD.js";import{I as lo,u as co,n as uo}from"./useInlineCommentController-Brz_cLcQ.js";import{b as fo}from"./CodeMirrorCommentWidgets-CSICpWQD.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-zod-CK21ihK-.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-C0ZLAepL.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Dp3KMRQG.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-codemirror-search-BmS-GmcX.js";import"./vendor-replit-codemirror-vim-B2DJlAhT.js";import"./vendor-replit-codemirror-vim-core-FHzKdNUS.js";import"./web-components-_mNEMjFY.js";import"./computeVirtualFileMetrics-CzgLum_K.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-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.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"./isFilePlainText-CWFPwmnU.js";import"./registerCustomTheme-BBXUCRnG.js";function Kn(a){const e=pt.c(41),{containerRef:s,filePath:d,fileContent:x}=a,{t:g}=$t(),v=Mn(bo),b=Mn(wo),f=ri(),C=Fa(vo),[p,F]=n.useState(null),[N,R]=n.useState(""),[j,T]=n.useState(!1),o=n.useRef(!1),A=n.useRef(null),I=n.useRef(null),[W,L]=n.useState(null);let E;e[0]===Symbol.for("react.memo_cache_sentinel")?(E=()=>{F(null),R(""),T(!1),o.current=!1,I.current=null,L(null)},e[0]=E):E=e[0];const V=E;let S,M;e[1]!==s?(S=()=>{const B=s.current;if(!B)return;const H=()=>{if(o.current)return;const se=window.getSelection(),Se=se?.toString().trim()??"";if(!se||!Se||se.rangeCount===0){V();return}const ae=se.getRangeAt(0);if(!B.contains(ae.commonAncestorContainer)){V();return}const oe=ae.getBoundingClientRect();I.current=ae.cloneRange(),R(Se),F({x:oe.left+oe.width/2,y:oe.top-10})},re=se=>{A.current?.contains(se.target)||o.current&&V()};return document.addEventListener("selectionchange",H),document.addEventListener("pointerdown",re),()=>{document.removeEventListener("selectionchange",H),document.removeEventListener("pointerdown",re)}},M=[s,V],e[1]=s,e[2]=S,e[3]=M):(S=e[2],M=e[3]),n.useEffect(S,M);let $;e[4]!==x?($=B=>{const H=de=>x.slice(0,de).split(`
|
|
2
|
-
`).length,re=go,se=(de,Ve)=>{for(const Ee of re(de)){const ke=x.indexOf(Ee,Ve);if(ke>=0)return ke}return-1},Se=B.length>=8?x.indexOf(B):-1;if(Se>=0){const de=H(Se);return{start:de,end:de+B.split(`
|
|
3
|
-
`).length-1}}const ae=B.split(`
|
|
4
|
-
`).map(po).filter(Boolean);if(ae.length===0)return null;const oe=se(ae[0],0);if(oe<0)return null;const be=H(oe);if(ae.length===1)return{start:be,end:be};const Te=se(ae[ae.length-1],oe);return Te<0?null:{start:be,end:Math.max(be,H(Te))}},e[4]=x,e[5]=$):$=e[5];const P=$;let X;e[6]===Symbol.for("react.memo_cache_sentinel")?(X=()=>{const B=I.current;if(!B){L(null);return}L(Na(B))},e[6]=X):X=e[6];const Ne=X;let _,Z;e[7]!==j?(_=()=>{if(!j)return;let B=null;const H=()=>{B===null&&(B=window.requestAnimationFrame(()=>{B=null,Ne()}))};return document.addEventListener("scroll",H,{capture:!0,passive:!0}),window.addEventListener("resize",H),()=>{B!==null&&window.cancelAnimationFrame(B),document.removeEventListener("scroll",H,{capture:!0}),window.removeEventListener("resize",H)}},Z=[j,Ne],e[7]=j,e[8]=_,e[9]=Z):(_=e[8],Z=e[9]),n.useEffect(_,Z);let ee;e[10]!==N?(ee=()=>{N&&(T(!0),o.current=!0,Ne(),window.getSelection()?.removeAllRanges())},e[10]=N,e[11]=ee):ee=e[11];const le=ee;let te;e[12]!==C||e[13]!==v||e[14]!==f||e[15]!==d||e[16]!==b||e[17]!==P||e[18]!==N?(te=B=>{const H=v??(b?"draft":null);if(!N||!H||!f){V();return}const re=P(N);C({directory:f,sessionKey:H},{source:"file-quote",fileLabel:d,startLine:re?.start??0,endLine:re?.end??0,code:N,language:"",text:B.trim()}),V(),queueMicrotask(ho)},e[12]=C,e[13]=v,e[14]=f,e[15]=d,e[16]=b,e[17]=P,e[18]=N,e[19]=te):te=e[19];const Ce=te;if(!p)return null;let O;e[20]!==j||e[21]!==P||e[22]!==N?(O=j?P(N):null,e[20]=j,e[21]=P,e[22]=N,e[23]=O):O=e[23];const xe=O;let ve;e[24]!==p.x||e[25]!==p.y?(ve={left:p.x,top:p.y,transform:"translate(-50%, -100%)"},e[24]=p.x,e[25]=p.y,e[26]=ve):ve=e[26];let ce;e[27]!==j||e[28]!==W?(ce=j&&W&&W.length>0?Vn.createPortal(r.jsx("div",{className:"pointer-events-none fixed inset-0 z-40",children:W.map(mo)}),document.body):null,e[27]=j,e[28]=W,e[29]=ce):ce=e[29];let ue;e[30]!==j||e[31]!==d||e[32]!==xe||e[33]!==le||e[34]!==Ce||e[35]!==g?(ue=j?r.jsx("div",{className:"w-[min(420px,80vw)]",children:r.jsx(lo,{fileLabel:d,lineRange:xe?{start:xe.start,end:xe.end}:void 0,onSave:Ce,onCancel:V})}):r.jsx("div",{className:G("flex items-center whitespace-nowrap","oc-glass-popover rounded-full border border-[var(--interactive-border)]","shadow-[0_4px_16px_-4px_rgb(0_0_0_/_0.12)]","p-1"),children:r.jsx("button",{type:"button",onClick:le,className:G("px-3.5 py-1.5 rounded-full","text-sm font-medium","text-[var(--surface-foreground)]","hover:bg-[var(--interactive-hover)]","transition-colors duration-150"),title:g("chat.textSelection.title.commentOnSelection"),children:g("chat.textSelection.actions.comment")})}),e[30]=j,e[31]=d,e[32]=xe,e[33]=le,e[34]=Ce,e[35]=g,e[36]=ue):ue=e[36];let we;return e[37]!==ve||e[38]!==ce||e[39]!==ue?(we=Vn.createPortal(r.jsxs("div",{ref:A,className:"fixed z-50",style:ve,children:[ce,ue]}),document.body),e[37]=ve,e[38]=ce,e[39]=ue,e[40]=we):we=e[40],we}function mo(a,e){return r.jsx("div",{className:"oc-chat-comment-rect absolute",style:{left:a.left,top:a.top,width:a.width,height:a.height}},e)}function ho(){Ca()}function po(a){return a.trim()}function go(a){const e=a.trim();return[e,e.slice(0,32),e.split(" ").slice(0,4).join(" ")].filter(xo)}function xo(a){return a.length>=8}function vo(a){return a.addDraft}function wo(a){return a.newSessionDraft?.open}function bo(a){return a.currentSessionId}const yo=(a,e)=>{if(!e)return null;const s=Number.parseInt(a.trim(),10);return!Number.isFinite(s)||s<1?null:Math.min(s,e.state.doc.lines)},Hn=(a,e)=>{const s=a.state.doc.lineAt(e.main.head);return{lineNumber:s.number,character:e.main.head-s.from+1,selection:e}},Gn=(a,e,s)=>{const d=a.state.doc.line(e),x=Math.max(1,Math.min(s,d.length+1)),g=d.from+x-1;a.dispatch({selection:Za.cursor(g),effects:jt.scrollIntoView(g,{y:"center"})})};function jo({open:a,onOpenChange:e,view:s,variant:d="overlay"}){const{t:x}=$t(),[g,v]=n.useState(""),b=n.useRef(null),f=n.useRef(!1),C=n.useRef(null),p=n.useRef(null),F=n.useMemo(()=>yo(g,s),[g,s]);n.useEffect(()=>{!a||!s||(f.current=!1,b.current=Hn(s,s.state.selection),v(""))},[a,s]),n.useEffect(()=>{a&&window.requestAnimationFrame(()=>{p.current?.focus(),p.current?.select()})},[a]),n.useEffect(()=>{if(!(!a||!s||!b.current)){if(F===null){const{selection:o}=b.current;s.dispatch({selection:o,effects:jt.scrollIntoView(o.main.from,{y:"center"})});return}Gn(s,F,b.current.character)}},[F,a,s]);const N=n.useCallback(()=>{if(!s||f.current||!b.current)return;const{selection:o}=b.current;s.dispatch({selection:o,effects:jt.scrollIntoView(o.main.from,{y:"center"})})},[s]),R=n.useCallback(o=>{o||N(),e(o)},[e,N]),j=n.useCallback(()=>{!s||F===null||!b.current||(f.current=!0,Gn(s,F,b.current.character),e(!1),s.focus())},[F,e,s]);n.useEffect(()=>{if(!a)return;const o=I=>{const W=C.current,L=I.target;!W||!(L instanceof Node)||W.contains(L)||R(!1)},A=I=>{I.key==="Escape"&&(I.preventDefault(),R(!1))};return document.addEventListener("pointerdown",o,!0),document.addEventListener("keydown",A,!0),()=>{document.removeEventListener("pointerdown",o,!0),document.removeEventListener("keydown",A,!0)}},[R,a,d]);const T=n.useMemo(()=>{if(!s)return x("goToLineDialog.helper.editorUnavailable");if(F===null){const o=b.current??Hn(s,s.state.selection);return x("goToLineDialog.helper.currentLineRange",{current:o.lineNumber,max:s.state.doc.lines})}return x("goToLineDialog.helper.goToLine",{line:F})},[F,x,s]);return d==="inline"?a?r.jsxs("div",{ref:C,className:"ml-1 flex h-6 items-center gap-1",children:[r.jsx(nr,{ref:p,type:"number",min:1,step:1,inputMode:"numeric",value:g,onChange:o=>v(o.target.value),onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),j())},placeholder:x("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),r.jsx(z,{variant:"outline",size:"xs",onClick:j,disabled:!s||F===null,className:"h-6 px-2",children:x("goToLineDialog.actions.go")})]}):null:r.jsx("div",{ref:C,className:G("absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all",a?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:r.jsxs("div",{className:"min-w-0",children:[r.jsx(nr,{ref:p,type:"number",min:1,step:1,inputMode:"numeric",value:g,onChange:o=>v(o.target.value),onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),j())},placeholder:x("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),r.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:T})]})})}const Fo=(a,e)=>{const s=e.trim().toLowerCase(),d=[];if(!s)return d;const x=a.toLowerCase();let g=0;for(;;){const v=x.indexOf(s,g);if(v===-1)break;d.push({start:v,end:v+s.length}),g=v+s.length}return d},Lr="data-md-find",gs="data-md-find-current",ci="rounded-[2px] bg-status-warning/30 text-foreground",No="rounded-[2px] bg-status-warning/60 text-foreground",Co=120,So=a=>a instanceof Element&&a.hasAttribute(Lr),ko=a=>a.target instanceof Element&&a.target.hasAttribute(Lr)?!0:[...a.addedNodes].some(e=>So(e)),ui=a=>{const e=new Set;a.querySelectorAll(`mark[${Lr}]`).forEach(s=>{const d=s.parentNode;d&&(d.replaceChild(document.createTextNode(s.textContent??""),s),e.add(d))}),e.forEach(s=>s.normalize())},Ro=(a,e)=>{ui(a);const s=e.trim().toLowerCase();if(!s)return[];const d=[],x=document.createTreeWalker(a,NodeFilter.SHOW_TEXT,{acceptNode(v){const b=v.parentElement;return!b||b.closest("svg, script, style")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),g=[];for(;x.nextNode();){const v=x.currentNode;v instanceof Text&&g.push(v)}for(const v of g){const b=v.nodeValue??"";if(!b)continue;const f=Fo(b,s);if(f.length===0)continue;const C=v.parentNode;if(!C)continue;const p=document.createDocumentFragment();let F=0;for(const N of f){N.start>F&&p.appendChild(document.createTextNode(b.slice(F,N.start)));const R=document.createElement("mark");R.setAttribute(Lr,""),R.className=ci,R.textContent=b.slice(N.start,N.end),p.appendChild(R),d.push(R),F=N.end}F<b.length&&p.appendChild(document.createTextNode(b.slice(F))),C.replaceChild(p,v)}return d},qn=({containerRef:a,open:e,onOpenChange:s,focusNonce:d,className:x})=>{const{t:g}=$t(),[v,b]=n.useState(""),[f,C]=n.useState(0),[p,F]=n.useState(0),N=n.useRef(null),R=n.useRef([]),j=n.useRef(v);j.current=v;const T=n.useRef(null),o=n.useRef(null),A=n.useCallback((S,M=!1)=>{const $=a.current;if(!$){R.current=[],C(0),F(0);return}R.current=Ro($,S);const P=R.current.length;C(P),F(X=>!M||P===0?0:Math.min(X,P-1))},[a]),I=n.useCallback((S,M=!1)=>{T.current&&clearTimeout(T.current),T.current=setTimeout(()=>{T.current=null,A(S,M)},Co)},[A]);n.useEffect(()=>()=>{T.current&&clearTimeout(T.current)},[]);const W=n.useCallback(()=>{s(!1);const S=o.current;o.current=null,S?.isConnected&&S.focus()},[s]);n.useEffect(()=>{const S=a.current;if(!e||!S)return;const M=new MutationObserver($=>{!j.current.trim()||!$.some(X=>!ko(X))||I(j.current,!0)});return M.observe(S,{childList:!0,subtree:!0,characterData:!0}),()=>{M.disconnect(),ui(S)}},[a,e,I]),n.useEffect(()=>{if(!e)return;const S=document.activeElement;S instanceof HTMLElement&&!o.current&&(o.current=S),N.current?.focus()},[e]),n.useEffect(()=>{e&&d>0&&(N.current?.focus(),N.current?.select())},[e,d]),n.useEffect(()=>{const S=a.current;if(!S||(S.querySelectorAll(`mark[${gs}]`).forEach($=>{$.removeAttribute(gs),$.className=ci}),f===0))return;const M=R.current[Math.min(Math.max(p,0),f-1)];M&&(M.setAttribute(gs,""),M.className=No,M.scrollIntoView({block:"nearest"}))},[a,p,f]);const L=n.useCallback(()=>{F(S=>f===0?0:(S+1)%f)},[f]),E=n.useCallback(()=>{F(S=>f===0?0:(S-1+f)%f)},[f]),V=n.useCallback(S=>{S.key==="Enter"?(S.preventDefault(),S.shiftKey?E():L()):S.key==="Escape"&&(S.preventDefault(),W())},[W,L,E]);return e?r.jsxs("div",{className:G("absolute right-3 top-3 z-10 flex items-center gap-1 rounded-lg border border-border/60 bg-[var(--surface-elevated)] px-1.5 py-1 shadow-lg",x),children:[r.jsx(y,{name:"search",className:"ml-0.5 size-3.5 text-muted-foreground"}),r.jsx(nr,{ref:N,value:v,onChange:S=>{b(S.target.value),I(S.target.value)},onKeyDown:V,placeholder:g("filesView.preview.find.placeholder"),"aria-label":g("filesView.preview.find.placeholder"),className:"h-7 w-40 rounded-md px-2 py-0 text-sm md:w-56"}),r.jsx("span",{className:"min-w-12 px-1 text-center typography-micro text-muted-foreground tabular-nums","aria-live":"polite","aria-label":f>0?g("filesView.preview.find.countAria",{current:p+1,total:f}):g("filesView.preview.find.noMatches"),children:v.trim()&&f===0?g("filesView.preview.find.noMatches"):f>0?`${p+1}/${f}`:""}),r.jsx(z,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:E,title:g("filesView.preview.find.previousAria"),"aria-label":g("filesView.preview.find.previousAria"),disabled:f===0,children:r.jsx(y,{name:"arrow-up",className:"size-3.5"})}),r.jsx(z,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:L,title:g("filesView.preview.find.nextAria"),"aria-label":g("filesView.preview.find.nextAria"),disabled:f===0,children:r.jsx(y,{name:"arrow-down",className:"size-3.5"})}),r.jsx(z,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:W,title:g("filesView.preview.find.closeAria"),"aria-label":g("filesView.preview.find.closeAria"),children:r.jsx(y,{name:"close",className:"size-3.5"})})]}):null},To=a=>{let e=!0;return{poll:async()=>{if(!e||a.isDirty())return!1;const s=a.getLoadedContent(),d=a.getLoadedRevision();try{const x=await a.readContent();if(!e||a.isDirty()||d!==a.getLoadedRevision())return!1;if(x===s)return!0;const g=await a.readContent();return!e||a.isDirty()||g!==x||d!==a.getLoadedRevision()?!1:(a.applyContent(x),!0)}catch{return!1}},dispose:()=>{e=!1}}},Vo=1,Eo=(a,e)=>e.size!==a.size||e.mtimeMs!==void 0&&a.mtimeMs!==void 0&&Math.abs(e.mtimeMs-a.mtimeMs)>=Vo;function Xn(){const a=pt.c(8),[e]=us.useState(Do),s=us.useRef(!1);let d;a[0]!==e?(d=f=>{if(f==null){e.cleanUp(),s.current=!1;return}s.current||(s.current=!0,e.setup(f,f.firstElementChild??void 0))},a[0]=e,a[1]=d):d=a[1];const x=d;let g,v;a[2]!==e?(g=()=>()=>{s.current=!1,e.cleanUp()},v=[e],a[2]=e,a[3]=g,a[4]=v):(g=a[3],v=a[4]),us.useLayoutEffect(g,v);let b;return a[5]!==x||a[6]!==e?(b={virtualizer:e,setScroller:x},a[5]=x,a[6]=e,a[7]=b):b=a[7],b}function Do(){return new no}function Po(a){return!(!a.autoSaveEnabled||!a.isDirty||!a.canWrite||a.isSaving||a.fileLoading||a.isNonEditableBinary||!a.selectedFilePath||a.loadedFilePath!==a.selectedFilePath)}function Mo(a){return a.selectedFilePath?a.isDirty?!(a.fileLoading||a.loadedFilePath!==a.selectedFilePath||a.isNonEditableBinary||a.draftContent===""&&a.fileContent!==""&&a.loadedFilePath!==a.selectedFilePath):!0:!1}const zo='<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 Jn(){if(typeof document>"u")return!1;const a=document.documentElement.getAttribute("data-theme");return a==="dark"||!a&&window.matchMedia("(prefers-color-scheme: dark)").matches}const Lo=n.forwardRef(function({xml:e,readOnly:s,className:d,onChange:x},g){const v=n.useRef(e),b=n.useRef(null),f=n.useRef(!1),[C,p]=n.useState(Jn),F=n.useRef(e),N=n.useRef(e);N.current!==e&&(N.current=e,F.current=e,v.current=e);const R=n.useRef(C);R.current!==C&&(R.current=C,F.current=v.current);const j=n.useRef(null);n.useEffect(()=>{const A=()=>p(Jn());A();const I=new MutationObserver(A);return I.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>I.disconnect()},[]),n.useEffect(()=>{const A=setTimeout(()=>{j.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(A)},[]),n.useImperativeHandle(g,()=>({getXml:()=>v.current}));const T=n.useCallback(()=>{!e&&!f.current&&(f.current=!0,setTimeout(()=>{b.current?.template({})},500))},[e]),o=n.useCallback(A=>{v.current=A.xml,x?.(A.xml)},[x]);return r.jsx("div",{ref:j,className:G("h-full w-full",d),children:r.jsx(oo,{ref:b,xml:F.current||zo,autosave:!0,urlParameters:{ui:s?"simple":C?"dark":"kennedy",spin:!0,libraries:!s,chrome:s,nav:s,layers:s,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:T,onAutoSave:o},C?"dark":"light")})}),Ao=a=>{const e=K(a);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const s=e.lastIndexOf("/");if(s<0)return e;if(s===0)return"/";const d=e.slice(0,s);return/^[A-Za-z]:$/.test(d)?`${d}/`:d},Io=a=>{const e=pt.c(8),{label:s,iconDataUrl:d}=a,[x,g]=n.useState(!1);let v;e[0]!==s?(v=s.trim().slice(0,1).toUpperCase()||"?",e[0]=s,e[1]=v):v=e[1];const b=v;if(d&&!x){let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=()=>g(!0),e[2]=p):p=e[2];let F;return e[3]!==d?(F=r.jsx("img",{src:d,alt:"",className:"size-4 rounded-sm",onError:p}),e[3]=d,e[4]=F):F=e[4],F}let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=G("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=f):f=e[5];let C;return e[6]!==b?(C=r.jsx("span",{className:f,children:b}),e[6]=b,e[7]=C):C=e[7],C},Oo=a=>a.slice().sort((e,s)=>e.type!==s.type?e.type==="directory"?-1:1:e.name.localeCompare(s.name)),K=a=>{if(!a)return"";const e=a.replace(/\\/g,"/"),s=e.startsWith("//");let d=e.replace(/\/+/g,"/");s&&!d.startsWith("//")&&(d=`/${d}`);const x=d==="/",g=/^[A-Za-z]:\/$/.test(d);return!x&&!g&&(d=d.replace(/\/+$/,"")),d},Bo=a=>a.startsWith("/")||a.startsWith("//")||/^[A-Za-z]:\//.test(a),Bt=a=>/^[A-Za-z]:\//.test(a)?a.toLowerCase():a,zr=(a,e)=>{const s=K(e),d=K(a);if(!s||!d)return!1;const x=Bt(s),g=Bt(d);return g===x||g.startsWith(`${x}/`)},Yn=(a,e)=>{const s=K(e),d=K(a);if(!zr(d,s))return[];const g=d.slice(s.length).replace(/^\//,"").split("/"),v=[];let b=s;for(let f=0;f<g.length-1;f++)b=b?`${b}/${g[f]}`:g[f],v.push(b);return v},Pr=(a,e)=>{if(!e)return"";const s=K(e);if(!a||!zr(s,a))return s;const d=s.slice(a.length);return d.startsWith("/")?d.slice(1):d},$o=new Set(["node_modules"]),Wo=a=>{const e=pt.c(3),{status:s}=a;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=d):d=e[0];const x=d[s];let g;return e[1]!==x?(g=r.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:x}}),e[1]=x,e[2]=g):g=e[2],g},Zn=a=>{const e=pt.c(11),{name:s}=a,d=n.useRef(null),x=n.useRef(null),[g,v]=n.useState(!1);let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{const N=d.current,R=x.current;if(!N||!R)return;const j=()=>{v(R.scrollWidth>N.clientWidth+1)};j();const T=new ResizeObserver(j);return T.observe(N),T.observe(R),()=>{T.disconnect()}},e[0]=b):b=e[0];let f;e[1]!==s?(f=[s],e[1]=s,e[2]=f):f=e[2],n.useLayoutEffect(b,f);let C;e[3]!==s?(C=r.jsx("span",{ref:x,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:s}),e[3]=s,e[4]=C):C=e[4];let p;e[5]!==s||e[6]!==g?(p=g?r.jsxs("span",{className:"open-file-name-marquee-track",children:[r.jsx("span",{className:"open-file-name-marquee-item",children:s}),r.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:s})]}):r.jsx("span",{className:"block min-w-0 truncate",children:s}),e[5]=s,e[6]=g,e[7]=p):p=e[7];let F;return e[8]!==C||e[9]!==p?(F=r.jsxs("span",{ref:d,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[C,p]}),e[8]=C,e[9]=p,e[10]=F):F=e[10],F},_o=a=>$o.has(a),Uo=a=>{const e=K(a);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Ko=a=>{const s=(a instanceof Error?a.message:String(a??"")).toLowerCase();return s.includes("is a directory")||s.includes("eisdir")},Qn=a=>{const s=(a instanceof Error?a.message:String(a??"")).toLowerCase();return s.includes("file not found")||s.includes("enoent")||s.includes("no such file")||s.includes("does not exist")},Ot=2e5,Ho=2e5;function Go(a){const e=a.length>400?`${a.slice(0,200)}${a.slice(-200)}`:a;let s=2166136261;for(let d=0;d<e.length;d+=1)s^=e.charCodeAt(d),s=s+((s<<1)+(s<<4)+(s<<7)+(s<<8)+(s<<24))>>>0;return`${a.length}:${s.toString(16)}`}const qo=a=>{let e=0,s=0;for(let d=0;d<a.length;d+=1)a.charCodeAt(d)===10&&(d>0&&a.charCodeAt(d-1)===13?e+=1:s+=1);return e>s?`\r
|
|
5
|
-
`:`
|
|
6
|
-
`},di=a=>a.replace(/\r\n/g,`
|
|
7
|
-
`).replace(/\r/g,`
|
|
8
|
-
`),Xo=(a,e)=>{const s=di(a);return e===`\r
|
|
9
|
-
`?s.replace(/\n/g,`\r
|
|
10
|
-
`):s},fi=(a,e)=>r.jsx(Er,{filePath:a,extension:e}),ei=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},Jo=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},xs=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="html"||e==="htm"},Yo=a=>{const e=pt.c(76),{node:s,root:d,isExpanded:x,isActive:g,isMobile:v,isBrowserClient:b,alwaysShowActions:f,status:C,badge:p,permissions:F,downloadFile:N,contextMenuPath:R,setContextMenuPath:j,rightClickMenuPath:T,setRightClickMenuPath:o,onSelect:A,onToggle:I,onRevealPath:W,onOpenDialog:L}=a,{t:E}=$t(),V=s.type==="directory",{canRename:S,canCreateFile:M,canCreateFolder:$,canDelete:P,canReveal:X}=F,Ne=!V&&!!N,_=X&&!b,Z=S||M||$||P||Ne||_;let ee;e[0]!==Z||e[1]!==s.path||e[2]!==o?(ee=fe=>{Z&&(fe?.preventDefault(),o(s.path))},e[0]=Z,e[1]=s.path,e[2]=o,e[3]=ee):ee=e[3];const le=ee;let te;e[4]!==V||e[5]!==s||e[6]!==A||e[7]!==I?(te=()=>{V?I(s.path):A(s)},e[4]=V,e[5]=s,e[6]=A,e[7]=I,e[8]=te):te=e[8];const Ce=te;let O;e[9]!==s.path||e[10]!==j||e[11]!==o?(O=fe=>{fe.stopPropagation(),o(null),j(s.path)},e[9]=s.path,e[10]=j,e[11]=o,e[12]=O):O=e[12];const xe=O;let ve;e[13]!==M||e[14]!==$||e[15]!==P||e[16]!==S||e[17]!==_||e[18]!==N||e[19]!==b||e[20]!==V||e[21]!==s||e[22]!==L||e[23]!==W||e[24]!==d||e[25]!==E?(ve=fe=>{const{Item:pe,Separator:et}=fe;return r.jsxs(r.Fragment,{children:[S&&r.jsxs(pe,{onClick:q=>{q.stopPropagation(),L("rename",s)},children:[r.jsx(y,{name:"edit",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.rename")]}),r.jsxs(pe,{onClick:q=>{q.stopPropagation(),Mr(s.path).then(at=>{if(at.ok){Y.success(E("sidebarFilesTree.toast.pathCopied"));return}Y.error(E("sidebarFilesTree.toast.copyFailed"))})},children:[r.jsx(y,{name:"file-copy",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.copyPath")]}),r.jsxs(pe,{onClick:q=>{q.stopPropagation();const at=Pr(d,s.path)||s.path;Mr(at).then(me=>{if(me.ok){Y.success(E("filesView.toast.relativePathCopied"));return}Y.error(E("sidebarFilesTree.toast.copyFailed"))})},children:[r.jsx(y,{name:"file-copy-2",className:"mr-2 size-4"})," ",E("filesView.tree.menu.copyRelativePath")]}),!V&&N&&r.jsxs(pe,{onClick:q=>{q.stopPropagation(),N(s.path).catch(at=>{console.error("Download failed:",at),Y.error(E("sidebarFilesTree.toast.operationFailed"))})},children:[r.jsx(y,{name:"download",className:"mr-2 size-4"})," ",E(b?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),_&&r.jsxs(pe,{onClick:q=>{q.stopPropagation(),W(s.path)},children:[r.jsx(y,{name:"folder-received",className:"mr-2 size-4"})," ",E(Ua())]}),V&&(M||$)&&r.jsxs(r.Fragment,{children:[r.jsx(et,{}),M&&r.jsxs(pe,{onClick:q=>{q.stopPropagation(),L("createFile",s)},children:[r.jsx(y,{name:"file-add",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.newFile")]}),$&&r.jsxs(pe,{onClick:q=>{q.stopPropagation(),L("createFolder",s)},children:[r.jsx(y,{name:"folder-add",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.newFolder")]})]}),P&&r.jsxs(r.Fragment,{children:[r.jsx(et,{}),r.jsxs(pe,{onClick:q=>{q.stopPropagation(),L("delete",s)},className:"text-destructive focus:text-destructive",children:[r.jsx(y,{name:"delete-bin",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.delete")]})]})]})},e[13]=M,e[14]=$,e[15]=P,e[16]=S,e[17]=_,e[18]=N,e[19]=b,e[20]=V,e[21]=s,e[22]=L,e[23]=W,e[24]=d,e[25]=E,e[26]=ve):ve=e[26];const ce=ve,ue=T===s.path;let we;e[27]!==s.path||e[28]!==o?(we=fe=>o(fe?s.path:null),e[27]=s.path,e[28]=o,e[29]=we):we=e[29];const B=v?void 0:le;let H;e[30]!==B?(H=r.jsx("div",{className:"group relative flex items-center",onContextMenu:B}),e[30]=B,e[31]=H):H=e[31];const re=v?void 0:le,se=g?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let Se;e[32]!==se?(Se=G("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",se),e[32]=se,e[33]=Se):Se=e[33];let ae;e[34]!==V||e[35]!==x||e[36]!==s.extension||e[37]!==s.path?(ae=V?x?r.jsx(y,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):r.jsx(y,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):fi(s.path,s.extension),e[34]=V,e[35]=x,e[36]=s.extension,e[37]=s.path,e[38]=ae):ae=e[38];let oe;e[39]!==s.name||e[40]!==s.path?(oe=r.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:s.path,children:s.name}),e[39]=s.name,e[40]=s.path,e[41]=oe):oe=e[41];let be;e[42]!==V||e[43]!==C?(be=!V&&C&&r.jsx(Wo,{status:C}),e[42]=V,e[43]=C,e[44]=be):be=e[44];let Te;e[45]!==p||e[46]!==V?(Te=V&&p&&r.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[p.modified>0&&r.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",p.modified]}),p.added>0&&r.jsxs("span",{className:"text-[var(--status-success)]",children:["+",p.added]})]}),e[45]=p,e[46]=V,e[47]=Te):Te=e[47];let de;e[48]!==Ce||e[49]!==Se||e[50]!==ae||e[51]!==oe||e[52]!==be||e[53]!==Te||e[54]!==re?(de=r.jsxs("button",{type:"button",onClick:Ce,onContextMenu:re,className:Se,children:[ae,oe,be,Te]}),e[48]=Ce,e[49]=Se,e[50]=ae,e[51]=oe,e[52]=be,e[53]=Te,e[54]=re,e[55]=de):de=e[55];let Ve;e[56]!==f||e[57]!==R||e[58]!==xe||e[59]!==Z||e[60]!==v||e[61]!==s.path||e[62]!==ce||e[63]!==j?(Ve=Z&&r.jsx("div",{className:G("absolute right-1 top-1/2 -translate-y-1/2",f?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:r.jsxs(vs,{open:R===s.path,onOpenChange:fe=>j(fe?s.path:null),children:[r.jsx(ws,{asChild:!0,children:r.jsx(z,{variant:"ghost",size:"icon",className:"size-6",onClick:xe,children:r.jsx(y,{name:"more-2-fill",className:"size-4"})})}),r.jsx(bs,{align:"end",side:"bottom",onCloseAutoFocus:()=>j(null),children:ce({Item:Dr,Separator:_a})})]})}),e[56]=f,e[57]=R,e[58]=xe,e[59]=Z,e[60]=v,e[61]=s.path,e[62]=ce,e[63]=j,e[64]=Ve):Ve=e[64];let Ee;e[65]!==de||e[66]!==Ve||e[67]!==H?(Ee=r.jsxs(Xa,{render:H,children:[de,Ve]}),e[65]=de,e[66]=Ve,e[67]=H,e[68]=Ee):Ee=e[68];let ke;e[69]!==ce?(ke=r.jsx(Ha,{className:"min-w-[180px]",children:ce({Item:qa,Separator:Ga})}),e[69]=ce,e[70]=ke):ke=e[70];let Q;return e[71]!==Ee||e[72]!==ke||e[73]!==ue||e[74]!==we?(Q=r.jsxs(Ja,{open:ue,onOpenChange:we,children:[Ee,ke]}),e[71]=Ee,e[72]=ke,e[73]=ue,e[74]=we,e[75]=Q):Q=e[75],Q},Zo=a=>{const e=pt.c(83),{activeDialog:s,dialogData:d,dialogInputValue:x,onDialogInputChange:g,isDialogSubmitting:v,onDialogSubmit:b,onClose:f,inputRef:C}=a,{t:p}=$t(),F=!!s;let N;e[0]!==f?(N=O=>!O&&f(),e[0]=f,e[1]=N):N=e[1];let R;e[2]!==s||e[3]!==p?(R=s==="createFile"&&p("filesView.dialog.createFile.title"),e[2]=s,e[3]=p,e[4]=R):R=e[4];let j;e[5]!==s||e[6]!==p?(j=s==="createFolder"&&p("filesView.dialog.createFolder.title"),e[5]=s,e[6]=p,e[7]=j):j=e[7];let T;e[8]!==s||e[9]!==p?(T=s==="rename"&&p("filesView.dialog.rename.title"),e[8]=s,e[9]=p,e[10]=T):T=e[10];let o;e[11]!==s||e[12]!==p?(o=s==="delete"&&p("filesView.dialog.delete.title"),e[11]=s,e[12]=p,e[13]=o):o=e[13];let A;e[14]!==R||e[15]!==j||e[16]!==T||e[17]!==o?(A=r.jsxs(ai,{children:[R,j,T,o]}),e[14]=R,e[15]=j,e[16]=T,e[17]=o,e[18]=A):A=e[18];let I;e[19]!==s||e[20]!==d?.path||e[21]!==p?(I=s==="createFile"&&p("filesView.dialog.createFile.description",{path:d?.path??p("filesView.dialog.rootFallback")}),e[19]=s,e[20]=d?.path,e[21]=p,e[22]=I):I=e[22];let W;e[23]!==s||e[24]!==d?.path||e[25]!==p?(W=s==="createFolder"&&p("filesView.dialog.createFolder.description",{path:d?.path??p("filesView.dialog.rootFallback")}),e[23]=s,e[24]=d?.path,e[25]=p,e[26]=W):W=e[26];let L;e[27]!==s||e[28]!==d?.name||e[29]!==p?(L=s==="rename"&&p("filesView.dialog.rename.description",{name:d?.name??""}),e[27]=s,e[28]=d?.name,e[29]=p,e[30]=L):L=e[30];let E;e[31]!==s||e[32]!==d?.name||e[33]!==p?(E=s==="delete"&&p("filesView.dialog.delete.description",{name:d?.name??""}),e[31]=s,e[32]=d?.name,e[33]=p,e[34]=E):E=e[34];let V;e[35]!==L||e[36]!==E||e[37]!==I||e[38]!==W?(V=r.jsxs(oi,{children:[I,W,L,E]}),e[35]=L,e[36]=E,e[37]=I,e[38]=W,e[39]=V):V=e[39];let S;e[40]!==V||e[41]!==A?(S=r.jsxs(ii,{children:[A,V]}),e[40]=V,e[41]=A,e[42]=S):S=e[42];let M;e[43]!==s||e[44]!==x||e[45]!==C||e[46]!==g||e[47]!==b||e[48]!==p?(M=s!=="delete"&&r.jsx("div",{className:"py-4",children:r.jsx(nr,{value:x,onChange:O=>g(O.target.value),placeholder:p(s==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:O=>{O.key==="Enter"&&b()},ref:C})}),e[43]=s,e[44]=x,e[45]=C,e[46]=g,e[47]=b,e[48]=p,e[49]=M):M=e[49];let $;e[50]!==p?($=p("filesView.dialog.cancel"),e[50]=p,e[51]=$):$=e[51];let P;e[52]!==v||e[53]!==f||e[54]!==$?(P=r.jsx(z,{variant:"outline",onClick:f,disabled:v,children:$}),e[52]=v,e[53]=f,e[54]=$,e[55]=P):P=e[55];const X=s==="delete"?"destructive":"default";let Ne;e[56]!==b?(Ne=()=>{b()},e[56]=b,e[57]=Ne):Ne=e[57];let _;e[58]!==s||e[59]!==x||e[60]!==v?(_=v||s!=="delete"&&!x.trim(),e[58]=s,e[59]=x,e[60]=v,e[61]=_):_=e[61];let Z;e[62]!==s||e[63]!==v||e[64]!==p?(Z=v?r.jsx(y,{name:"loader-4",className:"size-4 animate-spin"}):p(s==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=s,e[63]=v,e[64]=p,e[65]=Z):Z=e[65];let ee;e[66]!==X||e[67]!==Ne||e[68]!==_||e[69]!==Z?(ee=r.jsx(z,{variant:X,onClick:Ne,disabled:_,children:Z}),e[66]=X,e[67]=Ne,e[68]=_,e[69]=Z,e[70]=ee):ee=e[70];let le;e[71]!==P||e[72]!==ee?(le=r.jsxs(li,{children:[P,ee]}),e[71]=P,e[72]=ee,e[73]=le):le=e[73];let te;e[74]!==C||e[75]!==S||e[76]!==M||e[77]!==le?(te=r.jsxs(ni,{initialFocus:C,children:[S,M,le]}),e[74]=C,e[75]=S,e[76]=M,e[77]=le,e[78]=te):te=e[78];let Ce;return e[79]!==F||e[80]!==N||e[81]!==te?(Ce=r.jsx(si,{open:F,onOpenChange:N,children:te}),e[79]=F,e[80]=N,e[81]=te,e[82]=Ce):Ce=e[82],Ce},ti=(a,e,s)=>{const d=pt.c(8),[x,g]=n.useState(""),[v,b]=n.useState(0);let f,C;d[0]!==a||d[1]!==s||d[2]!==e?(f=()=>{if(!a){g("");return}let F=!1;g("");const N=va(),R=wa(N);ba(N).then(T=>{F||!T||(g(a),e(null))}).catch(T=>{F||(e(T instanceof Error?T.message:s),g(a))});const j=ya(()=>{F||(g(a),b(Qo),e(null))});return()=>{F=!0,R(),j()}},C=[a,e,s],d[0]=a,d[1]=s,d[2]=e,d[3]=f,d[4]=C):(f=d[3],C=d[4]),n.useEffect(f,C);let p;return d[5]!==v||d[6]!==x?(p={readyKey:x,nonce:v},d[5]=v,d[6]=x,d[7]=p):p=d[7],p},bu=({mode:a="full"})=>{const{t:e}=$t(),{files:s,runtime:d}=Sa(),{currentTheme:x,availableThemes:g,lightThemeId:v,darkThemeId:b}=ka(),{isMobile:f,isTablet:C,screenWidth:p}=Ra(),F=fa(d.platform),N=f||C,R=ma(),j=ha(),T=ri()??"",o=K(T.trim()),A=a!=="editor-only",I=a==="editor-only"&&!f,W=pa(t=>t.searchFiles),L=Ta(T),[E,V]=n.useState(""),S=Va(E,200),M=n.useRef(null),[$,P]=n.useState(!1),[X,Ne]=n.useState(!0),[_,Z]=n.useState(!1),[ee,le]=n.useState(!1),te=n.useRef(0),Ce=n.useCallback(t=>{te.current=Math.max(0,te.current+(t?1:-1))},[]),[O,xe]=n.useState("edit"),[ve,ce]=n.useState("edit"),[ue,we]=n.useState("tree"),[B,H]=n.useState("edit"),[re,se]=n.useState("preview"),[Se,ae]=n.useState(0),oe=n.useRef({}),be=n.useRef({}),Te=n.useRef({}),de=n.useRef({}),Ve=n.useMemo(()=>g.find(t=>t.metadata.id===v)??zn(!1),[g,v]),Ee=n.useMemo(()=>g.find(t=>t.metadata.id===b)??zn(!0),[g,b]);n.useEffect(()=>{Un(Ve),Un(Ee)},[Ve,Ee]);const ke=n.useMemo(()=>[],[]),Q=Ge(t=>o?t.byRoot[o]?.openPaths??ke:ke),fe=Ge(t=>o?t.byRoot[o]?.selectedPath??null:null),pe=Ge(t=>o?t.byRoot[o]?.expandedPaths??ke:ke),et=Ge(t=>t.removeOpenPath),q=Ge(t=>t.removeOpenPathsByPrefix),at=Ge(t=>t.removeExpandedPathsByPrefix),me=Ge(t=>t.setSelectedPath),ys=Ge(t=>t.toggleExpandedPath),ir=Ge(t=>t.expandPaths),Ft=n.useCallback(t=>{const i=K(t),l=i.split("/"),u=l[l.length-1]||i,h=u.includes(".")?u.split(".").pop()?.toLowerCase():void 0;return{name:u,path:i,type:"file",extension:h}},[]),Nt=n.useMemo(()=>Q.map(Ft),[Q,Ft]),Ar=n.useMemo(()=>{if(fe){const t=Bt(fe);if(Q.some(i=>Bt(i)===t))return fe}return Q[0]??null},[Q,fe]),c=n.useMemo(()=>Ar?Ft(Ar):null,[Ar,Ft]),qe=c?.path??"",[,mi]=n.useState(0);n.useEffect(()=>{if(!o||!fe)return;const t=Bt(fe);Q.some(l=>Bt(l)===t)||me(o,Q[0]??null)},[Q,o,fe,me]);const ar=!!(o&&qe&&!zr(qe,o)),js=ar?Ln(qe):void 0,gt=n.useMemo(()=>({allowOutsideWorkspace:a==="editor-only"&&ar,outsideFileGrant:js,directory:o||void 0}),[a,ar,js,o]),Xe=n.useCallback(async t=>{const i=Ln(t),l=await Ea(t,o,a==="editor-only");return l.outsideFileGrant&&l.outsideFileGrant!==i&&mi(u=>u+1),l},[a,o]),Ir=n.useRef(null),[Fs,hi]=n.useState({left:!1,right:!1}),Ns=n.useCallback(()=>{const t=Ir.current;t&&hi({left:t.scrollLeft>2,right:t.scrollLeft+t.clientWidth<t.scrollWidth-2})},[]),Cs=n.useRef(Ns);Cs.current=Ns,n.useEffect(()=>{const t=Ir.current;if(!t)return;const i=()=>Cs.current();i(),t.addEventListener("scroll",i,{passive:!0});const l=new ResizeObserver(i);return l.observe(t),()=>{t.removeEventListener("scroll",i),l.disconnect()}},[Nt.length]);const[Ss,Or]=n.useState({}),[or,Wt]=n.useState({}),ze=n.useRef(new Set),Le=n.useRef(new Set),tt=n.useRef(new Map),ks=n.useRef(0),[Rs,lr]=n.useState([]),[pi,cr]=n.useState(!1),[D,he]=n.useState(""),{isPlaying:ur,play:gi,stop:xi}=Da(),[Ae,ot]=n.useState(!1),[rt,ge]=n.useState(null),[vi,Ie]=n.useState(""),[De,ne]=n.useState(null),[ie,ye]=n.useState(""),[_t,Br]=n.useState(!1),[Ts,wi]=n.useState(`
|
|
11
|
-
`),bi=n.useRef(null),Je=n.useRef(null),Pe=n.useRef(null),lt=n.useRef(""),Ut=n.useRef(""),st=n.useRef(null),Vs=n.useRef(null),We=n.useRef(null),$r=n.useRef(""),Wr=n.useRef(0),Kt=n.useRef(0),Ct=n.useRef(null),[dr,yi]=n.useState(0),[ji,St]=n.useState("idle"),[Fi,fr]=n.useState(!1),[xt,Es]=n.useState(!1),je=ht(t=>t.autoSaveEnabled),Ni=ht(t=>t.setAutoSaveEnabled),[_r,Ht]=n.useState(!1),kt=n.useRef(null),Gt=n.useRef(null),qt=n.useRef(!1),Xt=n.useRef(null),Jt=n.useRef(null),_e=n.useRef(null),mr=n.useRef(null),[Ci,Ur]=n.useState(0),Rt=n.useRef(null),vt=n.useRef({key:"",attempts:0});n.useEffect(()=>()=>{Rt.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(Rt.current),Rt.current=null)},[]);const[wt,Kr]=n.useState(null),[bt,Si]=n.useState(null),[ct,Ds]=n.useState(""),[ki,Hr]=n.useState(!1),[Ri,Ti]=n.useState(null),[Vi,Ei]=n.useState(null),[Di,Ps]=n.useState(!1),[Pi,Ms]=n.useState(!1),[Mi,Gr]=n.useState(!1),[zs,hr]=n.useState(!1),[Ls,As]=n.useState(0),pr=n.useRef(null),gr=n.useCallback(t=>{const i=t?.currentTarget??pr.current;if(!i)return;const l=document.activeElement;l&&l!==document.body&&l!==i&&(Pa(l)||i.contains(l))||i.focus({preventScroll:!0})},[]),qr=n.useRef(null),Is=!!s.writeFile,Os=!!s.createDirectory,Bs=!!s.rename,$s=!!s.delete,Ws=!!s.revealPath,zi=Vr(t=>t.availableApps),Li=Vr(t=>t.isCacheStale),_s=Vr(t=>t.initialize),Ai=Vr(t=>t.loadInstalledApps);n.useEffect(()=>{_s()},[_s]);const Ii=n.useCallback(t=>{s.revealPath&&s.revealPath(t).catch(()=>{Y.error(e("sidebarFilesTree.toast.revealFailed"))})},[s,e]),Oi=n.useCallback(async t=>{if(!c?.path||await ga(c.path,t.id,t.appName)||await En(c.path,t.appName))return;const u=Ao(c.path)||o;u&&await En(u,t.appName)||Y.error(e("filesView.toast.openInAppFailed",{app:t.appName}))},[o,c?.path,e]),Xr=n.useCallback((t,i)=>{Kr(t),Si(i),Ds(t==="rename"&&i.name||""),Hr(!1)},[]),[U,Ue]=n.useState(null),Tt=n.useRef(!1),ut=n.useRef(null),[Us,Vt]=n.useState(!1),Ye=ht(t=>t.pendingFileNavigation),xr=ht(t=>t.setPendingFileNavigation),Jr=ht(t=>t.pendingFileFocusPath),Yr=ht(t=>t.setPendingFileFocusPath),Ks=ht(t=>t.fileEditorKeymap),Yt=An(t=>t.settingsDefaultFileViewerPreview),Bi=An(t=>t.showMessageTTSButtons);n.useEffect(()=>{const t=()=>{Tt.current=!1,ut.current=null,Vt(!1)};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]),n.useEffect(()=>()=>{Xt.current!==null&&window.clearTimeout(Xt.current),Jt.current!==null&&window.clearTimeout(Jt.current)},[]);const $i=n.useCallback((t,i)=>{const l=t.split(`
|
|
12
|
-
`),u=Math.max(1,i.start),h=Math.min(l.length,i.end);return u>h?"":l.slice(u-1,h).join(`
|
|
13
|
-
`)},[]),vr=n.useRef(null),Wi=co({source:"file",fileLabel:c?.path??null,language:c?.path&&ds(c.path)||"text",getCodeForRange:t=>$i(D,uo(t)),toStoreRange:t=>({startLine:t.start,endLine:t.end}),fromDraftRange:t=>({start:t.startLine,end:t.endLine})}),{drafts:Hs,commentText:wr,setCommentText:Gs,editingDraftId:br,setSelection:qs,saveComment:Xs,cancel:Zt,reset:Js,startEdit:Ys,deleteDraft:Zs}=Wi;n.useEffect(()=>{Ue(null),Js(),ye(""),Br(!1)},[c?.path,Js]),n.useEffect(()=>{qs(U)},[U,qs]),n.useEffect(()=>{if(!U&&!br)return;const t=l=>{const u=l.target;u.closest('[data-comment-input="true"]')||u.closest('[data-comment-card="true"]')||u.closest(".cm-gutterElement")||u.closest("[data-sonner-toast]")||u.closest("[data-sonner-toaster]")||wr.trim()||(Ue(null),Zt())},i=setTimeout(()=>{document.addEventListener("click",t)},100);return()=>{clearTimeout(i),document.removeEventListener("click",t)}},[Zt,wr,br,U]);const Qs=n.useCallback((t,i)=>{const l=i??U??void 0;i&&Ue(i),Xs(t,l),Ue(null)},[U,Xs]),en=n.useCallback((t,i)=>{const l=[];for(const u of i){if(!(u&&typeof u.name=="string"&&u.name.length>0)||!R&&u.name.startsWith(".")||!j&&_o(u.name))continue;const h=u.name,m=K(u.path||""),w=m?Bo(m)?m:K(`${t}/${m}`):K(`${t}/${h}`),k=u.isDirectory?"directory":"file",J=k==="file"&&h.includes(".")?h.split(".").pop()?.toLowerCase():void 0;l.push({name:h,path:w,type:k,extension:J})}return Oo(l)},[j,R]),Oe=n.useCallback(async t=>{const i=K(t.trim());if(!i||ze.current.has(i)||Le.current.has(i))return;Le.current=new Set(Le.current),Le.current.add(i);const l=ks.current+1;ks.current=l,tt.current=new Map(tt.current),tt.current.set(i,l);const u=()=>tt.current.get(i)===l;await(s.listDirectory?s.listDirectory(i).then(m=>m.entries.map(w=>({name:w.name,path:w.path,isDirectory:w.isDirectory}))):xa.listLocalDirectory(i).then(m=>m.map(w=>({name:w.name,path:w.path,isDirectory:w.isDirectory})))).then(m=>{if(!u())return;const w=en(i,m);ze.current=new Set(ze.current),ze.current.add(i),Wt(k=>{if(!k[i])return k;const J={...k};return delete J[i],J}),Or(k=>({...k,[i]:w}))}).catch(m=>{if(!u())return;const w=m instanceof Error?m.message:String(m??"");if(w==="Directory not found"&&o&&i!==o){at(o,i),Wt(k=>{if(!k[i])return k;const J={...k};return delete J[i],J});return}console.error("Failed to load files directory:",m),Wt(k=>({...k,[i]:w}))}).finally(()=>{u()&&(tt.current=new Map(tt.current),tt.current.delete(i),Le.current=new Set(Le.current),Le.current.delete(i))})},[s,en,at,o]),yr=n.useCallback(async()=>{o&&(ze.current=new Set,Le.current=new Set,tt.current=new Map,Wt({}),Or(t=>Object.keys(t).length===0?t:{}),await Oe(o))},[Oe,o]),Ze=n.useCallback(async t=>{if(!t){await yr();return}const i=K(t);ze.current=new Set(ze.current),ze.current.delete(i),Le.current=new Set(Le.current),Le.current.delete(i),await Oe(i)},[Oe,yr]),tn=n.useRef(""),rn=n.useRef("");n.useEffect(()=>{if(!o)return;const t=`${o}|h${R?"1":"0"}|g${j?"1":"0"}`,i=tn.current!==o,l=rn.current!==t;!i&&!l||(i&&(tn.current=o,he(""),ge(null),Ie(""),ne(null),P(!1)),l&&(rn.current=t,ze.current=new Set,Le.current=new Set,tt.current=new Map,Wt({}),Or(u=>Object.keys(u).length===0?u:{}),Oe(o)))},[Oe,o,j,R]),n.useEffect(()=>{if(!s.listDirectory)return;const t=()=>{if(!document.hidden&&pe.length>0)for(const i of pe)Ze(i)};return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[pe,s.listDirectory,Ze]),n.useEffect(()=>{if(!s.listDirectory||pe.length===0)return;const t=setInterval(()=>{if(!document.hidden)for(const i of pe)Ze(i)},8e3);return()=>clearInterval(t)},[pe,s.listDirectory,Ze]);const _i=n.useCallback(async t=>{if(t?.preventDefault(),!bt||!wt)return;Hr(!0);const i=()=>{Kr(null)},l=h=>{Y.error(h)},u=()=>{Hr(!1)};if(wt==="createFile"){if(!ct.trim()){l(e("sidebarFilesTree.toast.filenameRequired")),u();return}if(!s.writeFile){l(e("sidebarFilesTree.toast.writeNotSupported")),u();return}const h=bt.path,m=h?`${h}/`:"",w=K(`${m}${ct.trim()}`);await s.writeFile(w,"").then(async k=>{k.success&&(Y.success(e("sidebarFilesTree.toast.fileCreated")),await Ze(h)),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(wt==="createFolder"){if(!ct.trim()){l(e("sidebarFilesTree.toast.folderNameRequired")),u();return}const h=bt.path,m=h?`${h}/`:"",w=K(`${m}${ct.trim()}`);await s.createDirectory(w).then(async k=>{k.success&&(Y.success(e("sidebarFilesTree.toast.folderCreated")),await Ze(h)),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(wt==="rename"){if(!ct.trim()){l(e("sidebarFilesTree.toast.nameRequired")),u();return}if(!s.rename){l(e("sidebarFilesTree.toast.renameNotSupported")),u();return}const h=bt.path,m=h.split("/").slice(0,-1).join("/"),w=m?`${m}/`:"",k=K(`${w}${ct.trim()}`);await s.rename(h,k).then(async J=>{J.success&&(Y.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await Ze(m),o&&q(o,h),(c?.path===h||c?.path.startsWith(`${h}/`))&&(o&&me(o,null),he(""),ge(null),Ie(""),ne(null),f&&P(!1))),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(wt==="delete"){if(!s.delete){l(e("sidebarFilesTree.toast.deleteNotSupported")),u();return}const h=bt.path,m=h.split("/").slice(0,-1).join("/");await s.delete(h).then(async w=>{w.success&&(Y.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await Ze(m),o&&q(o,h),(c?.path===h||c?.path.startsWith(`${h}/`))&&(o&&me(o,null),he(""),ge(null),Ie(""),ne(null),f&&P(!1))),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}u()},[wt,bt,ct,s,Ze,f,q,o,c?.path,me,e]);n.useEffect(()=>{if(!T){lr([]),cr(!1);return}const t=S.trim();if(!t){lr([]),cr(!1);return}let i=!1;return cr(!0),W(T,t,150,{includeHidden:R,respectGitignore:!j,type:"file"}).then(l=>{if(i)return;const h=l.filter(m=>j||!Uo(m.path)).map(m=>({name:m.name,path:K(m.path),type:"file",extension:m.extension,relativePath:m.relativePath}));lr(h)}).catch(()=>{i||lr([])}).finally(()=>{i||cr(!1)}),()=>{i=!0}},[T,S,W,R,j]);const jr=n.useCallback(async(t,i)=>{const l=await Xe(t);if(s.readFile)return(await s.readFile(t,{...l,directory:o||void 0,...i})).content??"";const u=new URLSearchParams({path:t});l.allowOutsideWorkspace&&u.set("allowOutsideWorkspace","true"),l.outsideFileGrant&&u.set("outsideFileGrant",l.outsideFileGrant),o&&u.set("directory",o);const h=await Dn(`/api/fs/read?${u.toString()}`,i?.fresh?{cache:"no-store"}:void 0);if(!h.ok){const m=await h.json().catch(()=>({error:h.statusText}));throw new Error(m.error||e("filesView.error.readFileFailed"))}return h.text()},[s,Xe,o,e]),dt=n.useCallback(async t=>{if(s.statFile){const i=await Xe(t),l=await s.statFile(t,{...i,directory:o||void 0});return{path:l.path,size:l.size,mtimeMs:l.mtimeMs}}return null},[s,Xe,o]);n.useEffect(()=>{if(!o||!s.statFile||Q.length===0)return;let t=!1;const i=[...Q];return Promise.all(i.map(async l=>{try{const u=await Xe(l),h=await s.statFile?.(l,{...u,directory:o||void 0});!t&&h&&!h.isFile&&q(o,l)}catch(u){!t&&Qn(u)&&q(o,l)}})),()=>{t=!0}},[s,Q,q,Xe,o]);const Zr=n.useMemo(()=>D.length>Ot?`${D.slice(0,Ot)}
|
|
14
|
-
|
|
15
|
-
… truncated …`:D,[D]),Me=ie!==Zr,Et=n.useCallback(async()=>{if(!c||!s.writeFile)return Y.error(e("filesView.toast.savingNotSupported")),!1;const t=sr(c.path)||xt;if(!Mo({selectedFilePath:c.path,loadedFilePath:De,fileLoading:Ae,isDirty:Me,draftContent:ie,fileContent:D,isNonEditableBinary:t}))return t?console.warn(`[saveDraft] refusing to save binary file "${c.path}".`):ie===""&&D!==""&&De!==c.path&&console.warn(`[saveDraft] refusing to save empty draft for "${c.path}" (${D.length} bytes were expected). The file may have been read during a concurrent write (O_TRUNC race). Try again after content finishes loading if the save was intentional.`),!1;if(!Me)return!0;Br(!0);try{const i=Xo(ie,Ts);if(!(await s.writeFile(c.path,i))?.success)return Y.error(e("filesView.toast.writeFileFailed")),!1;if(he(ie),$r.current=i,Wr.current+=1,o&&zr(c.path,o)){const u=Pr(o,c.path);u&&Ma.requestGitRefresh({directory:o,paths:[u]})}if(o&&/(?:^|\/)\.agents\/loops\/[^/]+\.md$/i.test(K(c.path))){const u=za.getState().projects.find(h=>K(h.path)===K(o));if(u)try{await io(u.id)}catch{Y.error(e("sessions.scheduledTasks.dialog.toast.updateFailed"))}}return c?.path&&Tr(c.path)&&(lt.current=ie,Ut.current=ie),dt(c.path).then(u=>{u&&(We.current=u)}).catch(()=>{}),!0}catch(i){return Y.error(i instanceof Error?i.message:e("filesView.toast.saveFailed")),!1}finally{Br(!1)}},[xt,ie,D,Ae,s,Me,Ts,De,dt,o,c,e]);n.useEffect(()=>{je||(St("idle"),Je.current&&(clearTimeout(Je.current),Je.current=null))},[je]);const sn=1500;n.useEffect(()=>{const t=!!(c&&s.writeFile),i=!!(c?.path&&(sr(c.path)||xt));if(Po({autoSaveEnabled:je,isDirty:Me,canWrite:t,isSaving:_t,fileLoading:Ae,selectedFilePath:c?.path,loadedFilePath:De,isNonEditableBinary:i}))return Je.current=setTimeout(()=>{Et().then(l=>{l&&(St("saved"),setTimeout(()=>St("idle"),2e3))})},sn),()=>{Je.current&&(clearTimeout(Je.current),Je.current=null)}},[je,xt,ie,Ae,Me,De,c,s.writeFile,_t,Et]),n.useEffect(()=>{St("idle")},[c?.path]),La({save_file:t=>{if(!(t.target instanceof Node)||!mr.current?.contains(t.target))return!1;Je.current&&(clearTimeout(Je.current),Je.current=null),_t||Et().then(i=>{i&&(St("saved"),setTimeout(()=>St("idle"),2e3))})},find_in_file:t=>{if(!(t.target instanceof Node))return!1;if(Qe&&$e()==="preview"){if(f||!(_?qr.current:pr.current)?.contains(t.target))return!1;hr(!0),As(l=>l+1);return}if(!mr.current?.contains(t.target))return!1;le(!0)}});const Dt=n.useCallback(t=>{const i=di(t);$r.current=t,Wr.current+=1,wi(qo(t)),he(i),lt.current=i,Ut.current=i,ye(i.length>Ot?`${i.slice(0,Ot)}
|
|
16
|
-
|
|
17
|
-
… truncated …`:i)},[]),nn=n.useCallback(async t=>{const i=Kt.current+1;Kt.current=i;const l=()=>{if(!o)return!1;const k=Ge.getState().byRoot[o],J=k?.selectedPath??k?.openPaths[0]??null;return Kt.current===i&&J===t.path};if(ge(null),Ie(""),ne(null),Es(!1),ot(!0),await Xe(t.path),!l())return;const u=fs(t.path),h=In(t.path),m=On(t.path),w=sr(t.path);if(f&&P(!0),d.isDesktop&&u&&!h){he(""),ye("");return}if(!d.isDesktop&&u&&!h){he(""),ye(""),ne(t.path),ot(!1);return}if(m){he(""),ye(""),ne(t.path),ot(!1);return}if(w){he(""),ye(""),ne(t.path),ot(!1);return}await jr(t.path).then(k=>{if(l()){if(Bn(k)){Es(!0),he(""),ye(""),ne(t.path);return}Dt(k),ne(t.path),dt(t.path).then(J=>{J&&l()&&(We.current=J)}).catch(()=>{})}}).catch(k=>{if(l()){if(Ko(k)){if(ot(!1),o&&me(o,null),ge(null),he(""),ye(""),ne(null),We.current=null,E.trim().length>0&&V(""),f&&P(!1),o){const rr=[...Yn(t.path,o),t.path];rr.length>0&&ir(o,rr);for(const mt of rr)ze.current.has(mt)||Oe(mt)}return}if(Qn(k)){o&&q(o,t.path),he(""),ye(""),ge(null),We.current=null,f&&P(!1);return}he(""),ye(""),ge(k instanceof Error?k.message:e("filesView.error.readFileFailed")),We.current=null}}).finally(()=>{l()&&ot(!1)})},[Dt,ir,f,Oe,jr,dt,q,Xe,o,d.isDesktop,E,me,e]),Fr=n.useCallback(async(t,i)=>{if(!o)return;const l=Yn(t,o),u=i?[...l,t]:l;u.length>0&&ir(o,u);const h=u.map(m=>{if(!ze.current.has(m))return Oe(m)}).filter(Boolean);await Promise.all(h)},[ir,Oe,o]),an=n.useCallback((t,i)=>{const l=i.findIndex(u=>u.path===t);return l===-1||i.length<=1?null:i[l+1]??i[l-1]??null},[]),Re=n.useCallback(async t=>{if(qt.current)qt.current=!1;else if(Me){Ht(!0),kt.current=t;return}o&&(me(o,t.path),Fr(t.path,!1)),ge(null),Ie(""),he(""),lt.current="",Ut.current="",ye(""),ne(null),f&&P(!0)},[Fr,Me,f,o,me]);n.useEffect(()=>{c?.path&&Fr(c.path,!1)},[Fr,c?.path]),n.useEffect(()=>{if(!c){Kt.current+=1,Ct.current=null,ot(!1);return}if(De===c.path||Ct.current===c.path)return;const t=c.path;Ct.current=t,nn(c).finally(()=>{Ct.current===t&&(Ct.current=null)})},[dr,nn,De,c]);const Nr=n.useRef(Me);Nr.current=Me,n.useEffect(()=>ao(({runtimeKey:t,paths:i})=>{const l=c?.path;t!==ja()||!l||Nr.current||!i.includes(K(l))||(Kt.current+=1,Ct.current=null,We.current=null,Ie(""),ge(null),ne(null),yi(u=>u+1))}),[c?.path]),n.useEffect(()=>{if(!c?.path||De!==c.path)return;const t=c.path,i=()=>Nr.current||Tr(t)&<.current!==Ut.current,l=!sr(t)&&!fs(t)&&!xt?To({readContent:()=>jr(t,{fresh:!0}),getLoadedContent:()=>$r.current,getLoadedRevision:()=>Wr.current,isDirty:i,applyContent:w=>{if(Bn(w)){ne(null);return}Dt(w)}}):null;let u=!1,h=!1;const m=window.setInterval(()=>{document.hidden||h||(h=!0,dt(t).then(async w=>{if(u||!w)return;const k=We.current;if(!k||k.path!==t){We.current=w;return}if(Eo(k,w)){if(l&&w.size<=Ho){await l.poll()&&!u&&(We.current=w);return}Nr.current||(We.current=w,ne(null))}}).catch(()=>{}).finally(()=>{h=!1}))},2e3);return()=>{u=!0,l?.dispose(),window.clearInterval(m)}},[Dt,xt,De,jr,dt,c?.path]);const Ui=n.useCallback(()=>{const t=kt.current,i=Gt.current;if(kt.current=null,Gt.current=null,qt.current=!0,Ht(!1),ye(Zr),i){o&&et(o,i),c?.path===i&&(t?Re(t):(o&&me(o,null),he(""),ge(null),Ie(""),ne(null),f&&P(!1)));return}if(t){Re(t);return}},[Zr,Re,f,et,o,c?.path,me]),Ki=n.useCallback(async()=>{const t=kt.current,i=Gt.current;if(!await Et()){qt.current=!1;return}if(kt.current=null,Gt.current=null,qt.current=!0,Ht(!1),i){o&&et(o,i),c?.path===i&&(t?await Re(t):(o&&me(o,null),he(""),ge(null),Ie(""),ne(null),f&&P(!1)));return}if(t){await Re(t);return}},[Re,f,et,o,Et,c?.path,me]),on=n.useCallback(t=>{const i=c?.path===t,l=an(t,Nt);if(i&&Me){Ht(!0),kt.current=l,Gt.current=t;return}if(o&&et(o,t),!!i){if(l){Re(l);return}o&&me(o,null),he(""),ge(null),Ie(""),ne(null),f&&P(!1)}},[an,Re,Me,f,Nt,et,o,c?.path,me]),Hi=n.useCallback(t=>{if(Q.includes(t))return"open";if(L?.files){const i=t.startsWith(o+"/")?t.slice(o.length+1):t,l=L.files.find(u=>u.path===i);if(l){if(l.index==="A"||l.working_dir==="?")return"git-added";if(l.index==="D")return"git-deleted";if(l.index==="M"||l.working_dir==="M")return"git-modified"}}return null},[Q,L,o]),Gi=n.useCallback(t=>{if(!L?.files)return null;const i=t.startsWith(o+"/")?t.slice(o.length+1):t,l=i?`${i}/`:"";let u=0,h=0;for(const m of L.files)m.path.startsWith(l)&&((m.index==="M"||m.working_dir==="M")&&u++,(m.index==="A"||m.working_dir==="?")&&h++);return u+h>0?{modified:u,added:h}:null},[L,o]),qi=n.useCallback(async t=>{const i=K(t);o&&(ys(o,i),ze.current.has(i)||await Oe(i))},[Oe,o,ys]),Xi=n.useMemo(()=>({canRename:Bs,canCreateFile:Is,canCreateFolder:Os,canDelete:$s,canReveal:Ws}),[Bs,Is,Os,$s,Ws]);function ln(t,i){const l=Ss[t]??[];return l.map((u,h)=>{const m=u.type==="directory",w=m&&pe.includes(u.path),k=c?.path===u.path,J=h===l.length-1;return r.jsxs("li",{className:"relative",children:[i>0&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),J&&r.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),r.jsx(Yo,{node:u,root:o,isExpanded:w,isActive:k,isMobile:f,isBrowserClient:F,alwaysShowActions:N,status:m?void 0:Hi(u.path),badge:m?Gi(u.path):void 0,permissions:Xi,downloadFile:s.downloadFile,contextMenuPath:Ri,setContextMenuPath:Ti,rightClickMenuPath:Vi,setRightClickMenuPath:Ei,onSelect:Re,onToggle:qi,onRevealPath:Ii,onOpenDialog:Xr}),m&&w&&r.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[or[u.path]?r.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[r.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:or[u.path],children:or[u.path]}),r.jsxs(z,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{Ze(u.path)},children:[r.jsx(y,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):null,ln(u.path,i+1)]})]},u.path)})}const Fe=!!(c?.path&&fs(c.path)),Cr=!!(c?.path&&In(c.path)),Be=!!(c?.path&&On(c.path)),Qr=!!(c?.path&&(sr(c.path)||xt)),nt=Qr&&!Fe&&!Be,cn=n.useMemo(()=>K(Ye?.path??""),[Ye?.path]),Pt=!!(Ye&&cn&&qe&&qe===cn&&!Ae&&!rt&&!Fe&&!Be&&!nt),ft=n.useMemo(()=>Pr(o,qe),[qe,o]),Ji=!!(c&&(!Fe||Cr)&&!Be&&!nt&&D.length>0),Yi=!!(c&&ft.length>0),Ke=!!(c&&!ar&&!Qr&&!Fe&&s.writeFile&&D.length<=Ot),Qe=!!(c?.path&&ei(c.path)),Qt=!!(c?.path&&Jo(c.path)),Mt=!!(c?.path&&xs(c.path)),er=!!(c?.path&&Tr(c.path)),es=!!(c&&!Qr&&!Fe)&&!Qe&&!er&&!(Mt&&B==="preview"),Zi=Qe&&ve==="edit"||Mt&&B==="edit"||Qt&&ue==="text"||!Qe&&!Mt&&!Qt&&O==="edit",Sr=n.useMemo(()=>qe?Aa(qe):null,[qe]),[un,ts]=n.useState(null);n.useEffect(()=>{let t=!1;const i=c?.path;if(!i||Sr){ts(null);return}return ts(null),Ia(i).then(l=>{t||ts(l)}),()=>{t=!0}},[c?.path,Sr]),n.useEffect(()=>{!Ke&&O==="edit"&&xe("view")},[Ke,O]);const rs="aiworker:files:md-viewer-mode",ss="aiworker:files:html-viewer-mode",ns="aiworker:files:json-viewer-mode";n.useEffect(()=>{const t=c?.path;if(!t)return;xe(oe.current[t]??"edit");let i=Yt?"preview":"edit";try{const h=localStorage.getItem(rs);(h==="preview"||h==="edit")&&(i=h)}catch{}ce(be.current[t]??i);let l=Yt?"preview":"edit";try{const h=localStorage.getItem(ss);(h==="preview"||h==="edit")&&(l=h)}catch{}H(Te.current[t]??l),se(de.current[t]??(Yt?"preview":"edit"));let u=Yt?"tree":"text";try{const h=localStorage.getItem(ns);(h==="tree"||h==="text")&&(u=h)}catch{}we(u)},[c?.path,Yt]);const Qi=n.useCallback(t=>{const i=c?.path;i&&(oe.current[i]=t),xe(t)},[c?.path]),ea=n.useCallback(t=>{const i=c?.path;i&&(be.current[i]=t),ce(t);try{localStorage.setItem(rs,t)}catch{}},[c?.path]),$e=n.useCallback(()=>ve,[ve]),dn=c&&Qe&&$e()==="preview"&&!Ae?c.path:null;n.useEffect(()=>{!dn||f||gr()},[gr,_,f,dn]);const ta=n.useCallback(t=>{we(t);try{localStorage.setItem(ns,t)}catch{}},[]),ra=n.useCallback(t=>{const i=c?.path;i&&(Te.current[i]=t),H(t);try{localStorage.setItem(ss,t)}catch{}},[c?.path]),sa=n.useCallback(t=>{const i=c?.path;if(i&&(de.current[i]=t),Pe.current&&(clearTimeout(Pe.current),Pe.current=null),st.current!==null&&(cancelAnimationFrame(st.current),st.current=null),t==="edit")ye(lt.current||D),se(t);else{lt.current=ie;const l=i;se("edit"),st.current=requestAnimationFrame(()=>{st.current=requestAnimationFrame(()=>{st.current=null,!(o&&l&&Ge.getState().byRoot[o]?.selectedPath!==l)&&(ae(u=>u+1),se("preview"))})});return}},[ie,D,o,c?.path]),is=n.useCallback(async(t,i)=>{if(!s.writeFile||i===Ut.current)return!1;if(!(await s.writeFile(t,i))?.success)return Y.error(e("filesView.toast.writeFileFailed")),!1;Dt(i);const u=await dt(t).catch(()=>null);return u&&(We.current=u),!0},[Dt,s,dt,e]);n.useEffect(()=>()=>{Pe.current&&(clearTimeout(Pe.current),Pe.current=null),st.current!==null&&(cancelAnimationFrame(st.current),st.current=null)},[re,c?.path]);const na=n.useCallback(t=>{if(lt.current=t,!je||!c?.path||re!=="preview"||!s.writeFile)return;Pe.current&&clearTimeout(Pe.current);const i=c.path;Pe.current=setTimeout(()=>{Pe.current=null,is(i,t).then(l=>{l&&(fr(!0),setTimeout(()=>fr(!1),1500))}).catch(l=>{Y.error(l instanceof Error?l.message:e("filesView.toast.saveFailed"))})},sn)},[je,re,s.writeFile,is,c?.path,e]),ia=n.useMemo(()=>er&&(lt.current||ie)||D,[ie,D,er]),fn=n.useCallback(()=>B,[B]);n.useEffect(()=>{const t=l=>{const u=l?"preview":"edit",h=l?"tree":"text";for(const m of Q)oe.current[m]="edit",ei(m)&&(be.current[m]=u),xs(m)&&(Te.current[m]=u),Tr(m)&&(de.current[m]=u);xe("edit"),ce(u),H(u),se(u),we(h);try{localStorage.setItem(rs,u),localStorage.setItem(ss,u),localStorage.setItem(ns,h)}catch{}},i=l=>{const u=!!l.detail?.enabled;t(u)};return window.addEventListener("aiworker:file-viewer-preview-mode-changed",i),()=>{window.removeEventListener("aiworker:file-viewer-preview-mode-changed",i)}},[Q]),n.useEffect(()=>{if(!Ye||!o)return;const t=()=>{typeof window>"u"||Rt.current===null&&(Rt.current=window.requestAnimationFrame(()=>{Rt.current=null,Ur(it=>it+1)}))},i=(it,yt)=>{if(it.state.doc.length!==yt.length)return!1;if(yt.length===0)return!0;const cs=Math.min(128,yt.length);if(it.state.sliceDoc(0,cs)!==yt.slice(0,cs))return!1;const Tn=Math.max(0,yt.length-cs);return it.state.sliceDoc(Tn,yt.length)===yt.slice(Tn)},l=K(Ye.path);if(!l){xr(null),vt.current={key:"",attempts:0};return}const u=`${l}:${Ye.line}:${Ye.column??1}`;if(vt.current.key!==u&&(vt.current={key:u,attempts:0}),c?.path!==l){if(_r)return;Re(Ft(l));return}if(Ae||De!==l)return;if(rt||Fe||Be||nt){xr(null),vt.current={key:"",attempts:0};return}if(!Ke)return;if(O!=="edit"){xe("edit");return}const h=_e.current;if(!h){t();return}if(!i(h,ie)){t();return}const m=Math.max(1,Math.min(Ye.line,h.state.doc.lines)),w=h.state.doc.line(m),k=Math.max(1,Ye.column||1),J=Math.max(0,w.to-w.from),rr=Math.min(J,k-1),mt=w.from+rr;if(!(h.state.selection.main.head===mt)||vt.current.attempts===0){vt.current.attempts+=1,h.dispatch({selection:{anchor:mt},effects:jt.scrollIntoView(mt,{y:"center"})}),h.focus(),t();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const it=_e.current;it&&(it.dispatch({selection:{anchor:mt},effects:jt.scrollIntoView(mt,{y:"center"})}),it.focus())}),xr(null),vt.current={key:"",attempts:0}},[Ke,_r,ie,Ci,rt,Ae,Fe,Be,nt,De,Re,Ye,o,c?.path,xr,O,Ft]),n.useEffect(()=>{if(!Jr||!o)return;const t=K(Jr);if(!t){Yr(null);return}c?.path===t&&(Ae||De!==t||(!rt&&!Fe&&!Be&&!nt&&Ke&&O==="edit"&&_e.current?.focus(),Yr(null)))},[Ke,rt,Ae,Fe,Be,nt,De,Jr,o,c?.path,Yr,O]);const zt=n.useCallback(t=>{if(!f||!t||!t.hasFocus||typeof window>"u")return;const i=window.visualViewport;if(!i)return;const l=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,l-(i.offsetTop+i.height))<=0)return;const h=t.state.selection.main.head,m=t.coordsAtPos(h);if(!m)return;const w=Math.round(i.offsetTop+i.height),J=m.bottom+20-w;J<=0||(t.scrollDOM.scrollTop+=J)},[f]);n.useEffect(()=>{if(!f||typeof window>"u")return;const t=()=>{window.requestAnimationFrame(()=>{zt(_e.current)})},i=window.visualViewport;return i?.addEventListener("resize",t),i?.addEventListener("scroll",t,{passive:!0}),document.addEventListener("selectionchange",t),()=>{i?.removeEventListener("resize",t),i?.removeEventListener("scroll",t),document.removeEventListener("selectionchange",t)}},[f,zt]),Oa("open_go_to_line",t=>{if(!Ke||O!=="edit"||f)return!1;const i=t.target;if(i?.closest('[role="dialog"]')||!(i instanceof Node)||!mr.current?.contains(i))return!1;const l=!!i?.closest(".cm-editor");if(!!i?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!l)return!1;Gr(!0)});const kr=ht(t=>t.editorFontSize),mn=n.useMemo(()=>{if(!c?.path)return[Wn(x,{fontSize:kr})];const t=ds(c.path),i=[Wn(x,t?{syntaxColors:!1,fontSize:kr}:{fontSize:kr})],l=Sr??un;return l&&i.push(l),t&&i.push(Ya({language:t,themeName:x.metadata.id,theme:to(x)})),X&&i.push(jt.lineWrapping),f&&i.push(jt.updateListener.of(u=>{u.view.hasFocus&&(u.selectionSet||u.focusChanged||u.viewportChanged||u.geometryChanged)&&window.requestAnimationFrame(()=>{zt(u.view)})})),i},[x,c?.path,Sr,un,X,f,zt,kr]),hn=n.useMemo(()=>({light:Ve.metadata.id,dark:Ee.metadata.id}),[Ve.metadata.id,Ee.metadata.id]),tr=c?.path&&Be&&(!gt.allowOutsideWorkspace||gt.outsideFileGrant)?`${c.path}|${gt.allowOutsideWorkspace?"outside":"workspace"}|${gt.outsideFileGrant??""}|${dr}`:"",Rr=c?.path&&Mt&&B==="preview"&&!d.isVSCode?`${c.path}|${dr}`:"",pn=e("filesView.error.readFileFailed"),{readyKey:gn,nonce:aa}=ti(Rr,ge,pn),{readyKey:xn,nonce:vn}=ti(tr,ge,pn),oa=!!(Rr&&gn!==Rr),wn=!!(tr&&xn!==tr),bn=c?.path&&Fe?Cr?`data:${Ba(c.path)};utf8,${encodeURIComponent(D)}`:vi:"",yn=c?.path&&Be&&tr&&xn===tr?Pn().authenticatedAsset("/api/fs/raw",{path:c.path,allowOutsideWorkspace:gt.allowOutsideWorkspace?"true":void 0,outsideFileGrant:gt.outsideFileGrant,directory:o||void 0}):"",jn=n.useCallback(t=>r.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:r.jsx("iframe",{src:yn,className:"h-full w-full border-0",title:t.name},vn)}),[yn,vn]);n.useEffect(()=>{let t=!1,i="";return(async()=>{if(!c?.path||!Fe||Cr){Ie("");return}ge(null);const u=await Xe(c.path);if(t)return;await(s.readFileBinary?s.readFileBinary(c.path,u).then(m=>m.dataUrl):(async()=>{const m=await Dn("/api/fs/raw",{query:{path:c.path,allowOutsideWorkspace:u.allowOutsideWorkspace?"true":void 0,outsideFileGrant:u.outsideFileGrant,directory:o||void 0}});if(!m.ok)throw new Error(e("filesView.error.readFileFailed"));const w=await m.blob();return i=URL.createObjectURL(w),t?(URL.revokeObjectURL(i),i="",""):i})()).then(m=>{t||(Ie(m),ne(c.path))}).catch(m=>{t||(Ie(""),ge(m instanceof Error?m.message:e("filesView.error.readFileFailed")),ne(null))}).finally(()=>{t||ot(!1)})})(),()=>{t=!0,i&&URL.revokeObjectURL(i)}},[dr,s,Fe,Cr,Xe,o,c?.path,gt,e]);const la=n.useCallback(()=>Kr(null),[]),ca=n.useMemo(()=>fo({drafts:Hs,editingDraftId:br,commentText:wr,onTextChange:Gs,selection:U,isDragging:Us,fileLabel:c?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:t=>({start:t.startLine,end:t.endLine}),onSave:Qs,onCancel:()=>{Ue(null),Zt()},onEdit:t=>{Ys(t),Ue({start:t.startLine,end:t.endLine})},onDelete:Zs}),[Zt,wr,Zs,br,Hs,Qs,Us,U,c?.path,Gs,Ys]),Fn=Xn(),Nn=Xn(),as=Ka("unified"),He=D.length>Ot,os=n.useMemo(()=>He?Go(D):void 0,[D,He]),Cn=n.useCallback((t,i,l)=>{const u={name:t.name,contents:i,lang:ds(t.path)||void 0},h=m=>r.jsx(eo,{file:He&&os?{...u,cacheKey:`${t.path}:${os}`}:u,options:{disableFileHeader:!0,overflow:X?"wrap":"scroll",theme:hn,themeType:x.metadata.variant==="dark"?"dark":"light"},className:He?"block w-full":"block h-full w-full",style:He?void 0:{height:"100%"}},m);return He?r.jsx("div",{className:"h-full",children:r.jsx(ro.Provider,{value:l.virtualizer,children:r.jsx(so.Provider,{value:as,children:h(`${t.path}:${as?"pool":"pending"}`)})})}):r.jsx("div",{className:"h-full",children:h(t.path)})},[x.metadata.variant,He,os,hn,as,X]),Sn=({exitFullscreenOnly:t=!1,layout:i="floating"}={})=>{if(!c)return null;const l=i==="docked",u=$a(Wa("save_file")),h=l?"pointer-events-auto flex flex-wrap items-center gap-1":"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",m=(w,k)=>r.jsxs(Lt,{children:[r.jsx(At,{asChild:!0,children:r.jsx("span",{className:"inline-flex",children:k})}),r.jsx(It,{side:"bottom",sideOffset:6,children:w})]});return r.jsxs("div",{className:h,children:[Ke&&Zi&&r.jsxs(r.Fragment,{children:[_t?r.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[r.jsx(y,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):je&&ji==="saved"&&!Me?r.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[r.jsx(y,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):Me?m(e(je?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:u}),r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{Et()},className:"h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(je?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:u}),"aria-label":e("filesView.editor.saveAria",{shortcut:u}),children:r.jsx(y,{name:"save-3",className:"size-4"})})):null,m(e(je?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Ni(!je),className:G("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",je?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(je?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(je?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:je?r.jsx(y,{name:"file-check-fill",className:"size-4"}):r.jsx(y,{name:"file-check",className:"size-4"})}))]}),r.jsxs(vs,{onOpenChange:Ce,children:[r.jsxs(Lt,{children:[r.jsx(At,{asChild:!0,children:r.jsx("span",{className:"inline-flex",children:r.jsx(ws,{asChild:!0,children:r.jsx(z,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.openInDesktopApp"),"aria-label":e("filesView.editor.openInDesktopApp"),children:r.jsx(y,{name:"file-transfer",className:"size-4"})})})})}),r.jsx(It,{side:"bottom",sideOffset:6,children:e("filesView.editor.openInDesktopApp")})]}),r.jsxs(bs,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[zi.map(w=>r.jsxs(Dr,{className:"flex items-center gap-2",onClick:()=>{Oi(w)},children:[r.jsx(Io,{label:w.label,iconDataUrl:w.iconDataUrl}),r.jsx("span",{className:"typography-ui-label text-foreground",children:w.label})]},w.id)),Li?r.jsxs(Dr,{className:"flex items-center gap-2",onClick:()=>{Ai(!0)},children:[r.jsx(y,{name:"refresh",className:"size-4"}),r.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!Fe&&!Be&&!nt&&r.jsxs(r.Fragment,{children:[m(e(X?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Ne(!X),className:G("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",X?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(X?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:r.jsx(y,{name:"text-wrap",className:"size-4"})})),O==="edit"&&r.jsxs(r.Fragment,{children:[m(e("filesView.editor.findInFile"),r.jsx(z,{variant:"ghost",size:"sm",onClick:w=>{le(!ee),w.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:r.jsx(y,{name:"search",className:"size-4"})})),m(e("filesView.editor.goToLine"),r.jsx(z,{variant:"ghost",size:"sm",onClick:w=>{Gr(k=>!k),w.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.goToLine"),children:r.jsx(y,{name:"menu-fold-2",className:"size-4"})})),r.jsx(jo,{open:Mi,onOpenChange:Gr,view:_e.current,variant:"inline"})]})]}),es&&Ke&&!Qt&&!Mt&&r.jsx(ps,{currentMode:O==="view"?"preview":"edit",onToggle:()=>{Qi(O==="view"?"edit":"view")}}),Qe&&m(e($e()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>ea($e()==="preview"?"edit":"preview"),className:G("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",$e()==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)] focus-visible:bg-[var(--interactive-selection)] active:bg-[var(--interactive-selection)]":"text-muted-foreground opacity-65 hover:opacity-100"),title:e($e()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),"aria-label":e($e()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:r.jsx(y,{name:$e()==="preview"?"eye":"eye-off",className:"size-4"})})),xs(c?.path??"")&&r.jsx(ps,{currentMode:fn(),onToggle:()=>{ra(fn()==="preview"?"edit":"preview")}}),Qe&&$e()==="preview"&&m(e("filesView.editor.findInFile"),r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{hr(!0),As(w=>w+1)},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:r.jsx(y,{name:"search",className:"size-4"})})),Qe&&$e()==="preview"&&Bi&&r.jsxs(Lt,{children:[r.jsx(At,{asChild:!0,children:r.jsx(z,{variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent","aria-label":e(ur?"filesView.tts.stopSpeaking":"filesView.tts.readAloud"),onClick:()=>{ur?xi():D.trim()&&gi(D)},children:ur?r.jsx(y,{name:"stop",className:"size-4 text-[color:var(--status-success)]"}):r.jsx(y,{name:"volume-up",className:"size-4"})})}),r.jsx(It,{sideOffset:8,children:e(ur?"filesView.tts.stopSpeaking":"filesView.tts.readAloud")})]}),er&&r.jsxs(r.Fragment,{children:[r.jsx(ps,{currentMode:re,onToggle:()=>sa(re==="preview"?"edit":"preview")}),re==="preview"&&r.jsx(z,{variant:"ghost",size:"sm",onClick:async()=>{const w=Vs.current?.getXml();if(Pe.current&&(clearTimeout(Pe.current),Pe.current=null),c?.path&&w){if(!await is(c.path,w))return;fr(!0),setTimeout(()=>fr(!1),1500)}},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.diagram.saveDiagram"),children:Fi?r.jsx(y,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):r.jsx(y,{name:"save-3",className:"size-4"})})]}),Qt&&m(e(ue==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>ta(ue==="tree"?"text":"tree"),className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(ue==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:ue==="tree"?r.jsx(y,{name:"code-sslash",className:"size-4"}):r.jsx(y,{name:"node-tree",className:"size-4"})})),Ji&&m(e("filesView.editor.copyFileContents"),r.jsx(z,{variant:"ghost",size:"sm",onClick:async()=>{(await Mr(D)).ok?(Ps(!0),Xt.current!==null&&window.clearTimeout(Xt.current),Xt.current=window.setTimeout(()=>{Ps(!1)},1200)):Y.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:Di?r.jsx(y,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):r.jsx(y,{name:"clipboard",className:"size-4"})})),Yi&&m(e("filesView.editor.copyFilePathTitle",{path:ft}),r.jsx(z,{variant:"ghost",size:"sm",onClick:async()=>{(await Mr(ft)).ok?(Ms(!0),Jt.current!==null&&window.clearTimeout(Jt.current),Jt.current=window.setTimeout(()=>{Ms(!1)},1200)):Y.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:ft}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:ft}),children:Pi?r.jsx(y,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):r.jsx(y,{name:"file-copy-2",className:"size-4"})})),s.downloadFile&&m(e("filesView.editor.saveFile"),r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{const w=s.downloadFile;w&&w(c.path).catch(k=>{console.error("Download failed:",k),Y.error(e("sidebarFilesTree.toast.operationFailed"))})},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.saveFile"),"aria-label":e("filesView.editor.saveFile"),children:r.jsx(y,{name:"download",className:"size-4"})})),t?m(e("filesView.editor.exitFullscreen"),r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Z(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:r.jsx(y,{name:"fullscreen-exit",className:"size-4"})})):!f&&a==="full"&&m(e(_?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Z(!_),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(_?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(_?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:_?r.jsx(y,{name:"fullscreen-exit",className:"size-4"}):r.jsx(y,{name:"fullscreen",className:"size-4"})}))]})},ls=r.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[r.jsx(si,{open:_r,onOpenChange:t=>{t||Ht(!0)},children:r.jsxs(ni,{showCloseButton:!1,className:"max-w-md",children:[r.jsxs(ii,{children:[r.jsx(ai,{children:e("filesView.unsaved.title")}),r.jsx(oi,{children:e("filesView.unsaved.description")})]}),r.jsxs(li,{children:[r.jsx(z,{variant:"outline",onClick:()=>{Ki()},disabled:_t,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:e("filesView.unsaved.saveChanges")}),r.jsx(z,{variant:"destructive",onClick:Ui,children:e("filesView.unsaved.discard")})]})]})}),r.jsxs("div",{className:G("flex flex-col flex-shrink-0",A&&"border-b border-border/40"),children:[A?r.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[f&&$&&r.jsx("button",{type:"button",onClick:()=>P(!1),"aria-label":e("filesView.editor.back"),className:"inline-flex size-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:r.jsx(y,{name:"arrow-left-s",className:"size-5"})}),f?c?r.jsxs(vs,{children:[r.jsx(ws,{asChild:!0,children:r.jsxs("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium","aria-label":e("filesView.editor.openFilesAria"),children:[r.jsx(Er,{filePath:c.path,extension:c.extension,className:"size-3.5 flex-shrink-0"}),r.jsx(Zn,{name:c.name}),r.jsx(y,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),r.jsx(bs,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:Nt.map(t=>{const i=c?.path===t.path;return r.jsxs(Dr,{onSelect:l=>{if(l.target.closest("[data-close-open-file]")){l.preventDefault();return}i||Re(t)},className:G("flex min-w-0 items-center justify-between gap-2 overflow-hidden",i&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[r.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[r.jsx(Er,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),r.jsx(Zn,{name:t.name})]}),r.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:l=>{l.preventDefault(),l.stopPropagation()},onClick:l=>{l.preventDefault(),l.stopPropagation(),on(t.path)},className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:r.jsx(y,{name:"close",className:"size-3.5"})})]},t.path)})})]}):r.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):Nt.length>0?r.jsxs("div",{className:"relative min-w-0 flex-1",children:[Fs.left&&r.jsx("div",{className:"pointer-events-none absolute left-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-r from-background to-transparent"}),Fs.right&&r.jsx("div",{className:"pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent"}),r.jsx("div",{ref:Ir,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:Nt.map(t=>{const i=c?.path===t.path;return r.jsxs("div",{title:Pr(o,t.path),className:G("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",i?"bg-[var(--interactive-selection)] border-[var(--primary-muted)] text-[var(--interactive-selection-foreground)]":"bg-transparent border-[var(--interactive-border)] text-[var(--surface-muted-foreground)] hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]"),children:[r.jsx(Er,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),r.jsx("button",{type:"button",onClick:()=>{i||Re(t)},className:"max-w-[12rem] truncate text-left",children:t.name}),r.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),on(t.path)},className:G("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!i&&!N&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:r.jsx(y,{name:"close",className:"size-3.5"})})]},t.path)})})]}):r.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null,c?r.jsxs("div",{className:"flex min-w-0 items-center gap-3 border-t border-border/40 bg-[var(--surface-subtle)] px-3 py-1",children:[ft&&!f?r.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:ft,children:ft}):null,r.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:Sn({layout:"docked"})})]}):null]}),r.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:r.jsx(ms,{ref:Fn.setScroller,outerClassName:"h-full min-w-0",className:G("h-full min-w-0",He&&"[overflow-anchor:none]"),children:c?Ae||wn?I?r.jsx("div",{className:"p-3"}):r.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[r.jsx(y,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):rt?r.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:rt}):Fe?r.jsx("div",{className:"flex h-full items-center justify-center p-3",children:r.jsx("img",{src:bn,alt:c?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"},c.path)}):Be?jn(c):nt?r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[r.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),r.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),s.downloadFile?r.jsxs(z,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=s.downloadFile;!t||!c||t(c.path).catch(i=>{console.error("Download failed:",i),Y.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[r.jsx(y,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):c&&er&&re==="preview"?r.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:r.jsx(Lo,{ref:Vs,xml:ia,onChange:na},`${c.path}:${Se}`)}):c&&Qt&&ue==="tree"?r.jsx(hs,{fallback:r.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[r.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.jsonViewerUnavailable")}),r.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToTextMode")})]}),children:r.jsx("div",{className:"h-full overflow-auto",children:r.jsx(Qa,{jsonString:D,maxHeight:"100%",initiallyExpandedDepth:2})})}):c&&Qe&&$e()==="preview"?r.jsxs("div",{className:"relative h-full min-h-0",children:[r.jsxs("div",{className:"oc-file-preview h-full overflow-auto p-3 outline-none",tabIndex:-1,onMouseDown:gr,ref:t=>{vr.current=t,pr.current=t},children:[r.jsx(Kn,{containerRef:vr,filePath:c.path,fileContent:D}),D.length>500*1024&&r.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(D.length/1024)})}),r.jsx(hs,{fallback:r.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[r.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),r.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:r.jsx($n,{content:D,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}),!_&&r.jsx(qn,{containerRef:pr,open:zs,onOpenChange:hr,focusNonce:Ls})]}):c&&Mt&&B==="preview"?oa?r.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:e("common.loading")}):r.jsx("div",{className:"h-full overflow-hidden",children:r.jsx("iframe",{src:!d.isVSCode&&gn===Rr?(()=>{const t=c.path.split("/").map(i=>encodeURIComponent(i)).join("/");return Pn().authenticatedAsset(`/api/fs/serve${t.startsWith("/")?t:`/${t}`}`)})():void 0,srcDoc:d.isVSCode?(()=>{const t=c.path.substring(0,c.path.lastIndexOf("/")+1);return t?D.replace(/<head([^>]*)>/i,`<head$1><base href="${t}">`):D})():void 0,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")},aa)}):c&&es&&O==="view"?Cn(c,He?D:ie,Fn):r.jsxs("div",{className:G("relative h-full",Pt&&"overflow-hidden"),ref:mr,children:[r.jsx("div",{className:G("h-full",Pt&&"invisible"),children:r.jsx(_n,{value:ie,onChange:ye,readOnly:!Ke,vimMode:Ks==="vim",extensions:mn,className:"h-full",blockWidgets:ca,onViewReady:t=>{_e.current=t,Ur(i=>i+1),window.requestAnimationFrame(()=>{zt(t)})},onViewDestroy:()=>{_e.current&&(_e.current=null),Ur(t=>t+1)},enableSearch:!0,searchOpen:ee,onSearchOpenChange:le,highlightLines:U?{start:Math.min(U.start,U.end),end:Math.max(U.start,U.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(t,i,l)=>{if(!(l instanceof MouseEvent)||l.button!==0)return!1;l.preventDefault();const u=t.state.doc.lineAt(i.from).number;if(U&&!l.shiftKey&&Math.min(U.start,U.end)===u&&Math.max(U.start,U.end)===u)return Ue(null),Zt(),Tt.current=!1,ut.current=null,Vt(!1),!0;if(f&&U&&!l.shiftKey){const h=Math.min(U.start,U.end,u),m=Math.max(U.start,U.end,u);return Ue({start:h,end:m}),Tt.current=!1,ut.current=null,Vt(!1),!0}if(Tt.current=!0,ut.current=u,Vt(!0),U&&l.shiftKey){const h=Math.min(U.start,u),m=Math.max(U.end,u);Ue({start:h,end:m})}else Ue({start:u,end:u});return!0},mouseover:(t,i,l)=>{if(!(l instanceof MouseEvent)||l.buttons!==1||!Tt.current||ut.current===null)return!1;const u=t.state.doc.lineAt(i.from).number,h=Math.min(ut.current,u),m=Math.max(ut.current,u);return Ue({start:h,end:m}),Vt(!0),!1},mouseup:()=>(Tt.current=!1,ut.current=null,Vt(!1),!1)}}})}),Pt&&r.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:r.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[r.jsx(y,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):r.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})})]}),ua=!!(o&&Ss[o]),kn=o?or[o]:null,Rn=r.jsxs("section",{className:G("flex min-h-0 flex-col overflow-hidden",f?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[r.jsx("div",{className:G("flex flex-col gap-2 py-2",f?"px-3":"px-2"),children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("div",{className:"relative flex-1 min-w-0",children:[r.jsx(y,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),r.jsx(nr,{ref:M,value:E,onChange:t=>V(t.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),E.trim().length>0&&r.jsx("button",{type:"button","aria-label":e("filesView.tree.search.clearAria"),className:"absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{V(""),M.current?.focus()},children:r.jsx(y,{name:"close",className:"size-4"})})]}),r.jsxs(Lt,{children:[r.jsx(At,{asChild:!0,children:r.jsx("span",{className:"inline-flex flex-shrink-0",children:r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Xr("createFile",{path:T,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),"aria-label":e("filesView.tree.actions.newFileTitle"),children:r.jsx(y,{name:"file-add",className:"size-4"})})})}),r.jsx(It,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFileTitle")})]}),r.jsxs(Lt,{children:[r.jsx(At,{asChild:!0,children:r.jsx("span",{className:"inline-flex flex-shrink-0",children:r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Xr("createFolder",{path:T,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),"aria-label":e("filesView.tree.actions.newFolderTitle"),children:r.jsx(y,{name:"folder-add",className:"size-4"})})})}),r.jsx(It,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFolderTitle")})]}),r.jsxs(Lt,{children:[r.jsx(At,{asChild:!0,children:r.jsx("span",{className:"inline-flex flex-shrink-0",children:r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{yr()},className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.refreshTitle"),"aria-label":e("filesView.tree.actions.refreshTitle"),children:r.jsx(y,{name:"refresh",className:"size-4"})})})}),r.jsx(It,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.refreshTitle")})]})]})}),r.jsx(ms,{outerClassName:"flex-1 min-h-0",className:G("py-2",f?"px-3":"px-2"),children:r.jsx("ul",{className:"flex flex-col",children:pi?r.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[r.jsx(y,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):Rs.length>0?Rs.map(t=>{const i=c?.path===t.path;return r.jsx("li",{children:r.jsxs("button",{type:"button",onClick:()=>{Re(t)},className:G("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[fi(t.path,t.extension),r.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:t.path,children:t.relativePath??t.path})]})},t.path)}):kn?r.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[r.jsx("span",{className:"text-[var(--status-error)]",children:kn}),r.jsxs(z,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{yr()},children:[r.jsx(y,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):ua?ln(o,0):r.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),da=a==="full"&&_&&c&&r.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:r.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[r.jsx("div",{className:"absolute right-4 top-4 z-30",children:Sn({exitFullscreenOnly:!0})}),r.jsx(ms,{ref:Nn.setScroller,outerClassName:"h-full min-w-0",className:G("h-full min-w-0",He&&"[overflow-anchor:none]"),children:Ae||wn?I?r.jsx("div",{className:"p-4"}):r.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[r.jsx(y,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):rt?r.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:rt}):Fe?r.jsx("div",{className:"flex h-full items-center justify-center p-4",children:r.jsx("img",{src:bn,alt:c.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"},c.path)}):Be?jn(c):nt?r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[r.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),r.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),s.downloadFile?r.jsxs(z,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=s.downloadFile;!t||!c||t(c.path).catch(i=>{console.error("Download failed:",i),Y.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[r.jsx(y,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):Qe&&$e()==="preview"?r.jsxs("div",{className:"relative h-full min-h-0",children:[r.jsxs("div",{className:"oc-file-preview h-full overflow-auto p-4 outline-none",tabIndex:-1,onMouseDown:gr,ref:t=>{vr.current=t,qr.current=t},children:[c?r.jsx(Kn,{containerRef:vr,filePath:c.path,fileContent:D}):null,D.length>500*1024&&r.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(D.length/1024)})}),r.jsx(hs,{fallback:r.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[r.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),r.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:r.jsx($n,{content:D,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}),r.jsx(qn,{containerRef:qr,open:zs,onOpenChange:hr,focusNonce:Ls,className:"right-4 top-16"})]}):es&&O==="view"?Cn(c,He?D:ie,Nn):r.jsxs("div",{className:G("relative h-full",Pt&&"overflow-hidden"),children:[r.jsx("div",{className:G("h-full",Pt&&"invisible"),children:r.jsx(_n,{value:ie,onChange:ye,readOnly:!Ke,vimMode:Ks==="vim",extensions:mn,className:"h-full",onViewReady:t=>{_e.current=t,window.requestAnimationFrame(()=>{zt(t)})},onViewDestroy:()=>{_e.current&&(_e.current=null)}})}),Pt&&r.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:r.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[r.jsx(y,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return r.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[r.jsx(Zo,{activeDialog:wt,dialogData:bt,dialogInputValue:ct,onDialogInputChange:Ds,isDialogSubmitting:ki,onDialogSubmit:_i,onClose:la,inputRef:bi}),da,f?$?ls:Rn:a==="editor-only"?r.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:r.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:ls})}):r.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[p>=700&&r.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:Rn}),r.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:ls})]})]})};function Qo(a){return a+1}export{bu as FilesView};
|